adis16480.c 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * ADIS16480 and similar IMUs driver
  4. *
  5. * Copyright 2012 Analog Devices Inc.
  6. */
  7. #include <linux/clk.h>
  8. #include <linux/bitfield.h>
  9. #include <linux/interrupt.h>
  10. #include <linux/irq.h>
  11. #include <linux/math.h>
  12. #include <linux/device.h>
  13. #include <linux/kernel.h>
  14. #include <linux/spi/spi.h>
  15. #include <linux/mod_devicetable.h>
  16. #include <linux/module.h>
  17. #include <linux/lcm.h>
  18. #include <linux/property.h>
  19. #include <linux/swab.h>
  20. #include <linux/crc32.h>
  21. #include <linux/iio/iio.h>
  22. #include <linux/iio/buffer.h>
  23. #include <linux/iio/imu/adis.h>
  24. #include <linux/iio/trigger_consumer.h>
  25. #include <linux/debugfs.h>
  26. #define ADIS16480_PAGE_SIZE 0x80
  27. #define ADIS16480_REG(page, reg) ((page) * ADIS16480_PAGE_SIZE + (reg))
  28. #define ADIS16480_REG_PAGE_ID 0x00 /* Same address on each page */
  29. #define ADIS16480_REG_SEQ_CNT ADIS16480_REG(0x00, 0x06)
  30. #define ADIS16480_REG_SYS_E_FLA ADIS16480_REG(0x00, 0x08)
  31. #define ADIS16480_REG_DIAG_STS ADIS16480_REG(0x00, 0x0A)
  32. #define ADIS16480_REG_ALM_STS ADIS16480_REG(0x00, 0x0C)
  33. #define ADIS16480_REG_TEMP_OUT ADIS16480_REG(0x00, 0x0E)
  34. #define ADIS16480_REG_X_GYRO_OUT ADIS16480_REG(0x00, 0x10)
  35. #define ADIS16480_REG_Y_GYRO_OUT ADIS16480_REG(0x00, 0x14)
  36. #define ADIS16480_REG_Z_GYRO_OUT ADIS16480_REG(0x00, 0x18)
  37. #define ADIS16480_REG_X_ACCEL_OUT ADIS16480_REG(0x00, 0x1C)
  38. #define ADIS16480_REG_Y_ACCEL_OUT ADIS16480_REG(0x00, 0x20)
  39. #define ADIS16480_REG_Z_ACCEL_OUT ADIS16480_REG(0x00, 0x24)
  40. #define ADIS16480_REG_X_MAGN_OUT ADIS16480_REG(0x00, 0x28)
  41. #define ADIS16480_REG_Y_MAGN_OUT ADIS16480_REG(0x00, 0x2A)
  42. #define ADIS16480_REG_Z_MAGN_OUT ADIS16480_REG(0x00, 0x2C)
  43. #define ADIS16480_REG_BAROM_OUT ADIS16480_REG(0x00, 0x2E)
  44. #define ADIS16480_REG_X_DELTAANG_OUT ADIS16480_REG(0x00, 0x40)
  45. #define ADIS16480_REG_Y_DELTAANG_OUT ADIS16480_REG(0x00, 0x44)
  46. #define ADIS16480_REG_Z_DELTAANG_OUT ADIS16480_REG(0x00, 0x48)
  47. #define ADIS16480_REG_X_DELTAVEL_OUT ADIS16480_REG(0x00, 0x4C)
  48. #define ADIS16480_REG_Y_DELTAVEL_OUT ADIS16480_REG(0x00, 0x50)
  49. #define ADIS16480_REG_Z_DELTAVEL_OUT ADIS16480_REG(0x00, 0x54)
  50. #define ADIS16480_REG_PROD_ID ADIS16480_REG(0x00, 0x7E)
  51. #define ADIS16480_REG_X_GYRO_SCALE ADIS16480_REG(0x02, 0x04)
  52. #define ADIS16480_REG_Y_GYRO_SCALE ADIS16480_REG(0x02, 0x06)
  53. #define ADIS16480_REG_Z_GYRO_SCALE ADIS16480_REG(0x02, 0x08)
  54. #define ADIS16480_REG_X_ACCEL_SCALE ADIS16480_REG(0x02, 0x0A)
  55. #define ADIS16480_REG_Y_ACCEL_SCALE ADIS16480_REG(0x02, 0x0C)
  56. #define ADIS16480_REG_Z_ACCEL_SCALE ADIS16480_REG(0x02, 0x0E)
  57. #define ADIS16480_REG_X_GYRO_BIAS ADIS16480_REG(0x02, 0x10)
  58. #define ADIS16480_REG_Y_GYRO_BIAS ADIS16480_REG(0x02, 0x14)
  59. #define ADIS16480_REG_Z_GYRO_BIAS ADIS16480_REG(0x02, 0x18)
  60. #define ADIS16480_REG_X_ACCEL_BIAS ADIS16480_REG(0x02, 0x1C)
  61. #define ADIS16480_REG_Y_ACCEL_BIAS ADIS16480_REG(0x02, 0x20)
  62. #define ADIS16480_REG_Z_ACCEL_BIAS ADIS16480_REG(0x02, 0x24)
  63. #define ADIS16480_REG_X_HARD_IRON ADIS16480_REG(0x02, 0x28)
  64. #define ADIS16480_REG_Y_HARD_IRON ADIS16480_REG(0x02, 0x2A)
  65. #define ADIS16480_REG_Z_HARD_IRON ADIS16480_REG(0x02, 0x2C)
  66. #define ADIS16480_REG_BAROM_BIAS ADIS16480_REG(0x02, 0x40)
  67. #define ADIS16480_REG_FLASH_CNT ADIS16480_REG(0x02, 0x7C)
  68. #define ADIS16480_REG_GLOB_CMD ADIS16480_REG(0x03, 0x02)
  69. #define ADIS16480_REG_FNCTIO_CTRL ADIS16480_REG(0x03, 0x06)
  70. #define ADIS16480_REG_GPIO_CTRL ADIS16480_REG(0x03, 0x08)
  71. #define ADIS16480_REG_CONFIG ADIS16480_REG(0x03, 0x0A)
  72. #define ADIS16480_REG_DEC_RATE ADIS16480_REG(0x03, 0x0C)
  73. #define ADIS16480_REG_SLP_CNT ADIS16480_REG(0x03, 0x10)
  74. #define ADIS16480_REG_FILTER_BNK0 ADIS16480_REG(0x03, 0x16)
  75. #define ADIS16480_REG_FILTER_BNK1 ADIS16480_REG(0x03, 0x18)
  76. #define ADIS16480_REG_ALM_CNFG0 ADIS16480_REG(0x03, 0x20)
  77. #define ADIS16480_REG_ALM_CNFG1 ADIS16480_REG(0x03, 0x22)
  78. #define ADIS16480_REG_ALM_CNFG2 ADIS16480_REG(0x03, 0x24)
  79. #define ADIS16480_REG_XG_ALM_MAGN ADIS16480_REG(0x03, 0x28)
  80. #define ADIS16480_REG_YG_ALM_MAGN ADIS16480_REG(0x03, 0x2A)
  81. #define ADIS16480_REG_ZG_ALM_MAGN ADIS16480_REG(0x03, 0x2C)
  82. #define ADIS16480_REG_XA_ALM_MAGN ADIS16480_REG(0x03, 0x2E)
  83. #define ADIS16480_REG_YA_ALM_MAGN ADIS16480_REG(0x03, 0x30)
  84. #define ADIS16480_REG_ZA_ALM_MAGN ADIS16480_REG(0x03, 0x32)
  85. #define ADIS16480_REG_XM_ALM_MAGN ADIS16480_REG(0x03, 0x34)
  86. #define ADIS16480_REG_YM_ALM_MAGN ADIS16480_REG(0x03, 0x36)
  87. #define ADIS16480_REG_ZM_ALM_MAGN ADIS16480_REG(0x03, 0x38)
  88. #define ADIS16480_REG_BR_ALM_MAGN ADIS16480_REG(0x03, 0x3A)
  89. #define ADIS16480_REG_FIRM_REV ADIS16480_REG(0x03, 0x78)
  90. #define ADIS16480_REG_FIRM_DM ADIS16480_REG(0x03, 0x7A)
  91. #define ADIS16480_REG_FIRM_Y ADIS16480_REG(0x03, 0x7C)
  92. /*
  93. * External clock scaling in PPS mode.
  94. * Available only for ADIS1649x devices
  95. */
  96. #define ADIS16495_REG_SYNC_SCALE ADIS16480_REG(0x03, 0x10)
  97. #define ADIS16495_REG_BURST_CMD ADIS16480_REG(0x00, 0x7C)
  98. #define ADIS16495_BURST_ID 0xA5A5
  99. /* total number of segments in burst */
  100. #define ADIS16495_BURST_MAX_DATA 20
  101. /* spi max speed in burst mode */
  102. #define ADIS16495_BURST_MAX_SPEED 6000000
  103. #define ADIS16480_REG_SERIAL_NUM ADIS16480_REG(0x04, 0x20)
  104. /* Each filter coefficent bank spans two pages */
  105. #define ADIS16480_FIR_COEF(page) (x < 60 ? ADIS16480_REG(page, (x) + 8) : \
  106. ADIS16480_REG((page) + 1, (x) - 60 + 8))
  107. #define ADIS16480_FIR_COEF_A(x) ADIS16480_FIR_COEF(0x05, (x))
  108. #define ADIS16480_FIR_COEF_B(x) ADIS16480_FIR_COEF(0x07, (x))
  109. #define ADIS16480_FIR_COEF_C(x) ADIS16480_FIR_COEF(0x09, (x))
  110. #define ADIS16480_FIR_COEF_D(x) ADIS16480_FIR_COEF(0x0B, (x))
  111. /* ADIS16480_REG_FNCTIO_CTRL */
  112. #define ADIS16480_DRDY_SEL_MSK GENMASK(1, 0)
  113. #define ADIS16480_DRDY_SEL(x) FIELD_PREP(ADIS16480_DRDY_SEL_MSK, x)
  114. #define ADIS16480_DRDY_POL_MSK BIT(2)
  115. #define ADIS16480_DRDY_POL(x) FIELD_PREP(ADIS16480_DRDY_POL_MSK, x)
  116. #define ADIS16480_DRDY_EN_MSK BIT(3)
  117. #define ADIS16480_DRDY_EN(x) FIELD_PREP(ADIS16480_DRDY_EN_MSK, x)
  118. #define ADIS16480_SYNC_SEL_MSK GENMASK(5, 4)
  119. #define ADIS16480_SYNC_SEL(x) FIELD_PREP(ADIS16480_SYNC_SEL_MSK, x)
  120. #define ADIS16480_SYNC_EN_MSK BIT(7)
  121. #define ADIS16480_SYNC_EN(x) FIELD_PREP(ADIS16480_SYNC_EN_MSK, x)
  122. #define ADIS16480_SYNC_MODE_MSK BIT(8)
  123. #define ADIS16480_SYNC_MODE(x) FIELD_PREP(ADIS16480_SYNC_MODE_MSK, x)
  124. struct adis16480_chip_info {
  125. unsigned int num_channels;
  126. const struct iio_chan_spec *channels;
  127. unsigned int gyro_max_val;
  128. unsigned int gyro_max_scale;
  129. unsigned int accel_max_val;
  130. unsigned int accel_max_scale;
  131. unsigned int temp_scale;
  132. unsigned int int_clk;
  133. unsigned int max_dec_rate;
  134. const unsigned int *filter_freqs;
  135. bool has_pps_clk_mode;
  136. bool has_sleep_cnt;
  137. const struct adis_data adis_data;
  138. };
  139. enum adis16480_int_pin {
  140. ADIS16480_PIN_DIO1,
  141. ADIS16480_PIN_DIO2,
  142. ADIS16480_PIN_DIO3,
  143. ADIS16480_PIN_DIO4
  144. };
  145. enum adis16480_clock_mode {
  146. ADIS16480_CLK_SYNC,
  147. ADIS16480_CLK_PPS,
  148. ADIS16480_CLK_INT
  149. };
  150. struct adis16480 {
  151. const struct adis16480_chip_info *chip_info;
  152. struct adis adis;
  153. struct clk *ext_clk;
  154. enum adis16480_clock_mode clk_mode;
  155. unsigned int clk_freq;
  156. /* Alignment needed for the timestamp */
  157. __be16 data[ADIS16495_BURST_MAX_DATA] __aligned(8);
  158. };
  159. static const char * const adis16480_int_pin_names[4] = {
  160. [ADIS16480_PIN_DIO1] = "DIO1",
  161. [ADIS16480_PIN_DIO2] = "DIO2",
  162. [ADIS16480_PIN_DIO3] = "DIO3",
  163. [ADIS16480_PIN_DIO4] = "DIO4",
  164. };
  165. static bool low_rate_allow;
  166. module_param(low_rate_allow, bool, 0444);
  167. MODULE_PARM_DESC(low_rate_allow,
  168. "Allow IMU rates below the minimum advisable when external clk is used in PPS mode (default: N)");
  169. #ifdef CONFIG_DEBUG_FS
  170. static ssize_t adis16480_show_firmware_revision(struct file *file,
  171. char __user *userbuf, size_t count, loff_t *ppos)
  172. {
  173. struct adis16480 *adis16480 = file->private_data;
  174. char buf[7];
  175. size_t len;
  176. u16 rev;
  177. int ret;
  178. ret = adis_read_reg_16(&adis16480->adis, ADIS16480_REG_FIRM_REV, &rev);
  179. if (ret)
  180. return ret;
  181. len = scnprintf(buf, sizeof(buf), "%x.%x\n", rev >> 8, rev & 0xff);
  182. return simple_read_from_buffer(userbuf, count, ppos, buf, len);
  183. }
  184. static const struct file_operations adis16480_firmware_revision_fops = {
  185. .open = simple_open,
  186. .read = adis16480_show_firmware_revision,
  187. .llseek = default_llseek,
  188. .owner = THIS_MODULE,
  189. };
  190. static ssize_t adis16480_show_firmware_date(struct file *file,
  191. char __user *userbuf, size_t count, loff_t *ppos)
  192. {
  193. struct adis16480 *adis16480 = file->private_data;
  194. u16 md, year;
  195. char buf[12];
  196. size_t len;
  197. int ret;
  198. ret = adis_read_reg_16(&adis16480->adis, ADIS16480_REG_FIRM_Y, &year);
  199. if (ret)
  200. return ret;
  201. ret = adis_read_reg_16(&adis16480->adis, ADIS16480_REG_FIRM_DM, &md);
  202. if (ret)
  203. return ret;
  204. len = snprintf(buf, sizeof(buf), "%.2x-%.2x-%.4x\n",
  205. md >> 8, md & 0xff, year);
  206. return simple_read_from_buffer(userbuf, count, ppos, buf, len);
  207. }
  208. static const struct file_operations adis16480_firmware_date_fops = {
  209. .open = simple_open,
  210. .read = adis16480_show_firmware_date,
  211. .llseek = default_llseek,
  212. .owner = THIS_MODULE,
  213. };
  214. static int adis16480_show_serial_number(void *arg, u64 *val)
  215. {
  216. struct adis16480 *adis16480 = arg;
  217. u16 serial;
  218. int ret;
  219. ret = adis_read_reg_16(&adis16480->adis, ADIS16480_REG_SERIAL_NUM,
  220. &serial);
  221. if (ret)
  222. return ret;
  223. *val = serial;
  224. return 0;
  225. }
  226. DEFINE_DEBUGFS_ATTRIBUTE(adis16480_serial_number_fops,
  227. adis16480_show_serial_number, NULL, "0x%.4llx\n");
  228. static int adis16480_show_product_id(void *arg, u64 *val)
  229. {
  230. struct adis16480 *adis16480 = arg;
  231. u16 prod_id;
  232. int ret;
  233. ret = adis_read_reg_16(&adis16480->adis, ADIS16480_REG_PROD_ID,
  234. &prod_id);
  235. if (ret)
  236. return ret;
  237. *val = prod_id;
  238. return 0;
  239. }
  240. DEFINE_DEBUGFS_ATTRIBUTE(adis16480_product_id_fops,
  241. adis16480_show_product_id, NULL, "%llu\n");
  242. static int adis16480_show_flash_count(void *arg, u64 *val)
  243. {
  244. struct adis16480 *adis16480 = arg;
  245. u32 flash_count;
  246. int ret;
  247. ret = adis_read_reg_32(&adis16480->adis, ADIS16480_REG_FLASH_CNT,
  248. &flash_count);
  249. if (ret)
  250. return ret;
  251. *val = flash_count;
  252. return 0;
  253. }
  254. DEFINE_DEBUGFS_ATTRIBUTE(adis16480_flash_count_fops,
  255. adis16480_show_flash_count, NULL, "%lld\n");
  256. static int adis16480_debugfs_init(struct iio_dev *indio_dev)
  257. {
  258. struct adis16480 *adis16480 = iio_priv(indio_dev);
  259. struct dentry *d = iio_get_debugfs_dentry(indio_dev);
  260. debugfs_create_file_unsafe("firmware_revision", 0400,
  261. d, adis16480, &adis16480_firmware_revision_fops);
  262. debugfs_create_file_unsafe("firmware_date", 0400,
  263. d, adis16480, &adis16480_firmware_date_fops);
  264. debugfs_create_file_unsafe("serial_number", 0400,
  265. d, adis16480, &adis16480_serial_number_fops);
  266. debugfs_create_file_unsafe("product_id", 0400,
  267. d, adis16480, &adis16480_product_id_fops);
  268. debugfs_create_file_unsafe("flash_count", 0400,
  269. d, adis16480, &adis16480_flash_count_fops);
  270. return 0;
  271. }
  272. #else
  273. static int adis16480_debugfs_init(struct iio_dev *indio_dev)
  274. {
  275. return 0;
  276. }
  277. #endif
  278. static int adis16480_set_freq(struct iio_dev *indio_dev, int val, int val2)
  279. {
  280. struct adis16480 *st = iio_priv(indio_dev);
  281. unsigned int t, sample_rate = st->clk_freq;
  282. int ret;
  283. if (val < 0 || val2 < 0)
  284. return -EINVAL;
  285. t = val * 1000 + val2 / 1000;
  286. if (t == 0)
  287. return -EINVAL;
  288. adis_dev_lock(&st->adis);
  289. /*
  290. * When using PPS mode, the input clock needs to be scaled so that we have an IMU
  291. * sample rate between (optimally) 4000 and 4250. After this, we can use the
  292. * decimation filter to lower the sampling rate in order to get what the user wants.
  293. * Optimally, the user sample rate is a multiple of both the IMU sample rate and
  294. * the input clock. Hence, calculating the sync_scale dynamically gives us better
  295. * chances of achieving a perfect/integer value for DEC_RATE. The math here is:
  296. * 1. lcm of the input clock and the desired output rate.
  297. * 2. get the highest multiple of the previous result lower than the adis max rate.
  298. * 3. The last result becomes the IMU sample rate. Use that to calculate SYNC_SCALE
  299. * and DEC_RATE (to get the user output rate)
  300. */
  301. if (st->clk_mode == ADIS16480_CLK_PPS) {
  302. unsigned long scaled_rate = lcm(st->clk_freq, t);
  303. int sync_scale;
  304. /*
  305. * If lcm is bigger than the IMU maximum sampling rate there's no perfect
  306. * solution. In this case, we get the highest multiple of the input clock
  307. * lower than the IMU max sample rate.
  308. */
  309. if (scaled_rate > st->chip_info->int_clk)
  310. scaled_rate = st->chip_info->int_clk / st->clk_freq * st->clk_freq;
  311. else
  312. scaled_rate = st->chip_info->int_clk / scaled_rate * scaled_rate;
  313. /*
  314. * This is not an hard requirement but it's not advised to run the IMU
  315. * with a sample rate lower than 4000Hz due to possible undersampling
  316. * issues. However, there are users that might really want to take the risk.
  317. * Hence, we provide a module parameter for them. If set, we allow sample
  318. * rates lower than 4KHz. By default, we won't allow this and we just roundup
  319. * the rate to the next multiple of the input clock bigger than 4KHz. This
  320. * is done like this as in some cases (when DEC_RATE is 0) might give
  321. * us the closest value to the one desired by the user...
  322. */
  323. if (scaled_rate < 4000000 && !low_rate_allow)
  324. scaled_rate = roundup(4000000, st->clk_freq);
  325. sync_scale = scaled_rate / st->clk_freq;
  326. ret = __adis_write_reg_16(&st->adis, ADIS16495_REG_SYNC_SCALE, sync_scale);
  327. if (ret)
  328. goto error;
  329. sample_rate = scaled_rate;
  330. }
  331. t = DIV_ROUND_CLOSEST(sample_rate, t);
  332. if (t)
  333. t--;
  334. if (t > st->chip_info->max_dec_rate)
  335. t = st->chip_info->max_dec_rate;
  336. ret = __adis_write_reg_16(&st->adis, ADIS16480_REG_DEC_RATE, t);
  337. error:
  338. adis_dev_unlock(&st->adis);
  339. return ret;
  340. }
  341. static int adis16480_get_freq(struct iio_dev *indio_dev, int *val, int *val2)
  342. {
  343. struct adis16480 *st = iio_priv(indio_dev);
  344. uint16_t t;
  345. int ret;
  346. unsigned int freq, sample_rate = st->clk_freq;
  347. adis_dev_lock(&st->adis);
  348. if (st->clk_mode == ADIS16480_CLK_PPS) {
  349. u16 sync_scale;
  350. ret = __adis_read_reg_16(&st->adis, ADIS16495_REG_SYNC_SCALE, &sync_scale);
  351. if (ret)
  352. goto error;
  353. sample_rate = st->clk_freq * sync_scale;
  354. }
  355. ret = __adis_read_reg_16(&st->adis, ADIS16480_REG_DEC_RATE, &t);
  356. if (ret)
  357. goto error;
  358. adis_dev_unlock(&st->adis);
  359. freq = DIV_ROUND_CLOSEST(sample_rate, (t + 1));
  360. *val = freq / 1000;
  361. *val2 = (freq % 1000) * 1000;
  362. return IIO_VAL_INT_PLUS_MICRO;
  363. error:
  364. adis_dev_unlock(&st->adis);
  365. return ret;
  366. }
  367. enum {
  368. ADIS16480_SCAN_GYRO_X,
  369. ADIS16480_SCAN_GYRO_Y,
  370. ADIS16480_SCAN_GYRO_Z,
  371. ADIS16480_SCAN_ACCEL_X,
  372. ADIS16480_SCAN_ACCEL_Y,
  373. ADIS16480_SCAN_ACCEL_Z,
  374. ADIS16480_SCAN_MAGN_X,
  375. ADIS16480_SCAN_MAGN_Y,
  376. ADIS16480_SCAN_MAGN_Z,
  377. ADIS16480_SCAN_BARO,
  378. ADIS16480_SCAN_TEMP,
  379. };
  380. static const unsigned int adis16480_calibbias_regs[] = {
  381. [ADIS16480_SCAN_GYRO_X] = ADIS16480_REG_X_GYRO_BIAS,
  382. [ADIS16480_SCAN_GYRO_Y] = ADIS16480_REG_Y_GYRO_BIAS,
  383. [ADIS16480_SCAN_GYRO_Z] = ADIS16480_REG_Z_GYRO_BIAS,
  384. [ADIS16480_SCAN_ACCEL_X] = ADIS16480_REG_X_ACCEL_BIAS,
  385. [ADIS16480_SCAN_ACCEL_Y] = ADIS16480_REG_Y_ACCEL_BIAS,
  386. [ADIS16480_SCAN_ACCEL_Z] = ADIS16480_REG_Z_ACCEL_BIAS,
  387. [ADIS16480_SCAN_MAGN_X] = ADIS16480_REG_X_HARD_IRON,
  388. [ADIS16480_SCAN_MAGN_Y] = ADIS16480_REG_Y_HARD_IRON,
  389. [ADIS16480_SCAN_MAGN_Z] = ADIS16480_REG_Z_HARD_IRON,
  390. [ADIS16480_SCAN_BARO] = ADIS16480_REG_BAROM_BIAS,
  391. };
  392. static const unsigned int adis16480_calibscale_regs[] = {
  393. [ADIS16480_SCAN_GYRO_X] = ADIS16480_REG_X_GYRO_SCALE,
  394. [ADIS16480_SCAN_GYRO_Y] = ADIS16480_REG_Y_GYRO_SCALE,
  395. [ADIS16480_SCAN_GYRO_Z] = ADIS16480_REG_Z_GYRO_SCALE,
  396. [ADIS16480_SCAN_ACCEL_X] = ADIS16480_REG_X_ACCEL_SCALE,
  397. [ADIS16480_SCAN_ACCEL_Y] = ADIS16480_REG_Y_ACCEL_SCALE,
  398. [ADIS16480_SCAN_ACCEL_Z] = ADIS16480_REG_Z_ACCEL_SCALE,
  399. };
  400. static int adis16480_set_calibbias(struct iio_dev *indio_dev,
  401. const struct iio_chan_spec *chan, int bias)
  402. {
  403. unsigned int reg = adis16480_calibbias_regs[chan->scan_index];
  404. struct adis16480 *st = iio_priv(indio_dev);
  405. switch (chan->type) {
  406. case IIO_MAGN:
  407. case IIO_PRESSURE:
  408. if (bias < -0x8000 || bias >= 0x8000)
  409. return -EINVAL;
  410. return adis_write_reg_16(&st->adis, reg, bias);
  411. case IIO_ANGL_VEL:
  412. case IIO_ACCEL:
  413. return adis_write_reg_32(&st->adis, reg, bias);
  414. default:
  415. break;
  416. }
  417. return -EINVAL;
  418. }
  419. static int adis16480_get_calibbias(struct iio_dev *indio_dev,
  420. const struct iio_chan_spec *chan, int *bias)
  421. {
  422. unsigned int reg = adis16480_calibbias_regs[chan->scan_index];
  423. struct adis16480 *st = iio_priv(indio_dev);
  424. uint16_t val16;
  425. uint32_t val32;
  426. int ret;
  427. switch (chan->type) {
  428. case IIO_MAGN:
  429. case IIO_PRESSURE:
  430. ret = adis_read_reg_16(&st->adis, reg, &val16);
  431. if (ret == 0)
  432. *bias = sign_extend32(val16, 15);
  433. break;
  434. case IIO_ANGL_VEL:
  435. case IIO_ACCEL:
  436. ret = adis_read_reg_32(&st->adis, reg, &val32);
  437. if (ret == 0)
  438. *bias = sign_extend32(val32, 31);
  439. break;
  440. default:
  441. ret = -EINVAL;
  442. }
  443. if (ret)
  444. return ret;
  445. return IIO_VAL_INT;
  446. }
  447. static int adis16480_set_calibscale(struct iio_dev *indio_dev,
  448. const struct iio_chan_spec *chan, int scale)
  449. {
  450. unsigned int reg = adis16480_calibscale_regs[chan->scan_index];
  451. struct adis16480 *st = iio_priv(indio_dev);
  452. if (scale < -0x8000 || scale >= 0x8000)
  453. return -EINVAL;
  454. return adis_write_reg_16(&st->adis, reg, scale);
  455. }
  456. static int adis16480_get_calibscale(struct iio_dev *indio_dev,
  457. const struct iio_chan_spec *chan, int *scale)
  458. {
  459. unsigned int reg = adis16480_calibscale_regs[chan->scan_index];
  460. struct adis16480 *st = iio_priv(indio_dev);
  461. uint16_t val16;
  462. int ret;
  463. ret = adis_read_reg_16(&st->adis, reg, &val16);
  464. if (ret)
  465. return ret;
  466. *scale = sign_extend32(val16, 15);
  467. return IIO_VAL_INT;
  468. }
  469. static const unsigned int adis16480_def_filter_freqs[] = {
  470. 310,
  471. 55,
  472. 275,
  473. 63,
  474. };
  475. static const unsigned int adis16495_def_filter_freqs[] = {
  476. 300,
  477. 100,
  478. 300,
  479. 100,
  480. };
  481. static const unsigned int ad16480_filter_data[][2] = {
  482. [ADIS16480_SCAN_GYRO_X] = { ADIS16480_REG_FILTER_BNK0, 0 },
  483. [ADIS16480_SCAN_GYRO_Y] = { ADIS16480_REG_FILTER_BNK0, 3 },
  484. [ADIS16480_SCAN_GYRO_Z] = { ADIS16480_REG_FILTER_BNK0, 6 },
  485. [ADIS16480_SCAN_ACCEL_X] = { ADIS16480_REG_FILTER_BNK0, 9 },
  486. [ADIS16480_SCAN_ACCEL_Y] = { ADIS16480_REG_FILTER_BNK0, 12 },
  487. [ADIS16480_SCAN_ACCEL_Z] = { ADIS16480_REG_FILTER_BNK1, 0 },
  488. [ADIS16480_SCAN_MAGN_X] = { ADIS16480_REG_FILTER_BNK1, 3 },
  489. [ADIS16480_SCAN_MAGN_Y] = { ADIS16480_REG_FILTER_BNK1, 6 },
  490. [ADIS16480_SCAN_MAGN_Z] = { ADIS16480_REG_FILTER_BNK1, 9 },
  491. };
  492. static int adis16480_get_filter_freq(struct iio_dev *indio_dev,
  493. const struct iio_chan_spec *chan, int *freq)
  494. {
  495. struct adis16480 *st = iio_priv(indio_dev);
  496. unsigned int enable_mask, offset, reg;
  497. uint16_t val;
  498. int ret;
  499. reg = ad16480_filter_data[chan->scan_index][0];
  500. offset = ad16480_filter_data[chan->scan_index][1];
  501. enable_mask = BIT(offset + 2);
  502. ret = adis_read_reg_16(&st->adis, reg, &val);
  503. if (ret)
  504. return ret;
  505. if (!(val & enable_mask))
  506. *freq = 0;
  507. else
  508. *freq = st->chip_info->filter_freqs[(val >> offset) & 0x3];
  509. return IIO_VAL_INT;
  510. }
  511. static int adis16480_set_filter_freq(struct iio_dev *indio_dev,
  512. const struct iio_chan_spec *chan, unsigned int freq)
  513. {
  514. struct adis16480 *st = iio_priv(indio_dev);
  515. unsigned int enable_mask, offset, reg;
  516. unsigned int diff, best_diff;
  517. unsigned int i, best_freq;
  518. uint16_t val;
  519. int ret;
  520. reg = ad16480_filter_data[chan->scan_index][0];
  521. offset = ad16480_filter_data[chan->scan_index][1];
  522. enable_mask = BIT(offset + 2);
  523. adis_dev_lock(&st->adis);
  524. ret = __adis_read_reg_16(&st->adis, reg, &val);
  525. if (ret)
  526. goto out_unlock;
  527. if (freq == 0) {
  528. val &= ~enable_mask;
  529. } else {
  530. best_freq = 0;
  531. best_diff = st->chip_info->filter_freqs[0];
  532. for (i = 0; i < ARRAY_SIZE(adis16480_def_filter_freqs); i++) {
  533. if (st->chip_info->filter_freqs[i] >= freq) {
  534. diff = st->chip_info->filter_freqs[i] - freq;
  535. if (diff < best_diff) {
  536. best_diff = diff;
  537. best_freq = i;
  538. }
  539. }
  540. }
  541. val &= ~(0x3 << offset);
  542. val |= best_freq << offset;
  543. val |= enable_mask;
  544. }
  545. ret = __adis_write_reg_16(&st->adis, reg, val);
  546. out_unlock:
  547. adis_dev_unlock(&st->adis);
  548. return ret;
  549. }
  550. static int adis16480_read_raw(struct iio_dev *indio_dev,
  551. const struct iio_chan_spec *chan, int *val, int *val2, long info)
  552. {
  553. struct adis16480 *st = iio_priv(indio_dev);
  554. unsigned int temp;
  555. switch (info) {
  556. case IIO_CHAN_INFO_RAW:
  557. return adis_single_conversion(indio_dev, chan, 0, val);
  558. case IIO_CHAN_INFO_SCALE:
  559. switch (chan->type) {
  560. case IIO_ANGL_VEL:
  561. *val = st->chip_info->gyro_max_scale;
  562. *val2 = st->chip_info->gyro_max_val;
  563. return IIO_VAL_FRACTIONAL;
  564. case IIO_ACCEL:
  565. *val = st->chip_info->accel_max_scale;
  566. *val2 = st->chip_info->accel_max_val;
  567. return IIO_VAL_FRACTIONAL;
  568. case IIO_MAGN:
  569. *val = 0;
  570. *val2 = 100; /* 0.0001 gauss */
  571. return IIO_VAL_INT_PLUS_MICRO;
  572. case IIO_TEMP:
  573. /*
  574. * +85 degrees Celsius = temp_max_scale
  575. * +25 degrees Celsius = 0
  576. * LSB, 25 degrees Celsius = 60 / temp_max_scale
  577. */
  578. *val = st->chip_info->temp_scale / 1000;
  579. *val2 = (st->chip_info->temp_scale % 1000) * 1000;
  580. return IIO_VAL_INT_PLUS_MICRO;
  581. case IIO_PRESSURE:
  582. /*
  583. * max scale is 1310 mbar
  584. * max raw value is 32767 shifted for 32bits
  585. */
  586. *val = 131; /* 1310mbar = 131 kPa */
  587. *val2 = 32767 << 16;
  588. return IIO_VAL_FRACTIONAL;
  589. default:
  590. return -EINVAL;
  591. }
  592. case IIO_CHAN_INFO_OFFSET:
  593. /* Only the temperature channel has a offset */
  594. temp = 25 * 1000000LL; /* 25 degree Celsius = 0x0000 */
  595. *val = DIV_ROUND_CLOSEST_ULL(temp, st->chip_info->temp_scale);
  596. return IIO_VAL_INT;
  597. case IIO_CHAN_INFO_CALIBBIAS:
  598. return adis16480_get_calibbias(indio_dev, chan, val);
  599. case IIO_CHAN_INFO_CALIBSCALE:
  600. return adis16480_get_calibscale(indio_dev, chan, val);
  601. case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY:
  602. return adis16480_get_filter_freq(indio_dev, chan, val);
  603. case IIO_CHAN_INFO_SAMP_FREQ:
  604. return adis16480_get_freq(indio_dev, val, val2);
  605. default:
  606. return -EINVAL;
  607. }
  608. }
  609. static int adis16480_write_raw(struct iio_dev *indio_dev,
  610. const struct iio_chan_spec *chan, int val, int val2, long info)
  611. {
  612. switch (info) {
  613. case IIO_CHAN_INFO_CALIBBIAS:
  614. return adis16480_set_calibbias(indio_dev, chan, val);
  615. case IIO_CHAN_INFO_CALIBSCALE:
  616. return adis16480_set_calibscale(indio_dev, chan, val);
  617. case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY:
  618. return adis16480_set_filter_freq(indio_dev, chan, val);
  619. case IIO_CHAN_INFO_SAMP_FREQ:
  620. return adis16480_set_freq(indio_dev, val, val2);
  621. default:
  622. return -EINVAL;
  623. }
  624. }
  625. #define ADIS16480_MOD_CHANNEL(_type, _mod, _address, _si, _info_sep, _bits) \
  626. { \
  627. .type = (_type), \
  628. .modified = 1, \
  629. .channel2 = (_mod), \
  630. .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
  631. BIT(IIO_CHAN_INFO_CALIBBIAS) | \
  632. _info_sep, \
  633. .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
  634. .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), \
  635. .address = (_address), \
  636. .scan_index = (_si), \
  637. .scan_type = { \
  638. .sign = 's', \
  639. .realbits = (_bits), \
  640. .storagebits = (_bits), \
  641. .endianness = IIO_BE, \
  642. }, \
  643. }
  644. #define ADIS16480_GYRO_CHANNEL(_mod) \
  645. ADIS16480_MOD_CHANNEL(IIO_ANGL_VEL, IIO_MOD_ ## _mod, \
  646. ADIS16480_REG_ ## _mod ## _GYRO_OUT, ADIS16480_SCAN_GYRO_ ## _mod, \
  647. BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY) | \
  648. BIT(IIO_CHAN_INFO_CALIBSCALE), \
  649. 32)
  650. #define ADIS16480_ACCEL_CHANNEL(_mod) \
  651. ADIS16480_MOD_CHANNEL(IIO_ACCEL, IIO_MOD_ ## _mod, \
  652. ADIS16480_REG_ ## _mod ## _ACCEL_OUT, ADIS16480_SCAN_ACCEL_ ## _mod, \
  653. BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY) | \
  654. BIT(IIO_CHAN_INFO_CALIBSCALE), \
  655. 32)
  656. #define ADIS16480_MAGN_CHANNEL(_mod) \
  657. ADIS16480_MOD_CHANNEL(IIO_MAGN, IIO_MOD_ ## _mod, \
  658. ADIS16480_REG_ ## _mod ## _MAGN_OUT, ADIS16480_SCAN_MAGN_ ## _mod, \
  659. BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY), \
  660. 16)
  661. #define ADIS16480_PRESSURE_CHANNEL() \
  662. { \
  663. .type = IIO_PRESSURE, \
  664. .indexed = 1, \
  665. .channel = 0, \
  666. .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
  667. BIT(IIO_CHAN_INFO_CALIBBIAS) | \
  668. BIT(IIO_CHAN_INFO_SCALE), \
  669. .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), \
  670. .address = ADIS16480_REG_BAROM_OUT, \
  671. .scan_index = ADIS16480_SCAN_BARO, \
  672. .scan_type = { \
  673. .sign = 's', \
  674. .realbits = 32, \
  675. .storagebits = 32, \
  676. .endianness = IIO_BE, \
  677. }, \
  678. }
  679. #define ADIS16480_TEMP_CHANNEL() { \
  680. .type = IIO_TEMP, \
  681. .indexed = 1, \
  682. .channel = 0, \
  683. .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
  684. BIT(IIO_CHAN_INFO_SCALE) | \
  685. BIT(IIO_CHAN_INFO_OFFSET), \
  686. .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), \
  687. .address = ADIS16480_REG_TEMP_OUT, \
  688. .scan_index = ADIS16480_SCAN_TEMP, \
  689. .scan_type = { \
  690. .sign = 's', \
  691. .realbits = 16, \
  692. .storagebits = 16, \
  693. .endianness = IIO_BE, \
  694. }, \
  695. }
  696. static const struct iio_chan_spec adis16480_channels[] = {
  697. ADIS16480_GYRO_CHANNEL(X),
  698. ADIS16480_GYRO_CHANNEL(Y),
  699. ADIS16480_GYRO_CHANNEL(Z),
  700. ADIS16480_ACCEL_CHANNEL(X),
  701. ADIS16480_ACCEL_CHANNEL(Y),
  702. ADIS16480_ACCEL_CHANNEL(Z),
  703. ADIS16480_MAGN_CHANNEL(X),
  704. ADIS16480_MAGN_CHANNEL(Y),
  705. ADIS16480_MAGN_CHANNEL(Z),
  706. ADIS16480_PRESSURE_CHANNEL(),
  707. ADIS16480_TEMP_CHANNEL(),
  708. IIO_CHAN_SOFT_TIMESTAMP(11)
  709. };
  710. static const struct iio_chan_spec adis16485_channels[] = {
  711. ADIS16480_GYRO_CHANNEL(X),
  712. ADIS16480_GYRO_CHANNEL(Y),
  713. ADIS16480_GYRO_CHANNEL(Z),
  714. ADIS16480_ACCEL_CHANNEL(X),
  715. ADIS16480_ACCEL_CHANNEL(Y),
  716. ADIS16480_ACCEL_CHANNEL(Z),
  717. ADIS16480_TEMP_CHANNEL(),
  718. IIO_CHAN_SOFT_TIMESTAMP(7)
  719. };
  720. enum adis16480_variant {
  721. ADIS16375,
  722. ADIS16480,
  723. ADIS16485,
  724. ADIS16488,
  725. ADIS16490,
  726. ADIS16495_1,
  727. ADIS16495_2,
  728. ADIS16495_3,
  729. ADIS16497_1,
  730. ADIS16497_2,
  731. ADIS16497_3,
  732. };
  733. #define ADIS16480_DIAG_STAT_XGYRO_FAIL 0
  734. #define ADIS16480_DIAG_STAT_YGYRO_FAIL 1
  735. #define ADIS16480_DIAG_STAT_ZGYRO_FAIL 2
  736. #define ADIS16480_DIAG_STAT_XACCL_FAIL 3
  737. #define ADIS16480_DIAG_STAT_YACCL_FAIL 4
  738. #define ADIS16480_DIAG_STAT_ZACCL_FAIL 5
  739. #define ADIS16480_DIAG_STAT_XMAGN_FAIL 8
  740. #define ADIS16480_DIAG_STAT_YMAGN_FAIL 9
  741. #define ADIS16480_DIAG_STAT_ZMAGN_FAIL 10
  742. #define ADIS16480_DIAG_STAT_BARO_FAIL 11
  743. static const char * const adis16480_status_error_msgs[] = {
  744. [ADIS16480_DIAG_STAT_XGYRO_FAIL] = "X-axis gyroscope self-test failure",
  745. [ADIS16480_DIAG_STAT_YGYRO_FAIL] = "Y-axis gyroscope self-test failure",
  746. [ADIS16480_DIAG_STAT_ZGYRO_FAIL] = "Z-axis gyroscope self-test failure",
  747. [ADIS16480_DIAG_STAT_XACCL_FAIL] = "X-axis accelerometer self-test failure",
  748. [ADIS16480_DIAG_STAT_YACCL_FAIL] = "Y-axis accelerometer self-test failure",
  749. [ADIS16480_DIAG_STAT_ZACCL_FAIL] = "Z-axis accelerometer self-test failure",
  750. [ADIS16480_DIAG_STAT_XMAGN_FAIL] = "X-axis magnetometer self-test failure",
  751. [ADIS16480_DIAG_STAT_YMAGN_FAIL] = "Y-axis magnetometer self-test failure",
  752. [ADIS16480_DIAG_STAT_ZMAGN_FAIL] = "Z-axis magnetometer self-test failure",
  753. [ADIS16480_DIAG_STAT_BARO_FAIL] = "Barometer self-test failure",
  754. };
  755. static int adis16480_enable_irq(struct adis *adis, bool enable);
  756. #define ADIS16480_DATA(_prod_id, _timeouts, _burst_len) \
  757. { \
  758. .diag_stat_reg = ADIS16480_REG_DIAG_STS, \
  759. .glob_cmd_reg = ADIS16480_REG_GLOB_CMD, \
  760. .prod_id_reg = ADIS16480_REG_PROD_ID, \
  761. .prod_id = (_prod_id), \
  762. .has_paging = true, \
  763. .read_delay = 5, \
  764. .write_delay = 5, \
  765. .self_test_mask = BIT(1), \
  766. .self_test_reg = ADIS16480_REG_GLOB_CMD, \
  767. .status_error_msgs = adis16480_status_error_msgs, \
  768. .status_error_mask = BIT(ADIS16480_DIAG_STAT_XGYRO_FAIL) | \
  769. BIT(ADIS16480_DIAG_STAT_YGYRO_FAIL) | \
  770. BIT(ADIS16480_DIAG_STAT_ZGYRO_FAIL) | \
  771. BIT(ADIS16480_DIAG_STAT_XACCL_FAIL) | \
  772. BIT(ADIS16480_DIAG_STAT_YACCL_FAIL) | \
  773. BIT(ADIS16480_DIAG_STAT_ZACCL_FAIL) | \
  774. BIT(ADIS16480_DIAG_STAT_XMAGN_FAIL) | \
  775. BIT(ADIS16480_DIAG_STAT_YMAGN_FAIL) | \
  776. BIT(ADIS16480_DIAG_STAT_ZMAGN_FAIL) | \
  777. BIT(ADIS16480_DIAG_STAT_BARO_FAIL), \
  778. .enable_irq = adis16480_enable_irq, \
  779. .timeouts = (_timeouts), \
  780. .burst_reg_cmd = ADIS16495_REG_BURST_CMD, \
  781. .burst_len = (_burst_len), \
  782. .burst_max_speed_hz = ADIS16495_BURST_MAX_SPEED \
  783. }
  784. static const struct adis_timeout adis16485_timeouts = {
  785. .reset_ms = 560,
  786. .sw_reset_ms = 120,
  787. .self_test_ms = 12,
  788. };
  789. static const struct adis_timeout adis16480_timeouts = {
  790. .reset_ms = 560,
  791. .sw_reset_ms = 560,
  792. .self_test_ms = 12,
  793. };
  794. static const struct adis_timeout adis16495_timeouts = {
  795. .reset_ms = 170,
  796. .sw_reset_ms = 130,
  797. .self_test_ms = 40,
  798. };
  799. static const struct adis_timeout adis16495_1_timeouts = {
  800. .reset_ms = 250,
  801. .sw_reset_ms = 210,
  802. .self_test_ms = 20,
  803. };
  804. static const struct adis16480_chip_info adis16480_chip_info[] = {
  805. [ADIS16375] = {
  806. .channels = adis16485_channels,
  807. .num_channels = ARRAY_SIZE(adis16485_channels),
  808. /*
  809. * Typically we do IIO_RAD_TO_DEGREE in the denominator, which
  810. * is exactly the same as IIO_DEGREE_TO_RAD in numerator, since
  811. * it gives better approximation. However, in this case we
  812. * cannot do it since it would not fit in a 32bit variable.
  813. */
  814. .gyro_max_val = 22887 << 16,
  815. .gyro_max_scale = IIO_DEGREE_TO_RAD(300),
  816. .accel_max_val = IIO_M_S_2_TO_G(21973 << 16),
  817. .accel_max_scale = 18,
  818. .temp_scale = 5650, /* 5.65 milli degree Celsius */
  819. .int_clk = 2460000,
  820. .max_dec_rate = 2048,
  821. .has_sleep_cnt = true,
  822. .filter_freqs = adis16480_def_filter_freqs,
  823. .adis_data = ADIS16480_DATA(16375, &adis16485_timeouts, 0),
  824. },
  825. [ADIS16480] = {
  826. .channels = adis16480_channels,
  827. .num_channels = ARRAY_SIZE(adis16480_channels),
  828. .gyro_max_val = 22500 << 16,
  829. .gyro_max_scale = IIO_DEGREE_TO_RAD(450),
  830. .accel_max_val = IIO_M_S_2_TO_G(12500 << 16),
  831. .accel_max_scale = 10,
  832. .temp_scale = 5650, /* 5.65 milli degree Celsius */
  833. .int_clk = 2460000,
  834. .max_dec_rate = 2048,
  835. .has_sleep_cnt = true,
  836. .filter_freqs = adis16480_def_filter_freqs,
  837. .adis_data = ADIS16480_DATA(16480, &adis16480_timeouts, 0),
  838. },
  839. [ADIS16485] = {
  840. .channels = adis16485_channels,
  841. .num_channels = ARRAY_SIZE(adis16485_channels),
  842. .gyro_max_val = 22500 << 16,
  843. .gyro_max_scale = IIO_DEGREE_TO_RAD(450),
  844. .accel_max_val = IIO_M_S_2_TO_G(20000 << 16),
  845. .accel_max_scale = 5,
  846. .temp_scale = 5650, /* 5.65 milli degree Celsius */
  847. .int_clk = 2460000,
  848. .max_dec_rate = 2048,
  849. .has_sleep_cnt = true,
  850. .filter_freqs = adis16480_def_filter_freqs,
  851. .adis_data = ADIS16480_DATA(16485, &adis16485_timeouts, 0),
  852. },
  853. [ADIS16488] = {
  854. .channels = adis16480_channels,
  855. .num_channels = ARRAY_SIZE(adis16480_channels),
  856. .gyro_max_val = 22500 << 16,
  857. .gyro_max_scale = IIO_DEGREE_TO_RAD(450),
  858. .accel_max_val = IIO_M_S_2_TO_G(22500 << 16),
  859. .accel_max_scale = 18,
  860. .temp_scale = 5650, /* 5.65 milli degree Celsius */
  861. .int_clk = 2460000,
  862. .max_dec_rate = 2048,
  863. .has_sleep_cnt = true,
  864. .filter_freqs = adis16480_def_filter_freqs,
  865. .adis_data = ADIS16480_DATA(16488, &adis16485_timeouts, 0),
  866. },
  867. [ADIS16490] = {
  868. .channels = adis16485_channels,
  869. .num_channels = ARRAY_SIZE(adis16485_channels),
  870. .gyro_max_val = 20000 << 16,
  871. .gyro_max_scale = IIO_DEGREE_TO_RAD(100),
  872. .accel_max_val = IIO_M_S_2_TO_G(16000 << 16),
  873. .accel_max_scale = 8,
  874. .temp_scale = 14285, /* 14.285 milli degree Celsius */
  875. .int_clk = 4250000,
  876. .max_dec_rate = 4250,
  877. .filter_freqs = adis16495_def_filter_freqs,
  878. .has_pps_clk_mode = true,
  879. .adis_data = ADIS16480_DATA(16490, &adis16495_timeouts, 0),
  880. },
  881. [ADIS16495_1] = {
  882. .channels = adis16485_channels,
  883. .num_channels = ARRAY_SIZE(adis16485_channels),
  884. .gyro_max_val = 20000 << 16,
  885. .gyro_max_scale = IIO_DEGREE_TO_RAD(125),
  886. .accel_max_val = IIO_M_S_2_TO_G(32000 << 16),
  887. .accel_max_scale = 8,
  888. .temp_scale = 12500, /* 12.5 milli degree Celsius */
  889. .int_clk = 4250000,
  890. .max_dec_rate = 4250,
  891. .filter_freqs = adis16495_def_filter_freqs,
  892. .has_pps_clk_mode = true,
  893. /* 20 elements of 16bits */
  894. .adis_data = ADIS16480_DATA(16495, &adis16495_1_timeouts,
  895. ADIS16495_BURST_MAX_DATA * 2),
  896. },
  897. [ADIS16495_2] = {
  898. .channels = adis16485_channels,
  899. .num_channels = ARRAY_SIZE(adis16485_channels),
  900. .gyro_max_val = 18000 << 16,
  901. .gyro_max_scale = IIO_DEGREE_TO_RAD(450),
  902. .accel_max_val = IIO_M_S_2_TO_G(32000 << 16),
  903. .accel_max_scale = 8,
  904. .temp_scale = 12500, /* 12.5 milli degree Celsius */
  905. .int_clk = 4250000,
  906. .max_dec_rate = 4250,
  907. .filter_freqs = adis16495_def_filter_freqs,
  908. .has_pps_clk_mode = true,
  909. /* 20 elements of 16bits */
  910. .adis_data = ADIS16480_DATA(16495, &adis16495_1_timeouts,
  911. ADIS16495_BURST_MAX_DATA * 2),
  912. },
  913. [ADIS16495_3] = {
  914. .channels = adis16485_channels,
  915. .num_channels = ARRAY_SIZE(adis16485_channels),
  916. .gyro_max_val = 20000 << 16,
  917. .gyro_max_scale = IIO_DEGREE_TO_RAD(2000),
  918. .accel_max_val = IIO_M_S_2_TO_G(32000 << 16),
  919. .accel_max_scale = 8,
  920. .temp_scale = 12500, /* 12.5 milli degree Celsius */
  921. .int_clk = 4250000,
  922. .max_dec_rate = 4250,
  923. .filter_freqs = adis16495_def_filter_freqs,
  924. .has_pps_clk_mode = true,
  925. /* 20 elements of 16bits */
  926. .adis_data = ADIS16480_DATA(16495, &adis16495_1_timeouts,
  927. ADIS16495_BURST_MAX_DATA * 2),
  928. },
  929. [ADIS16497_1] = {
  930. .channels = adis16485_channels,
  931. .num_channels = ARRAY_SIZE(adis16485_channels),
  932. .gyro_max_val = 20000 << 16,
  933. .gyro_max_scale = IIO_DEGREE_TO_RAD(125),
  934. .accel_max_val = IIO_M_S_2_TO_G(32000 << 16),
  935. .accel_max_scale = 40,
  936. .temp_scale = 12500, /* 12.5 milli degree Celsius */
  937. .int_clk = 4250000,
  938. .max_dec_rate = 4250,
  939. .filter_freqs = adis16495_def_filter_freqs,
  940. .has_pps_clk_mode = true,
  941. /* 20 elements of 16bits */
  942. .adis_data = ADIS16480_DATA(16497, &adis16495_1_timeouts,
  943. ADIS16495_BURST_MAX_DATA * 2),
  944. },
  945. [ADIS16497_2] = {
  946. .channels = adis16485_channels,
  947. .num_channels = ARRAY_SIZE(adis16485_channels),
  948. .gyro_max_val = 18000 << 16,
  949. .gyro_max_scale = IIO_DEGREE_TO_RAD(450),
  950. .accel_max_val = IIO_M_S_2_TO_G(32000 << 16),
  951. .accel_max_scale = 40,
  952. .temp_scale = 12500, /* 12.5 milli degree Celsius */
  953. .int_clk = 4250000,
  954. .max_dec_rate = 4250,
  955. .filter_freqs = adis16495_def_filter_freqs,
  956. .has_pps_clk_mode = true,
  957. /* 20 elements of 16bits */
  958. .adis_data = ADIS16480_DATA(16497, &adis16495_1_timeouts,
  959. ADIS16495_BURST_MAX_DATA * 2),
  960. },
  961. [ADIS16497_3] = {
  962. .channels = adis16485_channels,
  963. .num_channels = ARRAY_SIZE(adis16485_channels),
  964. .gyro_max_val = 20000 << 16,
  965. .gyro_max_scale = IIO_DEGREE_TO_RAD(2000),
  966. .accel_max_val = IIO_M_S_2_TO_G(32000 << 16),
  967. .accel_max_scale = 40,
  968. .temp_scale = 12500, /* 12.5 milli degree Celsius */
  969. .int_clk = 4250000,
  970. .max_dec_rate = 4250,
  971. .filter_freqs = adis16495_def_filter_freqs,
  972. .has_pps_clk_mode = true,
  973. /* 20 elements of 16bits */
  974. .adis_data = ADIS16480_DATA(16497, &adis16495_1_timeouts,
  975. ADIS16495_BURST_MAX_DATA * 2),
  976. },
  977. };
  978. static bool adis16480_validate_crc(const u16 *buf, const u8 n_elem, const u32 crc)
  979. {
  980. u32 crc_calc;
  981. u16 crc_buf[15];
  982. int j;
  983. for (j = 0; j < n_elem; j++)
  984. crc_buf[j] = swab16(buf[j]);
  985. crc_calc = crc32(~0, crc_buf, n_elem * 2);
  986. crc_calc ^= ~0;
  987. return (crc == crc_calc);
  988. }
  989. static irqreturn_t adis16480_trigger_handler(int irq, void *p)
  990. {
  991. struct iio_poll_func *pf = p;
  992. struct iio_dev *indio_dev = pf->indio_dev;
  993. struct adis16480 *st = iio_priv(indio_dev);
  994. struct adis *adis = &st->adis;
  995. struct device *dev = &adis->spi->dev;
  996. int ret, bit, offset, i = 0;
  997. __be16 *buffer;
  998. u32 crc;
  999. bool valid;
  1000. adis_dev_lock(adis);
  1001. if (adis->current_page != 0) {
  1002. adis->tx[0] = ADIS_WRITE_REG(ADIS_REG_PAGE_ID);
  1003. adis->tx[1] = 0;
  1004. ret = spi_write(adis->spi, adis->tx, 2);
  1005. if (ret) {
  1006. dev_err(dev, "Failed to change device page: %d\n", ret);
  1007. adis_dev_unlock(adis);
  1008. goto irq_done;
  1009. }
  1010. adis->current_page = 0;
  1011. }
  1012. ret = spi_sync(adis->spi, &adis->msg);
  1013. if (ret) {
  1014. dev_err(dev, "Failed to read data: %d\n", ret);
  1015. adis_dev_unlock(adis);
  1016. goto irq_done;
  1017. }
  1018. adis_dev_unlock(adis);
  1019. /*
  1020. * After making the burst request, the response can have one or two
  1021. * 16-bit responses containing the BURST_ID depending on the sclk. If
  1022. * clk > 3.6MHz, then we will have two BURST_ID in a row. If clk < 3MHZ,
  1023. * we have only one. To manage that variation, we use the transition from the
  1024. * BURST_ID to the SYS_E_FLAG register, which will not be equal to 0xA5A5. If
  1025. * we not find this variation in the first 4 segments, then the data should
  1026. * not be valid.
  1027. */
  1028. buffer = adis->buffer;
  1029. for (offset = 0; offset < 4; offset++) {
  1030. u16 curr = be16_to_cpu(buffer[offset]);
  1031. u16 next = be16_to_cpu(buffer[offset + 1]);
  1032. if (curr == ADIS16495_BURST_ID && next != ADIS16495_BURST_ID) {
  1033. offset++;
  1034. break;
  1035. }
  1036. }
  1037. if (offset == 4) {
  1038. dev_err(dev, "Invalid burst data\n");
  1039. goto irq_done;
  1040. }
  1041. crc = be16_to_cpu(buffer[offset + 16]) << 16 | be16_to_cpu(buffer[offset + 15]);
  1042. valid = adis16480_validate_crc((u16 *)&buffer[offset], 15, crc);
  1043. if (!valid) {
  1044. dev_err(dev, "Invalid crc\n");
  1045. goto irq_done;
  1046. }
  1047. for_each_set_bit(bit, indio_dev->active_scan_mask, indio_dev->masklength) {
  1048. /*
  1049. * When burst mode is used, temperature is the first data
  1050. * channel in the sequence, but the temperature scan index
  1051. * is 10.
  1052. */
  1053. switch (bit) {
  1054. case ADIS16480_SCAN_TEMP:
  1055. st->data[i++] = buffer[offset + 1];
  1056. break;
  1057. case ADIS16480_SCAN_GYRO_X ... ADIS16480_SCAN_ACCEL_Z:
  1058. /* The lower register data is sequenced first */
  1059. st->data[i++] = buffer[2 * bit + offset + 3];
  1060. st->data[i++] = buffer[2 * bit + offset + 2];
  1061. break;
  1062. }
  1063. }
  1064. iio_push_to_buffers_with_timestamp(indio_dev, st->data, pf->timestamp);
  1065. irq_done:
  1066. iio_trigger_notify_done(indio_dev->trig);
  1067. return IRQ_HANDLED;
  1068. }
  1069. static const struct iio_info adis16480_info = {
  1070. .read_raw = &adis16480_read_raw,
  1071. .write_raw = &adis16480_write_raw,
  1072. .update_scan_mode = adis_update_scan_mode,
  1073. .debugfs_reg_access = adis_debugfs_reg_access,
  1074. };
  1075. static int adis16480_stop_device(struct iio_dev *indio_dev)
  1076. {
  1077. struct adis16480 *st = iio_priv(indio_dev);
  1078. struct device *dev = &st->adis.spi->dev;
  1079. int ret;
  1080. ret = adis_write_reg_16(&st->adis, ADIS16480_REG_SLP_CNT, BIT(9));
  1081. if (ret)
  1082. dev_err(dev, "Could not power down device: %d\n", ret);
  1083. return ret;
  1084. }
  1085. static int adis16480_enable_irq(struct adis *adis, bool enable)
  1086. {
  1087. uint16_t val;
  1088. int ret;
  1089. ret = __adis_read_reg_16(adis, ADIS16480_REG_FNCTIO_CTRL, &val);
  1090. if (ret)
  1091. return ret;
  1092. val &= ~ADIS16480_DRDY_EN_MSK;
  1093. val |= ADIS16480_DRDY_EN(enable);
  1094. return __adis_write_reg_16(adis, ADIS16480_REG_FNCTIO_CTRL, val);
  1095. }
  1096. static int adis16480_config_irq_pin(struct adis16480 *st)
  1097. {
  1098. struct device *dev = &st->adis.spi->dev;
  1099. struct fwnode_handle *fwnode = dev_fwnode(dev);
  1100. struct irq_data *desc;
  1101. enum adis16480_int_pin pin;
  1102. unsigned int irq_type;
  1103. uint16_t val;
  1104. int i, irq = 0;
  1105. desc = irq_get_irq_data(st->adis.spi->irq);
  1106. if (!desc) {
  1107. dev_err(dev, "Could not find IRQ %d\n", irq);
  1108. return -EINVAL;
  1109. }
  1110. /* Disable data ready since the default after reset is on */
  1111. val = ADIS16480_DRDY_EN(0);
  1112. /*
  1113. * Get the interrupt from the devicetre by reading the interrupt-names
  1114. * property. If it is not specified, use DIO1 pin as default.
  1115. * According to the datasheet, the factory default assigns DIO2 as data
  1116. * ready signal. However, in the previous versions of the driver, DIO1
  1117. * pin was used. So, we should leave it as is since some devices might
  1118. * be expecting the interrupt on the wrong physical pin.
  1119. */
  1120. pin = ADIS16480_PIN_DIO1;
  1121. for (i = 0; i < ARRAY_SIZE(adis16480_int_pin_names); i++) {
  1122. irq = fwnode_irq_get_byname(fwnode, adis16480_int_pin_names[i]);
  1123. if (irq > 0) {
  1124. pin = i;
  1125. break;
  1126. }
  1127. }
  1128. val |= ADIS16480_DRDY_SEL(pin);
  1129. /*
  1130. * Get the interrupt line behaviour. The data ready polarity can be
  1131. * configured as positive or negative, corresponding to
  1132. * IRQ_TYPE_EDGE_RISING or IRQ_TYPE_EDGE_FALLING respectively.
  1133. */
  1134. irq_type = irqd_get_trigger_type(desc);
  1135. if (irq_type == IRQ_TYPE_EDGE_RISING) { /* Default */
  1136. val |= ADIS16480_DRDY_POL(1);
  1137. } else if (irq_type == IRQ_TYPE_EDGE_FALLING) {
  1138. val |= ADIS16480_DRDY_POL(0);
  1139. } else {
  1140. dev_err(dev, "Invalid interrupt type 0x%x specified\n", irq_type);
  1141. return -EINVAL;
  1142. }
  1143. /* Write the data ready configuration to the FNCTIO_CTRL register */
  1144. return adis_write_reg_16(&st->adis, ADIS16480_REG_FNCTIO_CTRL, val);
  1145. }
  1146. static int adis16480_fw_get_ext_clk_pin(struct adis16480 *st)
  1147. {
  1148. struct device *dev = &st->adis.spi->dev;
  1149. const char *ext_clk_pin;
  1150. enum adis16480_int_pin pin;
  1151. int i;
  1152. pin = ADIS16480_PIN_DIO2;
  1153. if (device_property_read_string(dev, "adi,ext-clk-pin", &ext_clk_pin))
  1154. goto clk_input_not_found;
  1155. for (i = 0; i < ARRAY_SIZE(adis16480_int_pin_names); i++) {
  1156. if (strcasecmp(ext_clk_pin, adis16480_int_pin_names[i]) == 0)
  1157. return i;
  1158. }
  1159. clk_input_not_found:
  1160. dev_info(dev, "clk input line not specified, using DIO2\n");
  1161. return pin;
  1162. }
  1163. static int adis16480_ext_clk_config(struct adis16480 *st, bool enable)
  1164. {
  1165. struct device *dev = &st->adis.spi->dev;
  1166. unsigned int mode, mask;
  1167. enum adis16480_int_pin pin;
  1168. uint16_t val;
  1169. int ret;
  1170. ret = adis_read_reg_16(&st->adis, ADIS16480_REG_FNCTIO_CTRL, &val);
  1171. if (ret)
  1172. return ret;
  1173. pin = adis16480_fw_get_ext_clk_pin(st);
  1174. /*
  1175. * Each DIOx pin supports only one function at a time. When a single pin
  1176. * has two assignments, the enable bit for a lower priority function
  1177. * automatically resets to zero (disabling the lower priority function).
  1178. */
  1179. if (pin == ADIS16480_DRDY_SEL(val))
  1180. dev_warn(dev, "DIO%x pin supports only one function at a time\n", pin + 1);
  1181. mode = ADIS16480_SYNC_EN(enable) | ADIS16480_SYNC_SEL(pin);
  1182. mask = ADIS16480_SYNC_EN_MSK | ADIS16480_SYNC_SEL_MSK;
  1183. /* Only ADIS1649x devices support pps ext clock mode */
  1184. if (st->chip_info->has_pps_clk_mode) {
  1185. mode |= ADIS16480_SYNC_MODE(st->clk_mode);
  1186. mask |= ADIS16480_SYNC_MODE_MSK;
  1187. }
  1188. val &= ~mask;
  1189. val |= mode;
  1190. ret = adis_write_reg_16(&st->adis, ADIS16480_REG_FNCTIO_CTRL, val);
  1191. if (ret)
  1192. return ret;
  1193. return clk_prepare_enable(st->ext_clk);
  1194. }
  1195. static int adis16480_get_ext_clocks(struct adis16480 *st)
  1196. {
  1197. struct device *dev = &st->adis.spi->dev;
  1198. st->ext_clk = devm_clk_get_optional(dev, "sync");
  1199. if (IS_ERR(st->ext_clk))
  1200. return dev_err_probe(dev, PTR_ERR(st->ext_clk), "failed to get ext clk\n");
  1201. if (st->ext_clk) {
  1202. st->clk_mode = ADIS16480_CLK_SYNC;
  1203. return 0;
  1204. }
  1205. if (st->chip_info->has_pps_clk_mode) {
  1206. st->ext_clk = devm_clk_get_optional(dev, "pps");
  1207. if (IS_ERR(st->ext_clk))
  1208. return dev_err_probe(dev, PTR_ERR(st->ext_clk), "failed to get ext clk\n");
  1209. if (st->ext_clk) {
  1210. st->clk_mode = ADIS16480_CLK_PPS;
  1211. return 0;
  1212. }
  1213. }
  1214. st->clk_mode = ADIS16480_CLK_INT;
  1215. return 0;
  1216. }
  1217. static void adis16480_stop(void *data)
  1218. {
  1219. adis16480_stop_device(data);
  1220. }
  1221. static void adis16480_clk_disable(void *data)
  1222. {
  1223. clk_disable_unprepare(data);
  1224. }
  1225. static int adis16480_probe(struct spi_device *spi)
  1226. {
  1227. const struct spi_device_id *id = spi_get_device_id(spi);
  1228. const struct adis_data *adis16480_data;
  1229. irq_handler_t trigger_handler = NULL;
  1230. struct device *dev = &spi->dev;
  1231. struct iio_dev *indio_dev;
  1232. struct adis16480 *st;
  1233. int ret;
  1234. indio_dev = devm_iio_device_alloc(dev, sizeof(*st));
  1235. if (indio_dev == NULL)
  1236. return -ENOMEM;
  1237. st = iio_priv(indio_dev);
  1238. st->chip_info = &adis16480_chip_info[id->driver_data];
  1239. indio_dev->name = spi_get_device_id(spi)->name;
  1240. indio_dev->channels = st->chip_info->channels;
  1241. indio_dev->num_channels = st->chip_info->num_channels;
  1242. indio_dev->info = &adis16480_info;
  1243. indio_dev->modes = INDIO_DIRECT_MODE;
  1244. adis16480_data = &st->chip_info->adis_data;
  1245. ret = adis_init(&st->adis, indio_dev, spi, adis16480_data);
  1246. if (ret)
  1247. return ret;
  1248. ret = __adis_initial_startup(&st->adis);
  1249. if (ret)
  1250. return ret;
  1251. if (st->chip_info->has_sleep_cnt) {
  1252. ret = devm_add_action_or_reset(dev, adis16480_stop, indio_dev);
  1253. if (ret)
  1254. return ret;
  1255. }
  1256. ret = adis16480_config_irq_pin(st);
  1257. if (ret)
  1258. return ret;
  1259. ret = adis16480_get_ext_clocks(st);
  1260. if (ret)
  1261. return ret;
  1262. if (st->ext_clk) {
  1263. ret = adis16480_ext_clk_config(st, true);
  1264. if (ret)
  1265. return ret;
  1266. ret = devm_add_action_or_reset(dev, adis16480_clk_disable, st->ext_clk);
  1267. if (ret)
  1268. return ret;
  1269. st->clk_freq = clk_get_rate(st->ext_clk);
  1270. st->clk_freq *= 1000; /* micro */
  1271. if (st->clk_mode == ADIS16480_CLK_PPS) {
  1272. u16 sync_scale;
  1273. /*
  1274. * In PPS mode, the IMU sample rate is the clk_freq * sync_scale. Hence,
  1275. * default the IMU sample rate to the highest multiple of the input clock
  1276. * lower than the IMU max sample rate. The internal sample rate is the
  1277. * max...
  1278. */
  1279. sync_scale = st->chip_info->int_clk / st->clk_freq;
  1280. ret = __adis_write_reg_16(&st->adis, ADIS16495_REG_SYNC_SCALE, sync_scale);
  1281. if (ret)
  1282. return ret;
  1283. }
  1284. } else {
  1285. st->clk_freq = st->chip_info->int_clk;
  1286. }
  1287. /* Only use our trigger handler if burst mode is supported */
  1288. if (adis16480_data->burst_len)
  1289. trigger_handler = adis16480_trigger_handler;
  1290. ret = devm_adis_setup_buffer_and_trigger(&st->adis, indio_dev,
  1291. trigger_handler);
  1292. if (ret)
  1293. return ret;
  1294. ret = devm_iio_device_register(dev, indio_dev);
  1295. if (ret)
  1296. return ret;
  1297. adis16480_debugfs_init(indio_dev);
  1298. return 0;
  1299. }
  1300. static const struct spi_device_id adis16480_ids[] = {
  1301. { "adis16375", ADIS16375 },
  1302. { "adis16480", ADIS16480 },
  1303. { "adis16485", ADIS16485 },
  1304. { "adis16488", ADIS16488 },
  1305. { "adis16490", ADIS16490 },
  1306. { "adis16495-1", ADIS16495_1 },
  1307. { "adis16495-2", ADIS16495_2 },
  1308. { "adis16495-3", ADIS16495_3 },
  1309. { "adis16497-1", ADIS16497_1 },
  1310. { "adis16497-2", ADIS16497_2 },
  1311. { "adis16497-3", ADIS16497_3 },
  1312. { }
  1313. };
  1314. MODULE_DEVICE_TABLE(spi, adis16480_ids);
  1315. static const struct of_device_id adis16480_of_match[] = {
  1316. { .compatible = "adi,adis16375" },
  1317. { .compatible = "adi,adis16480" },
  1318. { .compatible = "adi,adis16485" },
  1319. { .compatible = "adi,adis16488" },
  1320. { .compatible = "adi,adis16490" },
  1321. { .compatible = "adi,adis16495-1" },
  1322. { .compatible = "adi,adis16495-2" },
  1323. { .compatible = "adi,adis16495-3" },
  1324. { .compatible = "adi,adis16497-1" },
  1325. { .compatible = "adi,adis16497-2" },
  1326. { .compatible = "adi,adis16497-3" },
  1327. { },
  1328. };
  1329. MODULE_DEVICE_TABLE(of, adis16480_of_match);
  1330. static struct spi_driver adis16480_driver = {
  1331. .driver = {
  1332. .name = "adis16480",
  1333. .of_match_table = adis16480_of_match,
  1334. },
  1335. .id_table = adis16480_ids,
  1336. .probe = adis16480_probe,
  1337. };
  1338. module_spi_driver(adis16480_driver);
  1339. MODULE_AUTHOR("Lars-Peter Clausen <[email protected]>");
  1340. MODULE_DESCRIPTION("Analog Devices ADIS16480 IMU driver");
  1341. MODULE_LICENSE("GPL v2");
  1342. MODULE_IMPORT_NS(IIO_ADISLIB);