Pisound: Read out the SPI speed to use from the Device Tree.
authorGiedrius <giedrius@blokas.io>
Mon, 22 Jan 2024 13:26:58 +0000 (13:26 +0000)
committerDom Cobley <popcornmix@gmail.com>
Mon, 19 Feb 2024 11:35:31 +0000 (11:35 +0000)
Signed-off-by: Giedrius Trainavičius <giedrius@blokas.io>
sound/soc/bcm/pisound.c

index 69d9c6b..b03ea62 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Pisound Linux kernel module.
- * Copyright (C) 2016-2020  Vilniaus Blokas UAB, https://blokas.io/pisound
+ * Copyright (C) 2016-2024  Vilniaus Blokas UAB, https://blokas.io/pisound
  *
  * This program is free software; you can redistribute it and/or
  * 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)
        }
 }
 
-static struct snd_rawmidi_ops pisnd_output_ops = {
+static const struct snd_rawmidi_ops pisnd_output_ops = {
        .open = pisnd_output_open,
        .close = pisnd_output_close,
        .trigger = pisnd_output_trigger,
        .drain = pisnd_output_drain,
 };
 
-static struct snd_rawmidi_ops pisnd_input_ops = {
+static const struct snd_rawmidi_ops pisnd_input_ops = {
        .open = pisnd_input_open,
        .close = pisnd_input_close,
        .trigger = pisnd_input_trigger,
@@ -226,6 +226,7 @@ static char g_id[25];
 enum { MAX_VERSION_STR_LEN = 6 };
 static char g_fw_version[MAX_VERSION_STR_LEN];
 static char g_hw_version[MAX_VERSION_STR_LEN];
+static u32 g_spi_speed_hz;
 
 static uint8_t g_ledFlashDuration;
 static bool    g_ledFlashDurationChanged;
@@ -329,7 +330,7 @@ static void spi_transfer(const uint8_t *txbuf, uint8_t *rxbuf, int len)
        transfer.tx_buf = txbuf;
        transfer.rx_buf = rxbuf;
        transfer.len = len;
-       transfer.speed_hz = 150000;
+       transfer.speed_hz = g_spi_speed_hz;
        transfer.delay.value = 10;
        transfer.delay.unit = SPI_DELAY_UNIT_USECS;
 
@@ -646,6 +647,26 @@ static int pisnd_spi_init(struct device *dev)
        memset(g_fw_version, 0, sizeof(g_fw_version));
        memset(g_hw_version, 0, sizeof(g_hw_version));
 
+       g_spi_speed_hz = 150000;
+       if (dev->of_node) {
+               struct device_node *spi_node;
+
+               spi_node = of_parse_phandle(
+                       dev->of_node,
+                       "spi-controller",
+                       0
+                       );
+
+               if (spi_node) {
+                       ret = of_property_read_u32(spi_node, "spi-speed-hz", &g_spi_speed_hz);
+                       if (ret != 0)
+                               printe("Failed reading spi-speed-hz! (%d)\n", ret);
+
+                       of_node_put(spi_node);
+               }
+       }
+       printi("Using SPI speed: %u\n", g_spi_speed_hz);
+
        spi = pisnd_spi_find_device();
 
        if (spi != NULL) {
@@ -950,7 +971,7 @@ static int pisnd_startup(struct snd_pcm_substream *substream)
        return 0;
 }
 
-static struct snd_soc_ops pisnd_ops = {
+static const struct snd_soc_ops pisnd_ops = {
        .startup = pisnd_startup,
        .hw_params = pisnd_hw_params,
 };