s6000-i2s.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  1. /*
  2. * ALSA SoC I2S Audio Layer for the Stretch S6000 family
  3. *
  4. * Author: Daniel Gloeckner, <dg@emlix.com>
  5. * Copyright: (C) 2009 emlix GmbH <info@emlix.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/init.h>
  12. #include <linux/module.h>
  13. #include <linux/device.h>
  14. #include <linux/delay.h>
  15. #include <linux/clk.h>
  16. #include <linux/interrupt.h>
  17. #include <linux/io.h>
  18. #include <linux/slab.h>
  19. #include <sound/core.h>
  20. #include <sound/pcm.h>
  21. #include <sound/pcm_params.h>
  22. #include <sound/initval.h>
  23. #include <sound/soc.h>
  24. #include "s6000-i2s.h"
  25. #include "s6000-pcm.h"
  26. struct s6000_i2s_dev {
  27. dma_addr_t sifbase;
  28. u8 __iomem *scbbase;
  29. unsigned int wide;
  30. unsigned int channel_in;
  31. unsigned int channel_out;
  32. unsigned int lines_in;
  33. unsigned int lines_out;
  34. struct s6000_pcm_dma_params dma_params;
  35. };
  36. #define S6_I2S_INTERRUPT_STATUS 0x00
  37. #define S6_I2S_INT_OVERRUN 1
  38. #define S6_I2S_INT_UNDERRUN 2
  39. #define S6_I2S_INT_ALIGNMENT 4
  40. #define S6_I2S_INTERRUPT_ENABLE 0x04
  41. #define S6_I2S_INTERRUPT_RAW 0x08
  42. #define S6_I2S_INTERRUPT_CLEAR 0x0C
  43. #define S6_I2S_INTERRUPT_SET 0x10
  44. #define S6_I2S_MODE 0x20
  45. #define S6_I2S_DUAL 0
  46. #define S6_I2S_WIDE 1
  47. #define S6_I2S_TX_DEFAULT 0x24
  48. #define S6_I2S_DATA_CFG(c) (0x40 + 0x10 * (c))
  49. #define S6_I2S_IN 0
  50. #define S6_I2S_OUT 1
  51. #define S6_I2S_UNUSED 2
  52. #define S6_I2S_INTERFACE_CFG(c) (0x44 + 0x10 * (c))
  53. #define S6_I2S_DIV_MASK 0x001fff
  54. #define S6_I2S_16BIT 0x000000
  55. #define S6_I2S_20BIT 0x002000
  56. #define S6_I2S_24BIT 0x004000
  57. #define S6_I2S_32BIT 0x006000
  58. #define S6_I2S_BITS_MASK 0x006000
  59. #define S6_I2S_MEM_16BIT 0x000000
  60. #define S6_I2S_MEM_32BIT 0x008000
  61. #define S6_I2S_MEM_MASK 0x008000
  62. #define S6_I2S_CHANNELS_SHIFT 16
  63. #define S6_I2S_CHANNELS_MASK 0x030000
  64. #define S6_I2S_SCK_IN 0x000000
  65. #define S6_I2S_SCK_OUT 0x040000
  66. #define S6_I2S_SCK_DIR 0x040000
  67. #define S6_I2S_WS_IN 0x000000
  68. #define S6_I2S_WS_OUT 0x080000
  69. #define S6_I2S_WS_DIR 0x080000
  70. #define S6_I2S_LEFT_FIRST 0x000000
  71. #define S6_I2S_RIGHT_FIRST 0x100000
  72. #define S6_I2S_FIRST 0x100000
  73. #define S6_I2S_CUR_SCK 0x200000
  74. #define S6_I2S_CUR_WS 0x400000
  75. #define S6_I2S_ENABLE(c) (0x48 + 0x10 * (c))
  76. #define S6_I2S_DISABLE_IF 0x02
  77. #define S6_I2S_ENABLE_IF 0x03
  78. #define S6_I2S_IS_BUSY 0x04
  79. #define S6_I2S_DMA_ACTIVE 0x08
  80. #define S6_I2S_IS_ENABLED 0x10
  81. #define S6_I2S_NUM_LINES 4
  82. #define S6_I2S_SIF_PORT0 0x0000000
  83. #define S6_I2S_SIF_PORT1 0x0000080 /* docs say 0x0000010 */
  84. static inline void s6_i2s_write_reg(struct s6000_i2s_dev *dev, int reg, u32 val)
  85. {
  86. writel(val, dev->scbbase + reg);
  87. }
  88. static inline u32 s6_i2s_read_reg(struct s6000_i2s_dev *dev, int reg)
  89. {
  90. return readl(dev->scbbase + reg);
  91. }
  92. static inline void s6_i2s_mod_reg(struct s6000_i2s_dev *dev, int reg,
  93. u32 mask, u32 val)
  94. {
  95. val ^= s6_i2s_read_reg(dev, reg) & ~mask;
  96. s6_i2s_write_reg(dev, reg, val);
  97. }
  98. static void s6000_i2s_start_channel(struct s6000_i2s_dev *dev, int channel)
  99. {
  100. int i, j, cur, prev;
  101. /*
  102. * Wait for WCLK to toggle 5 times before enabling the channel
  103. * s6000 Family Datasheet 3.6.4:
  104. * "At least two cycles of WS must occur between commands
  105. * to disable or enable the interface"
  106. */
  107. j = 0;
  108. prev = ~S6_I2S_CUR_WS;
  109. for (i = 1000000; --i && j < 6; ) {
  110. cur = s6_i2s_read_reg(dev, S6_I2S_INTERFACE_CFG(channel))
  111. & S6_I2S_CUR_WS;
  112. if (prev != cur) {
  113. prev = cur;
  114. j++;
  115. }
  116. }
  117. if (j < 6)
  118. printk(KERN_WARNING "s6000-i2s: timeout waiting for WCLK\n");
  119. s6_i2s_write_reg(dev, S6_I2S_ENABLE(channel), S6_I2S_ENABLE_IF);
  120. }
  121. static void s6000_i2s_stop_channel(struct s6000_i2s_dev *dev, int channel)
  122. {
  123. s6_i2s_write_reg(dev, S6_I2S_ENABLE(channel), S6_I2S_DISABLE_IF);
  124. }
  125. static void s6000_i2s_start(struct snd_pcm_substream *substream)
  126. {
  127. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  128. struct s6000_i2s_dev *dev = snd_soc_dai_get_drvdata(rtd->cpu_dai);
  129. int channel;
  130. channel = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ?
  131. dev->channel_out : dev->channel_in;
  132. s6000_i2s_start_channel(dev, channel);
  133. }
  134. static void s6000_i2s_stop(struct snd_pcm_substream *substream)
  135. {
  136. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  137. struct s6000_i2s_dev *dev = snd_soc_dai_get_drvdata(rtd->cpu_dai);
  138. int channel;
  139. channel = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ?
  140. dev->channel_out : dev->channel_in;
  141. s6000_i2s_stop_channel(dev, channel);
  142. }
  143. static int s6000_i2s_trigger(struct snd_pcm_substream *substream, int cmd,
  144. int after)
  145. {
  146. switch (cmd) {
  147. case SNDRV_PCM_TRIGGER_START:
  148. case SNDRV_PCM_TRIGGER_RESUME:
  149. case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  150. if ((substream->stream == SNDRV_PCM_STREAM_CAPTURE) ^ !after)
  151. s6000_i2s_start(substream);
  152. break;
  153. case SNDRV_PCM_TRIGGER_STOP:
  154. case SNDRV_PCM_TRIGGER_SUSPEND:
  155. case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  156. if (!after)
  157. s6000_i2s_stop(substream);
  158. }
  159. return 0;
  160. }
  161. static unsigned int s6000_i2s_int_sources(struct s6000_i2s_dev *dev)
  162. {
  163. unsigned int pending;
  164. pending = s6_i2s_read_reg(dev, S6_I2S_INTERRUPT_RAW);
  165. pending &= S6_I2S_INT_ALIGNMENT |
  166. S6_I2S_INT_UNDERRUN |
  167. S6_I2S_INT_OVERRUN;
  168. s6_i2s_write_reg(dev, S6_I2S_INTERRUPT_CLEAR, pending);
  169. return pending;
  170. }
  171. static unsigned int s6000_i2s_check_xrun(struct snd_soc_dai *cpu_dai)
  172. {
  173. struct s6000_i2s_dev *dev = snd_soc_dai_get_drvdata(cpu_dai);
  174. unsigned int errors;
  175. unsigned int ret;
  176. errors = s6000_i2s_int_sources(dev);
  177. if (likely(!errors))
  178. return 0;
  179. ret = 0;
  180. if (errors & S6_I2S_INT_ALIGNMENT)
  181. printk(KERN_ERR "s6000-i2s: WCLK misaligned\n");
  182. if (errors & S6_I2S_INT_UNDERRUN)
  183. ret |= 1 << SNDRV_PCM_STREAM_PLAYBACK;
  184. if (errors & S6_I2S_INT_OVERRUN)
  185. ret |= 1 << SNDRV_PCM_STREAM_CAPTURE;
  186. return ret;
  187. }
  188. static void s6000_i2s_wait_disabled(struct s6000_i2s_dev *dev)
  189. {
  190. int channel;
  191. int n = 50;
  192. for (channel = 0; channel < 2; channel++) {
  193. while (--n >= 0) {
  194. int v = s6_i2s_read_reg(dev, S6_I2S_ENABLE(channel));
  195. if ((v & S6_I2S_IS_ENABLED)
  196. || !(v & (S6_I2S_DMA_ACTIVE | S6_I2S_IS_BUSY)))
  197. break;
  198. udelay(20);
  199. }
  200. }
  201. if (n < 0)
  202. printk(KERN_WARNING "s6000-i2s: timeout disabling interfaces");
  203. }
  204. static int s6000_i2s_set_dai_fmt(struct snd_soc_dai *cpu_dai,
  205. unsigned int fmt)
  206. {
  207. struct s6000_i2s_dev *dev = snd_soc_dai_get_drvdata(cpu_dai);
  208. u32 w;
  209. switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  210. case SND_SOC_DAIFMT_CBM_CFM:
  211. w = S6_I2S_SCK_IN | S6_I2S_WS_IN;
  212. break;
  213. case SND_SOC_DAIFMT_CBS_CFM:
  214. w = S6_I2S_SCK_OUT | S6_I2S_WS_IN;
  215. break;
  216. case SND_SOC_DAIFMT_CBM_CFS:
  217. w = S6_I2S_SCK_IN | S6_I2S_WS_OUT;
  218. break;
  219. case SND_SOC_DAIFMT_CBS_CFS:
  220. w = S6_I2S_SCK_OUT | S6_I2S_WS_OUT;
  221. break;
  222. default:
  223. return -EINVAL;
  224. }
  225. switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
  226. case SND_SOC_DAIFMT_NB_NF:
  227. w |= S6_I2S_LEFT_FIRST;
  228. break;
  229. case SND_SOC_DAIFMT_NB_IF:
  230. w |= S6_I2S_RIGHT_FIRST;
  231. break;
  232. default:
  233. return -EINVAL;
  234. }
  235. s6_i2s_mod_reg(dev, S6_I2S_INTERFACE_CFG(0),
  236. S6_I2S_FIRST | S6_I2S_WS_DIR | S6_I2S_SCK_DIR, w);
  237. s6_i2s_mod_reg(dev, S6_I2S_INTERFACE_CFG(1),
  238. S6_I2S_FIRST | S6_I2S_WS_DIR | S6_I2S_SCK_DIR, w);
  239. return 0;
  240. }
  241. static int s6000_i2s_set_clkdiv(struct snd_soc_dai *dai, int div_id, int div)
  242. {
  243. struct s6000_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  244. if (!div || (div & 1) || div > (S6_I2S_DIV_MASK + 1) * 2)
  245. return -EINVAL;
  246. s6_i2s_mod_reg(dev, S6_I2S_INTERFACE_CFG(div_id),
  247. S6_I2S_DIV_MASK, div / 2 - 1);
  248. return 0;
  249. }
  250. static int s6000_i2s_hw_params(struct snd_pcm_substream *substream,
  251. struct snd_pcm_hw_params *params,
  252. struct snd_soc_dai *dai)
  253. {
  254. struct s6000_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  255. int interf;
  256. u32 w = 0;
  257. if (dev->wide)
  258. interf = 0;
  259. else {
  260. w |= (((params_channels(params) - 2) / 2)
  261. << S6_I2S_CHANNELS_SHIFT) & S6_I2S_CHANNELS_MASK;
  262. interf = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  263. ? dev->channel_out : dev->channel_in;
  264. }
  265. switch (params_format(params)) {
  266. case SNDRV_PCM_FORMAT_S16_LE:
  267. w |= S6_I2S_16BIT | S6_I2S_MEM_16BIT;
  268. break;
  269. case SNDRV_PCM_FORMAT_S32_LE:
  270. w |= S6_I2S_32BIT | S6_I2S_MEM_32BIT;
  271. break;
  272. default:
  273. printk(KERN_WARNING "s6000-i2s: unsupported PCM format %x\n",
  274. params_format(params));
  275. return -EINVAL;
  276. }
  277. if (s6_i2s_read_reg(dev, S6_I2S_INTERFACE_CFG(interf))
  278. & S6_I2S_IS_ENABLED) {
  279. printk(KERN_ERR "s6000-i2s: interface already enabled\n");
  280. return -EBUSY;
  281. }
  282. s6_i2s_mod_reg(dev, S6_I2S_INTERFACE_CFG(interf),
  283. S6_I2S_CHANNELS_MASK|S6_I2S_MEM_MASK|S6_I2S_BITS_MASK,
  284. w);
  285. return 0;
  286. }
  287. static int s6000_i2s_dai_probe(struct snd_soc_dai *dai)
  288. {
  289. struct s6000_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  290. struct s6000_snd_platform_data *pdata = dai->dev->platform_data;
  291. if (!pdata)
  292. return -EINVAL;
  293. dai->capture_dma_data = &dev->dma_params;
  294. dai->playback_dma_data = &dev->dma_params;
  295. dev->wide = pdata->wide;
  296. dev->channel_in = pdata->channel_in;
  297. dev->channel_out = pdata->channel_out;
  298. dev->lines_in = pdata->lines_in;
  299. dev->lines_out = pdata->lines_out;
  300. s6_i2s_write_reg(dev, S6_I2S_MODE,
  301. dev->wide ? S6_I2S_WIDE : S6_I2S_DUAL);
  302. if (dev->wide) {
  303. int i;
  304. if (dev->lines_in + dev->lines_out > S6_I2S_NUM_LINES)
  305. return -EINVAL;
  306. dev->channel_in = 0;
  307. dev->channel_out = 1;
  308. dai->driver->capture.channels_min = 2 * dev->lines_in;
  309. dai->driver->capture.channels_max = dai->driver->capture.channels_min;
  310. dai->driver->playback.channels_min = 2 * dev->lines_out;
  311. dai->driver->playback.channels_max = dai->driver->playback.channels_min;
  312. for (i = 0; i < dev->lines_out; i++)
  313. s6_i2s_write_reg(dev, S6_I2S_DATA_CFG(i), S6_I2S_OUT);
  314. for (; i < S6_I2S_NUM_LINES - dev->lines_in; i++)
  315. s6_i2s_write_reg(dev, S6_I2S_DATA_CFG(i),
  316. S6_I2S_UNUSED);
  317. for (; i < S6_I2S_NUM_LINES; i++)
  318. s6_i2s_write_reg(dev, S6_I2S_DATA_CFG(i), S6_I2S_IN);
  319. } else {
  320. unsigned int cfg[2] = {S6_I2S_UNUSED, S6_I2S_UNUSED};
  321. if (dev->lines_in > 1 || dev->lines_out > 1)
  322. return -EINVAL;
  323. dai->driver->capture.channels_min = 2 * dev->lines_in;
  324. dai->driver->capture.channels_max = 8 * dev->lines_in;
  325. dai->driver->playback.channels_min = 2 * dev->lines_out;
  326. dai->driver->playback.channels_max = 8 * dev->lines_out;
  327. if (dev->lines_in)
  328. cfg[dev->channel_in] = S6_I2S_IN;
  329. if (dev->lines_out)
  330. cfg[dev->channel_out] = S6_I2S_OUT;
  331. s6_i2s_write_reg(dev, S6_I2S_DATA_CFG(0), cfg[0]);
  332. s6_i2s_write_reg(dev, S6_I2S_DATA_CFG(1), cfg[1]);
  333. }
  334. if (dev->lines_out) {
  335. if (dev->lines_in) {
  336. if (!dev->dma_params.dma_out)
  337. return -ENODEV;
  338. } else {
  339. dev->dma_params.dma_out = dev->dma_params.dma_in;
  340. dev->dma_params.dma_in = 0;
  341. }
  342. }
  343. dev->dma_params.sif_in = dev->sifbase + (dev->channel_in ?
  344. S6_I2S_SIF_PORT1 : S6_I2S_SIF_PORT0);
  345. dev->dma_params.sif_out = dev->sifbase + (dev->channel_out ?
  346. S6_I2S_SIF_PORT1 : S6_I2S_SIF_PORT0);
  347. dev->dma_params.same_rate = pdata->same_rate | pdata->wide;
  348. return 0;
  349. }
  350. #define S6000_I2S_RATES (SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_5512 | \
  351. SNDRV_PCM_RATE_8000_192000)
  352. #define S6000_I2S_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE)
  353. static struct snd_soc_dai_ops s6000_i2s_dai_ops = {
  354. .set_fmt = s6000_i2s_set_dai_fmt,
  355. .set_clkdiv = s6000_i2s_set_clkdiv,
  356. .hw_params = s6000_i2s_hw_params,
  357. };
  358. static struct snd_soc_dai_driver s6000_i2s_dai = {
  359. .probe = s6000_i2s_dai_probe,
  360. .playback = {
  361. .channels_min = 2,
  362. .channels_max = 8,
  363. .formats = S6000_I2S_FORMATS,
  364. .rates = S6000_I2S_RATES,
  365. .rate_min = 0,
  366. .rate_max = 1562500,
  367. },
  368. .capture = {
  369. .channels_min = 2,
  370. .channels_max = 8,
  371. .formats = S6000_I2S_FORMATS,
  372. .rates = S6000_I2S_RATES,
  373. .rate_min = 0,
  374. .rate_max = 1562500,
  375. },
  376. .ops = &s6000_i2s_dai_ops,
  377. };
  378. static int __devinit s6000_i2s_probe(struct platform_device *pdev)
  379. {
  380. struct s6000_i2s_dev *dev;
  381. struct resource *scbmem, *sifmem, *region, *dma1, *dma2;
  382. u8 __iomem *mmio;
  383. int ret;
  384. scbmem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  385. if (!scbmem) {
  386. dev_err(&pdev->dev, "no mem resource?\n");
  387. ret = -ENODEV;
  388. goto err_release_none;
  389. }
  390. region = request_mem_region(scbmem->start, resource_size(scbmem),
  391. pdev->name);
  392. if (!region) {
  393. dev_err(&pdev->dev, "I2S SCB region already claimed\n");
  394. ret = -EBUSY;
  395. goto err_release_none;
  396. }
  397. mmio = ioremap(scbmem->start, resource_size(scbmem));
  398. if (!mmio) {
  399. dev_err(&pdev->dev, "can't ioremap SCB region\n");
  400. ret = -ENOMEM;
  401. goto err_release_scb;
  402. }
  403. sifmem = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  404. if (!sifmem) {
  405. dev_err(&pdev->dev, "no second mem resource?\n");
  406. ret = -ENODEV;
  407. goto err_release_map;
  408. }
  409. region = request_mem_region(sifmem->start, resource_size(sifmem),
  410. pdev->name);
  411. if (!region) {
  412. dev_err(&pdev->dev, "I2S SIF region already claimed\n");
  413. ret = -EBUSY;
  414. goto err_release_map;
  415. }
  416. dma1 = platform_get_resource(pdev, IORESOURCE_DMA, 0);
  417. if (!dma1) {
  418. dev_err(&pdev->dev, "no dma resource?\n");
  419. ret = -ENODEV;
  420. goto err_release_sif;
  421. }
  422. region = request_mem_region(dma1->start, resource_size(dma1),
  423. pdev->name);
  424. if (!region) {
  425. dev_err(&pdev->dev, "I2S DMA region already claimed\n");
  426. ret = -EBUSY;
  427. goto err_release_sif;
  428. }
  429. dma2 = platform_get_resource(pdev, IORESOURCE_DMA, 1);
  430. if (dma2) {
  431. region = request_mem_region(dma2->start, resource_size(dma2),
  432. pdev->name);
  433. if (!region) {
  434. dev_err(&pdev->dev,
  435. "I2S DMA region already claimed\n");
  436. ret = -EBUSY;
  437. goto err_release_dma1;
  438. }
  439. }
  440. dev = kzalloc(sizeof(struct s6000_i2s_dev), GFP_KERNEL);
  441. if (!dev) {
  442. ret = -ENOMEM;
  443. goto err_release_dma2;
  444. }
  445. dev_set_drvdata(&pdev->dev, dev);
  446. dev->sifbase = sifmem->start;
  447. dev->scbbase = mmio;
  448. s6_i2s_write_reg(dev, S6_I2S_INTERRUPT_ENABLE, 0);
  449. s6_i2s_write_reg(dev, S6_I2S_INTERRUPT_CLEAR,
  450. S6_I2S_INT_ALIGNMENT |
  451. S6_I2S_INT_UNDERRUN |
  452. S6_I2S_INT_OVERRUN);
  453. s6000_i2s_stop_channel(dev, 0);
  454. s6000_i2s_stop_channel(dev, 1);
  455. s6000_i2s_wait_disabled(dev);
  456. dev->dma_params.check_xrun = s6000_i2s_check_xrun;
  457. dev->dma_params.trigger = s6000_i2s_trigger;
  458. dev->dma_params.dma_in = dma1->start;
  459. dev->dma_params.dma_out = dma2 ? dma2->start : 0;
  460. dev->dma_params.irq = platform_get_irq(pdev, 0);
  461. if (dev->dma_params.irq < 0) {
  462. dev_err(&pdev->dev, "no irq resource?\n");
  463. ret = -ENODEV;
  464. goto err_release_dev;
  465. }
  466. s6_i2s_write_reg(dev, S6_I2S_INTERRUPT_ENABLE,
  467. S6_I2S_INT_ALIGNMENT |
  468. S6_I2S_INT_UNDERRUN |
  469. S6_I2S_INT_OVERRUN);
  470. ret = snd_soc_register_dai(&pdev->dev, &s6000_i2s_dai);
  471. if (ret)
  472. goto err_release_dev;
  473. return 0;
  474. err_release_dev:
  475. kfree(dev);
  476. err_release_dma2:
  477. if (dma2)
  478. release_mem_region(dma2->start, resource_size(dma2));
  479. err_release_dma1:
  480. release_mem_region(dma1->start, resource_size(dma1));
  481. err_release_sif:
  482. release_mem_region(sifmem->start, resource_size(sifmem));
  483. err_release_map:
  484. iounmap(mmio);
  485. err_release_scb:
  486. release_mem_region(scbmem->start, resource_size(scbmem));
  487. err_release_none:
  488. return ret;
  489. }
  490. static void __devexit s6000_i2s_remove(struct platform_device *pdev)
  491. {
  492. struct s6000_i2s_dev *dev = dev_get_drvdata(&pdev->dev);
  493. struct resource *region;
  494. void __iomem *mmio = dev->scbbase;
  495. snd_soc_unregister_dai(&pdev->dev);
  496. s6000_i2s_stop_channel(dev, 0);
  497. s6000_i2s_stop_channel(dev, 1);
  498. s6_i2s_write_reg(dev, S6_I2S_INTERRUPT_ENABLE, 0);
  499. kfree(dev);
  500. region = platform_get_resource(pdev, IORESOURCE_DMA, 0);
  501. release_mem_region(region->start, resource_size(region));
  502. region = platform_get_resource(pdev, IORESOURCE_DMA, 1);
  503. if (region)
  504. release_mem_region(region->start, resource_size(region));
  505. region = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  506. release_mem_region(region->start, resource_size(region));
  507. iounmap(mmio);
  508. region = platform_get_resource(pdev, IORESOURCE_IO, 0);
  509. release_mem_region(region->start, resource_size(region));
  510. }
  511. static struct platform_driver s6000_i2s_driver = {
  512. .probe = s6000_i2s_probe,
  513. .remove = __devexit_p(s6000_i2s_remove),
  514. .driver = {
  515. .name = "s6000-i2s",
  516. .owner = THIS_MODULE,
  517. },
  518. };
  519. static int __init s6000_i2s_init(void)
  520. {
  521. return platform_driver_register(&s6000_i2s_driver);
  522. }
  523. module_init(s6000_i2s_init);
  524. static void __exit s6000_i2s_exit(void)
  525. {
  526. platform_driver_unregister(&s6000_i2s_driver);
  527. }
  528. module_exit(s6000_i2s_exit);
  529. MODULE_AUTHOR("Daniel Gloeckner");
  530. MODULE_DESCRIPTION("Stretch s6000 family I2S SoC Interface");
  531. MODULE_LICENSE("GPL");