i2s.c 28 KB

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