bmi160_core.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  1. /*
  2. * BMI160 - Bosch IMU (accel, gyro plus external magnetometer)
  3. *
  4. * Copyright (c) 2016, 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 core driver for BMI160, with support for I2C/SPI busses
  11. *
  12. * TODO: magnetometer, interrupts, hardware FIFO
  13. */
  14. #include <linux/module.h>
  15. #include <linux/regmap.h>
  16. #include <linux/acpi.h>
  17. #include <linux/delay.h>
  18. #include <linux/iio/iio.h>
  19. #include <linux/iio/triggered_buffer.h>
  20. #include <linux/iio/trigger_consumer.h>
  21. #include <linux/iio/buffer.h>
  22. #include <linux/iio/sysfs.h>
  23. #include "bmi160.h"
  24. #define BMI160_REG_CHIP_ID 0x00
  25. #define BMI160_CHIP_ID_VAL 0xD1
  26. #define BMI160_REG_PMU_STATUS 0x03
  27. /* X axis data low byte address, the rest can be obtained using axis offset */
  28. #define BMI160_REG_DATA_MAGN_XOUT_L 0x04
  29. #define BMI160_REG_DATA_GYRO_XOUT_L 0x0C
  30. #define BMI160_REG_DATA_ACCEL_XOUT_L 0x12
  31. #define BMI160_REG_ACCEL_CONFIG 0x40
  32. #define BMI160_ACCEL_CONFIG_ODR_MASK GENMASK(3, 0)
  33. #define BMI160_ACCEL_CONFIG_BWP_MASK GENMASK(6, 4)
  34. #define BMI160_REG_ACCEL_RANGE 0x41
  35. #define BMI160_ACCEL_RANGE_2G 0x03
  36. #define BMI160_ACCEL_RANGE_4G 0x05
  37. #define BMI160_ACCEL_RANGE_8G 0x08
  38. #define BMI160_ACCEL_RANGE_16G 0x0C
  39. #define BMI160_REG_GYRO_CONFIG 0x42
  40. #define BMI160_GYRO_CONFIG_ODR_MASK GENMASK(3, 0)
  41. #define BMI160_GYRO_CONFIG_BWP_MASK GENMASK(5, 4)
  42. #define BMI160_REG_GYRO_RANGE 0x43
  43. #define BMI160_GYRO_RANGE_2000DPS 0x00
  44. #define BMI160_GYRO_RANGE_1000DPS 0x01
  45. #define BMI160_GYRO_RANGE_500DPS 0x02
  46. #define BMI160_GYRO_RANGE_250DPS 0x03
  47. #define BMI160_GYRO_RANGE_125DPS 0x04
  48. #define BMI160_REG_CMD 0x7E
  49. #define BMI160_CMD_ACCEL_PM_SUSPEND 0x10
  50. #define BMI160_CMD_ACCEL_PM_NORMAL 0x11
  51. #define BMI160_CMD_ACCEL_PM_LOW_POWER 0x12
  52. #define BMI160_CMD_GYRO_PM_SUSPEND 0x14
  53. #define BMI160_CMD_GYRO_PM_NORMAL 0x15
  54. #define BMI160_CMD_GYRO_PM_FAST_STARTUP 0x17
  55. #define BMI160_CMD_SOFTRESET 0xB6
  56. #define BMI160_REG_DUMMY 0x7F
  57. #define BMI160_ACCEL_PMU_MIN_USLEEP 3800
  58. #define BMI160_GYRO_PMU_MIN_USLEEP 80000
  59. #define BMI160_SOFTRESET_USLEEP 1000
  60. #define BMI160_CHANNEL(_type, _axis, _index) { \
  61. .type = _type, \
  62. .modified = 1, \
  63. .channel2 = IIO_MOD_##_axis, \
  64. .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
  65. .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \
  66. BIT(IIO_CHAN_INFO_SAMP_FREQ), \
  67. .scan_index = _index, \
  68. .scan_type = { \
  69. .sign = 's', \
  70. .realbits = 16, \
  71. .storagebits = 16, \
  72. .endianness = IIO_LE, \
  73. }, \
  74. }
  75. /* scan indexes follow DATA register order */
  76. enum bmi160_scan_axis {
  77. BMI160_SCAN_EXT_MAGN_X = 0,
  78. BMI160_SCAN_EXT_MAGN_Y,
  79. BMI160_SCAN_EXT_MAGN_Z,
  80. BMI160_SCAN_RHALL,
  81. BMI160_SCAN_GYRO_X,
  82. BMI160_SCAN_GYRO_Y,
  83. BMI160_SCAN_GYRO_Z,
  84. BMI160_SCAN_ACCEL_X,
  85. BMI160_SCAN_ACCEL_Y,
  86. BMI160_SCAN_ACCEL_Z,
  87. BMI160_SCAN_TIMESTAMP,
  88. };
  89. enum bmi160_sensor_type {
  90. BMI160_ACCEL = 0,
  91. BMI160_GYRO,
  92. BMI160_EXT_MAGN,
  93. BMI160_NUM_SENSORS /* must be last */
  94. };
  95. struct bmi160_data {
  96. struct regmap *regmap;
  97. };
  98. const struct regmap_config bmi160_regmap_config = {
  99. .reg_bits = 8,
  100. .val_bits = 8,
  101. };
  102. EXPORT_SYMBOL(bmi160_regmap_config);
  103. struct bmi160_regs {
  104. u8 data; /* LSB byte register for X-axis */
  105. u8 config;
  106. u8 config_odr_mask;
  107. u8 config_bwp_mask;
  108. u8 range;
  109. u8 pmu_cmd_normal;
  110. u8 pmu_cmd_suspend;
  111. };
  112. static struct bmi160_regs bmi160_regs[] = {
  113. [BMI160_ACCEL] = {
  114. .data = BMI160_REG_DATA_ACCEL_XOUT_L,
  115. .config = BMI160_REG_ACCEL_CONFIG,
  116. .config_odr_mask = BMI160_ACCEL_CONFIG_ODR_MASK,
  117. .config_bwp_mask = BMI160_ACCEL_CONFIG_BWP_MASK,
  118. .range = BMI160_REG_ACCEL_RANGE,
  119. .pmu_cmd_normal = BMI160_CMD_ACCEL_PM_NORMAL,
  120. .pmu_cmd_suspend = BMI160_CMD_ACCEL_PM_SUSPEND,
  121. },
  122. [BMI160_GYRO] = {
  123. .data = BMI160_REG_DATA_GYRO_XOUT_L,
  124. .config = BMI160_REG_GYRO_CONFIG,
  125. .config_odr_mask = BMI160_GYRO_CONFIG_ODR_MASK,
  126. .config_bwp_mask = BMI160_GYRO_CONFIG_BWP_MASK,
  127. .range = BMI160_REG_GYRO_RANGE,
  128. .pmu_cmd_normal = BMI160_CMD_GYRO_PM_NORMAL,
  129. .pmu_cmd_suspend = BMI160_CMD_GYRO_PM_SUSPEND,
  130. },
  131. };
  132. static unsigned long bmi160_pmu_time[] = {
  133. [BMI160_ACCEL] = BMI160_ACCEL_PMU_MIN_USLEEP,
  134. [BMI160_GYRO] = BMI160_GYRO_PMU_MIN_USLEEP,
  135. };
  136. struct bmi160_scale {
  137. u8 bits;
  138. int uscale;
  139. };
  140. struct bmi160_odr {
  141. u8 bits;
  142. int odr;
  143. int uodr;
  144. };
  145. static const struct bmi160_scale bmi160_accel_scale[] = {
  146. { BMI160_ACCEL_RANGE_2G, 598},
  147. { BMI160_ACCEL_RANGE_4G, 1197},
  148. { BMI160_ACCEL_RANGE_8G, 2394},
  149. { BMI160_ACCEL_RANGE_16G, 4788},
  150. };
  151. static const struct bmi160_scale bmi160_gyro_scale[] = {
  152. { BMI160_GYRO_RANGE_2000DPS, 1065},
  153. { BMI160_GYRO_RANGE_1000DPS, 532},
  154. { BMI160_GYRO_RANGE_500DPS, 266},
  155. { BMI160_GYRO_RANGE_250DPS, 133},
  156. { BMI160_GYRO_RANGE_125DPS, 66},
  157. };
  158. struct bmi160_scale_item {
  159. const struct bmi160_scale *tbl;
  160. int num;
  161. };
  162. static const struct bmi160_scale_item bmi160_scale_table[] = {
  163. [BMI160_ACCEL] = {
  164. .tbl = bmi160_accel_scale,
  165. .num = ARRAY_SIZE(bmi160_accel_scale),
  166. },
  167. [BMI160_GYRO] = {
  168. .tbl = bmi160_gyro_scale,
  169. .num = ARRAY_SIZE(bmi160_gyro_scale),
  170. },
  171. };
  172. static const struct bmi160_odr bmi160_accel_odr[] = {
  173. {0x01, 0, 781250},
  174. {0x02, 1, 562500},
  175. {0x03, 3, 125000},
  176. {0x04, 6, 250000},
  177. {0x05, 12, 500000},
  178. {0x06, 25, 0},
  179. {0x07, 50, 0},
  180. {0x08, 100, 0},
  181. {0x09, 200, 0},
  182. {0x0A, 400, 0},
  183. {0x0B, 800, 0},
  184. {0x0C, 1600, 0},
  185. };
  186. static const struct bmi160_odr bmi160_gyro_odr[] = {
  187. {0x06, 25, 0},
  188. {0x07, 50, 0},
  189. {0x08, 100, 0},
  190. {0x09, 200, 0},
  191. {0x0A, 400, 0},
  192. {0x0B, 800, 0},
  193. {0x0C, 1600, 0},
  194. {0x0D, 3200, 0},
  195. };
  196. struct bmi160_odr_item {
  197. const struct bmi160_odr *tbl;
  198. int num;
  199. };
  200. static const struct bmi160_odr_item bmi160_odr_table[] = {
  201. [BMI160_ACCEL] = {
  202. .tbl = bmi160_accel_odr,
  203. .num = ARRAY_SIZE(bmi160_accel_odr),
  204. },
  205. [BMI160_GYRO] = {
  206. .tbl = bmi160_gyro_odr,
  207. .num = ARRAY_SIZE(bmi160_gyro_odr),
  208. },
  209. };
  210. static const struct iio_chan_spec bmi160_channels[] = {
  211. BMI160_CHANNEL(IIO_ACCEL, X, BMI160_SCAN_ACCEL_X),
  212. BMI160_CHANNEL(IIO_ACCEL, Y, BMI160_SCAN_ACCEL_Y),
  213. BMI160_CHANNEL(IIO_ACCEL, Z, BMI160_SCAN_ACCEL_Z),
  214. BMI160_CHANNEL(IIO_ANGL_VEL, X, BMI160_SCAN_GYRO_X),
  215. BMI160_CHANNEL(IIO_ANGL_VEL, Y, BMI160_SCAN_GYRO_Y),
  216. BMI160_CHANNEL(IIO_ANGL_VEL, Z, BMI160_SCAN_GYRO_Z),
  217. IIO_CHAN_SOFT_TIMESTAMP(BMI160_SCAN_TIMESTAMP),
  218. };
  219. static enum bmi160_sensor_type bmi160_to_sensor(enum iio_chan_type iio_type)
  220. {
  221. switch (iio_type) {
  222. case IIO_ACCEL:
  223. return BMI160_ACCEL;
  224. case IIO_ANGL_VEL:
  225. return BMI160_GYRO;
  226. default:
  227. return -EINVAL;
  228. }
  229. }
  230. static
  231. int bmi160_set_mode(struct bmi160_data *data, enum bmi160_sensor_type t,
  232. bool mode)
  233. {
  234. int ret;
  235. u8 cmd;
  236. if (mode)
  237. cmd = bmi160_regs[t].pmu_cmd_normal;
  238. else
  239. cmd = bmi160_regs[t].pmu_cmd_suspend;
  240. ret = regmap_write(data->regmap, BMI160_REG_CMD, cmd);
  241. if (ret < 0)
  242. return ret;
  243. usleep_range(bmi160_pmu_time[t], bmi160_pmu_time[t] + 1000);
  244. return 0;
  245. }
  246. static
  247. int bmi160_set_scale(struct bmi160_data *data, enum bmi160_sensor_type t,
  248. int uscale)
  249. {
  250. int i;
  251. for (i = 0; i < bmi160_scale_table[t].num; i++)
  252. if (bmi160_scale_table[t].tbl[i].uscale == uscale)
  253. break;
  254. if (i == bmi160_scale_table[t].num)
  255. return -EINVAL;
  256. return regmap_write(data->regmap, bmi160_regs[t].range,
  257. bmi160_scale_table[t].tbl[i].bits);
  258. }
  259. static
  260. int bmi160_get_scale(struct bmi160_data *data, enum bmi160_sensor_type t,
  261. int *uscale)
  262. {
  263. int i, ret, val;
  264. ret = regmap_read(data->regmap, bmi160_regs[t].range, &val);
  265. if (ret < 0)
  266. return ret;
  267. for (i = 0; i < bmi160_scale_table[t].num; i++)
  268. if (bmi160_scale_table[t].tbl[i].bits == val) {
  269. *uscale = bmi160_scale_table[t].tbl[i].uscale;
  270. return 0;
  271. }
  272. return -EINVAL;
  273. }
  274. static int bmi160_get_data(struct bmi160_data *data, int chan_type,
  275. int axis, int *val)
  276. {
  277. u8 reg;
  278. int ret;
  279. __le16 sample;
  280. enum bmi160_sensor_type t = bmi160_to_sensor(chan_type);
  281. reg = bmi160_regs[t].data + (axis - IIO_MOD_X) * sizeof(__le16);
  282. ret = regmap_bulk_read(data->regmap, reg, &sample, sizeof(__le16));
  283. if (ret < 0)
  284. return ret;
  285. *val = sign_extend32(le16_to_cpu(sample), 15);
  286. return 0;
  287. }
  288. static
  289. int bmi160_set_odr(struct bmi160_data *data, enum bmi160_sensor_type t,
  290. int odr, int uodr)
  291. {
  292. int i;
  293. for (i = 0; i < bmi160_odr_table[t].num; i++)
  294. if (bmi160_odr_table[t].tbl[i].odr == odr &&
  295. bmi160_odr_table[t].tbl[i].uodr == uodr)
  296. break;
  297. if (i >= bmi160_odr_table[t].num)
  298. return -EINVAL;
  299. return regmap_update_bits(data->regmap,
  300. bmi160_regs[t].config,
  301. bmi160_regs[t].config_odr_mask,
  302. bmi160_odr_table[t].tbl[i].bits);
  303. }
  304. static int bmi160_get_odr(struct bmi160_data *data, enum bmi160_sensor_type t,
  305. int *odr, int *uodr)
  306. {
  307. int i, val, ret;
  308. ret = regmap_read(data->regmap, bmi160_regs[t].config, &val);
  309. if (ret < 0)
  310. return ret;
  311. val &= bmi160_regs[t].config_odr_mask;
  312. for (i = 0; i < bmi160_odr_table[t].num; i++)
  313. if (val == bmi160_odr_table[t].tbl[i].bits)
  314. break;
  315. if (i >= bmi160_odr_table[t].num)
  316. return -EINVAL;
  317. *odr = bmi160_odr_table[t].tbl[i].odr;
  318. *uodr = bmi160_odr_table[t].tbl[i].uodr;
  319. return 0;
  320. }
  321. static irqreturn_t bmi160_trigger_handler(int irq, void *p)
  322. {
  323. struct iio_poll_func *pf = p;
  324. struct iio_dev *indio_dev = pf->indio_dev;
  325. struct bmi160_data *data = iio_priv(indio_dev);
  326. s16 buf[16]; /* 3 sens x 3 axis x s16 + 3 x s16 pad + 4 x s16 tstamp */
  327. int i, ret, j = 0, base = BMI160_REG_DATA_MAGN_XOUT_L;
  328. __le16 sample;
  329. for_each_set_bit(i, indio_dev->active_scan_mask,
  330. indio_dev->masklength) {
  331. ret = regmap_bulk_read(data->regmap, base + i * sizeof(__le16),
  332. &sample, sizeof(__le16));
  333. if (ret < 0)
  334. goto done;
  335. buf[j++] = sample;
  336. }
  337. iio_push_to_buffers_with_timestamp(indio_dev, buf,
  338. iio_get_time_ns(indio_dev));
  339. done:
  340. iio_trigger_notify_done(indio_dev->trig);
  341. return IRQ_HANDLED;
  342. }
  343. static int bmi160_read_raw(struct iio_dev *indio_dev,
  344. struct iio_chan_spec const *chan,
  345. int *val, int *val2, long mask)
  346. {
  347. int ret;
  348. struct bmi160_data *data = iio_priv(indio_dev);
  349. switch (mask) {
  350. case IIO_CHAN_INFO_RAW:
  351. ret = bmi160_get_data(data, chan->type, chan->channel2, val);
  352. if (ret < 0)
  353. return ret;
  354. return IIO_VAL_INT;
  355. case IIO_CHAN_INFO_SCALE:
  356. *val = 0;
  357. ret = bmi160_get_scale(data,
  358. bmi160_to_sensor(chan->type), val2);
  359. return ret < 0 ? ret : IIO_VAL_INT_PLUS_MICRO;
  360. case IIO_CHAN_INFO_SAMP_FREQ:
  361. ret = bmi160_get_odr(data, bmi160_to_sensor(chan->type),
  362. val, val2);
  363. return ret < 0 ? ret : IIO_VAL_INT_PLUS_MICRO;
  364. default:
  365. return -EINVAL;
  366. }
  367. return 0;
  368. }
  369. static int bmi160_write_raw(struct iio_dev *indio_dev,
  370. struct iio_chan_spec const *chan,
  371. int val, int val2, long mask)
  372. {
  373. struct bmi160_data *data = iio_priv(indio_dev);
  374. switch (mask) {
  375. case IIO_CHAN_INFO_SCALE:
  376. return bmi160_set_scale(data,
  377. bmi160_to_sensor(chan->type), val2);
  378. break;
  379. case IIO_CHAN_INFO_SAMP_FREQ:
  380. return bmi160_set_odr(data, bmi160_to_sensor(chan->type),
  381. val, val2);
  382. default:
  383. return -EINVAL;
  384. }
  385. return 0;
  386. }
  387. static
  388. IIO_CONST_ATTR(in_accel_sampling_frequency_available,
  389. "0.78125 1.5625 3.125 6.25 12.5 25 50 100 200 400 800 1600");
  390. static
  391. IIO_CONST_ATTR(in_anglvel_sampling_frequency_available,
  392. "25 50 100 200 400 800 1600 3200");
  393. static
  394. IIO_CONST_ATTR(in_accel_scale_available,
  395. "0.000598 0.001197 0.002394 0.004788");
  396. static
  397. IIO_CONST_ATTR(in_anglvel_scale_available,
  398. "0.001065 0.000532 0.000266 0.000133 0.000066");
  399. static struct attribute *bmi160_attrs[] = {
  400. &iio_const_attr_in_accel_sampling_frequency_available.dev_attr.attr,
  401. &iio_const_attr_in_anglvel_sampling_frequency_available.dev_attr.attr,
  402. &iio_const_attr_in_accel_scale_available.dev_attr.attr,
  403. &iio_const_attr_in_anglvel_scale_available.dev_attr.attr,
  404. NULL,
  405. };
  406. static const struct attribute_group bmi160_attrs_group = {
  407. .attrs = bmi160_attrs,
  408. };
  409. static const struct iio_info bmi160_info = {
  410. .driver_module = THIS_MODULE,
  411. .read_raw = bmi160_read_raw,
  412. .write_raw = bmi160_write_raw,
  413. .attrs = &bmi160_attrs_group,
  414. };
  415. static const char *bmi160_match_acpi_device(struct device *dev)
  416. {
  417. const struct acpi_device_id *id;
  418. id = acpi_match_device(dev->driver->acpi_match_table, dev);
  419. if (!id)
  420. return NULL;
  421. return dev_name(dev);
  422. }
  423. static int bmi160_chip_init(struct bmi160_data *data, bool use_spi)
  424. {
  425. int ret;
  426. unsigned int val;
  427. struct device *dev = regmap_get_device(data->regmap);
  428. ret = regmap_write(data->regmap, BMI160_REG_CMD, BMI160_CMD_SOFTRESET);
  429. if (ret < 0)
  430. return ret;
  431. usleep_range(BMI160_SOFTRESET_USLEEP, BMI160_SOFTRESET_USLEEP + 1);
  432. /*
  433. * CS rising edge is needed before starting SPI, so do a dummy read
  434. * See Section 3.2.1, page 86 of the datasheet
  435. */
  436. if (use_spi) {
  437. ret = regmap_read(data->regmap, BMI160_REG_DUMMY, &val);
  438. if (ret < 0)
  439. return ret;
  440. }
  441. ret = regmap_read(data->regmap, BMI160_REG_CHIP_ID, &val);
  442. if (ret < 0) {
  443. dev_err(dev, "Error reading chip id\n");
  444. return ret;
  445. }
  446. if (val != BMI160_CHIP_ID_VAL) {
  447. dev_err(dev, "Wrong chip id, got %x expected %x\n",
  448. val, BMI160_CHIP_ID_VAL);
  449. return -ENODEV;
  450. }
  451. ret = bmi160_set_mode(data, BMI160_ACCEL, true);
  452. if (ret < 0)
  453. return ret;
  454. ret = bmi160_set_mode(data, BMI160_GYRO, true);
  455. if (ret < 0)
  456. return ret;
  457. return 0;
  458. }
  459. static void bmi160_chip_uninit(struct bmi160_data *data)
  460. {
  461. bmi160_set_mode(data, BMI160_GYRO, false);
  462. bmi160_set_mode(data, BMI160_ACCEL, false);
  463. }
  464. int bmi160_core_probe(struct device *dev, struct regmap *regmap,
  465. const char *name, bool use_spi)
  466. {
  467. struct iio_dev *indio_dev;
  468. struct bmi160_data *data;
  469. int ret;
  470. indio_dev = devm_iio_device_alloc(dev, sizeof(*data));
  471. if (!indio_dev)
  472. return -ENOMEM;
  473. data = iio_priv(indio_dev);
  474. dev_set_drvdata(dev, indio_dev);
  475. data->regmap = regmap;
  476. ret = bmi160_chip_init(data, use_spi);
  477. if (ret < 0)
  478. return ret;
  479. if (!name && ACPI_HANDLE(dev))
  480. name = bmi160_match_acpi_device(dev);
  481. indio_dev->dev.parent = dev;
  482. indio_dev->channels = bmi160_channels;
  483. indio_dev->num_channels = ARRAY_SIZE(bmi160_channels);
  484. indio_dev->name = name;
  485. indio_dev->modes = INDIO_DIRECT_MODE;
  486. indio_dev->info = &bmi160_info;
  487. ret = iio_triggered_buffer_setup(indio_dev, NULL,
  488. bmi160_trigger_handler, NULL);
  489. if (ret < 0)
  490. goto uninit;
  491. ret = iio_device_register(indio_dev);
  492. if (ret < 0)
  493. goto buffer_cleanup;
  494. return 0;
  495. buffer_cleanup:
  496. iio_triggered_buffer_cleanup(indio_dev);
  497. uninit:
  498. bmi160_chip_uninit(data);
  499. return ret;
  500. }
  501. EXPORT_SYMBOL_GPL(bmi160_core_probe);
  502. void bmi160_core_remove(struct device *dev)
  503. {
  504. struct iio_dev *indio_dev = dev_get_drvdata(dev);
  505. struct bmi160_data *data = iio_priv(indio_dev);
  506. iio_device_unregister(indio_dev);
  507. iio_triggered_buffer_cleanup(indio_dev);
  508. bmi160_chip_uninit(data);
  509. }
  510. EXPORT_SYMBOL_GPL(bmi160_core_remove);
  511. MODULE_AUTHOR("Daniel Baluta <daniel.baluta@intel.com");
  512. MODULE_DESCRIPTION("Bosch BMI160 driver");
  513. MODULE_LICENSE("GPL v2");