aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/iio
diff options
context:
space:
mode:
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>2014-06-18 23:02:33 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2014-06-18 23:02:33 -0400
commitf641f66784351d0266817301158d7171df6eec20 (patch)
treec2ef5a87a5243fe732cd69266c3e16a155c2431b /drivers/iio
parent98e11370052aa88a38c2d5d1693a5ec2966c4f81 (diff)
parent88f6da779a37a3579e580296776ba86d6c6bd980 (diff)
Merge tag 'iio-for-3.17a' of git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio into staging-next
Jonathan writes: First round of new drivers, cleanups and functionality for the 3.17 cycle. New drivers * t5403 barometric pressure sensor * kxcjk1013 accelerometer (with a locking followup fix). * ak09911 digital compass Documentation * ABI docs for proximity added (interface has been there a long time but somehow snuck through without being documented) * Move iio-trig-sysfs documentation out of staging (got left behind when the driver moved some time ago). Cleanups * drop the timestamp argument from iio_trigger_poll(_chained) as nothing has been done with it for some time. * ad799x kerneldoc for ad799x_chip brought up to date. * replace a number of reimplementations of the GENMASK macro and use the BIT macro to cleanup a few locations. * bring the iio_event_monitor example program up to date with new device types. * fix some incorrect function prototypes in iio_utils.h example code. * INDIO_RING_TRIGGERED to INDIO_BUFFER_TRIGGERED fix in docs. This got left behind after we renamed it a long time back. * fix error handling in the generic_buffer example program. * small tidy ups in the iio-trig-periodic-rtc driver. * Allow reseting iio-trig-periodic-rtc frequency to 0 (default) after it has changed. * Trivial tidy ups in coding style in iio_simply_dummy
Diffstat (limited to 'drivers/iio')
-rw-r--r--drivers/iio/accel/Kconfig12
-rw-r--r--drivers/iio/accel/Makefile1
-rw-r--r--drivers/iio/accel/kxcjk-1013.c764
-rw-r--r--drivers/iio/adc/ad7298.c21
-rw-r--r--drivers/iio/adc/ad7476.c5
-rw-r--r--drivers/iio/adc/ad7887.c21
-rw-r--r--drivers/iio/adc/ad799x.c3
-rw-r--r--drivers/iio/adc/ad_sigma_delta.c2
-rw-r--r--drivers/iio/adc/at91_adc.c2
-rw-r--r--drivers/iio/adc/xilinx-xadc-core.c2
-rw-r--r--drivers/iio/dac/ad5504.c11
-rw-r--r--drivers/iio/dac/ad5791.c29
-rw-r--r--drivers/iio/industrialio-trigger.c8
-rw-r--r--drivers/iio/light/gp2ap020a00f.c2
-rw-r--r--drivers/iio/magnetometer/Kconfig10
-rw-r--r--drivers/iio/magnetometer/Makefile1
-rw-r--r--drivers/iio/magnetometer/ak09911.c326
-rw-r--r--drivers/iio/pressure/Kconfig10
-rw-r--r--drivers/iio/pressure/Makefile1
-rw-r--r--drivers/iio/pressure/t5403.c275
-rw-r--r--drivers/iio/proximity/as3935.c2
-rw-r--r--drivers/iio/trigger/iio-trig-interrupt.c3
-rw-r--r--drivers/iio/trigger/iio-trig-sysfs.c2
23 files changed, 1452 insertions, 61 deletions
diff --git a/drivers/iio/accel/Kconfig b/drivers/iio/accel/Kconfig
index 1e120fa1e156..12addf272a61 100644
--- a/drivers/iio/accel/Kconfig
+++ b/drivers/iio/accel/Kconfig
@@ -77,4 +77,16 @@ config MMA8452
77 To compile this driver as a module, choose M here: the module 77 To compile this driver as a module, choose M here: the module
78 will be called mma8452. 78 will be called mma8452.
79 79
80config KXCJK1013
81 tristate "Kionix 3-Axis Accelerometer Driver"
82 depends on I2C
83 select IIO_BUFFER
84 select IIO_TRIGGERED_BUFFER
85 help
86 Say Y here if you want to build a driver for the Kionix KXCJK-1013
87 triaxial acceleration sensor.
88
89 To compile this driver as a module, choose M here: the module will
90 be called kxcjk-1013.
91
80endmenu 92endmenu
diff --git a/drivers/iio/accel/Makefile b/drivers/iio/accel/Makefile
index dc0e379c2592..6578ca1a8e09 100644
--- a/drivers/iio/accel/Makefile
+++ b/drivers/iio/accel/Makefile
@@ -5,6 +5,7 @@
5# When adding new entries keep the list in alphabetical order 5# When adding new entries keep the list in alphabetical order
6obj-$(CONFIG_BMA180) += bma180.o 6obj-$(CONFIG_BMA180) += bma180.o
7obj-$(CONFIG_HID_SENSOR_ACCEL_3D) += hid-sensor-accel-3d.o 7obj-$(CONFIG_HID_SENSOR_ACCEL_3D) += hid-sensor-accel-3d.o
8obj-$(CONFIG_KXCJK1013) += kxcjk-1013.o
8obj-$(CONFIG_KXSD9) += kxsd9.o 9obj-$(CONFIG_KXSD9) += kxsd9.o
9obj-$(CONFIG_MMA8452) += mma8452.o 10obj-$(CONFIG_MMA8452) += mma8452.o
10 11
diff --git a/drivers/iio/accel/kxcjk-1013.c b/drivers/iio/accel/kxcjk-1013.c
new file mode 100644
index 000000000000..72a6dbbc18d1
--- /dev/null
+++ b/drivers/iio/accel/kxcjk-1013.c
@@ -0,0 +1,764 @@
1/*
2 * KXCJK-1013 3-axis accelerometer driver
3 * Copyright (c) 2014, Intel Corporation.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 */
14
15#include <linux/module.h>
16#include <linux/i2c.h>
17#include <linux/interrupt.h>
18#include <linux/delay.h>
19#include <linux/bitops.h>
20#include <linux/slab.h>
21#include <linux/string.h>
22#include <linux/acpi.h>
23#include <linux/gpio/consumer.h>
24#include <linux/iio/iio.h>
25#include <linux/iio/sysfs.h>
26#include <linux/iio/buffer.h>
27#include <linux/iio/trigger.h>
28#include <linux/iio/trigger_consumer.h>
29#include <linux/iio/triggered_buffer.h>
30#include <linux/iio/accel/kxcjk_1013.h>
31
32#define KXCJK1013_DRV_NAME "kxcjk1013"
33#define KXCJK1013_IRQ_NAME "kxcjk1013_event"
34
35#define KXCJK1013_REG_XOUT_L 0x06
36/*
37 * From low byte X axis register, all the other addresses of Y and Z can be
38 * obtained by just applying axis offset. The following axis defines are just
39 * provide clarity, but not used.
40 */
41#define KXCJK1013_REG_XOUT_H 0x07
42#define KXCJK1013_REG_YOUT_L 0x08
43#define KXCJK1013_REG_YOUT_H 0x09
44#define KXCJK1013_REG_ZOUT_L 0x0A
45#define KXCJK1013_REG_ZOUT_H 0x0B
46
47#define KXCJK1013_REG_DCST_RESP 0x0C
48#define KXCJK1013_REG_WHO_AM_I 0x0F
49#define KXCJK1013_REG_INT_SRC1 0x16
50#define KXCJK1013_REG_INT_SRC2 0x17
51#define KXCJK1013_REG_STATUS_REG 0x18
52#define KXCJK1013_REG_INT_REL 0x1A
53#define KXCJK1013_REG_CTRL1 0x1B
54#define KXCJK1013_REG_CTRL2 0x1D
55#define KXCJK1013_REG_INT_CTRL1 0x1E
56#define KXCJK1013_REG_INT_CTRL2 0x1F
57#define KXCJK1013_REG_DATA_CTRL 0x21
58#define KXCJK1013_REG_WAKE_TIMER 0x29
59#define KXCJK1013_REG_SELF_TEST 0x3A
60#define KXCJK1013_REG_WAKE_THRES 0x6A
61
62#define KXCJK1013_REG_CTRL1_BIT_PC1 BIT(7)
63#define KXCJK1013_REG_CTRL1_BIT_RES BIT(6)
64#define KXCJK1013_REG_CTRL1_BIT_DRDY BIT(5)
65#define KXCJK1013_REG_CTRL1_BIT_GSEL1 BIT(4)
66#define KXCJK1013_REG_CTRL1_BIT_GSEL0 BIT(3)
67#define KXCJK1013_REG_CTRL1_BIT_WUFE BIT(1)
68#define KXCJK1013_REG_INT_REG1_BIT_IEA BIT(4)
69#define KXCJK1013_REG_INT_REG1_BIT_IEN BIT(5)
70
71#define KXCJK1013_DATA_MASK_12_BIT 0x0FFF
72#define KXCJK1013_MAX_STARTUP_TIME_US 100000
73
74struct kxcjk1013_data {
75 struct i2c_client *client;
76 struct iio_trigger *trig;
77 bool trig_mode;
78 struct mutex mutex;
79 s16 buffer[8];
80 int power_state;
81 u8 odr_bits;
82 bool active_high_intr;
83};
84
85enum kxcjk1013_axis {
86 AXIS_X,
87 AXIS_Y,
88 AXIS_Z,
89};
90
91enum kxcjk1013_mode {
92 STANDBY,
93 OPERATION,
94};
95
96static const struct {
97 int val;
98 int val2;
99 int odr_bits;
100} samp_freq_table[] = { {0, 781000, 0x08}, {1, 563000, 0x09},
101 {3, 125000, 0x0A}, {6, 25000, 0x0B}, {12, 5000, 0},
102 {25, 0, 0x01}, {50, 0, 0x02}, {100, 0, 0x03},
103 {200, 0, 0x04}, {400, 0, 0x05}, {800, 0, 0x06},
104 {1600, 0, 0x07} };
105
106/* Refer to section 4 of the specification */
107static const struct {
108 int odr_bits;
109 int usec;
110} odr_start_up_times[] = { {0x08, 100000}, {0x09, 100000}, {0x0A, 100000},
111 {0x0B, 100000}, { 0, 80000}, {0x01, 41000},
112 {0x02, 21000}, {0x03, 11000}, {0x04, 6400},
113 {0x05, 3900}, {0x06, 2700}, {0x07, 2100} };
114
115static int kxcjk1013_set_mode(struct kxcjk1013_data *data,
116 enum kxcjk1013_mode mode)
117{
118 int ret;
119
120 ret = i2c_smbus_read_byte_data(data->client, KXCJK1013_REG_CTRL1);
121 if (ret < 0) {
122 dev_err(&data->client->dev, "Error reading reg_ctrl1\n");
123 return ret;
124 }
125
126 if (mode == STANDBY)
127 ret &= ~KXCJK1013_REG_CTRL1_BIT_PC1;
128 else
129 ret |= KXCJK1013_REG_CTRL1_BIT_PC1;
130
131 ret = i2c_smbus_write_byte_data(data->client,
132 KXCJK1013_REG_CTRL1, ret);
133 if (ret < 0) {
134 dev_err(&data->client->dev, "Error writing reg_ctrl1\n");
135 return ret;
136 }
137
138 return 0;
139}
140
141static int kxcjk1013_chip_ack_intr(struct kxcjk1013_data *data)
142{
143 int ret;
144
145 ret = i2c_smbus_read_byte_data(data->client, KXCJK1013_REG_INT_REL);
146 if (ret < 0) {
147 dev_err(&data->client->dev, "Error writing reg_int_rel\n");
148 return ret;
149 }
150
151 return ret;
152}
153
154static int kxcjk1013_chip_init(struct kxcjk1013_data *data)
155{
156 int ret;
157
158 ret = i2c_smbus_read_byte_data(data->client, KXCJK1013_REG_WHO_AM_I);
159 if (ret < 0) {
160 dev_err(&data->client->dev, "Error reading who_am_i\n");
161 return ret;
162 }
163
164 dev_dbg(&data->client->dev, "KXCJK1013 Chip Id %x\n", ret);
165
166 ret = kxcjk1013_set_mode(data, STANDBY);
167 if (ret < 0)
168 return ret;
169
170 ret = i2c_smbus_read_byte_data(data->client, KXCJK1013_REG_CTRL1);
171 if (ret < 0) {
172 dev_err(&data->client->dev, "Error reading reg_ctrl1\n");
173 return ret;
174 }
175
176 /* Setting range to 4G */
177 ret |= KXCJK1013_REG_CTRL1_BIT_GSEL0;
178 ret &= ~KXCJK1013_REG_CTRL1_BIT_GSEL1;
179
180 /* Set 12 bit mode */
181 ret |= KXCJK1013_REG_CTRL1_BIT_RES;
182
183 ret = i2c_smbus_write_byte_data(data->client, KXCJK1013_REG_CTRL1,
184 ret);
185 if (ret < 0) {
186 dev_err(&data->client->dev, "Error reading reg_ctrl\n");
187 return ret;
188 }
189
190 ret = i2c_smbus_read_byte_data(data->client, KXCJK1013_REG_DATA_CTRL);
191 if (ret < 0) {
192 dev_err(&data->client->dev, "Error reading reg_data_ctrl\n");
193 return ret;
194 }
195
196 data->odr_bits = ret;
197
198 /* Set up INT polarity */
199 ret = i2c_smbus_read_byte_data(data->client, KXCJK1013_REG_INT_CTRL1);
200 if (ret < 0) {
201 dev_err(&data->client->dev, "Error reading reg_int_ctrl1\n");
202 return ret;
203 }
204
205 if (data->active_high_intr)
206 ret |= KXCJK1013_REG_INT_REG1_BIT_IEA;
207 else
208 ret &= ~KXCJK1013_REG_INT_REG1_BIT_IEA;
209
210 ret = i2c_smbus_write_byte_data(data->client, KXCJK1013_REG_INT_CTRL1,
211 ret);
212 if (ret < 0) {
213 dev_err(&data->client->dev, "Error writing reg_int_ctrl1\n");
214 return ret;
215 }
216
217 return 0;
218}
219
220static int kxcjk1013_chip_setup_interrupt(struct kxcjk1013_data *data,
221 bool status)
222{
223 int ret;
224
225 /* This is requirement by spec to change state to STANDBY */
226 ret = kxcjk1013_set_mode(data, STANDBY);
227 if (ret < 0)
228 return ret;
229
230 ret = i2c_smbus_read_byte_data(data->client, KXCJK1013_REG_INT_CTRL1);
231 if (ret < 0) {
232 dev_err(&data->client->dev, "Error reading reg_int_ctrl1\n");
233 return ret;
234 }
235
236 if (status)
237 ret |= KXCJK1013_REG_INT_REG1_BIT_IEN;
238 else
239 ret &= ~KXCJK1013_REG_INT_REG1_BIT_IEN;
240
241 ret = i2c_smbus_write_byte_data(data->client, KXCJK1013_REG_INT_CTRL1,
242 ret);
243 if (ret < 0) {
244 dev_err(&data->client->dev, "Error writing reg_int_ctrl1\n");
245 return ret;
246 }
247
248 ret = i2c_smbus_read_byte_data(data->client, KXCJK1013_REG_CTRL1);
249 if (ret < 0) {
250 dev_err(&data->client->dev, "Error reading reg_ctrl1\n");
251 return ret;
252 }
253
254 if (status)
255 ret |= KXCJK1013_REG_CTRL1_BIT_DRDY;
256 else
257 ret &= ~KXCJK1013_REG_CTRL1_BIT_DRDY;
258
259 ret = i2c_smbus_write_byte_data(data->client,
260 KXCJK1013_REG_CTRL1, ret);
261 if (ret < 0) {
262 dev_err(&data->client->dev, "Error writing reg_ctrl1\n");
263 return ret;
264 }
265
266 return ret;
267}
268
269static int kxcjk1013_convert_freq_to_bit(int val, int val2)
270{
271 int i;
272
273 for (i = 0; i < ARRAY_SIZE(samp_freq_table); ++i) {
274 if (samp_freq_table[i].val == val &&
275 samp_freq_table[i].val2 == val2) {
276 return samp_freq_table[i].odr_bits;
277 }
278 }
279
280 return -EINVAL;
281}
282
283static int kxcjk1013_set_odr(struct kxcjk1013_data *data, int val, int val2)
284{
285 int ret;
286 int odr_bits;
287
288 odr_bits = kxcjk1013_convert_freq_to_bit(val, val2);
289 if (odr_bits < 0)
290 return odr_bits;
291
292 /* To change ODR, the chip must be set to STANDBY as per spec */
293 ret = kxcjk1013_set_mode(data, STANDBY);
294 if (ret < 0)
295 return ret;
296
297 ret = i2c_smbus_write_byte_data(data->client, KXCJK1013_REG_DATA_CTRL,
298 odr_bits);
299 if (ret < 0) {
300 dev_err(&data->client->dev, "Error writing data_ctrl\n");
301 return ret;
302 }
303
304 data->odr_bits = odr_bits;
305
306 /* Check, if the ODR is changed after data enable */
307 if (data->power_state) {
308 /* Set the state back to operation */
309 ret = kxcjk1013_set_mode(data, OPERATION);
310 if (ret < 0)
311 return ret;
312 }
313
314 return 0;
315}
316
317static int kxcjk1013_get_odr(struct kxcjk1013_data *data, int *val, int *val2)
318{
319 int i;
320
321 for (i = 0; i < ARRAY_SIZE(samp_freq_table); ++i) {
322 if (samp_freq_table[i].odr_bits == data->odr_bits) {
323 *val = samp_freq_table[i].val;
324 *val2 = samp_freq_table[i].val2;
325 return IIO_VAL_INT_PLUS_MICRO;
326 }
327 }
328
329 return -EINVAL;
330}
331
332static int kxcjk1013_get_acc_reg(struct kxcjk1013_data *data, int axis)
333{
334 u8 reg = KXCJK1013_REG_XOUT_L + axis * 2;
335 int ret;
336
337 ret = i2c_smbus_read_word_data(data->client, reg);
338 if (ret < 0) {
339 dev_err(&data->client->dev,
340 "failed to read accel_%c registers\n", 'x' + axis);
341 return ret;
342 }
343
344 return ret;
345}
346
347static int kxcjk1013_get_startup_times(struct kxcjk1013_data *data)
348{
349 int i;
350
351 for (i = 0; i < ARRAY_SIZE(odr_start_up_times); ++i) {
352 if (odr_start_up_times[i].odr_bits == data->odr_bits)
353 return odr_start_up_times[i].usec;
354 }
355
356 return KXCJK1013_MAX_STARTUP_TIME_US;
357}
358
359static int kxcjk1013_read_raw(struct iio_dev *indio_dev,
360 struct iio_chan_spec const *chan, int *val,
361 int *val2, long mask)
362{
363 struct kxcjk1013_data *data = iio_priv(indio_dev);
364 int ret;
365
366 switch (mask) {
367 case IIO_CHAN_INFO_RAW:
368 mutex_lock(&data->mutex);
369 if (iio_buffer_enabled(indio_dev))
370 ret = -EBUSY;
371 else {
372 int sleep_val;
373
374 ret = kxcjk1013_set_mode(data, OPERATION);
375 if (ret < 0) {
376 mutex_unlock(&data->mutex);
377 return ret;
378 }
379 ++data->power_state;
380 sleep_val = kxcjk1013_get_startup_times(data);
381 if (sleep_val < 20000)
382 usleep_range(sleep_val, 20000);
383 else
384 msleep_interruptible(sleep_val/1000);
385 ret = kxcjk1013_get_acc_reg(data, chan->scan_index);
386 if (--data->power_state == 0)
387 kxcjk1013_set_mode(data, STANDBY);
388 }
389 mutex_unlock(&data->mutex);
390
391 if (ret < 0)
392 return ret;
393
394 *val = sign_extend32(ret >> 4, 11);
395 return IIO_VAL_INT;
396
397 case IIO_CHAN_INFO_SCALE:
398 *val = 0;
399 *val2 = 19163; /* range +-4g (4/2047*9.806650) */
400 return IIO_VAL_INT_PLUS_MICRO;
401
402 case IIO_CHAN_INFO_SAMP_FREQ:
403 mutex_lock(&data->mutex);
404 ret = kxcjk1013_get_odr(data, val, val2);
405 mutex_unlock(&data->mutex);
406 return ret;
407
408 default:
409 return -EINVAL;
410 }
411}
412
413static int kxcjk1013_write_raw(struct iio_dev *indio_dev,
414 struct iio_chan_spec const *chan, int val,
415 int val2, long mask)
416{
417 struct kxcjk1013_data *data = iio_priv(indio_dev);
418 int ret;
419
420 switch (mask) {
421 case IIO_CHAN_INFO_SAMP_FREQ:
422 mutex_lock(&data->mutex);
423 ret = kxcjk1013_set_odr(data, val, val2);
424 mutex_unlock(&data->mutex);
425 break;
426 default:
427 ret = -EINVAL;
428 }
429
430 return ret;
431}
432
433static int kxcjk1013_validate_trigger(struct iio_dev *indio_dev,
434 struct iio_trigger *trig)
435{
436 struct kxcjk1013_data *data = iio_priv(indio_dev);
437
438 if (data->trig != trig)
439 return -EINVAL;
440
441 return 0;
442}
443
444static IIO_CONST_ATTR_SAMP_FREQ_AVAIL(
445 "0.781000 1.563000 3.125000 6.250000 12.500000 25 50 100 200 400 800 1600");
446
447static struct attribute *kxcjk1013_attributes[] = {
448 &iio_const_attr_sampling_frequency_available.dev_attr.attr,
449 NULL,
450};
451
452static const struct attribute_group kxcjk1013_attrs_group = {
453 .attrs = kxcjk1013_attributes,
454};
455
456#define KXCJK1013_CHANNEL(_axis) { \
457 .type = IIO_ACCEL, \
458 .modified = 1, \
459 .channel2 = IIO_MOD_##_axis, \
460 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
461 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \
462 BIT(IIO_CHAN_INFO_SAMP_FREQ), \
463 .scan_index = AXIS_##_axis, \
464 .scan_type = { \
465 .sign = 's', \
466 .realbits = 12, \
467 .storagebits = 16, \
468 .shift = 4, \
469 .endianness = IIO_LE, \
470 }, \
471}
472
473static const struct iio_chan_spec kxcjk1013_channels[] = {
474 KXCJK1013_CHANNEL(X),
475 KXCJK1013_CHANNEL(Y),
476 KXCJK1013_CHANNEL(Z),
477 IIO_CHAN_SOFT_TIMESTAMP(3),
478};
479
480static const struct iio_info kxcjk1013_info = {
481 .attrs = &kxcjk1013_attrs_group,
482 .read_raw = kxcjk1013_read_raw,
483 .write_raw = kxcjk1013_write_raw,
484 .validate_trigger = kxcjk1013_validate_trigger,
485 .driver_module = THIS_MODULE,
486};
487
488static irqreturn_t kxcjk1013_trigger_handler(int irq, void *p)
489{
490 struct iio_poll_func *pf = p;
491 struct iio_dev *indio_dev = pf->indio_dev;
492 struct kxcjk1013_data *data = iio_priv(indio_dev);
493 int bit, ret, i = 0;
494
495 mutex_lock(&data->mutex);
496
497 for_each_set_bit(bit, indio_dev->buffer->scan_mask,
498 indio_dev->masklength) {
499 ret = kxcjk1013_get_acc_reg(data, bit);
500 if (ret < 0) {
501 kxcjk1013_chip_ack_intr(data);
502 mutex_unlock(&data->mutex);
503 goto err;
504 }
505 data->buffer[i++] = ret;
506 }
507
508 kxcjk1013_chip_ack_intr(data);
509
510 mutex_unlock(&data->mutex);
511
512 iio_push_to_buffers_with_timestamp(indio_dev, data->buffer,
513 pf->timestamp);
514err:
515 iio_trigger_notify_done(indio_dev->trig);
516
517 return IRQ_HANDLED;
518}
519
520static int kxcjk1013_data_rdy_trigger_set_state(struct iio_trigger *trig,
521 bool state)
522{
523 struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig);
524 struct kxcjk1013_data *data = iio_priv(indio_dev);
525
526 mutex_lock(&data->mutex);
527 if (state) {
528 kxcjk1013_chip_setup_interrupt(data, true);
529 kxcjk1013_set_mode(data, OPERATION);
530 ++data->power_state;
531 } else {
532 if (--data->power_state) {
533 mutex_unlock(&data->mutex);
534 return 0;
535 }
536 kxcjk1013_chip_setup_interrupt(data, false);
537 kxcjk1013_set_mode(data, STANDBY);
538 }
539 mutex_unlock(&data->mutex);
540
541 return 0;
542}
543
544static const struct iio_trigger_ops kxcjk1013_trigger_ops = {
545 .set_trigger_state = kxcjk1013_data_rdy_trigger_set_state,
546 .owner = THIS_MODULE,
547};
548
549static int kxcjk1013_acpi_gpio_probe(struct i2c_client *client,
550 struct kxcjk1013_data *data)
551{
552 const struct acpi_device_id *id;
553 struct device *dev;
554 struct gpio_desc *gpio;
555 int ret;
556
557 if (!client)
558 return -EINVAL;
559
560 dev = &client->dev;
561 if (!ACPI_HANDLE(dev))
562 return -ENODEV;
563
564 id = acpi_match_device(dev->driver->acpi_match_table, dev);
565 if (!id)
566 return -ENODEV;
567
568 /* data ready gpio interrupt pin */
569 gpio = devm_gpiod_get_index(dev, "kxcjk1013_int", 0);
570 if (IS_ERR(gpio)) {
571 dev_err(dev, "acpi gpio get index failed\n");
572 return PTR_ERR(gpio);
573 }
574
575 ret = gpiod_direction_input(gpio);
576 if (ret)
577 return ret;
578
579 ret = gpiod_to_irq(gpio);
580
581 dev_dbg(dev, "GPIO resource, no:%d irq:%d\n", desc_to_gpio(gpio), ret);
582
583 return ret;
584}
585
586static int kxcjk1013_probe(struct i2c_client *client,
587 const struct i2c_device_id *id)
588{
589 struct kxcjk1013_data *data;
590 struct iio_dev *indio_dev;
591 struct iio_trigger *trig = NULL;
592 struct kxcjk_1013_platform_data *pdata;
593 int ret;
594
595 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
596 if (!indio_dev)
597 return -ENOMEM;
598
599 data = iio_priv(indio_dev);
600 i2c_set_clientdata(client, indio_dev);
601 data->client = client;
602
603 pdata = dev_get_platdata(&client->dev);
604 if (pdata)
605 data->active_high_intr = pdata->active_high_intr;
606 else
607 data->active_high_intr = true; /* default polarity */
608
609 ret = kxcjk1013_chip_init(data);
610 if (ret < 0)
611 return ret;
612
613 mutex_init(&data->mutex);
614
615 indio_dev->dev.parent = &client->dev;
616 indio_dev->channels = kxcjk1013_channels;
617 indio_dev->num_channels = ARRAY_SIZE(kxcjk1013_channels);
618 indio_dev->name = KXCJK1013_DRV_NAME;
619 indio_dev->modes = INDIO_DIRECT_MODE;
620 indio_dev->info = &kxcjk1013_info;
621
622 if (client->irq < 0)
623 client->irq = kxcjk1013_acpi_gpio_probe(client, data);
624
625 if (client->irq >= 0) {
626 trig = iio_trigger_alloc("%s-dev%d", indio_dev->name,
627 indio_dev->id);
628 if (!trig)
629 return -ENOMEM;
630
631 data->trig_mode = true;
632
633 ret = devm_request_irq(&client->dev, client->irq,
634 iio_trigger_generic_data_rdy_poll,
635 IRQF_TRIGGER_RISING,
636 KXCJK1013_IRQ_NAME,
637 trig);
638 if (ret) {
639 dev_err(&client->dev, "unable to request IRQ\n");
640 goto err_trigger_free;
641 }
642
643 trig->dev.parent = &client->dev;
644 trig->ops = &kxcjk1013_trigger_ops;
645 iio_trigger_set_drvdata(trig, indio_dev);
646 data->trig = trig;
647 indio_dev->trig = trig;
648
649 ret = iio_trigger_register(trig);
650 if (ret)
651 goto err_trigger_free;
652
653 ret = iio_triggered_buffer_setup(indio_dev,
654 &iio_pollfunc_store_time,
655 kxcjk1013_trigger_handler,
656 NULL);
657 if (ret < 0) {
658 dev_err(&client->dev,
659 "iio triggered buffer setup failed\n");
660 goto err_trigger_unregister;
661 }
662 }
663
664 ret = devm_iio_device_register(&client->dev, indio_dev);
665 if (ret < 0) {
666 dev_err(&client->dev, "unable to register iio device\n");
667 goto err_buffer_cleanup;
668 }
669
670 return 0;
671
672err_buffer_cleanup:
673 if (data->trig_mode)
674 iio_triggered_buffer_cleanup(indio_dev);
675err_trigger_unregister:
676 if (data->trig_mode)
677 iio_trigger_unregister(trig);
678err_trigger_free:
679 if (data->trig_mode)
680 iio_trigger_free(trig);
681
682 return ret;
683}
684
685static int kxcjk1013_remove(struct i2c_client *client)
686{
687 struct iio_dev *indio_dev = i2c_get_clientdata(client);
688 struct kxcjk1013_data *data = iio_priv(indio_dev);
689
690 if (data->trig_mode) {
691 iio_triggered_buffer_cleanup(indio_dev);
692 iio_trigger_unregister(data->trig);
693 iio_trigger_free(data->trig);
694 }
695
696 mutex_lock(&data->mutex);
697 kxcjk1013_set_mode(data, STANDBY);
698 mutex_unlock(&data->mutex);
699
700 return 0;
701}
702
703#ifdef CONFIG_PM_SLEEP
704static int kxcjk1013_suspend(struct device *dev)
705{
706 struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
707 struct kxcjk1013_data *data = iio_priv(indio_dev);
708
709 mutex_lock(&data->mutex);
710 kxcjk1013_set_mode(data, STANDBY);
711 mutex_unlock(&data->mutex);
712
713 return 0;
714}
715
716static int kxcjk1013_resume(struct device *dev)
717{
718 struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
719 struct kxcjk1013_data *data = iio_priv(indio_dev);
720
721 mutex_lock(&data->mutex);
722
723 if (data->power_state)
724 kxcjk1013_set_mode(data, OPERATION);
725
726 mutex_unlock(&data->mutex);
727
728 return 0;
729}
730
731static SIMPLE_DEV_PM_OPS(kxcjk1013_pm_ops, kxcjk1013_suspend, kxcjk1013_resume);
732#define KXCJK1013_PM_OPS (&kxcjk1013_pm_ops)
733#else
734#define KXCJK1013_PM_OPS NULL
735#endif
736
737static const struct acpi_device_id kx_acpi_match[] = {
738 {"KXCJ1013", 0},
739 { },
740};
741MODULE_DEVICE_TABLE(acpi, kx_acpi_match);
742
743static const struct i2c_device_id kxcjk1013_id[] = {
744 {"kxcjk1013", 0},
745 {}
746};
747
748MODULE_DEVICE_TABLE(i2c, kxcjk1013_id);
749
750static struct i2c_driver kxcjk1013_driver = {
751 .driver = {
752 .name = KXCJK1013_DRV_NAME,
753 .acpi_match_table = ACPI_PTR(kx_acpi_match),
754 .pm = KXCJK1013_PM_OPS,
755 },
756 .probe = kxcjk1013_probe,
757 .remove = kxcjk1013_remove,
758 .id_table = kxcjk1013_id,
759};
760module_i2c_driver(kxcjk1013_driver);
761
762MODULE_AUTHOR("Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>");
763MODULE_LICENSE("GPL v2");
764MODULE_DESCRIPTION("KXCJK1013 accelerometer driver");
diff --git a/drivers/iio/adc/ad7298.c b/drivers/iio/adc/ad7298.c
index 2a3b65c74af9..4a8c0a2f49b6 100644
--- a/drivers/iio/adc/ad7298.c
+++ b/drivers/iio/adc/ad7298.c
@@ -16,6 +16,7 @@
16#include <linux/delay.h> 16#include <linux/delay.h>
17#include <linux/module.h> 17#include <linux/module.h>
18#include <linux/interrupt.h> 18#include <linux/interrupt.h>
19#include <linux/bitops.h>
19 20
20#include <linux/iio/iio.h> 21#include <linux/iio/iio.h>
21#include <linux/iio/sysfs.h> 22#include <linux/iio/sysfs.h>
@@ -25,23 +26,19 @@
25 26
26#include <linux/platform_data/ad7298.h> 27#include <linux/platform_data/ad7298.h>
27 28
28#define AD7298_WRITE (1 << 15) /* write to the control register */ 29#define AD7298_WRITE BIT(15) /* write to the control register */
29#define AD7298_REPEAT (1 << 14) /* repeated conversion enable */ 30#define AD7298_REPEAT BIT(14) /* repeated conversion enable */
30#define AD7298_CH(x) (1 << (13 - (x))) /* channel select */ 31#define AD7298_CH(x) BIT(13 - (x)) /* channel select */
31#define AD7298_TSENSE (1 << 5) /* temperature conversion enable */ 32#define AD7298_TSENSE BIT(5) /* temperature conversion enable */
32#define AD7298_EXTREF (1 << 2) /* external reference enable */ 33#define AD7298_EXTREF BIT(2) /* external reference enable */
33#define AD7298_TAVG (1 << 1) /* temperature sensor averaging enable */ 34#define AD7298_TAVG BIT(1) /* temperature sensor averaging enable */
34#define AD7298_PDD (1 << 0) /* partial power down enable */ 35#define AD7298_PDD BIT(0) /* partial power down enable */
35 36
36#define AD7298_MAX_CHAN 8 37#define AD7298_MAX_CHAN 8
37#define AD7298_BITS 12
38#define AD7298_STORAGE_BITS 16
39#define AD7298_INTREF_mV 2500 38#define AD7298_INTREF_mV 2500
40 39
41#define AD7298_CH_TEMP 9 40#define AD7298_CH_TEMP 9
42 41
43#define RES_MASK(bits) ((1 << (bits)) - 1)
44
45struct ad7298_state { 42struct ad7298_state {
46 struct spi_device *spi; 43 struct spi_device *spi;
47 struct regulator *reg; 44 struct regulator *reg;
@@ -257,7 +254,7 @@ static int ad7298_read_raw(struct iio_dev *indio_dev,
257 return ret; 254 return ret;
258 255
259 if (chan->address != AD7298_CH_TEMP) 256 if (chan->address != AD7298_CH_TEMP)
260 *val = ret & RES_MASK(AD7298_BITS); 257 *val = ret & GENMASK(chan->scan_type.realbits - 1, 0);
261 258
262 return IIO_VAL_INT; 259 return IIO_VAL_INT;
263 case IIO_CHAN_INFO_SCALE: 260 case IIO_CHAN_INFO_SCALE:
diff --git a/drivers/iio/adc/ad7476.c b/drivers/iio/adc/ad7476.c
index d141d452c3d1..ce400ec176f1 100644
--- a/drivers/iio/adc/ad7476.c
+++ b/drivers/iio/adc/ad7476.c
@@ -14,6 +14,7 @@
14#include <linux/regulator/consumer.h> 14#include <linux/regulator/consumer.h>
15#include <linux/err.h> 15#include <linux/err.h>
16#include <linux/module.h> 16#include <linux/module.h>
17#include <linux/bitops.h>
17 18
18#include <linux/iio/iio.h> 19#include <linux/iio/iio.h>
19#include <linux/iio/sysfs.h> 20#include <linux/iio/sysfs.h>
@@ -21,8 +22,6 @@
21#include <linux/iio/trigger_consumer.h> 22#include <linux/iio/trigger_consumer.h>
22#include <linux/iio/triggered_buffer.h> 23#include <linux/iio/triggered_buffer.h>
23 24
24#define RES_MASK(bits) ((1 << (bits)) - 1)
25
26struct ad7476_state; 25struct ad7476_state;
27 26
28struct ad7476_chip_info { 27struct ad7476_chip_info {
@@ -117,7 +116,7 @@ static int ad7476_read_raw(struct iio_dev *indio_dev,
117 if (ret < 0) 116 if (ret < 0)
118 return ret; 117 return ret;
119 *val = (ret >> st->chip_info->channel[0].scan_type.shift) & 118 *val = (ret >> st->chip_info->channel[0].scan_type.shift) &
120 RES_MASK(st->chip_info->channel[0].scan_type.realbits); 119 GENMASK(st->chip_info->channel[0].scan_type.realbits - 1, 0);
121 return IIO_VAL_INT; 120 return IIO_VAL_INT;
122 case IIO_CHAN_INFO_SCALE: 121 case IIO_CHAN_INFO_SCALE:
123 if (!st->chip_info->int_vref_uv) { 122 if (!st->chip_info->int_vref_uv) {
diff --git a/drivers/iio/adc/ad7887.c b/drivers/iio/adc/ad7887.c
index 749a6cadab8b..2fd012ee99f5 100644
--- a/drivers/iio/adc/ad7887.c
+++ b/drivers/iio/adc/ad7887.c
@@ -15,6 +15,7 @@
15#include <linux/err.h> 15#include <linux/err.h>
16#include <linux/module.h> 16#include <linux/module.h>
17#include <linux/interrupt.h> 17#include <linux/interrupt.h>
18#include <linux/bitops.h>
18 19
19#include <linux/iio/iio.h> 20#include <linux/iio/iio.h>
20#include <linux/iio/sysfs.h> 21#include <linux/iio/sysfs.h>
@@ -25,14 +26,14 @@
25 26
26#include <linux/platform_data/ad7887.h> 27#include <linux/platform_data/ad7887.h>
27 28
28#define AD7887_REF_DIS (1 << 5) /* on-chip reference disable */ 29#define AD7887_REF_DIS BIT(5) /* on-chip reference disable */
29#define AD7887_DUAL (1 << 4) /* dual-channel mode */ 30#define AD7887_DUAL BIT(4) /* dual-channel mode */
30#define AD7887_CH_AIN1 (1 << 3) /* convert on channel 1, DUAL=1 */ 31#define AD7887_CH_AIN1 BIT(3) /* convert on channel 1, DUAL=1 */
31#define AD7887_CH_AIN0 (0 << 3) /* convert on channel 0, DUAL=0,1 */ 32#define AD7887_CH_AIN0 0 /* convert on channel 0, DUAL=0,1 */
32#define AD7887_PM_MODE1 (0) /* CS based shutdown */ 33#define AD7887_PM_MODE1 0 /* CS based shutdown */
33#define AD7887_PM_MODE2 (1) /* full on */ 34#define AD7887_PM_MODE2 1 /* full on */
34#define AD7887_PM_MODE3 (2) /* auto shutdown after conversion */ 35#define AD7887_PM_MODE3 2 /* auto shutdown after conversion */
35#define AD7887_PM_MODE4 (3) /* standby mode */ 36#define AD7887_PM_MODE4 3 /* standby mode */
36 37
37enum ad7887_channels { 38enum ad7887_channels {
38 AD7887_CH0, 39 AD7887_CH0,
@@ -40,8 +41,6 @@ enum ad7887_channels {
40 AD7887_CH1, 41 AD7887_CH1,
41}; 42};
42 43
43#define RES_MASK(bits) ((1 << (bits)) - 1)
44
45/** 44/**
46 * struct ad7887_chip_info - chip specifc information 45 * struct ad7887_chip_info - chip specifc information
47 * @int_vref_mv: the internal reference voltage 46 * @int_vref_mv: the internal reference voltage
@@ -167,7 +166,7 @@ static int ad7887_read_raw(struct iio_dev *indio_dev,
167 if (ret < 0) 166 if (ret < 0)
168 return ret; 167 return ret;
169 *val = ret >> chan->scan_type.shift; 168 *val = ret >> chan->scan_type.shift;
170 *val &= RES_MASK(chan->scan_type.realbits); 169 *val &= GENMASK(chan->scan_type.realbits - 1, 0);
171 return IIO_VAL_INT; 170 return IIO_VAL_INT;
172 case IIO_CHAN_INFO_SCALE: 171 case IIO_CHAN_INFO_SCALE:
173 if (st->reg) { 172 if (st->reg) {
diff --git a/drivers/iio/adc/ad799x.c b/drivers/iio/adc/ad799x.c
index 39b4cb48d738..7e08c601f66e 100644
--- a/drivers/iio/adc/ad799x.c
+++ b/drivers/iio/adc/ad799x.c
@@ -105,9 +105,8 @@ enum {
105 * struct ad799x_chip_info - chip specific information 105 * struct ad799x_chip_info - chip specific information
106 * @channel: channel specification 106 * @channel: channel specification
107 * @num_channels: number of channels 107 * @num_channels: number of channels
108 * @monitor_mode: whether the chip supports monitor interrupts
109 * @default_config: device default configuration 108 * @default_config: device default configuration
110 * @event_attrs: pointer to the monitor event attribute group 109 * @info: pointer to iio_info struct
111 */ 110 */
112struct ad799x_chip_info { 111struct ad799x_chip_info {
113 struct iio_chan_spec channel[9]; 112 struct iio_chan_spec channel[9];
diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c
index 9a4e0e32a771..c55b81f7f970 100644
--- a/drivers/iio/adc/ad_sigma_delta.c
+++ b/drivers/iio/adc/ad_sigma_delta.c
@@ -410,7 +410,7 @@ static irqreturn_t ad_sd_data_rdy_trig_poll(int irq, void *private)
410 complete(&sigma_delta->completion); 410 complete(&sigma_delta->completion);
411 disable_irq_nosync(irq); 411 disable_irq_nosync(irq);
412 sigma_delta->irq_dis = true; 412 sigma_delta->irq_dis = true;
413 iio_trigger_poll(sigma_delta->trig, iio_get_time_ns()); 413 iio_trigger_poll(sigma_delta->trig);
414 414
415 return IRQ_HANDLED; 415 return IRQ_HANDLED;
416} 416}
diff --git a/drivers/iio/adc/at91_adc.c b/drivers/iio/adc/at91_adc.c
index 3b5bacd4d8da..8a5e67c4ced1 100644
--- a/drivers/iio/adc/at91_adc.c
+++ b/drivers/iio/adc/at91_adc.c
@@ -272,7 +272,7 @@ void handle_adc_eoc_trigger(int irq, struct iio_dev *idev)
272 272
273 if (iio_buffer_enabled(idev)) { 273 if (iio_buffer_enabled(idev)) {
274 disable_irq_nosync(irq); 274 disable_irq_nosync(irq);
275 iio_trigger_poll(idev->trig, iio_get_time_ns()); 275 iio_trigger_poll(idev->trig);
276 } else { 276 } else {
277 st->last_value = at91_adc_readl(st, AT91_ADC_LCDR); 277 st->last_value = at91_adc_readl(st, AT91_ADC_LCDR);
278 st->done = true; 278 st->done = true;
diff --git a/drivers/iio/adc/xilinx-xadc-core.c b/drivers/iio/adc/xilinx-xadc-core.c
index ab52be29141b..fd2745c62943 100644
--- a/drivers/iio/adc/xilinx-xadc-core.c
+++ b/drivers/iio/adc/xilinx-xadc-core.c
@@ -486,7 +486,7 @@ static irqreturn_t xadc_axi_interrupt_handler(int irq, void *devid)
486 return IRQ_NONE; 486 return IRQ_NONE;
487 487
488 if ((status & XADC_AXI_INT_EOS) && xadc->trigger) 488 if ((status & XADC_AXI_INT_EOS) && xadc->trigger)
489 iio_trigger_poll(xadc->trigger, 0); 489 iio_trigger_poll(xadc->trigger);
490 490
491 if (status & XADC_AXI_INT_ALARM_MASK) { 491 if (status & XADC_AXI_INT_ALARM_MASK) {
492 /* 492 /*
diff --git a/drivers/iio/dac/ad5504.c b/drivers/iio/dac/ad5504.c
index 1e6449346b50..c917dd24090a 100644
--- a/drivers/iio/dac/ad5504.c
+++ b/drivers/iio/dac/ad5504.c
@@ -15,17 +15,16 @@
15#include <linux/sysfs.h> 15#include <linux/sysfs.h>
16#include <linux/regulator/consumer.h> 16#include <linux/regulator/consumer.h>
17#include <linux/module.h> 17#include <linux/module.h>
18#include <linux/bitops.h>
18 19
19#include <linux/iio/iio.h> 20#include <linux/iio/iio.h>
20#include <linux/iio/sysfs.h> 21#include <linux/iio/sysfs.h>
21#include <linux/iio/events.h> 22#include <linux/iio/events.h>
22#include <linux/iio/dac/ad5504.h> 23#include <linux/iio/dac/ad5504.h>
23 24
24#define AD5505_BITS 12 25#define AD5504_RES_MASK GENMASK(11, 0)
25#define AD5504_RES_MASK ((1 << (AD5505_BITS)) - 1) 26#define AD5504_CMD_READ BIT(15)
26 27#define AD5504_CMD_WRITE 0
27#define AD5504_CMD_READ (1 << 15)
28#define AD5504_CMD_WRITE (0 << 15)
29#define AD5504_ADDR(addr) ((addr) << 12) 28#define AD5504_ADDR(addr) ((addr) << 12)
30 29
31/* Registers */ 30/* Registers */
@@ -42,7 +41,7 @@
42 41
43/** 42/**
44 * struct ad5446_state - driver instance specific data 43 * struct ad5446_state - driver instance specific data
45 * @us: spi_device 44 * @spi: spi_device
46 * @reg: supply regulator 45 * @reg: supply regulator
47 * @vref_mv: actual reference voltage used 46 * @vref_mv: actual reference voltage used
48 * @pwr_down_mask power down mask 47 * @pwr_down_mask power down mask
diff --git a/drivers/iio/dac/ad5791.c b/drivers/iio/dac/ad5791.c
index ae49afe2b380..5ba785f18589 100644
--- a/drivers/iio/dac/ad5791.c
+++ b/drivers/iio/dac/ad5791.c
@@ -16,17 +16,16 @@
16#include <linux/sysfs.h> 16#include <linux/sysfs.h>
17#include <linux/regulator/consumer.h> 17#include <linux/regulator/consumer.h>
18#include <linux/module.h> 18#include <linux/module.h>
19#include <linux/bitops.h>
19 20
20#include <linux/iio/iio.h> 21#include <linux/iio/iio.h>
21#include <linux/iio/sysfs.h> 22#include <linux/iio/sysfs.h>
22#include <linux/iio/dac/ad5791.h> 23#include <linux/iio/dac/ad5791.h>
23 24
24#define AD5791_RES_MASK(x) ((1 << (x)) - 1) 25#define AD5791_DAC_MASK GENMASK(19, 0)
25#define AD5791_DAC_MASK AD5791_RES_MASK(20)
26#define AD5791_DAC_MSB (1 << 19)
27 26
28#define AD5791_CMD_READ (1 << 23) 27#define AD5791_CMD_READ BIT(23)
29#define AD5791_CMD_WRITE (0 << 23) 28#define AD5791_CMD_WRITE 0
30#define AD5791_ADDR(addr) ((addr) << 20) 29#define AD5791_ADDR(addr) ((addr) << 20)
31 30
32/* Registers */ 31/* Registers */
@@ -37,11 +36,11 @@
37#define AD5791_ADDR_SW_CTRL 4 36#define AD5791_ADDR_SW_CTRL 4
38 37
39/* Control Register */ 38/* Control Register */
40#define AD5791_CTRL_RBUF (1 << 1) 39#define AD5791_CTRL_RBUF BIT(1)
41#define AD5791_CTRL_OPGND (1 << 2) 40#define AD5791_CTRL_OPGND BIT(2)
42#define AD5791_CTRL_DACTRI (1 << 3) 41#define AD5791_CTRL_DACTRI BIT(3)
43#define AD5791_CTRL_BIN2SC (1 << 4) 42#define AD5791_CTRL_BIN2SC BIT(4)
44#define AD5791_CTRL_SDODIS (1 << 5) 43#define AD5791_CTRL_SDODIS BIT(5)
45#define AD5761_CTRL_LINCOMP(x) ((x) << 6) 44#define AD5761_CTRL_LINCOMP(x) ((x) << 6)
46 45
47#define AD5791_LINCOMP_0_10 0 46#define AD5791_LINCOMP_0_10 0
@@ -54,9 +53,9 @@
54#define AD5780_LINCOMP_10_20 12 53#define AD5780_LINCOMP_10_20 12
55 54
56/* Software Control Register */ 55/* Software Control Register */
57#define AD5791_SWCTRL_LDAC (1 << 0) 56#define AD5791_SWCTRL_LDAC BIT(0)
58#define AD5791_SWCTRL_CLR (1 << 1) 57#define AD5791_SWCTRL_CLR BIT(1)
59#define AD5791_SWCTRL_RESET (1 << 2) 58#define AD5791_SWCTRL_RESET BIT(2)
60 59
61#define AD5791_DAC_PWRDN_6K 0 60#define AD5791_DAC_PWRDN_6K 0
62#define AD5791_DAC_PWRDN_3STATE 1 61#define AD5791_DAC_PWRDN_3STATE 1
@@ -72,7 +71,7 @@ struct ad5791_chip_info {
72 71
73/** 72/**
74 * struct ad5791_state - driver instance specific data 73 * struct ad5791_state - driver instance specific data
75 * @us: spi_device 74 * @spi: spi_device
76 * @reg_vdd: positive supply regulator 75 * @reg_vdd: positive supply regulator
77 * @reg_vss: negative supply regulator 76 * @reg_vss: negative supply regulator
78 * @chip_info: chip model specific constants 77 * @chip_info: chip model specific constants
@@ -328,7 +327,7 @@ static int ad5791_write_raw(struct iio_dev *indio_dev,
328 327
329 switch (mask) { 328 switch (mask) {
330 case IIO_CHAN_INFO_RAW: 329 case IIO_CHAN_INFO_RAW:
331 val &= AD5791_RES_MASK(chan->scan_type.realbits); 330 val &= GENMASK(chan->scan_type.realbits - 1, 0);
332 val <<= chan->scan_type.shift; 331 val <<= chan->scan_type.shift;
333 332
334 return ad5791_spi_write(st, chan->address, val); 333 return ad5791_spi_write(st, chan->address, val);
diff --git a/drivers/iio/industrialio-trigger.c b/drivers/iio/industrialio-trigger.c
index 3383b025f62e..d31098e0c43f 100644
--- a/drivers/iio/industrialio-trigger.c
+++ b/drivers/iio/industrialio-trigger.c
@@ -114,7 +114,7 @@ static struct iio_trigger *iio_trigger_find_by_name(const char *name,
114 return trig; 114 return trig;
115} 115}
116 116
117void iio_trigger_poll(struct iio_trigger *trig, s64 time) 117void iio_trigger_poll(struct iio_trigger *trig)
118{ 118{
119 int i; 119 int i;
120 120
@@ -133,12 +133,12 @@ EXPORT_SYMBOL(iio_trigger_poll);
133 133
134irqreturn_t iio_trigger_generic_data_rdy_poll(int irq, void *private) 134irqreturn_t iio_trigger_generic_data_rdy_poll(int irq, void *private)
135{ 135{
136 iio_trigger_poll(private, iio_get_time_ns()); 136 iio_trigger_poll(private);
137 return IRQ_HANDLED; 137 return IRQ_HANDLED;
138} 138}
139EXPORT_SYMBOL(iio_trigger_generic_data_rdy_poll); 139EXPORT_SYMBOL(iio_trigger_generic_data_rdy_poll);
140 140
141void iio_trigger_poll_chained(struct iio_trigger *trig, s64 time) 141void iio_trigger_poll_chained(struct iio_trigger *trig)
142{ 142{
143 int i; 143 int i;
144 144
@@ -161,7 +161,7 @@ void iio_trigger_notify_done(struct iio_trigger *trig)
161 trig->ops->try_reenable) 161 trig->ops->try_reenable)
162 if (trig->ops->try_reenable(trig)) 162 if (trig->ops->try_reenable(trig))
163 /* Missed an interrupt so launch new poll now */ 163 /* Missed an interrupt so launch new poll now */
164 iio_trigger_poll(trig, 0); 164 iio_trigger_poll(trig);
165} 165}
166EXPORT_SYMBOL(iio_trigger_notify_done); 166EXPORT_SYMBOL(iio_trigger_notify_done);
167 167
diff --git a/drivers/iio/light/gp2ap020a00f.c b/drivers/iio/light/gp2ap020a00f.c
index 04bdb85d2d9f..221ed16de1f7 100644
--- a/drivers/iio/light/gp2ap020a00f.c
+++ b/drivers/iio/light/gp2ap020a00f.c
@@ -827,7 +827,7 @@ static void gp2ap020a00f_iio_trigger_work(struct irq_work *work)
827 struct gp2ap020a00f_data *data = 827 struct gp2ap020a00f_data *data =
828 container_of(work, struct gp2ap020a00f_data, work); 828 container_of(work, struct gp2ap020a00f_data, work);
829 829
830 iio_trigger_poll(data->trig, 0); 830 iio_trigger_poll(data->trig);
831} 831}
832 832
833static irqreturn_t gp2ap020a00f_prox_sensing_handler(int irq, void *data) 833static irqreturn_t gp2ap020a00f_prox_sensing_handler(int irq, void *data)
diff --git a/drivers/iio/magnetometer/Kconfig b/drivers/iio/magnetometer/Kconfig
index 05a364c543f8..b2dba9e506ab 100644
--- a/drivers/iio/magnetometer/Kconfig
+++ b/drivers/iio/magnetometer/Kconfig
@@ -17,6 +17,16 @@ config AK8975
17 To compile this driver as a module, choose M here: the module 17 To compile this driver as a module, choose M here: the module
18 will be called ak8975. 18 will be called ak8975.
19 19
20config AK09911
21 tristate "Asahi Kasei AK09911 3-axis Compass"
22 depends on I2C
23 help
24 Say yes here to build support for Asahi Kasei AK09911 3-Axis
25 Magnetometer.
26
27 To compile this driver as a module, choose M here: the module
28 will be called ak09911.
29
20config MAG3110 30config MAG3110
21 tristate "Freescale MAG3110 3-Axis Magnetometer" 31 tristate "Freescale MAG3110 3-Axis Magnetometer"
22 depends on I2C 32 depends on I2C
diff --git a/drivers/iio/magnetometer/Makefile b/drivers/iio/magnetometer/Makefile
index 0f5d3c985799..b91315e0b826 100644
--- a/drivers/iio/magnetometer/Makefile
+++ b/drivers/iio/magnetometer/Makefile
@@ -3,6 +3,7 @@
3# 3#
4 4
5# When adding new entries keep the list in alphabetical order 5# When adding new entries keep the list in alphabetical order
6obj-$(CONFIG_AK09911) += ak09911.o
6obj-$(CONFIG_AK8975) += ak8975.o 7obj-$(CONFIG_AK8975) += ak8975.o
7obj-$(CONFIG_MAG3110) += mag3110.o 8obj-$(CONFIG_MAG3110) += mag3110.o
8obj-$(CONFIG_HID_SENSOR_MAGNETOMETER_3D) += hid-sensor-magn-3d.o 9obj-$(CONFIG_HID_SENSOR_MAGNETOMETER_3D) += hid-sensor-magn-3d.o
diff --git a/drivers/iio/magnetometer/ak09911.c b/drivers/iio/magnetometer/ak09911.c
new file mode 100644
index 000000000000..b2bc942ff6b8
--- /dev/null
+++ b/drivers/iio/magnetometer/ak09911.c
@@ -0,0 +1,326 @@
1/*
2 * AK09911 3-axis compass driver
3 * Copyright (c) 2014, Intel Corporation.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 */
14
15#include <linux/kernel.h>
16#include <linux/module.h>
17#include <linux/init.h>
18#include <linux/types.h>
19#include <linux/slab.h>
20#include <linux/delay.h>
21#include <linux/i2c.h>
22#include <linux/acpi.h>
23#include <linux/iio/iio.h>
24
25#define AK09911_REG_WIA1 0x00
26#define AK09911_REG_WIA2 0x01
27#define AK09911_WIA1_VALUE 0x48
28#define AK09911_WIA2_VALUE 0x05
29
30#define AK09911_REG_ST1 0x10
31#define AK09911_REG_HXL 0x11
32#define AK09911_REG_HXH 0x12
33#define AK09911_REG_HYL 0x13
34#define AK09911_REG_HYH 0x14
35#define AK09911_REG_HZL 0x15
36#define AK09911_REG_HZH 0x16
37
38#define AK09911_REG_ASAX 0x60
39#define AK09911_REG_ASAY 0x61
40#define AK09911_REG_ASAZ 0x62
41
42#define AK09911_REG_CNTL1 0x30
43#define AK09911_REG_CNTL2 0x31
44#define AK09911_REG_CNTL3 0x32
45
46#define AK09911_MODE_SNG_MEASURE 0x01
47#define AK09911_MODE_SELF_TEST 0x10
48#define AK09911_MODE_FUSE_ACCESS 0x1F
49#define AK09911_MODE_POWERDOWN 0x00
50#define AK09911_RESET_DATA 0x01
51
52#define AK09911_REG_CNTL1 0x30
53#define AK09911_REG_CNTL2 0x31
54#define AK09911_REG_CNTL3 0x32
55
56#define AK09911_RAW_TO_GAUSS(asa) ((((asa) + 128) * 6000) / 256)
57
58#define AK09911_MAX_CONVERSION_TIMEOUT_MS 500
59#define AK09911_CONVERSION_DONE_POLL_TIME_MS 10
60
61struct ak09911_data {
62 struct i2c_client *client;
63 struct mutex lock;
64 u8 asa[3];
65 long raw_to_gauss[3];
66};
67
68static const int ak09911_index_to_reg[] = {
69 AK09911_REG_HXL, AK09911_REG_HYL, AK09911_REG_HZL,
70};
71
72static int ak09911_set_mode(struct i2c_client *client, u8 mode)
73{
74 int ret;
75
76 switch (mode) {
77 case AK09911_MODE_SNG_MEASURE:
78 case AK09911_MODE_SELF_TEST:
79 case AK09911_MODE_FUSE_ACCESS:
80 case AK09911_MODE_POWERDOWN:
81 ret = i2c_smbus_write_byte_data(client,
82 AK09911_REG_CNTL2, mode);
83 if (ret < 0) {
84 dev_err(&client->dev, "set_mode error\n");
85 return ret;
86 }
87 /* After mode change wait atleast 100us */
88 usleep_range(100, 500);
89 break;
90 default:
91 dev_err(&client->dev,
92 "%s: Unknown mode(%d).", __func__, mode);
93 return -EINVAL;
94 }
95
96 return ret;
97}
98
99/* Get Sensitivity Adjustment value */
100static int ak09911_get_asa(struct i2c_client *client)
101{
102 struct iio_dev *indio_dev = i2c_get_clientdata(client);
103 struct ak09911_data *data = iio_priv(indio_dev);
104 int ret;
105
106 ret = ak09911_set_mode(client, AK09911_MODE_FUSE_ACCESS);
107 if (ret < 0)
108 return ret;
109
110 /* Get asa data and store in the device data. */
111 ret = i2c_smbus_read_i2c_block_data(client, AK09911_REG_ASAX,
112 3, data->asa);
113 if (ret < 0) {
114 dev_err(&client->dev, "Not able to read asa data\n");
115 return ret;
116 }
117
118 ret = ak09911_set_mode(client, AK09911_MODE_POWERDOWN);
119 if (ret < 0)
120 return ret;
121
122 data->raw_to_gauss[0] = AK09911_RAW_TO_GAUSS(data->asa[0]);
123 data->raw_to_gauss[1] = AK09911_RAW_TO_GAUSS(data->asa[1]);
124 data->raw_to_gauss[2] = AK09911_RAW_TO_GAUSS(data->asa[2]);
125
126 return 0;
127}
128
129static int ak09911_verify_chip_id(struct i2c_client *client)
130{
131 u8 wia_val[2];
132 int ret;
133
134 ret = i2c_smbus_read_i2c_block_data(client, AK09911_REG_WIA1,
135 2, wia_val);
136 if (ret < 0) {
137 dev_err(&client->dev, "Error reading WIA\n");
138 return ret;
139 }
140
141 dev_dbg(&client->dev, "WIA %02x %02x\n", wia_val[0], wia_val[1]);
142
143 if (wia_val[0] != AK09911_WIA1_VALUE ||
144 wia_val[1] != AK09911_WIA2_VALUE) {
145 dev_err(&client->dev, "Device ak09911 not found\n");
146 return -ENODEV;
147 }
148
149 return 0;
150}
151
152static int wait_conversion_complete_polled(struct ak09911_data *data)
153{
154 struct i2c_client *client = data->client;
155 u8 read_status;
156 u32 timeout_ms = AK09911_MAX_CONVERSION_TIMEOUT_MS;
157 int ret;
158
159 /* Wait for the conversion to complete. */
160 while (timeout_ms) {
161 msleep_interruptible(AK09911_CONVERSION_DONE_POLL_TIME_MS);
162 ret = i2c_smbus_read_byte_data(client, AK09911_REG_ST1);
163 if (ret < 0) {
164 dev_err(&client->dev, "Error in reading ST1\n");
165 return ret;
166 }
167 read_status = ret & 0x01;
168 if (read_status)
169 break;
170 timeout_ms -= AK09911_CONVERSION_DONE_POLL_TIME_MS;
171 }
172 if (!timeout_ms) {
173 dev_err(&client->dev, "Conversion timeout happened\n");
174 return -EIO;
175 }
176
177 return read_status;
178}
179
180static int ak09911_read_axis(struct iio_dev *indio_dev, int index, int *val)
181{
182 struct ak09911_data *data = iio_priv(indio_dev);
183 struct i2c_client *client = data->client;
184 int ret;
185
186 mutex_lock(&data->lock);
187
188 ret = ak09911_set_mode(client, AK09911_MODE_SNG_MEASURE);
189 if (ret < 0)
190 goto fn_exit;
191
192 ret = wait_conversion_complete_polled(data);
193 if (ret < 0)
194 goto fn_exit;
195
196 /* Read data */
197 ret = i2c_smbus_read_word_data(client, ak09911_index_to_reg[index]);
198 if (ret < 0) {
199 dev_err(&client->dev, "Read axis data fails\n");
200 goto fn_exit;
201 }
202
203 mutex_unlock(&data->lock);
204
205 /* Clamp to valid range. */
206 *val = sign_extend32(clamp_t(s16, ret, -8192, 8191), 13);
207
208 return IIO_VAL_INT;
209
210fn_exit:
211 mutex_unlock(&data->lock);
212
213 return ret;
214}
215
216static int ak09911_read_raw(struct iio_dev *indio_dev,
217 struct iio_chan_spec const *chan,
218 int *val, int *val2,
219 long mask)
220{
221 struct ak09911_data *data = iio_priv(indio_dev);
222
223 switch (mask) {
224 case IIO_CHAN_INFO_RAW:
225 return ak09911_read_axis(indio_dev, chan->address, val);
226 case IIO_CHAN_INFO_SCALE:
227 *val = 0;
228 *val2 = data->raw_to_gauss[chan->address];
229 return IIO_VAL_INT_PLUS_MICRO;
230 }
231
232 return -EINVAL;
233}
234
235#define AK09911_CHANNEL(axis, index) \
236 { \
237 .type = IIO_MAGN, \
238 .modified = 1, \
239 .channel2 = IIO_MOD_##axis, \
240 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
241 BIT(IIO_CHAN_INFO_SCALE), \
242 .address = index, \
243 }
244
245static const struct iio_chan_spec ak09911_channels[] = {
246 AK09911_CHANNEL(X, 0), AK09911_CHANNEL(Y, 1), AK09911_CHANNEL(Z, 2),
247};
248
249static const struct iio_info ak09911_info = {
250 .read_raw = &ak09911_read_raw,
251 .driver_module = THIS_MODULE,
252};
253
254static const struct acpi_device_id ak_acpi_match[] = {
255 {"AK009911", 0},
256 { },
257};
258MODULE_DEVICE_TABLE(acpi, ak_acpi_match);
259
260static int ak09911_probe(struct i2c_client *client,
261 const struct i2c_device_id *id)
262{
263 struct iio_dev *indio_dev;
264 struct ak09911_data *data;
265 const char *name;
266 int ret;
267
268 ret = ak09911_verify_chip_id(client);
269 if (ret) {
270 dev_err(&client->dev, "AK00911 not detected\n");
271 return -ENODEV;
272 }
273
274 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
275 if (indio_dev == NULL)
276 return -ENOMEM;
277
278 data = iio_priv(indio_dev);
279 i2c_set_clientdata(client, indio_dev);
280
281 data->client = client;
282 mutex_init(&data->lock);
283
284 ret = ak09911_get_asa(client);
285 if (ret)
286 return ret;
287
288 if (id)
289 name = id->name;
290 else if (ACPI_HANDLE(&client->dev))
291 name = dev_name(&client->dev);
292 else
293 return -ENODEV;
294
295 dev_dbg(&client->dev, "Asahi compass chip %s\n", name);
296
297 indio_dev->dev.parent = &client->dev;
298 indio_dev->channels = ak09911_channels;
299 indio_dev->num_channels = ARRAY_SIZE(ak09911_channels);
300 indio_dev->info = &ak09911_info;
301 indio_dev->modes = INDIO_DIRECT_MODE;
302 indio_dev->name = name;
303
304 return devm_iio_device_register(&client->dev, indio_dev);
305}
306
307static const struct i2c_device_id ak09911_id[] = {
308 {"ak09911", 0},
309 {}
310};
311
312MODULE_DEVICE_TABLE(i2c, ak09911_id);
313
314static struct i2c_driver ak09911_driver = {
315 .driver = {
316 .name = "ak09911",
317 .acpi_match_table = ACPI_PTR(ak_acpi_match),
318 },
319 .probe = ak09911_probe,
320 .id_table = ak09911_id,
321};
322module_i2c_driver(ak09911_driver);
323
324MODULE_AUTHOR("Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>");
325MODULE_LICENSE("GPL v2");
326MODULE_DESCRIPTION("AK09911 Compass driver");
diff --git a/drivers/iio/pressure/Kconfig b/drivers/iio/pressure/Kconfig
index ffac8ac1efca..15afbc919521 100644
--- a/drivers/iio/pressure/Kconfig
+++ b/drivers/iio/pressure/Kconfig
@@ -70,4 +70,14 @@ config IIO_ST_PRESS_SPI
70 depends on IIO_ST_PRESS 70 depends on IIO_ST_PRESS
71 depends on IIO_ST_SENSORS_SPI 71 depends on IIO_ST_SENSORS_SPI
72 72
73config T5403
74 tristate "EPCOS T5403 digital barometric pressure sensor driver"
75 depends on I2C
76 help
77 Say yes here to build support for the EPCOS T5403 pressure sensor
78 connected via I2C.
79
80 To compile this driver as a module, choose M here: the module
81 will be called t5403.
82
73endmenu 83endmenu
diff --git a/drivers/iio/pressure/Makefile b/drivers/iio/pressure/Makefile
index c53d2500737a..90a37e85cf21 100644
--- a/drivers/iio/pressure/Makefile
+++ b/drivers/iio/pressure/Makefile
@@ -9,6 +9,7 @@ obj-$(CONFIG_MPL3115) += mpl3115.o
9obj-$(CONFIG_IIO_ST_PRESS) += st_pressure.o 9obj-$(CONFIG_IIO_ST_PRESS) += st_pressure.o
10st_pressure-y := st_pressure_core.o 10st_pressure-y := st_pressure_core.o
11st_pressure-$(CONFIG_IIO_BUFFER) += st_pressure_buffer.o 11st_pressure-$(CONFIG_IIO_BUFFER) += st_pressure_buffer.o
12obj-$(CONFIG_T5403) += t5403.o
12 13
13obj-$(CONFIG_IIO_ST_PRESS_I2C) += st_pressure_i2c.o 14obj-$(CONFIG_IIO_ST_PRESS_I2C) += st_pressure_i2c.o
14obj-$(CONFIG_IIO_ST_PRESS_SPI) += st_pressure_spi.o 15obj-$(CONFIG_IIO_ST_PRESS_SPI) += st_pressure_spi.o
diff --git a/drivers/iio/pressure/t5403.c b/drivers/iio/pressure/t5403.c
new file mode 100644
index 000000000000..e11cd3938d67
--- /dev/null
+++ b/drivers/iio/pressure/t5403.c
@@ -0,0 +1,275 @@
1/*
2 * t5403.c - Support for EPCOS T5403 pressure/temperature sensor
3 *
4 * Copyright (c) 2014 Peter Meerwald <pmeerw@pmeerw.net>
5 *
6 * This file is subject to the terms and conditions of version 2 of
7 * the GNU General Public License. See the file COPYING in the main
8 * directory of this archive for more details.
9 *
10 * (7-bit I2C slave address 0x77)
11 *
12 * TODO: end-of-conversion irq
13 */
14
15#include <linux/module.h>
16#include <linux/i2c.h>
17#include <linux/iio/iio.h>
18#include <linux/iio/sysfs.h>
19#include <linux/delay.h>
20
21#define T5403_DATA 0xf5 /* data, LSB first, 16 bit */
22#define T5403_CALIB_DATA 0x8e /* 10 calibration coeff., LSB first, 16 bit */
23#define T5403_SLAVE_ADDR 0x88 /* I2C slave address, 0x77 */
24#define T5403_COMMAND 0xf1
25
26/* command bits */
27#define T5403_MODE_SHIFT 3 /* conversion time: 2, 8, 16, 66 ms */
28#define T5403_PT BIT(1) /* 0 .. pressure, 1 .. temperature measurement */
29#define T5403_SCO BIT(0) /* start conversion */
30
31#define T5403_MODE_LOW 0
32#define T5403_MODE_STANDARD 1
33#define T5403_MODE_HIGH 2
34#define T5403_MODE_ULTRA_HIGH 3
35
36#define T5403_I2C_MASK (~BIT(7))
37#define T5403_I2C_ADDR 0x77
38
39static const int t5403_pressure_conv_ms[] = {2, 8, 16, 66};
40
41struct t5403_data {
42 struct i2c_client *client;
43 struct mutex lock;
44 int mode;
45 __le16 c[10];
46};
47
48#define T5403_C_U16(i) le16_to_cpu(data->c[(i) - 1])
49#define T5403_C(i) sign_extend32(T5403_C_U16(i), 15)
50
51static int t5403_read(struct t5403_data *data, bool pressure)
52{
53 int wait_time = 3; /* wakeup time in ms */
54
55 int ret = i2c_smbus_write_byte_data(data->client, T5403_COMMAND,
56 (pressure ? (data->mode << T5403_MODE_SHIFT) : T5403_PT) |
57 T5403_SCO);
58 if (ret < 0)
59 return ret;
60
61 wait_time += pressure ? t5403_pressure_conv_ms[data->mode] : 2;
62
63 msleep(wait_time);
64
65 return i2c_smbus_read_word_data(data->client, T5403_DATA);
66}
67
68static int t5403_comp_pressure(struct t5403_data *data, int *val, int *val2)
69{
70 int ret;
71 s16 t_r;
72 u16 p_r;
73 s32 S, O, X;
74
75 mutex_lock(&data->lock);
76
77 ret = t5403_read(data, false);
78 if (ret < 0)
79 goto done;
80 t_r = ret;
81
82 ret = t5403_read(data, true);
83 if (ret < 0)
84 goto done;
85 p_r = ret;
86
87 /* see EPCOS application note */
88 S = T5403_C_U16(3) + (s32) T5403_C_U16(4) * t_r / 0x20000 +
89 T5403_C(5) * t_r / 0x8000 * t_r / 0x80000 +
90 T5403_C(9) * t_r / 0x8000 * t_r / 0x8000 * t_r / 0x10000;
91
92 O = T5403_C(6) * 0x4000 + T5403_C(7) * t_r / 8 +
93 T5403_C(8) * t_r / 0x8000 * t_r / 16 +
94 T5403_C(9) * t_r / 0x8000 * t_r / 0x10000 * t_r;
95
96 X = (S * p_r + O) / 0x4000;
97
98 X += ((X - 75000) * (X - 75000) / 0x10000 - 9537) *
99 T5403_C(10) / 0x10000;
100
101 *val = X / 1000;
102 *val2 = (X % 1000) * 1000;
103
104done:
105 mutex_unlock(&data->lock);
106 return ret;
107}
108
109static int t5403_comp_temp(struct t5403_data *data, int *val)
110{
111 int ret;
112 s16 t_r;
113
114 mutex_lock(&data->lock);
115 ret = t5403_read(data, false);
116 if (ret < 0)
117 goto done;
118 t_r = ret;
119
120 /* see EPCOS application note */
121 *val = ((s32) T5403_C_U16(1) * t_r / 0x100 +
122 (s32) T5403_C_U16(2) * 0x40) * 1000 / 0x10000;
123
124done:
125 mutex_unlock(&data->lock);
126 return ret;
127}
128
129static int t5403_read_raw(struct iio_dev *indio_dev,
130 struct iio_chan_spec const *chan,
131 int *val, int *val2, long mask)
132{
133 struct t5403_data *data = iio_priv(indio_dev);
134 int ret;
135
136 switch (mask) {
137 case IIO_CHAN_INFO_PROCESSED:
138 switch (chan->type) {
139 case IIO_PRESSURE:
140 ret = t5403_comp_pressure(data, val, val2);
141 if (ret < 0)
142 return ret;
143 return IIO_VAL_INT_PLUS_MICRO;
144 case IIO_TEMP:
145 ret = t5403_comp_temp(data, val);
146 if (ret < 0)
147 return ret;
148 return IIO_VAL_INT;
149 default:
150 return -EINVAL;
151 }
152 case IIO_CHAN_INFO_INT_TIME:
153 *val = 0;
154 *val2 = t5403_pressure_conv_ms[data->mode] * 1000;
155 return IIO_VAL_INT_PLUS_MICRO;
156 default:
157 return -EINVAL;
158 }
159}
160
161static int t5403_write_raw(struct iio_dev *indio_dev,
162 struct iio_chan_spec const *chan,
163 int val, int val2, long mask)
164{
165 struct t5403_data *data = iio_priv(indio_dev);
166 int i;
167
168 switch (mask) {
169 case IIO_CHAN_INFO_INT_TIME:
170 if (val != 0)
171 return -EINVAL;
172 for (i = 0; i < ARRAY_SIZE(t5403_pressure_conv_ms); i++)
173 if (val2 == t5403_pressure_conv_ms[i] * 1000) {
174 mutex_lock(&data->lock);
175 data->mode = i;
176 mutex_unlock(&data->lock);
177 return 0;
178 }
179 return -EINVAL;
180 default:
181 return -EINVAL;
182 }
183}
184
185static const struct iio_chan_spec t5403_channels[] = {
186 {
187 .type = IIO_PRESSURE,
188 .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) |
189 BIT(IIO_CHAN_INFO_INT_TIME),
190 },
191 {
192 .type = IIO_TEMP,
193 .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
194 },
195};
196
197static IIO_CONST_ATTR_INT_TIME_AVAIL("0.002 0.008 0.016 0.066");
198
199static struct attribute *t5403_attributes[] = {
200 &iio_const_attr_integration_time_available.dev_attr.attr,
201 NULL
202};
203
204static const struct attribute_group t5403_attribute_group = {
205 .attrs = t5403_attributes,
206};
207
208static const struct iio_info t5403_info = {
209 .read_raw = &t5403_read_raw,
210 .write_raw = &t5403_write_raw,
211 .attrs = &t5403_attribute_group,
212 .driver_module = THIS_MODULE,
213};
214
215static int t5403_probe(struct i2c_client *client,
216 const struct i2c_device_id *id)
217{
218 struct t5403_data *data;
219 struct iio_dev *indio_dev;
220 int ret;
221
222 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_WORD_DATA |
223 I2C_FUNC_SMBUS_I2C_BLOCK))
224 return -ENODEV;
225
226 ret = i2c_smbus_read_byte_data(client, T5403_SLAVE_ADDR);
227 if (ret < 0)
228 return ret;
229 if ((ret & T5403_I2C_MASK) != T5403_I2C_ADDR)
230 return -ENODEV;
231
232 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
233 if (!indio_dev)
234 return -ENOMEM;
235
236 data = iio_priv(indio_dev);
237 data->client = client;
238 mutex_init(&data->lock);
239
240 i2c_set_clientdata(client, indio_dev);
241 indio_dev->info = &t5403_info;
242 indio_dev->name = id->name;
243 indio_dev->dev.parent = &client->dev;
244 indio_dev->modes = INDIO_DIRECT_MODE;
245 indio_dev->channels = t5403_channels;
246 indio_dev->num_channels = ARRAY_SIZE(t5403_channels);
247
248 data->mode = T5403_MODE_STANDARD;
249
250 ret = i2c_smbus_read_i2c_block_data(data->client, T5403_CALIB_DATA,
251 sizeof(data->c), (u8 *) data->c);
252 if (ret < 0)
253 return ret;
254
255 return devm_iio_device_register(&client->dev, indio_dev);
256}
257
258static const struct i2c_device_id t5403_id[] = {
259 { "t5403", 0 },
260 { }
261};
262MODULE_DEVICE_TABLE(i2c, t5403_id);
263
264static struct i2c_driver t5403_driver = {
265 .driver = {
266 .name = "t5403",
267 },
268 .probe = t5403_probe,
269 .id_table = t5403_id,
270};
271module_i2c_driver(t5403_driver);
272
273MODULE_AUTHOR("Peter Meerwald <pmeerw@pmeerw.net>");
274MODULE_DESCRIPTION("EPCOS T5403 pressure/temperature sensor driver");
275MODULE_LICENSE("GPL");
diff --git a/drivers/iio/proximity/as3935.c b/drivers/iio/proximity/as3935.c
index bf677bfe8eb2..5e780ef206f3 100644
--- a/drivers/iio/proximity/as3935.c
+++ b/drivers/iio/proximity/as3935.c
@@ -232,7 +232,7 @@ static void as3935_event_work(struct work_struct *work)
232 232
233 switch (val) { 233 switch (val) {
234 case AS3935_EVENT_INT: 234 case AS3935_EVENT_INT:
235 iio_trigger_poll(st->trig, iio_get_time_ns()); 235 iio_trigger_poll(st->trig);
236 break; 236 break;
237 case AS3935_NOISE_INT: 237 case AS3935_NOISE_INT:
238 dev_warn(&st->spi->dev, "noise level is too high"); 238 dev_warn(&st->spi->dev, "noise level is too high");
diff --git a/drivers/iio/trigger/iio-trig-interrupt.c b/drivers/iio/trigger/iio-trig-interrupt.c
index 02577ec54c6b..7a149a7822bc 100644
--- a/drivers/iio/trigger/iio-trig-interrupt.c
+++ b/drivers/iio/trigger/iio-trig-interrupt.c
@@ -24,8 +24,7 @@ struct iio_interrupt_trigger_info {
24 24
25static irqreturn_t iio_interrupt_trigger_poll(int irq, void *private) 25static irqreturn_t iio_interrupt_trigger_poll(int irq, void *private)
26{ 26{
27 /* Timestamp not currently provided */ 27 iio_trigger_poll(private);
28 iio_trigger_poll(private, 0);
29 return IRQ_HANDLED; 28 return IRQ_HANDLED;
30} 29}
31 30
diff --git a/drivers/iio/trigger/iio-trig-sysfs.c b/drivers/iio/trigger/iio-trig-sysfs.c
index 15e3b850f513..254c7e906127 100644
--- a/drivers/iio/trigger/iio-trig-sysfs.c
+++ b/drivers/iio/trigger/iio-trig-sysfs.c
@@ -96,7 +96,7 @@ static void iio_sysfs_trigger_work(struct irq_work *work)
96 struct iio_sysfs_trig *trig = container_of(work, struct iio_sysfs_trig, 96 struct iio_sysfs_trig *trig = container_of(work, struct iio_sysfs_trig,
97 work); 97 work);
98 98
99 iio_trigger_poll(trig->trig, 0); 99 iio_trigger_poll(trig->trig);
100} 100}
101 101
102static ssize_t iio_sysfs_trigger_poll(struct device *dev, 102static ssize_t iio_sysfs_trigger_poll(struct device *dev,