summaryrefslogtreecommitdiffstats
path: root/target/linux/bcm27xx/patches-6.1/950-1250-Pisound-Read-out-the-SPI-speed-to-use-from-the-Devic.patch
blob: 5da78175b1ec404ec7520f8d5b99f6efdd31cfcd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
From 273139b285f7a1a825eb689943626a0172b8802b Mon Sep 17 00:00:00 2001
From: Giedrius <giedrius@blokas.io>
Date: Mon, 22 Jan 2024 13:26:58 +0000
Subject: [PATCH 1250/1295] Pisound: Read out the SPI speed to use from the
 Device Tree.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Giedrius Trainavičius <giedrius@blokas.io>
---
 sound/soc/bcm/pisound.c | 31 ++++++++++++++++++++++++++-----
 1 file changed, 26 insertions(+), 5 deletions(-)

--- a/sound/soc/bcm/pisound.c
+++ b/sound/soc/bcm/pisound.c
@@ -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 s
 	}
 }
 
-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 *
 	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
 	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_
 	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,
 };