omap-mcbsp.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  1. /*
  2. * omap-mcbsp.c -- OMAP ALSA SoC DAI driver using McBSP port
  3. *
  4. * Copyright (C) 2008 Nokia Corporation
  5. *
  6. * Contact: Jarkko Nikula <jhnikula@gmail.com>
  7. * Peter Ujfalusi <peter.ujfalusi@nokia.com>
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * version 2 as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  21. * 02110-1301 USA
  22. *
  23. */
  24. #include <linux/init.h>
  25. #include <linux/module.h>
  26. #include <linux/device.h>
  27. #include <sound/core.h>
  28. #include <sound/pcm.h>
  29. #include <sound/pcm_params.h>
  30. #include <sound/initval.h>
  31. #include <sound/soc.h>
  32. #include <mach/control.h>
  33. #include <mach/dma.h>
  34. #include <mach/mcbsp.h>
  35. #include "omap-mcbsp.h"
  36. #include "omap-pcm.h"
  37. #define OMAP_MCBSP_RATES (SNDRV_PCM_RATE_8000_96000)
  38. struct omap_mcbsp_data {
  39. unsigned int bus_id;
  40. struct omap_mcbsp_reg_cfg regs;
  41. unsigned int fmt;
  42. /*
  43. * Flags indicating is the bus already activated and configured by
  44. * another substream
  45. */
  46. int active;
  47. int configured;
  48. };
  49. #define to_mcbsp(priv) container_of((priv), struct omap_mcbsp_data, bus_id)
  50. static struct omap_mcbsp_data mcbsp_data[NUM_LINKS];
  51. /*
  52. * Stream DMA parameters. DMA request line and port address are set runtime
  53. * since they are different between OMAP1 and later OMAPs
  54. */
  55. static struct omap_pcm_dma_data omap_mcbsp_dai_dma_params[NUM_LINKS][2];
  56. #if defined(CONFIG_ARCH_OMAP15XX) || defined(CONFIG_ARCH_OMAP16XX)
  57. static const int omap1_dma_reqs[][2] = {
  58. { OMAP_DMA_MCBSP1_TX, OMAP_DMA_MCBSP1_RX },
  59. { OMAP_DMA_MCBSP2_TX, OMAP_DMA_MCBSP2_RX },
  60. { OMAP_DMA_MCBSP3_TX, OMAP_DMA_MCBSP3_RX },
  61. };
  62. static const unsigned long omap1_mcbsp_port[][2] = {
  63. { OMAP1510_MCBSP1_BASE + OMAP_MCBSP_REG_DXR1,
  64. OMAP1510_MCBSP1_BASE + OMAP_MCBSP_REG_DRR1 },
  65. { OMAP1510_MCBSP2_BASE + OMAP_MCBSP_REG_DXR1,
  66. OMAP1510_MCBSP2_BASE + OMAP_MCBSP_REG_DRR1 },
  67. { OMAP1510_MCBSP3_BASE + OMAP_MCBSP_REG_DXR1,
  68. OMAP1510_MCBSP3_BASE + OMAP_MCBSP_REG_DRR1 },
  69. };
  70. #else
  71. static const int omap1_dma_reqs[][2] = {};
  72. static const unsigned long omap1_mcbsp_port[][2] = {};
  73. #endif
  74. #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
  75. static const int omap24xx_dma_reqs[][2] = {
  76. { OMAP24XX_DMA_MCBSP1_TX, OMAP24XX_DMA_MCBSP1_RX },
  77. { OMAP24XX_DMA_MCBSP2_TX, OMAP24XX_DMA_MCBSP2_RX },
  78. #if defined(CONFIG_ARCH_OMAP2430) || defined(CONFIG_ARCH_OMAP34XX)
  79. { OMAP24XX_DMA_MCBSP3_TX, OMAP24XX_DMA_MCBSP3_RX },
  80. { OMAP24XX_DMA_MCBSP4_TX, OMAP24XX_DMA_MCBSP4_RX },
  81. { OMAP24XX_DMA_MCBSP5_TX, OMAP24XX_DMA_MCBSP5_RX },
  82. #endif
  83. };
  84. #else
  85. static const int omap24xx_dma_reqs[][2] = {};
  86. #endif
  87. #if defined(CONFIG_ARCH_OMAP2420)
  88. static const unsigned long omap2420_mcbsp_port[][2] = {
  89. { OMAP24XX_MCBSP1_BASE + OMAP_MCBSP_REG_DXR1,
  90. OMAP24XX_MCBSP1_BASE + OMAP_MCBSP_REG_DRR1 },
  91. { OMAP24XX_MCBSP2_BASE + OMAP_MCBSP_REG_DXR1,
  92. OMAP24XX_MCBSP2_BASE + OMAP_MCBSP_REG_DRR1 },
  93. };
  94. #else
  95. static const unsigned long omap2420_mcbsp_port[][2] = {};
  96. #endif
  97. #if defined(CONFIG_ARCH_OMAP2430)
  98. static const unsigned long omap2430_mcbsp_port[][2] = {
  99. { OMAP24XX_MCBSP1_BASE + OMAP_MCBSP_REG_DXR,
  100. OMAP24XX_MCBSP1_BASE + OMAP_MCBSP_REG_DRR },
  101. { OMAP24XX_MCBSP2_BASE + OMAP_MCBSP_REG_DXR,
  102. OMAP24XX_MCBSP2_BASE + OMAP_MCBSP_REG_DRR },
  103. { OMAP2430_MCBSP3_BASE + OMAP_MCBSP_REG_DXR,
  104. OMAP2430_MCBSP3_BASE + OMAP_MCBSP_REG_DRR },
  105. { OMAP2430_MCBSP4_BASE + OMAP_MCBSP_REG_DXR,
  106. OMAP2430_MCBSP4_BASE + OMAP_MCBSP_REG_DRR },
  107. { OMAP2430_MCBSP5_BASE + OMAP_MCBSP_REG_DXR,
  108. OMAP2430_MCBSP5_BASE + OMAP_MCBSP_REG_DRR },
  109. };
  110. #else
  111. static const unsigned long omap2430_mcbsp_port[][2] = {};
  112. #endif
  113. #if defined(CONFIG_ARCH_OMAP34XX)
  114. static const unsigned long omap34xx_mcbsp_port[][2] = {
  115. { OMAP34XX_MCBSP1_BASE + OMAP_MCBSP_REG_DXR,
  116. OMAP34XX_MCBSP1_BASE + OMAP_MCBSP_REG_DRR },
  117. { OMAP34XX_MCBSP2_BASE + OMAP_MCBSP_REG_DXR,
  118. OMAP34XX_MCBSP2_BASE + OMAP_MCBSP_REG_DRR },
  119. { OMAP34XX_MCBSP3_BASE + OMAP_MCBSP_REG_DXR,
  120. OMAP34XX_MCBSP3_BASE + OMAP_MCBSP_REG_DRR },
  121. { OMAP34XX_MCBSP4_BASE + OMAP_MCBSP_REG_DXR,
  122. OMAP34XX_MCBSP4_BASE + OMAP_MCBSP_REG_DRR },
  123. { OMAP34XX_MCBSP5_BASE + OMAP_MCBSP_REG_DXR,
  124. OMAP34XX_MCBSP5_BASE + OMAP_MCBSP_REG_DRR },
  125. };
  126. #else
  127. static const unsigned long omap34xx_mcbsp_port[][2] = {};
  128. #endif
  129. static void omap_mcbsp_set_threshold(struct snd_pcm_substream *substream)
  130. {
  131. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  132. struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
  133. struct omap_mcbsp_data *mcbsp_data = to_mcbsp(cpu_dai->private_data);
  134. int dma_op_mode = omap_mcbsp_get_dma_op_mode(mcbsp_data->bus_id);
  135. int samples;
  136. /* TODO: Currently, MODE_ELEMENT == MODE_FRAME */
  137. if (dma_op_mode == MCBSP_DMA_MODE_THRESHOLD)
  138. samples = snd_pcm_lib_period_bytes(substream) >> 1;
  139. else
  140. samples = 1;
  141. /* Configure McBSP internal buffer usage */
  142. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  143. omap_mcbsp_set_tx_threshold(mcbsp_data->bus_id, samples - 1);
  144. else
  145. omap_mcbsp_set_rx_threshold(mcbsp_data->bus_id, samples - 1);
  146. }
  147. static int omap_mcbsp_dai_startup(struct snd_pcm_substream *substream,
  148. struct snd_soc_dai *dai)
  149. {
  150. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  151. struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
  152. struct omap_mcbsp_data *mcbsp_data = to_mcbsp(cpu_dai->private_data);
  153. int bus_id = mcbsp_data->bus_id;
  154. int err = 0;
  155. if (!cpu_dai->active)
  156. err = omap_mcbsp_request(bus_id);
  157. if (cpu_is_omap343x()) {
  158. int dma_op_mode = omap_mcbsp_get_dma_op_mode(bus_id);
  159. int max_period;
  160. /*
  161. * McBSP2 in OMAP3 has 1024 * 32-bit internal audio buffer.
  162. * Set constraint for minimum buffer size to the same than FIFO
  163. * size in order to avoid underruns in playback startup because
  164. * HW is keeping the DMA request active until FIFO is filled.
  165. */
  166. if (bus_id == 1)
  167. snd_pcm_hw_constraint_minmax(substream->runtime,
  168. SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
  169. 4096, UINT_MAX);
  170. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  171. max_period = omap_mcbsp_get_max_tx_threshold(bus_id);
  172. else
  173. max_period = omap_mcbsp_get_max_rx_threshold(bus_id);
  174. max_period++;
  175. max_period <<= 1;
  176. if (dma_op_mode == MCBSP_DMA_MODE_THRESHOLD)
  177. snd_pcm_hw_constraint_minmax(substream->runtime,
  178. SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
  179. 32, max_period);
  180. }
  181. return err;
  182. }
  183. static void omap_mcbsp_dai_shutdown(struct snd_pcm_substream *substream,
  184. struct snd_soc_dai *dai)
  185. {
  186. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  187. struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
  188. struct omap_mcbsp_data *mcbsp_data = to_mcbsp(cpu_dai->private_data);
  189. if (!cpu_dai->active) {
  190. omap_mcbsp_free(mcbsp_data->bus_id);
  191. mcbsp_data->configured = 0;
  192. }
  193. }
  194. static int omap_mcbsp_dai_trigger(struct snd_pcm_substream *substream, int cmd,
  195. struct snd_soc_dai *dai)
  196. {
  197. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  198. struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
  199. struct omap_mcbsp_data *mcbsp_data = to_mcbsp(cpu_dai->private_data);
  200. int err = 0, play = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK);
  201. switch (cmd) {
  202. case SNDRV_PCM_TRIGGER_START:
  203. case SNDRV_PCM_TRIGGER_RESUME:
  204. case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  205. mcbsp_data->active++;
  206. omap_mcbsp_start(mcbsp_data->bus_id, play, !play);
  207. /* Make sure data transfer is frame synchronized */
  208. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  209. omap_mcbsp_xmit_enable(mcbsp_data->bus_id, 1);
  210. else
  211. omap_mcbsp_recv_enable(mcbsp_data->bus_id, 1);
  212. break;
  213. case SNDRV_PCM_TRIGGER_STOP:
  214. case SNDRV_PCM_TRIGGER_SUSPEND:
  215. case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  216. omap_mcbsp_stop(mcbsp_data->bus_id, play, !play);
  217. mcbsp_data->active--;
  218. break;
  219. default:
  220. err = -EINVAL;
  221. }
  222. return err;
  223. }
  224. static int omap_mcbsp_dai_hw_params(struct snd_pcm_substream *substream,
  225. struct snd_pcm_hw_params *params,
  226. struct snd_soc_dai *dai)
  227. {
  228. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  229. struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
  230. struct omap_mcbsp_data *mcbsp_data = to_mcbsp(cpu_dai->private_data);
  231. struct omap_mcbsp_reg_cfg *regs = &mcbsp_data->regs;
  232. int dma, bus_id = mcbsp_data->bus_id, id = cpu_dai->id;
  233. int wlen, channels, wpf, sync_mode = OMAP_DMA_SYNC_ELEMENT;
  234. unsigned long port;
  235. unsigned int format;
  236. if (cpu_class_is_omap1()) {
  237. dma = omap1_dma_reqs[bus_id][substream->stream];
  238. port = omap1_mcbsp_port[bus_id][substream->stream];
  239. } else if (cpu_is_omap2420()) {
  240. dma = omap24xx_dma_reqs[bus_id][substream->stream];
  241. port = omap2420_mcbsp_port[bus_id][substream->stream];
  242. } else if (cpu_is_omap2430()) {
  243. dma = omap24xx_dma_reqs[bus_id][substream->stream];
  244. port = omap2430_mcbsp_port[bus_id][substream->stream];
  245. } else if (cpu_is_omap343x()) {
  246. dma = omap24xx_dma_reqs[bus_id][substream->stream];
  247. port = omap34xx_mcbsp_port[bus_id][substream->stream];
  248. omap_mcbsp_dai_dma_params[id][substream->stream].set_threshold =
  249. omap_mcbsp_set_threshold;
  250. /* TODO: Currently, MODE_ELEMENT == MODE_FRAME */
  251. if (omap_mcbsp_get_dma_op_mode(bus_id) ==
  252. MCBSP_DMA_MODE_THRESHOLD)
  253. sync_mode = OMAP_DMA_SYNC_FRAME;
  254. } else {
  255. return -ENODEV;
  256. }
  257. omap_mcbsp_dai_dma_params[id][substream->stream].name =
  258. substream->stream ? "Audio Capture" : "Audio Playback";
  259. omap_mcbsp_dai_dma_params[id][substream->stream].dma_req = dma;
  260. omap_mcbsp_dai_dma_params[id][substream->stream].port_addr = port;
  261. omap_mcbsp_dai_dma_params[id][substream->stream].sync_mode = sync_mode;
  262. cpu_dai->dma_data = &omap_mcbsp_dai_dma_params[id][substream->stream];
  263. if (mcbsp_data->configured) {
  264. /* McBSP already configured by another stream */
  265. return 0;
  266. }
  267. format = mcbsp_data->fmt & SND_SOC_DAIFMT_FORMAT_MASK;
  268. wpf = channels = params_channels(params);
  269. switch (channels) {
  270. case 2:
  271. if (format == SND_SOC_DAIFMT_I2S) {
  272. /* Use dual-phase frames */
  273. regs->rcr2 |= RPHASE;
  274. regs->xcr2 |= XPHASE;
  275. /* Set 1 word per (McBSP) frame for phase1 and phase2 */
  276. wpf--;
  277. regs->rcr2 |= RFRLEN2(wpf - 1);
  278. regs->xcr2 |= XFRLEN2(wpf - 1);
  279. }
  280. case 1:
  281. case 4:
  282. /* Set word per (McBSP) frame for phase1 */
  283. regs->rcr1 |= RFRLEN1(wpf - 1);
  284. regs->xcr1 |= XFRLEN1(wpf - 1);
  285. break;
  286. default:
  287. /* Unsupported number of channels */
  288. return -EINVAL;
  289. }
  290. switch (params_format(params)) {
  291. case SNDRV_PCM_FORMAT_S16_LE:
  292. /* Set word lengths */
  293. wlen = 16;
  294. regs->rcr2 |= RWDLEN2(OMAP_MCBSP_WORD_16);
  295. regs->rcr1 |= RWDLEN1(OMAP_MCBSP_WORD_16);
  296. regs->xcr2 |= XWDLEN2(OMAP_MCBSP_WORD_16);
  297. regs->xcr1 |= XWDLEN1(OMAP_MCBSP_WORD_16);
  298. break;
  299. default:
  300. /* Unsupported PCM format */
  301. return -EINVAL;
  302. }
  303. /* Set FS period and length in terms of bit clock periods */
  304. switch (format) {
  305. case SND_SOC_DAIFMT_I2S:
  306. regs->srgr2 |= FPER(wlen * channels - 1);
  307. regs->srgr1 |= FWID(wlen - 1);
  308. break;
  309. case SND_SOC_DAIFMT_DSP_A:
  310. case SND_SOC_DAIFMT_DSP_B:
  311. regs->srgr2 |= FPER(wlen * channels - 1);
  312. regs->srgr1 |= FWID(0);
  313. break;
  314. }
  315. omap_mcbsp_config(bus_id, &mcbsp_data->regs);
  316. mcbsp_data->configured = 1;
  317. return 0;
  318. }
  319. /*
  320. * This must be called before _set_clkdiv and _set_sysclk since McBSP register
  321. * cache is initialized here
  322. */
  323. static int omap_mcbsp_dai_set_dai_fmt(struct snd_soc_dai *cpu_dai,
  324. unsigned int fmt)
  325. {
  326. struct omap_mcbsp_data *mcbsp_data = to_mcbsp(cpu_dai->private_data);
  327. struct omap_mcbsp_reg_cfg *regs = &mcbsp_data->regs;
  328. unsigned int temp_fmt = fmt;
  329. if (mcbsp_data->configured)
  330. return 0;
  331. mcbsp_data->fmt = fmt;
  332. memset(regs, 0, sizeof(*regs));
  333. /* Generic McBSP register settings */
  334. regs->spcr2 |= XINTM(3) | FREE;
  335. regs->spcr1 |= RINTM(3);
  336. /* RFIG and XFIG are not defined in 34xx */
  337. if (!cpu_is_omap34xx()) {
  338. regs->rcr2 |= RFIG;
  339. regs->xcr2 |= XFIG;
  340. }
  341. if (cpu_is_omap2430() || cpu_is_omap34xx()) {
  342. regs->xccr = DXENDLY(1) | XDMAEN | XDISABLE;
  343. regs->rccr = RFULL_CYCLE | RDMAEN | RDISABLE;
  344. }
  345. switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  346. case SND_SOC_DAIFMT_I2S:
  347. /* 1-bit data delay */
  348. regs->rcr2 |= RDATDLY(1);
  349. regs->xcr2 |= XDATDLY(1);
  350. break;
  351. case SND_SOC_DAIFMT_DSP_A:
  352. /* 1-bit data delay */
  353. regs->rcr2 |= RDATDLY(1);
  354. regs->xcr2 |= XDATDLY(1);
  355. /* Invert FS polarity configuration */
  356. temp_fmt ^= SND_SOC_DAIFMT_NB_IF;
  357. break;
  358. case SND_SOC_DAIFMT_DSP_B:
  359. /* 0-bit data delay */
  360. regs->rcr2 |= RDATDLY(0);
  361. regs->xcr2 |= XDATDLY(0);
  362. /* Invert FS polarity configuration */
  363. temp_fmt ^= SND_SOC_DAIFMT_NB_IF;
  364. break;
  365. default:
  366. /* Unsupported data format */
  367. return -EINVAL;
  368. }
  369. switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  370. case SND_SOC_DAIFMT_CBS_CFS:
  371. /* McBSP master. Set FS and bit clocks as outputs */
  372. regs->pcr0 |= FSXM | FSRM |
  373. CLKXM | CLKRM;
  374. /* Sample rate generator drives the FS */
  375. regs->srgr2 |= FSGM;
  376. break;
  377. case SND_SOC_DAIFMT_CBM_CFM:
  378. /* McBSP slave */
  379. break;
  380. default:
  381. /* Unsupported master/slave configuration */
  382. return -EINVAL;
  383. }
  384. /* Set bit clock (CLKX/CLKR) and FS polarities */
  385. switch (temp_fmt & SND_SOC_DAIFMT_INV_MASK) {
  386. case SND_SOC_DAIFMT_NB_NF:
  387. /*
  388. * Normal BCLK + FS.
  389. * FS active low. TX data driven on falling edge of bit clock
  390. * and RX data sampled on rising edge of bit clock.
  391. */
  392. regs->pcr0 |= FSXP | FSRP |
  393. CLKXP | CLKRP;
  394. break;
  395. case SND_SOC_DAIFMT_NB_IF:
  396. regs->pcr0 |= CLKXP | CLKRP;
  397. break;
  398. case SND_SOC_DAIFMT_IB_NF:
  399. regs->pcr0 |= FSXP | FSRP;
  400. break;
  401. case SND_SOC_DAIFMT_IB_IF:
  402. break;
  403. default:
  404. return -EINVAL;
  405. }
  406. return 0;
  407. }
  408. static int omap_mcbsp_dai_set_clkdiv(struct snd_soc_dai *cpu_dai,
  409. int div_id, int div)
  410. {
  411. struct omap_mcbsp_data *mcbsp_data = to_mcbsp(cpu_dai->private_data);
  412. struct omap_mcbsp_reg_cfg *regs = &mcbsp_data->regs;
  413. if (div_id != OMAP_MCBSP_CLKGDV)
  414. return -ENODEV;
  415. regs->srgr1 |= CLKGDV(div - 1);
  416. return 0;
  417. }
  418. static int omap_mcbsp_dai_set_clks_src(struct omap_mcbsp_data *mcbsp_data,
  419. int clk_id)
  420. {
  421. int sel_bit;
  422. u16 reg, reg_devconf1 = OMAP243X_CONTROL_DEVCONF1;
  423. if (cpu_class_is_omap1()) {
  424. /* OMAP1's can use only external source clock */
  425. if (unlikely(clk_id == OMAP_MCBSP_SYSCLK_CLKS_FCLK))
  426. return -EINVAL;
  427. else
  428. return 0;
  429. }
  430. if (cpu_is_omap2420() && mcbsp_data->bus_id > 1)
  431. return -EINVAL;
  432. if (cpu_is_omap343x())
  433. reg_devconf1 = OMAP343X_CONTROL_DEVCONF1;
  434. switch (mcbsp_data->bus_id) {
  435. case 0:
  436. reg = OMAP2_CONTROL_DEVCONF0;
  437. sel_bit = 2;
  438. break;
  439. case 1:
  440. reg = OMAP2_CONTROL_DEVCONF0;
  441. sel_bit = 6;
  442. break;
  443. case 2:
  444. reg = reg_devconf1;
  445. sel_bit = 0;
  446. break;
  447. case 3:
  448. reg = reg_devconf1;
  449. sel_bit = 2;
  450. break;
  451. case 4:
  452. reg = reg_devconf1;
  453. sel_bit = 4;
  454. break;
  455. default:
  456. return -EINVAL;
  457. }
  458. if (clk_id == OMAP_MCBSP_SYSCLK_CLKS_FCLK)
  459. omap_ctrl_writel(omap_ctrl_readl(reg) & ~(1 << sel_bit), reg);
  460. else
  461. omap_ctrl_writel(omap_ctrl_readl(reg) | (1 << sel_bit), reg);
  462. return 0;
  463. }
  464. static int omap_mcbsp_dai_set_dai_sysclk(struct snd_soc_dai *cpu_dai,
  465. int clk_id, unsigned int freq,
  466. int dir)
  467. {
  468. struct omap_mcbsp_data *mcbsp_data = to_mcbsp(cpu_dai->private_data);
  469. struct omap_mcbsp_reg_cfg *regs = &mcbsp_data->regs;
  470. int err = 0;
  471. switch (clk_id) {
  472. case OMAP_MCBSP_SYSCLK_CLK:
  473. regs->srgr2 |= CLKSM;
  474. break;
  475. case OMAP_MCBSP_SYSCLK_CLKS_FCLK:
  476. case OMAP_MCBSP_SYSCLK_CLKS_EXT:
  477. err = omap_mcbsp_dai_set_clks_src(mcbsp_data, clk_id);
  478. break;
  479. case OMAP_MCBSP_SYSCLK_CLKX_EXT:
  480. regs->srgr2 |= CLKSM;
  481. case OMAP_MCBSP_SYSCLK_CLKR_EXT:
  482. regs->pcr0 |= SCLKME;
  483. break;
  484. default:
  485. err = -ENODEV;
  486. }
  487. return err;
  488. }
  489. static struct snd_soc_dai_ops omap_mcbsp_dai_ops = {
  490. .startup = omap_mcbsp_dai_startup,
  491. .shutdown = omap_mcbsp_dai_shutdown,
  492. .trigger = omap_mcbsp_dai_trigger,
  493. .hw_params = omap_mcbsp_dai_hw_params,
  494. .set_fmt = omap_mcbsp_dai_set_dai_fmt,
  495. .set_clkdiv = omap_mcbsp_dai_set_clkdiv,
  496. .set_sysclk = omap_mcbsp_dai_set_dai_sysclk,
  497. };
  498. #define OMAP_MCBSP_DAI_BUILDER(link_id) \
  499. { \
  500. .name = "omap-mcbsp-dai-"#link_id, \
  501. .id = (link_id), \
  502. .playback = { \
  503. .channels_min = 1, \
  504. .channels_max = 4, \
  505. .rates = OMAP_MCBSP_RATES, \
  506. .formats = SNDRV_PCM_FMTBIT_S16_LE, \
  507. }, \
  508. .capture = { \
  509. .channels_min = 1, \
  510. .channels_max = 4, \
  511. .rates = OMAP_MCBSP_RATES, \
  512. .formats = SNDRV_PCM_FMTBIT_S16_LE, \
  513. }, \
  514. .ops = &omap_mcbsp_dai_ops, \
  515. .private_data = &mcbsp_data[(link_id)].bus_id, \
  516. }
  517. struct snd_soc_dai omap_mcbsp_dai[] = {
  518. OMAP_MCBSP_DAI_BUILDER(0),
  519. OMAP_MCBSP_DAI_BUILDER(1),
  520. #if NUM_LINKS >= 3
  521. OMAP_MCBSP_DAI_BUILDER(2),
  522. #endif
  523. #if NUM_LINKS == 5
  524. OMAP_MCBSP_DAI_BUILDER(3),
  525. OMAP_MCBSP_DAI_BUILDER(4),
  526. #endif
  527. };
  528. EXPORT_SYMBOL_GPL(omap_mcbsp_dai);
  529. static int __init snd_omap_mcbsp_init(void)
  530. {
  531. return snd_soc_register_dais(omap_mcbsp_dai,
  532. ARRAY_SIZE(omap_mcbsp_dai));
  533. }
  534. module_init(snd_omap_mcbsp_init);
  535. static void __exit snd_omap_mcbsp_exit(void)
  536. {
  537. snd_soc_unregister_dais(omap_mcbsp_dai, ARRAY_SIZE(omap_mcbsp_dai));
  538. }
  539. module_exit(snd_omap_mcbsp_exit);
  540. MODULE_AUTHOR("Jarkko Nikula <jhnikula@gmail.com>");
  541. MODULE_DESCRIPTION("OMAP I2S SoC Interface");
  542. MODULE_LICENSE("GPL");