165-asoc-add-sunxi-codec.patch 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865
  1. From 97dcb50623db12f13c9c9a8b68dca61901b7f030 Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Emilio=20L=C3=B3pez?= <emilio@elopez.com.ar>
  3. Date: Mon, 14 Jul 2014 20:25:23 -0300
  4. Subject: [PATCH] ASoC: sunxi: add support for the on-chip codec on early
  5. Allwinner SoCs
  6. The sun4i, sun5i and sun7i SoC families have a built-in codec, capable
  7. of both audio capture and playback. This memory-mapped device can be fed
  8. with audio data via the Allwinner DMA controller.
  9. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
  10. ---
  11. sound/soc/Kconfig | 1 +
  12. sound/soc/Makefile | 1 +
  13. sound/soc/sunxi/Kconfig | 10 +
  14. sound/soc/sunxi/Makefile | 2 +
  15. sound/soc/sunxi/sunxi-codec.c | 802 ++++++++++++++++++++++++++++++++++++++++++
  16. 5 files changed, 816 insertions(+)
  17. create mode 100644 sound/soc/sunxi/Kconfig
  18. create mode 100644 sound/soc/sunxi/Makefile
  19. create mode 100644 sound/soc/sunxi/sunxi-codec.c
  20. --- a/sound/soc/Kconfig
  21. +++ b/sound/soc/Kconfig
  22. @@ -53,6 +53,7 @@ source "sound/soc/samsung/Kconfig"
  23. source "sound/soc/sh/Kconfig"
  24. source "sound/soc/sirf/Kconfig"
  25. source "sound/soc/spear/Kconfig"
  26. +source "sound/soc/sunxi/Kconfig"
  27. source "sound/soc/tegra/Kconfig"
  28. source "sound/soc/txx9/Kconfig"
  29. source "sound/soc/ux500/Kconfig"
  30. --- a/sound/soc/Makefile
  31. +++ b/sound/soc/Makefile
  32. @@ -34,6 +34,7 @@ obj-$(CONFIG_SND_SOC) += samsung/
  33. obj-$(CONFIG_SND_SOC) += sh/
  34. obj-$(CONFIG_SND_SOC) += sirf/
  35. obj-$(CONFIG_SND_SOC) += spear/
  36. +obj-$(CONFIG_SND_SOC) += sunxi/
  37. obj-$(CONFIG_SND_SOC) += tegra/
  38. obj-$(CONFIG_SND_SOC) += txx9/
  39. obj-$(CONFIG_SND_SOC) += ux500/
  40. --- /dev/null
  41. +++ b/sound/soc/sunxi/Kconfig
  42. @@ -0,0 +1,10 @@
  43. +menu "SoC Audio support for Allwinner SoCs"
  44. + depends on ARCH_SUNXI
  45. +
  46. +config SND_SUNXI_SOC_CODEC
  47. + tristate "APB on-chip sun4i/sun5i/sun7i CODEC"
  48. + select SND_SOC_GENERIC_DMAENGINE_PCM
  49. + select REGMAP_MMIO
  50. + default y
  51. +
  52. +endmenu
  53. --- /dev/null
  54. +++ b/sound/soc/sunxi/Makefile
  55. @@ -0,0 +1,2 @@
  56. +obj-$(CONFIG_SND_SUNXI_SOC_CODEC) += sunxi-codec.o
  57. +
  58. --- /dev/null
  59. +++ b/sound/soc/sunxi/sunxi-codec.c
  60. @@ -0,0 +1,802 @@
  61. +/*
  62. + * Copyright 2014 Emilio López <emilio@elopez.com.ar>
  63. + * Copyright 2014 Jon Smirl <jonsmirl@gmail.com>
  64. + *
  65. + * Based on the Allwinner SDK driver, released under the GPL.
  66. + *
  67. + * This program is free software; you can redistribute it and/or modify
  68. + * it under the terms of the GNU General Public License as published by
  69. + * the Free Software Foundation; either version 2 of the License, or
  70. + * (at your option) any later version.
  71. + *
  72. + * This program is distributed in the hope that it will be useful,
  73. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  74. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  75. + * GNU General Public License for more details.
  76. + */
  77. +
  78. +#include <linux/init.h>
  79. +#include <linux/kernel.h>
  80. +#include <linux/module.h>
  81. +#include <linux/platform_device.h>
  82. +#include <linux/delay.h>
  83. +#include <linux/slab.h>
  84. +#include <linux/of.h>
  85. +#include <linux/of_platform.h>
  86. +#include <linux/of_address.h>
  87. +#include <linux/clk.h>
  88. +#include <linux/regmap.h>
  89. +
  90. +#include <sound/core.h>
  91. +#include <sound/pcm.h>
  92. +#include <sound/pcm_params.h>
  93. +#include <sound/soc.h>
  94. +#include <sound/tlv.h>
  95. +#include <sound/initval.h>
  96. +#include <sound/dmaengine_pcm.h>
  97. +
  98. +/* Codec DAC register offsets and bit fields */
  99. +#define SUNXI_DAC_DPC (0x00)
  100. +#define SUNXI_DAC_DPC_EN_DA (31)
  101. +#define SUNXI_DAC_DPC_DVOL (12)
  102. +#define SUNXI_DAC_FIFOC (0x04)
  103. +#define SUNXI_DAC_FIFOC_DAC_FS (29)
  104. +#define SUNXI_DAC_FIFOC_FIR_VERSION (28)
  105. +#define SUNXI_DAC_FIFOC_SEND_LASAT (26)
  106. +#define SUNXI_DAC_FIFOC_TX_FIFO_MODE (24)
  107. +#define SUNXI_DAC_FIFOC_DRQ_CLR_CNT (21)
  108. +#define SUNXI_DAC_FIFOC_TX_TRIG_LEVEL (8)
  109. +#define SUNXI_DAC_FIFOC_MONO_EN (6)
  110. +#define SUNXI_DAC_FIFOC_TX_SAMPLE_BITS (5)
  111. +#define SUNXI_DAC_FIFOC_DAC_DRQ_EN (4)
  112. +#define SUNXI_DAC_FIFOC_FIFO_FLUSH (0)
  113. +#define SUNXI_DAC_FIFOS (0x08)
  114. +#define SUNXI_DAC_TXDATA (0x0c)
  115. +#define SUNXI_DAC_ACTL (0x10)
  116. +#define SUNXI_DAC_ACTL_DACAENR (31)
  117. +#define SUNXI_DAC_ACTL_DACAENL (30)
  118. +#define SUNXI_DAC_ACTL_MIXEN (29)
  119. +#define SUNXI_DAC_ACTL_LDACLMIXS (15)
  120. +#define SUNXI_DAC_ACTL_RDACRMIXS (14)
  121. +#define SUNXI_DAC_ACTL_LDACRMIXS (13)
  122. +#define SUNXI_DAC_ACTL_DACPAS (8)
  123. +#define SUNXI_DAC_ACTL_MIXPAS (7)
  124. +#define SUNXI_DAC_ACTL_PA_MUTE (6)
  125. +#define SUNXI_DAC_ACTL_PA_VOL (0)
  126. +#define SUNXI_DAC_TUNE (0x14)
  127. +#define SUNXI_DAC_DEBUG (0x18)
  128. +
  129. +/* Codec ADC register offsets and bit fields */
  130. +#define SUNXI_ADC_FIFOC (0x1c)
  131. +#define SUNXI_ADC_FIFOC_EN_AD (28)
  132. +#define SUNXI_ADC_FIFOC_RX_FIFO_MODE (24)
  133. +#define SUNXI_ADC_FIFOC_RX_TRIG_LEVEL (8)
  134. +#define SUNXI_ADC_FIFOC_MONO_EN (7)
  135. +#define SUNXI_ADC_FIFOC_RX_SAMPLE_BITS (6)
  136. +#define SUNXI_ADC_FIFOC_ADC_DRQ_EN (4)
  137. +#define SUNXI_ADC_FIFOC_FIFO_FLUSH (0)
  138. +#define SUNXI_ADC_FIFOS (0x20)
  139. +#define SUNXI_ADC_RXDATA (0x24)
  140. +#define SUNXI_ADC_ACTL (0x28)
  141. +#define SUNXI_ADC_ACTL_ADCREN (31)
  142. +#define SUNXI_ADC_ACTL_ADCLEN (30)
  143. +#define SUNXI_ADC_ACTL_PREG1EN (29)
  144. +#define SUNXI_ADC_ACTL_PREG2EN (28)
  145. +#define SUNXI_ADC_ACTL_VMICEN (27)
  146. +#define SUNXI_ADC_ACTL_VADCG (20)
  147. +#define SUNXI_ADC_ACTL_ADCIS (17)
  148. +#define SUNXI_ADC_ACTL_PA_EN (4)
  149. +#define SUNXI_ADC_ACTL_DDE (3)
  150. +#define SUNXI_ADC_DEBUG (0x2c)
  151. +
  152. +/* Other various ADC registers */
  153. +#define SUNXI_DAC_TXCNT (0x30)
  154. +#define SUNXI_ADC_RXCNT (0x34)
  155. +#define SUNXI_AC_SYS_VERI (0x38)
  156. +#define SUNXI_AC_MIC_PHONE_CAL (0x3c)
  157. +
  158. +/* Supported SoC families - used for quirks */
  159. +enum sunxi_soc_family {
  160. + SUN4IA, /* A10 SoC - revision A */
  161. + SUN4I, /* A10 SoC - later revisions */
  162. + SUN5I, /* A10S/A13 SoCs */
  163. + SUN7I, /* A20 SoC */
  164. +};
  165. +
  166. +struct sunxi_priv {
  167. + struct regmap *regmap;
  168. + struct clk *clk_apb, *clk_module;
  169. +
  170. + enum sunxi_soc_family revision;
  171. +
  172. + struct snd_dmaengine_dai_dma_data playback_dma_data;
  173. + struct snd_dmaengine_dai_dma_data capture_dma_data;
  174. +};
  175. +
  176. +static void sunxi_codec_play_start(struct sunxi_priv *priv)
  177. +{
  178. + /* TODO: see if we need to drive PA GPIO high */
  179. +
  180. + /* flush TX FIFO */
  181. + regmap_update_bits(priv->regmap, SUNXI_DAC_FIFOC, 0x1 << SUNXI_DAC_FIFOC_FIFO_FLUSH, 0x1 << SUNXI_DAC_FIFOC_FIFO_FLUSH);
  182. +
  183. + /* enable DAC DRQ */
  184. + regmap_update_bits(priv->regmap, SUNXI_DAC_FIFOC, 0x1 << SUNXI_DAC_FIFOC_DAC_DRQ_EN, 0x1 << SUNXI_DAC_FIFOC_DAC_DRQ_EN);
  185. +}
  186. +
  187. +static void sunxi_codec_play_stop(struct sunxi_priv *priv)
  188. +{
  189. + /* TODO: see if we need to drive PA GPIO low */
  190. +
  191. + /* disable DAC DRQ */
  192. + regmap_update_bits(priv->regmap, SUNXI_DAC_FIFOC, 0x1 << SUNXI_DAC_FIFOC_DAC_DRQ_EN, 0x0 << SUNXI_DAC_FIFOC_DAC_DRQ_EN);
  193. +}
  194. +
  195. +static void sunxi_codec_capture_start(struct sunxi_priv *priv)
  196. +{
  197. + /* TODO: see if we need to drive PA GPIO high */
  198. +
  199. + /* enable ADC DRQ */
  200. + regmap_update_bits(priv->regmap, SUNXI_ADC_FIFOC, 0x1 << SUNXI_ADC_FIFOC_ADC_DRQ_EN, 0x1 << SUNXI_ADC_FIFOC_ADC_DRQ_EN);
  201. +}
  202. +
  203. +static void sunxi_codec_capture_stop(struct sunxi_priv *priv)
  204. +{
  205. + /* disable ADC DRQ */
  206. + regmap_update_bits(priv->regmap, SUNXI_ADC_FIFOC, 0x1 << SUNXI_ADC_FIFOC_ADC_DRQ_EN, 0x0 << SUNXI_ADC_FIFOC_ADC_DRQ_EN);
  207. +
  208. + /* enable mic1 PA */
  209. + regmap_update_bits(priv->regmap, SUNXI_ADC_ACTL, 0x1 << SUNXI_ADC_ACTL_PREG1EN, 0x0 << SUNXI_ADC_ACTL_PREG1EN);
  210. +
  211. + /* enable VMIC */
  212. + regmap_update_bits(priv->regmap, SUNXI_ADC_ACTL, 0x1 << SUNXI_ADC_ACTL_VMICEN, 0x0 << SUNXI_ADC_ACTL_VMICEN);
  213. + if (priv->revision == SUN7I) {
  214. + /* TODO: undocumented */
  215. + regmap_update_bits(priv->regmap, SUNXI_DAC_TUNE, 0x3 << 8, 0x0 << 8);
  216. + }
  217. +
  218. + /* enable ADC digital */
  219. + regmap_update_bits(priv->regmap, SUNXI_ADC_FIFOC, 0x1 << SUNXI_ADC_FIFOC_EN_AD, 0x0 << SUNXI_ADC_FIFOC_EN_AD);
  220. +
  221. + /* set RX FIFO mode */
  222. + regmap_update_bits(priv->regmap, SUNXI_ADC_FIFOC, 0x1 << SUNXI_ADC_FIFOC_RX_FIFO_MODE, 0x0 << SUNXI_ADC_FIFOC_RX_FIFO_MODE);
  223. +
  224. + /* flush RX FIFO */
  225. + regmap_update_bits(priv->regmap, SUNXI_ADC_FIFOC, 0x1 << SUNXI_ADC_FIFOC_FIFO_FLUSH, 0x0 << SUNXI_ADC_FIFOC_FIFO_FLUSH);
  226. +
  227. + /* enable adc1 analog */
  228. + regmap_update_bits(priv->regmap, SUNXI_ADC_ACTL, 0x3 << SUNXI_ADC_ACTL_ADCLEN, 0x0 << SUNXI_ADC_ACTL_ADCLEN);
  229. +}
  230. +
  231. +static int sunxi_codec_trigger(struct snd_pcm_substream *substream, int cmd,
  232. + struct snd_soc_dai *dai)
  233. +{
  234. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  235. + struct sunxi_priv *priv = snd_soc_card_get_drvdata(rtd->card);
  236. +
  237. + switch (cmd) {
  238. + case SNDRV_PCM_TRIGGER_START:
  239. + case SNDRV_PCM_TRIGGER_RESUME:
  240. + case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  241. + if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
  242. + sunxi_codec_capture_start(priv);
  243. + else
  244. + sunxi_codec_play_start(priv);
  245. + break;
  246. + case SNDRV_PCM_TRIGGER_STOP:
  247. + case SNDRV_PCM_TRIGGER_SUSPEND:
  248. + case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  249. + if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
  250. + sunxi_codec_capture_stop(priv);
  251. + else
  252. + sunxi_codec_play_stop(priv);
  253. + break;
  254. + default:
  255. + return -EINVAL;
  256. + }
  257. +
  258. + return 0;
  259. +}
  260. +
  261. +static int sunxi_codec_prepare(struct snd_pcm_substream *substream,
  262. + struct snd_soc_dai *dai)
  263. +{
  264. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  265. + struct sunxi_priv *priv = snd_soc_card_get_drvdata(rtd->card);
  266. +
  267. + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  268. + regmap_update_bits(priv->regmap, SUNXI_DAC_FIFOC, 0x1 << SUNXI_DAC_FIFOC_FIFO_FLUSH, 0x1 << SUNXI_DAC_FIFOC_FIFO_FLUSH);
  269. +
  270. + /* set TX FIFO send DRQ level */
  271. + regmap_update_bits(priv->regmap, SUNXI_DAC_FIFOC, 0x3f << SUNXI_DAC_FIFOC_TX_TRIG_LEVEL, 0xf << SUNXI_DAC_FIFOC_TX_TRIG_LEVEL);
  272. + if (substream->runtime->rate > 32000) {
  273. + regmap_update_bits(priv->regmap, SUNXI_DAC_FIFOC, 0x1 << SUNXI_DAC_FIFOC_FIR_VERSION, 0x0 << SUNXI_DAC_FIFOC_FIR_VERSION);
  274. + } else {
  275. + regmap_update_bits(priv->regmap, SUNXI_DAC_FIFOC, 0x1 << SUNXI_DAC_FIFOC_FIR_VERSION, 0x1 << SUNXI_DAC_FIFOC_FIR_VERSION);
  276. + }
  277. +
  278. + /* set TX FIFO MODE - 0 works for both 16 and 24 bits */
  279. + regmap_update_bits(priv->regmap, SUNXI_DAC_FIFOC, 0x1 << SUNXI_DAC_FIFOC_TX_FIFO_MODE, 0x0 << SUNXI_DAC_FIFOC_TX_FIFO_MODE);
  280. +
  281. + /* send last sample when DAC FIFO under run */
  282. + regmap_update_bits(priv->regmap, SUNXI_DAC_FIFOC, 0x1 << SUNXI_DAC_FIFOC_SEND_LASAT, 0x0 << SUNXI_DAC_FIFOC_SEND_LASAT);
  283. + } else {
  284. + /* enable mic1 PA */
  285. + regmap_update_bits(priv->regmap, SUNXI_ADC_ACTL, 0x1 << SUNXI_ADC_ACTL_PREG1EN, 0x1 << SUNXI_ADC_ACTL_PREG1EN);
  286. +
  287. + /* mic1 gain 32dB */ /* FIXME - makes no sense */
  288. + regmap_update_bits(priv->regmap, SUNXI_ADC_ACTL, 0x3 << 25, 0x1 << 25);
  289. +
  290. + /* enable VMIC */
  291. + regmap_update_bits(priv->regmap, SUNXI_ADC_ACTL, 0x1 << SUNXI_ADC_ACTL_VMICEN, 0x1 << SUNXI_ADC_ACTL_VMICEN);
  292. +
  293. + if (priv->revision == SUN7I) {
  294. + /* boost up record effect */
  295. + regmap_update_bits(priv->regmap, SUNXI_DAC_TUNE, 0x3 << 8, 0x1 << 8);
  296. + }
  297. +
  298. + /* enable ADC digital */
  299. + regmap_update_bits(priv->regmap, SUNXI_ADC_FIFOC, 0x1 << SUNXI_ADC_FIFOC_EN_AD, 0x1 << SUNXI_ADC_FIFOC_EN_AD);
  300. +
  301. + /* set RX FIFO mode */
  302. + regmap_update_bits(priv->regmap, SUNXI_ADC_FIFOC, 0x1 << SUNXI_ADC_FIFOC_RX_FIFO_MODE, 0x1 << SUNXI_ADC_FIFOC_RX_FIFO_MODE);
  303. +
  304. + /* flush RX FIFO */
  305. + regmap_update_bits(priv->regmap, SUNXI_ADC_FIFOC, 0x1 << SUNXI_ADC_FIFOC_FIFO_FLUSH, 0x1 << SUNXI_ADC_FIFOC_FIFO_FLUSH);
  306. +
  307. + /* set RX FIFO rec drq level */
  308. + regmap_update_bits(priv->regmap, SUNXI_ADC_FIFOC, 0xf << SUNXI_ADC_FIFOC_RX_TRIG_LEVEL, 0x7 << SUNXI_ADC_FIFOC_RX_TRIG_LEVEL);
  309. +
  310. + /* enable adc1 analog */
  311. + regmap_update_bits(priv->regmap, SUNXI_ADC_ACTL, 0x3 << SUNXI_ADC_ACTL_ADCLEN, 0x3 << SUNXI_ADC_ACTL_ADCLEN);
  312. + }
  313. +
  314. + return 0;
  315. +}
  316. +
  317. +static int sunxi_codec_hw_params(struct snd_pcm_substream *substream,
  318. + struct snd_pcm_hw_params *params,
  319. + struct snd_soc_dai *dai)
  320. +{
  321. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  322. + struct sunxi_priv *priv = snd_soc_card_get_drvdata(rtd->card);
  323. + int is_mono = !!(params_channels(params) == 1);
  324. + int is_24bit = !!(hw_param_interval(params, SNDRV_PCM_HW_PARAM_SAMPLE_BITS)->min == 32);
  325. + unsigned int rate = params_rate(params);
  326. + unsigned int hwrate;
  327. +
  328. + switch (rate) {
  329. + case 176400:
  330. + case 88200:
  331. + case 44100:
  332. + case 33075:
  333. + case 22050:
  334. + case 14700:
  335. + case 11025:
  336. + case 7350:
  337. + default:
  338. + clk_set_rate(priv->clk_module, 22579200);
  339. + break;
  340. + case 192000:
  341. + case 96000:
  342. + case 48000:
  343. + case 32000:
  344. + case 24000:
  345. + case 16000:
  346. + case 12000:
  347. + case 8000:
  348. + clk_set_rate(priv->clk_module, 24576000);
  349. + break;
  350. + }
  351. +
  352. + switch (rate) {
  353. + case 192000:
  354. + case 176400:
  355. + hwrate = 6;
  356. + break;
  357. + case 96000:
  358. + case 88200:
  359. + hwrate = 7;
  360. + break;
  361. + default:
  362. + case 48000:
  363. + case 44100:
  364. + hwrate = 0;
  365. + break;
  366. + case 32000:
  367. + case 33075:
  368. + hwrate = 1;
  369. + break;
  370. + case 24000:
  371. + case 22050:
  372. + hwrate = 2;
  373. + break;
  374. + case 16000:
  375. + case 14700:
  376. + hwrate = 3;
  377. + break;
  378. + case 12000:
  379. + case 11025:
  380. + hwrate = 4;
  381. + break;
  382. + case 8000:
  383. + case 7350:
  384. + hwrate = 5;
  385. + break;
  386. + }
  387. +
  388. + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  389. + regmap_update_bits(priv->regmap, SUNXI_DAC_FIFOC, 7 << SUNXI_DAC_FIFOC_DAC_FS, hwrate << SUNXI_DAC_FIFOC_DAC_FS);
  390. + regmap_update_bits(priv->regmap, SUNXI_DAC_FIFOC, 1 << SUNXI_DAC_FIFOC_MONO_EN, is_mono << SUNXI_DAC_FIFOC_MONO_EN);
  391. + regmap_update_bits(priv->regmap, SUNXI_DAC_FIFOC, 1 << SUNXI_DAC_FIFOC_TX_SAMPLE_BITS, is_24bit << SUNXI_DAC_FIFOC_TX_SAMPLE_BITS);
  392. + if (is_24bit)
  393. + priv->playback_dma_data.addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
  394. + else
  395. + priv->playback_dma_data.addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES;
  396. + } else {
  397. + regmap_update_bits(priv->regmap, SUNXI_ADC_FIFOC, 7 << SUNXI_DAC_FIFOC_DAC_FS, hwrate << SUNXI_DAC_FIFOC_DAC_FS);
  398. + regmap_update_bits(priv->regmap, SUNXI_ADC_FIFOC, 1 << SUNXI_ADC_FIFOC_MONO_EN, is_mono << SUNXI_ADC_FIFOC_MONO_EN);
  399. + }
  400. +
  401. + return 0;
  402. +}
  403. +
  404. +static const struct snd_kcontrol_new sun7i_dac_ctls[] = {
  405. + /*SUNXI_DAC_ACTL = 0x10,PAVOL*/
  406. + SOC_SINGLE("Master Playback Volume", SUNXI_DAC_ACTL, 0, 0x3f, 0),
  407. + SOC_SINGLE("Playback Switch", SUNXI_DAC_ACTL, 6, 1, 0), /* Global output switch */
  408. + SOC_SINGLE("FmL Switch", SUNXI_DAC_ACTL, 17, 1, 0), /* FM left switch */
  409. + SOC_SINGLE("FmR Switch", SUNXI_DAC_ACTL, 16, 1, 0), /* FM right switch */
  410. + SOC_SINGLE("LineL Switch", SUNXI_DAC_ACTL, 19, 1, 0), /* Line left switch */
  411. + SOC_SINGLE("LineR Switch", SUNXI_DAC_ACTL, 18, 1, 0), /* Line right switch */
  412. + SOC_SINGLE("Ldac Left Mixer", SUNXI_DAC_ACTL, 15, 1, 0),
  413. + SOC_SINGLE("Rdac Right Mixer", SUNXI_DAC_ACTL, 14, 1, 0),
  414. + SOC_SINGLE("Ldac Right Mixer", SUNXI_DAC_ACTL, 13, 1, 0),
  415. + SOC_SINGLE("Mic Input Mux", SUNXI_DAC_ACTL, 9, 15, 0), /* from bit 9 to bit 12. Microphone input mute */
  416. + SOC_SINGLE("MIC output volume", SUNXI_DAC_ACTL, 20, 7, 0),
  417. + /* FM Input to output mixer Gain Control
  418. + * From -4.5db to 6db,1.5db/step,default is 0db
  419. + * -4.5db:0x0,-3.0db:0x1,-1.5db:0x2,0db:0x3
  420. + * 1.5db:0x4,3.0db:0x5,4.5db:0x6,6db:0x7
  421. + */
  422. + SOC_SINGLE("Fm output Volume", SUNXI_DAC_ACTL, 23, 7, 0),
  423. + /* Line-in gain stage to output mixer Gain Control
  424. + * 0:-1.5db,1:0db
  425. + */
  426. + SOC_SINGLE("Line output Volume", SUNXI_DAC_ACTL, 26, 1, 0),
  427. +
  428. + SOC_SINGLE("Master Capture Mute", SUNXI_ADC_ACTL, 4, 1, 0),
  429. + SOC_SINGLE("Right Capture Mute", SUNXI_ADC_ACTL, 31, 1, 0),
  430. + SOC_SINGLE("Left Capture Mute", SUNXI_ADC_ACTL, 30, 1, 0),
  431. + SOC_SINGLE("Linein Pre-AMP", SUNXI_ADC_ACTL, 13, 7, 0),
  432. + SOC_SINGLE("LINEIN APM Volume", SUNXI_AC_MIC_PHONE_CAL, 13, 0x7, 0),
  433. + /* ADC Input Gain Control, capture volume
  434. + * 000:-4.5db,001:-3db,010:-1.5db,011:0db,100:1.5db,101:3db,110:4.5db,111:6db
  435. + */
  436. + SOC_SINGLE("Capture Volume", SUNXI_ADC_ACTL, 20, 7, 0),
  437. + /*
  438. + * MIC2 pre-amplifier Gain Control
  439. + * 00:0db,01:35db,10:38db,11:41db
  440. + */
  441. + SOC_SINGLE("MicL Volume", SUNXI_ADC_ACTL, 25, 3, 0), /* Microphone left volume */
  442. + SOC_SINGLE("MicR Volume", SUNXI_ADC_ACTL, 23, 3, 0), /* Microphone right volume */
  443. + SOC_SINGLE("Mic2 Boost", SUNXI_ADC_ACTL, 29, 1, 0),
  444. + SOC_SINGLE("Mic1 Boost", SUNXI_ADC_ACTL, 28, 1, 0),
  445. + SOC_SINGLE("Mic Power", SUNXI_ADC_ACTL, 27, 1, 0),
  446. + SOC_SINGLE("ADC Input Mux", SUNXI_ADC_ACTL, 17, 7, 0), /* ADC input mute */
  447. + SOC_SINGLE("Mic2 gain Volume", SUNXI_AC_MIC_PHONE_CAL, 26, 7, 0),
  448. + /*
  449. + * MIC1 pre-amplifier Gain Control
  450. + * 00:0db,01:35db,10:38db,11:41db
  451. + */
  452. + SOC_SINGLE("Mic1 gain Volume", SUNXI_AC_MIC_PHONE_CAL, 29, 3, 0),
  453. +};
  454. +
  455. +static int sunxi_codec_dai_probe(struct snd_soc_dai *dai)
  456. +{
  457. + struct snd_soc_card *card = snd_soc_dai_get_drvdata(dai);
  458. + struct sunxi_priv *priv = snd_soc_card_get_drvdata(card);
  459. +
  460. + snd_soc_dai_init_dma_data(dai, &priv->playback_dma_data, &priv->capture_dma_data);
  461. +
  462. + return 0;
  463. +}
  464. +
  465. +static void sunxi_codec_init(struct sunxi_priv *priv)
  466. +{
  467. + regmap_update_bits(priv->regmap, SUNXI_DAC_FIFOC, 1 << SUNXI_DAC_FIFOC_FIR_VERSION, 1 << SUNXI_DAC_FIFOC_FIR_VERSION);
  468. +
  469. + /* set digital volume to maximum */
  470. + if (priv->revision == SUN4IA)
  471. + regmap_update_bits(priv->regmap, SUNXI_DAC_DPC, 0x3F << SUNXI_DAC_DPC_DVOL, 0 << SUNXI_DAC_DPC_DVOL);
  472. +
  473. + regmap_update_bits(priv->regmap, SUNXI_DAC_FIFOC, 3 << SUNXI_DAC_FIFOC_DRQ_CLR_CNT, 3 << SUNXI_DAC_FIFOC_DRQ_CLR_CNT);
  474. +
  475. + /* set volume */ /* TODO: is A10A inverted? */
  476. + if (priv->revision == SUN4IA)
  477. + regmap_update_bits(priv->regmap, SUNXI_DAC_ACTL, 0x3f << SUNXI_DAC_ACTL_PA_VOL, 1 << SUNXI_DAC_ACTL_PA_VOL);
  478. + else
  479. + regmap_update_bits(priv->regmap, SUNXI_DAC_ACTL, 0x3f << SUNXI_DAC_ACTL_PA_VOL, 0x3b << SUNXI_DAC_ACTL_PA_VOL);
  480. +}
  481. +
  482. +static int sunxi_codec_startup(struct snd_pcm_substream *substream,
  483. + struct snd_soc_dai *dai)
  484. +{
  485. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  486. + struct sunxi_priv *priv = snd_soc_card_get_drvdata(rtd->card);
  487. +
  488. + sunxi_codec_init(priv);
  489. +
  490. + return clk_prepare_enable(priv->clk_module);
  491. +}
  492. +
  493. +static void sunxi_codec_shutdown(struct snd_pcm_substream *substream,
  494. + struct snd_soc_dai *dai)
  495. +{
  496. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  497. + struct sunxi_priv *priv = snd_soc_card_get_drvdata(rtd->card);
  498. +
  499. + clk_disable_unprepare(priv->clk_module);
  500. +}
  501. +
  502. +/*** Codec DAI ***/
  503. +
  504. +static const struct snd_soc_dai_ops sunxi_codec_dai_ops = {
  505. + .startup = sunxi_codec_startup,
  506. + .shutdown = sunxi_codec_shutdown,
  507. + .trigger = sunxi_codec_trigger,
  508. + .hw_params = sunxi_codec_hw_params,
  509. + .prepare = sunxi_codec_prepare,
  510. +};
  511. +
  512. +static struct snd_soc_dai_driver sunxi_codec_dai = {
  513. + .name = "Codec",
  514. + .playback = {
  515. + .stream_name = "Codec Playback",
  516. + .channels_min = 1,
  517. + .channels_max = 2,
  518. + .rate_min = 8000,
  519. + .rate_max = 192000,
  520. + .rates = (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_11025 |\
  521. + SNDRV_PCM_RATE_22050| SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 |\
  522. + SNDRV_PCM_RATE_48000 |SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000 |\
  523. + SNDRV_PCM_RATE_KNOT),
  524. + .formats = (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE),
  525. + .sig_bits = 24,
  526. + },
  527. + .capture = {
  528. + .stream_name = "Codec Capture",
  529. + .channels_min = 1,
  530. + .channels_max = 2,
  531. + .rate_min = 8000,
  532. + .rate_max = 192000,
  533. + .rates = (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_11025 |\
  534. + SNDRV_PCM_RATE_22050| SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 |\
  535. + SNDRV_PCM_RATE_48000 |SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000 |\
  536. + SNDRV_PCM_RATE_KNOT),
  537. + .formats = (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE),
  538. + .sig_bits = 24,
  539. + },
  540. + .ops = &sunxi_codec_dai_ops,
  541. +};
  542. +
  543. +/*** Codec ***/
  544. +
  545. +static const struct snd_kcontrol_new sunxi_pa =
  546. + SOC_DAPM_SINGLE("PA Switch", SUNXI_ADC_ACTL, SUNXI_ADC_ACTL_PA_EN, 1, 0);
  547. +
  548. +static const struct snd_kcontrol_new sunxi_pa_mute =
  549. + SOC_DAPM_SINGLE("PA Mute Switch", SUNXI_DAC_ACTL, SUNXI_DAC_ACTL_PA_MUTE, 1, 0);
  550. +
  551. +static DECLARE_TLV_DB_SCALE(sunxi_pa_volume_scale, -6300, 100, 1);
  552. +
  553. +static const struct snd_kcontrol_new sunxi_codec_widgets[] = {
  554. + SOC_SINGLE_TLV("PA Volume", SUNXI_DAC_ACTL, SUNXI_DAC_ACTL_PA_VOL,
  555. + 0x3F, 0, sunxi_pa_volume_scale),
  556. +};
  557. +
  558. +static const char *right_output_mixer_text[] = { "Disabled", "Left", "Right" };
  559. +static const unsigned int right_output_mixer_values[] = { 0x0, 0x1, 0x2 };
  560. +static SOC_VALUE_ENUM_SINGLE_DECL(right_output_mixer, SUNXI_DAC_ACTL,
  561. + SUNXI_DAC_ACTL_LDACRMIXS, 0x3,
  562. + right_output_mixer_text,
  563. + right_output_mixer_values);
  564. +
  565. +static const char *left_output_mixer_text[] = { "Disabled", "Left" };
  566. +static const unsigned int left_output_mixer_values[] = { 0x0, 0x1 };
  567. +static SOC_VALUE_ENUM_SINGLE_DECL(left_output_mixer, SUNXI_DAC_ACTL,
  568. + SUNXI_DAC_ACTL_LDACLMIXS, 0x1,
  569. + left_output_mixer_text,
  570. + left_output_mixer_values);
  571. +
  572. +static const struct snd_kcontrol_new right_mixer =
  573. + SOC_DAPM_ENUM("Right Mixer", right_output_mixer);
  574. +
  575. +static const struct snd_kcontrol_new left_mixer =
  576. + SOC_DAPM_ENUM("Left Mixer", left_output_mixer);
  577. +
  578. +static const struct snd_kcontrol_new sunxi_mixer =
  579. + SOC_DAPM_SINGLE("Mixer Switch", SUNXI_DAC_ACTL, SUNXI_DAC_ACTL_MIXEN, 1, 0);
  580. +
  581. +static const char *sunxi_dac_output_text[] = { "Muted", "Mixed", "Direct" };
  582. +static const unsigned int sunxi_dac_output_values[] = { 0x0, 0x1, 0x2 };
  583. +static SOC_VALUE_ENUM_SINGLE_DECL(dac_output_mux, SUNXI_DAC_ACTL,
  584. + SUNXI_DAC_ACTL_MIXPAS, 0x3,
  585. + sunxi_dac_output_text,
  586. + sunxi_dac_output_values);
  587. +
  588. +static const struct snd_kcontrol_new sunxi_dac_output =
  589. + SOC_DAPM_ENUM("DAC Output", dac_output_mux);
  590. +
  591. +static const struct snd_soc_dapm_widget codec_dapm_widgets[] = {
  592. + /* Digital parts of the DACs */
  593. + SND_SOC_DAPM_SUPPLY("DAC", SUNXI_DAC_DPC, SUNXI_DAC_DPC_EN_DA, 0, NULL, 0),
  594. +
  595. + /* Analog parts of the DACs */
  596. + SND_SOC_DAPM_DAC("Left DAC", NULL, SUNXI_DAC_ACTL, SUNXI_DAC_ACTL_DACAENL, 0),
  597. + SND_SOC_DAPM_DAC("Right DAC", NULL, SUNXI_DAC_ACTL, SUNXI_DAC_ACTL_DACAENR, 0),
  598. +
  599. + SND_SOC_DAPM_SWITCH("PA", SUNXI_ADC_ACTL, SUNXI_ADC_ACTL_PA_EN, 0, &sunxi_pa),
  600. + SND_SOC_DAPM_SWITCH("PA Mute", SUNXI_DAC_ACTL, SUNXI_DAC_ACTL_PA_MUTE, 0, &sunxi_pa_mute),
  601. +
  602. + SND_SOC_DAPM_MUX("Right Mixer", SUNXI_DAC_ACTL, SUNXI_DAC_ACTL_LDACRMIXS, 0, &right_mixer),
  603. + SND_SOC_DAPM_MUX("Left Mixer", SUNXI_DAC_ACTL, SUNXI_DAC_ACTL_LDACLMIXS, 0, &left_mixer),
  604. + SND_SOC_DAPM_SWITCH("Mixer", SUNXI_DAC_ACTL, SUNXI_DAC_ACTL_MIXEN, 0, &sunxi_mixer),
  605. +
  606. + SND_SOC_DAPM_MUX("DAC Output", SUNXI_DAC_ACTL, SUNXI_DAC_ACTL_MIXPAS, 0, &sunxi_dac_output),
  607. +
  608. + SND_SOC_DAPM_OUTPUT("Mic Bias"),
  609. + SND_SOC_DAPM_OUTPUT("HP Right"),
  610. + SND_SOC_DAPM_OUTPUT("HP Left"),
  611. + SND_SOC_DAPM_INPUT("MIC_IN"),
  612. + SND_SOC_DAPM_INPUT("LINE_IN"),
  613. +};
  614. +
  615. +static const struct snd_soc_dapm_route codec_dapm_routes[] = {
  616. + /* DAC block */
  617. + { "Left DAC", NULL, "Codec Playback" },
  618. + { "Right DAC", NULL, "Codec Playback" },
  619. + { "Left DAC", NULL, "DAC" },
  620. + { "Right DAC", NULL, "DAC" },
  621. +
  622. + /* DAC -> PA path */
  623. + { "DAC Output", "Direct", "Left DAC" },
  624. + { "DAC Output", "Direct", "Right DAC" },
  625. + { "PA", NULL, "DAC Output"},
  626. +
  627. + /* DAC -> MIX -> PA path */
  628. + { "Left Mixer", "Left", "Left DAC" },
  629. + { "Right Mixer", "Right", "Right DAC" },
  630. + { "Mixer", NULL, "Left Mixer" },
  631. + { "Mixer", NULL, "Right Mixer" },
  632. + { "DAC Output", "Mixed", "Mixer" },
  633. + { "PA", NULL, "DAC Output" },
  634. +
  635. + /* PA -> HP path */
  636. + { "PA Mute", NULL, "PA" },
  637. + { "HP Right", NULL, "PA Mute" },
  638. + { "HP Left", NULL, "PA Mute" },
  639. +};
  640. +
  641. +static struct snd_soc_codec_driver sunxi_codec = {
  642. + .controls = sunxi_codec_widgets,
  643. + .num_controls = ARRAY_SIZE(sunxi_codec_widgets),
  644. + .dapm_widgets = codec_dapm_widgets,
  645. + .num_dapm_widgets = ARRAY_SIZE(codec_dapm_widgets),
  646. + .dapm_routes = codec_dapm_routes,
  647. + .num_dapm_routes = ARRAY_SIZE(codec_dapm_routes),
  648. +};
  649. +
  650. +/*** Board routing ***/
  651. +/* TODO: do this with DT */
  652. +
  653. +static const struct snd_soc_dapm_widget sunxi_board_dapm_widgets[] = {
  654. + SND_SOC_DAPM_HP("Headphone Jack", NULL),
  655. +};
  656. +
  657. +static const struct snd_soc_dapm_route sunxi_board_routing[] = {
  658. + { "Headphone Jack", NULL, "HP Right" },
  659. + { "Headphone Jack", NULL, "HP Left" },
  660. +};
  661. +
  662. +/*** Card and DAI Link ***/
  663. +
  664. +static struct snd_soc_dai_link cdc_dai = {
  665. + .name = "cdc",
  666. +
  667. + .stream_name = "CDC PCM",
  668. + .codec_dai_name = "Codec",
  669. + .cpu_dai_name = "1c22c00.codec",
  670. + .codec_name = "1c22c00.codec",
  671. + .platform_name = "1c22c00.codec",
  672. + .dai_fmt = SND_SOC_DAIFMT_I2S,
  673. +};
  674. +
  675. +static struct snd_soc_card snd_soc_sunxi_codec = {
  676. + .name = "sunxi-codec",
  677. + .owner = THIS_MODULE,
  678. + .dai_link = &cdc_dai,
  679. + .num_links = 1,
  680. + .dapm_widgets = sunxi_board_dapm_widgets,
  681. + .num_dapm_widgets = ARRAY_SIZE(sunxi_board_dapm_widgets),
  682. + .dapm_routes = sunxi_board_routing,
  683. + .num_dapm_routes = ARRAY_SIZE(sunxi_board_routing),
  684. +};
  685. +
  686. +/*** CPU DAI ***/
  687. +
  688. +static const struct snd_soc_component_driver sunxi_codec_component = {
  689. + .name = "sunxi-codec",
  690. +};
  691. +
  692. +#define SUNXI_RATES SNDRV_PCM_RATE_8000_192000
  693. +#define SUNXI_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | \
  694. + SNDRV_PCM_FMTBIT_S32_LE)
  695. +
  696. +static struct snd_soc_dai_driver dummy_cpu_dai = {
  697. + .name = "sunxi-cpu-dai",
  698. + .probe = sunxi_codec_dai_probe,
  699. + .playback = {
  700. + .stream_name = "Playback",
  701. + .channels_min = 1,
  702. + .channels_max = 2,
  703. + .rates = SUNXI_RATES,
  704. + .formats = SUNXI_FORMATS,
  705. + .sig_bits = 24,
  706. + },
  707. + .capture = {
  708. + .stream_name = "Capture",
  709. + .channels_min = 1,
  710. + .channels_max = 2,
  711. + .rates = SUNXI_RATES,
  712. + .formats = SUNXI_FORMATS,
  713. + .sig_bits = 24,
  714. + },
  715. +};
  716. +
  717. +static const struct regmap_config sunxi_codec_regmap_config = {
  718. + .reg_bits = 32,
  719. + .reg_stride = 4,
  720. + .val_bits = 32,
  721. + .max_register = SUNXI_AC_MIC_PHONE_CAL,
  722. +};
  723. +
  724. +static const struct of_device_id sunxi_codec_of_match[] = {
  725. + { .compatible = "allwinner,sun4i-a10a-codec", .data = (void *)SUN4IA},
  726. + { .compatible = "allwinner,sun4i-a10-codec", .data = (void *)SUN4I},
  727. + { .compatible = "allwinner,sun5i-a13-codec", .data = (void *)SUN5I},
  728. + { .compatible = "allwinner,sun7i-a20-codec", .data = (void *)SUN7I},
  729. + {}
  730. +};
  731. +MODULE_DEVICE_TABLE(of, sunxi_codec_of_match);
  732. +
  733. +static int sunxi_codec_probe(struct platform_device *pdev)
  734. +{
  735. + struct device_node *np = pdev->dev.of_node;
  736. + struct snd_soc_card *card = &snd_soc_sunxi_codec;
  737. + const struct of_device_id *of_id;
  738. + struct device *dev = &pdev->dev;
  739. + struct sunxi_priv *priv;
  740. + struct resource *res;
  741. + void __iomem *base;
  742. + int ret;
  743. +
  744. + if (!of_device_is_available(np))
  745. + return -ENODEV;
  746. +
  747. + of_id = of_match_device(sunxi_codec_of_match, dev);
  748. + if (!of_id)
  749. + return -EINVAL;
  750. +
  751. + priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
  752. + if (!priv)
  753. + return -ENOMEM;
  754. +
  755. + card->dev = &pdev->dev;
  756. + platform_set_drvdata(pdev, card);
  757. + snd_soc_card_set_drvdata(card, priv);
  758. +
  759. + priv->revision = (enum sunxi_soc_family)of_id->data;
  760. +
  761. + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  762. + base = devm_ioremap_resource(&pdev->dev, res);
  763. + if (IS_ERR(base))
  764. + return PTR_ERR(base);
  765. +
  766. + priv->regmap = devm_regmap_init_mmio(&pdev->dev, base,
  767. + &sunxi_codec_regmap_config);
  768. + if (IS_ERR(priv->regmap))
  769. + return PTR_ERR(priv->regmap);
  770. +
  771. + /* Get the clocks from the DT */
  772. + priv->clk_apb = devm_clk_get(dev, "apb");
  773. + if (IS_ERR(priv->clk_apb)) {
  774. + dev_err(dev, "failed to get apb clock\n");
  775. + return PTR_ERR(priv->clk_apb);
  776. + }
  777. + priv->clk_module = devm_clk_get(dev, "codec");
  778. + if (IS_ERR(priv->clk_module)) {
  779. + dev_err(dev, "failed to get codec clock\n");
  780. + return PTR_ERR(priv->clk_module);
  781. + }
  782. +
  783. + /* Enable the clock on a basic rate */
  784. + ret = clk_set_rate(priv->clk_module, 24576000);
  785. + if (ret) {
  786. + dev_err(dev, "failed to set codec base clock rate\n");
  787. + return ret;
  788. + }
  789. +
  790. + /* Enable the bus clock */
  791. + if (clk_prepare_enable(priv->clk_apb)) {
  792. + dev_err(dev, "failed to enable apb clock\n");
  793. + clk_disable_unprepare(priv->clk_module);
  794. + return -EINVAL;
  795. + }
  796. +
  797. + /* DMA configuration for TX FIFO */
  798. + priv->playback_dma_data.addr = res->start + SUNXI_DAC_TXDATA;
  799. + priv->playback_dma_data.maxburst = 4;
  800. + priv->playback_dma_data.addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES;
  801. +
  802. + /* DMA configuration for RX FIFO */
  803. + priv->capture_dma_data.addr = res->start + SUNXI_ADC_RXDATA;
  804. + priv->capture_dma_data.maxburst = 4;
  805. + priv->capture_dma_data.addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES;
  806. +
  807. + ret = snd_soc_register_codec(&pdev->dev, &sunxi_codec, &sunxi_codec_dai, 1);
  808. +
  809. + ret = devm_snd_soc_register_component(&pdev->dev, &sunxi_codec_component, &dummy_cpu_dai, 1);
  810. + if (ret)
  811. + goto err_clk_disable;
  812. +
  813. + ret = devm_snd_dmaengine_pcm_register(&pdev->dev, NULL, 0);
  814. + if (ret)
  815. + goto err_clk_disable;
  816. +
  817. + sunxi_codec_init(priv);
  818. +
  819. + ret = snd_soc_register_card(card);
  820. + if (ret) {
  821. + dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret);
  822. + goto err_fini_utils;
  823. + }
  824. +
  825. + ret = snd_soc_of_parse_audio_routing(card, "routing");
  826. + if (ret)
  827. + goto err;
  828. +
  829. + return 0;
  830. +
  831. +err_fini_utils:
  832. +err:
  833. +err_clk_disable:
  834. + clk_disable_unprepare(priv->clk_apb);
  835. + return ret;
  836. +}
  837. +
  838. +static int sunxi_codec_remove(struct platform_device *pdev)
  839. +{
  840. + struct sunxi_priv *priv = platform_get_drvdata(pdev);
  841. +
  842. + clk_disable_unprepare(priv->clk_apb);
  843. + clk_disable_unprepare(priv->clk_module);
  844. +
  845. + return 0;
  846. +}
  847. +
  848. +static struct platform_driver sunxi_codec_driver = {
  849. + .driver = {
  850. + .name = "sunxi-codec",
  851. + .owner = THIS_MODULE,
  852. + .of_match_table = sunxi_codec_of_match,
  853. + },
  854. + .probe = sunxi_codec_probe,
  855. + .remove = sunxi_codec_remove,
  856. +};
  857. +module_platform_driver(sunxi_codec_driver);
  858. +
  859. +MODULE_DESCRIPTION("sunxi codec ASoC driver");
  860. +MODULE_AUTHOR("Emilio López <emilio@elopez.com.ar>");
  861. +MODULE_AUTHOR("Jon Smirl <jonsmirl@gmail.com>");
  862. +MODULE_LICENSE("GPL");