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