pxa-ssp.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855
  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 tx_mask, unsigned int rx_mask, int slots, int slot_width)
  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);
  331. sscr0 &= ~(SSCR0_MOD | SSCR0_SlotsPerFrm(8) | SSCR0_EDSS | SSCR0_DSS);
  332. /* set slot width */
  333. if (slot_width > 16)
  334. sscr0 |= SSCR0_EDSS | SSCR0_DataSize(slot_width - 16);
  335. else
  336. sscr0 |= SSCR0_DataSize(slot_width);
  337. if (slots > 1) {
  338. /* enable network mode */
  339. sscr0 |= SSCR0_MOD;
  340. /* set number of active slots */
  341. sscr0 |= SSCR0_SlotsPerFrm(slots);
  342. /* set active slot mask */
  343. ssp_write_reg(ssp, SSTSA, tx_mask);
  344. ssp_write_reg(ssp, SSRSA, rx_mask);
  345. }
  346. ssp_write_reg(ssp, SSCR0, sscr0);
  347. return 0;
  348. }
  349. /*
  350. * Tristate the SSP DAI lines
  351. */
  352. static int pxa_ssp_set_dai_tristate(struct snd_soc_dai *cpu_dai,
  353. int tristate)
  354. {
  355. struct ssp_priv *priv = cpu_dai->private_data;
  356. struct ssp_device *ssp = priv->dev.ssp;
  357. u32 sscr1;
  358. sscr1 = ssp_read_reg(ssp, SSCR1);
  359. if (tristate)
  360. sscr1 &= ~SSCR1_TTE;
  361. else
  362. sscr1 |= SSCR1_TTE;
  363. ssp_write_reg(ssp, SSCR1, sscr1);
  364. return 0;
  365. }
  366. /*
  367. * Set up the SSP DAI format.
  368. * The SSP Port must be inactive before calling this function as the
  369. * physical interface format is changed.
  370. */
  371. static int pxa_ssp_set_dai_fmt(struct snd_soc_dai *cpu_dai,
  372. unsigned int fmt)
  373. {
  374. struct ssp_priv *priv = cpu_dai->private_data;
  375. struct ssp_device *ssp = priv->dev.ssp;
  376. u32 sscr0;
  377. u32 sscr1;
  378. u32 sspsp;
  379. /* check if we need to change anything at all */
  380. if (priv->dai_fmt == fmt)
  381. return 0;
  382. /* we can only change the settings if the port is not in use */
  383. if (ssp_read_reg(ssp, SSCR0) & SSCR0_SSE) {
  384. dev_err(&ssp->pdev->dev,
  385. "can't change hardware dai format: stream is in use");
  386. return -EINVAL;
  387. }
  388. /* reset port settings */
  389. sscr0 = ssp_read_reg(ssp, SSCR0) &
  390. (SSCR0_ECS | SSCR0_NCS | SSCR0_MOD | SSCR0_ACS);
  391. sscr1 = SSCR1_RxTresh(8) | SSCR1_TxTresh(7);
  392. sspsp = 0;
  393. switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  394. case SND_SOC_DAIFMT_CBM_CFM:
  395. sscr1 |= SSCR1_SCLKDIR | SSCR1_SFRMDIR;
  396. break;
  397. case SND_SOC_DAIFMT_CBM_CFS:
  398. sscr1 |= SSCR1_SCLKDIR;
  399. break;
  400. case SND_SOC_DAIFMT_CBS_CFS:
  401. break;
  402. default:
  403. return -EINVAL;
  404. }
  405. switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
  406. case SND_SOC_DAIFMT_NB_NF:
  407. sspsp |= SSPSP_SFRMP;
  408. break;
  409. case SND_SOC_DAIFMT_NB_IF:
  410. break;
  411. case SND_SOC_DAIFMT_IB_IF:
  412. sspsp |= SSPSP_SCMODE(2);
  413. break;
  414. case SND_SOC_DAIFMT_IB_NF:
  415. sspsp |= SSPSP_SCMODE(2) | SSPSP_SFRMP;
  416. break;
  417. default:
  418. return -EINVAL;
  419. }
  420. switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  421. case SND_SOC_DAIFMT_I2S:
  422. sscr0 |= SSCR0_PSP;
  423. sscr1 |= SSCR1_RWOT | SSCR1_TRAIL;
  424. /* See hw_params() */
  425. break;
  426. case SND_SOC_DAIFMT_DSP_A:
  427. sspsp |= SSPSP_FSRT;
  428. case SND_SOC_DAIFMT_DSP_B:
  429. sscr0 |= SSCR0_MOD | SSCR0_PSP;
  430. sscr1 |= SSCR1_TRAIL | SSCR1_RWOT;
  431. break;
  432. default:
  433. return -EINVAL;
  434. }
  435. ssp_write_reg(ssp, SSCR0, sscr0);
  436. ssp_write_reg(ssp, SSCR1, sscr1);
  437. ssp_write_reg(ssp, SSPSP, sspsp);
  438. dump_registers(ssp);
  439. /* Since we are configuring the timings for the format by hand
  440. * we have to defer some things until hw_params() where we
  441. * know parameters like the sample size.
  442. */
  443. priv->dai_fmt = fmt;
  444. return 0;
  445. }
  446. /*
  447. * Set the SSP audio DMA parameters and sample size.
  448. * Can be called multiple times by oss emulation.
  449. */
  450. static int pxa_ssp_hw_params(struct snd_pcm_substream *substream,
  451. struct snd_pcm_hw_params *params,
  452. struct snd_soc_dai *dai)
  453. {
  454. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  455. struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
  456. struct ssp_priv *priv = cpu_dai->private_data;
  457. struct ssp_device *ssp = priv->dev.ssp;
  458. int chn = params_channels(params);
  459. u32 sscr0;
  460. u32 sspsp;
  461. int width = snd_pcm_format_physical_width(params_format(params));
  462. int ttsa = ssp_read_reg(ssp, SSTSA) & 0xf;
  463. /* generate correct DMA params */
  464. if (cpu_dai->dma_data)
  465. kfree(cpu_dai->dma_data);
  466. /* Network mode with one active slot (ttsa == 1) can be used
  467. * to force 16-bit frame width on the wire (for S16_LE), even
  468. * with two channels. Use 16-bit DMA transfers for this case.
  469. */
  470. cpu_dai->dma_data = ssp_get_dma_params(ssp,
  471. ((chn == 2) && (ttsa != 1)) || (width == 32),
  472. substream->stream == SNDRV_PCM_STREAM_PLAYBACK);
  473. /* we can only change the settings if the port is not in use */
  474. if (ssp_read_reg(ssp, SSCR0) & SSCR0_SSE)
  475. return 0;
  476. /* clear selected SSP bits */
  477. sscr0 = ssp_read_reg(ssp, SSCR0) & ~(SSCR0_DSS | SSCR0_EDSS);
  478. ssp_write_reg(ssp, SSCR0, sscr0);
  479. /* bit size */
  480. sscr0 = ssp_read_reg(ssp, SSCR0);
  481. switch (params_format(params)) {
  482. case SNDRV_PCM_FORMAT_S16_LE:
  483. #ifdef CONFIG_PXA3xx
  484. if (cpu_is_pxa3xx())
  485. sscr0 |= SSCR0_FPCKE;
  486. #endif
  487. sscr0 |= SSCR0_DataSize(16);
  488. break;
  489. case SNDRV_PCM_FORMAT_S24_LE:
  490. sscr0 |= (SSCR0_EDSS | SSCR0_DataSize(8));
  491. break;
  492. case SNDRV_PCM_FORMAT_S32_LE:
  493. sscr0 |= (SSCR0_EDSS | SSCR0_DataSize(16));
  494. break;
  495. }
  496. ssp_write_reg(ssp, SSCR0, sscr0);
  497. switch (priv->dai_fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  498. case SND_SOC_DAIFMT_I2S:
  499. sspsp = ssp_read_reg(ssp, SSPSP);
  500. if ((ssp_get_scr(ssp) == 4) && (width == 16)) {
  501. /* This is a special case where the bitclk is 64fs
  502. * and we're not dealing with 2*32 bits of audio
  503. * samples.
  504. *
  505. * The SSP values used for that are all found out by
  506. * trying and failing a lot; some of the registers
  507. * needed for that mode are only available on PXA3xx.
  508. */
  509. #ifdef CONFIG_PXA3xx
  510. if (!cpu_is_pxa3xx())
  511. return -EINVAL;
  512. sspsp |= SSPSP_SFRMWDTH(width * 2);
  513. sspsp |= SSPSP_SFRMDLY(width * 4);
  514. sspsp |= SSPSP_EDMYSTOP(3);
  515. sspsp |= SSPSP_DMYSTOP(3);
  516. sspsp |= SSPSP_DMYSTRT(1);
  517. #else
  518. return -EINVAL;
  519. #endif
  520. } else {
  521. /* The frame width is the width the LRCLK is
  522. * asserted for; the delay is expressed in
  523. * half cycle units. We need the extra cycle
  524. * because the data starts clocking out one BCLK
  525. * after LRCLK changes polarity.
  526. */
  527. sspsp |= SSPSP_SFRMWDTH(width + 1);
  528. sspsp |= SSPSP_SFRMDLY((width + 1) * 2);
  529. sspsp |= SSPSP_DMYSTRT(1);
  530. }
  531. ssp_write_reg(ssp, SSPSP, sspsp);
  532. break;
  533. default:
  534. break;
  535. }
  536. /* When we use a network mode, we always require TDM slots
  537. * - complain loudly and fail if they've not been set up yet.
  538. */
  539. if ((sscr0 & SSCR0_MOD) && !ttsa) {
  540. dev_err(&ssp->pdev->dev, "No TDM timeslot configured\n");
  541. return -EINVAL;
  542. }
  543. dump_registers(ssp);
  544. return 0;
  545. }
  546. static int pxa_ssp_trigger(struct snd_pcm_substream *substream, int cmd,
  547. struct snd_soc_dai *dai)
  548. {
  549. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  550. struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
  551. int ret = 0;
  552. struct ssp_priv *priv = cpu_dai->private_data;
  553. struct ssp_device *ssp = priv->dev.ssp;
  554. int val;
  555. switch (cmd) {
  556. case SNDRV_PCM_TRIGGER_RESUME:
  557. ssp_enable(&priv->dev);
  558. break;
  559. case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  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. val = ssp_read_reg(ssp, SSSR);
  567. ssp_write_reg(ssp, SSSR, val);
  568. break;
  569. case SNDRV_PCM_TRIGGER_START:
  570. val = ssp_read_reg(ssp, SSCR1);
  571. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  572. val |= SSCR1_TSRE;
  573. else
  574. val |= SSCR1_RSRE;
  575. ssp_write_reg(ssp, SSCR1, val);
  576. ssp_enable(&priv->dev);
  577. break;
  578. case SNDRV_PCM_TRIGGER_STOP:
  579. val = ssp_read_reg(ssp, SSCR1);
  580. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  581. val &= ~SSCR1_TSRE;
  582. else
  583. val &= ~SSCR1_RSRE;
  584. ssp_write_reg(ssp, SSCR1, val);
  585. break;
  586. case SNDRV_PCM_TRIGGER_SUSPEND:
  587. ssp_disable(&priv->dev);
  588. break;
  589. case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  590. val = ssp_read_reg(ssp, SSCR1);
  591. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  592. val &= ~SSCR1_TSRE;
  593. else
  594. val &= ~SSCR1_RSRE;
  595. ssp_write_reg(ssp, SSCR1, val);
  596. break;
  597. default:
  598. ret = -EINVAL;
  599. }
  600. dump_registers(ssp);
  601. return ret;
  602. }
  603. static int pxa_ssp_probe(struct platform_device *pdev,
  604. struct snd_soc_dai *dai)
  605. {
  606. struct ssp_priv *priv;
  607. int ret;
  608. priv = kzalloc(sizeof(struct ssp_priv), GFP_KERNEL);
  609. if (!priv)
  610. return -ENOMEM;
  611. priv->dev.ssp = ssp_request(dai->id + 1, "SoC audio");
  612. if (priv->dev.ssp == NULL) {
  613. ret = -ENODEV;
  614. goto err_priv;
  615. }
  616. priv->dai_fmt = (unsigned int) -1;
  617. dai->private_data = priv;
  618. return 0;
  619. err_priv:
  620. kfree(priv);
  621. return ret;
  622. }
  623. static void pxa_ssp_remove(struct platform_device *pdev,
  624. struct snd_soc_dai *dai)
  625. {
  626. struct ssp_priv *priv = dai->private_data;
  627. ssp_free(priv->dev.ssp);
  628. }
  629. #define PXA_SSP_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\
  630. SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 | \
  631. SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 | \
  632. SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000)
  633. #define PXA_SSP_FORMATS (SNDRV_PCM_FMTBIT_S16_LE |\
  634. SNDRV_PCM_FMTBIT_S24_LE | \
  635. SNDRV_PCM_FMTBIT_S32_LE)
  636. static struct snd_soc_dai_ops pxa_ssp_dai_ops = {
  637. .startup = pxa_ssp_startup,
  638. .shutdown = pxa_ssp_shutdown,
  639. .trigger = pxa_ssp_trigger,
  640. .hw_params = pxa_ssp_hw_params,
  641. .set_sysclk = pxa_ssp_set_dai_sysclk,
  642. .set_clkdiv = pxa_ssp_set_dai_clkdiv,
  643. .set_pll = pxa_ssp_set_dai_pll,
  644. .set_fmt = pxa_ssp_set_dai_fmt,
  645. .set_tdm_slot = pxa_ssp_set_dai_tdm_slot,
  646. .set_tristate = pxa_ssp_set_dai_tristate,
  647. };
  648. struct snd_soc_dai pxa_ssp_dai[] = {
  649. {
  650. .name = "pxa2xx-ssp1",
  651. .id = 0,
  652. .probe = pxa_ssp_probe,
  653. .remove = pxa_ssp_remove,
  654. .suspend = pxa_ssp_suspend,
  655. .resume = pxa_ssp_resume,
  656. .playback = {
  657. .channels_min = 1,
  658. .channels_max = 2,
  659. .rates = PXA_SSP_RATES,
  660. .formats = PXA_SSP_FORMATS,
  661. },
  662. .capture = {
  663. .channels_min = 1,
  664. .channels_max = 2,
  665. .rates = PXA_SSP_RATES,
  666. .formats = PXA_SSP_FORMATS,
  667. },
  668. .ops = &pxa_ssp_dai_ops,
  669. },
  670. { .name = "pxa2xx-ssp2",
  671. .id = 1,
  672. .probe = pxa_ssp_probe,
  673. .remove = pxa_ssp_remove,
  674. .suspend = pxa_ssp_suspend,
  675. .resume = pxa_ssp_resume,
  676. .playback = {
  677. .channels_min = 1,
  678. .channels_max = 2,
  679. .rates = PXA_SSP_RATES,
  680. .formats = PXA_SSP_FORMATS,
  681. },
  682. .capture = {
  683. .channels_min = 1,
  684. .channels_max = 2,
  685. .rates = PXA_SSP_RATES,
  686. .formats = PXA_SSP_FORMATS,
  687. },
  688. .ops = &pxa_ssp_dai_ops,
  689. },
  690. {
  691. .name = "pxa2xx-ssp3",
  692. .id = 2,
  693. .probe = pxa_ssp_probe,
  694. .remove = pxa_ssp_remove,
  695. .suspend = pxa_ssp_suspend,
  696. .resume = pxa_ssp_resume,
  697. .playback = {
  698. .channels_min = 1,
  699. .channels_max = 2,
  700. .rates = PXA_SSP_RATES,
  701. .formats = PXA_SSP_FORMATS,
  702. },
  703. .capture = {
  704. .channels_min = 1,
  705. .channels_max = 2,
  706. .rates = PXA_SSP_RATES,
  707. .formats = PXA_SSP_FORMATS,
  708. },
  709. .ops = &pxa_ssp_dai_ops,
  710. },
  711. {
  712. .name = "pxa2xx-ssp4",
  713. .id = 3,
  714. .probe = pxa_ssp_probe,
  715. .remove = pxa_ssp_remove,
  716. .suspend = pxa_ssp_suspend,
  717. .resume = pxa_ssp_resume,
  718. .playback = {
  719. .channels_min = 1,
  720. .channels_max = 2,
  721. .rates = PXA_SSP_RATES,
  722. .formats = PXA_SSP_FORMATS,
  723. },
  724. .capture = {
  725. .channels_min = 1,
  726. .channels_max = 2,
  727. .rates = PXA_SSP_RATES,
  728. .formats = PXA_SSP_FORMATS,
  729. },
  730. .ops = &pxa_ssp_dai_ops,
  731. },
  732. };
  733. EXPORT_SYMBOL_GPL(pxa_ssp_dai);
  734. static int __init pxa_ssp_init(void)
  735. {
  736. return snd_soc_register_dais(pxa_ssp_dai, ARRAY_SIZE(pxa_ssp_dai));
  737. }
  738. module_init(pxa_ssp_init);
  739. static void __exit pxa_ssp_exit(void)
  740. {
  741. snd_soc_unregister_dais(pxa_ssp_dai, ARRAY_SIZE(pxa_ssp_dai));
  742. }
  743. module_exit(pxa_ssp_exit);
  744. /* Module information */
  745. MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
  746. MODULE_DESCRIPTION("PXA SSP/PCM SoC Interface");
  747. MODULE_LICENSE("GPL");