adis16475.c 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * ADIS16475 IMU driver
  4. *
  5. * Copyright 2019 Analog Devices Inc.
  6. */
  7. #include <linux/bitfield.h>
  8. #include <linux/bitops.h>
  9. #include <linux/clk.h>
  10. #include <linux/debugfs.h>
  11. #include <linux/delay.h>
  12. #include <linux/device.h>
  13. #include <linux/kernel.h>
  14. #include <linux/iio/buffer.h>
  15. #include <linux/iio/iio.h>
  16. #include <linux/iio/imu/adis.h>
  17. #include <linux/iio/sysfs.h>
  18. #include <linux/iio/trigger_consumer.h>
  19. #include <linux/irq.h>
  20. #include <linux/lcm.h>
  21. #include <linux/math.h>
  22. #include <linux/module.h>
  23. #include <linux/mod_devicetable.h>
  24. #include <linux/property.h>
  25. #include <linux/spi/spi.h>
  26. #define ADIS16475_REG_DIAG_STAT 0x02
  27. #define ADIS16475_REG_X_GYRO_L 0x04
  28. #define ADIS16475_REG_Y_GYRO_L 0x08
  29. #define ADIS16475_REG_Z_GYRO_L 0x0C
  30. #define ADIS16475_REG_X_ACCEL_L 0x10
  31. #define ADIS16475_REG_Y_ACCEL_L 0x14
  32. #define ADIS16475_REG_Z_ACCEL_L 0x18
  33. #define ADIS16475_REG_TEMP_OUT 0x1c
  34. #define ADIS16475_REG_X_DELTANG_L 0x24
  35. #define ADIS16475_REG_Y_DELTANG_L 0x28
  36. #define ADIS16475_REG_Z_DELTANG_L 0x2C
  37. #define ADIS16475_REG_X_DELTVEL_L 0x30
  38. #define ADIS16475_REG_Y_DELTVEL_L 0x34
  39. #define ADIS16475_REG_Z_DELTVEL_L 0x38
  40. #define ADIS16475_REG_X_GYRO_BIAS_L 0x40
  41. #define ADIS16475_REG_Y_GYRO_BIAS_L 0x44
  42. #define ADIS16475_REG_Z_GYRO_BIAS_L 0x48
  43. #define ADIS16475_REG_X_ACCEL_BIAS_L 0x4c
  44. #define ADIS16475_REG_Y_ACCEL_BIAS_L 0x50
  45. #define ADIS16475_REG_Z_ACCEL_BIAS_L 0x54
  46. #define ADIS16475_REG_FILT_CTRL 0x5c
  47. #define ADIS16475_FILT_CTRL_MASK GENMASK(2, 0)
  48. #define ADIS16475_FILT_CTRL(x) FIELD_PREP(ADIS16475_FILT_CTRL_MASK, x)
  49. #define ADIS16475_REG_MSG_CTRL 0x60
  50. #define ADIS16475_MSG_CTRL_DR_POL_MASK BIT(0)
  51. #define ADIS16475_MSG_CTRL_DR_POL(x) \
  52. FIELD_PREP(ADIS16475_MSG_CTRL_DR_POL_MASK, x)
  53. #define ADIS16475_SYNC_MODE_MASK GENMASK(4, 2)
  54. #define ADIS16475_SYNC_MODE(x) FIELD_PREP(ADIS16475_SYNC_MODE_MASK, x)
  55. #define ADIS16575_SYNC_4KHZ_MASK BIT(11)
  56. #define ADIS16575_SYNC_4KHZ(x) FIELD_PREP(ADIS16575_SYNC_4KHZ_MASK, x)
  57. #define ADIS16475_REG_UP_SCALE 0x62
  58. #define ADIS16475_REG_DEC_RATE 0x64
  59. #define ADIS16475_REG_GLOB_CMD 0x68
  60. #define ADIS16475_REG_FIRM_REV 0x6c
  61. #define ADIS16475_REG_FIRM_DM 0x6e
  62. #define ADIS16475_REG_FIRM_Y 0x70
  63. #define ADIS16475_REG_PROD_ID 0x72
  64. #define ADIS16475_REG_SERIAL_NUM 0x74
  65. #define ADIS16475_REG_FLASH_CNT 0x7c
  66. #define ADIS16500_BURST_DATA_SEL_MASK BIT(8)
  67. #define ADIS16500_BURST32_MASK BIT(9)
  68. #define ADIS16500_BURST32(x) FIELD_PREP(ADIS16500_BURST32_MASK, x)
  69. /* number of data elements in burst mode */
  70. #define ADIS16475_BURST32_MAX_DATA_NO_TS32 32
  71. #define ADIS16575_BURST32_DATA_TS32 34
  72. #define ADIS16475_BURST_MAX_DATA 20
  73. #define ADIS16475_MAX_SCAN_DATA 20
  74. /* spi max speed in brust mode */
  75. #define ADIS16475_BURST_MAX_SPEED 1000000
  76. #define ADIS16575_BURST_MAX_SPEED 8000000
  77. #define ADIS16475_LSB_DEC_MASK 0
  78. #define ADIS16475_LSB_FIR_MASK 1
  79. #define ADIS16500_BURST_DATA_SEL_0_CHN_MASK GENMASK(5, 0)
  80. #define ADIS16500_BURST_DATA_SEL_1_CHN_MASK GENMASK(12, 7)
  81. #define ADIS16575_MAX_FIFO_WM 511UL
  82. #define ADIS16475_REG_FIFO_CTRL 0x5A
  83. #define ADIS16575_WM_LVL_MASK GENMASK(15, 4)
  84. #define ADIS16575_WM_LVL(x) FIELD_PREP(ADIS16575_WM_LVL_MASK, x)
  85. #define ADIS16575_WM_POL_MASK BIT(3)
  86. #define ADIS16575_WM_POL(x) FIELD_PREP(ADIS16575_WM_POL_MASK, x)
  87. #define ADIS16575_WM_EN_MASK BIT(2)
  88. #define ADIS16575_WM_EN(x) FIELD_PREP(ADIS16575_WM_EN_MASK, x)
  89. #define ADIS16575_OVERFLOW_MASK BIT(1)
  90. #define ADIS16575_STOP_ENQUEUE FIELD_PREP(ADIS16575_OVERFLOW_MASK, 0)
  91. #define ADIS16575_OVERWRITE_OLDEST FIELD_PREP(ADIS16575_OVERFLOW_MASK, 1)
  92. #define ADIS16575_FIFO_EN_MASK BIT(0)
  93. #define ADIS16575_FIFO_EN(x) FIELD_PREP(ADIS16575_FIFO_EN_MASK, x)
  94. #define ADIS16575_FIFO_FLUSH_CMD BIT(5)
  95. #define ADIS16575_REG_FIFO_CNT 0x3C
  96. enum {
  97. ADIS16475_SYNC_DIRECT = 1,
  98. ADIS16475_SYNC_SCALED,
  99. ADIS16475_SYNC_OUTPUT,
  100. ADIS16475_SYNC_PULSE = 5,
  101. };
  102. struct adis16475_sync {
  103. u16 sync_mode;
  104. u16 min_rate;
  105. u16 max_rate;
  106. };
  107. struct adis16475_chip_info {
  108. const struct iio_chan_spec *channels;
  109. const struct adis16475_sync *sync;
  110. const struct adis_data adis_data;
  111. const char *name;
  112. #define ADIS16475_HAS_BURST32 BIT(0)
  113. #define ADIS16475_HAS_BURST_DELTA_DATA BIT(1)
  114. #define ADIS16475_HAS_TIMESTAMP32 BIT(2)
  115. #define ADIS16475_NEEDS_BURST_REQUEST BIT(3)
  116. const long flags;
  117. u32 num_channels;
  118. u32 gyro_max_val;
  119. u32 gyro_max_scale;
  120. u32 accel_max_val;
  121. u32 accel_max_scale;
  122. u32 temp_scale;
  123. u32 deltang_max_val;
  124. u32 deltvel_max_val;
  125. u32 int_clk;
  126. u16 max_dec;
  127. u8 num_sync;
  128. };
  129. struct adis16475 {
  130. const struct adis16475_chip_info *info;
  131. struct adis adis;
  132. u32 clk_freq;
  133. bool burst32;
  134. unsigned long lsb_flag;
  135. u16 sync_mode;
  136. u16 fifo_watermark;
  137. /* Alignment needed for the timestamp */
  138. __be16 data[ADIS16475_MAX_SCAN_DATA] __aligned(8);
  139. };
  140. enum {
  141. ADIS16475_SCAN_GYRO_X,
  142. ADIS16475_SCAN_GYRO_Y,
  143. ADIS16475_SCAN_GYRO_Z,
  144. ADIS16475_SCAN_ACCEL_X,
  145. ADIS16475_SCAN_ACCEL_Y,
  146. ADIS16475_SCAN_ACCEL_Z,
  147. ADIS16475_SCAN_TEMP,
  148. ADIS16475_SCAN_DELTANG_X,
  149. ADIS16475_SCAN_DELTANG_Y,
  150. ADIS16475_SCAN_DELTANG_Z,
  151. ADIS16475_SCAN_DELTVEL_X,
  152. ADIS16475_SCAN_DELTVEL_Y,
  153. ADIS16475_SCAN_DELTVEL_Z,
  154. };
  155. static bool low_rate_allow;
  156. module_param(low_rate_allow, bool, 0444);
  157. MODULE_PARM_DESC(low_rate_allow,
  158. "Allow IMU rates below the minimum advisable when external clk is used in SCALED mode (default: N)");
  159. static ssize_t adis16475_show_firmware_revision(struct file *file,
  160. char __user *userbuf,
  161. size_t count, loff_t *ppos)
  162. {
  163. struct adis16475 *st = file->private_data;
  164. char buf[7];
  165. size_t len;
  166. u16 rev;
  167. int ret;
  168. ret = adis_read_reg_16(&st->adis, ADIS16475_REG_FIRM_REV, &rev);
  169. if (ret)
  170. return ret;
  171. len = scnprintf(buf, sizeof(buf), "%x.%x\n", rev >> 8, rev & 0xff);
  172. return simple_read_from_buffer(userbuf, count, ppos, buf, len);
  173. }
  174. static const struct file_operations adis16475_firmware_revision_fops = {
  175. .open = simple_open,
  176. .read = adis16475_show_firmware_revision,
  177. .llseek = default_llseek,
  178. .owner = THIS_MODULE,
  179. };
  180. static ssize_t adis16475_show_firmware_date(struct file *file,
  181. char __user *userbuf,
  182. size_t count, loff_t *ppos)
  183. {
  184. struct adis16475 *st = file->private_data;
  185. u16 md, year;
  186. char buf[12];
  187. size_t len;
  188. int ret;
  189. ret = adis_read_reg_16(&st->adis, ADIS16475_REG_FIRM_Y, &year);
  190. if (ret)
  191. return ret;
  192. ret = adis_read_reg_16(&st->adis, ADIS16475_REG_FIRM_DM, &md);
  193. if (ret)
  194. return ret;
  195. len = snprintf(buf, sizeof(buf), "%.2x-%.2x-%.4x\n", md >> 8, md & 0xff,
  196. year);
  197. return simple_read_from_buffer(userbuf, count, ppos, buf, len);
  198. }
  199. static const struct file_operations adis16475_firmware_date_fops = {
  200. .open = simple_open,
  201. .read = adis16475_show_firmware_date,
  202. .llseek = default_llseek,
  203. .owner = THIS_MODULE,
  204. };
  205. static int adis16475_show_serial_number(void *arg, u64 *val)
  206. {
  207. struct adis16475 *st = arg;
  208. u16 serial;
  209. int ret;
  210. ret = adis_read_reg_16(&st->adis, ADIS16475_REG_SERIAL_NUM, &serial);
  211. if (ret)
  212. return ret;
  213. *val = serial;
  214. return 0;
  215. }
  216. DEFINE_DEBUGFS_ATTRIBUTE(adis16475_serial_number_fops,
  217. adis16475_show_serial_number, NULL, "0x%.4llx\n");
  218. static int adis16475_show_product_id(void *arg, u64 *val)
  219. {
  220. struct adis16475 *st = arg;
  221. u16 prod_id;
  222. int ret;
  223. ret = adis_read_reg_16(&st->adis, ADIS16475_REG_PROD_ID, &prod_id);
  224. if (ret)
  225. return ret;
  226. *val = prod_id;
  227. return 0;
  228. }
  229. DEFINE_DEBUGFS_ATTRIBUTE(adis16475_product_id_fops,
  230. adis16475_show_product_id, NULL, "%llu\n");
  231. static int adis16475_show_flash_count(void *arg, u64 *val)
  232. {
  233. struct adis16475 *st = arg;
  234. u32 flash_count;
  235. int ret;
  236. ret = adis_read_reg_32(&st->adis, ADIS16475_REG_FLASH_CNT,
  237. &flash_count);
  238. if (ret)
  239. return ret;
  240. *val = flash_count;
  241. return 0;
  242. }
  243. DEFINE_DEBUGFS_ATTRIBUTE(adis16475_flash_count_fops,
  244. adis16475_show_flash_count, NULL, "%lld\n");
  245. static void adis16475_debugfs_init(struct iio_dev *indio_dev)
  246. {
  247. struct adis16475 *st = iio_priv(indio_dev);
  248. struct dentry *d = iio_get_debugfs_dentry(indio_dev);
  249. if (!IS_ENABLED(CONFIG_DEBUG_FS))
  250. return;
  251. debugfs_create_file_unsafe("serial_number", 0400,
  252. d, st, &adis16475_serial_number_fops);
  253. debugfs_create_file_unsafe("product_id", 0400,
  254. d, st, &adis16475_product_id_fops);
  255. debugfs_create_file_unsafe("flash_count", 0400,
  256. d, st, &adis16475_flash_count_fops);
  257. debugfs_create_file("firmware_revision", 0400,
  258. d, st, &adis16475_firmware_revision_fops);
  259. debugfs_create_file("firmware_date", 0400, d,
  260. st, &adis16475_firmware_date_fops);
  261. }
  262. static int adis16475_get_freq(struct adis16475 *st, u32 *freq)
  263. {
  264. int ret;
  265. u16 dec;
  266. u32 sample_rate = st->clk_freq;
  267. adis_dev_auto_lock(&st->adis);
  268. if (st->sync_mode == ADIS16475_SYNC_SCALED) {
  269. u16 sync_scale;
  270. ret = __adis_read_reg_16(&st->adis, ADIS16475_REG_UP_SCALE, &sync_scale);
  271. if (ret)
  272. return ret;
  273. sample_rate = st->clk_freq * sync_scale;
  274. }
  275. ret = __adis_read_reg_16(&st->adis, ADIS16475_REG_DEC_RATE, &dec);
  276. if (ret)
  277. return ret;
  278. *freq = DIV_ROUND_CLOSEST(sample_rate, dec + 1);
  279. return 0;
  280. }
  281. static int adis16475_set_freq(struct adis16475 *st, const u32 freq)
  282. {
  283. u16 dec;
  284. int ret;
  285. u32 sample_rate = st->clk_freq;
  286. /* The optimal sample rate for the supported IMUs is between int_clk - 100 and int_clk + 100. */
  287. u32 max_sample_rate = st->info->int_clk * 1000 + 100000;
  288. u32 min_sample_rate = st->info->int_clk * 1000 - 100000;
  289. if (!freq)
  290. return -EINVAL;
  291. adis_dev_auto_lock(&st->adis);
  292. /*
  293. * When using sync scaled mode, the input clock needs to be scaled so that we have
  294. * an IMU sample rate between (optimally) int_clk - 100 and int_clk + 100.
  295. * After this, we can use the decimation filter to lower the sampling rate in order
  296. * to get what the user wants.
  297. * Optimally, the user sample rate is a multiple of both the IMU sample rate and
  298. * the input clock. Hence, calculating the sync_scale dynamically gives us better
  299. * chances of achieving a perfect/integer value for DEC_RATE. The math here is:
  300. * 1. lcm of the input clock and the desired output rate.
  301. * 2. get the highest multiple of the previous result lower than the adis max rate.
  302. * 3. The last result becomes the IMU sample rate. Use that to calculate SYNC_SCALE
  303. * and DEC_RATE (to get the user output rate)
  304. */
  305. if (st->sync_mode == ADIS16475_SYNC_SCALED) {
  306. unsigned long scaled_rate = lcm(st->clk_freq, freq);
  307. int sync_scale;
  308. /*
  309. * If lcm is bigger than the IMU maximum sampling rate there's no perfect
  310. * solution. In this case, we get the highest multiple of the input clock
  311. * lower than the IMU max sample rate.
  312. */
  313. if (scaled_rate > max_sample_rate)
  314. scaled_rate = max_sample_rate / st->clk_freq * st->clk_freq;
  315. else
  316. scaled_rate = max_sample_rate / scaled_rate * scaled_rate;
  317. /*
  318. * This is not an hard requirement but it's not advised to run the IMU
  319. * with a sample rate lower than internal clock frequency, due to possible
  320. * undersampling issues. However, there are users that might really want
  321. * to take the risk. Hence, we provide a module parameter for them. If set,
  322. * we allow sample rates lower than internal clock frequency.
  323. * By default, we won't allow this and we just roundup the rate to the next
  324. * multiple of the input clock. This is done like this as in some cases
  325. * (when DEC_RATE is 0) might give us the closest value to the one desired
  326. * by the user...
  327. */
  328. if (scaled_rate < min_sample_rate && !low_rate_allow)
  329. scaled_rate = roundup(min_sample_rate, st->clk_freq);
  330. sync_scale = scaled_rate / st->clk_freq;
  331. ret = __adis_write_reg_16(&st->adis, ADIS16475_REG_UP_SCALE, sync_scale);
  332. if (ret)
  333. return ret;
  334. sample_rate = scaled_rate;
  335. }
  336. dec = DIV_ROUND_CLOSEST(sample_rate, freq);
  337. if (dec)
  338. dec--;
  339. if (dec > st->info->max_dec)
  340. dec = st->info->max_dec;
  341. ret = __adis_write_reg_16(&st->adis, ADIS16475_REG_DEC_RATE, dec);
  342. if (ret)
  343. return ret;
  344. /*
  345. * If decimation is used, then gyro and accel data will have meaningful
  346. * bits on the LSB registers. This info is used on the trigger handler.
  347. */
  348. assign_bit(ADIS16475_LSB_DEC_MASK, &st->lsb_flag, dec);
  349. return 0;
  350. }
  351. /* The values are approximated. */
  352. static const u32 adis16475_3db_freqs[] = {
  353. [0] = 720, /* Filter disabled, full BW (~720Hz) */
  354. [1] = 360,
  355. [2] = 164,
  356. [3] = 80,
  357. [4] = 40,
  358. [5] = 20,
  359. [6] = 10,
  360. };
  361. static int adis16475_get_filter(struct adis16475 *st, u32 *filter)
  362. {
  363. u16 filter_sz;
  364. int ret;
  365. const int mask = ADIS16475_FILT_CTRL_MASK;
  366. ret = adis_read_reg_16(&st->adis, ADIS16475_REG_FILT_CTRL, &filter_sz);
  367. if (ret)
  368. return ret;
  369. *filter = adis16475_3db_freqs[filter_sz & mask];
  370. return 0;
  371. }
  372. static int adis16475_set_filter(struct adis16475 *st, const u32 filter)
  373. {
  374. int i = ARRAY_SIZE(adis16475_3db_freqs);
  375. int ret;
  376. while (--i) {
  377. if (adis16475_3db_freqs[i] >= filter)
  378. break;
  379. }
  380. ret = adis_write_reg_16(&st->adis, ADIS16475_REG_FILT_CTRL,
  381. ADIS16475_FILT_CTRL(i));
  382. if (ret)
  383. return ret;
  384. /*
  385. * If FIR is used, then gyro and accel data will have meaningful
  386. * bits on the LSB registers. This info is used on the trigger handler.
  387. */
  388. assign_bit(ADIS16475_LSB_FIR_MASK, &st->lsb_flag, i);
  389. return 0;
  390. }
  391. static ssize_t adis16475_get_fifo_enabled(struct device *dev,
  392. struct device_attribute *attr,
  393. char *buf)
  394. {
  395. struct iio_dev *indio_dev = dev_to_iio_dev(dev);
  396. struct adis16475 *st = iio_priv(indio_dev);
  397. int ret;
  398. u16 val;
  399. ret = adis_read_reg_16(&st->adis, ADIS16475_REG_FIFO_CTRL, &val);
  400. if (ret)
  401. return ret;
  402. return sysfs_emit(buf, "%lu\n", FIELD_GET(ADIS16575_FIFO_EN_MASK, val));
  403. }
  404. static ssize_t adis16475_get_fifo_watermark(struct device *dev,
  405. struct device_attribute *attr,
  406. char *buf)
  407. {
  408. struct iio_dev *indio_dev = dev_to_iio_dev(dev);
  409. struct adis16475 *st = iio_priv(indio_dev);
  410. int ret;
  411. u16 val;
  412. ret = adis_read_reg_16(&st->adis, ADIS16475_REG_FIFO_CTRL, &val);
  413. if (ret)
  414. return ret;
  415. return sysfs_emit(buf, "%lu\n", FIELD_GET(ADIS16575_WM_LVL_MASK, val) + 1);
  416. }
  417. static ssize_t hwfifo_watermark_min_show(struct device *dev,
  418. struct device_attribute *attr,
  419. char *buf)
  420. {
  421. return sysfs_emit(buf, "1\n");
  422. }
  423. static ssize_t hwfifo_watermark_max_show(struct device *dev,
  424. struct device_attribute *attr,
  425. char *buf)
  426. {
  427. return sysfs_emit(buf, "%lu\n", ADIS16575_MAX_FIFO_WM);
  428. }
  429. static IIO_DEVICE_ATTR_RO(hwfifo_watermark_min, 0);
  430. static IIO_DEVICE_ATTR_RO(hwfifo_watermark_max, 0);
  431. static IIO_DEVICE_ATTR(hwfifo_watermark, 0444,
  432. adis16475_get_fifo_watermark, NULL, 0);
  433. static IIO_DEVICE_ATTR(hwfifo_enabled, 0444,
  434. adis16475_get_fifo_enabled, NULL, 0);
  435. static const struct iio_dev_attr *adis16475_fifo_attributes[] = {
  436. &iio_dev_attr_hwfifo_watermark_min,
  437. &iio_dev_attr_hwfifo_watermark_max,
  438. &iio_dev_attr_hwfifo_watermark,
  439. &iio_dev_attr_hwfifo_enabled,
  440. NULL
  441. };
  442. static int adis16475_buffer_postenable(struct iio_dev *indio_dev)
  443. {
  444. struct adis16475 *st = iio_priv(indio_dev);
  445. struct adis *adis = &st->adis;
  446. return adis_update_bits(adis, ADIS16475_REG_FIFO_CTRL,
  447. ADIS16575_FIFO_EN_MASK, (u16)ADIS16575_FIFO_EN(1));
  448. }
  449. static int adis16475_buffer_postdisable(struct iio_dev *indio_dev)
  450. {
  451. struct adis16475 *st = iio_priv(indio_dev);
  452. struct adis *adis = &st->adis;
  453. int ret;
  454. adis_dev_auto_lock(&st->adis);
  455. ret = __adis_update_bits(adis, ADIS16475_REG_FIFO_CTRL,
  456. ADIS16575_FIFO_EN_MASK, (u16)ADIS16575_FIFO_EN(0));
  457. if (ret)
  458. return ret;
  459. return __adis_write_reg_16(adis, ADIS16475_REG_GLOB_CMD,
  460. ADIS16575_FIFO_FLUSH_CMD);
  461. }
  462. static const struct iio_buffer_setup_ops adis16475_buffer_ops = {
  463. .postenable = adis16475_buffer_postenable,
  464. .postdisable = adis16475_buffer_postdisable,
  465. };
  466. static int adis16475_set_watermark(struct iio_dev *indio_dev, unsigned int val)
  467. {
  468. struct adis16475 *st = iio_priv(indio_dev);
  469. int ret;
  470. u16 wm_lvl;
  471. adis_dev_auto_lock(&st->adis);
  472. val = min_t(unsigned int, val, ADIS16575_MAX_FIFO_WM);
  473. wm_lvl = ADIS16575_WM_LVL(val - 1);
  474. ret = __adis_update_bits(&st->adis, ADIS16475_REG_FIFO_CTRL, ADIS16575_WM_LVL_MASK, wm_lvl);
  475. if (ret)
  476. return ret;
  477. st->fifo_watermark = val;
  478. return 0;
  479. }
  480. static const u32 adis16475_calib_regs[] = {
  481. [ADIS16475_SCAN_GYRO_X] = ADIS16475_REG_X_GYRO_BIAS_L,
  482. [ADIS16475_SCAN_GYRO_Y] = ADIS16475_REG_Y_GYRO_BIAS_L,
  483. [ADIS16475_SCAN_GYRO_Z] = ADIS16475_REG_Z_GYRO_BIAS_L,
  484. [ADIS16475_SCAN_ACCEL_X] = ADIS16475_REG_X_ACCEL_BIAS_L,
  485. [ADIS16475_SCAN_ACCEL_Y] = ADIS16475_REG_Y_ACCEL_BIAS_L,
  486. [ADIS16475_SCAN_ACCEL_Z] = ADIS16475_REG_Z_ACCEL_BIAS_L,
  487. };
  488. static int adis16475_read_raw(struct iio_dev *indio_dev,
  489. const struct iio_chan_spec *chan,
  490. int *val, int *val2, long info)
  491. {
  492. struct adis16475 *st = iio_priv(indio_dev);
  493. int ret;
  494. u32 tmp;
  495. switch (info) {
  496. case IIO_CHAN_INFO_RAW:
  497. return adis_single_conversion(indio_dev, chan, 0, val);
  498. case IIO_CHAN_INFO_SCALE:
  499. switch (chan->type) {
  500. case IIO_ANGL_VEL:
  501. *val = st->info->gyro_max_val;
  502. *val2 = st->info->gyro_max_scale;
  503. return IIO_VAL_FRACTIONAL;
  504. case IIO_ACCEL:
  505. *val = st->info->accel_max_val;
  506. *val2 = st->info->accel_max_scale;
  507. return IIO_VAL_FRACTIONAL;
  508. case IIO_TEMP:
  509. *val = st->info->temp_scale;
  510. return IIO_VAL_INT;
  511. case IIO_DELTA_ANGL:
  512. *val = st->info->deltang_max_val;
  513. *val2 = 31;
  514. return IIO_VAL_FRACTIONAL_LOG2;
  515. case IIO_DELTA_VELOCITY:
  516. *val = st->info->deltvel_max_val;
  517. *val2 = 31;
  518. return IIO_VAL_FRACTIONAL_LOG2;
  519. default:
  520. return -EINVAL;
  521. }
  522. case IIO_CHAN_INFO_CALIBBIAS:
  523. ret = adis_read_reg_32(&st->adis,
  524. adis16475_calib_regs[chan->scan_index],
  525. val);
  526. if (ret)
  527. return ret;
  528. return IIO_VAL_INT;
  529. case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY:
  530. ret = adis16475_get_filter(st, val);
  531. if (ret)
  532. return ret;
  533. return IIO_VAL_INT;
  534. case IIO_CHAN_INFO_SAMP_FREQ:
  535. ret = adis16475_get_freq(st, &tmp);
  536. if (ret)
  537. return ret;
  538. *val = tmp / 1000;
  539. *val2 = (tmp % 1000) * 1000;
  540. return IIO_VAL_INT_PLUS_MICRO;
  541. default:
  542. return -EINVAL;
  543. }
  544. }
  545. static int adis16475_write_raw(struct iio_dev *indio_dev,
  546. const struct iio_chan_spec *chan,
  547. int val, int val2, long info)
  548. {
  549. struct adis16475 *st = iio_priv(indio_dev);
  550. u32 tmp;
  551. switch (info) {
  552. case IIO_CHAN_INFO_SAMP_FREQ:
  553. tmp = val * 1000 + val2 / 1000;
  554. return adis16475_set_freq(st, tmp);
  555. case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY:
  556. return adis16475_set_filter(st, val);
  557. case IIO_CHAN_INFO_CALIBBIAS:
  558. return adis_write_reg_32(&st->adis,
  559. adis16475_calib_regs[chan->scan_index],
  560. val);
  561. default:
  562. return -EINVAL;
  563. }
  564. }
  565. #define ADIS16475_MOD_CHAN(_type, _mod, _address, _si, _r_bits, _s_bits) \
  566. { \
  567. .type = (_type), \
  568. .modified = 1, \
  569. .channel2 = (_mod), \
  570. .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
  571. BIT(IIO_CHAN_INFO_CALIBBIAS), \
  572. .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
  573. .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ) | \
  574. BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY), \
  575. .address = (_address), \
  576. .scan_index = (_si), \
  577. .scan_type = { \
  578. .sign = 's', \
  579. .realbits = (_r_bits), \
  580. .storagebits = (_s_bits), \
  581. .endianness = IIO_BE, \
  582. }, \
  583. }
  584. #define ADIS16475_GYRO_CHANNEL(_mod) \
  585. ADIS16475_MOD_CHAN(IIO_ANGL_VEL, IIO_MOD_ ## _mod, \
  586. ADIS16475_REG_ ## _mod ## _GYRO_L, \
  587. ADIS16475_SCAN_GYRO_ ## _mod, 32, 32)
  588. #define ADIS16475_ACCEL_CHANNEL(_mod) \
  589. ADIS16475_MOD_CHAN(IIO_ACCEL, IIO_MOD_ ## _mod, \
  590. ADIS16475_REG_ ## _mod ## _ACCEL_L, \
  591. ADIS16475_SCAN_ACCEL_ ## _mod, 32, 32)
  592. #define ADIS16475_TEMP_CHANNEL() { \
  593. .type = IIO_TEMP, \
  594. .indexed = 1, \
  595. .channel = 0, \
  596. .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
  597. BIT(IIO_CHAN_INFO_SCALE), \
  598. .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ) | \
  599. BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY), \
  600. .address = ADIS16475_REG_TEMP_OUT, \
  601. .scan_index = ADIS16475_SCAN_TEMP, \
  602. .scan_type = { \
  603. .sign = 's', \
  604. .realbits = 16, \
  605. .storagebits = 16, \
  606. .endianness = IIO_BE, \
  607. }, \
  608. }
  609. #define ADIS16475_MOD_CHAN_DELTA(_type, _mod, _address, _si, _r_bits, _s_bits) { \
  610. .type = (_type), \
  611. .modified = 1, \
  612. .channel2 = (_mod), \
  613. .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
  614. .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
  615. .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ) | \
  616. BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY), \
  617. .address = (_address), \
  618. .scan_index = _si, \
  619. .scan_type = { \
  620. .sign = 's', \
  621. .realbits = (_r_bits), \
  622. .storagebits = (_s_bits), \
  623. .endianness = IIO_BE, \
  624. }, \
  625. }
  626. #define ADIS16475_DELTANG_CHAN(_mod) \
  627. ADIS16475_MOD_CHAN_DELTA(IIO_DELTA_ANGL, IIO_MOD_ ## _mod, \
  628. ADIS16475_REG_ ## _mod ## _DELTANG_L, ADIS16475_SCAN_DELTANG_ ## _mod, 32, 32)
  629. #define ADIS16475_DELTVEL_CHAN(_mod) \
  630. ADIS16475_MOD_CHAN_DELTA(IIO_DELTA_VELOCITY, IIO_MOD_ ## _mod, \
  631. ADIS16475_REG_ ## _mod ## _DELTVEL_L, ADIS16475_SCAN_DELTVEL_ ## _mod, 32, 32)
  632. #define ADIS16475_DELTANG_CHAN_NO_SCAN(_mod) \
  633. ADIS16475_MOD_CHAN_DELTA(IIO_DELTA_ANGL, IIO_MOD_ ## _mod, \
  634. ADIS16475_REG_ ## _mod ## _DELTANG_L, -1, 32, 32)
  635. #define ADIS16475_DELTVEL_CHAN_NO_SCAN(_mod) \
  636. ADIS16475_MOD_CHAN_DELTA(IIO_DELTA_VELOCITY, IIO_MOD_ ## _mod, \
  637. ADIS16475_REG_ ## _mod ## _DELTVEL_L, -1, 32, 32)
  638. static const struct iio_chan_spec adis16477_channels[] = {
  639. ADIS16475_GYRO_CHANNEL(X),
  640. ADIS16475_GYRO_CHANNEL(Y),
  641. ADIS16475_GYRO_CHANNEL(Z),
  642. ADIS16475_ACCEL_CHANNEL(X),
  643. ADIS16475_ACCEL_CHANNEL(Y),
  644. ADIS16475_ACCEL_CHANNEL(Z),
  645. ADIS16475_TEMP_CHANNEL(),
  646. ADIS16475_DELTANG_CHAN(X),
  647. ADIS16475_DELTANG_CHAN(Y),
  648. ADIS16475_DELTANG_CHAN(Z),
  649. ADIS16475_DELTVEL_CHAN(X),
  650. ADIS16475_DELTVEL_CHAN(Y),
  651. ADIS16475_DELTVEL_CHAN(Z),
  652. IIO_CHAN_SOFT_TIMESTAMP(13)
  653. };
  654. static const struct iio_chan_spec adis16475_channels[] = {
  655. ADIS16475_GYRO_CHANNEL(X),
  656. ADIS16475_GYRO_CHANNEL(Y),
  657. ADIS16475_GYRO_CHANNEL(Z),
  658. ADIS16475_ACCEL_CHANNEL(X),
  659. ADIS16475_ACCEL_CHANNEL(Y),
  660. ADIS16475_ACCEL_CHANNEL(Z),
  661. ADIS16475_TEMP_CHANNEL(),
  662. ADIS16475_DELTANG_CHAN_NO_SCAN(X),
  663. ADIS16475_DELTANG_CHAN_NO_SCAN(Y),
  664. ADIS16475_DELTANG_CHAN_NO_SCAN(Z),
  665. ADIS16475_DELTVEL_CHAN_NO_SCAN(X),
  666. ADIS16475_DELTVEL_CHAN_NO_SCAN(Y),
  667. ADIS16475_DELTVEL_CHAN_NO_SCAN(Z),
  668. IIO_CHAN_SOFT_TIMESTAMP(7)
  669. };
  670. static const struct iio_chan_spec adis16575_channels[] = {
  671. ADIS16475_GYRO_CHANNEL(X),
  672. ADIS16475_GYRO_CHANNEL(Y),
  673. ADIS16475_GYRO_CHANNEL(Z),
  674. ADIS16475_ACCEL_CHANNEL(X),
  675. ADIS16475_ACCEL_CHANNEL(Y),
  676. ADIS16475_ACCEL_CHANNEL(Z),
  677. ADIS16475_TEMP_CHANNEL(),
  678. ADIS16475_DELTANG_CHAN(X),
  679. ADIS16475_DELTANG_CHAN(Y),
  680. ADIS16475_DELTANG_CHAN(Z),
  681. ADIS16475_DELTVEL_CHAN(X),
  682. ADIS16475_DELTVEL_CHAN(Y),
  683. ADIS16475_DELTVEL_CHAN(Z),
  684. };
  685. enum adis16475_variant {
  686. ADIS16470,
  687. ADIS16475_1,
  688. ADIS16475_2,
  689. ADIS16475_3,
  690. ADIS16477_1,
  691. ADIS16477_2,
  692. ADIS16477_3,
  693. ADIS16465_1,
  694. ADIS16465_2,
  695. ADIS16465_3,
  696. ADIS16467_1,
  697. ADIS16467_2,
  698. ADIS16467_3,
  699. ADIS16500,
  700. ADIS16501,
  701. ADIS16505_1,
  702. ADIS16505_2,
  703. ADIS16505_3,
  704. ADIS16507_1,
  705. ADIS16507_2,
  706. ADIS16507_3,
  707. ADIS16575_2,
  708. ADIS16575_3,
  709. ADIS16576_2,
  710. ADIS16576_3,
  711. ADIS16577_2,
  712. ADIS16577_3,
  713. };
  714. enum {
  715. ADIS16475_DIAG_STAT_DATA_PATH = 1,
  716. ADIS16475_DIAG_STAT_FLASH_MEM,
  717. ADIS16475_DIAG_STAT_SPI,
  718. ADIS16475_DIAG_STAT_STANDBY,
  719. ADIS16475_DIAG_STAT_SENSOR,
  720. ADIS16475_DIAG_STAT_MEMORY,
  721. ADIS16475_DIAG_STAT_CLK,
  722. };
  723. static const char * const adis16475_status_error_msgs[] = {
  724. [ADIS16475_DIAG_STAT_DATA_PATH] = "Data Path Overrun",
  725. [ADIS16475_DIAG_STAT_FLASH_MEM] = "Flash memory update failure",
  726. [ADIS16475_DIAG_STAT_SPI] = "SPI communication error",
  727. [ADIS16475_DIAG_STAT_STANDBY] = "Standby mode",
  728. [ADIS16475_DIAG_STAT_SENSOR] = "Sensor failure",
  729. [ADIS16475_DIAG_STAT_MEMORY] = "Memory failure",
  730. [ADIS16475_DIAG_STAT_CLK] = "Clock error",
  731. };
  732. #define ADIS16475_DATA(_prod_id, _timeouts, _burst_max_len, _burst_max_speed_hz, _has_fifo) \
  733. { \
  734. .msc_ctrl_reg = ADIS16475_REG_MSG_CTRL, \
  735. .glob_cmd_reg = ADIS16475_REG_GLOB_CMD, \
  736. .diag_stat_reg = ADIS16475_REG_DIAG_STAT, \
  737. .prod_id_reg = ADIS16475_REG_PROD_ID, \
  738. .prod_id = (_prod_id), \
  739. .self_test_mask = BIT(2), \
  740. .self_test_reg = ADIS16475_REG_GLOB_CMD, \
  741. .cs_change_delay = 16, \
  742. .read_delay = 5, \
  743. .write_delay = 5, \
  744. .status_error_msgs = adis16475_status_error_msgs, \
  745. .status_error_mask = BIT(ADIS16475_DIAG_STAT_DATA_PATH) | \
  746. BIT(ADIS16475_DIAG_STAT_FLASH_MEM) | \
  747. BIT(ADIS16475_DIAG_STAT_SPI) | \
  748. BIT(ADIS16475_DIAG_STAT_STANDBY) | \
  749. BIT(ADIS16475_DIAG_STAT_SENSOR) | \
  750. BIT(ADIS16475_DIAG_STAT_MEMORY) | \
  751. BIT(ADIS16475_DIAG_STAT_CLK), \
  752. .unmasked_drdy = true, \
  753. .has_fifo = _has_fifo, \
  754. .timeouts = (_timeouts), \
  755. .burst_reg_cmd = ADIS16475_REG_GLOB_CMD, \
  756. .burst_len = ADIS16475_BURST_MAX_DATA, \
  757. .burst_max_len = _burst_max_len, \
  758. .burst_max_speed_hz = _burst_max_speed_hz \
  759. }
  760. static const struct adis16475_sync adis16475_sync_mode[] = {
  761. { ADIS16475_SYNC_OUTPUT },
  762. { ADIS16475_SYNC_DIRECT, 1900, 2100 },
  763. { ADIS16475_SYNC_SCALED, 1, 128 },
  764. { ADIS16475_SYNC_PULSE, 1000, 2100 },
  765. };
  766. static const struct adis16475_sync adis16575_sync_mode[] = {
  767. { ADIS16475_SYNC_OUTPUT },
  768. { ADIS16475_SYNC_DIRECT, 1900, 4100 },
  769. { ADIS16475_SYNC_SCALED, 1, 400 },
  770. };
  771. static const struct adis_timeout adis16475_timeouts = {
  772. .reset_ms = 200,
  773. .sw_reset_ms = 200,
  774. .self_test_ms = 20,
  775. };
  776. static const struct adis_timeout adis1650x_timeouts = {
  777. .reset_ms = 260,
  778. .sw_reset_ms = 260,
  779. .self_test_ms = 30,
  780. };
  781. static const struct adis16475_chip_info adis16475_chip_info[] = {
  782. [ADIS16470] = {
  783. .name = "adis16470",
  784. .num_channels = ARRAY_SIZE(adis16475_channels),
  785. .channels = adis16475_channels,
  786. .gyro_max_val = 1,
  787. .gyro_max_scale = IIO_RAD_TO_DEGREE(10 << 16),
  788. .accel_max_val = 1,
  789. .accel_max_scale = IIO_M_S_2_TO_G(800 << 16),
  790. .temp_scale = 100,
  791. .deltang_max_val = IIO_DEGREE_TO_RAD(2160),
  792. .deltvel_max_val = 400,
  793. .int_clk = 2000,
  794. .max_dec = 1999,
  795. .sync = adis16475_sync_mode,
  796. .num_sync = ARRAY_SIZE(adis16475_sync_mode),
  797. .adis_data = ADIS16475_DATA(16470, &adis16475_timeouts,
  798. ADIS16475_BURST32_MAX_DATA_NO_TS32,
  799. ADIS16475_BURST_MAX_SPEED, false),
  800. },
  801. [ADIS16475_1] = {
  802. .name = "adis16475-1",
  803. .num_channels = ARRAY_SIZE(adis16475_channels),
  804. .channels = adis16475_channels,
  805. .gyro_max_val = 1,
  806. .gyro_max_scale = IIO_RAD_TO_DEGREE(160 << 16),
  807. .accel_max_val = 1,
  808. .accel_max_scale = IIO_M_S_2_TO_G(4000 << 16),
  809. .temp_scale = 100,
  810. .deltang_max_val = IIO_DEGREE_TO_RAD(360),
  811. .deltvel_max_val = 100,
  812. .int_clk = 2000,
  813. .max_dec = 1999,
  814. .sync = adis16475_sync_mode,
  815. .num_sync = ARRAY_SIZE(adis16475_sync_mode),
  816. .adis_data = ADIS16475_DATA(16475, &adis16475_timeouts,
  817. ADIS16475_BURST32_MAX_DATA_NO_TS32,
  818. ADIS16475_BURST_MAX_SPEED, false),
  819. },
  820. [ADIS16475_2] = {
  821. .name = "adis16475-2",
  822. .num_channels = ARRAY_SIZE(adis16475_channels),
  823. .channels = adis16475_channels,
  824. .gyro_max_val = 1,
  825. .gyro_max_scale = IIO_RAD_TO_DEGREE(40 << 16),
  826. .accel_max_val = 1,
  827. .accel_max_scale = IIO_M_S_2_TO_G(4000 << 16),
  828. .temp_scale = 100,
  829. .deltang_max_val = IIO_DEGREE_TO_RAD(720),
  830. .deltvel_max_val = 100,
  831. .int_clk = 2000,
  832. .max_dec = 1999,
  833. .sync = adis16475_sync_mode,
  834. .num_sync = ARRAY_SIZE(adis16475_sync_mode),
  835. .adis_data = ADIS16475_DATA(16475, &adis16475_timeouts,
  836. ADIS16475_BURST32_MAX_DATA_NO_TS32,
  837. ADIS16475_BURST_MAX_SPEED, false),
  838. },
  839. [ADIS16475_3] = {
  840. .name = "adis16475-3",
  841. .num_channels = ARRAY_SIZE(adis16475_channels),
  842. .channels = adis16475_channels,
  843. .gyro_max_val = 1,
  844. .gyro_max_scale = IIO_RAD_TO_DEGREE(10 << 16),
  845. .accel_max_val = 1,
  846. .accel_max_scale = IIO_M_S_2_TO_G(4000 << 16),
  847. .temp_scale = 100,
  848. .deltang_max_val = IIO_DEGREE_TO_RAD(2160),
  849. .deltvel_max_val = 100,
  850. .int_clk = 2000,
  851. .max_dec = 1999,
  852. .sync = adis16475_sync_mode,
  853. .num_sync = ARRAY_SIZE(adis16475_sync_mode),
  854. .adis_data = ADIS16475_DATA(16475, &adis16475_timeouts,
  855. ADIS16475_BURST32_MAX_DATA_NO_TS32,
  856. ADIS16475_BURST_MAX_SPEED, false),
  857. },
  858. [ADIS16477_1] = {
  859. .name = "adis16477-1",
  860. .num_channels = ARRAY_SIZE(adis16477_channels),
  861. .channels = adis16477_channels,
  862. .gyro_max_val = 1,
  863. .gyro_max_scale = IIO_RAD_TO_DEGREE(160 << 16),
  864. .accel_max_val = 1,
  865. .accel_max_scale = IIO_M_S_2_TO_G(800 << 16),
  866. .temp_scale = 100,
  867. .deltang_max_val = IIO_DEGREE_TO_RAD(360),
  868. .deltvel_max_val = 400,
  869. .int_clk = 2000,
  870. .max_dec = 1999,
  871. .sync = adis16475_sync_mode,
  872. .num_sync = ARRAY_SIZE(adis16475_sync_mode),
  873. .flags = ADIS16475_HAS_BURST32 | ADIS16475_HAS_BURST_DELTA_DATA,
  874. .adis_data = ADIS16475_DATA(16477, &adis16475_timeouts,
  875. ADIS16475_BURST32_MAX_DATA_NO_TS32,
  876. ADIS16475_BURST_MAX_SPEED, false),
  877. },
  878. [ADIS16477_2] = {
  879. .name = "adis16477-2",
  880. .num_channels = ARRAY_SIZE(adis16477_channels),
  881. .channels = adis16477_channels,
  882. .gyro_max_val = 1,
  883. .gyro_max_scale = IIO_RAD_TO_DEGREE(40 << 16),
  884. .accel_max_val = 1,
  885. .accel_max_scale = IIO_M_S_2_TO_G(800 << 16),
  886. .temp_scale = 100,
  887. .deltang_max_val = IIO_DEGREE_TO_RAD(720),
  888. .deltvel_max_val = 400,
  889. .int_clk = 2000,
  890. .max_dec = 1999,
  891. .sync = adis16475_sync_mode,
  892. .num_sync = ARRAY_SIZE(adis16475_sync_mode),
  893. .flags = ADIS16475_HAS_BURST32 | ADIS16475_HAS_BURST_DELTA_DATA,
  894. .adis_data = ADIS16475_DATA(16477, &adis16475_timeouts,
  895. ADIS16475_BURST32_MAX_DATA_NO_TS32,
  896. ADIS16475_BURST_MAX_SPEED, false),
  897. },
  898. [ADIS16477_3] = {
  899. .name = "adis16477-3",
  900. .num_channels = ARRAY_SIZE(adis16477_channels),
  901. .channels = adis16477_channels,
  902. .gyro_max_val = 1,
  903. .gyro_max_scale = IIO_RAD_TO_DEGREE(10 << 16),
  904. .accel_max_val = 1,
  905. .accel_max_scale = IIO_M_S_2_TO_G(800 << 16),
  906. .temp_scale = 100,
  907. .deltang_max_val = IIO_DEGREE_TO_RAD(2160),
  908. .deltvel_max_val = 400,
  909. .int_clk = 2000,
  910. .max_dec = 1999,
  911. .sync = adis16475_sync_mode,
  912. .num_sync = ARRAY_SIZE(adis16475_sync_mode),
  913. .flags = ADIS16475_HAS_BURST32 | ADIS16475_HAS_BURST_DELTA_DATA,
  914. .adis_data = ADIS16475_DATA(16477, &adis16475_timeouts,
  915. ADIS16475_BURST32_MAX_DATA_NO_TS32,
  916. ADIS16475_BURST_MAX_SPEED, false),
  917. },
  918. [ADIS16465_1] = {
  919. .name = "adis16465-1",
  920. .num_channels = ARRAY_SIZE(adis16475_channels),
  921. .channels = adis16475_channels,
  922. .gyro_max_val = 1,
  923. .gyro_max_scale = IIO_RAD_TO_DEGREE(160 << 16),
  924. .accel_max_val = 1,
  925. .accel_max_scale = IIO_M_S_2_TO_G(4000 << 16),
  926. .temp_scale = 100,
  927. .deltang_max_val = IIO_DEGREE_TO_RAD(360),
  928. .deltvel_max_val = 100,
  929. .int_clk = 2000,
  930. .max_dec = 1999,
  931. .sync = adis16475_sync_mode,
  932. .num_sync = ARRAY_SIZE(adis16475_sync_mode),
  933. .adis_data = ADIS16475_DATA(16465, &adis16475_timeouts,
  934. ADIS16475_BURST32_MAX_DATA_NO_TS32,
  935. ADIS16475_BURST_MAX_SPEED, false),
  936. },
  937. [ADIS16465_2] = {
  938. .name = "adis16465-2",
  939. .num_channels = ARRAY_SIZE(adis16475_channels),
  940. .channels = adis16475_channels,
  941. .gyro_max_val = 1,
  942. .gyro_max_scale = IIO_RAD_TO_DEGREE(40 << 16),
  943. .accel_max_val = 1,
  944. .accel_max_scale = IIO_M_S_2_TO_G(4000 << 16),
  945. .temp_scale = 100,
  946. .deltang_max_val = IIO_DEGREE_TO_RAD(720),
  947. .deltvel_max_val = 100,
  948. .int_clk = 2000,
  949. .max_dec = 1999,
  950. .sync = adis16475_sync_mode,
  951. .num_sync = ARRAY_SIZE(adis16475_sync_mode),
  952. .adis_data = ADIS16475_DATA(16465, &adis16475_timeouts,
  953. ADIS16475_BURST32_MAX_DATA_NO_TS32,
  954. ADIS16475_BURST_MAX_SPEED, false),
  955. },
  956. [ADIS16465_3] = {
  957. .name = "adis16465-3",
  958. .num_channels = ARRAY_SIZE(adis16475_channels),
  959. .channels = adis16475_channels,
  960. .gyro_max_val = 1,
  961. .gyro_max_scale = IIO_RAD_TO_DEGREE(10 << 16),
  962. .accel_max_val = 1,
  963. .accel_max_scale = IIO_M_S_2_TO_G(4000 << 16),
  964. .temp_scale = 100,
  965. .deltang_max_val = IIO_DEGREE_TO_RAD(2160),
  966. .deltvel_max_val = 100,
  967. .int_clk = 2000,
  968. .max_dec = 1999,
  969. .sync = adis16475_sync_mode,
  970. .num_sync = ARRAY_SIZE(adis16475_sync_mode),
  971. .adis_data = ADIS16475_DATA(16465, &adis16475_timeouts,
  972. ADIS16475_BURST32_MAX_DATA_NO_TS32,
  973. ADIS16475_BURST_MAX_SPEED, false),
  974. },
  975. [ADIS16467_1] = {
  976. .name = "adis16467-1",
  977. .num_channels = ARRAY_SIZE(adis16475_channels),
  978. .channels = adis16475_channels,
  979. .gyro_max_val = 1,
  980. .gyro_max_scale = IIO_RAD_TO_DEGREE(160 << 16),
  981. .accel_max_val = 1,
  982. .accel_max_scale = IIO_M_S_2_TO_G(800 << 16),
  983. .temp_scale = 100,
  984. .deltang_max_val = IIO_DEGREE_TO_RAD(360),
  985. .deltvel_max_val = 400,
  986. .int_clk = 2000,
  987. .max_dec = 1999,
  988. .sync = adis16475_sync_mode,
  989. .num_sync = ARRAY_SIZE(adis16475_sync_mode),
  990. .adis_data = ADIS16475_DATA(16467, &adis16475_timeouts,
  991. ADIS16475_BURST32_MAX_DATA_NO_TS32,
  992. ADIS16475_BURST_MAX_SPEED, false),
  993. },
  994. [ADIS16467_2] = {
  995. .name = "adis16467-2",
  996. .num_channels = ARRAY_SIZE(adis16475_channels),
  997. .channels = adis16475_channels,
  998. .gyro_max_val = 1,
  999. .gyro_max_scale = IIO_RAD_TO_DEGREE(40 << 16),
  1000. .accel_max_val = 1,
  1001. .accel_max_scale = IIO_M_S_2_TO_G(800 << 16),
  1002. .temp_scale = 100,
  1003. .deltang_max_val = IIO_DEGREE_TO_RAD(720),
  1004. .deltvel_max_val = 400,
  1005. .int_clk = 2000,
  1006. .max_dec = 1999,
  1007. .sync = adis16475_sync_mode,
  1008. .num_sync = ARRAY_SIZE(adis16475_sync_mode),
  1009. .adis_data = ADIS16475_DATA(16467, &adis16475_timeouts,
  1010. ADIS16475_BURST32_MAX_DATA_NO_TS32,
  1011. ADIS16475_BURST_MAX_SPEED, false),
  1012. },
  1013. [ADIS16467_3] = {
  1014. .name = "adis16467-3",
  1015. .num_channels = ARRAY_SIZE(adis16475_channels),
  1016. .channels = adis16475_channels,
  1017. .gyro_max_val = 1,
  1018. .gyro_max_scale = IIO_RAD_TO_DEGREE(10 << 16),
  1019. .accel_max_val = 1,
  1020. .accel_max_scale = IIO_M_S_2_TO_G(800 << 16),
  1021. .temp_scale = 100,
  1022. .deltang_max_val = IIO_DEGREE_TO_RAD(2160),
  1023. .deltvel_max_val = 400,
  1024. .int_clk = 2000,
  1025. .max_dec = 1999,
  1026. .sync = adis16475_sync_mode,
  1027. .num_sync = ARRAY_SIZE(adis16475_sync_mode),
  1028. .adis_data = ADIS16475_DATA(16467, &adis16475_timeouts,
  1029. ADIS16475_BURST32_MAX_DATA_NO_TS32,
  1030. ADIS16475_BURST_MAX_SPEED, false),
  1031. },
  1032. [ADIS16500] = {
  1033. .name = "adis16500",
  1034. .num_channels = ARRAY_SIZE(adis16477_channels),
  1035. .channels = adis16477_channels,
  1036. .gyro_max_val = 1,
  1037. .gyro_max_scale = IIO_RAD_TO_DEGREE(10 << 16),
  1038. .accel_max_val = 392,
  1039. .accel_max_scale = 32000 << 16,
  1040. .temp_scale = 100,
  1041. .deltang_max_val = IIO_DEGREE_TO_RAD(2160),
  1042. .deltvel_max_val = 400,
  1043. .int_clk = 2000,
  1044. .max_dec = 1999,
  1045. .sync = adis16475_sync_mode,
  1046. /* pulse sync not supported */
  1047. .num_sync = ARRAY_SIZE(adis16475_sync_mode) - 1,
  1048. .flags = ADIS16475_HAS_BURST32 | ADIS16475_HAS_BURST_DELTA_DATA,
  1049. .adis_data = ADIS16475_DATA(16500, &adis1650x_timeouts,
  1050. ADIS16475_BURST32_MAX_DATA_NO_TS32,
  1051. ADIS16475_BURST_MAX_SPEED, false),
  1052. },
  1053. [ADIS16501] = {
  1054. .name = "adis16501",
  1055. .num_channels = ARRAY_SIZE(adis16477_channels),
  1056. .channels = adis16477_channels,
  1057. .gyro_max_val = 1,
  1058. .gyro_max_scale = IIO_RAD_TO_DEGREE(40 << 16),
  1059. .accel_max_val = 1,
  1060. .accel_max_scale = IIO_M_S_2_TO_G(800 << 16),
  1061. .temp_scale = 100,
  1062. .deltang_max_val = IIO_DEGREE_TO_RAD(720),
  1063. .deltvel_max_val = 125,
  1064. .int_clk = 2000,
  1065. .max_dec = 1999,
  1066. .sync = adis16475_sync_mode,
  1067. /* pulse sync not supported */
  1068. .num_sync = ARRAY_SIZE(adis16475_sync_mode) - 1,
  1069. .flags = ADIS16475_HAS_BURST32 | ADIS16475_HAS_BURST_DELTA_DATA,
  1070. .adis_data = ADIS16475_DATA(16501, &adis1650x_timeouts,
  1071. ADIS16475_BURST32_MAX_DATA_NO_TS32,
  1072. ADIS16475_BURST_MAX_SPEED, false),
  1073. },
  1074. [ADIS16505_1] = {
  1075. .name = "adis16505-1",
  1076. .num_channels = ARRAY_SIZE(adis16477_channels),
  1077. .channels = adis16477_channels,
  1078. .gyro_max_val = 1,
  1079. .gyro_max_scale = IIO_RAD_TO_DEGREE(160 << 16),
  1080. .accel_max_val = 78,
  1081. .accel_max_scale = 32000 << 16,
  1082. .temp_scale = 100,
  1083. .deltang_max_val = IIO_DEGREE_TO_RAD(360),
  1084. .deltvel_max_val = 100,
  1085. .int_clk = 2000,
  1086. .max_dec = 1999,
  1087. .sync = adis16475_sync_mode,
  1088. /* pulse sync not supported */
  1089. .num_sync = ARRAY_SIZE(adis16475_sync_mode) - 1,
  1090. .flags = ADIS16475_HAS_BURST32 | ADIS16475_HAS_BURST_DELTA_DATA,
  1091. .adis_data = ADIS16475_DATA(16505, &adis1650x_timeouts,
  1092. ADIS16475_BURST32_MAX_DATA_NO_TS32,
  1093. ADIS16475_BURST_MAX_SPEED, false),
  1094. },
  1095. [ADIS16505_2] = {
  1096. .name = "adis16505-2",
  1097. .num_channels = ARRAY_SIZE(adis16477_channels),
  1098. .channels = adis16477_channels,
  1099. .gyro_max_val = 1,
  1100. .gyro_max_scale = IIO_RAD_TO_DEGREE(40 << 16),
  1101. .accel_max_val = 78,
  1102. .accel_max_scale = 32000 << 16,
  1103. .temp_scale = 100,
  1104. .deltang_max_val = IIO_DEGREE_TO_RAD(720),
  1105. .deltvel_max_val = 100,
  1106. .int_clk = 2000,
  1107. .max_dec = 1999,
  1108. .sync = adis16475_sync_mode,
  1109. /* pulse sync not supported */
  1110. .num_sync = ARRAY_SIZE(adis16475_sync_mode) - 1,
  1111. .flags = ADIS16475_HAS_BURST32 | ADIS16475_HAS_BURST_DELTA_DATA,
  1112. .adis_data = ADIS16475_DATA(16505, &adis1650x_timeouts,
  1113. ADIS16475_BURST32_MAX_DATA_NO_TS32,
  1114. ADIS16475_BURST_MAX_SPEED, false),
  1115. },
  1116. [ADIS16505_3] = {
  1117. .name = "adis16505-3",
  1118. .num_channels = ARRAY_SIZE(adis16477_channels),
  1119. .channels = adis16477_channels,
  1120. .gyro_max_val = 1,
  1121. .gyro_max_scale = IIO_RAD_TO_DEGREE(10 << 16),
  1122. .accel_max_val = 78,
  1123. .accel_max_scale = 32000 << 16,
  1124. .temp_scale = 100,
  1125. .deltang_max_val = IIO_DEGREE_TO_RAD(2160),
  1126. .deltvel_max_val = 100,
  1127. .int_clk = 2000,
  1128. .max_dec = 1999,
  1129. .sync = adis16475_sync_mode,
  1130. /* pulse sync not supported */
  1131. .num_sync = ARRAY_SIZE(adis16475_sync_mode) - 1,
  1132. .flags = ADIS16475_HAS_BURST32 | ADIS16475_HAS_BURST_DELTA_DATA,
  1133. .adis_data = ADIS16475_DATA(16505, &adis1650x_timeouts,
  1134. ADIS16475_BURST32_MAX_DATA_NO_TS32,
  1135. ADIS16475_BURST_MAX_SPEED, false),
  1136. },
  1137. [ADIS16507_1] = {
  1138. .name = "adis16507-1",
  1139. .num_channels = ARRAY_SIZE(adis16477_channels),
  1140. .channels = adis16477_channels,
  1141. .gyro_max_val = 1,
  1142. .gyro_max_scale = IIO_RAD_TO_DEGREE(160 << 16),
  1143. .accel_max_val = 392,
  1144. .accel_max_scale = 32000 << 16,
  1145. .temp_scale = 100,
  1146. .deltang_max_val = IIO_DEGREE_TO_RAD(360),
  1147. .deltvel_max_val = 400,
  1148. .int_clk = 2000,
  1149. .max_dec = 1999,
  1150. .sync = adis16475_sync_mode,
  1151. /* pulse sync not supported */
  1152. .num_sync = ARRAY_SIZE(adis16475_sync_mode) - 1,
  1153. .flags = ADIS16475_HAS_BURST32 | ADIS16475_HAS_BURST_DELTA_DATA,
  1154. .adis_data = ADIS16475_DATA(16507, &adis1650x_timeouts,
  1155. ADIS16475_BURST32_MAX_DATA_NO_TS32,
  1156. ADIS16475_BURST_MAX_SPEED, false),
  1157. },
  1158. [ADIS16507_2] = {
  1159. .name = "adis16507-2",
  1160. .num_channels = ARRAY_SIZE(adis16477_channels),
  1161. .channels = adis16477_channels,
  1162. .gyro_max_val = 1,
  1163. .gyro_max_scale = IIO_RAD_TO_DEGREE(40 << 16),
  1164. .accel_max_val = 392,
  1165. .accel_max_scale = 32000 << 16,
  1166. .temp_scale = 100,
  1167. .deltang_max_val = IIO_DEGREE_TO_RAD(720),
  1168. .deltvel_max_val = 400,
  1169. .int_clk = 2000,
  1170. .max_dec = 1999,
  1171. .sync = adis16475_sync_mode,
  1172. /* pulse sync not supported */
  1173. .num_sync = ARRAY_SIZE(adis16475_sync_mode) - 1,
  1174. .flags = ADIS16475_HAS_BURST32 | ADIS16475_HAS_BURST_DELTA_DATA,
  1175. .adis_data = ADIS16475_DATA(16507, &adis1650x_timeouts,
  1176. ADIS16475_BURST32_MAX_DATA_NO_TS32,
  1177. ADIS16475_BURST_MAX_SPEED, false),
  1178. },
  1179. [ADIS16507_3] = {
  1180. .name = "adis16507-3",
  1181. .num_channels = ARRAY_SIZE(adis16477_channels),
  1182. .channels = adis16477_channels,
  1183. .gyro_max_val = 1,
  1184. .gyro_max_scale = IIO_RAD_TO_DEGREE(10 << 16),
  1185. .accel_max_val = 392,
  1186. .accel_max_scale = 32000 << 16,
  1187. .temp_scale = 100,
  1188. .deltang_max_val = IIO_DEGREE_TO_RAD(2160),
  1189. .deltvel_max_val = 400,
  1190. .int_clk = 2000,
  1191. .max_dec = 1999,
  1192. .sync = adis16475_sync_mode,
  1193. /* pulse sync not supported */
  1194. .num_sync = ARRAY_SIZE(adis16475_sync_mode) - 1,
  1195. .flags = ADIS16475_HAS_BURST32 | ADIS16475_HAS_BURST_DELTA_DATA,
  1196. .adis_data = ADIS16475_DATA(16507, &adis1650x_timeouts,
  1197. ADIS16475_BURST32_MAX_DATA_NO_TS32,
  1198. ADIS16475_BURST_MAX_SPEED, false),
  1199. },
  1200. [ADIS16575_2] = {
  1201. .name = "adis16575-2",
  1202. .num_channels = ARRAY_SIZE(adis16575_channels),
  1203. .channels = adis16575_channels,
  1204. .gyro_max_val = 1,
  1205. .gyro_max_scale = IIO_RAD_TO_DEGREE(40 << 16),
  1206. .accel_max_val = 8,
  1207. .accel_max_scale = IIO_M_S_2_TO_G(32000 << 16),
  1208. .temp_scale = 100,
  1209. .deltang_max_val = IIO_DEGREE_TO_RAD(450),
  1210. .deltvel_max_val = 100,
  1211. .int_clk = 4000,
  1212. .max_dec = 3999,
  1213. .sync = adis16575_sync_mode,
  1214. .num_sync = ARRAY_SIZE(adis16575_sync_mode),
  1215. .flags = ADIS16475_HAS_BURST32 |
  1216. ADIS16475_HAS_BURST_DELTA_DATA |
  1217. ADIS16475_NEEDS_BURST_REQUEST |
  1218. ADIS16475_HAS_TIMESTAMP32,
  1219. .adis_data = ADIS16475_DATA(16575, &adis16475_timeouts,
  1220. ADIS16575_BURST32_DATA_TS32,
  1221. ADIS16575_BURST_MAX_SPEED, true),
  1222. },
  1223. [ADIS16575_3] = {
  1224. .name = "adis16575-3",
  1225. .num_channels = ARRAY_SIZE(adis16575_channels),
  1226. .channels = adis16575_channels,
  1227. .gyro_max_val = 1,
  1228. .gyro_max_scale = IIO_RAD_TO_DEGREE(10 << 16),
  1229. .accel_max_val = 8,
  1230. .accel_max_scale = IIO_M_S_2_TO_G(32000 << 16),
  1231. .temp_scale = 100,
  1232. .deltang_max_val = IIO_DEGREE_TO_RAD(2000),
  1233. .deltvel_max_val = 100,
  1234. .int_clk = 4000,
  1235. .max_dec = 3999,
  1236. .sync = adis16575_sync_mode,
  1237. .num_sync = ARRAY_SIZE(adis16575_sync_mode),
  1238. .flags = ADIS16475_HAS_BURST32 |
  1239. ADIS16475_HAS_BURST_DELTA_DATA |
  1240. ADIS16475_NEEDS_BURST_REQUEST |
  1241. ADIS16475_HAS_TIMESTAMP32,
  1242. .adis_data = ADIS16475_DATA(16575, &adis16475_timeouts,
  1243. ADIS16575_BURST32_DATA_TS32,
  1244. ADIS16575_BURST_MAX_SPEED, true),
  1245. },
  1246. [ADIS16576_2] = {
  1247. .name = "adis16576-2",
  1248. .num_channels = ARRAY_SIZE(adis16575_channels),
  1249. .channels = adis16575_channels,
  1250. .gyro_max_val = 1,
  1251. .gyro_max_scale = IIO_RAD_TO_DEGREE(40 << 16),
  1252. .accel_max_val = 40,
  1253. .accel_max_scale = IIO_M_S_2_TO_G(32000 << 16),
  1254. .temp_scale = 100,
  1255. .deltang_max_val = IIO_DEGREE_TO_RAD(450),
  1256. .deltvel_max_val = 125,
  1257. .int_clk = 4000,
  1258. .max_dec = 3999,
  1259. .sync = adis16575_sync_mode,
  1260. .num_sync = ARRAY_SIZE(adis16575_sync_mode),
  1261. .flags = ADIS16475_HAS_BURST32 |
  1262. ADIS16475_HAS_BURST_DELTA_DATA |
  1263. ADIS16475_NEEDS_BURST_REQUEST |
  1264. ADIS16475_HAS_TIMESTAMP32,
  1265. .adis_data = ADIS16475_DATA(16576, &adis16475_timeouts,
  1266. ADIS16575_BURST32_DATA_TS32,
  1267. ADIS16575_BURST_MAX_SPEED, true),
  1268. },
  1269. [ADIS16576_3] = {
  1270. .name = "adis16576-3",
  1271. .num_channels = ARRAY_SIZE(adis16575_channels),
  1272. .channels = adis16575_channels,
  1273. .gyro_max_val = 1,
  1274. .gyro_max_scale = IIO_RAD_TO_DEGREE(10 << 16),
  1275. .accel_max_val = 40,
  1276. .accel_max_scale = IIO_M_S_2_TO_G(32000 << 16),
  1277. .temp_scale = 100,
  1278. .deltang_max_val = IIO_DEGREE_TO_RAD(2000),
  1279. .deltvel_max_val = 125,
  1280. .int_clk = 4000,
  1281. .max_dec = 3999,
  1282. .sync = adis16575_sync_mode,
  1283. .num_sync = ARRAY_SIZE(adis16575_sync_mode),
  1284. .flags = ADIS16475_HAS_BURST32 |
  1285. ADIS16475_HAS_BURST_DELTA_DATA |
  1286. ADIS16475_NEEDS_BURST_REQUEST |
  1287. ADIS16475_HAS_TIMESTAMP32,
  1288. .adis_data = ADIS16475_DATA(16576, &adis16475_timeouts,
  1289. ADIS16575_BURST32_DATA_TS32,
  1290. ADIS16575_BURST_MAX_SPEED, true),
  1291. },
  1292. [ADIS16577_2] = {
  1293. .name = "adis16577-2",
  1294. .num_channels = ARRAY_SIZE(adis16575_channels),
  1295. .channels = adis16575_channels,
  1296. .gyro_max_val = 1,
  1297. .gyro_max_scale = IIO_RAD_TO_DEGREE(40 << 16),
  1298. .accel_max_val = 40,
  1299. .accel_max_scale = IIO_M_S_2_TO_G(32000 << 16),
  1300. .temp_scale = 100,
  1301. .deltang_max_val = IIO_DEGREE_TO_RAD(450),
  1302. .deltvel_max_val = 400,
  1303. .int_clk = 4000,
  1304. .max_dec = 3999,
  1305. .sync = adis16575_sync_mode,
  1306. .num_sync = ARRAY_SIZE(adis16575_sync_mode),
  1307. .flags = ADIS16475_HAS_BURST32 |
  1308. ADIS16475_HAS_BURST_DELTA_DATA |
  1309. ADIS16475_NEEDS_BURST_REQUEST |
  1310. ADIS16475_HAS_TIMESTAMP32,
  1311. .adis_data = ADIS16475_DATA(16577, &adis16475_timeouts,
  1312. ADIS16575_BURST32_DATA_TS32,
  1313. ADIS16575_BURST_MAX_SPEED, true),
  1314. },
  1315. [ADIS16577_3] = {
  1316. .name = "adis16577-3",
  1317. .num_channels = ARRAY_SIZE(adis16575_channels),
  1318. .channels = adis16575_channels,
  1319. .gyro_max_val = 1,
  1320. .gyro_max_scale = IIO_RAD_TO_DEGREE(10 << 16),
  1321. .accel_max_val = 40,
  1322. .accel_max_scale = IIO_M_S_2_TO_G(32000 << 16),
  1323. .temp_scale = 100,
  1324. .deltang_max_val = IIO_DEGREE_TO_RAD(2000),
  1325. .deltvel_max_val = 400,
  1326. .int_clk = 4000,
  1327. .max_dec = 3999,
  1328. .sync = adis16575_sync_mode,
  1329. .num_sync = ARRAY_SIZE(adis16575_sync_mode),
  1330. .flags = ADIS16475_HAS_BURST32 |
  1331. ADIS16475_HAS_BURST_DELTA_DATA |
  1332. ADIS16475_NEEDS_BURST_REQUEST |
  1333. ADIS16475_HAS_TIMESTAMP32,
  1334. .adis_data = ADIS16475_DATA(16577, &adis16475_timeouts,
  1335. ADIS16575_BURST32_DATA_TS32,
  1336. ADIS16575_BURST_MAX_SPEED, true),
  1337. },
  1338. };
  1339. static int adis16475_update_scan_mode(struct iio_dev *indio_dev,
  1340. const unsigned long *scan_mask)
  1341. {
  1342. u16 en;
  1343. int ret;
  1344. struct adis16475 *st = iio_priv(indio_dev);
  1345. if (st->info->flags & ADIS16475_HAS_BURST_DELTA_DATA) {
  1346. if ((*scan_mask & ADIS16500_BURST_DATA_SEL_0_CHN_MASK) &&
  1347. (*scan_mask & ADIS16500_BURST_DATA_SEL_1_CHN_MASK))
  1348. return -EINVAL;
  1349. if (*scan_mask & ADIS16500_BURST_DATA_SEL_0_CHN_MASK)
  1350. en = FIELD_PREP(ADIS16500_BURST_DATA_SEL_MASK, 0);
  1351. else
  1352. en = FIELD_PREP(ADIS16500_BURST_DATA_SEL_MASK, 1);
  1353. ret = __adis_update_bits(&st->adis, ADIS16475_REG_MSG_CTRL,
  1354. ADIS16500_BURST_DATA_SEL_MASK, en);
  1355. if (ret)
  1356. return ret;
  1357. }
  1358. return adis_update_scan_mode(indio_dev, scan_mask);
  1359. }
  1360. static const struct iio_info adis16475_info = {
  1361. .read_raw = &adis16475_read_raw,
  1362. .write_raw = &adis16475_write_raw,
  1363. .update_scan_mode = adis16475_update_scan_mode,
  1364. .debugfs_reg_access = adis_debugfs_reg_access,
  1365. };
  1366. static const struct iio_info adis16575_info = {
  1367. .read_raw = &adis16475_read_raw,
  1368. .write_raw = &adis16475_write_raw,
  1369. .update_scan_mode = adis16475_update_scan_mode,
  1370. .debugfs_reg_access = adis_debugfs_reg_access,
  1371. .hwfifo_set_watermark = adis16475_set_watermark,
  1372. };
  1373. static bool adis16475_validate_crc(const u8 *buffer, u16 crc,
  1374. u16 burst_size, u16 start_idx)
  1375. {
  1376. int i;
  1377. for (i = start_idx; i < burst_size - 2; i++)
  1378. crc -= buffer[i];
  1379. return crc == 0;
  1380. }
  1381. static void adis16475_burst32_check(struct adis16475 *st)
  1382. {
  1383. int ret;
  1384. struct adis *adis = &st->adis;
  1385. u8 timestamp32 = 0;
  1386. if (!(st->info->flags & ADIS16475_HAS_BURST32))
  1387. return;
  1388. if (st->info->flags & ADIS16475_HAS_TIMESTAMP32)
  1389. timestamp32 = 1;
  1390. if (st->lsb_flag && !st->burst32) {
  1391. const u16 en = ADIS16500_BURST32(1);
  1392. ret = __adis_update_bits(&st->adis, ADIS16475_REG_MSG_CTRL,
  1393. ADIS16500_BURST32_MASK, en);
  1394. if (ret)
  1395. return;
  1396. st->burst32 = true;
  1397. /*
  1398. * In 32-bit mode we need extra 2 bytes for all gyro
  1399. * and accel channels.
  1400. * If the device has 32-bit timestamp value we need 2 extra
  1401. * bytes for it.
  1402. */
  1403. adis->burst_extra_len = (6 + timestamp32) * sizeof(u16);
  1404. adis->xfer[1].len += (6 + timestamp32) * sizeof(u16);
  1405. dev_dbg(&adis->spi->dev, "Enable burst32 mode, xfer:%d",
  1406. adis->xfer[1].len);
  1407. } else if (!st->lsb_flag && st->burst32) {
  1408. const u16 en = ADIS16500_BURST32(0);
  1409. ret = __adis_update_bits(&st->adis, ADIS16475_REG_MSG_CTRL,
  1410. ADIS16500_BURST32_MASK, en);
  1411. if (ret)
  1412. return;
  1413. st->burst32 = false;
  1414. /* Remove the extra bits */
  1415. adis->burst_extra_len = 0;
  1416. adis->xfer[1].len -= (6 + timestamp32) * sizeof(u16);
  1417. dev_dbg(&adis->spi->dev, "Disable burst32 mode, xfer:%d\n",
  1418. adis->xfer[1].len);
  1419. }
  1420. }
  1421. static int adis16475_push_single_sample(struct iio_poll_func *pf)
  1422. {
  1423. struct iio_dev *indio_dev = pf->indio_dev;
  1424. struct adis16475 *st = iio_priv(indio_dev);
  1425. struct adis *adis = &st->adis;
  1426. int ret, bit, buff_offset = 0, i = 0;
  1427. __be16 *buffer;
  1428. u16 crc;
  1429. bool valid;
  1430. u8 crc_offset = 9;
  1431. u16 burst_size = ADIS16475_BURST_MAX_DATA;
  1432. u16 start_idx = (st->info->flags & ADIS16475_HAS_TIMESTAMP32) ? 2 : 0;
  1433. /* offset until the first element after gyro and accel */
  1434. const u8 offset = st->burst32 ? 13 : 7;
  1435. if (st->burst32) {
  1436. crc_offset = (st->info->flags & ADIS16475_HAS_TIMESTAMP32) ? 16 : 15;
  1437. burst_size = adis->data->burst_max_len;
  1438. }
  1439. ret = spi_sync(adis->spi, &adis->msg);
  1440. if (ret)
  1441. return ret;
  1442. buffer = adis->buffer;
  1443. crc = be16_to_cpu(buffer[crc_offset]);
  1444. valid = adis16475_validate_crc(adis->buffer, crc, burst_size, start_idx);
  1445. if (!valid) {
  1446. dev_err(&adis->spi->dev, "Invalid crc\n");
  1447. return -EINVAL;
  1448. }
  1449. iio_for_each_active_channel(indio_dev, bit) {
  1450. /*
  1451. * When burst mode is used, system flags is the first data
  1452. * channel in the sequence, but the scan index is 7.
  1453. */
  1454. switch (bit) {
  1455. case ADIS16475_SCAN_TEMP:
  1456. st->data[i++] = buffer[offset];
  1457. /*
  1458. * The temperature channel has 16-bit storage size.
  1459. * We need to perform the padding to have the buffer
  1460. * elements naturally aligned in case there are any
  1461. * 32-bit storage size channels enabled which have a
  1462. * scan index higher than the temperature channel scan
  1463. * index.
  1464. */
  1465. if (*indio_dev->active_scan_mask & GENMASK(ADIS16475_SCAN_DELTVEL_Z, ADIS16475_SCAN_DELTANG_X))
  1466. st->data[i++] = 0;
  1467. break;
  1468. case ADIS16475_SCAN_DELTANG_X ... ADIS16475_SCAN_DELTVEL_Z:
  1469. buff_offset = ADIS16475_SCAN_DELTANG_X;
  1470. fallthrough;
  1471. case ADIS16475_SCAN_GYRO_X ... ADIS16475_SCAN_ACCEL_Z:
  1472. /*
  1473. * The first 2 bytes on the received data are the
  1474. * DIAG_STAT reg, hence the +1 offset here...
  1475. */
  1476. if (st->burst32) {
  1477. /* upper 16 */
  1478. st->data[i++] = buffer[(bit - buff_offset) * 2 + 2];
  1479. /* lower 16 */
  1480. st->data[i++] = buffer[(bit - buff_offset) * 2 + 1];
  1481. } else {
  1482. st->data[i++] = buffer[(bit - buff_offset) + 1];
  1483. /*
  1484. * Don't bother in doing the manual read if the
  1485. * device supports burst32. burst32 will be
  1486. * enabled in the next call to
  1487. * adis16475_burst32_check()...
  1488. */
  1489. if (st->lsb_flag && !(st->info->flags & ADIS16475_HAS_BURST32)) {
  1490. u16 val = 0;
  1491. const u32 reg = ADIS16475_REG_X_GYRO_L +
  1492. bit * 4;
  1493. adis_read_reg_16(adis, reg, &val);
  1494. st->data[i++] = cpu_to_be16(val);
  1495. } else {
  1496. /* lower not used */
  1497. st->data[i++] = 0;
  1498. }
  1499. }
  1500. break;
  1501. }
  1502. }
  1503. /* There might not be a timestamp option for some devices. */
  1504. iio_push_to_buffers_with_timestamp(indio_dev, st->data, pf->timestamp);
  1505. return 0;
  1506. }
  1507. static irqreturn_t adis16475_trigger_handler(int irq, void *p)
  1508. {
  1509. struct iio_poll_func *pf = p;
  1510. struct iio_dev *indio_dev = pf->indio_dev;
  1511. struct adis16475 *st = iio_priv(indio_dev);
  1512. adis16475_push_single_sample(pf);
  1513. /*
  1514. * We only check the burst mode at the end of the current capture since
  1515. * it takes a full data ready cycle for the device to update the burst
  1516. * array.
  1517. */
  1518. adis16475_burst32_check(st);
  1519. iio_trigger_notify_done(indio_dev->trig);
  1520. return IRQ_HANDLED;
  1521. }
  1522. /*
  1523. * This function updates the first tx byte from the adis message based on the
  1524. * given burst request.
  1525. */
  1526. static void adis16575_update_msg_for_burst(struct adis *adis, u8 burst_req)
  1527. {
  1528. unsigned int burst_max_length;
  1529. u8 *tx;
  1530. if (adis->data->burst_max_len)
  1531. burst_max_length = adis->data->burst_max_len;
  1532. else
  1533. burst_max_length = adis->data->burst_len + adis->burst_extra_len;
  1534. tx = adis->buffer + burst_max_length;
  1535. tx[0] = ADIS_READ_REG(burst_req);
  1536. }
  1537. static int adis16575_custom_burst_read(struct iio_poll_func *pf, u8 burst_req)
  1538. {
  1539. struct iio_dev *indio_dev = pf->indio_dev;
  1540. struct adis16475 *st = iio_priv(indio_dev);
  1541. struct adis *adis = &st->adis;
  1542. adis16575_update_msg_for_burst(adis, burst_req);
  1543. if (burst_req)
  1544. return spi_sync(adis->spi, &adis->msg);
  1545. return adis16475_push_single_sample(pf);
  1546. }
  1547. /*
  1548. * This handler is meant to be used for devices which support burst readings
  1549. * from FIFO (namely devices from adis1657x family).
  1550. * In order to pop the FIFO the 0x68 0x00 FIFO pop burst request has to be sent.
  1551. * If the previous device command was not a FIFO pop burst request, the FIFO pop
  1552. * burst request will simply pop the FIFO without returning valid data.
  1553. * For the nth consecutive burst request, thedevice will send the data popped
  1554. * with the (n-1)th consecutive burst request.
  1555. * In order to read the data which was popped previously, without popping the
  1556. * FIFO, the 0x00 0x00 burst request has to be sent.
  1557. * If after a 0x68 0x00 FIFO pop burst request, there is any other device access
  1558. * different from a 0x68 0x00 or a 0x00 0x00 burst request, the FIFO data popped
  1559. * previously will be lost.
  1560. */
  1561. static irqreturn_t adis16475_trigger_handler_with_fifo(int irq, void *p)
  1562. {
  1563. struct iio_poll_func *pf = p;
  1564. struct iio_dev *indio_dev = pf->indio_dev;
  1565. struct adis16475 *st = iio_priv(indio_dev);
  1566. struct adis *adis = &st->adis;
  1567. int ret;
  1568. u16 fifo_cnt, i;
  1569. adis_dev_auto_lock(&st->adis);
  1570. ret = __adis_read_reg_16(adis, ADIS16575_REG_FIFO_CNT, &fifo_cnt);
  1571. if (ret)
  1572. goto unlock;
  1573. /*
  1574. * If no sample is available, nothing can be read. This can happen if
  1575. * a the used trigger has a higher frequency than the selected sample rate.
  1576. */
  1577. if (!fifo_cnt)
  1578. goto unlock;
  1579. /*
  1580. * First burst request - FIFO pop: popped data will be returned in the
  1581. * next burst request.
  1582. */
  1583. ret = adis16575_custom_burst_read(pf, adis->data->burst_reg_cmd);
  1584. if (ret)
  1585. goto unlock;
  1586. for (i = 0; i < fifo_cnt - 1; i++) {
  1587. ret = adis16475_push_single_sample(pf);
  1588. if (ret)
  1589. goto unlock;
  1590. }
  1591. /* FIFO read without popping */
  1592. ret = adis16575_custom_burst_read(pf, 0);
  1593. unlock:
  1594. /*
  1595. * We only check the burst mode at the end of the current capture since
  1596. * reading data from registers will impact the FIFO reading.
  1597. */
  1598. adis16475_burst32_check(st);
  1599. iio_trigger_notify_done(indio_dev->trig);
  1600. return IRQ_HANDLED;
  1601. }
  1602. static int adis16475_config_sync_mode(struct adis16475 *st)
  1603. {
  1604. int ret;
  1605. struct device *dev = &st->adis.spi->dev;
  1606. const struct adis16475_sync *sync;
  1607. u32 sync_mode;
  1608. u16 max_sample_rate = st->info->int_clk + 100;
  1609. u16 val;
  1610. /* if available, enable 4khz internal clock */
  1611. if (st->info->int_clk == 4000) {
  1612. ret = __adis_update_bits(&st->adis, ADIS16475_REG_MSG_CTRL,
  1613. ADIS16575_SYNC_4KHZ_MASK,
  1614. (u16)ADIS16575_SYNC_4KHZ(1));
  1615. if (ret)
  1616. return ret;
  1617. }
  1618. /* default to internal clk */
  1619. st->clk_freq = st->info->int_clk * 1000;
  1620. ret = device_property_read_u32(dev, "adi,sync-mode", &sync_mode);
  1621. if (ret)
  1622. return 0;
  1623. if (sync_mode >= st->info->num_sync) {
  1624. dev_err(dev, "Invalid sync mode: %u for %s\n", sync_mode,
  1625. st->info->name);
  1626. return -EINVAL;
  1627. }
  1628. sync = &st->info->sync[sync_mode];
  1629. st->sync_mode = sync->sync_mode;
  1630. /* All the other modes require external input signal */
  1631. if (sync->sync_mode != ADIS16475_SYNC_OUTPUT) {
  1632. struct clk *clk = devm_clk_get_enabled(dev, NULL);
  1633. if (IS_ERR(clk))
  1634. return PTR_ERR(clk);
  1635. st->clk_freq = clk_get_rate(clk);
  1636. if (st->clk_freq < sync->min_rate ||
  1637. st->clk_freq > sync->max_rate) {
  1638. dev_err(dev,
  1639. "Clk rate:%u not in a valid range:[%u %u]\n",
  1640. st->clk_freq, sync->min_rate, sync->max_rate);
  1641. return -EINVAL;
  1642. }
  1643. if (sync->sync_mode == ADIS16475_SYNC_SCALED) {
  1644. u16 up_scale;
  1645. /*
  1646. * In sync scaled mode, the IMU sample rate is the clk_freq * sync_scale.
  1647. * Hence, default the IMU sample rate to the highest multiple of the input
  1648. * clock lower than the IMU max sample rate.
  1649. */
  1650. up_scale = max_sample_rate / st->clk_freq;
  1651. ret = __adis_write_reg_16(&st->adis,
  1652. ADIS16475_REG_UP_SCALE,
  1653. up_scale);
  1654. if (ret)
  1655. return ret;
  1656. }
  1657. st->clk_freq *= 1000;
  1658. }
  1659. /*
  1660. * Keep in mind that the mask for the clk modes in adis1650*
  1661. * chips is different (1100 instead of 11100). However, we
  1662. * are not configuring BIT(4) in these chips and the default
  1663. * value is 0, so we are fine in doing the below operations.
  1664. * I'm keeping this for simplicity and avoiding extra variables
  1665. * in chip_info.
  1666. */
  1667. val = ADIS16475_SYNC_MODE(sync->sync_mode);
  1668. ret = __adis_update_bits(&st->adis, ADIS16475_REG_MSG_CTRL,
  1669. ADIS16475_SYNC_MODE_MASK, val);
  1670. if (ret)
  1671. return ret;
  1672. usleep_range(250, 260);
  1673. return 0;
  1674. }
  1675. static int adis16475_config_irq_pin(struct adis16475 *st)
  1676. {
  1677. int ret;
  1678. u32 irq_type;
  1679. u16 val = 0;
  1680. u8 polarity;
  1681. struct spi_device *spi = st->adis.spi;
  1682. irq_type = irq_get_trigger_type(spi->irq);
  1683. if (st->adis.data->has_fifo) {
  1684. /*
  1685. * It is possible to configure the fifo watermark pin polarity.
  1686. * Furthermore, we need to update the adis struct if we want the
  1687. * watermark pin active low.
  1688. */
  1689. if (irq_type == IRQ_TYPE_LEVEL_HIGH) {
  1690. polarity = 1;
  1691. st->adis.irq_flag = IRQF_TRIGGER_HIGH;
  1692. } else if (irq_type == IRQ_TYPE_LEVEL_LOW) {
  1693. polarity = 0;
  1694. st->adis.irq_flag = IRQF_TRIGGER_LOW;
  1695. } else {
  1696. dev_err(&spi->dev, "Invalid interrupt type 0x%x specified\n",
  1697. irq_type);
  1698. return -EINVAL;
  1699. }
  1700. /* Configure the watermark pin polarity. */
  1701. val = ADIS16575_WM_POL(polarity);
  1702. ret = adis_update_bits(&st->adis, ADIS16475_REG_FIFO_CTRL,
  1703. ADIS16575_WM_POL_MASK, val);
  1704. if (ret)
  1705. return ret;
  1706. /* Enable watermark interrupt pin. */
  1707. ret = adis_update_bits(&st->adis, ADIS16475_REG_FIFO_CTRL,
  1708. ADIS16575_WM_EN_MASK,
  1709. (u16)ADIS16575_WM_EN(1));
  1710. if (ret)
  1711. return ret;
  1712. } else {
  1713. /*
  1714. * It is possible to configure the data ready polarity. Furthermore, we
  1715. * need to update the adis struct if we want data ready as active low.
  1716. */
  1717. if (irq_type == IRQ_TYPE_EDGE_RISING) {
  1718. polarity = 1;
  1719. st->adis.irq_flag = IRQF_TRIGGER_RISING;
  1720. } else if (irq_type == IRQ_TYPE_EDGE_FALLING) {
  1721. polarity = 0;
  1722. st->adis.irq_flag = IRQF_TRIGGER_FALLING;
  1723. } else {
  1724. dev_err(&spi->dev, "Invalid interrupt type 0x%x specified\n",
  1725. irq_type);
  1726. return -EINVAL;
  1727. }
  1728. val = ADIS16475_MSG_CTRL_DR_POL(polarity);
  1729. ret = __adis_update_bits(&st->adis, ADIS16475_REG_MSG_CTRL,
  1730. ADIS16475_MSG_CTRL_DR_POL_MASK, val);
  1731. if (ret)
  1732. return ret;
  1733. /*
  1734. * There is a delay writing to any bits written to the MSC_CTRL
  1735. * register. It should not be bigger than 200us, so 250 should be more
  1736. * than enough!
  1737. */
  1738. usleep_range(250, 260);
  1739. }
  1740. return 0;
  1741. }
  1742. static int adis16475_probe(struct spi_device *spi)
  1743. {
  1744. struct iio_dev *indio_dev;
  1745. struct adis16475 *st;
  1746. int ret;
  1747. u16 val;
  1748. indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
  1749. if (!indio_dev)
  1750. return -ENOMEM;
  1751. st = iio_priv(indio_dev);
  1752. st->info = spi_get_device_match_data(spi);
  1753. if (!st->info)
  1754. return -EINVAL;
  1755. ret = adis_init(&st->adis, indio_dev, spi, &st->info->adis_data);
  1756. if (ret)
  1757. return ret;
  1758. indio_dev->name = st->info->name;
  1759. indio_dev->channels = st->info->channels;
  1760. indio_dev->num_channels = st->info->num_channels;
  1761. if (st->adis.data->has_fifo)
  1762. indio_dev->info = &adis16575_info;
  1763. else
  1764. indio_dev->info = &adis16475_info;
  1765. indio_dev->modes = INDIO_DIRECT_MODE;
  1766. ret = __adis_initial_startup(&st->adis);
  1767. if (ret)
  1768. return ret;
  1769. ret = adis16475_config_irq_pin(st);
  1770. if (ret)
  1771. return ret;
  1772. ret = adis16475_config_sync_mode(st);
  1773. if (ret)
  1774. return ret;
  1775. if (st->adis.data->has_fifo) {
  1776. ret = devm_adis_setup_buffer_and_trigger_with_attrs(&st->adis, indio_dev,
  1777. adis16475_trigger_handler_with_fifo,
  1778. &adis16475_buffer_ops,
  1779. adis16475_fifo_attributes);
  1780. if (ret)
  1781. return ret;
  1782. /* Update overflow behavior to always overwrite the oldest sample. */
  1783. val = ADIS16575_OVERWRITE_OLDEST;
  1784. ret = adis_update_bits(&st->adis, ADIS16475_REG_FIFO_CTRL,
  1785. ADIS16575_OVERFLOW_MASK, val);
  1786. if (ret)
  1787. return ret;
  1788. } else {
  1789. ret = devm_adis_setup_buffer_and_trigger(&st->adis, indio_dev,
  1790. adis16475_trigger_handler);
  1791. if (ret)
  1792. return ret;
  1793. }
  1794. ret = devm_iio_device_register(&spi->dev, indio_dev);
  1795. if (ret)
  1796. return ret;
  1797. adis16475_debugfs_init(indio_dev);
  1798. return 0;
  1799. }
  1800. static const struct of_device_id adis16475_of_match[] = {
  1801. { .compatible = "adi,adis16470",
  1802. .data = &adis16475_chip_info[ADIS16470] },
  1803. { .compatible = "adi,adis16475-1",
  1804. .data = &adis16475_chip_info[ADIS16475_1] },
  1805. { .compatible = "adi,adis16475-2",
  1806. .data = &adis16475_chip_info[ADIS16475_2] },
  1807. { .compatible = "adi,adis16475-3",
  1808. .data = &adis16475_chip_info[ADIS16475_3] },
  1809. { .compatible = "adi,adis16477-1",
  1810. .data = &adis16475_chip_info[ADIS16477_1] },
  1811. { .compatible = "adi,adis16477-2",
  1812. .data = &adis16475_chip_info[ADIS16477_2] },
  1813. { .compatible = "adi,adis16477-3",
  1814. .data = &adis16475_chip_info[ADIS16477_3] },
  1815. { .compatible = "adi,adis16465-1",
  1816. .data = &adis16475_chip_info[ADIS16465_1] },
  1817. { .compatible = "adi,adis16465-2",
  1818. .data = &adis16475_chip_info[ADIS16465_2] },
  1819. { .compatible = "adi,adis16465-3",
  1820. .data = &adis16475_chip_info[ADIS16465_3] },
  1821. { .compatible = "adi,adis16467-1",
  1822. .data = &adis16475_chip_info[ADIS16467_1] },
  1823. { .compatible = "adi,adis16467-2",
  1824. .data = &adis16475_chip_info[ADIS16467_2] },
  1825. { .compatible = "adi,adis16467-3",
  1826. .data = &adis16475_chip_info[ADIS16467_3] },
  1827. { .compatible = "adi,adis16500",
  1828. .data = &adis16475_chip_info[ADIS16500] },
  1829. { .compatible = "adi,adis16501",
  1830. .data = &adis16475_chip_info[ADIS16501] },
  1831. { .compatible = "adi,adis16505-1",
  1832. .data = &adis16475_chip_info[ADIS16505_1] },
  1833. { .compatible = "adi,adis16505-2",
  1834. .data = &adis16475_chip_info[ADIS16505_2] },
  1835. { .compatible = "adi,adis16505-3",
  1836. .data = &adis16475_chip_info[ADIS16505_3] },
  1837. { .compatible = "adi,adis16507-1",
  1838. .data = &adis16475_chip_info[ADIS16507_1] },
  1839. { .compatible = "adi,adis16507-2",
  1840. .data = &adis16475_chip_info[ADIS16507_2] },
  1841. { .compatible = "adi,adis16507-3",
  1842. .data = &adis16475_chip_info[ADIS16507_3] },
  1843. { .compatible = "adi,adis16575-2",
  1844. .data = &adis16475_chip_info[ADIS16575_2] },
  1845. { .compatible = "adi,adis16575-3",
  1846. .data = &adis16475_chip_info[ADIS16575_3] },
  1847. { .compatible = "adi,adis16576-2",
  1848. .data = &adis16475_chip_info[ADIS16576_2] },
  1849. { .compatible = "adi,adis16576-3",
  1850. .data = &adis16475_chip_info[ADIS16576_3] },
  1851. { .compatible = "adi,adis16577-2",
  1852. .data = &adis16475_chip_info[ADIS16577_2] },
  1853. { .compatible = "adi,adis16577-3",
  1854. .data = &adis16475_chip_info[ADIS16577_3] },
  1855. { },
  1856. };
  1857. MODULE_DEVICE_TABLE(of, adis16475_of_match);
  1858. static const struct spi_device_id adis16475_ids[] = {
  1859. { "adis16470", (kernel_ulong_t)&adis16475_chip_info[ADIS16470] },
  1860. { "adis16475-1", (kernel_ulong_t)&adis16475_chip_info[ADIS16475_1] },
  1861. { "adis16475-2", (kernel_ulong_t)&adis16475_chip_info[ADIS16475_2] },
  1862. { "adis16475-3", (kernel_ulong_t)&adis16475_chip_info[ADIS16475_3] },
  1863. { "adis16477-1", (kernel_ulong_t)&adis16475_chip_info[ADIS16477_1] },
  1864. { "adis16477-2", (kernel_ulong_t)&adis16475_chip_info[ADIS16477_2] },
  1865. { "adis16477-3", (kernel_ulong_t)&adis16475_chip_info[ADIS16477_3] },
  1866. { "adis16465-1", (kernel_ulong_t)&adis16475_chip_info[ADIS16465_1] },
  1867. { "adis16465-2", (kernel_ulong_t)&adis16475_chip_info[ADIS16465_2] },
  1868. { "adis16465-3", (kernel_ulong_t)&adis16475_chip_info[ADIS16465_3] },
  1869. { "adis16467-1", (kernel_ulong_t)&adis16475_chip_info[ADIS16467_1] },
  1870. { "adis16467-2", (kernel_ulong_t)&adis16475_chip_info[ADIS16467_2] },
  1871. { "adis16467-3", (kernel_ulong_t)&adis16475_chip_info[ADIS16467_3] },
  1872. { "adis16500", (kernel_ulong_t)&adis16475_chip_info[ADIS16500] },
  1873. { "adis16501", (kernel_ulong_t)&adis16475_chip_info[ADIS16501] },
  1874. { "adis16505-1", (kernel_ulong_t)&adis16475_chip_info[ADIS16505_1] },
  1875. { "adis16505-2", (kernel_ulong_t)&adis16475_chip_info[ADIS16505_2] },
  1876. { "adis16505-3", (kernel_ulong_t)&adis16475_chip_info[ADIS16505_3] },
  1877. { "adis16507-1", (kernel_ulong_t)&adis16475_chip_info[ADIS16507_1] },
  1878. { "adis16507-2", (kernel_ulong_t)&adis16475_chip_info[ADIS16507_2] },
  1879. { "adis16507-3", (kernel_ulong_t)&adis16475_chip_info[ADIS16507_3] },
  1880. { "adis16575-2", (kernel_ulong_t)&adis16475_chip_info[ADIS16575_2] },
  1881. { "adis16575-3", (kernel_ulong_t)&adis16475_chip_info[ADIS16575_3] },
  1882. { "adis16576-2", (kernel_ulong_t)&adis16475_chip_info[ADIS16576_2] },
  1883. { "adis16576-3", (kernel_ulong_t)&adis16475_chip_info[ADIS16576_3] },
  1884. { "adis16577-2", (kernel_ulong_t)&adis16475_chip_info[ADIS16577_2] },
  1885. { "adis16577-3", (kernel_ulong_t)&adis16475_chip_info[ADIS16577_3] },
  1886. { }
  1887. };
  1888. MODULE_DEVICE_TABLE(spi, adis16475_ids);
  1889. static struct spi_driver adis16475_driver = {
  1890. .driver = {
  1891. .name = "adis16475",
  1892. .of_match_table = adis16475_of_match,
  1893. },
  1894. .probe = adis16475_probe,
  1895. .id_table = adis16475_ids,
  1896. };
  1897. module_spi_driver(adis16475_driver);
  1898. MODULE_AUTHOR("Nuno Sa <nuno.sa@analog.com>");
  1899. MODULE_DESCRIPTION("Analog Devices ADIS16475 IMU driver");
  1900. MODULE_LICENSE("GPL");
  1901. MODULE_IMPORT_NS(IIO_ADISLIB);