s3c2412-i2s.c 18 KB

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