s3c-i2s-v2.c 17 KB

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