diff options
author | Lars-Peter Clausen <lars@metafoo.de> | 2012-11-13 08:28:00 -0500 |
---|---|---|
committer | Jonathan Cameron <jic23@kernel.org> | 2012-11-19 17:22:08 -0500 |
commit | 5cb7cb1191fc8fc0fcf9a1cc43b9ed7168c5c44a (patch) | |
tree | 705990f526adca93a1e6f1db1a4899df95a28efb /drivers/staging | |
parent | edcf600912d218a1d8a6378e37b19ecab63abddd (diff) |
staging:iio:adis16240: Use adis library
Use the new adis library for the adis16240 driver. This allows us to completely
scrap the adis16240 buffer and trigger code and more than half of the core
driver code.
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Diffstat (limited to 'drivers/staging')
-rw-r--r-- | drivers/staging/iio/accel/Kconfig | 5 | ||||
-rw-r--r-- | drivers/staging/iio/accel/Makefile | 1 | ||||
-rw-r--r-- | drivers/staging/iio/accel/adis16240.h | 85 | ||||
-rw-r--r-- | drivers/staging/iio/accel/adis16240_core.c | 472 | ||||
-rw-r--r-- | drivers/staging/iio/accel/adis16240_ring.c | 132 | ||||
-rw-r--r-- | drivers/staging/iio/accel/adis16240_trigger.c | 73 |
6 files changed, 77 insertions, 691 deletions
diff --git a/drivers/staging/iio/accel/Kconfig b/drivers/staging/iio/accel/Kconfig index affa732ef517..2b54430f2d99 100644 --- a/drivers/staging/iio/accel/Kconfig +++ b/drivers/staging/iio/accel/Kconfig | |||
@@ -42,6 +42,7 @@ config ADIS16209 | |||
42 | config ADIS16220 | 42 | config ADIS16220 |
43 | tristate "Analog Devices ADIS16220 Programmable Digital Vibration Sensor" | 43 | tristate "Analog Devices ADIS16220 Programmable Digital Vibration Sensor" |
44 | depends on SPI | 44 | depends on SPI |
45 | select IIO_ADIS_LIB | ||
45 | help | 46 | help |
46 | Say yes here to build support for Analog Devices adis16220 programmable | 47 | Say yes here to build support for Analog Devices adis16220 programmable |
47 | digital vibration sensor. | 48 | digital vibration sensor. |
@@ -49,8 +50,8 @@ config ADIS16220 | |||
49 | config ADIS16240 | 50 | config ADIS16240 |
50 | tristate "Analog Devices ADIS16240 Programmable Impact Sensor and Recorder" | 51 | tristate "Analog Devices ADIS16240 Programmable Impact Sensor and Recorder" |
51 | depends on SPI | 52 | depends on SPI |
52 | select IIO_TRIGGER if IIO_BUFFER | 53 | select IIO_ADIS_LIB |
53 | select IIO_SW_RING if IIO_BUFFER | 54 | select IIO_ADIS_LIB_BUFFER if IIO_BUFFER |
54 | help | 55 | help |
55 | Say yes here to build support for Analog Devices adis16240 programmable | 56 | Say yes here to build support for Analog Devices adis16240 programmable |
56 | impact Sensor and recorder. | 57 | impact Sensor and recorder. |
diff --git a/drivers/staging/iio/accel/Makefile b/drivers/staging/iio/accel/Makefile index 3cb9c67a29b8..8e7ee0368519 100644 --- a/drivers/staging/iio/accel/Makefile +++ b/drivers/staging/iio/accel/Makefile | |||
@@ -18,7 +18,6 @@ adis16220-y := adis16220_core.o | |||
18 | obj-$(CONFIG_ADIS16220) += adis16220.o | 18 | obj-$(CONFIG_ADIS16220) += adis16220.o |
19 | 19 | ||
20 | adis16240-y := adis16240_core.o | 20 | adis16240-y := adis16240_core.o |
21 | adis16240-$(CONFIG_IIO_BUFFER) += adis16240_ring.o adis16240_trigger.o | ||
22 | obj-$(CONFIG_ADIS16240) += adis16240.o | 21 | obj-$(CONFIG_ADIS16240) += adis16240.o |
23 | 22 | ||
24 | obj-$(CONFIG_KXSD9) += kxsd9.o | 23 | obj-$(CONFIG_KXSD9) += kxsd9.o |
diff --git a/drivers/staging/iio/accel/adis16240.h b/drivers/staging/iio/accel/adis16240.h index 3fabcc0b3471..d442d49f51f4 100644 --- a/drivers/staging/iio/accel/adis16240.h +++ b/drivers/staging/iio/accel/adis16240.h | |||
@@ -3,9 +3,6 @@ | |||
3 | 3 | ||
4 | #define ADIS16240_STARTUP_DELAY 220 /* ms */ | 4 | #define ADIS16240_STARTUP_DELAY 220 /* ms */ |
5 | 5 | ||
6 | #define ADIS16240_READ_REG(a) a | ||
7 | #define ADIS16240_WRITE_REG(a) ((a) | 0x80) | ||
8 | |||
9 | /* Flash memory write count */ | 6 | /* Flash memory write count */ |
10 | #define ADIS16240_FLASH_CNT 0x00 | 7 | #define ADIS16240_FLASH_CNT 0x00 |
11 | /* Output, power supply */ | 8 | /* Output, power supply */ |
@@ -75,8 +72,6 @@ | |||
75 | /* System command */ | 72 | /* System command */ |
76 | #define ADIS16240_GLOB_CMD 0x4A | 73 | #define ADIS16240_GLOB_CMD 0x4A |
77 | 74 | ||
78 | #define ADIS16240_OUTPUTS 6 | ||
79 | |||
80 | /* MSC_CTRL */ | 75 | /* MSC_CTRL */ |
81 | /* Enables sum-of-squares output (XYZPEAK_OUT) */ | 76 | /* Enables sum-of-squares output (XYZPEAK_OUT) */ |
82 | #define ADIS16240_MSC_CTRL_XYZPEAK_OUT_EN (1 << 15) | 77 | #define ADIS16240_MSC_CTRL_XYZPEAK_OUT_EN (1 << 15) |
@@ -101,17 +96,17 @@ | |||
101 | /* Flash test, checksum flag: 1 = mismatch, 0 = match */ | 96 | /* Flash test, checksum flag: 1 = mismatch, 0 = match */ |
102 | #define ADIS16240_DIAG_STAT_CHKSUM (1<<6) | 97 | #define ADIS16240_DIAG_STAT_CHKSUM (1<<6) |
103 | /* Power-on, self-test flag: 1 = failure, 0 = pass */ | 98 | /* Power-on, self-test flag: 1 = failure, 0 = pass */ |
104 | #define ADIS16240_DIAG_STAT_PWRON_FAIL (1<<5) | 99 | #define ADIS16240_DIAG_STAT_PWRON_FAIL_BIT 5 |
105 | /* Power-on self-test: 1 = in-progress, 0 = complete */ | 100 | /* Power-on self-test: 1 = in-progress, 0 = complete */ |
106 | #define ADIS16240_DIAG_STAT_PWRON_BUSY (1<<4) | 101 | #define ADIS16240_DIAG_STAT_PWRON_BUSY (1<<4) |
107 | /* SPI communications failure */ | 102 | /* SPI communications failure */ |
108 | #define ADIS16240_DIAG_STAT_SPI_FAIL (1<<3) | 103 | #define ADIS16240_DIAG_STAT_SPI_FAIL_BIT 3 |
109 | /* Flash update failure */ | 104 | /* Flash update failure */ |
110 | #define ADIS16240_DIAG_STAT_FLASH_UPT (1<<2) | 105 | #define ADIS16240_DIAG_STAT_FLASH_UPT_BIT 2 |
111 | /* Power supply above 3.625 V */ | 106 | /* Power supply above 3.625 V */ |
112 | #define ADIS16240_DIAG_STAT_POWER_HIGH (1<<1) | 107 | #define ADIS16240_DIAG_STAT_POWER_HIGH_BIT 1 |
113 | /* Power supply below 3.15 V */ | 108 | /* Power supply below 3.15 V */ |
114 | #define ADIS16240_DIAG_STAT_POWER_LOW (1<<0) | 109 | #define ADIS16240_DIAG_STAT_POWER_LOW_BIT 0 |
115 | 110 | ||
116 | /* GLOB_CMD */ | 111 | /* GLOB_CMD */ |
117 | #define ADIS16240_GLOB_CMD_RESUME (1<<8) | 112 | #define ADIS16240_GLOB_CMD_RESUME (1<<8) |
@@ -120,77 +115,15 @@ | |||
120 | 115 | ||
121 | #define ADIS16240_ERROR_ACTIVE (1<<14) | 116 | #define ADIS16240_ERROR_ACTIVE (1<<14) |
122 | 117 | ||
123 | #define ADIS16240_MAX_TX 24 | ||
124 | #define ADIS16240_MAX_RX 24 | ||
125 | |||
126 | /** | ||
127 | * struct adis16240_state - device instance specific data | ||
128 | * @us: actual spi_device | ||
129 | * @trig: data ready trigger registered with iio | ||
130 | * @tx: transmit buffer | ||
131 | * @rx: receive buffer | ||
132 | * @buf_lock: mutex to protect tx and rx | ||
133 | **/ | ||
134 | struct adis16240_state { | ||
135 | struct spi_device *us; | ||
136 | struct iio_trigger *trig; | ||
137 | struct mutex buf_lock; | ||
138 | u8 tx[ADIS16240_MAX_TX] ____cacheline_aligned; | ||
139 | u8 rx[ADIS16240_MAX_RX]; | ||
140 | }; | ||
141 | |||
142 | int adis16240_set_irq(struct iio_dev *indio_dev, bool enable); | ||
143 | |||
144 | /* At the moment triggers are only used for ring buffer | 118 | /* At the moment triggers are only used for ring buffer |
145 | * filling. This may change! | 119 | * filling. This may change! |
146 | */ | 120 | */ |
147 | 121 | ||
148 | #define ADIS16240_SCAN_SUPPLY 0 | 122 | #define ADIS16240_SCAN_ACC_X 0 |
149 | #define ADIS16240_SCAN_ACC_X 1 | 123 | #define ADIS16240_SCAN_ACC_Y 1 |
150 | #define ADIS16240_SCAN_ACC_Y 2 | 124 | #define ADIS16240_SCAN_ACC_Z 2 |
151 | #define ADIS16240_SCAN_ACC_Z 3 | 125 | #define ADIS16240_SCAN_SUPPLY 3 |
152 | #define ADIS16240_SCAN_AUX_ADC 4 | 126 | #define ADIS16240_SCAN_AUX_ADC 4 |
153 | #define ADIS16240_SCAN_TEMP 5 | 127 | #define ADIS16240_SCAN_TEMP 5 |
154 | 128 | ||
155 | #ifdef CONFIG_IIO_BUFFER | ||
156 | void adis16240_remove_trigger(struct iio_dev *indio_dev); | ||
157 | int adis16240_probe_trigger(struct iio_dev *indio_dev); | ||
158 | |||
159 | ssize_t adis16240_read_data_from_ring(struct device *dev, | ||
160 | struct device_attribute *attr, | ||
161 | char *buf); | ||
162 | |||
163 | |||
164 | int adis16240_configure_ring(struct iio_dev *indio_dev); | ||
165 | void adis16240_unconfigure_ring(struct iio_dev *indio_dev); | ||
166 | |||
167 | #else /* CONFIG_IIO_BUFFER */ | ||
168 | |||
169 | static inline void adis16240_remove_trigger(struct iio_dev *indio_dev) | ||
170 | { | ||
171 | } | ||
172 | |||
173 | static inline int adis16240_probe_trigger(struct iio_dev *indio_dev) | ||
174 | { | ||
175 | return 0; | ||
176 | } | ||
177 | |||
178 | static inline ssize_t | ||
179 | adis16240_read_data_from_ring(struct device *dev, | ||
180 | struct device_attribute *attr, | ||
181 | char *buf) | ||
182 | { | ||
183 | return 0; | ||
184 | } | ||
185 | |||
186 | static int adis16240_configure_ring(struct iio_dev *indio_dev) | ||
187 | { | ||
188 | return 0; | ||
189 | } | ||
190 | |||
191 | static inline void adis16240_unconfigure_ring(struct iio_dev *indio_dev) | ||
192 | { | ||
193 | } | ||
194 | |||
195 | #endif /* CONFIG_IIO_BUFFER */ | ||
196 | #endif /* SPI_ADIS16240_H_ */ | 129 | #endif /* SPI_ADIS16240_H_ */ |
diff --git a/drivers/staging/iio/accel/adis16240_core.c b/drivers/staging/iio/accel/adis16240_core.c index 289f81963c82..019a31e22038 100644 --- a/drivers/staging/iio/accel/adis16240_core.c +++ b/drivers/staging/iio/accel/adis16240_core.c | |||
@@ -24,128 +24,7 @@ | |||
24 | #include <linux/iio/buffer.h> | 24 | #include <linux/iio/buffer.h> |
25 | 25 | ||
26 | #include "adis16240.h" | 26 | #include "adis16240.h" |
27 | 27 | #include "../imu/adis.h" | |
28 | static int adis16240_check_status(struct iio_dev *indio_dev); | ||
29 | |||
30 | /** | ||
31 | * adis16240_spi_write_reg_8() - write single byte to a register | ||
32 | * @indio_dev: iio_dev associated with device | ||
33 | * @reg_address: the address of the register to be written | ||
34 | * @val: the value to write | ||
35 | **/ | ||
36 | static int adis16240_spi_write_reg_8(struct iio_dev *indio_dev, | ||
37 | u8 reg_address, | ||
38 | u8 val) | ||
39 | { | ||
40 | int ret; | ||
41 | struct adis16240_state *st = iio_priv(indio_dev); | ||
42 | |||
43 | mutex_lock(&st->buf_lock); | ||
44 | st->tx[0] = ADIS16240_WRITE_REG(reg_address); | ||
45 | st->tx[1] = val; | ||
46 | |||
47 | ret = spi_write(st->us, st->tx, 2); | ||
48 | mutex_unlock(&st->buf_lock); | ||
49 | |||
50 | return ret; | ||
51 | } | ||
52 | |||
53 | /** | ||
54 | * adis16240_spi_write_reg_16() - write 2 bytes to a pair of registers | ||
55 | * @indio_dev: iio_dev for this device | ||
56 | * @reg_address: the address of the lower of the two registers. Second register | ||
57 | * is assumed to have address one greater. | ||
58 | * @val: value to be written | ||
59 | **/ | ||
60 | static int adis16240_spi_write_reg_16(struct iio_dev *indio_dev, | ||
61 | u8 lower_reg_address, | ||
62 | u16 value) | ||
63 | { | ||
64 | int ret; | ||
65 | struct spi_message msg; | ||
66 | struct adis16240_state *st = iio_priv(indio_dev); | ||
67 | struct spi_transfer xfers[] = { | ||
68 | { | ||
69 | .tx_buf = st->tx, | ||
70 | .bits_per_word = 8, | ||
71 | .len = 2, | ||
72 | .cs_change = 1, | ||
73 | .delay_usecs = 35, | ||
74 | }, { | ||
75 | .tx_buf = st->tx + 2, | ||
76 | .bits_per_word = 8, | ||
77 | .len = 2, | ||
78 | .delay_usecs = 35, | ||
79 | }, | ||
80 | }; | ||
81 | |||
82 | mutex_lock(&st->buf_lock); | ||
83 | st->tx[0] = ADIS16240_WRITE_REG(lower_reg_address); | ||
84 | st->tx[1] = value & 0xFF; | ||
85 | st->tx[2] = ADIS16240_WRITE_REG(lower_reg_address + 1); | ||
86 | st->tx[3] = (value >> 8) & 0xFF; | ||
87 | |||
88 | spi_message_init(&msg); | ||
89 | spi_message_add_tail(&xfers[0], &msg); | ||
90 | spi_message_add_tail(&xfers[1], &msg); | ||
91 | ret = spi_sync(st->us, &msg); | ||
92 | mutex_unlock(&st->buf_lock); | ||
93 | |||
94 | return ret; | ||
95 | } | ||
96 | |||
97 | /** | ||
98 | * adis16240_spi_read_reg_16() - read 2 bytes from a 16-bit register | ||
99 | * @indio_dev: iio_dev for this device | ||
100 | * @reg_address: the address of the lower of the two registers. Second register | ||
101 | * is assumed to have address one greater. | ||
102 | * @val: somewhere to pass back the value read | ||
103 | **/ | ||
104 | static int adis16240_spi_read_reg_16(struct iio_dev *indio_dev, | ||
105 | u8 lower_reg_address, | ||
106 | u16 *val) | ||
107 | { | ||
108 | struct spi_message msg; | ||
109 | struct adis16240_state *st = iio_priv(indio_dev); | ||
110 | int ret; | ||
111 | struct spi_transfer xfers[] = { | ||
112 | { | ||
113 | .tx_buf = st->tx, | ||
114 | .bits_per_word = 8, | ||
115 | .len = 2, | ||
116 | .cs_change = 1, | ||
117 | .delay_usecs = 35, | ||
118 | }, { | ||
119 | .rx_buf = st->rx, | ||
120 | .bits_per_word = 8, | ||
121 | .len = 2, | ||
122 | .cs_change = 1, | ||
123 | .delay_usecs = 35, | ||
124 | }, | ||
125 | }; | ||
126 | |||
127 | mutex_lock(&st->buf_lock); | ||
128 | st->tx[0] = ADIS16240_READ_REG(lower_reg_address); | ||
129 | st->tx[1] = 0; | ||
130 | st->tx[2] = 0; | ||
131 | st->tx[3] = 0; | ||
132 | |||
133 | spi_message_init(&msg); | ||
134 | spi_message_add_tail(&xfers[0], &msg); | ||
135 | spi_message_add_tail(&xfers[1], &msg); | ||
136 | ret = spi_sync(st->us, &msg); | ||
137 | if (ret) { | ||
138 | dev_err(&st->us->dev, | ||
139 | "problem when reading 16 bit register 0x%02X", | ||
140 | lower_reg_address); | ||
141 | goto error_ret; | ||
142 | } | ||
143 | *val = (st->rx[0] << 8) | st->rx[1]; | ||
144 | |||
145 | error_ret: | ||
146 | mutex_unlock(&st->buf_lock); | ||
147 | return ret; | ||
148 | } | ||
149 | 28 | ||
150 | static ssize_t adis16240_spi_read_signed(struct device *dev, | 29 | static ssize_t adis16240_spi_read_signed(struct device *dev, |
151 | struct device_attribute *attr, | 30 | struct device_attribute *attr, |
@@ -153,18 +32,19 @@ static ssize_t adis16240_spi_read_signed(struct device *dev, | |||
153 | unsigned bits) | 32 | unsigned bits) |
154 | { | 33 | { |
155 | struct iio_dev *indio_dev = dev_to_iio_dev(dev); | 34 | struct iio_dev *indio_dev = dev_to_iio_dev(dev); |
35 | struct adis *st = iio_priv(indio_dev); | ||
156 | int ret; | 36 | int ret; |
157 | s16 val = 0; | 37 | s16 val = 0; |
158 | unsigned shift = 16 - bits; | 38 | unsigned shift = 16 - bits; |
159 | struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); | 39 | struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); |
160 | 40 | ||
161 | ret = adis16240_spi_read_reg_16(indio_dev, | 41 | ret = adis_read_reg_16(st, |
162 | this_attr->address, (u16 *)&val); | 42 | this_attr->address, (u16 *)&val); |
163 | if (ret) | 43 | if (ret) |
164 | return ret; | 44 | return ret; |
165 | 45 | ||
166 | if (val & ADIS16240_ERROR_ACTIVE) | 46 | if (val & ADIS16240_ERROR_ACTIVE) |
167 | adis16240_check_status(indio_dev); | 47 | adis_check_status(st); |
168 | 48 | ||
169 | val = ((s16)(val << shift) >> shift); | 49 | val = ((s16)(val << shift) >> shift); |
170 | return sprintf(buf, "%d\n", val); | 50 | return sprintf(buf, "%d\n", val); |
@@ -185,152 +65,16 @@ static ssize_t adis16240_read_12bit_signed(struct device *dev, | |||
185 | return ret; | 65 | return ret; |
186 | } | 66 | } |
187 | 67 | ||
188 | static int adis16240_reset(struct iio_dev *indio_dev) | ||
189 | { | ||
190 | int ret; | ||
191 | ret = adis16240_spi_write_reg_8(indio_dev, | ||
192 | ADIS16240_GLOB_CMD, | ||
193 | ADIS16240_GLOB_CMD_SW_RESET); | ||
194 | if (ret) | ||
195 | dev_err(&indio_dev->dev, "problem resetting device"); | ||
196 | |||
197 | return ret; | ||
198 | } | ||
199 | |||
200 | int adis16240_set_irq(struct iio_dev *indio_dev, bool enable) | ||
201 | { | ||
202 | int ret = 0; | ||
203 | u16 msc; | ||
204 | |||
205 | ret = adis16240_spi_read_reg_16(indio_dev, | ||
206 | ADIS16240_MSC_CTRL, &msc); | ||
207 | if (ret) | ||
208 | goto error_ret; | ||
209 | |||
210 | msc |= ADIS16240_MSC_CTRL_ACTIVE_HIGH; | ||
211 | msc &= ~ADIS16240_MSC_CTRL_DATA_RDY_DIO2; | ||
212 | if (enable) | ||
213 | msc |= ADIS16240_MSC_CTRL_DATA_RDY_EN; | ||
214 | else | ||
215 | msc &= ~ADIS16240_MSC_CTRL_DATA_RDY_EN; | ||
216 | |||
217 | ret = adis16240_spi_write_reg_16(indio_dev, | ||
218 | ADIS16240_MSC_CTRL, msc); | ||
219 | |||
220 | error_ret: | ||
221 | return ret; | ||
222 | } | ||
223 | |||
224 | static int adis16240_self_test(struct iio_dev *indio_dev) | ||
225 | { | ||
226 | int ret; | ||
227 | ret = adis16240_spi_write_reg_16(indio_dev, | ||
228 | ADIS16240_MSC_CTRL, | ||
229 | ADIS16240_MSC_CTRL_SELF_TEST_EN); | ||
230 | if (ret) { | ||
231 | dev_err(&indio_dev->dev, "problem starting self test"); | ||
232 | goto err_ret; | ||
233 | } | ||
234 | |||
235 | msleep(ADIS16240_STARTUP_DELAY); | ||
236 | |||
237 | adis16240_check_status(indio_dev); | ||
238 | |||
239 | err_ret: | ||
240 | return ret; | ||
241 | } | ||
242 | |||
243 | static int adis16240_check_status(struct iio_dev *indio_dev) | ||
244 | { | ||
245 | u16 status; | ||
246 | int ret; | ||
247 | struct device *dev = &indio_dev->dev; | ||
248 | |||
249 | ret = adis16240_spi_read_reg_16(indio_dev, | ||
250 | ADIS16240_DIAG_STAT, &status); | ||
251 | |||
252 | if (ret < 0) { | ||
253 | dev_err(dev, "Reading status failed\n"); | ||
254 | goto error_ret; | ||
255 | } | ||
256 | |||
257 | ret = status & 0x2F; | ||
258 | if (status & ADIS16240_DIAG_STAT_PWRON_FAIL) | ||
259 | dev_err(dev, "Power-on, self-test fail\n"); | ||
260 | if (status & ADIS16240_DIAG_STAT_SPI_FAIL) | ||
261 | dev_err(dev, "SPI failure\n"); | ||
262 | if (status & ADIS16240_DIAG_STAT_FLASH_UPT) | ||
263 | dev_err(dev, "Flash update failed\n"); | ||
264 | if (status & ADIS16240_DIAG_STAT_POWER_HIGH) | ||
265 | dev_err(dev, "Power supply above 3.625V\n"); | ||
266 | if (status & ADIS16240_DIAG_STAT_POWER_LOW) | ||
267 | dev_err(dev, "Power supply below 2.225V\n"); | ||
268 | |||
269 | error_ret: | ||
270 | return ret; | ||
271 | } | ||
272 | |||
273 | static int adis16240_initial_setup(struct iio_dev *indio_dev) | ||
274 | { | ||
275 | int ret; | ||
276 | struct device *dev = &indio_dev->dev; | ||
277 | |||
278 | /* Disable IRQ */ | ||
279 | ret = adis16240_set_irq(indio_dev, false); | ||
280 | if (ret) { | ||
281 | dev_err(dev, "disable irq failed"); | ||
282 | goto err_ret; | ||
283 | } | ||
284 | |||
285 | /* Do self test */ | ||
286 | ret = adis16240_self_test(indio_dev); | ||
287 | if (ret) { | ||
288 | dev_err(dev, "self test failure"); | ||
289 | goto err_ret; | ||
290 | } | ||
291 | |||
292 | /* Read status register to check the result */ | ||
293 | ret = adis16240_check_status(indio_dev); | ||
294 | if (ret) { | ||
295 | adis16240_reset(indio_dev); | ||
296 | dev_err(dev, "device not playing ball -> reset"); | ||
297 | msleep(ADIS16240_STARTUP_DELAY); | ||
298 | ret = adis16240_check_status(indio_dev); | ||
299 | if (ret) { | ||
300 | dev_err(dev, "giving up"); | ||
301 | goto err_ret; | ||
302 | } | ||
303 | } | ||
304 | |||
305 | err_ret: | ||
306 | return ret; | ||
307 | } | ||
308 | |||
309 | static IIO_DEVICE_ATTR(in_accel_xyz_squared_peak_raw, S_IRUGO, | 68 | static IIO_DEVICE_ATTR(in_accel_xyz_squared_peak_raw, S_IRUGO, |
310 | adis16240_read_12bit_signed, NULL, | 69 | adis16240_read_12bit_signed, NULL, |
311 | ADIS16240_XYZPEAK_OUT); | 70 | ADIS16240_XYZPEAK_OUT); |
312 | 71 | ||
313 | static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("4096"); | 72 | static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("4096"); |
314 | 73 | ||
315 | enum adis16240_chan { | 74 | static const u8 adis16240_addresses[][2] = { |
316 | in_supply, | 75 | [ADIS16240_SCAN_ACC_X] = { ADIS16240_XACCL_OFF, ADIS16240_XPEAK_OUT }, |
317 | in_aux, | 76 | [ADIS16240_SCAN_ACC_Y] = { ADIS16240_YACCL_OFF, ADIS16240_YPEAK_OUT }, |
318 | accel_x, | 77 | [ADIS16240_SCAN_ACC_Z] = { ADIS16240_ZACCL_OFF, ADIS16240_ZPEAK_OUT }, |
319 | accel_y, | ||
320 | accel_z, | ||
321 | temp, | ||
322 | }; | ||
323 | |||
324 | static const u8 adis16240_addresses[6][3] = { | ||
325 | [in_supply] = { ADIS16240_SUPPLY_OUT }, | ||
326 | [in_aux] = { ADIS16240_AUX_ADC }, | ||
327 | [accel_x] = { ADIS16240_XACCL_OUT, ADIS16240_XACCL_OFF, | ||
328 | ADIS16240_XPEAK_OUT }, | ||
329 | [accel_y] = { ADIS16240_YACCL_OUT, ADIS16240_YACCL_OFF, | ||
330 | ADIS16240_YPEAK_OUT }, | ||
331 | [accel_z] = { ADIS16240_ZACCL_OUT, ADIS16240_ZACCL_OFF, | ||
332 | ADIS16240_ZPEAK_OUT }, | ||
333 | [temp] = { ADIS16240_TEMP_OUT }, | ||
334 | }; | 78 | }; |
335 | 79 | ||
336 | static int adis16240_read_raw(struct iio_dev *indio_dev, | 80 | static int adis16240_read_raw(struct iio_dev *indio_dev, |
@@ -338,6 +82,7 @@ static int adis16240_read_raw(struct iio_dev *indio_dev, | |||
338 | int *val, int *val2, | 82 | int *val, int *val2, |
339 | long mask) | 83 | long mask) |
340 | { | 84 | { |
85 | struct adis *st = iio_priv(indio_dev); | ||
341 | int ret; | 86 | int ret; |
342 | int bits; | 87 | int bits; |
343 | u8 addr; | 88 | u8 addr; |
@@ -345,29 +90,8 @@ static int adis16240_read_raw(struct iio_dev *indio_dev, | |||
345 | 90 | ||
346 | switch (mask) { | 91 | switch (mask) { |
347 | case IIO_CHAN_INFO_RAW: | 92 | case IIO_CHAN_INFO_RAW: |
348 | mutex_lock(&indio_dev->mlock); | 93 | return adis_single_conversion(indio_dev, chan, |
349 | addr = adis16240_addresses[chan->address][0]; | 94 | ADIS16240_ERROR_ACTIVE, val); |
350 | ret = adis16240_spi_read_reg_16(indio_dev, addr, &val16); | ||
351 | if (ret) { | ||
352 | mutex_unlock(&indio_dev->mlock); | ||
353 | return ret; | ||
354 | } | ||
355 | |||
356 | if (val16 & ADIS16240_ERROR_ACTIVE) { | ||
357 | ret = adis16240_check_status(indio_dev); | ||
358 | if (ret) { | ||
359 | mutex_unlock(&indio_dev->mlock); | ||
360 | return ret; | ||
361 | } | ||
362 | } | ||
363 | val16 = val16 & ((1 << chan->scan_type.realbits) - 1); | ||
364 | if (chan->scan_type.sign == 's') | ||
365 | val16 = (s16)(val16 << | ||
366 | (16 - chan->scan_type.realbits)) >> | ||
367 | (16 - chan->scan_type.realbits); | ||
368 | *val = val16; | ||
369 | mutex_unlock(&indio_dev->mlock); | ||
370 | return IIO_VAL_INT; | ||
371 | case IIO_CHAN_INFO_SCALE: | 95 | case IIO_CHAN_INFO_SCALE: |
372 | switch (chan->type) { | 96 | switch (chan->type) { |
373 | case IIO_VOLTAGE: | 97 | case IIO_VOLTAGE: |
@@ -400,8 +124,8 @@ static int adis16240_read_raw(struct iio_dev *indio_dev, | |||
400 | case IIO_CHAN_INFO_CALIBBIAS: | 124 | case IIO_CHAN_INFO_CALIBBIAS: |
401 | bits = 10; | 125 | bits = 10; |
402 | mutex_lock(&indio_dev->mlock); | 126 | mutex_lock(&indio_dev->mlock); |
403 | addr = adis16240_addresses[chan->address][1]; | 127 | addr = adis16240_addresses[chan->scan_index][0]; |
404 | ret = adis16240_spi_read_reg_16(indio_dev, addr, &val16); | 128 | ret = adis_read_reg_16(st, addr, &val16); |
405 | if (ret) { | 129 | if (ret) { |
406 | mutex_unlock(&indio_dev->mlock); | 130 | mutex_unlock(&indio_dev->mlock); |
407 | return ret; | 131 | return ret; |
@@ -414,8 +138,8 @@ static int adis16240_read_raw(struct iio_dev *indio_dev, | |||
414 | case IIO_CHAN_INFO_PEAK: | 138 | case IIO_CHAN_INFO_PEAK: |
415 | bits = 10; | 139 | bits = 10; |
416 | mutex_lock(&indio_dev->mlock); | 140 | mutex_lock(&indio_dev->mlock); |
417 | addr = adis16240_addresses[chan->address][2]; | 141 | addr = adis16240_addresses[chan->scan_index][1]; |
418 | ret = adis16240_spi_read_reg_16(indio_dev, addr, &val16); | 142 | ret = adis_read_reg_16(st, addr, &val16); |
419 | if (ret) { | 143 | if (ret) { |
420 | mutex_unlock(&indio_dev->mlock); | 144 | mutex_unlock(&indio_dev->mlock); |
421 | return ret; | 145 | return ret; |
@@ -435,104 +159,32 @@ static int adis16240_write_raw(struct iio_dev *indio_dev, | |||
435 | int val2, | 159 | int val2, |
436 | long mask) | 160 | long mask) |
437 | { | 161 | { |
162 | struct adis *st = iio_priv(indio_dev); | ||
438 | int bits = 10; | 163 | int bits = 10; |
439 | s16 val16; | 164 | s16 val16; |
440 | u8 addr; | 165 | u8 addr; |
441 | switch (mask) { | 166 | switch (mask) { |
442 | case IIO_CHAN_INFO_CALIBBIAS: | 167 | case IIO_CHAN_INFO_CALIBBIAS: |
443 | val16 = val & ((1 << bits) - 1); | 168 | val16 = val & ((1 << bits) - 1); |
444 | addr = adis16240_addresses[chan->address][1]; | 169 | addr = adis16240_addresses[chan->scan_index][0]; |
445 | return adis16240_spi_write_reg_16(indio_dev, addr, val16); | 170 | return adis_write_reg_16(st, addr, val16); |
446 | } | 171 | } |
447 | return -EINVAL; | 172 | return -EINVAL; |
448 | } | 173 | } |
449 | 174 | ||
450 | static const struct iio_chan_spec adis16240_channels[] = { | 175 | static const struct iio_chan_spec adis16240_channels[] = { |
451 | { | 176 | ADIS_SUPPLY_CHAN(ADIS16240_SUPPLY_OUT, ADIS16240_SCAN_SUPPLY, 10), |
452 | .type = IIO_VOLTAGE, | 177 | ADIS_AUX_ADC_CHAN(ADIS16240_AUX_ADC, ADIS16240_SCAN_AUX_ADC, 10), |
453 | .indexed = 1, | 178 | ADIS_ACCEL_CHAN(X, ADIS16240_XACCL_OUT, ADIS16240_SCAN_ACC_X, |
454 | .channel = 0, | ||
455 | .extend_name = "supply", | ||
456 | .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | | ||
457 | IIO_CHAN_INFO_SCALE_SEPARATE_BIT, | ||
458 | .address = in_supply, | ||
459 | .scan_index = ADIS16240_SCAN_SUPPLY, | ||
460 | .scan_type = { | ||
461 | .sign = 'u', | ||
462 | .realbits = 10, | ||
463 | .storagebits = 16, | ||
464 | }, | ||
465 | }, { | ||
466 | .type = IIO_VOLTAGE, | ||
467 | .indexed = 1, | ||
468 | .channel = 1, | ||
469 | .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT, | ||
470 | .address = in_aux, | ||
471 | .scan_index = ADIS16240_SCAN_AUX_ADC, | ||
472 | .scan_type = { | ||
473 | .sign = 'u', | ||
474 | .realbits = 10, | ||
475 | .storagebits = 16, | ||
476 | }, | ||
477 | }, { | ||
478 | .type = IIO_ACCEL, | ||
479 | .modified = 1, | ||
480 | .channel2 = IIO_MOD_X, | ||
481 | .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | | ||
482 | IIO_CHAN_INFO_SCALE_SHARED_BIT | | ||
483 | IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | | 179 | IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | |
484 | IIO_CHAN_INFO_PEAK_SEPARATE_BIT, | 180 | IIO_CHAN_INFO_PEAK_SEPARATE_BIT, 10), |
485 | .address = accel_x, | 181 | ADIS_ACCEL_CHAN(Y, ADIS16240_YACCL_OUT, ADIS16240_SCAN_ACC_Y, |
486 | .scan_index = ADIS16240_SCAN_ACC_X, | ||
487 | .scan_type = { | ||
488 | .sign = 's', | ||
489 | .realbits = 10, | ||
490 | .storagebits = 16, | ||
491 | }, | ||
492 | }, { | ||
493 | .type = IIO_ACCEL, | ||
494 | .modified = 1, | ||
495 | .channel2 = IIO_MOD_Y, | ||
496 | .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | | ||
497 | IIO_CHAN_INFO_SCALE_SHARED_BIT | | ||
498 | IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | | 182 | IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | |
499 | IIO_CHAN_INFO_PEAK_SEPARATE_BIT, | 183 | IIO_CHAN_INFO_PEAK_SEPARATE_BIT, 10), |
500 | .address = accel_y, | 184 | ADIS_ACCEL_CHAN(Z, ADIS16240_ZACCL_OUT, ADIS16240_SCAN_ACC_Z, |
501 | .scan_index = ADIS16240_SCAN_ACC_Y, | ||
502 | .scan_type = { | ||
503 | .sign = 's', | ||
504 | .realbits = 10, | ||
505 | .storagebits = 16, | ||
506 | }, | ||
507 | }, { | ||
508 | .type = IIO_ACCEL, | ||
509 | .modified = 1, | ||
510 | .channel2 = IIO_MOD_Z, | ||
511 | .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | | ||
512 | IIO_CHAN_INFO_SCALE_SHARED_BIT | | ||
513 | IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | | 185 | IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | |
514 | IIO_CHAN_INFO_PEAK_SEPARATE_BIT, | 186 | IIO_CHAN_INFO_PEAK_SEPARATE_BIT, 10), |
515 | .address = accel_z, | 187 | ADIS_TEMP_CHAN(ADIS16240_TEMP_OUT, ADIS16240_SCAN_TEMP, 10), |
516 | .scan_index = ADIS16240_SCAN_ACC_Z, | ||
517 | .scan_type = { | ||
518 | .sign = 's', | ||
519 | .realbits = 10, | ||
520 | .storagebits = 16, | ||
521 | }, | ||
522 | }, { | ||
523 | .type = IIO_TEMP, | ||
524 | .indexed = 1, | ||
525 | .channel = 0, | ||
526 | .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | | ||
527 | IIO_CHAN_INFO_SCALE_SEPARATE_BIT, | ||
528 | .address = temp, | ||
529 | .scan_index = ADIS16240_SCAN_TEMP, | ||
530 | .scan_type = { | ||
531 | .sign = 'u', | ||
532 | .realbits = 10, | ||
533 | .storagebits = 16, | ||
534 | }, | ||
535 | }, | ||
536 | IIO_CHAN_SOFT_TIMESTAMP(6) | 188 | IIO_CHAN_SOFT_TIMESTAMP(6) |
537 | }; | 189 | }; |
538 | 190 | ||
@@ -553,10 +205,36 @@ static const struct iio_info adis16240_info = { | |||
553 | .driver_module = THIS_MODULE, | 205 | .driver_module = THIS_MODULE, |
554 | }; | 206 | }; |
555 | 207 | ||
208 | static const char * const adis16240_status_error_msgs[] = { | ||
209 | [ADIS16240_DIAG_STAT_PWRON_FAIL_BIT] = "Power on, self-test failed", | ||
210 | [ADIS16240_DIAG_STAT_SPI_FAIL_BIT] = "SPI failure", | ||
211 | [ADIS16240_DIAG_STAT_FLASH_UPT_BIT] = "Flash update failed", | ||
212 | [ADIS16240_DIAG_STAT_POWER_HIGH_BIT] = "Power supply above 3.625V", | ||
213 | [ADIS16240_DIAG_STAT_POWER_LOW_BIT] = "Power supply below 2.225V", | ||
214 | }; | ||
215 | |||
216 | static const struct adis_data adis16240_data = { | ||
217 | .write_delay = 35, | ||
218 | .read_delay = 35, | ||
219 | .msc_ctrl_reg = ADIS16240_MSC_CTRL, | ||
220 | .glob_cmd_reg = ADIS16240_GLOB_CMD, | ||
221 | .diag_stat_reg = ADIS16240_DIAG_STAT, | ||
222 | |||
223 | .self_test_mask = ADIS16240_MSC_CTRL_SELF_TEST_EN, | ||
224 | .startup_delay = ADIS16240_STARTUP_DELAY, | ||
225 | |||
226 | .status_error_msgs = adis16240_status_error_msgs, | ||
227 | .status_error_mask = BIT(ADIS16240_DIAG_STAT_PWRON_FAIL_BIT) | | ||
228 | BIT(ADIS16240_DIAG_STAT_SPI_FAIL_BIT) | | ||
229 | BIT(ADIS16240_DIAG_STAT_FLASH_UPT_BIT) | | ||
230 | BIT(ADIS16240_DIAG_STAT_POWER_HIGH_BIT) | | ||
231 | BIT(ADIS16240_DIAG_STAT_POWER_LOW_BIT), | ||
232 | }; | ||
233 | |||
556 | static int __devinit adis16240_probe(struct spi_device *spi) | 234 | static int __devinit adis16240_probe(struct spi_device *spi) |
557 | { | 235 | { |
558 | int ret; | 236 | int ret; |
559 | struct adis16240_state *st; | 237 | struct adis *st; |
560 | struct iio_dev *indio_dev; | 238 | struct iio_dev *indio_dev; |
561 | 239 | ||
562 | /* setup the industrialio driver allocated elements */ | 240 | /* setup the industrialio driver allocated elements */ |
@@ -569,9 +247,6 @@ static int __devinit adis16240_probe(struct spi_device *spi) | |||
569 | /* this is only used for removal purposes */ | 247 | /* this is only used for removal purposes */ |
570 | spi_set_drvdata(spi, indio_dev); | 248 | spi_set_drvdata(spi, indio_dev); |
571 | 249 | ||
572 | st->us = spi; | ||
573 | mutex_init(&st->buf_lock); | ||
574 | |||
575 | indio_dev->name = spi->dev.driver->name; | 250 | indio_dev->name = spi->dev.driver->name; |
576 | indio_dev->dev.parent = &spi->dev; | 251 | indio_dev->dev.parent = &spi->dev; |
577 | indio_dev->info = &adis16240_info; | 252 | indio_dev->info = &adis16240_info; |
@@ -579,39 +254,24 @@ static int __devinit adis16240_probe(struct spi_device *spi) | |||
579 | indio_dev->num_channels = ARRAY_SIZE(adis16240_channels); | 254 | indio_dev->num_channels = ARRAY_SIZE(adis16240_channels); |
580 | indio_dev->modes = INDIO_DIRECT_MODE; | 255 | indio_dev->modes = INDIO_DIRECT_MODE; |
581 | 256 | ||
582 | ret = adis16240_configure_ring(indio_dev); | 257 | ret = adis_init(st, indio_dev, spi, &adis16240_data); |
258 | if (ret) | ||
259 | goto error_free_dev; | ||
260 | ret = adis_setup_buffer_and_trigger(st, indio_dev, NULL); | ||
583 | if (ret) | 261 | if (ret) |
584 | goto error_free_dev; | 262 | goto error_free_dev; |
585 | |||
586 | ret = iio_buffer_register(indio_dev, | ||
587 | adis16240_channels, | ||
588 | ARRAY_SIZE(adis16240_channels)); | ||
589 | if (ret) { | ||
590 | printk(KERN_ERR "failed to initialize the ring\n"); | ||
591 | goto error_unreg_ring_funcs; | ||
592 | } | ||
593 | |||
594 | if (spi->irq) { | ||
595 | ret = adis16240_probe_trigger(indio_dev); | ||
596 | if (ret) | ||
597 | goto error_uninitialize_ring; | ||
598 | } | ||
599 | 263 | ||
600 | /* Get the device into a sane initial state */ | 264 | /* Get the device into a sane initial state */ |
601 | ret = adis16240_initial_setup(indio_dev); | 265 | ret = adis_initial_startup(st); |
602 | if (ret) | 266 | if (ret) |
603 | goto error_remove_trigger; | 267 | goto error_cleanup_buffer_trigger; |
604 | ret = iio_device_register(indio_dev); | 268 | ret = iio_device_register(indio_dev); |
605 | if (ret) | 269 | if (ret) |
606 | goto error_remove_trigger; | 270 | goto error_cleanup_buffer_trigger; |
607 | return 0; | 271 | return 0; |
608 | 272 | ||
609 | error_remove_trigger: | 273 | error_cleanup_buffer_trigger: |
610 | adis16240_remove_trigger(indio_dev); | 274 | adis_cleanup_buffer_and_trigger(st, indio_dev); |
611 | error_uninitialize_ring: | ||
612 | iio_buffer_unregister(indio_dev); | ||
613 | error_unreg_ring_funcs: | ||
614 | adis16240_unconfigure_ring(indio_dev); | ||
615 | error_free_dev: | 275 | error_free_dev: |
616 | iio_device_free(indio_dev); | 276 | iio_device_free(indio_dev); |
617 | error_ret: | 277 | error_ret: |
@@ -620,13 +280,11 @@ error_ret: | |||
620 | 280 | ||
621 | static int __devexit adis16240_remove(struct spi_device *spi) | 281 | static int __devexit adis16240_remove(struct spi_device *spi) |
622 | { | 282 | { |
623 | |||
624 | struct iio_dev *indio_dev = spi_get_drvdata(spi); | 283 | struct iio_dev *indio_dev = spi_get_drvdata(spi); |
284 | struct adis *st = iio_priv(indio_dev); | ||
625 | 285 | ||
626 | iio_device_unregister(indio_dev); | 286 | iio_device_unregister(indio_dev); |
627 | adis16240_remove_trigger(indio_dev); | 287 | adis_cleanup_buffer_and_trigger(st, indio_dev); |
628 | iio_buffer_unregister(indio_dev); | ||
629 | adis16240_unconfigure_ring(indio_dev); | ||
630 | iio_device_free(indio_dev); | 288 | iio_device_free(indio_dev); |
631 | 289 | ||
632 | return 0; | 290 | return 0; |
diff --git a/drivers/staging/iio/accel/adis16240_ring.c b/drivers/staging/iio/accel/adis16240_ring.c deleted file mode 100644 index e2ac8a8c8107..000000000000 --- a/drivers/staging/iio/accel/adis16240_ring.c +++ /dev/null | |||
@@ -1,132 +0,0 @@ | |||
1 | #include <linux/export.h> | ||
2 | #include <linux/interrupt.h> | ||
3 | #include <linux/mutex.h> | ||
4 | #include <linux/kernel.h> | ||
5 | #include <linux/spi/spi.h> | ||
6 | #include <linux/slab.h> | ||
7 | |||
8 | #include <linux/iio/iio.h> | ||
9 | #include "../ring_sw.h" | ||
10 | #include <linux/iio/trigger_consumer.h> | ||
11 | #include "adis16240.h" | ||
12 | |||
13 | /** | ||
14 | * adis16240_read_ring_data() read data registers which will be placed into ring | ||
15 | * @indio_dev: the IIO device | ||
16 | * @rx: somewhere to pass back the value read | ||
17 | **/ | ||
18 | static int adis16240_read_ring_data(struct iio_dev *indio_dev, u8 *rx) | ||
19 | { | ||
20 | struct spi_message msg; | ||
21 | struct adis16240_state *st = iio_priv(indio_dev); | ||
22 | struct spi_transfer xfers[ADIS16240_OUTPUTS + 1]; | ||
23 | int ret; | ||
24 | int i; | ||
25 | |||
26 | mutex_lock(&st->buf_lock); | ||
27 | |||
28 | spi_message_init(&msg); | ||
29 | |||
30 | memset(xfers, 0, sizeof(xfers)); | ||
31 | for (i = 0; i <= ADIS16240_OUTPUTS; i++) { | ||
32 | xfers[i].bits_per_word = 8; | ||
33 | xfers[i].cs_change = 1; | ||
34 | xfers[i].len = 2; | ||
35 | xfers[i].delay_usecs = 30; | ||
36 | xfers[i].tx_buf = st->tx + 2 * i; | ||
37 | st->tx[2 * i] | ||
38 | = ADIS16240_READ_REG(ADIS16240_SUPPLY_OUT + 2 * i); | ||
39 | st->tx[2 * i + 1] = 0; | ||
40 | if (i >= 1) | ||
41 | xfers[i].rx_buf = rx + 2 * (i - 1); | ||
42 | spi_message_add_tail(&xfers[i], &msg); | ||
43 | } | ||
44 | |||
45 | ret = spi_sync(st->us, &msg); | ||
46 | if (ret) | ||
47 | dev_err(&st->us->dev, "problem when burst reading"); | ||
48 | |||
49 | mutex_unlock(&st->buf_lock); | ||
50 | |||
51 | return ret; | ||
52 | } | ||
53 | |||
54 | static irqreturn_t adis16240_trigger_handler(int irq, void *p) | ||
55 | { | ||
56 | struct iio_poll_func *pf = p; | ||
57 | struct iio_dev *indio_dev = pf->indio_dev; | ||
58 | struct adis16240_state *st = iio_priv(indio_dev); | ||
59 | |||
60 | int i = 0; | ||
61 | s16 *data; | ||
62 | |||
63 | data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL); | ||
64 | if (data == NULL) { | ||
65 | dev_err(&st->us->dev, "memory alloc failed in ring bh"); | ||
66 | goto done; | ||
67 | } | ||
68 | |||
69 | if (!bitmap_empty(indio_dev->active_scan_mask, indio_dev->masklength) && | ||
70 | adis16240_read_ring_data(indio_dev, st->rx) >= 0) | ||
71 | for (; i < bitmap_weight(indio_dev->active_scan_mask, | ||
72 | indio_dev->masklength); i++) | ||
73 | data[i] = be16_to_cpup((__be16 *)&(st->rx[i*2])); | ||
74 | |||
75 | /* Guaranteed to be aligned with 8 byte boundary */ | ||
76 | if (indio_dev->scan_timestamp) | ||
77 | *((s64 *)(data + ((i + 3)/4)*4)) = pf->timestamp; | ||
78 | |||
79 | iio_push_to_buffers(indio_dev, (u8 *)data); | ||
80 | |||
81 | kfree(data); | ||
82 | done: | ||
83 | iio_trigger_notify_done(indio_dev->trig); | ||
84 | |||
85 | return IRQ_HANDLED; | ||
86 | } | ||
87 | |||
88 | void adis16240_unconfigure_ring(struct iio_dev *indio_dev) | ||
89 | { | ||
90 | iio_dealloc_pollfunc(indio_dev->pollfunc); | ||
91 | iio_sw_rb_free(indio_dev->buffer); | ||
92 | } | ||
93 | |||
94 | static const struct iio_buffer_setup_ops adis16240_ring_setup_ops = { | ||
95 | .preenable = &iio_sw_buffer_preenable, | ||
96 | .postenable = &iio_triggered_buffer_postenable, | ||
97 | .predisable = &iio_triggered_buffer_predisable, | ||
98 | }; | ||
99 | |||
100 | int adis16240_configure_ring(struct iio_dev *indio_dev) | ||
101 | { | ||
102 | int ret = 0; | ||
103 | struct iio_buffer *ring; | ||
104 | |||
105 | ring = iio_sw_rb_allocate(indio_dev); | ||
106 | if (!ring) { | ||
107 | ret = -ENOMEM; | ||
108 | return ret; | ||
109 | } | ||
110 | indio_dev->buffer = ring; | ||
111 | ring->scan_timestamp = true; | ||
112 | indio_dev->setup_ops = &adis16240_ring_setup_ops; | ||
113 | |||
114 | indio_dev->pollfunc = iio_alloc_pollfunc(&iio_pollfunc_store_time, | ||
115 | &adis16240_trigger_handler, | ||
116 | IRQF_ONESHOT, | ||
117 | indio_dev, | ||
118 | "%s_consumer%d", | ||
119 | indio_dev->name, | ||
120 | indio_dev->id); | ||
121 | if (indio_dev->pollfunc == NULL) { | ||
122 | ret = -ENOMEM; | ||
123 | goto error_iio_sw_rb_free; | ||
124 | } | ||
125 | |||
126 | indio_dev->modes |= INDIO_BUFFER_TRIGGERED; | ||
127 | return 0; | ||
128 | |||
129 | error_iio_sw_rb_free: | ||
130 | iio_sw_rb_free(indio_dev->buffer); | ||
131 | return ret; | ||
132 | } | ||
diff --git a/drivers/staging/iio/accel/adis16240_trigger.c b/drivers/staging/iio/accel/adis16240_trigger.c deleted file mode 100644 index f3caf09dcb89..000000000000 --- a/drivers/staging/iio/accel/adis16240_trigger.c +++ /dev/null | |||
@@ -1,73 +0,0 @@ | |||
1 | #include <linux/interrupt.h> | ||
2 | #include <linux/kernel.h> | ||
3 | #include <linux/spi/spi.h> | ||
4 | #include <linux/export.h> | ||
5 | |||
6 | #include <linux/iio/iio.h> | ||
7 | #include <linux/iio/trigger.h> | ||
8 | #include "adis16240.h" | ||
9 | |||
10 | /** | ||
11 | * adis16240_data_rdy_trigger_set_state() set datardy interrupt state | ||
12 | **/ | ||
13 | static int adis16240_data_rdy_trigger_set_state(struct iio_trigger *trig, | ||
14 | bool state) | ||
15 | { | ||
16 | struct iio_dev *indio_dev = trig->private_data; | ||
17 | |||
18 | dev_dbg(&indio_dev->dev, "%s (%d)\n", __func__, state); | ||
19 | return adis16240_set_irq(indio_dev, state); | ||
20 | } | ||
21 | |||
22 | static const struct iio_trigger_ops adis16240_trigger_ops = { | ||
23 | .owner = THIS_MODULE, | ||
24 | .set_trigger_state = &adis16240_data_rdy_trigger_set_state, | ||
25 | }; | ||
26 | |||
27 | int adis16240_probe_trigger(struct iio_dev *indio_dev) | ||
28 | { | ||
29 | int ret; | ||
30 | struct adis16240_state *st = iio_priv(indio_dev); | ||
31 | |||
32 | st->trig = iio_trigger_alloc("adis16240-dev%d", indio_dev->id); | ||
33 | if (st->trig == NULL) { | ||
34 | ret = -ENOMEM; | ||
35 | goto error_ret; | ||
36 | } | ||
37 | |||
38 | ret = request_irq(st->us->irq, | ||
39 | iio_trigger_generic_data_rdy_poll, | ||
40 | IRQF_TRIGGER_RISING, | ||
41 | "adis16240", | ||
42 | st->trig); | ||
43 | if (ret) | ||
44 | goto error_free_trig; | ||
45 | |||
46 | st->trig->dev.parent = &st->us->dev; | ||
47 | st->trig->ops = &adis16240_trigger_ops; | ||
48 | st->trig->private_data = indio_dev; | ||
49 | ret = iio_trigger_register(st->trig); | ||
50 | |||
51 | /* select default trigger */ | ||
52 | indio_dev->trig = st->trig; | ||
53 | if (ret) | ||
54 | goto error_free_irq; | ||
55 | |||
56 | return 0; | ||
57 | |||
58 | error_free_irq: | ||
59 | free_irq(st->us->irq, st->trig); | ||
60 | error_free_trig: | ||
61 | iio_trigger_free(st->trig); | ||
62 | error_ret: | ||
63 | return ret; | ||
64 | } | ||
65 | |||
66 | void adis16240_remove_trigger(struct iio_dev *indio_dev) | ||
67 | { | ||
68 | struct adis16240_state *st = iio_priv(indio_dev); | ||
69 | |||
70 | iio_trigger_unregister(st->trig); | ||
71 | free_irq(st->us->irq, st->trig); | ||
72 | iio_trigger_free(st->trig); | ||
73 | } | ||