pxa-ssp.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842
  1. /*
  2. * pxa-ssp.c -- ALSA Soc Audio Layer
  3. *
  4. * Copyright 2005,2008 Wolfson Microelectronics PLC.
  5. * Author: Liam Girdwood
  6. * Mark Brown <broonie@opensource.wolfsonmicro.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation; either version 2 of the License, or (at your
  11. * option) any later version.
  12. *
  13. * TODO:
  14. * o Test network mode for > 16bit sample size
  15. */
  16. #include <linux/init.h>
  17. #include <linux/module.h>
  18. #include <linux/platform_device.h>
  19. #include <linux/clk.h>
  20. #include <linux/io.h>
  21. #include <asm/irq.h>
  22. #include <sound/core.h>
  23. #include <sound/pcm.h>
  24. #include <sound/initval.h>
  25. #include <sound/pcm_params.h>
  26. #include <sound/soc.h>
  27. #include <sound/pxa2xx-lib.h>
  28. #include <mach/hardware.h>
  29. #include <mach/dma.h>
  30. #include <mach/regs-ssp.h>
  31. #include <mach/audio.h>
  32. #include <mach/ssp.h>
  33. #include "pxa2xx-pcm.h"
  34. #include "pxa-ssp.h"
  35. /*
  36. * SSP audio private data
  37. */
  38. struct ssp_priv {
  39. struct ssp_dev dev;
  40. unsigned int sysclk;
  41. int dai_fmt;
  42. #ifdef CONFIG_PM
  43. struct ssp_state state;
  44. #endif
  45. };
  46. static void dump_registers(struct ssp_device *ssp)
  47. {
  48. dev_dbg(&ssp->pdev->dev, "SSCR0 0x%08x SSCR1 0x%08x SSTO 0x%08x\n",
  49. ssp_read_reg(ssp, SSCR0), ssp_read_reg(ssp, SSCR1),
  50. ssp_read_reg(ssp, SSTO));
  51. dev_dbg(&ssp->pdev->dev, "SSPSP 0x%08x SSSR 0x%08x SSACD 0x%08x\n",
  52. ssp_read_reg(ssp, SSPSP), ssp_read_reg(ssp, SSSR),
  53. ssp_read_reg(ssp, SSACD));
  54. }
  55. struct pxa2xx_pcm_dma_data {
  56. struct pxa2xx_pcm_dma_params params;
  57. char name[20];
  58. };
  59. static struct pxa2xx_pcm_dma_params *
  60. ssp_get_dma_params(struct ssp_device *ssp, int width4, int out)
  61. {
  62. struct pxa2xx_pcm_dma_data *dma;
  63. dma = kzalloc(sizeof(struct pxa2xx_pcm_dma_data), GFP_KERNEL);
  64. if (dma == NULL)
  65. return NULL;
  66. snprintf(dma->name, 20, "SSP%d PCM %s %s", ssp->port_id,
  67. width4 ? "32-bit" : "16-bit", out ? "out" : "in");
  68. dma->params.name = dma->name;
  69. dma->params.drcmr = &DRCMR(out ? ssp->drcmr_tx : ssp->drcmr_rx);
  70. dma->params.dcmd = (out ? (DCMD_INCSRCADDR | DCMD_FLOWTRG) :
  71. (DCMD_INCTRGADDR | DCMD_FLOWSRC)) |
  72. (width4 ? DCMD_WIDTH4 : DCMD_WIDTH2) | DCMD_BURST16;
  73. dma->params.dev_addr = ssp->phys_base + SSDR;
  74. return &dma->params;
  75. }
  76. static int pxa_ssp_startup(struct snd_pcm_substream *substream,
  77. struct snd_soc_dai *dai)
  78. {
  79. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  80. struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
  81. struct ssp_priv *priv = cpu_dai->private_data;
  82. int ret = 0;
  83. if (!cpu_dai->active) {
  84. priv->dev.port = cpu_dai->id + 1;
  85. priv->dev.irq = NO_IRQ;
  86. clk_enable(priv->dev.ssp->clk);
  87. ssp_disable(&priv->dev);
  88. }
  89. if (cpu_dai->dma_data) {
  90. kfree(cpu_dai->dma_data);
  91. cpu_dai->dma_data = NULL;
  92. }
  93. return ret;
  94. }
  95. static void pxa_ssp_shutdown(struct snd_pcm_substream *substream,
  96. struct snd_soc_dai *dai)
  97. {
  98. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  99. struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
  100. struct ssp_priv *priv = cpu_dai->private_data;
  101. if (!cpu_dai->active) {
  102. ssp_disable(&priv->dev);
  103. clk_disable(priv->dev.ssp->clk);
  104. }
  105. if (cpu_dai->dma_data) {
  106. kfree(cpu_dai->dma_data);
  107. cpu_dai->dma_data = NULL;
  108. }
  109. }
  110. #ifdef CONFIG_PM
  111. static int pxa_ssp_suspend(struct snd_soc_dai *cpu_dai)
  112. {
  113. struct ssp_priv *priv = cpu_dai->private_data;
  114. if (!cpu_dai->active)
  115. return 0;
  116. ssp_save_state(&priv->dev, &priv->state);
  117. clk_disable(priv->dev.ssp->clk);
  118. return 0;
  119. }
  120. static int pxa_ssp_resume(struct snd_soc_dai *cpu_dai)
  121. {
  122. struct ssp_priv *priv = cpu_dai->private_data;
  123. if (!cpu_dai->active)
  124. return 0;
  125. clk_enable(priv->dev.ssp->clk);
  126. ssp_restore_state(&priv->dev, &priv->state);
  127. ssp_enable(&priv->dev);
  128. return 0;
  129. }
  130. #else
  131. #define pxa_ssp_suspend NULL
  132. #define pxa_ssp_resume NULL
  133. #endif
  134. /**
  135. * ssp_set_clkdiv - set SSP clock divider
  136. * @div: serial clock rate divider
  137. */
  138. static void ssp_set_scr(struct ssp_device *ssp, u32 div)
  139. {
  140. u32 sscr0 = ssp_read_reg(ssp, SSCR0);
  141. if (cpu_is_pxa25x() && ssp->type == PXA25x_SSP) {
  142. sscr0 &= ~0x0000ff00;
  143. sscr0 |= ((div - 2)/2) << 8; /* 2..512 */
  144. } else {
  145. sscr0 &= ~0x000fff00;
  146. sscr0 |= (div - 1) << 8; /* 1..4096 */
  147. }
  148. ssp_write_reg(ssp, SSCR0, sscr0);
  149. }
  150. /**
  151. * ssp_get_clkdiv - get SSP clock divider
  152. */
  153. static u32 ssp_get_scr(struct ssp_device *ssp)
  154. {
  155. u32 sscr0 = ssp_read_reg(ssp, SSCR0);
  156. u32 div;
  157. if (cpu_is_pxa25x() && ssp->type == PXA25x_SSP)
  158. div = ((sscr0 >> 8) & 0xff) * 2 + 2;
  159. else
  160. div = ((sscr0 >> 8) & 0xfff) + 1;
  161. return div;
  162. }
  163. /*
  164. * Set the SSP ports SYSCLK.
  165. */
  166. static int pxa_ssp_set_dai_sysclk(struct snd_soc_dai *cpu_dai,
  167. int clk_id, unsigned int freq, int dir)
  168. {
  169. struct ssp_priv *priv = cpu_dai->private_data;
  170. struct ssp_device *ssp = priv->dev.ssp;
  171. int val;
  172. u32 sscr0 = ssp_read_reg(ssp, SSCR0) &
  173. ~(SSCR0_ECS | SSCR0_NCS | SSCR0_MOD | SSCR0_ACS);
  174. dev_dbg(&ssp->pdev->dev,
  175. "pxa_ssp_set_dai_sysclk id: %d, clk_id %d, freq %u\n",
  176. cpu_dai->id, clk_id, freq);
  177. switch (clk_id) {
  178. case PXA_SSP_CLK_NET_PLL:
  179. sscr0 |= SSCR0_MOD;
  180. break;
  181. case PXA_SSP_CLK_PLL:
  182. /* Internal PLL is fixed */
  183. if (cpu_is_pxa25x())
  184. priv->sysclk = 1843200;
  185. else
  186. priv->sysclk = 13000000;
  187. break;
  188. case PXA_SSP_CLK_EXT:
  189. priv->sysclk = freq;
  190. sscr0 |= SSCR0_ECS;
  191. break;
  192. case PXA_SSP_CLK_NET:
  193. priv->sysclk = freq;
  194. sscr0 |= SSCR0_NCS | SSCR0_MOD;
  195. break;
  196. case PXA_SSP_CLK_AUDIO:
  197. priv->sysclk = 0;
  198. ssp_set_scr(ssp, 1);
  199. sscr0 |= SSCR0_ACS;
  200. break;
  201. default:
  202. return -ENODEV;
  203. }
  204. /* The SSP clock must be disabled when changing SSP clock mode
  205. * on PXA2xx. On PXA3xx it must be enabled when doing so. */
  206. if (!cpu_is_pxa3xx())
  207. clk_disable(priv->dev.ssp->clk);
  208. val = ssp_read_reg(ssp, SSCR0) | sscr0;
  209. ssp_write_reg(ssp, SSCR0, val);
  210. if (!cpu_is_pxa3xx())
  211. clk_enable(priv->dev.ssp->clk);
  212. return 0;
  213. }
  214. /*
  215. * Set the SSP clock dividers.
  216. */
  217. static int pxa_ssp_set_dai_clkdiv(struct snd_soc_dai *cpu_dai,
  218. int div_id, int div)
  219. {
  220. struct ssp_priv *priv = cpu_dai->private_data;
  221. struct ssp_device *ssp = priv->dev.ssp;
  222. int val;
  223. switch (div_id) {
  224. case PXA_SSP_AUDIO_DIV_ACDS:
  225. val = (ssp_read_reg(ssp, SSACD) & ~0x7) | SSACD_ACDS(div);
  226. ssp_write_reg(ssp, SSACD, val);
  227. break;
  228. case PXA_SSP_AUDIO_DIV_SCDB:
  229. val = ssp_read_reg(ssp, SSACD);
  230. val &= ~SSACD_SCDB;
  231. #if defined(CONFIG_PXA3xx)
  232. if (cpu_is_pxa3xx())
  233. val &= ~SSACD_SCDX8;
  234. #endif
  235. switch (div) {
  236. case PXA_SSP_CLK_SCDB_1:
  237. val |= SSACD_SCDB;
  238. break;
  239. case PXA_SSP_CLK_SCDB_4:
  240. break;
  241. #if defined(CONFIG_PXA3xx)
  242. case PXA_SSP_CLK_SCDB_8:
  243. if (cpu_is_pxa3xx())
  244. val |= SSACD_SCDX8;
  245. else
  246. return -EINVAL;
  247. break;
  248. #endif
  249. default:
  250. return -EINVAL;
  251. }
  252. ssp_write_reg(ssp, SSACD, val);
  253. break;
  254. case PXA_SSP_DIV_SCR:
  255. ssp_set_scr(ssp, div);
  256. break;
  257. default:
  258. return -ENODEV;
  259. }
  260. return 0;
  261. }
  262. /*
  263. * Configure the PLL frequency pxa27x and (afaik - pxa320 only)
  264. */
  265. static int pxa_ssp_set_dai_pll(struct snd_soc_dai *cpu_dai,
  266. int pll_id, unsigned int freq_in, unsigned int freq_out)
  267. {
  268. struct ssp_priv *priv = cpu_dai->private_data;
  269. struct ssp_device *ssp = priv->dev.ssp;
  270. u32 ssacd = ssp_read_reg(ssp, SSACD) & ~0x70;
  271. #if defined(CONFIG_PXA3xx)
  272. if (cpu_is_pxa3xx())
  273. ssp_write_reg(ssp, SSACDD, 0);
  274. #endif
  275. switch (freq_out) {
  276. case 5622000:
  277. break;
  278. case 11345000:
  279. ssacd |= (0x1 << 4);
  280. break;
  281. case 12235000:
  282. ssacd |= (0x2 << 4);
  283. break;
  284. case 14857000:
  285. ssacd |= (0x3 << 4);
  286. break;
  287. case 32842000:
  288. ssacd |= (0x4 << 4);
  289. break;
  290. case 48000000:
  291. ssacd |= (0x5 << 4);
  292. break;
  293. case 0:
  294. /* Disable */
  295. break;
  296. default:
  297. #ifdef CONFIG_PXA3xx
  298. /* PXA3xx has a clock ditherer which can be used to generate
  299. * a wider range of frequencies - calculate a value for it.
  300. */
  301. if (cpu_is_pxa3xx()) {
  302. u32 val;
  303. u64 tmp = 19968;
  304. tmp *= 1000000;
  305. do_div(tmp, freq_out);
  306. val = tmp;
  307. val = (val << 16) | 64;;
  308. ssp_write_reg(ssp, SSACDD, val);
  309. ssacd |= (0x6 << 4);
  310. dev_dbg(&ssp->pdev->dev,
  311. "Using SSACDD %x to supply %uHz\n",
  312. val, freq_out);
  313. break;
  314. }
  315. #endif
  316. return -EINVAL;
  317. }
  318. ssp_write_reg(ssp, SSACD, ssacd);
  319. return 0;
  320. }
  321. /*
  322. * Set the active slots in TDM/Network mode
  323. */
  324. static int pxa_ssp_set_dai_tdm_slot(struct snd_soc_dai *cpu_dai,
  325. unsigned int mask, int slots)
  326. {
  327. struct ssp_priv *priv = cpu_dai->private_data;
  328. struct ssp_device *ssp = priv->dev.ssp;
  329. u32 sscr0;
  330. sscr0 = ssp_read_reg(ssp, SSCR0) & ~SSCR0_SlotsPerFrm(7);
  331. /* set number of active slots */
  332. sscr0 |= SSCR0_SlotsPerFrm(slots);
  333. ssp_write_reg(ssp, SSCR0, sscr0);
  334. /* set active slot mask */
  335. ssp_write_reg(ssp, SSTSA, mask);
  336. ssp_write_reg(ssp, SSRSA, mask);
  337. return 0;
  338. }
  339. /*
  340. * Tristate the SSP DAI lines
  341. */
  342. static int pxa_ssp_set_dai_tristate(struct snd_soc_dai *cpu_dai,
  343. int tristate)
  344. {
  345. struct ssp_priv *priv = cpu_dai->private_data;
  346. struct ssp_device *ssp = priv->dev.ssp;
  347. u32 sscr1;
  348. sscr1 = ssp_read_reg(ssp, SSCR1);
  349. if (tristate)
  350. sscr1 &= ~SSCR1_TTE;
  351. else
  352. sscr1 |= SSCR1_TTE;
  353. ssp_write_reg(ssp, SSCR1, sscr1);
  354. return 0;
  355. }
  356. /*
  357. * Set up the SSP DAI format.
  358. * The SSP Port must be inactive before calling this function as the
  359. * physical interface format is changed.
  360. */
  361. static int pxa_ssp_set_dai_fmt(struct snd_soc_dai *cpu_dai,
  362. unsigned int fmt)
  363. {
  364. struct ssp_priv *priv = cpu_dai->private_data;
  365. struct ssp_device *ssp = priv->dev.ssp;
  366. u32 sscr0;
  367. u32 sscr1;
  368. u32 sspsp;
  369. /* check if we need to change anything at all */
  370. if (priv->dai_fmt == fmt)
  371. return 0;
  372. /* we can only change the settings if the port is not in use */
  373. if (ssp_read_reg(ssp, SSCR0) & SSCR0_SSE) {
  374. dev_err(&ssp->pdev->dev,
  375. "can't change hardware dai format: stream is in use");
  376. return -EINVAL;
  377. }
  378. /* reset port settings */
  379. sscr0 = ssp_read_reg(ssp, SSCR0) &
  380. (SSCR0_ECS | SSCR0_NCS | SSCR0_MOD | SSCR0_ACS);
  381. sscr1 = SSCR1_RxTresh(8) | SSCR1_TxTresh(7);
  382. sspsp = 0;
  383. switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  384. case SND_SOC_DAIFMT_CBM_CFM:
  385. sscr1 |= SSCR1_SCLKDIR | SSCR1_SFRMDIR;
  386. break;
  387. case SND_SOC_DAIFMT_CBM_CFS:
  388. sscr1 |= SSCR1_SCLKDIR;
  389. break;
  390. case SND_SOC_DAIFMT_CBS_CFS:
  391. break;
  392. default:
  393. return -EINVAL;
  394. }
  395. switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
  396. case SND_SOC_DAIFMT_NB_NF:
  397. sspsp |= SSPSP_SFRMP;
  398. break;
  399. case SND_SOC_DAIFMT_NB_IF:
  400. break;
  401. case SND_SOC_DAIFMT_IB_IF:
  402. sspsp |= SSPSP_SCMODE(2);
  403. break;
  404. case SND_SOC_DAIFMT_IB_NF:
  405. sspsp |= SSPSP_SCMODE(2) | SSPSP_SFRMP;
  406. break;
  407. default:
  408. return -EINVAL;
  409. }
  410. switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  411. case SND_SOC_DAIFMT_I2S:
  412. sscr0 |= SSCR0_PSP;
  413. sscr1 |= SSCR1_RWOT | SSCR1_TRAIL;
  414. /* See hw_params() */
  415. break;
  416. case SND_SOC_DAIFMT_DSP_A:
  417. sspsp |= SSPSP_FSRT;
  418. case SND_SOC_DAIFMT_DSP_B:
  419. sscr0 |= SSCR0_MOD | SSCR0_PSP;
  420. sscr1 |= SSCR1_TRAIL | SSCR1_RWOT;
  421. break;
  422. default:
  423. return -EINVAL;
  424. }
  425. ssp_write_reg(ssp, SSCR0, sscr0);
  426. ssp_write_reg(ssp, SSCR1, sscr1);
  427. ssp_write_reg(ssp, SSPSP, sspsp);
  428. dump_registers(ssp);
  429. /* Since we are configuring the timings for the format by hand
  430. * we have to defer some things until hw_params() where we
  431. * know parameters like the sample size.
  432. */
  433. priv->dai_fmt = fmt;
  434. return 0;
  435. }
  436. /*
  437. * Set the SSP audio DMA parameters and sample size.
  438. * Can be called multiple times by oss emulation.
  439. */
  440. static int pxa_ssp_hw_params(struct snd_pcm_substream *substream,
  441. struct snd_pcm_hw_params *params,
  442. struct snd_soc_dai *dai)
  443. {
  444. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  445. struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
  446. struct ssp_priv *priv = cpu_dai->private_data;
  447. struct ssp_device *ssp = priv->dev.ssp;
  448. int chn = params_channels(params);
  449. u32 sscr0;
  450. u32 sspsp;
  451. int width = snd_pcm_format_physical_width(params_format(params));
  452. int ttsa = ssp_read_reg(ssp, SSTSA) & 0xf;
  453. /* generate correct DMA params */
  454. if (cpu_dai->dma_data)
  455. kfree(cpu_dai->dma_data);
  456. /* Network mode with one active slot (ttsa == 1) can be used
  457. * to force 16-bit frame width on the wire (for S16_LE), even
  458. * with two channels. Use 16-bit DMA transfers for this case.
  459. */
  460. cpu_dai->dma_data = ssp_get_dma_params(ssp,
  461. ((chn == 2) && (ttsa != 1)) || (width == 32),
  462. substream->stream == SNDRV_PCM_STREAM_PLAYBACK);
  463. /* we can only change the settings if the port is not in use */
  464. if (ssp_read_reg(ssp, SSCR0) & SSCR0_SSE)
  465. return 0;
  466. /* clear selected SSP bits */
  467. sscr0 = ssp_read_reg(ssp, SSCR0) & ~(SSCR0_DSS | SSCR0_EDSS);
  468. ssp_write_reg(ssp, SSCR0, sscr0);
  469. /* bit size */
  470. sscr0 = ssp_read_reg(ssp, SSCR0);
  471. switch (params_format(params)) {
  472. case SNDRV_PCM_FORMAT_S16_LE:
  473. #ifdef CONFIG_PXA3xx
  474. if (cpu_is_pxa3xx())
  475. sscr0 |= SSCR0_FPCKE;
  476. #endif
  477. sscr0 |= SSCR0_DataSize(16);
  478. break;
  479. case SNDRV_PCM_FORMAT_S24_LE:
  480. sscr0 |= (SSCR0_EDSS | SSCR0_DataSize(8));
  481. break;
  482. case SNDRV_PCM_FORMAT_S32_LE:
  483. sscr0 |= (SSCR0_EDSS | SSCR0_DataSize(16));
  484. break;
  485. }
  486. ssp_write_reg(ssp, SSCR0, sscr0);
  487. switch (priv->dai_fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  488. case SND_SOC_DAIFMT_I2S:
  489. sspsp = ssp_read_reg(ssp, SSPSP);
  490. if ((ssp_get_scr(ssp) == 4) && (width == 16)) {
  491. /* This is a special case where the bitclk is 64fs
  492. * and we're not dealing with 2*32 bits of audio
  493. * samples.
  494. *
  495. * The SSP values used for that are all found out by
  496. * trying and failing a lot; some of the registers
  497. * needed for that mode are only available on PXA3xx.
  498. */
  499. #ifdef CONFIG_PXA3xx
  500. if (!cpu_is_pxa3xx())
  501. return -EINVAL;
  502. sspsp |= SSPSP_SFRMWDTH(width * 2);
  503. sspsp |= SSPSP_SFRMDLY(width * 4);
  504. sspsp |= SSPSP_EDMYSTOP(3);
  505. sspsp |= SSPSP_DMYSTOP(3);
  506. sspsp |= SSPSP_DMYSTRT(1);
  507. #else
  508. return -EINVAL;
  509. #endif
  510. } else {
  511. /* The frame width is the width the LRCLK is
  512. * asserted for; the delay is expressed in
  513. * half cycle units. We need the extra cycle
  514. * because the data starts clocking out one BCLK
  515. * after LRCLK changes polarity.
  516. */
  517. sspsp |= SSPSP_SFRMWDTH(width + 1);
  518. sspsp |= SSPSP_SFRMDLY((width + 1) * 2);
  519. sspsp |= SSPSP_DMYSTRT(1);
  520. }
  521. ssp_write_reg(ssp, SSPSP, sspsp);
  522. break;
  523. default:
  524. break;
  525. }
  526. /* When we use a network mode, we always require TDM slots
  527. * - complain loudly and fail if they've not been set up yet.
  528. */
  529. if ((sscr0 & SSCR0_MOD) && !ttsa) {
  530. dev_err(&ssp->pdev->dev, "No TDM timeslot configured\n");
  531. return -EINVAL;
  532. }
  533. dump_registers(ssp);
  534. return 0;
  535. }
  536. static int pxa_ssp_trigger(struct snd_pcm_substream *substream, int cmd,
  537. struct snd_soc_dai *dai)
  538. {
  539. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  540. struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
  541. int ret = 0;
  542. struct ssp_priv *priv = cpu_dai->private_data;
  543. struct ssp_device *ssp = priv->dev.ssp;
  544. int val;
  545. switch (cmd) {
  546. case SNDRV_PCM_TRIGGER_RESUME:
  547. ssp_enable(&priv->dev);
  548. break;
  549. case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  550. val = ssp_read_reg(ssp, SSCR1);
  551. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  552. val |= SSCR1_TSRE;
  553. else
  554. val |= SSCR1_RSRE;
  555. ssp_write_reg(ssp, SSCR1, val);
  556. val = ssp_read_reg(ssp, SSSR);
  557. ssp_write_reg(ssp, SSSR, val);
  558. break;
  559. case SNDRV_PCM_TRIGGER_START:
  560. val = ssp_read_reg(ssp, SSCR1);
  561. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  562. val |= SSCR1_TSRE;
  563. else
  564. val |= SSCR1_RSRE;
  565. ssp_write_reg(ssp, SSCR1, val);
  566. ssp_enable(&priv->dev);
  567. break;
  568. case SNDRV_PCM_TRIGGER_STOP:
  569. val = ssp_read_reg(ssp, SSCR1);
  570. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  571. val &= ~SSCR1_TSRE;
  572. else
  573. val &= ~SSCR1_RSRE;
  574. ssp_write_reg(ssp, SSCR1, val);
  575. break;
  576. case SNDRV_PCM_TRIGGER_SUSPEND:
  577. ssp_disable(&priv->dev);
  578. break;
  579. case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  580. val = ssp_read_reg(ssp, SSCR1);
  581. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  582. val &= ~SSCR1_TSRE;
  583. else
  584. val &= ~SSCR1_RSRE;
  585. ssp_write_reg(ssp, SSCR1, val);
  586. break;
  587. default:
  588. ret = -EINVAL;
  589. }
  590. dump_registers(ssp);
  591. return ret;
  592. }
  593. static int pxa_ssp_probe(struct platform_device *pdev,
  594. struct snd_soc_dai *dai)
  595. {
  596. struct ssp_priv *priv;
  597. int ret;
  598. priv = kzalloc(sizeof(struct ssp_priv), GFP_KERNEL);
  599. if (!priv)
  600. return -ENOMEM;
  601. priv->dev.ssp = ssp_request(dai->id + 1, "SoC audio");
  602. if (priv->dev.ssp == NULL) {
  603. ret = -ENODEV;
  604. goto err_priv;
  605. }
  606. priv->dai_fmt = (unsigned int) -1;
  607. dai->private_data = priv;
  608. return 0;
  609. err_priv:
  610. kfree(priv);
  611. return ret;
  612. }
  613. static void pxa_ssp_remove(struct platform_device *pdev,
  614. struct snd_soc_dai *dai)
  615. {
  616. struct ssp_priv *priv = dai->private_data;
  617. ssp_free(priv->dev.ssp);
  618. }
  619. #define PXA_SSP_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\
  620. SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 | \
  621. SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 | \
  622. SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000)
  623. #define PXA_SSP_FORMATS (SNDRV_PCM_FMTBIT_S16_LE |\
  624. SNDRV_PCM_FMTBIT_S24_LE | \
  625. SNDRV_PCM_FMTBIT_S32_LE)
  626. static struct snd_soc_dai_ops pxa_ssp_dai_ops = {
  627. .startup = pxa_ssp_startup,
  628. .shutdown = pxa_ssp_shutdown,
  629. .trigger = pxa_ssp_trigger,
  630. .hw_params = pxa_ssp_hw_params,
  631. .set_sysclk = pxa_ssp_set_dai_sysclk,
  632. .set_clkdiv = pxa_ssp_set_dai_clkdiv,
  633. .set_pll = pxa_ssp_set_dai_pll,
  634. .set_fmt = pxa_ssp_set_dai_fmt,
  635. .set_tdm_slot = pxa_ssp_set_dai_tdm_slot,
  636. .set_tristate = pxa_ssp_set_dai_tristate,
  637. };
  638. struct snd_soc_dai pxa_ssp_dai[] = {
  639. {
  640. .name = "pxa2xx-ssp1",
  641. .id = 0,
  642. .probe = pxa_ssp_probe,
  643. .remove = pxa_ssp_remove,
  644. .suspend = pxa_ssp_suspend,
  645. .resume = pxa_ssp_resume,
  646. .playback = {
  647. .channels_min = 1,
  648. .channels_max = 2,
  649. .rates = PXA_SSP_RATES,
  650. .formats = PXA_SSP_FORMATS,
  651. },
  652. .capture = {
  653. .channels_min = 1,
  654. .channels_max = 2,
  655. .rates = PXA_SSP_RATES,
  656. .formats = PXA_SSP_FORMATS,
  657. },
  658. .ops = &pxa_ssp_dai_ops,
  659. },
  660. { .name = "pxa2xx-ssp2",
  661. .id = 1,
  662. .probe = pxa_ssp_probe,
  663. .remove = pxa_ssp_remove,
  664. .suspend = pxa_ssp_suspend,
  665. .resume = pxa_ssp_resume,
  666. .playback = {
  667. .channels_min = 1,
  668. .channels_max = 2,
  669. .rates = PXA_SSP_RATES,
  670. .formats = PXA_SSP_FORMATS,
  671. },
  672. .capture = {
  673. .channels_min = 1,
  674. .channels_max = 2,
  675. .rates = PXA_SSP_RATES,
  676. .formats = PXA_SSP_FORMATS,
  677. },
  678. .ops = &pxa_ssp_dai_ops,
  679. },
  680. {
  681. .name = "pxa2xx-ssp3",
  682. .id = 2,
  683. .probe = pxa_ssp_probe,
  684. .remove = pxa_ssp_remove,
  685. .suspend = pxa_ssp_suspend,
  686. .resume = pxa_ssp_resume,
  687. .playback = {
  688. .channels_min = 1,
  689. .channels_max = 2,
  690. .rates = PXA_SSP_RATES,
  691. .formats = PXA_SSP_FORMATS,
  692. },
  693. .capture = {
  694. .channels_min = 1,
  695. .channels_max = 2,
  696. .rates = PXA_SSP_RATES,
  697. .formats = PXA_SSP_FORMATS,
  698. },
  699. .ops = &pxa_ssp_dai_ops,
  700. },
  701. {
  702. .name = "pxa2xx-ssp4",
  703. .id = 3,
  704. .probe = pxa_ssp_probe,
  705. .remove = pxa_ssp_remove,
  706. .suspend = pxa_ssp_suspend,
  707. .resume = pxa_ssp_resume,
  708. .playback = {
  709. .channels_min = 1,
  710. .channels_max = 2,
  711. .rates = PXA_SSP_RATES,
  712. .formats = PXA_SSP_FORMATS,
  713. },
  714. .capture = {
  715. .channels_min = 1,
  716. .channels_max = 2,
  717. .rates = PXA_SSP_RATES,
  718. .formats = PXA_SSP_FORMATS,
  719. },
  720. .ops = &pxa_ssp_dai_ops,
  721. },
  722. };
  723. EXPORT_SYMBOL_GPL(pxa_ssp_dai);
  724. static int __init pxa_ssp_init(void)
  725. {
  726. return snd_soc_register_dais(pxa_ssp_dai, ARRAY_SIZE(pxa_ssp_dai));
  727. }
  728. module_init(pxa_ssp_init);
  729. static void __exit pxa_ssp_exit(void)
  730. {
  731. snd_soc_unregister_dais(pxa_ssp_dai, ARRAY_SIZE(pxa_ssp_dai));
  732. }
  733. module_exit(pxa_ssp_exit);
  734. /* Module information */
  735. MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
  736. MODULE_DESCRIPTION("PXA SSP/PCM SoC Interface");
  737. MODULE_LICENSE("GPL");