aboutsummaryrefslogtreecommitdiff
path: root/hw
diff options
context:
space:
mode:
authorPaul Brook <paul@codesourcery.com>2009-05-14 22:35:08 +0100
committerPaul Brook <paul@codesourcery.com>2009-05-14 22:35:08 +0100
commitcdbe40ca836624a474bf8378b78a715ded36178c (patch)
tree25f499586b74a30a975b331f1f038a3d1d55bb80 /hw
parent697454eb8e2335c21e07b8cd0a7468d1c53bed08 (diff)
WM8750 qdev coversion
Signed-off-by: Paul Brook <paul@codesourcery.com>
Diffstat (limited to 'hw')
-rw-r--r--hw/i2c.h4
-rw-r--r--hw/musicpal.c7
-rw-r--r--hw/spitz.c4
-rw-r--r--hw/wm8750.c30
4 files changed, 24 insertions, 21 deletions
diff --git a/hw/i2c.h b/hw/i2c.h
index 723dbdc1e3..99e0dbcd5f 100644
--- a/hw/i2c.h
+++ b/hw/i2c.h
@@ -80,9 +80,7 @@ qemu_irq *max7310_gpio_in_get(i2c_slave *i2c);
void max7310_gpio_out_set(i2c_slave *i2c, int line, qemu_irq handler);
/* wm8750.c */
-i2c_slave *wm8750_init(i2c_bus *bus);
-void wm8750_reset(i2c_slave *i2c);
-void wm8750_data_req_set(i2c_slave *i2c,
+void wm8750_data_req_set(DeviceState *dev,
void (*data_req)(void *, int, int), void *opaque);
void wm8750_dac_dat(void *opaque, uint32_t sample);
uint32_t wm8750_adc_dat(void *opaque);
diff --git a/hw/musicpal.c b/hw/musicpal.c
index 538fb8ecdc..87dda0ce5c 100644
--- a/hw/musicpal.c
+++ b/hw/musicpal.c
@@ -235,7 +235,7 @@ typedef struct musicpal_audio_state {
unsigned int play_pos;
unsigned int last_free;
uint32_t clock_div;
- i2c_slave *wm;
+ DeviceState *wm;
} musicpal_audio_state;
static void audio_callback(void *opaque, int free_out, int free_in)
@@ -434,10 +434,7 @@ static i2c_interface *musicpal_audio_init(qemu_irq irq)
i2c->bus = i2c_init_bus();
i2c->current_addr = -1;
- s->wm = wm8750_init(i2c->bus);
- if (!s->wm)
- return NULL;
- i2c_set_slave_address(s->wm, MP_WM_ADDR);
+ s->wm = i2c_create_slave(i2c->bus, "wm8750", MP_WM_ADDR);
wm8750_data_req_set(s->wm, audio_callback, s);
iomemtype = cpu_register_io_memory(0, musicpal_audio_readfn,
diff --git a/hw/spitz.c b/hw/spitz.c
index 943302b08d..f59f39c1c6 100644
--- a/hw/spitz.c
+++ b/hw/spitz.c
@@ -740,10 +740,10 @@ static void spitz_i2c_setup(PXA2xxState *cpu)
i2c_bus *bus = pxa2xx_i2c_bus(cpu->i2c[0]);
#ifdef HAS_AUDIO
- i2c_slave *wm;
+ DeviceState *wm;
/* Attach a WM8750 to the bus */
- wm = wm8750_init(bus);
+ wm = i2c_create_slave(bus, "wm8750", 0);
spitz_wm8750_addr(wm, 0, 0);
pxa2xx_gpio_out_set(cpu->gpio, SPITZ_GPIO_WM,
diff --git a/hw/wm8750.c b/hw/wm8750.c
index bb5106dca5..9f5bd46de4 100644
--- a/hw/wm8750.c
+++ b/hw/wm8750.c
@@ -259,7 +259,7 @@ static void wm8750_clk_update(WM8750State *s, int ext)
}
}
-void wm8750_reset(i2c_slave *i2c)
+static void wm8750_reset(i2c_slave *i2c)
{
WM8750State *s = (WM8750State *) i2c;
s->rate = &wm_rate_table[0];
@@ -645,20 +645,14 @@ static int wm8750_load(QEMUFile *f, void *opaque, int version_id)
return 0;
}
-i2c_slave *wm8750_init(i2c_bus *bus)
+static void wm8750_init(i2c_slave *i2c)
{
- WM8750State *s = (WM8750State *)
- i2c_slave_init(bus, 0, sizeof(WM8750State));
- s->i2c.event = wm8750_event;
- s->i2c.recv = wm8750_rx;
- s->i2c.send = wm8750_tx;
+ WM8750State *s = FROM_I2C_SLAVE(WM8750State, i2c);
AUD_register_card(CODEC, &s->card);
wm8750_reset(&s->i2c);
register_savevm(CODEC, -1, 0, wm8750_save, wm8750_load, s);
-
- return &s->i2c;
}
#if 0
@@ -671,10 +665,10 @@ static void wm8750_fini(i2c_slave *i2c)
}
#endif
-void wm8750_data_req_set(i2c_slave *i2c,
+void wm8750_data_req_set(DeviceState *dev,
void (*data_req)(void *, int, int), void *opaque)
{
- WM8750State *s = (WM8750State *) i2c;
+ WM8750State *s = FROM_I2C_SLAVE(WM8750State, I2C_SLAVE_FROM_QDEV(dev));
s->data_req = data_req;
s->opaque = opaque;
}
@@ -730,3 +724,17 @@ void wm8750_set_bclk_in(void *opaque, int new_hz)
s->ext_dac_hz = new_hz;
wm8750_clk_update(s, 1);
}
+
+static I2CSlaveInfo wm8750_info = {
+ .init = wm8750_init,
+ .event = wm8750_event,
+ .recv = wm8750_rx,
+ .send = wm8750_tx
+};
+
+static void wm8750_register_devices(void)
+{
+ i2c_register_slave("wm8750", sizeof(WM8750State), &wm8750_info);
+}
+
+device_init(wm8750_register_devices)