Hi,

I am new to QEMU development, so please excuse if I my direction here is wrong:

I am trying to implement an i2c slave device.
My device should be able to read/write data from its i2c bus.

I defined my device-state object like so:

    typedef struct {
          I2CSlave i2c;
          void     *my_data;

    }   MyI2CSlave;


In my implementation occasionally I may have to send data on the bus, due to an 
internal event on my side.
For this I implemented the following code:

    //  Get bus pointer:
    BusState *parentBus = qdev_get_parent_bus(DEVICE(&obj->i2c));
    I2CBus   *i2cBus    = I2C_BUS(parentBus);
      
    //  Try to send data on bus:  
    if (i2c_start_send(i2cBus, address)) {
        //  error?
        return;
    }
    for (int i = 0; i < size; i++) {
        i2c_send(i2cBus, data[i]);
    }
    i2c_end_transfer(i2cBus);

      
The problem is that 'i2c_start_send()' always fails here:

    if (QLIST_EMPTY(&bus->current_devs)) {
        return 1;
    }

The member 'i2cBus->current_devs.lh_first' is always null.

I will add that in my QEMU execution I specify the bus 'aspeed.i2c.bus.0' to be 
used with my device.
In my 'realize' method I can see that a bus is connected to my device, as 
'qdev_get_parent_bus()' does return a valid pointer.

My question:
1. Am I missing some initialization for the bus?
2. Is there other way to send data on the i2c bus, assuming it can happen 
anytime due to an internal event on my device side?

Thanks for any tip,
Pazo  

Reply via email to