designware_i2s.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  1. /*
  2. * ALSA SoC Synopsys I2S Audio Layer
  3. *
  4. * sound/soc/dwc/designware_i2s.c
  5. *
  6. * Copyright (C) 2010 ST Microelectronics
  7. * Rajeev Kumar <rajeevkumar.linux@gmail.com>
  8. *
  9. * This file is licensed under the terms of the GNU General Public
  10. * License version 2. This program is licensed "as is" without any
  11. * warranty of any kind, whether express or implied.
  12. */
  13. #include <linux/clk.h>
  14. #include <linux/device.h>
  15. #include <linux/init.h>
  16. #include <linux/io.h>
  17. #include <linux/interrupt.h>
  18. #include <linux/module.h>
  19. #include <linux/slab.h>
  20. #include <sound/designware_i2s.h>
  21. #include <sound/pcm.h>
  22. #include <sound/pcm_params.h>
  23. #include <sound/soc.h>
  24. #include <sound/dmaengine_pcm.h>
  25. /* common register for all channel */
  26. #define IER 0x000
  27. #define IRER 0x004
  28. #define ITER 0x008
  29. #define CER 0x00C
  30. #define CCR 0x010
  31. #define RXFFR 0x014
  32. #define TXFFR 0x018
  33. /* I2STxRxRegisters for all channels */
  34. #define LRBR_LTHR(x) (0x40 * x + 0x020)
  35. #define RRBR_RTHR(x) (0x40 * x + 0x024)
  36. #define RER(x) (0x40 * x + 0x028)
  37. #define TER(x) (0x40 * x + 0x02C)
  38. #define RCR(x) (0x40 * x + 0x030)
  39. #define TCR(x) (0x40 * x + 0x034)
  40. #define ISR(x) (0x40 * x + 0x038)
  41. #define IMR(x) (0x40 * x + 0x03C)
  42. #define ROR(x) (0x40 * x + 0x040)
  43. #define TOR(x) (0x40 * x + 0x044)
  44. #define RFCR(x) (0x40 * x + 0x048)
  45. #define TFCR(x) (0x40 * x + 0x04C)
  46. #define RFF(x) (0x40 * x + 0x050)
  47. #define TFF(x) (0x40 * x + 0x054)
  48. /* I2SCOMPRegisters */
  49. #define I2S_COMP_PARAM_2 0x01F0
  50. #define I2S_COMP_PARAM_1 0x01F4
  51. #define I2S_COMP_VERSION 0x01F8
  52. #define I2S_COMP_TYPE 0x01FC
  53. /*
  54. * Component parameter register fields - define the I2S block's
  55. * configuration.
  56. */
  57. #define COMP1_TX_WORDSIZE_3(r) (((r) & GENMASK(27, 25)) >> 25)
  58. #define COMP1_TX_WORDSIZE_2(r) (((r) & GENMASK(24, 22)) >> 22)
  59. #define COMP1_TX_WORDSIZE_1(r) (((r) & GENMASK(21, 19)) >> 19)
  60. #define COMP1_TX_WORDSIZE_0(r) (((r) & GENMASK(18, 16)) >> 16)
  61. #define COMP1_TX_CHANNELS(r) (((r) & GENMASK(10, 9)) >> 9)
  62. #define COMP1_RX_CHANNELS(r) (((r) & GENMASK(8, 7)) >> 7)
  63. #define COMP1_RX_ENABLED(r) (((r) & BIT(6)) >> 6)
  64. #define COMP1_TX_ENABLED(r) (((r) & BIT(5)) >> 5)
  65. #define COMP1_MODE_EN(r) (((r) & BIT(4)) >> 4)
  66. #define COMP1_FIFO_DEPTH_GLOBAL(r) (((r) & GENMASK(3, 2)) >> 2)
  67. #define COMP1_APB_DATA_WIDTH(r) (((r) & GENMASK(1, 0)) >> 0)
  68. #define COMP2_RX_WORDSIZE_3(r) (((r) & GENMASK(12, 10)) >> 10)
  69. #define COMP2_RX_WORDSIZE_2(r) (((r) & GENMASK(9, 7)) >> 7)
  70. #define COMP2_RX_WORDSIZE_1(r) (((r) & GENMASK(5, 3)) >> 3)
  71. #define COMP2_RX_WORDSIZE_0(r) (((r) & GENMASK(2, 0)) >> 0)
  72. /* Number of entries in WORDSIZE and DATA_WIDTH parameter registers */
  73. #define COMP_MAX_WORDSIZE (1 << 3)
  74. #define COMP_MAX_DATA_WIDTH (1 << 2)
  75. #define MAX_CHANNEL_NUM 8
  76. #define MIN_CHANNEL_NUM 2
  77. union dw_i2s_snd_dma_data {
  78. struct i2s_dma_data pd;
  79. struct snd_dmaengine_dai_dma_data dt;
  80. };
  81. struct dw_i2s_dev {
  82. void __iomem *i2s_base;
  83. struct clk *clk;
  84. int active;
  85. unsigned int capability;
  86. struct device *dev;
  87. /* data related to DMA transfers b/w i2s and DMAC */
  88. union dw_i2s_snd_dma_data play_dma_data;
  89. union dw_i2s_snd_dma_data capture_dma_data;
  90. struct i2s_clk_config_data config;
  91. int (*i2s_clk_cfg)(struct i2s_clk_config_data *config);
  92. };
  93. static inline void i2s_write_reg(void __iomem *io_base, int reg, u32 val)
  94. {
  95. writel(val, io_base + reg);
  96. }
  97. static inline u32 i2s_read_reg(void __iomem *io_base, int reg)
  98. {
  99. return readl(io_base + reg);
  100. }
  101. static inline void i2s_disable_channels(struct dw_i2s_dev *dev, u32 stream)
  102. {
  103. u32 i = 0;
  104. if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
  105. for (i = 0; i < 4; i++)
  106. i2s_write_reg(dev->i2s_base, TER(i), 0);
  107. } else {
  108. for (i = 0; i < 4; i++)
  109. i2s_write_reg(dev->i2s_base, RER(i), 0);
  110. }
  111. }
  112. static inline void i2s_clear_irqs(struct dw_i2s_dev *dev, u32 stream)
  113. {
  114. u32 i = 0;
  115. if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
  116. for (i = 0; i < 4; i++)
  117. i2s_write_reg(dev->i2s_base, TOR(i), 0);
  118. } else {
  119. for (i = 0; i < 4; i++)
  120. i2s_write_reg(dev->i2s_base, ROR(i), 0);
  121. }
  122. }
  123. static void i2s_start(struct dw_i2s_dev *dev,
  124. struct snd_pcm_substream *substream)
  125. {
  126. i2s_write_reg(dev->i2s_base, IER, 1);
  127. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  128. i2s_write_reg(dev->i2s_base, ITER, 1);
  129. else
  130. i2s_write_reg(dev->i2s_base, IRER, 1);
  131. i2s_write_reg(dev->i2s_base, CER, 1);
  132. }
  133. static void i2s_stop(struct dw_i2s_dev *dev,
  134. struct snd_pcm_substream *substream)
  135. {
  136. u32 i = 0, irq;
  137. i2s_clear_irqs(dev, substream->stream);
  138. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  139. i2s_write_reg(dev->i2s_base, ITER, 0);
  140. for (i = 0; i < 4; i++) {
  141. irq = i2s_read_reg(dev->i2s_base, IMR(i));
  142. i2s_write_reg(dev->i2s_base, IMR(i), irq | 0x30);
  143. }
  144. } else {
  145. i2s_write_reg(dev->i2s_base, IRER, 0);
  146. for (i = 0; i < 4; i++) {
  147. irq = i2s_read_reg(dev->i2s_base, IMR(i));
  148. i2s_write_reg(dev->i2s_base, IMR(i), irq | 0x03);
  149. }
  150. }
  151. if (!dev->active) {
  152. i2s_write_reg(dev->i2s_base, CER, 0);
  153. i2s_write_reg(dev->i2s_base, IER, 0);
  154. }
  155. }
  156. static int dw_i2s_startup(struct snd_pcm_substream *substream,
  157. struct snd_soc_dai *cpu_dai)
  158. {
  159. struct dw_i2s_dev *dev = snd_soc_dai_get_drvdata(cpu_dai);
  160. union dw_i2s_snd_dma_data *dma_data = NULL;
  161. if (!(dev->capability & DWC_I2S_RECORD) &&
  162. (substream->stream == SNDRV_PCM_STREAM_CAPTURE))
  163. return -EINVAL;
  164. if (!(dev->capability & DWC_I2S_PLAY) &&
  165. (substream->stream == SNDRV_PCM_STREAM_PLAYBACK))
  166. return -EINVAL;
  167. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  168. dma_data = &dev->play_dma_data;
  169. else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
  170. dma_data = &dev->capture_dma_data;
  171. snd_soc_dai_set_dma_data(cpu_dai, substream, (void *)dma_data);
  172. return 0;
  173. }
  174. static int dw_i2s_hw_params(struct snd_pcm_substream *substream,
  175. struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
  176. {
  177. struct dw_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  178. struct i2s_clk_config_data *config = &dev->config;
  179. u32 ccr, xfer_resolution, ch_reg, irq;
  180. int ret;
  181. switch (params_format(params)) {
  182. case SNDRV_PCM_FORMAT_S16_LE:
  183. config->data_width = 16;
  184. ccr = 0x00;
  185. xfer_resolution = 0x02;
  186. break;
  187. case SNDRV_PCM_FORMAT_S24_LE:
  188. config->data_width = 24;
  189. ccr = 0x08;
  190. xfer_resolution = 0x04;
  191. break;
  192. case SNDRV_PCM_FORMAT_S32_LE:
  193. config->data_width = 32;
  194. ccr = 0x10;
  195. xfer_resolution = 0x05;
  196. break;
  197. default:
  198. dev_err(dev->dev, "designware-i2s: unsuppted PCM fmt");
  199. return -EINVAL;
  200. }
  201. config->chan_nr = params_channels(params);
  202. switch (config->chan_nr) {
  203. case EIGHT_CHANNEL_SUPPORT:
  204. case SIX_CHANNEL_SUPPORT:
  205. case FOUR_CHANNEL_SUPPORT:
  206. case TWO_CHANNEL_SUPPORT:
  207. break;
  208. default:
  209. dev_err(dev->dev, "channel not supported\n");
  210. return -EINVAL;
  211. }
  212. i2s_disable_channels(dev, substream->stream);
  213. for (ch_reg = 0; ch_reg < (config->chan_nr / 2); ch_reg++) {
  214. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  215. i2s_write_reg(dev->i2s_base, TCR(ch_reg),
  216. xfer_resolution);
  217. i2s_write_reg(dev->i2s_base, TFCR(ch_reg), 0x02);
  218. irq = i2s_read_reg(dev->i2s_base, IMR(ch_reg));
  219. i2s_write_reg(dev->i2s_base, IMR(ch_reg), irq & ~0x30);
  220. i2s_write_reg(dev->i2s_base, TER(ch_reg), 1);
  221. } else {
  222. i2s_write_reg(dev->i2s_base, RCR(ch_reg),
  223. xfer_resolution);
  224. i2s_write_reg(dev->i2s_base, RFCR(ch_reg), 0x07);
  225. irq = i2s_read_reg(dev->i2s_base, IMR(ch_reg));
  226. i2s_write_reg(dev->i2s_base, IMR(ch_reg), irq & ~0x03);
  227. i2s_write_reg(dev->i2s_base, RER(ch_reg), 1);
  228. }
  229. }
  230. i2s_write_reg(dev->i2s_base, CCR, ccr);
  231. config->sample_rate = params_rate(params);
  232. if (dev->i2s_clk_cfg) {
  233. ret = dev->i2s_clk_cfg(config);
  234. if (ret < 0) {
  235. dev_err(dev->dev, "runtime audio clk config fail\n");
  236. return ret;
  237. }
  238. } else {
  239. u32 bitclk = config->sample_rate * config->data_width * 2;
  240. ret = clk_set_rate(dev->clk, bitclk);
  241. if (ret) {
  242. dev_err(dev->dev, "Can't set I2S clock rate: %d\n",
  243. ret);
  244. return ret;
  245. }
  246. }
  247. return 0;
  248. }
  249. static void dw_i2s_shutdown(struct snd_pcm_substream *substream,
  250. struct snd_soc_dai *dai)
  251. {
  252. snd_soc_dai_set_dma_data(dai, substream, NULL);
  253. }
  254. static int dw_i2s_prepare(struct snd_pcm_substream *substream,
  255. struct snd_soc_dai *dai)
  256. {
  257. struct dw_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  258. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  259. i2s_write_reg(dev->i2s_base, TXFFR, 1);
  260. else
  261. i2s_write_reg(dev->i2s_base, RXFFR, 1);
  262. return 0;
  263. }
  264. static int dw_i2s_trigger(struct snd_pcm_substream *substream,
  265. int cmd, struct snd_soc_dai *dai)
  266. {
  267. struct dw_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  268. int ret = 0;
  269. switch (cmd) {
  270. case SNDRV_PCM_TRIGGER_START:
  271. case SNDRV_PCM_TRIGGER_RESUME:
  272. case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  273. dev->active++;
  274. i2s_start(dev, substream);
  275. break;
  276. case SNDRV_PCM_TRIGGER_STOP:
  277. case SNDRV_PCM_TRIGGER_SUSPEND:
  278. case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  279. dev->active--;
  280. i2s_stop(dev, substream);
  281. break;
  282. default:
  283. ret = -EINVAL;
  284. break;
  285. }
  286. return ret;
  287. }
  288. static struct snd_soc_dai_ops dw_i2s_dai_ops = {
  289. .startup = dw_i2s_startup,
  290. .shutdown = dw_i2s_shutdown,
  291. .hw_params = dw_i2s_hw_params,
  292. .prepare = dw_i2s_prepare,
  293. .trigger = dw_i2s_trigger,
  294. };
  295. static const struct snd_soc_component_driver dw_i2s_component = {
  296. .name = "dw-i2s",
  297. };
  298. #ifdef CONFIG_PM
  299. static int dw_i2s_suspend(struct snd_soc_dai *dai)
  300. {
  301. struct dw_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  302. clk_disable(dev->clk);
  303. return 0;
  304. }
  305. static int dw_i2s_resume(struct snd_soc_dai *dai)
  306. {
  307. struct dw_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  308. clk_enable(dev->clk);
  309. return 0;
  310. }
  311. #else
  312. #define dw_i2s_suspend NULL
  313. #define dw_i2s_resume NULL
  314. #endif
  315. /*
  316. * The following tables allow a direct lookup of various parameters
  317. * defined in the I2S block's configuration in terms of sound system
  318. * parameters. Each table is sized to the number of entries possible
  319. * according to the number of configuration bits describing an I2S
  320. * block parameter.
  321. */
  322. /* Maximum bit resolution of a channel - not uniformly spaced */
  323. static const u32 fifo_width[COMP_MAX_WORDSIZE] = {
  324. 12, 16, 20, 24, 32, 0, 0, 0
  325. };
  326. /* Width of (DMA) bus */
  327. static const u32 bus_widths[COMP_MAX_DATA_WIDTH] = {
  328. DMA_SLAVE_BUSWIDTH_1_BYTE,
  329. DMA_SLAVE_BUSWIDTH_2_BYTES,
  330. DMA_SLAVE_BUSWIDTH_4_BYTES,
  331. DMA_SLAVE_BUSWIDTH_UNDEFINED
  332. };
  333. /* PCM format to support channel resolution */
  334. static const u32 formats[COMP_MAX_WORDSIZE] = {
  335. SNDRV_PCM_FMTBIT_S16_LE,
  336. SNDRV_PCM_FMTBIT_S16_LE,
  337. SNDRV_PCM_FMTBIT_S24_LE,
  338. SNDRV_PCM_FMTBIT_S24_LE,
  339. SNDRV_PCM_FMTBIT_S32_LE,
  340. 0,
  341. 0,
  342. 0
  343. };
  344. static int dw_configure_dai(struct dw_i2s_dev *dev,
  345. struct snd_soc_dai_driver *dw_i2s_dai,
  346. unsigned int rates)
  347. {
  348. /*
  349. * Read component parameter registers to extract
  350. * the I2S block's configuration.
  351. */
  352. u32 comp1 = i2s_read_reg(dev->i2s_base, I2S_COMP_PARAM_1);
  353. u32 comp2 = i2s_read_reg(dev->i2s_base, I2S_COMP_PARAM_2);
  354. u32 idx;
  355. if (COMP1_TX_ENABLED(comp1)) {
  356. dev_dbg(dev->dev, " designware: play supported\n");
  357. idx = COMP1_TX_WORDSIZE_0(comp1);
  358. if (WARN_ON(idx >= ARRAY_SIZE(formats)))
  359. return -EINVAL;
  360. dw_i2s_dai->playback.channels_min = MIN_CHANNEL_NUM;
  361. dw_i2s_dai->playback.channels_max =
  362. 1 << (COMP1_TX_CHANNELS(comp1) + 1);
  363. dw_i2s_dai->playback.formats = formats[idx];
  364. dw_i2s_dai->playback.rates = rates;
  365. }
  366. if (COMP1_RX_ENABLED(comp1)) {
  367. dev_dbg(dev->dev, "designware: record supported\n");
  368. idx = COMP2_RX_WORDSIZE_0(comp2);
  369. if (WARN_ON(idx >= ARRAY_SIZE(formats)))
  370. return -EINVAL;
  371. dw_i2s_dai->capture.channels_min = MIN_CHANNEL_NUM;
  372. dw_i2s_dai->capture.channels_max =
  373. 1 << (COMP1_RX_CHANNELS(comp1) + 1);
  374. dw_i2s_dai->capture.formats = formats[idx];
  375. dw_i2s_dai->capture.rates = rates;
  376. }
  377. return 0;
  378. }
  379. static int dw_configure_dai_by_pd(struct dw_i2s_dev *dev,
  380. struct snd_soc_dai_driver *dw_i2s_dai,
  381. struct resource *res,
  382. const struct i2s_platform_data *pdata)
  383. {
  384. u32 comp1 = i2s_read_reg(dev->i2s_base, I2S_COMP_PARAM_1);
  385. u32 idx = COMP1_APB_DATA_WIDTH(comp1);
  386. int ret;
  387. if (WARN_ON(idx >= ARRAY_SIZE(bus_widths)))
  388. return -EINVAL;
  389. ret = dw_configure_dai(dev, dw_i2s_dai, pdata->snd_rates);
  390. if (ret < 0)
  391. return ret;
  392. /* Set DMA slaves info */
  393. dev->play_dma_data.pd.data = pdata->play_dma_data;
  394. dev->capture_dma_data.pd.data = pdata->capture_dma_data;
  395. dev->play_dma_data.pd.addr = res->start + I2S_TXDMA;
  396. dev->capture_dma_data.pd.addr = res->start + I2S_RXDMA;
  397. dev->play_dma_data.pd.max_burst = 16;
  398. dev->capture_dma_data.pd.max_burst = 16;
  399. dev->play_dma_data.pd.addr_width = bus_widths[idx];
  400. dev->capture_dma_data.pd.addr_width = bus_widths[idx];
  401. dev->play_dma_data.pd.filter = pdata->filter;
  402. dev->capture_dma_data.pd.filter = pdata->filter;
  403. return 0;
  404. }
  405. static int dw_configure_dai_by_dt(struct dw_i2s_dev *dev,
  406. struct snd_soc_dai_driver *dw_i2s_dai,
  407. struct resource *res)
  408. {
  409. u32 comp1 = i2s_read_reg(dev->i2s_base, I2S_COMP_PARAM_1);
  410. u32 comp2 = i2s_read_reg(dev->i2s_base, I2S_COMP_PARAM_2);
  411. u32 fifo_depth = 1 << (1 + COMP1_FIFO_DEPTH_GLOBAL(comp1));
  412. u32 idx = COMP1_APB_DATA_WIDTH(comp1);
  413. u32 idx2;
  414. int ret;
  415. if (WARN_ON(idx >= ARRAY_SIZE(bus_widths)))
  416. return -EINVAL;
  417. ret = dw_configure_dai(dev, dw_i2s_dai, SNDRV_PCM_RATE_8000_192000);
  418. if (ret < 0)
  419. return ret;
  420. if (COMP1_TX_ENABLED(comp1)) {
  421. idx2 = COMP1_TX_WORDSIZE_0(comp1);
  422. dev->capability |= DWC_I2S_PLAY;
  423. dev->play_dma_data.dt.addr = res->start + I2S_TXDMA;
  424. dev->play_dma_data.dt.addr_width = bus_widths[idx];
  425. dev->play_dma_data.dt.chan_name = "TX";
  426. dev->play_dma_data.dt.fifo_size = fifo_depth *
  427. (fifo_width[idx2]) >> 8;
  428. dev->play_dma_data.dt.maxburst = 16;
  429. }
  430. if (COMP1_RX_ENABLED(comp1)) {
  431. idx2 = COMP2_RX_WORDSIZE_0(comp2);
  432. dev->capability |= DWC_I2S_RECORD;
  433. dev->capture_dma_data.dt.addr = res->start + I2S_RXDMA;
  434. dev->capture_dma_data.dt.addr_width = bus_widths[idx];
  435. dev->capture_dma_data.dt.chan_name = "RX";
  436. dev->capture_dma_data.dt.fifo_size = fifo_depth *
  437. (fifo_width[idx2] >> 8);
  438. dev->capture_dma_data.dt.maxburst = 16;
  439. }
  440. return 0;
  441. }
  442. static int dw_i2s_probe(struct platform_device *pdev)
  443. {
  444. const struct i2s_platform_data *pdata = pdev->dev.platform_data;
  445. struct dw_i2s_dev *dev;
  446. struct resource *res;
  447. int ret;
  448. struct snd_soc_dai_driver *dw_i2s_dai;
  449. dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL);
  450. if (!dev) {
  451. dev_warn(&pdev->dev, "kzalloc fail\n");
  452. return -ENOMEM;
  453. }
  454. dw_i2s_dai = devm_kzalloc(&pdev->dev, sizeof(*dw_i2s_dai), GFP_KERNEL);
  455. if (!dw_i2s_dai)
  456. return -ENOMEM;
  457. dw_i2s_dai->ops = &dw_i2s_dai_ops;
  458. dw_i2s_dai->suspend = dw_i2s_suspend;
  459. dw_i2s_dai->resume = dw_i2s_resume;
  460. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  461. dev->i2s_base = devm_ioremap_resource(&pdev->dev, res);
  462. if (IS_ERR(dev->i2s_base))
  463. return PTR_ERR(dev->i2s_base);
  464. dev->dev = &pdev->dev;
  465. if (pdata) {
  466. ret = dw_configure_dai_by_pd(dev, dw_i2s_dai, res, pdata);
  467. if (ret < 0)
  468. return ret;
  469. dev->capability = pdata->cap;
  470. dev->i2s_clk_cfg = pdata->i2s_clk_cfg;
  471. if (!dev->i2s_clk_cfg) {
  472. dev_err(&pdev->dev, "no clock configure method\n");
  473. return -ENODEV;
  474. }
  475. dev->clk = devm_clk_get(&pdev->dev, NULL);
  476. } else {
  477. ret = dw_configure_dai_by_dt(dev, dw_i2s_dai, res);
  478. if (ret < 0)
  479. return ret;
  480. dev->clk = devm_clk_get(&pdev->dev, "i2sclk");
  481. }
  482. if (IS_ERR(dev->clk))
  483. return PTR_ERR(dev->clk);
  484. ret = clk_prepare_enable(dev->clk);
  485. if (ret < 0)
  486. return ret;
  487. dev_set_drvdata(&pdev->dev, dev);
  488. ret = devm_snd_soc_register_component(&pdev->dev, &dw_i2s_component,
  489. dw_i2s_dai, 1);
  490. if (ret != 0) {
  491. dev_err(&pdev->dev, "not able to register dai\n");
  492. goto err_clk_disable;
  493. }
  494. if (!pdata) {
  495. ret = devm_snd_dmaengine_pcm_register(&pdev->dev, NULL, 0);
  496. if (ret) {
  497. dev_err(&pdev->dev,
  498. "Could not register PCM: %d\n", ret);
  499. goto err_clk_disable;
  500. }
  501. }
  502. return 0;
  503. err_clk_disable:
  504. clk_disable_unprepare(dev->clk);
  505. return ret;
  506. }
  507. static int dw_i2s_remove(struct platform_device *pdev)
  508. {
  509. struct dw_i2s_dev *dev = dev_get_drvdata(&pdev->dev);
  510. clk_disable_unprepare(dev->clk);
  511. return 0;
  512. }
  513. #ifdef CONFIG_OF
  514. static const struct of_device_id dw_i2s_of_match[] = {
  515. { .compatible = "snps,designware-i2s", },
  516. {},
  517. };
  518. MODULE_DEVICE_TABLE(of, dw_i2s_of_match);
  519. #endif
  520. static struct platform_driver dw_i2s_driver = {
  521. .probe = dw_i2s_probe,
  522. .remove = dw_i2s_remove,
  523. .driver = {
  524. .name = "designware-i2s",
  525. .of_match_table = of_match_ptr(dw_i2s_of_match),
  526. },
  527. };
  528. module_platform_driver(dw_i2s_driver);
  529. MODULE_AUTHOR("Rajeev Kumar <rajeevkumar.linux@gmail.com>");
  530. MODULE_DESCRIPTION("DESIGNWARE I2S SoC Interface");
  531. MODULE_LICENSE("GPL");
  532. MODULE_ALIAS("platform:designware_i2s");