i2s.c 28 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256
  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. return 0;
  446. }
  447. }
  448. i2s->op_clk = clk_get(&i2s->pdev->dev,
  449. i2s->src_clk[clk_id]);
  450. clk_enable(i2s->op_clk);
  451. i2s->rclk_srcrate = clk_get_rate(i2s->op_clk);
  452. /* Over-ride the other's */
  453. if (other) {
  454. other->op_clk = i2s->op_clk;
  455. other->rclk_srcrate = i2s->rclk_srcrate;
  456. }
  457. } else if ((!clk_id && (mod & MOD_IMS_SYSMUX))
  458. || (clk_id && !(mod & MOD_IMS_SYSMUX))) {
  459. dev_err(&i2s->pdev->dev,
  460. "%s:%d Other DAI busy\n", __func__, __LINE__);
  461. return -EAGAIN;
  462. } else {
  463. /* Call can't be on the active DAI */
  464. i2s->op_clk = other->op_clk;
  465. i2s->rclk_srcrate = other->rclk_srcrate;
  466. return 0;
  467. }
  468. if (clk_id == 0)
  469. mod &= ~MOD_IMS_SYSMUX;
  470. else
  471. mod |= MOD_IMS_SYSMUX;
  472. break;
  473. default:
  474. dev_err(&i2s->pdev->dev, "We don't serve that!\n");
  475. return -EINVAL;
  476. }
  477. writel(mod, i2s->addr + I2SMOD);
  478. return 0;
  479. }
  480. static int i2s_set_fmt(struct snd_soc_dai *dai,
  481. unsigned int fmt)
  482. {
  483. struct i2s_dai *i2s = to_info(dai);
  484. u32 mod = readl(i2s->addr + I2SMOD);
  485. u32 tmp = 0;
  486. /* Format is priority */
  487. switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  488. case SND_SOC_DAIFMT_RIGHT_J:
  489. tmp |= MOD_LR_RLOW;
  490. tmp |= MOD_SDF_MSB;
  491. break;
  492. case SND_SOC_DAIFMT_LEFT_J:
  493. tmp |= MOD_LR_RLOW;
  494. tmp |= MOD_SDF_LSB;
  495. break;
  496. case SND_SOC_DAIFMT_I2S:
  497. tmp |= MOD_SDF_IIS;
  498. break;
  499. default:
  500. dev_err(&i2s->pdev->dev, "Format not supported\n");
  501. return -EINVAL;
  502. }
  503. /*
  504. * INV flag is relative to the FORMAT flag - if set it simply
  505. * flips the polarity specified by the Standard
  506. */
  507. switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
  508. case SND_SOC_DAIFMT_NB_NF:
  509. break;
  510. case SND_SOC_DAIFMT_NB_IF:
  511. if (tmp & MOD_LR_RLOW)
  512. tmp &= ~MOD_LR_RLOW;
  513. else
  514. tmp |= MOD_LR_RLOW;
  515. break;
  516. default:
  517. dev_err(&i2s->pdev->dev, "Polarity not supported\n");
  518. return -EINVAL;
  519. }
  520. switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  521. case SND_SOC_DAIFMT_CBM_CFM:
  522. tmp |= MOD_SLAVE;
  523. break;
  524. case SND_SOC_DAIFMT_CBS_CFS:
  525. /* Set default source clock in Master mode */
  526. if (i2s->rclk_srcrate == 0)
  527. i2s_set_sysclk(dai, SAMSUNG_I2S_RCLKSRC_0,
  528. 0, SND_SOC_CLOCK_IN);
  529. break;
  530. default:
  531. dev_err(&i2s->pdev->dev, "master/slave format not supported\n");
  532. return -EINVAL;
  533. }
  534. if (any_active(i2s) &&
  535. ((mod & (MOD_SDF_MASK | MOD_LR_RLOW
  536. | MOD_SLAVE)) != tmp)) {
  537. dev_err(&i2s->pdev->dev,
  538. "%s:%d Other DAI busy\n", __func__, __LINE__);
  539. return -EAGAIN;
  540. }
  541. mod &= ~(MOD_SDF_MASK | MOD_LR_RLOW | MOD_SLAVE);
  542. mod |= tmp;
  543. writel(mod, i2s->addr + I2SMOD);
  544. return 0;
  545. }
  546. static int i2s_hw_params(struct snd_pcm_substream *substream,
  547. struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
  548. {
  549. struct i2s_dai *i2s = to_info(dai);
  550. u32 mod = readl(i2s->addr + I2SMOD);
  551. if (!is_secondary(i2s))
  552. mod &= ~(MOD_DC2_EN | MOD_DC1_EN);
  553. switch (params_channels(params)) {
  554. case 6:
  555. mod |= MOD_DC2_EN;
  556. case 4:
  557. mod |= MOD_DC1_EN;
  558. break;
  559. case 2:
  560. break;
  561. default:
  562. dev_err(&i2s->pdev->dev, "%d channels not supported\n",
  563. params_channels(params));
  564. return -EINVAL;
  565. }
  566. if (is_secondary(i2s))
  567. mod &= ~MOD_BLCS_MASK;
  568. else
  569. mod &= ~MOD_BLCP_MASK;
  570. if (is_manager(i2s))
  571. mod &= ~MOD_BLC_MASK;
  572. switch (params_format(params)) {
  573. case SNDRV_PCM_FORMAT_S8:
  574. if (is_secondary(i2s))
  575. mod |= MOD_BLCS_8BIT;
  576. else
  577. mod |= MOD_BLCP_8BIT;
  578. if (is_manager(i2s))
  579. mod |= MOD_BLC_8BIT;
  580. break;
  581. case SNDRV_PCM_FORMAT_S16_LE:
  582. if (is_secondary(i2s))
  583. mod |= MOD_BLCS_16BIT;
  584. else
  585. mod |= MOD_BLCP_16BIT;
  586. if (is_manager(i2s))
  587. mod |= MOD_BLC_16BIT;
  588. break;
  589. case SNDRV_PCM_FORMAT_S24_LE:
  590. if (is_secondary(i2s))
  591. mod |= MOD_BLCS_24BIT;
  592. else
  593. mod |= MOD_BLCP_24BIT;
  594. if (is_manager(i2s))
  595. mod |= MOD_BLC_24BIT;
  596. break;
  597. default:
  598. dev_err(&i2s->pdev->dev, "Format(%d) not supported\n",
  599. params_format(params));
  600. return -EINVAL;
  601. }
  602. writel(mod, i2s->addr + I2SMOD);
  603. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  604. snd_soc_dai_set_dma_data(dai, substream,
  605. (void *)&i2s->dma_playback);
  606. else
  607. snd_soc_dai_set_dma_data(dai, substream,
  608. (void *)&i2s->dma_capture);
  609. i2s->frmclk = params_rate(params);
  610. return 0;
  611. }
  612. /* We set constraints on the substream acc to the version of I2S */
  613. static int i2s_startup(struct snd_pcm_substream *substream,
  614. struct snd_soc_dai *dai)
  615. {
  616. struct i2s_dai *i2s = to_info(dai);
  617. struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai;
  618. unsigned long flags;
  619. spin_lock_irqsave(&lock, flags);
  620. i2s->mode |= DAI_OPENED;
  621. if (is_manager(other))
  622. i2s->mode &= ~DAI_MANAGER;
  623. else
  624. i2s->mode |= DAI_MANAGER;
  625. /* Enforce set_sysclk in Master mode */
  626. i2s->rclk_srcrate = 0;
  627. spin_unlock_irqrestore(&lock, flags);
  628. return 0;
  629. }
  630. static void i2s_shutdown(struct snd_pcm_substream *substream,
  631. struct snd_soc_dai *dai)
  632. {
  633. struct i2s_dai *i2s = to_info(dai);
  634. struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai;
  635. unsigned long flags;
  636. spin_lock_irqsave(&lock, flags);
  637. i2s->mode &= ~DAI_OPENED;
  638. i2s->mode &= ~DAI_MANAGER;
  639. if (is_opened(other))
  640. other->mode |= DAI_MANAGER;
  641. /* Reset any constraint on RFS and BFS */
  642. i2s->rfs = 0;
  643. i2s->bfs = 0;
  644. spin_unlock_irqrestore(&lock, flags);
  645. /* Gate CDCLK by default */
  646. if (!is_opened(other))
  647. i2s_set_sysclk(dai, SAMSUNG_I2S_CDCLK,
  648. 0, SND_SOC_CLOCK_IN);
  649. }
  650. static int config_setup(struct i2s_dai *i2s)
  651. {
  652. struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai;
  653. unsigned rfs, bfs, blc;
  654. u32 psr;
  655. blc = get_blc(i2s);
  656. bfs = i2s->bfs;
  657. if (!bfs && other)
  658. bfs = other->bfs;
  659. /* Select least possible multiple(2) if no constraint set */
  660. if (!bfs)
  661. bfs = blc * 2;
  662. rfs = i2s->rfs;
  663. if (!rfs && other)
  664. rfs = other->rfs;
  665. if ((rfs == 256 || rfs == 512) && (blc == 24)) {
  666. dev_err(&i2s->pdev->dev,
  667. "%d-RFS not supported for 24-blc\n", rfs);
  668. return -EINVAL;
  669. }
  670. if (!rfs) {
  671. if (bfs == 16 || bfs == 32)
  672. rfs = 256;
  673. else
  674. rfs = 384;
  675. }
  676. /* If already setup and running */
  677. if (any_active(i2s) && (get_rfs(i2s) != rfs || get_bfs(i2s) != bfs)) {
  678. dev_err(&i2s->pdev->dev,
  679. "%s:%d Other DAI busy\n", __func__, __LINE__);
  680. return -EAGAIN;
  681. }
  682. /* Don't bother RFS, BFS & PSR in Slave mode */
  683. if (is_slave(i2s))
  684. return 0;
  685. set_bfs(i2s, bfs);
  686. set_rfs(i2s, rfs);
  687. if (!(i2s->quirks & QUIRK_NO_MUXPSR)) {
  688. psr = i2s->rclk_srcrate / i2s->frmclk / rfs;
  689. writel(((psr - 1) << 8) | PSR_PSREN, i2s->addr + I2SPSR);
  690. dev_dbg(&i2s->pdev->dev,
  691. "RCLK_SRC=%luHz PSR=%u, RCLK=%dfs, BCLK=%dfs\n",
  692. i2s->rclk_srcrate, psr, rfs, bfs);
  693. }
  694. return 0;
  695. }
  696. static int i2s_trigger(struct snd_pcm_substream *substream,
  697. int cmd, struct snd_soc_dai *dai)
  698. {
  699. int capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE);
  700. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  701. struct i2s_dai *i2s = to_info(rtd->cpu_dai);
  702. unsigned long flags;
  703. switch (cmd) {
  704. case SNDRV_PCM_TRIGGER_START:
  705. case SNDRV_PCM_TRIGGER_RESUME:
  706. case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  707. local_irq_save(flags);
  708. if (capture)
  709. i2s_fifo(i2s, FIC_RXFLUSH);
  710. else
  711. i2s_fifo(i2s, FIC_TXFLUSH);
  712. if (config_setup(i2s)) {
  713. local_irq_restore(flags);
  714. return -EINVAL;
  715. }
  716. if (capture)
  717. i2s_rxctrl(i2s, 1);
  718. else
  719. i2s_txctrl(i2s, 1);
  720. local_irq_restore(flags);
  721. break;
  722. case SNDRV_PCM_TRIGGER_STOP:
  723. case SNDRV_PCM_TRIGGER_SUSPEND:
  724. case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  725. local_irq_save(flags);
  726. if (capture)
  727. i2s_rxctrl(i2s, 0);
  728. else
  729. i2s_txctrl(i2s, 0);
  730. local_irq_restore(flags);
  731. break;
  732. }
  733. return 0;
  734. }
  735. static int i2s_set_clkdiv(struct snd_soc_dai *dai,
  736. int div_id, int div)
  737. {
  738. struct i2s_dai *i2s = to_info(dai);
  739. struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai;
  740. switch (div_id) {
  741. case SAMSUNG_I2S_DIV_BCLK:
  742. if ((any_active(i2s) && div && (get_bfs(i2s) != div))
  743. || (other && other->bfs && (other->bfs != div))) {
  744. dev_err(&i2s->pdev->dev,
  745. "%s:%d Other DAI busy\n", __func__, __LINE__);
  746. return -EAGAIN;
  747. }
  748. i2s->bfs = div;
  749. break;
  750. default:
  751. dev_err(&i2s->pdev->dev,
  752. "Invalid clock divider(%d)\n", div_id);
  753. return -EINVAL;
  754. }
  755. return 0;
  756. }
  757. static snd_pcm_sframes_t
  758. i2s_delay(struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
  759. {
  760. struct i2s_dai *i2s = to_info(dai);
  761. u32 reg = readl(i2s->addr + I2SFIC);
  762. snd_pcm_sframes_t delay;
  763. if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
  764. delay = FIC_RXCOUNT(reg);
  765. else if (is_secondary(i2s))
  766. delay = FICS_TXCOUNT(readl(i2s->addr + I2SFICS));
  767. else
  768. delay = FIC_TXCOUNT(reg);
  769. return delay;
  770. }
  771. #ifdef CONFIG_PM
  772. static int i2s_suspend(struct snd_soc_dai *dai)
  773. {
  774. struct i2s_dai *i2s = to_info(dai);
  775. if (dai->active) {
  776. i2s->suspend_i2smod = readl(i2s->addr + I2SMOD);
  777. i2s->suspend_i2scon = readl(i2s->addr + I2SCON);
  778. i2s->suspend_i2spsr = readl(i2s->addr + I2SPSR);
  779. }
  780. return 0;
  781. }
  782. static int i2s_resume(struct snd_soc_dai *dai)
  783. {
  784. struct i2s_dai *i2s = to_info(dai);
  785. if (dai->active) {
  786. writel(i2s->suspend_i2scon, i2s->addr + I2SCON);
  787. writel(i2s->suspend_i2smod, i2s->addr + I2SMOD);
  788. writel(i2s->suspend_i2spsr, i2s->addr + I2SPSR);
  789. }
  790. return 0;
  791. }
  792. #else
  793. #define i2s_suspend NULL
  794. #define i2s_resume NULL
  795. #endif
  796. static int samsung_i2s_dai_probe(struct snd_soc_dai *dai)
  797. {
  798. struct i2s_dai *i2s = to_info(dai);
  799. struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai;
  800. if (other && other->clk) /* If this is probe on secondary */
  801. goto probe_exit;
  802. i2s->addr = ioremap(i2s->base, 0x100);
  803. if (i2s->addr == NULL) {
  804. dev_err(&i2s->pdev->dev, "cannot ioremap registers\n");
  805. return -ENXIO;
  806. }
  807. i2s->clk = clk_get(&i2s->pdev->dev, "iis");
  808. if (IS_ERR(i2s->clk)) {
  809. dev_err(&i2s->pdev->dev, "failed to get i2s_clock\n");
  810. iounmap(i2s->addr);
  811. return -ENOENT;
  812. }
  813. clk_enable(i2s->clk);
  814. if (other) {
  815. other->addr = i2s->addr;
  816. other->clk = i2s->clk;
  817. }
  818. if (i2s->quirks & QUIRK_NEED_RSTCLR)
  819. writel(CON_RSTCLR, i2s->addr + I2SCON);
  820. probe_exit:
  821. /* Reset any constraint on RFS and BFS */
  822. i2s->rfs = 0;
  823. i2s->bfs = 0;
  824. i2s_txctrl(i2s, 0);
  825. i2s_rxctrl(i2s, 0);
  826. i2s_fifo(i2s, FIC_TXFLUSH);
  827. i2s_fifo(other, FIC_TXFLUSH);
  828. i2s_fifo(i2s, FIC_RXFLUSH);
  829. /* Gate CDCLK by default */
  830. if (!is_opened(other))
  831. i2s_set_sysclk(dai, SAMSUNG_I2S_CDCLK,
  832. 0, SND_SOC_CLOCK_IN);
  833. return 0;
  834. }
  835. static int samsung_i2s_dai_remove(struct snd_soc_dai *dai)
  836. {
  837. struct i2s_dai *i2s = snd_soc_dai_get_drvdata(dai);
  838. struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai;
  839. if (!other || !other->clk) {
  840. if (i2s->quirks & QUIRK_NEED_RSTCLR)
  841. writel(0, i2s->addr + I2SCON);
  842. clk_disable(i2s->clk);
  843. clk_put(i2s->clk);
  844. iounmap(i2s->addr);
  845. }
  846. i2s->clk = NULL;
  847. return 0;
  848. }
  849. static struct snd_soc_dai_ops samsung_i2s_dai_ops = {
  850. .trigger = i2s_trigger,
  851. .hw_params = i2s_hw_params,
  852. .set_fmt = i2s_set_fmt,
  853. .set_clkdiv = i2s_set_clkdiv,
  854. .set_sysclk = i2s_set_sysclk,
  855. .startup = i2s_startup,
  856. .shutdown = i2s_shutdown,
  857. .delay = i2s_delay,
  858. };
  859. #define SAMSUNG_I2S_RATES SNDRV_PCM_RATE_8000_96000
  860. #define SAMSUNG_I2S_FMTS (SNDRV_PCM_FMTBIT_S8 | \
  861. SNDRV_PCM_FMTBIT_S16_LE | \
  862. SNDRV_PCM_FMTBIT_S24_LE)
  863. static __devinit
  864. struct i2s_dai *i2s_alloc_dai(struct platform_device *pdev, bool sec)
  865. {
  866. struct i2s_dai *i2s;
  867. i2s = kzalloc(sizeof(struct i2s_dai), GFP_KERNEL);
  868. if (i2s == NULL)
  869. return NULL;
  870. i2s->pdev = pdev;
  871. i2s->pri_dai = NULL;
  872. i2s->sec_dai = NULL;
  873. i2s->i2s_dai_drv.symmetric_rates = 1;
  874. i2s->i2s_dai_drv.probe = samsung_i2s_dai_probe;
  875. i2s->i2s_dai_drv.remove = samsung_i2s_dai_remove;
  876. i2s->i2s_dai_drv.ops = &samsung_i2s_dai_ops;
  877. i2s->i2s_dai_drv.suspend = i2s_suspend;
  878. i2s->i2s_dai_drv.resume = i2s_resume;
  879. i2s->i2s_dai_drv.playback.channels_min = 2;
  880. i2s->i2s_dai_drv.playback.channels_max = 2;
  881. i2s->i2s_dai_drv.playback.rates = SAMSUNG_I2S_RATES;
  882. i2s->i2s_dai_drv.playback.formats = SAMSUNG_I2S_FMTS;
  883. if (!sec) {
  884. i2s->i2s_dai_drv.capture.channels_min = 2;
  885. i2s->i2s_dai_drv.capture.channels_max = 2;
  886. i2s->i2s_dai_drv.capture.rates = SAMSUNG_I2S_RATES;
  887. i2s->i2s_dai_drv.capture.formats = SAMSUNG_I2S_FMTS;
  888. } else { /* Create a new platform_device for Secondary */
  889. i2s->pdev = platform_device_register_resndata(NULL,
  890. pdev->name, pdev->id + SAMSUNG_I2S_SECOFF,
  891. NULL, 0, NULL, 0);
  892. if (IS_ERR(i2s->pdev)) {
  893. kfree(i2s);
  894. return NULL;
  895. }
  896. }
  897. /* Pre-assign snd_soc_dai_set_drvdata */
  898. dev_set_drvdata(&i2s->pdev->dev, i2s);
  899. return i2s;
  900. }
  901. static __devinit int samsung_i2s_probe(struct platform_device *pdev)
  902. {
  903. u32 dma_pl_chan, dma_cp_chan, dma_pl_sec_chan;
  904. struct i2s_dai *pri_dai, *sec_dai = NULL;
  905. struct s3c_audio_pdata *i2s_pdata;
  906. struct samsung_i2s *i2s_cfg;
  907. struct resource *res;
  908. u32 regs_base, quirks;
  909. int ret = 0;
  910. /* Call during Seconday interface registration */
  911. if (pdev->id >= SAMSUNG_I2S_SECOFF) {
  912. sec_dai = dev_get_drvdata(&pdev->dev);
  913. snd_soc_register_dai(&sec_dai->pdev->dev,
  914. &sec_dai->i2s_dai_drv);
  915. return 0;
  916. }
  917. i2s_pdata = pdev->dev.platform_data;
  918. if (i2s_pdata == NULL) {
  919. dev_err(&pdev->dev, "Can't work without s3c_audio_pdata\n");
  920. return -EINVAL;
  921. }
  922. res = platform_get_resource(pdev, IORESOURCE_DMA, 0);
  923. if (!res) {
  924. dev_err(&pdev->dev, "Unable to get I2S-TX dma resource\n");
  925. return -ENXIO;
  926. }
  927. dma_pl_chan = res->start;
  928. res = platform_get_resource(pdev, IORESOURCE_DMA, 1);
  929. if (!res) {
  930. dev_err(&pdev->dev, "Unable to get I2S-RX dma resource\n");
  931. return -ENXIO;
  932. }
  933. dma_cp_chan = res->start;
  934. res = platform_get_resource(pdev, IORESOURCE_DMA, 2);
  935. if (res)
  936. dma_pl_sec_chan = res->start;
  937. else
  938. dma_pl_sec_chan = 0;
  939. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  940. if (!res) {
  941. dev_err(&pdev->dev, "Unable to get I2S SFR address\n");
  942. return -ENXIO;
  943. }
  944. if (!request_mem_region(res->start, resource_size(res),
  945. "samsung-i2s")) {
  946. dev_err(&pdev->dev, "Unable to request SFR region\n");
  947. return -EBUSY;
  948. }
  949. regs_base = res->start;
  950. i2s_cfg = &i2s_pdata->type.i2s;
  951. quirks = i2s_cfg->quirks;
  952. pri_dai = i2s_alloc_dai(pdev, false);
  953. if (!pri_dai) {
  954. dev_err(&pdev->dev, "Unable to alloc I2S_pri\n");
  955. ret = -ENOMEM;
  956. goto err1;
  957. }
  958. pri_dai->dma_playback.dma_addr = regs_base + I2STXD;
  959. pri_dai->dma_capture.dma_addr = regs_base + I2SRXD;
  960. pri_dai->dma_playback.client =
  961. (struct s3c2410_dma_client *)&pri_dai->dma_playback;
  962. pri_dai->dma_capture.client =
  963. (struct s3c2410_dma_client *)&pri_dai->dma_capture;
  964. pri_dai->dma_playback.channel = dma_pl_chan;
  965. pri_dai->dma_capture.channel = dma_cp_chan;
  966. pri_dai->src_clk = i2s_cfg->src_clk;
  967. pri_dai->dma_playback.dma_size = 4;
  968. pri_dai->dma_capture.dma_size = 4;
  969. pri_dai->base = regs_base;
  970. pri_dai->quirks = quirks;
  971. if (quirks & QUIRK_PRI_6CHAN)
  972. pri_dai->i2s_dai_drv.playback.channels_max = 6;
  973. if (quirks & QUIRK_SEC_DAI) {
  974. sec_dai = i2s_alloc_dai(pdev, true);
  975. if (!sec_dai) {
  976. dev_err(&pdev->dev, "Unable to alloc I2S_sec\n");
  977. ret = -ENOMEM;
  978. goto err2;
  979. }
  980. sec_dai->dma_playback.dma_addr = regs_base + I2STXDS;
  981. sec_dai->dma_playback.client =
  982. (struct s3c2410_dma_client *)&sec_dai->dma_playback;
  983. /* Use iDMA always if SysDMA not provided */
  984. sec_dai->dma_playback.channel = dma_pl_sec_chan ? : -1;
  985. sec_dai->src_clk = i2s_cfg->src_clk;
  986. sec_dai->dma_playback.dma_size = 4;
  987. sec_dai->base = regs_base;
  988. sec_dai->quirks = quirks;
  989. sec_dai->pri_dai = pri_dai;
  990. pri_dai->sec_dai = sec_dai;
  991. }
  992. if (i2s_pdata->cfg_gpio && i2s_pdata->cfg_gpio(pdev)) {
  993. dev_err(&pdev->dev, "Unable to configure gpio\n");
  994. ret = -EINVAL;
  995. goto err3;
  996. }
  997. snd_soc_register_dai(&pri_dai->pdev->dev, &pri_dai->i2s_dai_drv);
  998. return 0;
  999. err3:
  1000. kfree(sec_dai);
  1001. err2:
  1002. kfree(pri_dai);
  1003. err1:
  1004. release_mem_region(regs_base, resource_size(res));
  1005. return ret;
  1006. }
  1007. static __devexit int samsung_i2s_remove(struct platform_device *pdev)
  1008. {
  1009. struct i2s_dai *i2s, *other;
  1010. i2s = dev_get_drvdata(&pdev->dev);
  1011. other = i2s->pri_dai ? : i2s->sec_dai;
  1012. if (other) {
  1013. other->pri_dai = NULL;
  1014. other->sec_dai = NULL;
  1015. } else {
  1016. struct resource *res;
  1017. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1018. if (res)
  1019. release_mem_region(res->start, resource_size(res));
  1020. }
  1021. i2s->pri_dai = NULL;
  1022. i2s->sec_dai = NULL;
  1023. kfree(i2s);
  1024. snd_soc_unregister_dai(&pdev->dev);
  1025. return 0;
  1026. }
  1027. static struct platform_driver samsung_i2s_driver = {
  1028. .probe = samsung_i2s_probe,
  1029. .remove = samsung_i2s_remove,
  1030. .driver = {
  1031. .name = "samsung-i2s",
  1032. .owner = THIS_MODULE,
  1033. },
  1034. };
  1035. static int __init samsung_i2s_init(void)
  1036. {
  1037. return platform_driver_register(&samsung_i2s_driver);
  1038. }
  1039. module_init(samsung_i2s_init);
  1040. static void __exit samsung_i2s_exit(void)
  1041. {
  1042. platform_driver_unregister(&samsung_i2s_driver);
  1043. }
  1044. module_exit(samsung_i2s_exit);
  1045. /* Module information */
  1046. MODULE_AUTHOR("Jaswinder Singh, <jassi.brar@samsung.com>");
  1047. MODULE_DESCRIPTION("Samsung I2S Interface");
  1048. MODULE_ALIAS("platform:samsung-i2s");
  1049. MODULE_LICENSE("GPL");