s3c-i2s-v2.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  1. // SPDX-License-Identifier: GPL-2.0+
  2. //
  3. // ALSA Soc Audio Layer - I2S core for newer Samsung SoCs.
  4. //
  5. // Copyright (c) 2006 Wolfson Microelectronics PLC.
  6. // Graeme Gregory [email protected]
  7. // [email protected]
  8. //
  9. // Copyright (c) 2008, 2007, 2004-2005 Simtec Electronics
  10. // http://armlinux.simtec.co.uk/
  11. // Ben Dooks <[email protected]>
  12. #include <linux/module.h>
  13. #include <linux/delay.h>
  14. #include <linux/clk.h>
  15. #include <linux/io.h>
  16. #include <sound/soc.h>
  17. #include <sound/pcm_params.h>
  18. #include "regs-i2s-v2.h"
  19. #include "s3c-i2s-v2.h"
  20. #define S3C2412_I2S_DEBUG_CON 0
  21. static inline struct s3c_i2sv2_info *to_info(struct snd_soc_dai *cpu_dai)
  22. {
  23. return snd_soc_dai_get_drvdata(cpu_dai);
  24. }
  25. #define bit_set(v, b) (((v) & (b)) ? 1 : 0)
  26. #if S3C2412_I2S_DEBUG_CON
  27. static void dbg_showcon(const char *fn, u32 con)
  28. {
  29. printk(KERN_DEBUG "%s: LRI=%d, TXFEMPT=%d, RXFEMPT=%d, TXFFULL=%d, RXFFULL=%d\n", fn,
  30. bit_set(con, S3C2412_IISCON_LRINDEX),
  31. bit_set(con, S3C2412_IISCON_TXFIFO_EMPTY),
  32. bit_set(con, S3C2412_IISCON_RXFIFO_EMPTY),
  33. bit_set(con, S3C2412_IISCON_TXFIFO_FULL),
  34. bit_set(con, S3C2412_IISCON_RXFIFO_FULL));
  35. printk(KERN_DEBUG "%s: PAUSE: TXDMA=%d, RXDMA=%d, TXCH=%d, RXCH=%d\n",
  36. fn,
  37. bit_set(con, S3C2412_IISCON_TXDMA_PAUSE),
  38. bit_set(con, S3C2412_IISCON_RXDMA_PAUSE),
  39. bit_set(con, S3C2412_IISCON_TXCH_PAUSE),
  40. bit_set(con, S3C2412_IISCON_RXCH_PAUSE));
  41. printk(KERN_DEBUG "%s: ACTIVE: TXDMA=%d, RXDMA=%d, IIS=%d\n", fn,
  42. bit_set(con, S3C2412_IISCON_TXDMA_ACTIVE),
  43. bit_set(con, S3C2412_IISCON_RXDMA_ACTIVE),
  44. bit_set(con, S3C2412_IISCON_IIS_ACTIVE));
  45. }
  46. #else
  47. static inline void dbg_showcon(const char *fn, u32 con)
  48. {
  49. }
  50. #endif
  51. /* Turn on or off the transmission path. */
  52. static void s3c2412_snd_txctrl(struct s3c_i2sv2_info *i2s, int on)
  53. {
  54. void __iomem *regs = i2s->regs;
  55. u32 fic, con, mod;
  56. pr_debug("%s(%d)\n", __func__, on);
  57. fic = readl(regs + S3C2412_IISFIC);
  58. con = readl(regs + S3C2412_IISCON);
  59. mod = readl(regs + S3C2412_IISMOD);
  60. pr_debug("%s: IIS: CON=%x MOD=%x FIC=%x\n", __func__, con, mod, fic);
  61. if (on) {
  62. con |= S3C2412_IISCON_TXDMA_ACTIVE | S3C2412_IISCON_IIS_ACTIVE;
  63. con &= ~S3C2412_IISCON_TXDMA_PAUSE;
  64. con &= ~S3C2412_IISCON_TXCH_PAUSE;
  65. switch (mod & S3C2412_IISMOD_MODE_MASK) {
  66. case S3C2412_IISMOD_MODE_TXONLY:
  67. case S3C2412_IISMOD_MODE_TXRX:
  68. /* do nothing, we are in the right mode */
  69. break;
  70. case S3C2412_IISMOD_MODE_RXONLY:
  71. mod &= ~S3C2412_IISMOD_MODE_MASK;
  72. mod |= S3C2412_IISMOD_MODE_TXRX;
  73. break;
  74. default:
  75. dev_err(i2s->dev, "TXEN: Invalid MODE %x in IISMOD\n",
  76. mod & S3C2412_IISMOD_MODE_MASK);
  77. break;
  78. }
  79. writel(con, regs + S3C2412_IISCON);
  80. writel(mod, regs + S3C2412_IISMOD);
  81. } else {
  82. /* Note, we do not have any indication that the FIFO problems
  83. * tha the S3C2410/2440 had apply here, so we should be able
  84. * to disable the DMA and TX without resetting the FIFOS.
  85. */
  86. con |= S3C2412_IISCON_TXDMA_PAUSE;
  87. con |= S3C2412_IISCON_TXCH_PAUSE;
  88. con &= ~S3C2412_IISCON_TXDMA_ACTIVE;
  89. switch (mod & S3C2412_IISMOD_MODE_MASK) {
  90. case S3C2412_IISMOD_MODE_TXRX:
  91. mod &= ~S3C2412_IISMOD_MODE_MASK;
  92. mod |= S3C2412_IISMOD_MODE_RXONLY;
  93. break;
  94. case S3C2412_IISMOD_MODE_TXONLY:
  95. mod &= ~S3C2412_IISMOD_MODE_MASK;
  96. con &= ~S3C2412_IISCON_IIS_ACTIVE;
  97. break;
  98. default:
  99. dev_err(i2s->dev, "TXDIS: Invalid MODE %x in IISMOD\n",
  100. mod & S3C2412_IISMOD_MODE_MASK);
  101. break;
  102. }
  103. writel(mod, regs + S3C2412_IISMOD);
  104. writel(con, regs + S3C2412_IISCON);
  105. }
  106. fic = readl(regs + S3C2412_IISFIC);
  107. dbg_showcon(__func__, con);
  108. pr_debug("%s: IIS: CON=%x MOD=%x FIC=%x\n", __func__, con, mod, fic);
  109. }
  110. static void s3c2412_snd_rxctrl(struct s3c_i2sv2_info *i2s, int on)
  111. {
  112. void __iomem *regs = i2s->regs;
  113. u32 fic, con, mod;
  114. pr_debug("%s(%d)\n", __func__, on);
  115. fic = readl(regs + S3C2412_IISFIC);
  116. con = readl(regs + S3C2412_IISCON);
  117. mod = readl(regs + S3C2412_IISMOD);
  118. pr_debug("%s: IIS: CON=%x MOD=%x FIC=%x\n", __func__, con, mod, fic);
  119. if (on) {
  120. con |= S3C2412_IISCON_RXDMA_ACTIVE | S3C2412_IISCON_IIS_ACTIVE;
  121. con &= ~S3C2412_IISCON_RXDMA_PAUSE;
  122. con &= ~S3C2412_IISCON_RXCH_PAUSE;
  123. switch (mod & S3C2412_IISMOD_MODE_MASK) {
  124. case S3C2412_IISMOD_MODE_TXRX:
  125. case S3C2412_IISMOD_MODE_RXONLY:
  126. /* do nothing, we are in the right mode */
  127. break;
  128. case S3C2412_IISMOD_MODE_TXONLY:
  129. mod &= ~S3C2412_IISMOD_MODE_MASK;
  130. mod |= S3C2412_IISMOD_MODE_TXRX;
  131. break;
  132. default:
  133. dev_err(i2s->dev, "RXEN: Invalid MODE %x in IISMOD\n",
  134. mod & S3C2412_IISMOD_MODE_MASK);
  135. }
  136. writel(mod, regs + S3C2412_IISMOD);
  137. writel(con, regs + S3C2412_IISCON);
  138. } else {
  139. /* See txctrl notes on FIFOs. */
  140. con &= ~S3C2412_IISCON_RXDMA_ACTIVE;
  141. con |= S3C2412_IISCON_RXDMA_PAUSE;
  142. con |= S3C2412_IISCON_RXCH_PAUSE;
  143. switch (mod & S3C2412_IISMOD_MODE_MASK) {
  144. case S3C2412_IISMOD_MODE_RXONLY:
  145. con &= ~S3C2412_IISCON_IIS_ACTIVE;
  146. mod &= ~S3C2412_IISMOD_MODE_MASK;
  147. break;
  148. case S3C2412_IISMOD_MODE_TXRX:
  149. mod &= ~S3C2412_IISMOD_MODE_MASK;
  150. mod |= S3C2412_IISMOD_MODE_TXONLY;
  151. break;
  152. default:
  153. dev_err(i2s->dev, "RXDIS: Invalid MODE %x in IISMOD\n",
  154. mod & S3C2412_IISMOD_MODE_MASK);
  155. }
  156. writel(con, regs + S3C2412_IISCON);
  157. writel(mod, regs + S3C2412_IISMOD);
  158. }
  159. fic = readl(regs + S3C2412_IISFIC);
  160. pr_debug("%s: IIS: CON=%x MOD=%x FIC=%x\n", __func__, con, mod, fic);
  161. }
  162. #define msecs_to_loops(t) (loops_per_jiffy / 1000 * HZ * t)
  163. /*
  164. * Wait for the LR signal to allow synchronisation to the L/R clock
  165. * from the codec. May only be needed for slave mode.
  166. */
  167. static int s3c2412_snd_lrsync(struct s3c_i2sv2_info *i2s)
  168. {
  169. u32 iiscon;
  170. unsigned long loops = msecs_to_loops(5);
  171. pr_debug("Entered %s\n", __func__);
  172. while (--loops) {
  173. iiscon = readl(i2s->regs + S3C2412_IISCON);
  174. if (iiscon & S3C2412_IISCON_LRINDEX)
  175. break;
  176. cpu_relax();
  177. }
  178. if (!loops) {
  179. printk(KERN_ERR "%s: timeout\n", __func__);
  180. return -ETIMEDOUT;
  181. }
  182. return 0;
  183. }
  184. /*
  185. * Set S3C2412 I2S DAI format
  186. */
  187. static int s3c2412_i2s_set_fmt(struct snd_soc_dai *cpu_dai,
  188. unsigned int fmt)
  189. {
  190. struct s3c_i2sv2_info *i2s = to_info(cpu_dai);
  191. u32 iismod;
  192. pr_debug("Entered %s\n", __func__);
  193. iismod = readl(i2s->regs + S3C2412_IISMOD);
  194. pr_debug("hw_params r: IISMOD: %x \n", iismod);
  195. switch (fmt & SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK) {
  196. case SND_SOC_DAIFMT_BC_FC:
  197. i2s->master = 0;
  198. iismod |= S3C2412_IISMOD_SLAVE;
  199. break;
  200. case SND_SOC_DAIFMT_BP_FP:
  201. i2s->master = 1;
  202. iismod &= ~S3C2412_IISMOD_SLAVE;
  203. break;
  204. default:
  205. pr_err("unknown master/slave format\n");
  206. return -EINVAL;
  207. }
  208. iismod &= ~S3C2412_IISMOD_SDF_MASK;
  209. switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  210. case SND_SOC_DAIFMT_RIGHT_J:
  211. iismod |= S3C2412_IISMOD_LR_RLOW;
  212. iismod |= S3C2412_IISMOD_SDF_MSB;
  213. break;
  214. case SND_SOC_DAIFMT_LEFT_J:
  215. iismod |= S3C2412_IISMOD_LR_RLOW;
  216. iismod |= S3C2412_IISMOD_SDF_LSB;
  217. break;
  218. case SND_SOC_DAIFMT_I2S:
  219. iismod &= ~S3C2412_IISMOD_LR_RLOW;
  220. iismod |= S3C2412_IISMOD_SDF_IIS;
  221. break;
  222. default:
  223. pr_err("Unknown data format\n");
  224. return -EINVAL;
  225. }
  226. writel(iismod, i2s->regs + S3C2412_IISMOD);
  227. pr_debug("hw_params w: IISMOD: %x \n", iismod);
  228. return 0;
  229. }
  230. static int s3c_i2sv2_hw_params(struct snd_pcm_substream *substream,
  231. struct snd_pcm_hw_params *params,
  232. struct snd_soc_dai *dai)
  233. {
  234. struct s3c_i2sv2_info *i2s = to_info(dai);
  235. struct snd_dmaengine_dai_dma_data *dma_data;
  236. u32 iismod;
  237. pr_debug("Entered %s\n", __func__);
  238. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  239. dma_data = i2s->dma_playback;
  240. else
  241. dma_data = i2s->dma_capture;
  242. snd_soc_dai_set_dma_data(dai, substream, dma_data);
  243. /* Working copies of register */
  244. iismod = readl(i2s->regs + S3C2412_IISMOD);
  245. pr_debug("%s: r: IISMOD: %x\n", __func__, iismod);
  246. iismod &= ~S3C64XX_IISMOD_BLC_MASK;
  247. /* Sample size */
  248. switch (params_width(params)) {
  249. case 8:
  250. iismod |= S3C64XX_IISMOD_BLC_8BIT;
  251. break;
  252. case 16:
  253. break;
  254. case 24:
  255. iismod |= S3C64XX_IISMOD_BLC_24BIT;
  256. break;
  257. }
  258. writel(iismod, i2s->regs + S3C2412_IISMOD);
  259. pr_debug("%s: w: IISMOD: %x\n", __func__, iismod);
  260. return 0;
  261. }
  262. static int s3c_i2sv2_set_sysclk(struct snd_soc_dai *cpu_dai,
  263. int clk_id, unsigned int freq, int dir)
  264. {
  265. struct s3c_i2sv2_info *i2s = to_info(cpu_dai);
  266. u32 iismod = readl(i2s->regs + S3C2412_IISMOD);
  267. pr_debug("Entered %s\n", __func__);
  268. pr_debug("%s r: IISMOD: %x\n", __func__, iismod);
  269. switch (clk_id) {
  270. case S3C_I2SV2_CLKSRC_PCLK:
  271. iismod &= ~S3C2412_IISMOD_IMS_SYSMUX;
  272. break;
  273. case S3C_I2SV2_CLKSRC_AUDIOBUS:
  274. iismod |= S3C2412_IISMOD_IMS_SYSMUX;
  275. break;
  276. case S3C_I2SV2_CLKSRC_CDCLK:
  277. /* Error if controller doesn't have the CDCLKCON bit */
  278. if (!(i2s->feature & S3C_FEATURE_CDCLKCON))
  279. return -EINVAL;
  280. switch (dir) {
  281. case SND_SOC_CLOCK_IN:
  282. iismod |= S3C64XX_IISMOD_CDCLKCON;
  283. break;
  284. case SND_SOC_CLOCK_OUT:
  285. iismod &= ~S3C64XX_IISMOD_CDCLKCON;
  286. break;
  287. default:
  288. return -EINVAL;
  289. }
  290. break;
  291. default:
  292. return -EINVAL;
  293. }
  294. writel(iismod, i2s->regs + S3C2412_IISMOD);
  295. pr_debug("%s w: IISMOD: %x\n", __func__, iismod);
  296. return 0;
  297. }
  298. static int s3c2412_i2s_trigger(struct snd_pcm_substream *substream, int cmd,
  299. struct snd_soc_dai *dai)
  300. {
  301. struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
  302. struct s3c_i2sv2_info *i2s = to_info(asoc_rtd_to_cpu(rtd, 0));
  303. int capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE);
  304. unsigned long irqs;
  305. int ret = 0;
  306. pr_debug("Entered %s\n", __func__);
  307. switch (cmd) {
  308. case SNDRV_PCM_TRIGGER_START:
  309. /* On start, ensure that the FIFOs are cleared and reset. */
  310. writel(capture ? S3C2412_IISFIC_RXFLUSH : S3C2412_IISFIC_TXFLUSH,
  311. i2s->regs + S3C2412_IISFIC);
  312. /* clear again, just in case */
  313. writel(0x0, i2s->regs + S3C2412_IISFIC);
  314. fallthrough;
  315. case SNDRV_PCM_TRIGGER_RESUME:
  316. case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  317. if (!i2s->master) {
  318. ret = s3c2412_snd_lrsync(i2s);
  319. if (ret)
  320. goto exit_err;
  321. }
  322. local_irq_save(irqs);
  323. if (capture)
  324. s3c2412_snd_rxctrl(i2s, 1);
  325. else
  326. s3c2412_snd_txctrl(i2s, 1);
  327. local_irq_restore(irqs);
  328. break;
  329. case SNDRV_PCM_TRIGGER_STOP:
  330. case SNDRV_PCM_TRIGGER_SUSPEND:
  331. case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  332. local_irq_save(irqs);
  333. if (capture)
  334. s3c2412_snd_rxctrl(i2s, 0);
  335. else
  336. s3c2412_snd_txctrl(i2s, 0);
  337. local_irq_restore(irqs);
  338. break;
  339. default:
  340. ret = -EINVAL;
  341. break;
  342. }
  343. exit_err:
  344. return ret;
  345. }
  346. /*
  347. * Set S3C2412 Clock dividers
  348. */
  349. static int s3c2412_i2s_set_clkdiv(struct snd_soc_dai *cpu_dai,
  350. int div_id, int div)
  351. {
  352. struct s3c_i2sv2_info *i2s = to_info(cpu_dai);
  353. u32 reg;
  354. pr_debug("%s(%p, %d, %d)\n", __func__, cpu_dai, div_id, div);
  355. switch (div_id) {
  356. case S3C_I2SV2_DIV_BCLK:
  357. switch (div) {
  358. case 16:
  359. div = S3C2412_IISMOD_BCLK_16FS;
  360. break;
  361. case 32:
  362. div = S3C2412_IISMOD_BCLK_32FS;
  363. break;
  364. case 24:
  365. div = S3C2412_IISMOD_BCLK_24FS;
  366. break;
  367. case 48:
  368. div = S3C2412_IISMOD_BCLK_48FS;
  369. break;
  370. default:
  371. return -EINVAL;
  372. }
  373. reg = readl(i2s->regs + S3C2412_IISMOD);
  374. reg &= ~S3C2412_IISMOD_BCLK_MASK;
  375. writel(reg | div, i2s->regs + S3C2412_IISMOD);
  376. pr_debug("%s: MOD=%08x\n", __func__, readl(i2s->regs + S3C2412_IISMOD));
  377. break;
  378. case S3C_I2SV2_DIV_RCLK:
  379. switch (div) {
  380. case 256:
  381. div = S3C2412_IISMOD_RCLK_256FS;
  382. break;
  383. case 384:
  384. div = S3C2412_IISMOD_RCLK_384FS;
  385. break;
  386. case 512:
  387. div = S3C2412_IISMOD_RCLK_512FS;
  388. break;
  389. case 768:
  390. div = S3C2412_IISMOD_RCLK_768FS;
  391. break;
  392. default:
  393. return -EINVAL;
  394. }
  395. reg = readl(i2s->regs + S3C2412_IISMOD);
  396. reg &= ~S3C2412_IISMOD_RCLK_MASK;
  397. writel(reg | div, i2s->regs + S3C2412_IISMOD);
  398. pr_debug("%s: MOD=%08x\n", __func__, readl(i2s->regs + S3C2412_IISMOD));
  399. break;
  400. case S3C_I2SV2_DIV_PRESCALER:
  401. if (div >= 0) {
  402. writel((div << 8) | S3C2412_IISPSR_PSREN,
  403. i2s->regs + S3C2412_IISPSR);
  404. } else {
  405. writel(0x0, i2s->regs + S3C2412_IISPSR);
  406. }
  407. pr_debug("%s: PSR=%08x\n", __func__, readl(i2s->regs + S3C2412_IISPSR));
  408. break;
  409. default:
  410. return -EINVAL;
  411. }
  412. return 0;
  413. }
  414. static snd_pcm_sframes_t s3c2412_i2s_delay(struct snd_pcm_substream *substream,
  415. struct snd_soc_dai *dai)
  416. {
  417. struct s3c_i2sv2_info *i2s = to_info(dai);
  418. u32 reg = readl(i2s->regs + S3C2412_IISFIC);
  419. snd_pcm_sframes_t delay;
  420. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  421. delay = S3C2412_IISFIC_TXCOUNT(reg);
  422. else
  423. delay = S3C2412_IISFIC_RXCOUNT(reg);
  424. return delay;
  425. }
  426. struct clk *s3c_i2sv2_get_clock(struct snd_soc_dai *cpu_dai)
  427. {
  428. struct s3c_i2sv2_info *i2s = to_info(cpu_dai);
  429. u32 iismod = readl(i2s->regs + S3C2412_IISMOD);
  430. if (iismod & S3C2412_IISMOD_IMS_SYSMUX)
  431. return i2s->iis_cclk;
  432. else
  433. return i2s->iis_pclk;
  434. }
  435. EXPORT_SYMBOL_GPL(s3c_i2sv2_get_clock);
  436. /* default table of all avaialable root fs divisors */
  437. static unsigned int iis_fs_tab[] = { 256, 512, 384, 768 };
  438. int s3c_i2sv2_iis_calc_rate(struct s3c_i2sv2_rate_calc *info,
  439. unsigned int *fstab,
  440. unsigned int rate, struct clk *clk)
  441. {
  442. unsigned long clkrate = clk_get_rate(clk);
  443. unsigned int div;
  444. unsigned int fsclk;
  445. unsigned int actual;
  446. unsigned int fs;
  447. unsigned int fsdiv;
  448. signed int deviation = 0;
  449. unsigned int best_fs = 0;
  450. unsigned int best_div = 0;
  451. unsigned int best_rate = 0;
  452. unsigned int best_deviation = INT_MAX;
  453. pr_debug("Input clock rate %ldHz\n", clkrate);
  454. if (fstab == NULL)
  455. fstab = iis_fs_tab;
  456. for (fs = 0; fs < ARRAY_SIZE(iis_fs_tab); fs++) {
  457. fsdiv = iis_fs_tab[fs];
  458. fsclk = clkrate / fsdiv;
  459. div = fsclk / rate;
  460. if ((fsclk % rate) > (rate / 2))
  461. div++;
  462. if (div <= 1)
  463. continue;
  464. actual = clkrate / (fsdiv * div);
  465. deviation = actual - rate;
  466. printk(KERN_DEBUG "%ufs: div %u => result %u, deviation %d\n",
  467. fsdiv, div, actual, deviation);
  468. deviation = abs(deviation);
  469. if (deviation < best_deviation) {
  470. best_fs = fsdiv;
  471. best_div = div;
  472. best_rate = actual;
  473. best_deviation = deviation;
  474. }
  475. if (deviation == 0)
  476. break;
  477. }
  478. printk(KERN_DEBUG "best: fs=%u, div=%u, rate=%u\n",
  479. best_fs, best_div, best_rate);
  480. info->fs_div = best_fs;
  481. info->clk_div = best_div;
  482. return 0;
  483. }
  484. EXPORT_SYMBOL_GPL(s3c_i2sv2_iis_calc_rate);
  485. int s3c_i2sv2_probe(struct snd_soc_dai *dai,
  486. struct s3c_i2sv2_info *i2s)
  487. {
  488. struct device *dev = dai->dev;
  489. unsigned int iismod;
  490. i2s->dev = dev;
  491. /* record our i2s structure for later use in the callbacks */
  492. snd_soc_dai_set_drvdata(dai, i2s);
  493. i2s->iis_pclk = clk_get(dev, "iis");
  494. if (IS_ERR(i2s->iis_pclk)) {
  495. dev_err(dev, "failed to get iis_clock\n");
  496. return -ENOENT;
  497. }
  498. clk_prepare_enable(i2s->iis_pclk);
  499. /* Mark ourselves as in TXRX mode so we can run through our cleanup
  500. * process without warnings. */
  501. iismod = readl(i2s->regs + S3C2412_IISMOD);
  502. iismod |= S3C2412_IISMOD_MODE_TXRX;
  503. writel(iismod, i2s->regs + S3C2412_IISMOD);
  504. s3c2412_snd_txctrl(i2s, 0);
  505. s3c2412_snd_rxctrl(i2s, 0);
  506. return 0;
  507. }
  508. EXPORT_SYMBOL_GPL(s3c_i2sv2_probe);
  509. void s3c_i2sv2_cleanup(struct snd_soc_dai *dai,
  510. struct s3c_i2sv2_info *i2s)
  511. {
  512. clk_disable_unprepare(i2s->iis_pclk);
  513. clk_put(i2s->iis_pclk);
  514. i2s->iis_pclk = NULL;
  515. }
  516. EXPORT_SYMBOL_GPL(s3c_i2sv2_cleanup);
  517. int s3c_i2sv2_register_component(struct device *dev, int id,
  518. const struct snd_soc_component_driver *cmp_drv,
  519. struct snd_soc_dai_driver *dai_drv)
  520. {
  521. struct snd_soc_dai_ops *ops = (struct snd_soc_dai_ops *)dai_drv->ops;
  522. ops->trigger = s3c2412_i2s_trigger;
  523. if (!ops->hw_params)
  524. ops->hw_params = s3c_i2sv2_hw_params;
  525. ops->set_fmt = s3c2412_i2s_set_fmt;
  526. ops->set_clkdiv = s3c2412_i2s_set_clkdiv;
  527. ops->set_sysclk = s3c_i2sv2_set_sysclk;
  528. /* Allow overriding by (for example) IISv4 */
  529. if (!ops->delay)
  530. ops->delay = s3c2412_i2s_delay;
  531. return devm_snd_soc_register_component(dev, cmp_drv, dai_drv, 1);
  532. }
  533. EXPORT_SYMBOL_GPL(s3c_i2sv2_register_component);
  534. MODULE_LICENSE("GPL");