diff options
Diffstat (limited to 'drivers/iio/imu/adis16400_core.c')
-rw-r--r-- | drivers/iio/imu/adis16400_core.c | 113 |
1 files changed, 109 insertions, 4 deletions
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: |