Skip to content

Commit d9997b1

Browse files
committed
Pisound: Use 100kHz SPI speed for Pi 5.
Signed-off-by: Giedrius Trainavičius <giedrius@blokas.io>
1 parent 59902d6 commit d9997b1

File tree

5 files changed

+71
-6
lines changed

5 files changed

+71
-6
lines changed

arch/arm/boot/dts/overlays/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ dtbo-$(CONFIG_ARCH_BCM2835) += \
192192
piscreen.dtbo \
193193
piscreen2r.dtbo \
194194
pisound.dtbo \
195+
pisound-pi5.dtbo \
195196
pitft22.dtbo \
196197
pitft28-capacitive.dtbo \
197198
pitft28-resistive.dtbo \

arch/arm/boot/dts/overlays/overlay_map.dts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,16 @@
203203
renamed = "miniuart-bt";
204204
};
205205

206+
pisound {
207+
bcm2835;
208+
bcm2711;
209+
bcm2712 = "pisound-pi5";
210+
};
211+
212+
pisound-pi5 {
213+
bcm2712;
214+
};
215+
206216
pwm1 {
207217
bcm2711;
208218
};

arch/arm/boot/dts/overlays/pisound-overlay.dts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Pisound Linux kernel module.
3-
* Copyright (C) 2016-2017 Vilniaus Blokas UAB, https://blokas.io/pisound
3+
* Copyright (C) 2016-2024 Vilniaus Blokas UAB, https://blokas.io/pisound
44
*
55
* This program is free software; you can redistribute it and/or
66
* modify it under the terms of the GNU General Public License
@@ -56,6 +56,7 @@
5656
compatible = "blokaslabs,pisound-spi";
5757
reg = <0>;
5858
spi-max-frequency = <1000000>;
59+
spi-speed-hz = <150000>;
5960
};
6061
};
6162
};
@@ -76,6 +77,7 @@
7677
__overlay__ {
7778
compatible = "blokaslabs,pisound";
7879
i2s-controller = <&i2s_clk_consumer>;
80+
spi-controller = <&pisound_spi>;
7981
status = "okay";
8082

8183
pinctrl-names = "default";
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Pisound Linux kernel module.
3+
* Copyright (C) 2016-2024 Vilniaus Blokas UAB, https://blokas.io/pisound
4+
*
5+
* This program is free software; you can redistribute it and/or
6+
* modify it under the terms of the GNU General Public License
7+
* as published by the Free Software Foundation; version 2 of the
8+
* License.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program; if not, write to the Free Software
17+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18+
*/
19+
20+
/dts-v1/;
21+
/plugin/;
22+
23+
#include "pisound-overlay.dts"
24+
25+
&pisound_spi {
26+
spi-speed-hz = <100000>;
27+
};
28+
29+
/ {
30+
compatible = "brcm,bcm2712";
31+
};

sound/soc/bcm/pisound.c

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Pisound Linux kernel module.
3-
* Copyright (C) 2016-2020 Vilniaus Blokas UAB, https://blokas.io/pisound
3+
* Copyright (C) 2016-2024 Vilniaus Blokas UAB, https://blokas.io/pisound
44
*
55
* This program is free software; you can redistribute it and/or
66
* modify it under the terms of the GNU General Public License
@@ -142,14 +142,14 @@ static void pisnd_input_trigger(struct snd_rawmidi_substream *substream, int up)
142142
}
143143
}
144144

145-
static struct snd_rawmidi_ops pisnd_output_ops = {
145+
static const struct snd_rawmidi_ops pisnd_output_ops = {
146146
.open = pisnd_output_open,
147147
.close = pisnd_output_close,
148148
.trigger = pisnd_output_trigger,
149149
.drain = pisnd_output_drain,
150150
};
151151

152-
static struct snd_rawmidi_ops pisnd_input_ops = {
152+
static const struct snd_rawmidi_ops pisnd_input_ops = {
153153
.open = pisnd_input_open,
154154
.close = pisnd_input_close,
155155
.trigger = pisnd_input_trigger,
@@ -226,6 +226,7 @@ static char g_id[25];
226226
enum { MAX_VERSION_STR_LEN = 6 };
227227
static char g_fw_version[MAX_VERSION_STR_LEN];
228228
static char g_hw_version[MAX_VERSION_STR_LEN];
229+
static u32 g_spi_speed_hz;
229230

230231
static uint8_t g_ledFlashDuration;
231232
static bool g_ledFlashDurationChanged;
@@ -329,7 +330,7 @@ static void spi_transfer(const uint8_t *txbuf, uint8_t *rxbuf, int len)
329330
transfer.tx_buf = txbuf;
330331
transfer.rx_buf = rxbuf;
331332
transfer.len = len;
332-
transfer.speed_hz = 150000;
333+
transfer.speed_hz = g_spi_speed_hz;
333334
transfer.delay.value = 10;
334335
transfer.delay.unit = SPI_DELAY_UNIT_USECS;
335336

@@ -646,6 +647,26 @@ static int pisnd_spi_init(struct device *dev)
646647
memset(g_fw_version, 0, sizeof(g_fw_version));
647648
memset(g_hw_version, 0, sizeof(g_hw_version));
648649

650+
g_spi_speed_hz = 150000;
651+
if (dev->of_node) {
652+
struct device_node *spi_node;
653+
654+
spi_node = of_parse_phandle(
655+
dev->of_node,
656+
"spi-controller",
657+
0
658+
);
659+
660+
if (spi_node) {
661+
ret = of_property_read_u32(spi_node, "spi-speed-hz", &g_spi_speed_hz);
662+
if (ret != 0)
663+
printe("Failed reading spi-speed-hz! (%d)\n", ret);
664+
665+
of_node_put(spi_node);
666+
}
667+
}
668+
printi("Using SPI speed: %u\n", g_spi_speed_hz);
669+
649670
spi = pisnd_spi_find_device();
650671

651672
if (spi != NULL) {
@@ -950,7 +971,7 @@ static int pisnd_startup(struct snd_pcm_substream *substream)
950971
return 0;
951972
}
952973

953-
static struct snd_soc_ops pisnd_ops = {
974+
static const struct snd_soc_ops pisnd_ops = {
954975
.startup = pisnd_startup,
955976
.hw_params = pisnd_hw_params,
956977
};

0 commit comments

Comments
 (0)