diff options
author | Lars-Peter Clausen <lars@metafoo.de> | 2013-01-16 07:48:00 -0500 |
---|---|---|
committer | Jonathan Cameron <jic23@kernel.org> | 2013-01-26 05:07:51 -0500 |
commit | 1db18bb4c25823bfc11f370157f9d23a4d99ea1d (patch) | |
tree | 7ca075b04e1aaaa95786f3c48adf58dd53ed14a0 | |
parent | 7ba8a04dcdfb5ebcb4985a92dfc4dc4f59510464 (diff) |
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>
-rw-r--r-- | drivers/iio/imu/adis16400.h | 4 | ||||
-rw-r--r-- | drivers/iio/imu/adis16400_core.c | 113 |
2 files changed, 113 insertions, 4 deletions
diff --git a/drivers/iio/imu/adis16400.h b/drivers/iio/imu/adis16400.h index a3b9e56c5bd1..627018537aac 100644 --- a/drivers/iio/imu/adis16400.h +++ b/drivers/iio/imu/adis16400.h | |||
@@ -74,7 +74,10 @@ | |||
74 | #define ADIS16400_ALM_CTRL 0x48 /* Alarm control */ | 74 | #define ADIS16400_ALM_CTRL 0x48 /* Alarm control */ |
75 | #define ADIS16400_AUX_DAC 0x4A /* Auxiliary DAC data */ | 75 | #define ADIS16400_AUX_DAC 0x4A /* Auxiliary DAC data */ |
76 | 76 | ||
77 | #define ADIS16334_LOT_ID1 0x52 /* Lot identification code 1 */ | ||
78 | #define ADIS16334_LOT_ID2 0x54 /* Lot identification code 2 */ | ||
77 | #define ADIS16400_PRODUCT_ID 0x56 /* Product identifier */ | 79 | #define ADIS16400_PRODUCT_ID 0x56 /* Product identifier */ |
80 | #define ADIS16334_SERIAL_NUMBER 0x58 /* Serial number, lot specific */ | ||
78 | 81 | ||
79 | #define ADIS16400_ERROR_ACTIVE (1<<14) | 82 | #define ADIS16400_ERROR_ACTIVE (1<<14) |
80 | #define ADIS16400_NEW_DATA (1<<14) | 83 | #define ADIS16400_NEW_DATA (1<<14) |
@@ -132,6 +135,7 @@ | |||
132 | #define ADIS16400_HAS_PROD_ID BIT(0) | 135 | #define ADIS16400_HAS_PROD_ID BIT(0) |
133 | #define ADIS16400_NO_BURST BIT(1) | 136 | #define ADIS16400_NO_BURST BIT(1) |
134 | #define ADIS16400_HAS_SLOW_MODE BIT(2) | 137 | #define ADIS16400_HAS_SLOW_MODE BIT(2) |
138 | #define ADIS16400_HAS_SERIAL_NUMBER BIT(3) | ||
135 | 139 | ||
136 | struct adis16400_state; | 140 | struct adis16400_state; |
137 | 141 | ||
diff --git a/drivers/iio/imu/adis16400_core.c b/drivers/iio/imu/adis16400_core.c index 58699ac22d02..e8f84c9e84c6 100644 --- a/drivers/iio/imu/adis16400_core.c +++ b/drivers/iio/imu/adis16400_core.c | |||
@@ -25,6 +25,7 @@ | |||
25 | #include <linux/sysfs.h> | 25 | #include <linux/sysfs.h> |
26 | #include <linux/list.h> | 26 | #include <linux/list.h> |
27 | #include <linux/module.h> | 27 | #include <linux/module.h> |
28 | #include <linux/debugfs.h> | ||
28 | 29 | ||
29 | #include <linux/iio/iio.h> | 30 | #include <linux/iio/iio.h> |
30 | #include <linux/iio/sysfs.h> | 31 | #include <linux/iio/sysfs.h> |
@@ -32,6 +33,104 @@ | |||
32 | 33 | ||
33 | #include "adis16400.h" | 34 | #include "adis16400.h" |
34 | 35 | ||
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 | |||
35 | enum adis16400_chip_variant { | 134 | enum adis16400_chip_variant { |
36 | ADIS16300, | 135 | ADIS16300, |
37 | ADIS16334, | 136 | ADIS16334, |
@@ -600,7 +699,8 @@ static struct adis16400_chip_info adis16400_chips[] = { | |||
600 | [ADIS16334] = { | 699 | [ADIS16334] = { |
601 | .channels = adis16334_channels, | 700 | .channels = adis16334_channels, |
602 | .num_channels = ARRAY_SIZE(adis16334_channels), | 701 | .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, | ||
604 | .gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */ | 704 | .gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */ |
605 | .accel_scale_micro = IIO_G_TO_M_S_2(1000), /* 1 mg */ | 705 | .accel_scale_micro = IIO_G_TO_M_S_2(1000), /* 1 mg */ |
606 | .temp_scale_nano = 67850000, /* 0.06785 C */ | 706 | .temp_scale_nano = 67850000, /* 0.06785 C */ |
@@ -622,7 +722,8 @@ static struct adis16400_chip_info adis16400_chips[] = { | |||
622 | [ADIS16360] = { | 722 | [ADIS16360] = { |
623 | .channels = adis16350_channels, | 723 | .channels = adis16350_channels, |
624 | .num_channels = ARRAY_SIZE(adis16350_channels), | 724 | .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, | ||
626 | .gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */ | 727 | .gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */ |
627 | .accel_scale_micro = IIO_G_TO_M_S_2(3333), /* 3.333 mg */ | 728 | .accel_scale_micro = IIO_G_TO_M_S_2(3333), /* 3.333 mg */ |
628 | .temp_scale_nano = 136000000, /* 0.136 C */ | 729 | .temp_scale_nano = 136000000, /* 0.136 C */ |
@@ -633,7 +734,8 @@ static struct adis16400_chip_info adis16400_chips[] = { | |||
633 | [ADIS16362] = { | 734 | [ADIS16362] = { |
634 | .channels = adis16350_channels, | 735 | .channels = adis16350_channels, |
635 | .num_channels = ARRAY_SIZE(adis16350_channels), | 736 | .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, | ||
637 | .gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */ | 739 | .gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */ |
638 | .accel_scale_micro = IIO_G_TO_M_S_2(333), /* 0.333 mg */ | 740 | .accel_scale_micro = IIO_G_TO_M_S_2(333), /* 0.333 mg */ |
639 | .temp_scale_nano = 136000000, /* 0.136 C */ | 741 | .temp_scale_nano = 136000000, /* 0.136 C */ |
@@ -644,7 +746,8 @@ static struct adis16400_chip_info adis16400_chips[] = { | |||
644 | [ADIS16364] = { | 746 | [ADIS16364] = { |
645 | .channels = adis16350_channels, | 747 | .channels = adis16350_channels, |
646 | .num_channels = ARRAY_SIZE(adis16350_channels), | 748 | .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, | ||
648 | .gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */ | 751 | .gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */ |
649 | .accel_scale_micro = IIO_G_TO_M_S_2(1000), /* 1 mg */ | 752 | .accel_scale_micro = IIO_G_TO_M_S_2(1000), /* 1 mg */ |
650 | .temp_scale_nano = 136000000, /* 0.136 C */ | 753 | .temp_scale_nano = 136000000, /* 0.136 C */ |
@@ -671,6 +774,7 @@ static const struct iio_info adis16400_info = { | |||
671 | .write_raw = &adis16400_write_raw, | 774 | .write_raw = &adis16400_write_raw, |
672 | .attrs = &adis16400_attribute_group, | 775 | .attrs = &adis16400_attribute_group, |
673 | .update_scan_mode = adis16400_update_scan_mode, | 776 | .update_scan_mode = adis16400_update_scan_mode, |
777 | .debugfs_reg_access = adis_debugfs_reg_access, | ||
674 | }; | 778 | }; |
675 | 779 | ||
676 | static const unsigned long adis16400_burst_scan_mask[] = { | 780 | static const unsigned long adis16400_burst_scan_mask[] = { |
@@ -768,6 +872,7 @@ static int adis16400_probe(struct spi_device *spi) | |||
768 | if (ret) | 872 | if (ret) |
769 | goto error_cleanup_buffer; | 873 | goto error_cleanup_buffer; |
770 | 874 | ||
875 | adis16400_debugfs_init(indio_dev); | ||
771 | return 0; | 876 | return 0; |
772 | 877 | ||
773 | error_cleanup_buffer: | 878 | error_cleanup_buffer: |