sound: bcm2835-analog-audio: Add driver for bcm2835(Raspberry PI) headphone jack.
Subsystems (5)
RFC PATCH 1/1 sound: bcm2835-analog-audio: Add driver for bcm2835(Raspberry PI) headphone jack.
I tried sending this a few times, but I'm not sure it made it through to the e-mail list.
Someone on the internet mentioned that if we have a HDMI Audio driver, why not have a driver for the headphone/analog jack on the Raspberry PI that doesn't use the firmware. So I quickly make up a prototype that isn't submit quality yet, but is very functional. The idea is to like the firmware, just use the PWM of the bcm2835 to generate the audio.
Questions:
1. Is this something that people would want in the upstream kernel and would be seriously considered for submission?
2. Is it a complete deal breaker that the driver is a regular ALSA driver instead of a ASoC driver?
TODO(Things I will do before submitting for real):
1. I found several people on the Internet that have written bare metal applications to do the same thing as this driver. One thing they all typically have is more signal conditioning(higher hardware bitrates, noise shaping filters, support For multiple software formats).
2. The DMA engine doesn't have support for bus priorities even though the hardware supports it. It might be good to put support for this in the DMA engine driver since it might be required for HDMI audio as well.
3. Checkpatch.pl/Formatting issues.
--- arch/arm/boot/dts/bcm283x.dtsi | 19 ++ drivers/dma/bcm2835-dma.c | 33 ++- sound/arm/Kconfig | 10 +- sound/arm/Makefile | 3 + sound/arm/bcm2835-analog-audio.c | 585 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 641 insertions(+), 9 deletions(-) create mode 100644 sound/arm/bcm2835-analog-audio.c
arch/arm/boot/dts/bcm283x.dtsi +19 -0
@@ -338,6 +338,12 @@ brcm,pins = <42 43>; brcm,function = <BCM2835_FSEL_ALT5>; }; + + analog_audio_pins: analog_audio_pins { + brcm,pins = <40 45>; + brcm,function = <4 4>; /* Alt0 */ + }; + }; uart0: serial@7e201000 {
@@ -464,6 +470,19 @@ status = "disabled"; }; + analogaudio: analogaudio@7e20c000 { + compatible = "brcm,bcm2835-analog-audio"; + reg = <0x7e20c000 0x28>; + clocks = <&clocks BCM2835_CLOCK_PWM>; + assigned-clocks = <&clocks BCM2835_CLOCK_PWM>; + pinctrl-names = "default"; + pinctrl-0 = <&analog_audio_pins>; + assigned-clock-rates = <250000000>; + + dmas = <&dma 5>; + dma-names = "tx"; + }; + sdhci: sdhci@7e300000 { compatible = "brcm,bcm2835-sdhci"; reg = <0x7e300000 0x100>;
drivers/dma/bcm2835-dma.c +25 -8
@@ -179,6 +179,17 @@ struct bcm2835_desc {#define MAX_DMA_LEN SZ_1G#define MAX_LITE_DMA_LEN (SZ_64K - 4) +static inline u32 bcm2835_get_priority (struct bcm2835_chan *c) +{ +if (c->dreq !=5 ) +return BCM2835_DMA_PRIORITY (0 ) |BCM2835_DMA_PANIC_PRIORITY (0 ); + +else { +// printk( KERN_ERR "Setting priority to 15 for DRAQ 5"); +return BCM2835_DMA_PRIORITY (15 ) |BCM2835_DMA_PANIC_PRIORITY (15 ); + } +} +static inline size_t bcm2835_dma_max_frame_length (struct bcm2835_chan *c) {/* lite and normal channels have different max frame length */
@@ -465,7 +476,7 @@ static void bcm2835_dma_start_desc(struct bcm2835_chan *c) c->desc = d =to_bcm2835_dma_desc (&vd->tx);writel (d->cb_list[0 ].paddr, c->chan_base +BCM2835_DMA_ADDR ); -writel (BCM2835_DMA_ACTIVE , c->chan_base +BCM2835_DMA_CS ); +writel (BCM2835_DMA_ACTIVE |bcm2835_get_priority (c), c->chan_base +BCM2835_DMA_CS ); }static irqreturn_t bcm2835_dma_callback (int irq,void *data)
@@ -485,24 +496,30 @@ static irqreturn_t bcm2835_dma_callback(int irq, void *data)spin_lock_irqsave (&c->vc.lock, flags); -/* Acknowledge interrupt */ -writel (BCM2835_DMA_INT , c->chan_base +BCM2835_DMA_CS ); - d = c->desc;if (d) {if (d->cyclic) { + +/* Acknowledge interrupt */ +writel (BCM2835_DMA_INT |BCM2835_DMA_ACTIVE |bcm2835_get_priority (c), c->chan_base +BCM2835_DMA_CS ); +/* call the cyclic callback */ vchan_cyclic_callback (&d->vd); - -/* Keep the DMA engine running */ -writel (BCM2835_DMA_ACTIVE , - c->chan_base +BCM2835_DMA_CS ); }else { + +/* Acknowledge interrupt */ +writel (BCM2835_DMA_INT |bcm2835_get_priority (c), c->chan_base +BCM2835_DMA_CS ); +vchan_cookie_complete (&c->desc->vd);bcm2835_dma_start_desc (c); } } +else + { +/* Acknowledge interrupt */ +writel (BCM2835_DMA_INT , c->chan_base +BCM2835_DMA_CS ); + }spin_unlock_irqrestore (&c->vc.lock, flags);
sound/arm/Kconfig +9 -1
@@ -2,7 +2,7 @@ menuconfig SND_ARM bool "ARM sound devices" - depends on ARM + depends on ARM || ARM64 default y help Support for sound devices specific to ARM architectures.
@@ -11,6 +11,14 @@ menuconfig SND_ARM if SND_ARM +config SND_BCM2835_ANALOG_AUDIO + tristate "Analog/Headphone jack support for BCM2835" + depends on ARCH_BCM2835 && HAS_DMA + select SND_PCM + help + Say y or m to support the analog/headphone jack + for the BCM2835 as used by the Raspberry PI. + config SND_ARMAACI tristate "ARM PrimeCell PL041 AC Link support" depends on ARM_AMBA
sound/arm/Makefile +3 -0
@@ -14,3 +14,6 @@ snd-pxa2xx-lib-$(CONFIG_SND_PXA2XX_LIB_AC97) += pxa2xx-ac97-lib.o obj-$(CONFIG_SND_PXA2XX_AC97) += snd-pxa2xx-ac97.o snd-pxa2xx-ac97-objs := pxa2xx-ac97.o + +obj-$(CONFIG_SND_BCM2835_ANALOG_AUDIO) += bcm2835-analog-audio.o +
sound/arm/bcm2835-analog-audio.c new file +585 -0
585 lines not on this page · raw message
Signature · 1 line
2.11.0