s3c2412-i2s.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745
  1. /* sound/soc/s3c24xx/s3c2412-i2s.c
  2. *
  3. * ALSA Soc Audio Layer - S3C2412 I2S driver
  4. *
  5. * Copyright (c) 2006 Wolfson Microelectronics PLC.
  6. * Graeme Gregory graeme.gregory@wolfsonmicro.com
  7. * linux@wolfsonmicro.com
  8. *
  9. * Copyright (c) 2007, 2004-2005 Simtec Electronics
  10. * http://armlinux.simtec.co.uk/
  11. * Ben Dooks <ben@simtec.co.uk>
  12. *
  13. * This program is free software; you can redistribute it and/or modify it
  14. * under the terms of the GNU General Public License as published by the
  15. * Free Software Foundation; either version 2 of the License, or (at your
  16. * option) any later version.
  17. */
  18. #include <linux/init.h>
  19. #include <linux/module.h>
  20. #include <linux/device.h>
  21. #include <linux/delay.h>
  22. #include <linux/clk.h>
  23. #include <linux/kernel.h>
  24. #include <sound/core.h>
  25. #include <sound/pcm.h>
  26. #include <sound/pcm_params.h>
  27. #include <sound/initval.h>
  28. #include <sound/soc.h>
  29. #include <mach/hardware.h>
  30. #include <linux/io.h>
  31. #include <asm/dma.h>
  32. #include <asm/plat-s3c24xx/regs-s3c2412-iis.h>
  33. #include <mach/regs-gpio.h>
  34. #include <mach/audio.h>
  35. #include <mach/dma.h>
  36. #include "s3c24xx-pcm.h"
  37. #include "s3c2412-i2s.h"
  38. #define S3C2412_I2S_DEBUG 0
  39. #define S3C2412_I2S_DEBUG_CON 0
  40. #if S3C2412_I2S_DEBUG
  41. #define DBG(x...) printk(KERN_INFO x)
  42. #else
  43. #define DBG(x...) do { } while (0)
  44. #endif
  45. static struct s3c2410_dma_client s3c2412_dma_client_out = {
  46. .name = "I2S PCM Stereo out"
  47. };
  48. static struct s3c2410_dma_client s3c2412_dma_client_in = {
  49. .name = "I2S PCM Stereo in"
  50. };
  51. static struct s3c24xx_pcm_dma_params s3c2412_i2s_pcm_stereo_out = {
  52. .client = &s3c2412_dma_client_out,
  53. .channel = DMACH_I2S_OUT,
  54. .dma_addr = S3C2410_PA_IIS + S3C2412_IISTXD,
  55. .dma_size = 4,
  56. };
  57. static struct s3c24xx_pcm_dma_params s3c2412_i2s_pcm_stereo_in = {
  58. .client = &s3c2412_dma_client_in,
  59. .channel = DMACH_I2S_IN,
  60. .dma_addr = S3C2410_PA_IIS + S3C2412_IISRXD,
  61. .dma_size = 4,
  62. };
  63. struct s3c2412_i2s_info {
  64. struct device *dev;
  65. void __iomem *regs;
  66. struct clk *iis_clk;
  67. struct clk *iis_pclk;
  68. struct clk *iis_cclk;
  69. u32 suspend_iismod;
  70. u32 suspend_iiscon;
  71. u32 suspend_iispsr;
  72. };
  73. static struct s3c2412_i2s_info s3c2412_i2s;
  74. #define bit_set(v, b) (((v) & (b)) ? 1 : 0)
  75. #if S3C2412_I2S_DEBUG_CON
  76. static void dbg_showcon(const char *fn, u32 con)
  77. {
  78. printk(KERN_DEBUG "%s: LRI=%d, TXFEMPT=%d, RXFEMPT=%d, TXFFULL=%d, RXFFULL=%d\n", fn,
  79. bit_set(con, S3C2412_IISCON_LRINDEX),
  80. bit_set(con, S3C2412_IISCON_TXFIFO_EMPTY),
  81. bit_set(con, S3C2412_IISCON_RXFIFO_EMPTY),
  82. bit_set(con, S3C2412_IISCON_TXFIFO_FULL),
  83. bit_set(con, S3C2412_IISCON_RXFIFO_FULL));
  84. printk(KERN_DEBUG "%s: PAUSE: TXDMA=%d, RXDMA=%d, TXCH=%d, RXCH=%d\n",
  85. fn,
  86. bit_set(con, S3C2412_IISCON_TXDMA_PAUSE),
  87. bit_set(con, S3C2412_IISCON_RXDMA_PAUSE),
  88. bit_set(con, S3C2412_IISCON_TXCH_PAUSE),
  89. bit_set(con, S3C2412_IISCON_RXCH_PAUSE));
  90. printk(KERN_DEBUG "%s: ACTIVE: TXDMA=%d, RXDMA=%d, IIS=%d\n", fn,
  91. bit_set(con, S3C2412_IISCON_TXDMA_ACTIVE),
  92. bit_set(con, S3C2412_IISCON_RXDMA_ACTIVE),
  93. bit_set(con, S3C2412_IISCON_IIS_ACTIVE));
  94. }
  95. #else
  96. static inline void dbg_showcon(const char *fn, u32 con)
  97. {
  98. }
  99. #endif
  100. /* Turn on or off the transmission path. */
  101. static void s3c2412_snd_txctrl(int on)
  102. {
  103. struct s3c2412_i2s_info *i2s = &s3c2412_i2s;
  104. void __iomem *regs = i2s->regs;
  105. u32 fic, con, mod;
  106. DBG("%s(%d)\n", __func__, on);
  107. fic = readl(regs + S3C2412_IISFIC);
  108. con = readl(regs + S3C2412_IISCON);
  109. mod = readl(regs + S3C2412_IISMOD);
  110. DBG("%s: IIS: CON=%x MOD=%x FIC=%x\n", __func__, con, mod, fic);
  111. if (on) {
  112. con |= S3C2412_IISCON_TXDMA_ACTIVE | S3C2412_IISCON_IIS_ACTIVE;
  113. con &= ~S3C2412_IISCON_TXDMA_PAUSE;
  114. con &= ~S3C2412_IISCON_TXCH_PAUSE;
  115. switch (mod & S3C2412_IISMOD_MODE_MASK) {
  116. case S3C2412_IISMOD_MODE_TXONLY:
  117. case S3C2412_IISMOD_MODE_TXRX:
  118. /* do nothing, we are in the right mode */
  119. break;
  120. case S3C2412_IISMOD_MODE_RXONLY:
  121. mod &= ~S3C2412_IISMOD_MODE_MASK;
  122. mod |= S3C2412_IISMOD_MODE_TXRX;
  123. break;
  124. default:
  125. dev_err(i2s->dev, "TXEN: Invalid MODE in IISMOD\n");
  126. }
  127. writel(con, regs + S3C2412_IISCON);
  128. writel(mod, regs + S3C2412_IISMOD);
  129. } else {
  130. /* Note, we do not have any indication that the FIFO problems
  131. * tha the S3C2410/2440 had apply here, so we should be able
  132. * to disable the DMA and TX without resetting the FIFOS.
  133. */
  134. con |= S3C2412_IISCON_TXDMA_PAUSE;
  135. con |= S3C2412_IISCON_TXCH_PAUSE;
  136. con &= ~S3C2412_IISCON_TXDMA_ACTIVE;
  137. switch (mod & S3C2412_IISMOD_MODE_MASK) {
  138. case S3C2412_IISMOD_MODE_TXRX:
  139. mod &= ~S3C2412_IISMOD_MODE_MASK;
  140. mod |= S3C2412_IISMOD_MODE_RXONLY;
  141. break;
  142. case S3C2412_IISMOD_MODE_TXONLY:
  143. mod &= ~S3C2412_IISMOD_MODE_MASK;
  144. con &= ~S3C2412_IISCON_IIS_ACTIVE;
  145. break;
  146. default:
  147. dev_err(i2s->dev, "TXDIS: Invalid MODE in IISMOD\n");
  148. }
  149. writel(mod, regs + S3C2412_IISMOD);
  150. writel(con, regs + S3C2412_IISCON);
  151. }
  152. fic = readl(regs + S3C2412_IISFIC);
  153. dbg_showcon(__func__, con);
  154. DBG("%s: IIS: CON=%x MOD=%x FIC=%x\n", __func__, con, mod, fic);
  155. }
  156. static void s3c2412_snd_rxctrl(int on)
  157. {
  158. struct s3c2412_i2s_info *i2s = &s3c2412_i2s;
  159. void __iomem *regs = i2s->regs;
  160. u32 fic, con, mod;
  161. DBG("%s(%d)\n", __func__, on);
  162. fic = readl(regs + S3C2412_IISFIC);
  163. con = readl(regs + S3C2412_IISCON);
  164. mod = readl(regs + S3C2412_IISMOD);
  165. DBG("%s: IIS: CON=%x MOD=%x FIC=%x\n", __func__, con, mod, fic);
  166. if (on) {
  167. con |= S3C2412_IISCON_RXDMA_ACTIVE | S3C2412_IISCON_IIS_ACTIVE;
  168. con &= ~S3C2412_IISCON_RXDMA_PAUSE;
  169. con &= ~S3C2412_IISCON_RXCH_PAUSE;
  170. switch (mod & S3C2412_IISMOD_MODE_MASK) {
  171. case S3C2412_IISMOD_MODE_TXRX:
  172. case S3C2412_IISMOD_MODE_RXONLY:
  173. /* do nothing, we are in the right mode */
  174. break;
  175. case S3C2412_IISMOD_MODE_TXONLY:
  176. mod &= ~S3C2412_IISMOD_MODE_MASK;
  177. mod |= S3C2412_IISMOD_MODE_TXRX;
  178. break;
  179. default:
  180. dev_err(i2s->dev, "RXEN: Invalid MODE in IISMOD\n");
  181. }
  182. writel(mod, regs + S3C2412_IISMOD);
  183. writel(con, regs + S3C2412_IISCON);
  184. } else {
  185. /* See txctrl notes on FIFOs. */
  186. con &= ~S3C2412_IISCON_RXDMA_ACTIVE;
  187. con |= S3C2412_IISCON_RXDMA_PAUSE;
  188. con |= S3C2412_IISCON_RXCH_PAUSE;
  189. switch (mod & S3C2412_IISMOD_MODE_MASK) {
  190. case S3C2412_IISMOD_MODE_RXONLY:
  191. con &= ~S3C2412_IISCON_IIS_ACTIVE;
  192. mod &= ~S3C2412_IISMOD_MODE_MASK;
  193. break;
  194. case S3C2412_IISMOD_MODE_TXRX:
  195. mod &= ~S3C2412_IISMOD_MODE_MASK;
  196. mod |= S3C2412_IISMOD_MODE_TXONLY;
  197. break;
  198. default:
  199. dev_err(i2s->dev, "RXEN: Invalid MODE in IISMOD\n");
  200. }
  201. writel(con, regs + S3C2412_IISCON);
  202. writel(mod, regs + S3C2412_IISMOD);
  203. }
  204. fic = readl(regs + S3C2412_IISFIC);
  205. DBG("%s: IIS: CON=%x MOD=%x FIC=%x\n", __func__, con, mod, fic);
  206. }
  207. /*
  208. * Wait for the LR signal to allow synchronisation to the L/R clock
  209. * from the codec. May only be needed for slave mode.
  210. */
  211. static int s3c2412_snd_lrsync(void)
  212. {
  213. u32 iiscon;
  214. unsigned long timeout = jiffies + msecs_to_jiffies(5);
  215. DBG("Entered %s\n", __func__);
  216. while (1) {
  217. iiscon = readl(s3c2412_i2s.regs + S3C2412_IISCON);
  218. if (iiscon & S3C2412_IISCON_LRINDEX)
  219. break;
  220. if (timeout < jiffies) {
  221. printk(KERN_ERR "%s: timeout\n", __func__);
  222. return -ETIMEDOUT;
  223. }
  224. }
  225. return 0;
  226. }
  227. /*
  228. * Check whether CPU is the master or slave
  229. */
  230. static inline int s3c2412_snd_is_clkmaster(void)
  231. {
  232. u32 iismod = readl(s3c2412_i2s.regs + S3C2412_IISMOD);
  233. DBG("Entered %s\n", __func__);
  234. iismod &= S3C2412_IISMOD_MASTER_MASK;
  235. return !(iismod == S3C2412_IISMOD_SLAVE);
  236. }
  237. /*
  238. * Set S3C2412 I2S DAI format
  239. */
  240. static int s3c2412_i2s_set_fmt(struct snd_soc_dai *cpu_dai,
  241. unsigned int fmt)
  242. {
  243. u32 iismod;
  244. DBG("Entered %s\n", __func__);
  245. iismod = readl(s3c2412_i2s.regs + S3C2412_IISMOD);
  246. DBG("hw_params r: IISMOD: %x \n", iismod);
  247. switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  248. case SND_SOC_DAIFMT_CBM_CFM:
  249. iismod &= ~S3C2412_IISMOD_MASTER_MASK;
  250. iismod |= S3C2412_IISMOD_SLAVE;
  251. break;
  252. case SND_SOC_DAIFMT_CBS_CFS:
  253. iismod &= ~S3C2412_IISMOD_MASTER_MASK;
  254. iismod |= S3C2412_IISMOD_MASTER_INTERNAL;
  255. break;
  256. default:
  257. DBG("unknwon master/slave format\n");
  258. return -EINVAL;
  259. }
  260. iismod &= ~S3C2412_IISMOD_SDF_MASK;
  261. switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  262. case SND_SOC_DAIFMT_RIGHT_J:
  263. iismod |= S3C2412_IISMOD_SDF_MSB;
  264. break;
  265. case SND_SOC_DAIFMT_LEFT_J:
  266. iismod |= S3C2412_IISMOD_SDF_LSB;
  267. break;
  268. case SND_SOC_DAIFMT_I2S:
  269. iismod |= S3C2412_IISMOD_SDF_IIS;
  270. break;
  271. default:
  272. DBG("Unknown data format\n");
  273. return -EINVAL;
  274. }
  275. writel(iismod, s3c2412_i2s.regs + S3C2412_IISMOD);
  276. DBG("hw_params w: IISMOD: %x \n", iismod);
  277. return 0;
  278. }
  279. static int s3c2412_i2s_hw_params(struct snd_pcm_substream *substream,
  280. struct snd_pcm_hw_params *params)
  281. {
  282. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  283. u32 iismod;
  284. DBG("Entered %s\n", __func__);
  285. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  286. rtd->dai->cpu_dai->dma_data = &s3c2412_i2s_pcm_stereo_out;
  287. else
  288. rtd->dai->cpu_dai->dma_data = &s3c2412_i2s_pcm_stereo_in;
  289. /* Working copies of register */
  290. iismod = readl(s3c2412_i2s.regs + S3C2412_IISMOD);
  291. DBG("%s: r: IISMOD: %x\n", __func__, iismod);
  292. switch (params_format(params)) {
  293. case SNDRV_PCM_FORMAT_S8:
  294. iismod |= S3C2412_IISMOD_8BIT;
  295. break;
  296. case SNDRV_PCM_FORMAT_S16_LE:
  297. iismod &= ~S3C2412_IISMOD_8BIT;
  298. break;
  299. }
  300. writel(iismod, s3c2412_i2s.regs + S3C2412_IISMOD);
  301. DBG("%s: w: IISMOD: %x\n", __func__, iismod);
  302. return 0;
  303. }
  304. static int s3c2412_i2s_trigger(struct snd_pcm_substream *substream, int cmd)
  305. {
  306. int capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE);
  307. unsigned long irqs;
  308. int ret = 0;
  309. DBG("Entered %s\n", __func__);
  310. switch (cmd) {
  311. case SNDRV_PCM_TRIGGER_START:
  312. /* On start, ensure that the FIFOs are cleared and reset. */
  313. writel(capture ? S3C2412_IISFIC_RXFLUSH : S3C2412_IISFIC_TXFLUSH,
  314. s3c2412_i2s.regs + S3C2412_IISFIC);
  315. /* clear again, just in case */
  316. writel(0x0, s3c2412_i2s.regs + S3C2412_IISFIC);
  317. case SNDRV_PCM_TRIGGER_RESUME:
  318. case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  319. if (!s3c2412_snd_is_clkmaster()) {
  320. ret = s3c2412_snd_lrsync();
  321. if (ret)
  322. goto exit_err;
  323. }
  324. local_irq_save(irqs);
  325. if (capture)
  326. s3c2412_snd_rxctrl(1);
  327. else
  328. s3c2412_snd_txctrl(1);
  329. local_irq_restore(irqs);
  330. break;
  331. case SNDRV_PCM_TRIGGER_STOP:
  332. case SNDRV_PCM_TRIGGER_SUSPEND:
  333. case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  334. local_irq_save(irqs);
  335. if (capture)
  336. s3c2412_snd_rxctrl(0);
  337. else
  338. s3c2412_snd_txctrl(0);
  339. local_irq_restore(irqs);
  340. break;
  341. default:
  342. ret = -EINVAL;
  343. break;
  344. }
  345. exit_err:
  346. return ret;
  347. }
  348. /* default table of all avaialable root fs divisors */
  349. static unsigned int s3c2412_iis_fs[] = { 256, 512, 384, 768, 0 };
  350. int s3c2412_iis_calc_rate(struct s3c2412_rate_calc *info,
  351. unsigned int *fstab,
  352. unsigned int rate, struct clk *clk)
  353. {
  354. unsigned long clkrate = clk_get_rate(clk);
  355. unsigned int div;
  356. unsigned int fsclk;
  357. unsigned int actual;
  358. unsigned int fs;
  359. unsigned int fsdiv;
  360. signed int deviation = 0;
  361. unsigned int best_fs = 0;
  362. unsigned int best_div = 0;
  363. unsigned int best_rate = 0;
  364. unsigned int best_deviation = INT_MAX;
  365. if (fstab == NULL)
  366. fstab = s3c2412_iis_fs;
  367. for (fs = 0;; fs++) {
  368. fsdiv = s3c2412_iis_fs[fs];
  369. if (fsdiv == 0)
  370. break;
  371. fsclk = clkrate / fsdiv;
  372. div = fsclk / rate;
  373. if ((fsclk % rate) > (rate / 2))
  374. div++;
  375. if (div <= 1)
  376. continue;
  377. actual = clkrate / (fsdiv * div);
  378. deviation = actual - rate;
  379. printk(KERN_DEBUG "%dfs: div %d => result %d, deviation %d\n",
  380. fsdiv, div, actual, deviation);
  381. deviation = abs(deviation);
  382. if (deviation < best_deviation) {
  383. best_fs = fsdiv;
  384. best_div = div;
  385. best_rate = actual;
  386. best_deviation = deviation;
  387. }
  388. if (deviation == 0)
  389. break;
  390. }
  391. printk(KERN_DEBUG "best: fs=%d, div=%d, rate=%d\n",
  392. best_fs, best_div, best_rate);
  393. info->fs_div = best_fs;
  394. info->clk_div = best_div;
  395. return 0;
  396. }
  397. EXPORT_SYMBOL_GPL(s3c2412_iis_calc_rate);
  398. /*
  399. * Set S3C2412 Clock source
  400. */
  401. static int s3c2412_i2s_set_sysclk(struct snd_soc_dai *cpu_dai,
  402. int clk_id, unsigned int freq, int dir)
  403. {
  404. u32 iismod = readl(s3c2412_i2s.regs + S3C2412_IISMOD);
  405. DBG("%s(%p, %d, %u, %d)\n", __func__, cpu_dai, clk_id,
  406. freq, dir);
  407. switch (clk_id) {
  408. case S3C2412_CLKSRC_PCLK:
  409. iismod &= ~S3C2412_IISMOD_MASTER_MASK;
  410. iismod |= S3C2412_IISMOD_MASTER_INTERNAL;
  411. break;
  412. case S3C2412_CLKSRC_I2SCLK:
  413. iismod &= ~S3C2412_IISMOD_MASTER_MASK;
  414. iismod |= S3C2412_IISMOD_MASTER_EXTERNAL;
  415. break;
  416. default:
  417. return -EINVAL;
  418. }
  419. writel(iismod, s3c2412_i2s.regs + S3C2412_IISMOD);
  420. return 0;
  421. }
  422. /*
  423. * Set S3C2412 Clock dividers
  424. */
  425. static int s3c2412_i2s_set_clkdiv(struct snd_soc_dai *cpu_dai,
  426. int div_id, int div)
  427. {
  428. struct s3c2412_i2s_info *i2s = &s3c2412_i2s;
  429. u32 reg;
  430. DBG("%s(%p, %d, %d)\n", __func__, cpu_dai, div_id, div);
  431. switch (div_id) {
  432. case S3C2412_DIV_BCLK:
  433. reg = readl(i2s->regs + S3C2412_IISMOD);
  434. reg &= ~S3C2412_IISMOD_BCLK_MASK;
  435. writel(reg | div, i2s->regs + S3C2412_IISMOD);
  436. DBG("%s: MOD=%08x\n", __func__, readl(i2s->regs + S3C2412_IISMOD));
  437. break;
  438. case S3C2412_DIV_RCLK:
  439. if (div > 3) {
  440. /* convert value to bit field */
  441. switch (div) {
  442. case 256:
  443. div = S3C2412_IISMOD_RCLK_256FS;
  444. break;
  445. case 384:
  446. div = S3C2412_IISMOD_RCLK_384FS;
  447. break;
  448. case 512:
  449. div = S3C2412_IISMOD_RCLK_512FS;
  450. break;
  451. case 768:
  452. div = S3C2412_IISMOD_RCLK_768FS;
  453. break;
  454. default:
  455. return -EINVAL;
  456. }
  457. }
  458. reg = readl(s3c2412_i2s.regs + S3C2412_IISMOD);
  459. reg &= ~S3C2412_IISMOD_RCLK_MASK;
  460. writel(reg | div, i2s->regs + S3C2412_IISMOD);
  461. DBG("%s: MOD=%08x\n", __func__, readl(i2s->regs + S3C2412_IISMOD));
  462. break;
  463. case S3C2412_DIV_PRESCALER:
  464. if (div >= 0) {
  465. writel((div << 8) | S3C2412_IISPSR_PSREN,
  466. i2s->regs + S3C2412_IISPSR);
  467. } else {
  468. writel(0x0, i2s->regs + S3C2412_IISPSR);
  469. }
  470. DBG("%s: PSR=%08x\n", __func__, readl(i2s->regs + S3C2412_IISPSR));
  471. break;
  472. default:
  473. return -EINVAL;
  474. }
  475. return 0;
  476. }
  477. struct clk *s3c2412_get_iisclk(void)
  478. {
  479. return s3c2412_i2s.iis_clk;
  480. }
  481. EXPORT_SYMBOL_GPL(s3c2412_get_iisclk);
  482. static int s3c2412_i2s_probe(struct platform_device *pdev,
  483. struct snd_soc_dai *dai)
  484. {
  485. DBG("Entered %s\n", __func__);
  486. s3c2412_i2s.dev = &pdev->dev;
  487. s3c2412_i2s.regs = ioremap(S3C2410_PA_IIS, 0x100);
  488. if (s3c2412_i2s.regs == NULL)
  489. return -ENXIO;
  490. s3c2412_i2s.iis_pclk = clk_get(&pdev->dev, "iis");
  491. if (s3c2412_i2s.iis_pclk == NULL) {
  492. DBG("failed to get iis_clock\n");
  493. iounmap(s3c2412_i2s.regs);
  494. return -ENODEV;
  495. }
  496. s3c2412_i2s.iis_cclk = clk_get(&pdev->dev, "i2sclk");
  497. if (s3c2412_i2s.iis_cclk == NULL) {
  498. DBG("failed to get i2sclk clock\n");
  499. iounmap(s3c2412_i2s.regs);
  500. return -ENODEV;
  501. }
  502. clk_set_parent(s3c2412_i2s.iis_cclk, clk_get(NULL, "mpll"));
  503. clk_enable(s3c2412_i2s.iis_pclk);
  504. clk_enable(s3c2412_i2s.iis_cclk);
  505. s3c2412_i2s.iis_clk = s3c2412_i2s.iis_pclk;
  506. /* Configure the I2S pins in correct mode */
  507. s3c2410_gpio_cfgpin(S3C2410_GPE0, S3C2410_GPE0_I2SLRCK);
  508. s3c2410_gpio_cfgpin(S3C2410_GPE1, S3C2410_GPE1_I2SSCLK);
  509. s3c2410_gpio_cfgpin(S3C2410_GPE2, S3C2410_GPE2_CDCLK);
  510. s3c2410_gpio_cfgpin(S3C2410_GPE3, S3C2410_GPE3_I2SSDI);
  511. s3c2410_gpio_cfgpin(S3C2410_GPE4, S3C2410_GPE4_I2SSDO);
  512. s3c2412_snd_txctrl(0);
  513. s3c2412_snd_rxctrl(0);
  514. return 0;
  515. }
  516. #ifdef CONFIG_PM
  517. static int s3c2412_i2s_suspend(struct platform_device *dev,
  518. struct snd_soc_dai *dai)
  519. {
  520. struct s3c2412_i2s_info *i2s = &s3c2412_i2s;
  521. u32 iismod;
  522. if (dai->active) {
  523. i2s->suspend_iismod = readl(i2s->regs + S3C2412_IISMOD);
  524. i2s->suspend_iiscon = readl(i2s->regs + S3C2412_IISCON);
  525. i2s->suspend_iispsr = readl(i2s->regs + S3C2412_IISPSR);
  526. /* some basic suspend checks */
  527. iismod = readl(i2s->regs + S3C2412_IISMOD);
  528. if (iismod & S3C2412_IISCON_RXDMA_ACTIVE)
  529. dev_warn(&dev->dev, "%s: RXDMA active?\n", __func__);
  530. if (iismod & S3C2412_IISCON_TXDMA_ACTIVE)
  531. dev_warn(&dev->dev, "%s: TXDMA active?\n", __func__);
  532. if (iismod & S3C2412_IISCON_IIS_ACTIVE)
  533. dev_warn(&dev->dev, "%s: IIS active\n", __func__);
  534. }
  535. return 0;
  536. }
  537. static int s3c2412_i2s_resume(struct platform_device *pdev,
  538. struct snd_soc_dai *dai)
  539. {
  540. struct s3c2412_i2s_info *i2s = &s3c2412_i2s;
  541. dev_info(&pdev->dev, "dai_active %d, IISMOD %08x, IISCON %08x\n",
  542. dai->active, i2s->suspend_iismod, i2s->suspend_iiscon);
  543. if (dai->active) {
  544. writel(i2s->suspend_iiscon, i2s->regs + S3C2412_IISCON);
  545. writel(i2s->suspend_iismod, i2s->regs + S3C2412_IISMOD);
  546. writel(i2s->suspend_iispsr, i2s->regs + S3C2412_IISPSR);
  547. writel(S3C2412_IISFIC_RXFLUSH | S3C2412_IISFIC_TXFLUSH,
  548. i2s->regs + S3C2412_IISFIC);
  549. ndelay(250);
  550. writel(0x0, i2s->regs + S3C2412_IISFIC);
  551. }
  552. return 0;
  553. }
  554. #else
  555. #define s3c2412_i2s_suspend NULL
  556. #define s3c2412_i2s_resume NULL
  557. #endif /* CONFIG_PM */
  558. #define S3C2412_I2S_RATES \
  559. (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | SNDRV_PCM_RATE_16000 | \
  560. SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
  561. SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000)
  562. struct snd_soc_dai s3c2412_i2s_dai = {
  563. .name = "s3c2412-i2s",
  564. .id = 0,
  565. .type = SND_SOC_DAI_I2S,
  566. .probe = s3c2412_i2s_probe,
  567. .suspend = s3c2412_i2s_suspend,
  568. .resume = s3c2412_i2s_resume,
  569. .playback = {
  570. .channels_min = 2,
  571. .channels_max = 2,
  572. .rates = S3C2412_I2S_RATES,
  573. .formats = SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE,
  574. },
  575. .capture = {
  576. .channels_min = 2,
  577. .channels_max = 2,
  578. .rates = S3C2412_I2S_RATES,
  579. .formats = SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE,
  580. },
  581. .ops = {
  582. .trigger = s3c2412_i2s_trigger,
  583. .hw_params = s3c2412_i2s_hw_params,
  584. },
  585. .dai_ops = {
  586. .set_fmt = s3c2412_i2s_set_fmt,
  587. .set_clkdiv = s3c2412_i2s_set_clkdiv,
  588. .set_sysclk = s3c2412_i2s_set_sysclk,
  589. },
  590. };
  591. EXPORT_SYMBOL_GPL(s3c2412_i2s_dai);
  592. /* Module information */
  593. MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>");
  594. MODULE_DESCRIPTION("S3C2412 I2S SoC Interface");
  595. MODULE_LICENSE("GPL");