Add AACI audio playback support to the ARM Versatile/PB platform
PATCH v3 1/1 Add AACI audio playback support to the ARM Versatile/PB platform
This driver emulates the ARM AACI interface (PL041) connected to a LM4549 codec. It enables audio playback for the Versatile/PB platform.
Limitations:
- Supports only a playback on one channel (Versatile/Vexpress)
- Supports only a TX FIFO in compact-mode.
- Record is not supported.
- The PL041 is hardwired to a LM4549 codec.
Versatile/PB test build:
linux-2.6.38.5
buildroot-2010.11
alsa-lib-1.0.22
alsa-utils-1.0.22
mpg123-0.66
Qemu host: Ubuntu 10.04 in Vmware/OS X
Playback tested successfully with speaker-test/aplay/mpg123.
---v2->v3
This version takes into account the remarks from Peter Maydell's review:
* Both pl041 and lm4549 source code has been simplified by removing extraneous abstractions.
* hw_error occurences has been replaced by warnings.
* The FIFO depth is now a qdev property.
* The model now has load/save support.
Makefile.target | 1 + hw/lm4549.c | 326 +++++++++++++++++++++++++++++++++++ hw/lm4549.h | 44 +++++ hw/pl041.c | 501 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ hw/pl041.h | 135 +++++++++++++++ hw/pl041.hx | 81 +++++++++ hw/versatilepb.c | 8 + 7 files changed, 1096 insertions(+), 0 deletions(-) create mode 100644 hw/lm4549.c create mode 100644 hw/lm4549.h create mode 100644 hw/pl041.c create mode 100644 hw/pl041.h create mode 100644 hw/pl041.hx
Makefile.target +1 -0
@@ -355,6 +355,7 @@ obj-arm-y += syborg_virtio.o obj-arm-y += vexpress.o obj-arm-y += strongarm.o obj-arm-y += collie.o +obj-arm-y += pl041.o lm4549.o obj-sh4-y = shix.o r2d.o sh7750.o sh7750_regnames.o tc58128.o obj-sh4-y += sh_timer.o sh_serial.o sh_intc.o sh_pci.o sm501.o
hw/lm4549.c new file +326 -0
326 lines not on this page · raw message
hw/lm4549.h new file +44 -0
44 lines not on this page · raw message
hw/pl041.c new file +501 -0
501 lines not on this page · raw message
hw/pl041.h new file +135 -0
135 lines not on this page · raw message
hw/pl041.hx new file +81 -0
81 lines not on this page · raw message
hw/versatilepb.c +8 -0
@@ -181,6 +181,7 @@ static void versatile_init(ram_addr_t ram_size,qemu_irq pic[32 ];qemu_irq sic[32 ];DeviceState *dev, *sysctl; +DeviceState *pl041;PCIBus *pci_bus;NICInfo *nd;int n;
@@ -265,6 +266,13 @@ static void versatile_init(ram_addr_t ram_size,/* Add PL031 Real Time Clock. */ sysbus_create_simple ("pl031" ,0x101e8000 , pic[10 ]); +/* Add PL041 AACI Interface to the LM4549 codec */ + pl041 =qdev_create (NULL ,"pl041" ); +qdev_prop_set_uint32 (pl041,"fifo_depth" ,256 );/* AN115B - Table 1.1 */ +qdev_init_nofail (pl041); +sysbus_mmio_map (sysbus_from_qdev (pl041),0 ,0x10004000 ); +sysbus_connect_irq (sysbus_from_qdev (pl041),0 , sic[24 ]); +/* Memory map for Versatile/PB: */ /* 0x10000000 System registers. */ /* 0x10001000 PCI controller config registers. */
--
1.7.0.4
Quoted 17 lines · Mathieu Sonet
This driver emulates the ARM AACI interface (PL041) connected to a LM4549 codec.
It enables audio playback for the Versatile/PB platform.Limitations:
- Supports only a playback on one channel (Versatile/Vexpress)
- Supports only a TX FIFO in compact-mode.
- Record is not supported.
- The PL041 is hardwired to a LM4549 codec.Versatile/PB test build:
linux-2.6.38.5
buildroot-2010.11
alsa-lib-1.0.22
alsa-utils-1.0.22
mpg123-0.66
Quoted 3 lines
Qemu host: Ubuntu 10.04 in Vmware/OS X
Playback tested successfully with speaker-test/aplay/mpg123.
No objections from me.
[..snip..]
Signature · 1 line
mailto:[email protected]
Quoted 7 lines · Mathieu Sonet
This driver emulates the ARM AACI interface (PL041) connected to a LM4549 codec.
It enables audio playback for the Versatile/PB platform.Limitations:
- Supports only a playback on one channel (Versatile/Vexpress)
- Supports only a TX FIFO in compact-mode.
Actually you seem to have implemented a weird hybrid of compact and non-compact modes.
Non-compact mode: FIFOs are 20 bits wide; a word write from the CPU writes to bits [19:0] of the FIFO slot; each 'slot' of data to the LM4549 reads 20 bits from the FIFO.
Compact mode: FIFOs are 40 bits wide (and half as deep); a word write from the CPU writes to bits [31:0] of the FIFO slot; each 'slot' of data to the LM4549 reads 16 bits from the FIFO (bits [15:0] then [31:16], and you have to read two slots (ie the 2 channels of stereo).
You've implemented a single 32 bit depth FIFO which one CPU write writes to and which always passes one 32 bit word to the LM4549. There are two issues here:
(1) the LM4549 can take up to 18 bits of data per slot,
which your current lm4549_write_sample() API doesn't allow. Passing two 32 bit words here would fix that. [My point here is that we shouldn't hardwire the missing non-compact mode support into the API between the two components.]
(2) when the Linux driver dynamically identifies the size
of the FIFO it does it in non-compact mode, so it will return a value half as big as is actually right for the compact-mode behaviour you've implemented.
(Also your FIFO is twice as deep as it should be if we're only implementing compact mode.)
Quoted 1 line
Playback tested successfully with speaker-test/aplay/mpg123.
I find that on vexpress mpg123 playback works but can be quite stuttery. madplay (integer only) is somewhat better, so I suspect that qemu is spending ages emulating Neon/VFP in mpg123...
Further (minor) comments below.
Quoted 4 lines
+ regfile[LM4549_PCM_Front_DAC_Rate] =
0xBB80;
+ regfile[LM4549_PCM_ADC_Rate] =0xBB80;
+ regfile[LM4549_Vendor_ID1] =0x4e53;
+ regfile[LM4549_Vendor_ID2] =0x4331;
Can we be consistent about upper or lower case for the hex?
hw/pl041.c line 49
Quoted 2 lines
hw/pl041.c new file +2
-0+#define MAX_FIFO_DEPTH (1024) +#define VERSATILEPB_DEFAULT_FIFO_DEPTH (256)/* AN115B - Table 1.1 */
pl041.c shouldn't know anything about VersatilePB. The default fifo depth should be 8 (same as the hardware PL041).
hw/pl041.c line 105
Quoted 5 lines
hw/pl041.c new file +5
-0+static uint8_t pl041_compute_periphid3 (pl041_state *s) +{ + uint8_t id3 = (1 | ((s->fifo_depth >> 4) << 3)); + return id3; +}
This isn't right.
[5:3] FIFO depth (non-compact mode)
b000 8 b001 16 b010 32 b011 64 b100 128 b101 256 b110 512 b111 1024
...which isn't what your function calculates.
(Linux determines FIFO depth programmatically by stuffing words into the FIFO until the status register says it's full, which is why it doesn't complain.)
NB that some of the board TRMs have what seem to be incorrect labelling on the tables of depth vs ID register bits.
Quoted 5 lines
+ /* Update the irq state */
+ qemu_set_irq(s->irq, ((s->regs.isr1&s->regs.ie1) > 0) ? 1 : 0);
+ DBG_L2("Set interrupt sr1 = 0x%08x isr1 = 0x%08x masked = 0x%08x\n",
+s->regs.sr1,s->regs.isr1,s->regs.isr1& mask); +}
This debug printf won't compile if enabled -- you forgot to update it when you changed the main code to remove the 'mask' variable.
hw/pl041.c line 424
Quoted 6 lines
hw/pl041.c new file +6
-0+static int pl041_post_load (void *opaque,int version_id) +{ + pl041_state *s = opaque; + lm4549_post_load(&s->codec); + return 0; +}
Is it not possible to just register lm4549_post_load() as the post_load function for lm4549_state, rather than having a pl041 post_load hook which only passes it through?
(Something in your mailsending path is wrapping long lines, by the way.)
-- PMM
Quoted 94 lines · Peter Maydell
Quoted 7 lines · Mathieu Sonet
This driver emulates the ARM AACI interface (PL041) connected to a LM4549 codec.
It enables audio playback for the Versatile/PB platform.Limitations:
- Supports only a playback on one channel (Versatile/Vexpress)
- Supports only a TX FIFO in compact-mode.Actually you seem to have implemented a weird hybrid of compact and non-compact modes.
Non-compact mode: FIFOs are 20 bits wide; a word write from the CPU writes to bits [19:0] of the FIFO slot; each 'slot' of data to the LM4549 reads 20 bits from the FIFO.
Compact mode: FIFOs are 40 bits wide (and half as deep); a word write from the CPU writes to bits [31:0] of the FIFO slot; each 'slot' of data to the LM4549 reads 16 bits from the FIFO (bits [15:0] then [31:16], and you have to read two slots (ie the 2 channels of stereo).You've implemented a single 32 bit depth FIFO which one CPU write writes to and which always passes one 32 bit word to the LM4549. There are two issues here:
(1) the LM4549 can take up to 18 bits of data per slot,
which your currentlm4549_write_sample()API doesn't allow. Passing two 32 bit words here would fix that. [My point here is that we shouldn't hardwire the missing non-compact mode support into the API between the two components.]
(2) when the Linux driver dynamically identifies the size
of the FIFO it does it in non-compact mode, so it will return a value half as big as is actually right for the compact-mode behaviour you've implemented.(Also your FIFO is twice as deep as it should be if we're only implementing compact mode.)
Quoted 1 line
Playback tested successfully with speaker-test/aplay/mpg123.
I find that on vexpress mpg123 playback works but can be quite stuttery. madplay (integer only) is somewhat better, so I suspect that qemu is spending ages emulating Neon/VFP in mpg123...
Further (minor) comments below.
hw/lm4549.c line 93
Quoted 4 lines
hw/lm4549.c new file +4
-0+ regfile[LM4549_PCM_Front_DAC_Rate] =0xBB80 ; + regfile[LM4549_PCM_ADC_Rate] =0xBB80 ; + regfile[LM4549_Vendor_ID1] =0x4e53 ; + regfile[LM4549_Vendor_ID2] =0x4331 ;Can we be consistent about upper or lower case for the hex?
hw/pl041.c line 49
Quoted 2 lines
hw/pl041.c new file +2
-0+#define MAX_FIFO_DEPTH (1024) +#define VERSATILEPB_DEFAULT_FIFO_DEPTH (256)/* AN115B - Table 1.1 */
pl041.cshouldn't know anything about VersatilePB. The default fifo depth should be 8 (same as the hardware PL041).hw/pl041.c line 105
Quoted 5 lines
hw/pl041.c new file +5
-0+static uint8_t pl041_compute_periphid3 (pl041_state *s) +{ +uint8_t id3 = (1 | ((s->fifo_depth >>4 ) <<3 )); +return id3; +}This isn't right.
[5:3] FIFO depth (non-compact mode)
b000 8 b001 16 b010 32 b011 64 b100 128 b101 256 b110 512 b111 1024...which isn't what your function calculates.
(Linux determines FIFO depth programmatically by stuffing words into the FIFO until the status register says it's full, which is why it doesn't complain.)NB that some of the board TRMs have what seem to be incorrect labelling on the tables of depth vs ID register bits.
hw/pl041.c line 214
Quoted 5 lines
hw/pl041.c new file +5
-0+/* Update the irq state */ +qemu_set_irq (s->irq, ((s->regs.isr1 & s->regs.ie1) >0 ) ?1 :0 ); +DBG_L2 ("Set interrupt sr1 = 0x%08x isr1 = 0x%08x masked = 0x%08x\n" , + s->regs.sr1, s->regs.isr1, s->regs.isr1 & mask); +}This debug printf won't compile if enabled -- you forgot to update it when you changed the main code to remove the 'mask' variable.
Quoted 10 lines
hw/pl041.c line 424
Quoted 6 lines
hw/pl041.c new file +6
-0+static int pl041_post_load (void *opaque,int version_id) +{ +pl041_state *s = opaque; +lm4549_post_load (&s->codec); +return 0 ; +}Is it not possible to just register
lm4549_post_load()as thepost_loadfunction forlm4549_state, rather than having a pl041post_loadhook which only passes it through?
The lm4549 model has no knowledge of its pl041 client and uses a separate context structure. The opaque pointer passed to the post_load hook can not be used directly to setup the lm4549.
I would prefer to keep the two models separated.
Quoted 4 lines
(Something in your mailsending path is wrapping long lines, by the way.)
-- PMM
Mathieu