Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pisound: Added reading Pisound board hardware revision and exposing it #3425

Merged
merged 3 commits into from
Jan 28, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 55 additions & 17 deletions sound/soc/bcm/pisound.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ static void pisnd_spi_set_callback(pisnd_spi_recv_cb cb, void *data);

static const char *pisnd_spi_get_serial(void);
static const char *pisnd_spi_get_id(void);
static const char *pisnd_spi_get_version(void);
static const char *pisnd_spi_get_fw_version(void);
static const char *pisnd_spi_get_hw_version(void);

static int pisnd_midi_init(struct snd_card *card);
static void pisnd_midi_uninit(void);
Expand Down Expand Up @@ -222,7 +223,9 @@ static pisnd_spi_recv_cb g_recvCallback;

static char g_serial_num[11];
static char g_id[25];
static char g_version[5];
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 uint8_t g_ledFlashDuration;
static bool g_ledFlashDurationChanged;
Expand Down Expand Up @@ -558,7 +561,8 @@ static int spi_read_info(void)
char *p;

memset(g_serial_num, 0, sizeof(g_serial_num));
memset(g_version, 0, sizeof(g_version));
memset(g_fw_version, 0, sizeof(g_fw_version));
strcpy(g_hw_version, "1.0"); // Assume 1.0 hw version.
memset(g_id, 0, sizeof(g_id));

tmp = spi_transfer16(0);
Expand All @@ -581,13 +585,25 @@ static int spi_read_info(void)
return -EINVAL;

snprintf(
g_version,
sizeof(g_version),
g_fw_version,
pelwell marked this conversation as resolved.
Show resolved Hide resolved
MAX_VERSION_STR_LEN,
"%x.%02x",
buffer[0],
buffer[1]
);
break;
case 3:
if (n != 2)
return -EINVAL;

snprintf(
g_hw_version,
MAX_VERSION_STR_LEN,
"%x.%x",
buffer[0],
buffer[1]
);
break;
case 1:
if (n >= sizeof(g_serial_num))
return -EINVAL;
Expand Down Expand Up @@ -619,7 +635,8 @@ static int pisnd_spi_init(struct device *dev)

memset(g_serial_num, 0, sizeof(g_serial_num));
memset(g_id, 0, sizeof(g_id));
memset(g_version, 0, sizeof(g_version));
memset(g_fw_version, 0, sizeof(g_fw_version));
memset(g_hw_version, 0, sizeof(g_hw_version));

spi = pisnd_spi_find_device();

Expand Down Expand Up @@ -743,10 +760,18 @@ static const char *pisnd_spi_get_id(void)
return "";
}

static const char *pisnd_spi_get_version(void)
static const char *pisnd_spi_get_fw_version(void)
pelwell marked this conversation as resolved.
Show resolved Hide resolved
{
if (strlen(g_version))
return g_version;
if (strlen(g_fw_version))
return g_fw_version;

return "";
}

static const char *pisnd_spi_get_hw_version(void)
{
if (strlen(g_hw_version))
return g_hw_version;

return "";
}
Expand Down Expand Up @@ -1054,13 +1079,22 @@ static ssize_t pisnd_id_show(
return sprintf(buf, "%s\n", pisnd_spi_get_id());
}

static ssize_t pisnd_version_show(
static ssize_t pisnd_fw_version_show(
struct kobject *kobj,
struct kobj_attribute *attr,
char *buf
)
{
return sprintf(buf, "%s\n", pisnd_spi_get_version());
return sprintf(buf, "%s\n", pisnd_spi_get_fw_version());
}

static ssize_t pisnd_hw_version_show(
struct kobject *kobj,
struct kobj_attribute *attr,
char *buf
)
{
return sprintf(buf, "%s\n", pisnd_spi_get_hw_version());
}

static ssize_t pisnd_led_store(
Expand All @@ -1085,15 +1119,18 @@ static struct kobj_attribute pisnd_serial_attribute =
__ATTR(serial, 0444, pisnd_serial_show, NULL);
static struct kobj_attribute pisnd_id_attribute =
__ATTR(id, 0444, pisnd_id_show, NULL);
static struct kobj_attribute pisnd_version_attribute =
__ATTR(version, 0444, pisnd_version_show, NULL);
static struct kobj_attribute pisnd_fw_version_attribute =
__ATTR(version, 0444, pisnd_fw_version_show, NULL);
static struct kobj_attribute pisnd_hw_version_attribute =
__ATTR(hw_version, 0444, pisnd_hw_version_show, NULL);
static struct kobj_attribute pisnd_led_attribute =
__ATTR(led, 0644, NULL, pisnd_led_store);

static struct attribute *attrs[] = {
&pisnd_serial_attribute.attr,
&pisnd_id_attribute.attr,
&pisnd_version_attribute.attr,
&pisnd_fw_version_attribute.attr,
&pisnd_hw_version_attribute.attr,
&pisnd_led_attribute.attr,
NULL
};
Expand All @@ -1112,9 +1149,10 @@ static int pisnd_probe(struct platform_device *pdev)
}

printi("Detected Pisound card:\n");
printi("\tSerial: %s\n", pisnd_spi_get_serial());
printi("\tVersion: %s\n", pisnd_spi_get_version());
printi("\tId: %s\n", pisnd_spi_get_id());
printi("\tSerial: %s\n", pisnd_spi_get_serial());
printi("\tFirmware Version: %s\n", pisnd_spi_get_fw_version());
printi("\tHardware Version: %s\n", pisnd_spi_get_hw_version());
printi("\tId: %s\n", pisnd_spi_get_id());

pisnd_kobj = kobject_create_and_add("pisound", kernel_kobj);
if (!pisnd_kobj) {
Expand Down