aboutsummaryrefslogtreecommitdiff
path: root/hw
diff options
context:
space:
mode:
Diffstat (limited to 'hw')
-rw-r--r--hw/i2c.h3
-rw-r--r--hw/lm832x.c31
-rw-r--r--hw/nseries.c5
3 files changed, 23 insertions, 16 deletions
diff --git a/hw/i2c.h b/hw/i2c.h
index 6d223ea4e3..7e672f0da0 100644
--- a/hw/i2c.h
+++ b/hw/i2c.h
@@ -101,7 +101,6 @@ void tmp105_reset(i2c_slave *i2c);
void tmp105_set(i2c_slave *i2c, int temp);
/* lm832x.c */
-struct i2c_slave *lm8323_init(i2c_bus *bus, qemu_irq nirq);
-void lm832x_key_event(struct i2c_slave *i2c, int key, int state);
+void lm832x_key_event(i2c_slave *i2c, int key, int state);
#endif
diff --git a/hw/lm832x.c b/hw/lm832x.c
index f3915f0d91..decde55da2 100644
--- a/hw/lm832x.c
+++ b/hw/lm832x.c
@@ -378,7 +378,7 @@ static void lm_kbd_write(LM823KbdState *s, int reg, int byte, uint8_t value)
static void lm_i2c_event(i2c_slave *i2c, enum i2c_event event)
{
- LM823KbdState *s = (LM823KbdState *) i2c;
+ LM823KbdState *s = FROM_I2C_SLAVE(LM823KbdState, i2c);
switch (event) {
case I2C_START_RECV:
@@ -394,7 +394,7 @@ static void lm_i2c_event(i2c_slave *i2c, enum i2c_event event)
static int lm_i2c_rx(i2c_slave *i2c)
{
- LM823KbdState *s = (LM823KbdState *) i2c;
+ LM823KbdState *s = FROM_I2C_SLAVE(LM823KbdState, i2c);
return lm_kbd_read(s, s->reg, s->i2c_cycle ++);
}
@@ -489,27 +489,20 @@ static int lm_kbd_load(QEMUFile *f, void *opaque, int version_id)
return 0;
}
-i2c_slave *lm8323_init(i2c_bus *bus, qemu_irq nirq)
+static void lm8323_init(i2c_slave *i2c)
{
- LM823KbdState *s;
+ LM823KbdState *s = FROM_I2C_SLAVE(LM823KbdState, i2c);
- s = (LM823KbdState *) i2c_slave_init(bus, 0, sizeof(LM823KbdState));
s->model = 0x8323;
s->pwm.tm[0] = qemu_new_timer(vm_clock, lm_kbd_pwm0_tick, s);
s->pwm.tm[1] = qemu_new_timer(vm_clock, lm_kbd_pwm1_tick, s);
s->pwm.tm[2] = qemu_new_timer(vm_clock, lm_kbd_pwm2_tick, s);
- s->nirq = nirq;
-
- s->i2c.event = lm_i2c_event;
- s->i2c.recv = lm_i2c_rx;
- s->i2c.send = lm_i2c_tx;
+ qdev_init_gpio_out(&i2c->qdev, &s->nirq, 1);
lm_kbd_reset(s);
qemu_register_reset((void *) lm_kbd_reset, s);
register_savevm("LM8323", -1, 0, lm_kbd_save, lm_kbd_load, s);
-
- return &s->i2c;
}
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)
s->status |= INT_KEYPAD;
lm_kbd_irq_update(s);
}
+
+static I2CSlaveInfo lm8323_info = {
+ .init = lm8323_init,
+ .event = lm_i2c_event,
+ .recv = lm_i2c_rx,
+ .send = lm_i2c_tx
+};
+
+static void lm832x_register_devices(void)
+{
+ i2c_register_slave("lm8323", sizeof(LM823KbdState), &lm8323_info);
+}
+
+device_init(lm832x_register_devices)
diff --git a/hw/nseries.c b/hw/nseries.c
index 63a1c336ea..bd904c7ddb 100644
--- a/hw/nseries.c
+++ b/hw/nseries.c
@@ -362,6 +362,7 @@ static int n810_keys[0x80] = {
static void n810_kbd_setup(struct n800_s *s)
{
qemu_irq kbd_irq = omap2_gpio_in_get(s->cpu->gpif, N810_KEYBOARD_GPIO)[0];
+ DeviceState *dev;
int i;
for (i = 0; i < 0x80; i ++)
@@ -374,8 +375,8 @@ static void n810_kbd_setup(struct n800_s *s)
/* Attach the LM8322 keyboard to the I2C bus,
* should happen in n8x0_i2c_setup and s->kbd be initialised here. */
- s->kbd = lm8323_init(s->i2c, kbd_irq);
- i2c_set_slave_address(s->kbd, N810_LM8323_ADDR);
+ dev = i2c_create_slave(s->i2c, "lm8323", N810_LM8323_ADDR);
+ qdev_connect_gpio_out(dev, 0, kbd_irq);
}
/* LCD MIPI DBI-C controller (URAL) */