pxa-ssp.c 20 KB

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