Commit cdbe40ca836624a474bf8378b78a715ded36178c
1 parent
697454eb
WM8750 qdev coversion
Signed-off-by: Paul Brook <paul@codesourcery.com>
Showing
4 changed files
with
24 additions
and
21 deletions
hw/i2c.h
@@ -80,9 +80,7 @@ qemu_irq *max7310_gpio_in_get(i2c_slave *i2c); | @@ -80,9 +80,7 @@ qemu_irq *max7310_gpio_in_get(i2c_slave *i2c); | ||
80 | void max7310_gpio_out_set(i2c_slave *i2c, int line, qemu_irq handler); | 80 | void max7310_gpio_out_set(i2c_slave *i2c, int line, qemu_irq handler); |
81 | 81 | ||
82 | /* wm8750.c */ | 82 | /* wm8750.c */ |
83 | -i2c_slave *wm8750_init(i2c_bus *bus); | ||
84 | -void wm8750_reset(i2c_slave *i2c); | ||
85 | -void wm8750_data_req_set(i2c_slave *i2c, | 83 | +void wm8750_data_req_set(DeviceState *dev, |
86 | void (*data_req)(void *, int, int), void *opaque); | 84 | void (*data_req)(void *, int, int), void *opaque); |
87 | void wm8750_dac_dat(void *opaque, uint32_t sample); | 85 | void wm8750_dac_dat(void *opaque, uint32_t sample); |
88 | uint32_t wm8750_adc_dat(void *opaque); | 86 | uint32_t wm8750_adc_dat(void *opaque); |
hw/musicpal.c
@@ -235,7 +235,7 @@ typedef struct musicpal_audio_state { | @@ -235,7 +235,7 @@ typedef struct musicpal_audio_state { | ||
235 | unsigned int play_pos; | 235 | unsigned int play_pos; |
236 | unsigned int last_free; | 236 | unsigned int last_free; |
237 | uint32_t clock_div; | 237 | uint32_t clock_div; |
238 | - i2c_slave *wm; | 238 | + DeviceState *wm; |
239 | } musicpal_audio_state; | 239 | } musicpal_audio_state; |
240 | 240 | ||
241 | static void audio_callback(void *opaque, int free_out, int free_in) | 241 | 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) | @@ -434,10 +434,7 @@ static i2c_interface *musicpal_audio_init(qemu_irq irq) | ||
434 | i2c->bus = i2c_init_bus(); | 434 | i2c->bus = i2c_init_bus(); |
435 | i2c->current_addr = -1; | 435 | i2c->current_addr = -1; |
436 | 436 | ||
437 | - s->wm = wm8750_init(i2c->bus); | ||
438 | - if (!s->wm) | ||
439 | - return NULL; | ||
440 | - i2c_set_slave_address(s->wm, MP_WM_ADDR); | 437 | + s->wm = i2c_create_slave(i2c->bus, "wm8750", MP_WM_ADDR); |
441 | wm8750_data_req_set(s->wm, audio_callback, s); | 438 | wm8750_data_req_set(s->wm, audio_callback, s); |
442 | 439 | ||
443 | iomemtype = cpu_register_io_memory(0, musicpal_audio_readfn, | 440 | iomemtype = cpu_register_io_memory(0, musicpal_audio_readfn, |
hw/spitz.c
@@ -740,10 +740,10 @@ static void spitz_i2c_setup(PXA2xxState *cpu) | @@ -740,10 +740,10 @@ static void spitz_i2c_setup(PXA2xxState *cpu) | ||
740 | i2c_bus *bus = pxa2xx_i2c_bus(cpu->i2c[0]); | 740 | i2c_bus *bus = pxa2xx_i2c_bus(cpu->i2c[0]); |
741 | 741 | ||
742 | #ifdef HAS_AUDIO | 742 | #ifdef HAS_AUDIO |
743 | - i2c_slave *wm; | 743 | + DeviceState *wm; |
744 | 744 | ||
745 | /* Attach a WM8750 to the bus */ | 745 | /* Attach a WM8750 to the bus */ |
746 | - wm = wm8750_init(bus); | 746 | + wm = i2c_create_slave(bus, "wm8750", 0); |
747 | 747 | ||
748 | spitz_wm8750_addr(wm, 0, 0); | 748 | spitz_wm8750_addr(wm, 0, 0); |
749 | pxa2xx_gpio_out_set(cpu->gpio, SPITZ_GPIO_WM, | 749 | pxa2xx_gpio_out_set(cpu->gpio, SPITZ_GPIO_WM, |
hw/wm8750.c
@@ -259,7 +259,7 @@ static void wm8750_clk_update(WM8750State *s, int ext) | @@ -259,7 +259,7 @@ static void wm8750_clk_update(WM8750State *s, int ext) | ||
259 | } | 259 | } |
260 | } | 260 | } |
261 | 261 | ||
262 | -void wm8750_reset(i2c_slave *i2c) | 262 | +static void wm8750_reset(i2c_slave *i2c) |
263 | { | 263 | { |
264 | WM8750State *s = (WM8750State *) i2c; | 264 | WM8750State *s = (WM8750State *) i2c; |
265 | s->rate = &wm_rate_table[0]; | 265 | s->rate = &wm_rate_table[0]; |
@@ -645,20 +645,14 @@ static int wm8750_load(QEMUFile *f, void *opaque, int version_id) | @@ -645,20 +645,14 @@ static int wm8750_load(QEMUFile *f, void *opaque, int version_id) | ||
645 | return 0; | 645 | return 0; |
646 | } | 646 | } |
647 | 647 | ||
648 | -i2c_slave *wm8750_init(i2c_bus *bus) | 648 | +static void wm8750_init(i2c_slave *i2c) |
649 | { | 649 | { |
650 | - WM8750State *s = (WM8750State *) | ||
651 | - i2c_slave_init(bus, 0, sizeof(WM8750State)); | ||
652 | - s->i2c.event = wm8750_event; | ||
653 | - s->i2c.recv = wm8750_rx; | ||
654 | - s->i2c.send = wm8750_tx; | 650 | + WM8750State *s = FROM_I2C_SLAVE(WM8750State, i2c); |
655 | 651 | ||
656 | AUD_register_card(CODEC, &s->card); | 652 | AUD_register_card(CODEC, &s->card); |
657 | wm8750_reset(&s->i2c); | 653 | wm8750_reset(&s->i2c); |
658 | 654 | ||
659 | register_savevm(CODEC, -1, 0, wm8750_save, wm8750_load, s); | 655 | register_savevm(CODEC, -1, 0, wm8750_save, wm8750_load, s); |
660 | - | ||
661 | - return &s->i2c; | ||
662 | } | 656 | } |
663 | 657 | ||
664 | #if 0 | 658 | #if 0 |
@@ -671,10 +665,10 @@ static void wm8750_fini(i2c_slave *i2c) | @@ -671,10 +665,10 @@ static void wm8750_fini(i2c_slave *i2c) | ||
671 | } | 665 | } |
672 | #endif | 666 | #endif |
673 | 667 | ||
674 | -void wm8750_data_req_set(i2c_slave *i2c, | 668 | +void wm8750_data_req_set(DeviceState *dev, |
675 | void (*data_req)(void *, int, int), void *opaque) | 669 | void (*data_req)(void *, int, int), void *opaque) |
676 | { | 670 | { |
677 | - WM8750State *s = (WM8750State *) i2c; | 671 | + WM8750State *s = FROM_I2C_SLAVE(WM8750State, I2C_SLAVE_FROM_QDEV(dev)); |
678 | s->data_req = data_req; | 672 | s->data_req = data_req; |
679 | s->opaque = opaque; | 673 | s->opaque = opaque; |
680 | } | 674 | } |
@@ -730,3 +724,17 @@ void wm8750_set_bclk_in(void *opaque, int new_hz) | @@ -730,3 +724,17 @@ void wm8750_set_bclk_in(void *opaque, int new_hz) | ||
730 | s->ext_dac_hz = new_hz; | 724 | s->ext_dac_hz = new_hz; |
731 | wm8750_clk_update(s, 1); | 725 | wm8750_clk_update(s, 1); |
732 | } | 726 | } |
727 | + | ||
728 | +static I2CSlaveInfo wm8750_info = { | ||
729 | + .init = wm8750_init, | ||
730 | + .event = wm8750_event, | ||
731 | + .recv = wm8750_rx, | ||
732 | + .send = wm8750_tx | ||
733 | +}; | ||
734 | + | ||
735 | +static void wm8750_register_devices(void) | ||
736 | +{ | ||
737 | + i2c_register_slave("wm8750", sizeof(WM8750State), &wm8750_info); | ||
738 | +} | ||
739 | + | ||
740 | +device_init(wm8750_register_devices) |