imx7d_adc.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Freescale i.MX7D ADC driver
  4. *
  5. * Copyright (C) 2015 Freescale Semiconductor, Inc.
  6. */
  7. #include <linux/clk.h>
  8. #include <linux/completion.h>
  9. #include <linux/err.h>
  10. #include <linux/interrupt.h>
  11. #include <linux/io.h>
  12. #include <linux/kernel.h>
  13. #include <linux/mod_devicetable.h>
  14. #include <linux/module.h>
  15. #include <linux/mutex.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/regulator/consumer.h>
  18. #include <linux/iio/iio.h>
  19. #include <linux/iio/driver.h>
  20. #include <linux/iio/sysfs.h>
  21. /* ADC register */
  22. #define IMX7D_REG_ADC_CH_A_CFG1 0x00
  23. #define IMX7D_REG_ADC_CH_A_CFG2 0x10
  24. #define IMX7D_REG_ADC_CH_B_CFG1 0x20
  25. #define IMX7D_REG_ADC_CH_B_CFG2 0x30
  26. #define IMX7D_REG_ADC_CH_C_CFG1 0x40
  27. #define IMX7D_REG_ADC_CH_C_CFG2 0x50
  28. #define IMX7D_REG_ADC_CH_D_CFG1 0x60
  29. #define IMX7D_REG_ADC_CH_D_CFG2 0x70
  30. #define IMX7D_REG_ADC_CH_SW_CFG 0x80
  31. #define IMX7D_REG_ADC_TIMER_UNIT 0x90
  32. #define IMX7D_REG_ADC_DMA_FIFO 0xa0
  33. #define IMX7D_REG_ADC_FIFO_STATUS 0xb0
  34. #define IMX7D_REG_ADC_INT_SIG_EN 0xc0
  35. #define IMX7D_REG_ADC_INT_EN 0xd0
  36. #define IMX7D_REG_ADC_INT_STATUS 0xe0
  37. #define IMX7D_REG_ADC_CHA_B_CNV_RSLT 0xf0
  38. #define IMX7D_REG_ADC_CHC_D_CNV_RSLT 0x100
  39. #define IMX7D_REG_ADC_CH_SW_CNV_RSLT 0x110
  40. #define IMX7D_REG_ADC_DMA_FIFO_DAT 0x120
  41. #define IMX7D_REG_ADC_ADC_CFG 0x130
  42. #define IMX7D_REG_ADC_CHANNEL_CFG2_BASE 0x10
  43. #define IMX7D_EACH_CHANNEL_REG_OFFSET 0x20
  44. #define IMX7D_REG_ADC_CH_CFG1_CHANNEL_EN (0x1 << 31)
  45. #define IMX7D_REG_ADC_CH_CFG1_CHANNEL_SINGLE BIT(30)
  46. #define IMX7D_REG_ADC_CH_CFG1_CHANNEL_AVG_EN BIT(29)
  47. #define IMX7D_REG_ADC_CH_CFG1_CHANNEL_SEL(x) ((x) << 24)
  48. #define IMX7D_REG_ADC_CH_CFG2_AVG_NUM_4 (0x0 << 12)
  49. #define IMX7D_REG_ADC_CH_CFG2_AVG_NUM_8 (0x1 << 12)
  50. #define IMX7D_REG_ADC_CH_CFG2_AVG_NUM_16 (0x2 << 12)
  51. #define IMX7D_REG_ADC_CH_CFG2_AVG_NUM_32 (0x3 << 12)
  52. #define IMX7D_REG_ADC_TIMER_UNIT_PRE_DIV_4 (0x0 << 29)
  53. #define IMX7D_REG_ADC_TIMER_UNIT_PRE_DIV_8 (0x1 << 29)
  54. #define IMX7D_REG_ADC_TIMER_UNIT_PRE_DIV_16 (0x2 << 29)
  55. #define IMX7D_REG_ADC_TIMER_UNIT_PRE_DIV_32 (0x3 << 29)
  56. #define IMX7D_REG_ADC_TIMER_UNIT_PRE_DIV_64 (0x4 << 29)
  57. #define IMX7D_REG_ADC_TIMER_UNIT_PRE_DIV_128 (0x5 << 29)
  58. #define IMX7D_REG_ADC_ADC_CFG_ADC_CLK_DOWN BIT(31)
  59. #define IMX7D_REG_ADC_ADC_CFG_ADC_POWER_DOWN BIT(1)
  60. #define IMX7D_REG_ADC_ADC_CFG_ADC_EN BIT(0)
  61. #define IMX7D_REG_ADC_INT_CHA_COV_INT_EN BIT(8)
  62. #define IMX7D_REG_ADC_INT_CHB_COV_INT_EN BIT(9)
  63. #define IMX7D_REG_ADC_INT_CHC_COV_INT_EN BIT(10)
  64. #define IMX7D_REG_ADC_INT_CHD_COV_INT_EN BIT(11)
  65. #define IMX7D_REG_ADC_INT_CHANNEL_INT_EN \
  66. (IMX7D_REG_ADC_INT_CHA_COV_INT_EN | \
  67. IMX7D_REG_ADC_INT_CHB_COV_INT_EN | \
  68. IMX7D_REG_ADC_INT_CHC_COV_INT_EN | \
  69. IMX7D_REG_ADC_INT_CHD_COV_INT_EN)
  70. #define IMX7D_REG_ADC_INT_STATUS_CHANNEL_INT_STATUS 0xf00
  71. #define IMX7D_REG_ADC_INT_STATUS_CHANNEL_CONV_TIME_OUT 0xf0000
  72. #define IMX7D_ADC_TIMEOUT msecs_to_jiffies(100)
  73. #define IMX7D_ADC_INPUT_CLK 24000000
  74. enum imx7d_adc_clk_pre_div {
  75. IMX7D_ADC_ANALOG_CLK_PRE_DIV_4,
  76. IMX7D_ADC_ANALOG_CLK_PRE_DIV_8,
  77. IMX7D_ADC_ANALOG_CLK_PRE_DIV_16,
  78. IMX7D_ADC_ANALOG_CLK_PRE_DIV_32,
  79. IMX7D_ADC_ANALOG_CLK_PRE_DIV_64,
  80. IMX7D_ADC_ANALOG_CLK_PRE_DIV_128,
  81. };
  82. enum imx7d_adc_average_num {
  83. IMX7D_ADC_AVERAGE_NUM_4,
  84. IMX7D_ADC_AVERAGE_NUM_8,
  85. IMX7D_ADC_AVERAGE_NUM_16,
  86. IMX7D_ADC_AVERAGE_NUM_32,
  87. };
  88. struct imx7d_adc_feature {
  89. enum imx7d_adc_clk_pre_div clk_pre_div;
  90. enum imx7d_adc_average_num avg_num;
  91. u32 core_time_unit; /* impact the sample rate */
  92. };
  93. struct imx7d_adc {
  94. struct device *dev;
  95. void __iomem *regs;
  96. struct clk *clk;
  97. /* lock to protect against multiple access to the device */
  98. struct mutex lock;
  99. u32 vref_uv;
  100. u32 value;
  101. u32 channel;
  102. u32 pre_div_num;
  103. struct regulator *vref;
  104. struct imx7d_adc_feature adc_feature;
  105. struct completion completion;
  106. };
  107. struct imx7d_adc_analogue_core_clk {
  108. u32 pre_div;
  109. u32 reg_config;
  110. };
  111. #define IMX7D_ADC_ANALOGUE_CLK_CONFIG(_pre_div, _reg_conf) { \
  112. .pre_div = (_pre_div), \
  113. .reg_config = (_reg_conf), \
  114. }
  115. static const struct imx7d_adc_analogue_core_clk imx7d_adc_analogue_clk[] = {
  116. IMX7D_ADC_ANALOGUE_CLK_CONFIG(4, IMX7D_REG_ADC_TIMER_UNIT_PRE_DIV_4),
  117. IMX7D_ADC_ANALOGUE_CLK_CONFIG(8, IMX7D_REG_ADC_TIMER_UNIT_PRE_DIV_8),
  118. IMX7D_ADC_ANALOGUE_CLK_CONFIG(16, IMX7D_REG_ADC_TIMER_UNIT_PRE_DIV_16),
  119. IMX7D_ADC_ANALOGUE_CLK_CONFIG(32, IMX7D_REG_ADC_TIMER_UNIT_PRE_DIV_32),
  120. IMX7D_ADC_ANALOGUE_CLK_CONFIG(64, IMX7D_REG_ADC_TIMER_UNIT_PRE_DIV_64),
  121. IMX7D_ADC_ANALOGUE_CLK_CONFIG(128, IMX7D_REG_ADC_TIMER_UNIT_PRE_DIV_128),
  122. };
  123. #define IMX7D_ADC_CHAN(_idx) { \
  124. .type = IIO_VOLTAGE, \
  125. .indexed = 1, \
  126. .channel = (_idx), \
  127. .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
  128. .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \
  129. BIT(IIO_CHAN_INFO_SAMP_FREQ), \
  130. }
  131. static const struct iio_chan_spec imx7d_adc_iio_channels[] = {
  132. IMX7D_ADC_CHAN(0),
  133. IMX7D_ADC_CHAN(1),
  134. IMX7D_ADC_CHAN(2),
  135. IMX7D_ADC_CHAN(3),
  136. IMX7D_ADC_CHAN(4),
  137. IMX7D_ADC_CHAN(5),
  138. IMX7D_ADC_CHAN(6),
  139. IMX7D_ADC_CHAN(7),
  140. IMX7D_ADC_CHAN(8),
  141. IMX7D_ADC_CHAN(9),
  142. IMX7D_ADC_CHAN(10),
  143. IMX7D_ADC_CHAN(11),
  144. IMX7D_ADC_CHAN(12),
  145. IMX7D_ADC_CHAN(13),
  146. IMX7D_ADC_CHAN(14),
  147. IMX7D_ADC_CHAN(15),
  148. };
  149. static const u32 imx7d_adc_average_num[] = {
  150. IMX7D_REG_ADC_CH_CFG2_AVG_NUM_4,
  151. IMX7D_REG_ADC_CH_CFG2_AVG_NUM_8,
  152. IMX7D_REG_ADC_CH_CFG2_AVG_NUM_16,
  153. IMX7D_REG_ADC_CH_CFG2_AVG_NUM_32,
  154. };
  155. static void imx7d_adc_feature_config(struct imx7d_adc *info)
  156. {
  157. info->adc_feature.clk_pre_div = IMX7D_ADC_ANALOG_CLK_PRE_DIV_4;
  158. info->adc_feature.avg_num = IMX7D_ADC_AVERAGE_NUM_32;
  159. info->adc_feature.core_time_unit = 1;
  160. }
  161. static void imx7d_adc_sample_rate_set(struct imx7d_adc *info)
  162. {
  163. struct imx7d_adc_feature *adc_feature = &info->adc_feature;
  164. struct imx7d_adc_analogue_core_clk adc_analogure_clk;
  165. u32 i;
  166. u32 tmp_cfg1;
  167. u32 sample_rate = 0;
  168. /*
  169. * Before sample set, disable channel A,B,C,D. Here we
  170. * clear the bit 31 of register REG_ADC_CH_A\B\C\D_CFG1.
  171. */
  172. for (i = 0; i < 4; i++) {
  173. tmp_cfg1 =
  174. readl(info->regs + i * IMX7D_EACH_CHANNEL_REG_OFFSET);
  175. tmp_cfg1 &= ~IMX7D_REG_ADC_CH_CFG1_CHANNEL_EN;
  176. writel(tmp_cfg1,
  177. info->regs + i * IMX7D_EACH_CHANNEL_REG_OFFSET);
  178. }
  179. adc_analogure_clk = imx7d_adc_analogue_clk[adc_feature->clk_pre_div];
  180. sample_rate |= adc_analogure_clk.reg_config;
  181. info->pre_div_num = adc_analogure_clk.pre_div;
  182. sample_rate |= adc_feature->core_time_unit;
  183. writel(sample_rate, info->regs + IMX7D_REG_ADC_TIMER_UNIT);
  184. }
  185. static void imx7d_adc_hw_init(struct imx7d_adc *info)
  186. {
  187. u32 cfg;
  188. /* power up and enable adc analogue core */
  189. cfg = readl(info->regs + IMX7D_REG_ADC_ADC_CFG);
  190. cfg &= ~(IMX7D_REG_ADC_ADC_CFG_ADC_CLK_DOWN |
  191. IMX7D_REG_ADC_ADC_CFG_ADC_POWER_DOWN);
  192. cfg |= IMX7D_REG_ADC_ADC_CFG_ADC_EN;
  193. writel(cfg, info->regs + IMX7D_REG_ADC_ADC_CFG);
  194. /* enable channel A,B,C,D interrupt */
  195. writel(IMX7D_REG_ADC_INT_CHANNEL_INT_EN,
  196. info->regs + IMX7D_REG_ADC_INT_SIG_EN);
  197. writel(IMX7D_REG_ADC_INT_CHANNEL_INT_EN,
  198. info->regs + IMX7D_REG_ADC_INT_EN);
  199. imx7d_adc_sample_rate_set(info);
  200. }
  201. static void imx7d_adc_channel_set(struct imx7d_adc *info)
  202. {
  203. u32 cfg1 = 0;
  204. u32 cfg2;
  205. u32 channel;
  206. channel = info->channel;
  207. /* the channel choose single conversion, and enable average mode */
  208. cfg1 |= (IMX7D_REG_ADC_CH_CFG1_CHANNEL_EN |
  209. IMX7D_REG_ADC_CH_CFG1_CHANNEL_SINGLE |
  210. IMX7D_REG_ADC_CH_CFG1_CHANNEL_AVG_EN);
  211. /*
  212. * physical channel 0 chose logical channel A
  213. * physical channel 1 chose logical channel B
  214. * physical channel 2 chose logical channel C
  215. * physical channel 3 chose logical channel D
  216. */
  217. cfg1 |= IMX7D_REG_ADC_CH_CFG1_CHANNEL_SEL(channel);
  218. /*
  219. * read register REG_ADC_CH_A\B\C\D_CFG2, according to the
  220. * channel chosen
  221. */
  222. cfg2 = readl(info->regs + IMX7D_EACH_CHANNEL_REG_OFFSET * channel +
  223. IMX7D_REG_ADC_CHANNEL_CFG2_BASE);
  224. cfg2 |= imx7d_adc_average_num[info->adc_feature.avg_num];
  225. /*
  226. * write the register REG_ADC_CH_A\B\C\D_CFG2, according to
  227. * the channel chosen
  228. */
  229. writel(cfg2, info->regs + IMX7D_EACH_CHANNEL_REG_OFFSET * channel +
  230. IMX7D_REG_ADC_CHANNEL_CFG2_BASE);
  231. writel(cfg1, info->regs + IMX7D_EACH_CHANNEL_REG_OFFSET * channel);
  232. }
  233. static u32 imx7d_adc_get_sample_rate(struct imx7d_adc *info)
  234. {
  235. u32 analogue_core_clk;
  236. u32 core_time_unit = info->adc_feature.core_time_unit;
  237. u32 tmp;
  238. analogue_core_clk = IMX7D_ADC_INPUT_CLK / info->pre_div_num;
  239. tmp = (core_time_unit + 1) * 6;
  240. return analogue_core_clk / tmp;
  241. }
  242. static int imx7d_adc_read_raw(struct iio_dev *indio_dev,
  243. struct iio_chan_spec const *chan,
  244. int *val,
  245. int *val2,
  246. long mask)
  247. {
  248. struct imx7d_adc *info = iio_priv(indio_dev);
  249. u32 channel;
  250. long ret;
  251. switch (mask) {
  252. case IIO_CHAN_INFO_RAW:
  253. mutex_lock(&info->lock);
  254. reinit_completion(&info->completion);
  255. channel = chan->channel & 0x03;
  256. info->channel = channel;
  257. imx7d_adc_channel_set(info);
  258. ret = wait_for_completion_interruptible_timeout
  259. (&info->completion, IMX7D_ADC_TIMEOUT);
  260. if (ret == 0) {
  261. mutex_unlock(&info->lock);
  262. return -ETIMEDOUT;
  263. }
  264. if (ret < 0) {
  265. mutex_unlock(&info->lock);
  266. return ret;
  267. }
  268. *val = info->value;
  269. mutex_unlock(&info->lock);
  270. return IIO_VAL_INT;
  271. case IIO_CHAN_INFO_SCALE:
  272. info->vref_uv = regulator_get_voltage(info->vref);
  273. *val = info->vref_uv / 1000;
  274. *val2 = 12;
  275. return IIO_VAL_FRACTIONAL_LOG2;
  276. case IIO_CHAN_INFO_SAMP_FREQ:
  277. *val = imx7d_adc_get_sample_rate(info);
  278. return IIO_VAL_INT;
  279. default:
  280. return -EINVAL;
  281. }
  282. }
  283. static int imx7d_adc_read_data(struct imx7d_adc *info)
  284. {
  285. u32 channel;
  286. u32 value;
  287. channel = info->channel & 0x03;
  288. /*
  289. * channel A and B conversion result share one register,
  290. * bit[27~16] is the channel B conversion result,
  291. * bit[11~0] is the channel A conversion result.
  292. * channel C and D is the same.
  293. */
  294. if (channel < 2)
  295. value = readl(info->regs + IMX7D_REG_ADC_CHA_B_CNV_RSLT);
  296. else
  297. value = readl(info->regs + IMX7D_REG_ADC_CHC_D_CNV_RSLT);
  298. if (channel & 0x1) /* channel B or D */
  299. value = (value >> 16) & 0xFFF;
  300. else /* channel A or C */
  301. value &= 0xFFF;
  302. return value;
  303. }
  304. static irqreturn_t imx7d_adc_isr(int irq, void *dev_id)
  305. {
  306. struct imx7d_adc *info = dev_id;
  307. int status;
  308. status = readl(info->regs + IMX7D_REG_ADC_INT_STATUS);
  309. if (status & IMX7D_REG_ADC_INT_STATUS_CHANNEL_INT_STATUS) {
  310. info->value = imx7d_adc_read_data(info);
  311. complete(&info->completion);
  312. /*
  313. * The register IMX7D_REG_ADC_INT_STATUS can't clear
  314. * itself after read operation, need software to write
  315. * 0 to the related bit. Here we clear the channel A/B/C/D
  316. * conversion finished flag.
  317. */
  318. status &= ~IMX7D_REG_ADC_INT_STATUS_CHANNEL_INT_STATUS;
  319. writel(status, info->regs + IMX7D_REG_ADC_INT_STATUS);
  320. }
  321. /*
  322. * If the channel A/B/C/D conversion timeout, report it and clear these
  323. * timeout flags.
  324. */
  325. if (status & IMX7D_REG_ADC_INT_STATUS_CHANNEL_CONV_TIME_OUT) {
  326. dev_err(info->dev,
  327. "ADC got conversion time out interrupt: 0x%08x\n",
  328. status);
  329. status &= ~IMX7D_REG_ADC_INT_STATUS_CHANNEL_CONV_TIME_OUT;
  330. writel(status, info->regs + IMX7D_REG_ADC_INT_STATUS);
  331. }
  332. return IRQ_HANDLED;
  333. }
  334. static int imx7d_adc_reg_access(struct iio_dev *indio_dev,
  335. unsigned reg, unsigned writeval,
  336. unsigned *readval)
  337. {
  338. struct imx7d_adc *info = iio_priv(indio_dev);
  339. if (!readval || reg % 4 || reg > IMX7D_REG_ADC_ADC_CFG)
  340. return -EINVAL;
  341. *readval = readl(info->regs + reg);
  342. return 0;
  343. }
  344. static const struct iio_info imx7d_adc_iio_info = {
  345. .read_raw = &imx7d_adc_read_raw,
  346. .debugfs_reg_access = &imx7d_adc_reg_access,
  347. };
  348. static const struct of_device_id imx7d_adc_match[] = {
  349. { .compatible = "fsl,imx7d-adc", },
  350. { /* sentinel */ }
  351. };
  352. MODULE_DEVICE_TABLE(of, imx7d_adc_match);
  353. static void imx7d_adc_power_down(struct imx7d_adc *info)
  354. {
  355. u32 adc_cfg;
  356. adc_cfg = readl(info->regs + IMX7D_REG_ADC_ADC_CFG);
  357. adc_cfg |= IMX7D_REG_ADC_ADC_CFG_ADC_CLK_DOWN |
  358. IMX7D_REG_ADC_ADC_CFG_ADC_POWER_DOWN;
  359. adc_cfg &= ~IMX7D_REG_ADC_ADC_CFG_ADC_EN;
  360. writel(adc_cfg, info->regs + IMX7D_REG_ADC_ADC_CFG);
  361. }
  362. static int imx7d_adc_enable(struct device *dev)
  363. {
  364. struct iio_dev *indio_dev = dev_get_drvdata(dev);
  365. struct imx7d_adc *info = iio_priv(indio_dev);
  366. int ret;
  367. ret = regulator_enable(info->vref);
  368. if (ret) {
  369. dev_err(info->dev,
  370. "Can't enable adc reference top voltage, err = %d\n",
  371. ret);
  372. return ret;
  373. }
  374. ret = clk_prepare_enable(info->clk);
  375. if (ret) {
  376. dev_err(info->dev,
  377. "Could not prepare or enable clock.\n");
  378. regulator_disable(info->vref);
  379. return ret;
  380. }
  381. imx7d_adc_hw_init(info);
  382. return 0;
  383. }
  384. static int imx7d_adc_disable(struct device *dev)
  385. {
  386. struct iio_dev *indio_dev = dev_get_drvdata(dev);
  387. struct imx7d_adc *info = iio_priv(indio_dev);
  388. imx7d_adc_power_down(info);
  389. clk_disable_unprepare(info->clk);
  390. regulator_disable(info->vref);
  391. return 0;
  392. }
  393. static void __imx7d_adc_disable(void *data)
  394. {
  395. imx7d_adc_disable(data);
  396. }
  397. static int imx7d_adc_probe(struct platform_device *pdev)
  398. {
  399. struct imx7d_adc *info;
  400. struct iio_dev *indio_dev;
  401. struct device *dev = &pdev->dev;
  402. int irq;
  403. int ret;
  404. indio_dev = devm_iio_device_alloc(dev, sizeof(*info));
  405. if (!indio_dev) {
  406. dev_err(&pdev->dev, "Failed allocating iio device\n");
  407. return -ENOMEM;
  408. }
  409. info = iio_priv(indio_dev);
  410. info->dev = dev;
  411. info->regs = devm_platform_ioremap_resource(pdev, 0);
  412. if (IS_ERR(info->regs))
  413. return PTR_ERR(info->regs);
  414. irq = platform_get_irq(pdev, 0);
  415. if (irq < 0)
  416. return irq;
  417. info->clk = devm_clk_get(dev, "adc");
  418. if (IS_ERR(info->clk))
  419. return dev_err_probe(dev, PTR_ERR(info->clk), "Failed getting clock\n");
  420. info->vref = devm_regulator_get(dev, "vref");
  421. if (IS_ERR(info->vref))
  422. return dev_err_probe(dev, PTR_ERR(info->vref),
  423. "Failed getting reference voltage\n");
  424. platform_set_drvdata(pdev, indio_dev);
  425. init_completion(&info->completion);
  426. indio_dev->name = dev_name(dev);
  427. indio_dev->info = &imx7d_adc_iio_info;
  428. indio_dev->modes = INDIO_DIRECT_MODE;
  429. indio_dev->channels = imx7d_adc_iio_channels;
  430. indio_dev->num_channels = ARRAY_SIZE(imx7d_adc_iio_channels);
  431. ret = devm_request_irq(dev, irq, imx7d_adc_isr, 0, dev_name(dev), info);
  432. if (ret < 0) {
  433. dev_err(dev, "Failed requesting irq, irq = %d\n", irq);
  434. return ret;
  435. }
  436. imx7d_adc_feature_config(info);
  437. ret = imx7d_adc_enable(dev);
  438. if (ret)
  439. return ret;
  440. ret = devm_add_action_or_reset(dev, __imx7d_adc_disable, dev);
  441. if (ret)
  442. return ret;
  443. mutex_init(&info->lock);
  444. ret = devm_iio_device_register(dev, indio_dev);
  445. if (ret) {
  446. dev_err(&pdev->dev, "Couldn't register the device.\n");
  447. return ret;
  448. }
  449. return 0;
  450. }
  451. static DEFINE_SIMPLE_DEV_PM_OPS(imx7d_adc_pm_ops, imx7d_adc_disable,
  452. imx7d_adc_enable);
  453. static struct platform_driver imx7d_adc_driver = {
  454. .probe = imx7d_adc_probe,
  455. .driver = {
  456. .name = "imx7d_adc",
  457. .of_match_table = imx7d_adc_match,
  458. .pm = pm_sleep_ptr(&imx7d_adc_pm_ops),
  459. },
  460. };
  461. module_platform_driver(imx7d_adc_driver);
  462. MODULE_AUTHOR("Haibo Chen <haibo.chen@freescale.com>");
  463. MODULE_DESCRIPTION("Freescale IMX7D ADC driver");
  464. MODULE_LICENSE("GPL v2");