diff options
Diffstat (limited to 'hw')
-rw-r--r-- | hw/i2c.h | 5 | ||||
-rw-r--r-- | hw/nseries.c | 6 | ||||
-rw-r--r-- | hw/twl92230.c | 65 |
3 files changed, 30 insertions, 46 deletions
@@ -88,11 +88,6 @@ void *wm8750_dac_buffer(void *opaque, int samples); void wm8750_dac_commit(void *opaque); void wm8750_set_bclk_in(void *opaque, int new_hz); -/* twl92230.c */ -i2c_slave *twl92230_init(i2c_bus *bus, qemu_irq irq); -qemu_irq *twl92230_gpio_in_get(i2c_slave *i2c); -void twl92230_gpio_out_set(i2c_slave *i2c, int line, qemu_irq handler); - /* tmp105.c */ void tmp105_set(i2c_slave *i2c, int temp); diff --git a/hw/nseries.c b/hw/nseries.c index b7a1c6be56..daf1b8ba92 100644 --- a/hw/nseries.c +++ b/hw/nseries.c @@ -186,10 +186,8 @@ static void n8x0_i2c_setup(struct n800_s *s) s->i2c = omap_i2c_bus(s->cpu->i2c[0]); /* Attach a menelaus PM chip */ - i2c_set_slave_address( - twl92230_init(s->i2c, - s->cpu->irq[0][OMAP_INT_24XX_SYS_NIRQ]), - N8X0_MENELAUS_ADDR); + dev = i2c_create_slave(s->i2c, "twl92230", N8X0_MENELAUS_ADDR); + qdev_connect_gpio_out(dev, 3, s->cpu->irq[0][OMAP_INT_24XX_SYS_NIRQ]); /* Attach a TMP105 PM chip (A0 wired to ground) */ dev = i2c_create_slave(s->i2c, "tmp105", N8X0_TMP105_ADDR); diff --git a/hw/twl92230.c b/hw/twl92230.c index 35e16af01b..3a226923b1 100644 --- a/hw/twl92230.c +++ b/hw/twl92230.c @@ -30,7 +30,6 @@ typedef struct { i2c_slave i2c; - qemu_irq irq; int firstbyte; uint8_t reg; @@ -62,7 +61,7 @@ typedef struct { int alm_sec; int next_comp; } rtc; - qemu_irq handler[3]; + qemu_irq out[4]; qemu_irq *in; int pwrbtn_state; qemu_irq pwrbtn; @@ -70,7 +69,7 @@ typedef struct { static inline void menelaus_update(MenelausState *s) { - qemu_set_irq(s->irq, s->status & ~s->mask); + qemu_set_irq(s->out[3], s->status & ~s->mask); } static inline void menelaus_rtc_start(MenelausState *s) @@ -540,18 +539,20 @@ static void menelaus_write(void *opaque, uint8_t addr, uint8_t value) break; case MENELAUS_GPIO_CTRL: - for (line = 0; line < 3; line ++) - if (((s->dir ^ value) >> line) & 1) - if (s->handler[line]) - qemu_set_irq(s->handler[line], - ((s->outputs & ~s->dir) >> line) & 1); + for (line = 0; line < 3; line ++) { + if (((s->dir ^ value) >> line) & 1) { + qemu_set_irq(s->out[line], + ((s->outputs & ~s->dir) >> line) & 1); + } + } s->dir = value & 0x67; break; case MENELAUS_GPIO_OUT: - for (line = 0; line < 3; line ++) - if ((((s->outputs ^ value) & ~s->dir) >> line) & 1) - if (s->handler[line]) - qemu_set_irq(s->handler[line], (s->outputs >> line) & 1); + for (line = 0; line < 3; line ++) { + if ((((s->outputs ^ value) & ~s->dir) >> line) & 1) { + qemu_set_irq(s->out[line], (s->outputs >> line) & 1); + } + } s->outputs = value & 0x07; break; @@ -875,41 +876,31 @@ static int menelaus_load(QEMUFile *f, void *opaque, int version_id) return 0; } -i2c_slave *twl92230_init(i2c_bus *bus, qemu_irq irq) +static void twl92230_init(i2c_slave *i2c) { - MenelausState *s = (MenelausState *) - i2c_slave_init(bus, 0, sizeof(MenelausState)); - - s->i2c.event = menelaus_event; - s->i2c.recv = menelaus_rx; - s->i2c.send = menelaus_tx; + MenelausState *s = FROM_I2C_SLAVE(MenelausState, i2c); - s->irq = irq; s->rtc.hz_tm = qemu_new_timer(rt_clock, menelaus_rtc_hz, s); - s->in = qemu_allocate_irqs(menelaus_gpio_set, s, 3); + /* Three output pins plus one interrupt pin. */ + qdev_init_gpio_out(&i2c->qdev, s->out, 4); + qdev_init_gpio_in(&i2c->qdev, menelaus_gpio_set, 3); s->pwrbtn = qemu_allocate_irqs(menelaus_pwrbtn_set, s, 1)[0]; menelaus_reset(&s->i2c); register_savevm("menelaus", -1, 0, menelaus_save, menelaus_load, s); - - return &s->i2c; } -qemu_irq *twl92230_gpio_in_get(i2c_slave *i2c) -{ - MenelausState *s = (MenelausState *) i2c; - - return s->in; -} +static I2CSlaveInfo twl92230_info = { + .init = twl92230_init, + .event = menelaus_event, + .recv = menelaus_rx, + .send = menelaus_tx +}; -void twl92230_gpio_out_set(i2c_slave *i2c, int line, qemu_irq handler) +static void twl92230_register_devices(void) { - MenelausState *s = (MenelausState *) i2c; - - if (line >= 3 || line < 0) { - fprintf(stderr, "%s: No GPO line %i\n", __FUNCTION__, line); - exit(-1); - } - s->handler[line] = handler; + i2c_register_slave("twl92230", sizeof(MenelausState), &twl92230_info); } + +device_init(twl92230_register_devices) |