xref: /linux/drivers/iio/light/cm32181.c (revision 02cdab2a8d55c85967a4be4a084efa9641c56066)
1d2912cb1SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2971672c0SKevin Tsai /*
3971672c0SKevin Tsai  * Copyright (C) 2013 Capella Microsystems Inc.
4971672c0SKevin Tsai  * Author: Kevin Tsai <ktsai@capellamicro.com>
5971672c0SKevin Tsai  */
6971672c0SKevin Tsai 
7971672c0SKevin Tsai #include <linux/delay.h>
8971672c0SKevin Tsai #include <linux/err.h>
9971672c0SKevin Tsai #include <linux/i2c.h>
10971672c0SKevin Tsai #include <linux/mutex.h>
11971672c0SKevin Tsai #include <linux/module.h>
129065b780SJonathan Cameron #include <linux/mod_devicetable.h>
13971672c0SKevin Tsai #include <linux/interrupt.h>
14971672c0SKevin Tsai #include <linux/regulator/consumer.h>
15971672c0SKevin Tsai #include <linux/iio/iio.h>
16971672c0SKevin Tsai #include <linux/iio/sysfs.h>
17971672c0SKevin Tsai #include <linux/iio/events.h>
18971672c0SKevin Tsai #include <linux/init.h>
19971672c0SKevin Tsai 
20971672c0SKevin Tsai /* Registers Address */
21971672c0SKevin Tsai #define CM32181_REG_ADDR_CMD		0x00
223bf4a59cSHans de Goede #define CM32181_REG_ADDR_WH		0x01
233bf4a59cSHans de Goede #define CM32181_REG_ADDR_WL		0x02
243bf4a59cSHans de Goede #define CM32181_REG_ADDR_TEST		0x03
25971672c0SKevin Tsai #define CM32181_REG_ADDR_ALS		0x04
26971672c0SKevin Tsai #define CM32181_REG_ADDR_STATUS		0x06
27971672c0SKevin Tsai #define CM32181_REG_ADDR_ID		0x07
28971672c0SKevin Tsai 
29971672c0SKevin Tsai /* Number of Configurable Registers */
30971672c0SKevin Tsai #define CM32181_CONF_REG_NUM		0x01
31971672c0SKevin Tsai 
32971672c0SKevin Tsai /* CMD register */
333bf4a59cSHans de Goede #define CM32181_CMD_ALS_DISABLE		BIT(0)
343bf4a59cSHans de Goede #define CM32181_CMD_ALS_INT_EN		BIT(1)
353bf4a59cSHans de Goede #define CM32181_CMD_ALS_THRES_WINDOW	BIT(2)
363bf4a59cSHans de Goede 
373bf4a59cSHans de Goede #define CM32181_CMD_ALS_PERS_SHIFT	4
383bf4a59cSHans de Goede #define CM32181_CMD_ALS_PERS_MASK	(0x03 << CM32181_CMD_ALS_PERS_SHIFT)
393bf4a59cSHans de Goede #define CM32181_CMD_ALS_PERS_DEFAULT	(0x01 << CM32181_CMD_ALS_PERS_SHIFT)
40971672c0SKevin Tsai 
41971672c0SKevin Tsai #define CM32181_CMD_ALS_IT_SHIFT	6
42971672c0SKevin Tsai #define CM32181_CMD_ALS_IT_MASK		(0x0F << CM32181_CMD_ALS_IT_SHIFT)
43971672c0SKevin Tsai #define CM32181_CMD_ALS_IT_DEFAULT	(0x00 << CM32181_CMD_ALS_IT_SHIFT)
44971672c0SKevin Tsai 
45971672c0SKevin Tsai #define CM32181_CMD_ALS_SM_SHIFT	11
46971672c0SKevin Tsai #define CM32181_CMD_ALS_SM_MASK		(0x03 << CM32181_CMD_ALS_SM_SHIFT)
47971672c0SKevin Tsai #define CM32181_CMD_ALS_SM_DEFAULT	(0x01 << CM32181_CMD_ALS_SM_SHIFT)
48971672c0SKevin Tsai 
49971672c0SKevin Tsai #define CM32181_MLUX_PER_BIT		5	/* ALS_SM=01 IT=800ms */
50971672c0SKevin Tsai #define CM32181_MLUX_PER_BIT_BASE_IT	800000	/* Based on IT=800ms */
51971672c0SKevin Tsai #define	CM32181_CALIBSCALE_DEFAULT	1000
52971672c0SKevin Tsai #define CM32181_CALIBSCALE_RESOLUTION	1000
53971672c0SKevin Tsai #define MLUX_PER_LUX			1000
54971672c0SKevin Tsai 
55971672c0SKevin Tsai static const u8 cm32181_reg[CM32181_CONF_REG_NUM] = {
56971672c0SKevin Tsai 	CM32181_REG_ADDR_CMD,
57971672c0SKevin Tsai };
58971672c0SKevin Tsai 
59*02cdab2aSHans de Goede /* CM3218 Family */
60*02cdab2aSHans de Goede static const int cm3218_als_it_bits[] = { 0, 1, 2, 3 };
61*02cdab2aSHans de Goede static const int cm3218_als_it_values[] = { 100000, 200000, 400000, 800000 };
62*02cdab2aSHans de Goede 
63*02cdab2aSHans de Goede /* CM32181 Family */
64*02cdab2aSHans de Goede static const int cm32181_als_it_bits[] = { 12, 8, 0, 1, 2, 3 };
65*02cdab2aSHans de Goede static const int cm32181_als_it_values[] = {
66*02cdab2aSHans de Goede 	25000, 50000, 100000, 200000, 400000, 800000
67*02cdab2aSHans de Goede };
68971672c0SKevin Tsai 
69971672c0SKevin Tsai struct cm32181_chip {
70971672c0SKevin Tsai 	struct i2c_client *client;
71971672c0SKevin Tsai 	struct mutex lock;
72971672c0SKevin Tsai 	u16 conf_regs[CM32181_CONF_REG_NUM];
73971672c0SKevin Tsai 	int calibscale;
74*02cdab2aSHans de Goede 	int num_als_it;
75*02cdab2aSHans de Goede 	const int *als_it_bits;
76*02cdab2aSHans de Goede 	const int *als_it_values;
77971672c0SKevin Tsai };
78971672c0SKevin Tsai 
79971672c0SKevin Tsai /**
80971672c0SKevin Tsai  * cm32181_reg_init() - Initialize CM32181 registers
81971672c0SKevin Tsai  * @cm32181:	pointer of struct cm32181.
82971672c0SKevin Tsai  *
83971672c0SKevin Tsai  * Initialize CM32181 ambient light sensor register to default values.
84971672c0SKevin Tsai  *
85971672c0SKevin Tsai  * Return: 0 for success; otherwise for error code.
86971672c0SKevin Tsai  */
87971672c0SKevin Tsai static int cm32181_reg_init(struct cm32181_chip *cm32181)
88971672c0SKevin Tsai {
89971672c0SKevin Tsai 	struct i2c_client *client = cm32181->client;
90971672c0SKevin Tsai 	int i;
91971672c0SKevin Tsai 	s32 ret;
92971672c0SKevin Tsai 
93971672c0SKevin Tsai 	ret = i2c_smbus_read_word_data(client, CM32181_REG_ADDR_ID);
94971672c0SKevin Tsai 	if (ret < 0)
95971672c0SKevin Tsai 		return ret;
96971672c0SKevin Tsai 
97971672c0SKevin Tsai 	/* check device ID */
98*02cdab2aSHans de Goede 	switch (ret & 0xFF) {
99*02cdab2aSHans de Goede 	case 0x18: /* CM3218 */
100*02cdab2aSHans de Goede 		cm32181->num_als_it = ARRAY_SIZE(cm3218_als_it_bits);
101*02cdab2aSHans de Goede 		cm32181->als_it_bits = cm3218_als_it_bits;
102*02cdab2aSHans de Goede 		cm32181->als_it_values = cm3218_als_it_values;
103*02cdab2aSHans de Goede 		break;
104*02cdab2aSHans de Goede 	case 0x81: /* CM32181 */
105*02cdab2aSHans de Goede 	case 0x82: /* CM32182, fully compat. with CM32181 */
106*02cdab2aSHans de Goede 		cm32181->num_als_it = ARRAY_SIZE(cm32181_als_it_bits);
107*02cdab2aSHans de Goede 		cm32181->als_it_bits = cm32181_als_it_bits;
108*02cdab2aSHans de Goede 		cm32181->als_it_values = cm32181_als_it_values;
109*02cdab2aSHans de Goede 		break;
110*02cdab2aSHans de Goede 	default:
111971672c0SKevin Tsai 		return -ENODEV;
112*02cdab2aSHans de Goede 	}
113971672c0SKevin Tsai 
114971672c0SKevin Tsai 	/* Default Values */
1153bf4a59cSHans de Goede 	cm32181->conf_regs[CM32181_REG_ADDR_CMD] =
116971672c0SKevin Tsai 			CM32181_CMD_ALS_IT_DEFAULT | CM32181_CMD_ALS_SM_DEFAULT;
117971672c0SKevin Tsai 	cm32181->calibscale = CM32181_CALIBSCALE_DEFAULT;
118971672c0SKevin Tsai 
119971672c0SKevin Tsai 	/* Initialize registers*/
120971672c0SKevin Tsai 	for (i = 0; i < CM32181_CONF_REG_NUM; i++) {
121971672c0SKevin Tsai 		ret = i2c_smbus_write_word_data(client, cm32181_reg[i],
122971672c0SKevin Tsai 			cm32181->conf_regs[i]);
123971672c0SKevin Tsai 		if (ret < 0)
124971672c0SKevin Tsai 			return ret;
125971672c0SKevin Tsai 	}
126971672c0SKevin Tsai 
127971672c0SKevin Tsai 	return 0;
128971672c0SKevin Tsai }
129971672c0SKevin Tsai 
130971672c0SKevin Tsai /**
131971672c0SKevin Tsai  *  cm32181_read_als_it() - Get sensor integration time (ms)
132971672c0SKevin Tsai  *  @cm32181:	pointer of struct cm32181
1331463a166SBeomho Seo  *  @val2:	pointer of int to load the als_it value.
134971672c0SKevin Tsai  *
135971672c0SKevin Tsai  *  Report the current integartion time by millisecond.
136971672c0SKevin Tsai  *
1371463a166SBeomho Seo  *  Return: IIO_VAL_INT_PLUS_MICRO for success, otherwise -EINVAL.
138971672c0SKevin Tsai  */
1391463a166SBeomho Seo static int cm32181_read_als_it(struct cm32181_chip *cm32181, int *val2)
140971672c0SKevin Tsai {
141971672c0SKevin Tsai 	u16 als_it;
142971672c0SKevin Tsai 	int i;
143971672c0SKevin Tsai 
144971672c0SKevin Tsai 	als_it = cm32181->conf_regs[CM32181_REG_ADDR_CMD];
145971672c0SKevin Tsai 	als_it &= CM32181_CMD_ALS_IT_MASK;
146971672c0SKevin Tsai 	als_it >>= CM32181_CMD_ALS_IT_SHIFT;
147*02cdab2aSHans de Goede 	for (i = 0; i < cm32181->num_als_it; i++) {
148*02cdab2aSHans de Goede 		if (als_it == cm32181->als_it_bits[i]) {
149*02cdab2aSHans de Goede 			*val2 = cm32181->als_it_values[i];
1501463a166SBeomho Seo 			return IIO_VAL_INT_PLUS_MICRO;
151971672c0SKevin Tsai 		}
152971672c0SKevin Tsai 	}
153971672c0SKevin Tsai 
154971672c0SKevin Tsai 	return -EINVAL;
155971672c0SKevin Tsai }
156971672c0SKevin Tsai 
157971672c0SKevin Tsai /**
158971672c0SKevin Tsai  * cm32181_write_als_it() - Write sensor integration time
159971672c0SKevin Tsai  * @cm32181:	pointer of struct cm32181.
160971672c0SKevin Tsai  * @val:	integration time by millisecond.
161971672c0SKevin Tsai  *
162971672c0SKevin Tsai  * Convert integration time (ms) to sensor value.
163971672c0SKevin Tsai  *
164971672c0SKevin Tsai  * Return: i2c_smbus_write_word_data command return value.
165971672c0SKevin Tsai  */
166971672c0SKevin Tsai static int cm32181_write_als_it(struct cm32181_chip *cm32181, int val)
167971672c0SKevin Tsai {
168971672c0SKevin Tsai 	struct i2c_client *client = cm32181->client;
169971672c0SKevin Tsai 	u16 als_it;
170971672c0SKevin Tsai 	int ret, i, n;
171971672c0SKevin Tsai 
172*02cdab2aSHans de Goede 	n = cm32181->num_als_it;
173971672c0SKevin Tsai 	for (i = 0; i < n; i++)
174*02cdab2aSHans de Goede 		if (val <= cm32181->als_it_values[i])
175971672c0SKevin Tsai 			break;
176971672c0SKevin Tsai 	if (i >= n)
177971672c0SKevin Tsai 		i = n - 1;
178971672c0SKevin Tsai 
179*02cdab2aSHans de Goede 	als_it = cm32181->als_it_bits[i];
180971672c0SKevin Tsai 	als_it <<= CM32181_CMD_ALS_IT_SHIFT;
181971672c0SKevin Tsai 
182971672c0SKevin Tsai 	mutex_lock(&cm32181->lock);
183971672c0SKevin Tsai 	cm32181->conf_regs[CM32181_REG_ADDR_CMD] &=
184971672c0SKevin Tsai 		~CM32181_CMD_ALS_IT_MASK;
185971672c0SKevin Tsai 	cm32181->conf_regs[CM32181_REG_ADDR_CMD] |=
186971672c0SKevin Tsai 		als_it;
187971672c0SKevin Tsai 	ret = i2c_smbus_write_word_data(client, CM32181_REG_ADDR_CMD,
188971672c0SKevin Tsai 			cm32181->conf_regs[CM32181_REG_ADDR_CMD]);
189971672c0SKevin Tsai 	mutex_unlock(&cm32181->lock);
190971672c0SKevin Tsai 
191971672c0SKevin Tsai 	return ret;
192971672c0SKevin Tsai }
193971672c0SKevin Tsai 
194971672c0SKevin Tsai /**
195971672c0SKevin Tsai  * cm32181_get_lux() - report current lux value
196971672c0SKevin Tsai  * @cm32181:	pointer of struct cm32181.
197971672c0SKevin Tsai  *
198971672c0SKevin Tsai  * Convert sensor raw data to lux.  It depends on integration
199a86ea557SRoberta Dobrescu  * time and calibscale variable.
200971672c0SKevin Tsai  *
201971672c0SKevin Tsai  * Return: Positive value is lux, otherwise is error code.
202971672c0SKevin Tsai  */
203971672c0SKevin Tsai static int cm32181_get_lux(struct cm32181_chip *cm32181)
204971672c0SKevin Tsai {
205971672c0SKevin Tsai 	struct i2c_client *client = cm32181->client;
206971672c0SKevin Tsai 	int ret;
207971672c0SKevin Tsai 	int als_it;
208971672c0SKevin Tsai 	unsigned long lux;
209971672c0SKevin Tsai 
210971672c0SKevin Tsai 	ret = cm32181_read_als_it(cm32181, &als_it);
211971672c0SKevin Tsai 	if (ret < 0)
212971672c0SKevin Tsai 		return -EINVAL;
213971672c0SKevin Tsai 
214971672c0SKevin Tsai 	lux = CM32181_MLUX_PER_BIT;
215971672c0SKevin Tsai 	lux *= CM32181_MLUX_PER_BIT_BASE_IT;
216971672c0SKevin Tsai 	lux /= als_it;
217971672c0SKevin Tsai 
218971672c0SKevin Tsai 	ret = i2c_smbus_read_word_data(client, CM32181_REG_ADDR_ALS);
219971672c0SKevin Tsai 	if (ret < 0)
220971672c0SKevin Tsai 		return ret;
221971672c0SKevin Tsai 
222971672c0SKevin Tsai 	lux *= ret;
223971672c0SKevin Tsai 	lux *= cm32181->calibscale;
224971672c0SKevin Tsai 	lux /= CM32181_CALIBSCALE_RESOLUTION;
225971672c0SKevin Tsai 	lux /= MLUX_PER_LUX;
226971672c0SKevin Tsai 
227971672c0SKevin Tsai 	if (lux > 0xFFFF)
228971672c0SKevin Tsai 		lux = 0xFFFF;
229971672c0SKevin Tsai 
230971672c0SKevin Tsai 	return lux;
231971672c0SKevin Tsai }
232971672c0SKevin Tsai 
233971672c0SKevin Tsai static int cm32181_read_raw(struct iio_dev *indio_dev,
234971672c0SKevin Tsai 			    struct iio_chan_spec const *chan,
235971672c0SKevin Tsai 			    int *val, int *val2, long mask)
236971672c0SKevin Tsai {
237971672c0SKevin Tsai 	struct cm32181_chip *cm32181 = iio_priv(indio_dev);
238971672c0SKevin Tsai 	int ret;
239971672c0SKevin Tsai 
240971672c0SKevin Tsai 	switch (mask) {
241971672c0SKevin Tsai 	case IIO_CHAN_INFO_PROCESSED:
242971672c0SKevin Tsai 		ret = cm32181_get_lux(cm32181);
243971672c0SKevin Tsai 		if (ret < 0)
244971672c0SKevin Tsai 			return ret;
245971672c0SKevin Tsai 		*val = ret;
246971672c0SKevin Tsai 		return IIO_VAL_INT;
247971672c0SKevin Tsai 	case IIO_CHAN_INFO_CALIBSCALE:
248971672c0SKevin Tsai 		*val = cm32181->calibscale;
249971672c0SKevin Tsai 		return IIO_VAL_INT;
250971672c0SKevin Tsai 	case IIO_CHAN_INFO_INT_TIME:
25141c897f8SBeomho Seo 		*val = 0;
2521463a166SBeomho Seo 		ret = cm32181_read_als_it(cm32181, val2);
253971672c0SKevin Tsai 		return ret;
254971672c0SKevin Tsai 	}
255971672c0SKevin Tsai 
256971672c0SKevin Tsai 	return -EINVAL;
257971672c0SKevin Tsai }
258971672c0SKevin Tsai 
259971672c0SKevin Tsai static int cm32181_write_raw(struct iio_dev *indio_dev,
260971672c0SKevin Tsai 			     struct iio_chan_spec const *chan,
261971672c0SKevin Tsai 			     int val, int val2, long mask)
262971672c0SKevin Tsai {
263971672c0SKevin Tsai 	struct cm32181_chip *cm32181 = iio_priv(indio_dev);
264971672c0SKevin Tsai 	int ret;
265971672c0SKevin Tsai 
266971672c0SKevin Tsai 	switch (mask) {
267971672c0SKevin Tsai 	case IIO_CHAN_INFO_CALIBSCALE:
268971672c0SKevin Tsai 		cm32181->calibscale = val;
269971672c0SKevin Tsai 		return val;
270971672c0SKevin Tsai 	case IIO_CHAN_INFO_INT_TIME:
2711463a166SBeomho Seo 		ret = cm32181_write_als_it(cm32181, val2);
272971672c0SKevin Tsai 		return ret;
273971672c0SKevin Tsai 	}
274971672c0SKevin Tsai 
275971672c0SKevin Tsai 	return -EINVAL;
276971672c0SKevin Tsai }
277971672c0SKevin Tsai 
278971672c0SKevin Tsai /**
279971672c0SKevin Tsai  * cm32181_get_it_available() - Get available ALS IT value
280971672c0SKevin Tsai  * @dev:	pointer of struct device.
281971672c0SKevin Tsai  * @attr:	pointer of struct device_attribute.
282971672c0SKevin Tsai  * @buf:	pointer of return string buffer.
283971672c0SKevin Tsai  *
284971672c0SKevin Tsai  * Display the available integration time values by millisecond.
285971672c0SKevin Tsai  *
286971672c0SKevin Tsai  * Return: string length.
287971672c0SKevin Tsai  */
288971672c0SKevin Tsai static ssize_t cm32181_get_it_available(struct device *dev,
289971672c0SKevin Tsai 			struct device_attribute *attr, char *buf)
290971672c0SKevin Tsai {
291*02cdab2aSHans de Goede 	struct cm32181_chip *cm32181 = iio_priv(dev_to_iio_dev(dev));
292971672c0SKevin Tsai 	int i, n, len;
293971672c0SKevin Tsai 
294*02cdab2aSHans de Goede 	n = cm32181->num_als_it;
295971672c0SKevin Tsai 	for (i = 0, len = 0; i < n; i++)
296*02cdab2aSHans de Goede 		len += sprintf(buf + len, "0.%06u ", cm32181->als_it_values[i]);
297971672c0SKevin Tsai 	return len + sprintf(buf + len, "\n");
298971672c0SKevin Tsai }
299971672c0SKevin Tsai 
300971672c0SKevin Tsai static const struct iio_chan_spec cm32181_channels[] = {
301971672c0SKevin Tsai 	{
302971672c0SKevin Tsai 		.type = IIO_LIGHT,
303971672c0SKevin Tsai 		.info_mask_separate =
304971672c0SKevin Tsai 			BIT(IIO_CHAN_INFO_PROCESSED) |
305971672c0SKevin Tsai 			BIT(IIO_CHAN_INFO_CALIBSCALE) |
306971672c0SKevin Tsai 			BIT(IIO_CHAN_INFO_INT_TIME),
307971672c0SKevin Tsai 	}
308971672c0SKevin Tsai };
309971672c0SKevin Tsai 
310971672c0SKevin Tsai static IIO_DEVICE_ATTR(in_illuminance_integration_time_available,
311971672c0SKevin Tsai 			S_IRUGO, cm32181_get_it_available, NULL, 0);
312971672c0SKevin Tsai 
313971672c0SKevin Tsai static struct attribute *cm32181_attributes[] = {
314971672c0SKevin Tsai 	&iio_dev_attr_in_illuminance_integration_time_available.dev_attr.attr,
315971672c0SKevin Tsai 	NULL,
316971672c0SKevin Tsai };
317971672c0SKevin Tsai 
318971672c0SKevin Tsai static const struct attribute_group cm32181_attribute_group = {
319971672c0SKevin Tsai 	.attrs = cm32181_attributes
320971672c0SKevin Tsai };
321971672c0SKevin Tsai 
322971672c0SKevin Tsai static const struct iio_info cm32181_info = {
323971672c0SKevin Tsai 	.read_raw		= &cm32181_read_raw,
324971672c0SKevin Tsai 	.write_raw		= &cm32181_write_raw,
325971672c0SKevin Tsai 	.attrs			= &cm32181_attribute_group,
326971672c0SKevin Tsai };
327971672c0SKevin Tsai 
32806770454SHans de Goede static int cm32181_probe(struct i2c_client *client)
329971672c0SKevin Tsai {
330971672c0SKevin Tsai 	struct cm32181_chip *cm32181;
331971672c0SKevin Tsai 	struct iio_dev *indio_dev;
332971672c0SKevin Tsai 	int ret;
333971672c0SKevin Tsai 
334971672c0SKevin Tsai 	indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*cm32181));
335971672c0SKevin Tsai 	if (!indio_dev) {
336971672c0SKevin Tsai 		dev_err(&client->dev, "devm_iio_device_alloc failed\n");
337971672c0SKevin Tsai 		return -ENOMEM;
338971672c0SKevin Tsai 	}
339971672c0SKevin Tsai 
340971672c0SKevin Tsai 	cm32181 = iio_priv(indio_dev);
341971672c0SKevin Tsai 	i2c_set_clientdata(client, indio_dev);
342971672c0SKevin Tsai 	cm32181->client = client;
343971672c0SKevin Tsai 
344971672c0SKevin Tsai 	mutex_init(&cm32181->lock);
345971672c0SKevin Tsai 	indio_dev->dev.parent = &client->dev;
346971672c0SKevin Tsai 	indio_dev->channels = cm32181_channels;
347971672c0SKevin Tsai 	indio_dev->num_channels = ARRAY_SIZE(cm32181_channels);
348971672c0SKevin Tsai 	indio_dev->info = &cm32181_info;
34906770454SHans de Goede 	indio_dev->name = dev_name(&client->dev);
350971672c0SKevin Tsai 	indio_dev->modes = INDIO_DIRECT_MODE;
351971672c0SKevin Tsai 
352971672c0SKevin Tsai 	ret = cm32181_reg_init(cm32181);
353971672c0SKevin Tsai 	if (ret) {
354971672c0SKevin Tsai 		dev_err(&client->dev,
355971672c0SKevin Tsai 			"%s: register init failed\n",
356971672c0SKevin Tsai 			__func__);
357971672c0SKevin Tsai 		return ret;
358971672c0SKevin Tsai 	}
359971672c0SKevin Tsai 
360b9785535SBeomho Seo 	ret = devm_iio_device_register(&client->dev, indio_dev);
361971672c0SKevin Tsai 	if (ret) {
362971672c0SKevin Tsai 		dev_err(&client->dev,
363971672c0SKevin Tsai 			"%s: regist device failed\n",
364971672c0SKevin Tsai 			__func__);
365971672c0SKevin Tsai 		return ret;
366971672c0SKevin Tsai 	}
367971672c0SKevin Tsai 
368971672c0SKevin Tsai 	return 0;
369971672c0SKevin Tsai }
370971672c0SKevin Tsai 
371971672c0SKevin Tsai static const struct of_device_id cm32181_of_match[] = {
372*02cdab2aSHans de Goede 	{ .compatible = "capella,cm3218" },
373971672c0SKevin Tsai 	{ .compatible = "capella,cm32181" },
374971672c0SKevin Tsai 	{ }
375971672c0SKevin Tsai };
376119c4fceSJavier Martinez Canillas MODULE_DEVICE_TABLE(of, cm32181_of_match);
377971672c0SKevin Tsai 
37844b9409cSHans de Goede #ifdef CONFIG_ACPI
37944b9409cSHans de Goede static const struct acpi_device_id cm32181_acpi_match[] = {
38044b9409cSHans de Goede 	{ "CPLM3218", 0 },
38144b9409cSHans de Goede 	{ }
38244b9409cSHans de Goede };
38344b9409cSHans de Goede MODULE_DEVICE_TABLE(acpi, cm32181_acpi_match);
38444b9409cSHans de Goede #endif
38544b9409cSHans de Goede 
386971672c0SKevin Tsai static struct i2c_driver cm32181_driver = {
387971672c0SKevin Tsai 	.driver = {
388971672c0SKevin Tsai 		.name	= "cm32181",
38944b9409cSHans de Goede 		.acpi_match_table = ACPI_PTR(cm32181_acpi_match),
3909065b780SJonathan Cameron 		.of_match_table = cm32181_of_match,
391971672c0SKevin Tsai 	},
39206770454SHans de Goede 	.probe_new	= cm32181_probe,
393971672c0SKevin Tsai };
394971672c0SKevin Tsai 
395971672c0SKevin Tsai module_i2c_driver(cm32181_driver);
396971672c0SKevin Tsai 
397971672c0SKevin Tsai MODULE_AUTHOR("Kevin Tsai <ktsai@capellamicro.com>");
398971672c0SKevin Tsai MODULE_DESCRIPTION("CM32181 ambient light sensor driver");
399971672c0SKevin Tsai MODULE_LICENSE("GPL");
400