2014-02-17 14:19 GMT+01:00 Paolo Bonzini <[email protected]>:
> Il 17/02/2014 14:11, Alex David ha scritto:
>
> I've tried using tmp105. As my linux isn't 64bits, i'm using
>> qemu-system-i386... It crashes my computer when I use it with my linux
>> image (it's a debian .qcow2..., easy to do some tests...).
>>
>
> You mean crashes your host?
>
Yes, my host crashes... I need to hard-reboot my computer.
>
> I will most probably need a chardev anyways, I will need to read/write
>> data when I want to.
>>
>
> Depends on how much data. If it's just one or two ints, like tmp105, QOM
> would work too. qmp-shell talks to QEMU via a simple JSON protocol, and it
> has simple Python bindings too.
>
>
> static const TypeInfo mydevice_i2c_type_info = {
>> .name = TYPE_MYDEVICE_I2C,
>> .parent = TYPE_I2C_SLAVE,
>> .instance_size = sizeof(MYDEVICEI2CState),
>> .instance_init = MYDEVICE_i2c_init,
>> .class_init = mydevice_i2c_class_init,
>> };
>>
>> I will be able to add a chardev using the properties, right ?
>>
>
> Yes, using dc->props.
>
>
> Does this seems ok for you ? So far, I understood the "props" are needed
>> for when I'm gonna declare the device at QEMU launch.
>> I am not sure if it's needed (my i2c-0 should be created anyways), but
>> in that case, how do I "plug" it on my socket on the host ?
>>
>
> Your device is not i2c-0. i2c-0 is provided by the PC board. Your device
> will get one address, e.g. 0x42, on the i2c bus. You'll be able to access
> it with i2cget and i2cset using "0" as the bus address (for i2c-0) and 0x42
> as the device address on bus 0.
>
> So you'll indeed have to do something like "-chardev socket,id=foo -device
> myi2c,address=0x42,chr=foo" if you go for sockets, or just "-device
> myi2c,address=0x42" if you go for QOM. The "chr" property should go into
> dc->props, while "address" is provided by the abstract class TYPE_I2C_SLAVE.
>
> Paolo
>
That seems fairly easy.
But that leaves me with another problem as I now understand how I2C works
on linux... I, in fact, need at least 3 busses (for my at least 3 devices)
- so i2c-0, i2c-1, i2c-2 ... There are applications I can't change on the
guest and opening / writing / reading on i2c-0, i2c-1 etc...
Can I just declare these busses using i2c-dev ?