ad5755.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  1. /*
  2. * AD5755, AD5755-1, AD5757, AD5735, AD5737 Digital to analog converters driver
  3. *
  4. * Copyright 2012 Analog Devices Inc.
  5. *
  6. * Licensed under the GPL-2.
  7. */
  8. #include <linux/device.h>
  9. #include <linux/err.h>
  10. #include <linux/module.h>
  11. #include <linux/kernel.h>
  12. #include <linux/spi/spi.h>
  13. #include <linux/slab.h>
  14. #include <linux/sysfs.h>
  15. #include <linux/delay.h>
  16. #include <linux/iio/iio.h>
  17. #include <linux/iio/sysfs.h>
  18. #include <linux/platform_data/ad5755.h>
  19. #define AD5755_NUM_CHANNELS 4
  20. #define AD5755_ADDR(x) ((x) << 16)
  21. #define AD5755_WRITE_REG_DATA(chan) (chan)
  22. #define AD5755_WRITE_REG_GAIN(chan) (0x08 | (chan))
  23. #define AD5755_WRITE_REG_OFFSET(chan) (0x10 | (chan))
  24. #define AD5755_WRITE_REG_CTRL(chan) (0x1c | (chan))
  25. #define AD5755_READ_REG_DATA(chan) (chan)
  26. #define AD5755_READ_REG_CTRL(chan) (0x4 | (chan))
  27. #define AD5755_READ_REG_GAIN(chan) (0x8 | (chan))
  28. #define AD5755_READ_REG_OFFSET(chan) (0xc | (chan))
  29. #define AD5755_READ_REG_CLEAR(chan) (0x10 | (chan))
  30. #define AD5755_READ_REG_SLEW(chan) (0x14 | (chan))
  31. #define AD5755_READ_REG_STATUS 0x18
  32. #define AD5755_READ_REG_MAIN 0x19
  33. #define AD5755_READ_REG_DC_DC 0x1a
  34. #define AD5755_CTRL_REG_SLEW 0x0
  35. #define AD5755_CTRL_REG_MAIN 0x1
  36. #define AD5755_CTRL_REG_DAC 0x2
  37. #define AD5755_CTRL_REG_DC_DC 0x3
  38. #define AD5755_CTRL_REG_SW 0x4
  39. #define AD5755_READ_FLAG 0x800000
  40. #define AD5755_NOOP 0x1CE000
  41. #define AD5755_DAC_INT_EN BIT(8)
  42. #define AD5755_DAC_CLR_EN BIT(7)
  43. #define AD5755_DAC_OUT_EN BIT(6)
  44. #define AD5755_DAC_INT_CURRENT_SENSE_RESISTOR BIT(5)
  45. #define AD5755_DAC_DC_DC_EN BIT(4)
  46. #define AD5755_DAC_VOLTAGE_OVERRANGE_EN BIT(3)
  47. #define AD5755_DC_DC_MAXV 0
  48. #define AD5755_DC_DC_FREQ_SHIFT 2
  49. #define AD5755_DC_DC_PHASE_SHIFT 4
  50. #define AD5755_EXT_DC_DC_COMP_RES BIT(6)
  51. #define AD5755_SLEW_STEP_SIZE_SHIFT 0
  52. #define AD5755_SLEW_RATE_SHIFT 3
  53. #define AD5755_SLEW_ENABLE BIT(12)
  54. /**
  55. * struct ad5755_chip_info - chip specific information
  56. * @channel_template: channel specification
  57. * @calib_shift: shift for the calibration data registers
  58. * @has_voltage_out: whether the chip has voltage outputs
  59. */
  60. struct ad5755_chip_info {
  61. const struct iio_chan_spec channel_template;
  62. unsigned int calib_shift;
  63. bool has_voltage_out;
  64. };
  65. /**
  66. * struct ad5755_state - driver instance specific data
  67. * @spi: spi device the driver is attached to
  68. * @chip_info: chip model specific constants, available modes etc
  69. * @pwr_down: bitmask which contains hether a channel is powered down or not
  70. * @ctrl: software shadow of the channel ctrl registers
  71. * @channels: iio channel spec for the device
  72. * @data: spi transfer buffers
  73. */
  74. struct ad5755_state {
  75. struct spi_device *spi;
  76. const struct ad5755_chip_info *chip_info;
  77. unsigned int pwr_down;
  78. unsigned int ctrl[AD5755_NUM_CHANNELS];
  79. struct iio_chan_spec channels[AD5755_NUM_CHANNELS];
  80. /*
  81. * DMA (thus cache coherency maintenance) requires the
  82. * transfer buffers to live in their own cache lines.
  83. */
  84. union {
  85. __be32 d32;
  86. u8 d8[4];
  87. } data[2] ____cacheline_aligned;
  88. };
  89. enum ad5755_type {
  90. ID_AD5755,
  91. ID_AD5757,
  92. ID_AD5735,
  93. ID_AD5737,
  94. };
  95. static int ad5755_write_unlocked(struct iio_dev *indio_dev,
  96. unsigned int reg, unsigned int val)
  97. {
  98. struct ad5755_state *st = iio_priv(indio_dev);
  99. st->data[0].d32 = cpu_to_be32((reg << 16) | val);
  100. return spi_write(st->spi, &st->data[0].d8[1], 3);
  101. }
  102. static int ad5755_write_ctrl_unlocked(struct iio_dev *indio_dev,
  103. unsigned int channel, unsigned int reg, unsigned int val)
  104. {
  105. return ad5755_write_unlocked(indio_dev,
  106. AD5755_WRITE_REG_CTRL(channel), (reg << 13) | val);
  107. }
  108. static int ad5755_write(struct iio_dev *indio_dev, unsigned int reg,
  109. unsigned int val)
  110. {
  111. int ret;
  112. mutex_lock(&indio_dev->mlock);
  113. ret = ad5755_write_unlocked(indio_dev, reg, val);
  114. mutex_unlock(&indio_dev->mlock);
  115. return ret;
  116. }
  117. static int ad5755_write_ctrl(struct iio_dev *indio_dev, unsigned int channel,
  118. unsigned int reg, unsigned int val)
  119. {
  120. int ret;
  121. mutex_lock(&indio_dev->mlock);
  122. ret = ad5755_write_ctrl_unlocked(indio_dev, channel, reg, val);
  123. mutex_unlock(&indio_dev->mlock);
  124. return ret;
  125. }
  126. static int ad5755_read(struct iio_dev *indio_dev, unsigned int addr)
  127. {
  128. struct ad5755_state *st = iio_priv(indio_dev);
  129. int ret;
  130. struct spi_transfer t[] = {
  131. {
  132. .tx_buf = &st->data[0].d8[1],
  133. .len = 3,
  134. .cs_change = 1,
  135. }, {
  136. .tx_buf = &st->data[1].d8[1],
  137. .rx_buf = &st->data[1].d8[1],
  138. .len = 3,
  139. },
  140. };
  141. mutex_lock(&indio_dev->mlock);
  142. st->data[0].d32 = cpu_to_be32(AD5755_READ_FLAG | (addr << 16));
  143. st->data[1].d32 = cpu_to_be32(AD5755_NOOP);
  144. ret = spi_sync_transfer(st->spi, t, ARRAY_SIZE(t));
  145. if (ret >= 0)
  146. ret = be32_to_cpu(st->data[1].d32) & 0xffff;
  147. mutex_unlock(&indio_dev->mlock);
  148. return ret;
  149. }
  150. static int ad5755_update_dac_ctrl(struct iio_dev *indio_dev,
  151. unsigned int channel, unsigned int set, unsigned int clr)
  152. {
  153. struct ad5755_state *st = iio_priv(indio_dev);
  154. int ret;
  155. st->ctrl[channel] |= set;
  156. st->ctrl[channel] &= ~clr;
  157. ret = ad5755_write_ctrl_unlocked(indio_dev, channel,
  158. AD5755_CTRL_REG_DAC, st->ctrl[channel]);
  159. return ret;
  160. }
  161. static int ad5755_set_channel_pwr_down(struct iio_dev *indio_dev,
  162. unsigned int channel, bool pwr_down)
  163. {
  164. struct ad5755_state *st = iio_priv(indio_dev);
  165. unsigned int mask = BIT(channel);
  166. mutex_lock(&indio_dev->mlock);
  167. if ((bool)(st->pwr_down & mask) == pwr_down)
  168. goto out_unlock;
  169. if (!pwr_down) {
  170. st->pwr_down &= ~mask;
  171. ad5755_update_dac_ctrl(indio_dev, channel,
  172. AD5755_DAC_INT_EN | AD5755_DAC_DC_DC_EN, 0);
  173. udelay(200);
  174. ad5755_update_dac_ctrl(indio_dev, channel,
  175. AD5755_DAC_OUT_EN, 0);
  176. } else {
  177. st->pwr_down |= mask;
  178. ad5755_update_dac_ctrl(indio_dev, channel,
  179. 0, AD5755_DAC_INT_EN | AD5755_DAC_OUT_EN |
  180. AD5755_DAC_DC_DC_EN);
  181. }
  182. out_unlock:
  183. mutex_unlock(&indio_dev->mlock);
  184. return 0;
  185. }
  186. static const int ad5755_min_max_table[][2] = {
  187. [AD5755_MODE_VOLTAGE_0V_5V] = { 0, 5000 },
  188. [AD5755_MODE_VOLTAGE_0V_10V] = { 0, 10000 },
  189. [AD5755_MODE_VOLTAGE_PLUSMINUS_5V] = { -5000, 5000 },
  190. [AD5755_MODE_VOLTAGE_PLUSMINUS_10V] = { -10000, 10000 },
  191. [AD5755_MODE_CURRENT_4mA_20mA] = { 4, 20 },
  192. [AD5755_MODE_CURRENT_0mA_20mA] = { 0, 20 },
  193. [AD5755_MODE_CURRENT_0mA_24mA] = { 0, 24 },
  194. };
  195. static void ad5755_get_min_max(struct ad5755_state *st,
  196. struct iio_chan_spec const *chan, int *min, int *max)
  197. {
  198. enum ad5755_mode mode = st->ctrl[chan->channel] & 7;
  199. *min = ad5755_min_max_table[mode][0];
  200. *max = ad5755_min_max_table[mode][1];
  201. }
  202. static inline int ad5755_get_offset(struct ad5755_state *st,
  203. struct iio_chan_spec const *chan)
  204. {
  205. int min, max;
  206. ad5755_get_min_max(st, chan, &min, &max);
  207. return (min * (1 << chan->scan_type.realbits)) / (max - min);
  208. }
  209. static int ad5755_chan_reg_info(struct ad5755_state *st,
  210. struct iio_chan_spec const *chan, long info, bool write,
  211. unsigned int *reg, unsigned int *shift, unsigned int *offset)
  212. {
  213. switch (info) {
  214. case IIO_CHAN_INFO_RAW:
  215. if (write)
  216. *reg = AD5755_WRITE_REG_DATA(chan->address);
  217. else
  218. *reg = AD5755_READ_REG_DATA(chan->address);
  219. *shift = chan->scan_type.shift;
  220. *offset = 0;
  221. break;
  222. case IIO_CHAN_INFO_CALIBBIAS:
  223. if (write)
  224. *reg = AD5755_WRITE_REG_OFFSET(chan->address);
  225. else
  226. *reg = AD5755_READ_REG_OFFSET(chan->address);
  227. *shift = st->chip_info->calib_shift;
  228. *offset = 32768;
  229. break;
  230. case IIO_CHAN_INFO_CALIBSCALE:
  231. if (write)
  232. *reg = AD5755_WRITE_REG_GAIN(chan->address);
  233. else
  234. *reg = AD5755_READ_REG_GAIN(chan->address);
  235. *shift = st->chip_info->calib_shift;
  236. *offset = 0;
  237. break;
  238. default:
  239. return -EINVAL;
  240. }
  241. return 0;
  242. }
  243. static int ad5755_read_raw(struct iio_dev *indio_dev,
  244. const struct iio_chan_spec *chan, int *val, int *val2, long info)
  245. {
  246. struct ad5755_state *st = iio_priv(indio_dev);
  247. unsigned int reg, shift, offset;
  248. int min, max;
  249. int ret;
  250. switch (info) {
  251. case IIO_CHAN_INFO_SCALE:
  252. ad5755_get_min_max(st, chan, &min, &max);
  253. *val = max - min;
  254. *val2 = chan->scan_type.realbits;
  255. return IIO_VAL_FRACTIONAL_LOG2;
  256. case IIO_CHAN_INFO_OFFSET:
  257. *val = ad5755_get_offset(st, chan);
  258. return IIO_VAL_INT;
  259. default:
  260. ret = ad5755_chan_reg_info(st, chan, info, false,
  261. &reg, &shift, &offset);
  262. if (ret)
  263. return ret;
  264. ret = ad5755_read(indio_dev, reg);
  265. if (ret < 0)
  266. return ret;
  267. *val = (ret - offset) >> shift;
  268. return IIO_VAL_INT;
  269. }
  270. return -EINVAL;
  271. }
  272. static int ad5755_write_raw(struct iio_dev *indio_dev,
  273. const struct iio_chan_spec *chan, int val, int val2, long info)
  274. {
  275. struct ad5755_state *st = iio_priv(indio_dev);
  276. unsigned int shift, reg, offset;
  277. int ret;
  278. ret = ad5755_chan_reg_info(st, chan, info, true,
  279. &reg, &shift, &offset);
  280. if (ret)
  281. return ret;
  282. val <<= shift;
  283. val += offset;
  284. if (val < 0 || val > 0xffff)
  285. return -EINVAL;
  286. return ad5755_write(indio_dev, reg, val);
  287. }
  288. static ssize_t ad5755_read_powerdown(struct iio_dev *indio_dev, uintptr_t priv,
  289. const struct iio_chan_spec *chan, char *buf)
  290. {
  291. struct ad5755_state *st = iio_priv(indio_dev);
  292. return sprintf(buf, "%d\n",
  293. (bool)(st->pwr_down & (1 << chan->channel)));
  294. }
  295. static ssize_t ad5755_write_powerdown(struct iio_dev *indio_dev, uintptr_t priv,
  296. struct iio_chan_spec const *chan, const char *buf, size_t len)
  297. {
  298. bool pwr_down;
  299. int ret;
  300. ret = strtobool(buf, &pwr_down);
  301. if (ret)
  302. return ret;
  303. ret = ad5755_set_channel_pwr_down(indio_dev, chan->channel, pwr_down);
  304. return ret ? ret : len;
  305. }
  306. static const struct iio_info ad5755_info = {
  307. .read_raw = ad5755_read_raw,
  308. .write_raw = ad5755_write_raw,
  309. .driver_module = THIS_MODULE,
  310. };
  311. static const struct iio_chan_spec_ext_info ad5755_ext_info[] = {
  312. {
  313. .name = "powerdown",
  314. .read = ad5755_read_powerdown,
  315. .write = ad5755_write_powerdown,
  316. .shared = IIO_SEPARATE,
  317. },
  318. { },
  319. };
  320. #define AD5755_CHANNEL(_bits) { \
  321. .indexed = 1, \
  322. .output = 1, \
  323. .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
  324. BIT(IIO_CHAN_INFO_SCALE) | \
  325. BIT(IIO_CHAN_INFO_OFFSET) | \
  326. BIT(IIO_CHAN_INFO_CALIBSCALE) | \
  327. BIT(IIO_CHAN_INFO_CALIBBIAS), \
  328. .scan_type = { \
  329. .sign = 'u', \
  330. .realbits = (_bits), \
  331. .storagebits = 16, \
  332. .shift = 16 - (_bits), \
  333. }, \
  334. .ext_info = ad5755_ext_info, \
  335. }
  336. static const struct ad5755_chip_info ad5755_chip_info_tbl[] = {
  337. [ID_AD5735] = {
  338. .channel_template = AD5755_CHANNEL(14),
  339. .has_voltage_out = true,
  340. .calib_shift = 4,
  341. },
  342. [ID_AD5737] = {
  343. .channel_template = AD5755_CHANNEL(14),
  344. .has_voltage_out = false,
  345. .calib_shift = 4,
  346. },
  347. [ID_AD5755] = {
  348. .channel_template = AD5755_CHANNEL(16),
  349. .has_voltage_out = true,
  350. .calib_shift = 0,
  351. },
  352. [ID_AD5757] = {
  353. .channel_template = AD5755_CHANNEL(16),
  354. .has_voltage_out = false,
  355. .calib_shift = 0,
  356. },
  357. };
  358. static bool ad5755_is_valid_mode(struct ad5755_state *st, enum ad5755_mode mode)
  359. {
  360. switch (mode) {
  361. case AD5755_MODE_VOLTAGE_0V_5V:
  362. case AD5755_MODE_VOLTAGE_0V_10V:
  363. case AD5755_MODE_VOLTAGE_PLUSMINUS_5V:
  364. case AD5755_MODE_VOLTAGE_PLUSMINUS_10V:
  365. return st->chip_info->has_voltage_out;
  366. case AD5755_MODE_CURRENT_4mA_20mA:
  367. case AD5755_MODE_CURRENT_0mA_20mA:
  368. case AD5755_MODE_CURRENT_0mA_24mA:
  369. return true;
  370. default:
  371. return false;
  372. }
  373. }
  374. static int ad5755_setup_pdata(struct iio_dev *indio_dev,
  375. const struct ad5755_platform_data *pdata)
  376. {
  377. struct ad5755_state *st = iio_priv(indio_dev);
  378. unsigned int val;
  379. unsigned int i;
  380. int ret;
  381. if (pdata->dc_dc_phase > AD5755_DC_DC_PHASE_90_DEGREE ||
  382. pdata->dc_dc_freq > AD5755_DC_DC_FREQ_650kHZ ||
  383. pdata->dc_dc_maxv > AD5755_DC_DC_MAXV_29V5)
  384. return -EINVAL;
  385. val = pdata->dc_dc_maxv << AD5755_DC_DC_MAXV;
  386. val |= pdata->dc_dc_freq << AD5755_DC_DC_FREQ_SHIFT;
  387. val |= pdata->dc_dc_phase << AD5755_DC_DC_PHASE_SHIFT;
  388. if (pdata->ext_dc_dc_compenstation_resistor)
  389. val |= AD5755_EXT_DC_DC_COMP_RES;
  390. ret = ad5755_write_ctrl(indio_dev, 0, AD5755_CTRL_REG_DC_DC, val);
  391. if (ret < 0)
  392. return ret;
  393. for (i = 0; i < ARRAY_SIZE(pdata->dac); ++i) {
  394. val = pdata->dac[i].slew.step_size <<
  395. AD5755_SLEW_STEP_SIZE_SHIFT;
  396. val |= pdata->dac[i].slew.rate <<
  397. AD5755_SLEW_RATE_SHIFT;
  398. if (pdata->dac[i].slew.enable)
  399. val |= AD5755_SLEW_ENABLE;
  400. ret = ad5755_write_ctrl(indio_dev, i,
  401. AD5755_CTRL_REG_SLEW, val);
  402. if (ret < 0)
  403. return ret;
  404. }
  405. for (i = 0; i < ARRAY_SIZE(pdata->dac); ++i) {
  406. if (!ad5755_is_valid_mode(st, pdata->dac[i].mode))
  407. return -EINVAL;
  408. val = 0;
  409. if (!pdata->dac[i].ext_current_sense_resistor)
  410. val |= AD5755_DAC_INT_CURRENT_SENSE_RESISTOR;
  411. if (pdata->dac[i].enable_voltage_overrange)
  412. val |= AD5755_DAC_VOLTAGE_OVERRANGE_EN;
  413. val |= pdata->dac[i].mode;
  414. ret = ad5755_update_dac_ctrl(indio_dev, i, val, 0);
  415. if (ret < 0)
  416. return ret;
  417. }
  418. return 0;
  419. }
  420. static bool ad5755_is_voltage_mode(enum ad5755_mode mode)
  421. {
  422. switch (mode) {
  423. case AD5755_MODE_VOLTAGE_0V_5V:
  424. case AD5755_MODE_VOLTAGE_0V_10V:
  425. case AD5755_MODE_VOLTAGE_PLUSMINUS_5V:
  426. case AD5755_MODE_VOLTAGE_PLUSMINUS_10V:
  427. return true;
  428. default:
  429. return false;
  430. }
  431. }
  432. static int ad5755_init_channels(struct iio_dev *indio_dev,
  433. const struct ad5755_platform_data *pdata)
  434. {
  435. struct ad5755_state *st = iio_priv(indio_dev);
  436. struct iio_chan_spec *channels = st->channels;
  437. unsigned int i;
  438. for (i = 0; i < AD5755_NUM_CHANNELS; ++i) {
  439. channels[i] = st->chip_info->channel_template;
  440. channels[i].channel = i;
  441. channels[i].address = i;
  442. if (pdata && ad5755_is_voltage_mode(pdata->dac[i].mode))
  443. channels[i].type = IIO_VOLTAGE;
  444. else
  445. channels[i].type = IIO_CURRENT;
  446. }
  447. indio_dev->channels = channels;
  448. return 0;
  449. }
  450. #define AD5755_DEFAULT_DAC_PDATA { \
  451. .mode = AD5755_MODE_CURRENT_4mA_20mA, \
  452. .ext_current_sense_resistor = true, \
  453. .enable_voltage_overrange = false, \
  454. .slew = { \
  455. .enable = false, \
  456. .rate = AD5755_SLEW_RATE_64k, \
  457. .step_size = AD5755_SLEW_STEP_SIZE_1, \
  458. }, \
  459. }
  460. static const struct ad5755_platform_data ad5755_default_pdata = {
  461. .ext_dc_dc_compenstation_resistor = false,
  462. .dc_dc_phase = AD5755_DC_DC_PHASE_ALL_SAME_EDGE,
  463. .dc_dc_freq = AD5755_DC_DC_FREQ_410kHZ,
  464. .dc_dc_maxv = AD5755_DC_DC_MAXV_23V,
  465. .dac = {
  466. [0] = AD5755_DEFAULT_DAC_PDATA,
  467. [1] = AD5755_DEFAULT_DAC_PDATA,
  468. [2] = AD5755_DEFAULT_DAC_PDATA,
  469. [3] = AD5755_DEFAULT_DAC_PDATA,
  470. },
  471. };
  472. static int ad5755_probe(struct spi_device *spi)
  473. {
  474. enum ad5755_type type = spi_get_device_id(spi)->driver_data;
  475. const struct ad5755_platform_data *pdata = dev_get_platdata(&spi->dev);
  476. struct iio_dev *indio_dev;
  477. struct ad5755_state *st;
  478. int ret;
  479. indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
  480. if (indio_dev == NULL) {
  481. dev_err(&spi->dev, "Failed to allocate iio device\n");
  482. return -ENOMEM;
  483. }
  484. st = iio_priv(indio_dev);
  485. spi_set_drvdata(spi, indio_dev);
  486. st->chip_info = &ad5755_chip_info_tbl[type];
  487. st->spi = spi;
  488. st->pwr_down = 0xf;
  489. indio_dev->dev.parent = &spi->dev;
  490. indio_dev->name = spi_get_device_id(spi)->name;
  491. indio_dev->info = &ad5755_info;
  492. indio_dev->modes = INDIO_DIRECT_MODE;
  493. indio_dev->num_channels = AD5755_NUM_CHANNELS;
  494. if (!pdata)
  495. pdata = &ad5755_default_pdata;
  496. ret = ad5755_init_channels(indio_dev, pdata);
  497. if (ret)
  498. return ret;
  499. ret = ad5755_setup_pdata(indio_dev, pdata);
  500. if (ret)
  501. return ret;
  502. return devm_iio_device_register(&spi->dev, indio_dev);
  503. }
  504. static const struct spi_device_id ad5755_id[] = {
  505. { "ad5755", ID_AD5755 },
  506. { "ad5755-1", ID_AD5755 },
  507. { "ad5757", ID_AD5757 },
  508. { "ad5735", ID_AD5735 },
  509. { "ad5737", ID_AD5737 },
  510. {}
  511. };
  512. MODULE_DEVICE_TABLE(spi, ad5755_id);
  513. static struct spi_driver ad5755_driver = {
  514. .driver = {
  515. .name = "ad5755",
  516. .owner = THIS_MODULE,
  517. },
  518. .probe = ad5755_probe,
  519. .id_table = ad5755_id,
  520. };
  521. module_spi_driver(ad5755_driver);
  522. MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
  523. MODULE_DESCRIPTION("Analog Devices AD5755/55-1/57/35/37 DAC");
  524. MODULE_LICENSE("GPL v2");