bcm27xx-gpu-fw: update to latest version
[openwrt/openwrt.git] / target / linux / bcm27xx / patches-5.4 / 950-0372-Pisound-MIDI-communication-fixes-for-scaled-down-CPU.patch
1 From 67dd4d137557909279a21c1b5de87a24c84903f9 Mon Sep 17 00:00:00 2001
2 From: Giedrius <giedrius@blokas.io>
3 Date: Tue, 7 Jan 2020 11:04:21 +0200
4 Subject: [PATCH] Pisound: MIDI communication fixes for scaled down
5 CPU.
6 MIME-Version: 1.0
7 Content-Type: text/plain; charset=UTF-8
8 Content-Transfer-Encoding: 8bit
9
10 * Increased maximum SPI communication speed to avoid running too slow
11 when the CPU is scaled down and losing MIDI data.
12
13 * Keep track of buffer usage in millibytes for higher precision.
14
15 Signed-off-by: Giedrius Trainavičius <giedrius@blokas.io>
16 ---
17 sound/soc/bcm/pisound.c | 31 ++++++++++++++++++-------------
18 1 file changed, 18 insertions(+), 13 deletions(-)
19
20 --- a/sound/soc/bcm/pisound.c
21 +++ b/sound/soc/bcm/pisound.c
22 @@ -1,6 +1,6 @@
23 /*
24 * Pisound Linux kernel module.
25 - * Copyright (C) 2016-2019 Vilniaus Blokas UAB, https://blokas.io/pisound
26 + * Copyright (C) 2016-2020 Vilniaus Blokas UAB, https://blokas.io/pisound
27 *
28 * This program is free software; you can redistribute it and/or
29 * modify it under the terms of the GNU General Public License
30 @@ -326,7 +326,7 @@ static void spi_transfer(const uint8_t *
31 transfer.tx_buf = txbuf;
32 transfer.rx_buf = rxbuf;
33 transfer.len = len;
34 - transfer.speed_hz = 100000;
35 + transfer.speed_hz = 150000;
36 transfer.delay_usecs = 10;
37 spi_message_add_tail(&transfer, &msg);
38
39 @@ -403,9 +403,9 @@ static struct spi_device *pisnd_spi_find
40 static void pisnd_work_handler(struct work_struct *work)
41 {
42 enum { TRANSFER_SIZE = 4 };
43 - enum { PISOUND_OUTPUT_BUFFER_SIZE = 128 };
44 - enum { MIDI_BYTES_PER_SECOND = 3125 };
45 - int out_buffer_used = 0;
46 + enum { PISOUND_OUTPUT_BUFFER_SIZE_MILLIBYTES = 127 * 1000 };
47 + enum { MIDI_MILLIBYTES_PER_JIFFIE = (3125 * 1000) / HZ };
48 + int out_buffer_used_millibytes = 0;
49 unsigned long now;
50 uint8_t val;
51 uint8_t txbuf[TRANSFER_SIZE];
52 @@ -445,7 +445,9 @@ static void pisnd_work_handler(struct wo
53 had_data = false;
54 memset(txbuf, 0, sizeof(txbuf));
55 for (i = 0; i < sizeof(txbuf) &&
56 - out_buffer_used < PISOUND_OUTPUT_BUFFER_SIZE;
57 + ((out_buffer_used_millibytes+1000 <
58 + PISOUND_OUTPUT_BUFFER_SIZE_MILLIBYTES) ||
59 + g_ledFlashDurationChanged);
60 i += 2) {
61
62 val = 0;
63 @@ -458,7 +460,7 @@ static void pisnd_work_handler(struct wo
64 } else if (kfifo_get(&spi_fifo_out, &val)) {
65 txbuf[i+0] = 0x0f;
66 txbuf[i+1] = val;
67 - ++out_buffer_used;
68 + out_buffer_used_millibytes += 1000;
69 }
70 }
71
72 @@ -469,12 +471,14 @@ static void pisnd_work_handler(struct wo
73 * rate.
74 */
75 now = jiffies;
76 - out_buffer_used -=
77 - (MIDI_BYTES_PER_SECOND / HZ) /
78 - (now - last_transfer_at);
79 - if (out_buffer_used < 0)
80 - out_buffer_used = 0;
81 - last_transfer_at = now;
82 + if (now != last_transfer_at) {
83 + out_buffer_used_millibytes -=
84 + (now - last_transfer_at) *
85 + MIDI_MILLIBYTES_PER_JIFFIE;
86 + if (out_buffer_used_millibytes < 0)
87 + out_buffer_used_millibytes = 0;
88 + last_transfer_at = now;
89 + }
90
91 for (i = 0; i < sizeof(rxbuf); i += 2) {
92 if (rxbuf[i]) {
93 @@ -489,6 +493,7 @@ static void pisnd_work_handler(struct wo
94 || !kfifo_is_empty(&spi_fifo_out)
95 || pisnd_spi_has_more()
96 || g_ledFlashDurationChanged
97 + || out_buffer_used_millibytes != 0
98 );
99
100 if (!kfifo_is_empty(&spi_fifo_in) && g_recvCallback)