Commit 2d9401aa58f33cfbd0a585306b69916ca18dedcf
1 parent
6c0bd6bd
LM832x qdev conversion
Signed-off-by: Paul Brook <paul@codesourcery.com>
Showing
3 changed files
with
23 additions
and
16 deletions
hw/i2c.h
| ... | ... | @@ -101,7 +101,6 @@ void tmp105_reset(i2c_slave *i2c); |
| 101 | 101 | void tmp105_set(i2c_slave *i2c, int temp); |
| 102 | 102 | |
| 103 | 103 | /* lm832x.c */ |
| 104 | -struct i2c_slave *lm8323_init(i2c_bus *bus, qemu_irq nirq); | |
| 105 | -void lm832x_key_event(struct i2c_slave *i2c, int key, int state); | |
| 104 | +void lm832x_key_event(i2c_slave *i2c, int key, int state); | |
| 106 | 105 | |
| 107 | 106 | #endif | ... | ... |
hw/lm832x.c
| ... | ... | @@ -378,7 +378,7 @@ static void lm_kbd_write(LM823KbdState *s, int reg, int byte, uint8_t value) |
| 378 | 378 | |
| 379 | 379 | static void lm_i2c_event(i2c_slave *i2c, enum i2c_event event) |
| 380 | 380 | { |
| 381 | - LM823KbdState *s = (LM823KbdState *) i2c; | |
| 381 | + LM823KbdState *s = FROM_I2C_SLAVE(LM823KbdState, i2c); | |
| 382 | 382 | |
| 383 | 383 | switch (event) { |
| 384 | 384 | case I2C_START_RECV: |
| ... | ... | @@ -394,7 +394,7 @@ static void lm_i2c_event(i2c_slave *i2c, enum i2c_event event) |
| 394 | 394 | |
| 395 | 395 | static int lm_i2c_rx(i2c_slave *i2c) |
| 396 | 396 | { |
| 397 | - LM823KbdState *s = (LM823KbdState *) i2c; | |
| 397 | + LM823KbdState *s = FROM_I2C_SLAVE(LM823KbdState, i2c); | |
| 398 | 398 | |
| 399 | 399 | return lm_kbd_read(s, s->reg, s->i2c_cycle ++); |
| 400 | 400 | } |
| ... | ... | @@ -489,27 +489,20 @@ static int lm_kbd_load(QEMUFile *f, void *opaque, int version_id) |
| 489 | 489 | return 0; |
| 490 | 490 | } |
| 491 | 491 | |
| 492 | -i2c_slave *lm8323_init(i2c_bus *bus, qemu_irq nirq) | |
| 492 | +static void lm8323_init(i2c_slave *i2c) | |
| 493 | 493 | { |
| 494 | - LM823KbdState *s; | |
| 494 | + LM823KbdState *s = FROM_I2C_SLAVE(LM823KbdState, i2c); | |
| 495 | 495 | |
| 496 | - s = (LM823KbdState *) i2c_slave_init(bus, 0, sizeof(LM823KbdState)); | |
| 497 | 496 | s->model = 0x8323; |
| 498 | 497 | s->pwm.tm[0] = qemu_new_timer(vm_clock, lm_kbd_pwm0_tick, s); |
| 499 | 498 | s->pwm.tm[1] = qemu_new_timer(vm_clock, lm_kbd_pwm1_tick, s); |
| 500 | 499 | s->pwm.tm[2] = qemu_new_timer(vm_clock, lm_kbd_pwm2_tick, s); |
| 501 | - s->nirq = nirq; | |
| 502 | - | |
| 503 | - s->i2c.event = lm_i2c_event; | |
| 504 | - s->i2c.recv = lm_i2c_rx; | |
| 505 | - s->i2c.send = lm_i2c_tx; | |
| 500 | + qdev_init_gpio_out(&i2c->qdev, &s->nirq, 1); | |
| 506 | 501 | |
| 507 | 502 | lm_kbd_reset(s); |
| 508 | 503 | |
| 509 | 504 | qemu_register_reset((void *) lm_kbd_reset, s); |
| 510 | 505 | register_savevm("LM8323", -1, 0, lm_kbd_save, lm_kbd_load, s); |
| 511 | - | |
| 512 | - return &s->i2c; | |
| 513 | 506 | } |
| 514 | 507 | |
| 515 | 508 | void lm832x_key_event(struct i2c_slave *i2c, int key, int state) |
| ... | ... | @@ -531,3 +524,17 @@ void lm832x_key_event(struct i2c_slave *i2c, int key, int state) |
| 531 | 524 | s->status |= INT_KEYPAD; |
| 532 | 525 | lm_kbd_irq_update(s); |
| 533 | 526 | } |
| 527 | + | |
| 528 | +static I2CSlaveInfo lm8323_info = { | |
| 529 | + .init = lm8323_init, | |
| 530 | + .event = lm_i2c_event, | |
| 531 | + .recv = lm_i2c_rx, | |
| 532 | + .send = lm_i2c_tx | |
| 533 | +}; | |
| 534 | + | |
| 535 | +static void lm832x_register_devices(void) | |
| 536 | +{ | |
| 537 | + i2c_register_slave("lm8323", sizeof(LM823KbdState), &lm8323_info); | |
| 538 | +} | |
| 539 | + | |
| 540 | +device_init(lm832x_register_devices) | ... | ... |
hw/nseries.c
| ... | ... | @@ -362,6 +362,7 @@ static int n810_keys[0x80] = { |
| 362 | 362 | static void n810_kbd_setup(struct n800_s *s) |
| 363 | 363 | { |
| 364 | 364 | qemu_irq kbd_irq = omap2_gpio_in_get(s->cpu->gpif, N810_KEYBOARD_GPIO)[0]; |
| 365 | + DeviceState *dev; | |
| 365 | 366 | int i; |
| 366 | 367 | |
| 367 | 368 | for (i = 0; i < 0x80; i ++) |
| ... | ... | @@ -374,8 +375,8 @@ static void n810_kbd_setup(struct n800_s *s) |
| 374 | 375 | |
| 375 | 376 | /* Attach the LM8322 keyboard to the I2C bus, |
| 376 | 377 | * should happen in n8x0_i2c_setup and s->kbd be initialised here. */ |
| 377 | - s->kbd = lm8323_init(s->i2c, kbd_irq); | |
| 378 | - i2c_set_slave_address(s->kbd, N810_LM8323_ADDR); | |
| 378 | + dev = i2c_create_slave(s->i2c, "lm8323", N810_LM8323_ADDR); | |
| 379 | + qdev_connect_gpio_out(dev, 0, kbd_irq); | |
| 379 | 380 | } |
| 380 | 381 | |
| 381 | 382 | /* LCD MIPI DBI-C controller (URAL) */ | ... | ... |