Push AUD_init down to devices
Now we can safely call AUD_init multiple times we can push it down to
individual audio devices, rather than having to pass it from the board
init.
Signed-off-by: Paul Brook <paul@codesourcery.com>
diff --git a/hw/ac97.c b/hw/ac97.c
index d9ef141..f2ae4b3 100644
--- a/hw/ac97.c
+++ b/hw/ac97.c
@@ -1308,8 +1308,9 @@
mixer_reset (s);
}
-int ac97_init (PCIBus *bus, AudioState *audio)
+int ac97_init (PCIBus *bus)
{
+ AudioState *audio = AUD_init();
PCIAC97LinkState *d;
AC97LinkState *s;
uint8_t *c;
@@ -1319,11 +1320,6 @@
return -1;
}
- if (!audio) {
- AUD_log ("ac97", "No audio state\n");
- return -1;
- }
-
d = (PCIAC97LinkState *) pci_register_device (bus, "AC97",
sizeof (PCIAC97LinkState),
-1, NULL, NULL);
diff --git a/hw/adlib.c b/hw/adlib.c
index 9f8f6f2..076c1a0 100644
--- a/hw/adlib.c
+++ b/hw/adlib.c
@@ -277,16 +277,12 @@
AUD_remove_card (&s->card);
}
-int Adlib_init (AudioState *audio, qemu_irq *pic)
+int Adlib_init (qemu_irq *pic)
{
+ AudioState *audio = AUD_init();
AdlibState *s = &glob_adlib;
struct audsettings as;
- if (!audio) {
- dolog ("No audio state\n");
- return -1;
- }
-
#ifdef HAS_YMF262
if (YMF262Init (1, 14318180, conf.freq)) {
dolog ("YMF262Init %d failed\n", conf.freq);
diff --git a/hw/audiodev.h b/hw/audiodev.h
index 5f4a211..39a729b 100644
--- a/hw/audiodev.h
+++ b/hw/audiodev.h
@@ -1,17 +1,17 @@
/* es1370.c */
-int es1370_init (PCIBus *bus, AudioState *s);
+int es1370_init(PCIBus *bus);
/* sb16.c */
-int SB16_init (AudioState *s, qemu_irq *pic);
+int SB16_init(qemu_irq *pic);
/* adlib.c */
-int Adlib_init (AudioState *s, qemu_irq *pic);
+int Adlib_init(qemu_irq *pic);
/* gus.c */
-int GUS_init (AudioState *s, qemu_irq *pic);
+int GUS_init(qemu_irq *pic);
/* ac97.c */
-int ac97_init (PCIBus *buf, AudioState *s);
+int ac97_init(PCIBus *buf);
/* cs4231a.c */
-int cs4231a_init (AudioState *s, qemu_irq *pic);
+int cs4231a_init(qemu_irq *pic);
diff --git a/hw/cs4231a.c b/hw/cs4231a.c
index 25ad409..4212ed1 100644
--- a/hw/cs4231a.c
+++ b/hw/cs4231a.c
@@ -636,16 +636,12 @@
return 0;
}
-int cs4231a_init (AudioState *audio, qemu_irq *pic)
+int cs4231a_init (qemu_irq *pic)
{
+ AudioState *audio = AUD_init();
int i;
CSState *s;
- if (!audio) {
- lerr ("No audio state\n");
- return -1;
- }
-
s = qemu_mallocz (sizeof (*s));
s->pic = pic;
diff --git a/hw/devices.h b/hw/devices.h
index 4d4a489..7bf3063 100644
--- a/hw/devices.h
+++ b/hw/devices.h
@@ -17,9 +17,8 @@
ADS7846State *ads7846_init(qemu_irq penirq);
/* tsc210x.c */
-uWireSlave *tsc2102_init(qemu_irq pint, AudioState *audio);
-uWireSlave *tsc2301_init(qemu_irq penirq, qemu_irq kbirq,
- qemu_irq dav, AudioState *audio);
+uWireSlave *tsc2102_init(qemu_irq pint);
+uWireSlave *tsc2301_init(qemu_irq penirq, qemu_irq kbirq, qemu_irq dav);
I2SCodec *tsc210x_codec(uWireSlave *chip);
uint32_t tsc210x_txrx(void *opaque, uint32_t value, int len);
void tsc210x_set_transform(uWireSlave *chip,
diff --git a/hw/es1370.c b/hw/es1370.c
index 50f5a55..99ee208 100644
--- a/hw/es1370.c
+++ b/hw/es1370.c
@@ -1005,8 +1005,9 @@
es1370_reset (s);
}
-int es1370_init (PCIBus *bus, AudioState *audio)
+int es1370_init (PCIBus *bus)
{
+ AudioState *audio = AUD_init();
PCIES1370State *d;
ES1370State *s;
uint8_t *c;
@@ -1016,11 +1017,6 @@
return -1;
}
- if (!audio) {
- dolog ("No audio state\n");
- return -1;
- }
-
d = (PCIES1370State *) pci_register_device (bus, "ES1370",
sizeof (PCIES1370State),
-1, NULL, NULL);
diff --git a/hw/gus.c b/hw/gus.c
index 070aa99..44f3e25 100644
--- a/hw/gus.c
+++ b/hw/gus.c
@@ -250,16 +250,12 @@
return 0;
}
-int GUS_init (AudioState *audio, qemu_irq *pic)
+int GUS_init (qemu_irq *pic)
{
+ AudioState *audio = AUD_init();
GUSState *s;
struct audsettings as;
- if (!audio) {
- dolog ("No audio state\n");
- return -1;
- }
-
s = qemu_mallocz (sizeof (*s));
AUD_register_card (audio, "gus", &s->card);
diff --git a/hw/i2c.h b/hw/i2c.h
index fea2ee1..870a084 100644
--- a/hw/i2c.h
+++ b/hw/i2c.h
@@ -60,7 +60,7 @@
void max7310_gpio_out_set(i2c_slave *i2c, int line, qemu_irq handler);
/* wm8750.c */
-i2c_slave *wm8750_init(i2c_bus *bus, AudioState *audio);
+i2c_slave *wm8750_init(i2c_bus *bus);
void wm8750_reset(i2c_slave *i2c);
void wm8750_data_req_set(i2c_slave *i2c,
void (*data_req)(void *, int, int), void *opaque);
diff --git a/hw/mips_jazz.c b/hw/mips_jazz.c
index 3734aa9..5ea4bba 100644
--- a/hw/mips_jazz.c
+++ b/hw/mips_jazz.c
@@ -104,13 +104,10 @@
}
if (audio_enabled) {
- AudioState *s;
-
- s = AUD_init();
for (c = soundhw; c->name; ++c) {
if (c->enabled) {
if (c->isa) {
- c->init.init_isa(s, pic);
+ c->init.init_isa(pic);
}
}
}
diff --git a/hw/mips_malta.c b/hw/mips_malta.c
index 015c16b..083e732 100644
--- a/hw/mips_malta.c
+++ b/hw/mips_malta.c
@@ -469,12 +469,9 @@
}
if (audio_enabled) {
- AudioState *s;
-
- s = AUD_init ();
for (c = soundhw; c->name; ++c) {
if (c->enabled) {
- c->init.init_pci (pci_bus, s);
+ c->init.init_pci(pci_bus);
}
}
}
diff --git a/hw/musicpal.c b/hw/musicpal.c
index 0c47e5d..b1cece4 100644
--- a/hw/musicpal.c
+++ b/hw/musicpal.c
@@ -422,13 +422,10 @@
static i2c_interface *musicpal_audio_init(qemu_irq irq)
{
- AudioState *audio;
musicpal_audio_state *s;
i2c_interface *i2c;
int iomemtype;
- audio = AUD_init();
-
s = qemu_mallocz(sizeof(musicpal_audio_state));
s->irq = irq;
@@ -436,7 +433,7 @@
i2c->bus = i2c_init_bus();
i2c->current_addr = -1;
- s->wm = wm8750_init(i2c->bus, audio);
+ s->wm = wm8750_init(i2c->bus);
if (!s->wm)
return NULL;
i2c_set_slave_address(s->wm, MP_WM_ADDR);
diff --git a/hw/nseries.c b/hw/nseries.c
index 55df20e..8f90d53 100644
--- a/hw/nseries.c
+++ b/hw/nseries.c
@@ -252,7 +252,7 @@
qemu_irq kbirq = omap2_gpio_in_get(s->cpu->gpif, N800_TSC_KP_IRQ_GPIO)[0];
qemu_irq dav = omap2_gpio_in_get(s->cpu->gpif, N800_TSC_TS_GPIO)[0];
- s->ts.chip = tsc2301_init(penirq, kbirq, dav, 0);
+ s->ts.chip = tsc2301_init(penirq, kbirq, dav);
s->ts.opaque = s->ts.chip->opaque;
s->ts.txrx = tsc210x_txrx;
diff --git a/hw/omap2.c b/hw/omap2.c
index 1cbbf49..82ea618 100644
--- a/hw/omap2.c
+++ b/hw/omap2.c
@@ -1973,7 +1973,6 @@
omap_eac_reset(s);
#ifdef HAS_AUDIO
- /* TODO: do AUD_init globally for machine */
AUD_register_card(AUD_init(), "OMAP EAC", &s->codec.card);
iomemtype = cpu_register_io_memory(0, omap_eac_readfn,
diff --git a/hw/palm.c b/hw/palm.c
index 7c01682..785ddf1 100644
--- a/hw/palm.c
+++ b/hw/palm.c
@@ -93,14 +93,8 @@
static void palmte_microwire_setup(struct omap_mpu_state_s *cpu)
{
uWireSlave *tsc;
- AudioState *audio = 0;
-#ifdef HAS_AUDIO
- audio = AUD_init();
-#endif
-
- tsc = tsc2102_init(omap_gpio_in_get(cpu->gpio)[PALMTE_PINTDAV_GPIO],
- audio);
+ tsc = tsc2102_init(omap_gpio_in_get(cpu->gpio)[PALMTE_PINTDAV_GPIO]);
omap_uwire_attach(cpu->microwire, tsc, 0);
omap_mcbsp_i2s_attach(cpu->mcbsp1, tsc210x_codec(tsc));
diff --git a/hw/pc.c b/hw/pc.c
index fe9d644..c81a7a8 100644
--- a/hw/pc.c
+++ b/hw/pc.c
@@ -788,17 +788,13 @@
}
if (audio_enabled) {
- AudioState *s;
-
- s = AUD_init ();
for (c = soundhw; c->name; ++c) {
if (c->enabled) {
if (c->isa) {
- c->init.init_isa (s, pic);
- }
- else {
+ c->init.init_isa(pic);
+ } else {
if (pci_bus) {
- c->init.init_pci (pci_bus, s);
+ c->init.init_pci(pci_bus);
}
}
}
diff --git a/hw/pc.h b/hw/pc.h
index 50e6c39..7567d28 100644
--- a/hw/pc.h
+++ b/hw/pc.h
@@ -119,7 +119,7 @@
/* pcspk.c */
void pcspk_init(PITState *);
-int pcspk_audio_init(AudioState *, qemu_irq *pic);
+int pcspk_audio_init(qemu_irq *pic);
/* piix_pci.c */
PCIBus *i440fx_init(PCIDevice **pi440fx_state, qemu_irq *pic);
diff --git a/hw/pcspk.c b/hw/pcspk.c
index ec1d0c6..0dad161 100644
--- a/hw/pcspk.c
+++ b/hw/pcspk.c
@@ -96,15 +96,12 @@
}
}
-int pcspk_audio_init(AudioState *audio, qemu_irq *pic)
+int pcspk_audio_init(qemu_irq *pic)
{
+ AudioState *audio = AUD_init();
PCSpkState *s = &pcspk_state;
struct audsettings as = {PCSPK_SAMPLE_RATE, 1, AUD_FMT_U8, 0};
- if (!audio) {
- AUD_log(s_spk, "No audio state\n");
- return -1;
- }
AUD_register_card(audio, s_spk, &s->card);
s->voice = AUD_open_out(&s->card, s->voice, s_spk, s, pcspk_callback, &as);
diff --git a/hw/ppc_prep.c b/hw/ppc_prep.c
index 020b5b7..e078211 100644
--- a/hw/ppc_prep.c
+++ b/hw/ppc_prep.c
@@ -696,7 +696,6 @@
}
i8042_init(i8259[1], i8259[12], 0x60);
DMA_init(1);
- // AUD_init();
// SB16_init();
for(i = 0; i < MAX_FD; i++) {
diff --git a/hw/sb16.c b/hw/sb16.c
index 14f3e3d..32e6a28 100644
--- a/hw/sb16.c
+++ b/hw/sb16.c
@@ -1398,18 +1398,14 @@
return 0;
}
-int SB16_init (AudioState *audio, qemu_irq *pic)
+int SB16_init (qemu_irq *pic)
{
+ AudioState *audio = AUD_init();
SB16State *s;
int i;
static const uint8_t dsp_write_ports[] = {0x6, 0xc};
static const uint8_t dsp_read_ports[] = {0x6, 0xa, 0xc, 0xd, 0xe, 0xf};
- if (!audio) {
- dolog ("No audio state\n");
- return -1;
- }
-
s = qemu_mallocz (sizeof (*s));
s->cmd = -1;
diff --git a/hw/spitz.c b/hw/spitz.c
index e53a81d..805af35 100644
--- a/hw/spitz.c
+++ b/hw/spitz.c
@@ -740,12 +740,10 @@
i2c_bus *bus = pxa2xx_i2c_bus(cpu->i2c[0]);
#ifdef HAS_AUDIO
- AudioState *audio;
i2c_slave *wm;
- audio = AUD_init();
/* Attach a WM8750 to the bus */
- wm = wm8750_init(bus, audio);
+ wm = wm8750_init(bus);
spitz_wm8750_addr(wm, 0, 0);
pxa2xx_gpio_out_set(cpu->gpio, SPITZ_GPIO_WM,
diff --git a/hw/tsc210x.c b/hw/tsc210x.c
index 76e36d6..316156d 100644
--- a/hw/tsc210x.c
+++ b/hw/tsc210x.c
@@ -684,8 +684,7 @@
"wrong value written into Audio 1\n");
#endif
tsc2102_audio_rate_update(s);
- if (s->audio)
- tsc2102_audio_output_update(s);
+ tsc2102_audio_output_update(s);
return;
case 0x01:
@@ -729,8 +728,7 @@
"wrong value written into Power\n");
#endif
tsc2102_audio_rate_update(s);
- if (s->audio)
- tsc2102_audio_output_update(s);
+ tsc2102_audio_output_update(s);
return;
case 0x06: /* Audio Control 3 */
@@ -741,8 +739,7 @@
fprintf(stderr, "tsc2102_audio_register_write: "
"wrong value written into Audio 3\n");
#endif
- if (s->audio)
- tsc2102_audio_output_update(s);
+ tsc2102_audio_output_update(s);
return;
case 0x07: /* LCH_BASS_BOOST_N0 */
@@ -1105,7 +1102,7 @@
return 0;
}
-uWireSlave *tsc2102_init(qemu_irq pint, AudioState *audio)
+uWireSlave *tsc2102_init(qemu_irq pint)
{
TSC210xState *s;
@@ -1120,7 +1117,7 @@
s->pint = pint;
s->model = 0x2102;
s->name = "tsc2102";
- s->audio = audio;
+ s->audio = AUD_init();;
s->tr[0] = 0;
s->tr[1] = 1;
@@ -1146,8 +1143,7 @@
qemu_add_mouse_event_handler(tsc210x_touchscreen_event, s, 1,
"QEMU TSC2102-driven Touchscreen");
- if (s->audio)
- AUD_register_card(s->audio, s->name, &s->card);
+ AUD_register_card(s->audio, s->name, &s->card);
qemu_register_reset((void *) tsc210x_reset, s);
register_savevm(s->name, -1, 0,
@@ -1156,8 +1152,7 @@
return &s->chip;
}
-uWireSlave *tsc2301_init(qemu_irq penirq, qemu_irq kbirq,
- qemu_irq dav, AudioState *audio)
+uWireSlave *tsc2301_init(qemu_irq penirq, qemu_irq kbirq, qemu_irq dav)
{
TSC210xState *s;
@@ -1174,7 +1169,7 @@
s->davint = dav;
s->model = 0x2301;
s->name = "tsc2301";
- s->audio = audio;
+ s->audio = AUD_init();
s->tr[0] = 0;
s->tr[1] = 1;
@@ -1200,8 +1195,7 @@
qemu_add_mouse_event_handler(tsc210x_touchscreen_event, s, 1,
"QEMU TSC2301-driven Touchscreen");
- if (s->audio)
- AUD_register_card(s->audio, s->name, &s->card);
+ AUD_register_card(s->audio, s->name, &s->card);
qemu_register_reset((void *) tsc210x_reset, s);
register_savevm(s->name, -1, 0, tsc210x_save, tsc210x_load, s);
diff --git a/hw/wm8750.c b/hw/wm8750.c
index 7086a79..3a428c6 100644
--- a/hw/wm8750.c
+++ b/hw/wm8750.c
@@ -645,8 +645,9 @@
return 0;
}
-i2c_slave *wm8750_init(i2c_bus *bus, AudioState *audio)
+i2c_slave *wm8750_init(i2c_bus *bus)
{
+ AudioState *audio = AUD_init();
WM8750State *s = (WM8750State *)
i2c_slave_init(bus, 0, sizeof(WM8750State));
s->i2c.event = wm8750_event;
diff --git a/sysemu.h b/sysemu.h
index 9bb9fbc..25a7c32 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -241,8 +241,8 @@
int enabled;
int isa;
union {
- int (*init_isa) (AudioState *s, qemu_irq *pic);
- int (*init_pci) (PCIBus *bus, AudioState *s);
+ int (*init_isa) (qemu_irq *pic);
+ int (*init_pci) (PCIBus *bus);
} init;
};