Skip to content

Commit 77d6a23

Browse files
gtrainaviciuspopcornmix
authored andcommitted
Pisound: Read out the SPI speed to use from the Device Tree.
Signed-off-by: Giedrius Trainavičius <[email protected]>
1 parent 81862fc commit 77d6a23

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

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)