i2s.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378
  1. /* sound/soc/samsung/i2s.c
  2. *
  3. * ALSA SoC Audio Layer - Samsung I2S Controller driver
  4. *
  5. * Copyright (c) 2010 Samsung Electronics Co. Ltd.
  6. * Jaswinder Singh <jassisinghbrar@gmail.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include <linux/delay.h>
  13. #include <linux/slab.h>
  14. #include <linux/clk.h>
  15. #include <linux/io.h>
  16. #include <linux/module.h>
  17. #include <linux/of.h>
  18. #include <linux/of_gpio.h>
  19. #include <linux/pm_runtime.h>
  20. #include <sound/soc.h>
  21. #include <sound/pcm_params.h>
  22. #include <mach/dma.h>
  23. #include <linux/platform_data/asoc-s3c.h>
  24. #include "dma.h"
  25. #include "idma.h"
  26. #include "i2s.h"
  27. #include "i2s-regs.h"
  28. #define msecs_to_loops(t) (loops_per_jiffy / 1000 * HZ * t)
  29. enum samsung_dai_type {
  30. TYPE_PRI,
  31. TYPE_SEC,
  32. };
  33. struct samsung_i2s_dai_data {
  34. int dai_type;
  35. u32 quirks;
  36. };
  37. struct i2s_dai {
  38. /* Platform device for this DAI */
  39. struct platform_device *pdev;
  40. /* IOREMAP'd SFRs */
  41. void __iomem *addr;
  42. /* Physical base address of SFRs */
  43. u32 base;
  44. /* Rate of RCLK source clock */
  45. unsigned long rclk_srcrate;
  46. /* Frame Clock */
  47. unsigned frmclk;
  48. /*
  49. * Specifically requested RCLK,BCLK by MACHINE Driver.
  50. * 0 indicates CPU driver is free to choose any value.
  51. */
  52. unsigned rfs, bfs;
  53. /* I2S Controller's core clock */
  54. struct clk *clk;
  55. /* Clock for generating I2S signals */
  56. struct clk *op_clk;
  57. /* Pointer to the Primary_Fifo if this is Sec_Fifo, NULL otherwise */
  58. struct i2s_dai *pri_dai;
  59. /* Pointer to the Secondary_Fifo if it has one, NULL otherwise */
  60. struct i2s_dai *sec_dai;
  61. #define DAI_OPENED (1 << 0) /* Dai is opened */
  62. #define DAI_MANAGER (1 << 1) /* Dai is the manager */
  63. unsigned mode;
  64. /* Driver for this DAI */
  65. struct snd_soc_dai_driver i2s_dai_drv;
  66. /* DMA parameters */
  67. struct s3c_dma_params dma_playback;
  68. struct s3c_dma_params dma_capture;
  69. struct s3c_dma_params idma_playback;
  70. u32 quirks;
  71. u32 suspend_i2smod;
  72. u32 suspend_i2scon;
  73. u32 suspend_i2spsr;
  74. unsigned long gpios[7]; /* i2s gpio line numbers */
  75. };
  76. /* Lock for cross i/f checks */
  77. static DEFINE_SPINLOCK(lock);
  78. /* If this is the 'overlay' stereo DAI */
  79. static inline bool is_secondary(struct i2s_dai *i2s)
  80. {
  81. return i2s->pri_dai ? true : false;
  82. }
  83. /* If operating in SoC-Slave mode */
  84. static inline bool is_slave(struct i2s_dai *i2s)
  85. {
  86. return (readl(i2s->addr + I2SMOD) & MOD_SLAVE) ? true : false;
  87. }
  88. /* If this interface of the controller is transmitting data */
  89. static inline bool tx_active(struct i2s_dai *i2s)
  90. {
  91. u32 active;
  92. if (!i2s)
  93. return false;
  94. active = readl(i2s->addr + I2SCON);
  95. if (is_secondary(i2s))
  96. active &= CON_TXSDMA_ACTIVE;
  97. else
  98. active &= CON_TXDMA_ACTIVE;
  99. return active ? true : false;
  100. }
  101. /* If the other interface of the controller is transmitting data */
  102. static inline bool other_tx_active(struct i2s_dai *i2s)
  103. {
  104. struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai;
  105. return tx_active(other);
  106. }
  107. /* If any interface of the controller is transmitting data */
  108. static inline bool any_tx_active(struct i2s_dai *i2s)
  109. {
  110. return tx_active(i2s) || other_tx_active(i2s);
  111. }
  112. /* If this interface of the controller is receiving data */
  113. static inline bool rx_active(struct i2s_dai *i2s)
  114. {
  115. u32 active;
  116. if (!i2s)
  117. return false;
  118. active = readl(i2s->addr + I2SCON) & CON_RXDMA_ACTIVE;
  119. return active ? true : false;
  120. }
  121. /* If the other interface of the controller is receiving data */
  122. static inline bool other_rx_active(struct i2s_dai *i2s)
  123. {
  124. struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai;
  125. return rx_active(other);
  126. }
  127. /* If any interface of the controller is receiving data */
  128. static inline bool any_rx_active(struct i2s_dai *i2s)
  129. {
  130. return rx_active(i2s) || other_rx_active(i2s);
  131. }
  132. /* If the other DAI is transmitting or receiving data */
  133. static inline bool other_active(struct i2s_dai *i2s)
  134. {
  135. return other_rx_active(i2s) || other_tx_active(i2s);
  136. }
  137. /* If this DAI is transmitting or receiving data */
  138. static inline bool this_active(struct i2s_dai *i2s)
  139. {
  140. return tx_active(i2s) || rx_active(i2s);
  141. }
  142. /* If the controller is active anyway */
  143. static inline bool any_active(struct i2s_dai *i2s)
  144. {
  145. return this_active(i2s) || other_active(i2s);
  146. }
  147. static inline struct i2s_dai *to_info(struct snd_soc_dai *dai)
  148. {
  149. return snd_soc_dai_get_drvdata(dai);
  150. }
  151. static inline bool is_opened(struct i2s_dai *i2s)
  152. {
  153. if (i2s && (i2s->mode & DAI_OPENED))
  154. return true;
  155. else
  156. return false;
  157. }
  158. static inline bool is_manager(struct i2s_dai *i2s)
  159. {
  160. if (is_opened(i2s) && (i2s->mode & DAI_MANAGER))
  161. return true;
  162. else
  163. return false;
  164. }
  165. /* Read RCLK of I2S (in multiples of LRCLK) */
  166. static inline unsigned get_rfs(struct i2s_dai *i2s)
  167. {
  168. u32 rfs;
  169. if (i2s->quirks & QUIRK_SUPPORTS_TDM)
  170. rfs = readl(i2s->addr + I2SMOD) >> EXYNOS5420_MOD_RCLK_SHIFT;
  171. else
  172. rfs = (readl(i2s->addr + I2SMOD) >> MOD_RCLK_SHIFT);
  173. rfs &= MOD_RCLK_MASK;
  174. switch (rfs) {
  175. case 3: return 768;
  176. case 2: return 384;
  177. case 1: return 512;
  178. default: return 256;
  179. }
  180. }
  181. /* Write RCLK of I2S (in multiples of LRCLK) */
  182. static inline void set_rfs(struct i2s_dai *i2s, unsigned rfs)
  183. {
  184. u32 mod = readl(i2s->addr + I2SMOD);
  185. int rfs_shift;
  186. if (i2s->quirks & QUIRK_SUPPORTS_TDM)
  187. rfs_shift = EXYNOS5420_MOD_RCLK_SHIFT;
  188. else
  189. rfs_shift = MOD_RCLK_SHIFT;
  190. mod &= ~(MOD_RCLK_MASK << rfs_shift);
  191. switch (rfs) {
  192. case 768:
  193. mod |= (MOD_RCLK_768FS << rfs_shift);
  194. break;
  195. case 512:
  196. mod |= (MOD_RCLK_512FS << rfs_shift);
  197. break;
  198. case 384:
  199. mod |= (MOD_RCLK_384FS << rfs_shift);
  200. break;
  201. default:
  202. mod |= (MOD_RCLK_256FS << rfs_shift);
  203. break;
  204. }
  205. writel(mod, i2s->addr + I2SMOD);
  206. }
  207. /* Read Bit-Clock of I2S (in multiples of LRCLK) */
  208. static inline unsigned get_bfs(struct i2s_dai *i2s)
  209. {
  210. u32 bfs;
  211. if (i2s->quirks & QUIRK_SUPPORTS_TDM) {
  212. bfs = readl(i2s->addr + I2SMOD) >> EXYNOS5420_MOD_BCLK_SHIFT;
  213. bfs &= EXYNOS5420_MOD_BCLK_MASK;
  214. } else {
  215. bfs = readl(i2s->addr + I2SMOD) >> MOD_BCLK_SHIFT;
  216. bfs &= MOD_BCLK_MASK;
  217. }
  218. switch (bfs) {
  219. case 8: return 256;
  220. case 7: return 192;
  221. case 6: return 128;
  222. case 5: return 96;
  223. case 4: return 64;
  224. case 3: return 24;
  225. case 2: return 16;
  226. case 1: return 48;
  227. default: return 32;
  228. }
  229. }
  230. /* Write Bit-Clock of I2S (in multiples of LRCLK) */
  231. static inline void set_bfs(struct i2s_dai *i2s, unsigned bfs)
  232. {
  233. u32 mod = readl(i2s->addr + I2SMOD);
  234. int bfs_shift;
  235. int tdm = i2s->quirks & QUIRK_SUPPORTS_TDM;
  236. if (i2s->quirks & QUIRK_SUPPORTS_TDM) {
  237. bfs_shift = EXYNOS5420_MOD_BCLK_SHIFT;
  238. mod &= ~(EXYNOS5420_MOD_BCLK_MASK << bfs_shift);
  239. } else {
  240. bfs_shift = MOD_BCLK_SHIFT;
  241. mod &= ~(MOD_BCLK_MASK << bfs_shift);
  242. }
  243. /* Non-TDM I2S controllers do not support BCLK > 48 * FS */
  244. if (!tdm && bfs > 48) {
  245. dev_err(&i2s->pdev->dev, "Unsupported BCLK divider\n");
  246. return;
  247. }
  248. switch (bfs) {
  249. case 48:
  250. mod |= (MOD_BCLK_48FS << bfs_shift);
  251. break;
  252. case 32:
  253. mod |= (MOD_BCLK_32FS << bfs_shift);
  254. break;
  255. case 24:
  256. mod |= (MOD_BCLK_24FS << bfs_shift);
  257. break;
  258. case 16:
  259. mod |= (MOD_BCLK_16FS << bfs_shift);
  260. break;
  261. case 64:
  262. mod |= (EXYNOS5420_MOD_BCLK_64FS << bfs_shift);
  263. break;
  264. case 96:
  265. mod |= (EXYNOS5420_MOD_BCLK_96FS << bfs_shift);
  266. break;
  267. case 128:
  268. mod |= (EXYNOS5420_MOD_BCLK_128FS << bfs_shift);
  269. break;
  270. case 192:
  271. mod |= (EXYNOS5420_MOD_BCLK_192FS << bfs_shift);
  272. break;
  273. case 256:
  274. mod |= (EXYNOS5420_MOD_BCLK_256FS << bfs_shift);
  275. break;
  276. default:
  277. dev_err(&i2s->pdev->dev, "Wrong BCLK Divider!\n");
  278. return;
  279. }
  280. writel(mod, i2s->addr + I2SMOD);
  281. }
  282. /* Sample-Size */
  283. static inline int get_blc(struct i2s_dai *i2s)
  284. {
  285. int blc = readl(i2s->addr + I2SMOD);
  286. blc = (blc >> 13) & 0x3;
  287. switch (blc) {
  288. case 2: return 24;
  289. case 1: return 8;
  290. default: return 16;
  291. }
  292. }
  293. /* TX Channel Control */
  294. static void i2s_txctrl(struct i2s_dai *i2s, int on)
  295. {
  296. void __iomem *addr = i2s->addr;
  297. u32 con = readl(addr + I2SCON);
  298. u32 mod = readl(addr + I2SMOD) & ~MOD_MASK;
  299. if (on) {
  300. con |= CON_ACTIVE;
  301. con &= ~CON_TXCH_PAUSE;
  302. if (is_secondary(i2s)) {
  303. con |= CON_TXSDMA_ACTIVE;
  304. con &= ~CON_TXSDMA_PAUSE;
  305. } else {
  306. con |= CON_TXDMA_ACTIVE;
  307. con &= ~CON_TXDMA_PAUSE;
  308. }
  309. if (any_rx_active(i2s))
  310. mod |= MOD_TXRX;
  311. else
  312. mod |= MOD_TXONLY;
  313. } else {
  314. if (is_secondary(i2s)) {
  315. con |= CON_TXSDMA_PAUSE;
  316. con &= ~CON_TXSDMA_ACTIVE;
  317. } else {
  318. con |= CON_TXDMA_PAUSE;
  319. con &= ~CON_TXDMA_ACTIVE;
  320. }
  321. if (other_tx_active(i2s)) {
  322. writel(con, addr + I2SCON);
  323. return;
  324. }
  325. con |= CON_TXCH_PAUSE;
  326. if (any_rx_active(i2s))
  327. mod |= MOD_RXONLY;
  328. else
  329. con &= ~CON_ACTIVE;
  330. }
  331. writel(mod, addr + I2SMOD);
  332. writel(con, addr + I2SCON);
  333. }
  334. /* RX Channel Control */
  335. static void i2s_rxctrl(struct i2s_dai *i2s, int on)
  336. {
  337. void __iomem *addr = i2s->addr;
  338. u32 con = readl(addr + I2SCON);
  339. u32 mod = readl(addr + I2SMOD) & ~MOD_MASK;
  340. if (on) {
  341. con |= CON_RXDMA_ACTIVE | CON_ACTIVE;
  342. con &= ~(CON_RXDMA_PAUSE | CON_RXCH_PAUSE);
  343. if (any_tx_active(i2s))
  344. mod |= MOD_TXRX;
  345. else
  346. mod |= MOD_RXONLY;
  347. } else {
  348. con |= CON_RXDMA_PAUSE | CON_RXCH_PAUSE;
  349. con &= ~CON_RXDMA_ACTIVE;
  350. if (any_tx_active(i2s))
  351. mod |= MOD_TXONLY;
  352. else
  353. con &= ~CON_ACTIVE;
  354. }
  355. writel(mod, addr + I2SMOD);
  356. writel(con, addr + I2SCON);
  357. }
  358. /* Flush FIFO of an interface */
  359. static inline void i2s_fifo(struct i2s_dai *i2s, u32 flush)
  360. {
  361. void __iomem *fic;
  362. u32 val;
  363. if (!i2s)
  364. return;
  365. if (is_secondary(i2s))
  366. fic = i2s->addr + I2SFICS;
  367. else
  368. fic = i2s->addr + I2SFIC;
  369. /* Flush the FIFO */
  370. writel(readl(fic) | flush, fic);
  371. /* Be patient */
  372. val = msecs_to_loops(1) / 1000; /* 1 usec */
  373. while (--val)
  374. cpu_relax();
  375. writel(readl(fic) & ~flush, fic);
  376. }
  377. static int i2s_set_sysclk(struct snd_soc_dai *dai,
  378. int clk_id, unsigned int rfs, int dir)
  379. {
  380. struct i2s_dai *i2s = to_info(dai);
  381. struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai;
  382. u32 mod = readl(i2s->addr + I2SMOD);
  383. switch (clk_id) {
  384. case SAMSUNG_I2S_CDCLK:
  385. /* Shouldn't matter in GATING(CLOCK_IN) mode */
  386. if (dir == SND_SOC_CLOCK_IN)
  387. rfs = 0;
  388. if ((rfs && other->rfs && (other->rfs != rfs)) ||
  389. (any_active(i2s) &&
  390. (((dir == SND_SOC_CLOCK_IN)
  391. && !(mod & MOD_CDCLKCON)) ||
  392. ((dir == SND_SOC_CLOCK_OUT)
  393. && (mod & MOD_CDCLKCON))))) {
  394. dev_err(&i2s->pdev->dev,
  395. "%s:%d Other DAI busy\n", __func__, __LINE__);
  396. return -EAGAIN;
  397. }
  398. if (dir == SND_SOC_CLOCK_IN)
  399. mod |= MOD_CDCLKCON;
  400. else
  401. mod &= ~MOD_CDCLKCON;
  402. i2s->rfs = rfs;
  403. break;
  404. case SAMSUNG_I2S_RCLKSRC_0: /* clock corrsponding to IISMOD[10] := 0 */
  405. case SAMSUNG_I2S_RCLKSRC_1: /* clock corrsponding to IISMOD[10] := 1 */
  406. if ((i2s->quirks & QUIRK_NO_MUXPSR)
  407. || (clk_id == SAMSUNG_I2S_RCLKSRC_0))
  408. clk_id = 0;
  409. else
  410. clk_id = 1;
  411. if (!any_active(i2s)) {
  412. if (i2s->op_clk) {
  413. if ((clk_id && !(mod & MOD_IMS_SYSMUX)) ||
  414. (!clk_id && (mod & MOD_IMS_SYSMUX))) {
  415. clk_disable_unprepare(i2s->op_clk);
  416. clk_put(i2s->op_clk);
  417. } else {
  418. i2s->rclk_srcrate =
  419. clk_get_rate(i2s->op_clk);
  420. return 0;
  421. }
  422. }
  423. if (clk_id)
  424. i2s->op_clk = clk_get(&i2s->pdev->dev,
  425. "i2s_opclk1");
  426. else
  427. i2s->op_clk = clk_get(&i2s->pdev->dev,
  428. "i2s_opclk0");
  429. clk_prepare_enable(i2s->op_clk);
  430. i2s->rclk_srcrate = clk_get_rate(i2s->op_clk);
  431. /* Over-ride the other's */
  432. if (other) {
  433. other->op_clk = i2s->op_clk;
  434. other->rclk_srcrate = i2s->rclk_srcrate;
  435. }
  436. } else if ((!clk_id && (mod & MOD_IMS_SYSMUX))
  437. || (clk_id && !(mod & MOD_IMS_SYSMUX))) {
  438. dev_err(&i2s->pdev->dev,
  439. "%s:%d Other DAI busy\n", __func__, __LINE__);
  440. return -EAGAIN;
  441. } else {
  442. /* Call can't be on the active DAI */
  443. i2s->op_clk = other->op_clk;
  444. i2s->rclk_srcrate = other->rclk_srcrate;
  445. return 0;
  446. }
  447. if (clk_id == 0)
  448. mod &= ~MOD_IMS_SYSMUX;
  449. else
  450. mod |= MOD_IMS_SYSMUX;
  451. break;
  452. default:
  453. dev_err(&i2s->pdev->dev, "We don't serve that!\n");
  454. return -EINVAL;
  455. }
  456. writel(mod, i2s->addr + I2SMOD);
  457. return 0;
  458. }
  459. static int i2s_set_fmt(struct snd_soc_dai *dai,
  460. unsigned int fmt)
  461. {
  462. struct i2s_dai *i2s = to_info(dai);
  463. u32 mod = readl(i2s->addr + I2SMOD);
  464. int lrp_shift, sdf_shift, sdf_mask, lrp_rlow;
  465. u32 tmp = 0;
  466. if (i2s->quirks & QUIRK_SUPPORTS_TDM) {
  467. lrp_shift = EXYNOS5420_MOD_LRP_SHIFT;
  468. sdf_shift = EXYNOS5420_MOD_SDF_SHIFT;
  469. } else {
  470. lrp_shift = MOD_LRP_SHIFT;
  471. sdf_shift = MOD_SDF_SHIFT;
  472. }
  473. sdf_mask = MOD_SDF_MASK << sdf_shift;
  474. lrp_rlow = MOD_LR_RLOW << lrp_shift;
  475. /* Format is priority */
  476. switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  477. case SND_SOC_DAIFMT_RIGHT_J:
  478. tmp |= lrp_rlow;
  479. tmp |= (MOD_SDF_MSB << sdf_shift);
  480. break;
  481. case SND_SOC_DAIFMT_LEFT_J:
  482. tmp |= lrp_rlow;
  483. tmp |= (MOD_SDF_LSB << sdf_shift);
  484. break;
  485. case SND_SOC_DAIFMT_I2S:
  486. tmp |= (MOD_SDF_IIS << sdf_shift);
  487. break;
  488. default:
  489. dev_err(&i2s->pdev->dev, "Format not supported\n");
  490. return -EINVAL;
  491. }
  492. /*
  493. * INV flag is relative to the FORMAT flag - if set it simply
  494. * flips the polarity specified by the Standard
  495. */
  496. switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
  497. case SND_SOC_DAIFMT_NB_NF:
  498. break;
  499. case SND_SOC_DAIFMT_NB_IF:
  500. if (tmp & lrp_rlow)
  501. tmp &= ~lrp_rlow;
  502. else
  503. tmp |= lrp_rlow;
  504. break;
  505. default:
  506. dev_err(&i2s->pdev->dev, "Polarity not supported\n");
  507. return -EINVAL;
  508. }
  509. switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  510. case SND_SOC_DAIFMT_CBM_CFM:
  511. tmp |= MOD_SLAVE;
  512. break;
  513. case SND_SOC_DAIFMT_CBS_CFS:
  514. /* Set default source clock in Master mode */
  515. if (i2s->rclk_srcrate == 0)
  516. i2s_set_sysclk(dai, SAMSUNG_I2S_RCLKSRC_0,
  517. 0, SND_SOC_CLOCK_IN);
  518. break;
  519. default:
  520. dev_err(&i2s->pdev->dev, "master/slave format not supported\n");
  521. return -EINVAL;
  522. }
  523. /*
  524. * Don't change the I2S mode if any controller is active on this
  525. * channel.
  526. */
  527. if (any_active(i2s) &&
  528. ((mod & (sdf_mask | lrp_rlow | MOD_SLAVE)) != tmp)) {
  529. dev_err(&i2s->pdev->dev,
  530. "%s:%d Other DAI busy\n", __func__, __LINE__);
  531. return -EAGAIN;
  532. }
  533. mod &= ~(sdf_mask | lrp_rlow | MOD_SLAVE);
  534. mod |= tmp;
  535. writel(mod, i2s->addr + I2SMOD);
  536. return 0;
  537. }
  538. static int i2s_hw_params(struct snd_pcm_substream *substream,
  539. struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
  540. {
  541. struct i2s_dai *i2s = to_info(dai);
  542. u32 mod = readl(i2s->addr + I2SMOD);
  543. if (!is_secondary(i2s))
  544. mod &= ~(MOD_DC2_EN | MOD_DC1_EN);
  545. switch (params_channels(params)) {
  546. case 6:
  547. mod |= MOD_DC2_EN;
  548. case 4:
  549. mod |= MOD_DC1_EN;
  550. break;
  551. case 2:
  552. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  553. i2s->dma_playback.dma_size = 4;
  554. else
  555. i2s->dma_capture.dma_size = 4;
  556. break;
  557. case 1:
  558. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  559. i2s->dma_playback.dma_size = 2;
  560. else
  561. i2s->dma_capture.dma_size = 2;
  562. break;
  563. default:
  564. dev_err(&i2s->pdev->dev, "%d channels not supported\n",
  565. params_channels(params));
  566. return -EINVAL;
  567. }
  568. if (is_secondary(i2s))
  569. mod &= ~MOD_BLCS_MASK;
  570. else
  571. mod &= ~MOD_BLCP_MASK;
  572. if (is_manager(i2s))
  573. mod &= ~MOD_BLC_MASK;
  574. switch (params_format(params)) {
  575. case SNDRV_PCM_FORMAT_S8:
  576. if (is_secondary(i2s))
  577. mod |= MOD_BLCS_8BIT;
  578. else
  579. mod |= MOD_BLCP_8BIT;
  580. if (is_manager(i2s))
  581. mod |= MOD_BLC_8BIT;
  582. break;
  583. case SNDRV_PCM_FORMAT_S16_LE:
  584. if (is_secondary(i2s))
  585. mod |= MOD_BLCS_16BIT;
  586. else
  587. mod |= MOD_BLCP_16BIT;
  588. if (is_manager(i2s))
  589. mod |= MOD_BLC_16BIT;
  590. break;
  591. case SNDRV_PCM_FORMAT_S24_LE:
  592. if (is_secondary(i2s))
  593. mod |= MOD_BLCS_24BIT;
  594. else
  595. mod |= MOD_BLCP_24BIT;
  596. if (is_manager(i2s))
  597. mod |= MOD_BLC_24BIT;
  598. break;
  599. default:
  600. dev_err(&i2s->pdev->dev, "Format(%d) not supported\n",
  601. params_format(params));
  602. return -EINVAL;
  603. }
  604. writel(mod, i2s->addr + I2SMOD);
  605. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  606. snd_soc_dai_set_dma_data(dai, substream,
  607. (void *)&i2s->dma_playback);
  608. else
  609. snd_soc_dai_set_dma_data(dai, substream,
  610. (void *)&i2s->dma_capture);
  611. i2s->frmclk = params_rate(params);
  612. return 0;
  613. }
  614. /* We set constraints on the substream acc to the version of I2S */
  615. static int i2s_startup(struct snd_pcm_substream *substream,
  616. struct snd_soc_dai *dai)
  617. {
  618. struct i2s_dai *i2s = to_info(dai);
  619. struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai;
  620. unsigned long flags;
  621. spin_lock_irqsave(&lock, flags);
  622. i2s->mode |= DAI_OPENED;
  623. if (is_manager(other))
  624. i2s->mode &= ~DAI_MANAGER;
  625. else
  626. i2s->mode |= DAI_MANAGER;
  627. /* Enforce set_sysclk in Master mode */
  628. i2s->rclk_srcrate = 0;
  629. if (!any_active(i2s) && (i2s->quirks & QUIRK_NEED_RSTCLR))
  630. writel(CON_RSTCLR, i2s->addr + I2SCON);
  631. spin_unlock_irqrestore(&lock, flags);
  632. return 0;
  633. }
  634. static void i2s_shutdown(struct snd_pcm_substream *substream,
  635. struct snd_soc_dai *dai)
  636. {
  637. struct i2s_dai *i2s = to_info(dai);
  638. struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai;
  639. unsigned long flags;
  640. spin_lock_irqsave(&lock, flags);
  641. i2s->mode &= ~DAI_OPENED;
  642. i2s->mode &= ~DAI_MANAGER;
  643. if (is_opened(other))
  644. other->mode |= DAI_MANAGER;
  645. /* Reset any constraint on RFS and BFS */
  646. i2s->rfs = 0;
  647. i2s->bfs = 0;
  648. spin_unlock_irqrestore(&lock, flags);
  649. /* Gate CDCLK by default */
  650. if (!is_opened(other))
  651. i2s_set_sysclk(dai, SAMSUNG_I2S_CDCLK,
  652. 0, SND_SOC_CLOCK_IN);
  653. }
  654. static int config_setup(struct i2s_dai *i2s)
  655. {
  656. struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai;
  657. unsigned rfs, bfs, blc;
  658. u32 psr;
  659. blc = get_blc(i2s);
  660. bfs = i2s->bfs;
  661. if (!bfs && other)
  662. bfs = other->bfs;
  663. /* Select least possible multiple(2) if no constraint set */
  664. if (!bfs)
  665. bfs = blc * 2;
  666. rfs = i2s->rfs;
  667. if (!rfs && other)
  668. rfs = other->rfs;
  669. if ((rfs == 256 || rfs == 512) && (blc == 24)) {
  670. dev_err(&i2s->pdev->dev,
  671. "%d-RFS not supported for 24-blc\n", rfs);
  672. return -EINVAL;
  673. }
  674. if (!rfs) {
  675. if (bfs == 16 || bfs == 32)
  676. rfs = 256;
  677. else
  678. rfs = 384;
  679. }
  680. /* If already setup and running */
  681. if (any_active(i2s) && (get_rfs(i2s) != rfs || get_bfs(i2s) != bfs)) {
  682. dev_err(&i2s->pdev->dev,
  683. "%s:%d Other DAI busy\n", __func__, __LINE__);
  684. return -EAGAIN;
  685. }
  686. set_bfs(i2s, bfs);
  687. set_rfs(i2s, rfs);
  688. /* Don't bother with PSR in Slave mode */
  689. if (is_slave(i2s))
  690. return 0;
  691. if (!(i2s->quirks & QUIRK_NO_MUXPSR)) {
  692. psr = i2s->rclk_srcrate / i2s->frmclk / rfs;
  693. writel(((psr - 1) << 8) | PSR_PSREN, i2s->addr + I2SPSR);
  694. dev_dbg(&i2s->pdev->dev,
  695. "RCLK_SRC=%luHz PSR=%u, RCLK=%dfs, BCLK=%dfs\n",
  696. i2s->rclk_srcrate, psr, rfs, bfs);
  697. }
  698. return 0;
  699. }
  700. static int i2s_trigger(struct snd_pcm_substream *substream,
  701. int cmd, struct snd_soc_dai *dai)
  702. {
  703. int capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE);
  704. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  705. struct i2s_dai *i2s = to_info(rtd->cpu_dai);
  706. unsigned long flags;
  707. switch (cmd) {
  708. case SNDRV_PCM_TRIGGER_START:
  709. case SNDRV_PCM_TRIGGER_RESUME:
  710. case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  711. local_irq_save(flags);
  712. if (config_setup(i2s)) {
  713. local_irq_restore(flags);
  714. return -EINVAL;
  715. }
  716. if (capture)
  717. i2s_rxctrl(i2s, 1);
  718. else
  719. i2s_txctrl(i2s, 1);
  720. local_irq_restore(flags);
  721. break;
  722. case SNDRV_PCM_TRIGGER_STOP:
  723. case SNDRV_PCM_TRIGGER_SUSPEND:
  724. case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  725. local_irq_save(flags);
  726. if (capture) {
  727. i2s_rxctrl(i2s, 0);
  728. i2s_fifo(i2s, FIC_RXFLUSH);
  729. } else {
  730. i2s_txctrl(i2s, 0);
  731. i2s_fifo(i2s, FIC_TXFLUSH);
  732. }
  733. local_irq_restore(flags);
  734. break;
  735. }
  736. return 0;
  737. }
  738. static int i2s_set_clkdiv(struct snd_soc_dai *dai,
  739. int div_id, int div)
  740. {
  741. struct i2s_dai *i2s = to_info(dai);
  742. struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai;
  743. switch (div_id) {
  744. case SAMSUNG_I2S_DIV_BCLK:
  745. if ((any_active(i2s) && div && (get_bfs(i2s) != div))
  746. || (other && other->bfs && (other->bfs != div))) {
  747. dev_err(&i2s->pdev->dev,
  748. "%s:%d Other DAI busy\n", __func__, __LINE__);
  749. return -EAGAIN;
  750. }
  751. i2s->bfs = div;
  752. break;
  753. default:
  754. dev_err(&i2s->pdev->dev,
  755. "Invalid clock divider(%d)\n", div_id);
  756. return -EINVAL;
  757. }
  758. return 0;
  759. }
  760. static snd_pcm_sframes_t
  761. i2s_delay(struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
  762. {
  763. struct i2s_dai *i2s = to_info(dai);
  764. u32 reg = readl(i2s->addr + I2SFIC);
  765. snd_pcm_sframes_t delay;
  766. if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
  767. delay = FIC_RXCOUNT(reg);
  768. else if (is_secondary(i2s))
  769. delay = FICS_TXCOUNT(readl(i2s->addr + I2SFICS));
  770. else
  771. delay = FIC_TXCOUNT(reg);
  772. return delay;
  773. }
  774. #ifdef CONFIG_PM
  775. static int i2s_suspend(struct snd_soc_dai *dai)
  776. {
  777. struct i2s_dai *i2s = to_info(dai);
  778. if (dai->active) {
  779. i2s->suspend_i2smod = readl(i2s->addr + I2SMOD);
  780. i2s->suspend_i2scon = readl(i2s->addr + I2SCON);
  781. i2s->suspend_i2spsr = readl(i2s->addr + I2SPSR);
  782. }
  783. return 0;
  784. }
  785. static int i2s_resume(struct snd_soc_dai *dai)
  786. {
  787. struct i2s_dai *i2s = to_info(dai);
  788. if (dai->active) {
  789. writel(i2s->suspend_i2scon, i2s->addr + I2SCON);
  790. writel(i2s->suspend_i2smod, i2s->addr + I2SMOD);
  791. writel(i2s->suspend_i2spsr, i2s->addr + I2SPSR);
  792. }
  793. return 0;
  794. }
  795. #else
  796. #define i2s_suspend NULL
  797. #define i2s_resume NULL
  798. #endif
  799. static int samsung_i2s_dai_probe(struct snd_soc_dai *dai)
  800. {
  801. struct i2s_dai *i2s = to_info(dai);
  802. struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai;
  803. if (other && other->clk) /* If this is probe on secondary */
  804. goto probe_exit;
  805. i2s->addr = ioremap(i2s->base, 0x100);
  806. if (i2s->addr == NULL) {
  807. dev_err(&i2s->pdev->dev, "cannot ioremap registers\n");
  808. return -ENXIO;
  809. }
  810. i2s->clk = clk_get(&i2s->pdev->dev, "iis");
  811. if (IS_ERR(i2s->clk)) {
  812. dev_err(&i2s->pdev->dev, "failed to get i2s_clock\n");
  813. iounmap(i2s->addr);
  814. return -ENOENT;
  815. }
  816. clk_prepare_enable(i2s->clk);
  817. if (other) {
  818. other->addr = i2s->addr;
  819. other->clk = i2s->clk;
  820. }
  821. if (i2s->quirks & QUIRK_NEED_RSTCLR)
  822. writel(CON_RSTCLR, i2s->addr + I2SCON);
  823. if (i2s->quirks & QUIRK_SEC_DAI)
  824. idma_reg_addr_init(i2s->addr,
  825. i2s->sec_dai->idma_playback.dma_addr);
  826. probe_exit:
  827. /* Reset any constraint on RFS and BFS */
  828. i2s->rfs = 0;
  829. i2s->bfs = 0;
  830. i2s_txctrl(i2s, 0);
  831. i2s_rxctrl(i2s, 0);
  832. i2s_fifo(i2s, FIC_TXFLUSH);
  833. i2s_fifo(other, FIC_TXFLUSH);
  834. i2s_fifo(i2s, FIC_RXFLUSH);
  835. /* Gate CDCLK by default */
  836. if (!is_opened(other))
  837. i2s_set_sysclk(dai, SAMSUNG_I2S_CDCLK,
  838. 0, SND_SOC_CLOCK_IN);
  839. return 0;
  840. }
  841. static int samsung_i2s_dai_remove(struct snd_soc_dai *dai)
  842. {
  843. struct i2s_dai *i2s = snd_soc_dai_get_drvdata(dai);
  844. struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai;
  845. if (!other || !other->clk) {
  846. if (i2s->quirks & QUIRK_NEED_RSTCLR)
  847. writel(0, i2s->addr + I2SCON);
  848. clk_disable_unprepare(i2s->clk);
  849. clk_put(i2s->clk);
  850. iounmap(i2s->addr);
  851. }
  852. i2s->clk = NULL;
  853. return 0;
  854. }
  855. static const struct snd_soc_dai_ops samsung_i2s_dai_ops = {
  856. .trigger = i2s_trigger,
  857. .hw_params = i2s_hw_params,
  858. .set_fmt = i2s_set_fmt,
  859. .set_clkdiv = i2s_set_clkdiv,
  860. .set_sysclk = i2s_set_sysclk,
  861. .startup = i2s_startup,
  862. .shutdown = i2s_shutdown,
  863. .delay = i2s_delay,
  864. };
  865. static const struct snd_soc_component_driver samsung_i2s_component = {
  866. .name = "samsung-i2s",
  867. };
  868. #define SAMSUNG_I2S_RATES SNDRV_PCM_RATE_8000_96000
  869. #define SAMSUNG_I2S_FMTS (SNDRV_PCM_FMTBIT_S8 | \
  870. SNDRV_PCM_FMTBIT_S16_LE | \
  871. SNDRV_PCM_FMTBIT_S24_LE)
  872. static struct i2s_dai *i2s_alloc_dai(struct platform_device *pdev, bool sec)
  873. {
  874. struct i2s_dai *i2s;
  875. int ret;
  876. i2s = devm_kzalloc(&pdev->dev, sizeof(struct i2s_dai), GFP_KERNEL);
  877. if (i2s == NULL)
  878. return NULL;
  879. i2s->pdev = pdev;
  880. i2s->pri_dai = NULL;
  881. i2s->sec_dai = NULL;
  882. i2s->i2s_dai_drv.symmetric_rates = 1;
  883. i2s->i2s_dai_drv.probe = samsung_i2s_dai_probe;
  884. i2s->i2s_dai_drv.remove = samsung_i2s_dai_remove;
  885. i2s->i2s_dai_drv.ops = &samsung_i2s_dai_ops;
  886. i2s->i2s_dai_drv.suspend = i2s_suspend;
  887. i2s->i2s_dai_drv.resume = i2s_resume;
  888. i2s->i2s_dai_drv.playback.channels_min = 2;
  889. i2s->i2s_dai_drv.playback.channels_max = 2;
  890. i2s->i2s_dai_drv.playback.rates = SAMSUNG_I2S_RATES;
  891. i2s->i2s_dai_drv.playback.formats = SAMSUNG_I2S_FMTS;
  892. if (!sec) {
  893. i2s->i2s_dai_drv.capture.channels_min = 1;
  894. i2s->i2s_dai_drv.capture.channels_max = 2;
  895. i2s->i2s_dai_drv.capture.rates = SAMSUNG_I2S_RATES;
  896. i2s->i2s_dai_drv.capture.formats = SAMSUNG_I2S_FMTS;
  897. dev_set_drvdata(&i2s->pdev->dev, i2s);
  898. } else { /* Create a new platform_device for Secondary */
  899. i2s->pdev = platform_device_alloc("samsung-i2s-sec", -1);
  900. if (IS_ERR(i2s->pdev))
  901. return NULL;
  902. i2s->pdev->dev.parent = &pdev->dev;
  903. platform_set_drvdata(i2s->pdev, i2s);
  904. ret = platform_device_add(i2s->pdev);
  905. if (ret < 0)
  906. return NULL;
  907. }
  908. return i2s;
  909. }
  910. static const struct of_device_id exynos_i2s_match[];
  911. static inline const struct samsung_i2s_dai_data *samsung_i2s_get_driver_data(
  912. struct platform_device *pdev)
  913. {
  914. #ifdef CONFIG_OF
  915. if (pdev->dev.of_node) {
  916. const struct of_device_id *match;
  917. match = of_match_node(exynos_i2s_match, pdev->dev.of_node);
  918. return match->data;
  919. } else
  920. #endif
  921. return (struct samsung_i2s_dai_data *)
  922. platform_get_device_id(pdev)->driver_data;
  923. }
  924. #ifdef CONFIG_PM_RUNTIME
  925. static int i2s_runtime_suspend(struct device *dev)
  926. {
  927. struct i2s_dai *i2s = dev_get_drvdata(dev);
  928. clk_disable_unprepare(i2s->clk);
  929. return 0;
  930. }
  931. static int i2s_runtime_resume(struct device *dev)
  932. {
  933. struct i2s_dai *i2s = dev_get_drvdata(dev);
  934. clk_prepare_enable(i2s->clk);
  935. return 0;
  936. }
  937. #endif /* CONFIG_PM_RUNTIME */
  938. static int samsung_i2s_probe(struct platform_device *pdev)
  939. {
  940. struct i2s_dai *pri_dai, *sec_dai = NULL;
  941. struct s3c_audio_pdata *i2s_pdata = pdev->dev.platform_data;
  942. struct samsung_i2s *i2s_cfg = NULL;
  943. struct resource *res;
  944. u32 regs_base, quirks = 0, idma_addr = 0;
  945. struct device_node *np = pdev->dev.of_node;
  946. const struct samsung_i2s_dai_data *i2s_dai_data;
  947. int ret = 0;
  948. /* Call during Seconday interface registration */
  949. i2s_dai_data = samsung_i2s_get_driver_data(pdev);
  950. if (i2s_dai_data->dai_type == TYPE_SEC) {
  951. sec_dai = dev_get_drvdata(&pdev->dev);
  952. if (!sec_dai) {
  953. dev_err(&pdev->dev, "Unable to get drvdata\n");
  954. return -EFAULT;
  955. }
  956. snd_soc_register_component(&sec_dai->pdev->dev,
  957. &samsung_i2s_component,
  958. &sec_dai->i2s_dai_drv, 1);
  959. samsung_asoc_dma_platform_register(&pdev->dev);
  960. return 0;
  961. }
  962. pri_dai = i2s_alloc_dai(pdev, false);
  963. if (!pri_dai) {
  964. dev_err(&pdev->dev, "Unable to alloc I2S_pri\n");
  965. return -ENOMEM;
  966. }
  967. if (!np) {
  968. res = platform_get_resource(pdev, IORESOURCE_DMA, 0);
  969. if (!res) {
  970. dev_err(&pdev->dev,
  971. "Unable to get I2S-TX dma resource\n");
  972. return -ENXIO;
  973. }
  974. pri_dai->dma_playback.channel = res->start;
  975. res = platform_get_resource(pdev, IORESOURCE_DMA, 1);
  976. if (!res) {
  977. dev_err(&pdev->dev,
  978. "Unable to get I2S-RX dma resource\n");
  979. return -ENXIO;
  980. }
  981. pri_dai->dma_capture.channel = res->start;
  982. if (i2s_pdata == NULL) {
  983. dev_err(&pdev->dev, "Can't work without s3c_audio_pdata\n");
  984. return -EINVAL;
  985. }
  986. if (&i2s_pdata->type)
  987. i2s_cfg = &i2s_pdata->type.i2s;
  988. if (i2s_cfg) {
  989. quirks = i2s_cfg->quirks;
  990. idma_addr = i2s_cfg->idma_addr;
  991. }
  992. } else {
  993. quirks = i2s_dai_data->quirks;
  994. if (of_property_read_u32(np, "samsung,idma-addr",
  995. &idma_addr)) {
  996. if (quirks & QUIRK_SEC_DAI) {
  997. dev_err(&pdev->dev, "idma address is not"\
  998. "specified");
  999. return -EINVAL;
  1000. }
  1001. }
  1002. }
  1003. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1004. if (!res) {
  1005. dev_err(&pdev->dev, "Unable to get I2S SFR address\n");
  1006. return -ENXIO;
  1007. }
  1008. if (!request_mem_region(res->start, resource_size(res),
  1009. "samsung-i2s")) {
  1010. dev_err(&pdev->dev, "Unable to request SFR region\n");
  1011. return -EBUSY;
  1012. }
  1013. regs_base = res->start;
  1014. pri_dai->dma_playback.dma_addr = regs_base + I2STXD;
  1015. pri_dai->dma_capture.dma_addr = regs_base + I2SRXD;
  1016. pri_dai->dma_playback.client =
  1017. (struct s3c2410_dma_client *)&pri_dai->dma_playback;
  1018. pri_dai->dma_playback.ch_name = "tx";
  1019. pri_dai->dma_capture.client =
  1020. (struct s3c2410_dma_client *)&pri_dai->dma_capture;
  1021. pri_dai->dma_capture.ch_name = "rx";
  1022. pri_dai->dma_playback.dma_size = 4;
  1023. pri_dai->dma_capture.dma_size = 4;
  1024. pri_dai->base = regs_base;
  1025. pri_dai->quirks = quirks;
  1026. if (quirks & QUIRK_PRI_6CHAN)
  1027. pri_dai->i2s_dai_drv.playback.channels_max = 6;
  1028. if (quirks & QUIRK_SEC_DAI) {
  1029. sec_dai = i2s_alloc_dai(pdev, true);
  1030. if (!sec_dai) {
  1031. dev_err(&pdev->dev, "Unable to alloc I2S_sec\n");
  1032. ret = -ENOMEM;
  1033. goto err;
  1034. }
  1035. sec_dai->dma_playback.dma_addr = regs_base + I2STXDS;
  1036. sec_dai->dma_playback.client =
  1037. (struct s3c2410_dma_client *)&sec_dai->dma_playback;
  1038. sec_dai->dma_playback.ch_name = "tx-sec";
  1039. if (!np) {
  1040. res = platform_get_resource(pdev, IORESOURCE_DMA, 2);
  1041. if (res)
  1042. sec_dai->dma_playback.channel = res->start;
  1043. }
  1044. sec_dai->dma_playback.dma_size = 4;
  1045. sec_dai->base = regs_base;
  1046. sec_dai->quirks = quirks;
  1047. sec_dai->idma_playback.dma_addr = idma_addr;
  1048. sec_dai->pri_dai = pri_dai;
  1049. pri_dai->sec_dai = sec_dai;
  1050. }
  1051. if (i2s_pdata && i2s_pdata->cfg_gpio && i2s_pdata->cfg_gpio(pdev)) {
  1052. dev_err(&pdev->dev, "Unable to configure gpio\n");
  1053. ret = -EINVAL;
  1054. goto err;
  1055. }
  1056. snd_soc_register_component(&pri_dai->pdev->dev, &samsung_i2s_component,
  1057. &pri_dai->i2s_dai_drv, 1);
  1058. pm_runtime_enable(&pdev->dev);
  1059. samsung_asoc_dma_platform_register(&pdev->dev);
  1060. return 0;
  1061. err:
  1062. release_mem_region(regs_base, resource_size(res));
  1063. return ret;
  1064. }
  1065. static int samsung_i2s_remove(struct platform_device *pdev)
  1066. {
  1067. struct i2s_dai *i2s, *other;
  1068. struct resource *res;
  1069. i2s = dev_get_drvdata(&pdev->dev);
  1070. other = i2s->pri_dai ? : i2s->sec_dai;
  1071. if (other) {
  1072. other->pri_dai = NULL;
  1073. other->sec_dai = NULL;
  1074. } else {
  1075. pm_runtime_disable(&pdev->dev);
  1076. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1077. if (res)
  1078. release_mem_region(res->start, resource_size(res));
  1079. }
  1080. i2s->pri_dai = NULL;
  1081. i2s->sec_dai = NULL;
  1082. samsung_asoc_dma_platform_unregister(&pdev->dev);
  1083. snd_soc_unregister_component(&pdev->dev);
  1084. return 0;
  1085. }
  1086. static const struct samsung_i2s_dai_data i2sv3_dai_type = {
  1087. .dai_type = TYPE_PRI,
  1088. .quirks = QUIRK_NO_MUXPSR,
  1089. };
  1090. static const struct samsung_i2s_dai_data i2sv5_dai_type = {
  1091. .dai_type = TYPE_PRI,
  1092. .quirks = QUIRK_PRI_6CHAN | QUIRK_SEC_DAI | QUIRK_NEED_RSTCLR,
  1093. };
  1094. static const struct samsung_i2s_dai_data i2sv6_dai_type = {
  1095. .dai_type = TYPE_PRI,
  1096. .quirks = QUIRK_PRI_6CHAN | QUIRK_SEC_DAI | QUIRK_NEED_RSTCLR |
  1097. QUIRK_SUPPORTS_TDM,
  1098. };
  1099. static const struct samsung_i2s_dai_data samsung_dai_type_pri = {
  1100. .dai_type = TYPE_PRI,
  1101. };
  1102. static const struct samsung_i2s_dai_data samsung_dai_type_sec = {
  1103. .dai_type = TYPE_SEC,
  1104. };
  1105. static struct platform_device_id samsung_i2s_driver_ids[] = {
  1106. {
  1107. .name = "samsung-i2s",
  1108. .driver_data = (kernel_ulong_t)&samsung_dai_type_pri,
  1109. }, {
  1110. .name = "samsung-i2s-sec",
  1111. .driver_data = (kernel_ulong_t)&samsung_dai_type_sec,
  1112. },
  1113. {},
  1114. };
  1115. MODULE_DEVICE_TABLE(platform, samsung_i2s_driver_ids);
  1116. #ifdef CONFIG_OF
  1117. static const struct of_device_id exynos_i2s_match[] = {
  1118. {
  1119. .compatible = "samsung,s3c6410-i2s",
  1120. .data = &i2sv3_dai_type,
  1121. }, {
  1122. .compatible = "samsung,s5pv210-i2s",
  1123. .data = &i2sv5_dai_type,
  1124. }, {
  1125. .compatible = "samsung,exynos5420-i2s",
  1126. .data = &i2sv6_dai_type,
  1127. },
  1128. {},
  1129. };
  1130. MODULE_DEVICE_TABLE(of, exynos_i2s_match);
  1131. #endif
  1132. static const struct dev_pm_ops samsung_i2s_pm = {
  1133. SET_RUNTIME_PM_OPS(i2s_runtime_suspend,
  1134. i2s_runtime_resume, NULL)
  1135. };
  1136. static struct platform_driver samsung_i2s_driver = {
  1137. .probe = samsung_i2s_probe,
  1138. .remove = samsung_i2s_remove,
  1139. .id_table = samsung_i2s_driver_ids,
  1140. .driver = {
  1141. .name = "samsung-i2s",
  1142. .owner = THIS_MODULE,
  1143. .of_match_table = of_match_ptr(exynos_i2s_match),
  1144. .pm = &samsung_i2s_pm,
  1145. },
  1146. };
  1147. module_platform_driver(samsung_i2s_driver);
  1148. /* Module information */
  1149. MODULE_AUTHOR("Jaswinder Singh, <jassisinghbrar@gmail.com>");
  1150. MODULE_DESCRIPTION("Samsung I2S Interface");
  1151. MODULE_ALIAS("platform:samsung-i2s");
  1152. MODULE_LICENSE("GPL");