st_gyro_core.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  1. /*
  2. * STMicroelectronics gyroscopes driver
  3. *
  4. * Copyright 2012-2013 STMicroelectronics Inc.
  5. *
  6. * Denis Ciocca <denis.ciocca@st.com>
  7. *
  8. * Licensed under the GPL-2.
  9. */
  10. #include <linux/kernel.h>
  11. #include <linux/module.h>
  12. #include <linux/slab.h>
  13. #include <linux/errno.h>
  14. #include <linux/types.h>
  15. #include <linux/mutex.h>
  16. #include <linux/interrupt.h>
  17. #include <linux/i2c.h>
  18. #include <linux/gpio.h>
  19. #include <linux/irq.h>
  20. #include <linux/delay.h>
  21. #include <linux/iio/iio.h>
  22. #include <linux/iio/sysfs.h>
  23. #include <linux/iio/trigger.h>
  24. #include <linux/iio/buffer.h>
  25. #include <linux/iio/common/st_sensors.h>
  26. #include "st_gyro.h"
  27. #define ST_GYRO_NUMBER_DATA_CHANNELS 3
  28. /* DEFAULT VALUE FOR SENSORS */
  29. #define ST_GYRO_DEFAULT_OUT_X_L_ADDR 0x28
  30. #define ST_GYRO_DEFAULT_OUT_Y_L_ADDR 0x2a
  31. #define ST_GYRO_DEFAULT_OUT_Z_L_ADDR 0x2c
  32. /* FULLSCALE */
  33. #define ST_GYRO_FS_AVL_250DPS 250
  34. #define ST_GYRO_FS_AVL_500DPS 500
  35. #define ST_GYRO_FS_AVL_2000DPS 2000
  36. /* CUSTOM VALUES FOR SENSOR 1 */
  37. #define ST_GYRO_1_WAI_EXP 0xd3
  38. #define ST_GYRO_1_ODR_ADDR 0x20
  39. #define ST_GYRO_1_ODR_MASK 0xc0
  40. #define ST_GYRO_1_ODR_AVL_100HZ_VAL 0x00
  41. #define ST_GYRO_1_ODR_AVL_200HZ_VAL 0x01
  42. #define ST_GYRO_1_ODR_AVL_400HZ_VAL 0x02
  43. #define ST_GYRO_1_ODR_AVL_800HZ_VAL 0x03
  44. #define ST_GYRO_1_PW_ADDR 0x20
  45. #define ST_GYRO_1_PW_MASK 0x08
  46. #define ST_GYRO_1_FS_ADDR 0x23
  47. #define ST_GYRO_1_FS_MASK 0x30
  48. #define ST_GYRO_1_FS_AVL_250_VAL 0x00
  49. #define ST_GYRO_1_FS_AVL_500_VAL 0x01
  50. #define ST_GYRO_1_FS_AVL_2000_VAL 0x02
  51. #define ST_GYRO_1_FS_AVL_250_GAIN IIO_DEGREE_TO_RAD(8750)
  52. #define ST_GYRO_1_FS_AVL_500_GAIN IIO_DEGREE_TO_RAD(17500)
  53. #define ST_GYRO_1_FS_AVL_2000_GAIN IIO_DEGREE_TO_RAD(70000)
  54. #define ST_GYRO_1_BDU_ADDR 0x23
  55. #define ST_GYRO_1_BDU_MASK 0x80
  56. #define ST_GYRO_1_DRDY_IRQ_ADDR 0x22
  57. #define ST_GYRO_1_DRDY_IRQ_INT2_MASK 0x08
  58. #define ST_GYRO_1_MULTIREAD_BIT true
  59. /* CUSTOM VALUES FOR SENSOR 2 */
  60. #define ST_GYRO_2_WAI_EXP 0xd4
  61. #define ST_GYRO_2_ODR_ADDR 0x20
  62. #define ST_GYRO_2_ODR_MASK 0xc0
  63. #define ST_GYRO_2_ODR_AVL_95HZ_VAL 0x00
  64. #define ST_GYRO_2_ODR_AVL_190HZ_VAL 0x01
  65. #define ST_GYRO_2_ODR_AVL_380HZ_VAL 0x02
  66. #define ST_GYRO_2_ODR_AVL_760HZ_VAL 0x03
  67. #define ST_GYRO_2_PW_ADDR 0x20
  68. #define ST_GYRO_2_PW_MASK 0x08
  69. #define ST_GYRO_2_FS_ADDR 0x23
  70. #define ST_GYRO_2_FS_MASK 0x30
  71. #define ST_GYRO_2_FS_AVL_250_VAL 0x00
  72. #define ST_GYRO_2_FS_AVL_500_VAL 0x01
  73. #define ST_GYRO_2_FS_AVL_2000_VAL 0x02
  74. #define ST_GYRO_2_FS_AVL_250_GAIN IIO_DEGREE_TO_RAD(8750)
  75. #define ST_GYRO_2_FS_AVL_500_GAIN IIO_DEGREE_TO_RAD(17500)
  76. #define ST_GYRO_2_FS_AVL_2000_GAIN IIO_DEGREE_TO_RAD(70000)
  77. #define ST_GYRO_2_BDU_ADDR 0x23
  78. #define ST_GYRO_2_BDU_MASK 0x80
  79. #define ST_GYRO_2_DRDY_IRQ_ADDR 0x22
  80. #define ST_GYRO_2_DRDY_IRQ_INT2_MASK 0x08
  81. #define ST_GYRO_2_MULTIREAD_BIT true
  82. /* CUSTOM VALUES FOR SENSOR 3 */
  83. #define ST_GYRO_3_WAI_EXP 0xd7
  84. #define ST_GYRO_3_ODR_ADDR 0x20
  85. #define ST_GYRO_3_ODR_MASK 0xc0
  86. #define ST_GYRO_3_ODR_AVL_95HZ_VAL 0x00
  87. #define ST_GYRO_3_ODR_AVL_190HZ_VAL 0x01
  88. #define ST_GYRO_3_ODR_AVL_380HZ_VAL 0x02
  89. #define ST_GYRO_3_ODR_AVL_760HZ_VAL 0x03
  90. #define ST_GYRO_3_PW_ADDR 0x20
  91. #define ST_GYRO_3_PW_MASK 0x08
  92. #define ST_GYRO_3_FS_ADDR 0x23
  93. #define ST_GYRO_3_FS_MASK 0x30
  94. #define ST_GYRO_3_FS_AVL_250_VAL 0x00
  95. #define ST_GYRO_3_FS_AVL_500_VAL 0x01
  96. #define ST_GYRO_3_FS_AVL_2000_VAL 0x02
  97. #define ST_GYRO_3_FS_AVL_250_GAIN IIO_DEGREE_TO_RAD(8750)
  98. #define ST_GYRO_3_FS_AVL_500_GAIN IIO_DEGREE_TO_RAD(17500)
  99. #define ST_GYRO_3_FS_AVL_2000_GAIN IIO_DEGREE_TO_RAD(70000)
  100. #define ST_GYRO_3_BDU_ADDR 0x23
  101. #define ST_GYRO_3_BDU_MASK 0x80
  102. #define ST_GYRO_3_DRDY_IRQ_ADDR 0x22
  103. #define ST_GYRO_3_DRDY_IRQ_INT2_MASK 0x08
  104. #define ST_GYRO_3_MULTIREAD_BIT true
  105. static const struct iio_chan_spec st_gyro_16bit_channels[] = {
  106. ST_SENSORS_LSM_CHANNELS(IIO_ANGL_VEL,
  107. BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
  108. ST_SENSORS_SCAN_X, 1, IIO_MOD_X, 's', IIO_LE, 16, 16,
  109. ST_GYRO_DEFAULT_OUT_X_L_ADDR),
  110. ST_SENSORS_LSM_CHANNELS(IIO_ANGL_VEL,
  111. BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
  112. ST_SENSORS_SCAN_Y, 1, IIO_MOD_Y, 's', IIO_LE, 16, 16,
  113. ST_GYRO_DEFAULT_OUT_Y_L_ADDR),
  114. ST_SENSORS_LSM_CHANNELS(IIO_ANGL_VEL,
  115. BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
  116. ST_SENSORS_SCAN_Z, 1, IIO_MOD_Z, 's', IIO_LE, 16, 16,
  117. ST_GYRO_DEFAULT_OUT_Z_L_ADDR),
  118. IIO_CHAN_SOFT_TIMESTAMP(3)
  119. };
  120. static const struct st_sensor_settings st_gyro_sensors_settings[] = {
  121. {
  122. .wai = ST_GYRO_1_WAI_EXP,
  123. .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
  124. .sensors_supported = {
  125. [0] = L3G4200D_GYRO_DEV_NAME,
  126. [1] = LSM330DL_GYRO_DEV_NAME,
  127. },
  128. .ch = (struct iio_chan_spec *)st_gyro_16bit_channels,
  129. .odr = {
  130. .addr = ST_GYRO_1_ODR_ADDR,
  131. .mask = ST_GYRO_1_ODR_MASK,
  132. .odr_avl = {
  133. { 100, ST_GYRO_1_ODR_AVL_100HZ_VAL, },
  134. { 200, ST_GYRO_1_ODR_AVL_200HZ_VAL, },
  135. { 400, ST_GYRO_1_ODR_AVL_400HZ_VAL, },
  136. { 800, ST_GYRO_1_ODR_AVL_800HZ_VAL, },
  137. },
  138. },
  139. .pw = {
  140. .addr = ST_GYRO_1_PW_ADDR,
  141. .mask = ST_GYRO_1_PW_MASK,
  142. .value_on = ST_SENSORS_DEFAULT_POWER_ON_VALUE,
  143. .value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
  144. },
  145. .enable_axis = {
  146. .addr = ST_SENSORS_DEFAULT_AXIS_ADDR,
  147. .mask = ST_SENSORS_DEFAULT_AXIS_MASK,
  148. },
  149. .fs = {
  150. .addr = ST_GYRO_1_FS_ADDR,
  151. .mask = ST_GYRO_1_FS_MASK,
  152. .fs_avl = {
  153. [0] = {
  154. .num = ST_GYRO_FS_AVL_250DPS,
  155. .value = ST_GYRO_1_FS_AVL_250_VAL,
  156. .gain = ST_GYRO_1_FS_AVL_250_GAIN,
  157. },
  158. [1] = {
  159. .num = ST_GYRO_FS_AVL_500DPS,
  160. .value = ST_GYRO_1_FS_AVL_500_VAL,
  161. .gain = ST_GYRO_1_FS_AVL_500_GAIN,
  162. },
  163. [2] = {
  164. .num = ST_GYRO_FS_AVL_2000DPS,
  165. .value = ST_GYRO_1_FS_AVL_2000_VAL,
  166. .gain = ST_GYRO_1_FS_AVL_2000_GAIN,
  167. },
  168. },
  169. },
  170. .bdu = {
  171. .addr = ST_GYRO_1_BDU_ADDR,
  172. .mask = ST_GYRO_1_BDU_MASK,
  173. },
  174. .drdy_irq = {
  175. .addr = ST_GYRO_1_DRDY_IRQ_ADDR,
  176. .mask_int2 = ST_GYRO_1_DRDY_IRQ_INT2_MASK,
  177. /*
  178. * The sensor has IHL (active low) and open
  179. * drain settings, but only for INT1 and not
  180. * for the DRDY line on INT2.
  181. */
  182. .addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
  183. },
  184. .multi_read_bit = ST_GYRO_1_MULTIREAD_BIT,
  185. .bootime = 2,
  186. },
  187. {
  188. .wai = ST_GYRO_2_WAI_EXP,
  189. .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
  190. .sensors_supported = {
  191. [0] = L3GD20_GYRO_DEV_NAME,
  192. [1] = LSM330D_GYRO_DEV_NAME,
  193. [2] = LSM330DLC_GYRO_DEV_NAME,
  194. [3] = L3G4IS_GYRO_DEV_NAME,
  195. [4] = LSM330_GYRO_DEV_NAME,
  196. [5] = LSM9DS0_GYRO_DEV_NAME,
  197. },
  198. .ch = (struct iio_chan_spec *)st_gyro_16bit_channels,
  199. .odr = {
  200. .addr = ST_GYRO_2_ODR_ADDR,
  201. .mask = ST_GYRO_2_ODR_MASK,
  202. .odr_avl = {
  203. { 95, ST_GYRO_2_ODR_AVL_95HZ_VAL, },
  204. { 190, ST_GYRO_2_ODR_AVL_190HZ_VAL, },
  205. { 380, ST_GYRO_2_ODR_AVL_380HZ_VAL, },
  206. { 760, ST_GYRO_2_ODR_AVL_760HZ_VAL, },
  207. },
  208. },
  209. .pw = {
  210. .addr = ST_GYRO_2_PW_ADDR,
  211. .mask = ST_GYRO_2_PW_MASK,
  212. .value_on = ST_SENSORS_DEFAULT_POWER_ON_VALUE,
  213. .value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
  214. },
  215. .enable_axis = {
  216. .addr = ST_SENSORS_DEFAULT_AXIS_ADDR,
  217. .mask = ST_SENSORS_DEFAULT_AXIS_MASK,
  218. },
  219. .fs = {
  220. .addr = ST_GYRO_2_FS_ADDR,
  221. .mask = ST_GYRO_2_FS_MASK,
  222. .fs_avl = {
  223. [0] = {
  224. .num = ST_GYRO_FS_AVL_250DPS,
  225. .value = ST_GYRO_2_FS_AVL_250_VAL,
  226. .gain = ST_GYRO_2_FS_AVL_250_GAIN,
  227. },
  228. [1] = {
  229. .num = ST_GYRO_FS_AVL_500DPS,
  230. .value = ST_GYRO_2_FS_AVL_500_VAL,
  231. .gain = ST_GYRO_2_FS_AVL_500_GAIN,
  232. },
  233. [2] = {
  234. .num = ST_GYRO_FS_AVL_2000DPS,
  235. .value = ST_GYRO_2_FS_AVL_2000_VAL,
  236. .gain = ST_GYRO_2_FS_AVL_2000_GAIN,
  237. },
  238. },
  239. },
  240. .bdu = {
  241. .addr = ST_GYRO_2_BDU_ADDR,
  242. .mask = ST_GYRO_2_BDU_MASK,
  243. },
  244. .drdy_irq = {
  245. .addr = ST_GYRO_2_DRDY_IRQ_ADDR,
  246. .mask_int2 = ST_GYRO_2_DRDY_IRQ_INT2_MASK,
  247. /*
  248. * The sensor has IHL (active low) and open
  249. * drain settings, but only for INT1 and not
  250. * for the DRDY line on INT2.
  251. */
  252. .addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
  253. },
  254. .multi_read_bit = ST_GYRO_2_MULTIREAD_BIT,
  255. .bootime = 2,
  256. },
  257. {
  258. .wai = ST_GYRO_3_WAI_EXP,
  259. .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
  260. .sensors_supported = {
  261. [0] = L3GD20_GYRO_DEV_NAME,
  262. },
  263. .ch = (struct iio_chan_spec *)st_gyro_16bit_channels,
  264. .odr = {
  265. .addr = ST_GYRO_3_ODR_ADDR,
  266. .mask = ST_GYRO_3_ODR_MASK,
  267. .odr_avl = {
  268. { 95, ST_GYRO_3_ODR_AVL_95HZ_VAL, },
  269. { 190, ST_GYRO_3_ODR_AVL_190HZ_VAL, },
  270. { 380, ST_GYRO_3_ODR_AVL_380HZ_VAL, },
  271. { 760, ST_GYRO_3_ODR_AVL_760HZ_VAL, },
  272. },
  273. },
  274. .pw = {
  275. .addr = ST_GYRO_3_PW_ADDR,
  276. .mask = ST_GYRO_3_PW_MASK,
  277. .value_on = ST_SENSORS_DEFAULT_POWER_ON_VALUE,
  278. .value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
  279. },
  280. .enable_axis = {
  281. .addr = ST_SENSORS_DEFAULT_AXIS_ADDR,
  282. .mask = ST_SENSORS_DEFAULT_AXIS_MASK,
  283. },
  284. .fs = {
  285. .addr = ST_GYRO_3_FS_ADDR,
  286. .mask = ST_GYRO_3_FS_MASK,
  287. .fs_avl = {
  288. [0] = {
  289. .num = ST_GYRO_FS_AVL_250DPS,
  290. .value = ST_GYRO_3_FS_AVL_250_VAL,
  291. .gain = ST_GYRO_3_FS_AVL_250_GAIN,
  292. },
  293. [1] = {
  294. .num = ST_GYRO_FS_AVL_500DPS,
  295. .value = ST_GYRO_3_FS_AVL_500_VAL,
  296. .gain = ST_GYRO_3_FS_AVL_500_GAIN,
  297. },
  298. [2] = {
  299. .num = ST_GYRO_FS_AVL_2000DPS,
  300. .value = ST_GYRO_3_FS_AVL_2000_VAL,
  301. .gain = ST_GYRO_3_FS_AVL_2000_GAIN,
  302. },
  303. },
  304. },
  305. .bdu = {
  306. .addr = ST_GYRO_3_BDU_ADDR,
  307. .mask = ST_GYRO_3_BDU_MASK,
  308. },
  309. .drdy_irq = {
  310. .addr = ST_GYRO_3_DRDY_IRQ_ADDR,
  311. .mask_int2 = ST_GYRO_3_DRDY_IRQ_INT2_MASK,
  312. /*
  313. * The sensor has IHL (active low) and open
  314. * drain settings, but only for INT1 and not
  315. * for the DRDY line on INT2.
  316. */
  317. .addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
  318. },
  319. .multi_read_bit = ST_GYRO_3_MULTIREAD_BIT,
  320. .bootime = 2,
  321. },
  322. };
  323. static int st_gyro_read_raw(struct iio_dev *indio_dev,
  324. struct iio_chan_spec const *ch, int *val,
  325. int *val2, long mask)
  326. {
  327. int err;
  328. struct st_sensor_data *gdata = iio_priv(indio_dev);
  329. switch (mask) {
  330. case IIO_CHAN_INFO_RAW:
  331. err = st_sensors_read_info_raw(indio_dev, ch, val);
  332. if (err < 0)
  333. goto read_error;
  334. return IIO_VAL_INT;
  335. case IIO_CHAN_INFO_SCALE:
  336. *val = 0;
  337. *val2 = gdata->current_fullscale->gain;
  338. return IIO_VAL_INT_PLUS_MICRO;
  339. case IIO_CHAN_INFO_SAMP_FREQ:
  340. *val = gdata->odr;
  341. return IIO_VAL_INT;
  342. default:
  343. return -EINVAL;
  344. }
  345. read_error:
  346. return err;
  347. }
  348. static int st_gyro_write_raw(struct iio_dev *indio_dev,
  349. struct iio_chan_spec const *chan, int val, int val2, long mask)
  350. {
  351. int err;
  352. switch (mask) {
  353. case IIO_CHAN_INFO_SCALE:
  354. err = st_sensors_set_fullscale_by_gain(indio_dev, val2);
  355. break;
  356. case IIO_CHAN_INFO_SAMP_FREQ:
  357. if (val2)
  358. return -EINVAL;
  359. mutex_lock(&indio_dev->mlock);
  360. err = st_sensors_set_odr(indio_dev, val);
  361. mutex_unlock(&indio_dev->mlock);
  362. return err;
  363. default:
  364. err = -EINVAL;
  365. }
  366. return err;
  367. }
  368. static ST_SENSORS_DEV_ATTR_SAMP_FREQ_AVAIL();
  369. static ST_SENSORS_DEV_ATTR_SCALE_AVAIL(in_anglvel_scale_available);
  370. static struct attribute *st_gyro_attributes[] = {
  371. &iio_dev_attr_sampling_frequency_available.dev_attr.attr,
  372. &iio_dev_attr_in_anglvel_scale_available.dev_attr.attr,
  373. NULL,
  374. };
  375. static const struct attribute_group st_gyro_attribute_group = {
  376. .attrs = st_gyro_attributes,
  377. };
  378. static const struct iio_info gyro_info = {
  379. .driver_module = THIS_MODULE,
  380. .attrs = &st_gyro_attribute_group,
  381. .read_raw = &st_gyro_read_raw,
  382. .write_raw = &st_gyro_write_raw,
  383. .debugfs_reg_access = &st_sensors_debugfs_reg_access,
  384. };
  385. #ifdef CONFIG_IIO_TRIGGER
  386. static const struct iio_trigger_ops st_gyro_trigger_ops = {
  387. .owner = THIS_MODULE,
  388. .set_trigger_state = ST_GYRO_TRIGGER_SET_STATE,
  389. .validate_device = st_sensors_validate_device,
  390. };
  391. #define ST_GYRO_TRIGGER_OPS (&st_gyro_trigger_ops)
  392. #else
  393. #define ST_GYRO_TRIGGER_OPS NULL
  394. #endif
  395. int st_gyro_common_probe(struct iio_dev *indio_dev)
  396. {
  397. struct st_sensor_data *gdata = iio_priv(indio_dev);
  398. int irq = gdata->get_irq_data_ready(indio_dev);
  399. int err;
  400. indio_dev->modes = INDIO_DIRECT_MODE;
  401. indio_dev->info = &gyro_info;
  402. mutex_init(&gdata->tb.buf_lock);
  403. err = st_sensors_power_enable(indio_dev);
  404. if (err)
  405. return err;
  406. err = st_sensors_check_device_support(indio_dev,
  407. ARRAY_SIZE(st_gyro_sensors_settings),
  408. st_gyro_sensors_settings);
  409. if (err < 0)
  410. goto st_gyro_power_off;
  411. gdata->num_data_channels = ST_GYRO_NUMBER_DATA_CHANNELS;
  412. gdata->multiread_bit = gdata->sensor_settings->multi_read_bit;
  413. indio_dev->channels = gdata->sensor_settings->ch;
  414. indio_dev->num_channels = ST_SENSORS_NUMBER_ALL_CHANNELS;
  415. gdata->current_fullscale = (struct st_sensor_fullscale_avl *)
  416. &gdata->sensor_settings->fs.fs_avl[0];
  417. gdata->odr = gdata->sensor_settings->odr.odr_avl[0].hz;
  418. err = st_sensors_init_sensor(indio_dev,
  419. (struct st_sensors_platform_data *)&gyro_pdata);
  420. if (err < 0)
  421. goto st_gyro_power_off;
  422. err = st_gyro_allocate_ring(indio_dev);
  423. if (err < 0)
  424. goto st_gyro_power_off;
  425. if (irq > 0) {
  426. err = st_sensors_allocate_trigger(indio_dev,
  427. ST_GYRO_TRIGGER_OPS);
  428. if (err < 0)
  429. goto st_gyro_probe_trigger_error;
  430. }
  431. err = iio_device_register(indio_dev);
  432. if (err)
  433. goto st_gyro_device_register_error;
  434. dev_info(&indio_dev->dev, "registered gyroscope %s\n",
  435. indio_dev->name);
  436. return 0;
  437. st_gyro_device_register_error:
  438. if (irq > 0)
  439. st_sensors_deallocate_trigger(indio_dev);
  440. st_gyro_probe_trigger_error:
  441. st_gyro_deallocate_ring(indio_dev);
  442. st_gyro_power_off:
  443. st_sensors_power_disable(indio_dev);
  444. return err;
  445. }
  446. EXPORT_SYMBOL(st_gyro_common_probe);
  447. void st_gyro_common_remove(struct iio_dev *indio_dev)
  448. {
  449. struct st_sensor_data *gdata = iio_priv(indio_dev);
  450. st_sensors_power_disable(indio_dev);
  451. iio_device_unregister(indio_dev);
  452. if (gdata->get_irq_data_ready(indio_dev) > 0)
  453. st_sensors_deallocate_trigger(indio_dev);
  454. st_gyro_deallocate_ring(indio_dev);
  455. }
  456. EXPORT_SYMBOL(st_gyro_common_remove);
  457. MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
  458. MODULE_DESCRIPTION("STMicroelectronics gyroscopes driver");
  459. MODULE_LICENSE("GPL v2");