i2s.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373
  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. i2s->frmclk = params_rate(params);
  606. return 0;
  607. }
  608. /* We set constraints on the substream acc to the version of I2S */
  609. static int i2s_startup(struct snd_pcm_substream *substream,
  610. struct snd_soc_dai *dai)
  611. {
  612. struct i2s_dai *i2s = to_info(dai);
  613. struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai;
  614. unsigned long flags;
  615. spin_lock_irqsave(&lock, flags);
  616. i2s->mode |= DAI_OPENED;
  617. if (is_manager(other))
  618. i2s->mode &= ~DAI_MANAGER;
  619. else
  620. i2s->mode |= DAI_MANAGER;
  621. /* Enforce set_sysclk in Master mode */
  622. i2s->rclk_srcrate = 0;
  623. if (!any_active(i2s) && (i2s->quirks & QUIRK_NEED_RSTCLR))
  624. writel(CON_RSTCLR, i2s->addr + I2SCON);
  625. spin_unlock_irqrestore(&lock, flags);
  626. return 0;
  627. }
  628. static void i2s_shutdown(struct snd_pcm_substream *substream,
  629. struct snd_soc_dai *dai)
  630. {
  631. struct i2s_dai *i2s = to_info(dai);
  632. struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai;
  633. unsigned long flags;
  634. spin_lock_irqsave(&lock, flags);
  635. i2s->mode &= ~DAI_OPENED;
  636. i2s->mode &= ~DAI_MANAGER;
  637. if (is_opened(other))
  638. other->mode |= DAI_MANAGER;
  639. /* Reset any constraint on RFS and BFS */
  640. i2s->rfs = 0;
  641. i2s->bfs = 0;
  642. spin_unlock_irqrestore(&lock, flags);
  643. /* Gate CDCLK by default */
  644. if (!is_opened(other))
  645. i2s_set_sysclk(dai, SAMSUNG_I2S_CDCLK,
  646. 0, SND_SOC_CLOCK_IN);
  647. }
  648. static int config_setup(struct i2s_dai *i2s)
  649. {
  650. struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai;
  651. unsigned rfs, bfs, blc;
  652. u32 psr;
  653. blc = get_blc(i2s);
  654. bfs = i2s->bfs;
  655. if (!bfs && other)
  656. bfs = other->bfs;
  657. /* Select least possible multiple(2) if no constraint set */
  658. if (!bfs)
  659. bfs = blc * 2;
  660. rfs = i2s->rfs;
  661. if (!rfs && other)
  662. rfs = other->rfs;
  663. if ((rfs == 256 || rfs == 512) && (blc == 24)) {
  664. dev_err(&i2s->pdev->dev,
  665. "%d-RFS not supported for 24-blc\n", rfs);
  666. return -EINVAL;
  667. }
  668. if (!rfs) {
  669. if (bfs == 16 || bfs == 32)
  670. rfs = 256;
  671. else
  672. rfs = 384;
  673. }
  674. /* If already setup and running */
  675. if (any_active(i2s) && (get_rfs(i2s) != rfs || get_bfs(i2s) != bfs)) {
  676. dev_err(&i2s->pdev->dev,
  677. "%s:%d Other DAI busy\n", __func__, __LINE__);
  678. return -EAGAIN;
  679. }
  680. set_bfs(i2s, bfs);
  681. set_rfs(i2s, rfs);
  682. /* Don't bother with PSR in Slave mode */
  683. if (is_slave(i2s))
  684. return 0;
  685. if (!(i2s->quirks & QUIRK_NO_MUXPSR)) {
  686. psr = i2s->rclk_srcrate / i2s->frmclk / rfs;
  687. writel(((psr - 1) << 8) | PSR_PSREN, i2s->addr + I2SPSR);
  688. dev_dbg(&i2s->pdev->dev,
  689. "RCLK_SRC=%luHz PSR=%u, RCLK=%dfs, BCLK=%dfs\n",
  690. i2s->rclk_srcrate, psr, rfs, bfs);
  691. }
  692. return 0;
  693. }
  694. static int i2s_trigger(struct snd_pcm_substream *substream,
  695. int cmd, struct snd_soc_dai *dai)
  696. {
  697. int capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE);
  698. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  699. struct i2s_dai *i2s = to_info(rtd->cpu_dai);
  700. unsigned long flags;
  701. switch (cmd) {
  702. case SNDRV_PCM_TRIGGER_START:
  703. case SNDRV_PCM_TRIGGER_RESUME:
  704. case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  705. local_irq_save(flags);
  706. if (config_setup(i2s)) {
  707. local_irq_restore(flags);
  708. return -EINVAL;
  709. }
  710. if (capture)
  711. i2s_rxctrl(i2s, 1);
  712. else
  713. i2s_txctrl(i2s, 1);
  714. local_irq_restore(flags);
  715. break;
  716. case SNDRV_PCM_TRIGGER_STOP:
  717. case SNDRV_PCM_TRIGGER_SUSPEND:
  718. case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  719. local_irq_save(flags);
  720. if (capture) {
  721. i2s_rxctrl(i2s, 0);
  722. i2s_fifo(i2s, FIC_RXFLUSH);
  723. } else {
  724. i2s_txctrl(i2s, 0);
  725. i2s_fifo(i2s, FIC_TXFLUSH);
  726. }
  727. local_irq_restore(flags);
  728. break;
  729. }
  730. return 0;
  731. }
  732. static int i2s_set_clkdiv(struct snd_soc_dai *dai,
  733. int div_id, int div)
  734. {
  735. struct i2s_dai *i2s = to_info(dai);
  736. struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai;
  737. switch (div_id) {
  738. case SAMSUNG_I2S_DIV_BCLK:
  739. if ((any_active(i2s) && div && (get_bfs(i2s) != div))
  740. || (other && other->bfs && (other->bfs != div))) {
  741. dev_err(&i2s->pdev->dev,
  742. "%s:%d Other DAI busy\n", __func__, __LINE__);
  743. return -EAGAIN;
  744. }
  745. i2s->bfs = div;
  746. break;
  747. default:
  748. dev_err(&i2s->pdev->dev,
  749. "Invalid clock divider(%d)\n", div_id);
  750. return -EINVAL;
  751. }
  752. return 0;
  753. }
  754. static snd_pcm_sframes_t
  755. i2s_delay(struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
  756. {
  757. struct i2s_dai *i2s = to_info(dai);
  758. u32 reg = readl(i2s->addr + I2SFIC);
  759. snd_pcm_sframes_t delay;
  760. if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
  761. delay = FIC_RXCOUNT(reg);
  762. else if (is_secondary(i2s))
  763. delay = FICS_TXCOUNT(readl(i2s->addr + I2SFICS));
  764. else
  765. delay = FIC_TXCOUNT(reg);
  766. return delay;
  767. }
  768. #ifdef CONFIG_PM
  769. static int i2s_suspend(struct snd_soc_dai *dai)
  770. {
  771. struct i2s_dai *i2s = to_info(dai);
  772. if (dai->active) {
  773. i2s->suspend_i2smod = readl(i2s->addr + I2SMOD);
  774. i2s->suspend_i2scon = readl(i2s->addr + I2SCON);
  775. i2s->suspend_i2spsr = readl(i2s->addr + I2SPSR);
  776. }
  777. return 0;
  778. }
  779. static int i2s_resume(struct snd_soc_dai *dai)
  780. {
  781. struct i2s_dai *i2s = to_info(dai);
  782. if (dai->active) {
  783. writel(i2s->suspend_i2scon, i2s->addr + I2SCON);
  784. writel(i2s->suspend_i2smod, i2s->addr + I2SMOD);
  785. writel(i2s->suspend_i2spsr, i2s->addr + I2SPSR);
  786. }
  787. return 0;
  788. }
  789. #else
  790. #define i2s_suspend NULL
  791. #define i2s_resume NULL
  792. #endif
  793. static int samsung_i2s_dai_probe(struct snd_soc_dai *dai)
  794. {
  795. struct i2s_dai *i2s = to_info(dai);
  796. struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai;
  797. if (other && other->clk) /* If this is probe on secondary */
  798. goto probe_exit;
  799. i2s->addr = ioremap(i2s->base, 0x100);
  800. if (i2s->addr == NULL) {
  801. dev_err(&i2s->pdev->dev, "cannot ioremap registers\n");
  802. return -ENXIO;
  803. }
  804. i2s->clk = clk_get(&i2s->pdev->dev, "iis");
  805. if (IS_ERR(i2s->clk)) {
  806. dev_err(&i2s->pdev->dev, "failed to get i2s_clock\n");
  807. iounmap(i2s->addr);
  808. return -ENOENT;
  809. }
  810. clk_prepare_enable(i2s->clk);
  811. snd_soc_dai_init_dma_data(dai, &i2s->dma_playback, &i2s->dma_capture);
  812. if (other) {
  813. other->addr = i2s->addr;
  814. other->clk = i2s->clk;
  815. }
  816. if (i2s->quirks & QUIRK_NEED_RSTCLR)
  817. writel(CON_RSTCLR, i2s->addr + I2SCON);
  818. if (i2s->quirks & QUIRK_SEC_DAI)
  819. idma_reg_addr_init(i2s->addr,
  820. i2s->sec_dai->idma_playback.dma_addr);
  821. probe_exit:
  822. /* Reset any constraint on RFS and BFS */
  823. i2s->rfs = 0;
  824. i2s->bfs = 0;
  825. i2s_txctrl(i2s, 0);
  826. i2s_rxctrl(i2s, 0);
  827. i2s_fifo(i2s, FIC_TXFLUSH);
  828. i2s_fifo(other, FIC_TXFLUSH);
  829. i2s_fifo(i2s, FIC_RXFLUSH);
  830. /* Gate CDCLK by default */
  831. if (!is_opened(other))
  832. i2s_set_sysclk(dai, SAMSUNG_I2S_CDCLK,
  833. 0, SND_SOC_CLOCK_IN);
  834. return 0;
  835. }
  836. static int samsung_i2s_dai_remove(struct snd_soc_dai *dai)
  837. {
  838. struct i2s_dai *i2s = snd_soc_dai_get_drvdata(dai);
  839. struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai;
  840. if (!other || !other->clk) {
  841. if (i2s->quirks & QUIRK_NEED_RSTCLR)
  842. writel(0, i2s->addr + I2SCON);
  843. clk_disable_unprepare(i2s->clk);
  844. clk_put(i2s->clk);
  845. iounmap(i2s->addr);
  846. }
  847. i2s->clk = NULL;
  848. return 0;
  849. }
  850. static const struct snd_soc_dai_ops samsung_i2s_dai_ops = {
  851. .trigger = i2s_trigger,
  852. .hw_params = i2s_hw_params,
  853. .set_fmt = i2s_set_fmt,
  854. .set_clkdiv = i2s_set_clkdiv,
  855. .set_sysclk = i2s_set_sysclk,
  856. .startup = i2s_startup,
  857. .shutdown = i2s_shutdown,
  858. .delay = i2s_delay,
  859. };
  860. static const struct snd_soc_component_driver samsung_i2s_component = {
  861. .name = "samsung-i2s",
  862. };
  863. #define SAMSUNG_I2S_RATES SNDRV_PCM_RATE_8000_96000
  864. #define SAMSUNG_I2S_FMTS (SNDRV_PCM_FMTBIT_S8 | \
  865. SNDRV_PCM_FMTBIT_S16_LE | \
  866. SNDRV_PCM_FMTBIT_S24_LE)
  867. static struct i2s_dai *i2s_alloc_dai(struct platform_device *pdev, bool sec)
  868. {
  869. struct i2s_dai *i2s;
  870. int ret;
  871. i2s = devm_kzalloc(&pdev->dev, sizeof(struct i2s_dai), GFP_KERNEL);
  872. if (i2s == NULL)
  873. return NULL;
  874. i2s->pdev = pdev;
  875. i2s->pri_dai = NULL;
  876. i2s->sec_dai = NULL;
  877. i2s->i2s_dai_drv.symmetric_rates = 1;
  878. i2s->i2s_dai_drv.probe = samsung_i2s_dai_probe;
  879. i2s->i2s_dai_drv.remove = samsung_i2s_dai_remove;
  880. i2s->i2s_dai_drv.ops = &samsung_i2s_dai_ops;
  881. i2s->i2s_dai_drv.suspend = i2s_suspend;
  882. i2s->i2s_dai_drv.resume = i2s_resume;
  883. i2s->i2s_dai_drv.playback.channels_min = 1;
  884. i2s->i2s_dai_drv.playback.channels_max = 2;
  885. i2s->i2s_dai_drv.playback.rates = SAMSUNG_I2S_RATES;
  886. i2s->i2s_dai_drv.playback.formats = SAMSUNG_I2S_FMTS;
  887. if (!sec) {
  888. i2s->i2s_dai_drv.capture.channels_min = 1;
  889. i2s->i2s_dai_drv.capture.channels_max = 2;
  890. i2s->i2s_dai_drv.capture.rates = SAMSUNG_I2S_RATES;
  891. i2s->i2s_dai_drv.capture.formats = SAMSUNG_I2S_FMTS;
  892. dev_set_drvdata(&i2s->pdev->dev, i2s);
  893. } else { /* Create a new platform_device for Secondary */
  894. i2s->pdev = platform_device_alloc("samsung-i2s-sec", -1);
  895. if (!i2s->pdev)
  896. return NULL;
  897. i2s->pdev->dev.parent = &pdev->dev;
  898. platform_set_drvdata(i2s->pdev, i2s);
  899. ret = platform_device_add(i2s->pdev);
  900. if (ret < 0)
  901. return NULL;
  902. }
  903. return i2s;
  904. }
  905. static const struct of_device_id exynos_i2s_match[];
  906. static inline const struct samsung_i2s_dai_data *samsung_i2s_get_driver_data(
  907. struct platform_device *pdev)
  908. {
  909. #ifdef CONFIG_OF
  910. if (pdev->dev.of_node) {
  911. const struct of_device_id *match;
  912. match = of_match_node(exynos_i2s_match, pdev->dev.of_node);
  913. return match->data;
  914. } else
  915. #endif
  916. return (struct samsung_i2s_dai_data *)
  917. platform_get_device_id(pdev)->driver_data;
  918. }
  919. #ifdef CONFIG_PM_RUNTIME
  920. static int i2s_runtime_suspend(struct device *dev)
  921. {
  922. struct i2s_dai *i2s = dev_get_drvdata(dev);
  923. clk_disable_unprepare(i2s->clk);
  924. return 0;
  925. }
  926. static int i2s_runtime_resume(struct device *dev)
  927. {
  928. struct i2s_dai *i2s = dev_get_drvdata(dev);
  929. clk_prepare_enable(i2s->clk);
  930. return 0;
  931. }
  932. #endif /* CONFIG_PM_RUNTIME */
  933. static int samsung_i2s_probe(struct platform_device *pdev)
  934. {
  935. struct i2s_dai *pri_dai, *sec_dai = NULL;
  936. struct s3c_audio_pdata *i2s_pdata = pdev->dev.platform_data;
  937. struct samsung_i2s *i2s_cfg = NULL;
  938. struct resource *res;
  939. u32 regs_base, quirks = 0, idma_addr = 0;
  940. struct device_node *np = pdev->dev.of_node;
  941. const struct samsung_i2s_dai_data *i2s_dai_data;
  942. int ret = 0;
  943. /* Call during Seconday interface registration */
  944. i2s_dai_data = samsung_i2s_get_driver_data(pdev);
  945. if (i2s_dai_data->dai_type == TYPE_SEC) {
  946. sec_dai = dev_get_drvdata(&pdev->dev);
  947. if (!sec_dai) {
  948. dev_err(&pdev->dev, "Unable to get drvdata\n");
  949. return -EFAULT;
  950. }
  951. devm_snd_soc_register_component(&sec_dai->pdev->dev,
  952. &samsung_i2s_component,
  953. &sec_dai->i2s_dai_drv, 1);
  954. samsung_asoc_dma_platform_register(&pdev->dev);
  955. return 0;
  956. }
  957. pri_dai = i2s_alloc_dai(pdev, false);
  958. if (!pri_dai) {
  959. dev_err(&pdev->dev, "Unable to alloc I2S_pri\n");
  960. return -ENOMEM;
  961. }
  962. if (!np) {
  963. res = platform_get_resource(pdev, IORESOURCE_DMA, 0);
  964. if (!res) {
  965. dev_err(&pdev->dev,
  966. "Unable to get I2S-TX dma resource\n");
  967. return -ENXIO;
  968. }
  969. pri_dai->dma_playback.channel = res->start;
  970. res = platform_get_resource(pdev, IORESOURCE_DMA, 1);
  971. if (!res) {
  972. dev_err(&pdev->dev,
  973. "Unable to get I2S-RX dma resource\n");
  974. return -ENXIO;
  975. }
  976. pri_dai->dma_capture.channel = res->start;
  977. if (i2s_pdata == NULL) {
  978. dev_err(&pdev->dev, "Can't work without s3c_audio_pdata\n");
  979. return -EINVAL;
  980. }
  981. if (&i2s_pdata->type)
  982. i2s_cfg = &i2s_pdata->type.i2s;
  983. if (i2s_cfg) {
  984. quirks = i2s_cfg->quirks;
  985. idma_addr = i2s_cfg->idma_addr;
  986. }
  987. } else {
  988. quirks = i2s_dai_data->quirks;
  989. if (of_property_read_u32(np, "samsung,idma-addr",
  990. &idma_addr)) {
  991. if (quirks & QUIRK_SEC_DAI) {
  992. dev_err(&pdev->dev, "idma address is not"\
  993. "specified");
  994. return -EINVAL;
  995. }
  996. }
  997. }
  998. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  999. if (!res) {
  1000. dev_err(&pdev->dev, "Unable to get I2S SFR address\n");
  1001. return -ENXIO;
  1002. }
  1003. if (!request_mem_region(res->start, resource_size(res),
  1004. "samsung-i2s")) {
  1005. dev_err(&pdev->dev, "Unable to request SFR region\n");
  1006. return -EBUSY;
  1007. }
  1008. regs_base = res->start;
  1009. pri_dai->dma_playback.dma_addr = regs_base + I2STXD;
  1010. pri_dai->dma_capture.dma_addr = regs_base + I2SRXD;
  1011. pri_dai->dma_playback.client =
  1012. (struct s3c2410_dma_client *)&pri_dai->dma_playback;
  1013. pri_dai->dma_playback.ch_name = "tx";
  1014. pri_dai->dma_capture.client =
  1015. (struct s3c2410_dma_client *)&pri_dai->dma_capture;
  1016. pri_dai->dma_capture.ch_name = "rx";
  1017. pri_dai->dma_playback.dma_size = 4;
  1018. pri_dai->dma_capture.dma_size = 4;
  1019. pri_dai->base = regs_base;
  1020. pri_dai->quirks = quirks;
  1021. if (quirks & QUIRK_PRI_6CHAN)
  1022. pri_dai->i2s_dai_drv.playback.channels_max = 6;
  1023. if (quirks & QUIRK_SEC_DAI) {
  1024. sec_dai = i2s_alloc_dai(pdev, true);
  1025. if (!sec_dai) {
  1026. dev_err(&pdev->dev, "Unable to alloc I2S_sec\n");
  1027. ret = -ENOMEM;
  1028. goto err;
  1029. }
  1030. sec_dai->dma_playback.dma_addr = regs_base + I2STXDS;
  1031. sec_dai->dma_playback.client =
  1032. (struct s3c2410_dma_client *)&sec_dai->dma_playback;
  1033. sec_dai->dma_playback.ch_name = "tx-sec";
  1034. if (!np) {
  1035. res = platform_get_resource(pdev, IORESOURCE_DMA, 2);
  1036. if (res)
  1037. sec_dai->dma_playback.channel = res->start;
  1038. }
  1039. sec_dai->dma_playback.dma_size = 4;
  1040. sec_dai->base = regs_base;
  1041. sec_dai->quirks = quirks;
  1042. sec_dai->idma_playback.dma_addr = idma_addr;
  1043. sec_dai->pri_dai = pri_dai;
  1044. pri_dai->sec_dai = sec_dai;
  1045. }
  1046. if (i2s_pdata && i2s_pdata->cfg_gpio && i2s_pdata->cfg_gpio(pdev)) {
  1047. dev_err(&pdev->dev, "Unable to configure gpio\n");
  1048. ret = -EINVAL;
  1049. goto err;
  1050. }
  1051. devm_snd_soc_register_component(&pri_dai->pdev->dev,
  1052. &samsung_i2s_component,
  1053. &pri_dai->i2s_dai_drv, 1);
  1054. pm_runtime_enable(&pdev->dev);
  1055. samsung_asoc_dma_platform_register(&pdev->dev);
  1056. return 0;
  1057. err:
  1058. release_mem_region(regs_base, resource_size(res));
  1059. return ret;
  1060. }
  1061. static int samsung_i2s_remove(struct platform_device *pdev)
  1062. {
  1063. struct i2s_dai *i2s, *other;
  1064. struct resource *res;
  1065. i2s = dev_get_drvdata(&pdev->dev);
  1066. other = i2s->pri_dai ? : i2s->sec_dai;
  1067. if (other) {
  1068. other->pri_dai = NULL;
  1069. other->sec_dai = NULL;
  1070. } else {
  1071. pm_runtime_disable(&pdev->dev);
  1072. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1073. if (res)
  1074. release_mem_region(res->start, resource_size(res));
  1075. }
  1076. i2s->pri_dai = NULL;
  1077. i2s->sec_dai = NULL;
  1078. samsung_asoc_dma_platform_unregister(&pdev->dev);
  1079. return 0;
  1080. }
  1081. static const struct samsung_i2s_dai_data i2sv3_dai_type = {
  1082. .dai_type = TYPE_PRI,
  1083. .quirks = QUIRK_NO_MUXPSR,
  1084. };
  1085. static const struct samsung_i2s_dai_data i2sv5_dai_type = {
  1086. .dai_type = TYPE_PRI,
  1087. .quirks = QUIRK_PRI_6CHAN | QUIRK_SEC_DAI | QUIRK_NEED_RSTCLR,
  1088. };
  1089. static const struct samsung_i2s_dai_data i2sv6_dai_type = {
  1090. .dai_type = TYPE_PRI,
  1091. .quirks = QUIRK_PRI_6CHAN | QUIRK_SEC_DAI | QUIRK_NEED_RSTCLR |
  1092. QUIRK_SUPPORTS_TDM,
  1093. };
  1094. static const struct samsung_i2s_dai_data samsung_dai_type_pri = {
  1095. .dai_type = TYPE_PRI,
  1096. };
  1097. static const struct samsung_i2s_dai_data samsung_dai_type_sec = {
  1098. .dai_type = TYPE_SEC,
  1099. };
  1100. static struct platform_device_id samsung_i2s_driver_ids[] = {
  1101. {
  1102. .name = "samsung-i2s",
  1103. .driver_data = (kernel_ulong_t)&samsung_dai_type_pri,
  1104. }, {
  1105. .name = "samsung-i2s-sec",
  1106. .driver_data = (kernel_ulong_t)&samsung_dai_type_sec,
  1107. },
  1108. {},
  1109. };
  1110. MODULE_DEVICE_TABLE(platform, samsung_i2s_driver_ids);
  1111. #ifdef CONFIG_OF
  1112. static const struct of_device_id exynos_i2s_match[] = {
  1113. {
  1114. .compatible = "samsung,s3c6410-i2s",
  1115. .data = &i2sv3_dai_type,
  1116. }, {
  1117. .compatible = "samsung,s5pv210-i2s",
  1118. .data = &i2sv5_dai_type,
  1119. }, {
  1120. .compatible = "samsung,exynos5420-i2s",
  1121. .data = &i2sv6_dai_type,
  1122. },
  1123. {},
  1124. };
  1125. MODULE_DEVICE_TABLE(of, exynos_i2s_match);
  1126. #endif
  1127. static const struct dev_pm_ops samsung_i2s_pm = {
  1128. SET_RUNTIME_PM_OPS(i2s_runtime_suspend,
  1129. i2s_runtime_resume, NULL)
  1130. };
  1131. static struct platform_driver samsung_i2s_driver = {
  1132. .probe = samsung_i2s_probe,
  1133. .remove = samsung_i2s_remove,
  1134. .id_table = samsung_i2s_driver_ids,
  1135. .driver = {
  1136. .name = "samsung-i2s",
  1137. .owner = THIS_MODULE,
  1138. .of_match_table = of_match_ptr(exynos_i2s_match),
  1139. .pm = &samsung_i2s_pm,
  1140. },
  1141. };
  1142. module_platform_driver(samsung_i2s_driver);
  1143. /* Module information */
  1144. MODULE_AUTHOR("Jaswinder Singh, <jassisinghbrar@gmail.com>");
  1145. MODULE_DESCRIPTION("Samsung I2S Interface");
  1146. MODULE_ALIAS("platform:samsung-i2s");
  1147. MODULE_LICENSE("GPL");