imx7d_adc.c 15 KB

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