stm32-dfsdm-adc.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * This file is the ADC part of the STM32 DFSDM driver
  4. *
  5. * Copyright (C) 2017, STMicroelectronics - All Rights Reserved
  6. * Author: Arnaud Pouliquen <arnaud.pouliquen@st.com>.
  7. */
  8. #include <linux/dmaengine.h>
  9. #include <linux/dma-mapping.h>
  10. #include <linux/interrupt.h>
  11. #include <linux/iio/buffer.h>
  12. #include <linux/iio/hw-consumer.h>
  13. #include <linux/iio/iio.h>
  14. #include <linux/iio/sysfs.h>
  15. #include <linux/module.h>
  16. #include <linux/of_device.h>
  17. #include <linux/platform_device.h>
  18. #include <linux/regmap.h>
  19. #include <linux/slab.h>
  20. #include "stm32-dfsdm.h"
  21. #define DFSDM_DMA_BUFFER_SIZE (4 * PAGE_SIZE)
  22. /* Conversion timeout */
  23. #define DFSDM_TIMEOUT_US 100000
  24. #define DFSDM_TIMEOUT (msecs_to_jiffies(DFSDM_TIMEOUT_US / 1000))
  25. /* Oversampling attribute default */
  26. #define DFSDM_DEFAULT_OVERSAMPLING 100
  27. /* Oversampling max values */
  28. #define DFSDM_MAX_INT_OVERSAMPLING 256
  29. #define DFSDM_MAX_FL_OVERSAMPLING 1024
  30. /* Max sample resolutions */
  31. #define DFSDM_MAX_RES BIT(31)
  32. #define DFSDM_DATA_RES BIT(23)
  33. enum sd_converter_type {
  34. DFSDM_AUDIO,
  35. DFSDM_IIO,
  36. };
  37. struct stm32_dfsdm_dev_data {
  38. int type;
  39. int (*init)(struct iio_dev *indio_dev);
  40. unsigned int num_channels;
  41. const struct regmap_config *regmap_cfg;
  42. };
  43. struct stm32_dfsdm_adc {
  44. struct stm32_dfsdm *dfsdm;
  45. const struct stm32_dfsdm_dev_data *dev_data;
  46. unsigned int fl_id;
  47. unsigned int ch_id;
  48. /* ADC specific */
  49. unsigned int oversamp;
  50. struct iio_hw_consumer *hwc;
  51. struct completion completion;
  52. u32 *buffer;
  53. /* Audio specific */
  54. unsigned int spi_freq; /* SPI bus clock frequency */
  55. unsigned int sample_freq; /* Sample frequency after filter decimation */
  56. int (*cb)(const void *data, size_t size, void *cb_priv);
  57. void *cb_priv;
  58. /* DMA */
  59. u8 *rx_buf;
  60. unsigned int bufi; /* Buffer current position */
  61. unsigned int buf_sz; /* Buffer size */
  62. struct dma_chan *dma_chan;
  63. dma_addr_t dma_buf;
  64. };
  65. struct stm32_dfsdm_str2field {
  66. const char *name;
  67. unsigned int val;
  68. };
  69. /* DFSDM channel serial interface type */
  70. static const struct stm32_dfsdm_str2field stm32_dfsdm_chan_type[] = {
  71. { "SPI_R", 0 }, /* SPI with data on rising edge */
  72. { "SPI_F", 1 }, /* SPI with data on falling edge */
  73. { "MANCH_R", 2 }, /* Manchester codec, rising edge = logic 0 */
  74. { "MANCH_F", 3 }, /* Manchester codec, falling edge = logic 1 */
  75. {},
  76. };
  77. /* DFSDM channel clock source */
  78. static const struct stm32_dfsdm_str2field stm32_dfsdm_chan_src[] = {
  79. /* External SPI clock (CLKIN x) */
  80. { "CLKIN", DFSDM_CHANNEL_SPI_CLOCK_EXTERNAL },
  81. /* Internal SPI clock (CLKOUT) */
  82. { "CLKOUT", DFSDM_CHANNEL_SPI_CLOCK_INTERNAL },
  83. /* Internal SPI clock divided by 2 (falling edge) */
  84. { "CLKOUT_F", DFSDM_CHANNEL_SPI_CLOCK_INTERNAL_DIV2_FALLING },
  85. /* Internal SPI clock divided by 2 (falling edge) */
  86. { "CLKOUT_R", DFSDM_CHANNEL_SPI_CLOCK_INTERNAL_DIV2_RISING },
  87. {},
  88. };
  89. static int stm32_dfsdm_str2val(const char *str,
  90. const struct stm32_dfsdm_str2field *list)
  91. {
  92. const struct stm32_dfsdm_str2field *p = list;
  93. for (p = list; p && p->name; p++)
  94. if (!strcmp(p->name, str))
  95. return p->val;
  96. return -EINVAL;
  97. }
  98. static int stm32_dfsdm_set_osrs(struct stm32_dfsdm_filter *fl,
  99. unsigned int fast, unsigned int oversamp)
  100. {
  101. unsigned int i, d, fosr, iosr;
  102. u64 res;
  103. s64 delta;
  104. unsigned int m = 1; /* multiplication factor */
  105. unsigned int p = fl->ford; /* filter order (ford) */
  106. pr_debug("%s: Requested oversampling: %d\n", __func__, oversamp);
  107. /*
  108. * This function tries to compute filter oversampling and integrator
  109. * oversampling, base on oversampling ratio requested by user.
  110. *
  111. * Decimation d depends on the filter order and the oversampling ratios.
  112. * ford: filter order
  113. * fosr: filter over sampling ratio
  114. * iosr: integrator over sampling ratio
  115. */
  116. if (fl->ford == DFSDM_FASTSINC_ORDER) {
  117. m = 2;
  118. p = 2;
  119. }
  120. /*
  121. * Look for filter and integrator oversampling ratios which allows
  122. * to reach 24 bits data output resolution.
  123. * Leave as soon as if exact resolution if reached.
  124. * Otherwise the higher resolution below 32 bits is kept.
  125. */
  126. for (fosr = 1; fosr <= DFSDM_MAX_FL_OVERSAMPLING; fosr++) {
  127. for (iosr = 1; iosr <= DFSDM_MAX_INT_OVERSAMPLING; iosr++) {
  128. if (fast)
  129. d = fosr * iosr;
  130. else if (fl->ford == DFSDM_FASTSINC_ORDER)
  131. d = fosr * (iosr + 3) + 2;
  132. else
  133. d = fosr * (iosr - 1 + p) + p;
  134. if (d > oversamp)
  135. break;
  136. else if (d != oversamp)
  137. continue;
  138. /*
  139. * Check resolution (limited to signed 32 bits)
  140. * res <= 2^31
  141. * Sincx filters:
  142. * res = m * fosr^p x iosr (with m=1, p=ford)
  143. * FastSinc filter
  144. * res = m * fosr^p x iosr (with m=2, p=2)
  145. */
  146. res = fosr;
  147. for (i = p - 1; i > 0; i--) {
  148. res = res * (u64)fosr;
  149. if (res > DFSDM_MAX_RES)
  150. break;
  151. }
  152. if (res > DFSDM_MAX_RES)
  153. continue;
  154. res = res * (u64)m * (u64)iosr;
  155. if (res > DFSDM_MAX_RES)
  156. continue;
  157. delta = res - DFSDM_DATA_RES;
  158. if (res >= fl->res) {
  159. fl->res = res;
  160. fl->fosr = fosr;
  161. fl->iosr = iosr;
  162. fl->fast = fast;
  163. pr_debug("%s: fosr = %d, iosr = %d\n",
  164. __func__, fl->fosr, fl->iosr);
  165. }
  166. if (!delta)
  167. return 0;
  168. }
  169. }
  170. if (!fl->fosr)
  171. return -EINVAL;
  172. return 0;
  173. }
  174. static int stm32_dfsdm_start_channel(struct stm32_dfsdm *dfsdm,
  175. unsigned int ch_id)
  176. {
  177. return regmap_update_bits(dfsdm->regmap, DFSDM_CHCFGR1(ch_id),
  178. DFSDM_CHCFGR1_CHEN_MASK,
  179. DFSDM_CHCFGR1_CHEN(1));
  180. }
  181. static void stm32_dfsdm_stop_channel(struct stm32_dfsdm *dfsdm,
  182. unsigned int ch_id)
  183. {
  184. regmap_update_bits(dfsdm->regmap, DFSDM_CHCFGR1(ch_id),
  185. DFSDM_CHCFGR1_CHEN_MASK, DFSDM_CHCFGR1_CHEN(0));
  186. }
  187. static int stm32_dfsdm_chan_configure(struct stm32_dfsdm *dfsdm,
  188. struct stm32_dfsdm_channel *ch)
  189. {
  190. unsigned int id = ch->id;
  191. struct regmap *regmap = dfsdm->regmap;
  192. int ret;
  193. ret = regmap_update_bits(regmap, DFSDM_CHCFGR1(id),
  194. DFSDM_CHCFGR1_SITP_MASK,
  195. DFSDM_CHCFGR1_SITP(ch->type));
  196. if (ret < 0)
  197. return ret;
  198. ret = regmap_update_bits(regmap, DFSDM_CHCFGR1(id),
  199. DFSDM_CHCFGR1_SPICKSEL_MASK,
  200. DFSDM_CHCFGR1_SPICKSEL(ch->src));
  201. if (ret < 0)
  202. return ret;
  203. return regmap_update_bits(regmap, DFSDM_CHCFGR1(id),
  204. DFSDM_CHCFGR1_CHINSEL_MASK,
  205. DFSDM_CHCFGR1_CHINSEL(ch->alt_si));
  206. }
  207. static int stm32_dfsdm_start_filter(struct stm32_dfsdm *dfsdm,
  208. unsigned int fl_id)
  209. {
  210. int ret;
  211. /* Enable filter */
  212. ret = regmap_update_bits(dfsdm->regmap, DFSDM_CR1(fl_id),
  213. DFSDM_CR1_DFEN_MASK, DFSDM_CR1_DFEN(1));
  214. if (ret < 0)
  215. return ret;
  216. /* Start conversion */
  217. return regmap_update_bits(dfsdm->regmap, DFSDM_CR1(fl_id),
  218. DFSDM_CR1_RSWSTART_MASK,
  219. DFSDM_CR1_RSWSTART(1));
  220. }
  221. static void stm32_dfsdm_stop_filter(struct stm32_dfsdm *dfsdm, unsigned int fl_id)
  222. {
  223. /* Disable conversion */
  224. regmap_update_bits(dfsdm->regmap, DFSDM_CR1(fl_id),
  225. DFSDM_CR1_DFEN_MASK, DFSDM_CR1_DFEN(0));
  226. }
  227. static int stm32_dfsdm_filter_configure(struct stm32_dfsdm *dfsdm,
  228. unsigned int fl_id, unsigned int ch_id)
  229. {
  230. struct regmap *regmap = dfsdm->regmap;
  231. struct stm32_dfsdm_filter *fl = &dfsdm->fl_list[fl_id];
  232. int ret;
  233. /* Average integrator oversampling */
  234. ret = regmap_update_bits(regmap, DFSDM_FCR(fl_id), DFSDM_FCR_IOSR_MASK,
  235. DFSDM_FCR_IOSR(fl->iosr - 1));
  236. if (ret)
  237. return ret;
  238. /* Filter order and Oversampling */
  239. ret = regmap_update_bits(regmap, DFSDM_FCR(fl_id), DFSDM_FCR_FOSR_MASK,
  240. DFSDM_FCR_FOSR(fl->fosr - 1));
  241. if (ret)
  242. return ret;
  243. ret = regmap_update_bits(regmap, DFSDM_FCR(fl_id), DFSDM_FCR_FORD_MASK,
  244. DFSDM_FCR_FORD(fl->ford));
  245. if (ret)
  246. return ret;
  247. /* No scan mode supported for the moment */
  248. ret = regmap_update_bits(regmap, DFSDM_CR1(fl_id), DFSDM_CR1_RCH_MASK,
  249. DFSDM_CR1_RCH(ch_id));
  250. if (ret)
  251. return ret;
  252. return regmap_update_bits(regmap, DFSDM_CR1(fl_id),
  253. DFSDM_CR1_RSYNC_MASK,
  254. DFSDM_CR1_RSYNC(fl->sync_mode));
  255. }
  256. static int stm32_dfsdm_channel_parse_of(struct stm32_dfsdm *dfsdm,
  257. struct iio_dev *indio_dev,
  258. struct iio_chan_spec *ch)
  259. {
  260. struct stm32_dfsdm_channel *df_ch;
  261. const char *of_str;
  262. int chan_idx = ch->scan_index;
  263. int ret, val;
  264. ret = of_property_read_u32_index(indio_dev->dev.of_node,
  265. "st,adc-channels", chan_idx,
  266. &ch->channel);
  267. if (ret < 0) {
  268. dev_err(&indio_dev->dev,
  269. " Error parsing 'st,adc-channels' for idx %d\n",
  270. chan_idx);
  271. return ret;
  272. }
  273. if (ch->channel >= dfsdm->num_chs) {
  274. dev_err(&indio_dev->dev,
  275. " Error bad channel number %d (max = %d)\n",
  276. ch->channel, dfsdm->num_chs);
  277. return -EINVAL;
  278. }
  279. ret = of_property_read_string_index(indio_dev->dev.of_node,
  280. "st,adc-channel-names", chan_idx,
  281. &ch->datasheet_name);
  282. if (ret < 0) {
  283. dev_err(&indio_dev->dev,
  284. " Error parsing 'st,adc-channel-names' for idx %d\n",
  285. chan_idx);
  286. return ret;
  287. }
  288. df_ch = &dfsdm->ch_list[ch->channel];
  289. df_ch->id = ch->channel;
  290. ret = of_property_read_string_index(indio_dev->dev.of_node,
  291. "st,adc-channel-types", chan_idx,
  292. &of_str);
  293. if (!ret) {
  294. val = stm32_dfsdm_str2val(of_str, stm32_dfsdm_chan_type);
  295. if (val < 0)
  296. return val;
  297. } else {
  298. val = 0;
  299. }
  300. df_ch->type = val;
  301. ret = of_property_read_string_index(indio_dev->dev.of_node,
  302. "st,adc-channel-clk-src", chan_idx,
  303. &of_str);
  304. if (!ret) {
  305. val = stm32_dfsdm_str2val(of_str, stm32_dfsdm_chan_src);
  306. if (val < 0)
  307. return val;
  308. } else {
  309. val = 0;
  310. }
  311. df_ch->src = val;
  312. ret = of_property_read_u32_index(indio_dev->dev.of_node,
  313. "st,adc-alt-channel", chan_idx,
  314. &df_ch->alt_si);
  315. if (ret < 0)
  316. df_ch->alt_si = 0;
  317. return 0;
  318. }
  319. static ssize_t dfsdm_adc_audio_get_spiclk(struct iio_dev *indio_dev,
  320. uintptr_t priv,
  321. const struct iio_chan_spec *chan,
  322. char *buf)
  323. {
  324. struct stm32_dfsdm_adc *adc = iio_priv(indio_dev);
  325. return snprintf(buf, PAGE_SIZE, "%d\n", adc->spi_freq);
  326. }
  327. static ssize_t dfsdm_adc_audio_set_spiclk(struct iio_dev *indio_dev,
  328. uintptr_t priv,
  329. const struct iio_chan_spec *chan,
  330. const char *buf, size_t len)
  331. {
  332. struct stm32_dfsdm_adc *adc = iio_priv(indio_dev);
  333. struct stm32_dfsdm_filter *fl = &adc->dfsdm->fl_list[adc->fl_id];
  334. struct stm32_dfsdm_channel *ch = &adc->dfsdm->ch_list[adc->ch_id];
  335. unsigned int sample_freq = adc->sample_freq;
  336. unsigned int spi_freq;
  337. int ret;
  338. dev_err(&indio_dev->dev, "enter %s\n", __func__);
  339. /* If DFSDM is master on SPI, SPI freq can not be updated */
  340. if (ch->src != DFSDM_CHANNEL_SPI_CLOCK_EXTERNAL)
  341. return -EPERM;
  342. ret = kstrtoint(buf, 0, &spi_freq);
  343. if (ret)
  344. return ret;
  345. if (!spi_freq)
  346. return -EINVAL;
  347. if (sample_freq) {
  348. if (spi_freq % sample_freq)
  349. dev_warn(&indio_dev->dev,
  350. "Sampling rate not accurate (%d)\n",
  351. spi_freq / (spi_freq / sample_freq));
  352. ret = stm32_dfsdm_set_osrs(fl, 0, (spi_freq / sample_freq));
  353. if (ret < 0) {
  354. dev_err(&indio_dev->dev,
  355. "No filter parameters that match!\n");
  356. return ret;
  357. }
  358. }
  359. adc->spi_freq = spi_freq;
  360. return len;
  361. }
  362. static int stm32_dfsdm_start_conv(struct stm32_dfsdm_adc *adc, bool dma)
  363. {
  364. struct regmap *regmap = adc->dfsdm->regmap;
  365. int ret;
  366. unsigned int dma_en = 0, cont_en = 0;
  367. ret = stm32_dfsdm_start_channel(adc->dfsdm, adc->ch_id);
  368. if (ret < 0)
  369. return ret;
  370. ret = stm32_dfsdm_filter_configure(adc->dfsdm, adc->fl_id,
  371. adc->ch_id);
  372. if (ret < 0)
  373. goto stop_channels;
  374. if (dma) {
  375. /* Enable DMA transfer*/
  376. dma_en = DFSDM_CR1_RDMAEN(1);
  377. /* Enable conversion triggered by SPI clock*/
  378. cont_en = DFSDM_CR1_RCONT(1);
  379. }
  380. /* Enable DMA transfer*/
  381. ret = regmap_update_bits(regmap, DFSDM_CR1(adc->fl_id),
  382. DFSDM_CR1_RDMAEN_MASK, dma_en);
  383. if (ret < 0)
  384. goto stop_channels;
  385. /* Enable conversion triggered by SPI clock*/
  386. ret = regmap_update_bits(regmap, DFSDM_CR1(adc->fl_id),
  387. DFSDM_CR1_RCONT_MASK, cont_en);
  388. if (ret < 0)
  389. goto stop_channels;
  390. ret = stm32_dfsdm_start_filter(adc->dfsdm, adc->fl_id);
  391. if (ret < 0)
  392. goto stop_channels;
  393. return 0;
  394. stop_channels:
  395. regmap_update_bits(regmap, DFSDM_CR1(adc->fl_id),
  396. DFSDM_CR1_RDMAEN_MASK, 0);
  397. regmap_update_bits(regmap, DFSDM_CR1(adc->fl_id),
  398. DFSDM_CR1_RCONT_MASK, 0);
  399. stm32_dfsdm_stop_channel(adc->dfsdm, adc->fl_id);
  400. return ret;
  401. }
  402. static void stm32_dfsdm_stop_conv(struct stm32_dfsdm_adc *adc)
  403. {
  404. struct regmap *regmap = adc->dfsdm->regmap;
  405. stm32_dfsdm_stop_filter(adc->dfsdm, adc->fl_id);
  406. /* Clean conversion options */
  407. regmap_update_bits(regmap, DFSDM_CR1(adc->fl_id),
  408. DFSDM_CR1_RDMAEN_MASK, 0);
  409. regmap_update_bits(regmap, DFSDM_CR1(adc->fl_id),
  410. DFSDM_CR1_RCONT_MASK, 0);
  411. stm32_dfsdm_stop_channel(adc->dfsdm, adc->ch_id);
  412. }
  413. static int stm32_dfsdm_set_watermark(struct iio_dev *indio_dev,
  414. unsigned int val)
  415. {
  416. struct stm32_dfsdm_adc *adc = iio_priv(indio_dev);
  417. unsigned int watermark = DFSDM_DMA_BUFFER_SIZE / 2;
  418. /*
  419. * DMA cyclic transfers are used, buffer is split into two periods.
  420. * There should be :
  421. * - always one buffer (period) DMA is working on
  422. * - one buffer (period) driver pushed to ASoC side.
  423. */
  424. watermark = min(watermark, val * (unsigned int)(sizeof(u32)));
  425. adc->buf_sz = watermark * 2;
  426. return 0;
  427. }
  428. static unsigned int stm32_dfsdm_adc_dma_residue(struct stm32_dfsdm_adc *adc)
  429. {
  430. struct dma_tx_state state;
  431. enum dma_status status;
  432. status = dmaengine_tx_status(adc->dma_chan,
  433. adc->dma_chan->cookie,
  434. &state);
  435. if (status == DMA_IN_PROGRESS) {
  436. /* Residue is size in bytes from end of buffer */
  437. unsigned int i = adc->buf_sz - state.residue;
  438. unsigned int size;
  439. /* Return available bytes */
  440. if (i >= adc->bufi)
  441. size = i - adc->bufi;
  442. else
  443. size = adc->buf_sz + i - adc->bufi;
  444. return size;
  445. }
  446. return 0;
  447. }
  448. static void stm32_dfsdm_audio_dma_buffer_done(void *data)
  449. {
  450. struct iio_dev *indio_dev = data;
  451. struct stm32_dfsdm_adc *adc = iio_priv(indio_dev);
  452. int available = stm32_dfsdm_adc_dma_residue(adc);
  453. size_t old_pos;
  454. /*
  455. * FIXME: In Kernel interface does not support cyclic DMA buffer,and
  456. * offers only an interface to push data samples per samples.
  457. * For this reason IIO buffer interface is not used and interface is
  458. * bypassed using a private callback registered by ASoC.
  459. * This should be a temporary solution waiting a cyclic DMA engine
  460. * support in IIO.
  461. */
  462. dev_dbg(&indio_dev->dev, "%s: pos = %d, available = %d\n", __func__,
  463. adc->bufi, available);
  464. old_pos = adc->bufi;
  465. while (available >= indio_dev->scan_bytes) {
  466. u32 *buffer = (u32 *)&adc->rx_buf[adc->bufi];
  467. /* Mask 8 LSB that contains the channel ID */
  468. *buffer = (*buffer & 0xFFFFFF00) << 8;
  469. available -= indio_dev->scan_bytes;
  470. adc->bufi += indio_dev->scan_bytes;
  471. if (adc->bufi >= adc->buf_sz) {
  472. if (adc->cb)
  473. adc->cb(&adc->rx_buf[old_pos],
  474. adc->buf_sz - old_pos, adc->cb_priv);
  475. adc->bufi = 0;
  476. old_pos = 0;
  477. }
  478. }
  479. if (adc->cb)
  480. adc->cb(&adc->rx_buf[old_pos], adc->bufi - old_pos,
  481. adc->cb_priv);
  482. }
  483. static int stm32_dfsdm_adc_dma_start(struct iio_dev *indio_dev)
  484. {
  485. struct stm32_dfsdm_adc *adc = iio_priv(indio_dev);
  486. struct dma_async_tx_descriptor *desc;
  487. dma_cookie_t cookie;
  488. int ret;
  489. if (!adc->dma_chan)
  490. return -EINVAL;
  491. dev_dbg(&indio_dev->dev, "%s size=%d watermark=%d\n", __func__,
  492. adc->buf_sz, adc->buf_sz / 2);
  493. /* Prepare a DMA cyclic transaction */
  494. desc = dmaengine_prep_dma_cyclic(adc->dma_chan,
  495. adc->dma_buf,
  496. adc->buf_sz, adc->buf_sz / 2,
  497. DMA_DEV_TO_MEM,
  498. DMA_PREP_INTERRUPT);
  499. if (!desc)
  500. return -EBUSY;
  501. desc->callback = stm32_dfsdm_audio_dma_buffer_done;
  502. desc->callback_param = indio_dev;
  503. cookie = dmaengine_submit(desc);
  504. ret = dma_submit_error(cookie);
  505. if (ret) {
  506. dmaengine_terminate_all(adc->dma_chan);
  507. return ret;
  508. }
  509. /* Issue pending DMA requests */
  510. dma_async_issue_pending(adc->dma_chan);
  511. return 0;
  512. }
  513. static int stm32_dfsdm_postenable(struct iio_dev *indio_dev)
  514. {
  515. struct stm32_dfsdm_adc *adc = iio_priv(indio_dev);
  516. int ret;
  517. /* Reset adc buffer index */
  518. adc->bufi = 0;
  519. ret = stm32_dfsdm_start_dfsdm(adc->dfsdm);
  520. if (ret < 0)
  521. return ret;
  522. ret = stm32_dfsdm_start_conv(adc, true);
  523. if (ret) {
  524. dev_err(&indio_dev->dev, "Can't start conversion\n");
  525. goto stop_dfsdm;
  526. }
  527. if (adc->dma_chan) {
  528. ret = stm32_dfsdm_adc_dma_start(indio_dev);
  529. if (ret) {
  530. dev_err(&indio_dev->dev, "Can't start DMA\n");
  531. goto err_stop_conv;
  532. }
  533. }
  534. return 0;
  535. err_stop_conv:
  536. stm32_dfsdm_stop_conv(adc);
  537. stop_dfsdm:
  538. stm32_dfsdm_stop_dfsdm(adc->dfsdm);
  539. return ret;
  540. }
  541. static int stm32_dfsdm_predisable(struct iio_dev *indio_dev)
  542. {
  543. struct stm32_dfsdm_adc *adc = iio_priv(indio_dev);
  544. if (adc->dma_chan)
  545. dmaengine_terminate_all(adc->dma_chan);
  546. stm32_dfsdm_stop_conv(adc);
  547. stm32_dfsdm_stop_dfsdm(adc->dfsdm);
  548. return 0;
  549. }
  550. static const struct iio_buffer_setup_ops stm32_dfsdm_buffer_setup_ops = {
  551. .postenable = &stm32_dfsdm_postenable,
  552. .predisable = &stm32_dfsdm_predisable,
  553. };
  554. /**
  555. * stm32_dfsdm_get_buff_cb() - register a callback that will be called when
  556. * DMA transfer period is achieved.
  557. *
  558. * @iio_dev: Handle to IIO device.
  559. * @cb: Pointer to callback function:
  560. * - data: pointer to data buffer
  561. * - size: size in byte of the data buffer
  562. * - private: pointer to consumer private structure.
  563. * @private: Pointer to consumer private structure.
  564. */
  565. int stm32_dfsdm_get_buff_cb(struct iio_dev *iio_dev,
  566. int (*cb)(const void *data, size_t size,
  567. void *private),
  568. void *private)
  569. {
  570. struct stm32_dfsdm_adc *adc;
  571. if (!iio_dev)
  572. return -EINVAL;
  573. adc = iio_priv(iio_dev);
  574. adc->cb = cb;
  575. adc->cb_priv = private;
  576. return 0;
  577. }
  578. EXPORT_SYMBOL_GPL(stm32_dfsdm_get_buff_cb);
  579. /**
  580. * stm32_dfsdm_release_buff_cb - unregister buffer callback
  581. *
  582. * @iio_dev: Handle to IIO device.
  583. */
  584. int stm32_dfsdm_release_buff_cb(struct iio_dev *iio_dev)
  585. {
  586. struct stm32_dfsdm_adc *adc;
  587. if (!iio_dev)
  588. return -EINVAL;
  589. adc = iio_priv(iio_dev);
  590. adc->cb = NULL;
  591. adc->cb_priv = NULL;
  592. return 0;
  593. }
  594. EXPORT_SYMBOL_GPL(stm32_dfsdm_release_buff_cb);
  595. static int stm32_dfsdm_single_conv(struct iio_dev *indio_dev,
  596. const struct iio_chan_spec *chan, int *res)
  597. {
  598. struct stm32_dfsdm_adc *adc = iio_priv(indio_dev);
  599. long timeout;
  600. int ret;
  601. reinit_completion(&adc->completion);
  602. adc->buffer = res;
  603. ret = stm32_dfsdm_start_dfsdm(adc->dfsdm);
  604. if (ret < 0)
  605. return ret;
  606. ret = regmap_update_bits(adc->dfsdm->regmap, DFSDM_CR2(adc->fl_id),
  607. DFSDM_CR2_REOCIE_MASK, DFSDM_CR2_REOCIE(1));
  608. if (ret < 0)
  609. goto stop_dfsdm;
  610. ret = stm32_dfsdm_start_conv(adc, false);
  611. if (ret < 0) {
  612. regmap_update_bits(adc->dfsdm->regmap, DFSDM_CR2(adc->fl_id),
  613. DFSDM_CR2_REOCIE_MASK, DFSDM_CR2_REOCIE(0));
  614. goto stop_dfsdm;
  615. }
  616. timeout = wait_for_completion_interruptible_timeout(&adc->completion,
  617. DFSDM_TIMEOUT);
  618. /* Mask IRQ for regular conversion achievement*/
  619. regmap_update_bits(adc->dfsdm->regmap, DFSDM_CR2(adc->fl_id),
  620. DFSDM_CR2_REOCIE_MASK, DFSDM_CR2_REOCIE(0));
  621. if (timeout == 0)
  622. ret = -ETIMEDOUT;
  623. else if (timeout < 0)
  624. ret = timeout;
  625. else
  626. ret = IIO_VAL_INT;
  627. stm32_dfsdm_stop_conv(adc);
  628. stop_dfsdm:
  629. stm32_dfsdm_stop_dfsdm(adc->dfsdm);
  630. return ret;
  631. }
  632. static int stm32_dfsdm_write_raw(struct iio_dev *indio_dev,
  633. struct iio_chan_spec const *chan,
  634. int val, int val2, long mask)
  635. {
  636. struct stm32_dfsdm_adc *adc = iio_priv(indio_dev);
  637. struct stm32_dfsdm_filter *fl = &adc->dfsdm->fl_list[adc->fl_id];
  638. struct stm32_dfsdm_channel *ch = &adc->dfsdm->ch_list[adc->ch_id];
  639. unsigned int spi_freq = adc->spi_freq;
  640. int ret = -EINVAL;
  641. switch (mask) {
  642. case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
  643. ret = stm32_dfsdm_set_osrs(fl, 0, val);
  644. if (!ret)
  645. adc->oversamp = val;
  646. return ret;
  647. case IIO_CHAN_INFO_SAMP_FREQ:
  648. if (!val)
  649. return -EINVAL;
  650. if (ch->src != DFSDM_CHANNEL_SPI_CLOCK_EXTERNAL)
  651. spi_freq = adc->dfsdm->spi_master_freq;
  652. if (spi_freq % val)
  653. dev_warn(&indio_dev->dev,
  654. "Sampling rate not accurate (%d)\n",
  655. spi_freq / (spi_freq / val));
  656. ret = stm32_dfsdm_set_osrs(fl, 0, (spi_freq / val));
  657. if (ret < 0) {
  658. dev_err(&indio_dev->dev,
  659. "Not able to find parameter that match!\n");
  660. return ret;
  661. }
  662. adc->sample_freq = val;
  663. return 0;
  664. }
  665. return -EINVAL;
  666. }
  667. static int stm32_dfsdm_read_raw(struct iio_dev *indio_dev,
  668. struct iio_chan_spec const *chan, int *val,
  669. int *val2, long mask)
  670. {
  671. struct stm32_dfsdm_adc *adc = iio_priv(indio_dev);
  672. int ret;
  673. switch (mask) {
  674. case IIO_CHAN_INFO_RAW:
  675. ret = iio_hw_consumer_enable(adc->hwc);
  676. if (ret < 0) {
  677. dev_err(&indio_dev->dev,
  678. "%s: IIO enable failed (channel %d)\n",
  679. __func__, chan->channel);
  680. return ret;
  681. }
  682. ret = stm32_dfsdm_single_conv(indio_dev, chan, val);
  683. iio_hw_consumer_disable(adc->hwc);
  684. if (ret < 0) {
  685. dev_err(&indio_dev->dev,
  686. "%s: Conversion failed (channel %d)\n",
  687. __func__, chan->channel);
  688. return ret;
  689. }
  690. return IIO_VAL_INT;
  691. case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
  692. *val = adc->oversamp;
  693. return IIO_VAL_INT;
  694. case IIO_CHAN_INFO_SAMP_FREQ:
  695. *val = adc->sample_freq;
  696. return IIO_VAL_INT;
  697. }
  698. return -EINVAL;
  699. }
  700. static const struct iio_info stm32_dfsdm_info_audio = {
  701. .hwfifo_set_watermark = stm32_dfsdm_set_watermark,
  702. .read_raw = stm32_dfsdm_read_raw,
  703. .write_raw = stm32_dfsdm_write_raw,
  704. };
  705. static const struct iio_info stm32_dfsdm_info_adc = {
  706. .read_raw = stm32_dfsdm_read_raw,
  707. .write_raw = stm32_dfsdm_write_raw,
  708. };
  709. static irqreturn_t stm32_dfsdm_irq(int irq, void *arg)
  710. {
  711. struct stm32_dfsdm_adc *adc = arg;
  712. struct iio_dev *indio_dev = iio_priv_to_dev(adc);
  713. struct regmap *regmap = adc->dfsdm->regmap;
  714. unsigned int status, int_en;
  715. regmap_read(regmap, DFSDM_ISR(adc->fl_id), &status);
  716. regmap_read(regmap, DFSDM_CR2(adc->fl_id), &int_en);
  717. if (status & DFSDM_ISR_REOCF_MASK) {
  718. /* Read the data register clean the IRQ status */
  719. regmap_read(regmap, DFSDM_RDATAR(adc->fl_id), adc->buffer);
  720. complete(&adc->completion);
  721. }
  722. if (status & DFSDM_ISR_ROVRF_MASK) {
  723. if (int_en & DFSDM_CR2_ROVRIE_MASK)
  724. dev_warn(&indio_dev->dev, "Overrun detected\n");
  725. regmap_update_bits(regmap, DFSDM_ICR(adc->fl_id),
  726. DFSDM_ICR_CLRROVRF_MASK,
  727. DFSDM_ICR_CLRROVRF_MASK);
  728. }
  729. return IRQ_HANDLED;
  730. }
  731. /*
  732. * Define external info for SPI Frequency and audio sampling rate that can be
  733. * configured by ASoC driver through consumer.h API
  734. */
  735. static const struct iio_chan_spec_ext_info dfsdm_adc_audio_ext_info[] = {
  736. /* spi_clk_freq : clock freq on SPI/manchester bus used by channel */
  737. {
  738. .name = "spi_clk_freq",
  739. .shared = IIO_SHARED_BY_TYPE,
  740. .read = dfsdm_adc_audio_get_spiclk,
  741. .write = dfsdm_adc_audio_set_spiclk,
  742. },
  743. {},
  744. };
  745. static void stm32_dfsdm_dma_release(struct iio_dev *indio_dev)
  746. {
  747. struct stm32_dfsdm_adc *adc = iio_priv(indio_dev);
  748. if (adc->dma_chan) {
  749. dma_free_coherent(adc->dma_chan->device->dev,
  750. DFSDM_DMA_BUFFER_SIZE,
  751. adc->rx_buf, adc->dma_buf);
  752. dma_release_channel(adc->dma_chan);
  753. }
  754. }
  755. static int stm32_dfsdm_dma_request(struct iio_dev *indio_dev)
  756. {
  757. struct stm32_dfsdm_adc *adc = iio_priv(indio_dev);
  758. struct dma_slave_config config = {
  759. .src_addr = (dma_addr_t)adc->dfsdm->phys_base +
  760. DFSDM_RDATAR(adc->fl_id),
  761. .src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES,
  762. };
  763. int ret;
  764. adc->dma_chan = dma_request_slave_channel(&indio_dev->dev, "rx");
  765. if (!adc->dma_chan)
  766. return -EINVAL;
  767. adc->rx_buf = dma_alloc_coherent(adc->dma_chan->device->dev,
  768. DFSDM_DMA_BUFFER_SIZE,
  769. &adc->dma_buf, GFP_KERNEL);
  770. if (!adc->rx_buf) {
  771. ret = -ENOMEM;
  772. goto err_release;
  773. }
  774. ret = dmaengine_slave_config(adc->dma_chan, &config);
  775. if (ret)
  776. goto err_free;
  777. return 0;
  778. err_free:
  779. dma_free_coherent(adc->dma_chan->device->dev, DFSDM_DMA_BUFFER_SIZE,
  780. adc->rx_buf, adc->dma_buf);
  781. err_release:
  782. dma_release_channel(adc->dma_chan);
  783. return ret;
  784. }
  785. static int stm32_dfsdm_adc_chan_init_one(struct iio_dev *indio_dev,
  786. struct iio_chan_spec *ch)
  787. {
  788. struct stm32_dfsdm_adc *adc = iio_priv(indio_dev);
  789. int ret;
  790. ret = stm32_dfsdm_channel_parse_of(adc->dfsdm, indio_dev, ch);
  791. if (ret < 0)
  792. return ret;
  793. ch->type = IIO_VOLTAGE;
  794. ch->indexed = 1;
  795. /*
  796. * IIO_CHAN_INFO_RAW: used to compute regular conversion
  797. * IIO_CHAN_INFO_OVERSAMPLING_RATIO: used to set oversampling
  798. */
  799. ch->info_mask_separate = BIT(IIO_CHAN_INFO_RAW);
  800. ch->info_mask_shared_by_all = BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO);
  801. if (adc->dev_data->type == DFSDM_AUDIO) {
  802. ch->scan_type.sign = 's';
  803. ch->ext_info = dfsdm_adc_audio_ext_info;
  804. } else {
  805. ch->scan_type.sign = 'u';
  806. }
  807. ch->scan_type.realbits = 24;
  808. ch->scan_type.storagebits = 32;
  809. adc->ch_id = ch->channel;
  810. return stm32_dfsdm_chan_configure(adc->dfsdm,
  811. &adc->dfsdm->ch_list[ch->channel]);
  812. }
  813. static int stm32_dfsdm_audio_init(struct iio_dev *indio_dev)
  814. {
  815. struct iio_chan_spec *ch;
  816. struct stm32_dfsdm_adc *adc = iio_priv(indio_dev);
  817. struct stm32_dfsdm_channel *d_ch;
  818. int ret;
  819. indio_dev->modes |= INDIO_BUFFER_SOFTWARE;
  820. indio_dev->setup_ops = &stm32_dfsdm_buffer_setup_ops;
  821. ch = devm_kzalloc(&indio_dev->dev, sizeof(*ch), GFP_KERNEL);
  822. if (!ch)
  823. return -ENOMEM;
  824. ch->scan_index = 0;
  825. ret = stm32_dfsdm_adc_chan_init_one(indio_dev, ch);
  826. if (ret < 0) {
  827. dev_err(&indio_dev->dev, "Channels init failed\n");
  828. return ret;
  829. }
  830. ch->info_mask_separate = BIT(IIO_CHAN_INFO_SAMP_FREQ);
  831. d_ch = &adc->dfsdm->ch_list[adc->ch_id];
  832. if (d_ch->src != DFSDM_CHANNEL_SPI_CLOCK_EXTERNAL)
  833. adc->spi_freq = adc->dfsdm->spi_master_freq;
  834. indio_dev->num_channels = 1;
  835. indio_dev->channels = ch;
  836. return stm32_dfsdm_dma_request(indio_dev);
  837. }
  838. static int stm32_dfsdm_adc_init(struct iio_dev *indio_dev)
  839. {
  840. struct iio_chan_spec *ch;
  841. struct stm32_dfsdm_adc *adc = iio_priv(indio_dev);
  842. int num_ch;
  843. int ret, chan_idx;
  844. adc->oversamp = DFSDM_DEFAULT_OVERSAMPLING;
  845. ret = stm32_dfsdm_set_osrs(&adc->dfsdm->fl_list[adc->fl_id], 0,
  846. adc->oversamp);
  847. if (ret < 0)
  848. return ret;
  849. num_ch = of_property_count_u32_elems(indio_dev->dev.of_node,
  850. "st,adc-channels");
  851. if (num_ch < 0 || num_ch > adc->dfsdm->num_chs) {
  852. dev_err(&indio_dev->dev, "Bad st,adc-channels\n");
  853. return num_ch < 0 ? num_ch : -EINVAL;
  854. }
  855. /* Bind to SD modulator IIO device */
  856. adc->hwc = devm_iio_hw_consumer_alloc(&indio_dev->dev);
  857. if (IS_ERR(adc->hwc))
  858. return -EPROBE_DEFER;
  859. ch = devm_kcalloc(&indio_dev->dev, num_ch, sizeof(*ch),
  860. GFP_KERNEL);
  861. if (!ch)
  862. return -ENOMEM;
  863. for (chan_idx = 0; chan_idx < num_ch; chan_idx++) {
  864. ch->scan_index = chan_idx;
  865. ret = stm32_dfsdm_adc_chan_init_one(indio_dev, ch);
  866. if (ret < 0) {
  867. dev_err(&indio_dev->dev, "Channels init failed\n");
  868. return ret;
  869. }
  870. }
  871. indio_dev->num_channels = num_ch;
  872. indio_dev->channels = ch;
  873. init_completion(&adc->completion);
  874. return 0;
  875. }
  876. static const struct stm32_dfsdm_dev_data stm32h7_dfsdm_adc_data = {
  877. .type = DFSDM_IIO,
  878. .init = stm32_dfsdm_adc_init,
  879. };
  880. static const struct stm32_dfsdm_dev_data stm32h7_dfsdm_audio_data = {
  881. .type = DFSDM_AUDIO,
  882. .init = stm32_dfsdm_audio_init,
  883. };
  884. static const struct of_device_id stm32_dfsdm_adc_match[] = {
  885. {
  886. .compatible = "st,stm32-dfsdm-adc",
  887. .data = &stm32h7_dfsdm_adc_data,
  888. },
  889. {
  890. .compatible = "st,stm32-dfsdm-dmic",
  891. .data = &stm32h7_dfsdm_audio_data,
  892. },
  893. {}
  894. };
  895. static int stm32_dfsdm_adc_probe(struct platform_device *pdev)
  896. {
  897. struct device *dev = &pdev->dev;
  898. struct stm32_dfsdm_adc *adc;
  899. struct device_node *np = dev->of_node;
  900. const struct stm32_dfsdm_dev_data *dev_data;
  901. struct iio_dev *iio;
  902. const struct of_device_id *of_id;
  903. char *name;
  904. int ret, irq, val;
  905. of_id = of_match_node(stm32_dfsdm_adc_match, np);
  906. if (!of_id->data) {
  907. dev_err(&pdev->dev, "Data associated to device is missing\n");
  908. return -EINVAL;
  909. }
  910. dev_data = (const struct stm32_dfsdm_dev_data *)of_id->data;
  911. iio = devm_iio_device_alloc(dev, sizeof(*adc));
  912. if (IS_ERR(iio)) {
  913. dev_err(dev, "%s: Failed to allocate IIO\n", __func__);
  914. return PTR_ERR(iio);
  915. }
  916. adc = iio_priv(iio);
  917. if (IS_ERR(adc)) {
  918. dev_err(dev, "%s: Failed to allocate ADC\n", __func__);
  919. return PTR_ERR(adc);
  920. }
  921. adc->dfsdm = dev_get_drvdata(dev->parent);
  922. iio->dev.parent = dev;
  923. iio->dev.of_node = np;
  924. iio->modes = INDIO_DIRECT_MODE | INDIO_BUFFER_SOFTWARE;
  925. platform_set_drvdata(pdev, adc);
  926. ret = of_property_read_u32(dev->of_node, "reg", &adc->fl_id);
  927. if (ret != 0) {
  928. dev_err(dev, "Missing reg property\n");
  929. return -EINVAL;
  930. }
  931. name = devm_kzalloc(dev, sizeof("dfsdm-adc0"), GFP_KERNEL);
  932. if (!name)
  933. return -ENOMEM;
  934. if (dev_data->type == DFSDM_AUDIO) {
  935. iio->info = &stm32_dfsdm_info_audio;
  936. snprintf(name, sizeof("dfsdm-pdm0"), "dfsdm-pdm%d", adc->fl_id);
  937. } else {
  938. iio->info = &stm32_dfsdm_info_adc;
  939. snprintf(name, sizeof("dfsdm-adc0"), "dfsdm-adc%d", adc->fl_id);
  940. }
  941. iio->name = name;
  942. /*
  943. * In a first step IRQs generated for channels are not treated.
  944. * So IRQ associated to filter instance 0 is dedicated to the Filter 0.
  945. */
  946. irq = platform_get_irq(pdev, 0);
  947. ret = devm_request_irq(dev, irq, stm32_dfsdm_irq,
  948. 0, pdev->name, adc);
  949. if (ret < 0) {
  950. dev_err(dev, "Failed to request IRQ\n");
  951. return ret;
  952. }
  953. ret = of_property_read_u32(dev->of_node, "st,filter-order", &val);
  954. if (ret < 0) {
  955. dev_err(dev, "Failed to set filter order\n");
  956. return ret;
  957. }
  958. adc->dfsdm->fl_list[adc->fl_id].ford = val;
  959. ret = of_property_read_u32(dev->of_node, "st,filter0-sync", &val);
  960. if (!ret)
  961. adc->dfsdm->fl_list[adc->fl_id].sync_mode = val;
  962. adc->dev_data = dev_data;
  963. ret = dev_data->init(iio);
  964. if (ret < 0)
  965. return ret;
  966. ret = iio_device_register(iio);
  967. if (ret < 0)
  968. goto err_cleanup;
  969. dev_err(dev, "of_platform_populate\n");
  970. if (dev_data->type == DFSDM_AUDIO) {
  971. ret = of_platform_populate(np, NULL, NULL, dev);
  972. if (ret < 0) {
  973. dev_err(dev, "Failed to find an audio DAI\n");
  974. goto err_unregister;
  975. }
  976. }
  977. return 0;
  978. err_unregister:
  979. iio_device_unregister(iio);
  980. err_cleanup:
  981. stm32_dfsdm_dma_release(iio);
  982. return ret;
  983. }
  984. static int stm32_dfsdm_adc_remove(struct platform_device *pdev)
  985. {
  986. struct stm32_dfsdm_adc *adc = platform_get_drvdata(pdev);
  987. struct iio_dev *indio_dev = iio_priv_to_dev(adc);
  988. if (adc->dev_data->type == DFSDM_AUDIO)
  989. of_platform_depopulate(&pdev->dev);
  990. iio_device_unregister(indio_dev);
  991. stm32_dfsdm_dma_release(indio_dev);
  992. return 0;
  993. }
  994. static struct platform_driver stm32_dfsdm_adc_driver = {
  995. .driver = {
  996. .name = "stm32-dfsdm-adc",
  997. .of_match_table = stm32_dfsdm_adc_match,
  998. },
  999. .probe = stm32_dfsdm_adc_probe,
  1000. .remove = stm32_dfsdm_adc_remove,
  1001. };
  1002. module_platform_driver(stm32_dfsdm_adc_driver);
  1003. MODULE_DESCRIPTION("STM32 sigma delta ADC");
  1004. MODULE_AUTHOR("Arnaud Pouliquen <arnaud.pouliquen@st.com>");
  1005. MODULE_LICENSE("GPL v2");