iio:light:stk3310: use correct names and type for state
[deliverable/linux.git] / drivers / iio / light / stk3310.c
1 /**
2 * Sensortek STK3310/STK3311 Ambient Light and Proximity Sensor
3 *
4 * Copyright (c) 2015, Intel Corporation.
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 * IIO driver for STK3310/STK3311. 7-bit I2C address: 0x48.
11 */
12
13 #include <linux/acpi.h>
14 #include <linux/i2c.h>
15 #include <linux/interrupt.h>
16 #include <linux/kernel.h>
17 #include <linux/module.h>
18 #include <linux/regmap.h>
19 #include <linux/gpio/consumer.h>
20 #include <linux/iio/events.h>
21 #include <linux/iio/iio.h>
22 #include <linux/iio/sysfs.h>
23
24 #define STK3310_REG_STATE 0x00
25 #define STK3310_REG_PSCTRL 0x01
26 #define STK3310_REG_ALSCTRL 0x02
27 #define STK3310_REG_INT 0x04
28 #define STK3310_REG_THDH_PS 0x06
29 #define STK3310_REG_THDL_PS 0x08
30 #define STK3310_REG_FLAG 0x10
31 #define STK3310_REG_PS_DATA_MSB 0x11
32 #define STK3310_REG_PS_DATA_LSB 0x12
33 #define STK3310_REG_ALS_DATA_MSB 0x13
34 #define STK3310_REG_ALS_DATA_LSB 0x14
35 #define STK3310_REG_ID 0x3E
36 #define STK3310_MAX_REG 0x80
37
38 #define STK3310_STATE_EN_PS BIT(0)
39 #define STK3310_STATE_EN_ALS BIT(1)
40 #define STK3310_STATE_STANDBY 0x00
41
42 #define STK3310_CHIP_ID_VAL 0x13
43 #define STK3311_CHIP_ID_VAL 0x1D
44 #define STK3310_PSINT_EN 0x01
45 #define STK3310_PS_MAX_VAL 0xFFFF
46
47 #define STK3310_DRIVER_NAME "stk3310"
48 #define STK3310_REGMAP_NAME "stk3310_regmap"
49 #define STK3310_EVENT "stk3310_event"
50 #define STK3310_GPIO "stk3310_gpio"
51
52 #define STK3310_SCALE_AVAILABLE "6.4 1.6 0.4 0.1"
53
54 #define STK3310_IT_AVAILABLE \
55 "0.000185 0.000370 0.000741 0.001480 0.002960 0.005920 0.011840 " \
56 "0.023680 0.047360 0.094720 0.189440 0.378880 0.757760 1.515520 " \
57 "3.031040 6.062080"
58
59 #define STK3310_REGFIELD(name) \
60 do { \
61 data->reg_##name = \
62 devm_regmap_field_alloc(&client->dev, regmap, \
63 stk3310_reg_field_##name); \
64 if (IS_ERR(data->reg_##name)) { \
65 dev_err(&client->dev, "reg field alloc failed.\n"); \
66 return PTR_ERR(data->reg_##name); \
67 } \
68 } while (0)
69
70 static const struct reg_field stk3310_reg_field_state =
71 REG_FIELD(STK3310_REG_STATE, 0, 2);
72 static const struct reg_field stk3310_reg_field_als_gain =
73 REG_FIELD(STK3310_REG_ALSCTRL, 4, 5);
74 static const struct reg_field stk3310_reg_field_ps_gain =
75 REG_FIELD(STK3310_REG_PSCTRL, 4, 5);
76 static const struct reg_field stk3310_reg_field_als_it =
77 REG_FIELD(STK3310_REG_ALSCTRL, 0, 3);
78 static const struct reg_field stk3310_reg_field_ps_it =
79 REG_FIELD(STK3310_REG_PSCTRL, 0, 3);
80 static const struct reg_field stk3310_reg_field_int_ps =
81 REG_FIELD(STK3310_REG_INT, 0, 2);
82 static const struct reg_field stk3310_reg_field_flag_psint =
83 REG_FIELD(STK3310_REG_FLAG, 4, 4);
84 static const struct reg_field stk3310_reg_field_flag_nf =
85 REG_FIELD(STK3310_REG_FLAG, 0, 0);
86
87 /* Estimate maximum proximity values with regard to measurement scale. */
88 static const int stk3310_ps_max[4] = {
89 STK3310_PS_MAX_VAL / 640,
90 STK3310_PS_MAX_VAL / 160,
91 STK3310_PS_MAX_VAL / 40,
92 STK3310_PS_MAX_VAL / 10
93 };
94
95 static const int stk3310_scale_table[][2] = {
96 {6, 400000}, {1, 600000}, {0, 400000}, {0, 100000}
97 };
98
99 /* Integration time in seconds, microseconds */
100 static const int stk3310_it_table[][2] = {
101 {0, 185}, {0, 370}, {0, 741}, {0, 1480},
102 {0, 2960}, {0, 5920}, {0, 11840}, {0, 23680},
103 {0, 47360}, {0, 94720}, {0, 189440}, {0, 378880},
104 {0, 757760}, {1, 515520}, {3, 31040}, {6, 62080},
105 };
106
107 struct stk3310_data {
108 struct i2c_client *client;
109 struct mutex lock;
110 bool als_enabled;
111 bool ps_enabled;
112 u64 timestamp;
113 struct regmap *regmap;
114 struct regmap_field *reg_state;
115 struct regmap_field *reg_als_gain;
116 struct regmap_field *reg_ps_gain;
117 struct regmap_field *reg_als_it;
118 struct regmap_field *reg_ps_it;
119 struct regmap_field *reg_int_ps;
120 struct regmap_field *reg_flag_psint;
121 struct regmap_field *reg_flag_nf;
122 };
123
124 static const struct iio_event_spec stk3310_events[] = {
125 /* Proximity event */
126 {
127 .type = IIO_EV_TYPE_THRESH,
128 .dir = IIO_EV_DIR_RISING,
129 .mask_separate = BIT(IIO_EV_INFO_VALUE) |
130 BIT(IIO_EV_INFO_ENABLE),
131 },
132 /* Out-of-proximity event */
133 {
134 .type = IIO_EV_TYPE_THRESH,
135 .dir = IIO_EV_DIR_FALLING,
136 .mask_separate = BIT(IIO_EV_INFO_VALUE) |
137 BIT(IIO_EV_INFO_ENABLE),
138 },
139 };
140
141 static const struct iio_chan_spec stk3310_channels[] = {
142 {
143 .type = IIO_LIGHT,
144 .info_mask_separate =
145 BIT(IIO_CHAN_INFO_RAW) |
146 BIT(IIO_CHAN_INFO_SCALE) |
147 BIT(IIO_CHAN_INFO_INT_TIME),
148 },
149 {
150 .type = IIO_PROXIMITY,
151 .info_mask_separate =
152 BIT(IIO_CHAN_INFO_RAW) |
153 BIT(IIO_CHAN_INFO_SCALE) |
154 BIT(IIO_CHAN_INFO_INT_TIME),
155 .event_spec = stk3310_events,
156 .num_event_specs = ARRAY_SIZE(stk3310_events),
157 }
158 };
159
160 static IIO_CONST_ATTR(in_illuminance_scale_available, STK3310_SCALE_AVAILABLE);
161
162 static IIO_CONST_ATTR(in_proximity_scale_available, STK3310_SCALE_AVAILABLE);
163
164 static IIO_CONST_ATTR(in_illuminance_integration_time_available,
165 STK3310_IT_AVAILABLE);
166
167 static IIO_CONST_ATTR(in_proximity_integration_time_available,
168 STK3310_IT_AVAILABLE);
169
170 static struct attribute *stk3310_attributes[] = {
171 &iio_const_attr_in_illuminance_scale_available.dev_attr.attr,
172 &iio_const_attr_in_proximity_scale_available.dev_attr.attr,
173 &iio_const_attr_in_illuminance_integration_time_available.dev_attr.attr,
174 &iio_const_attr_in_proximity_integration_time_available.dev_attr.attr,
175 NULL,
176 };
177
178 static const struct attribute_group stk3310_attribute_group = {
179 .attrs = stk3310_attributes
180 };
181
182 static int stk3310_get_index(const int table[][2], int table_size,
183 int val, int val2)
184 {
185 int i;
186
187 for (i = 0; i < table_size; i++) {
188 if (val == table[i][0] && val2 == table[i][1])
189 return i;
190 }
191
192 return -EINVAL;
193 }
194
195 static int stk3310_read_event(struct iio_dev *indio_dev,
196 const struct iio_chan_spec *chan,
197 enum iio_event_type type,
198 enum iio_event_direction dir,
199 enum iio_event_info info,
200 int *val, int *val2)
201 {
202 u8 reg;
203 __be16 buf;
204 int ret;
205 struct stk3310_data *data = iio_priv(indio_dev);
206
207 if (info != IIO_EV_INFO_VALUE)
208 return -EINVAL;
209
210 /* Only proximity interrupts are implemented at the moment. */
211 if (dir == IIO_EV_DIR_RISING)
212 reg = STK3310_REG_THDH_PS;
213 else if (dir == IIO_EV_DIR_FALLING)
214 reg = STK3310_REG_THDL_PS;
215 else
216 return -EINVAL;
217
218 mutex_lock(&data->lock);
219 ret = regmap_bulk_read(data->regmap, reg, &buf, 2);
220 mutex_unlock(&data->lock);
221 if (ret < 0) {
222 dev_err(&data->client->dev, "register read failed\n");
223 return ret;
224 }
225 *val = be16_to_cpu(buf);
226
227 return IIO_VAL_INT;
228 }
229
230 static int stk3310_write_event(struct iio_dev *indio_dev,
231 const struct iio_chan_spec *chan,
232 enum iio_event_type type,
233 enum iio_event_direction dir,
234 enum iio_event_info info,
235 int val, int val2)
236 {
237 u8 reg;
238 __be16 buf;
239 int ret;
240 unsigned int index;
241 struct stk3310_data *data = iio_priv(indio_dev);
242 struct i2c_client *client = data->client;
243
244 ret = regmap_field_read(data->reg_ps_gain, &index);
245 if (ret < 0)
246 return ret;
247
248 if (val < 0 || val > stk3310_ps_max[index])
249 return -EINVAL;
250
251 if (dir == IIO_EV_DIR_RISING)
252 reg = STK3310_REG_THDH_PS;
253 else if (dir == IIO_EV_DIR_FALLING)
254 reg = STK3310_REG_THDL_PS;
255 else
256 return -EINVAL;
257
258 buf = cpu_to_be16(val);
259 ret = regmap_bulk_write(data->regmap, reg, &buf, 2);
260 if (ret < 0)
261 dev_err(&client->dev, "failed to set PS threshold!\n");
262
263 return ret;
264 }
265
266 static int stk3310_read_event_config(struct iio_dev *indio_dev,
267 const struct iio_chan_spec *chan,
268 enum iio_event_type type,
269 enum iio_event_direction dir)
270 {
271 unsigned int event_val;
272 int ret;
273 struct stk3310_data *data = iio_priv(indio_dev);
274
275 ret = regmap_field_read(data->reg_int_ps, &event_val);
276 if (ret < 0)
277 return ret;
278
279 return event_val;
280 }
281
282 static int stk3310_write_event_config(struct iio_dev *indio_dev,
283 const struct iio_chan_spec *chan,
284 enum iio_event_type type,
285 enum iio_event_direction dir,
286 int state)
287 {
288 int ret;
289 struct stk3310_data *data = iio_priv(indio_dev);
290 struct i2c_client *client = data->client;
291
292 if (state < 0 || state > 7)
293 return -EINVAL;
294
295 /* Set INT_PS value */
296 mutex_lock(&data->lock);
297 ret = regmap_field_write(data->reg_int_ps, state);
298 if (ret < 0)
299 dev_err(&client->dev, "failed to set interrupt mode\n");
300 mutex_unlock(&data->lock);
301
302 return ret;
303 }
304
305 static int stk3310_read_raw(struct iio_dev *indio_dev,
306 struct iio_chan_spec const *chan,
307 int *val, int *val2, long mask)
308 {
309 u8 reg;
310 __be16 buf;
311 int ret;
312 unsigned int index;
313 struct stk3310_data *data = iio_priv(indio_dev);
314 struct i2c_client *client = data->client;
315
316 if (chan->type != IIO_LIGHT && chan->type != IIO_PROXIMITY)
317 return -EINVAL;
318
319 switch (mask) {
320 case IIO_CHAN_INFO_RAW:
321 if (chan->type == IIO_LIGHT)
322 reg = STK3310_REG_ALS_DATA_MSB;
323 else
324 reg = STK3310_REG_PS_DATA_MSB;
325
326 mutex_lock(&data->lock);
327 ret = regmap_bulk_read(data->regmap, reg, &buf, 2);
328 if (ret < 0) {
329 dev_err(&client->dev, "register read failed\n");
330 mutex_unlock(&data->lock);
331 return ret;
332 }
333 *val = be16_to_cpu(buf);
334 mutex_unlock(&data->lock);
335 return IIO_VAL_INT;
336 case IIO_CHAN_INFO_INT_TIME:
337 if (chan->type == IIO_LIGHT)
338 ret = regmap_field_read(data->reg_als_it, &index);
339 else
340 ret = regmap_field_read(data->reg_ps_it, &index);
341 if (ret < 0)
342 return ret;
343
344 *val = stk3310_it_table[index][0];
345 *val2 = stk3310_it_table[index][1];
346 return IIO_VAL_INT_PLUS_MICRO;
347 case IIO_CHAN_INFO_SCALE:
348 if (chan->type == IIO_LIGHT)
349 ret = regmap_field_read(data->reg_als_gain, &index);
350 else
351 ret = regmap_field_read(data->reg_ps_gain, &index);
352 if (ret < 0)
353 return ret;
354
355 *val = stk3310_scale_table[index][0];
356 *val2 = stk3310_scale_table[index][1];
357 return IIO_VAL_INT_PLUS_MICRO;
358 }
359
360 return -EINVAL;
361 }
362
363 static int stk3310_write_raw(struct iio_dev *indio_dev,
364 struct iio_chan_spec const *chan,
365 int val, int val2, long mask)
366 {
367 int ret;
368 int index;
369 struct stk3310_data *data = iio_priv(indio_dev);
370
371 if (chan->type != IIO_LIGHT && chan->type != IIO_PROXIMITY)
372 return -EINVAL;
373
374 switch (mask) {
375 case IIO_CHAN_INFO_INT_TIME:
376 index = stk3310_get_index(stk3310_it_table,
377 ARRAY_SIZE(stk3310_it_table),
378 val, val2);
379 if (index < 0)
380 return -EINVAL;
381 mutex_lock(&data->lock);
382 if (chan->type == IIO_LIGHT)
383 ret = regmap_field_write(data->reg_als_it, index);
384 else
385 ret = regmap_field_write(data->reg_ps_it, index);
386 if (ret < 0)
387 dev_err(&data->client->dev,
388 "sensor configuration failed\n");
389 mutex_unlock(&data->lock);
390 return ret;
391
392 case IIO_CHAN_INFO_SCALE:
393 index = stk3310_get_index(stk3310_scale_table,
394 ARRAY_SIZE(stk3310_scale_table),
395 val, val2);
396 if (index < 0)
397 return -EINVAL;
398 mutex_lock(&data->lock);
399 if (chan->type == IIO_LIGHT)
400 ret = regmap_field_write(data->reg_als_gain, index);
401 else
402 ret = regmap_field_write(data->reg_ps_gain, index);
403 if (ret < 0)
404 dev_err(&data->client->dev,
405 "sensor configuration failed\n");
406 mutex_unlock(&data->lock);
407 return ret;
408 }
409
410 return -EINVAL;
411 }
412
413 static const struct iio_info stk3310_info = {
414 .driver_module = THIS_MODULE,
415 .read_raw = stk3310_read_raw,
416 .write_raw = stk3310_write_raw,
417 .attrs = &stk3310_attribute_group,
418 .read_event_value = stk3310_read_event,
419 .write_event_value = stk3310_write_event,
420 .read_event_config = stk3310_read_event_config,
421 .write_event_config = stk3310_write_event_config,
422 };
423
424 static int stk3310_set_state(struct stk3310_data *data, u8 state)
425 {
426 int ret;
427 struct i2c_client *client = data->client;
428
429 /* 3-bit state; 0b100 is not supported. */
430 if (state > 7 || state == 4)
431 return -EINVAL;
432
433 mutex_lock(&data->lock);
434 ret = regmap_field_write(data->reg_state, state);
435 if (ret < 0) {
436 dev_err(&client->dev, "failed to change sensor state\n");
437 } else if (state != STK3310_STATE_STANDBY) {
438 /* Don't reset the 'enabled' flags if we're going in standby */
439 data->ps_enabled = !!(state & STK3310_STATE_EN_PS);
440 data->als_enabled = !!(state & STK3310_STATE_EN_ALS);
441 }
442 mutex_unlock(&data->lock);
443
444 return ret;
445 }
446
447 static int stk3310_init(struct iio_dev *indio_dev)
448 {
449 int ret;
450 int chipid;
451 u8 state;
452 struct stk3310_data *data = iio_priv(indio_dev);
453 struct i2c_client *client = data->client;
454
455 ret = regmap_read(data->regmap, STK3310_REG_ID, &chipid);
456 if (ret < 0)
457 return ret;
458
459 if (chipid != STK3310_CHIP_ID_VAL &&
460 chipid != STK3311_CHIP_ID_VAL) {
461 dev_err(&client->dev, "invalid chip id: 0x%x\n", chipid);
462 return -ENODEV;
463 }
464
465 state = STK3310_STATE_EN_ALS | STK3310_STATE_EN_PS;
466 ret = stk3310_set_state(data, state);
467 if (ret < 0) {
468 dev_err(&client->dev, "failed to enable sensor");
469 return ret;
470 }
471
472 /* Enable PS interrupts */
473 ret = regmap_field_write(data->reg_int_ps, STK3310_PSINT_EN);
474 if (ret < 0)
475 dev_err(&client->dev, "failed to enable interrupts!\n");
476
477 return ret;
478 }
479
480 static int stk3310_gpio_probe(struct i2c_client *client)
481 {
482 struct device *dev;
483 struct gpio_desc *gpio;
484 int ret;
485
486 if (!client)
487 return -EINVAL;
488
489 dev = &client->dev;
490
491 /* gpio interrupt pin */
492 gpio = devm_gpiod_get_index(dev, STK3310_GPIO, 0);
493 if (IS_ERR(gpio)) {
494 dev_err(dev, "acpi gpio get index failed\n");
495 return PTR_ERR(gpio);
496 }
497
498 ret = gpiod_direction_input(gpio);
499 if (ret)
500 return ret;
501
502 ret = gpiod_to_irq(gpio);
503 dev_dbg(dev, "GPIO resource, no:%d irq:%d\n", desc_to_gpio(gpio), ret);
504
505 return ret;
506 }
507
508 static bool stk3310_is_volatile_reg(struct device *dev, unsigned int reg)
509 {
510 switch (reg) {
511 case STK3310_REG_ALS_DATA_MSB:
512 case STK3310_REG_ALS_DATA_LSB:
513 case STK3310_REG_PS_DATA_LSB:
514 case STK3310_REG_PS_DATA_MSB:
515 case STK3310_REG_FLAG:
516 return true;
517 default:
518 return false;
519 }
520 }
521
522 static struct regmap_config stk3310_regmap_config = {
523 .name = STK3310_REGMAP_NAME,
524 .reg_bits = 8,
525 .val_bits = 8,
526 .max_register = STK3310_MAX_REG,
527 .cache_type = REGCACHE_RBTREE,
528 .volatile_reg = stk3310_is_volatile_reg,
529 };
530
531 static int stk3310_regmap_init(struct stk3310_data *data)
532 {
533 struct regmap *regmap;
534 struct i2c_client *client;
535
536 client = data->client;
537 regmap = devm_regmap_init_i2c(client, &stk3310_regmap_config);
538 if (IS_ERR(regmap)) {
539 dev_err(&client->dev, "regmap initialization failed.\n");
540 return PTR_ERR(regmap);
541 }
542 data->regmap = regmap;
543
544 STK3310_REGFIELD(state);
545 STK3310_REGFIELD(als_gain);
546 STK3310_REGFIELD(ps_gain);
547 STK3310_REGFIELD(als_it);
548 STK3310_REGFIELD(ps_it);
549 STK3310_REGFIELD(int_ps);
550 STK3310_REGFIELD(flag_psint);
551 STK3310_REGFIELD(flag_nf);
552
553 return 0;
554 }
555
556 static irqreturn_t stk3310_irq_handler(int irq, void *private)
557 {
558 struct iio_dev *indio_dev = private;
559 struct stk3310_data *data = iio_priv(indio_dev);
560
561 data->timestamp = iio_get_time_ns();
562
563 return IRQ_WAKE_THREAD;
564 }
565
566 static irqreturn_t stk3310_irq_event_handler(int irq, void *private)
567 {
568 int ret;
569 unsigned int dir;
570 u64 event;
571
572 struct iio_dev *indio_dev = private;
573 struct stk3310_data *data = iio_priv(indio_dev);
574
575 /* Read FLAG_NF to figure out what threshold has been met. */
576 mutex_lock(&data->lock);
577 ret = regmap_field_read(data->reg_flag_nf, &dir);
578 if (ret < 0) {
579 dev_err(&data->client->dev, "register read failed\n");
580 mutex_unlock(&data->lock);
581 return ret;
582 }
583 event = IIO_UNMOD_EVENT_CODE(IIO_PROXIMITY, 1,
584 IIO_EV_TYPE_THRESH,
585 (dir ? IIO_EV_DIR_FALLING :
586 IIO_EV_DIR_RISING));
587 iio_push_event(indio_dev, event, data->timestamp);
588
589 /* Reset the interrupt flag */
590 ret = regmap_field_write(data->reg_flag_psint, 0);
591 if (ret < 0)
592 dev_err(&data->client->dev, "failed to reset interrupts\n");
593 mutex_unlock(&data->lock);
594
595 return IRQ_HANDLED;
596 }
597
598 static int stk3310_probe(struct i2c_client *client,
599 const struct i2c_device_id *id)
600 {
601 int ret;
602 struct iio_dev *indio_dev;
603 struct stk3310_data *data;
604
605 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
606 if (!indio_dev) {
607 dev_err(&client->dev, "iio allocation failed!\n");
608 return -ENOMEM;
609 }
610
611 data = iio_priv(indio_dev);
612 data->client = client;
613 i2c_set_clientdata(client, indio_dev);
614 mutex_init(&data->lock);
615
616 ret = stk3310_regmap_init(data);
617 if (ret < 0)
618 return ret;
619
620 indio_dev->dev.parent = &client->dev;
621 indio_dev->info = &stk3310_info;
622 indio_dev->name = STK3310_DRIVER_NAME;
623 indio_dev->modes = INDIO_DIRECT_MODE;
624 indio_dev->channels = stk3310_channels;
625 indio_dev->num_channels = ARRAY_SIZE(stk3310_channels);
626
627 ret = stk3310_init(indio_dev);
628 if (ret < 0)
629 return ret;
630
631 if (client->irq < 0) {
632 client->irq = stk3310_gpio_probe(client);
633 if (client->irq < 0) {
634 ret = client->irq;
635 goto err_standby;
636 }
637 }
638
639 if (client->irq >= 0) {
640 ret = devm_request_threaded_irq(&client->dev, client->irq,
641 stk3310_irq_handler,
642 stk3310_irq_event_handler,
643 IRQF_TRIGGER_FALLING |
644 IRQF_ONESHOT,
645 STK3310_EVENT, indio_dev);
646 if (ret < 0) {
647 dev_err(&client->dev, "request irq %d failed\n",
648 client->irq);
649 goto err_standby;
650 }
651 }
652
653 ret = iio_device_register(indio_dev);
654 if (ret < 0) {
655 dev_err(&client->dev, "device_register failed\n");
656 goto err_standby;
657 }
658
659 return 0;
660
661 err_standby:
662 stk3310_set_state(data, STK3310_STATE_STANDBY);
663 return ret;
664 }
665
666 static int stk3310_remove(struct i2c_client *client)
667 {
668 struct iio_dev *indio_dev = i2c_get_clientdata(client);
669
670 iio_device_unregister(indio_dev);
671 return stk3310_set_state(iio_priv(indio_dev), STK3310_STATE_STANDBY);
672 }
673
674 #ifdef CONFIG_PM_SLEEP
675 static int stk3310_suspend(struct device *dev)
676 {
677 struct stk3310_data *data;
678
679 data = iio_priv(i2c_get_clientdata(to_i2c_client(dev)));
680
681 return stk3310_set_state(data, STK3310_STATE_STANDBY);
682 }
683
684 static int stk3310_resume(struct device *dev)
685 {
686 u8 state = 0;
687 struct stk3310_data *data;
688
689 data = iio_priv(i2c_get_clientdata(to_i2c_client(dev)));
690 if (data->ps_enabled)
691 state |= STK3310_STATE_EN_PS;
692 if (data->als_enabled)
693 state |= STK3310_STATE_EN_ALS;
694
695 return stk3310_set_state(data, state);
696 }
697
698 static SIMPLE_DEV_PM_OPS(stk3310_pm_ops, stk3310_suspend, stk3310_resume);
699
700 #define STK3310_PM_OPS (&stk3310_pm_ops)
701 #else
702 #define STK3310_PM_OPS NULL
703 #endif
704
705 static const struct i2c_device_id stk3310_i2c_id[] = {
706 {"STK3310", 0},
707 {"STK3311", 0},
708 {}
709 };
710 MODULE_DEVICE_TABLE(i2c, stk3310_i2c_id);
711
712 static const struct acpi_device_id stk3310_acpi_id[] = {
713 {"STK3310", 0},
714 {"STK3311", 0},
715 {}
716 };
717
718 MODULE_DEVICE_TABLE(acpi, stk3310_acpi_id);
719
720 static struct i2c_driver stk3310_driver = {
721 .driver = {
722 .name = "stk3310",
723 .pm = STK3310_PM_OPS,
724 .acpi_match_table = ACPI_PTR(stk3310_acpi_id),
725 },
726 .probe = stk3310_probe,
727 .remove = stk3310_remove,
728 .id_table = stk3310_i2c_id,
729 };
730
731 module_i2c_driver(stk3310_driver);
732
733 MODULE_AUTHOR("Tiberiu Breana <tiberiu.a.breana@intel.com>");
734 MODULE_DESCRIPTION("STK3310 Ambient Light and Proximity Sensor driver");
735 MODULE_LICENSE("GPL v2");
This page took 0.098647 seconds and 5 git commands to generate.