pxa-ssp.c 19 KB

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