1 From a879ab9cad6b598c08988404934273d3cbfbd993 Mon Sep 17 00:00:00 2001
2 From: gtrainavicius <gtrainavicius@users.noreply.github.com>
3 Date: Tue, 28 Jan 2020 14:16:37 +0200
4 Subject: [PATCH] pisound: Added reading Pisound board hardware
5 revision and exposing it (#3425)
7 pisound: Added reading Pisound board hardware revision and exposing it in kernel log and sysfs file:
9 /sys/kernel/pisound/hw_version
11 Signed-off-by: Giedrius <giedrius@blokas.io>
13 sound/soc/bcm/pisound.c | 86 ++++++++++++++++++++++++++++-------------
14 1 file changed, 59 insertions(+), 27 deletions(-)
16 --- a/sound/soc/bcm/pisound.c
17 +++ b/sound/soc/bcm/pisound.c
18 @@ -51,7 +51,8 @@ static void pisnd_spi_set_callback(pisnd
20 static const char *pisnd_spi_get_serial(void);
21 static const char *pisnd_spi_get_id(void);
22 -static const char *pisnd_spi_get_version(void);
23 +static const char *pisnd_spi_get_fw_version(void);
24 +static const char *pisnd_spi_get_hw_version(void);
26 static int pisnd_midi_init(struct snd_card *card);
27 static void pisnd_midi_uninit(void);
28 @@ -222,7 +223,9 @@ static pisnd_spi_recv_cb g_recvCallback;
30 static char g_serial_num[11];
32 -static char g_version[5];
33 +enum { MAX_VERSION_STR_LEN = 6 };
34 +static char g_fw_version[MAX_VERSION_STR_LEN];
35 +static char g_hw_version[MAX_VERSION_STR_LEN];
37 static uint8_t g_ledFlashDuration;
38 static bool g_ledFlashDurationChanged;
39 @@ -558,7 +561,8 @@ static int spi_read_info(void)
42 memset(g_serial_num, 0, sizeof(g_serial_num));
43 - memset(g_version, 0, sizeof(g_version));
44 + memset(g_fw_version, 0, sizeof(g_fw_version));
45 + strcpy(g_hw_version, "1.0"); // Assume 1.0 hw version.
46 memset(g_id, 0, sizeof(g_id));
48 tmp = spi_transfer16(0);
49 @@ -581,12 +585,28 @@ static int spi_read_info(void)
56 + MAX_VERSION_STR_LEN,
62 + g_fw_version[MAX_VERSION_STR_LEN-1] = '\0';
70 + MAX_VERSION_STR_LEN,
76 + g_hw_version[MAX_VERSION_STR_LEN-1] = '\0';
79 if (n >= sizeof(g_serial_num))
80 @@ -596,12 +616,14 @@ static int spi_read_info(void)
84 - if (n >= sizeof(g_id))
85 + if (n*2 >= sizeof(g_id))
89 for (j = 0; j < n; ++j)
90 p += sprintf(p, "%02x", buffer[j]);
96 @@ -619,7 +641,8 @@ static int pisnd_spi_init(struct device
98 memset(g_serial_num, 0, sizeof(g_serial_num));
99 memset(g_id, 0, sizeof(g_id));
100 - memset(g_version, 0, sizeof(g_version));
101 + memset(g_fw_version, 0, sizeof(g_fw_version));
102 + memset(g_hw_version, 0, sizeof(g_hw_version));
104 spi = pisnd_spi_find_device();
106 @@ -729,26 +752,22 @@ static void pisnd_spi_set_callback(pisnd
108 static const char *pisnd_spi_get_serial(void)
110 - if (strlen(g_serial_num))
111 - return g_serial_num;
114 + return g_serial_num;
117 static const char *pisnd_spi_get_id(void)
126 -static const char *pisnd_spi_get_version(void)
127 +static const char *pisnd_spi_get_fw_version(void)
129 - if (strlen(g_version))
131 + return g_fw_version;
135 +static const char *pisnd_spi_get_hw_version(void)
137 + return g_hw_version;
140 static const struct of_device_id pisound_of_match[] = {
141 @@ -1054,13 +1073,22 @@ static ssize_t pisnd_id_show(
142 return sprintf(buf, "%s\n", pisnd_spi_get_id());
145 -static ssize_t pisnd_version_show(
146 +static ssize_t pisnd_fw_version_show(
147 struct kobject *kobj,
148 struct kobj_attribute *attr,
152 - return sprintf(buf, "%s\n", pisnd_spi_get_version());
153 + return sprintf(buf, "%s\n", pisnd_spi_get_fw_version());
156 +static ssize_t pisnd_hw_version_show(
157 + struct kobject *kobj,
158 + struct kobj_attribute *attr,
162 + return sprintf(buf, "%s\n", pisnd_spi_get_hw_version());
165 static ssize_t pisnd_led_store(
166 @@ -1085,15 +1113,18 @@ static struct kobj_attribute pisnd_seria
167 __ATTR(serial, 0444, pisnd_serial_show, NULL);
168 static struct kobj_attribute pisnd_id_attribute =
169 __ATTR(id, 0444, pisnd_id_show, NULL);
170 -static struct kobj_attribute pisnd_version_attribute =
171 - __ATTR(version, 0444, pisnd_version_show, NULL);
172 +static struct kobj_attribute pisnd_fw_version_attribute =
173 + __ATTR(version, 0444, pisnd_fw_version_show, NULL);
174 +static struct kobj_attribute pisnd_hw_version_attribute =
175 +__ATTR(hw_version, 0444, pisnd_hw_version_show, NULL);
176 static struct kobj_attribute pisnd_led_attribute =
177 __ATTR(led, 0644, NULL, pisnd_led_store);
179 static struct attribute *attrs[] = {
180 &pisnd_serial_attribute.attr,
181 &pisnd_id_attribute.attr,
182 - &pisnd_version_attribute.attr,
183 + &pisnd_fw_version_attribute.attr,
184 + &pisnd_hw_version_attribute.attr,
185 &pisnd_led_attribute.attr,
188 @@ -1112,9 +1143,10 @@ static int pisnd_probe(struct platform_d
191 printi("Detected Pisound card:\n");
192 - printi("\tSerial: %s\n", pisnd_spi_get_serial());
193 - printi("\tVersion: %s\n", pisnd_spi_get_version());
194 - printi("\tId: %s\n", pisnd_spi_get_id());
195 + printi("\tSerial: %s\n", pisnd_spi_get_serial());
196 + printi("\tFirmware Version: %s\n", pisnd_spi_get_fw_version());
197 + printi("\tHardware Version: %s\n", pisnd_spi_get_hw_version());
198 + printi("\tId: %s\n", pisnd_spi_get_id());
200 pisnd_kobj = kobject_create_and_add("pisound", kernel_kobj);