Revision bc24a225 hw/max7310.c
b/hw/max7310.c | ||
---|---|---|
10 | 10 |
#include "hw.h" |
11 | 11 |
#include "i2c.h" |
12 | 12 |
|
13 |
struct max7310_s {
|
|
13 |
typedef struct {
|
|
14 | 14 |
i2c_slave i2c; |
15 | 15 |
int i2c_command_byte; |
16 | 16 |
int len; |
... | ... | |
22 | 22 |
uint8_t command; |
23 | 23 |
qemu_irq handler[8]; |
24 | 24 |
qemu_irq *gpio_in; |
25 |
}; |
|
25 |
} MAX7310State;
|
|
26 | 26 |
|
27 | 27 |
void max7310_reset(i2c_slave *i2c) |
28 | 28 |
{ |
29 |
struct max7310_s *s = (struct max7310_s *) i2c;
|
|
29 |
MAX7310State *s = (MAX7310State *) i2c;
|
|
30 | 30 |
s->level &= s->direction; |
31 | 31 |
s->direction = 0xff; |
32 | 32 |
s->polarity = 0xf0; |
... | ... | |
36 | 36 |
|
37 | 37 |
static int max7310_rx(i2c_slave *i2c) |
38 | 38 |
{ |
39 |
struct max7310_s *s = (struct max7310_s *) i2c;
|
|
39 |
MAX7310State *s = (MAX7310State *) i2c;
|
|
40 | 40 |
|
41 | 41 |
switch (s->command) { |
42 | 42 |
case 0x00: /* Input port */ |
... | ... | |
71 | 71 |
|
72 | 72 |
static int max7310_tx(i2c_slave *i2c, uint8_t data) |
73 | 73 |
{ |
74 |
struct max7310_s *s = (struct max7310_s *) i2c;
|
|
74 |
MAX7310State *s = (MAX7310State *) i2c;
|
|
75 | 75 |
uint8_t diff; |
76 | 76 |
int line; |
77 | 77 |
|
... | ... | |
126 | 126 |
|
127 | 127 |
static void max7310_event(i2c_slave *i2c, enum i2c_event event) |
128 | 128 |
{ |
129 |
struct max7310_s *s = (struct max7310_s *) i2c;
|
|
129 |
MAX7310State *s = (MAX7310State *) i2c;
|
|
130 | 130 |
s->len = 0; |
131 | 131 |
|
132 | 132 |
switch (event) { |
... | ... | |
146 | 146 |
|
147 | 147 |
static void max7310_save(QEMUFile *f, void *opaque) |
148 | 148 |
{ |
149 |
struct max7310_s *s = (struct max7310_s *) opaque;
|
|
149 |
MAX7310State *s = (MAX7310State *) opaque;
|
|
150 | 150 |
|
151 | 151 |
qemu_put_be32(f, s->i2c_command_byte); |
152 | 152 |
qemu_put_be32(f, s->len); |
... | ... | |
162 | 162 |
|
163 | 163 |
static int max7310_load(QEMUFile *f, void *opaque, int version_id) |
164 | 164 |
{ |
165 |
struct max7310_s *s = (struct max7310_s *) opaque;
|
|
165 |
MAX7310State *s = (MAX7310State *) opaque;
|
|
166 | 166 |
|
167 | 167 |
s->i2c_command_byte = qemu_get_be32(f); |
168 | 168 |
s->len = qemu_get_be32(f); |
... | ... | |
179 | 179 |
|
180 | 180 |
static void max7310_gpio_set(void *opaque, int line, int level) |
181 | 181 |
{ |
182 |
struct max7310_s *s = (struct max7310_s *) opaque;
|
|
182 |
MAX7310State *s = (MAX7310State *) opaque;
|
|
183 | 183 |
if (line >= ARRAY_SIZE(s->handler) || line < 0) |
184 | 184 |
hw_error("bad GPIO line"); |
185 | 185 |
|
... | ... | |
191 | 191 |
|
192 | 192 |
/* MAX7310 is SMBus-compatible (can be used with only SMBus protocols), |
193 | 193 |
* but also accepts sequences that are not SMBus so return an I2C device. */ |
194 |
struct i2c_slave *max7310_init(i2c_bus *bus)
|
|
194 |
i2c_slave *max7310_init(i2c_bus *bus) |
|
195 | 195 |
{ |
196 |
struct max7310_s *s = (struct max7310_s *)
|
|
197 |
i2c_slave_init(bus, 0, sizeof(struct max7310_s));
|
|
196 |
MAX7310State *s = (MAX7310State *)
|
|
197 |
i2c_slave_init(bus, 0, sizeof(MAX7310State));
|
|
198 | 198 |
s->i2c.event = max7310_event; |
199 | 199 |
s->i2c.recv = max7310_rx; |
200 | 200 |
s->i2c.send = max7310_tx; |
... | ... | |
210 | 210 |
|
211 | 211 |
qemu_irq *max7310_gpio_in_get(i2c_slave *i2c) |
212 | 212 |
{ |
213 |
struct max7310_s *s = (struct max7310_s *) i2c;
|
|
213 |
MAX7310State *s = (MAX7310State *) i2c;
|
|
214 | 214 |
return s->gpio_in; |
215 | 215 |
} |
216 | 216 |
|
217 | 217 |
void max7310_gpio_out_set(i2c_slave *i2c, int line, qemu_irq handler) |
218 | 218 |
{ |
219 |
struct max7310_s *s = (struct max7310_s *) i2c;
|
|
219 |
MAX7310State *s = (MAX7310State *) i2c;
|
|
220 | 220 |
if (line >= ARRAY_SIZE(s->handler) || line < 0) |
221 | 221 |
hw_error("bad GPIO line"); |
222 | 222 |
|
Also available in: Unified diff