1 // SPDX-License-Identifier: GPL-2.0-only
3 * Support for AMS AS73211 JENCOLOR(R) Digital XYZ Sensor
5 * Author: Christian Eggers <ceggers@arri.de>
7 * Copyright (c) 2020 ARRI Lighting
9 * Color light sensor with 16-bit channels for x, y, z and temperature);
10 * 7-bit I2C slave address 0x74 .. 0x77.
12 * Datasheet: https://ams.com/documents/20143/36005/AS73211_DS000556_3-01.pdf
15 #include <linux/bitfield.h>
16 #include <linux/completion.h>
17 #include <linux/delay.h>
18 #include <linux/i2c.h>
19 #include <linux/iio/buffer.h>
20 #include <linux/iio/iio.h>
21 #include <linux/iio/sysfs.h>
22 #include <linux/iio/trigger_consumer.h>
23 #include <linux/iio/triggered_buffer.h>
24 #include <linux/module.h>
25 #include <linux/mutex.h>
27 #include <linux/units.h>
29 #define AS73211_DRV_NAME "as73211"
31 /* AS73211 configuration registers */
32 #define AS73211_REG_OSR 0x0
33 #define AS73211_REG_AGEN 0x2
34 #define AS73211_REG_CREG1 0x6
35 #define AS73211_REG_CREG2 0x7
36 #define AS73211_REG_CREG3 0x8
38 /* AS73211 output register bank */
39 #define AS73211_OUT_OSR_STATUS 0
40 #define AS73211_OUT_TEMP 1
41 #define AS73211_OUT_MRES1 2
42 #define AS73211_OUT_MRES2 3
43 #define AS73211_OUT_MRES3 4
45 #define AS73211_OSR_SS BIT(7)
46 #define AS73211_OSR_PD BIT(6)
47 #define AS73211_OSR_SW_RES BIT(3)
48 #define AS73211_OSR_DOS_MASK GENMASK(2, 0)
49 #define AS73211_OSR_DOS_CONFIG FIELD_PREP(AS73211_OSR_DOS_MASK, 0x2)
50 #define AS73211_OSR_DOS_MEASURE FIELD_PREP(AS73211_OSR_DOS_MASK, 0x3)
52 #define AS73211_AGEN_DEVID_MASK GENMASK(7, 4)
53 #define AS73211_AGEN_DEVID(x) FIELD_PREP(AS73211_AGEN_DEVID_MASK, (x))
54 #define AS73211_AGEN_MUT_MASK GENMASK(3, 0)
55 #define AS73211_AGEN_MUT(x) FIELD_PREP(AS73211_AGEN_MUT_MASK, (x))
57 #define AS73211_CREG1_GAIN_MASK GENMASK(7, 4)
58 #define AS73211_CREG1_GAIN_1 11
59 #define AS73211_CREG1_TIME_MASK GENMASK(3, 0)
61 #define AS73211_CREG3_CCLK_MASK GENMASK(1, 0)
63 #define AS73211_OSR_STATUS_OUTCONVOF BIT(15)
64 #define AS73211_OSR_STATUS_MRESOF BIT(14)
65 #define AS73211_OSR_STATUS_ADCOF BIT(13)
66 #define AS73211_OSR_STATUS_LDATA BIT(12)
67 #define AS73211_OSR_STATUS_NDATA BIT(11)
68 #define AS73211_OSR_STATUS_NOTREADY BIT(10)
70 #define AS73211_SAMPLE_FREQ_BASE 1024000
72 #define AS73211_SAMPLE_TIME_NUM 15
73 #define AS73211_SAMPLE_TIME_MAX_MS BIT(AS73211_SAMPLE_TIME_NUM - 1)
75 /* Available sample frequencies are 1.024MHz multiplied by powers of two. */
76 static const int as73211_samp_freq_avail[] = {
77 AS73211_SAMPLE_FREQ_BASE * 1,
78 AS73211_SAMPLE_FREQ_BASE * 2,
79 AS73211_SAMPLE_FREQ_BASE * 4,
80 AS73211_SAMPLE_FREQ_BASE * 8,
83 static const int as73211_hardwaregain_avail[] = {
84 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048,
88 * struct as73211_data - Instance data for one AS73211
89 * @client: I2C client.
90 * @osr: Cached Operational State Register.
91 * @creg1: Cached Configuration Register 1.
92 * @creg2: Cached Configuration Register 2.
93 * @creg3: Cached Configuration Register 3.
94 * @mutex: Keeps cached registers in sync with the device.
95 * @completion: Completion to wait for interrupt.
96 * @int_time_avail: Available integration times (depend on sampling frequency).
99 struct i2c_client *client;
105 struct completion completion;
106 int int_time_avail[AS73211_SAMPLE_TIME_NUM * 2];
109 #define AS73211_COLOR_CHANNEL(_color, _si, _addr) { \
110 .type = IIO_INTENSITY, \
112 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), \
113 .info_mask_shared_by_type = \
114 BIT(IIO_CHAN_INFO_SAMP_FREQ) | \
115 BIT(IIO_CHAN_INFO_HARDWAREGAIN) | \
116 BIT(IIO_CHAN_INFO_INT_TIME), \
117 .info_mask_shared_by_type_available = \
118 BIT(IIO_CHAN_INFO_SAMP_FREQ) | \
119 BIT(IIO_CHAN_INFO_HARDWAREGAIN) | \
120 BIT(IIO_CHAN_INFO_INT_TIME), \
121 .channel2 = IIO_MOD_##_color, \
128 .endianness = IIO_LE, \
132 #define AS73211_OFFSET_TEMP_INT (-66)
133 #define AS73211_OFFSET_TEMP_MICRO 900000
134 #define AS73211_SCALE_TEMP_INT 0
135 #define AS73211_SCALE_TEMP_MICRO 50000
137 #define AS73211_SCALE_X 277071108 /* nW/m^2 */
138 #define AS73211_SCALE_Y 298384270 /* nW/m^2 */
139 #define AS73211_SCALE_Z 160241927 /* nW/m^2 */
141 /* Channel order MUST match devices result register order */
142 #define AS73211_SCAN_INDEX_TEMP 0
143 #define AS73211_SCAN_INDEX_X 1
144 #define AS73211_SCAN_INDEX_Y 2
145 #define AS73211_SCAN_INDEX_Z 3
146 #define AS73211_SCAN_INDEX_TS 4
148 #define AS73211_SCAN_MASK_COLOR ( \
149 BIT(AS73211_SCAN_INDEX_X) | \
150 BIT(AS73211_SCAN_INDEX_Y) | \
151 BIT(AS73211_SCAN_INDEX_Z))
153 #define AS73211_SCAN_MASK_ALL ( \
154 BIT(AS73211_SCAN_INDEX_TEMP) | \
155 AS73211_SCAN_MASK_COLOR)
157 static const struct iio_chan_spec as73211_channels[] = {
160 .info_mask_separate =
161 BIT(IIO_CHAN_INFO_RAW) |
162 BIT(IIO_CHAN_INFO_OFFSET) |
163 BIT(IIO_CHAN_INFO_SCALE),
164 .address = AS73211_OUT_TEMP,
165 .scan_index = AS73211_SCAN_INDEX_TEMP,
170 .endianness = IIO_LE,
173 AS73211_COLOR_CHANNEL(X, AS73211_SCAN_INDEX_X, AS73211_OUT_MRES1),
174 AS73211_COLOR_CHANNEL(Y, AS73211_SCAN_INDEX_Y, AS73211_OUT_MRES2),
175 AS73211_COLOR_CHANNEL(Z, AS73211_SCAN_INDEX_Z, AS73211_OUT_MRES3),
176 IIO_CHAN_SOFT_TIMESTAMP(AS73211_SCAN_INDEX_TS),
179 static unsigned int as73211_integration_time_1024cyc(struct as73211_data *data)
182 * Return integration time in units of 1024 clock cycles. Integration time
183 * in CREG1 is in powers of 2 (x 1024 cycles).
185 return BIT(FIELD_GET(AS73211_CREG1_TIME_MASK, data->creg1));
188 static unsigned int as73211_integration_time_us(struct as73211_data *data,
189 unsigned int integration_time_1024cyc)
192 * f_samp is configured in CREG3 in powers of 2 (x 1.024 MHz)
193 * t_cycl is configured in CREG1 in powers of 2 (x 1024 cycles)
194 * t_int_us = 1 / (f_samp) * t_cycl * US_PER_SEC
195 * = 1 / (2^CREG3_CCLK * 1,024,000) * 2^CREG1_CYCLES * 1,024 * US_PER_SEC
196 * = 2^(-CREG3_CCLK) * 2^CREG1_CYCLES * 1,000
197 * In order to get rid of negative exponents, we extend the "fraction"
198 * by 2^3 (CREG3_CCLK,max = 3)
199 * t_int_us = 2^(3-CREG3_CCLK) * 2^CREG1_CYCLES * 125
201 return BIT(3 - FIELD_GET(AS73211_CREG3_CCLK_MASK, data->creg3)) *
202 integration_time_1024cyc * 125;
205 static void as73211_integration_time_calc_avail(struct as73211_data *data)
209 for (i = 0; i < ARRAY_SIZE(data->int_time_avail) / 2; i++) {
210 unsigned int time_us = as73211_integration_time_us(data, BIT(i));
212 data->int_time_avail[i * 2 + 0] = time_us / USEC_PER_SEC;
213 data->int_time_avail[i * 2 + 1] = time_us % USEC_PER_SEC;
217 static unsigned int as73211_gain(struct as73211_data *data)
219 /* gain can be calculated from CREG1 as 2^(11 - CREG1_GAIN) */
220 return BIT(AS73211_CREG1_GAIN_1 - FIELD_GET(AS73211_CREG1_GAIN_MASK, data->creg1));
223 /* must be called with as73211_data::mutex held. */
224 static int as73211_req_data(struct as73211_data *data)
226 unsigned int time_us = as73211_integration_time_us(data,
227 as73211_integration_time_1024cyc(data));
228 struct device *dev = &data->client->dev;
229 union i2c_smbus_data smbus_data;
233 if (data->client->irq)
234 reinit_completion(&data->completion);
237 * During measurement, there should be no traffic on the i2c bus as the
238 * electrical noise would disturb the measurement process.
240 i2c_lock_bus(data->client->adapter, I2C_LOCK_SEGMENT);
242 data->osr &= ~AS73211_OSR_DOS_MASK;
243 data->osr |= AS73211_OSR_DOS_MEASURE | AS73211_OSR_SS;
245 smbus_data.byte = data->osr;
246 ret = __i2c_smbus_xfer(data->client->adapter, data->client->addr,
247 data->client->flags, I2C_SMBUS_WRITE,
248 AS73211_REG_OSR, I2C_SMBUS_BYTE_DATA, &smbus_data);
250 i2c_unlock_bus(data->client->adapter, I2C_LOCK_SEGMENT);
255 * Reset AS73211_OSR_SS (is self clearing) in order to avoid unintentional
256 * triggering of further measurements later.
258 data->osr &= ~AS73211_OSR_SS;
261 * Add 33% extra margin for the timeout. fclk,min = fclk,typ - 27%.
263 time_us += time_us / 3;
264 if (data->client->irq) {
265 ret = wait_for_completion_timeout(&data->completion, usecs_to_jiffies(time_us));
267 dev_err(dev, "timeout waiting for READY IRQ\n");
268 i2c_unlock_bus(data->client->adapter, I2C_LOCK_SEGMENT);
272 /* Wait integration time */
273 usleep_range(time_us, 2 * time_us);
276 i2c_unlock_bus(data->client->adapter, I2C_LOCK_SEGMENT);
278 ret = i2c_smbus_read_word_data(data->client, AS73211_OUT_OSR_STATUS);
283 if (osr_status != (AS73211_OSR_DOS_MEASURE | AS73211_OSR_STATUS_NDATA)) {
284 if (osr_status & AS73211_OSR_SS) {
285 dev_err(dev, "%s() Measurement has not stopped\n", __func__);
288 if (osr_status & AS73211_OSR_STATUS_NOTREADY) {
289 dev_err(dev, "%s() Data is not ready\n", __func__);
292 if (!(osr_status & AS73211_OSR_STATUS_NDATA)) {
293 dev_err(dev, "%s() No new data available\n", __func__);
296 if (osr_status & AS73211_OSR_STATUS_LDATA) {
297 dev_err(dev, "%s() Result buffer overrun\n", __func__);
300 if (osr_status & AS73211_OSR_STATUS_ADCOF) {
301 dev_err(dev, "%s() ADC overflow\n", __func__);
304 if (osr_status & AS73211_OSR_STATUS_MRESOF) {
305 dev_err(dev, "%s() Measurement result overflow\n", __func__);
308 if (osr_status & AS73211_OSR_STATUS_OUTCONVOF) {
309 dev_err(dev, "%s() Timer overflow\n", __func__);
312 dev_err(dev, "%s() Unexpected status value\n", __func__);
319 static int as73211_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan,
320 int *val, int *val2, long mask)
322 struct as73211_data *data = iio_priv(indio_dev);
325 case IIO_CHAN_INFO_RAW: {
328 ret = iio_device_claim_direct_mode(indio_dev);
332 ret = as73211_req_data(data);
334 iio_device_release_direct_mode(indio_dev);
338 ret = i2c_smbus_read_word_data(data->client, chan->address);
339 iio_device_release_direct_mode(indio_dev);
346 case IIO_CHAN_INFO_OFFSET:
347 *val = AS73211_OFFSET_TEMP_INT;
348 *val2 = AS73211_OFFSET_TEMP_MICRO;
349 return IIO_VAL_INT_PLUS_MICRO;
351 case IIO_CHAN_INFO_SCALE:
352 switch (chan->type) {
354 *val = AS73211_SCALE_TEMP_INT;
355 *val2 = AS73211_SCALE_TEMP_MICRO;
356 return IIO_VAL_INT_PLUS_MICRO;
358 case IIO_INTENSITY: {
361 switch (chan->channel2) {
363 scale = AS73211_SCALE_X;
366 scale = AS73211_SCALE_Y;
369 scale = AS73211_SCALE_Z;
374 scale /= as73211_gain(data);
375 scale /= as73211_integration_time_1024cyc(data);
383 case IIO_CHAN_INFO_SAMP_FREQ:
384 /* f_samp is configured in CREG3 in powers of 2 (x 1.024 MHz) */
385 *val = BIT(FIELD_GET(AS73211_CREG3_CCLK_MASK, data->creg3)) *
386 AS73211_SAMPLE_FREQ_BASE;
389 case IIO_CHAN_INFO_HARDWAREGAIN:
390 *val = as73211_gain(data);
393 case IIO_CHAN_INFO_INT_TIME: {
394 unsigned int time_us;
396 mutex_lock(&data->mutex);
397 time_us = as73211_integration_time_us(data, as73211_integration_time_1024cyc(data));
398 mutex_unlock(&data->mutex);
399 *val = time_us / USEC_PER_SEC;
400 *val2 = time_us % USEC_PER_SEC;
401 return IIO_VAL_INT_PLUS_MICRO;
408 static int as73211_read_avail(struct iio_dev *indio_dev, struct iio_chan_spec const *chan,
409 const int **vals, int *type, int *length, long mask)
411 struct as73211_data *data = iio_priv(indio_dev);
414 case IIO_CHAN_INFO_SAMP_FREQ:
415 *length = ARRAY_SIZE(as73211_samp_freq_avail);
416 *vals = as73211_samp_freq_avail;
418 return IIO_AVAIL_LIST;
420 case IIO_CHAN_INFO_HARDWAREGAIN:
421 *length = ARRAY_SIZE(as73211_hardwaregain_avail);
422 *vals = as73211_hardwaregain_avail;
424 return IIO_AVAIL_LIST;
426 case IIO_CHAN_INFO_INT_TIME:
427 *length = ARRAY_SIZE(data->int_time_avail);
428 *vals = data->int_time_avail;
429 *type = IIO_VAL_INT_PLUS_MICRO;
430 return IIO_AVAIL_LIST;
437 static int _as73211_write_raw(struct iio_dev *indio_dev,
438 struct iio_chan_spec const *chan __always_unused,
439 int val, int val2, long mask)
441 struct as73211_data *data = iio_priv(indio_dev);
445 case IIO_CHAN_INFO_SAMP_FREQ: {
446 int reg_bits, freq_kHz = val / HZ_PER_KHZ; /* 1024, 2048, ... */
448 /* val must be 1024 * 2^x */
449 if (val < 0 || (freq_kHz * HZ_PER_KHZ) != val ||
450 !is_power_of_2(freq_kHz) || val2)
453 /* f_samp is configured in CREG3 in powers of 2 (x 1.024 MHz (=2^10)) */
454 reg_bits = ilog2(freq_kHz) - 10;
455 if (!FIELD_FIT(AS73211_CREG3_CCLK_MASK, reg_bits))
458 data->creg3 &= ~AS73211_CREG3_CCLK_MASK;
459 data->creg3 |= FIELD_PREP(AS73211_CREG3_CCLK_MASK, reg_bits);
460 as73211_integration_time_calc_avail(data);
462 ret = i2c_smbus_write_byte_data(data->client, AS73211_REG_CREG3, data->creg3);
468 case IIO_CHAN_INFO_HARDWAREGAIN: {
469 unsigned int reg_bits;
471 if (val < 0 || !is_power_of_2(val) || val2)
474 /* gain can be calculated from CREG1 as 2^(11 - CREG1_GAIN) */
475 reg_bits = AS73211_CREG1_GAIN_1 - ilog2(val);
476 if (!FIELD_FIT(AS73211_CREG1_GAIN_MASK, reg_bits))
479 data->creg1 &= ~AS73211_CREG1_GAIN_MASK;
480 data->creg1 |= FIELD_PREP(AS73211_CREG1_GAIN_MASK, reg_bits);
482 ret = i2c_smbus_write_byte_data(data->client, AS73211_REG_CREG1, data->creg1);
488 case IIO_CHAN_INFO_INT_TIME: {
489 int val_us = val * USEC_PER_SEC + val2;
493 /* f_samp is configured in CREG3 in powers of 2 (x 1.024 MHz) */
494 int f_samp_1_024mhz = BIT(FIELD_GET(AS73211_CREG3_CCLK_MASK, data->creg3));
497 * time_ms = time_us * US_PER_MS * f_samp_1_024mhz / MHZ_PER_HZ
498 * = time_us * f_samp_1_024mhz / 1000
500 time_ms = (val_us * f_samp_1_024mhz) / 1000; /* 1 ms, 2 ms, ... (power of two) */
501 if (time_ms < 0 || !is_power_of_2(time_ms) || time_ms > AS73211_SAMPLE_TIME_MAX_MS)
504 reg_bits = ilog2(time_ms);
505 if (!FIELD_FIT(AS73211_CREG1_TIME_MASK, reg_bits))
506 return -EINVAL; /* not possible due to previous tests */
508 data->creg1 &= ~AS73211_CREG1_TIME_MASK;
509 data->creg1 |= FIELD_PREP(AS73211_CREG1_TIME_MASK, reg_bits);
511 ret = i2c_smbus_write_byte_data(data->client, AS73211_REG_CREG1, data->creg1);
522 static int as73211_write_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan,
523 int val, int val2, long mask)
525 struct as73211_data *data = iio_priv(indio_dev);
528 mutex_lock(&data->mutex);
530 ret = iio_device_claim_direct_mode(indio_dev);
534 /* Need to switch to config mode ... */
535 if ((data->osr & AS73211_OSR_DOS_MASK) != AS73211_OSR_DOS_CONFIG) {
536 data->osr &= ~AS73211_OSR_DOS_MASK;
537 data->osr |= AS73211_OSR_DOS_CONFIG;
539 ret = i2c_smbus_write_byte_data(data->client, AS73211_REG_OSR, data->osr);
544 ret = _as73211_write_raw(indio_dev, chan, val, val2, mask);
547 iio_device_release_direct_mode(indio_dev);
549 mutex_unlock(&data->mutex);
553 static irqreturn_t as73211_ready_handler(int irq __always_unused, void *priv)
555 struct as73211_data *data = iio_priv(priv);
557 complete(&data->completion);
562 static irqreturn_t as73211_trigger_handler(int irq __always_unused, void *p)
564 struct iio_poll_func *pf = p;
565 struct iio_dev *indio_dev = pf->indio_dev;
566 struct as73211_data *data = iio_priv(indio_dev);
571 int data_result, ret;
573 mutex_lock(&data->mutex);
575 data_result = as73211_req_data(data);
576 if (data_result < 0 && data_result != -EOVERFLOW)
577 goto done; /* don't push any data for errors other than EOVERFLOW */
579 if (*indio_dev->active_scan_mask == AS73211_SCAN_MASK_ALL) {
580 /* Optimization for reading all (color + temperature) channels */
581 u8 addr = as73211_channels[0].address;
582 struct i2c_msg msgs[] = {
584 .addr = data->client->addr,
590 .addr = data->client->addr,
592 .len = sizeof(scan.chan),
593 .buf = (u8 *)&scan.chan,
597 ret = i2c_transfer(data->client->adapter, msgs, ARRAY_SIZE(msgs));
601 /* Optimization for reading only color channels */
603 /* AS73211 starts reading at address 2 */
604 ret = i2c_master_recv(data->client,
605 (char *)&scan.chan[1], 3 * sizeof(scan.chan[1]));
612 * Saturate all channels (in case of overflows). Temperature channel
613 * is not affected by overflows.
615 scan.chan[1] = cpu_to_le16(U16_MAX);
616 scan.chan[2] = cpu_to_le16(U16_MAX);
617 scan.chan[3] = cpu_to_le16(U16_MAX);
620 iio_push_to_buffers_with_timestamp(indio_dev, &scan, iio_get_time_ns(indio_dev));
623 mutex_unlock(&data->mutex);
624 iio_trigger_notify_done(indio_dev->trig);
629 static const struct iio_info as73211_info = {
630 .read_raw = as73211_read_raw,
631 .read_avail = as73211_read_avail,
632 .write_raw = as73211_write_raw,
635 static int as73211_power(struct iio_dev *indio_dev, bool state)
637 struct as73211_data *data = iio_priv(indio_dev);
640 mutex_lock(&data->mutex);
643 data->osr &= ~AS73211_OSR_PD;
645 data->osr |= AS73211_OSR_PD;
647 ret = i2c_smbus_write_byte_data(data->client, AS73211_REG_OSR, data->osr);
649 mutex_unlock(&data->mutex);
657 static void as73211_power_disable(void *data)
659 struct iio_dev *indio_dev = data;
661 as73211_power(indio_dev, false);
664 static int as73211_probe(struct i2c_client *client)
666 struct device *dev = &client->dev;
667 struct as73211_data *data;
668 struct iio_dev *indio_dev;
671 indio_dev = devm_iio_device_alloc(dev, sizeof(*data));
675 data = iio_priv(indio_dev);
676 i2c_set_clientdata(client, indio_dev);
677 data->client = client;
679 mutex_init(&data->mutex);
680 init_completion(&data->completion);
682 indio_dev->info = &as73211_info;
683 indio_dev->name = AS73211_DRV_NAME;
684 indio_dev->channels = as73211_channels;
685 indio_dev->num_channels = ARRAY_SIZE(as73211_channels);
686 indio_dev->modes = INDIO_DIRECT_MODE;
688 ret = i2c_smbus_read_byte_data(data->client, AS73211_REG_OSR);
694 data->osr |= AS73211_OSR_SW_RES;
695 ret = i2c_smbus_write_byte_data(data->client, AS73211_REG_OSR, data->osr);
699 ret = i2c_smbus_read_byte_data(data->client, AS73211_REG_OSR);
705 * Reading AGEN is only possible after reset (AGEN is not available if
706 * device is in measurement mode).
708 ret = i2c_smbus_read_byte_data(data->client, AS73211_REG_AGEN);
712 /* At the time of writing this driver, only DEVID 2 and MUT 1 are known. */
713 if ((ret & AS73211_AGEN_DEVID_MASK) != AS73211_AGEN_DEVID(2) ||
714 (ret & AS73211_AGEN_MUT_MASK) != AS73211_AGEN_MUT(1))
717 ret = i2c_smbus_read_byte_data(data->client, AS73211_REG_CREG1);
722 ret = i2c_smbus_read_byte_data(data->client, AS73211_REG_CREG2);
727 ret = i2c_smbus_read_byte_data(data->client, AS73211_REG_CREG3);
731 as73211_integration_time_calc_avail(data);
733 ret = as73211_power(indio_dev, true);
737 ret = devm_add_action_or_reset(dev, as73211_power_disable, indio_dev);
741 ret = devm_iio_triggered_buffer_setup(dev, indio_dev, NULL, as73211_trigger_handler, NULL);
746 ret = devm_request_threaded_irq(&client->dev, client->irq,
748 as73211_ready_handler,
750 client->name, indio_dev);
755 return devm_iio_device_register(dev, indio_dev);
758 static int as73211_suspend(struct device *dev)
760 struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
762 return as73211_power(indio_dev, false);
765 static int as73211_resume(struct device *dev)
767 struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
769 return as73211_power(indio_dev, true);
772 static DEFINE_SIMPLE_DEV_PM_OPS(as73211_pm_ops, as73211_suspend,
775 static const struct of_device_id as73211_of_match[] = {
776 { .compatible = "ams,as73211" },
779 MODULE_DEVICE_TABLE(of, as73211_of_match);
781 static const struct i2c_device_id as73211_id[] = {
785 MODULE_DEVICE_TABLE(i2c, as73211_id);
787 static struct i2c_driver as73211_driver = {
789 .name = AS73211_DRV_NAME,
790 .of_match_table = as73211_of_match,
791 .pm = pm_sleep_ptr(&as73211_pm_ops),
793 .probe = as73211_probe,
794 .id_table = as73211_id,
796 module_i2c_driver(as73211_driver);
798 MODULE_AUTHOR("Christian Eggers <ceggers@arri.de>");
799 MODULE_DESCRIPTION("AS73211 XYZ True Color Sensor driver");
800 MODULE_LICENSE("GPL");