xref: /linux/drivers/iio/pressure/icp10100.c (revision d2c9a99135da931377240942d44f3dea104cedb8)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (C) 2020 InvenSense, Inc.
4  *
5  * Driver for InvenSense ICP-1010xx barometric pressure and temperature sensor.
6  *
7  * Datasheet:
8  * http://www.invensense.com/wp-content/uploads/2018/01/DS-000186-ICP-101xx-v1.2.pdf
9  */
10 
11 #include <linux/device.h>
12 #include <linux/module.h>
13 #include <linux/i2c.h>
14 #include <linux/pm_runtime.h>
15 #include <linux/crc8.h>
16 #include <linux/mutex.h>
17 #include <linux/delay.h>
18 #include <linux/log2.h>
19 #include <linux/math64.h>
20 #include <linux/regulator/consumer.h>
21 #include <linux/iio/iio.h>
22 
23 #define ICP10100_ID_REG_GET(_reg)	((_reg) & 0x003F)
24 #define ICP10100_ID_REG			0x08
25 #define ICP10100_RESPONSE_WORD_LENGTH	3
26 #define ICP10100_CRC8_WORD_LENGTH	2
27 #define ICP10100_CRC8_POLYNOMIAL	0x31
28 #define ICP10100_CRC8_INIT		0xFF
29 
30 enum icp10100_mode {
31 	ICP10100_MODE_LP,	/* Low power mode: 1x sampling */
32 	ICP10100_MODE_N,	/* Normal mode: 2x sampling */
33 	ICP10100_MODE_LN,	/* Low noise mode: 4x sampling */
34 	ICP10100_MODE_ULN,	/* Ultra low noise mode: 8x sampling */
35 	ICP10100_MODE_NB,
36 };
37 
38 struct icp10100_state {
39 	struct mutex lock;
40 	struct i2c_client *client;
41 	struct regulator *vdd;
42 	enum icp10100_mode mode;
43 	int16_t cal[4];
44 };
45 
46 struct icp10100_command {
47 	__be16 cmd;
48 	unsigned long wait_us;
49 	unsigned long wait_max_us;
50 	size_t response_word_nb;
51 };
52 
53 static const struct icp10100_command icp10100_cmd_soft_reset = {
54 	.cmd = cpu_to_be16(0x805D),
55 	.wait_us = 170,
56 	.wait_max_us = 200,
57 	.response_word_nb = 0,
58 };
59 
60 static const struct icp10100_command icp10100_cmd_read_id = {
61 	.cmd = cpu_to_be16(0xEFC8),
62 	.wait_us = 0,
63 	.response_word_nb = 1,
64 };
65 
66 static const struct icp10100_command icp10100_cmd_read_otp = {
67 	.cmd = cpu_to_be16(0xC7F7),
68 	.wait_us = 0,
69 	.response_word_nb = 1,
70 };
71 
72 static const struct icp10100_command icp10100_cmd_measure[] = {
73 	[ICP10100_MODE_LP] = {
74 		.cmd = cpu_to_be16(0x401A),
75 		.wait_us = 1800,
76 		.wait_max_us = 2000,
77 		.response_word_nb = 3,
78 	},
79 	[ICP10100_MODE_N] = {
80 		.cmd = cpu_to_be16(0x48A3),
81 		.wait_us = 6300,
82 		.wait_max_us = 6500,
83 		.response_word_nb = 3,
84 	},
85 	[ICP10100_MODE_LN] = {
86 		.cmd = cpu_to_be16(0x5059),
87 		.wait_us = 23800,
88 		.wait_max_us = 24000,
89 		.response_word_nb = 3,
90 	},
91 	[ICP10100_MODE_ULN] = {
92 		.cmd = cpu_to_be16(0x58E0),
93 		.wait_us = 94500,
94 		.wait_max_us = 94700,
95 		.response_word_nb = 3,
96 	},
97 };
98 
99 static const uint8_t icp10100_switch_mode_otp[] =
100 	{0xC5, 0x95, 0x00, 0x66, 0x9c};
101 
102 DECLARE_CRC8_TABLE(icp10100_crc8_table);
103 
icp10100_i2c_xfer(struct i2c_adapter * adap,struct i2c_msg * msgs,int num)104 static inline int icp10100_i2c_xfer(struct i2c_adapter *adap,
105 				    struct i2c_msg *msgs, int num)
106 {
107 	int ret;
108 
109 	ret = i2c_transfer(adap, msgs, num);
110 	if (ret < 0)
111 		return ret;
112 
113 	if (ret != num)
114 		return -EIO;
115 
116 	return 0;
117 }
118 
icp10100_send_cmd(struct icp10100_state * st,const struct icp10100_command * cmd,__be16 * buf,size_t buf_len)119 static int icp10100_send_cmd(struct icp10100_state *st,
120 			     const struct icp10100_command *cmd,
121 			     __be16 *buf, size_t buf_len)
122 {
123 	size_t size = cmd->response_word_nb * ICP10100_RESPONSE_WORD_LENGTH;
124 	uint8_t data[16];
125 	uint8_t *ptr;
126 	uint8_t *buf_ptr = (uint8_t *)buf;
127 	struct i2c_msg msgs[2] = {
128 		{
129 			.addr = st->client->addr,
130 			.flags = 0,
131 			.len = 2,
132 			.buf = (uint8_t *)&cmd->cmd,
133 		}, {
134 			.addr = st->client->addr,
135 			.flags = I2C_M_RD,
136 			.len = size,
137 			.buf = data,
138 		},
139 	};
140 	uint8_t crc;
141 	unsigned int i;
142 	int ret;
143 
144 	if (size > sizeof(data))
145 		return -EINVAL;
146 
147 	if (cmd->response_word_nb > 0 &&
148 			(buf == NULL || buf_len < (cmd->response_word_nb * 2)))
149 		return -EINVAL;
150 
151 	dev_dbg(&st->client->dev, "sending cmd %#x\n", be16_to_cpu(cmd->cmd));
152 
153 	if (cmd->response_word_nb > 0 && cmd->wait_us == 0) {
154 		/* direct command-response without waiting */
155 		ret = icp10100_i2c_xfer(st->client->adapter, msgs,
156 					ARRAY_SIZE(msgs));
157 		if (ret)
158 			return ret;
159 	} else {
160 		/* transfer command write */
161 		ret = icp10100_i2c_xfer(st->client->adapter, &msgs[0], 1);
162 		if (ret)
163 			return ret;
164 		if (cmd->wait_us > 0)
165 			usleep_range(cmd->wait_us, cmd->wait_max_us);
166 		/* transfer response read if needed */
167 		if (cmd->response_word_nb > 0) {
168 			ret = icp10100_i2c_xfer(st->client->adapter, &msgs[1], 1);
169 			if (ret)
170 				return ret;
171 		} else {
172 			return 0;
173 		}
174 	}
175 
176 	/* process read words with crc checking */
177 	for (i = 0; i < cmd->response_word_nb; ++i) {
178 		ptr = &data[i * ICP10100_RESPONSE_WORD_LENGTH];
179 		crc = crc8(icp10100_crc8_table, ptr, ICP10100_CRC8_WORD_LENGTH,
180 			   ICP10100_CRC8_INIT);
181 		if (crc != ptr[ICP10100_CRC8_WORD_LENGTH]) {
182 			dev_err(&st->client->dev, "crc error recv=%#x calc=%#x\n",
183 				ptr[ICP10100_CRC8_WORD_LENGTH], crc);
184 			return -EIO;
185 		}
186 		*buf_ptr++ = ptr[0];
187 		*buf_ptr++ = ptr[1];
188 	}
189 
190 	return 0;
191 }
192 
icp10100_read_cal_otp(struct icp10100_state * st)193 static int icp10100_read_cal_otp(struct icp10100_state *st)
194 {
195 	__be16 val;
196 	int i;
197 	int ret;
198 
199 	/* switch into OTP read mode */
200 	ret = i2c_master_send(st->client, icp10100_switch_mode_otp,
201 			      ARRAY_SIZE(icp10100_switch_mode_otp));
202 	if (ret < 0)
203 		return ret;
204 	if (ret != ARRAY_SIZE(icp10100_switch_mode_otp))
205 		return -EIO;
206 
207 	/* read 4 calibration values */
208 	for (i = 0; i < 4; ++i) {
209 		ret = icp10100_send_cmd(st, &icp10100_cmd_read_otp,
210 					&val, sizeof(val));
211 		if (ret)
212 			return ret;
213 		st->cal[i] = be16_to_cpu(val);
214 		dev_dbg(&st->client->dev, "cal[%d] = %d\n", i, st->cal[i]);
215 	}
216 
217 	return 0;
218 }
219 
icp10100_init_chip(struct icp10100_state * st)220 static int icp10100_init_chip(struct icp10100_state *st)
221 {
222 	__be16 val;
223 	uint16_t id;
224 	int ret;
225 
226 	/* read and check id */
227 	ret = icp10100_send_cmd(st, &icp10100_cmd_read_id, &val, sizeof(val));
228 	if (ret)
229 		return ret;
230 	id = ICP10100_ID_REG_GET(be16_to_cpu(val));
231 	if (id != ICP10100_ID_REG) {
232 		dev_err(&st->client->dev, "invalid id %#x\n", id);
233 		return -ENODEV;
234 	}
235 
236 	/* read calibration data from OTP */
237 	ret = icp10100_read_cal_otp(st);
238 	if (ret)
239 		return ret;
240 
241 	/* reset chip */
242 	return icp10100_send_cmd(st, &icp10100_cmd_soft_reset, NULL, 0);
243 }
244 
icp10100_get_measures(struct icp10100_state * st,uint32_t * pressure,uint16_t * temperature)245 static int icp10100_get_measures(struct icp10100_state *st,
246 				uint32_t *pressure, uint16_t *temperature)
247 {
248 	const struct icp10100_command *cmd;
249 	__be16 measures[3];
250 	int ret;
251 
252 	ret = pm_runtime_resume_and_get(&st->client->dev);
253 	if (ret < 0)
254 		return ret;
255 
256 	mutex_lock(&st->lock);
257 	cmd = &icp10100_cmd_measure[st->mode];
258 	ret = icp10100_send_cmd(st, cmd, measures, sizeof(measures));
259 	mutex_unlock(&st->lock);
260 	if (ret)
261 		goto error_measure;
262 
263 	*pressure = (be16_to_cpu(measures[0]) << 8) |
264 			(be16_to_cpu(measures[1]) >> 8);
265 	*temperature = be16_to_cpu(measures[2]);
266 
267 error_measure:
268 	pm_runtime_put_autosuspend(&st->client->dev);
269 	return ret;
270 }
271 
icp10100_get_pressure(struct icp10100_state * st,uint32_t raw_pressure,uint16_t raw_temp)272 static uint32_t icp10100_get_pressure(struct icp10100_state *st,
273 				      uint32_t raw_pressure, uint16_t raw_temp)
274 {
275 	static int32_t p_calib[] = {45000, 80000, 105000};
276 	static int32_t lut_lower = 3670016;
277 	static int32_t lut_upper = 12058624;
278 	static int32_t inv_quadr_factor = 16777216;
279 	static int32_t offset_factor = 2048;
280 	int64_t val1, val2;
281 	int32_t p_lut[3];
282 	int32_t t, t_square;
283 	int64_t a, b, c;
284 	uint32_t pressure_mPa;
285 
286 	dev_dbg(&st->client->dev, "raw: pressure = %u, temp = %u\n",
287 		raw_pressure, raw_temp);
288 
289 	/* compute p_lut values */
290 	t = (int32_t)raw_temp - 32768;
291 	t_square = t * t;
292 	val1 = (int64_t)st->cal[0] * (int64_t)t_square;
293 	p_lut[0] = lut_lower + (int32_t)div_s64(val1, inv_quadr_factor);
294 	val1 = (int64_t)st->cal[1] * (int64_t)t_square;
295 	p_lut[1] = offset_factor * st->cal[3] +
296 			(int32_t)div_s64(val1, inv_quadr_factor);
297 	val1 = (int64_t)st->cal[2] * (int64_t)t_square;
298 	p_lut[2] = lut_upper + (int32_t)div_s64(val1, inv_quadr_factor);
299 	dev_dbg(&st->client->dev, "p_lut = [%d, %d, %d]\n",
300 		p_lut[0], p_lut[1], p_lut[2]);
301 
302 	/* compute a, b, c factors */
303 	val1 = (int64_t)p_lut[0] * (int64_t)p_lut[1] *
304 			(int64_t)(p_calib[0] - p_calib[1]) +
305 		(int64_t)p_lut[1] * (int64_t)p_lut[2] *
306 			(int64_t)(p_calib[1] - p_calib[2]) +
307 		(int64_t)p_lut[2] * (int64_t)p_lut[0] *
308 			(int64_t)(p_calib[2] - p_calib[0]);
309 	val2 = (int64_t)p_lut[2] * (int64_t)(p_calib[0] - p_calib[1]) +
310 		(int64_t)p_lut[0] * (int64_t)(p_calib[1] - p_calib[2]) +
311 		(int64_t)p_lut[1] * (int64_t)(p_calib[2] - p_calib[0]);
312 	c = div64_s64(val1, val2);
313 	dev_dbg(&st->client->dev, "val1 = %lld, val2 = %lld, c = %lld\n",
314 		val1, val2, c);
315 	val1 = (int64_t)p_calib[0] * (int64_t)p_lut[0] -
316 		(int64_t)p_calib[1] * (int64_t)p_lut[1] -
317 		(int64_t)(p_calib[1] - p_calib[0]) * c;
318 	val2 = (int64_t)p_lut[0] - (int64_t)p_lut[1];
319 	a = div64_s64(val1, val2);
320 	dev_dbg(&st->client->dev, "val1 = %lld, val2 = %lld, a = %lld\n",
321 		val1, val2, a);
322 	b = ((int64_t)p_calib[0] - a) * ((int64_t)p_lut[0] + c);
323 	dev_dbg(&st->client->dev, "b = %lld\n", b);
324 
325 	/*
326 	 * pressure_Pa = a + (b / (c + raw_pressure))
327 	 * pressure_mPa = 1000 * pressure_Pa
328 	 */
329 	pressure_mPa = 1000LL * a + div64_s64(1000LL * b, c + raw_pressure);
330 
331 	return pressure_mPa;
332 }
333 
icp10100_read_raw_measures(struct iio_dev * indio_dev,struct iio_chan_spec const * chan,int * val,int * val2)334 static int icp10100_read_raw_measures(struct iio_dev *indio_dev,
335 				      struct iio_chan_spec const *chan,
336 				      int *val, int *val2)
337 {
338 	struct icp10100_state *st = iio_priv(indio_dev);
339 	uint32_t raw_pressure;
340 	uint16_t raw_temp;
341 	uint32_t pressure_mPa;
342 	int ret;
343 
344 	if (!iio_device_claim_direct(indio_dev))
345 		return -EBUSY;
346 
347 	ret = icp10100_get_measures(st, &raw_pressure, &raw_temp);
348 	if (ret)
349 		goto error_release;
350 
351 	switch (chan->type) {
352 	case IIO_PRESSURE:
353 		pressure_mPa = icp10100_get_pressure(st, raw_pressure,
354 						     raw_temp);
355 		/* mPa to kPa */
356 		*val = pressure_mPa / 1000000;
357 		*val2 = pressure_mPa % 1000000;
358 		ret = IIO_VAL_INT_PLUS_MICRO;
359 		break;
360 	case IIO_TEMP:
361 		*val = raw_temp;
362 		ret = IIO_VAL_INT;
363 		break;
364 	default:
365 		ret = -EINVAL;
366 		break;
367 	}
368 
369 error_release:
370 	iio_device_release_direct(indio_dev);
371 	return ret;
372 }
373 
icp10100_read_raw(struct iio_dev * indio_dev,struct iio_chan_spec const * chan,int * val,int * val2,long mask)374 static int icp10100_read_raw(struct iio_dev *indio_dev,
375 			     struct iio_chan_spec const *chan,
376 			     int *val, int *val2, long mask)
377 {
378 	struct icp10100_state *st = iio_priv(indio_dev);
379 
380 	switch (mask) {
381 	case IIO_CHAN_INFO_RAW:
382 	case IIO_CHAN_INFO_PROCESSED:
383 		return icp10100_read_raw_measures(indio_dev, chan, val, val2);
384 	case IIO_CHAN_INFO_SCALE:
385 		switch (chan->type) {
386 		case IIO_TEMP:
387 			/* 1000 * 175°C / 65536 in m°C */
388 			*val = 2;
389 			*val2 = 670288;
390 			return IIO_VAL_INT_PLUS_MICRO;
391 		default:
392 			return -EINVAL;
393 		}
394 		break;
395 	case IIO_CHAN_INFO_OFFSET:
396 		switch (chan->type) {
397 		case IIO_TEMP:
398 			/* 1000 * -45°C in m°C */
399 			*val = -45000;
400 			return IIO_VAL_INT;
401 		default:
402 			return -EINVAL;
403 		}
404 		break;
405 	case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
406 		mutex_lock(&st->lock);
407 		*val = 1 << st->mode;
408 		mutex_unlock(&st->lock);
409 		return IIO_VAL_INT;
410 	default:
411 		return -EINVAL;
412 	}
413 }
414 
icp10100_read_avail(struct iio_dev * indio_dev,struct iio_chan_spec const * chan,const int ** vals,int * type,int * length,long mask)415 static int icp10100_read_avail(struct iio_dev *indio_dev,
416 			       struct iio_chan_spec const *chan,
417 			       const int **vals, int *type, int *length,
418 			       long mask)
419 {
420 	static int oversamplings[] = {1, 2, 4, 8};
421 
422 	switch (mask) {
423 	case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
424 		*vals = oversamplings;
425 		*type = IIO_VAL_INT;
426 		*length = ARRAY_SIZE(oversamplings);
427 		return IIO_AVAIL_LIST;
428 	default:
429 		return -EINVAL;
430 	}
431 }
432 
icp10100_write_raw(struct iio_dev * indio_dev,struct iio_chan_spec const * chan,int val,int val2,long mask)433 static int icp10100_write_raw(struct iio_dev *indio_dev,
434 			      struct iio_chan_spec const *chan,
435 			      int val, int val2, long mask)
436 {
437 	struct icp10100_state *st = iio_priv(indio_dev);
438 	unsigned int mode;
439 
440 	switch (mask) {
441 	case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
442 		/* oversampling is always positive and a power of 2 */
443 		if (val <= 0 || !is_power_of_2(val))
444 			return -EINVAL;
445 		mode = ilog2(val);
446 		if (mode >= ICP10100_MODE_NB)
447 			return -EINVAL;
448 		if (!iio_device_claim_direct(indio_dev))
449 			return -EBUSY;
450 		mutex_lock(&st->lock);
451 		st->mode = mode;
452 		mutex_unlock(&st->lock);
453 		iio_device_release_direct(indio_dev);
454 		return 0;
455 	default:
456 		return -EINVAL;
457 	}
458 }
459 
icp10100_write_raw_get_fmt(struct iio_dev * indio_dev,struct iio_chan_spec const * chan,long mask)460 static int icp10100_write_raw_get_fmt(struct iio_dev *indio_dev,
461 				      struct iio_chan_spec const *chan,
462 				      long mask)
463 {
464 	switch (mask) {
465 	case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
466 		return IIO_VAL_INT;
467 	default:
468 		return -EINVAL;
469 	}
470 }
471 
472 static const struct iio_info icp10100_info = {
473 	.read_raw = icp10100_read_raw,
474 	.read_avail = icp10100_read_avail,
475 	.write_raw = icp10100_write_raw,
476 	.write_raw_get_fmt = icp10100_write_raw_get_fmt,
477 };
478 
479 static const struct iio_chan_spec icp10100_channels[] = {
480 	{
481 		.type = IIO_PRESSURE,
482 		.info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
483 		.info_mask_shared_by_all =
484 			BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO),
485 		.info_mask_shared_by_all_available =
486 			BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO),
487 	}, {
488 		.type = IIO_TEMP,
489 		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
490 			BIT(IIO_CHAN_INFO_SCALE) |
491 			BIT(IIO_CHAN_INFO_OFFSET),
492 		.info_mask_shared_by_all =
493 			BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO),
494 		.info_mask_shared_by_all_available =
495 			BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO),
496 	},
497 };
498 
icp10100_enable_regulator(struct icp10100_state * st)499 static int icp10100_enable_regulator(struct icp10100_state *st)
500 {
501 	int ret;
502 
503 	ret = regulator_enable(st->vdd);
504 	if (ret)
505 		return ret;
506 	msleep(100);
507 
508 	return 0;
509 }
510 
icp10100_disable_regulator_action(void * data)511 static void icp10100_disable_regulator_action(void *data)
512 {
513 	struct icp10100_state *st = data;
514 	int ret;
515 
516 	ret = regulator_disable(st->vdd);
517 	if (ret)
518 		dev_err(&st->client->dev, "error %d disabling vdd\n", ret);
519 }
520 
icp10100_pm_disable(void * data)521 static void icp10100_pm_disable(void *data)
522 {
523 	struct device *dev = data;
524 
525 	pm_runtime_disable(dev);
526 }
527 
icp10100_probe(struct i2c_client * client)528 static int icp10100_probe(struct i2c_client *client)
529 {
530 	struct iio_dev *indio_dev;
531 	struct icp10100_state *st;
532 	int ret;
533 
534 	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
535 		dev_err(&client->dev, "plain i2c transactions not supported\n");
536 		return -ENODEV;
537 	}
538 
539 	indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*st));
540 	if (!indio_dev)
541 		return -ENOMEM;
542 
543 	i2c_set_clientdata(client, indio_dev);
544 	indio_dev->name = client->name;
545 	indio_dev->modes = INDIO_DIRECT_MODE;
546 	indio_dev->channels = icp10100_channels;
547 	indio_dev->num_channels = ARRAY_SIZE(icp10100_channels);
548 	indio_dev->info = &icp10100_info;
549 
550 	st = iio_priv(indio_dev);
551 	mutex_init(&st->lock);
552 	st->client = client;
553 	st->mode = ICP10100_MODE_N;
554 
555 	st->vdd = devm_regulator_get(&client->dev, "vdd");
556 	if (IS_ERR(st->vdd))
557 		return PTR_ERR(st->vdd);
558 
559 	ret = icp10100_enable_regulator(st);
560 	if (ret)
561 		return ret;
562 
563 	ret = devm_add_action_or_reset(&client->dev,
564 				       icp10100_disable_regulator_action, st);
565 	if (ret)
566 		return ret;
567 
568 	/* has to be done before the first i2c communication */
569 	crc8_populate_msb(icp10100_crc8_table, ICP10100_CRC8_POLYNOMIAL);
570 
571 	ret = icp10100_init_chip(st);
572 	if (ret) {
573 		dev_err(&client->dev, "init chip error %d\n", ret);
574 		return ret;
575 	}
576 
577 	/* enable runtime pm with autosuspend delay of 2s */
578 	pm_runtime_get_noresume(&client->dev);
579 	pm_runtime_set_active(&client->dev);
580 	pm_runtime_enable(&client->dev);
581 	pm_runtime_set_autosuspend_delay(&client->dev, 2000);
582 	pm_runtime_use_autosuspend(&client->dev);
583 	pm_runtime_put(&client->dev);
584 	ret = devm_add_action_or_reset(&client->dev, icp10100_pm_disable,
585 				       &client->dev);
586 	if (ret)
587 		return ret;
588 
589 	return devm_iio_device_register(&client->dev, indio_dev);
590 }
591 
icp10100_suspend(struct device * dev)592 static int icp10100_suspend(struct device *dev)
593 {
594 	struct icp10100_state *st = iio_priv(dev_get_drvdata(dev));
595 	int ret;
596 
597 	mutex_lock(&st->lock);
598 	ret = regulator_disable(st->vdd);
599 	mutex_unlock(&st->lock);
600 
601 	return ret;
602 }
603 
icp10100_resume(struct device * dev)604 static int icp10100_resume(struct device *dev)
605 {
606 	struct icp10100_state *st = iio_priv(dev_get_drvdata(dev));
607 	int ret;
608 
609 	mutex_lock(&st->lock);
610 
611 	ret = icp10100_enable_regulator(st);
612 	if (ret)
613 		goto out_unlock;
614 
615 	/* reset chip */
616 	ret = icp10100_send_cmd(st, &icp10100_cmd_soft_reset, NULL, 0);
617 
618 out_unlock:
619 	mutex_unlock(&st->lock);
620 	return ret;
621 }
622 
623 static DEFINE_RUNTIME_DEV_PM_OPS(icp10100_pm, icp10100_suspend, icp10100_resume,
624 				 NULL);
625 
626 static const struct of_device_id icp10100_of_match[] = {
627 	{
628 		.compatible = "invensense,icp10100",
629 	},
630 	{ }
631 };
632 MODULE_DEVICE_TABLE(of, icp10100_of_match);
633 
634 static const struct i2c_device_id icp10100_id[] = {
635 	{ .name = "icp10100" },
636 	{ }
637 };
638 MODULE_DEVICE_TABLE(i2c, icp10100_id);
639 
640 static struct i2c_driver icp10100_driver = {
641 	.driver = {
642 		.name = "icp10100",
643 		.pm = pm_ptr(&icp10100_pm),
644 		.of_match_table = icp10100_of_match,
645 	},
646 	.probe = icp10100_probe,
647 	.id_table = icp10100_id,
648 };
649 module_i2c_driver(icp10100_driver);
650 
651 MODULE_AUTHOR("InvenSense, Inc.");
652 MODULE_DESCRIPTION("InvenSense icp10100 driver");
653 MODULE_LICENSE("GPL");
654