icp10100.c 16 KB

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