ad7380.c 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Analog Devices AD738x Simultaneous Sampling SAR ADCs
  4. *
  5. * Copyright 2017 Analog Devices Inc.
  6. * Copyright 2024 BayLibre, SAS
  7. *
  8. * Datasheets of supported parts:
  9. * ad7380/1 : https://www.analog.com/media/en/technical-documentation/data-sheets/AD7380-7381.pdf
  10. * ad7383/4 : https://www.analog.com/media/en/technical-documentation/data-sheets/ad7383-7384.pdf
  11. * ad7386/7/8 : https://www.analog.com/media/en/technical-documentation/data-sheets/AD7386-7387-7388.pdf
  12. * ad7380-4 : https://www.analog.com/media/en/technical-documentation/data-sheets/ad7380-4.pdf
  13. * ad7381-4 : https://www.analog.com/media/en/technical-documentation/data-sheets/ad7381-4.pdf
  14. * ad7383/4-4 : https://www.analog.com/media/en/technical-documentation/data-sheets/ad7383-4-ad7384-4.pdf
  15. * ad7386/7/8-4 : https://www.analog.com/media/en/technical-documentation/data-sheets/ad7386-4-7387-4-7388-4.pdf
  16. * ad7389-4 : https://www.analog.com/media/en/technical-documentation/data-sheets/ad7389-4.pdf
  17. * adaq4370-4 : https://www.analog.com/media/en/technical-documentation/data-sheets/adaq4370-4.pdf
  18. * adaq4380-4 : https://www.analog.com/media/en/technical-documentation/data-sheets/adaq4380-4.pdf
  19. * adaq4381-4 : https://www.analog.com/media/en/technical-documentation/data-sheets/adaq4381-4.pdf
  20. *
  21. * HDL ad738x_fmc: https://analogdevicesinc.github.io/hdl/projects/ad738x_fmc/index.html
  22. *
  23. */
  24. #include <linux/align.h>
  25. #include <linux/bitfield.h>
  26. #include <linux/bitops.h>
  27. #include <linux/cleanup.h>
  28. #include <linux/device.h>
  29. #include <linux/err.h>
  30. #include <linux/kernel.h>
  31. #include <linux/math.h>
  32. #include <linux/module.h>
  33. #include <linux/regmap.h>
  34. #include <linux/regulator/consumer.h>
  35. #include <linux/slab.h>
  36. #include <linux/spi/offload/consumer.h>
  37. #include <linux/spi/spi.h>
  38. #include <linux/units.h>
  39. #include <linux/util_macros.h>
  40. #include <linux/iio/buffer.h>
  41. #include <linux/iio/buffer-dmaengine.h>
  42. #include <linux/iio/events.h>
  43. #include <linux/iio/iio.h>
  44. #include <linux/iio/trigger_consumer.h>
  45. #include <linux/iio/triggered_buffer.h>
  46. #define MAX_NUM_CHANNELS 8
  47. /* 2.5V internal reference voltage */
  48. #define AD7380_INTERNAL_REF_MV 2500
  49. /* 3.3V internal reference voltage for ADAQ */
  50. #define ADAQ4380_INTERNAL_REF_MV 3300
  51. /* reading and writing registers is more reliable at lower than max speed */
  52. #define AD7380_REG_WR_SPEED_HZ 10000000
  53. #define AD7380_REG_WR BIT(15)
  54. #define AD7380_REG_REGADDR GENMASK(14, 12)
  55. #define AD7380_REG_DATA GENMASK(11, 0)
  56. #define AD7380_REG_ADDR_NOP 0x0
  57. #define AD7380_REG_ADDR_CONFIG1 0x1
  58. #define AD7380_REG_ADDR_CONFIG2 0x2
  59. #define AD7380_REG_ADDR_ALERT 0x3
  60. #define AD7380_REG_ADDR_ALERT_LOW_TH 0x4
  61. #define AD7380_REG_ADDR_ALERT_HIGH_TH 0x5
  62. #define AD7380_CONFIG1_CH BIT(11)
  63. #define AD7380_CONFIG1_SEQ BIT(10)
  64. #define AD7380_CONFIG1_OS_MODE BIT(9)
  65. #define AD7380_CONFIG1_OSR GENMASK(8, 6)
  66. #define AD7380_CONFIG1_CRC_W BIT(5)
  67. #define AD7380_CONFIG1_CRC_R BIT(4)
  68. #define AD7380_CONFIG1_ALERTEN BIT(3)
  69. #define AD7380_CONFIG1_RES BIT(2)
  70. #define AD7380_CONFIG1_REFSEL BIT(1)
  71. #define AD7380_CONFIG1_PMODE BIT(0)
  72. #define AD7380_CONFIG2_SDO2 GENMASK(9, 8)
  73. #define AD7380_CONFIG2_SDO BIT(8)
  74. #define AD7380_CONFIG2_RESET GENMASK(7, 0)
  75. #define AD7380_CONFIG2_RESET_SOFT 0x3C
  76. #define AD7380_CONFIG2_RESET_HARD 0xFF
  77. #define AD7380_ALERT_LOW_TH GENMASK(11, 0)
  78. #define AD7380_ALERT_HIGH_TH GENMASK(11, 0)
  79. #define T_CONVERT_NS 190 /* conversion time */
  80. #define T_CONVERT_0_NS 10 /* 1st conversion start time (oversampling) */
  81. #define T_CONVERT_X_NS 500 /* xth conversion start time (oversampling) */
  82. #define T_POWERUP_US 5000 /* Power up */
  83. /*
  84. * AD738x support several SDO lines to increase throughput, but driver currently
  85. * supports only 1 SDO line (standard SPI transaction)
  86. */
  87. #define AD7380_NUM_SDO_LINES 1
  88. #define AD7380_DEFAULT_GAIN_MILLI 1000
  89. /*
  90. * Using SPI offload, storagebits is always 32, so can't be used to compute struct
  91. * spi_transfer.len. Using realbits instead.
  92. */
  93. #define AD7380_SPI_BYTES(scan_type) ((scan_type)->realbits > 16 ? 4 : 2)
  94. struct ad7380_timing_specs {
  95. const unsigned int t_csh_ns; /* CS minimum high time */
  96. };
  97. struct ad7380_chip_info {
  98. const char *name;
  99. const struct iio_chan_spec *channels;
  100. const struct iio_chan_spec *offload_channels;
  101. unsigned int num_channels;
  102. unsigned int num_simult_channels;
  103. bool has_hardware_gain;
  104. bool has_mux;
  105. const char * const *supplies;
  106. unsigned int num_supplies;
  107. bool external_ref_only;
  108. bool internal_ref_only;
  109. unsigned int internal_ref_mv;
  110. const char * const *vcm_supplies;
  111. unsigned int num_vcm_supplies;
  112. const unsigned long *available_scan_masks;
  113. const struct ad7380_timing_specs *timing_specs;
  114. u32 max_conversion_rate_hz;
  115. };
  116. static const struct iio_event_spec ad7380_events[] = {
  117. {
  118. .type = IIO_EV_TYPE_THRESH,
  119. .dir = IIO_EV_DIR_RISING,
  120. .mask_shared_by_dir = BIT(IIO_EV_INFO_VALUE),
  121. },
  122. {
  123. .type = IIO_EV_TYPE_THRESH,
  124. .dir = IIO_EV_DIR_FALLING,
  125. .mask_shared_by_dir = BIT(IIO_EV_INFO_VALUE),
  126. },
  127. {
  128. .type = IIO_EV_TYPE_THRESH,
  129. .dir = IIO_EV_DIR_EITHER,
  130. .mask_shared_by_all = BIT(IIO_EV_INFO_ENABLE),
  131. },
  132. };
  133. enum {
  134. AD7380_SCAN_TYPE_NORMAL,
  135. AD7380_SCAN_TYPE_RESOLUTION_BOOST,
  136. };
  137. /* Extended scan types for 12-bit unsigned chips. */
  138. static const struct iio_scan_type ad7380_scan_type_12_u[] = {
  139. [AD7380_SCAN_TYPE_NORMAL] = {
  140. .sign = 'u',
  141. .realbits = 12,
  142. .storagebits = 16,
  143. .endianness = IIO_CPU,
  144. },
  145. [AD7380_SCAN_TYPE_RESOLUTION_BOOST] = {
  146. .sign = 'u',
  147. .realbits = 14,
  148. .storagebits = 16,
  149. .endianness = IIO_CPU,
  150. },
  151. };
  152. /* Extended scan types for 14-bit signed chips. */
  153. static const struct iio_scan_type ad7380_scan_type_14_s[] = {
  154. [AD7380_SCAN_TYPE_NORMAL] = {
  155. .sign = 's',
  156. .realbits = 14,
  157. .storagebits = 16,
  158. .endianness = IIO_CPU,
  159. },
  160. [AD7380_SCAN_TYPE_RESOLUTION_BOOST] = {
  161. .sign = 's',
  162. .realbits = 16,
  163. .storagebits = 16,
  164. .endianness = IIO_CPU,
  165. },
  166. };
  167. /* Extended scan types for 14-bit unsigned chips. */
  168. static const struct iio_scan_type ad7380_scan_type_14_u[] = {
  169. [AD7380_SCAN_TYPE_NORMAL] = {
  170. .sign = 'u',
  171. .realbits = 14,
  172. .storagebits = 16,
  173. .endianness = IIO_CPU,
  174. },
  175. [AD7380_SCAN_TYPE_RESOLUTION_BOOST] = {
  176. .sign = 'u',
  177. .realbits = 16,
  178. .storagebits = 16,
  179. .endianness = IIO_CPU,
  180. },
  181. };
  182. /* Extended scan types for 16-bit signed_chips. */
  183. static const struct iio_scan_type ad7380_scan_type_16_s[] = {
  184. [AD7380_SCAN_TYPE_NORMAL] = {
  185. .sign = 's',
  186. .realbits = 16,
  187. .storagebits = 16,
  188. .endianness = IIO_CPU,
  189. },
  190. [AD7380_SCAN_TYPE_RESOLUTION_BOOST] = {
  191. .sign = 's',
  192. .realbits = 18,
  193. .storagebits = 32,
  194. .endianness = IIO_CPU,
  195. },
  196. };
  197. /* Extended scan types for 16-bit unsigned chips. */
  198. static const struct iio_scan_type ad7380_scan_type_16_u[] = {
  199. [AD7380_SCAN_TYPE_NORMAL] = {
  200. .sign = 'u',
  201. .realbits = 16,
  202. .storagebits = 16,
  203. .endianness = IIO_CPU,
  204. },
  205. [AD7380_SCAN_TYPE_RESOLUTION_BOOST] = {
  206. .sign = 'u',
  207. .realbits = 18,
  208. .storagebits = 32,
  209. .endianness = IIO_CPU,
  210. },
  211. };
  212. /*
  213. * Defining here scan types for offload mode, since with current available HDL
  214. * only a value of 32 for storagebits is supported.
  215. */
  216. /* Extended scan types for 12-bit unsigned chips, offload support. */
  217. static const struct iio_scan_type ad7380_scan_type_12_u_offload[] = {
  218. [AD7380_SCAN_TYPE_NORMAL] = {
  219. .sign = 'u',
  220. .realbits = 12,
  221. .storagebits = 32,
  222. .endianness = IIO_CPU,
  223. },
  224. [AD7380_SCAN_TYPE_RESOLUTION_BOOST] = {
  225. .sign = 'u',
  226. .realbits = 14,
  227. .storagebits = 32,
  228. .endianness = IIO_CPU,
  229. },
  230. };
  231. /* Extended scan types for 14-bit signed chips, offload support. */
  232. static const struct iio_scan_type ad7380_scan_type_14_s_offload[] = {
  233. [AD7380_SCAN_TYPE_NORMAL] = {
  234. .sign = 's',
  235. .realbits = 14,
  236. .storagebits = 32,
  237. .endianness = IIO_CPU,
  238. },
  239. [AD7380_SCAN_TYPE_RESOLUTION_BOOST] = {
  240. .sign = 's',
  241. .realbits = 16,
  242. .storagebits = 32,
  243. .endianness = IIO_CPU,
  244. },
  245. };
  246. /* Extended scan types for 14-bit unsigned chips, offload support. */
  247. static const struct iio_scan_type ad7380_scan_type_14_u_offload[] = {
  248. [AD7380_SCAN_TYPE_NORMAL] = {
  249. .sign = 'u',
  250. .realbits = 14,
  251. .storagebits = 32,
  252. .endianness = IIO_CPU,
  253. },
  254. [AD7380_SCAN_TYPE_RESOLUTION_BOOST] = {
  255. .sign = 'u',
  256. .realbits = 16,
  257. .storagebits = 32,
  258. .endianness = IIO_CPU,
  259. },
  260. };
  261. /* Extended scan types for 16-bit signed_chips, offload support. */
  262. static const struct iio_scan_type ad7380_scan_type_16_s_offload[] = {
  263. [AD7380_SCAN_TYPE_NORMAL] = {
  264. .sign = 's',
  265. .realbits = 16,
  266. .storagebits = 32,
  267. .endianness = IIO_CPU,
  268. },
  269. [AD7380_SCAN_TYPE_RESOLUTION_BOOST] = {
  270. .sign = 's',
  271. .realbits = 18,
  272. .storagebits = 32,
  273. .endianness = IIO_CPU,
  274. },
  275. };
  276. /* Extended scan types for 16-bit unsigned chips, offload support. */
  277. static const struct iio_scan_type ad7380_scan_type_16_u_offload[] = {
  278. [AD7380_SCAN_TYPE_NORMAL] = {
  279. .sign = 'u',
  280. .realbits = 16,
  281. .storagebits = 32,
  282. .endianness = IIO_CPU,
  283. },
  284. [AD7380_SCAN_TYPE_RESOLUTION_BOOST] = {
  285. .sign = 'u',
  286. .realbits = 18,
  287. .storagebits = 32,
  288. .endianness = IIO_CPU,
  289. },
  290. };
  291. #define _AD7380_CHANNEL(index, bits, diff, sign, gain) { \
  292. .type = IIO_VOLTAGE, \
  293. .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
  294. ((gain) ? BIT(IIO_CHAN_INFO_SCALE) : 0) | \
  295. ((diff) ? 0 : BIT(IIO_CHAN_INFO_OFFSET)), \
  296. .info_mask_shared_by_type = ((gain) ? 0 : BIT(IIO_CHAN_INFO_SCALE)) | \
  297. BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \
  298. .info_mask_shared_by_type_available = \
  299. BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \
  300. .indexed = 1, \
  301. .differential = (diff), \
  302. .channel = (diff) ? (2 * (index)) : (index), \
  303. .channel2 = (diff) ? (2 * (index) + 1) : 0, \
  304. .scan_index = (index), \
  305. .has_ext_scan_type = 1, \
  306. .ext_scan_type = ad7380_scan_type_##bits##_##sign, \
  307. .num_ext_scan_type = ARRAY_SIZE(ad7380_scan_type_##bits##_##sign), \
  308. .event_spec = ad7380_events, \
  309. .num_event_specs = ARRAY_SIZE(ad7380_events), \
  310. }
  311. #define _AD7380_OFFLOAD_CHANNEL(index, bits, diff, sign, gain) { \
  312. .type = IIO_VOLTAGE, \
  313. .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
  314. ((gain) ? BIT(IIO_CHAN_INFO_SCALE) : 0) | \
  315. ((diff) ? 0 : BIT(IIO_CHAN_INFO_OFFSET)), \
  316. .info_mask_shared_by_type = ((gain) ? 0 : BIT(IIO_CHAN_INFO_SCALE)) | \
  317. BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO) | \
  318. BIT(IIO_CHAN_INFO_SAMP_FREQ), \
  319. .info_mask_shared_by_type_available = \
  320. BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO) | \
  321. BIT(IIO_CHAN_INFO_SAMP_FREQ), \
  322. .indexed = 1, \
  323. .differential = (diff), \
  324. .channel = (diff) ? (2 * (index)) : (index), \
  325. .channel2 = (diff) ? (2 * (index) + 1) : 0, \
  326. .scan_index = (index), \
  327. .has_ext_scan_type = 1, \
  328. .ext_scan_type = ad7380_scan_type_##bits##_##sign##_offload, \
  329. .num_ext_scan_type = \
  330. ARRAY_SIZE(ad7380_scan_type_##bits##_##sign##_offload), \
  331. .event_spec = ad7380_events, \
  332. .num_event_specs = ARRAY_SIZE(ad7380_events), \
  333. }
  334. /*
  335. * Notes on the offload channels:
  336. * - There is no soft timestamp since everything is done in hardware.
  337. * - There is a sampling frequency attribute added. This controls the SPI
  338. * offload trigger.
  339. * - The storagebits value depends on the SPI offload provider. Currently there
  340. * is only one supported provider, namely the ADI PULSAR ADC HDL project,
  341. * which always uses 32-bit words for data values, even for <= 16-bit ADCs.
  342. * So the value is just hardcoded to 32 for now.
  343. */
  344. #define AD7380_CHANNEL(index, bits, diff, sign) \
  345. _AD7380_CHANNEL(index, bits, diff, sign, false)
  346. #define ADAQ4380_CHANNEL(index, bits, diff, sign) \
  347. _AD7380_CHANNEL(index, bits, diff, sign, true)
  348. #define DEFINE_AD7380_2_CHANNEL(name, bits, diff, sign) \
  349. static const struct iio_chan_spec name[] = { \
  350. AD7380_CHANNEL(0, bits, diff, sign), \
  351. AD7380_CHANNEL(1, bits, diff, sign), \
  352. IIO_CHAN_SOFT_TIMESTAMP(2), \
  353. }
  354. #define DEFINE_AD7380_4_CHANNEL(name, bits, diff, sign) \
  355. static const struct iio_chan_spec name[] = { \
  356. AD7380_CHANNEL(0, bits, diff, sign), \
  357. AD7380_CHANNEL(1, bits, diff, sign), \
  358. AD7380_CHANNEL(2, bits, diff, sign), \
  359. AD7380_CHANNEL(3, bits, diff, sign), \
  360. IIO_CHAN_SOFT_TIMESTAMP(4), \
  361. }
  362. #define DEFINE_ADAQ4380_4_CHANNEL(name, bits, diff, sign) \
  363. static const struct iio_chan_spec name[] = { \
  364. ADAQ4380_CHANNEL(0, bits, diff, sign), \
  365. ADAQ4380_CHANNEL(1, bits, diff, sign), \
  366. ADAQ4380_CHANNEL(2, bits, diff, sign), \
  367. ADAQ4380_CHANNEL(3, bits, diff, sign), \
  368. IIO_CHAN_SOFT_TIMESTAMP(4), \
  369. }
  370. #define DEFINE_AD7380_8_CHANNEL(name, bits, diff, sign) \
  371. static const struct iio_chan_spec name[] = { \
  372. AD7380_CHANNEL(0, bits, diff, sign), \
  373. AD7380_CHANNEL(1, bits, diff, sign), \
  374. AD7380_CHANNEL(2, bits, diff, sign), \
  375. AD7380_CHANNEL(3, bits, diff, sign), \
  376. AD7380_CHANNEL(4, bits, diff, sign), \
  377. AD7380_CHANNEL(5, bits, diff, sign), \
  378. AD7380_CHANNEL(6, bits, diff, sign), \
  379. AD7380_CHANNEL(7, bits, diff, sign), \
  380. IIO_CHAN_SOFT_TIMESTAMP(8), \
  381. }
  382. #define AD7380_OFFLOAD_CHANNEL(index, bits, diff, sign) \
  383. _AD7380_OFFLOAD_CHANNEL(index, bits, diff, sign, false)
  384. #define ADAQ4380_OFFLOAD_CHANNEL(index, bits, diff, sign) \
  385. _AD7380_OFFLOAD_CHANNEL(index, bits, diff, sign, true)
  386. #define DEFINE_AD7380_2_OFFLOAD_CHANNEL(name, bits, diff, sign) \
  387. static const struct iio_chan_spec name[] = { \
  388. AD7380_OFFLOAD_CHANNEL(0, bits, diff, sign), \
  389. AD7380_OFFLOAD_CHANNEL(1, bits, diff, sign), \
  390. }
  391. #define DEFINE_AD7380_4_OFFLOAD_CHANNEL(name, bits, diff, sign) \
  392. static const struct iio_chan_spec name[] = { \
  393. AD7380_OFFLOAD_CHANNEL(0, bits, diff, sign), \
  394. AD7380_OFFLOAD_CHANNEL(1, bits, diff, sign), \
  395. AD7380_OFFLOAD_CHANNEL(2, bits, diff, sign), \
  396. AD7380_OFFLOAD_CHANNEL(3, bits, diff, sign), \
  397. }
  398. #define DEFINE_ADAQ4380_4_OFFLOAD_CHANNEL(name, bits, diff, sign) \
  399. static const struct iio_chan_spec name[] = { \
  400. AD7380_OFFLOAD_CHANNEL(0, bits, diff, sign), \
  401. AD7380_OFFLOAD_CHANNEL(1, bits, diff, sign), \
  402. AD7380_OFFLOAD_CHANNEL(2, bits, diff, sign), \
  403. AD7380_OFFLOAD_CHANNEL(3, bits, diff, sign), \
  404. }
  405. #define DEFINE_AD7380_8_OFFLOAD_CHANNEL(name, bits, diff, sign) \
  406. static const struct iio_chan_spec name[] = { \
  407. AD7380_OFFLOAD_CHANNEL(0, bits, diff, sign), \
  408. AD7380_OFFLOAD_CHANNEL(1, bits, diff, sign), \
  409. AD7380_OFFLOAD_CHANNEL(2, bits, diff, sign), \
  410. AD7380_OFFLOAD_CHANNEL(3, bits, diff, sign), \
  411. AD7380_OFFLOAD_CHANNEL(4, bits, diff, sign), \
  412. AD7380_OFFLOAD_CHANNEL(5, bits, diff, sign), \
  413. AD7380_OFFLOAD_CHANNEL(6, bits, diff, sign), \
  414. AD7380_OFFLOAD_CHANNEL(7, bits, diff, sign), \
  415. }
  416. /* fully differential */
  417. DEFINE_AD7380_2_CHANNEL(ad7380_channels, 16, 1, s);
  418. DEFINE_AD7380_2_CHANNEL(ad7381_channels, 14, 1, s);
  419. DEFINE_AD7380_4_CHANNEL(ad7380_4_channels, 16, 1, s);
  420. DEFINE_AD7380_4_CHANNEL(ad7381_4_channels, 14, 1, s);
  421. DEFINE_ADAQ4380_4_CHANNEL(adaq4380_4_channels, 16, 1, s);
  422. DEFINE_ADAQ4380_4_CHANNEL(adaq4381_4_channels, 14, 1, s);
  423. /* pseudo differential */
  424. DEFINE_AD7380_2_CHANNEL(ad7383_channels, 16, 0, s);
  425. DEFINE_AD7380_2_CHANNEL(ad7384_channels, 14, 0, s);
  426. DEFINE_AD7380_4_CHANNEL(ad7383_4_channels, 16, 0, s);
  427. DEFINE_AD7380_4_CHANNEL(ad7384_4_channels, 14, 0, s);
  428. /* Single ended */
  429. DEFINE_AD7380_4_CHANNEL(ad7386_channels, 16, 0, u);
  430. DEFINE_AD7380_4_CHANNEL(ad7387_channels, 14, 0, u);
  431. DEFINE_AD7380_4_CHANNEL(ad7388_channels, 12, 0, u);
  432. DEFINE_AD7380_8_CHANNEL(ad7386_4_channels, 16, 0, u);
  433. DEFINE_AD7380_8_CHANNEL(ad7387_4_channels, 14, 0, u);
  434. DEFINE_AD7380_8_CHANNEL(ad7388_4_channels, 12, 0, u);
  435. /* offload channels */
  436. DEFINE_AD7380_2_OFFLOAD_CHANNEL(ad7380_offload_channels, 16, 1, s);
  437. DEFINE_AD7380_2_OFFLOAD_CHANNEL(ad7381_offload_channels, 14, 1, s);
  438. DEFINE_AD7380_4_OFFLOAD_CHANNEL(ad7380_4_offload_channels, 16, 1, s);
  439. DEFINE_AD7380_4_OFFLOAD_CHANNEL(ad7381_4_offload_channels, 14, 1, s);
  440. DEFINE_ADAQ4380_4_OFFLOAD_CHANNEL(adaq4380_4_offload_channels, 16, 1, s);
  441. DEFINE_ADAQ4380_4_OFFLOAD_CHANNEL(adaq4381_4_offload_channels, 14, 1, s);
  442. /* pseudo differential */
  443. DEFINE_AD7380_2_OFFLOAD_CHANNEL(ad7383_offload_channels, 16, 0, s);
  444. DEFINE_AD7380_2_OFFLOAD_CHANNEL(ad7384_offload_channels, 14, 0, s);
  445. DEFINE_AD7380_4_OFFLOAD_CHANNEL(ad7383_4_offload_channels, 16, 0, s);
  446. DEFINE_AD7380_4_OFFLOAD_CHANNEL(ad7384_4_offload_channels, 14, 0, s);
  447. /* Single ended */
  448. DEFINE_AD7380_4_OFFLOAD_CHANNEL(ad7386_offload_channels, 16, 0, u);
  449. DEFINE_AD7380_4_OFFLOAD_CHANNEL(ad7387_offload_channels, 14, 0, u);
  450. DEFINE_AD7380_4_OFFLOAD_CHANNEL(ad7388_offload_channels, 12, 0, u);
  451. DEFINE_AD7380_8_OFFLOAD_CHANNEL(ad7386_4_offload_channels, 16, 0, u);
  452. DEFINE_AD7380_8_OFFLOAD_CHANNEL(ad7387_4_offload_channels, 14, 0, u);
  453. DEFINE_AD7380_8_OFFLOAD_CHANNEL(ad7388_4_offload_channels, 12, 0, u);
  454. static const char * const ad7380_supplies[] = {
  455. "vcc", "vlogic",
  456. };
  457. static const char * const adaq4380_supplies[] = {
  458. "ldo", "vcc", "vlogic", "vs-p", "vs-n", "refin",
  459. };
  460. static const char * const ad7380_2_channel_vcm_supplies[] = {
  461. "aina", "ainb",
  462. };
  463. static const char * const ad7380_4_channel_vcm_supplies[] = {
  464. "aina", "ainb", "ainc", "aind",
  465. };
  466. /* Since this is simultaneous sampling, we don't allow individual channels. */
  467. static const unsigned long ad7380_2_channel_scan_masks[] = {
  468. GENMASK(1, 0),
  469. 0
  470. };
  471. static const unsigned long ad7380_4_channel_scan_masks[] = {
  472. GENMASK(3, 0),
  473. 0
  474. };
  475. /*
  476. * Single ended parts have a 2:1 multiplexer in front of each ADC.
  477. *
  478. * From an IIO point of view, all inputs are exported, i.e ad7386/7/8
  479. * export 4 channels and ad7386-4/7-4/8-4 export 8 channels.
  480. *
  481. * Inputs AinX0 of multiplexers correspond to the first half of IIO channels
  482. * (i.e 0-1 or 0-3) and inputs AinX1 correspond to second half (i.e 2-3 or
  483. * 4-7). Example for AD7386/7/8 (2 channels parts):
  484. *
  485. * IIO | AD7386/7/8
  486. * | +----------------------------
  487. * | | _____ ______
  488. * | | | | | |
  489. * voltage0 | AinA0 --|--->| | | |
  490. * | | | mux |----->| ADCA |---
  491. * voltage2 | AinA1 --|--->| | | |
  492. * | | |_____| |_____ |
  493. * | | _____ ______
  494. * | | | | | |
  495. * voltage1 | AinB0 --|--->| | | |
  496. * | | | mux |----->| ADCB |---
  497. * voltage3 | AinB1 --|--->| | | |
  498. * | | |_____| |______|
  499. * | |
  500. * | +----------------------------
  501. *
  502. * Since this is simultaneous sampling for AinX0 OR AinX1 we have two separate
  503. * scan masks.
  504. * When sequencer mode is enabled, chip automatically cycles through
  505. * AinX0 and AinX1 channels. From an IIO point of view, we ca enable all
  506. * channels, at the cost of an extra read, thus dividing the maximum rate by
  507. * two.
  508. */
  509. enum {
  510. AD7380_SCAN_MASK_CH_0,
  511. AD7380_SCAN_MASK_CH_1,
  512. AD7380_SCAN_MASK_SEQ,
  513. };
  514. static const unsigned long ad7380_2x2_channel_scan_masks[] = {
  515. [AD7380_SCAN_MASK_CH_0] = GENMASK(1, 0),
  516. [AD7380_SCAN_MASK_CH_1] = GENMASK(3, 2),
  517. [AD7380_SCAN_MASK_SEQ] = GENMASK(3, 0),
  518. 0
  519. };
  520. static const unsigned long ad7380_2x4_channel_scan_masks[] = {
  521. [AD7380_SCAN_MASK_CH_0] = GENMASK(3, 0),
  522. [AD7380_SCAN_MASK_CH_1] = GENMASK(7, 4),
  523. [AD7380_SCAN_MASK_SEQ] = GENMASK(7, 0),
  524. 0
  525. };
  526. static const struct ad7380_timing_specs ad7380_timing = {
  527. .t_csh_ns = 10,
  528. };
  529. static const struct ad7380_timing_specs ad7380_4_timing = {
  530. .t_csh_ns = 20,
  531. };
  532. /*
  533. * Available oversampling ratios. The indices correspond with the bit value
  534. * expected by the chip. The available ratios depend on the averaging mode,
  535. * only normal averaging is supported for now.
  536. */
  537. static const int ad7380_oversampling_ratios[] = {
  538. 1, 2, 4, 8, 16, 32,
  539. };
  540. /* Gains stored as fractions of 1000 so they can be expressed by integers. */
  541. static const int ad7380_gains[] = {
  542. 300, 600, 1000, 1600,
  543. };
  544. static const struct ad7380_chip_info ad7380_chip_info = {
  545. .name = "ad7380",
  546. .channels = ad7380_channels,
  547. .offload_channels = ad7380_offload_channels,
  548. .num_channels = ARRAY_SIZE(ad7380_channels),
  549. .num_simult_channels = 2,
  550. .supplies = ad7380_supplies,
  551. .num_supplies = ARRAY_SIZE(ad7380_supplies),
  552. .internal_ref_mv = AD7380_INTERNAL_REF_MV,
  553. .available_scan_masks = ad7380_2_channel_scan_masks,
  554. .timing_specs = &ad7380_timing,
  555. .max_conversion_rate_hz = 4 * MEGA,
  556. };
  557. static const struct ad7380_chip_info ad7381_chip_info = {
  558. .name = "ad7381",
  559. .channels = ad7381_channels,
  560. .offload_channels = ad7381_offload_channels,
  561. .num_channels = ARRAY_SIZE(ad7381_channels),
  562. .num_simult_channels = 2,
  563. .supplies = ad7380_supplies,
  564. .num_supplies = ARRAY_SIZE(ad7380_supplies),
  565. .internal_ref_mv = AD7380_INTERNAL_REF_MV,
  566. .available_scan_masks = ad7380_2_channel_scan_masks,
  567. .timing_specs = &ad7380_timing,
  568. .max_conversion_rate_hz = 4 * MEGA,
  569. };
  570. static const struct ad7380_chip_info ad7383_chip_info = {
  571. .name = "ad7383",
  572. .channels = ad7383_channels,
  573. .offload_channels = ad7383_offload_channels,
  574. .num_channels = ARRAY_SIZE(ad7383_channels),
  575. .num_simult_channels = 2,
  576. .supplies = ad7380_supplies,
  577. .num_supplies = ARRAY_SIZE(ad7380_supplies),
  578. .vcm_supplies = ad7380_2_channel_vcm_supplies,
  579. .num_vcm_supplies = ARRAY_SIZE(ad7380_2_channel_vcm_supplies),
  580. .internal_ref_mv = AD7380_INTERNAL_REF_MV,
  581. .available_scan_masks = ad7380_2_channel_scan_masks,
  582. .timing_specs = &ad7380_timing,
  583. .max_conversion_rate_hz = 4 * MEGA,
  584. };
  585. static const struct ad7380_chip_info ad7384_chip_info = {
  586. .name = "ad7384",
  587. .channels = ad7384_channels,
  588. .offload_channels = ad7384_offload_channels,
  589. .num_channels = ARRAY_SIZE(ad7384_channels),
  590. .num_simult_channels = 2,
  591. .supplies = ad7380_supplies,
  592. .num_supplies = ARRAY_SIZE(ad7380_supplies),
  593. .vcm_supplies = ad7380_2_channel_vcm_supplies,
  594. .num_vcm_supplies = ARRAY_SIZE(ad7380_2_channel_vcm_supplies),
  595. .internal_ref_mv = AD7380_INTERNAL_REF_MV,
  596. .available_scan_masks = ad7380_2_channel_scan_masks,
  597. .timing_specs = &ad7380_timing,
  598. .max_conversion_rate_hz = 4 * MEGA,
  599. };
  600. static const struct ad7380_chip_info ad7386_chip_info = {
  601. .name = "ad7386",
  602. .channels = ad7386_channels,
  603. .offload_channels = ad7386_offload_channels,
  604. .num_channels = ARRAY_SIZE(ad7386_channels),
  605. .num_simult_channels = 2,
  606. .supplies = ad7380_supplies,
  607. .num_supplies = ARRAY_SIZE(ad7380_supplies),
  608. .internal_ref_mv = AD7380_INTERNAL_REF_MV,
  609. .has_mux = true,
  610. .available_scan_masks = ad7380_2x2_channel_scan_masks,
  611. .timing_specs = &ad7380_timing,
  612. .max_conversion_rate_hz = 4 * MEGA,
  613. };
  614. static const struct ad7380_chip_info ad7387_chip_info = {
  615. .name = "ad7387",
  616. .channels = ad7387_channels,
  617. .offload_channels = ad7387_offload_channels,
  618. .num_channels = ARRAY_SIZE(ad7387_channels),
  619. .num_simult_channels = 2,
  620. .supplies = ad7380_supplies,
  621. .num_supplies = ARRAY_SIZE(ad7380_supplies),
  622. .internal_ref_mv = AD7380_INTERNAL_REF_MV,
  623. .has_mux = true,
  624. .available_scan_masks = ad7380_2x2_channel_scan_masks,
  625. .timing_specs = &ad7380_timing,
  626. .max_conversion_rate_hz = 4 * MEGA,
  627. };
  628. static const struct ad7380_chip_info ad7388_chip_info = {
  629. .name = "ad7388",
  630. .channels = ad7388_channels,
  631. .offload_channels = ad7388_offload_channels,
  632. .num_channels = ARRAY_SIZE(ad7388_channels),
  633. .num_simult_channels = 2,
  634. .supplies = ad7380_supplies,
  635. .num_supplies = ARRAY_SIZE(ad7380_supplies),
  636. .internal_ref_mv = AD7380_INTERNAL_REF_MV,
  637. .has_mux = true,
  638. .available_scan_masks = ad7380_2x2_channel_scan_masks,
  639. .timing_specs = &ad7380_timing,
  640. .max_conversion_rate_hz = 4 * MEGA,
  641. };
  642. static const struct ad7380_chip_info ad7380_4_chip_info = {
  643. .name = "ad7380-4",
  644. .channels = ad7380_4_channels,
  645. .offload_channels = ad7380_4_offload_channels,
  646. .num_channels = ARRAY_SIZE(ad7380_4_channels),
  647. .num_simult_channels = 4,
  648. .supplies = ad7380_supplies,
  649. .num_supplies = ARRAY_SIZE(ad7380_supplies),
  650. .external_ref_only = true,
  651. .available_scan_masks = ad7380_4_channel_scan_masks,
  652. .timing_specs = &ad7380_4_timing,
  653. .max_conversion_rate_hz = 4 * MEGA,
  654. };
  655. static const struct ad7380_chip_info ad7381_4_chip_info = {
  656. .name = "ad7381-4",
  657. .channels = ad7381_4_channels,
  658. .offload_channels = ad7381_4_offload_channels,
  659. .num_channels = ARRAY_SIZE(ad7381_4_channels),
  660. .num_simult_channels = 4,
  661. .supplies = ad7380_supplies,
  662. .num_supplies = ARRAY_SIZE(ad7380_supplies),
  663. .internal_ref_mv = AD7380_INTERNAL_REF_MV,
  664. .available_scan_masks = ad7380_4_channel_scan_masks,
  665. .timing_specs = &ad7380_4_timing,
  666. .max_conversion_rate_hz = 4 * MEGA,
  667. };
  668. static const struct ad7380_chip_info ad7383_4_chip_info = {
  669. .name = "ad7383-4",
  670. .channels = ad7383_4_channels,
  671. .offload_channels = ad7383_4_offload_channels,
  672. .num_channels = ARRAY_SIZE(ad7383_4_channels),
  673. .num_simult_channels = 4,
  674. .supplies = ad7380_supplies,
  675. .num_supplies = ARRAY_SIZE(ad7380_supplies),
  676. .internal_ref_mv = AD7380_INTERNAL_REF_MV,
  677. .vcm_supplies = ad7380_4_channel_vcm_supplies,
  678. .num_vcm_supplies = ARRAY_SIZE(ad7380_4_channel_vcm_supplies),
  679. .available_scan_masks = ad7380_4_channel_scan_masks,
  680. .timing_specs = &ad7380_4_timing,
  681. .max_conversion_rate_hz = 4 * MEGA,
  682. };
  683. static const struct ad7380_chip_info ad7384_4_chip_info = {
  684. .name = "ad7384-4",
  685. .channels = ad7384_4_channels,
  686. .offload_channels = ad7384_4_offload_channels,
  687. .num_channels = ARRAY_SIZE(ad7384_4_channels),
  688. .num_simult_channels = 4,
  689. .supplies = ad7380_supplies,
  690. .num_supplies = ARRAY_SIZE(ad7380_supplies),
  691. .internal_ref_mv = AD7380_INTERNAL_REF_MV,
  692. .vcm_supplies = ad7380_4_channel_vcm_supplies,
  693. .num_vcm_supplies = ARRAY_SIZE(ad7380_4_channel_vcm_supplies),
  694. .available_scan_masks = ad7380_4_channel_scan_masks,
  695. .timing_specs = &ad7380_4_timing,
  696. .max_conversion_rate_hz = 4 * MEGA,
  697. };
  698. static const struct ad7380_chip_info ad7386_4_chip_info = {
  699. .name = "ad7386-4",
  700. .channels = ad7386_4_channels,
  701. .offload_channels = ad7386_4_offload_channels,
  702. .num_channels = ARRAY_SIZE(ad7386_4_channels),
  703. .num_simult_channels = 4,
  704. .supplies = ad7380_supplies,
  705. .num_supplies = ARRAY_SIZE(ad7380_supplies),
  706. .internal_ref_mv = AD7380_INTERNAL_REF_MV,
  707. .has_mux = true,
  708. .available_scan_masks = ad7380_2x4_channel_scan_masks,
  709. .timing_specs = &ad7380_4_timing,
  710. .max_conversion_rate_hz = 4 * MEGA,
  711. };
  712. static const struct ad7380_chip_info ad7387_4_chip_info = {
  713. .name = "ad7387-4",
  714. .channels = ad7387_4_channels,
  715. .offload_channels = ad7387_4_offload_channels,
  716. .num_channels = ARRAY_SIZE(ad7387_4_channels),
  717. .num_simult_channels = 4,
  718. .supplies = ad7380_supplies,
  719. .num_supplies = ARRAY_SIZE(ad7380_supplies),
  720. .internal_ref_mv = AD7380_INTERNAL_REF_MV,
  721. .has_mux = true,
  722. .available_scan_masks = ad7380_2x4_channel_scan_masks,
  723. .timing_specs = &ad7380_4_timing,
  724. .max_conversion_rate_hz = 4 * MEGA,
  725. };
  726. static const struct ad7380_chip_info ad7388_4_chip_info = {
  727. .name = "ad7388-4",
  728. .channels = ad7388_4_channels,
  729. .offload_channels = ad7388_4_offload_channels,
  730. .num_channels = ARRAY_SIZE(ad7388_4_channels),
  731. .num_simult_channels = 4,
  732. .supplies = ad7380_supplies,
  733. .num_supplies = ARRAY_SIZE(ad7380_supplies),
  734. .internal_ref_mv = AD7380_INTERNAL_REF_MV,
  735. .has_mux = true,
  736. .available_scan_masks = ad7380_2x4_channel_scan_masks,
  737. .timing_specs = &ad7380_4_timing,
  738. .max_conversion_rate_hz = 4 * MEGA,
  739. };
  740. static const struct ad7380_chip_info ad7389_4_chip_info = {
  741. .name = "ad7389-4",
  742. .channels = ad7380_4_channels,
  743. .offload_channels = ad7380_4_offload_channels,
  744. .num_channels = ARRAY_SIZE(ad7380_4_channels),
  745. .num_simult_channels = 4,
  746. .supplies = ad7380_supplies,
  747. .num_supplies = ARRAY_SIZE(ad7380_supplies),
  748. .internal_ref_only = true,
  749. .internal_ref_mv = AD7380_INTERNAL_REF_MV,
  750. .available_scan_masks = ad7380_4_channel_scan_masks,
  751. .timing_specs = &ad7380_4_timing,
  752. .max_conversion_rate_hz = 4 * MEGA,
  753. };
  754. static const struct ad7380_chip_info adaq4370_4_chip_info = {
  755. .name = "adaq4370-4",
  756. .channels = adaq4380_4_channels,
  757. .offload_channels = adaq4380_4_offload_channels,
  758. .num_channels = ARRAY_SIZE(adaq4380_4_channels),
  759. .num_simult_channels = 4,
  760. .supplies = adaq4380_supplies,
  761. .num_supplies = ARRAY_SIZE(adaq4380_supplies),
  762. .internal_ref_only = true,
  763. .internal_ref_mv = ADAQ4380_INTERNAL_REF_MV,
  764. .has_hardware_gain = true,
  765. .available_scan_masks = ad7380_4_channel_scan_masks,
  766. .timing_specs = &ad7380_4_timing,
  767. .max_conversion_rate_hz = 2 * MEGA,
  768. };
  769. static const struct ad7380_chip_info adaq4380_4_chip_info = {
  770. .name = "adaq4380-4",
  771. .channels = adaq4380_4_channels,
  772. .offload_channels = adaq4380_4_offload_channels,
  773. .num_channels = ARRAY_SIZE(adaq4380_4_channels),
  774. .num_simult_channels = 4,
  775. .supplies = adaq4380_supplies,
  776. .num_supplies = ARRAY_SIZE(adaq4380_supplies),
  777. .internal_ref_only = true,
  778. .internal_ref_mv = ADAQ4380_INTERNAL_REF_MV,
  779. .has_hardware_gain = true,
  780. .available_scan_masks = ad7380_4_channel_scan_masks,
  781. .timing_specs = &ad7380_4_timing,
  782. .max_conversion_rate_hz = 4 * MEGA,
  783. };
  784. static const struct ad7380_chip_info adaq4381_4_chip_info = {
  785. .name = "adaq4381-4",
  786. .channels = adaq4381_4_channels,
  787. .offload_channels = adaq4381_4_offload_channels,
  788. .num_channels = ARRAY_SIZE(adaq4381_4_channels),
  789. .num_simult_channels = 4,
  790. .supplies = adaq4380_supplies,
  791. .num_supplies = ARRAY_SIZE(adaq4380_supplies),
  792. .internal_ref_only = true,
  793. .internal_ref_mv = ADAQ4380_INTERNAL_REF_MV,
  794. .has_hardware_gain = true,
  795. .available_scan_masks = ad7380_4_channel_scan_masks,
  796. .timing_specs = &ad7380_4_timing,
  797. .max_conversion_rate_hz = 4 * MEGA,
  798. };
  799. static const struct spi_offload_config ad7380_offload_config = {
  800. .capability_flags = SPI_OFFLOAD_CAP_TRIGGER |
  801. SPI_OFFLOAD_CAP_RX_STREAM_DMA,
  802. };
  803. struct ad7380_state {
  804. const struct ad7380_chip_info *chip_info;
  805. struct spi_device *spi;
  806. struct regmap *regmap;
  807. bool resolution_boost_enabled;
  808. unsigned int ch;
  809. bool seq;
  810. unsigned int vref_mv;
  811. unsigned int vcm_mv[MAX_NUM_CHANNELS];
  812. unsigned int gain_milli[MAX_NUM_CHANNELS];
  813. /* xfers, message an buffer for reading sample data */
  814. struct spi_transfer normal_xfer[2];
  815. struct spi_message normal_msg;
  816. struct spi_transfer seq_xfer[4];
  817. struct spi_message seq_msg;
  818. struct spi_transfer offload_xfer;
  819. struct spi_message offload_msg;
  820. struct spi_offload *offload;
  821. struct spi_offload_trigger *offload_trigger;
  822. unsigned long offload_trigger_hz;
  823. int sample_freq_range[3];
  824. /*
  825. * DMA (thus cache coherency maintenance) requires the transfer buffers
  826. * to live in their own cache lines.
  827. *
  828. * Make the buffer large enough for MAX_NUM_CHANNELS 32-bit samples and
  829. * one 64-bit aligned 64-bit timestamp.
  830. */
  831. IIO_DECLARE_DMA_BUFFER_WITH_TS(u8, scan_data, MAX_NUM_CHANNELS * sizeof(u32));
  832. /* buffers for reading/writing registers */
  833. u16 tx;
  834. u16 rx;
  835. };
  836. static int ad7380_regmap_reg_write(void *context, unsigned int reg,
  837. unsigned int val)
  838. {
  839. struct ad7380_state *st = context;
  840. struct spi_transfer xfer = {
  841. .speed_hz = AD7380_REG_WR_SPEED_HZ,
  842. .bits_per_word = 16,
  843. .len = 2,
  844. .tx_buf = &st->tx,
  845. };
  846. st->tx = FIELD_PREP(AD7380_REG_WR, 1) |
  847. FIELD_PREP(AD7380_REG_REGADDR, reg) |
  848. FIELD_PREP(AD7380_REG_DATA, val);
  849. return spi_sync_transfer(st->spi, &xfer, 1);
  850. }
  851. static int ad7380_regmap_reg_read(void *context, unsigned int reg,
  852. unsigned int *val)
  853. {
  854. struct ad7380_state *st = context;
  855. struct spi_transfer xfers[] = {
  856. {
  857. .speed_hz = AD7380_REG_WR_SPEED_HZ,
  858. .bits_per_word = 16,
  859. .len = 2,
  860. .tx_buf = &st->tx,
  861. .cs_change = 1,
  862. .cs_change_delay = {
  863. .value = st->chip_info->timing_specs->t_csh_ns,
  864. .unit = SPI_DELAY_UNIT_NSECS,
  865. },
  866. }, {
  867. .speed_hz = AD7380_REG_WR_SPEED_HZ,
  868. .bits_per_word = 16,
  869. .len = 2,
  870. .rx_buf = &st->rx,
  871. },
  872. };
  873. int ret;
  874. st->tx = FIELD_PREP(AD7380_REG_WR, 0) |
  875. FIELD_PREP(AD7380_REG_REGADDR, reg) |
  876. FIELD_PREP(AD7380_REG_DATA, 0);
  877. ret = spi_sync_transfer(st->spi, xfers, ARRAY_SIZE(xfers));
  878. if (ret < 0)
  879. return ret;
  880. *val = FIELD_GET(AD7380_REG_DATA, st->rx);
  881. return 0;
  882. }
  883. static const struct reg_default ad7380_reg_defaults[] = {
  884. { AD7380_REG_ADDR_ALERT_LOW_TH, 0x800 },
  885. { AD7380_REG_ADDR_ALERT_HIGH_TH, 0x7FF },
  886. };
  887. static const struct regmap_range ad7380_volatile_reg_ranges[] = {
  888. regmap_reg_range(AD7380_REG_ADDR_CONFIG2, AD7380_REG_ADDR_ALERT),
  889. };
  890. static const struct regmap_access_table ad7380_volatile_regs = {
  891. .yes_ranges = ad7380_volatile_reg_ranges,
  892. .n_yes_ranges = ARRAY_SIZE(ad7380_volatile_reg_ranges),
  893. };
  894. static const struct regmap_config ad7380_regmap_config = {
  895. .reg_bits = 3,
  896. .val_bits = 12,
  897. .reg_read = ad7380_regmap_reg_read,
  898. .reg_write = ad7380_regmap_reg_write,
  899. .max_register = AD7380_REG_ADDR_ALERT_HIGH_TH,
  900. .can_sleep = true,
  901. .reg_defaults = ad7380_reg_defaults,
  902. .num_reg_defaults = ARRAY_SIZE(ad7380_reg_defaults),
  903. .volatile_table = &ad7380_volatile_regs,
  904. .cache_type = REGCACHE_MAPLE,
  905. };
  906. static int ad7380_debugfs_reg_access(struct iio_dev *indio_dev, u32 reg,
  907. u32 writeval, u32 *readval)
  908. {
  909. struct ad7380_state *st = iio_priv(indio_dev);
  910. int ret;
  911. if (!iio_device_claim_direct(indio_dev))
  912. return -EBUSY;
  913. if (readval)
  914. ret = regmap_read(st->regmap, reg, readval);
  915. else
  916. ret = regmap_write(st->regmap, reg, writeval);
  917. iio_device_release_direct(indio_dev);
  918. return ret;
  919. }
  920. /**
  921. * ad7380_regval_to_osr - convert OSR register value to ratio
  922. * @regval: register value to check
  923. *
  924. * Returns: the ratio corresponding to the OSR register. If regval is not in
  925. * bound, return 1 (oversampling disabled)
  926. *
  927. */
  928. static int ad7380_regval_to_osr(unsigned int regval)
  929. {
  930. if (regval >= ARRAY_SIZE(ad7380_oversampling_ratios))
  931. return 1;
  932. return ad7380_oversampling_ratios[regval];
  933. }
  934. static int ad7380_get_osr(struct ad7380_state *st, int *val)
  935. {
  936. u32 tmp;
  937. int ret;
  938. ret = regmap_read(st->regmap, AD7380_REG_ADDR_CONFIG1, &tmp);
  939. if (ret)
  940. return ret;
  941. *val = ad7380_regval_to_osr(FIELD_GET(AD7380_CONFIG1_OSR, tmp));
  942. return 0;
  943. }
  944. /*
  945. * When switching channel, the ADC require an additional settling time.
  946. * According to the datasheet, data is value on the third CS low. We already
  947. * have an extra toggle before each read (either direct reads or buffered reads)
  948. * to sample correct data, so we just add a single CS toggle at the end of the
  949. * register write.
  950. */
  951. static int ad7380_set_ch(struct ad7380_state *st, unsigned int ch)
  952. {
  953. struct spi_transfer xfer = {
  954. .delay = {
  955. .value = T_CONVERT_NS,
  956. .unit = SPI_DELAY_UNIT_NSECS,
  957. }
  958. };
  959. int oversampling_ratio, ret;
  960. if (st->ch == ch)
  961. return 0;
  962. ret = ad7380_get_osr(st, &oversampling_ratio);
  963. if (ret)
  964. return ret;
  965. ret = regmap_update_bits(st->regmap,
  966. AD7380_REG_ADDR_CONFIG1,
  967. AD7380_CONFIG1_CH,
  968. FIELD_PREP(AD7380_CONFIG1_CH, ch));
  969. if (ret)
  970. return ret;
  971. st->ch = ch;
  972. if (oversampling_ratio > 1)
  973. xfer.delay.value = T_CONVERT_0_NS +
  974. T_CONVERT_X_NS * (oversampling_ratio - 1) *
  975. st->chip_info->num_simult_channels / AD7380_NUM_SDO_LINES;
  976. return spi_sync_transfer(st->spi, &xfer, 1);
  977. }
  978. /**
  979. * ad7380_update_xfers - update the SPI transfers base on the current scan type
  980. * @st: device instance specific state
  981. * @scan_type: current scan type
  982. */
  983. static int ad7380_update_xfers(struct ad7380_state *st,
  984. const struct iio_scan_type *scan_type)
  985. {
  986. struct spi_transfer *xfer = st->seq ? st->seq_xfer : st->normal_xfer;
  987. unsigned int t_convert = T_CONVERT_NS;
  988. int oversampling_ratio, ret;
  989. /*
  990. * In the case of oversampling, conversion time is higher than in normal
  991. * mode. Technically T_CONVERT_X_NS is lower for some chips, but we use
  992. * the maximum value for simplicity for now.
  993. */
  994. ret = ad7380_get_osr(st, &oversampling_ratio);
  995. if (ret)
  996. return ret;
  997. if (oversampling_ratio > 1)
  998. t_convert = T_CONVERT_0_NS + T_CONVERT_X_NS *
  999. (oversampling_ratio - 1) *
  1000. st->chip_info->num_simult_channels / AD7380_NUM_SDO_LINES;
  1001. if (st->seq) {
  1002. xfer[0].delay.value = xfer[1].delay.value = t_convert;
  1003. xfer[0].delay.unit = xfer[1].delay.unit = SPI_DELAY_UNIT_NSECS;
  1004. xfer[2].bits_per_word = xfer[3].bits_per_word =
  1005. scan_type->realbits;
  1006. xfer[2].len = xfer[3].len =
  1007. AD7380_SPI_BYTES(scan_type) *
  1008. st->chip_info->num_simult_channels;
  1009. xfer[3].rx_buf = xfer[2].rx_buf + xfer[2].len;
  1010. /* Additional delay required here when oversampling is enabled */
  1011. if (oversampling_ratio > 1)
  1012. xfer[2].delay.value = t_convert;
  1013. else
  1014. xfer[2].delay.value = 0;
  1015. xfer[2].delay.unit = SPI_DELAY_UNIT_NSECS;
  1016. } else {
  1017. xfer[0].delay.value = t_convert;
  1018. xfer[0].delay.unit = SPI_DELAY_UNIT_NSECS;
  1019. xfer[1].bits_per_word = scan_type->realbits;
  1020. xfer[1].len = AD7380_SPI_BYTES(scan_type) *
  1021. st->chip_info->num_simult_channels;
  1022. }
  1023. return 0;
  1024. }
  1025. static int ad7380_set_sample_freq(struct ad7380_state *st, int val)
  1026. {
  1027. struct spi_offload_trigger_config config = {
  1028. .type = SPI_OFFLOAD_TRIGGER_PERIODIC,
  1029. .periodic = {
  1030. .frequency_hz = val,
  1031. },
  1032. };
  1033. int ret;
  1034. ret = spi_offload_trigger_validate(st->offload_trigger, &config);
  1035. if (ret)
  1036. return ret;
  1037. st->offload_trigger_hz = config.periodic.frequency_hz;
  1038. return 0;
  1039. }
  1040. static int ad7380_init_offload_msg(struct ad7380_state *st,
  1041. struct iio_dev *indio_dev)
  1042. {
  1043. struct spi_transfer *xfer = &st->offload_xfer;
  1044. struct device *dev = &st->spi->dev;
  1045. const struct iio_scan_type *scan_type;
  1046. int ret;
  1047. scan_type = iio_get_current_scan_type(indio_dev,
  1048. &indio_dev->channels[0]);
  1049. if (IS_ERR(scan_type))
  1050. return PTR_ERR(scan_type);
  1051. if (st->chip_info->has_mux) {
  1052. int index;
  1053. ret = iio_active_scan_mask_index(indio_dev);
  1054. if (ret < 0)
  1055. return ret;
  1056. index = ret;
  1057. if (index == AD7380_SCAN_MASK_SEQ) {
  1058. ret = regmap_set_bits(st->regmap, AD7380_REG_ADDR_CONFIG1,
  1059. AD7380_CONFIG1_SEQ);
  1060. if (ret)
  1061. return ret;
  1062. st->seq = true;
  1063. } else {
  1064. ret = ad7380_set_ch(st, index);
  1065. if (ret)
  1066. return ret;
  1067. }
  1068. }
  1069. xfer->bits_per_word = scan_type->realbits;
  1070. xfer->offload_flags = SPI_OFFLOAD_XFER_RX_STREAM;
  1071. xfer->len = AD7380_SPI_BYTES(scan_type) * st->chip_info->num_simult_channels;
  1072. spi_message_init_with_transfers(&st->offload_msg, xfer, 1);
  1073. st->offload_msg.offload = st->offload;
  1074. ret = spi_optimize_message(st->spi, &st->offload_msg);
  1075. if (ret) {
  1076. dev_err(dev, "failed to prepare offload msg, err: %d\n",
  1077. ret);
  1078. return ret;
  1079. }
  1080. return 0;
  1081. }
  1082. static int ad7380_offload_buffer_postenable(struct iio_dev *indio_dev)
  1083. {
  1084. struct ad7380_state *st = iio_priv(indio_dev);
  1085. struct spi_offload_trigger_config config = {
  1086. .type = SPI_OFFLOAD_TRIGGER_PERIODIC,
  1087. .periodic = {
  1088. .frequency_hz = st->offload_trigger_hz,
  1089. },
  1090. };
  1091. int ret;
  1092. ret = ad7380_init_offload_msg(st, indio_dev);
  1093. if (ret)
  1094. return ret;
  1095. /*
  1096. * When the sequencer is required to read all channels, we need to
  1097. * trigger twice per sample period in order to read one complete set
  1098. * of samples.
  1099. */
  1100. if (st->seq)
  1101. config.periodic.frequency_hz *= 2;
  1102. ret = spi_offload_trigger_enable(st->offload, st->offload_trigger, &config);
  1103. if (ret)
  1104. spi_unoptimize_message(&st->offload_msg);
  1105. return ret;
  1106. }
  1107. static int ad7380_offload_buffer_predisable(struct iio_dev *indio_dev)
  1108. {
  1109. struct ad7380_state *st = iio_priv(indio_dev);
  1110. int ret;
  1111. spi_offload_trigger_disable(st->offload, st->offload_trigger);
  1112. spi_unoptimize_message(&st->offload_msg);
  1113. if (st->seq) {
  1114. ret = regmap_update_bits(st->regmap,
  1115. AD7380_REG_ADDR_CONFIG1,
  1116. AD7380_CONFIG1_SEQ,
  1117. FIELD_PREP(AD7380_CONFIG1_SEQ, 0));
  1118. if (ret)
  1119. return ret;
  1120. st->seq = false;
  1121. }
  1122. return 0;
  1123. }
  1124. static const struct iio_buffer_setup_ops ad7380_offload_buffer_setup_ops = {
  1125. .postenable = ad7380_offload_buffer_postenable,
  1126. .predisable = ad7380_offload_buffer_predisable,
  1127. };
  1128. static int ad7380_triggered_buffer_preenable(struct iio_dev *indio_dev)
  1129. {
  1130. struct ad7380_state *st = iio_priv(indio_dev);
  1131. const struct iio_scan_type *scan_type;
  1132. struct spi_message *msg = &st->normal_msg;
  1133. int ret;
  1134. /*
  1135. * Currently, we always read all channels at the same time. The scan_type
  1136. * is the same for all channels, so we just pass the first channel.
  1137. */
  1138. scan_type = iio_get_current_scan_type(indio_dev, &indio_dev->channels[0]);
  1139. if (IS_ERR(scan_type))
  1140. return PTR_ERR(scan_type);
  1141. if (st->chip_info->has_mux) {
  1142. unsigned int index;
  1143. /*
  1144. * Depending on the requested scan_mask and current state,
  1145. * we need to either change CH bit, or enable sequencer mode
  1146. * to sample correct data.
  1147. * Sequencer mode is enabled if active mask corresponds to all
  1148. * IIO channels enabled. Otherwise, CH bit is set.
  1149. */
  1150. ret = iio_active_scan_mask_index(indio_dev);
  1151. if (ret < 0)
  1152. return ret;
  1153. index = ret;
  1154. if (index == AD7380_SCAN_MASK_SEQ) {
  1155. ret = regmap_update_bits(st->regmap,
  1156. AD7380_REG_ADDR_CONFIG1,
  1157. AD7380_CONFIG1_SEQ,
  1158. FIELD_PREP(AD7380_CONFIG1_SEQ, 1));
  1159. if (ret)
  1160. return ret;
  1161. msg = &st->seq_msg;
  1162. st->seq = true;
  1163. } else {
  1164. ret = ad7380_set_ch(st, index);
  1165. if (ret)
  1166. return ret;
  1167. }
  1168. }
  1169. ret = ad7380_update_xfers(st, scan_type);
  1170. if (ret)
  1171. return ret;
  1172. return spi_optimize_message(st->spi, msg);
  1173. }
  1174. static int ad7380_triggered_buffer_postdisable(struct iio_dev *indio_dev)
  1175. {
  1176. struct ad7380_state *st = iio_priv(indio_dev);
  1177. struct spi_message *msg = &st->normal_msg;
  1178. int ret;
  1179. if (st->seq) {
  1180. ret = regmap_update_bits(st->regmap,
  1181. AD7380_REG_ADDR_CONFIG1,
  1182. AD7380_CONFIG1_SEQ,
  1183. FIELD_PREP(AD7380_CONFIG1_SEQ, 0));
  1184. if (ret)
  1185. return ret;
  1186. msg = &st->seq_msg;
  1187. st->seq = false;
  1188. }
  1189. spi_unoptimize_message(msg);
  1190. return 0;
  1191. }
  1192. static const struct iio_buffer_setup_ops ad7380_buffer_setup_ops = {
  1193. .preenable = ad7380_triggered_buffer_preenable,
  1194. .postdisable = ad7380_triggered_buffer_postdisable,
  1195. };
  1196. static irqreturn_t ad7380_trigger_handler(int irq, void *p)
  1197. {
  1198. struct iio_poll_func *pf = p;
  1199. struct iio_dev *indio_dev = pf->indio_dev;
  1200. struct ad7380_state *st = iio_priv(indio_dev);
  1201. struct spi_message *msg = st->seq ? &st->seq_msg : &st->normal_msg;
  1202. int ret;
  1203. ret = spi_sync(st->spi, msg);
  1204. if (ret)
  1205. goto out;
  1206. iio_push_to_buffers_with_ts(indio_dev, &st->scan_data, sizeof(st->scan_data),
  1207. pf->timestamp);
  1208. out:
  1209. iio_trigger_notify_done(indio_dev->trig);
  1210. return IRQ_HANDLED;
  1211. }
  1212. static int ad7380_read_direct(struct ad7380_state *st, unsigned int scan_index,
  1213. const struct iio_scan_type *scan_type, int *val)
  1214. {
  1215. unsigned int index = scan_index;
  1216. int ret;
  1217. if (st->chip_info->has_mux) {
  1218. unsigned int ch = 0;
  1219. if (index >= st->chip_info->num_simult_channels) {
  1220. index -= st->chip_info->num_simult_channels;
  1221. ch = 1;
  1222. }
  1223. ret = ad7380_set_ch(st, ch);
  1224. if (ret)
  1225. return ret;
  1226. }
  1227. ret = ad7380_update_xfers(st, scan_type);
  1228. if (ret)
  1229. return ret;
  1230. ret = spi_sync(st->spi, &st->normal_msg);
  1231. if (ret < 0)
  1232. return ret;
  1233. if (scan_type->realbits > 16) {
  1234. if (scan_type->sign == 's')
  1235. *val = sign_extend32(*(u32 *)(st->scan_data + 4 * index),
  1236. scan_type->realbits - 1);
  1237. else
  1238. *val = *(u32 *)(st->scan_data + 4 * index) &
  1239. GENMASK(scan_type->realbits - 1, 0);
  1240. } else {
  1241. if (scan_type->sign == 's')
  1242. *val = sign_extend32(*(u16 *)(st->scan_data + 2 * index),
  1243. scan_type->realbits - 1);
  1244. else
  1245. *val = *(u16 *)(st->scan_data + 2 * index) &
  1246. GENMASK(scan_type->realbits - 1, 0);
  1247. }
  1248. return IIO_VAL_INT;
  1249. }
  1250. static int ad7380_read_raw(struct iio_dev *indio_dev,
  1251. struct iio_chan_spec const *chan,
  1252. int *val, int *val2, long info)
  1253. {
  1254. struct ad7380_state *st = iio_priv(indio_dev);
  1255. const struct iio_scan_type *scan_type;
  1256. int ret;
  1257. scan_type = iio_get_current_scan_type(indio_dev, chan);
  1258. if (IS_ERR(scan_type))
  1259. return PTR_ERR(scan_type);
  1260. switch (info) {
  1261. case IIO_CHAN_INFO_RAW:
  1262. if (!iio_device_claim_direct(indio_dev))
  1263. return -EBUSY;
  1264. ret = ad7380_read_direct(st, chan->scan_index,
  1265. scan_type, val);
  1266. iio_device_release_direct(indio_dev);
  1267. return ret;
  1268. case IIO_CHAN_INFO_SCALE:
  1269. /*
  1270. * According to the datasheet, the LSB size is:
  1271. * * (2 × VREF) / 2^N, for differential chips
  1272. * * VREF / 2^N, for pseudo-differential chips
  1273. * where N is the ADC resolution (i.e realbits)
  1274. *
  1275. * The gain is stored as a fraction of 1000 and, as we need to
  1276. * divide vref_mv by the gain, we invert the gain/1000 fraction.
  1277. */
  1278. if (st->chip_info->has_hardware_gain)
  1279. *val = mult_frac(st->vref_mv, MILLI,
  1280. st->gain_milli[chan->scan_index]);
  1281. else
  1282. *val = st->vref_mv;
  1283. *val2 = scan_type->realbits - chan->differential;
  1284. return IIO_VAL_FRACTIONAL_LOG2;
  1285. case IIO_CHAN_INFO_OFFSET:
  1286. /*
  1287. * According to IIO ABI, offset is applied before scale,
  1288. * so offset is: vcm_mv / scale
  1289. */
  1290. *val = st->vcm_mv[chan->channel] * (1 << scan_type->realbits)
  1291. / st->vref_mv;
  1292. return IIO_VAL_INT;
  1293. case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
  1294. if (!iio_device_claim_direct(indio_dev))
  1295. return -EBUSY;
  1296. ret = ad7380_get_osr(st, val);
  1297. iio_device_release_direct(indio_dev);
  1298. if (ret)
  1299. return ret;
  1300. return IIO_VAL_INT;
  1301. case IIO_CHAN_INFO_SAMP_FREQ:
  1302. *val = st->offload_trigger_hz;
  1303. return IIO_VAL_INT;
  1304. default:
  1305. return -EINVAL;
  1306. }
  1307. }
  1308. static int ad7380_read_avail(struct iio_dev *indio_dev,
  1309. struct iio_chan_spec const *chan,
  1310. const int **vals, int *type, int *length,
  1311. long mask)
  1312. {
  1313. struct ad7380_state *st = iio_priv(indio_dev);
  1314. switch (mask) {
  1315. case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
  1316. *vals = ad7380_oversampling_ratios;
  1317. *length = ARRAY_SIZE(ad7380_oversampling_ratios);
  1318. *type = IIO_VAL_INT;
  1319. return IIO_AVAIL_LIST;
  1320. case IIO_CHAN_INFO_SAMP_FREQ:
  1321. *vals = st->sample_freq_range;
  1322. *type = IIO_VAL_INT;
  1323. return IIO_AVAIL_RANGE;
  1324. default:
  1325. return -EINVAL;
  1326. }
  1327. }
  1328. /**
  1329. * ad7380_osr_to_regval - convert ratio to OSR register value
  1330. * @ratio: ratio to check
  1331. *
  1332. * Check if ratio is present in the list of available ratios and return the
  1333. * corresponding value that needs to be written to the register to select that
  1334. * ratio.
  1335. *
  1336. * Returns: register value (0 to 7) or -EINVAL if there is not an exact match
  1337. */
  1338. static int ad7380_osr_to_regval(int ratio)
  1339. {
  1340. int i;
  1341. for (i = 0; i < ARRAY_SIZE(ad7380_oversampling_ratios); i++) {
  1342. if (ratio == ad7380_oversampling_ratios[i])
  1343. return i;
  1344. }
  1345. return -EINVAL;
  1346. }
  1347. static int ad7380_set_oversampling_ratio(struct ad7380_state *st, int val)
  1348. {
  1349. int ret, osr, boost;
  1350. osr = ad7380_osr_to_regval(val);
  1351. if (osr < 0)
  1352. return osr;
  1353. /* always enable resolution boost when oversampling is enabled */
  1354. boost = osr > 0 ? 1 : 0;
  1355. ret = regmap_update_bits(st->regmap,
  1356. AD7380_REG_ADDR_CONFIG1,
  1357. AD7380_CONFIG1_OSR | AD7380_CONFIG1_RES,
  1358. FIELD_PREP(AD7380_CONFIG1_OSR, osr) |
  1359. FIELD_PREP(AD7380_CONFIG1_RES, boost));
  1360. if (ret)
  1361. return ret;
  1362. st->resolution_boost_enabled = boost;
  1363. /*
  1364. * Perform a soft reset. This will flush the oversampling
  1365. * block and FIFO but will maintain the content of the
  1366. * configurable registers.
  1367. */
  1368. ret = regmap_update_bits(st->regmap,
  1369. AD7380_REG_ADDR_CONFIG2,
  1370. AD7380_CONFIG2_RESET,
  1371. FIELD_PREP(AD7380_CONFIG2_RESET,
  1372. AD7380_CONFIG2_RESET_SOFT));
  1373. return ret;
  1374. }
  1375. static int ad7380_write_raw(struct iio_dev *indio_dev,
  1376. struct iio_chan_spec const *chan, int val,
  1377. int val2, long mask)
  1378. {
  1379. struct ad7380_state *st = iio_priv(indio_dev);
  1380. int ret;
  1381. switch (mask) {
  1382. case IIO_CHAN_INFO_SAMP_FREQ:
  1383. if (val < 1)
  1384. return -EINVAL;
  1385. return ad7380_set_sample_freq(st, val);
  1386. case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
  1387. if (!iio_device_claim_direct(indio_dev))
  1388. return -EBUSY;
  1389. ret = ad7380_set_oversampling_ratio(st, val);
  1390. iio_device_release_direct(indio_dev);
  1391. return ret;
  1392. default:
  1393. return -EINVAL;
  1394. }
  1395. }
  1396. static int ad7380_get_current_scan_type(const struct iio_dev *indio_dev,
  1397. const struct iio_chan_spec *chan)
  1398. {
  1399. struct ad7380_state *st = iio_priv(indio_dev);
  1400. return st->resolution_boost_enabled ? AD7380_SCAN_TYPE_RESOLUTION_BOOST
  1401. : AD7380_SCAN_TYPE_NORMAL;
  1402. }
  1403. static int ad7380_read_event_config(struct iio_dev *indio_dev,
  1404. const struct iio_chan_spec *chan,
  1405. enum iio_event_type type,
  1406. enum iio_event_direction dir)
  1407. {
  1408. struct ad7380_state *st = iio_priv(indio_dev);
  1409. int tmp, ret;
  1410. if (!iio_device_claim_direct(indio_dev))
  1411. return -EBUSY;
  1412. ret = regmap_read(st->regmap, AD7380_REG_ADDR_CONFIG1, &tmp);
  1413. iio_device_release_direct(indio_dev);
  1414. if (ret)
  1415. return ret;
  1416. return FIELD_GET(AD7380_CONFIG1_ALERTEN, tmp);
  1417. }
  1418. static int ad7380_write_event_config(struct iio_dev *indio_dev,
  1419. const struct iio_chan_spec *chan,
  1420. enum iio_event_type type,
  1421. enum iio_event_direction dir,
  1422. bool state)
  1423. {
  1424. struct ad7380_state *st = iio_priv(indio_dev);
  1425. int ret;
  1426. if (!iio_device_claim_direct(indio_dev))
  1427. return -EBUSY;
  1428. ret = regmap_update_bits(st->regmap,
  1429. AD7380_REG_ADDR_CONFIG1,
  1430. AD7380_CONFIG1_ALERTEN,
  1431. FIELD_PREP(AD7380_CONFIG1_ALERTEN, state));
  1432. iio_device_release_direct(indio_dev);
  1433. return ret;
  1434. }
  1435. static int ad7380_get_alert_th(struct iio_dev *indio_dev,
  1436. const struct iio_chan_spec *chan,
  1437. enum iio_event_direction dir,
  1438. int *val)
  1439. {
  1440. struct ad7380_state *st = iio_priv(indio_dev);
  1441. const struct iio_scan_type *scan_type;
  1442. int ret, tmp, shift;
  1443. scan_type = iio_get_current_scan_type(indio_dev, chan);
  1444. if (IS_ERR(scan_type))
  1445. return PTR_ERR(scan_type);
  1446. /*
  1447. * The register value is 12-bits and is compared to the most significant
  1448. * bits of raw value, therefore a shift is required to convert this to
  1449. * the same scale as the raw value.
  1450. */
  1451. shift = scan_type->realbits - 12;
  1452. switch (dir) {
  1453. case IIO_EV_DIR_RISING:
  1454. ret = regmap_read(st->regmap,
  1455. AD7380_REG_ADDR_ALERT_HIGH_TH,
  1456. &tmp);
  1457. if (ret)
  1458. return ret;
  1459. *val = FIELD_GET(AD7380_ALERT_HIGH_TH, tmp) << shift;
  1460. return IIO_VAL_INT;
  1461. case IIO_EV_DIR_FALLING:
  1462. ret = regmap_read(st->regmap,
  1463. AD7380_REG_ADDR_ALERT_LOW_TH,
  1464. &tmp);
  1465. if (ret)
  1466. return ret;
  1467. *val = FIELD_GET(AD7380_ALERT_LOW_TH, tmp) << shift;
  1468. return IIO_VAL_INT;
  1469. default:
  1470. return -EINVAL;
  1471. }
  1472. }
  1473. static int ad7380_read_event_value(struct iio_dev *indio_dev,
  1474. const struct iio_chan_spec *chan,
  1475. enum iio_event_type type,
  1476. enum iio_event_direction dir,
  1477. enum iio_event_info info,
  1478. int *val, int *val2)
  1479. {
  1480. int ret;
  1481. switch (info) {
  1482. case IIO_EV_INFO_VALUE:
  1483. if (!iio_device_claim_direct(indio_dev))
  1484. return -EBUSY;
  1485. ret = ad7380_get_alert_th(indio_dev, chan, dir, val);
  1486. iio_device_release_direct(indio_dev);
  1487. return ret;
  1488. default:
  1489. return -EINVAL;
  1490. }
  1491. }
  1492. static int ad7380_set_alert_th(struct iio_dev *indio_dev,
  1493. const struct iio_chan_spec *chan,
  1494. enum iio_event_direction dir,
  1495. int val)
  1496. {
  1497. struct ad7380_state *st = iio_priv(indio_dev);
  1498. const struct iio_scan_type *scan_type;
  1499. u16 th;
  1500. /*
  1501. * According to the datasheet,
  1502. * AD7380_REG_ADDR_ALERT_HIGH_TH[11:0] are the 12 MSB of the
  1503. * 16-bits internal alert high register. LSB are set to 0xf.
  1504. * AD7380_REG_ADDR_ALERT_LOW_TH[11:0] are the 12 MSB of the
  1505. * 16 bits internal alert low register. LSB are set to 0x0.
  1506. *
  1507. * When alert is enabled the conversion from the adc is compared
  1508. * immediately to the alert high/low thresholds, before any
  1509. * oversampling. This means that the thresholds are the same for
  1510. * normal mode and oversampling mode.
  1511. */
  1512. /* Extract the 12 MSB of val */
  1513. scan_type = iio_get_current_scan_type(indio_dev, chan);
  1514. if (IS_ERR(scan_type))
  1515. return PTR_ERR(scan_type);
  1516. th = val >> (scan_type->realbits - 12);
  1517. switch (dir) {
  1518. case IIO_EV_DIR_RISING:
  1519. return regmap_write(st->regmap,
  1520. AD7380_REG_ADDR_ALERT_HIGH_TH,
  1521. th);
  1522. case IIO_EV_DIR_FALLING:
  1523. return regmap_write(st->regmap,
  1524. AD7380_REG_ADDR_ALERT_LOW_TH,
  1525. th);
  1526. default:
  1527. return -EINVAL;
  1528. }
  1529. }
  1530. static int ad7380_write_event_value(struct iio_dev *indio_dev,
  1531. const struct iio_chan_spec *chan,
  1532. enum iio_event_type type,
  1533. enum iio_event_direction dir,
  1534. enum iio_event_info info,
  1535. int val, int val2)
  1536. {
  1537. int ret;
  1538. switch (info) {
  1539. case IIO_EV_INFO_VALUE:
  1540. if (!iio_device_claim_direct(indio_dev))
  1541. return -EBUSY;
  1542. ret = ad7380_set_alert_th(indio_dev, chan, dir, val);
  1543. iio_device_release_direct(indio_dev);
  1544. return ret;
  1545. default:
  1546. return -EINVAL;
  1547. }
  1548. }
  1549. static const struct iio_info ad7380_info = {
  1550. .read_raw = &ad7380_read_raw,
  1551. .read_avail = &ad7380_read_avail,
  1552. .write_raw = &ad7380_write_raw,
  1553. .get_current_scan_type = &ad7380_get_current_scan_type,
  1554. .debugfs_reg_access = &ad7380_debugfs_reg_access,
  1555. .read_event_config = &ad7380_read_event_config,
  1556. .write_event_config = &ad7380_write_event_config,
  1557. .read_event_value = &ad7380_read_event_value,
  1558. .write_event_value = &ad7380_write_event_value,
  1559. };
  1560. static int ad7380_init(struct ad7380_state *st, bool external_ref_en)
  1561. {
  1562. int ret;
  1563. /* perform hard reset */
  1564. ret = regmap_update_bits(st->regmap, AD7380_REG_ADDR_CONFIG2,
  1565. AD7380_CONFIG2_RESET,
  1566. FIELD_PREP(AD7380_CONFIG2_RESET,
  1567. AD7380_CONFIG2_RESET_HARD));
  1568. if (ret < 0)
  1569. return ret;
  1570. if (external_ref_en) {
  1571. /* select external reference voltage */
  1572. ret = regmap_set_bits(st->regmap, AD7380_REG_ADDR_CONFIG1,
  1573. AD7380_CONFIG1_REFSEL);
  1574. if (ret < 0)
  1575. return ret;
  1576. }
  1577. /* This is the default value after reset. */
  1578. st->ch = 0;
  1579. st->seq = false;
  1580. /* SPI 1-wire mode */
  1581. return regmap_update_bits(st->regmap, AD7380_REG_ADDR_CONFIG2,
  1582. AD7380_CONFIG2_SDO,
  1583. FIELD_PREP(AD7380_CONFIG2_SDO,
  1584. AD7380_NUM_SDO_LINES));
  1585. }
  1586. static int ad7380_probe_spi_offload(struct iio_dev *indio_dev,
  1587. struct ad7380_state *st)
  1588. {
  1589. struct spi_device *spi = st->spi;
  1590. struct device *dev = &spi->dev;
  1591. struct dma_chan *rx_dma;
  1592. int sample_rate, ret;
  1593. indio_dev->setup_ops = &ad7380_offload_buffer_setup_ops;
  1594. indio_dev->channels = st->chip_info->offload_channels;
  1595. /* Just removing the timestamp channel. */
  1596. indio_dev->num_channels--;
  1597. st->offload_trigger = devm_spi_offload_trigger_get(dev, st->offload,
  1598. SPI_OFFLOAD_TRIGGER_PERIODIC);
  1599. if (IS_ERR(st->offload_trigger))
  1600. return dev_err_probe(dev, PTR_ERR(st->offload_trigger),
  1601. "failed to get offload trigger\n");
  1602. sample_rate = st->chip_info->max_conversion_rate_hz *
  1603. AD7380_NUM_SDO_LINES / st->chip_info->num_simult_channels;
  1604. st->sample_freq_range[0] = 1; /* min */
  1605. st->sample_freq_range[1] = 1; /* step */
  1606. st->sample_freq_range[2] = sample_rate; /* max */
  1607. /*
  1608. * Starting with a quite low frequency, to allow oversampling x32,
  1609. * user is then reponsible to adjust the frequency for the specific case.
  1610. */
  1611. ret = ad7380_set_sample_freq(st, sample_rate / 32);
  1612. if (ret)
  1613. return ret;
  1614. rx_dma = devm_spi_offload_rx_stream_request_dma_chan(dev, st->offload);
  1615. if (IS_ERR(rx_dma))
  1616. return dev_err_probe(dev, PTR_ERR(rx_dma),
  1617. "failed to get offload RX DMA\n");
  1618. ret = devm_iio_dmaengine_buffer_setup_with_handle(dev, indio_dev,
  1619. rx_dma, IIO_BUFFER_DIRECTION_IN);
  1620. if (ret)
  1621. return dev_err_probe(dev, ret, "cannot setup dma buffer\n");
  1622. return 0;
  1623. }
  1624. static int ad7380_probe(struct spi_device *spi)
  1625. {
  1626. struct device *dev = &spi->dev;
  1627. struct iio_dev *indio_dev;
  1628. struct ad7380_state *st;
  1629. bool external_ref_en;
  1630. int ret, i;
  1631. indio_dev = devm_iio_device_alloc(dev, sizeof(*st));
  1632. if (!indio_dev)
  1633. return -ENOMEM;
  1634. st = iio_priv(indio_dev);
  1635. st->spi = spi;
  1636. st->chip_info = spi_get_device_match_data(spi);
  1637. if (!st->chip_info)
  1638. return dev_err_probe(dev, -EINVAL, "missing match data\n");
  1639. ret = devm_regulator_bulk_get_enable(dev, st->chip_info->num_supplies,
  1640. st->chip_info->supplies);
  1641. if (ret)
  1642. return dev_err_probe(dev, ret,
  1643. "Failed to enable power supplies\n");
  1644. fsleep(T_POWERUP_US);
  1645. if (st->chip_info->internal_ref_only) {
  1646. /*
  1647. * ADAQ chips use fixed internal reference but still
  1648. * require a specific reference supply to power it.
  1649. * "refin" is already enabled with other power supplies
  1650. * in bulk_get_enable().
  1651. */
  1652. st->vref_mv = st->chip_info->internal_ref_mv;
  1653. /* these chips don't have a register bit for this */
  1654. external_ref_en = false;
  1655. } else if (st->chip_info->external_ref_only) {
  1656. ret = devm_regulator_get_enable_read_voltage(dev, "refin");
  1657. if (ret < 0)
  1658. return dev_err_probe(dev, ret,
  1659. "Failed to get refin regulator\n");
  1660. st->vref_mv = ret / 1000;
  1661. /* these chips don't have a register bit for this */
  1662. external_ref_en = false;
  1663. } else {
  1664. /*
  1665. * If there is no REFIO supply, then it means that we are using
  1666. * the internal reference, otherwise REFIO is reference voltage.
  1667. */
  1668. ret = devm_regulator_get_enable_read_voltage(dev, "refio");
  1669. if (ret < 0 && ret != -ENODEV)
  1670. return dev_err_probe(dev, ret,
  1671. "Failed to get refio regulator\n");
  1672. external_ref_en = ret != -ENODEV;
  1673. st->vref_mv = external_ref_en ? ret / 1000
  1674. : st->chip_info->internal_ref_mv;
  1675. }
  1676. if (st->chip_info->num_vcm_supplies > ARRAY_SIZE(st->vcm_mv))
  1677. return dev_err_probe(dev, -EINVAL,
  1678. "invalid number of VCM supplies\n");
  1679. /*
  1680. * pseudo-differential chips have common mode supplies for the negative
  1681. * input pin.
  1682. */
  1683. for (i = 0; i < st->chip_info->num_vcm_supplies; i++) {
  1684. const char *vcm = st->chip_info->vcm_supplies[i];
  1685. ret = devm_regulator_get_enable_read_voltage(dev, vcm);
  1686. if (ret < 0)
  1687. return dev_err_probe(dev, ret,
  1688. "Failed to get %s regulator\n",
  1689. vcm);
  1690. st->vcm_mv[i] = ret / 1000;
  1691. }
  1692. for (i = 0; i < MAX_NUM_CHANNELS; i++)
  1693. st->gain_milli[i] = AD7380_DEFAULT_GAIN_MILLI;
  1694. if (st->chip_info->has_hardware_gain) {
  1695. device_for_each_child_node_scoped(dev, node) {
  1696. unsigned int channel;
  1697. int gain_idx;
  1698. u16 gain;
  1699. ret = fwnode_property_read_u32(node, "reg", &channel);
  1700. if (ret)
  1701. return dev_err_probe(dev, ret,
  1702. "Failed to read reg property\n");
  1703. if (channel >= st->chip_info->num_channels - 1)
  1704. return dev_err_probe(dev, -EINVAL,
  1705. "Invalid channel number %i\n",
  1706. channel);
  1707. ret = fwnode_property_read_u16(node, "adi,gain-milli",
  1708. &gain);
  1709. if (ret && ret != -EINVAL)
  1710. return dev_err_probe(dev, ret,
  1711. "Failed to read gain for channel %i\n",
  1712. channel);
  1713. if (ret != -EINVAL) {
  1714. /*
  1715. * Match gain value from dt to one of supported
  1716. * gains
  1717. */
  1718. gain_idx = find_closest(gain, ad7380_gains,
  1719. ARRAY_SIZE(ad7380_gains));
  1720. st->gain_milli[channel] = ad7380_gains[gain_idx];
  1721. }
  1722. }
  1723. }
  1724. st->regmap = devm_regmap_init(dev, NULL, st, &ad7380_regmap_config);
  1725. if (IS_ERR(st->regmap))
  1726. return dev_err_probe(dev, PTR_ERR(st->regmap),
  1727. "failed to allocate register map\n");
  1728. /*
  1729. * Setting up xfer structures for both normal and sequence mode. These
  1730. * struct are used for both direct read and triggered buffer. Additional
  1731. * fields will be set up in ad7380_update_xfers() based on the current
  1732. * state of the driver at the time of the read.
  1733. */
  1734. /*
  1735. * In normal mode a read is composed of two steps:
  1736. * - first, toggle CS (no data xfer) to trigger a conversion
  1737. * - then, read data
  1738. */
  1739. st->normal_xfer[0].cs_change = 1;
  1740. st->normal_xfer[0].cs_change_delay.value = st->chip_info->timing_specs->t_csh_ns;
  1741. st->normal_xfer[0].cs_change_delay.unit = SPI_DELAY_UNIT_NSECS;
  1742. st->normal_xfer[1].rx_buf = st->scan_data;
  1743. spi_message_init_with_transfers(&st->normal_msg, st->normal_xfer,
  1744. ARRAY_SIZE(st->normal_xfer));
  1745. /*
  1746. * In sequencer mode a read is composed of four steps:
  1747. * - CS toggle (no data xfer) to get the right point in the sequence
  1748. * - CS toggle (no data xfer) to trigger a conversion of AinX0 and
  1749. * acquisition of AinX1
  1750. * - 2 data reads, to read AinX0 and AinX1
  1751. */
  1752. st->seq_xfer[0].cs_change = 1;
  1753. st->seq_xfer[0].cs_change_delay.value = st->chip_info->timing_specs->t_csh_ns;
  1754. st->seq_xfer[0].cs_change_delay.unit = SPI_DELAY_UNIT_NSECS;
  1755. st->seq_xfer[1].cs_change = 1;
  1756. st->seq_xfer[1].cs_change_delay.value = st->chip_info->timing_specs->t_csh_ns;
  1757. st->seq_xfer[1].cs_change_delay.unit = SPI_DELAY_UNIT_NSECS;
  1758. st->seq_xfer[2].rx_buf = st->scan_data;
  1759. st->seq_xfer[2].cs_change = 1;
  1760. st->seq_xfer[2].cs_change_delay.value = st->chip_info->timing_specs->t_csh_ns;
  1761. st->seq_xfer[2].cs_change_delay.unit = SPI_DELAY_UNIT_NSECS;
  1762. spi_message_init_with_transfers(&st->seq_msg, st->seq_xfer,
  1763. ARRAY_SIZE(st->seq_xfer));
  1764. indio_dev->channels = st->chip_info->channels;
  1765. indio_dev->num_channels = st->chip_info->num_channels;
  1766. indio_dev->name = st->chip_info->name;
  1767. indio_dev->info = &ad7380_info;
  1768. indio_dev->modes = INDIO_DIRECT_MODE;
  1769. indio_dev->available_scan_masks = st->chip_info->available_scan_masks;
  1770. st->offload = devm_spi_offload_get(dev, spi, &ad7380_offload_config);
  1771. ret = PTR_ERR_OR_ZERO(st->offload);
  1772. if (ret && ret != -ENODEV)
  1773. return dev_err_probe(dev, ret, "failed to get offload\n");
  1774. /* If no SPI offload, fall back to low speed usage. */
  1775. if (ret == -ENODEV) {
  1776. ret = devm_iio_triggered_buffer_setup(dev, indio_dev,
  1777. iio_pollfunc_store_time,
  1778. ad7380_trigger_handler,
  1779. &ad7380_buffer_setup_ops);
  1780. if (ret)
  1781. return ret;
  1782. } else {
  1783. ret = ad7380_probe_spi_offload(indio_dev, st);
  1784. if (ret)
  1785. return ret;
  1786. }
  1787. ret = ad7380_init(st, external_ref_en);
  1788. if (ret)
  1789. return ret;
  1790. return devm_iio_device_register(dev, indio_dev);
  1791. }
  1792. static const struct of_device_id ad7380_of_match_table[] = {
  1793. { .compatible = "adi,ad7380", .data = &ad7380_chip_info },
  1794. { .compatible = "adi,ad7381", .data = &ad7381_chip_info },
  1795. { .compatible = "adi,ad7383", .data = &ad7383_chip_info },
  1796. { .compatible = "adi,ad7384", .data = &ad7384_chip_info },
  1797. { .compatible = "adi,ad7386", .data = &ad7386_chip_info },
  1798. { .compatible = "adi,ad7387", .data = &ad7387_chip_info },
  1799. { .compatible = "adi,ad7388", .data = &ad7388_chip_info },
  1800. { .compatible = "adi,ad7380-4", .data = &ad7380_4_chip_info },
  1801. { .compatible = "adi,ad7381-4", .data = &ad7381_4_chip_info },
  1802. { .compatible = "adi,ad7383-4", .data = &ad7383_4_chip_info },
  1803. { .compatible = "adi,ad7384-4", .data = &ad7384_4_chip_info },
  1804. { .compatible = "adi,ad7386-4", .data = &ad7386_4_chip_info },
  1805. { .compatible = "adi,ad7387-4", .data = &ad7387_4_chip_info },
  1806. { .compatible = "adi,ad7388-4", .data = &ad7388_4_chip_info },
  1807. { .compatible = "adi,ad7389-4", .data = &ad7389_4_chip_info },
  1808. { .compatible = "adi,adaq4370-4", .data = &adaq4370_4_chip_info },
  1809. { .compatible = "adi,adaq4380-4", .data = &adaq4380_4_chip_info },
  1810. { .compatible = "adi,adaq4381-4", .data = &adaq4381_4_chip_info },
  1811. { }
  1812. };
  1813. static const struct spi_device_id ad7380_id_table[] = {
  1814. { "ad7380", (kernel_ulong_t)&ad7380_chip_info },
  1815. { "ad7381", (kernel_ulong_t)&ad7381_chip_info },
  1816. { "ad7383", (kernel_ulong_t)&ad7383_chip_info },
  1817. { "ad7384", (kernel_ulong_t)&ad7384_chip_info },
  1818. { "ad7386", (kernel_ulong_t)&ad7386_chip_info },
  1819. { "ad7387", (kernel_ulong_t)&ad7387_chip_info },
  1820. { "ad7388", (kernel_ulong_t)&ad7388_chip_info },
  1821. { "ad7380-4", (kernel_ulong_t)&ad7380_4_chip_info },
  1822. { "ad7381-4", (kernel_ulong_t)&ad7381_4_chip_info },
  1823. { "ad7383-4", (kernel_ulong_t)&ad7383_4_chip_info },
  1824. { "ad7384-4", (kernel_ulong_t)&ad7384_4_chip_info },
  1825. { "ad7386-4", (kernel_ulong_t)&ad7386_4_chip_info },
  1826. { "ad7387-4", (kernel_ulong_t)&ad7387_4_chip_info },
  1827. { "ad7388-4", (kernel_ulong_t)&ad7388_4_chip_info },
  1828. { "ad7389-4", (kernel_ulong_t)&ad7389_4_chip_info },
  1829. { "adaq4370-4", (kernel_ulong_t)&adaq4370_4_chip_info },
  1830. { "adaq4380-4", (kernel_ulong_t)&adaq4380_4_chip_info },
  1831. { "adaq4381-4", (kernel_ulong_t)&adaq4381_4_chip_info },
  1832. { }
  1833. };
  1834. MODULE_DEVICE_TABLE(spi, ad7380_id_table);
  1835. static struct spi_driver ad7380_driver = {
  1836. .driver = {
  1837. .name = "ad7380",
  1838. .of_match_table = ad7380_of_match_table,
  1839. },
  1840. .probe = ad7380_probe,
  1841. .id_table = ad7380_id_table,
  1842. };
  1843. module_spi_driver(ad7380_driver);
  1844. MODULE_AUTHOR("Stefan Popa <stefan.popa@analog.com>");
  1845. MODULE_DESCRIPTION("Analog Devices AD738x ADC driver");
  1846. MODULE_LICENSE("GPL");
  1847. MODULE_IMPORT_NS("IIO_DMAENGINE_BUFFER");