omap-mcbsp.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600
  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 samples = snd_pcm_lib_period_bytes(substream) >> 1;
  135. /* Configure McBSP internal buffer usage */
  136. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  137. omap_mcbsp_set_tx_threshold(mcbsp_data->bus_id, samples - 1);
  138. else
  139. omap_mcbsp_set_rx_threshold(mcbsp_data->bus_id, samples - 1);
  140. }
  141. static int omap_mcbsp_dai_startup(struct snd_pcm_substream *substream,
  142. struct snd_soc_dai *dai)
  143. {
  144. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  145. struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
  146. struct omap_mcbsp_data *mcbsp_data = to_mcbsp(cpu_dai->private_data);
  147. int bus_id = mcbsp_data->bus_id;
  148. int err = 0;
  149. if (!cpu_dai->active)
  150. err = omap_mcbsp_request(bus_id);
  151. if (cpu_is_omap343x()) {
  152. int max_period;
  153. /*
  154. * McBSP2 in OMAP3 has 1024 * 32-bit internal audio buffer.
  155. * Set constraint for minimum buffer size to the same than FIFO
  156. * size in order to avoid underruns in playback startup because
  157. * HW is keeping the DMA request active until FIFO is filled.
  158. */
  159. if (bus_id == 1)
  160. snd_pcm_hw_constraint_minmax(substream->runtime,
  161. SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
  162. 4096, UINT_MAX);
  163. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  164. max_period = omap_mcbsp_get_max_tx_threshold(bus_id);
  165. else
  166. max_period = omap_mcbsp_get_max_rx_threshold(bus_id);
  167. max_period++;
  168. max_period <<= 1;
  169. snd_pcm_hw_constraint_minmax(substream->runtime,
  170. SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
  171. 32, max_period);
  172. }
  173. return err;
  174. }
  175. static void omap_mcbsp_dai_shutdown(struct snd_pcm_substream *substream,
  176. struct snd_soc_dai *dai)
  177. {
  178. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  179. struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
  180. struct omap_mcbsp_data *mcbsp_data = to_mcbsp(cpu_dai->private_data);
  181. if (!cpu_dai->active) {
  182. omap_mcbsp_free(mcbsp_data->bus_id);
  183. mcbsp_data->configured = 0;
  184. }
  185. }
  186. static int omap_mcbsp_dai_trigger(struct snd_pcm_substream *substream, int cmd,
  187. struct snd_soc_dai *dai)
  188. {
  189. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  190. struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
  191. struct omap_mcbsp_data *mcbsp_data = to_mcbsp(cpu_dai->private_data);
  192. int err = 0, play = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK);
  193. switch (cmd) {
  194. case SNDRV_PCM_TRIGGER_START:
  195. case SNDRV_PCM_TRIGGER_RESUME:
  196. case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  197. mcbsp_data->active++;
  198. omap_mcbsp_start(mcbsp_data->bus_id, play, !play);
  199. /* Make sure data transfer is frame synchronized */
  200. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  201. omap_mcbsp_xmit_enable(mcbsp_data->bus_id, 1);
  202. else
  203. omap_mcbsp_recv_enable(mcbsp_data->bus_id, 1);
  204. break;
  205. case SNDRV_PCM_TRIGGER_STOP:
  206. case SNDRV_PCM_TRIGGER_SUSPEND:
  207. case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  208. omap_mcbsp_stop(mcbsp_data->bus_id, play, !play);
  209. mcbsp_data->active--;
  210. break;
  211. default:
  212. err = -EINVAL;
  213. }
  214. return err;
  215. }
  216. static int omap_mcbsp_dai_hw_params(struct snd_pcm_substream *substream,
  217. struct snd_pcm_hw_params *params,
  218. struct snd_soc_dai *dai)
  219. {
  220. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  221. struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
  222. struct omap_mcbsp_data *mcbsp_data = to_mcbsp(cpu_dai->private_data);
  223. struct omap_mcbsp_reg_cfg *regs = &mcbsp_data->regs;
  224. int dma, bus_id = mcbsp_data->bus_id, id = cpu_dai->id;
  225. int wlen, channels, wpf, sync_mode = OMAP_DMA_SYNC_ELEMENT;
  226. unsigned long port;
  227. unsigned int format;
  228. if (cpu_class_is_omap1()) {
  229. dma = omap1_dma_reqs[bus_id][substream->stream];
  230. port = omap1_mcbsp_port[bus_id][substream->stream];
  231. } else if (cpu_is_omap2420()) {
  232. dma = omap24xx_dma_reqs[bus_id][substream->stream];
  233. port = omap2420_mcbsp_port[bus_id][substream->stream];
  234. } else if (cpu_is_omap2430()) {
  235. dma = omap24xx_dma_reqs[bus_id][substream->stream];
  236. port = omap2430_mcbsp_port[bus_id][substream->stream];
  237. } else if (cpu_is_omap343x()) {
  238. dma = omap24xx_dma_reqs[bus_id][substream->stream];
  239. port = omap34xx_mcbsp_port[bus_id][substream->stream];
  240. omap_mcbsp_dai_dma_params[id][substream->stream].set_threshold =
  241. omap_mcbsp_set_threshold;
  242. sync_mode = OMAP_DMA_SYNC_FRAME;
  243. } else {
  244. return -ENODEV;
  245. }
  246. omap_mcbsp_dai_dma_params[id][substream->stream].name =
  247. substream->stream ? "Audio Capture" : "Audio Playback";
  248. omap_mcbsp_dai_dma_params[id][substream->stream].dma_req = dma;
  249. omap_mcbsp_dai_dma_params[id][substream->stream].port_addr = port;
  250. omap_mcbsp_dai_dma_params[id][substream->stream].sync_mode = sync_mode;
  251. cpu_dai->dma_data = &omap_mcbsp_dai_dma_params[id][substream->stream];
  252. if (mcbsp_data->configured) {
  253. /* McBSP already configured by another stream */
  254. return 0;
  255. }
  256. format = mcbsp_data->fmt & SND_SOC_DAIFMT_FORMAT_MASK;
  257. wpf = channels = params_channels(params);
  258. switch (channels) {
  259. case 2:
  260. if (format == SND_SOC_DAIFMT_I2S) {
  261. /* Use dual-phase frames */
  262. regs->rcr2 |= RPHASE;
  263. regs->xcr2 |= XPHASE;
  264. /* Set 1 word per (McBSP) frame for phase1 and phase2 */
  265. wpf--;
  266. regs->rcr2 |= RFRLEN2(wpf - 1);
  267. regs->xcr2 |= XFRLEN2(wpf - 1);
  268. }
  269. case 1:
  270. case 4:
  271. /* Set word per (McBSP) frame for phase1 */
  272. regs->rcr1 |= RFRLEN1(wpf - 1);
  273. regs->xcr1 |= XFRLEN1(wpf - 1);
  274. break;
  275. default:
  276. /* Unsupported number of channels */
  277. return -EINVAL;
  278. }
  279. switch (params_format(params)) {
  280. case SNDRV_PCM_FORMAT_S16_LE:
  281. /* Set word lengths */
  282. wlen = 16;
  283. regs->rcr2 |= RWDLEN2(OMAP_MCBSP_WORD_16);
  284. regs->rcr1 |= RWDLEN1(OMAP_MCBSP_WORD_16);
  285. regs->xcr2 |= XWDLEN2(OMAP_MCBSP_WORD_16);
  286. regs->xcr1 |= XWDLEN1(OMAP_MCBSP_WORD_16);
  287. break;
  288. default:
  289. /* Unsupported PCM format */
  290. return -EINVAL;
  291. }
  292. /* Set FS period and length in terms of bit clock periods */
  293. switch (format) {
  294. case SND_SOC_DAIFMT_I2S:
  295. regs->srgr2 |= FPER(wlen * channels - 1);
  296. regs->srgr1 |= FWID(wlen - 1);
  297. break;
  298. case SND_SOC_DAIFMT_DSP_A:
  299. case SND_SOC_DAIFMT_DSP_B:
  300. regs->srgr2 |= FPER(wlen * channels - 1);
  301. regs->srgr1 |= FWID(0);
  302. break;
  303. }
  304. omap_mcbsp_config(bus_id, &mcbsp_data->regs);
  305. mcbsp_data->configured = 1;
  306. return 0;
  307. }
  308. /*
  309. * This must be called before _set_clkdiv and _set_sysclk since McBSP register
  310. * cache is initialized here
  311. */
  312. static int omap_mcbsp_dai_set_dai_fmt(struct snd_soc_dai *cpu_dai,
  313. unsigned int fmt)
  314. {
  315. struct omap_mcbsp_data *mcbsp_data = to_mcbsp(cpu_dai->private_data);
  316. struct omap_mcbsp_reg_cfg *regs = &mcbsp_data->regs;
  317. unsigned int temp_fmt = fmt;
  318. if (mcbsp_data->configured)
  319. return 0;
  320. mcbsp_data->fmt = fmt;
  321. memset(regs, 0, sizeof(*regs));
  322. /* Generic McBSP register settings */
  323. regs->spcr2 |= XINTM(3) | FREE;
  324. regs->spcr1 |= RINTM(3);
  325. /* RFIG and XFIG are not defined in 34xx */
  326. if (!cpu_is_omap34xx()) {
  327. regs->rcr2 |= RFIG;
  328. regs->xcr2 |= XFIG;
  329. }
  330. if (cpu_is_omap2430() || cpu_is_omap34xx()) {
  331. regs->xccr = DXENDLY(1) | XDMAEN;
  332. regs->rccr = RFULL_CYCLE | RDMAEN;
  333. }
  334. switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  335. case SND_SOC_DAIFMT_I2S:
  336. /* 1-bit data delay */
  337. regs->rcr2 |= RDATDLY(1);
  338. regs->xcr2 |= XDATDLY(1);
  339. regs->rccr |= RFULL_CYCLE | RDMAEN | RDISABLE;
  340. regs->xccr |= (DXENDLY(1) | XDMAEN | XDISABLE);
  341. break;
  342. case SND_SOC_DAIFMT_DSP_A:
  343. /* 1-bit data delay */
  344. regs->rcr2 |= RDATDLY(1);
  345. regs->xcr2 |= XDATDLY(1);
  346. regs->rccr |= RFULL_CYCLE | RDMAEN | RDISABLE;
  347. regs->xccr |= (DXENDLY(1) | XDMAEN | XDISABLE);
  348. /* Invert FS polarity configuration */
  349. temp_fmt ^= SND_SOC_DAIFMT_NB_IF;
  350. break;
  351. case SND_SOC_DAIFMT_DSP_B:
  352. /* 0-bit data delay */
  353. regs->rcr2 |= RDATDLY(0);
  354. regs->xcr2 |= XDATDLY(0);
  355. /* Invert FS polarity configuration */
  356. temp_fmt ^= SND_SOC_DAIFMT_NB_IF;
  357. break;
  358. default:
  359. /* Unsupported data format */
  360. return -EINVAL;
  361. }
  362. switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  363. case SND_SOC_DAIFMT_CBS_CFS:
  364. /* McBSP master. Set FS and bit clocks as outputs */
  365. regs->pcr0 |= FSXM | FSRM |
  366. CLKXM | CLKRM;
  367. /* Sample rate generator drives the FS */
  368. regs->srgr2 |= FSGM;
  369. break;
  370. case SND_SOC_DAIFMT_CBM_CFM:
  371. /* McBSP slave */
  372. break;
  373. default:
  374. /* Unsupported master/slave configuration */
  375. return -EINVAL;
  376. }
  377. /* Set bit clock (CLKX/CLKR) and FS polarities */
  378. switch (temp_fmt & SND_SOC_DAIFMT_INV_MASK) {
  379. case SND_SOC_DAIFMT_NB_NF:
  380. /*
  381. * Normal BCLK + FS.
  382. * FS active low. TX data driven on falling edge of bit clock
  383. * and RX data sampled on rising edge of bit clock.
  384. */
  385. regs->pcr0 |= FSXP | FSRP |
  386. CLKXP | CLKRP;
  387. break;
  388. case SND_SOC_DAIFMT_NB_IF:
  389. regs->pcr0 |= CLKXP | CLKRP;
  390. break;
  391. case SND_SOC_DAIFMT_IB_NF:
  392. regs->pcr0 |= FSXP | FSRP;
  393. break;
  394. case SND_SOC_DAIFMT_IB_IF:
  395. break;
  396. default:
  397. return -EINVAL;
  398. }
  399. return 0;
  400. }
  401. static int omap_mcbsp_dai_set_clkdiv(struct snd_soc_dai *cpu_dai,
  402. int div_id, int div)
  403. {
  404. struct omap_mcbsp_data *mcbsp_data = to_mcbsp(cpu_dai->private_data);
  405. struct omap_mcbsp_reg_cfg *regs = &mcbsp_data->regs;
  406. if (div_id != OMAP_MCBSP_CLKGDV)
  407. return -ENODEV;
  408. regs->srgr1 |= CLKGDV(div - 1);
  409. return 0;
  410. }
  411. static int omap_mcbsp_dai_set_clks_src(struct omap_mcbsp_data *mcbsp_data,
  412. int clk_id)
  413. {
  414. int sel_bit;
  415. u16 reg, reg_devconf1 = OMAP243X_CONTROL_DEVCONF1;
  416. if (cpu_class_is_omap1()) {
  417. /* OMAP1's can use only external source clock */
  418. if (unlikely(clk_id == OMAP_MCBSP_SYSCLK_CLKS_FCLK))
  419. return -EINVAL;
  420. else
  421. return 0;
  422. }
  423. if (cpu_is_omap2420() && mcbsp_data->bus_id > 1)
  424. return -EINVAL;
  425. if (cpu_is_omap343x())
  426. reg_devconf1 = OMAP343X_CONTROL_DEVCONF1;
  427. switch (mcbsp_data->bus_id) {
  428. case 0:
  429. reg = OMAP2_CONTROL_DEVCONF0;
  430. sel_bit = 2;
  431. break;
  432. case 1:
  433. reg = OMAP2_CONTROL_DEVCONF0;
  434. sel_bit = 6;
  435. break;
  436. case 2:
  437. reg = reg_devconf1;
  438. sel_bit = 0;
  439. break;
  440. case 3:
  441. reg = reg_devconf1;
  442. sel_bit = 2;
  443. break;
  444. case 4:
  445. reg = reg_devconf1;
  446. sel_bit = 4;
  447. break;
  448. default:
  449. return -EINVAL;
  450. }
  451. if (clk_id == OMAP_MCBSP_SYSCLK_CLKS_FCLK)
  452. omap_ctrl_writel(omap_ctrl_readl(reg) & ~(1 << sel_bit), reg);
  453. else
  454. omap_ctrl_writel(omap_ctrl_readl(reg) | (1 << sel_bit), reg);
  455. return 0;
  456. }
  457. static int omap_mcbsp_dai_set_dai_sysclk(struct snd_soc_dai *cpu_dai,
  458. int clk_id, unsigned int freq,
  459. int dir)
  460. {
  461. struct omap_mcbsp_data *mcbsp_data = to_mcbsp(cpu_dai->private_data);
  462. struct omap_mcbsp_reg_cfg *regs = &mcbsp_data->regs;
  463. int err = 0;
  464. switch (clk_id) {
  465. case OMAP_MCBSP_SYSCLK_CLK:
  466. regs->srgr2 |= CLKSM;
  467. break;
  468. case OMAP_MCBSP_SYSCLK_CLKS_FCLK:
  469. case OMAP_MCBSP_SYSCLK_CLKS_EXT:
  470. err = omap_mcbsp_dai_set_clks_src(mcbsp_data, clk_id);
  471. break;
  472. case OMAP_MCBSP_SYSCLK_CLKX_EXT:
  473. regs->srgr2 |= CLKSM;
  474. case OMAP_MCBSP_SYSCLK_CLKR_EXT:
  475. regs->pcr0 |= SCLKME;
  476. break;
  477. default:
  478. err = -ENODEV;
  479. }
  480. return err;
  481. }
  482. static struct snd_soc_dai_ops omap_mcbsp_dai_ops = {
  483. .startup = omap_mcbsp_dai_startup,
  484. .shutdown = omap_mcbsp_dai_shutdown,
  485. .trigger = omap_mcbsp_dai_trigger,
  486. .hw_params = omap_mcbsp_dai_hw_params,
  487. .set_fmt = omap_mcbsp_dai_set_dai_fmt,
  488. .set_clkdiv = omap_mcbsp_dai_set_clkdiv,
  489. .set_sysclk = omap_mcbsp_dai_set_dai_sysclk,
  490. };
  491. #define OMAP_MCBSP_DAI_BUILDER(link_id) \
  492. { \
  493. .name = "omap-mcbsp-dai-"#link_id, \
  494. .id = (link_id), \
  495. .playback = { \
  496. .channels_min = 1, \
  497. .channels_max = 4, \
  498. .rates = OMAP_MCBSP_RATES, \
  499. .formats = SNDRV_PCM_FMTBIT_S16_LE, \
  500. }, \
  501. .capture = { \
  502. .channels_min = 1, \
  503. .channels_max = 4, \
  504. .rates = OMAP_MCBSP_RATES, \
  505. .formats = SNDRV_PCM_FMTBIT_S16_LE, \
  506. }, \
  507. .ops = &omap_mcbsp_dai_ops, \
  508. .private_data = &mcbsp_data[(link_id)].bus_id, \
  509. }
  510. struct snd_soc_dai omap_mcbsp_dai[] = {
  511. OMAP_MCBSP_DAI_BUILDER(0),
  512. OMAP_MCBSP_DAI_BUILDER(1),
  513. #if NUM_LINKS >= 3
  514. OMAP_MCBSP_DAI_BUILDER(2),
  515. #endif
  516. #if NUM_LINKS == 5
  517. OMAP_MCBSP_DAI_BUILDER(3),
  518. OMAP_MCBSP_DAI_BUILDER(4),
  519. #endif
  520. };
  521. EXPORT_SYMBOL_GPL(omap_mcbsp_dai);
  522. static int __init snd_omap_mcbsp_init(void)
  523. {
  524. return snd_soc_register_dais(omap_mcbsp_dai,
  525. ARRAY_SIZE(omap_mcbsp_dai));
  526. }
  527. module_init(snd_omap_mcbsp_init);
  528. static void __exit snd_omap_mcbsp_exit(void)
  529. {
  530. snd_soc_unregister_dais(omap_mcbsp_dai, ARRAY_SIZE(omap_mcbsp_dai));
  531. }
  532. module_exit(snd_omap_mcbsp_exit);
  533. MODULE_AUTHOR("Jarkko Nikula <jhnikula@gmail.com>");
  534. MODULE_DESCRIPTION("OMAP I2S SoC Interface");
  535. MODULE_LICENSE("GPL");