0055-asoc-add-mt7620-support.patch 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766
  1. From 241188942603dc73f62cf2553c53cae2235c9957 Mon Sep 17 00:00:00 2001
  2. From: John Crispin <blogic@openwrt.org>
  3. Date: Sun, 27 Jul 2014 09:31:47 +0100
  4. Subject: [PATCH 55/57] asoc: add mt7620 support
  5. Signed-off-by: John Crispin <blogic@openwrt.org>
  6. ---
  7. arch/mips/ralink/of.c | 2 +
  8. sound/soc/Kconfig | 1 +
  9. sound/soc/Makefile | 1 +
  10. sound/soc/ralink/Kconfig | 15 ++
  11. sound/soc/ralink/Makefile | 11 +
  12. sound/soc/ralink/mt7620-i2s.c | 466 ++++++++++++++++++++++++++++++++++++++
  13. sound/soc/ralink/mt7620-wm8960.c | 125 ++++++++++
  14. sound/soc/soc-io.c | 10 -
  15. 8 files changed, 621 insertions(+), 10 deletions(-)
  16. create mode 100644 sound/soc/ralink/Kconfig
  17. create mode 100644 sound/soc/ralink/Makefile
  18. create mode 100644 sound/soc/ralink/mt7620-i2s.c
  19. create mode 100644 sound/soc/ralink/mt7620-wm8960.c
  20. --- a/arch/mips/ralink/of.c
  21. +++ b/arch/mips/ralink/of.c
  22. @@ -15,6 +15,7 @@
  23. #include <linux/of_fdt.h>
  24. #include <linux/kernel.h>
  25. #include <linux/bootmem.h>
  26. +#include <linux/module.h>
  27. #include <linux/of_platform.h>
  28. #include <linux/of_address.h>
  29. @@ -26,6 +27,7 @@
  30. #include "common.h"
  31. __iomem void *rt_sysc_membase;
  32. +EXPORT_SYMBOL(rt_sysc_membase);
  33. __iomem void *rt_memc_membase;
  34. __iomem void *plat_of_remap_node(const char *node)
  35. --- a/sound/soc/Kconfig
  36. +++ b/sound/soc/Kconfig
  37. @@ -48,6 +48,7 @@ source "sound/soc/intel/Kconfig"
  38. source "sound/soc/mxs/Kconfig"
  39. source "sound/soc/pxa/Kconfig"
  40. source "sound/soc/rockchip/Kconfig"
  41. +source "sound/soc/ralink/Kconfig"
  42. source "sound/soc/samsung/Kconfig"
  43. source "sound/soc/sh/Kconfig"
  44. source "sound/soc/sirf/Kconfig"
  45. --- a/sound/soc/Makefile
  46. +++ b/sound/soc/Makefile
  47. @@ -25,6 +25,7 @@ obj-$(CONFIG_SND_SOC) += omap/
  48. obj-$(CONFIG_SND_SOC) += kirkwood/
  49. obj-$(CONFIG_SND_SOC) += pxa/
  50. obj-$(CONFIG_SND_SOC) += rockchip/
  51. +obj-$(CONFIG_SND_SOC) += ralink/
  52. obj-$(CONFIG_SND_SOC) += samsung/
  53. obj-$(CONFIG_SND_SOC) += sh/
  54. obj-$(CONFIG_SND_SOC) += sirf/
  55. --- /dev/null
  56. +++ b/sound/soc/ralink/Kconfig
  57. @@ -0,0 +1,15 @@
  58. +config SND_MT7620_SOC_I2S
  59. + depends on SOC_MT7620 && SND_SOC
  60. + select SND_SOC_GENERIC_DMAENGINE_PCM
  61. + tristate "SoC Audio (I2S protocol) for Ralink MT7620 SoC"
  62. + help
  63. + Say Y if you want to use I2S protocol and I2S codec on Ingenic MT7620
  64. + based boards.
  65. +
  66. +config SND_MT7620_SOC_WM8960
  67. + tristate "SoC Audio support for Ralink WM8960"
  68. + select SND_MT7620_SOC_I2S
  69. + select SND_SOC_WM8960
  70. + help
  71. + Say Y if you want to add support for ASoC audio on the Qi LB60 board
  72. + a.k.a Qi Ben NanoNote.
  73. --- /dev/null
  74. +++ b/sound/soc/ralink/Makefile
  75. @@ -0,0 +1,11 @@
  76. +#
  77. +# Jz4740 Platform Support
  78. +#
  79. +snd-soc-mt7620-i2s-objs := mt7620-i2s.o
  80. +
  81. +obj-$(CONFIG_SND_MT7620_SOC_I2S) += snd-soc-mt7620-i2s.o
  82. +
  83. +# Jz4740 Machine Support
  84. +snd-soc-mt7620-wm8960-objs := mt7620-wm8960.o
  85. +
  86. +obj-$(CONFIG_SND_MT7620_SOC_WM8960) += snd-soc-mt7620-wm8960.o
  87. --- /dev/null
  88. +++ b/sound/soc/ralink/mt7620-i2s.c
  89. @@ -0,0 +1,436 @@
  90. +/*
  91. + * Copyright (C) 2010, Lars-Peter Clausen <lars@metafoo.de>
  92. + *
  93. + * This program is free software; you can redistribute it and/or modify it
  94. + * under the terms of the GNU General Public License as published by the
  95. + * Free Software Foundation; either version 2 of the License, or (at your
  96. + * option) any later version.
  97. + *
  98. + * You should have received a copy of the GNU General Public License along
  99. + * with this program; if not, write to the Free Software Foundation, Inc.,
  100. + * 675 Mass Ave, Cambridge, MA 02139, USA.
  101. + *
  102. + */
  103. +
  104. +#include <linux/init.h>
  105. +#include <linux/io.h>
  106. +#include <linux/kernel.h>
  107. +#include <linux/module.h>
  108. +#include <linux/platform_device.h>
  109. +#include <linux/slab.h>
  110. +
  111. +#include <linux/delay.h>
  112. +
  113. +#include <linux/dma-mapping.h>
  114. +
  115. +#include <sound/core.h>
  116. +#include <sound/pcm.h>
  117. +#include <sound/pcm_params.h>
  118. +#include <sound/soc.h>
  119. +#include <sound/initval.h>
  120. +#include <sound/dmaengine_pcm.h>
  121. +
  122. +#include <ralink_regs.h>
  123. +
  124. +#define I2S_REG_CFG0 0x00
  125. +#define I2S_REG_CFG0_EN BIT(31)
  126. +#define I2S_REG_CFG0_DMA_EN BIT(30)
  127. +#define I2S_REG_CFG0_BYTE_SWAP BIT(28)
  128. +#define I2S_REG_CFG0_TX_EN BIT(24)
  129. +#define I2S_REG_CFG0_RX_EN BIT(20)
  130. +#define I2S_REG_CFG0_SLAVE BIT(16)
  131. +#define I2S_REG_CFG0_RX_THRES 12
  132. +#define I2S_REG_CFG0_TX_THRES 4
  133. +#define I2S_REG_CFG0_DFT_THRES (4 << I2S_REG_CFG0_RX_THRES) | \
  134. + (4 << I2S_REG_CFG0_TX_THRES)
  135. +
  136. +#define I2S_REG_INT_STATUS 0x04
  137. +#define I2S_REG_INT_EN 0x08
  138. +#define I2S_REG_FF_STATUS 0x0c
  139. +#define I2S_REG_WREG 0x10
  140. +#define I2S_REG_RREG 0x14
  141. +#define I2S_REG_CFG1 0x18
  142. +
  143. +#define I2S_REG_DIVCMP 0x20
  144. +#define I2S_REG_DIVINT 0x24
  145. +#define I2S_REG_CLK_EN BIT(31)
  146. +
  147. +struct mt7620_i2s {
  148. + struct resource *mem;
  149. + void __iomem *base;
  150. + dma_addr_t phys_base;
  151. +
  152. + struct snd_dmaengine_dai_dma_data playback_dma_data;
  153. + struct snd_dmaengine_dai_dma_data capture_dma_data;
  154. +};
  155. +
  156. +static inline uint32_t mt7620_i2s_read(const struct mt7620_i2s *i2s,
  157. + unsigned int reg)
  158. +{
  159. + return readl(i2s->base + reg);
  160. +}
  161. +
  162. +static inline void mt7620_i2s_write(const struct mt7620_i2s *i2s,
  163. + unsigned int reg, uint32_t value)
  164. +{
  165. + //printk("i2s --> %p = 0x%08X\n", i2s->base + reg, value);
  166. + writel(value, i2s->base + reg);
  167. +}
  168. +
  169. +static int mt7620_i2s_startup(struct snd_pcm_substream *substream,
  170. + struct snd_soc_dai *dai)
  171. +{
  172. + struct mt7620_i2s *i2s = snd_soc_dai_get_drvdata(dai);
  173. + uint32_t cfg;
  174. +
  175. + if (dai->active)
  176. + return 0;
  177. +
  178. + cfg = mt7620_i2s_read(i2s, I2S_REG_CFG0);
  179. + cfg |= I2S_REG_CFG0_EN;
  180. + mt7620_i2s_write(i2s, I2S_REG_CFG0, cfg);
  181. +
  182. + return 0;
  183. +}
  184. +
  185. +static void mt7620_i2s_shutdown(struct snd_pcm_substream *substream,
  186. + struct snd_soc_dai *dai)
  187. +{
  188. + struct mt7620_i2s *i2s = snd_soc_dai_get_drvdata(dai);
  189. + uint32_t cfg;
  190. +
  191. + if (dai->active)
  192. + return;
  193. +
  194. + cfg = mt7620_i2s_read(i2s, I2S_REG_CFG0);
  195. + cfg &= ~I2S_REG_CFG0_EN;
  196. + mt7620_i2s_write(i2s, I2S_REG_CFG0, cfg);
  197. +}
  198. +
  199. +static int mt7620_i2s_trigger(struct snd_pcm_substream *substream, int cmd,
  200. + struct snd_soc_dai *dai)
  201. +{
  202. + struct mt7620_i2s *i2s = snd_soc_dai_get_drvdata(dai);
  203. +
  204. + uint32_t cfg;
  205. + uint32_t mask;
  206. +
  207. + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  208. + mask = I2S_REG_CFG0_TX_EN;
  209. + else
  210. + mask = I2S_REG_CFG0_RX_EN;
  211. +
  212. + cfg = mt7620_i2s_read(i2s, I2S_REG_CFG0);
  213. +
  214. + switch (cmd) {
  215. + case SNDRV_PCM_TRIGGER_START:
  216. + case SNDRV_PCM_TRIGGER_RESUME:
  217. + case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  218. + cfg |= mask;
  219. + break;
  220. + case SNDRV_PCM_TRIGGER_STOP:
  221. + case SNDRV_PCM_TRIGGER_SUSPEND:
  222. + case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  223. + cfg &= ~mask;
  224. + break;
  225. + default:
  226. + return -EINVAL;
  227. + }
  228. +
  229. + if (cfg & (I2S_REG_CFG0_TX_EN | I2S_REG_CFG0_RX_EN))
  230. + cfg |= I2S_REG_CFG0_DMA_EN;
  231. + else
  232. + cfg &= ~I2S_REG_CFG0_DMA_EN;
  233. +
  234. + mt7620_i2s_write(i2s, I2S_REG_CFG0, cfg);
  235. +
  236. + return 0;
  237. +}
  238. +
  239. +static int mt7620_i2s_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
  240. +{
  241. + struct mt7620_i2s *i2s = snd_soc_dai_get_drvdata(dai);
  242. + uint32_t cfg;
  243. +
  244. + cfg = mt7620_i2s_read(i2s, I2S_REG_CFG0);
  245. +
  246. + switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  247. + case SND_SOC_DAIFMT_CBS_CFS:
  248. + cfg |= I2S_REG_CFG0_SLAVE;
  249. + break;
  250. + case SND_SOC_DAIFMT_CBM_CFM:
  251. + cfg &= ~I2S_REG_CFG0_SLAVE;
  252. + break;
  253. + case SND_SOC_DAIFMT_CBM_CFS:
  254. + default:
  255. + return -EINVAL;
  256. + }
  257. +
  258. + switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  259. + case SND_SOC_DAIFMT_I2S:
  260. + case SND_SOC_DAIFMT_MSB:
  261. + cfg &= ~I2S_REG_CFG0_BYTE_SWAP;
  262. + break;
  263. + case SND_SOC_DAIFMT_LSB:
  264. + cfg |= I2S_REG_CFG0_BYTE_SWAP;
  265. + break;
  266. + default:
  267. + return -EINVAL;
  268. + }
  269. +
  270. + switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
  271. + case SND_SOC_DAIFMT_NB_NF:
  272. + break;
  273. + default:
  274. + return -EINVAL;
  275. + }
  276. +
  277. + mt7620_i2s_write(i2s, I2S_REG_CFG0, cfg);
  278. +
  279. + return 0;
  280. +}
  281. +
  282. +static int mt7620_i2s_hw_params(struct snd_pcm_substream *substream,
  283. + struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
  284. +{
  285. +
  286. + return 0;
  287. +}
  288. +
  289. +unsigned long i2sMaster_inclk_int[11] = {
  290. + 78, 56, 52, 39, 28, 26, 19, 14, 13, 9, 6};
  291. +unsigned long i2sMaster_inclk_comp[11] = {
  292. + 64, 352, 42, 32, 176, 21, 272, 88, 10, 455, 261};
  293. +
  294. +
  295. +static int mt7620_i2s_set_sysclk(struct snd_soc_dai *dai, int clk_id,
  296. + unsigned int freq, int dir)
  297. +{
  298. + struct mt7620_i2s *i2s = snd_soc_dai_get_drvdata(dai);
  299. +
  300. + printk("Internal REFCLK with fractional division\n");
  301. +
  302. + mt7620_i2s_write(i2s, I2S_REG_DIVINT, i2sMaster_inclk_int[7]);
  303. + mt7620_i2s_write(i2s, I2S_REG_DIVCMP,
  304. + i2sMaster_inclk_comp[7] | I2S_REG_CLK_EN);
  305. +
  306. +/* struct mt7620_i2s *i2s = snd_soc_dai_get_drvdata(dai);
  307. + struct clk *parent;
  308. + int ret = 0;
  309. +
  310. + switch (clk_id) {
  311. + case JZ4740_I2S_CLKSRC_EXT:
  312. + parent = clk_get(NULL, "ext");
  313. + clk_set_parent(i2s->clk_i2s, parent);
  314. + break;
  315. + case JZ4740_I2S_CLKSRC_PLL:
  316. + parent = clk_get(NULL, "pll half");
  317. + clk_set_parent(i2s->clk_i2s, parent);
  318. + ret = clk_set_rate(i2s->clk_i2s, freq);
  319. + break;
  320. + default:
  321. + return -EINVAL;
  322. + }
  323. + clk_put(parent);
  324. +
  325. + return ret;*/
  326. + return 0;
  327. +}
  328. +
  329. +static void mt7620_i2c_init_pcm_config(struct mt7620_i2s *i2s)
  330. +{
  331. + struct snd_dmaengine_dai_dma_data *dma_data;
  332. +
  333. + /* Playback */
  334. + dma_data = &i2s->playback_dma_data;
  335. + dma_data->maxburst = 16;
  336. + dma_data->slave_id = 2; //JZ4740_DMA_TYPE_AIC_TRANSMIT;
  337. + dma_data->addr = i2s->phys_base + I2S_REG_WREG;
  338. +
  339. + /* Capture */
  340. + dma_data = &i2s->capture_dma_data;
  341. + dma_data->maxburst = 16;
  342. + dma_data->slave_id = 3; //JZ4740_DMA_TYPE_AIC_RECEIVE;
  343. + dma_data->addr = i2s->phys_base + I2S_REG_RREG;
  344. +}
  345. +
  346. +static int mt7620_i2s_dai_probe(struct snd_soc_dai *dai)
  347. +{
  348. + struct mt7620_i2s *i2s = snd_soc_dai_get_drvdata(dai);
  349. + uint32_t data;
  350. +
  351. + mt7620_i2c_init_pcm_config(i2s);
  352. + dai->playback_dma_data = &i2s->playback_dma_data;
  353. + dai->capture_dma_data = &i2s->capture_dma_data;
  354. +
  355. + /* set share pins to i2s/gpio mode and i2c mode */
  356. + data = rt_sysc_r32(0x60);
  357. + data &= 0xFFFFFFE2;
  358. + data |= 0x00000018;
  359. + rt_sysc_w32(data, 0x60);
  360. +
  361. + printk("Internal REFCLK with fractional division\n");
  362. +
  363. + mt7620_i2s_write(i2s, I2S_REG_CFG0, I2S_REG_CFG0_DFT_THRES);
  364. + mt7620_i2s_write(i2s, I2S_REG_CFG1, 0);
  365. + mt7620_i2s_write(i2s, I2S_REG_INT_EN, 0);
  366. +
  367. + mt7620_i2s_write(i2s, I2S_REG_DIVINT, i2sMaster_inclk_int[7]);
  368. + mt7620_i2s_write(i2s, I2S_REG_DIVCMP,
  369. + i2sMaster_inclk_comp[7] | I2S_REG_CLK_EN);
  370. +
  371. + return 0;
  372. +}
  373. +
  374. +static int mt7620_i2s_dai_remove(struct snd_soc_dai *dai)
  375. +{
  376. + return 0;
  377. +}
  378. +
  379. +static const struct snd_soc_dai_ops mt7620_i2s_dai_ops = {
  380. + .startup = mt7620_i2s_startup,
  381. + .shutdown = mt7620_i2s_shutdown,
  382. + .trigger = mt7620_i2s_trigger,
  383. + .hw_params = mt7620_i2s_hw_params,
  384. + .set_fmt = mt7620_i2s_set_fmt,
  385. + .set_sysclk = mt7620_i2s_set_sysclk,
  386. +};
  387. +
  388. +#define JZ4740_I2S_FMTS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
  389. + SNDRV_PCM_FMTBIT_S24_LE)
  390. +
  391. +static struct snd_soc_dai_driver mt7620_i2s_dai = {
  392. + .probe = mt7620_i2s_dai_probe,
  393. + .remove = mt7620_i2s_dai_remove,
  394. + .playback = {
  395. + .channels_min = 1,
  396. + .channels_max = 2,
  397. + .rates = SNDRV_PCM_RATE_8000_48000,
  398. + .formats = JZ4740_I2S_FMTS,
  399. + },
  400. + .capture = {
  401. + .channels_min = 2,
  402. + .channels_max = 2,
  403. + .rates = SNDRV_PCM_RATE_8000_48000,
  404. + .formats = JZ4740_I2S_FMTS,
  405. + },
  406. + .symmetric_rates = 1,
  407. + .ops = &mt7620_i2s_dai_ops,
  408. +};
  409. +
  410. +static const struct snd_pcm_hardware mt7620_pcm_hardware = {
  411. + .info = SNDRV_PCM_INFO_MMAP |
  412. + SNDRV_PCM_INFO_MMAP_VALID |
  413. + SNDRV_PCM_INFO_INTERLEAVED |
  414. + SNDRV_PCM_INFO_BLOCK_TRANSFER,
  415. + .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S8,
  416. + .period_bytes_min = PAGE_SIZE,
  417. + .period_bytes_max = 64 * 1024,
  418. + .periods_min = 2,
  419. + .periods_max = 128,
  420. + .buffer_bytes_max = 128 * 1024,
  421. + .fifo_size = 32,
  422. +};
  423. +
  424. +static const struct snd_dmaengine_pcm_config mt7620_dmaengine_pcm_config = {
  425. + .prepare_slave_config = snd_dmaengine_pcm_prepare_slave_config,
  426. + .pcm_hardware = &mt7620_pcm_hardware,
  427. + .prealloc_buffer_size = 256 * PAGE_SIZE,
  428. +};
  429. +
  430. +static const struct snd_soc_component_driver mt7620_i2s_component = {
  431. + .name = "mt7620-i2s",
  432. +};
  433. +
  434. +static int mt7620_i2s_dev_probe(struct platform_device *pdev)
  435. +{
  436. + struct mt7620_i2s *i2s;
  437. + int ret;
  438. +
  439. + snd_dmaengine_pcm_register(&pdev->dev,
  440. + &mt7620_dmaengine_pcm_config,
  441. + SND_DMAENGINE_PCM_FLAG_COMPAT);
  442. +
  443. + i2s = kzalloc(sizeof(*i2s), GFP_KERNEL);
  444. + if (!i2s)
  445. + return -ENOMEM;
  446. +
  447. + i2s->mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  448. + if (!i2s->mem) {
  449. + ret = -ENOENT;
  450. + goto err_free;
  451. + }
  452. +
  453. + i2s->mem = request_mem_region(i2s->mem->start, resource_size(i2s->mem),
  454. + pdev->name);
  455. + if (!i2s->mem) {
  456. + ret = -EBUSY;
  457. + goto err_free;
  458. + }
  459. +
  460. + i2s->base = ioremap_nocache(i2s->mem->start, resource_size(i2s->mem));
  461. + if (!i2s->base) {
  462. + ret = -EBUSY;
  463. + goto err_release_mem_region;
  464. + }
  465. +
  466. + i2s->phys_base = i2s->mem->start;
  467. +
  468. + platform_set_drvdata(pdev, i2s);
  469. + ret = snd_soc_register_component(&pdev->dev, &mt7620_i2s_component,
  470. + &mt7620_i2s_dai, 1);
  471. +
  472. + if (!ret) {
  473. + dev_err(&pdev->dev, "loaded\n");
  474. + return ret;
  475. + }
  476. +
  477. + dev_err(&pdev->dev, "Failed to register DAI\n");
  478. + iounmap(i2s->base);
  479. +
  480. +err_release_mem_region:
  481. + release_mem_region(i2s->mem->start, resource_size(i2s->mem));
  482. +err_free:
  483. + kfree(i2s);
  484. +
  485. + return ret;
  486. +}
  487. +
  488. +static int mt7620_i2s_dev_remove(struct platform_device *pdev)
  489. +{
  490. + struct mt7620_i2s *i2s = platform_get_drvdata(pdev);
  491. +
  492. + snd_soc_unregister_component(&pdev->dev);
  493. +
  494. + iounmap(i2s->base);
  495. + release_mem_region(i2s->mem->start, resource_size(i2s->mem));
  496. +
  497. + kfree(i2s);
  498. +
  499. + snd_dmaengine_pcm_unregister(&pdev->dev);
  500. +
  501. + return 0;
  502. +}
  503. +
  504. +static const struct of_device_id mt7620_i2s_match[] = {
  505. + { .compatible = "ralink,mt7620a-i2s" },
  506. + {},
  507. +};
  508. +MODULE_DEVICE_TABLE(of, mt7620_i2s_match);
  509. +
  510. +static struct platform_driver mt7620_i2s_driver = {
  511. + .probe = mt7620_i2s_dev_probe,
  512. + .remove = mt7620_i2s_dev_remove,
  513. + .driver = {
  514. + .name = "mt7620-i2s",
  515. + .owner = THIS_MODULE,
  516. + .of_match_table = mt7620_i2s_match,
  517. + },
  518. +};
  519. +
  520. +module_platform_driver(mt7620_i2s_driver);
  521. +
  522. +MODULE_AUTHOR("Lars-Peter Clausen, <lars@metafoo.de>");
  523. +MODULE_DESCRIPTION("Ingenic JZ4740 SoC I2S driver");
  524. +MODULE_LICENSE("GPL");
  525. +MODULE_ALIAS("platform:mt7620-i2s");
  526. --- /dev/null
  527. +++ b/sound/soc/ralink/mt7620-wm8960.c
  528. @@ -0,0 +1,233 @@
  529. +/*
  530. + * Copyright 2013 Freescale Semiconductor, Inc.
  531. + *
  532. + * Based on mt7620-sgtl5000.c
  533. + * Copyright 2012 Freescale Semiconductor, Inc.
  534. + * Copyright 2012 Linaro Ltd.
  535. + *
  536. + * The code contained herein is licensed under the GNU General Public
  537. + * License. You may obtain a copy of the GNU General Public License
  538. + * Version 2 or later at the following locations:
  539. + *
  540. + * http://www.opensource.org/licenses/gpl-license.html
  541. + * http://www.gnu.org/copyleft/gpl.html
  542. + */
  543. +
  544. +#include <linux/module.h>
  545. +#include <linux/of_platform.h>
  546. +#include <linux/i2c.h>
  547. +#include <linux/slab.h>
  548. +#include <sound/soc.h>
  549. +#include <sound/pcm_params.h>
  550. +#include <sound/soc-dapm.h>
  551. +#include <linux/pinctrl/consumer.h>
  552. +
  553. +#include "../codecs/wm8960.h"
  554. +
  555. +#define DAI_NAME_SIZE 32
  556. +
  557. +struct mt7620_wm8960_data {
  558. + struct snd_soc_dai_link dai;
  559. + struct snd_soc_card card;
  560. + char codec_dai_name[DAI_NAME_SIZE];
  561. + char platform_name[DAI_NAME_SIZE];
  562. + unsigned int clk_frequency;
  563. +};
  564. +
  565. +struct mt7620_priv {
  566. + struct platform_device *pdev;
  567. +};
  568. +static struct mt7620_priv card_priv;
  569. +
  570. +static const struct snd_soc_dapm_widget mt7620_wm8960_dapm_widgets[] = {
  571. + SND_SOC_DAPM_HP("Headphone Jack", NULL),
  572. + SND_SOC_DAPM_SPK("Ext Spk", NULL),
  573. + SND_SOC_DAPM_MIC("AMIC", NULL),
  574. + SND_SOC_DAPM_MIC("DMIC", NULL),
  575. +};
  576. +
  577. +static int sample_rate = 44100;
  578. +static snd_pcm_format_t sample_format = SNDRV_PCM_FORMAT_S16_LE;
  579. +
  580. +static int mt7620_hifi_hw_params(struct snd_pcm_substream *substream,
  581. + struct snd_pcm_hw_params *params)
  582. +{
  583. + sample_rate = params_rate(params);
  584. + sample_format = params_format(params);
  585. +
  586. + return 0;
  587. +}
  588. +
  589. +static struct snd_soc_ops mt7620_hifi_ops = {
  590. + .hw_params = mt7620_hifi_hw_params,
  591. +};
  592. +
  593. +static int mt7620_wm8960_set_bias_level(struct snd_soc_card *card,
  594. + struct snd_soc_dapm_context *dapm,
  595. + enum snd_soc_bias_level level)
  596. +{
  597. + struct snd_soc_dai *codec_dai = card->rtd[0].codec_dai;
  598. + struct mt7620_priv *priv = &card_priv;
  599. + struct mt7620_wm8960_data *data = snd_soc_card_get_drvdata(card);
  600. + struct device *dev = &priv->pdev->dev;
  601. + int ret;
  602. +
  603. + if (dapm->dev != codec_dai->dev)
  604. + return 0;
  605. +
  606. + switch (level) {
  607. + case SND_SOC_BIAS_PREPARE:
  608. + if (dapm->bias_level == SND_SOC_BIAS_STANDBY) {
  609. + }
  610. + break;
  611. +
  612. + case SND_SOC_BIAS_STANDBY:
  613. + if (dapm->bias_level == SND_SOC_BIAS_PREPARE) {
  614. + ret = snd_soc_dai_set_sysclk(codec_dai,
  615. + WM8960_SYSCLK_MCLK, data->clk_frequency,
  616. + SND_SOC_CLOCK_IN);
  617. + if (ret < 0) {
  618. + dev_err(dev,
  619. + "failed to switch away from FLL: %d\n",
  620. + ret);
  621. + return ret;
  622. + }
  623. + }
  624. + break;
  625. +
  626. + default:
  627. + break;
  628. + }
  629. +
  630. + return 0;
  631. +}
  632. +
  633. +static int mt7620_wm8960_late_probe(struct snd_soc_card *card)
  634. +{
  635. + struct snd_soc_dai *codec_dai = card->rtd[0].codec_dai;
  636. + struct mt7620_priv *priv = &card_priv;
  637. + struct mt7620_wm8960_data *data = snd_soc_card_get_drvdata(card);
  638. + struct device *dev = &priv->pdev->dev;
  639. + int ret;
  640. +
  641. + ret = snd_soc_dai_set_sysclk(codec_dai, WM8960_SYSCLK_MCLK,
  642. + data->clk_frequency, SND_SOC_CLOCK_IN);
  643. + if (ret < 0)
  644. + dev_err(dev, "failed to set sysclk in %s\n", __func__);
  645. +
  646. + return ret;
  647. +}
  648. +
  649. +static int mt7620_wm8960_probe(struct platform_device *pdev)
  650. +{
  651. + struct device_node *i2s_np, *codec_np;
  652. + struct platform_device *i2s_pdev;
  653. + struct mt7620_priv *priv = &card_priv;
  654. + struct i2c_client *codec_dev;
  655. + struct mt7620_wm8960_data *data;
  656. + int ret;
  657. +
  658. + priv->pdev = pdev;
  659. +
  660. + i2s_np = of_parse_phandle(pdev->dev.of_node, "i2s-controller", 0);
  661. + codec_np = of_parse_phandle(pdev->dev.of_node, "audio-codec", 0);
  662. + if (!i2s_np || !codec_np) {
  663. + dev_err(&pdev->dev, "phandle missing or invalid\n");
  664. + ret = -EINVAL;
  665. + goto fail;
  666. + }
  667. +
  668. + i2s_pdev = of_find_device_by_node(i2s_np);
  669. + if (!i2s_pdev) {
  670. + dev_err(&pdev->dev, "failed to find SSI platform device\n");
  671. + ret = -EINVAL;
  672. + goto fail;
  673. + }
  674. + codec_dev = of_find_i2c_device_by_node(codec_np);
  675. + if (!codec_dev || !codec_dev->dev.driver) {
  676. + dev_err(&pdev->dev, "failed to find codec platform device\n");
  677. + ret = -EINVAL;
  678. + goto fail;
  679. + }
  680. +
  681. + data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
  682. + if (!data) {
  683. + ret = -ENOMEM;
  684. + goto fail;
  685. + }
  686. +
  687. + data->clk_frequency = 12000000;
  688. + data->dai.name = "HiFi";
  689. + data->dai.stream_name = "HiFi";
  690. + data->dai.codec_dai_name = "wm8960-hifi";
  691. + data->dai.codec_of_node = codec_np;
  692. + data->dai.cpu_dai_name = dev_name(&i2s_pdev->dev);
  693. + data->dai.platform_of_node = i2s_np;
  694. + data->dai.ops = &mt7620_hifi_ops;
  695. + data->dai.dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  696. + SND_SOC_DAIFMT_CBM_CFM;
  697. +
  698. + data->card.dev = &pdev->dev;
  699. + ret = snd_soc_of_parse_card_name(&data->card, "model");
  700. + if (ret)
  701. + goto fail;
  702. + ret = snd_soc_of_parse_audio_routing(&data->card, "audio-routing");
  703. + if (ret)
  704. + goto fail;
  705. + data->card.num_links = 1;
  706. + data->card.dai_link = &data->dai;
  707. + data->card.dapm_widgets = mt7620_wm8960_dapm_widgets;
  708. + data->card.num_dapm_widgets = ARRAY_SIZE(mt7620_wm8960_dapm_widgets);
  709. +
  710. + data->card.late_probe = mt7620_wm8960_late_probe;
  711. + data->card.set_bias_level = mt7620_wm8960_set_bias_level;
  712. +
  713. + platform_set_drvdata(pdev, &data->card);
  714. + snd_soc_card_set_drvdata(&data->card, data);
  715. +
  716. + ret = devm_snd_soc_register_card(&pdev->dev, &data->card);
  717. + if (ret) {
  718. + dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret);
  719. + goto fail;
  720. + }
  721. +
  722. + of_node_put(i2s_np);
  723. + of_node_put(codec_np);
  724. +
  725. + return 0;
  726. +fail:
  727. + if (i2s_np)
  728. + of_node_put(i2s_np);
  729. + if (codec_np)
  730. + of_node_put(codec_np);
  731. +
  732. + return ret;
  733. +}
  734. +
  735. +static int mt7620_wm8960_remove(struct platform_device *pdev)
  736. +{
  737. + return 0;
  738. +}
  739. +
  740. +static const struct of_device_id mt7620_wm8960_dt_ids[] = {
  741. + { .compatible = "mediatek,mt7620-audio-wm8960", },
  742. + { /* sentinel */ }
  743. +};
  744. +MODULE_DEVICE_TABLE(of, mt7620_wm8960_dt_ids);
  745. +
  746. +static struct platform_driver mt7620_wm8960_driver = {
  747. + .driver = {
  748. + .name = "mt7620-wm8960",
  749. + .owner = THIS_MODULE,
  750. + .pm = &snd_soc_pm_ops,
  751. + .of_match_table = mt7620_wm8960_dt_ids,
  752. + },
  753. + .probe = mt7620_wm8960_probe,
  754. + .remove = mt7620_wm8960_remove,
  755. +};
  756. +module_platform_driver(mt7620_wm8960_driver);
  757. +
  758. +MODULE_AUTHOR("Freescale Semiconductor, Inc.");
  759. +MODULE_DESCRIPTION("Freescale i.MX WM8962 ASoC machine driver");
  760. +MODULE_LICENSE("GPL v2");
  761. +MODULE_ALIAS("platform:mt7620-wm8962");