blob: 85b81967dcaad64ec1a71d6acf817dd5a6acbd3b [file] [log] [blame]
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +01001/*
Laurentiu Palcu8ecbb3c2014-02-09 10:30:00 +00002 * 3-axis accelerometer driver supporting following Bosch-Sensortec chips:
3 * - BMC150
4 * - BMI055
5 * - BMA255
6 * - BMA250E
7 * - BMA222E
8 * - BMA280
9 *
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +010010 * Copyright (c) 2014, Intel Corporation.
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms and conditions of the GNU General Public License,
14 * version 2, as published by the Free Software Foundation.
15 *
16 * This program is distributed in the hope it will be useful, but WITHOUT
17 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
19 * more details.
20 */
21
22#include <linux/module.h>
23#include <linux/i2c.h>
24#include <linux/interrupt.h>
25#include <linux/delay.h>
26#include <linux/slab.h>
27#include <linux/acpi.h>
28#include <linux/gpio/consumer.h>
29#include <linux/pm.h>
30#include <linux/pm_runtime.h>
31#include <linux/iio/iio.h>
32#include <linux/iio/sysfs.h>
33#include <linux/iio/buffer.h>
34#include <linux/iio/events.h>
35#include <linux/iio/trigger.h>
36#include <linux/iio/trigger_consumer.h>
37#include <linux/iio/triggered_buffer.h>
Markus Pargmann4011eda2015-09-21 12:55:13 +020038#include <linux/regmap.h>
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +010039
40#define BMC150_ACCEL_DRV_NAME "bmc150_accel"
41#define BMC150_ACCEL_IRQ_NAME "bmc150_accel_event"
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +010042
43#define BMC150_ACCEL_REG_CHIP_ID 0x00
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +010044
45#define BMC150_ACCEL_REG_INT_STATUS_2 0x0B
46#define BMC150_ACCEL_ANY_MOTION_MASK 0x07
Srinivas Pandruvada8d5a9782014-10-10 20:35:32 -070047#define BMC150_ACCEL_ANY_MOTION_BIT_X BIT(0)
48#define BMC150_ACCEL_ANY_MOTION_BIT_Y BIT(1)
49#define BMC150_ACCEL_ANY_MOTION_BIT_Z BIT(2)
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +010050#define BMC150_ACCEL_ANY_MOTION_BIT_SIGN BIT(3)
51
52#define BMC150_ACCEL_REG_PMU_LPW 0x11
53#define BMC150_ACCEL_PMU_MODE_MASK 0xE0
54#define BMC150_ACCEL_PMU_MODE_SHIFT 5
55#define BMC150_ACCEL_PMU_BIT_SLEEP_DUR_MASK 0x17
56#define BMC150_ACCEL_PMU_BIT_SLEEP_DUR_SHIFT 1
57
58#define BMC150_ACCEL_REG_PMU_RANGE 0x0F
59
60#define BMC150_ACCEL_DEF_RANGE_2G 0x03
61#define BMC150_ACCEL_DEF_RANGE_4G 0x05
62#define BMC150_ACCEL_DEF_RANGE_8G 0x08
63#define BMC150_ACCEL_DEF_RANGE_16G 0x0C
64
65/* Default BW: 125Hz */
66#define BMC150_ACCEL_REG_PMU_BW 0x10
67#define BMC150_ACCEL_DEF_BW 125
68
69#define BMC150_ACCEL_REG_INT_MAP_0 0x19
70#define BMC150_ACCEL_INT_MAP_0_BIT_SLOPE BIT(2)
71
72#define BMC150_ACCEL_REG_INT_MAP_1 0x1A
Octavian Purdila3bbec972015-03-22 20:33:40 +020073#define BMC150_ACCEL_INT_MAP_1_BIT_DATA BIT(0)
74#define BMC150_ACCEL_INT_MAP_1_BIT_FWM BIT(1)
75#define BMC150_ACCEL_INT_MAP_1_BIT_FFULL BIT(2)
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +010076
77#define BMC150_ACCEL_REG_INT_RST_LATCH 0x21
78#define BMC150_ACCEL_INT_MODE_LATCH_RESET 0x80
79#define BMC150_ACCEL_INT_MODE_LATCH_INT 0x0F
80#define BMC150_ACCEL_INT_MODE_NON_LATCH_INT 0x00
81
82#define BMC150_ACCEL_REG_INT_EN_0 0x16
83#define BMC150_ACCEL_INT_EN_BIT_SLP_X BIT(0)
84#define BMC150_ACCEL_INT_EN_BIT_SLP_Y BIT(1)
85#define BMC150_ACCEL_INT_EN_BIT_SLP_Z BIT(2)
86
87#define BMC150_ACCEL_REG_INT_EN_1 0x17
Octavian Purdila3bbec972015-03-22 20:33:40 +020088#define BMC150_ACCEL_INT_EN_BIT_DATA_EN BIT(4)
89#define BMC150_ACCEL_INT_EN_BIT_FFULL_EN BIT(5)
90#define BMC150_ACCEL_INT_EN_BIT_FWM_EN BIT(6)
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +010091
92#define BMC150_ACCEL_REG_INT_OUT_CTRL 0x20
93#define BMC150_ACCEL_INT_OUT_CTRL_INT1_LVL BIT(0)
94
95#define BMC150_ACCEL_REG_INT_5 0x27
96#define BMC150_ACCEL_SLOPE_DUR_MASK 0x03
97
98#define BMC150_ACCEL_REG_INT_6 0x28
99#define BMC150_ACCEL_SLOPE_THRES_MASK 0xFF
100
101/* Slope duration in terms of number of samples */
Srinivas Pandruvada9e8e2282014-10-10 20:35:33 -0700102#define BMC150_ACCEL_DEF_SLOPE_DURATION 1
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +0100103/* in terms of multiples of g's/LSB, based on range */
Srinivas Pandruvada9e8e2282014-10-10 20:35:33 -0700104#define BMC150_ACCEL_DEF_SLOPE_THRESHOLD 1
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +0100105
106#define BMC150_ACCEL_REG_XOUT_L 0x02
107
108#define BMC150_ACCEL_MAX_STARTUP_TIME_MS 100
109
110/* Sleep Duration values */
111#define BMC150_ACCEL_SLEEP_500_MICRO 0x05
112#define BMC150_ACCEL_SLEEP_1_MS 0x06
113#define BMC150_ACCEL_SLEEP_2_MS 0x07
114#define BMC150_ACCEL_SLEEP_4_MS 0x08
115#define BMC150_ACCEL_SLEEP_6_MS 0x09
116#define BMC150_ACCEL_SLEEP_10_MS 0x0A
117#define BMC150_ACCEL_SLEEP_25_MS 0x0B
118#define BMC150_ACCEL_SLEEP_50_MS 0x0C
119#define BMC150_ACCEL_SLEEP_100_MS 0x0D
120#define BMC150_ACCEL_SLEEP_500_MS 0x0E
121#define BMC150_ACCEL_SLEEP_1_SEC 0x0F
122
123#define BMC150_ACCEL_REG_TEMP 0x08
124#define BMC150_ACCEL_TEMP_CENTER_VAL 24
125
126#define BMC150_ACCEL_AXIS_TO_REG(axis) (BMC150_ACCEL_REG_XOUT_L + (axis * 2))
127#define BMC150_AUTO_SUSPEND_DELAY_MS 2000
128
Octavian Purdila3bbec972015-03-22 20:33:40 +0200129#define BMC150_ACCEL_REG_FIFO_STATUS 0x0E
130#define BMC150_ACCEL_REG_FIFO_CONFIG0 0x30
131#define BMC150_ACCEL_REG_FIFO_CONFIG1 0x3E
132#define BMC150_ACCEL_REG_FIFO_DATA 0x3F
133#define BMC150_ACCEL_FIFO_LENGTH 32
134
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +0100135enum bmc150_accel_axis {
136 AXIS_X,
137 AXIS_Y,
138 AXIS_Z,
139};
140
141enum bmc150_power_modes {
142 BMC150_ACCEL_SLEEP_MODE_NORMAL,
143 BMC150_ACCEL_SLEEP_MODE_DEEP_SUSPEND,
144 BMC150_ACCEL_SLEEP_MODE_LPM,
145 BMC150_ACCEL_SLEEP_MODE_SUSPEND = 0x04,
146};
147
Laurentiu Palcu8ecbb3c2014-02-09 10:30:00 +0000148struct bmc150_scale_info {
149 int scale;
150 u8 reg_range;
151};
152
153struct bmc150_accel_chip_info {
Bastien Nocera0ad4bf32015-07-23 17:21:07 +0200154 const char *name;
Laurentiu Palcu8ecbb3c2014-02-09 10:30:00 +0000155 u8 chip_id;
156 const struct iio_chan_spec *channels;
157 int num_channels;
158 const struct bmc150_scale_info scale_table[4];
159};
160
Octavian Purdila3e825ec2015-03-03 18:17:57 +0200161struct bmc150_accel_interrupt {
162 const struct bmc150_accel_interrupt_info *info;
163 atomic_t users;
164};
165
Octavian Purdila7d963212015-03-03 18:17:58 +0200166struct bmc150_accel_trigger {
167 struct bmc150_accel_data *data;
168 struct iio_trigger *indio_trig;
169 int (*setup)(struct bmc150_accel_trigger *t, bool state);
170 int intr;
171 bool enabled;
172};
173
Octavian Purdila3e825ec2015-03-03 18:17:57 +0200174enum bmc150_accel_interrupt_id {
175 BMC150_ACCEL_INT_DATA_READY,
176 BMC150_ACCEL_INT_ANY_MOTION,
177 BMC150_ACCEL_INT_WATERMARK,
178 BMC150_ACCEL_INTERRUPTS,
179};
180
Octavian Purdila7d963212015-03-03 18:17:58 +0200181enum bmc150_accel_trigger_id {
182 BMC150_ACCEL_TRIGGER_DATA_READY,
183 BMC150_ACCEL_TRIGGER_ANY_MOTION,
184 BMC150_ACCEL_TRIGGERS,
185};
186
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +0100187struct bmc150_accel_data {
Markus Pargmann4011eda2015-09-21 12:55:13 +0200188 struct regmap *regmap;
189 struct device *dev;
Markus Pargmann19c95d62015-09-21 12:55:14 +0200190 int irq;
Octavian Purdila3e825ec2015-03-03 18:17:57 +0200191 struct bmc150_accel_interrupt interrupts[BMC150_ACCEL_INTERRUPTS];
Octavian Purdila3e825ec2015-03-03 18:17:57 +0200192 atomic_t active_intr;
Octavian Purdila7d963212015-03-03 18:17:58 +0200193 struct bmc150_accel_trigger triggers[BMC150_ACCEL_TRIGGERS];
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +0100194 struct mutex mutex;
Octavian Purdila3bbec972015-03-22 20:33:40 +0200195 u8 fifo_mode, watermark;
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +0100196 s16 buffer[8];
197 u8 bw_bits;
198 u32 slope_dur;
199 u32 slope_thres;
200 u32 range;
201 int ev_enable_state;
Vlad Dogaruc16bff42015-05-12 17:03:24 +0300202 int64_t timestamp, old_timestamp; /* Only used in hw fifo mode. */
Laurentiu Palcu8ecbb3c2014-02-09 10:30:00 +0000203 const struct bmc150_accel_chip_info *chip_info;
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +0100204};
205
206static const struct {
207 int val;
208 int val2;
209 u8 bw_bits;
Sathyanarayanan Kuppuswamy0ba8da92015-03-03 18:17:56 +0200210} bmc150_accel_samp_freq_table[] = { {15, 620000, 0x08},
211 {31, 260000, 0x09},
212 {62, 500000, 0x0A},
213 {125, 0, 0x0B},
214 {250, 0, 0x0C},
215 {500, 0, 0x0D},
216 {1000, 0, 0x0E},
217 {2000, 0, 0x0F} };
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +0100218
219static const struct {
220 int bw_bits;
221 int msec;
222} bmc150_accel_sample_upd_time[] = { {0x08, 64},
223 {0x09, 32},
224 {0x0A, 16},
225 {0x0B, 8},
226 {0x0C, 4},
227 {0x0D, 2},
228 {0x0E, 1},
229 {0x0F, 1} };
230
231static const struct {
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +0100232 int sleep_dur;
Laurentiu Palcu8ecbb3c2014-02-09 10:30:00 +0000233 u8 reg_value;
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +0100234} bmc150_accel_sleep_value_table[] = { {0, 0},
235 {500, BMC150_ACCEL_SLEEP_500_MICRO},
236 {1000, BMC150_ACCEL_SLEEP_1_MS},
237 {2000, BMC150_ACCEL_SLEEP_2_MS},
238 {4000, BMC150_ACCEL_SLEEP_4_MS},
239 {6000, BMC150_ACCEL_SLEEP_6_MS},
240 {10000, BMC150_ACCEL_SLEEP_10_MS},
241 {25000, BMC150_ACCEL_SLEEP_25_MS},
242 {50000, BMC150_ACCEL_SLEEP_50_MS},
243 {100000, BMC150_ACCEL_SLEEP_100_MS},
244 {500000, BMC150_ACCEL_SLEEP_500_MS},
245 {1000000, BMC150_ACCEL_SLEEP_1_SEC} };
246
Markus Pargmann4011eda2015-09-21 12:55:13 +0200247static const struct regmap_config bmc150_i2c_regmap_conf = {
248 .reg_bits = 8,
249 .val_bits = 8,
250 .max_register = 0x3f,
251};
252
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +0100253static int bmc150_accel_set_mode(struct bmc150_accel_data *data,
254 enum bmc150_power_modes mode,
255 int dur_us)
256{
257 int i;
258 int ret;
259 u8 lpw_bits;
260 int dur_val = -1;
261
262 if (dur_us > 0) {
263 for (i = 0; i < ARRAY_SIZE(bmc150_accel_sleep_value_table);
264 ++i) {
265 if (bmc150_accel_sleep_value_table[i].sleep_dur ==
266 dur_us)
267 dur_val =
268 bmc150_accel_sleep_value_table[i].reg_value;
269 }
Hartmut Knaacke20008e2015-06-15 23:48:26 +0200270 } else {
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +0100271 dur_val = 0;
Hartmut Knaacke20008e2015-06-15 23:48:26 +0200272 }
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +0100273
274 if (dur_val < 0)
275 return -EINVAL;
276
277 lpw_bits = mode << BMC150_ACCEL_PMU_MODE_SHIFT;
278 lpw_bits |= (dur_val << BMC150_ACCEL_PMU_BIT_SLEEP_DUR_SHIFT);
279
Markus Pargmann19c95d62015-09-21 12:55:14 +0200280 dev_dbg(data->dev, "Set Mode bits %x\n", lpw_bits);
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +0100281
Markus Pargmann4011eda2015-09-21 12:55:13 +0200282 ret = regmap_write(data->regmap, BMC150_ACCEL_REG_PMU_LPW, lpw_bits);
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +0100283 if (ret < 0) {
Markus Pargmann19c95d62015-09-21 12:55:14 +0200284 dev_err(data->dev, "Error writing reg_pmu_lpw\n");
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +0100285 return ret;
286 }
287
288 return 0;
289}
290
291static int bmc150_accel_set_bw(struct bmc150_accel_data *data, int val,
292 int val2)
293{
294 int i;
295 int ret;
296
297 for (i = 0; i < ARRAY_SIZE(bmc150_accel_samp_freq_table); ++i) {
298 if (bmc150_accel_samp_freq_table[i].val == val &&
Hartmut Knaacke20008e2015-06-15 23:48:26 +0200299 bmc150_accel_samp_freq_table[i].val2 == val2) {
Markus Pargmann4011eda2015-09-21 12:55:13 +0200300 ret = regmap_write(data->regmap,
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +0100301 BMC150_ACCEL_REG_PMU_BW,
302 bmc150_accel_samp_freq_table[i].bw_bits);
303 if (ret < 0)
304 return ret;
305
306 data->bw_bits =
307 bmc150_accel_samp_freq_table[i].bw_bits;
308 return 0;
309 }
310 }
311
312 return -EINVAL;
313}
314
Octavian Purdila802a3ae2015-01-31 02:00:03 +0200315static int bmc150_accel_update_slope(struct bmc150_accel_data *data)
316{
Markus Pargmann4011eda2015-09-21 12:55:13 +0200317 int ret;
Octavian Purdila802a3ae2015-01-31 02:00:03 +0200318
Markus Pargmann4011eda2015-09-21 12:55:13 +0200319 ret = regmap_write(data->regmap, BMC150_ACCEL_REG_INT_6,
Octavian Purdila802a3ae2015-01-31 02:00:03 +0200320 data->slope_thres);
321 if (ret < 0) {
Markus Pargmann19c95d62015-09-21 12:55:14 +0200322 dev_err(data->dev, "Error writing reg_int_6\n");
Octavian Purdila802a3ae2015-01-31 02:00:03 +0200323 return ret;
324 }
325
Markus Pargmann4011eda2015-09-21 12:55:13 +0200326 ret = regmap_update_bits(data->regmap, BMC150_ACCEL_REG_INT_5,
327 BMC150_ACCEL_SLOPE_DUR_MASK, data->slope_dur);
Octavian Purdila802a3ae2015-01-31 02:00:03 +0200328 if (ret < 0) {
Markus Pargmann19c95d62015-09-21 12:55:14 +0200329 dev_err(data->dev, "Error updating reg_int_5\n");
Octavian Purdila802a3ae2015-01-31 02:00:03 +0200330 return ret;
331 }
332
Markus Pargmann19c95d62015-09-21 12:55:14 +0200333 dev_dbg(data->dev, "%s: %x %x\n", __func__, data->slope_thres,
Octavian Purdila802a3ae2015-01-31 02:00:03 +0200334 data->slope_dur);
335
336 return ret;
337}
338
Octavian Purdila7d963212015-03-03 18:17:58 +0200339static int bmc150_accel_any_motion_setup(struct bmc150_accel_trigger *t,
340 bool state)
341{
342 if (state)
343 return bmc150_accel_update_slope(t->data);
344
345 return 0;
346}
347
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +0100348static int bmc150_accel_get_bw(struct bmc150_accel_data *data, int *val,
349 int *val2)
350{
351 int i;
352
353 for (i = 0; i < ARRAY_SIZE(bmc150_accel_samp_freq_table); ++i) {
354 if (bmc150_accel_samp_freq_table[i].bw_bits == data->bw_bits) {
355 *val = bmc150_accel_samp_freq_table[i].val;
356 *val2 = bmc150_accel_samp_freq_table[i].val2;
357 return IIO_VAL_INT_PLUS_MICRO;
358 }
359 }
360
361 return -EINVAL;
362}
363
Rafael J. Wysocki6f0a13f2014-12-04 01:08:13 +0100364#ifdef CONFIG_PM
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +0100365static int bmc150_accel_get_startup_times(struct bmc150_accel_data *data)
366{
367 int i;
368
369 for (i = 0; i < ARRAY_SIZE(bmc150_accel_sample_upd_time); ++i) {
370 if (bmc150_accel_sample_upd_time[i].bw_bits == data->bw_bits)
371 return bmc150_accel_sample_upd_time[i].msec;
372 }
373
374 return BMC150_ACCEL_MAX_STARTUP_TIME_MS;
375}
376
377static int bmc150_accel_set_power_state(struct bmc150_accel_data *data, bool on)
378{
379 int ret;
380
Hartmut Knaacke20008e2015-06-15 23:48:26 +0200381 if (on) {
Markus Pargmann19c95d62015-09-21 12:55:14 +0200382 ret = pm_runtime_get_sync(data->dev);
Hartmut Knaacke20008e2015-06-15 23:48:26 +0200383 } else {
Markus Pargmann19c95d62015-09-21 12:55:14 +0200384 pm_runtime_mark_last_busy(data->dev);
385 ret = pm_runtime_put_autosuspend(data->dev);
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +0100386 }
Hartmut Knaacke20008e2015-06-15 23:48:26 +0200387
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +0100388 if (ret < 0) {
Markus Pargmann19c95d62015-09-21 12:55:14 +0200389 dev_err(data->dev,
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +0100390 "Failed: bmc150_accel_set_power_state for %d\n", on);
Srinivas Pandruvadaaaeecd82014-10-10 20:35:31 -0700391 if (on)
Markus Pargmann19c95d62015-09-21 12:55:14 +0200392 pm_runtime_put_noidle(data->dev);
Srinivas Pandruvadaaaeecd82014-10-10 20:35:31 -0700393
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +0100394 return ret;
395 }
396
397 return 0;
398}
Laurentiu Palcub31b05c2014-08-29 09:38:00 +0100399#else
400static int bmc150_accel_set_power_state(struct bmc150_accel_data *data, bool on)
401{
402 return 0;
403}
404#endif
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +0100405
Octavian Purdila8e22f472015-01-31 02:00:04 +0200406static const struct bmc150_accel_interrupt_info {
407 u8 map_reg;
408 u8 map_bitmask;
409 u8 en_reg;
410 u8 en_bitmask;
Octavian Purdila3e825ec2015-03-03 18:17:57 +0200411} bmc150_accel_interrupts[BMC150_ACCEL_INTERRUPTS] = {
Octavian Purdila8e22f472015-01-31 02:00:04 +0200412 { /* data ready interrupt */
413 .map_reg = BMC150_ACCEL_REG_INT_MAP_1,
414 .map_bitmask = BMC150_ACCEL_INT_MAP_1_BIT_DATA,
415 .en_reg = BMC150_ACCEL_REG_INT_EN_1,
416 .en_bitmask = BMC150_ACCEL_INT_EN_BIT_DATA_EN,
417 },
418 { /* motion interrupt */
419 .map_reg = BMC150_ACCEL_REG_INT_MAP_0,
420 .map_bitmask = BMC150_ACCEL_INT_MAP_0_BIT_SLOPE,
421 .en_reg = BMC150_ACCEL_REG_INT_EN_0,
422 .en_bitmask = BMC150_ACCEL_INT_EN_BIT_SLP_X |
423 BMC150_ACCEL_INT_EN_BIT_SLP_Y |
424 BMC150_ACCEL_INT_EN_BIT_SLP_Z
425 },
Octavian Purdila3bbec972015-03-22 20:33:40 +0200426 { /* fifo watermark interrupt */
427 .map_reg = BMC150_ACCEL_REG_INT_MAP_1,
428 .map_bitmask = BMC150_ACCEL_INT_MAP_1_BIT_FWM,
429 .en_reg = BMC150_ACCEL_REG_INT_EN_1,
430 .en_bitmask = BMC150_ACCEL_INT_EN_BIT_FWM_EN,
431 },
Octavian Purdila8e22f472015-01-31 02:00:04 +0200432};
433
Octavian Purdila3e825ec2015-03-03 18:17:57 +0200434static void bmc150_accel_interrupts_setup(struct iio_dev *indio_dev,
435 struct bmc150_accel_data *data)
436{
437 int i;
438
439 for (i = 0; i < BMC150_ACCEL_INTERRUPTS; i++)
440 data->interrupts[i].info = &bmc150_accel_interrupts[i];
441}
442
443static int bmc150_accel_set_interrupt(struct bmc150_accel_data *data, int i,
Octavian Purdila8e22f472015-01-31 02:00:04 +0200444 bool state)
445{
Octavian Purdila3e825ec2015-03-03 18:17:57 +0200446 struct bmc150_accel_interrupt *intr = &data->interrupts[i];
447 const struct bmc150_accel_interrupt_info *info = intr->info;
Octavian Purdila8e22f472015-01-31 02:00:04 +0200448 int ret;
449
Octavian Purdila3e825ec2015-03-03 18:17:57 +0200450 if (state) {
451 if (atomic_inc_return(&intr->users) > 1)
452 return 0;
453 } else {
454 if (atomic_dec_return(&intr->users) > 0)
455 return 0;
456 }
457
Octavian Purdila8e22f472015-01-31 02:00:04 +0200458 /*
Hartmut Knaacke20008e2015-06-15 23:48:26 +0200459 * We will expect the enable and disable to do operation in reverse
460 * order. This will happen here anyway, as our resume operation uses
461 * sync mode runtime pm calls. The suspend operation will be delayed
462 * by autosuspend delay.
463 * So the disable operation will still happen in reverse order of
464 * enable operation. When runtime pm is disabled the mode is always on,
465 * so sequence doesn't matter.
Octavian Purdila8e22f472015-01-31 02:00:04 +0200466 */
467 ret = bmc150_accel_set_power_state(data, state);
468 if (ret < 0)
469 return ret;
470
471 /* map the interrupt to the appropriate pins */
Markus Pargmann4011eda2015-09-21 12:55:13 +0200472 ret = regmap_update_bits(data->regmap, info->map_reg, info->map_bitmask,
473 (state ? info->map_bitmask : 0));
Octavian Purdila8e22f472015-01-31 02:00:04 +0200474 if (ret < 0) {
Markus Pargmann19c95d62015-09-21 12:55:14 +0200475 dev_err(data->dev, "Error updating reg_int_map\n");
Octavian Purdila8e22f472015-01-31 02:00:04 +0200476 goto out_fix_power_state;
477 }
478
479 /* enable/disable the interrupt */
Markus Pargmann4011eda2015-09-21 12:55:13 +0200480 ret = regmap_update_bits(data->regmap, info->en_reg, info->en_bitmask,
481 (state ? info->en_bitmask : 0));
Octavian Purdila8e22f472015-01-31 02:00:04 +0200482 if (ret < 0) {
Markus Pargmann19c95d62015-09-21 12:55:14 +0200483 dev_err(data->dev, "Error updating reg_int_en\n");
Octavian Purdila8e22f472015-01-31 02:00:04 +0200484 goto out_fix_power_state;
485 }
486
Octavian Purdila3e825ec2015-03-03 18:17:57 +0200487 if (state)
488 atomic_inc(&data->active_intr);
489 else
490 atomic_dec(&data->active_intr);
491
Octavian Purdila8e22f472015-01-31 02:00:04 +0200492 return 0;
493
494out_fix_power_state:
495 bmc150_accel_set_power_state(data, false);
496 return ret;
497}
498
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +0100499static int bmc150_accel_set_scale(struct bmc150_accel_data *data, int val)
500{
501 int ret, i;
502
Laurentiu Palcu8ecbb3c2014-02-09 10:30:00 +0000503 for (i = 0; i < ARRAY_SIZE(data->chip_info->scale_table); ++i) {
504 if (data->chip_info->scale_table[i].scale == val) {
Markus Pargmann4011eda2015-09-21 12:55:13 +0200505 ret = regmap_write(data->regmap,
Laurentiu Palcu8ecbb3c2014-02-09 10:30:00 +0000506 BMC150_ACCEL_REG_PMU_RANGE,
507 data->chip_info->scale_table[i].reg_range);
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +0100508 if (ret < 0) {
Markus Pargmann19c95d62015-09-21 12:55:14 +0200509 dev_err(data->dev,
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +0100510 "Error writing pmu_range\n");
511 return ret;
512 }
513
Laurentiu Palcu8ecbb3c2014-02-09 10:30:00 +0000514 data->range = data->chip_info->scale_table[i].reg_range;
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +0100515 return 0;
516 }
517 }
518
519 return -EINVAL;
520}
521
522static int bmc150_accel_get_temp(struct bmc150_accel_data *data, int *val)
523{
524 int ret;
Markus Pargmann4011eda2015-09-21 12:55:13 +0200525 unsigned int value;
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +0100526
527 mutex_lock(&data->mutex);
528
Markus Pargmann4011eda2015-09-21 12:55:13 +0200529 ret = regmap_read(data->regmap, BMC150_ACCEL_REG_TEMP, &value);
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +0100530 if (ret < 0) {
Markus Pargmann19c95d62015-09-21 12:55:14 +0200531 dev_err(data->dev, "Error reading reg_temp\n");
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +0100532 mutex_unlock(&data->mutex);
533 return ret;
534 }
Markus Pargmann4011eda2015-09-21 12:55:13 +0200535 *val = sign_extend32(value, 7);
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +0100536
537 mutex_unlock(&data->mutex);
538
539 return IIO_VAL_INT;
540}
541
Laurentiu Palcu8ecbb3c2014-02-09 10:30:00 +0000542static int bmc150_accel_get_axis(struct bmc150_accel_data *data,
543 struct iio_chan_spec const *chan,
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +0100544 int *val)
545{
546 int ret;
Laurentiu Palcu8ecbb3c2014-02-09 10:30:00 +0000547 int axis = chan->scan_index;
Markus Pargmann4011eda2015-09-21 12:55:13 +0200548 unsigned int raw_val;
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +0100549
550 mutex_lock(&data->mutex);
551 ret = bmc150_accel_set_power_state(data, true);
552 if (ret < 0) {
553 mutex_unlock(&data->mutex);
554 return ret;
555 }
556
Markus Pargmann4011eda2015-09-21 12:55:13 +0200557 ret = regmap_bulk_read(data->regmap, BMC150_ACCEL_AXIS_TO_REG(axis),
558 &raw_val, 2);
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +0100559 if (ret < 0) {
Markus Pargmann19c95d62015-09-21 12:55:14 +0200560 dev_err(data->dev, "Error reading axis %d\n", axis);
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +0100561 bmc150_accel_set_power_state(data, false);
562 mutex_unlock(&data->mutex);
563 return ret;
564 }
Markus Pargmann4011eda2015-09-21 12:55:13 +0200565 *val = sign_extend32(raw_val >> chan->scan_type.shift,
Laurentiu Palcu8ecbb3c2014-02-09 10:30:00 +0000566 chan->scan_type.realbits - 1);
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +0100567 ret = bmc150_accel_set_power_state(data, false);
568 mutex_unlock(&data->mutex);
569 if (ret < 0)
570 return ret;
571
572 return IIO_VAL_INT;
573}
574
575static int bmc150_accel_read_raw(struct iio_dev *indio_dev,
576 struct iio_chan_spec const *chan,
577 int *val, int *val2, long mask)
578{
579 struct bmc150_accel_data *data = iio_priv(indio_dev);
580 int ret;
581
582 switch (mask) {
583 case IIO_CHAN_INFO_RAW:
584 switch (chan->type) {
585 case IIO_TEMP:
586 return bmc150_accel_get_temp(data, val);
587 case IIO_ACCEL:
588 if (iio_buffer_enabled(indio_dev))
589 return -EBUSY;
590 else
Laurentiu Palcu8ecbb3c2014-02-09 10:30:00 +0000591 return bmc150_accel_get_axis(data, chan, val);
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +0100592 default:
593 return -EINVAL;
594 }
595 case IIO_CHAN_INFO_OFFSET:
596 if (chan->type == IIO_TEMP) {
597 *val = BMC150_ACCEL_TEMP_CENTER_VAL;
598 return IIO_VAL_INT;
Hartmut Knaacke20008e2015-06-15 23:48:26 +0200599 } else {
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +0100600 return -EINVAL;
Hartmut Knaacke20008e2015-06-15 23:48:26 +0200601 }
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +0100602 case IIO_CHAN_INFO_SCALE:
603 *val = 0;
604 switch (chan->type) {
605 case IIO_TEMP:
606 *val2 = 500000;
607 return IIO_VAL_INT_PLUS_MICRO;
608 case IIO_ACCEL:
609 {
610 int i;
Laurentiu Palcu8ecbb3c2014-02-09 10:30:00 +0000611 const struct bmc150_scale_info *si;
612 int st_size = ARRAY_SIZE(data->chip_info->scale_table);
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +0100613
Laurentiu Palcu8ecbb3c2014-02-09 10:30:00 +0000614 for (i = 0; i < st_size; ++i) {
615 si = &data->chip_info->scale_table[i];
616 if (si->reg_range == data->range) {
617 *val2 = si->scale;
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +0100618 return IIO_VAL_INT_PLUS_MICRO;
619 }
620 }
621 return -EINVAL;
622 }
623 default:
624 return -EINVAL;
625 }
626 case IIO_CHAN_INFO_SAMP_FREQ:
627 mutex_lock(&data->mutex);
628 ret = bmc150_accel_get_bw(data, val, val2);
629 mutex_unlock(&data->mutex);
630 return ret;
631 default:
632 return -EINVAL;
633 }
634}
635
636static int bmc150_accel_write_raw(struct iio_dev *indio_dev,
637 struct iio_chan_spec const *chan,
638 int val, int val2, long mask)
639{
640 struct bmc150_accel_data *data = iio_priv(indio_dev);
641 int ret;
642
643 switch (mask) {
644 case IIO_CHAN_INFO_SAMP_FREQ:
645 mutex_lock(&data->mutex);
646 ret = bmc150_accel_set_bw(data, val, val2);
647 mutex_unlock(&data->mutex);
648 break;
649 case IIO_CHAN_INFO_SCALE:
650 if (val)
651 return -EINVAL;
652
653 mutex_lock(&data->mutex);
654 ret = bmc150_accel_set_scale(data, val2);
655 mutex_unlock(&data->mutex);
656 return ret;
657 default:
658 ret = -EINVAL;
659 }
660
661 return ret;
662}
663
664static int bmc150_accel_read_event(struct iio_dev *indio_dev,
665 const struct iio_chan_spec *chan,
666 enum iio_event_type type,
667 enum iio_event_direction dir,
668 enum iio_event_info info,
669 int *val, int *val2)
670{
671 struct bmc150_accel_data *data = iio_priv(indio_dev);
672
673 *val2 = 0;
674 switch (info) {
675 case IIO_EV_INFO_VALUE:
676 *val = data->slope_thres;
677 break;
678 case IIO_EV_INFO_PERIOD:
Octavian Purdila802a3ae2015-01-31 02:00:03 +0200679 *val = data->slope_dur;
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +0100680 break;
681 default:
682 return -EINVAL;
683 }
684
685 return IIO_VAL_INT;
686}
687
688static int bmc150_accel_write_event(struct iio_dev *indio_dev,
689 const struct iio_chan_spec *chan,
690 enum iio_event_type type,
691 enum iio_event_direction dir,
692 enum iio_event_info info,
693 int val, int val2)
694{
695 struct bmc150_accel_data *data = iio_priv(indio_dev);
696
697 if (data->ev_enable_state)
698 return -EBUSY;
699
700 switch (info) {
701 case IIO_EV_INFO_VALUE:
Hartmut Knaackfdd15f62015-06-15 23:48:25 +0200702 data->slope_thres = val & BMC150_ACCEL_SLOPE_THRES_MASK;
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +0100703 break;
704 case IIO_EV_INFO_PERIOD:
Octavian Purdila802a3ae2015-01-31 02:00:03 +0200705 data->slope_dur = val & BMC150_ACCEL_SLOPE_DUR_MASK;
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +0100706 break;
707 default:
708 return -EINVAL;
709 }
710
711 return 0;
712}
713
714static int bmc150_accel_read_event_config(struct iio_dev *indio_dev,
715 const struct iio_chan_spec *chan,
716 enum iio_event_type type,
717 enum iio_event_direction dir)
718{
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +0100719 struct bmc150_accel_data *data = iio_priv(indio_dev);
720
721 return data->ev_enable_state;
722}
723
724static int bmc150_accel_write_event_config(struct iio_dev *indio_dev,
725 const struct iio_chan_spec *chan,
726 enum iio_event_type type,
727 enum iio_event_direction dir,
728 int state)
729{
730 struct bmc150_accel_data *data = iio_priv(indio_dev);
731 int ret;
732
Octavian Purdila14ee64f2015-01-31 02:00:05 +0200733 if (state == data->ev_enable_state)
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +0100734 return 0;
735
736 mutex_lock(&data->mutex);
737
Octavian Purdila3e825ec2015-03-03 18:17:57 +0200738 ret = bmc150_accel_set_interrupt(data, BMC150_ACCEL_INT_ANY_MOTION,
739 state);
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +0100740 if (ret < 0) {
741 mutex_unlock(&data->mutex);
742 return ret;
743 }
744
745 data->ev_enable_state = state;
746 mutex_unlock(&data->mutex);
747
748 return 0;
749}
750
751static int bmc150_accel_validate_trigger(struct iio_dev *indio_dev,
Hartmut Knaacke20008e2015-06-15 23:48:26 +0200752 struct iio_trigger *trig)
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +0100753{
754 struct bmc150_accel_data *data = iio_priv(indio_dev);
Octavian Purdila7d963212015-03-03 18:17:58 +0200755 int i;
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +0100756
Octavian Purdila7d963212015-03-03 18:17:58 +0200757 for (i = 0; i < BMC150_ACCEL_TRIGGERS; i++) {
758 if (data->triggers[i].indio_trig == trig)
759 return 0;
760 }
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +0100761
Octavian Purdila7d963212015-03-03 18:17:58 +0200762 return -EINVAL;
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +0100763}
764
Octavian Purdila3bbec972015-03-22 20:33:40 +0200765static ssize_t bmc150_accel_get_fifo_watermark(struct device *dev,
766 struct device_attribute *attr,
767 char *buf)
768{
769 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
770 struct bmc150_accel_data *data = iio_priv(indio_dev);
771 int wm;
772
773 mutex_lock(&data->mutex);
774 wm = data->watermark;
775 mutex_unlock(&data->mutex);
776
777 return sprintf(buf, "%d\n", wm);
778}
779
780static ssize_t bmc150_accel_get_fifo_state(struct device *dev,
781 struct device_attribute *attr,
782 char *buf)
783{
784 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
785 struct bmc150_accel_data *data = iio_priv(indio_dev);
786 bool state;
787
788 mutex_lock(&data->mutex);
789 state = data->fifo_mode;
790 mutex_unlock(&data->mutex);
791
792 return sprintf(buf, "%d\n", state);
793}
794
795static IIO_CONST_ATTR(hwfifo_watermark_min, "1");
796static IIO_CONST_ATTR(hwfifo_watermark_max,
797 __stringify(BMC150_ACCEL_FIFO_LENGTH));
798static IIO_DEVICE_ATTR(hwfifo_enabled, S_IRUGO,
799 bmc150_accel_get_fifo_state, NULL, 0);
800static IIO_DEVICE_ATTR(hwfifo_watermark, S_IRUGO,
801 bmc150_accel_get_fifo_watermark, NULL, 0);
802
803static const struct attribute *bmc150_accel_fifo_attributes[] = {
804 &iio_const_attr_hwfifo_watermark_min.dev_attr.attr,
805 &iio_const_attr_hwfifo_watermark_max.dev_attr.attr,
806 &iio_dev_attr_hwfifo_watermark.dev_attr.attr,
807 &iio_dev_attr_hwfifo_enabled.dev_attr.attr,
808 NULL,
809};
810
811static int bmc150_accel_set_watermark(struct iio_dev *indio_dev, unsigned val)
812{
813 struct bmc150_accel_data *data = iio_priv(indio_dev);
814
815 if (val > BMC150_ACCEL_FIFO_LENGTH)
816 val = BMC150_ACCEL_FIFO_LENGTH;
817
818 mutex_lock(&data->mutex);
819 data->watermark = val;
820 mutex_unlock(&data->mutex);
821
822 return 0;
823}
824
825/*
826 * We must read at least one full frame in one burst, otherwise the rest of the
827 * frame data is discarded.
828 */
Markus Pargmann4011eda2015-09-21 12:55:13 +0200829static int bmc150_accel_fifo_transfer(struct bmc150_accel_data *data,
Octavian Purdila3bbec972015-03-22 20:33:40 +0200830 char *buffer, int samples)
831{
832 int sample_length = 3 * 2;
Markus Pargmann4011eda2015-09-21 12:55:13 +0200833 int ret;
834 int total_length = samples * sample_length;
835 int i;
836 size_t step = regmap_get_raw_read_max(data->regmap);
Octavian Purdila3bbec972015-03-22 20:33:40 +0200837
Markus Pargmann4011eda2015-09-21 12:55:13 +0200838 if (!step || step > total_length)
839 step = total_length;
840 else if (step < total_length)
841 step = sample_length;
Octavian Purdila3bbec972015-03-22 20:33:40 +0200842
Markus Pargmann4011eda2015-09-21 12:55:13 +0200843 /*
844 * Seems we have a bus with size limitation so we have to execute
845 * multiple reads
846 */
847 for (i = 0; i < total_length; i += step) {
848 ret = regmap_raw_read(data->regmap, BMC150_ACCEL_REG_FIFO_DATA,
849 &buffer[i], step);
850 if (ret)
851 break;
Octavian Purdila3bbec972015-03-22 20:33:40 +0200852 }
853
854 if (ret)
Markus Pargmann4011eda2015-09-21 12:55:13 +0200855 dev_err(data->dev, "Error transferring data from fifo in single steps of %zu\n",
856 step);
Octavian Purdila3bbec972015-03-22 20:33:40 +0200857
858 return ret;
859}
860
861static int __bmc150_accel_fifo_flush(struct iio_dev *indio_dev,
862 unsigned samples, bool irq)
863{
864 struct bmc150_accel_data *data = iio_priv(indio_dev);
865 int ret, i;
866 u8 count;
867 u16 buffer[BMC150_ACCEL_FIFO_LENGTH * 3];
868 int64_t tstamp;
869 uint64_t sample_period;
Markus Pargmann4011eda2015-09-21 12:55:13 +0200870 unsigned int val;
Hartmut Knaacke20008e2015-06-15 23:48:26 +0200871
Markus Pargmann4011eda2015-09-21 12:55:13 +0200872 ret = regmap_read(data->regmap, BMC150_ACCEL_REG_FIFO_STATUS, &val);
Octavian Purdila3bbec972015-03-22 20:33:40 +0200873 if (ret < 0) {
Markus Pargmann19c95d62015-09-21 12:55:14 +0200874 dev_err(data->dev, "Error reading reg_fifo_status\n");
Octavian Purdila3bbec972015-03-22 20:33:40 +0200875 return ret;
876 }
877
Markus Pargmann4011eda2015-09-21 12:55:13 +0200878 count = val & 0x7F;
Octavian Purdila3bbec972015-03-22 20:33:40 +0200879
880 if (!count)
881 return 0;
882
883 /*
884 * If we getting called from IRQ handler we know the stored timestamp is
885 * fairly accurate for the last stored sample. Otherwise, if we are
886 * called as a result of a read operation from userspace and hence
887 * before the watermark interrupt was triggered, take a timestamp
888 * now. We can fall anywhere in between two samples so the error in this
889 * case is at most one sample period.
890 */
891 if (!irq) {
892 data->old_timestamp = data->timestamp;
893 data->timestamp = iio_get_time_ns();
894 }
895
896 /*
897 * Approximate timestamps for each of the sample based on the sampling
898 * frequency, timestamp for last sample and number of samples.
899 *
900 * Note that we can't use the current bandwidth settings to compute the
901 * sample period because the sample rate varies with the device
902 * (e.g. between 31.70ms to 32.20ms for a bandwidth of 15.63HZ). That
903 * small variation adds when we store a large number of samples and
904 * creates significant jitter between the last and first samples in
905 * different batches (e.g. 32ms vs 21ms).
906 *
907 * To avoid this issue we compute the actual sample period ourselves
908 * based on the timestamp delta between the last two flush operations.
909 */
910 sample_period = (data->timestamp - data->old_timestamp);
911 do_div(sample_period, count);
912 tstamp = data->timestamp - (count - 1) * sample_period;
913
914 if (samples && count > samples)
915 count = samples;
916
Markus Pargmann4011eda2015-09-21 12:55:13 +0200917 ret = bmc150_accel_fifo_transfer(data, (u8 *)buffer, count);
Octavian Purdila3bbec972015-03-22 20:33:40 +0200918 if (ret)
919 return ret;
920
921 /*
922 * Ideally we want the IIO core to handle the demux when running in fifo
923 * mode but not when running in triggered buffer mode. Unfortunately
924 * this does not seem to be possible, so stick with driver demux for
925 * now.
926 */
927 for (i = 0; i < count; i++) {
928 u16 sample[8];
929 int j, bit;
930
931 j = 0;
932 for_each_set_bit(bit, indio_dev->active_scan_mask,
933 indio_dev->masklength)
934 memcpy(&sample[j++], &buffer[i * 3 + bit], 2);
935
936 iio_push_to_buffers_with_timestamp(indio_dev, sample, tstamp);
937
938 tstamp += sample_period;
939 }
940
941 return count;
942}
943
944static int bmc150_accel_fifo_flush(struct iio_dev *indio_dev, unsigned samples)
945{
946 struct bmc150_accel_data *data = iio_priv(indio_dev);
947 int ret;
948
949 mutex_lock(&data->mutex);
950 ret = __bmc150_accel_fifo_flush(indio_dev, samples, false);
951 mutex_unlock(&data->mutex);
952
953 return ret;
954}
955
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +0100956static IIO_CONST_ATTR_SAMP_FREQ_AVAIL(
Sathyanarayanan Kuppuswamy0ba8da92015-03-03 18:17:56 +0200957 "15.620000 31.260000 62.50000 125 250 500 1000 2000");
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +0100958
959static struct attribute *bmc150_accel_attributes[] = {
960 &iio_const_attr_sampling_frequency_available.dev_attr.attr,
961 NULL,
962};
963
964static const struct attribute_group bmc150_accel_attrs_group = {
965 .attrs = bmc150_accel_attributes,
966};
967
968static const struct iio_event_spec bmc150_accel_event = {
969 .type = IIO_EV_TYPE_ROC,
Srinivas Pandruvada11741242014-10-10 20:35:34 -0700970 .dir = IIO_EV_DIR_EITHER,
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +0100971 .mask_separate = BIT(IIO_EV_INFO_VALUE) |
972 BIT(IIO_EV_INFO_ENABLE) |
973 BIT(IIO_EV_INFO_PERIOD)
974};
975
Laurentiu Palcu8ecbb3c2014-02-09 10:30:00 +0000976#define BMC150_ACCEL_CHANNEL(_axis, bits) { \
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +0100977 .type = IIO_ACCEL, \
978 .modified = 1, \
979 .channel2 = IIO_MOD_##_axis, \
980 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
981 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \
982 BIT(IIO_CHAN_INFO_SAMP_FREQ), \
983 .scan_index = AXIS_##_axis, \
984 .scan_type = { \
985 .sign = 's', \
Laurentiu Palcu8ecbb3c2014-02-09 10:30:00 +0000986 .realbits = (bits), \
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +0100987 .storagebits = 16, \
Laurentiu Palcu8ecbb3c2014-02-09 10:30:00 +0000988 .shift = 16 - (bits), \
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +0100989 }, \
990 .event_spec = &bmc150_accel_event, \
991 .num_event_specs = 1 \
992}
993
Laurentiu Palcu8ecbb3c2014-02-09 10:30:00 +0000994#define BMC150_ACCEL_CHANNELS(bits) { \
995 { \
996 .type = IIO_TEMP, \
997 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
998 BIT(IIO_CHAN_INFO_SCALE) | \
999 BIT(IIO_CHAN_INFO_OFFSET), \
1000 .scan_index = -1, \
1001 }, \
1002 BMC150_ACCEL_CHANNEL(X, bits), \
1003 BMC150_ACCEL_CHANNEL(Y, bits), \
1004 BMC150_ACCEL_CHANNEL(Z, bits), \
1005 IIO_CHAN_SOFT_TIMESTAMP(3), \
1006}
1007
1008static const struct iio_chan_spec bma222e_accel_channels[] =
1009 BMC150_ACCEL_CHANNELS(8);
1010static const struct iio_chan_spec bma250e_accel_channels[] =
1011 BMC150_ACCEL_CHANNELS(10);
1012static const struct iio_chan_spec bmc150_accel_channels[] =
1013 BMC150_ACCEL_CHANNELS(12);
1014static const struct iio_chan_spec bma280_accel_channels[] =
1015 BMC150_ACCEL_CHANNELS(14);
1016
1017enum {
1018 bmc150,
1019 bmi055,
1020 bma255,
1021 bma250e,
1022 bma222e,
1023 bma280,
1024};
1025
1026static const struct bmc150_accel_chip_info bmc150_accel_chip_info_tbl[] = {
1027 [bmc150] = {
Bastien Nocera0ad4bf32015-07-23 17:21:07 +02001028 .name = "BMC150A",
Laurentiu Palcu8ecbb3c2014-02-09 10:30:00 +00001029 .chip_id = 0xFA,
1030 .channels = bmc150_accel_channels,
1031 .num_channels = ARRAY_SIZE(bmc150_accel_channels),
1032 .scale_table = { {9610, BMC150_ACCEL_DEF_RANGE_2G},
1033 {19122, BMC150_ACCEL_DEF_RANGE_4G},
1034 {38344, BMC150_ACCEL_DEF_RANGE_8G},
1035 {76590, BMC150_ACCEL_DEF_RANGE_16G} },
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +01001036 },
Laurentiu Palcu8ecbb3c2014-02-09 10:30:00 +00001037 [bmi055] = {
Bastien Nocera0ad4bf32015-07-23 17:21:07 +02001038 .name = "BMI055A",
Laurentiu Palcu8ecbb3c2014-02-09 10:30:00 +00001039 .chip_id = 0xFA,
1040 .channels = bmc150_accel_channels,
1041 .num_channels = ARRAY_SIZE(bmc150_accel_channels),
1042 .scale_table = { {9610, BMC150_ACCEL_DEF_RANGE_2G},
1043 {19122, BMC150_ACCEL_DEF_RANGE_4G},
1044 {38344, BMC150_ACCEL_DEF_RANGE_8G},
1045 {76590, BMC150_ACCEL_DEF_RANGE_16G} },
1046 },
1047 [bma255] = {
Bastien Nocera0ad4bf32015-07-23 17:21:07 +02001048 .name = "BMA0255",
Laurentiu Palcu8ecbb3c2014-02-09 10:30:00 +00001049 .chip_id = 0xFA,
1050 .channels = bmc150_accel_channels,
1051 .num_channels = ARRAY_SIZE(bmc150_accel_channels),
1052 .scale_table = { {9610, BMC150_ACCEL_DEF_RANGE_2G},
1053 {19122, BMC150_ACCEL_DEF_RANGE_4G},
1054 {38344, BMC150_ACCEL_DEF_RANGE_8G},
1055 {76590, BMC150_ACCEL_DEF_RANGE_16G} },
1056 },
1057 [bma250e] = {
Bastien Nocera0ad4bf32015-07-23 17:21:07 +02001058 .name = "BMA250E",
Laurentiu Palcu8ecbb3c2014-02-09 10:30:00 +00001059 .chip_id = 0xF9,
1060 .channels = bma250e_accel_channels,
1061 .num_channels = ARRAY_SIZE(bma250e_accel_channels),
1062 .scale_table = { {38344, BMC150_ACCEL_DEF_RANGE_2G},
1063 {76590, BMC150_ACCEL_DEF_RANGE_4G},
1064 {153277, BMC150_ACCEL_DEF_RANGE_8G},
1065 {306457, BMC150_ACCEL_DEF_RANGE_16G} },
1066 },
1067 [bma222e] = {
Bastien Nocera0ad4bf32015-07-23 17:21:07 +02001068 .name = "BMA222E",
Laurentiu Palcu8ecbb3c2014-02-09 10:30:00 +00001069 .chip_id = 0xF8,
1070 .channels = bma222e_accel_channels,
1071 .num_channels = ARRAY_SIZE(bma222e_accel_channels),
1072 .scale_table = { {153277, BMC150_ACCEL_DEF_RANGE_2G},
1073 {306457, BMC150_ACCEL_DEF_RANGE_4G},
1074 {612915, BMC150_ACCEL_DEF_RANGE_8G},
1075 {1225831, BMC150_ACCEL_DEF_RANGE_16G} },
1076 },
1077 [bma280] = {
Bastien Nocera0ad4bf32015-07-23 17:21:07 +02001078 .name = "BMA0280",
Laurentiu Palcu8ecbb3c2014-02-09 10:30:00 +00001079 .chip_id = 0xFB,
1080 .channels = bma280_accel_channels,
1081 .num_channels = ARRAY_SIZE(bma280_accel_channels),
1082 .scale_table = { {2392, BMC150_ACCEL_DEF_RANGE_2G},
1083 {4785, BMC150_ACCEL_DEF_RANGE_4G},
1084 {9581, BMC150_ACCEL_DEF_RANGE_8G},
1085 {19152, BMC150_ACCEL_DEF_RANGE_16G} },
1086 },
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +01001087};
1088
1089static const struct iio_info bmc150_accel_info = {
1090 .attrs = &bmc150_accel_attrs_group,
1091 .read_raw = bmc150_accel_read_raw,
1092 .write_raw = bmc150_accel_write_raw,
1093 .read_event_value = bmc150_accel_read_event,
1094 .write_event_value = bmc150_accel_write_event,
1095 .write_event_config = bmc150_accel_write_event_config,
1096 .read_event_config = bmc150_accel_read_event_config,
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +01001097 .driver_module = THIS_MODULE,
1098};
1099
Octavian Purdila3bbec972015-03-22 20:33:40 +02001100static const struct iio_info bmc150_accel_info_fifo = {
1101 .attrs = &bmc150_accel_attrs_group,
1102 .read_raw = bmc150_accel_read_raw,
1103 .write_raw = bmc150_accel_write_raw,
1104 .read_event_value = bmc150_accel_read_event,
1105 .write_event_value = bmc150_accel_write_event,
1106 .write_event_config = bmc150_accel_write_event_config,
1107 .read_event_config = bmc150_accel_read_event_config,
1108 .validate_trigger = bmc150_accel_validate_trigger,
1109 .hwfifo_set_watermark = bmc150_accel_set_watermark,
1110 .hwfifo_flush_to_buffer = bmc150_accel_fifo_flush,
1111 .driver_module = THIS_MODULE,
1112};
1113
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +01001114static irqreturn_t bmc150_accel_trigger_handler(int irq, void *p)
1115{
1116 struct iio_poll_func *pf = p;
1117 struct iio_dev *indio_dev = pf->indio_dev;
1118 struct bmc150_accel_data *data = iio_priv(indio_dev);
1119 int bit, ret, i = 0;
Markus Pargmann4011eda2015-09-21 12:55:13 +02001120 unsigned int raw_val;
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +01001121
1122 mutex_lock(&data->mutex);
Octavian Purdila70dddee2015-03-02 21:03:05 +02001123 for_each_set_bit(bit, indio_dev->active_scan_mask,
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +01001124 indio_dev->masklength) {
Markus Pargmann4011eda2015-09-21 12:55:13 +02001125 ret = regmap_bulk_read(data->regmap,
1126 BMC150_ACCEL_AXIS_TO_REG(bit), &raw_val,
1127 2);
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +01001128 if (ret < 0) {
1129 mutex_unlock(&data->mutex);
1130 goto err_read;
1131 }
Markus Pargmann4011eda2015-09-21 12:55:13 +02001132 data->buffer[i++] = raw_val;
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +01001133 }
1134 mutex_unlock(&data->mutex);
1135
1136 iio_push_to_buffers_with_timestamp(indio_dev, data->buffer,
Vlad Dogaruc16bff42015-05-12 17:03:24 +03001137 pf->timestamp);
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +01001138err_read:
1139 iio_trigger_notify_done(indio_dev->trig);
1140
1141 return IRQ_HANDLED;
1142}
1143
1144static int bmc150_accel_trig_try_reen(struct iio_trigger *trig)
1145{
Octavian Purdila7d963212015-03-03 18:17:58 +02001146 struct bmc150_accel_trigger *t = iio_trigger_get_drvdata(trig);
1147 struct bmc150_accel_data *data = t->data;
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +01001148 int ret;
1149
1150 /* new data interrupts don't need ack */
Octavian Purdila7d963212015-03-03 18:17:58 +02001151 if (t == &t->data->triggers[BMC150_ACCEL_TRIGGER_DATA_READY])
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +01001152 return 0;
1153
1154 mutex_lock(&data->mutex);
1155 /* clear any latched interrupt */
Markus Pargmann4011eda2015-09-21 12:55:13 +02001156 ret = regmap_write(data->regmap, BMC150_ACCEL_REG_INT_RST_LATCH,
1157 BMC150_ACCEL_INT_MODE_LATCH_INT |
1158 BMC150_ACCEL_INT_MODE_LATCH_RESET);
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +01001159 mutex_unlock(&data->mutex);
1160 if (ret < 0) {
Markus Pargmann19c95d62015-09-21 12:55:14 +02001161 dev_err(data->dev,
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +01001162 "Error writing reg_int_rst_latch\n");
1163 return ret;
1164 }
1165
1166 return 0;
1167}
1168
Octavian Purdila7d963212015-03-03 18:17:58 +02001169static int bmc150_accel_trigger_set_state(struct iio_trigger *trig,
Hartmut Knaacke20008e2015-06-15 23:48:26 +02001170 bool state)
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +01001171{
Octavian Purdila7d963212015-03-03 18:17:58 +02001172 struct bmc150_accel_trigger *t = iio_trigger_get_drvdata(trig);
1173 struct bmc150_accel_data *data = t->data;
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +01001174 int ret;
1175
1176 mutex_lock(&data->mutex);
1177
Octavian Purdila7d963212015-03-03 18:17:58 +02001178 if (t->enabled == state) {
1179 mutex_unlock(&data->mutex);
1180 return 0;
1181 }
1182
1183 if (t->setup) {
1184 ret = t->setup(t, state);
1185 if (ret < 0) {
Octavian Purdila14ee64f2015-01-31 02:00:05 +02001186 mutex_unlock(&data->mutex);
Octavian Purdila7d963212015-03-03 18:17:58 +02001187 return ret;
Octavian Purdila14ee64f2015-01-31 02:00:05 +02001188 }
1189 }
1190
Octavian Purdila7d963212015-03-03 18:17:58 +02001191 ret = bmc150_accel_set_interrupt(data, t->intr, state);
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +01001192 if (ret < 0) {
1193 mutex_unlock(&data->mutex);
1194 return ret;
1195 }
Octavian Purdila7d963212015-03-03 18:17:58 +02001196
1197 t->enabled = state;
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +01001198
1199 mutex_unlock(&data->mutex);
1200
1201 return ret;
1202}
1203
1204static const struct iio_trigger_ops bmc150_accel_trigger_ops = {
Octavian Purdila7d963212015-03-03 18:17:58 +02001205 .set_trigger_state = bmc150_accel_trigger_set_state,
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +01001206 .try_reenable = bmc150_accel_trig_try_reen,
1207 .owner = THIS_MODULE,
1208};
1209
Octavian Purdila3bbec972015-03-22 20:33:40 +02001210static int bmc150_accel_handle_roc_event(struct iio_dev *indio_dev)
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +01001211{
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +01001212 struct bmc150_accel_data *data = iio_priv(indio_dev);
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +01001213 int dir;
Octavian Purdila3bbec972015-03-22 20:33:40 +02001214 int ret;
Markus Pargmann4011eda2015-09-21 12:55:13 +02001215 unsigned int val;
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +01001216
Markus Pargmann4011eda2015-09-21 12:55:13 +02001217 ret = regmap_read(data->regmap, BMC150_ACCEL_REG_INT_STATUS_2, &val);
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +01001218 if (ret < 0) {
Markus Pargmann19c95d62015-09-21 12:55:14 +02001219 dev_err(data->dev, "Error reading reg_int_status_2\n");
Octavian Purdila3bbec972015-03-22 20:33:40 +02001220 return ret;
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +01001221 }
1222
Markus Pargmann4011eda2015-09-21 12:55:13 +02001223 if (val & BMC150_ACCEL_ANY_MOTION_BIT_SIGN)
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +01001224 dir = IIO_EV_DIR_FALLING;
1225 else
1226 dir = IIO_EV_DIR_RISING;
1227
Markus Pargmann4011eda2015-09-21 12:55:13 +02001228 if (val & BMC150_ACCEL_ANY_MOTION_BIT_X)
Hartmut Knaacke20008e2015-06-15 23:48:26 +02001229 iio_push_event(indio_dev,
1230 IIO_MOD_EVENT_CODE(IIO_ACCEL,
1231 0,
1232 IIO_MOD_X,
1233 IIO_EV_TYPE_ROC,
1234 dir),
1235 data->timestamp);
1236
Markus Pargmann4011eda2015-09-21 12:55:13 +02001237 if (val & BMC150_ACCEL_ANY_MOTION_BIT_Y)
Hartmut Knaacke20008e2015-06-15 23:48:26 +02001238 iio_push_event(indio_dev,
1239 IIO_MOD_EVENT_CODE(IIO_ACCEL,
1240 0,
1241 IIO_MOD_Y,
1242 IIO_EV_TYPE_ROC,
1243 dir),
1244 data->timestamp);
1245
Markus Pargmann4011eda2015-09-21 12:55:13 +02001246 if (val & BMC150_ACCEL_ANY_MOTION_BIT_Z)
Hartmut Knaacke20008e2015-06-15 23:48:26 +02001247 iio_push_event(indio_dev,
1248 IIO_MOD_EVENT_CODE(IIO_ACCEL,
1249 0,
1250 IIO_MOD_Z,
1251 IIO_EV_TYPE_ROC,
1252 dir),
1253 data->timestamp);
1254
Octavian Purdila3bbec972015-03-22 20:33:40 +02001255 return ret;
1256}
1257
1258static irqreturn_t bmc150_accel_irq_thread_handler(int irq, void *private)
1259{
1260 struct iio_dev *indio_dev = private;
1261 struct bmc150_accel_data *data = iio_priv(indio_dev);
1262 bool ack = false;
1263 int ret;
1264
1265 mutex_lock(&data->mutex);
1266
1267 if (data->fifo_mode) {
1268 ret = __bmc150_accel_fifo_flush(indio_dev,
1269 BMC150_ACCEL_FIFO_LENGTH, true);
1270 if (ret > 0)
1271 ack = true;
1272 }
1273
1274 if (data->ev_enable_state) {
1275 ret = bmc150_accel_handle_roc_event(indio_dev);
1276 if (ret > 0)
1277 ack = true;
1278 }
1279
1280 if (ack) {
Markus Pargmann4011eda2015-09-21 12:55:13 +02001281 ret = regmap_write(data->regmap, BMC150_ACCEL_REG_INT_RST_LATCH,
1282 BMC150_ACCEL_INT_MODE_LATCH_INT |
1283 BMC150_ACCEL_INT_MODE_LATCH_RESET);
Octavian Purdila3bbec972015-03-22 20:33:40 +02001284 if (ret)
Markus Pargmann19c95d62015-09-21 12:55:14 +02001285 dev_err(data->dev, "Error writing reg_int_rst_latch\n");
Hartmut Knaacke20008e2015-06-15 23:48:26 +02001286
Octavian Purdila3bbec972015-03-22 20:33:40 +02001287 ret = IRQ_HANDLED;
1288 } else {
1289 ret = IRQ_NONE;
1290 }
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +01001291
Octavian Purdila3bbec972015-03-22 20:33:40 +02001292 mutex_unlock(&data->mutex);
1293
1294 return ret;
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +01001295}
1296
Octavian Purdila3bbec972015-03-22 20:33:40 +02001297static irqreturn_t bmc150_accel_irq_handler(int irq, void *private)
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +01001298{
1299 struct iio_dev *indio_dev = private;
1300 struct bmc150_accel_data *data = iio_priv(indio_dev);
Octavian Purdila3bbec972015-03-22 20:33:40 +02001301 bool ack = false;
Octavian Purdila7d963212015-03-03 18:17:58 +02001302 int i;
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +01001303
Octavian Purdila3bbec972015-03-22 20:33:40 +02001304 data->old_timestamp = data->timestamp;
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +01001305 data->timestamp = iio_get_time_ns();
1306
Octavian Purdila7d963212015-03-03 18:17:58 +02001307 for (i = 0; i < BMC150_ACCEL_TRIGGERS; i++) {
1308 if (data->triggers[i].enabled) {
1309 iio_trigger_poll(data->triggers[i].indio_trig);
Octavian Purdila3bbec972015-03-22 20:33:40 +02001310 ack = true;
Octavian Purdila7d963212015-03-03 18:17:58 +02001311 break;
1312 }
1313 }
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +01001314
Octavian Purdila3bbec972015-03-22 20:33:40 +02001315 if (data->ev_enable_state || data->fifo_mode)
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +01001316 return IRQ_WAKE_THREAD;
Octavian Purdila3bbec972015-03-22 20:33:40 +02001317
1318 if (ack)
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +01001319 return IRQ_HANDLED;
Octavian Purdila3bbec972015-03-22 20:33:40 +02001320
1321 return IRQ_NONE;
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +01001322}
1323
Octavian Purdila7d963212015-03-03 18:17:58 +02001324static const struct {
1325 int intr;
1326 const char *name;
1327 int (*setup)(struct bmc150_accel_trigger *t, bool state);
1328} bmc150_accel_triggers[BMC150_ACCEL_TRIGGERS] = {
1329 {
1330 .intr = 0,
1331 .name = "%s-dev%d",
1332 },
1333 {
1334 .intr = 1,
1335 .name = "%s-any-motion-dev%d",
1336 .setup = bmc150_accel_any_motion_setup,
1337 },
1338};
1339
1340static void bmc150_accel_unregister_triggers(struct bmc150_accel_data *data,
1341 int from)
1342{
1343 int i;
1344
Hartmut Knaack7a1d0d92015-06-15 23:48:24 +02001345 for (i = from; i >= 0; i--) {
Octavian Purdila7d963212015-03-03 18:17:58 +02001346 if (data->triggers[i].indio_trig) {
1347 iio_trigger_unregister(data->triggers[i].indio_trig);
1348 data->triggers[i].indio_trig = NULL;
1349 }
1350 }
1351}
1352
1353static int bmc150_accel_triggers_setup(struct iio_dev *indio_dev,
1354 struct bmc150_accel_data *data)
1355{
1356 int i, ret;
1357
1358 for (i = 0; i < BMC150_ACCEL_TRIGGERS; i++) {
1359 struct bmc150_accel_trigger *t = &data->triggers[i];
1360
Markus Pargmann19c95d62015-09-21 12:55:14 +02001361 t->indio_trig = devm_iio_trigger_alloc(data->dev,
Octavian Purdila7d963212015-03-03 18:17:58 +02001362 bmc150_accel_triggers[i].name,
1363 indio_dev->name,
1364 indio_dev->id);
1365 if (!t->indio_trig) {
1366 ret = -ENOMEM;
1367 break;
1368 }
1369
Markus Pargmann19c95d62015-09-21 12:55:14 +02001370 t->indio_trig->dev.parent = data->dev;
Octavian Purdila7d963212015-03-03 18:17:58 +02001371 t->indio_trig->ops = &bmc150_accel_trigger_ops;
1372 t->intr = bmc150_accel_triggers[i].intr;
1373 t->data = data;
1374 t->setup = bmc150_accel_triggers[i].setup;
1375 iio_trigger_set_drvdata(t->indio_trig, t);
1376
1377 ret = iio_trigger_register(t->indio_trig);
1378 if (ret)
1379 break;
1380 }
1381
1382 if (ret)
1383 bmc150_accel_unregister_triggers(data, i - 1);
1384
1385 return ret;
1386}
1387
Octavian Purdila3bbec972015-03-22 20:33:40 +02001388#define BMC150_ACCEL_FIFO_MODE_STREAM 0x80
1389#define BMC150_ACCEL_FIFO_MODE_FIFO 0x40
1390#define BMC150_ACCEL_FIFO_MODE_BYPASS 0x00
1391
1392static int bmc150_accel_fifo_set_mode(struct bmc150_accel_data *data)
1393{
1394 u8 reg = BMC150_ACCEL_REG_FIFO_CONFIG1;
1395 int ret;
1396
Markus Pargmann4011eda2015-09-21 12:55:13 +02001397 ret = regmap_write(data->regmap, reg, data->fifo_mode);
Octavian Purdila3bbec972015-03-22 20:33:40 +02001398 if (ret < 0) {
Markus Pargmann19c95d62015-09-21 12:55:14 +02001399 dev_err(data->dev, "Error writing reg_fifo_config1\n");
Octavian Purdila3bbec972015-03-22 20:33:40 +02001400 return ret;
1401 }
1402
1403 if (!data->fifo_mode)
1404 return 0;
1405
Markus Pargmann4011eda2015-09-21 12:55:13 +02001406 ret = regmap_write(data->regmap, BMC150_ACCEL_REG_FIFO_CONFIG0,
1407 data->watermark);
Octavian Purdila3bbec972015-03-22 20:33:40 +02001408 if (ret < 0)
Markus Pargmann19c95d62015-09-21 12:55:14 +02001409 dev_err(data->dev, "Error writing reg_fifo_config0\n");
Octavian Purdila3bbec972015-03-22 20:33:40 +02001410
1411 return ret;
1412}
1413
Vlad Dogaruc16bff42015-05-12 17:03:24 +03001414static int bmc150_accel_buffer_preenable(struct iio_dev *indio_dev)
1415{
1416 struct bmc150_accel_data *data = iio_priv(indio_dev);
1417
1418 return bmc150_accel_set_power_state(data, true);
1419}
1420
Octavian Purdila3bbec972015-03-22 20:33:40 +02001421static int bmc150_accel_buffer_postenable(struct iio_dev *indio_dev)
1422{
1423 struct bmc150_accel_data *data = iio_priv(indio_dev);
1424 int ret = 0;
1425
1426 if (indio_dev->currentmode == INDIO_BUFFER_TRIGGERED)
1427 return iio_triggered_buffer_postenable(indio_dev);
1428
1429 mutex_lock(&data->mutex);
1430
1431 if (!data->watermark)
1432 goto out;
1433
1434 ret = bmc150_accel_set_interrupt(data, BMC150_ACCEL_INT_WATERMARK,
1435 true);
1436 if (ret)
1437 goto out;
1438
1439 data->fifo_mode = BMC150_ACCEL_FIFO_MODE_FIFO;
1440
1441 ret = bmc150_accel_fifo_set_mode(data);
1442 if (ret) {
1443 data->fifo_mode = 0;
1444 bmc150_accel_set_interrupt(data, BMC150_ACCEL_INT_WATERMARK,
1445 false);
1446 }
1447
1448out:
1449 mutex_unlock(&data->mutex);
1450
1451 return ret;
1452}
1453
1454static int bmc150_accel_buffer_predisable(struct iio_dev *indio_dev)
1455{
1456 struct bmc150_accel_data *data = iio_priv(indio_dev);
1457
1458 if (indio_dev->currentmode == INDIO_BUFFER_TRIGGERED)
1459 return iio_triggered_buffer_predisable(indio_dev);
1460
1461 mutex_lock(&data->mutex);
1462
1463 if (!data->fifo_mode)
1464 goto out;
1465
1466 bmc150_accel_set_interrupt(data, BMC150_ACCEL_INT_WATERMARK, false);
1467 __bmc150_accel_fifo_flush(indio_dev, BMC150_ACCEL_FIFO_LENGTH, false);
1468 data->fifo_mode = 0;
1469 bmc150_accel_fifo_set_mode(data);
1470
1471out:
1472 mutex_unlock(&data->mutex);
1473
1474 return 0;
1475}
1476
Vlad Dogaruc16bff42015-05-12 17:03:24 +03001477static int bmc150_accel_buffer_postdisable(struct iio_dev *indio_dev)
1478{
1479 struct bmc150_accel_data *data = iio_priv(indio_dev);
1480
1481 return bmc150_accel_set_power_state(data, false);
1482}
1483
Octavian Purdila3bbec972015-03-22 20:33:40 +02001484static const struct iio_buffer_setup_ops bmc150_accel_buffer_ops = {
Vlad Dogaruc16bff42015-05-12 17:03:24 +03001485 .preenable = bmc150_accel_buffer_preenable,
Octavian Purdila3bbec972015-03-22 20:33:40 +02001486 .postenable = bmc150_accel_buffer_postenable,
1487 .predisable = bmc150_accel_buffer_predisable,
Vlad Dogaruc16bff42015-05-12 17:03:24 +03001488 .postdisable = bmc150_accel_buffer_postdisable,
Octavian Purdila3bbec972015-03-22 20:33:40 +02001489};
1490
Bastien Nocerac4eaab72015-07-23 17:20:59 +02001491static int bmc150_accel_chip_init(struct bmc150_accel_data *data)
1492{
Bastien Nocera0ad4bf32015-07-23 17:21:07 +02001493 int ret, i;
Markus Pargmann4011eda2015-09-21 12:55:13 +02001494 unsigned int val;
Bastien Nocerac4eaab72015-07-23 17:20:59 +02001495
Markus Pargmann4011eda2015-09-21 12:55:13 +02001496 ret = regmap_read(data->regmap, BMC150_ACCEL_REG_CHIP_ID, &val);
Bastien Nocerac4eaab72015-07-23 17:20:59 +02001497 if (ret < 0) {
Markus Pargmann19c95d62015-09-21 12:55:14 +02001498 dev_err(data->dev,
Markus Pargmann4011eda2015-09-21 12:55:13 +02001499 "Error: Reading chip id\n");
Bastien Nocerac4eaab72015-07-23 17:20:59 +02001500 return ret;
1501 }
1502
Markus Pargmann19c95d62015-09-21 12:55:14 +02001503 dev_dbg(data->dev, "Chip Id %x\n", val);
Bastien Nocera0ad4bf32015-07-23 17:21:07 +02001504 for (i = 0; i < ARRAY_SIZE(bmc150_accel_chip_info_tbl); i++) {
Markus Pargmann4011eda2015-09-21 12:55:13 +02001505 if (bmc150_accel_chip_info_tbl[i].chip_id == val) {
Bastien Nocera0ad4bf32015-07-23 17:21:07 +02001506 data->chip_info = &bmc150_accel_chip_info_tbl[i];
1507 break;
1508 }
1509 }
1510
1511 if (!data->chip_info) {
Markus Pargmann19c95d62015-09-21 12:55:14 +02001512 dev_err(data->dev, "Invalid chip %x\n", val);
Bastien Nocerac4eaab72015-07-23 17:20:59 +02001513 return -ENODEV;
1514 }
1515
1516 ret = bmc150_accel_set_mode(data, BMC150_ACCEL_SLEEP_MODE_NORMAL, 0);
1517 if (ret < 0)
1518 return ret;
1519
1520 /* Set Bandwidth */
1521 ret = bmc150_accel_set_bw(data, BMC150_ACCEL_DEF_BW, 0);
1522 if (ret < 0)
1523 return ret;
1524
1525 /* Set Default Range */
Markus Pargmann4011eda2015-09-21 12:55:13 +02001526 ret = regmap_write(data->regmap, BMC150_ACCEL_REG_PMU_RANGE,
1527 BMC150_ACCEL_DEF_RANGE_4G);
Bastien Nocerac4eaab72015-07-23 17:20:59 +02001528 if (ret < 0) {
Markus Pargmann19c95d62015-09-21 12:55:14 +02001529 dev_err(data->dev,
Markus Pargmann4011eda2015-09-21 12:55:13 +02001530 "Error writing reg_pmu_range\n");
Bastien Nocerac4eaab72015-07-23 17:20:59 +02001531 return ret;
1532 }
1533
1534 data->range = BMC150_ACCEL_DEF_RANGE_4G;
1535
1536 /* Set default slope duration and thresholds */
1537 data->slope_thres = BMC150_ACCEL_DEF_SLOPE_THRESHOLD;
1538 data->slope_dur = BMC150_ACCEL_DEF_SLOPE_DURATION;
1539 ret = bmc150_accel_update_slope(data);
1540 if (ret < 0)
1541 return ret;
1542
1543 /* Set default as latched interrupts */
Markus Pargmann4011eda2015-09-21 12:55:13 +02001544 ret = regmap_write(data->regmap, BMC150_ACCEL_REG_INT_RST_LATCH,
1545 BMC150_ACCEL_INT_MODE_LATCH_INT |
1546 BMC150_ACCEL_INT_MODE_LATCH_RESET);
Bastien Nocerac4eaab72015-07-23 17:20:59 +02001547 if (ret < 0) {
Markus Pargmann19c95d62015-09-21 12:55:14 +02001548 dev_err(data->dev,
Bastien Nocerac4eaab72015-07-23 17:20:59 +02001549 "Error writing reg_int_rst_latch\n");
1550 return ret;
1551 }
1552
1553 return 0;
1554}
1555
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +01001556static int bmc150_accel_probe(struct i2c_client *client,
1557 const struct i2c_device_id *id)
1558{
1559 struct bmc150_accel_data *data;
1560 struct iio_dev *indio_dev;
1561 int ret;
Laurentiu Palcu8ecbb3c2014-02-09 10:30:00 +00001562 const char *name = NULL;
Markus Pargmann19c95d62015-09-21 12:55:14 +02001563 struct device *dev;
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +01001564
1565 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
1566 if (!indio_dev)
1567 return -ENOMEM;
1568
1569 data = iio_priv(indio_dev);
1570 i2c_set_clientdata(client, indio_dev);
Markus Pargmann4011eda2015-09-21 12:55:13 +02001571 data->dev = &client->dev;
Markus Pargmann19c95d62015-09-21 12:55:14 +02001572 dev = &client->dev;
1573 data->irq = client->irq;
Markus Pargmann4011eda2015-09-21 12:55:13 +02001574
1575 data->regmap = devm_regmap_init_i2c(client, &bmc150_i2c_regmap_conf);
1576 if (IS_ERR(data->regmap)) {
Markus Pargmann19c95d62015-09-21 12:55:14 +02001577 dev_err(dev, "Failed to initialize i2c regmap\n");
Markus Pargmann4011eda2015-09-21 12:55:13 +02001578 return PTR_ERR(data->regmap);
1579 }
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +01001580
Bastien Nocera0ad4bf32015-07-23 17:21:07 +02001581 if (id)
Laurentiu Palcu8ecbb3c2014-02-09 10:30:00 +00001582 name = id->name;
Laurentiu Palcu8ecbb3c2014-02-09 10:30:00 +00001583
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +01001584 ret = bmc150_accel_chip_init(data);
1585 if (ret < 0)
1586 return ret;
1587
1588 mutex_init(&data->mutex);
1589
Markus Pargmann19c95d62015-09-21 12:55:14 +02001590 indio_dev->dev.parent = dev;
Laurentiu Palcu8ecbb3c2014-02-09 10:30:00 +00001591 indio_dev->channels = data->chip_info->channels;
1592 indio_dev->num_channels = data->chip_info->num_channels;
Bastien Nocera0ad4bf32015-07-23 17:21:07 +02001593 indio_dev->name = name ? name : data->chip_info->name;
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +01001594 indio_dev->modes = INDIO_DIRECT_MODE;
1595 indio_dev->info = &bmc150_accel_info;
1596
Vlad Dogaruc16bff42015-05-12 17:03:24 +03001597 ret = iio_triggered_buffer_setup(indio_dev,
1598 &iio_pollfunc_store_time,
1599 bmc150_accel_trigger_handler,
1600 &bmc150_accel_buffer_ops);
1601 if (ret < 0) {
Markus Pargmann19c95d62015-09-21 12:55:14 +02001602 dev_err(data->dev, "Failed: iio triggered buffer setup\n");
Vlad Dogaruc16bff42015-05-12 17:03:24 +03001603 return ret;
1604 }
1605
Markus Pargmann19c95d62015-09-21 12:55:14 +02001606 if (data->irq > 0) {
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +01001607 ret = devm_request_threaded_irq(
Markus Pargmann19c95d62015-09-21 12:55:14 +02001608 data->dev, data->irq,
Octavian Purdila3bbec972015-03-22 20:33:40 +02001609 bmc150_accel_irq_handler,
1610 bmc150_accel_irq_thread_handler,
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +01001611 IRQF_TRIGGER_RISING,
1612 BMC150_ACCEL_IRQ_NAME,
1613 indio_dev);
1614 if (ret)
Vlad Dogaruc16bff42015-05-12 17:03:24 +03001615 goto err_buffer_cleanup;
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +01001616
Octavian Purdila8e22f472015-01-31 02:00:04 +02001617 /*
1618 * Set latched mode interrupt. While certain interrupts are
1619 * non-latched regardless of this settings (e.g. new data) we
1620 * want to use latch mode when we can to prevent interrupt
1621 * flooding.
1622 */
Markus Pargmann4011eda2015-09-21 12:55:13 +02001623 ret = regmap_write(data->regmap, BMC150_ACCEL_REG_INT_RST_LATCH,
1624 BMC150_ACCEL_INT_MODE_LATCH_RESET);
Octavian Purdila8e22f472015-01-31 02:00:04 +02001625 if (ret < 0) {
Markus Pargmann19c95d62015-09-21 12:55:14 +02001626 dev_err(data->dev, "Error writing reg_int_rst_latch\n");
Vlad Dogaruc16bff42015-05-12 17:03:24 +03001627 goto err_buffer_cleanup;
Octavian Purdila8e22f472015-01-31 02:00:04 +02001628 }
1629
Octavian Purdila3e825ec2015-03-03 18:17:57 +02001630 bmc150_accel_interrupts_setup(indio_dev, data);
1631
Octavian Purdila7d963212015-03-03 18:17:58 +02001632 ret = bmc150_accel_triggers_setup(indio_dev, data);
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +01001633 if (ret)
Vlad Dogaruc16bff42015-05-12 17:03:24 +03001634 goto err_buffer_cleanup;
Octavian Purdila3bbec972015-03-22 20:33:40 +02001635
1636 if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C) ||
1637 i2c_check_functionality(client->adapter,
1638 I2C_FUNC_SMBUS_READ_I2C_BLOCK)) {
1639 indio_dev->modes |= INDIO_BUFFER_SOFTWARE;
1640 indio_dev->info = &bmc150_accel_info_fifo;
1641 indio_dev->buffer->attrs = bmc150_accel_fifo_attributes;
1642 }
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +01001643 }
1644
1645 ret = iio_device_register(indio_dev);
1646 if (ret < 0) {
Markus Pargmann19c95d62015-09-21 12:55:14 +02001647 dev_err(data->dev, "Unable to register iio device\n");
Vlad Dogaruc16bff42015-05-12 17:03:24 +03001648 goto err_trigger_unregister;
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +01001649 }
1650
Markus Pargmann19c95d62015-09-21 12:55:14 +02001651 ret = pm_runtime_set_active(dev);
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +01001652 if (ret)
1653 goto err_iio_unregister;
1654
Markus Pargmann19c95d62015-09-21 12:55:14 +02001655 pm_runtime_enable(dev);
1656 pm_runtime_set_autosuspend_delay(dev, BMC150_AUTO_SUSPEND_DELAY_MS);
1657 pm_runtime_use_autosuspend(dev);
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +01001658
1659 return 0;
1660
1661err_iio_unregister:
1662 iio_device_unregister(indio_dev);
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +01001663err_trigger_unregister:
Octavian Purdila7d963212015-03-03 18:17:58 +02001664 bmc150_accel_unregister_triggers(data, BMC150_ACCEL_TRIGGERS - 1);
Vlad Dogaruc16bff42015-05-12 17:03:24 +03001665err_buffer_cleanup:
1666 iio_triggered_buffer_cleanup(indio_dev);
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +01001667
1668 return ret;
1669}
1670
1671static int bmc150_accel_remove(struct i2c_client *client)
1672{
1673 struct iio_dev *indio_dev = i2c_get_clientdata(client);
1674 struct bmc150_accel_data *data = iio_priv(indio_dev);
1675
Markus Pargmann19c95d62015-09-21 12:55:14 +02001676 pm_runtime_disable(data->dev);
1677 pm_runtime_set_suspended(data->dev);
1678 pm_runtime_put_noidle(data->dev);
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +01001679
1680 iio_device_unregister(indio_dev);
1681
Octavian Purdila7d963212015-03-03 18:17:58 +02001682 bmc150_accel_unregister_triggers(data, BMC150_ACCEL_TRIGGERS - 1);
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +01001683
Vlad Dogaruc16bff42015-05-12 17:03:24 +03001684 iio_triggered_buffer_cleanup(indio_dev);
1685
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +01001686 mutex_lock(&data->mutex);
1687 bmc150_accel_set_mode(data, BMC150_ACCEL_SLEEP_MODE_DEEP_SUSPEND, 0);
1688 mutex_unlock(&data->mutex);
1689
1690 return 0;
1691}
1692
1693#ifdef CONFIG_PM_SLEEP
1694static int bmc150_accel_suspend(struct device *dev)
1695{
Markus Pargmann19c95d62015-09-21 12:55:14 +02001696 struct iio_dev *indio_dev = dev_get_drvdata(dev);
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +01001697 struct bmc150_accel_data *data = iio_priv(indio_dev);
1698
1699 mutex_lock(&data->mutex);
1700 bmc150_accel_set_mode(data, BMC150_ACCEL_SLEEP_MODE_SUSPEND, 0);
1701 mutex_unlock(&data->mutex);
1702
1703 return 0;
1704}
1705
1706static int bmc150_accel_resume(struct device *dev)
1707{
Markus Pargmann19c95d62015-09-21 12:55:14 +02001708 struct iio_dev *indio_dev = dev_get_drvdata(dev);
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +01001709 struct bmc150_accel_data *data = iio_priv(indio_dev);
1710
1711 mutex_lock(&data->mutex);
Octavian Purdila3e825ec2015-03-03 18:17:57 +02001712 if (atomic_read(&data->active_intr))
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +01001713 bmc150_accel_set_mode(data, BMC150_ACCEL_SLEEP_MODE_NORMAL, 0);
Octavian Purdila3bbec972015-03-22 20:33:40 +02001714 bmc150_accel_fifo_set_mode(data);
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +01001715 mutex_unlock(&data->mutex);
1716
1717 return 0;
1718}
1719#endif
1720
Rafael J. Wysocki6f0a13f2014-12-04 01:08:13 +01001721#ifdef CONFIG_PM
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +01001722static int bmc150_accel_runtime_suspend(struct device *dev)
1723{
Markus Pargmann19c95d62015-09-21 12:55:14 +02001724 struct iio_dev *indio_dev = dev_get_drvdata(dev);
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +01001725 struct bmc150_accel_data *data = iio_priv(indio_dev);
Srinivas Pandruvadaaaeecd82014-10-10 20:35:31 -07001726 int ret;
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +01001727
Markus Pargmann19c95d62015-09-21 12:55:14 +02001728 dev_dbg(data->dev, __func__);
Srinivas Pandruvadaaaeecd82014-10-10 20:35:31 -07001729 ret = bmc150_accel_set_mode(data, BMC150_ACCEL_SLEEP_MODE_SUSPEND, 0);
1730 if (ret < 0)
1731 return -EAGAIN;
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +01001732
Srinivas Pandruvadaaaeecd82014-10-10 20:35:31 -07001733 return 0;
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +01001734}
1735
1736static int bmc150_accel_runtime_resume(struct device *dev)
1737{
Markus Pargmann19c95d62015-09-21 12:55:14 +02001738 struct iio_dev *indio_dev = dev_get_drvdata(dev);
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +01001739 struct bmc150_accel_data *data = iio_priv(indio_dev);
1740 int ret;
1741 int sleep_val;
1742
Markus Pargmann19c95d62015-09-21 12:55:14 +02001743 dev_dbg(data->dev, __func__);
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +01001744
1745 ret = bmc150_accel_set_mode(data, BMC150_ACCEL_SLEEP_MODE_NORMAL, 0);
1746 if (ret < 0)
1747 return ret;
Octavian Purdila3bbec972015-03-22 20:33:40 +02001748 ret = bmc150_accel_fifo_set_mode(data);
1749 if (ret < 0)
1750 return ret;
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +01001751
1752 sleep_val = bmc150_accel_get_startup_times(data);
1753 if (sleep_val < 20)
1754 usleep_range(sleep_val * 1000, 20000);
1755 else
1756 msleep_interruptible(sleep_val);
1757
1758 return 0;
1759}
1760#endif
1761
1762static const struct dev_pm_ops bmc150_accel_pm_ops = {
1763 SET_SYSTEM_SLEEP_PM_OPS(bmc150_accel_suspend, bmc150_accel_resume)
1764 SET_RUNTIME_PM_OPS(bmc150_accel_runtime_suspend,
1765 bmc150_accel_runtime_resume, NULL)
1766};
1767
1768static const struct acpi_device_id bmc150_accel_acpi_match[] = {
Laurentiu Palcu8ecbb3c2014-02-09 10:30:00 +00001769 {"BSBA0150", bmc150},
1770 {"BMC150A", bmc150},
1771 {"BMI055A", bmi055},
1772 {"BMA0255", bma255},
1773 {"BMA250E", bma250e},
1774 {"BMA222E", bma222e},
1775 {"BMA0280", bma280},
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +01001776 { },
1777};
1778MODULE_DEVICE_TABLE(acpi, bmc150_accel_acpi_match);
1779
1780static const struct i2c_device_id bmc150_accel_id[] = {
Laurentiu Palcu8ecbb3c2014-02-09 10:30:00 +00001781 {"bmc150_accel", bmc150},
1782 {"bmi055_accel", bmi055},
1783 {"bma255", bma255},
1784 {"bma250e", bma250e},
1785 {"bma222e", bma222e},
1786 {"bma280", bma280},
Srinivas Pandruvadabd7fe5b2014-05-08 22:57:00 +01001787 {}
1788};
1789
1790MODULE_DEVICE_TABLE(i2c, bmc150_accel_id);
1791
1792static struct i2c_driver bmc150_accel_driver = {
1793 .driver = {
1794 .name = BMC150_ACCEL_DRV_NAME,
1795 .acpi_match_table = ACPI_PTR(bmc150_accel_acpi_match),
1796 .pm = &bmc150_accel_pm_ops,
1797 },
1798 .probe = bmc150_accel_probe,
1799 .remove = bmc150_accel_remove,
1800 .id_table = bmc150_accel_id,
1801};
1802module_i2c_driver(bmc150_accel_driver);
1803
1804MODULE_AUTHOR("Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>");
1805MODULE_LICENSE("GPL v2");
1806MODULE_DESCRIPTION("BMC150 accelerometer driver");