s3c-i2s-v2.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714
  1. /* sound/soc/s3c24xx/s3c-i2c-v2.c
  2. *
  3. * ALSA Soc Audio Layer - I2S core for newer Samsung SoCs.
  4. *
  5. * Copyright (c) 2006 Wolfson Microelectronics PLC.
  6. * Graeme Gregory graeme.gregory@wolfsonmicro.com
  7. * linux@wolfsonmicro.com
  8. *
  9. * Copyright (c) 2008, 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 <plat/regs-s3c2412-iis.h>
  31. #include <plat/audio.h>
  32. #include <mach/dma.h>
  33. #include "s3c-i2s-v2.h"
  34. #undef S3C_IIS_V2_SUPPORTED
  35. #if defined(CONFIG_CPU_S3C2412) || defined(CONFIG_CPU_S3C2413)
  36. #define S3C_IIS_V2_SUPPORTED
  37. #endif
  38. #ifdef CONFIG_PLAT_S3C64XX
  39. #define S3C_IIS_V2_SUPPORTED
  40. #endif
  41. #ifndef S3C_IIS_V2_SUPPORTED
  42. #error Unsupported CPU model
  43. #endif
  44. #define S3C2412_I2S_DEBUG_CON 0
  45. static inline struct s3c_i2sv2_info *to_info(struct snd_soc_dai *cpu_dai)
  46. {
  47. return cpu_dai->private_data;
  48. }
  49. #define bit_set(v, b) (((v) & (b)) ? 1 : 0)
  50. #if S3C2412_I2S_DEBUG_CON
  51. static void dbg_showcon(const char *fn, u32 con)
  52. {
  53. printk(KERN_DEBUG "%s: LRI=%d, TXFEMPT=%d, RXFEMPT=%d, TXFFULL=%d, RXFFULL=%d\n", fn,
  54. bit_set(con, S3C2412_IISCON_LRINDEX),
  55. bit_set(con, S3C2412_IISCON_TXFIFO_EMPTY),
  56. bit_set(con, S3C2412_IISCON_RXFIFO_EMPTY),
  57. bit_set(con, S3C2412_IISCON_TXFIFO_FULL),
  58. bit_set(con, S3C2412_IISCON_RXFIFO_FULL));
  59. printk(KERN_DEBUG "%s: PAUSE: TXDMA=%d, RXDMA=%d, TXCH=%d, RXCH=%d\n",
  60. fn,
  61. bit_set(con, S3C2412_IISCON_TXDMA_PAUSE),
  62. bit_set(con, S3C2412_IISCON_RXDMA_PAUSE),
  63. bit_set(con, S3C2412_IISCON_TXCH_PAUSE),
  64. bit_set(con, S3C2412_IISCON_RXCH_PAUSE));
  65. printk(KERN_DEBUG "%s: ACTIVE: TXDMA=%d, RXDMA=%d, IIS=%d\n", fn,
  66. bit_set(con, S3C2412_IISCON_TXDMA_ACTIVE),
  67. bit_set(con, S3C2412_IISCON_RXDMA_ACTIVE),
  68. bit_set(con, S3C2412_IISCON_IIS_ACTIVE));
  69. }
  70. #else
  71. static inline void dbg_showcon(const char *fn, u32 con)
  72. {
  73. }
  74. #endif
  75. /* Turn on or off the transmission path. */
  76. static void s3c2412_snd_txctrl(struct s3c_i2sv2_info *i2s, int on)
  77. {
  78. void __iomem *regs = i2s->regs;
  79. u32 fic, con, mod;
  80. pr_debug("%s(%d)\n", __func__, on);
  81. fic = readl(regs + S3C2412_IISFIC);
  82. con = readl(regs + S3C2412_IISCON);
  83. mod = readl(regs + S3C2412_IISMOD);
  84. pr_debug("%s: IIS: CON=%x MOD=%x FIC=%x\n", __func__, con, mod, fic);
  85. if (on) {
  86. con |= S3C2412_IISCON_TXDMA_ACTIVE | S3C2412_IISCON_IIS_ACTIVE;
  87. con &= ~S3C2412_IISCON_TXDMA_PAUSE;
  88. con &= ~S3C2412_IISCON_TXCH_PAUSE;
  89. switch (mod & S3C2412_IISMOD_MODE_MASK) {
  90. case S3C2412_IISMOD_MODE_TXONLY:
  91. case S3C2412_IISMOD_MODE_TXRX:
  92. /* do nothing, we are in the right mode */
  93. break;
  94. case S3C2412_IISMOD_MODE_RXONLY:
  95. mod &= ~S3C2412_IISMOD_MODE_MASK;
  96. mod |= S3C2412_IISMOD_MODE_TXRX;
  97. break;
  98. default:
  99. dev_err(i2s->dev, "TXEN: Invalid MODE %x in IISMOD\n",
  100. mod & S3C2412_IISMOD_MODE_MASK);
  101. break;
  102. }
  103. writel(con, regs + S3C2412_IISCON);
  104. writel(mod, regs + S3C2412_IISMOD);
  105. } else {
  106. /* Note, we do not have any indication that the FIFO problems
  107. * tha the S3C2410/2440 had apply here, so we should be able
  108. * to disable the DMA and TX without resetting the FIFOS.
  109. */
  110. con |= S3C2412_IISCON_TXDMA_PAUSE;
  111. con |= S3C2412_IISCON_TXCH_PAUSE;
  112. con &= ~S3C2412_IISCON_TXDMA_ACTIVE;
  113. switch (mod & S3C2412_IISMOD_MODE_MASK) {
  114. case S3C2412_IISMOD_MODE_TXRX:
  115. mod &= ~S3C2412_IISMOD_MODE_MASK;
  116. mod |= S3C2412_IISMOD_MODE_RXONLY;
  117. break;
  118. case S3C2412_IISMOD_MODE_TXONLY:
  119. mod &= ~S3C2412_IISMOD_MODE_MASK;
  120. con &= ~S3C2412_IISCON_IIS_ACTIVE;
  121. break;
  122. default:
  123. dev_err(i2s->dev, "TXDIS: Invalid MODE %x in IISMOD\n",
  124. mod & S3C2412_IISMOD_MODE_MASK);
  125. break;
  126. }
  127. writel(mod, regs + S3C2412_IISMOD);
  128. writel(con, regs + S3C2412_IISCON);
  129. }
  130. fic = readl(regs + S3C2412_IISFIC);
  131. dbg_showcon(__func__, con);
  132. pr_debug("%s: IIS: CON=%x MOD=%x FIC=%x\n", __func__, con, mod, fic);
  133. }
  134. static void s3c2412_snd_rxctrl(struct s3c_i2sv2_info *i2s, int on)
  135. {
  136. void __iomem *regs = i2s->regs;
  137. u32 fic, con, mod;
  138. pr_debug("%s(%d)\n", __func__, on);
  139. fic = readl(regs + S3C2412_IISFIC);
  140. con = readl(regs + S3C2412_IISCON);
  141. mod = readl(regs + S3C2412_IISMOD);
  142. pr_debug("%s: IIS: CON=%x MOD=%x FIC=%x\n", __func__, con, mod, fic);
  143. if (on) {
  144. con |= S3C2412_IISCON_RXDMA_ACTIVE | S3C2412_IISCON_IIS_ACTIVE;
  145. con &= ~S3C2412_IISCON_RXDMA_PAUSE;
  146. con &= ~S3C2412_IISCON_RXCH_PAUSE;
  147. switch (mod & S3C2412_IISMOD_MODE_MASK) {
  148. case S3C2412_IISMOD_MODE_TXRX:
  149. case S3C2412_IISMOD_MODE_RXONLY:
  150. /* do nothing, we are in the right mode */
  151. break;
  152. case S3C2412_IISMOD_MODE_TXONLY:
  153. mod &= ~S3C2412_IISMOD_MODE_MASK;
  154. mod |= S3C2412_IISMOD_MODE_TXRX;
  155. break;
  156. default:
  157. dev_err(i2s->dev, "RXEN: Invalid MODE %x in IISMOD\n",
  158. mod & S3C2412_IISMOD_MODE_MASK);
  159. }
  160. writel(mod, regs + S3C2412_IISMOD);
  161. writel(con, regs + S3C2412_IISCON);
  162. } else {
  163. /* See txctrl notes on FIFOs. */
  164. con &= ~S3C2412_IISCON_RXDMA_ACTIVE;
  165. con |= S3C2412_IISCON_RXDMA_PAUSE;
  166. con |= S3C2412_IISCON_RXCH_PAUSE;
  167. switch (mod & S3C2412_IISMOD_MODE_MASK) {
  168. case S3C2412_IISMOD_MODE_RXONLY:
  169. con &= ~S3C2412_IISCON_IIS_ACTIVE;
  170. mod &= ~S3C2412_IISMOD_MODE_MASK;
  171. break;
  172. case S3C2412_IISMOD_MODE_TXRX:
  173. mod &= ~S3C2412_IISMOD_MODE_MASK;
  174. mod |= S3C2412_IISMOD_MODE_TXONLY;
  175. break;
  176. default:
  177. dev_err(i2s->dev, "RXDIS: Invalid MODE %x in IISMOD\n",
  178. mod & S3C2412_IISMOD_MODE_MASK);
  179. }
  180. writel(con, regs + S3C2412_IISCON);
  181. writel(mod, regs + S3C2412_IISMOD);
  182. }
  183. fic = readl(regs + S3C2412_IISFIC);
  184. pr_debug("%s: IIS: CON=%x MOD=%x FIC=%x\n", __func__, con, mod, fic);
  185. }
  186. /*
  187. * Wait for the LR signal to allow synchronisation to the L/R clock
  188. * from the codec. May only be needed for slave mode.
  189. */
  190. static int s3c2412_snd_lrsync(struct s3c_i2sv2_info *i2s)
  191. {
  192. u32 iiscon;
  193. unsigned long timeout = jiffies + msecs_to_jiffies(5);
  194. pr_debug("Entered %s\n", __func__);
  195. while (1) {
  196. iiscon = readl(i2s->regs + S3C2412_IISCON);
  197. if (iiscon & S3C2412_IISCON_LRINDEX)
  198. break;
  199. if (timeout < jiffies) {
  200. printk(KERN_ERR "%s: timeout\n", __func__);
  201. return -ETIMEDOUT;
  202. }
  203. }
  204. return 0;
  205. }
  206. /*
  207. * Set S3C2412 I2S DAI format
  208. */
  209. static int s3c2412_i2s_set_fmt(struct snd_soc_dai *cpu_dai,
  210. unsigned int fmt)
  211. {
  212. struct s3c_i2sv2_info *i2s = to_info(cpu_dai);
  213. u32 iismod;
  214. pr_debug("Entered %s\n", __func__);
  215. iismod = readl(i2s->regs + S3C2412_IISMOD);
  216. pr_debug("hw_params r: IISMOD: %x \n", iismod);
  217. #if defined(CONFIG_CPU_S3C2412) || defined(CONFIG_CPU_S3C2413)
  218. #define IISMOD_MASTER_MASK S3C2412_IISMOD_MASTER_MASK
  219. #define IISMOD_SLAVE S3C2412_IISMOD_SLAVE
  220. #define IISMOD_MASTER S3C2412_IISMOD_MASTER_INTERNAL
  221. #endif
  222. #if defined(CONFIG_PLAT_S3C64XX)
  223. /* From Rev1.1 datasheet, we have two master and two slave modes:
  224. * IMS[11:10]:
  225. * 00 = master mode, fed from PCLK
  226. * 01 = master mode, fed from CLKAUDIO
  227. * 10 = slave mode, using PCLK
  228. * 11 = slave mode, using I2SCLK
  229. */
  230. #define IISMOD_MASTER_MASK (1 << 11)
  231. #define IISMOD_SLAVE (1 << 11)
  232. #define IISMOD_MASTER (0 << 11)
  233. #endif
  234. switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  235. case SND_SOC_DAIFMT_CBM_CFM:
  236. i2s->master = 0;
  237. iismod &= ~IISMOD_MASTER_MASK;
  238. iismod |= IISMOD_SLAVE;
  239. break;
  240. case SND_SOC_DAIFMT_CBS_CFS:
  241. i2s->master = 1;
  242. iismod &= ~IISMOD_MASTER_MASK;
  243. iismod |= IISMOD_MASTER;
  244. break;
  245. default:
  246. pr_err("unknwon master/slave format\n");
  247. return -EINVAL;
  248. }
  249. iismod &= ~S3C2412_IISMOD_SDF_MASK;
  250. switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  251. case SND_SOC_DAIFMT_RIGHT_J:
  252. iismod |= S3C2412_IISMOD_SDF_MSB;
  253. break;
  254. case SND_SOC_DAIFMT_LEFT_J:
  255. iismod |= S3C2412_IISMOD_SDF_LSB;
  256. break;
  257. case SND_SOC_DAIFMT_I2S:
  258. iismod |= S3C2412_IISMOD_SDF_IIS;
  259. break;
  260. default:
  261. pr_err("Unknown data format\n");
  262. return -EINVAL;
  263. }
  264. writel(iismod, i2s->regs + S3C2412_IISMOD);
  265. pr_debug("hw_params w: IISMOD: %x \n", iismod);
  266. return 0;
  267. }
  268. static int s3c2412_i2s_hw_params(struct snd_pcm_substream *substream,
  269. struct snd_pcm_hw_params *params,
  270. struct snd_soc_dai *socdai)
  271. {
  272. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  273. struct snd_soc_dai_link *dai = rtd->dai;
  274. struct s3c_i2sv2_info *i2s = to_info(dai->cpu_dai);
  275. u32 iismod;
  276. pr_debug("Entered %s\n", __func__);
  277. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  278. dai->cpu_dai->dma_data = i2s->dma_playback;
  279. else
  280. dai->cpu_dai->dma_data = i2s->dma_capture;
  281. /* Working copies of register */
  282. iismod = readl(i2s->regs + S3C2412_IISMOD);
  283. pr_debug("%s: r: IISMOD: %x\n", __func__, iismod);
  284. #if defined(CONFIG_CPU_S3C2412) || defined(CONFIG_CPU_S3C2413)
  285. switch (params_format(params)) {
  286. case SNDRV_PCM_FORMAT_S8:
  287. iismod |= S3C2412_IISMOD_8BIT;
  288. break;
  289. case SNDRV_PCM_FORMAT_S16_LE:
  290. iismod &= ~S3C2412_IISMOD_8BIT;
  291. break;
  292. }
  293. #endif
  294. #ifdef CONFIG_PLAT_S3C64XX
  295. iismod &= ~(S3C64XX_IISMOD_BLC_MASK | S3C2412_IISMOD_BCLK_MASK);
  296. /* Sample size */
  297. switch (params_format(params)) {
  298. case SNDRV_PCM_FORMAT_S8:
  299. /* 8 bit sample, 16fs BCLK */
  300. iismod |= (S3C64XX_IISMOD_BLC_8BIT | S3C2412_IISMOD_BCLK_16FS);
  301. break;
  302. case SNDRV_PCM_FORMAT_S16_LE:
  303. /* 16 bit sample, 32fs BCLK */
  304. break;
  305. case SNDRV_PCM_FORMAT_S24_LE:
  306. /* 24 bit sample, 48fs BCLK */
  307. iismod |= (S3C64XX_IISMOD_BLC_24BIT | S3C2412_IISMOD_BCLK_48FS);
  308. break;
  309. }
  310. #endif
  311. writel(iismod, i2s->regs + S3C2412_IISMOD);
  312. pr_debug("%s: w: IISMOD: %x\n", __func__, iismod);
  313. return 0;
  314. }
  315. static int s3c2412_i2s_trigger(struct snd_pcm_substream *substream, int cmd,
  316. struct snd_soc_dai *dai)
  317. {
  318. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  319. struct s3c_i2sv2_info *i2s = to_info(rtd->dai->cpu_dai);
  320. int capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE);
  321. unsigned long irqs;
  322. int ret = 0;
  323. int channel = ((struct s3c24xx_pcm_dma_params *)
  324. rtd->dai->cpu_dai->dma_data)->channel;
  325. pr_debug("Entered %s\n", __func__);
  326. switch (cmd) {
  327. case SNDRV_PCM_TRIGGER_START:
  328. /* On start, ensure that the FIFOs are cleared and reset. */
  329. writel(capture ? S3C2412_IISFIC_RXFLUSH : S3C2412_IISFIC_TXFLUSH,
  330. i2s->regs + S3C2412_IISFIC);
  331. /* clear again, just in case */
  332. writel(0x0, i2s->regs + S3C2412_IISFIC);
  333. case SNDRV_PCM_TRIGGER_RESUME:
  334. case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  335. if (!i2s->master) {
  336. ret = s3c2412_snd_lrsync(i2s);
  337. if (ret)
  338. goto exit_err;
  339. }
  340. local_irq_save(irqs);
  341. if (capture)
  342. s3c2412_snd_rxctrl(i2s, 1);
  343. else
  344. s3c2412_snd_txctrl(i2s, 1);
  345. local_irq_restore(irqs);
  346. /*
  347. * Load the next buffer to DMA to meet the reqirement
  348. * of the auto reload mechanism of S3C24XX.
  349. * This call won't bother S3C64XX.
  350. */
  351. s3c2410_dma_ctrl(channel, S3C2410_DMAOP_STARTED);
  352. break;
  353. case SNDRV_PCM_TRIGGER_STOP:
  354. case SNDRV_PCM_TRIGGER_SUSPEND:
  355. case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  356. local_irq_save(irqs);
  357. if (capture)
  358. s3c2412_snd_rxctrl(i2s, 0);
  359. else
  360. s3c2412_snd_txctrl(i2s, 0);
  361. local_irq_restore(irqs);
  362. break;
  363. default:
  364. ret = -EINVAL;
  365. break;
  366. }
  367. exit_err:
  368. return ret;
  369. }
  370. /*
  371. * Set S3C2412 Clock dividers
  372. */
  373. static int s3c2412_i2s_set_clkdiv(struct snd_soc_dai *cpu_dai,
  374. int div_id, int div)
  375. {
  376. struct s3c_i2sv2_info *i2s = to_info(cpu_dai);
  377. u32 reg;
  378. pr_debug("%s(%p, %d, %d)\n", __func__, cpu_dai, div_id, div);
  379. switch (div_id) {
  380. case S3C_I2SV2_DIV_BCLK:
  381. reg = readl(i2s->regs + S3C2412_IISMOD);
  382. reg &= ~S3C2412_IISMOD_BCLK_MASK;
  383. writel(reg | div, i2s->regs + S3C2412_IISMOD);
  384. pr_debug("%s: MOD=%08x\n", __func__, readl(i2s->regs + S3C2412_IISMOD));
  385. break;
  386. case S3C_I2SV2_DIV_RCLK:
  387. if (div > 3) {
  388. /* convert value to bit field */
  389. switch (div) {
  390. case 256:
  391. div = S3C2412_IISMOD_RCLK_256FS;
  392. break;
  393. case 384:
  394. div = S3C2412_IISMOD_RCLK_384FS;
  395. break;
  396. case 512:
  397. div = S3C2412_IISMOD_RCLK_512FS;
  398. break;
  399. case 768:
  400. div = S3C2412_IISMOD_RCLK_768FS;
  401. break;
  402. default:
  403. return -EINVAL;
  404. }
  405. }
  406. reg = readl(i2s->regs + S3C2412_IISMOD);
  407. reg &= ~S3C2412_IISMOD_RCLK_MASK;
  408. writel(reg | div, i2s->regs + S3C2412_IISMOD);
  409. pr_debug("%s: MOD=%08x\n", __func__, readl(i2s->regs + S3C2412_IISMOD));
  410. break;
  411. case S3C_I2SV2_DIV_PRESCALER:
  412. if (div >= 0) {
  413. writel((div << 8) | S3C2412_IISPSR_PSREN,
  414. i2s->regs + S3C2412_IISPSR);
  415. } else {
  416. writel(0x0, i2s->regs + S3C2412_IISPSR);
  417. }
  418. pr_debug("%s: PSR=%08x\n", __func__, readl(i2s->regs + S3C2412_IISPSR));
  419. break;
  420. default:
  421. return -EINVAL;
  422. }
  423. return 0;
  424. }
  425. /* default table of all avaialable root fs divisors */
  426. static unsigned int iis_fs_tab[] = { 256, 512, 384, 768 };
  427. int s3c_i2sv2_iis_calc_rate(struct s3c_i2sv2_rate_calc *info,
  428. unsigned int *fstab,
  429. unsigned int rate, struct clk *clk)
  430. {
  431. unsigned long clkrate = clk_get_rate(clk);
  432. unsigned int div;
  433. unsigned int fsclk;
  434. unsigned int actual;
  435. unsigned int fs;
  436. unsigned int fsdiv;
  437. signed int deviation = 0;
  438. unsigned int best_fs = 0;
  439. unsigned int best_div = 0;
  440. unsigned int best_rate = 0;
  441. unsigned int best_deviation = INT_MAX;
  442. pr_debug("Input clock rate %ldHz\n", clkrate);
  443. if (fstab == NULL)
  444. fstab = iis_fs_tab;
  445. for (fs = 0; fs < ARRAY_SIZE(iis_fs_tab); fs++) {
  446. fsdiv = iis_fs_tab[fs];
  447. fsclk = clkrate / fsdiv;
  448. div = fsclk / rate;
  449. if ((fsclk % rate) > (rate / 2))
  450. div++;
  451. if (div <= 1)
  452. continue;
  453. actual = clkrate / (fsdiv * div);
  454. deviation = actual - rate;
  455. printk(KERN_DEBUG "%ufs: div %u => result %u, deviation %d\n",
  456. fsdiv, div, actual, deviation);
  457. deviation = abs(deviation);
  458. if (deviation < best_deviation) {
  459. best_fs = fsdiv;
  460. best_div = div;
  461. best_rate = actual;
  462. best_deviation = deviation;
  463. }
  464. if (deviation == 0)
  465. break;
  466. }
  467. printk(KERN_DEBUG "best: fs=%u, div=%u, rate=%u\n",
  468. best_fs, best_div, best_rate);
  469. info->fs_div = best_fs;
  470. info->clk_div = best_div;
  471. return 0;
  472. }
  473. EXPORT_SYMBOL_GPL(s3c_i2sv2_iis_calc_rate);
  474. int s3c_i2sv2_probe(struct platform_device *pdev,
  475. struct snd_soc_dai *dai,
  476. struct s3c_i2sv2_info *i2s,
  477. unsigned long base)
  478. {
  479. struct device *dev = &pdev->dev;
  480. unsigned int iismod;
  481. i2s->dev = dev;
  482. /* record our i2s structure for later use in the callbacks */
  483. dai->private_data = i2s;
  484. if (!base) {
  485. struct resource *res = platform_get_resource(pdev,
  486. IORESOURCE_MEM,
  487. 0);
  488. if (!res) {
  489. dev_err(dev, "Unable to get register resource\n");
  490. return -ENXIO;
  491. }
  492. if (!request_mem_region(res->start, resource_size(res),
  493. "s3c64xx-i2s-v4")) {
  494. dev_err(dev, "Unable to request register region\n");
  495. return -EBUSY;
  496. }
  497. base = res->start;
  498. }
  499. i2s->regs = ioremap(base, 0x100);
  500. if (i2s->regs == NULL) {
  501. dev_err(dev, "cannot ioremap registers\n");
  502. return -ENXIO;
  503. }
  504. i2s->iis_pclk = clk_get(dev, "iis");
  505. if (i2s->iis_pclk == NULL) {
  506. dev_err(dev, "failed to get iis_clock\n");
  507. iounmap(i2s->regs);
  508. return -ENOENT;
  509. }
  510. clk_enable(i2s->iis_pclk);
  511. /* Mark ourselves as in TXRX mode so we can run through our cleanup
  512. * process without warnings. */
  513. iismod = readl(i2s->regs + S3C2412_IISMOD);
  514. iismod |= S3C2412_IISMOD_MODE_TXRX;
  515. writel(iismod, i2s->regs + S3C2412_IISMOD);
  516. s3c2412_snd_txctrl(i2s, 0);
  517. s3c2412_snd_rxctrl(i2s, 0);
  518. return 0;
  519. }
  520. EXPORT_SYMBOL_GPL(s3c_i2sv2_probe);
  521. #ifdef CONFIG_PM
  522. static int s3c2412_i2s_suspend(struct snd_soc_dai *dai)
  523. {
  524. struct s3c_i2sv2_info *i2s = to_info(dai);
  525. u32 iismod;
  526. if (dai->active) {
  527. i2s->suspend_iismod = readl(i2s->regs + S3C2412_IISMOD);
  528. i2s->suspend_iiscon = readl(i2s->regs + S3C2412_IISCON);
  529. i2s->suspend_iispsr = readl(i2s->regs + S3C2412_IISPSR);
  530. /* some basic suspend checks */
  531. iismod = readl(i2s->regs + S3C2412_IISMOD);
  532. if (iismod & S3C2412_IISCON_RXDMA_ACTIVE)
  533. pr_warning("%s: RXDMA active?\n", __func__);
  534. if (iismod & S3C2412_IISCON_TXDMA_ACTIVE)
  535. pr_warning("%s: TXDMA active?\n", __func__);
  536. if (iismod & S3C2412_IISCON_IIS_ACTIVE)
  537. pr_warning("%s: IIS active\n", __func__);
  538. }
  539. return 0;
  540. }
  541. static int s3c2412_i2s_resume(struct snd_soc_dai *dai)
  542. {
  543. struct s3c_i2sv2_info *i2s = to_info(dai);
  544. pr_info("dai_active %d, IISMOD %08x, IISCON %08x\n",
  545. dai->active, i2s->suspend_iismod, i2s->suspend_iiscon);
  546. if (dai->active) {
  547. writel(i2s->suspend_iiscon, i2s->regs + S3C2412_IISCON);
  548. writel(i2s->suspend_iismod, i2s->regs + S3C2412_IISMOD);
  549. writel(i2s->suspend_iispsr, i2s->regs + S3C2412_IISPSR);
  550. writel(S3C2412_IISFIC_RXFLUSH | S3C2412_IISFIC_TXFLUSH,
  551. i2s->regs + S3C2412_IISFIC);
  552. ndelay(250);
  553. writel(0x0, i2s->regs + S3C2412_IISFIC);
  554. }
  555. return 0;
  556. }
  557. #else
  558. #define s3c2412_i2s_suspend NULL
  559. #define s3c2412_i2s_resume NULL
  560. #endif
  561. int s3c_i2sv2_register_dai(struct snd_soc_dai *dai)
  562. {
  563. struct snd_soc_dai_ops *ops = dai->ops;
  564. ops->trigger = s3c2412_i2s_trigger;
  565. ops->hw_params = s3c2412_i2s_hw_params;
  566. ops->set_fmt = s3c2412_i2s_set_fmt;
  567. ops->set_clkdiv = s3c2412_i2s_set_clkdiv;
  568. dai->suspend = s3c2412_i2s_suspend;
  569. dai->resume = s3c2412_i2s_resume;
  570. return snd_soc_register_dai(dai);
  571. }
  572. EXPORT_SYMBOL_GPL(s3c_i2sv2_register_dai);
  573. MODULE_LICENSE("GPL");