Skip to content

Commit 1db18bb

Browse files
larsclausenjic23
authored andcommitted
iio:adis16400: Expose some debug information in debugfs
Expose some information useful for debugging a device in debugfs. This includes for now the flash count, the product id and the serial number and raw register access. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
1 parent 7ba8a04 commit 1db18bb

File tree

2 files changed

+113
-4
lines changed

2 files changed

+113
-4
lines changed

drivers/iio/imu/adis16400.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,10 @@
7474
#define ADIS16400_ALM_CTRL 0x48 /* Alarm control */
7575
#define ADIS16400_AUX_DAC 0x4A /* Auxiliary DAC data */
7676

77+
#define ADIS16334_LOT_ID1 0x52 /* Lot identification code 1 */
78+
#define ADIS16334_LOT_ID2 0x54 /* Lot identification code 2 */
7779
#define ADIS16400_PRODUCT_ID 0x56 /* Product identifier */
80+
#define ADIS16334_SERIAL_NUMBER 0x58 /* Serial number, lot specific */
7881

7982
#define ADIS16400_ERROR_ACTIVE (1<<14)
8083
#define ADIS16400_NEW_DATA (1<<14)
@@ -132,6 +135,7 @@
132135
#define ADIS16400_HAS_PROD_ID BIT(0)
133136
#define ADIS16400_NO_BURST BIT(1)
134137
#define ADIS16400_HAS_SLOW_MODE BIT(2)
138+
#define ADIS16400_HAS_SERIAL_NUMBER BIT(3)
135139

136140
struct adis16400_state;
137141

drivers/iio/imu/adis16400_core.c

Lines changed: 109 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,112 @@
2525
#include <linux/sysfs.h>
2626
#include <linux/list.h>
2727
#include <linux/module.h>
28+
#include <linux/debugfs.h>
2829

2930
#include <linux/iio/iio.h>
3031
#include <linux/iio/sysfs.h>
3132
#include <linux/iio/buffer.h>
3233

3334
#include "adis16400.h"
3435

36+
#ifdef CONFIG_DEBUG_FS
37+
38+
static ssize_t adis16400_show_serial_number(struct file *file,
39+
char __user *userbuf, size_t count, loff_t *ppos)
40+
{
41+
struct adis16400_state *st = file->private_data;
42+
u16 lot1, lot2, serial_number;
43+
char buf[16];
44+
size_t len;
45+
int ret;
46+
47+
ret = adis_read_reg_16(&st->adis, ADIS16334_LOT_ID1, &lot1);
48+
if (ret < 0)
49+
return ret;
50+
51+
ret = adis_read_reg_16(&st->adis, ADIS16334_LOT_ID2, &lot2);
52+
if (ret < 0)
53+
return ret;
54+
55+
ret = adis_read_reg_16(&st->adis, ADIS16334_SERIAL_NUMBER,
56+
&serial_number);
57+
if (ret < 0)
58+
return ret;
59+
60+
len = snprintf(buf, sizeof(buf), "%.4x-%.4x-%.4x\n", lot1, lot2,
61+
serial_number);
62+
63+
return simple_read_from_buffer(userbuf, count, ppos, buf, len);
64+
}
65+
66+
static const struct file_operations adis16400_serial_number_fops = {
67+
.open = simple_open,
68+
.read = adis16400_show_serial_number,
69+
.llseek = default_llseek,
70+
.owner = THIS_MODULE,
71+
};
72+
73+
static int adis16400_show_product_id(void *arg, u64 *val)
74+
{
75+
struct adis16400_state *st = arg;
76+
uint16_t prod_id;
77+
int ret;
78+
79+
ret = adis_read_reg_16(&st->adis, ADIS16400_PRODUCT_ID, &prod_id);
80+
if (ret < 0)
81+
return ret;
82+
83+
*val = prod_id;
84+
85+
return 0;
86+
}
87+
DEFINE_SIMPLE_ATTRIBUTE(adis16400_product_id_fops,
88+
adis16400_show_product_id, NULL, "%lld\n");
89+
90+
static int adis16400_show_flash_count(void *arg, u64 *val)
91+
{
92+
struct adis16400_state *st = arg;
93+
uint16_t flash_count;
94+
int ret;
95+
96+
ret = adis_read_reg_16(&st->adis, ADIS16400_FLASH_CNT, &flash_count);
97+
if (ret < 0)
98+
return ret;
99+
100+
*val = flash_count;
101+
102+
return 0;
103+
}
104+
DEFINE_SIMPLE_ATTRIBUTE(adis16400_flash_count_fops,
105+
adis16400_show_flash_count, NULL, "%lld\n");
106+
107+
static int adis16400_debugfs_init(struct iio_dev *indio_dev)
108+
{
109+
struct adis16400_state *st = iio_priv(indio_dev);
110+
111+
if (st->variant->flags & ADIS16400_HAS_SERIAL_NUMBER)
112+
debugfs_create_file("serial_number", 0400,
113+
indio_dev->debugfs_dentry, st,
114+
&adis16400_serial_number_fops);
115+
if (st->variant->flags & ADIS16400_HAS_PROD_ID)
116+
debugfs_create_file("product_id", 0400,
117+
indio_dev->debugfs_dentry, st,
118+
&adis16400_product_id_fops);
119+
debugfs_create_file("flash_count", 0400, indio_dev->debugfs_dentry,
120+
st, &adis16400_flash_count_fops);
121+
122+
return 0;
123+
}
124+
125+
#else
126+
127+
static int adis16400_debugfs_init(struct iio_dev *indio_dev)
128+
{
129+
return 0;
130+
}
131+
132+
#endif
133+
35134
enum adis16400_chip_variant {
36135
ADIS16300,
37136
ADIS16334,
@@ -600,7 +699,8 @@ static struct adis16400_chip_info adis16400_chips[] = {
600699
[ADIS16334] = {
601700
.channels = adis16334_channels,
602701
.num_channels = ARRAY_SIZE(adis16334_channels),
603-
.flags = ADIS16400_HAS_PROD_ID,
702+
.flags = ADIS16400_HAS_PROD_ID | ADIS16400_NO_BURST |
703+
ADIS16400_HAS_SERIAL_NUMBER,
604704
.gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */
605705
.accel_scale_micro = IIO_G_TO_M_S_2(1000), /* 1 mg */
606706
.temp_scale_nano = 67850000, /* 0.06785 C */
@@ -622,7 +722,8 @@ static struct adis16400_chip_info adis16400_chips[] = {
622722
[ADIS16360] = {
623723
.channels = adis16350_channels,
624724
.num_channels = ARRAY_SIZE(adis16350_channels),
625-
.flags = ADIS16400_HAS_PROD_ID | ADIS16400_HAS_SLOW_MODE,
725+
.flags = ADIS16400_HAS_PROD_ID | ADIS16400_HAS_SLOW_MODE |
726+
ADIS16400_HAS_SERIAL_NUMBER,
626727
.gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */
627728
.accel_scale_micro = IIO_G_TO_M_S_2(3333), /* 3.333 mg */
628729
.temp_scale_nano = 136000000, /* 0.136 C */
@@ -633,7 +734,8 @@ static struct adis16400_chip_info adis16400_chips[] = {
633734
[ADIS16362] = {
634735
.channels = adis16350_channels,
635736
.num_channels = ARRAY_SIZE(adis16350_channels),
636-
.flags = ADIS16400_HAS_PROD_ID | ADIS16400_HAS_SLOW_MODE,
737+
.flags = ADIS16400_HAS_PROD_ID | ADIS16400_HAS_SLOW_MODE |
738+
ADIS16400_HAS_SERIAL_NUMBER,
637739
.gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */
638740
.accel_scale_micro = IIO_G_TO_M_S_2(333), /* 0.333 mg */
639741
.temp_scale_nano = 136000000, /* 0.136 C */
@@ -644,7 +746,8 @@ static struct adis16400_chip_info adis16400_chips[] = {
644746
[ADIS16364] = {
645747
.channels = adis16350_channels,
646748
.num_channels = ARRAY_SIZE(adis16350_channels),
647-
.flags = ADIS16400_HAS_PROD_ID | ADIS16400_HAS_SLOW_MODE,
749+
.flags = ADIS16400_HAS_PROD_ID | ADIS16400_HAS_SLOW_MODE |
750+
ADIS16400_HAS_SERIAL_NUMBER,
648751
.gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */
649752
.accel_scale_micro = IIO_G_TO_M_S_2(1000), /* 1 mg */
650753
.temp_scale_nano = 136000000, /* 0.136 C */
@@ -671,6 +774,7 @@ static const struct iio_info adis16400_info = {
671774
.write_raw = &adis16400_write_raw,
672775
.attrs = &adis16400_attribute_group,
673776
.update_scan_mode = adis16400_update_scan_mode,
777+
.debugfs_reg_access = adis_debugfs_reg_access,
674778
};
675779

676780
static const unsigned long adis16400_burst_scan_mask[] = {
@@ -768,6 +872,7 @@ static int adis16400_probe(struct spi_device *spi)
768872
if (ret)
769873
goto error_cleanup_buffer;
770874

875+
adis16400_debugfs_init(indio_dev);
771876
return 0;
772877

773878
error_cleanup_buffer:

0 commit comments

Comments
 (0)