Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RP1 Audio Out #6668

Open
wants to merge 4 commits into
base: rpi-6.12.y
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions arch/arm/boot/dts/overlays/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ dtbo-$(CONFIG_ARCH_BCM2835) += \
audioinjector-wm8731-audio.dtbo \
audiosense-pi.dtbo \
audremap.dtbo \
audremap-pi5.dtbo \
balena-fin.dtbo \
bcm2712d0.dtbo \
camera-mux-2port.dtbo \
Expand Down
11 changes: 11 additions & 0 deletions arch/arm/boot/dts/overlays/README
Original file line number Diff line number Diff line change
Expand Up @@ -871,6 +871,17 @@ Params: swap_lr Reverse the channel allocation, which will also
pins are on different controllers)


Name: audremap-pi5
Info: On Raspberry Pi 5 / 500 /CM5, enable digital audio output
and route it to GPIOs 12 & 13 on the 40-pin header
Load: dtoverlay=audremap-pi5,<param>=<val>
Params: swap_lr Reverse the channel allocation (default off)
pins_12_13 Select GPIOs 12 & 13 (default)
pins_18_19 Not available; this will not enable audio out
pins_40_41 Not available; this will not enable audio out
pins_40_45 Not available; this will not enable audio out


Name: balena-fin
Info: Overlay that enables WLAN, Bluetooth and the GPIO expander on the
balenaFin carrier board for the Raspberry Pi Compute Module 3/3+ Lite.
Expand Down
65 changes: 65 additions & 0 deletions arch/arm/boot/dts/overlays/audremap-pi5-overlay.dts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/dts-v1/;
/plugin/;

/*
* Raspberry Pi 5 has a different Audio Out hardware from earlier Raspberry Pis.
* It can output only to GPIOs 12 and 13. We therefore enable it *only* when
* that particular GPIO mapping is requested here. To make it work with ASOC
* we must also define a "dummy" codec and a generic audio card.
*/

/ {
compatible = "brcm,bcm2712";

fragment@0 {
target = <&rp1_audio_out>;
frag0: __overlay__ {
pinctrl-0 = <&rp1_audio_out_12_13>;
pinctrl-names = "default";
status = "ok";
};
};

fragment@1 {
target-path = "/";
__overlay__ {

rp1_audio_out_codec: rp1_audio_out_codec@0 {
compatible = "linux,spdif-dit";
#sound-dai-cells = <0>;
status = "ok";
};

rp1_audio_out_simple_card@0 {
compatible = "simple-audio-card";
simple-audio-card,name = "RP1-Audio-Out";
#address-cells = <1>;
#size-cells = <0>;
status = "ok";

simple-audio-card,dai-link@0 {
reg = <0>;
format = "left_j";
bitclock-master = <&sndcpu0>;
frame-master = <&sndcpu0>;

sndcpu0: cpu {
sound-dai = <&rp1_audio_out>;
};

codec {
sound-dai = <&rp1_audio_out_codec>;
};
};
};
};
};

__overrides__ {
swap_lr = <&frag0>, "swap_lr?";
pins_12_13 = <0>, "+0+1"; /* this is the default */
pins_18_19 = <0>, "-0-1"; /* sorry not supported */
pins_40_41 = <0>, "-0-1"; /* sorry not supported */
pins_40_45 = <0>, "-0-1"; /* sorry not supported */
};
};
5 changes: 5 additions & 0 deletions arch/arm/boot/dts/overlays/overlay_map.dts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
audremap {
bcm2835;
bcm2711;
bcm2712 = "audremap-pi5";
};

audremap-pi5 {
bcm2712;
};

balena-fin {
Expand Down
22 changes: 21 additions & 1 deletion arch/arm64/boot/dts/broadcom/rp1.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<125000000>, // RP1_PLL_SYS_SEC
<125000000>, // RP1_CLK_ETH
<61440000>, // RP1_PLL_AUDIO
<192000000>, // RP1_PLL_AUDIO_SEC
<153600000>, // RP1_PLL_AUDIO_SEC
<200000000>, // RP1_CLK_SYS
<100000000>, // RP1_PLL_SYS_PRI_PH
// Must match the XOSC frequency
Expand Down Expand Up @@ -380,6 +380,20 @@
status = "disabled";
};

rp1_audio_out: audio_out@94000 {
compatible = "raspberrypi,rp1-audio-out";
reg = <0xc0 0x40094000 0x0 0x4000>;
clocks = <&rp1_clocks RP1_CLK_AUDIO_OUT>;
assigned-clocks = <&rp1_clocks RP1_CLK_AUDIO_OUT>;
assigned-clock-rates = <153600000>;
assigned-clock-parents = <&rp1_clocks RP1_PLL_AUDIO_SEC>;
dmas = <&rp1_dma RP1_DMA_AUDIO_OUT>;
dma-maxburst = <4>;
dma-names = "tx";
#sound-dai-cells = <0>;
status = "disabled";
};

rp1_pwm0: pwm@98000 {
compatible = "raspberrypi,rp1-pwm";
reg = <0xc0 0x40098000 0x0 0x100>;
Expand Down Expand Up @@ -974,6 +988,12 @@
pins = "gpio52", "gpio53";
bias-pull-up;
};

rp1_audio_out_12_13: rp1_audio_out_12_13 {
function = "aaud";
pins = "gpio12", "gpio13";
bias-disable;
};
};

rp1_eth: ethernet@100000 {
Expand Down
1 change: 1 addition & 0 deletions arch/arm64/configs/bcm2712_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -1151,6 +1151,7 @@ CONFIG_SND_PISOUND=m
CONFIG_SND_DACBERRY400=m
CONFIG_SND_DESIGNWARE_I2S=m
CONFIG_SND_DESIGNWARE_PCM=y
CONFIG_SND_RP1_AUDIO_OUT=m
CONFIG_SND_SOC_AD193X_SPI=m
CONFIG_SND_SOC_AD193X_I2C=m
CONFIG_SND_SOC_ADAU1701=m
Expand Down
8 changes: 5 additions & 3 deletions drivers/clk/clk-rp1.c
Original file line number Diff line number Diff line change
Expand Up @@ -1326,9 +1326,11 @@ static void rp1_clock_choose_div_and_prate(struct clk_hw *hw,
/*
* Prevent overclocks - if all parent choices result in
* a downstream clock in excess of the maximum, then the
* call to set the clock will fail.
* call to set the clock will fail. But due to round-to-
* nearest in the PLL core (which has 24 fractional bits),
* it's expedient to tolerate a tiny error (1Hz/33MHz).
*/
if (tmp > clock->data->max_freq)
if (tmp > clock->data->max_freq + (clock->data->max_freq >> 25))
*calc_rate = 0;
else
*calc_rate = tmp;
Expand Down Expand Up @@ -2006,7 +2008,7 @@ static const struct rp1_clk_desc clk_desc_array[] = {
[RP1_CLK_AUDIO_OUT] = REGISTER_CLK(
.name = "clk_audio_out",
.parents = {"", //"pll_audio",
"", //"pll_audio_sec",
"pll_audio_sec",
"pll_video_sec",
"xosc",
"clksrc_gp0",
Expand Down
1 change: 1 addition & 0 deletions sound/soc/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ source "sound/soc/meson/Kconfig"
source "sound/soc/mxs/Kconfig"
source "sound/soc/pxa/Kconfig"
source "sound/soc/qcom/Kconfig"
source "sound/soc/raspberrypi/Kconfig"
source "sound/soc/rockchip/Kconfig"
source "sound/soc/samsung/Kconfig"
source "sound/soc/sh/Kconfig"
Expand Down
1 change: 1 addition & 0 deletions sound/soc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ obj-$(CONFIG_SND_SOC) += mxs/
obj-$(CONFIG_SND_SOC) += kirkwood/
obj-$(CONFIG_SND_SOC) += pxa/
obj-$(CONFIG_SND_SOC) += qcom/
obj-$(CONFIG_SND_SOC) += raspberrypi/
obj-$(CONFIG_SND_SOC) += rockchip/
obj-$(CONFIG_SND_SOC) += samsung/
obj-$(CONFIG_SND_SOC) += sh/
Expand Down
12 changes: 12 additions & 0 deletions sound/soc/raspberrypi/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# SPDX-License-Identifier: GPL-2.0-only
config SND_RP1_AUDIO_OUT
tristate "PWM Audio Out from RP1"
select SND_SOC_GENERIC_DMAENGINE_PCM
select SND_SOC_SPDIF
help
Say Y or M if you want to add support for PWM digital
audio output from a Raspberry Pi 5, 500 or CM5.

Output is from RP1 GPIOs pins 12 and 13 only, and additional
components will be needed. It may be useful when HDMI, I2S
or USB audio devices are unavailable, or for compatibility.
2 changes: 2 additions & 0 deletions sound/soc/raspberrypi/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# SPDX-License-Identifier: GPL-2.0-only
obj-$(CONFIG_SND_RP1_AUDIO_OUT) += rp1_aout.o
Loading