Commit d335681177137c4bf455aabc95a0bd9277085e58
1 parent
cdbe40ca
TWL92230 qdev conversion
Signed-off-by: Paul Brook <paul@codesourcery.com>
Showing
3 changed files
with
30 additions
and
46 deletions
hw/i2c.h
| ... | ... | @@ -88,11 +88,6 @@ void *wm8750_dac_buffer(void *opaque, int samples); |
| 88 | 88 | void wm8750_dac_commit(void *opaque); |
| 89 | 89 | void wm8750_set_bclk_in(void *opaque, int new_hz); |
| 90 | 90 | |
| 91 | -/* twl92230.c */ | |
| 92 | -i2c_slave *twl92230_init(i2c_bus *bus, qemu_irq irq); | |
| 93 | -qemu_irq *twl92230_gpio_in_get(i2c_slave *i2c); | |
| 94 | -void twl92230_gpio_out_set(i2c_slave *i2c, int line, qemu_irq handler); | |
| 95 | - | |
| 96 | 91 | /* tmp105.c */ |
| 97 | 92 | void tmp105_set(i2c_slave *i2c, int temp); |
| 98 | 93 | ... | ... |
hw/nseries.c
| ... | ... | @@ -186,10 +186,8 @@ static void n8x0_i2c_setup(struct n800_s *s) |
| 186 | 186 | s->i2c = omap_i2c_bus(s->cpu->i2c[0]); |
| 187 | 187 | |
| 188 | 188 | /* Attach a menelaus PM chip */ |
| 189 | - i2c_set_slave_address( | |
| 190 | - twl92230_init(s->i2c, | |
| 191 | - s->cpu->irq[0][OMAP_INT_24XX_SYS_NIRQ]), | |
| 192 | - N8X0_MENELAUS_ADDR); | |
| 189 | + dev = i2c_create_slave(s->i2c, "twl92230", N8X0_MENELAUS_ADDR); | |
| 190 | + qdev_connect_gpio_out(dev, 3, s->cpu->irq[0][OMAP_INT_24XX_SYS_NIRQ]); | |
| 193 | 191 | |
| 194 | 192 | /* Attach a TMP105 PM chip (A0 wired to ground) */ |
| 195 | 193 | dev = i2c_create_slave(s->i2c, "tmp105", N8X0_TMP105_ADDR); | ... | ... |
hw/twl92230.c
| ... | ... | @@ -30,7 +30,6 @@ |
| 30 | 30 | |
| 31 | 31 | typedef struct { |
| 32 | 32 | i2c_slave i2c; |
| 33 | - qemu_irq irq; | |
| 34 | 33 | |
| 35 | 34 | int firstbyte; |
| 36 | 35 | uint8_t reg; |
| ... | ... | @@ -62,7 +61,7 @@ typedef struct { |
| 62 | 61 | int alm_sec; |
| 63 | 62 | int next_comp; |
| 64 | 63 | } rtc; |
| 65 | - qemu_irq handler[3]; | |
| 64 | + qemu_irq out[4]; | |
| 66 | 65 | qemu_irq *in; |
| 67 | 66 | int pwrbtn_state; |
| 68 | 67 | qemu_irq pwrbtn; |
| ... | ... | @@ -70,7 +69,7 @@ typedef struct { |
| 70 | 69 | |
| 71 | 70 | static inline void menelaus_update(MenelausState *s) |
| 72 | 71 | { |
| 73 | - qemu_set_irq(s->irq, s->status & ~s->mask); | |
| 72 | + qemu_set_irq(s->out[3], s->status & ~s->mask); | |
| 74 | 73 | } |
| 75 | 74 | |
| 76 | 75 | static inline void menelaus_rtc_start(MenelausState *s) |
| ... | ... | @@ -540,18 +539,20 @@ static void menelaus_write(void *opaque, uint8_t addr, uint8_t value) |
| 540 | 539 | break; |
| 541 | 540 | |
| 542 | 541 | case MENELAUS_GPIO_CTRL: |
| 543 | - for (line = 0; line < 3; line ++) | |
| 544 | - if (((s->dir ^ value) >> line) & 1) | |
| 545 | - if (s->handler[line]) | |
| 546 | - qemu_set_irq(s->handler[line], | |
| 547 | - ((s->outputs & ~s->dir) >> line) & 1); | |
| 542 | + for (line = 0; line < 3; line ++) { | |
| 543 | + if (((s->dir ^ value) >> line) & 1) { | |
| 544 | + qemu_set_irq(s->out[line], | |
| 545 | + ((s->outputs & ~s->dir) >> line) & 1); | |
| 546 | + } | |
| 547 | + } | |
| 548 | 548 | s->dir = value & 0x67; |
| 549 | 549 | break; |
| 550 | 550 | case MENELAUS_GPIO_OUT: |
| 551 | - for (line = 0; line < 3; line ++) | |
| 552 | - if ((((s->outputs ^ value) & ~s->dir) >> line) & 1) | |
| 553 | - if (s->handler[line]) | |
| 554 | - qemu_set_irq(s->handler[line], (s->outputs >> line) & 1); | |
| 551 | + for (line = 0; line < 3; line ++) { | |
| 552 | + if ((((s->outputs ^ value) & ~s->dir) >> line) & 1) { | |
| 553 | + qemu_set_irq(s->out[line], (s->outputs >> line) & 1); | |
| 554 | + } | |
| 555 | + } | |
| 555 | 556 | s->outputs = value & 0x07; |
| 556 | 557 | break; |
| 557 | 558 | |
| ... | ... | @@ -875,41 +876,31 @@ static int menelaus_load(QEMUFile *f, void *opaque, int version_id) |
| 875 | 876 | return 0; |
| 876 | 877 | } |
| 877 | 878 | |
| 878 | -i2c_slave *twl92230_init(i2c_bus *bus, qemu_irq irq) | |
| 879 | +static void twl92230_init(i2c_slave *i2c) | |
| 879 | 880 | { |
| 880 | - MenelausState *s = (MenelausState *) | |
| 881 | - i2c_slave_init(bus, 0, sizeof(MenelausState)); | |
| 882 | - | |
| 883 | - s->i2c.event = menelaus_event; | |
| 884 | - s->i2c.recv = menelaus_rx; | |
| 885 | - s->i2c.send = menelaus_tx; | |
| 881 | + MenelausState *s = FROM_I2C_SLAVE(MenelausState, i2c); | |
| 886 | 882 | |
| 887 | - s->irq = irq; | |
| 888 | 883 | s->rtc.hz_tm = qemu_new_timer(rt_clock, menelaus_rtc_hz, s); |
| 889 | - s->in = qemu_allocate_irqs(menelaus_gpio_set, s, 3); | |
| 884 | + /* Three output pins plus one interrupt pin. */ | |
| 885 | + qdev_init_gpio_out(&i2c->qdev, s->out, 4); | |
| 886 | + qdev_init_gpio_in(&i2c->qdev, menelaus_gpio_set, 3); | |
| 890 | 887 | s->pwrbtn = qemu_allocate_irqs(menelaus_pwrbtn_set, s, 1)[0]; |
| 891 | 888 | |
| 892 | 889 | menelaus_reset(&s->i2c); |
| 893 | 890 | |
| 894 | 891 | register_savevm("menelaus", -1, 0, menelaus_save, menelaus_load, s); |
| 895 | - | |
| 896 | - return &s->i2c; | |
| 897 | 892 | } |
| 898 | 893 | |
| 899 | -qemu_irq *twl92230_gpio_in_get(i2c_slave *i2c) | |
| 900 | -{ | |
| 901 | - MenelausState *s = (MenelausState *) i2c; | |
| 902 | - | |
| 903 | - return s->in; | |
| 904 | -} | |
| 894 | +static I2CSlaveInfo twl92230_info = { | |
| 895 | + .init = twl92230_init, | |
| 896 | + .event = menelaus_event, | |
| 897 | + .recv = menelaus_rx, | |
| 898 | + .send = menelaus_tx | |
| 899 | +}; | |
| 905 | 900 | |
| 906 | -void twl92230_gpio_out_set(i2c_slave *i2c, int line, qemu_irq handler) | |
| 901 | +static void twl92230_register_devices(void) | |
| 907 | 902 | { |
| 908 | - MenelausState *s = (MenelausState *) i2c; | |
| 909 | - | |
| 910 | - if (line >= 3 || line < 0) { | |
| 911 | - fprintf(stderr, "%s: No GPO line %i\n", __FUNCTION__, line); | |
| 912 | - exit(-1); | |
| 913 | - } | |
| 914 | - s->handler[line] = handler; | |
| 903 | + i2c_register_slave("twl92230", sizeof(MenelausState), &twl92230_info); | |
| 915 | 904 | } |
| 905 | + | |
| 906 | +device_init(twl92230_register_devices) | ... | ... |