omap-mcpdm.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  1. /*
  2. * omap-mcpdm.c -- OMAP ALSA SoC DAI driver using McPDM port
  3. *
  4. * Copyright (C) 2009 - 2011 Texas Instruments
  5. *
  6. * Author: Misael Lopez Cruz <misael.lopez@ti.com>
  7. * Contact: Jorge Eduardo Candelaria <x0107209@ti.com>
  8. * Margarita Olaya <magi.olaya@ti.com>
  9. * Peter Ujfalusi <peter.ujfalusi@ti.com>
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License
  13. * version 2 as published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope that it will be useful, but
  16. * WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  23. * 02110-1301 USA
  24. *
  25. */
  26. #include <linux/init.h>
  27. #include <linux/module.h>
  28. #include <linux/platform_device.h>
  29. #include <linux/interrupt.h>
  30. #include <linux/err.h>
  31. #include <linux/io.h>
  32. #include <linux/irq.h>
  33. #include <linux/slab.h>
  34. #include <linux/pm_runtime.h>
  35. #include <linux/of_device.h>
  36. #include <sound/core.h>
  37. #include <sound/pcm.h>
  38. #include <sound/pcm_params.h>
  39. #include <sound/soc.h>
  40. #include <sound/dmaengine_pcm.h>
  41. #include "omap-mcpdm.h"
  42. #include "sdma-pcm.h"
  43. struct mcpdm_link_config {
  44. u32 link_mask; /* channel mask for the direction */
  45. u32 threshold; /* FIFO threshold */
  46. };
  47. struct omap_mcpdm {
  48. struct device *dev;
  49. unsigned long phys_base;
  50. void __iomem *io_base;
  51. int irq;
  52. struct pm_qos_request pm_qos_req;
  53. int latency[2];
  54. struct mutex mutex;
  55. /* Playback/Capture configuration */
  56. struct mcpdm_link_config config[2];
  57. /* McPDM dn offsets for rx1, and 2 channels */
  58. u32 dn_rx_offset;
  59. /* McPDM needs to be restarted due to runtime reconfiguration */
  60. bool restart;
  61. /* pm state for suspend/resume handling */
  62. int pm_active_count;
  63. struct snd_dmaengine_dai_dma_data dma_data[2];
  64. };
  65. /*
  66. * Stream DMA parameters
  67. */
  68. static inline void omap_mcpdm_write(struct omap_mcpdm *mcpdm, u16 reg, u32 val)
  69. {
  70. writel_relaxed(val, mcpdm->io_base + reg);
  71. }
  72. static inline int omap_mcpdm_read(struct omap_mcpdm *mcpdm, u16 reg)
  73. {
  74. return readl_relaxed(mcpdm->io_base + reg);
  75. }
  76. #ifdef DEBUG
  77. static void omap_mcpdm_reg_dump(struct omap_mcpdm *mcpdm)
  78. {
  79. dev_dbg(mcpdm->dev, "***********************\n");
  80. dev_dbg(mcpdm->dev, "IRQSTATUS_RAW: 0x%04x\n",
  81. omap_mcpdm_read(mcpdm, MCPDM_REG_IRQSTATUS_RAW));
  82. dev_dbg(mcpdm->dev, "IRQSTATUS: 0x%04x\n",
  83. omap_mcpdm_read(mcpdm, MCPDM_REG_IRQSTATUS));
  84. dev_dbg(mcpdm->dev, "IRQENABLE_SET: 0x%04x\n",
  85. omap_mcpdm_read(mcpdm, MCPDM_REG_IRQENABLE_SET));
  86. dev_dbg(mcpdm->dev, "IRQENABLE_CLR: 0x%04x\n",
  87. omap_mcpdm_read(mcpdm, MCPDM_REG_IRQENABLE_CLR));
  88. dev_dbg(mcpdm->dev, "IRQWAKE_EN: 0x%04x\n",
  89. omap_mcpdm_read(mcpdm, MCPDM_REG_IRQWAKE_EN));
  90. dev_dbg(mcpdm->dev, "DMAENABLE_SET: 0x%04x\n",
  91. omap_mcpdm_read(mcpdm, MCPDM_REG_DMAENABLE_SET));
  92. dev_dbg(mcpdm->dev, "DMAENABLE_CLR: 0x%04x\n",
  93. omap_mcpdm_read(mcpdm, MCPDM_REG_DMAENABLE_CLR));
  94. dev_dbg(mcpdm->dev, "DMAWAKEEN: 0x%04x\n",
  95. omap_mcpdm_read(mcpdm, MCPDM_REG_DMAWAKEEN));
  96. dev_dbg(mcpdm->dev, "CTRL: 0x%04x\n",
  97. omap_mcpdm_read(mcpdm, MCPDM_REG_CTRL));
  98. dev_dbg(mcpdm->dev, "DN_DATA: 0x%04x\n",
  99. omap_mcpdm_read(mcpdm, MCPDM_REG_DN_DATA));
  100. dev_dbg(mcpdm->dev, "UP_DATA: 0x%04x\n",
  101. omap_mcpdm_read(mcpdm, MCPDM_REG_UP_DATA));
  102. dev_dbg(mcpdm->dev, "FIFO_CTRL_DN: 0x%04x\n",
  103. omap_mcpdm_read(mcpdm, MCPDM_REG_FIFO_CTRL_DN));
  104. dev_dbg(mcpdm->dev, "FIFO_CTRL_UP: 0x%04x\n",
  105. omap_mcpdm_read(mcpdm, MCPDM_REG_FIFO_CTRL_UP));
  106. dev_dbg(mcpdm->dev, "***********************\n");
  107. }
  108. #else
  109. static void omap_mcpdm_reg_dump(struct omap_mcpdm *mcpdm) {}
  110. #endif
  111. /*
  112. * Enables the transfer through the PDM interface to/from the Phoenix
  113. * codec by enabling the corresponding UP or DN channels.
  114. */
  115. static void omap_mcpdm_start(struct omap_mcpdm *mcpdm)
  116. {
  117. u32 ctrl = omap_mcpdm_read(mcpdm, MCPDM_REG_CTRL);
  118. u32 link_mask = mcpdm->config[0].link_mask | mcpdm->config[1].link_mask;
  119. ctrl |= (MCPDM_SW_DN_RST | MCPDM_SW_UP_RST);
  120. omap_mcpdm_write(mcpdm, MCPDM_REG_CTRL, ctrl);
  121. ctrl |= link_mask;
  122. omap_mcpdm_write(mcpdm, MCPDM_REG_CTRL, ctrl);
  123. ctrl &= ~(MCPDM_SW_DN_RST | MCPDM_SW_UP_RST);
  124. omap_mcpdm_write(mcpdm, MCPDM_REG_CTRL, ctrl);
  125. }
  126. /*
  127. * Disables the transfer through the PDM interface to/from the Phoenix
  128. * codec by disabling the corresponding UP or DN channels.
  129. */
  130. static void omap_mcpdm_stop(struct omap_mcpdm *mcpdm)
  131. {
  132. u32 ctrl = omap_mcpdm_read(mcpdm, MCPDM_REG_CTRL);
  133. u32 link_mask = MCPDM_PDM_DN_MASK | MCPDM_PDM_UP_MASK;
  134. ctrl |= (MCPDM_SW_DN_RST | MCPDM_SW_UP_RST);
  135. omap_mcpdm_write(mcpdm, MCPDM_REG_CTRL, ctrl);
  136. ctrl &= ~(link_mask);
  137. omap_mcpdm_write(mcpdm, MCPDM_REG_CTRL, ctrl);
  138. ctrl &= ~(MCPDM_SW_DN_RST | MCPDM_SW_UP_RST);
  139. omap_mcpdm_write(mcpdm, MCPDM_REG_CTRL, ctrl);
  140. }
  141. /*
  142. * Is the physical McPDM interface active.
  143. */
  144. static inline int omap_mcpdm_active(struct omap_mcpdm *mcpdm)
  145. {
  146. return omap_mcpdm_read(mcpdm, MCPDM_REG_CTRL) &
  147. (MCPDM_PDM_DN_MASK | MCPDM_PDM_UP_MASK);
  148. }
  149. /*
  150. * Configures McPDM uplink, and downlink for audio.
  151. * This function should be called before omap_mcpdm_start.
  152. */
  153. static void omap_mcpdm_open_streams(struct omap_mcpdm *mcpdm)
  154. {
  155. u32 ctrl = omap_mcpdm_read(mcpdm, MCPDM_REG_CTRL);
  156. omap_mcpdm_write(mcpdm, MCPDM_REG_CTRL, ctrl | MCPDM_WD_EN);
  157. omap_mcpdm_write(mcpdm, MCPDM_REG_IRQENABLE_SET,
  158. MCPDM_DN_IRQ_EMPTY | MCPDM_DN_IRQ_FULL |
  159. MCPDM_UP_IRQ_EMPTY | MCPDM_UP_IRQ_FULL);
  160. /* Enable DN RX1/2 offset cancellation feature, if configured */
  161. if (mcpdm->dn_rx_offset) {
  162. u32 dn_offset = mcpdm->dn_rx_offset;
  163. omap_mcpdm_write(mcpdm, MCPDM_REG_DN_OFFSET, dn_offset);
  164. dn_offset |= (MCPDM_DN_OFST_RX1_EN | MCPDM_DN_OFST_RX2_EN);
  165. omap_mcpdm_write(mcpdm, MCPDM_REG_DN_OFFSET, dn_offset);
  166. }
  167. omap_mcpdm_write(mcpdm, MCPDM_REG_FIFO_CTRL_DN,
  168. mcpdm->config[SNDRV_PCM_STREAM_PLAYBACK].threshold);
  169. omap_mcpdm_write(mcpdm, MCPDM_REG_FIFO_CTRL_UP,
  170. mcpdm->config[SNDRV_PCM_STREAM_CAPTURE].threshold);
  171. omap_mcpdm_write(mcpdm, MCPDM_REG_DMAENABLE_SET,
  172. MCPDM_DMA_DN_ENABLE | MCPDM_DMA_UP_ENABLE);
  173. }
  174. /*
  175. * Cleans McPDM uplink, and downlink configuration.
  176. * This function should be called when the stream is closed.
  177. */
  178. static void omap_mcpdm_close_streams(struct omap_mcpdm *mcpdm)
  179. {
  180. /* Disable irq request generation for downlink */
  181. omap_mcpdm_write(mcpdm, MCPDM_REG_IRQENABLE_CLR,
  182. MCPDM_DN_IRQ_EMPTY | MCPDM_DN_IRQ_FULL);
  183. /* Disable DMA request generation for downlink */
  184. omap_mcpdm_write(mcpdm, MCPDM_REG_DMAENABLE_CLR, MCPDM_DMA_DN_ENABLE);
  185. /* Disable irq request generation for uplink */
  186. omap_mcpdm_write(mcpdm, MCPDM_REG_IRQENABLE_CLR,
  187. MCPDM_UP_IRQ_EMPTY | MCPDM_UP_IRQ_FULL);
  188. /* Disable DMA request generation for uplink */
  189. omap_mcpdm_write(mcpdm, MCPDM_REG_DMAENABLE_CLR, MCPDM_DMA_UP_ENABLE);
  190. /* Disable RX1/2 offset cancellation */
  191. if (mcpdm->dn_rx_offset)
  192. omap_mcpdm_write(mcpdm, MCPDM_REG_DN_OFFSET, 0);
  193. }
  194. static irqreturn_t omap_mcpdm_irq_handler(int irq, void *dev_id)
  195. {
  196. struct omap_mcpdm *mcpdm = dev_id;
  197. int irq_status;
  198. irq_status = omap_mcpdm_read(mcpdm, MCPDM_REG_IRQSTATUS);
  199. /* Acknowledge irq event */
  200. omap_mcpdm_write(mcpdm, MCPDM_REG_IRQSTATUS, irq_status);
  201. if (irq_status & MCPDM_DN_IRQ_FULL)
  202. dev_dbg(mcpdm->dev, "DN (playback) FIFO Full\n");
  203. if (irq_status & MCPDM_DN_IRQ_EMPTY)
  204. dev_dbg(mcpdm->dev, "DN (playback) FIFO Empty\n");
  205. if (irq_status & MCPDM_DN_IRQ)
  206. dev_dbg(mcpdm->dev, "DN (playback) write request\n");
  207. if (irq_status & MCPDM_UP_IRQ_FULL)
  208. dev_dbg(mcpdm->dev, "UP (capture) FIFO Full\n");
  209. if (irq_status & MCPDM_UP_IRQ_EMPTY)
  210. dev_dbg(mcpdm->dev, "UP (capture) FIFO Empty\n");
  211. if (irq_status & MCPDM_UP_IRQ)
  212. dev_dbg(mcpdm->dev, "UP (capture) write request\n");
  213. return IRQ_HANDLED;
  214. }
  215. static int omap_mcpdm_dai_startup(struct snd_pcm_substream *substream,
  216. struct snd_soc_dai *dai)
  217. {
  218. struct omap_mcpdm *mcpdm = snd_soc_dai_get_drvdata(dai);
  219. mutex_lock(&mcpdm->mutex);
  220. if (!dai->active)
  221. omap_mcpdm_open_streams(mcpdm);
  222. mutex_unlock(&mcpdm->mutex);
  223. return 0;
  224. }
  225. static void omap_mcpdm_dai_shutdown(struct snd_pcm_substream *substream,
  226. struct snd_soc_dai *dai)
  227. {
  228. struct omap_mcpdm *mcpdm = snd_soc_dai_get_drvdata(dai);
  229. int tx = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK);
  230. int stream1 = tx ? SNDRV_PCM_STREAM_PLAYBACK : SNDRV_PCM_STREAM_CAPTURE;
  231. int stream2 = tx ? SNDRV_PCM_STREAM_CAPTURE : SNDRV_PCM_STREAM_PLAYBACK;
  232. mutex_lock(&mcpdm->mutex);
  233. if (!dai->active) {
  234. if (omap_mcpdm_active(mcpdm)) {
  235. omap_mcpdm_stop(mcpdm);
  236. omap_mcpdm_close_streams(mcpdm);
  237. mcpdm->config[0].link_mask = 0;
  238. mcpdm->config[1].link_mask = 0;
  239. }
  240. }
  241. if (mcpdm->latency[stream2])
  242. pm_qos_update_request(&mcpdm->pm_qos_req,
  243. mcpdm->latency[stream2]);
  244. else if (mcpdm->latency[stream1])
  245. pm_qos_remove_request(&mcpdm->pm_qos_req);
  246. mcpdm->latency[stream1] = 0;
  247. mutex_unlock(&mcpdm->mutex);
  248. }
  249. static int omap_mcpdm_dai_hw_params(struct snd_pcm_substream *substream,
  250. struct snd_pcm_hw_params *params,
  251. struct snd_soc_dai *dai)
  252. {
  253. struct omap_mcpdm *mcpdm = snd_soc_dai_get_drvdata(dai);
  254. int stream = substream->stream;
  255. struct snd_dmaengine_dai_dma_data *dma_data;
  256. u32 threshold;
  257. int channels, latency;
  258. int link_mask = 0;
  259. channels = params_channels(params);
  260. switch (channels) {
  261. case 5:
  262. if (stream == SNDRV_PCM_STREAM_CAPTURE)
  263. /* up to 3 channels for capture */
  264. return -EINVAL;
  265. link_mask |= 1 << 4;
  266. /* fall through */
  267. case 4:
  268. if (stream == SNDRV_PCM_STREAM_CAPTURE)
  269. /* up to 3 channels for capture */
  270. return -EINVAL;
  271. link_mask |= 1 << 3;
  272. /* fall through */
  273. case 3:
  274. link_mask |= 1 << 2;
  275. /* fall through */
  276. case 2:
  277. link_mask |= 1 << 1;
  278. /* fall through */
  279. case 1:
  280. link_mask |= 1 << 0;
  281. break;
  282. default:
  283. /* unsupported number of channels */
  284. return -EINVAL;
  285. }
  286. dma_data = snd_soc_dai_get_dma_data(dai, substream);
  287. threshold = mcpdm->config[stream].threshold;
  288. /* Configure McPDM channels, and DMA packet size */
  289. if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
  290. link_mask <<= 3;
  291. /* If capture is not running assume a stereo stream to come */
  292. if (!mcpdm->config[!stream].link_mask)
  293. mcpdm->config[!stream].link_mask = 0x3;
  294. dma_data->maxburst =
  295. (MCPDM_DN_THRES_MAX - threshold) * channels;
  296. latency = threshold;
  297. } else {
  298. /* If playback is not running assume a stereo stream to come */
  299. if (!mcpdm->config[!stream].link_mask)
  300. mcpdm->config[!stream].link_mask = (0x3 << 3);
  301. dma_data->maxburst = threshold * channels;
  302. latency = (MCPDM_DN_THRES_MAX - threshold);
  303. }
  304. /*
  305. * The DMA must act to a DMA request within latency time (usec) to avoid
  306. * under/overflow
  307. */
  308. mcpdm->latency[stream] = latency * USEC_PER_SEC / params_rate(params);
  309. if (!mcpdm->latency[stream])
  310. mcpdm->latency[stream] = 10;
  311. /* Check if we need to restart McPDM with this stream */
  312. if (mcpdm->config[stream].link_mask &&
  313. mcpdm->config[stream].link_mask != link_mask)
  314. mcpdm->restart = true;
  315. mcpdm->config[stream].link_mask = link_mask;
  316. return 0;
  317. }
  318. static int omap_mcpdm_prepare(struct snd_pcm_substream *substream,
  319. struct snd_soc_dai *dai)
  320. {
  321. struct omap_mcpdm *mcpdm = snd_soc_dai_get_drvdata(dai);
  322. struct pm_qos_request *pm_qos_req = &mcpdm->pm_qos_req;
  323. int tx = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK);
  324. int stream1 = tx ? SNDRV_PCM_STREAM_PLAYBACK : SNDRV_PCM_STREAM_CAPTURE;
  325. int stream2 = tx ? SNDRV_PCM_STREAM_CAPTURE : SNDRV_PCM_STREAM_PLAYBACK;
  326. int latency = mcpdm->latency[stream2];
  327. /* Prevent omap hardware from hitting off between FIFO fills */
  328. if (!latency || mcpdm->latency[stream1] < latency)
  329. latency = mcpdm->latency[stream1];
  330. if (pm_qos_request_active(pm_qos_req))
  331. pm_qos_update_request(pm_qos_req, latency);
  332. else if (latency)
  333. pm_qos_add_request(pm_qos_req, PM_QOS_CPU_DMA_LATENCY, latency);
  334. if (!omap_mcpdm_active(mcpdm)) {
  335. omap_mcpdm_start(mcpdm);
  336. omap_mcpdm_reg_dump(mcpdm);
  337. } else if (mcpdm->restart) {
  338. omap_mcpdm_stop(mcpdm);
  339. omap_mcpdm_start(mcpdm);
  340. mcpdm->restart = false;
  341. omap_mcpdm_reg_dump(mcpdm);
  342. }
  343. return 0;
  344. }
  345. static const struct snd_soc_dai_ops omap_mcpdm_dai_ops = {
  346. .startup = omap_mcpdm_dai_startup,
  347. .shutdown = omap_mcpdm_dai_shutdown,
  348. .hw_params = omap_mcpdm_dai_hw_params,
  349. .prepare = omap_mcpdm_prepare,
  350. };
  351. static int omap_mcpdm_probe(struct snd_soc_dai *dai)
  352. {
  353. struct omap_mcpdm *mcpdm = snd_soc_dai_get_drvdata(dai);
  354. int ret;
  355. pm_runtime_enable(mcpdm->dev);
  356. /* Disable lines while request is ongoing */
  357. pm_runtime_get_sync(mcpdm->dev);
  358. omap_mcpdm_write(mcpdm, MCPDM_REG_CTRL, 0x00);
  359. ret = request_irq(mcpdm->irq, omap_mcpdm_irq_handler, 0, "McPDM",
  360. (void *)mcpdm);
  361. pm_runtime_put_sync(mcpdm->dev);
  362. if (ret) {
  363. dev_err(mcpdm->dev, "Request for IRQ failed\n");
  364. pm_runtime_disable(mcpdm->dev);
  365. }
  366. /* Configure McPDM threshold values */
  367. mcpdm->config[SNDRV_PCM_STREAM_PLAYBACK].threshold = 2;
  368. mcpdm->config[SNDRV_PCM_STREAM_CAPTURE].threshold =
  369. MCPDM_UP_THRES_MAX - 3;
  370. snd_soc_dai_init_dma_data(dai,
  371. &mcpdm->dma_data[SNDRV_PCM_STREAM_PLAYBACK],
  372. &mcpdm->dma_data[SNDRV_PCM_STREAM_CAPTURE]);
  373. return ret;
  374. }
  375. static int omap_mcpdm_remove(struct snd_soc_dai *dai)
  376. {
  377. struct omap_mcpdm *mcpdm = snd_soc_dai_get_drvdata(dai);
  378. free_irq(mcpdm->irq, (void *)mcpdm);
  379. pm_runtime_disable(mcpdm->dev);
  380. if (pm_qos_request_active(&mcpdm->pm_qos_req))
  381. pm_qos_remove_request(&mcpdm->pm_qos_req);
  382. return 0;
  383. }
  384. #ifdef CONFIG_PM_SLEEP
  385. static int omap_mcpdm_suspend(struct snd_soc_dai *dai)
  386. {
  387. struct omap_mcpdm *mcpdm = snd_soc_dai_get_drvdata(dai);
  388. if (dai->active) {
  389. omap_mcpdm_stop(mcpdm);
  390. omap_mcpdm_close_streams(mcpdm);
  391. }
  392. mcpdm->pm_active_count = 0;
  393. while (pm_runtime_active(mcpdm->dev)) {
  394. pm_runtime_put_sync(mcpdm->dev);
  395. mcpdm->pm_active_count++;
  396. }
  397. return 0;
  398. }
  399. static int omap_mcpdm_resume(struct snd_soc_dai *dai)
  400. {
  401. struct omap_mcpdm *mcpdm = snd_soc_dai_get_drvdata(dai);
  402. if (mcpdm->pm_active_count) {
  403. while (mcpdm->pm_active_count--)
  404. pm_runtime_get_sync(mcpdm->dev);
  405. if (dai->active) {
  406. omap_mcpdm_open_streams(mcpdm);
  407. omap_mcpdm_start(mcpdm);
  408. }
  409. }
  410. return 0;
  411. }
  412. #else
  413. #define omap_mcpdm_suspend NULL
  414. #define omap_mcpdm_resume NULL
  415. #endif
  416. #define OMAP_MCPDM_RATES (SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000)
  417. #define OMAP_MCPDM_FORMATS SNDRV_PCM_FMTBIT_S32_LE
  418. static struct snd_soc_dai_driver omap_mcpdm_dai = {
  419. .probe = omap_mcpdm_probe,
  420. .remove = omap_mcpdm_remove,
  421. .suspend = omap_mcpdm_suspend,
  422. .resume = omap_mcpdm_resume,
  423. .probe_order = SND_SOC_COMP_ORDER_LATE,
  424. .remove_order = SND_SOC_COMP_ORDER_EARLY,
  425. .playback = {
  426. .channels_min = 1,
  427. .channels_max = 5,
  428. .rates = OMAP_MCPDM_RATES,
  429. .formats = OMAP_MCPDM_FORMATS,
  430. .sig_bits = 24,
  431. },
  432. .capture = {
  433. .channels_min = 1,
  434. .channels_max = 3,
  435. .rates = OMAP_MCPDM_RATES,
  436. .formats = OMAP_MCPDM_FORMATS,
  437. .sig_bits = 24,
  438. },
  439. .ops = &omap_mcpdm_dai_ops,
  440. };
  441. static const struct snd_soc_component_driver omap_mcpdm_component = {
  442. .name = "omap-mcpdm",
  443. };
  444. void omap_mcpdm_configure_dn_offsets(struct snd_soc_pcm_runtime *rtd,
  445. u8 rx1, u8 rx2)
  446. {
  447. struct omap_mcpdm *mcpdm = snd_soc_dai_get_drvdata(rtd->cpu_dai);
  448. mcpdm->dn_rx_offset = MCPDM_DNOFST_RX1(rx1) | MCPDM_DNOFST_RX2(rx2);
  449. }
  450. EXPORT_SYMBOL_GPL(omap_mcpdm_configure_dn_offsets);
  451. static int asoc_mcpdm_probe(struct platform_device *pdev)
  452. {
  453. struct omap_mcpdm *mcpdm;
  454. struct resource *res;
  455. int ret;
  456. mcpdm = devm_kzalloc(&pdev->dev, sizeof(struct omap_mcpdm), GFP_KERNEL);
  457. if (!mcpdm)
  458. return -ENOMEM;
  459. platform_set_drvdata(pdev, mcpdm);
  460. mutex_init(&mcpdm->mutex);
  461. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dma");
  462. if (res == NULL)
  463. return -ENOMEM;
  464. mcpdm->dma_data[0].addr = res->start + MCPDM_REG_DN_DATA;
  465. mcpdm->dma_data[1].addr = res->start + MCPDM_REG_UP_DATA;
  466. mcpdm->dma_data[0].filter_data = "dn_link";
  467. mcpdm->dma_data[1].filter_data = "up_link";
  468. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mpu");
  469. mcpdm->io_base = devm_ioremap_resource(&pdev->dev, res);
  470. if (IS_ERR(mcpdm->io_base))
  471. return PTR_ERR(mcpdm->io_base);
  472. mcpdm->irq = platform_get_irq(pdev, 0);
  473. if (mcpdm->irq < 0)
  474. return mcpdm->irq;
  475. mcpdm->dev = &pdev->dev;
  476. ret = devm_snd_soc_register_component(&pdev->dev,
  477. &omap_mcpdm_component,
  478. &omap_mcpdm_dai, 1);
  479. if (ret)
  480. return ret;
  481. return sdma_pcm_platform_register(&pdev->dev, "dn_link", "up_link");
  482. }
  483. static const struct of_device_id omap_mcpdm_of_match[] = {
  484. { .compatible = "ti,omap4-mcpdm", },
  485. { }
  486. };
  487. MODULE_DEVICE_TABLE(of, omap_mcpdm_of_match);
  488. static struct platform_driver asoc_mcpdm_driver = {
  489. .driver = {
  490. .name = "omap-mcpdm",
  491. .of_match_table = omap_mcpdm_of_match,
  492. },
  493. .probe = asoc_mcpdm_probe,
  494. };
  495. module_platform_driver(asoc_mcpdm_driver);
  496. MODULE_ALIAS("platform:omap-mcpdm");
  497. MODULE_AUTHOR("Misael Lopez Cruz <misael.lopez@ti.com>");
  498. MODULE_DESCRIPTION("OMAP PDM SoC Interface");
  499. MODULE_LICENSE("GPL");