~jderose/ubuntu/raring/qemu/vde-again

« back to all changes in this revision

Viewing changes to hw/smbus.c

  • Committer: Bazaar Package Importer
  • Author(s): Riku Voipio, Josh Triplett, Riku Voipio
  • Date: 2009-07-29 13:28:05 UTC
  • mfrom: (1.4.1 upstream)
  • mto: (12.1.1 sid) (10.1.13 sid)
  • mto: This revision was merged to the branch mainline in revision 13.
  • Revision ID: james.westby@ubuntu.com-20090729132805-cau7rfexh7dawyb8
Tags: 0.10.50+git20090729-1
[ Josh Triplett ]
* Remove myself from Uploaders.

[ Riku Voipio ]
* new upstream RC version
* nuke all linux-user patches (applied upstream)
  06_exit_segfault
  12_signal_powerpc_support
  21_net_soopts
  30_syscall_ipc
  32_syscall_sysctl
  35_syscall_sockaddr
  48_signal_terminate
  55_unmux_socketcall
* nuke all other applied-upstream patches
  01_nostrip (better version upstream)
  07_i386_exec_name (can be reintroduced in debian/rules)
  50_linuxbios_isa_bios_ram (shouldn't be needed anymore)
  51_linuxbios_piix_ram_size (applied)
  56_dhcp (crap)
  60_ppc_ld (reintroduce if needed)
  64_ppc_asm_constraints (ditto)
  66_tls_ld.patch (ditto)
  81_compile_dtb.patch (applied upstream)
  82_qemu-img_decimal (ditto)
* move to git
* simplify build rules
* Correct my email address

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
//#define DEBUG_SMBUS 1
17
17
 
18
18
#ifdef DEBUG_SMBUS
19
 
#define DPRINTF(fmt, args...) \
20
 
do { printf("smbus(%02x): " fmt , dev->i2c.address, ##args); } while (0)
21
 
#define BADF(fmt, args...) \
22
 
do { fprintf(stderr, "smbus: error: " fmt , ##args); exit(1);} while (0)
 
19
#define DPRINTF(fmt, ...) \
 
20
do { printf("smbus(%02x): " fmt , dev->i2c.address, ## __VA_ARGS__); } while (0)
 
21
#define BADF(fmt, ...) \
 
22
do { fprintf(stderr, "smbus: error: " fmt , ## __VA_ARGS__); exit(1);} while (0)
23
23
#else
24
 
#define DPRINTF(fmt, args...) do {} while(0)
25
 
#define BADF(fmt, args...) \
26
 
do { fprintf(stderr, "smbus: error: " fmt , ##args);} while (0)
 
24
#define DPRINTF(fmt, ...) do {} while(0)
 
25
#define BADF(fmt, ...) \
 
26
do { fprintf(stderr, "smbus: error: " fmt , ## __VA_ARGS__);} while (0)
27
27
#endif
28
28
 
29
29
enum {
37
37
 
38
38
static void smbus_do_quick_cmd(SMBusDevice *dev, int recv)
39
39
{
 
40
    SMBusDeviceInfo *t = container_of(dev->i2c.info, SMBusDeviceInfo, i2c);
 
41
 
40
42
    DPRINTF("Quick Command %d\n", recv);
41
 
    if (dev->quick_cmd)
42
 
        dev->quick_cmd(dev, recv);
 
43
    if (t->quick_cmd)
 
44
        t->quick_cmd(dev, recv);
43
45
}
44
46
 
45
47
static void smbus_do_write(SMBusDevice *dev)
46
48
{
 
49
    SMBusDeviceInfo *t = container_of(dev->i2c.info, SMBusDeviceInfo, i2c);
 
50
 
47
51
    if (dev->data_len == 0) {
48
52
        smbus_do_quick_cmd(dev, 0);
49
53
    } else if (dev->data_len == 1) {
50
54
        DPRINTF("Send Byte\n");
51
 
        if (dev->send_byte) {
52
 
            dev->send_byte(dev, dev->data_buf[0]);
 
55
        if (t->send_byte) {
 
56
            t->send_byte(dev, dev->data_buf[0]);
53
57
        }
54
58
    } else {
55
59
        dev->command = dev->data_buf[0];
56
60
        DPRINTF("Command %d len %d\n", dev->command, dev->data_len - 1);
57
 
        if (dev->write_data) {
58
 
            dev->write_data(dev, dev->command, dev->data_buf + 1,
59
 
                            dev->data_len - 1);
 
61
        if (t->write_data) {
 
62
            t->write_data(dev, dev->command, dev->data_buf + 1,
 
63
                          dev->data_len - 1);
60
64
        }
61
65
    }
62
66
}
63
67
 
64
68
static void smbus_i2c_event(i2c_slave *s, enum i2c_event event)
65
69
{
66
 
    SMBusDevice *dev = (SMBusDevice *)s;
 
70
    SMBusDevice *dev = FROM_I2C_SLAVE(SMBusDevice, s);
 
71
 
67
72
    switch (event) {
68
73
    case I2C_START_SEND:
69
74
        switch (dev->mode) {
145
150
 
146
151
static int smbus_i2c_recv(i2c_slave *s)
147
152
{
148
 
    SMBusDevice *dev = (SMBusDevice *)s;
 
153
    SMBusDeviceInfo *t = container_of(s->info, SMBusDeviceInfo, i2c);
 
154
    SMBusDevice *dev = FROM_I2C_SLAVE(SMBusDevice, s);
149
155
    int ret;
150
156
 
151
157
    switch (dev->mode) {
152
158
    case SMBUS_RECV_BYTE:
153
 
        if (dev->receive_byte) {
154
 
            ret = dev->receive_byte(dev);
 
159
        if (t->receive_byte) {
 
160
            ret = t->receive_byte(dev);
155
161
        } else {
156
162
            ret = 0;
157
163
        }
159
165
        dev->mode = SMBUS_DONE;
160
166
        break;
161
167
    case SMBUS_READ_DATA:
162
 
        if (dev->read_data) {
163
 
            ret = dev->read_data(dev, dev->command, dev->data_len);
 
168
        if (t->read_data) {
 
169
            ret = t->read_data(dev, dev->command, dev->data_len);
164
170
            dev->data_len++;
165
171
        } else {
166
172
            ret = 0;
178
184
 
179
185
static int smbus_i2c_send(i2c_slave *s, uint8_t data)
180
186
{
181
 
    SMBusDevice *dev = (SMBusDevice *)s;
 
187
    SMBusDevice *dev = FROM_I2C_SLAVE(SMBusDevice, s);
 
188
 
182
189
    switch (dev->mode) {
183
190
    case SMBUS_WRITE_DATA:
184
191
        DPRINTF("Write data %02x\n", data);
191
198
    return 0;
192
199
}
193
200
 
194
 
SMBusDevice *smbus_device_init(i2c_bus *bus, int address, int size)
195
 
{
196
 
    SMBusDevice *dev;
197
 
 
198
 
    if (size < sizeof(SMBusDevice))
199
 
        hw_error("SMBus struct too small");
200
 
 
201
 
    dev = (SMBusDevice *)i2c_slave_init(bus, address, size);
202
 
    dev->i2c.event = smbus_i2c_event;
203
 
    dev->i2c.recv = smbus_i2c_recv;
204
 
    dev->i2c.send = smbus_i2c_send;
205
 
 
206
 
    return dev;
 
201
static void smbus_device_init(i2c_slave *i2c)
 
202
{
 
203
    SMBusDeviceInfo *t = container_of(i2c->info, SMBusDeviceInfo, i2c);
 
204
    SMBusDevice *dev = FROM_I2C_SLAVE(SMBusDevice, i2c);
 
205
 
 
206
    t->init(dev);
 
207
}
 
208
 
 
209
void smbus_register_device(SMBusDeviceInfo *info)
 
210
{
 
211
    assert(info->i2c.qdev.size >= sizeof(SMBusDevice));
 
212
    info->i2c.init = smbus_device_init;
 
213
    info->i2c.event = smbus_i2c_event;
 
214
    info->i2c.recv = smbus_i2c_recv;
 
215
    info->i2c.send = smbus_i2c_send;
 
216
    i2c_register_slave(&info->i2c);
207
217
}
208
218
 
209
219
/* Master device commands.  */