imx-ssi.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  1. /*
  2. * imx-ssi.c -- ALSA Soc Audio Layer
  3. *
  4. * Copyright 2009 Sascha Hauer <s.hauer@pengutronix.de>
  5. *
  6. * This code is based on code copyrighted by Freescale,
  7. * Liam Girdwood, Javier Martin and probably others.
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License as published by the
  11. * Free Software Foundation; either version 2 of the License, or (at your
  12. * option) any later version.
  13. *
  14. *
  15. * The i.MX SSI core has some nasty limitations in AC97 mode. While most
  16. * sane processor vendors have a FIFO per AC97 slot, the i.MX has only
  17. * one FIFO which combines all valid receive slots. We cannot even select
  18. * which slots we want to receive. The WM9712 with which this driver
  19. * was developed with always sends GPIO status data in slot 12 which
  20. * we receive in our (PCM-) data stream. The only chance we have is to
  21. * manually skip this data in the FIQ handler. With sampling rates different
  22. * from 48000Hz not every frame has valid receive data, so the ratio
  23. * between pcm data and GPIO status data changes. Our FIQ handler is not
  24. * able to handle this, hence this driver only works with 48000Hz sampling
  25. * rate.
  26. * Reading and writing AC97 registers is another challenge. The core
  27. * provides us status bits when the read register is updated with *another*
  28. * value. When we read the same register two times (and the register still
  29. * contains the same value) these status bits are not set. We work
  30. * around this by not polling these bits but only wait a fixed delay.
  31. *
  32. */
  33. #include <linux/clk.h>
  34. #include <linux/delay.h>
  35. #include <linux/device.h>
  36. #include <linux/dma-mapping.h>
  37. #include <linux/init.h>
  38. #include <linux/interrupt.h>
  39. #include <linux/module.h>
  40. #include <linux/platform_device.h>
  41. #include <linux/slab.h>
  42. #include <sound/core.h>
  43. #include <sound/initval.h>
  44. #include <sound/pcm.h>
  45. #include <sound/pcm_params.h>
  46. #include <sound/soc.h>
  47. #include <mach/ssi.h>
  48. #include <mach/hardware.h>
  49. #include "imx-ssi.h"
  50. #define SSI_SACNT_DEFAULT (SSI_SACNT_AC97EN | SSI_SACNT_FV)
  51. /*
  52. * SSI Network Mode or TDM slots configuration.
  53. * Should only be called when port is inactive (i.e. SSIEN = 0).
  54. */
  55. static int imx_ssi_set_dai_tdm_slot(struct snd_soc_dai *cpu_dai,
  56. unsigned int tx_mask, unsigned int rx_mask, int slots, int slot_width)
  57. {
  58. struct imx_ssi *ssi = snd_soc_dai_get_drvdata(cpu_dai);
  59. u32 sccr;
  60. sccr = readl(ssi->base + SSI_STCCR);
  61. sccr &= ~SSI_STCCR_DC_MASK;
  62. sccr |= SSI_STCCR_DC(slots - 1);
  63. writel(sccr, ssi->base + SSI_STCCR);
  64. sccr = readl(ssi->base + SSI_SRCCR);
  65. sccr &= ~SSI_STCCR_DC_MASK;
  66. sccr |= SSI_STCCR_DC(slots - 1);
  67. writel(sccr, ssi->base + SSI_SRCCR);
  68. writel(tx_mask, ssi->base + SSI_STMSK);
  69. writel(rx_mask, ssi->base + SSI_SRMSK);
  70. return 0;
  71. }
  72. /*
  73. * SSI DAI format configuration.
  74. * Should only be called when port is inactive (i.e. SSIEN = 0).
  75. */
  76. static int imx_ssi_set_dai_fmt(struct snd_soc_dai *cpu_dai, unsigned int fmt)
  77. {
  78. struct imx_ssi *ssi = snd_soc_dai_get_drvdata(cpu_dai);
  79. u32 strcr = 0, scr;
  80. scr = readl(ssi->base + SSI_SCR) & ~(SSI_SCR_SYN | SSI_SCR_NET);
  81. /* DAI mode */
  82. switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  83. case SND_SOC_DAIFMT_I2S:
  84. /* data on rising edge of bclk, frame low 1clk before data */
  85. strcr |= SSI_STCR_TFSI | SSI_STCR_TEFS | SSI_STCR_TXBIT0;
  86. scr |= SSI_SCR_NET;
  87. if (ssi->flags & IMX_SSI_USE_I2S_SLAVE) {
  88. scr &= ~SSI_I2S_MODE_MASK;
  89. scr |= SSI_SCR_I2S_MODE_SLAVE;
  90. }
  91. break;
  92. case SND_SOC_DAIFMT_LEFT_J:
  93. /* data on rising edge of bclk, frame high with data */
  94. strcr |= SSI_STCR_TXBIT0;
  95. break;
  96. case SND_SOC_DAIFMT_DSP_B:
  97. /* data on rising edge of bclk, frame high with data */
  98. strcr |= SSI_STCR_TFSL | SSI_STCR_TXBIT0;
  99. break;
  100. case SND_SOC_DAIFMT_DSP_A:
  101. /* data on rising edge of bclk, frame high 1clk before data */
  102. strcr |= SSI_STCR_TFSL | SSI_STCR_TXBIT0 | SSI_STCR_TEFS;
  103. break;
  104. }
  105. /* DAI clock inversion */
  106. switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
  107. case SND_SOC_DAIFMT_IB_IF:
  108. strcr |= SSI_STCR_TFSI;
  109. strcr &= ~SSI_STCR_TSCKP;
  110. break;
  111. case SND_SOC_DAIFMT_IB_NF:
  112. strcr &= ~(SSI_STCR_TSCKP | SSI_STCR_TFSI);
  113. break;
  114. case SND_SOC_DAIFMT_NB_IF:
  115. strcr |= SSI_STCR_TFSI | SSI_STCR_TSCKP;
  116. break;
  117. case SND_SOC_DAIFMT_NB_NF:
  118. strcr &= ~SSI_STCR_TFSI;
  119. strcr |= SSI_STCR_TSCKP;
  120. break;
  121. }
  122. /* DAI clock master masks */
  123. switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  124. case SND_SOC_DAIFMT_CBM_CFM:
  125. break;
  126. default:
  127. /* Master mode not implemented, needs handling of clocks. */
  128. return -EINVAL;
  129. }
  130. strcr |= SSI_STCR_TFEN0;
  131. if (ssi->flags & IMX_SSI_NET)
  132. scr |= SSI_SCR_NET;
  133. if (ssi->flags & IMX_SSI_SYN)
  134. scr |= SSI_SCR_SYN;
  135. writel(strcr, ssi->base + SSI_STCR);
  136. writel(strcr, ssi->base + SSI_SRCR);
  137. writel(scr, ssi->base + SSI_SCR);
  138. return 0;
  139. }
  140. /*
  141. * SSI system clock configuration.
  142. * Should only be called when port is inactive (i.e. SSIEN = 0).
  143. */
  144. static int imx_ssi_set_dai_sysclk(struct snd_soc_dai *cpu_dai,
  145. int clk_id, unsigned int freq, int dir)
  146. {
  147. struct imx_ssi *ssi = snd_soc_dai_get_drvdata(cpu_dai);
  148. u32 scr;
  149. scr = readl(ssi->base + SSI_SCR);
  150. switch (clk_id) {
  151. case IMX_SSP_SYS_CLK:
  152. if (dir == SND_SOC_CLOCK_OUT)
  153. scr |= SSI_SCR_SYS_CLK_EN;
  154. else
  155. scr &= ~SSI_SCR_SYS_CLK_EN;
  156. break;
  157. default:
  158. return -EINVAL;
  159. }
  160. writel(scr, ssi->base + SSI_SCR);
  161. return 0;
  162. }
  163. /*
  164. * SSI Clock dividers
  165. * Should only be called when port is inactive (i.e. SSIEN = 0).
  166. */
  167. static int imx_ssi_set_dai_clkdiv(struct snd_soc_dai *cpu_dai,
  168. int div_id, int div)
  169. {
  170. struct imx_ssi *ssi = snd_soc_dai_get_drvdata(cpu_dai);
  171. u32 stccr, srccr;
  172. stccr = readl(ssi->base + SSI_STCCR);
  173. srccr = readl(ssi->base + SSI_SRCCR);
  174. switch (div_id) {
  175. case IMX_SSI_TX_DIV_2:
  176. stccr &= ~SSI_STCCR_DIV2;
  177. stccr |= div;
  178. break;
  179. case IMX_SSI_TX_DIV_PSR:
  180. stccr &= ~SSI_STCCR_PSR;
  181. stccr |= div;
  182. break;
  183. case IMX_SSI_TX_DIV_PM:
  184. stccr &= ~0xff;
  185. stccr |= SSI_STCCR_PM(div);
  186. break;
  187. case IMX_SSI_RX_DIV_2:
  188. stccr &= ~SSI_STCCR_DIV2;
  189. stccr |= div;
  190. break;
  191. case IMX_SSI_RX_DIV_PSR:
  192. stccr &= ~SSI_STCCR_PSR;
  193. stccr |= div;
  194. break;
  195. case IMX_SSI_RX_DIV_PM:
  196. stccr &= ~0xff;
  197. stccr |= SSI_STCCR_PM(div);
  198. break;
  199. default:
  200. return -EINVAL;
  201. }
  202. writel(stccr, ssi->base + SSI_STCCR);
  203. writel(srccr, ssi->base + SSI_SRCCR);
  204. return 0;
  205. }
  206. static int imx_ssi_startup(struct snd_pcm_substream *substream,
  207. struct snd_soc_dai *cpu_dai)
  208. {
  209. struct imx_ssi *ssi = snd_soc_dai_get_drvdata(cpu_dai);
  210. struct imx_pcm_dma_params *dma_data;
  211. /* Tx/Rx config */
  212. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  213. dma_data = &ssi->dma_params_tx;
  214. else
  215. dma_data = &ssi->dma_params_rx;
  216. snd_soc_dai_set_dma_data(cpu_dai, substream, dma_data);
  217. return 0;
  218. }
  219. /*
  220. * Should only be called when port is inactive (i.e. SSIEN = 0),
  221. * although can be called multiple times by upper layers.
  222. */
  223. static int imx_ssi_hw_params(struct snd_pcm_substream *substream,
  224. struct snd_pcm_hw_params *params,
  225. struct snd_soc_dai *cpu_dai)
  226. {
  227. struct imx_ssi *ssi = snd_soc_dai_get_drvdata(cpu_dai);
  228. u32 reg, sccr;
  229. /* Tx/Rx config */
  230. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  231. reg = SSI_STCCR;
  232. else
  233. reg = SSI_SRCCR;
  234. if (ssi->flags & IMX_SSI_SYN)
  235. reg = SSI_STCCR;
  236. sccr = readl(ssi->base + reg) & ~SSI_STCCR_WL_MASK;
  237. /* DAI data (word) size */
  238. switch (params_format(params)) {
  239. case SNDRV_PCM_FORMAT_S16_LE:
  240. sccr |= SSI_SRCCR_WL(16);
  241. break;
  242. case SNDRV_PCM_FORMAT_S20_3LE:
  243. sccr |= SSI_SRCCR_WL(20);
  244. break;
  245. case SNDRV_PCM_FORMAT_S24_LE:
  246. sccr |= SSI_SRCCR_WL(24);
  247. break;
  248. }
  249. writel(sccr, ssi->base + reg);
  250. return 0;
  251. }
  252. static int imx_ssi_trigger(struct snd_pcm_substream *substream, int cmd,
  253. struct snd_soc_dai *dai)
  254. {
  255. struct imx_ssi *ssi = snd_soc_dai_get_drvdata(dai);
  256. unsigned int sier_bits, sier;
  257. unsigned int scr;
  258. scr = readl(ssi->base + SSI_SCR);
  259. sier = readl(ssi->base + SSI_SIER);
  260. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  261. if (ssi->flags & IMX_SSI_DMA)
  262. sier_bits = SSI_SIER_TDMAE;
  263. else
  264. sier_bits = SSI_SIER_TIE | SSI_SIER_TFE0_EN;
  265. } else {
  266. if (ssi->flags & IMX_SSI_DMA)
  267. sier_bits = SSI_SIER_RDMAE;
  268. else
  269. sier_bits = SSI_SIER_RIE | SSI_SIER_RFF0_EN;
  270. }
  271. switch (cmd) {
  272. case SNDRV_PCM_TRIGGER_START:
  273. case SNDRV_PCM_TRIGGER_RESUME:
  274. case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  275. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  276. scr |= SSI_SCR_TE;
  277. else
  278. scr |= SSI_SCR_RE;
  279. sier |= sier_bits;
  280. if (++ssi->enabled == 1)
  281. scr |= SSI_SCR_SSIEN;
  282. break;
  283. case SNDRV_PCM_TRIGGER_STOP:
  284. case SNDRV_PCM_TRIGGER_SUSPEND:
  285. case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  286. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  287. scr &= ~SSI_SCR_TE;
  288. else
  289. scr &= ~SSI_SCR_RE;
  290. sier &= ~sier_bits;
  291. if (--ssi->enabled == 0)
  292. scr &= ~SSI_SCR_SSIEN;
  293. break;
  294. default:
  295. return -EINVAL;
  296. }
  297. if (!(ssi->flags & IMX_SSI_USE_AC97))
  298. /* rx/tx are always enabled to access ac97 registers */
  299. writel(scr, ssi->base + SSI_SCR);
  300. writel(sier, ssi->base + SSI_SIER);
  301. return 0;
  302. }
  303. static const struct snd_soc_dai_ops imx_ssi_pcm_dai_ops = {
  304. .startup = imx_ssi_startup,
  305. .hw_params = imx_ssi_hw_params,
  306. .set_fmt = imx_ssi_set_dai_fmt,
  307. .set_clkdiv = imx_ssi_set_dai_clkdiv,
  308. .set_sysclk = imx_ssi_set_dai_sysclk,
  309. .set_tdm_slot = imx_ssi_set_dai_tdm_slot,
  310. .trigger = imx_ssi_trigger,
  311. };
  312. static int imx_ssi_dai_probe(struct snd_soc_dai *dai)
  313. {
  314. struct imx_ssi *ssi = dev_get_drvdata(dai->dev);
  315. uint32_t val;
  316. snd_soc_dai_set_drvdata(dai, ssi);
  317. val = SSI_SFCSR_TFWM0(ssi->dma_params_tx.burstsize) |
  318. SSI_SFCSR_RFWM0(ssi->dma_params_rx.burstsize);
  319. writel(val, ssi->base + SSI_SFCSR);
  320. return 0;
  321. }
  322. static struct snd_soc_dai_driver imx_ssi_dai = {
  323. .probe = imx_ssi_dai_probe,
  324. .playback = {
  325. .channels_min = 1,
  326. .channels_max = 2,
  327. .rates = SNDRV_PCM_RATE_8000_96000,
  328. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  329. },
  330. .capture = {
  331. .channels_min = 1,
  332. .channels_max = 2,
  333. .rates = SNDRV_PCM_RATE_8000_96000,
  334. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  335. },
  336. .ops = &imx_ssi_pcm_dai_ops,
  337. };
  338. static struct snd_soc_dai_driver imx_ac97_dai = {
  339. .probe = imx_ssi_dai_probe,
  340. .ac97_control = 1,
  341. .playback = {
  342. .stream_name = "AC97 Playback",
  343. .channels_min = 2,
  344. .channels_max = 2,
  345. .rates = SNDRV_PCM_RATE_48000,
  346. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  347. },
  348. .capture = {
  349. .stream_name = "AC97 Capture",
  350. .channels_min = 2,
  351. .channels_max = 2,
  352. .rates = SNDRV_PCM_RATE_48000,
  353. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  354. },
  355. .ops = &imx_ssi_pcm_dai_ops,
  356. };
  357. static void setup_channel_to_ac97(struct imx_ssi *imx_ssi)
  358. {
  359. void __iomem *base = imx_ssi->base;
  360. writel(0x0, base + SSI_SCR);
  361. writel(0x0, base + SSI_STCR);
  362. writel(0x0, base + SSI_SRCR);
  363. writel(SSI_SCR_SYN | SSI_SCR_NET, base + SSI_SCR);
  364. writel(SSI_SFCSR_RFWM0(8) |
  365. SSI_SFCSR_TFWM0(8) |
  366. SSI_SFCSR_RFWM1(8) |
  367. SSI_SFCSR_TFWM1(8), base + SSI_SFCSR);
  368. writel(SSI_STCCR_WL(16) | SSI_STCCR_DC(12), base + SSI_STCCR);
  369. writel(SSI_STCCR_WL(16) | SSI_STCCR_DC(12), base + SSI_SRCCR);
  370. writel(SSI_SCR_SYN | SSI_SCR_NET | SSI_SCR_SSIEN, base + SSI_SCR);
  371. writel(SSI_SOR_WAIT(3), base + SSI_SOR);
  372. writel(SSI_SCR_SYN | SSI_SCR_NET | SSI_SCR_SSIEN |
  373. SSI_SCR_TE | SSI_SCR_RE,
  374. base + SSI_SCR);
  375. writel(SSI_SACNT_DEFAULT, base + SSI_SACNT);
  376. writel(0xff, base + SSI_SACCDIS);
  377. writel(0x300, base + SSI_SACCEN);
  378. }
  379. static struct imx_ssi *ac97_ssi;
  380. static void imx_ssi_ac97_write(struct snd_ac97 *ac97, unsigned short reg,
  381. unsigned short val)
  382. {
  383. struct imx_ssi *imx_ssi = ac97_ssi;
  384. void __iomem *base = imx_ssi->base;
  385. unsigned int lreg;
  386. unsigned int lval;
  387. if (reg > 0x7f)
  388. return;
  389. pr_debug("%s: 0x%02x 0x%04x\n", __func__, reg, val);
  390. lreg = reg << 12;
  391. writel(lreg, base + SSI_SACADD);
  392. lval = val << 4;
  393. writel(lval , base + SSI_SACDAT);
  394. writel(SSI_SACNT_DEFAULT | SSI_SACNT_WR, base + SSI_SACNT);
  395. udelay(100);
  396. }
  397. static unsigned short imx_ssi_ac97_read(struct snd_ac97 *ac97,
  398. unsigned short reg)
  399. {
  400. struct imx_ssi *imx_ssi = ac97_ssi;
  401. void __iomem *base = imx_ssi->base;
  402. unsigned short val = -1;
  403. unsigned int lreg;
  404. lreg = (reg & 0x7f) << 12 ;
  405. writel(lreg, base + SSI_SACADD);
  406. writel(SSI_SACNT_DEFAULT | SSI_SACNT_RD, base + SSI_SACNT);
  407. udelay(100);
  408. val = (readl(base + SSI_SACDAT) >> 4) & 0xffff;
  409. pr_debug("%s: 0x%02x 0x%04x\n", __func__, reg, val);
  410. return val;
  411. }
  412. static void imx_ssi_ac97_reset(struct snd_ac97 *ac97)
  413. {
  414. struct imx_ssi *imx_ssi = ac97_ssi;
  415. if (imx_ssi->ac97_reset)
  416. imx_ssi->ac97_reset(ac97);
  417. /* First read sometimes fails, do a dummy read */
  418. imx_ssi_ac97_read(ac97, 0);
  419. }
  420. static void imx_ssi_ac97_warm_reset(struct snd_ac97 *ac97)
  421. {
  422. struct imx_ssi *imx_ssi = ac97_ssi;
  423. if (imx_ssi->ac97_warm_reset)
  424. imx_ssi->ac97_warm_reset(ac97);
  425. /* First read sometimes fails, do a dummy read */
  426. imx_ssi_ac97_read(ac97, 0);
  427. }
  428. struct snd_ac97_bus_ops soc_ac97_ops = {
  429. .read = imx_ssi_ac97_read,
  430. .write = imx_ssi_ac97_write,
  431. .reset = imx_ssi_ac97_reset,
  432. .warm_reset = imx_ssi_ac97_warm_reset
  433. };
  434. EXPORT_SYMBOL_GPL(soc_ac97_ops);
  435. static int imx_ssi_probe(struct platform_device *pdev)
  436. {
  437. struct resource *res;
  438. struct imx_ssi *ssi;
  439. struct imx_ssi_platform_data *pdata = pdev->dev.platform_data;
  440. int ret = 0;
  441. struct snd_soc_dai_driver *dai;
  442. ssi = kzalloc(sizeof(*ssi), GFP_KERNEL);
  443. if (!ssi)
  444. return -ENOMEM;
  445. dev_set_drvdata(&pdev->dev, ssi);
  446. if (pdata) {
  447. ssi->ac97_reset = pdata->ac97_reset;
  448. ssi->ac97_warm_reset = pdata->ac97_warm_reset;
  449. ssi->flags = pdata->flags;
  450. }
  451. ssi->irq = platform_get_irq(pdev, 0);
  452. ssi->clk = clk_get(&pdev->dev, NULL);
  453. if (IS_ERR(ssi->clk)) {
  454. ret = PTR_ERR(ssi->clk);
  455. dev_err(&pdev->dev, "Cannot get the clock: %d\n",
  456. ret);
  457. goto failed_clk;
  458. }
  459. clk_enable(ssi->clk);
  460. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  461. if (!res) {
  462. ret = -ENODEV;
  463. goto failed_get_resource;
  464. }
  465. if (!request_mem_region(res->start, resource_size(res), DRV_NAME)) {
  466. dev_err(&pdev->dev, "request_mem_region failed\n");
  467. ret = -EBUSY;
  468. goto failed_get_resource;
  469. }
  470. ssi->base = ioremap(res->start, resource_size(res));
  471. if (!ssi->base) {
  472. dev_err(&pdev->dev, "ioremap failed\n");
  473. ret = -ENODEV;
  474. goto failed_ioremap;
  475. }
  476. if (ssi->flags & IMX_SSI_USE_AC97) {
  477. if (ac97_ssi) {
  478. ret = -EBUSY;
  479. goto failed_ac97;
  480. }
  481. ac97_ssi = ssi;
  482. setup_channel_to_ac97(ssi);
  483. dai = &imx_ac97_dai;
  484. } else
  485. dai = &imx_ssi_dai;
  486. writel(0x0, ssi->base + SSI_SIER);
  487. ssi->dma_params_rx.dma_addr = res->start + SSI_SRX0;
  488. ssi->dma_params_tx.dma_addr = res->start + SSI_STX0;
  489. ssi->dma_params_tx.burstsize = 6;
  490. ssi->dma_params_rx.burstsize = 4;
  491. res = platform_get_resource_byname(pdev, IORESOURCE_DMA, "tx0");
  492. if (res)
  493. ssi->dma_params_tx.dma = res->start;
  494. res = platform_get_resource_byname(pdev, IORESOURCE_DMA, "rx0");
  495. if (res)
  496. ssi->dma_params_rx.dma = res->start;
  497. platform_set_drvdata(pdev, ssi);
  498. ret = snd_soc_register_dai(&pdev->dev, dai);
  499. if (ret) {
  500. dev_err(&pdev->dev, "register DAI failed\n");
  501. goto failed_register;
  502. }
  503. ssi->soc_platform_pdev_fiq = platform_device_alloc("imx-fiq-pcm-audio", pdev->id);
  504. if (!ssi->soc_platform_pdev_fiq) {
  505. ret = -ENOMEM;
  506. goto failed_pdev_fiq_alloc;
  507. }
  508. platform_set_drvdata(ssi->soc_platform_pdev_fiq, ssi);
  509. ret = platform_device_add(ssi->soc_platform_pdev_fiq);
  510. if (ret) {
  511. dev_err(&pdev->dev, "failed to add platform device\n");
  512. goto failed_pdev_fiq_add;
  513. }
  514. ssi->soc_platform_pdev = platform_device_alloc("imx-pcm-audio", pdev->id);
  515. if (!ssi->soc_platform_pdev) {
  516. ret = -ENOMEM;
  517. goto failed_pdev_alloc;
  518. }
  519. platform_set_drvdata(ssi->soc_platform_pdev, ssi);
  520. ret = platform_device_add(ssi->soc_platform_pdev);
  521. if (ret) {
  522. dev_err(&pdev->dev, "failed to add platform device\n");
  523. goto failed_pdev_add;
  524. }
  525. return 0;
  526. failed_pdev_add:
  527. platform_device_put(ssi->soc_platform_pdev);
  528. failed_pdev_alloc:
  529. platform_device_del(ssi->soc_platform_pdev_fiq);
  530. failed_pdev_fiq_add:
  531. platform_device_put(ssi->soc_platform_pdev_fiq);
  532. failed_pdev_fiq_alloc:
  533. snd_soc_unregister_dai(&pdev->dev);
  534. failed_register:
  535. failed_ac97:
  536. iounmap(ssi->base);
  537. failed_ioremap:
  538. release_mem_region(res->start, resource_size(res));
  539. failed_get_resource:
  540. clk_disable(ssi->clk);
  541. clk_put(ssi->clk);
  542. failed_clk:
  543. kfree(ssi);
  544. return ret;
  545. }
  546. static int __devexit imx_ssi_remove(struct platform_device *pdev)
  547. {
  548. struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  549. struct imx_ssi *ssi = platform_get_drvdata(pdev);
  550. platform_device_unregister(ssi->soc_platform_pdev);
  551. platform_device_unregister(ssi->soc_platform_pdev_fiq);
  552. snd_soc_unregister_dai(&pdev->dev);
  553. if (ssi->flags & IMX_SSI_USE_AC97)
  554. ac97_ssi = NULL;
  555. iounmap(ssi->base);
  556. release_mem_region(res->start, resource_size(res));
  557. clk_disable(ssi->clk);
  558. clk_put(ssi->clk);
  559. kfree(ssi);
  560. return 0;
  561. }
  562. static struct platform_driver imx_ssi_driver = {
  563. .probe = imx_ssi_probe,
  564. .remove = __devexit_p(imx_ssi_remove),
  565. .driver = {
  566. .name = "imx-ssi",
  567. .owner = THIS_MODULE,
  568. },
  569. };
  570. module_platform_driver(imx_ssi_driver);
  571. /* Module information */
  572. MODULE_AUTHOR("Sascha Hauer, <s.hauer@pengutronix.de>");
  573. MODULE_DESCRIPTION("i.MX I2S/ac97 SoC Interface");
  574. MODULE_LICENSE("GPL");
  575. MODULE_ALIAS("platform:imx-ssi");