imx-ssi.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  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 <linux/platform_data/asoc-imx-ssi.h>
  48. #include "imx-ssi.h"
  49. #include "fsl_utils.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_TXBIT0 | SSI_STCR_TSCKP | SSI_STCR_TFSI |
  86. SSI_STCR_TEFS;
  87. scr |= SSI_SCR_NET;
  88. if (ssi->flags & IMX_SSI_USE_I2S_SLAVE) {
  89. scr &= ~SSI_I2S_MODE_MASK;
  90. scr |= SSI_SCR_I2S_MODE_SLAVE;
  91. }
  92. break;
  93. case SND_SOC_DAIFMT_LEFT_J:
  94. /* data on rising edge of bclk, frame high with data */
  95. strcr |= SSI_STCR_TXBIT0 | SSI_STCR_TSCKP;
  96. break;
  97. case SND_SOC_DAIFMT_DSP_B:
  98. /* data on rising edge of bclk, frame high with data */
  99. strcr |= SSI_STCR_TXBIT0 | SSI_STCR_TSCKP | SSI_STCR_TFSL;
  100. break;
  101. case SND_SOC_DAIFMT_DSP_A:
  102. /* data on rising edge of bclk, frame high 1clk before data */
  103. strcr |= SSI_STCR_TXBIT0 | SSI_STCR_TSCKP | SSI_STCR_TFSL |
  104. SSI_STCR_TEFS;
  105. break;
  106. }
  107. /* DAI clock inversion */
  108. switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
  109. case SND_SOC_DAIFMT_IB_IF:
  110. strcr ^= SSI_STCR_TSCKP | SSI_STCR_TFSI;
  111. break;
  112. case SND_SOC_DAIFMT_IB_NF:
  113. strcr ^= SSI_STCR_TSCKP;
  114. break;
  115. case SND_SOC_DAIFMT_NB_IF:
  116. strcr ^= SSI_STCR_TFSI;
  117. break;
  118. case SND_SOC_DAIFMT_NB_NF:
  119. break;
  120. }
  121. /* DAI clock master masks */
  122. switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  123. case SND_SOC_DAIFMT_CBM_CFM:
  124. break;
  125. default:
  126. /* Master mode not implemented, needs handling of clocks. */
  127. return -EINVAL;
  128. }
  129. strcr |= SSI_STCR_TFEN0;
  130. if (ssi->flags & IMX_SSI_NET)
  131. scr |= SSI_SCR_NET;
  132. if (ssi->flags & IMX_SSI_SYN)
  133. scr |= SSI_SCR_SYN;
  134. writel(strcr, ssi->base + SSI_STCR);
  135. writel(strcr, ssi->base + SSI_SRCR);
  136. writel(scr, ssi->base + SSI_SCR);
  137. return 0;
  138. }
  139. /*
  140. * SSI system clock configuration.
  141. * Should only be called when port is inactive (i.e. SSIEN = 0).
  142. */
  143. static int imx_ssi_set_dai_sysclk(struct snd_soc_dai *cpu_dai,
  144. int clk_id, unsigned int freq, int dir)
  145. {
  146. struct imx_ssi *ssi = snd_soc_dai_get_drvdata(cpu_dai);
  147. u32 scr;
  148. scr = readl(ssi->base + SSI_SCR);
  149. switch (clk_id) {
  150. case IMX_SSP_SYS_CLK:
  151. if (dir == SND_SOC_CLOCK_OUT)
  152. scr |= SSI_SCR_SYS_CLK_EN;
  153. else
  154. scr &= ~SSI_SCR_SYS_CLK_EN;
  155. break;
  156. default:
  157. return -EINVAL;
  158. }
  159. writel(scr, ssi->base + SSI_SCR);
  160. return 0;
  161. }
  162. /*
  163. * SSI Clock dividers
  164. * Should only be called when port is inactive (i.e. SSIEN = 0).
  165. */
  166. static int imx_ssi_set_dai_clkdiv(struct snd_soc_dai *cpu_dai,
  167. int div_id, int div)
  168. {
  169. struct imx_ssi *ssi = snd_soc_dai_get_drvdata(cpu_dai);
  170. u32 stccr, srccr;
  171. stccr = readl(ssi->base + SSI_STCCR);
  172. srccr = readl(ssi->base + SSI_SRCCR);
  173. switch (div_id) {
  174. case IMX_SSI_TX_DIV_2:
  175. stccr &= ~SSI_STCCR_DIV2;
  176. stccr |= div;
  177. break;
  178. case IMX_SSI_TX_DIV_PSR:
  179. stccr &= ~SSI_STCCR_PSR;
  180. stccr |= div;
  181. break;
  182. case IMX_SSI_TX_DIV_PM:
  183. stccr &= ~0xff;
  184. stccr |= SSI_STCCR_PM(div);
  185. break;
  186. case IMX_SSI_RX_DIV_2:
  187. stccr &= ~SSI_STCCR_DIV2;
  188. stccr |= div;
  189. break;
  190. case IMX_SSI_RX_DIV_PSR:
  191. stccr &= ~SSI_STCCR_PSR;
  192. stccr |= div;
  193. break;
  194. case IMX_SSI_RX_DIV_PM:
  195. stccr &= ~0xff;
  196. stccr |= SSI_STCCR_PM(div);
  197. break;
  198. default:
  199. return -EINVAL;
  200. }
  201. writel(stccr, ssi->base + SSI_STCCR);
  202. writel(srccr, ssi->base + SSI_SRCCR);
  203. return 0;
  204. }
  205. /*
  206. * Should only be called when port is inactive (i.e. SSIEN = 0),
  207. * although can be called multiple times by upper layers.
  208. */
  209. static int imx_ssi_hw_params(struct snd_pcm_substream *substream,
  210. struct snd_pcm_hw_params *params,
  211. struct snd_soc_dai *cpu_dai)
  212. {
  213. struct imx_ssi *ssi = snd_soc_dai_get_drvdata(cpu_dai);
  214. u32 reg, sccr;
  215. /* Tx/Rx config */
  216. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  217. reg = SSI_STCCR;
  218. else
  219. reg = SSI_SRCCR;
  220. if (ssi->flags & IMX_SSI_SYN)
  221. reg = SSI_STCCR;
  222. sccr = readl(ssi->base + reg) & ~SSI_STCCR_WL_MASK;
  223. /* DAI data (word) size */
  224. switch (params_format(params)) {
  225. case SNDRV_PCM_FORMAT_S16_LE:
  226. sccr |= SSI_SRCCR_WL(16);
  227. break;
  228. case SNDRV_PCM_FORMAT_S20_3LE:
  229. sccr |= SSI_SRCCR_WL(20);
  230. break;
  231. case SNDRV_PCM_FORMAT_S24_LE:
  232. sccr |= SSI_SRCCR_WL(24);
  233. break;
  234. }
  235. writel(sccr, ssi->base + reg);
  236. return 0;
  237. }
  238. static int imx_ssi_trigger(struct snd_pcm_substream *substream, int cmd,
  239. struct snd_soc_dai *dai)
  240. {
  241. struct imx_ssi *ssi = snd_soc_dai_get_drvdata(dai);
  242. unsigned int sier_bits, sier;
  243. unsigned int scr;
  244. scr = readl(ssi->base + SSI_SCR);
  245. sier = readl(ssi->base + SSI_SIER);
  246. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  247. if (ssi->flags & IMX_SSI_DMA)
  248. sier_bits = SSI_SIER_TDMAE;
  249. else
  250. sier_bits = SSI_SIER_TIE | SSI_SIER_TFE0_EN;
  251. } else {
  252. if (ssi->flags & IMX_SSI_DMA)
  253. sier_bits = SSI_SIER_RDMAE;
  254. else
  255. sier_bits = SSI_SIER_RIE | SSI_SIER_RFF0_EN;
  256. }
  257. switch (cmd) {
  258. case SNDRV_PCM_TRIGGER_START:
  259. case SNDRV_PCM_TRIGGER_RESUME:
  260. case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  261. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  262. scr |= SSI_SCR_TE;
  263. else
  264. scr |= SSI_SCR_RE;
  265. sier |= sier_bits;
  266. scr |= SSI_SCR_SSIEN;
  267. break;
  268. case SNDRV_PCM_TRIGGER_STOP:
  269. case SNDRV_PCM_TRIGGER_SUSPEND:
  270. case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  271. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  272. scr &= ~SSI_SCR_TE;
  273. else
  274. scr &= ~SSI_SCR_RE;
  275. sier &= ~sier_bits;
  276. if (!(scr & (SSI_SCR_TE | SSI_SCR_RE)))
  277. scr &= ~SSI_SCR_SSIEN;
  278. break;
  279. default:
  280. return -EINVAL;
  281. }
  282. if (!(ssi->flags & IMX_SSI_USE_AC97))
  283. /* rx/tx are always enabled to access ac97 registers */
  284. writel(scr, ssi->base + SSI_SCR);
  285. writel(sier, ssi->base + SSI_SIER);
  286. return 0;
  287. }
  288. static const struct snd_soc_dai_ops imx_ssi_pcm_dai_ops = {
  289. .hw_params = imx_ssi_hw_params,
  290. .set_fmt = imx_ssi_set_dai_fmt,
  291. .set_clkdiv = imx_ssi_set_dai_clkdiv,
  292. .set_sysclk = imx_ssi_set_dai_sysclk,
  293. .set_tdm_slot = imx_ssi_set_dai_tdm_slot,
  294. .trigger = imx_ssi_trigger,
  295. };
  296. static int imx_ssi_dai_probe(struct snd_soc_dai *dai)
  297. {
  298. struct imx_ssi *ssi = dev_get_drvdata(dai->dev);
  299. uint32_t val;
  300. snd_soc_dai_set_drvdata(dai, ssi);
  301. val = SSI_SFCSR_TFWM0(ssi->dma_params_tx.maxburst) |
  302. SSI_SFCSR_RFWM0(ssi->dma_params_rx.maxburst);
  303. writel(val, ssi->base + SSI_SFCSR);
  304. /* Tx/Rx config */
  305. dai->playback_dma_data = &ssi->dma_params_tx;
  306. dai->capture_dma_data = &ssi->dma_params_rx;
  307. return 0;
  308. }
  309. static struct snd_soc_dai_driver imx_ssi_dai = {
  310. .probe = imx_ssi_dai_probe,
  311. .playback = {
  312. .channels_min = 1,
  313. .channels_max = 2,
  314. .rates = SNDRV_PCM_RATE_8000_96000,
  315. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  316. },
  317. .capture = {
  318. .channels_min = 1,
  319. .channels_max = 2,
  320. .rates = SNDRV_PCM_RATE_8000_96000,
  321. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  322. },
  323. .ops = &imx_ssi_pcm_dai_ops,
  324. };
  325. static struct snd_soc_dai_driver imx_ac97_dai = {
  326. .probe = imx_ssi_dai_probe,
  327. .bus_control = true,
  328. .playback = {
  329. .stream_name = "AC97 Playback",
  330. .channels_min = 2,
  331. .channels_max = 2,
  332. .rates = SNDRV_PCM_RATE_8000_48000,
  333. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  334. },
  335. .capture = {
  336. .stream_name = "AC97 Capture",
  337. .channels_min = 2,
  338. .channels_max = 2,
  339. .rates = SNDRV_PCM_RATE_48000,
  340. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  341. },
  342. .ops = &imx_ssi_pcm_dai_ops,
  343. };
  344. static const struct snd_soc_component_driver imx_component = {
  345. .name = DRV_NAME,
  346. };
  347. static void setup_channel_to_ac97(struct imx_ssi *imx_ssi)
  348. {
  349. void __iomem *base = imx_ssi->base;
  350. writel(0x0, base + SSI_SCR);
  351. writel(0x0, base + SSI_STCR);
  352. writel(0x0, base + SSI_SRCR);
  353. writel(SSI_SCR_SYN | SSI_SCR_NET, base + SSI_SCR);
  354. writel(SSI_SFCSR_RFWM0(8) |
  355. SSI_SFCSR_TFWM0(8) |
  356. SSI_SFCSR_RFWM1(8) |
  357. SSI_SFCSR_TFWM1(8), base + SSI_SFCSR);
  358. writel(SSI_STCCR_WL(16) | SSI_STCCR_DC(12), base + SSI_STCCR);
  359. writel(SSI_STCCR_WL(16) | SSI_STCCR_DC(12), base + SSI_SRCCR);
  360. writel(SSI_SCR_SYN | SSI_SCR_NET | SSI_SCR_SSIEN, base + SSI_SCR);
  361. writel(SSI_SOR_WAIT(3), base + SSI_SOR);
  362. writel(SSI_SCR_SYN | SSI_SCR_NET | SSI_SCR_SSIEN |
  363. SSI_SCR_TE | SSI_SCR_RE,
  364. base + SSI_SCR);
  365. writel(SSI_SACNT_DEFAULT, base + SSI_SACNT);
  366. writel(0xff, base + SSI_SACCDIS);
  367. writel(0x300, base + SSI_SACCEN);
  368. }
  369. static struct imx_ssi *ac97_ssi;
  370. static void imx_ssi_ac97_write(struct snd_ac97 *ac97, unsigned short reg,
  371. unsigned short val)
  372. {
  373. struct imx_ssi *imx_ssi = ac97_ssi;
  374. void __iomem *base = imx_ssi->base;
  375. unsigned int lreg;
  376. unsigned int lval;
  377. if (reg > 0x7f)
  378. return;
  379. pr_debug("%s: 0x%02x 0x%04x\n", __func__, reg, val);
  380. lreg = reg << 12;
  381. writel(lreg, base + SSI_SACADD);
  382. lval = val << 4;
  383. writel(lval , base + SSI_SACDAT);
  384. writel(SSI_SACNT_DEFAULT | SSI_SACNT_WR, base + SSI_SACNT);
  385. udelay(100);
  386. }
  387. static unsigned short imx_ssi_ac97_read(struct snd_ac97 *ac97,
  388. unsigned short reg)
  389. {
  390. struct imx_ssi *imx_ssi = ac97_ssi;
  391. void __iomem *base = imx_ssi->base;
  392. unsigned short val = -1;
  393. unsigned int lreg;
  394. lreg = (reg & 0x7f) << 12 ;
  395. writel(lreg, base + SSI_SACADD);
  396. writel(SSI_SACNT_DEFAULT | SSI_SACNT_RD, base + SSI_SACNT);
  397. udelay(100);
  398. val = (readl(base + SSI_SACDAT) >> 4) & 0xffff;
  399. pr_debug("%s: 0x%02x 0x%04x\n", __func__, reg, val);
  400. return val;
  401. }
  402. static void imx_ssi_ac97_reset(struct snd_ac97 *ac97)
  403. {
  404. struct imx_ssi *imx_ssi = ac97_ssi;
  405. if (imx_ssi->ac97_reset)
  406. imx_ssi->ac97_reset(ac97);
  407. /* First read sometimes fails, do a dummy read */
  408. imx_ssi_ac97_read(ac97, 0);
  409. }
  410. static void imx_ssi_ac97_warm_reset(struct snd_ac97 *ac97)
  411. {
  412. struct imx_ssi *imx_ssi = ac97_ssi;
  413. if (imx_ssi->ac97_warm_reset)
  414. imx_ssi->ac97_warm_reset(ac97);
  415. /* First read sometimes fails, do a dummy read */
  416. imx_ssi_ac97_read(ac97, 0);
  417. }
  418. static struct snd_ac97_bus_ops imx_ssi_ac97_ops = {
  419. .read = imx_ssi_ac97_read,
  420. .write = imx_ssi_ac97_write,
  421. .reset = imx_ssi_ac97_reset,
  422. .warm_reset = imx_ssi_ac97_warm_reset
  423. };
  424. static int imx_ssi_probe(struct platform_device *pdev)
  425. {
  426. struct resource *res;
  427. struct imx_ssi *ssi;
  428. struct imx_ssi_platform_data *pdata = pdev->dev.platform_data;
  429. int ret = 0;
  430. struct snd_soc_dai_driver *dai;
  431. ssi = devm_kzalloc(&pdev->dev, sizeof(*ssi), GFP_KERNEL);
  432. if (!ssi)
  433. return -ENOMEM;
  434. dev_set_drvdata(&pdev->dev, ssi);
  435. if (pdata) {
  436. ssi->ac97_reset = pdata->ac97_reset;
  437. ssi->ac97_warm_reset = pdata->ac97_warm_reset;
  438. ssi->flags = pdata->flags;
  439. }
  440. ssi->irq = platform_get_irq(pdev, 0);
  441. ssi->clk = devm_clk_get(&pdev->dev, NULL);
  442. if (IS_ERR(ssi->clk)) {
  443. ret = PTR_ERR(ssi->clk);
  444. dev_err(&pdev->dev, "Cannot get the clock: %d\n",
  445. ret);
  446. goto failed_clk;
  447. }
  448. ret = clk_prepare_enable(ssi->clk);
  449. if (ret)
  450. goto failed_clk;
  451. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  452. ssi->base = devm_ioremap_resource(&pdev->dev, res);
  453. if (IS_ERR(ssi->base)) {
  454. ret = PTR_ERR(ssi->base);
  455. goto failed_register;
  456. }
  457. if (ssi->flags & IMX_SSI_USE_AC97) {
  458. if (ac97_ssi) {
  459. dev_err(&pdev->dev, "AC'97 SSI already registered\n");
  460. ret = -EBUSY;
  461. goto failed_register;
  462. }
  463. ac97_ssi = ssi;
  464. setup_channel_to_ac97(ssi);
  465. dai = &imx_ac97_dai;
  466. } else
  467. dai = &imx_ssi_dai;
  468. writel(0x0, ssi->base + SSI_SIER);
  469. ssi->dma_params_rx.addr = res->start + SSI_SRX0;
  470. ssi->dma_params_tx.addr = res->start + SSI_STX0;
  471. ssi->dma_params_tx.maxburst = 6;
  472. ssi->dma_params_rx.maxburst = 4;
  473. ssi->dma_params_tx.filter_data = &ssi->filter_data_tx;
  474. ssi->dma_params_rx.filter_data = &ssi->filter_data_rx;
  475. res = platform_get_resource_byname(pdev, IORESOURCE_DMA, "tx0");
  476. if (res) {
  477. imx_pcm_dma_params_init_data(&ssi->filter_data_tx, res->start,
  478. IMX_DMATYPE_SSI);
  479. }
  480. res = platform_get_resource_byname(pdev, IORESOURCE_DMA, "rx0");
  481. if (res) {
  482. imx_pcm_dma_params_init_data(&ssi->filter_data_rx, res->start,
  483. IMX_DMATYPE_SSI);
  484. }
  485. platform_set_drvdata(pdev, ssi);
  486. ret = snd_soc_set_ac97_ops(&imx_ssi_ac97_ops);
  487. if (ret != 0) {
  488. dev_err(&pdev->dev, "Failed to set AC'97 ops: %d\n", ret);
  489. goto failed_register;
  490. }
  491. ret = snd_soc_register_component(&pdev->dev, &imx_component,
  492. dai, 1);
  493. if (ret) {
  494. dev_err(&pdev->dev, "register DAI failed\n");
  495. goto failed_register;
  496. }
  497. ssi->fiq_params.irq = ssi->irq;
  498. ssi->fiq_params.base = ssi->base;
  499. ssi->fiq_params.dma_params_rx = &ssi->dma_params_rx;
  500. ssi->fiq_params.dma_params_tx = &ssi->dma_params_tx;
  501. ssi->fiq_init = imx_pcm_fiq_init(pdev, &ssi->fiq_params);
  502. ssi->dma_init = imx_pcm_dma_init(pdev, IMX_SSI_DMABUF_SIZE);
  503. if (ssi->fiq_init && ssi->dma_init) {
  504. ret = ssi->fiq_init;
  505. goto failed_pcm;
  506. }
  507. return 0;
  508. failed_pcm:
  509. snd_soc_unregister_component(&pdev->dev);
  510. failed_register:
  511. clk_disable_unprepare(ssi->clk);
  512. failed_clk:
  513. snd_soc_set_ac97_ops(NULL);
  514. return ret;
  515. }
  516. static int imx_ssi_remove(struct platform_device *pdev)
  517. {
  518. struct imx_ssi *ssi = platform_get_drvdata(pdev);
  519. if (!ssi->fiq_init)
  520. imx_pcm_fiq_exit(pdev);
  521. snd_soc_unregister_component(&pdev->dev);
  522. if (ssi->flags & IMX_SSI_USE_AC97)
  523. ac97_ssi = NULL;
  524. clk_disable_unprepare(ssi->clk);
  525. snd_soc_set_ac97_ops(NULL);
  526. return 0;
  527. }
  528. static struct platform_driver imx_ssi_driver = {
  529. .probe = imx_ssi_probe,
  530. .remove = imx_ssi_remove,
  531. .driver = {
  532. .name = "imx-ssi",
  533. },
  534. };
  535. module_platform_driver(imx_ssi_driver);
  536. /* Module information */
  537. MODULE_AUTHOR("Sascha Hauer, <s.hauer@pengutronix.de>");
  538. MODULE_DESCRIPTION("i.MX I2S/ac97 SoC Interface");
  539. MODULE_LICENSE("GPL");
  540. MODULE_ALIAS("platform:imx-ssi");