pxa-ssp.c 20 KB

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