max1027.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * iio/adc/max1027.c
  4. * Copyright (C) 2014 Philippe Reynes
  5. *
  6. * based on linux/drivers/iio/ad7923.c
  7. * Copyright 2011 Analog Devices Inc (from AD7923 Driver)
  8. * Copyright 2012 CS Systemes d'Information
  9. *
  10. * max1027.c
  11. *
  12. * Partial support for max1027 and similar chips.
  13. */
  14. #include <linux/kernel.h>
  15. #include <linux/module.h>
  16. #include <linux/mod_devicetable.h>
  17. #include <linux/spi/spi.h>
  18. #include <linux/delay.h>
  19. #include <linux/iio/iio.h>
  20. #include <linux/iio/buffer.h>
  21. #include <linux/iio/trigger.h>
  22. #include <linux/iio/trigger_consumer.h>
  23. #include <linux/iio/triggered_buffer.h>
  24. #define MAX1027_CONV_REG BIT(7)
  25. #define MAX1027_SETUP_REG BIT(6)
  26. #define MAX1027_AVG_REG BIT(5)
  27. #define MAX1027_RST_REG BIT(4)
  28. /* conversion register */
  29. #define MAX1027_TEMP BIT(0)
  30. #define MAX1027_SCAN_0_N (0x00 << 1)
  31. #define MAX1027_SCAN_N_M (0x01 << 1)
  32. #define MAX1027_SCAN_N (0x02 << 1)
  33. #define MAX1027_NOSCAN (0x03 << 1)
  34. #define MAX1027_CHAN(n) ((n) << 3)
  35. /* setup register */
  36. #define MAX1027_UNIPOLAR 0x02
  37. #define MAX1027_BIPOLAR 0x03
  38. #define MAX1027_REF_MODE0 (0x00 << 2)
  39. #define MAX1027_REF_MODE1 (0x01 << 2)
  40. #define MAX1027_REF_MODE2 (0x02 << 2)
  41. #define MAX1027_REF_MODE3 (0x03 << 2)
  42. #define MAX1027_CKS_MODE0 (0x00 << 4)
  43. #define MAX1027_CKS_MODE1 (0x01 << 4)
  44. #define MAX1027_CKS_MODE2 (0x02 << 4)
  45. #define MAX1027_CKS_MODE3 (0x03 << 4)
  46. /* averaging register */
  47. #define MAX1027_NSCAN_4 0x00
  48. #define MAX1027_NSCAN_8 0x01
  49. #define MAX1027_NSCAN_12 0x02
  50. #define MAX1027_NSCAN_16 0x03
  51. #define MAX1027_NAVG_4 (0x00 << 2)
  52. #define MAX1027_NAVG_8 (0x01 << 2)
  53. #define MAX1027_NAVG_16 (0x02 << 2)
  54. #define MAX1027_NAVG_32 (0x03 << 2)
  55. #define MAX1027_AVG_EN BIT(4)
  56. /* Device can achieve 300ksps so we assume a 3.33us conversion delay */
  57. #define MAX1027_CONVERSION_UDELAY 4
  58. enum max1027_id {
  59. max1027,
  60. max1029,
  61. max1031,
  62. max1227,
  63. max1229,
  64. max1231,
  65. };
  66. static const struct spi_device_id max1027_id[] = {
  67. {"max1027", max1027},
  68. {"max1029", max1029},
  69. {"max1031", max1031},
  70. {"max1227", max1227},
  71. {"max1229", max1229},
  72. {"max1231", max1231},
  73. {}
  74. };
  75. MODULE_DEVICE_TABLE(spi, max1027_id);
  76. static const struct of_device_id max1027_adc_dt_ids[] = {
  77. { .compatible = "maxim,max1027" },
  78. { .compatible = "maxim,max1029" },
  79. { .compatible = "maxim,max1031" },
  80. { .compatible = "maxim,max1227" },
  81. { .compatible = "maxim,max1229" },
  82. { .compatible = "maxim,max1231" },
  83. {},
  84. };
  85. MODULE_DEVICE_TABLE(of, max1027_adc_dt_ids);
  86. #define MAX1027_V_CHAN(index, depth) \
  87. { \
  88. .type = IIO_VOLTAGE, \
  89. .indexed = 1, \
  90. .channel = index, \
  91. .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
  92. .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
  93. .scan_index = index + 1, \
  94. .scan_type = { \
  95. .sign = 'u', \
  96. .realbits = depth, \
  97. .storagebits = 16, \
  98. .shift = (depth == 10) ? 2 : 0, \
  99. .endianness = IIO_BE, \
  100. }, \
  101. }
  102. #define MAX1027_T_CHAN \
  103. { \
  104. .type = IIO_TEMP, \
  105. .channel = 0, \
  106. .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
  107. .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
  108. .scan_index = 0, \
  109. .scan_type = { \
  110. .sign = 'u', \
  111. .realbits = 12, \
  112. .storagebits = 16, \
  113. .endianness = IIO_BE, \
  114. }, \
  115. }
  116. #define MAX1X27_CHANNELS(depth) \
  117. MAX1027_T_CHAN, \
  118. MAX1027_V_CHAN(0, depth), \
  119. MAX1027_V_CHAN(1, depth), \
  120. MAX1027_V_CHAN(2, depth), \
  121. MAX1027_V_CHAN(3, depth), \
  122. MAX1027_V_CHAN(4, depth), \
  123. MAX1027_V_CHAN(5, depth), \
  124. MAX1027_V_CHAN(6, depth), \
  125. MAX1027_V_CHAN(7, depth)
  126. #define MAX1X29_CHANNELS(depth) \
  127. MAX1X27_CHANNELS(depth), \
  128. MAX1027_V_CHAN(8, depth), \
  129. MAX1027_V_CHAN(9, depth), \
  130. MAX1027_V_CHAN(10, depth), \
  131. MAX1027_V_CHAN(11, depth)
  132. #define MAX1X31_CHANNELS(depth) \
  133. MAX1X29_CHANNELS(depth), \
  134. MAX1027_V_CHAN(12, depth), \
  135. MAX1027_V_CHAN(13, depth), \
  136. MAX1027_V_CHAN(14, depth), \
  137. MAX1027_V_CHAN(15, depth)
  138. static const struct iio_chan_spec max1027_channels[] = {
  139. MAX1X27_CHANNELS(10),
  140. };
  141. static const struct iio_chan_spec max1029_channels[] = {
  142. MAX1X29_CHANNELS(10),
  143. };
  144. static const struct iio_chan_spec max1031_channels[] = {
  145. MAX1X31_CHANNELS(10),
  146. };
  147. static const struct iio_chan_spec max1227_channels[] = {
  148. MAX1X27_CHANNELS(12),
  149. };
  150. static const struct iio_chan_spec max1229_channels[] = {
  151. MAX1X29_CHANNELS(12),
  152. };
  153. static const struct iio_chan_spec max1231_channels[] = {
  154. MAX1X31_CHANNELS(12),
  155. };
  156. /*
  157. * These devices are able to scan from 0 to N, N being the highest voltage
  158. * channel requested by the user. The temperature can be included or not,
  159. * but cannot be retrieved alone. Based on the below
  160. * ->available_scan_masks, the core will select the most appropriate
  161. * ->active_scan_mask and the "minimum" number of channels will be
  162. * scanned and pushed to the buffers.
  163. *
  164. * For example, if the user wants channels 1, 4 and 5, all channels from
  165. * 0 to 5 will be scanned and pushed to the IIO buffers. The core will then
  166. * filter out the unneeded samples based on the ->active_scan_mask that has
  167. * been selected and only channels 1, 4 and 5 will be available to the user
  168. * in the shared buffer.
  169. */
  170. #define MAX1X27_SCAN_MASK_TEMP BIT(0)
  171. #define MAX1X27_SCAN_MASKS(temp) \
  172. GENMASK(1, 1 - (temp)), GENMASK(2, 1 - (temp)), \
  173. GENMASK(3, 1 - (temp)), GENMASK(4, 1 - (temp)), \
  174. GENMASK(5, 1 - (temp)), GENMASK(6, 1 - (temp)), \
  175. GENMASK(7, 1 - (temp)), GENMASK(8, 1 - (temp))
  176. #define MAX1X29_SCAN_MASKS(temp) \
  177. MAX1X27_SCAN_MASKS(temp), \
  178. GENMASK(9, 1 - (temp)), GENMASK(10, 1 - (temp)), \
  179. GENMASK(11, 1 - (temp)), GENMASK(12, 1 - (temp))
  180. #define MAX1X31_SCAN_MASKS(temp) \
  181. MAX1X29_SCAN_MASKS(temp), \
  182. GENMASK(13, 1 - (temp)), GENMASK(14, 1 - (temp)), \
  183. GENMASK(15, 1 - (temp)), GENMASK(16, 1 - (temp))
  184. static const unsigned long max1027_available_scan_masks[] = {
  185. MAX1X27_SCAN_MASKS(0),
  186. MAX1X27_SCAN_MASKS(1),
  187. 0x00000000,
  188. };
  189. static const unsigned long max1029_available_scan_masks[] = {
  190. MAX1X29_SCAN_MASKS(0),
  191. MAX1X29_SCAN_MASKS(1),
  192. 0x00000000,
  193. };
  194. static const unsigned long max1031_available_scan_masks[] = {
  195. MAX1X31_SCAN_MASKS(0),
  196. MAX1X31_SCAN_MASKS(1),
  197. 0x00000000,
  198. };
  199. struct max1027_chip_info {
  200. const struct iio_chan_spec *channels;
  201. unsigned int num_channels;
  202. const unsigned long *available_scan_masks;
  203. };
  204. static const struct max1027_chip_info max1027_chip_info_tbl[] = {
  205. [max1027] = {
  206. .channels = max1027_channels,
  207. .num_channels = ARRAY_SIZE(max1027_channels),
  208. .available_scan_masks = max1027_available_scan_masks,
  209. },
  210. [max1029] = {
  211. .channels = max1029_channels,
  212. .num_channels = ARRAY_SIZE(max1029_channels),
  213. .available_scan_masks = max1029_available_scan_masks,
  214. },
  215. [max1031] = {
  216. .channels = max1031_channels,
  217. .num_channels = ARRAY_SIZE(max1031_channels),
  218. .available_scan_masks = max1031_available_scan_masks,
  219. },
  220. [max1227] = {
  221. .channels = max1227_channels,
  222. .num_channels = ARRAY_SIZE(max1227_channels),
  223. .available_scan_masks = max1027_available_scan_masks,
  224. },
  225. [max1229] = {
  226. .channels = max1229_channels,
  227. .num_channels = ARRAY_SIZE(max1229_channels),
  228. .available_scan_masks = max1029_available_scan_masks,
  229. },
  230. [max1231] = {
  231. .channels = max1231_channels,
  232. .num_channels = ARRAY_SIZE(max1231_channels),
  233. .available_scan_masks = max1031_available_scan_masks,
  234. },
  235. };
  236. struct max1027_state {
  237. const struct max1027_chip_info *info;
  238. struct spi_device *spi;
  239. struct iio_trigger *trig;
  240. __be16 *buffer;
  241. struct mutex lock;
  242. struct completion complete;
  243. u8 reg __aligned(IIO_DMA_MINALIGN);
  244. };
  245. static int max1027_wait_eoc(struct iio_dev *indio_dev)
  246. {
  247. struct max1027_state *st = iio_priv(indio_dev);
  248. unsigned int conversion_time = MAX1027_CONVERSION_UDELAY;
  249. int ret;
  250. if (st->spi->irq) {
  251. ret = wait_for_completion_timeout(&st->complete,
  252. msecs_to_jiffies(1000));
  253. reinit_completion(&st->complete);
  254. if (!ret)
  255. return -ETIMEDOUT;
  256. } else {
  257. if (indio_dev->active_scan_mask)
  258. conversion_time *= hweight32(*indio_dev->active_scan_mask);
  259. usleep_range(conversion_time, conversion_time * 2);
  260. }
  261. return 0;
  262. }
  263. /* Scan from chan 0 to the highest requested channel. Include temperature on demand. */
  264. static int max1027_configure_chans_and_start(struct iio_dev *indio_dev)
  265. {
  266. struct max1027_state *st = iio_priv(indio_dev);
  267. st->reg = MAX1027_CONV_REG | MAX1027_SCAN_0_N;
  268. st->reg |= MAX1027_CHAN(fls(*indio_dev->active_scan_mask) - 2);
  269. if (*indio_dev->active_scan_mask & MAX1X27_SCAN_MASK_TEMP)
  270. st->reg |= MAX1027_TEMP;
  271. return spi_write(st->spi, &st->reg, 1);
  272. }
  273. static int max1027_enable_trigger(struct iio_dev *indio_dev, bool enable)
  274. {
  275. struct max1027_state *st = iio_priv(indio_dev);
  276. st->reg = MAX1027_SETUP_REG | MAX1027_REF_MODE2;
  277. /*
  278. * Start acquisition on:
  279. * MODE0: external hardware trigger wired to the cnvst input pin
  280. * MODE2: conversion register write
  281. */
  282. if (enable)
  283. st->reg |= MAX1027_CKS_MODE0;
  284. else
  285. st->reg |= MAX1027_CKS_MODE2;
  286. return spi_write(st->spi, &st->reg, 1);
  287. }
  288. static int max1027_read_single_value(struct iio_dev *indio_dev,
  289. struct iio_chan_spec const *chan,
  290. int *val)
  291. {
  292. int ret;
  293. struct max1027_state *st = iio_priv(indio_dev);
  294. ret = iio_device_claim_direct_mode(indio_dev);
  295. if (ret)
  296. return ret;
  297. /* Configure conversion register with the requested chan */
  298. st->reg = MAX1027_CONV_REG | MAX1027_CHAN(chan->channel) |
  299. MAX1027_NOSCAN;
  300. if (chan->type == IIO_TEMP)
  301. st->reg |= MAX1027_TEMP;
  302. ret = spi_write(st->spi, &st->reg, 1);
  303. if (ret < 0) {
  304. dev_err(&indio_dev->dev,
  305. "Failed to configure conversion register\n");
  306. goto release;
  307. }
  308. /*
  309. * For an unknown reason, when we use the mode "10" (write
  310. * conversion register), the interrupt doesn't occur every time.
  311. * So we just wait the maximum conversion time and deliver the value.
  312. */
  313. ret = max1027_wait_eoc(indio_dev);
  314. if (ret)
  315. goto release;
  316. /* Read result */
  317. ret = spi_read(st->spi, st->buffer, (chan->type == IIO_TEMP) ? 4 : 2);
  318. release:
  319. iio_device_release_direct_mode(indio_dev);
  320. if (ret < 0)
  321. return ret;
  322. *val = be16_to_cpu(st->buffer[0]);
  323. return IIO_VAL_INT;
  324. }
  325. static int max1027_read_raw(struct iio_dev *indio_dev,
  326. struct iio_chan_spec const *chan,
  327. int *val, int *val2, long mask)
  328. {
  329. int ret = 0;
  330. struct max1027_state *st = iio_priv(indio_dev);
  331. mutex_lock(&st->lock);
  332. switch (mask) {
  333. case IIO_CHAN_INFO_RAW:
  334. ret = max1027_read_single_value(indio_dev, chan, val);
  335. break;
  336. case IIO_CHAN_INFO_SCALE:
  337. switch (chan->type) {
  338. case IIO_TEMP:
  339. *val = 1;
  340. *val2 = 8;
  341. ret = IIO_VAL_FRACTIONAL;
  342. break;
  343. case IIO_VOLTAGE:
  344. *val = 2500;
  345. *val2 = chan->scan_type.realbits;
  346. ret = IIO_VAL_FRACTIONAL_LOG2;
  347. break;
  348. default:
  349. ret = -EINVAL;
  350. break;
  351. }
  352. break;
  353. default:
  354. ret = -EINVAL;
  355. break;
  356. }
  357. mutex_unlock(&st->lock);
  358. return ret;
  359. }
  360. static int max1027_debugfs_reg_access(struct iio_dev *indio_dev,
  361. unsigned int reg, unsigned int writeval,
  362. unsigned int *readval)
  363. {
  364. struct max1027_state *st = iio_priv(indio_dev);
  365. u8 *val = (u8 *)st->buffer;
  366. if (readval) {
  367. int ret = spi_read(st->spi, val, 2);
  368. *readval = be16_to_cpu(st->buffer[0]);
  369. return ret;
  370. }
  371. *val = (u8)writeval;
  372. return spi_write(st->spi, val, 1);
  373. }
  374. static int max1027_set_cnvst_trigger_state(struct iio_trigger *trig, bool state)
  375. {
  376. struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig);
  377. int ret;
  378. /*
  379. * In order to disable the convst trigger, start acquisition on
  380. * conversion register write, which basically disables triggering
  381. * conversions upon cnvst changes and thus has the effect of disabling
  382. * the external hardware trigger.
  383. */
  384. ret = max1027_enable_trigger(indio_dev, state);
  385. if (ret)
  386. return ret;
  387. if (state) {
  388. ret = max1027_configure_chans_and_start(indio_dev);
  389. if (ret)
  390. return ret;
  391. }
  392. return 0;
  393. }
  394. static int max1027_read_scan(struct iio_dev *indio_dev)
  395. {
  396. struct max1027_state *st = iio_priv(indio_dev);
  397. unsigned int scanned_chans;
  398. int ret;
  399. scanned_chans = fls(*indio_dev->active_scan_mask) - 1;
  400. if (*indio_dev->active_scan_mask & MAX1X27_SCAN_MASK_TEMP)
  401. scanned_chans++;
  402. /* fill buffer with all channel */
  403. ret = spi_read(st->spi, st->buffer, scanned_chans * 2);
  404. if (ret < 0)
  405. return ret;
  406. iio_push_to_buffers(indio_dev, st->buffer);
  407. return 0;
  408. }
  409. static irqreturn_t max1027_handler(int irq, void *private)
  410. {
  411. struct iio_dev *indio_dev = private;
  412. struct max1027_state *st = iio_priv(indio_dev);
  413. /*
  414. * If buffers are disabled (raw read) or when using external triggers,
  415. * we just need to unlock the waiters which will then handle the data.
  416. *
  417. * When using the internal trigger, we must hand-off the choice of the
  418. * handler to the core which will then lookup through the interrupt tree
  419. * for the right handler registered with iio_triggered_buffer_setup()
  420. * to execute, as this trigger might very well be used in conjunction
  421. * with another device. The core will then call the relevant handler to
  422. * perform the data processing step.
  423. */
  424. if (!iio_buffer_enabled(indio_dev))
  425. complete(&st->complete);
  426. else
  427. iio_trigger_poll(indio_dev->trig);
  428. return IRQ_HANDLED;
  429. }
  430. static irqreturn_t max1027_trigger_handler(int irq, void *private)
  431. {
  432. struct iio_poll_func *pf = private;
  433. struct iio_dev *indio_dev = pf->indio_dev;
  434. int ret;
  435. if (!iio_trigger_using_own(indio_dev)) {
  436. ret = max1027_configure_chans_and_start(indio_dev);
  437. if (ret)
  438. goto out;
  439. /* This is a threaded handler, it is fine to wait for an IRQ */
  440. ret = max1027_wait_eoc(indio_dev);
  441. if (ret)
  442. goto out;
  443. }
  444. ret = max1027_read_scan(indio_dev);
  445. out:
  446. if (ret)
  447. dev_err(&indio_dev->dev,
  448. "Cannot read scanned values (%d)\n", ret);
  449. iio_trigger_notify_done(indio_dev->trig);
  450. return IRQ_HANDLED;
  451. }
  452. static const struct iio_trigger_ops max1027_trigger_ops = {
  453. .validate_device = &iio_trigger_validate_own_device,
  454. .set_trigger_state = &max1027_set_cnvst_trigger_state,
  455. };
  456. static const struct iio_info max1027_info = {
  457. .read_raw = &max1027_read_raw,
  458. .debugfs_reg_access = &max1027_debugfs_reg_access,
  459. };
  460. static int max1027_probe(struct spi_device *spi)
  461. {
  462. int ret;
  463. struct iio_dev *indio_dev;
  464. struct max1027_state *st;
  465. indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
  466. if (!indio_dev) {
  467. pr_err("Can't allocate iio device\n");
  468. return -ENOMEM;
  469. }
  470. st = iio_priv(indio_dev);
  471. st->spi = spi;
  472. st->info = &max1027_chip_info_tbl[spi_get_device_id(spi)->driver_data];
  473. mutex_init(&st->lock);
  474. init_completion(&st->complete);
  475. indio_dev->name = spi_get_device_id(spi)->name;
  476. indio_dev->info = &max1027_info;
  477. indio_dev->modes = INDIO_DIRECT_MODE;
  478. indio_dev->channels = st->info->channels;
  479. indio_dev->num_channels = st->info->num_channels;
  480. indio_dev->available_scan_masks = st->info->available_scan_masks;
  481. st->buffer = devm_kmalloc_array(&indio_dev->dev,
  482. indio_dev->num_channels, 2,
  483. GFP_KERNEL);
  484. if (!st->buffer)
  485. return -ENOMEM;
  486. /* Enable triggered buffers */
  487. ret = devm_iio_triggered_buffer_setup(&spi->dev, indio_dev,
  488. &iio_pollfunc_store_time,
  489. &max1027_trigger_handler,
  490. NULL);
  491. if (ret < 0) {
  492. dev_err(&indio_dev->dev, "Failed to setup buffer\n");
  493. return ret;
  494. }
  495. /* If there is an EOC interrupt, register the cnvst hardware trigger */
  496. if (spi->irq) {
  497. st->trig = devm_iio_trigger_alloc(&spi->dev, "%s-trigger",
  498. indio_dev->name);
  499. if (!st->trig) {
  500. ret = -ENOMEM;
  501. dev_err(&indio_dev->dev,
  502. "Failed to allocate iio trigger\n");
  503. return ret;
  504. }
  505. st->trig->ops = &max1027_trigger_ops;
  506. iio_trigger_set_drvdata(st->trig, indio_dev);
  507. ret = devm_iio_trigger_register(&indio_dev->dev,
  508. st->trig);
  509. if (ret < 0) {
  510. dev_err(&indio_dev->dev,
  511. "Failed to register iio trigger\n");
  512. return ret;
  513. }
  514. ret = devm_request_irq(&spi->dev, spi->irq, max1027_handler,
  515. IRQF_TRIGGER_FALLING,
  516. spi->dev.driver->name, indio_dev);
  517. if (ret < 0) {
  518. dev_err(&indio_dev->dev, "Failed to allocate IRQ.\n");
  519. return ret;
  520. }
  521. }
  522. /* Internal reset */
  523. st->reg = MAX1027_RST_REG;
  524. ret = spi_write(st->spi, &st->reg, 1);
  525. if (ret < 0) {
  526. dev_err(&indio_dev->dev, "Failed to reset the ADC\n");
  527. return ret;
  528. }
  529. /* Disable averaging */
  530. st->reg = MAX1027_AVG_REG;
  531. ret = spi_write(st->spi, &st->reg, 1);
  532. if (ret < 0) {
  533. dev_err(&indio_dev->dev, "Failed to configure averaging register\n");
  534. return ret;
  535. }
  536. /* Assume conversion on register write for now */
  537. ret = max1027_enable_trigger(indio_dev, false);
  538. if (ret)
  539. return ret;
  540. return devm_iio_device_register(&spi->dev, indio_dev);
  541. }
  542. static struct spi_driver max1027_driver = {
  543. .driver = {
  544. .name = "max1027",
  545. .of_match_table = max1027_adc_dt_ids,
  546. },
  547. .probe = max1027_probe,
  548. .id_table = max1027_id,
  549. };
  550. module_spi_driver(max1027_driver);
  551. MODULE_AUTHOR("Philippe Reynes <[email protected]>");
  552. MODULE_DESCRIPTION("MAX1X27/MAX1X29/MAX1X31 ADC");
  553. MODULE_LICENSE("GPL v2");