|
1 | 1 | /* |
2 | 2 | * 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 |
4 | 4 | * |
5 | 5 | * This program is free software; you can redistribute it and/or |
6 | 6 | * 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) |
142 | 142 | } |
143 | 143 | } |
144 | 144 |
|
145 | | -static struct snd_rawmidi_ops pisnd_output_ops = { |
| 145 | +static const struct snd_rawmidi_ops pisnd_output_ops = { |
146 | 146 | .open = pisnd_output_open, |
147 | 147 | .close = pisnd_output_close, |
148 | 148 | .trigger = pisnd_output_trigger, |
149 | 149 | .drain = pisnd_output_drain, |
150 | 150 | }; |
151 | 151 |
|
152 | | -static struct snd_rawmidi_ops pisnd_input_ops = { |
| 152 | +static const struct snd_rawmidi_ops pisnd_input_ops = { |
153 | 153 | .open = pisnd_input_open, |
154 | 154 | .close = pisnd_input_close, |
155 | 155 | .trigger = pisnd_input_trigger, |
@@ -226,6 +226,7 @@ static char g_id[25]; |
226 | 226 | enum { MAX_VERSION_STR_LEN = 6 }; |
227 | 227 | static char g_fw_version[MAX_VERSION_STR_LEN]; |
228 | 228 | static char g_hw_version[MAX_VERSION_STR_LEN]; |
| 229 | +static u32 g_spi_speed_hz; |
229 | 230 |
|
230 | 231 | static uint8_t g_ledFlashDuration; |
231 | 232 | static bool g_ledFlashDurationChanged; |
@@ -329,7 +330,7 @@ static void spi_transfer(const uint8_t *txbuf, uint8_t *rxbuf, int len) |
329 | 330 | transfer.tx_buf = txbuf; |
330 | 331 | transfer.rx_buf = rxbuf; |
331 | 332 | transfer.len = len; |
332 | | - transfer.speed_hz = 150000; |
| 333 | + transfer.speed_hz = g_spi_speed_hz; |
333 | 334 | transfer.delay.value = 10; |
334 | 335 | transfer.delay.unit = SPI_DELAY_UNIT_USECS; |
335 | 336 |
|
@@ -646,6 +647,26 @@ static int pisnd_spi_init(struct device *dev) |
646 | 647 | memset(g_fw_version, 0, sizeof(g_fw_version)); |
647 | 648 | memset(g_hw_version, 0, sizeof(g_hw_version)); |
648 | 649 |
|
| 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 | + |
649 | 670 | spi = pisnd_spi_find_device(); |
650 | 671 |
|
651 | 672 | if (spi != NULL) { |
@@ -950,7 +971,7 @@ static int pisnd_startup(struct snd_pcm_substream *substream) |
950 | 971 | return 0; |
951 | 972 | } |
952 | 973 |
|
953 | | -static struct snd_soc_ops pisnd_ops = { |
| 974 | +static const struct snd_soc_ops pisnd_ops = { |
954 | 975 | .startup = pisnd_startup, |
955 | 976 | .hw_params = pisnd_hw_params, |
956 | 977 | }; |
|
0 commit comments