sun8i-codec-analog.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938
  1. /*
  2. * This driver supports the analog controls for the internal codec
  3. * found in Allwinner's A31s, A23, A33 and H3 SoCs.
  4. *
  5. * Copyright 2016 Chen-Yu Tsai <wens@csie.org>
  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 as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. */
  17. #include <linux/io.h>
  18. #include <linux/kernel.h>
  19. #include <linux/module.h>
  20. #include <linux/of.h>
  21. #include <linux/of_device.h>
  22. #include <linux/platform_device.h>
  23. #include <linux/regmap.h>
  24. #include <sound/soc.h>
  25. #include <sound/soc-dapm.h>
  26. #include <sound/tlv.h>
  27. /* Codec analog control register offsets and bit fields */
  28. #define SUN8I_ADDA_HP_VOLC 0x00
  29. #define SUN8I_ADDA_HP_VOLC_PA_CLK_GATE 7
  30. #define SUN8I_ADDA_HP_VOLC_HP_VOL 0
  31. #define SUN8I_ADDA_LOMIXSC 0x01
  32. #define SUN8I_ADDA_LOMIXSC_MIC1 6
  33. #define SUN8I_ADDA_LOMIXSC_MIC2 5
  34. #define SUN8I_ADDA_LOMIXSC_PHONE 4
  35. #define SUN8I_ADDA_LOMIXSC_PHONEN 3
  36. #define SUN8I_ADDA_LOMIXSC_LINEINL 2
  37. #define SUN8I_ADDA_LOMIXSC_DACL 1
  38. #define SUN8I_ADDA_LOMIXSC_DACR 0
  39. #define SUN8I_ADDA_ROMIXSC 0x02
  40. #define SUN8I_ADDA_ROMIXSC_MIC1 6
  41. #define SUN8I_ADDA_ROMIXSC_MIC2 5
  42. #define SUN8I_ADDA_ROMIXSC_PHONE 4
  43. #define SUN8I_ADDA_ROMIXSC_PHONEP 3
  44. #define SUN8I_ADDA_ROMIXSC_LINEINR 2
  45. #define SUN8I_ADDA_ROMIXSC_DACR 1
  46. #define SUN8I_ADDA_ROMIXSC_DACL 0
  47. #define SUN8I_ADDA_DAC_PA_SRC 0x03
  48. #define SUN8I_ADDA_DAC_PA_SRC_DACAREN 7
  49. #define SUN8I_ADDA_DAC_PA_SRC_DACALEN 6
  50. #define SUN8I_ADDA_DAC_PA_SRC_RMIXEN 5
  51. #define SUN8I_ADDA_DAC_PA_SRC_LMIXEN 4
  52. #define SUN8I_ADDA_DAC_PA_SRC_RHPPAMUTE 3
  53. #define SUN8I_ADDA_DAC_PA_SRC_LHPPAMUTE 2
  54. #define SUN8I_ADDA_DAC_PA_SRC_RHPIS 1
  55. #define SUN8I_ADDA_DAC_PA_SRC_LHPIS 0
  56. #define SUN8I_ADDA_PHONEIN_GCTRL 0x04
  57. #define SUN8I_ADDA_PHONEIN_GCTRL_PHONEPG 4
  58. #define SUN8I_ADDA_PHONEIN_GCTRL_PHONENG 0
  59. #define SUN8I_ADDA_LINEIN_GCTRL 0x05
  60. #define SUN8I_ADDA_LINEIN_GCTRL_LINEING 4
  61. #define SUN8I_ADDA_LINEIN_GCTRL_PHONEG 0
  62. #define SUN8I_ADDA_MICIN_GCTRL 0x06
  63. #define SUN8I_ADDA_MICIN_GCTRL_MIC1G 4
  64. #define SUN8I_ADDA_MICIN_GCTRL_MIC2G 0
  65. #define SUN8I_ADDA_PAEN_HP_CTRL 0x07
  66. #define SUN8I_ADDA_PAEN_HP_CTRL_HPPAEN 7
  67. #define SUN8I_ADDA_PAEN_HP_CTRL_LINEOUTEN 7 /* H3 specific */
  68. #define SUN8I_ADDA_PAEN_HP_CTRL_HPCOM_FC 5
  69. #define SUN8I_ADDA_PAEN_HP_CTRL_COMPTEN 4
  70. #define SUN8I_ADDA_PAEN_HP_CTRL_PA_ANTI_POP_CTRL 2
  71. #define SUN8I_ADDA_PAEN_HP_CTRL_LTRNMUTE 1
  72. #define SUN8I_ADDA_PAEN_HP_CTRL_RTLNMUTE 0
  73. #define SUN8I_ADDA_PHONEOUT_CTRL 0x08
  74. #define SUN8I_ADDA_PHONEOUT_CTRL_PHONEOUTG 5
  75. #define SUN8I_ADDA_PHONEOUT_CTRL_PHONEOUTEN 4
  76. #define SUN8I_ADDA_PHONEOUT_CTRL_PHONEOUT_MIC1 3
  77. #define SUN8I_ADDA_PHONEOUT_CTRL_PHONEOUT_MIC2 2
  78. #define SUN8I_ADDA_PHONEOUT_CTRL_PHONEOUT_RMIX 1
  79. #define SUN8I_ADDA_PHONEOUT_CTRL_PHONEOUT_LMIX 0
  80. #define SUN8I_ADDA_PHONE_GAIN_CTRL 0x09
  81. #define SUN8I_ADDA_PHONE_GAIN_CTRL_LINEOUT_VOL 3
  82. #define SUN8I_ADDA_PHONE_GAIN_CTRL_PHONEPREG 0
  83. #define SUN8I_ADDA_MIC2G_CTRL 0x0a
  84. #define SUN8I_ADDA_MIC2G_CTRL_MIC2AMPEN 7
  85. #define SUN8I_ADDA_MIC2G_CTRL_MIC2BOOST 4
  86. #define SUN8I_ADDA_MIC2G_CTRL_LINEOUTLEN 3
  87. #define SUN8I_ADDA_MIC2G_CTRL_LINEOUTREN 2
  88. #define SUN8I_ADDA_MIC2G_CTRL_LINEOUTLSRC 1
  89. #define SUN8I_ADDA_MIC2G_CTRL_LINEOUTRSRC 0
  90. #define SUN8I_ADDA_MIC1G_MICBIAS_CTRL 0x0b
  91. #define SUN8I_ADDA_MIC1G_MICBIAS_CTRL_HMICBIASEN 7
  92. #define SUN8I_ADDA_MIC1G_MICBIAS_CTRL_MMICBIASEN 6
  93. #define SUN8I_ADDA_MIC1G_MICBIAS_CTRL_HMICBIAS_MODE 5
  94. #define SUN8I_ADDA_MIC1G_MICBIAS_CTRL_MIC1AMPEN 3
  95. #define SUN8I_ADDA_MIC1G_MICBIAS_CTRL_MIC1BOOST 0
  96. #define SUN8I_ADDA_LADCMIXSC 0x0c
  97. #define SUN8I_ADDA_LADCMIXSC_MIC1 6
  98. #define SUN8I_ADDA_LADCMIXSC_MIC2 5
  99. #define SUN8I_ADDA_LADCMIXSC_PHONE 4
  100. #define SUN8I_ADDA_LADCMIXSC_PHONEN 3
  101. #define SUN8I_ADDA_LADCMIXSC_LINEINL 2
  102. #define SUN8I_ADDA_LADCMIXSC_OMIXRL 1
  103. #define SUN8I_ADDA_LADCMIXSC_OMIXRR 0
  104. #define SUN8I_ADDA_RADCMIXSC 0x0d
  105. #define SUN8I_ADDA_RADCMIXSC_MIC1 6
  106. #define SUN8I_ADDA_RADCMIXSC_MIC2 5
  107. #define SUN8I_ADDA_RADCMIXSC_PHONE 4
  108. #define SUN8I_ADDA_RADCMIXSC_PHONEP 3
  109. #define SUN8I_ADDA_RADCMIXSC_LINEINR 2
  110. #define SUN8I_ADDA_RADCMIXSC_OMIXR 1
  111. #define SUN8I_ADDA_RADCMIXSC_OMIXL 0
  112. #define SUN8I_ADDA_RES 0x0e
  113. #define SUN8I_ADDA_RES_MMICBIAS_SEL 4
  114. #define SUN8I_ADDA_RES_PA_ANTI_POP_CTRL 0
  115. #define SUN8I_ADDA_ADC_AP_EN 0x0f
  116. #define SUN8I_ADDA_ADC_AP_EN_ADCREN 7
  117. #define SUN8I_ADDA_ADC_AP_EN_ADCLEN 6
  118. #define SUN8I_ADDA_ADC_AP_EN_ADCG 0
  119. /* Analog control register access bits */
  120. #define ADDA_PR 0x0 /* PRCM base + 0x1c0 */
  121. #define ADDA_PR_RESET BIT(28)
  122. #define ADDA_PR_WRITE BIT(24)
  123. #define ADDA_PR_ADDR_SHIFT 16
  124. #define ADDA_PR_ADDR_MASK GENMASK(4, 0)
  125. #define ADDA_PR_DATA_IN_SHIFT 8
  126. #define ADDA_PR_DATA_IN_MASK GENMASK(7, 0)
  127. #define ADDA_PR_DATA_OUT_SHIFT 0
  128. #define ADDA_PR_DATA_OUT_MASK GENMASK(7, 0)
  129. /* regmap access bits */
  130. static int adda_reg_read(void *context, unsigned int reg, unsigned int *val)
  131. {
  132. void __iomem *base = (void __iomem *)context;
  133. u32 tmp;
  134. /* De-assert reset */
  135. writel(readl(base) | ADDA_PR_RESET, base);
  136. /* Clear write bit */
  137. writel(readl(base) & ~ADDA_PR_WRITE, base);
  138. /* Set register address */
  139. tmp = readl(base);
  140. tmp &= ~(ADDA_PR_ADDR_MASK << ADDA_PR_ADDR_SHIFT);
  141. tmp |= (reg & ADDA_PR_ADDR_MASK) << ADDA_PR_ADDR_SHIFT;
  142. writel(tmp, base);
  143. /* Read back value */
  144. *val = readl(base) & ADDA_PR_DATA_OUT_MASK;
  145. return 0;
  146. }
  147. static int adda_reg_write(void *context, unsigned int reg, unsigned int val)
  148. {
  149. void __iomem *base = (void __iomem *)context;
  150. u32 tmp;
  151. /* De-assert reset */
  152. writel(readl(base) | ADDA_PR_RESET, base);
  153. /* Set register address */
  154. tmp = readl(base);
  155. tmp &= ~(ADDA_PR_ADDR_MASK << ADDA_PR_ADDR_SHIFT);
  156. tmp |= (reg & ADDA_PR_ADDR_MASK) << ADDA_PR_ADDR_SHIFT;
  157. writel(tmp, base);
  158. /* Set data to write */
  159. tmp = readl(base);
  160. tmp &= ~(ADDA_PR_DATA_IN_MASK << ADDA_PR_DATA_IN_SHIFT);
  161. tmp |= (val & ADDA_PR_DATA_IN_MASK) << ADDA_PR_DATA_IN_SHIFT;
  162. writel(tmp, base);
  163. /* Set write bit to signal a write */
  164. writel(readl(base) | ADDA_PR_WRITE, base);
  165. /* Clear write bit */
  166. writel(readl(base) & ~ADDA_PR_WRITE, base);
  167. return 0;
  168. }
  169. static const struct regmap_config adda_pr_regmap_cfg = {
  170. .name = "adda-pr",
  171. .reg_bits = 5,
  172. .reg_stride = 1,
  173. .val_bits = 8,
  174. .reg_read = adda_reg_read,
  175. .reg_write = adda_reg_write,
  176. .fast_io = true,
  177. .max_register = 24,
  178. };
  179. /* mixer controls */
  180. static const struct snd_kcontrol_new sun8i_codec_mixer_controls[] = {
  181. SOC_DAPM_DOUBLE_R("DAC Playback Switch",
  182. SUN8I_ADDA_LOMIXSC,
  183. SUN8I_ADDA_ROMIXSC,
  184. SUN8I_ADDA_LOMIXSC_DACL, 1, 0),
  185. SOC_DAPM_DOUBLE_R("DAC Reversed Playback Switch",
  186. SUN8I_ADDA_LOMIXSC,
  187. SUN8I_ADDA_ROMIXSC,
  188. SUN8I_ADDA_LOMIXSC_DACR, 1, 0),
  189. SOC_DAPM_DOUBLE_R("Line In Playback Switch",
  190. SUN8I_ADDA_LOMIXSC,
  191. SUN8I_ADDA_ROMIXSC,
  192. SUN8I_ADDA_LOMIXSC_LINEINL, 1, 0),
  193. SOC_DAPM_DOUBLE_R("Mic1 Playback Switch",
  194. SUN8I_ADDA_LOMIXSC,
  195. SUN8I_ADDA_ROMIXSC,
  196. SUN8I_ADDA_LOMIXSC_MIC1, 1, 0),
  197. SOC_DAPM_DOUBLE_R("Mic2 Playback Switch",
  198. SUN8I_ADDA_LOMIXSC,
  199. SUN8I_ADDA_ROMIXSC,
  200. SUN8I_ADDA_LOMIXSC_MIC2, 1, 0),
  201. };
  202. /* mixer controls */
  203. static const struct snd_kcontrol_new sun8i_v3s_codec_mixer_controls[] = {
  204. SOC_DAPM_DOUBLE_R("DAC Playback Switch",
  205. SUN8I_ADDA_LOMIXSC,
  206. SUN8I_ADDA_ROMIXSC,
  207. SUN8I_ADDA_LOMIXSC_DACL, 1, 0),
  208. SOC_DAPM_DOUBLE_R("DAC Reversed Playback Switch",
  209. SUN8I_ADDA_LOMIXSC,
  210. SUN8I_ADDA_ROMIXSC,
  211. SUN8I_ADDA_LOMIXSC_DACR, 1, 0),
  212. SOC_DAPM_DOUBLE_R("Mic1 Playback Switch",
  213. SUN8I_ADDA_LOMIXSC,
  214. SUN8I_ADDA_ROMIXSC,
  215. SUN8I_ADDA_LOMIXSC_MIC1, 1, 0),
  216. };
  217. /* ADC mixer controls */
  218. static const struct snd_kcontrol_new sun8i_codec_adc_mixer_controls[] = {
  219. SOC_DAPM_DOUBLE_R("Mixer Capture Switch",
  220. SUN8I_ADDA_LADCMIXSC,
  221. SUN8I_ADDA_RADCMIXSC,
  222. SUN8I_ADDA_LADCMIXSC_OMIXRL, 1, 0),
  223. SOC_DAPM_DOUBLE_R("Mixer Reversed Capture Switch",
  224. SUN8I_ADDA_LADCMIXSC,
  225. SUN8I_ADDA_RADCMIXSC,
  226. SUN8I_ADDA_LADCMIXSC_OMIXRR, 1, 0),
  227. SOC_DAPM_DOUBLE_R("Line In Capture Switch",
  228. SUN8I_ADDA_LADCMIXSC,
  229. SUN8I_ADDA_RADCMIXSC,
  230. SUN8I_ADDA_LADCMIXSC_LINEINL, 1, 0),
  231. SOC_DAPM_DOUBLE_R("Mic1 Capture Switch",
  232. SUN8I_ADDA_LADCMIXSC,
  233. SUN8I_ADDA_RADCMIXSC,
  234. SUN8I_ADDA_LADCMIXSC_MIC1, 1, 0),
  235. SOC_DAPM_DOUBLE_R("Mic2 Capture Switch",
  236. SUN8I_ADDA_LADCMIXSC,
  237. SUN8I_ADDA_RADCMIXSC,
  238. SUN8I_ADDA_LADCMIXSC_MIC2, 1, 0),
  239. };
  240. /* ADC mixer controls */
  241. static const struct snd_kcontrol_new sun8i_v3s_codec_adc_mixer_controls[] = {
  242. SOC_DAPM_DOUBLE_R("Mixer Capture Switch",
  243. SUN8I_ADDA_LADCMIXSC,
  244. SUN8I_ADDA_RADCMIXSC,
  245. SUN8I_ADDA_LADCMIXSC_OMIXRL, 1, 0),
  246. SOC_DAPM_DOUBLE_R("Mixer Reversed Capture Switch",
  247. SUN8I_ADDA_LADCMIXSC,
  248. SUN8I_ADDA_RADCMIXSC,
  249. SUN8I_ADDA_LADCMIXSC_OMIXRR, 1, 0),
  250. SOC_DAPM_DOUBLE_R("Mic1 Capture Switch",
  251. SUN8I_ADDA_LADCMIXSC,
  252. SUN8I_ADDA_RADCMIXSC,
  253. SUN8I_ADDA_LADCMIXSC_MIC1, 1, 0),
  254. };
  255. /* volume / mute controls */
  256. static const DECLARE_TLV_DB_SCALE(sun8i_codec_out_mixer_pregain_scale,
  257. -450, 150, 0);
  258. static const DECLARE_TLV_DB_RANGE(sun8i_codec_mic_gain_scale,
  259. 0, 0, TLV_DB_SCALE_ITEM(0, 0, 0),
  260. 1, 7, TLV_DB_SCALE_ITEM(2400, 300, 0),
  261. );
  262. static const struct snd_kcontrol_new sun8i_codec_common_controls[] = {
  263. /* Mixer pre-gain */
  264. SOC_SINGLE_TLV("Mic1 Playback Volume", SUN8I_ADDA_MICIN_GCTRL,
  265. SUN8I_ADDA_MICIN_GCTRL_MIC1G,
  266. 0x7, 0, sun8i_codec_out_mixer_pregain_scale),
  267. /* Microphone Amp boost gain */
  268. SOC_SINGLE_TLV("Mic1 Boost Volume", SUN8I_ADDA_MIC1G_MICBIAS_CTRL,
  269. SUN8I_ADDA_MIC1G_MICBIAS_CTRL_MIC1BOOST, 0x7, 0,
  270. sun8i_codec_mic_gain_scale),
  271. /* ADC */
  272. SOC_SINGLE_TLV("ADC Gain Capture Volume", SUN8I_ADDA_ADC_AP_EN,
  273. SUN8I_ADDA_ADC_AP_EN_ADCG, 0x7, 0,
  274. sun8i_codec_out_mixer_pregain_scale),
  275. };
  276. static const struct snd_soc_dapm_widget sun8i_codec_common_widgets[] = {
  277. /* ADC */
  278. SND_SOC_DAPM_ADC("Left ADC", NULL, SUN8I_ADDA_ADC_AP_EN,
  279. SUN8I_ADDA_ADC_AP_EN_ADCLEN, 0),
  280. SND_SOC_DAPM_ADC("Right ADC", NULL, SUN8I_ADDA_ADC_AP_EN,
  281. SUN8I_ADDA_ADC_AP_EN_ADCREN, 0),
  282. /* DAC */
  283. SND_SOC_DAPM_DAC("Left DAC", NULL, SUN8I_ADDA_DAC_PA_SRC,
  284. SUN8I_ADDA_DAC_PA_SRC_DACALEN, 0),
  285. SND_SOC_DAPM_DAC("Right DAC", NULL, SUN8I_ADDA_DAC_PA_SRC,
  286. SUN8I_ADDA_DAC_PA_SRC_DACAREN, 0),
  287. /*
  288. * Due to this component and the codec belonging to separate DAPM
  289. * contexts, we need to manually link the above widgets to their
  290. * stream widgets at the card level.
  291. */
  292. /* Microphone input */
  293. SND_SOC_DAPM_INPUT("MIC1"),
  294. /* Mic input path */
  295. SND_SOC_DAPM_PGA("Mic1 Amplifier", SUN8I_ADDA_MIC1G_MICBIAS_CTRL,
  296. SUN8I_ADDA_MIC1G_MICBIAS_CTRL_MIC1AMPEN, 0, NULL, 0),
  297. };
  298. static const struct snd_soc_dapm_widget sun8i_codec_mixer_widgets[] = {
  299. SND_SOC_DAPM_MIXER("Left Mixer", SUN8I_ADDA_DAC_PA_SRC,
  300. SUN8I_ADDA_DAC_PA_SRC_LMIXEN, 0,
  301. sun8i_codec_mixer_controls,
  302. ARRAY_SIZE(sun8i_codec_mixer_controls)),
  303. SND_SOC_DAPM_MIXER("Right Mixer", SUN8I_ADDA_DAC_PA_SRC,
  304. SUN8I_ADDA_DAC_PA_SRC_RMIXEN, 0,
  305. sun8i_codec_mixer_controls,
  306. ARRAY_SIZE(sun8i_codec_mixer_controls)),
  307. SND_SOC_DAPM_MIXER("Left ADC Mixer", SUN8I_ADDA_ADC_AP_EN,
  308. SUN8I_ADDA_ADC_AP_EN_ADCLEN, 0,
  309. sun8i_codec_adc_mixer_controls,
  310. ARRAY_SIZE(sun8i_codec_adc_mixer_controls)),
  311. SND_SOC_DAPM_MIXER("Right ADC Mixer", SUN8I_ADDA_ADC_AP_EN,
  312. SUN8I_ADDA_ADC_AP_EN_ADCREN, 0,
  313. sun8i_codec_adc_mixer_controls,
  314. ARRAY_SIZE(sun8i_codec_adc_mixer_controls)),
  315. };
  316. static const struct snd_soc_dapm_widget sun8i_v3s_codec_mixer_widgets[] = {
  317. SND_SOC_DAPM_MIXER("Left Mixer", SUN8I_ADDA_DAC_PA_SRC,
  318. SUN8I_ADDA_DAC_PA_SRC_LMIXEN, 0,
  319. sun8i_v3s_codec_mixer_controls,
  320. ARRAY_SIZE(sun8i_v3s_codec_mixer_controls)),
  321. SND_SOC_DAPM_MIXER("Right Mixer", SUN8I_ADDA_DAC_PA_SRC,
  322. SUN8I_ADDA_DAC_PA_SRC_RMIXEN, 0,
  323. sun8i_v3s_codec_mixer_controls,
  324. ARRAY_SIZE(sun8i_v3s_codec_mixer_controls)),
  325. SND_SOC_DAPM_MIXER("Left ADC Mixer", SUN8I_ADDA_ADC_AP_EN,
  326. SUN8I_ADDA_ADC_AP_EN_ADCLEN, 0,
  327. sun8i_v3s_codec_adc_mixer_controls,
  328. ARRAY_SIZE(sun8i_v3s_codec_adc_mixer_controls)),
  329. SND_SOC_DAPM_MIXER("Right ADC Mixer", SUN8I_ADDA_ADC_AP_EN,
  330. SUN8I_ADDA_ADC_AP_EN_ADCREN, 0,
  331. sun8i_v3s_codec_adc_mixer_controls,
  332. ARRAY_SIZE(sun8i_v3s_codec_adc_mixer_controls)),
  333. };
  334. static const struct snd_soc_dapm_route sun8i_codec_common_routes[] = {
  335. /* Microphone Routes */
  336. { "Mic1 Amplifier", NULL, "MIC1"},
  337. };
  338. static const struct snd_soc_dapm_route sun8i_codec_mixer_routes[] = {
  339. /* Left Mixer Routes */
  340. { "Left Mixer", "DAC Playback Switch", "Left DAC" },
  341. { "Left Mixer", "DAC Reversed Playback Switch", "Right DAC" },
  342. { "Left Mixer", "Mic1 Playback Switch", "Mic1 Amplifier" },
  343. /* Right Mixer Routes */
  344. { "Right Mixer", "DAC Playback Switch", "Right DAC" },
  345. { "Right Mixer", "DAC Reversed Playback Switch", "Left DAC" },
  346. { "Right Mixer", "Mic1 Playback Switch", "Mic1 Amplifier" },
  347. /* Left ADC Mixer Routes */
  348. { "Left ADC Mixer", "Mixer Capture Switch", "Left Mixer" },
  349. { "Left ADC Mixer", "Mixer Reversed Capture Switch", "Right Mixer" },
  350. { "Left ADC Mixer", "Mic1 Capture Switch", "Mic1 Amplifier" },
  351. /* Right ADC Mixer Routes */
  352. { "Right ADC Mixer", "Mixer Capture Switch", "Right Mixer" },
  353. { "Right ADC Mixer", "Mixer Reversed Capture Switch", "Left Mixer" },
  354. { "Right ADC Mixer", "Mic1 Capture Switch", "Mic1 Amplifier" },
  355. /* ADC Routes */
  356. { "Left ADC", NULL, "Left ADC Mixer" },
  357. { "Right ADC", NULL, "Right ADC Mixer" },
  358. };
  359. /* headphone specific controls, widgets, and routes */
  360. static const DECLARE_TLV_DB_SCALE(sun8i_codec_hp_vol_scale, -6300, 100, 1);
  361. static const struct snd_kcontrol_new sun8i_codec_headphone_controls[] = {
  362. SOC_SINGLE_TLV("Headphone Playback Volume",
  363. SUN8I_ADDA_HP_VOLC,
  364. SUN8I_ADDA_HP_VOLC_HP_VOL, 0x3f, 0,
  365. sun8i_codec_hp_vol_scale),
  366. SOC_DOUBLE("Headphone Playback Switch",
  367. SUN8I_ADDA_DAC_PA_SRC,
  368. SUN8I_ADDA_DAC_PA_SRC_LHPPAMUTE,
  369. SUN8I_ADDA_DAC_PA_SRC_RHPPAMUTE, 1, 0),
  370. };
  371. static const char * const sun8i_codec_hp_src_enum_text[] = {
  372. "DAC", "Mixer",
  373. };
  374. static SOC_ENUM_DOUBLE_DECL(sun8i_codec_hp_src_enum,
  375. SUN8I_ADDA_DAC_PA_SRC,
  376. SUN8I_ADDA_DAC_PA_SRC_LHPIS,
  377. SUN8I_ADDA_DAC_PA_SRC_RHPIS,
  378. sun8i_codec_hp_src_enum_text);
  379. static const struct snd_kcontrol_new sun8i_codec_hp_src[] = {
  380. SOC_DAPM_ENUM("Headphone Source Playback Route",
  381. sun8i_codec_hp_src_enum),
  382. };
  383. static int sun8i_headphone_amp_event(struct snd_soc_dapm_widget *w,
  384. struct snd_kcontrol *k, int event)
  385. {
  386. struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
  387. if (SND_SOC_DAPM_EVENT_ON(event)) {
  388. snd_soc_component_update_bits(component, SUN8I_ADDA_PAEN_HP_CTRL,
  389. BIT(SUN8I_ADDA_PAEN_HP_CTRL_HPPAEN),
  390. BIT(SUN8I_ADDA_PAEN_HP_CTRL_HPPAEN));
  391. /*
  392. * Need a delay to have the amplifier up. 700ms seems the best
  393. * compromise between the time to let the amplifier up and the
  394. * time not to feel this delay while playing a sound.
  395. */
  396. msleep(700);
  397. } else if (SND_SOC_DAPM_EVENT_OFF(event)) {
  398. snd_soc_component_update_bits(component, SUN8I_ADDA_PAEN_HP_CTRL,
  399. BIT(SUN8I_ADDA_PAEN_HP_CTRL_HPPAEN),
  400. 0x0);
  401. }
  402. return 0;
  403. }
  404. static const struct snd_soc_dapm_widget sun8i_codec_headphone_widgets[] = {
  405. SND_SOC_DAPM_MUX("Headphone Source Playback Route",
  406. SND_SOC_NOPM, 0, 0, sun8i_codec_hp_src),
  407. SND_SOC_DAPM_OUT_DRV_E("Headphone Amp", SUN8I_ADDA_PAEN_HP_CTRL,
  408. SUN8I_ADDA_PAEN_HP_CTRL_HPPAEN, 0, NULL, 0,
  409. sun8i_headphone_amp_event,
  410. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD),
  411. SND_SOC_DAPM_SUPPLY("HPCOM Protection", SUN8I_ADDA_PAEN_HP_CTRL,
  412. SUN8I_ADDA_PAEN_HP_CTRL_COMPTEN, 0, NULL, 0),
  413. SND_SOC_DAPM_REG(snd_soc_dapm_supply, "HPCOM", SUN8I_ADDA_PAEN_HP_CTRL,
  414. SUN8I_ADDA_PAEN_HP_CTRL_HPCOM_FC, 0x3, 0x3, 0),
  415. SND_SOC_DAPM_OUTPUT("HP"),
  416. };
  417. static const struct snd_soc_dapm_route sun8i_codec_headphone_routes[] = {
  418. { "Headphone Source Playback Route", "DAC", "Left DAC" },
  419. { "Headphone Source Playback Route", "DAC", "Right DAC" },
  420. { "Headphone Source Playback Route", "Mixer", "Left Mixer" },
  421. { "Headphone Source Playback Route", "Mixer", "Right Mixer" },
  422. { "Headphone Amp", NULL, "Headphone Source Playback Route" },
  423. { "HPCOM", NULL, "HPCOM Protection" },
  424. { "HP", NULL, "Headphone Amp" },
  425. };
  426. static int sun8i_codec_add_headphone(struct snd_soc_component *cmpnt)
  427. {
  428. struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(cmpnt);
  429. struct device *dev = cmpnt->dev;
  430. int ret;
  431. ret = snd_soc_add_component_controls(cmpnt,
  432. sun8i_codec_headphone_controls,
  433. ARRAY_SIZE(sun8i_codec_headphone_controls));
  434. if (ret) {
  435. dev_err(dev, "Failed to add Headphone controls: %d\n", ret);
  436. return ret;
  437. }
  438. ret = snd_soc_dapm_new_controls(dapm, sun8i_codec_headphone_widgets,
  439. ARRAY_SIZE(sun8i_codec_headphone_widgets));
  440. if (ret) {
  441. dev_err(dev, "Failed to add Headphone DAPM widgets: %d\n", ret);
  442. return ret;
  443. }
  444. ret = snd_soc_dapm_add_routes(dapm, sun8i_codec_headphone_routes,
  445. ARRAY_SIZE(sun8i_codec_headphone_routes));
  446. if (ret) {
  447. dev_err(dev, "Failed to add Headphone DAPM routes: %d\n", ret);
  448. return ret;
  449. }
  450. return 0;
  451. }
  452. /* mbias specific widget */
  453. static const struct snd_soc_dapm_widget sun8i_codec_mbias_widgets[] = {
  454. SND_SOC_DAPM_SUPPLY("MBIAS", SUN8I_ADDA_MIC1G_MICBIAS_CTRL,
  455. SUN8I_ADDA_MIC1G_MICBIAS_CTRL_MMICBIASEN,
  456. 0, NULL, 0),
  457. };
  458. static int sun8i_codec_add_mbias(struct snd_soc_component *cmpnt)
  459. {
  460. struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(cmpnt);
  461. struct device *dev = cmpnt->dev;
  462. int ret;
  463. ret = snd_soc_dapm_new_controls(dapm, sun8i_codec_mbias_widgets,
  464. ARRAY_SIZE(sun8i_codec_mbias_widgets));
  465. if (ret)
  466. dev_err(dev, "Failed to add MBIAS DAPM widgets: %d\n", ret);
  467. return ret;
  468. }
  469. /* hmic specific widget */
  470. static const struct snd_soc_dapm_widget sun8i_codec_hmic_widgets[] = {
  471. SND_SOC_DAPM_SUPPLY("HBIAS", SUN8I_ADDA_MIC1G_MICBIAS_CTRL,
  472. SUN8I_ADDA_MIC1G_MICBIAS_CTRL_HMICBIASEN,
  473. 0, NULL, 0),
  474. };
  475. static int sun8i_codec_add_hmic(struct snd_soc_component *cmpnt)
  476. {
  477. struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(cmpnt);
  478. struct device *dev = cmpnt->dev;
  479. int ret;
  480. ret = snd_soc_dapm_new_controls(dapm, sun8i_codec_hmic_widgets,
  481. ARRAY_SIZE(sun8i_codec_hmic_widgets));
  482. if (ret)
  483. dev_err(dev, "Failed to add Mic3 DAPM widgets: %d\n", ret);
  484. return ret;
  485. }
  486. /* line in specific controls, widgets and rines */
  487. static const struct snd_kcontrol_new sun8i_codec_linein_controls[] = {
  488. /* Mixer pre-gain */
  489. SOC_SINGLE_TLV("Line In Playback Volume", SUN8I_ADDA_LINEIN_GCTRL,
  490. SUN8I_ADDA_LINEIN_GCTRL_LINEING,
  491. 0x7, 0, sun8i_codec_out_mixer_pregain_scale),
  492. };
  493. static const struct snd_soc_dapm_widget sun8i_codec_linein_widgets[] = {
  494. /* Line input */
  495. SND_SOC_DAPM_INPUT("LINEIN"),
  496. };
  497. static const struct snd_soc_dapm_route sun8i_codec_linein_routes[] = {
  498. { "Left Mixer", "Line In Playback Switch", "LINEIN" },
  499. { "Right Mixer", "Line In Playback Switch", "LINEIN" },
  500. { "Left ADC Mixer", "Line In Capture Switch", "LINEIN" },
  501. { "Right ADC Mixer", "Line In Capture Switch", "LINEIN" },
  502. };
  503. static int sun8i_codec_add_linein(struct snd_soc_component *cmpnt)
  504. {
  505. struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(cmpnt);
  506. struct device *dev = cmpnt->dev;
  507. int ret;
  508. ret = snd_soc_add_component_controls(cmpnt,
  509. sun8i_codec_linein_controls,
  510. ARRAY_SIZE(sun8i_codec_linein_controls));
  511. if (ret) {
  512. dev_err(dev, "Failed to add Line In controls: %d\n", ret);
  513. return ret;
  514. }
  515. ret = snd_soc_dapm_new_controls(dapm, sun8i_codec_linein_widgets,
  516. ARRAY_SIZE(sun8i_codec_linein_widgets));
  517. if (ret) {
  518. dev_err(dev, "Failed to add Line In DAPM widgets: %d\n", ret);
  519. return ret;
  520. }
  521. ret = snd_soc_dapm_add_routes(dapm, sun8i_codec_linein_routes,
  522. ARRAY_SIZE(sun8i_codec_linein_routes));
  523. if (ret) {
  524. dev_err(dev, "Failed to add Line In DAPM routes: %d\n", ret);
  525. return ret;
  526. }
  527. return 0;
  528. }
  529. /* line out specific controls, widgets and routes */
  530. static const DECLARE_TLV_DB_RANGE(sun8i_codec_lineout_vol_scale,
  531. 0, 1, TLV_DB_SCALE_ITEM(TLV_DB_GAIN_MUTE, 0, 1),
  532. 2, 31, TLV_DB_SCALE_ITEM(-4350, 150, 0),
  533. );
  534. static const struct snd_kcontrol_new sun8i_codec_lineout_controls[] = {
  535. SOC_SINGLE_TLV("Line Out Playback Volume",
  536. SUN8I_ADDA_PHONE_GAIN_CTRL,
  537. SUN8I_ADDA_PHONE_GAIN_CTRL_LINEOUT_VOL, 0x1f, 0,
  538. sun8i_codec_lineout_vol_scale),
  539. SOC_DOUBLE("Line Out Playback Switch",
  540. SUN8I_ADDA_MIC2G_CTRL,
  541. SUN8I_ADDA_MIC2G_CTRL_LINEOUTLEN,
  542. SUN8I_ADDA_MIC2G_CTRL_LINEOUTREN, 1, 0),
  543. };
  544. static const char * const sun8i_codec_lineout_src_enum_text[] = {
  545. "Stereo", "Mono Differential",
  546. };
  547. static SOC_ENUM_DOUBLE_DECL(sun8i_codec_lineout_src_enum,
  548. SUN8I_ADDA_MIC2G_CTRL,
  549. SUN8I_ADDA_MIC2G_CTRL_LINEOUTLSRC,
  550. SUN8I_ADDA_MIC2G_CTRL_LINEOUTRSRC,
  551. sun8i_codec_lineout_src_enum_text);
  552. static const struct snd_kcontrol_new sun8i_codec_lineout_src[] = {
  553. SOC_DAPM_ENUM("Line Out Source Playback Route",
  554. sun8i_codec_lineout_src_enum),
  555. };
  556. static const struct snd_soc_dapm_widget sun8i_codec_lineout_widgets[] = {
  557. SND_SOC_DAPM_MUX("Line Out Source Playback Route",
  558. SND_SOC_NOPM, 0, 0, sun8i_codec_lineout_src),
  559. /* It is unclear if this is a buffer or gate, model it as a supply */
  560. SND_SOC_DAPM_SUPPLY("Line Out Enable", SUN8I_ADDA_PAEN_HP_CTRL,
  561. SUN8I_ADDA_PAEN_HP_CTRL_LINEOUTEN, 0, NULL, 0),
  562. SND_SOC_DAPM_OUTPUT("LINEOUT"),
  563. };
  564. static const struct snd_soc_dapm_route sun8i_codec_lineout_routes[] = {
  565. { "Line Out Source Playback Route", "Stereo", "Left Mixer" },
  566. { "Line Out Source Playback Route", "Stereo", "Right Mixer" },
  567. { "Line Out Source Playback Route", "Mono Differential", "Left Mixer" },
  568. { "Line Out Source Playback Route", "Mono Differential", "Right Mixer" },
  569. { "LINEOUT", NULL, "Line Out Source Playback Route" },
  570. { "LINEOUT", NULL, "Line Out Enable", },
  571. };
  572. static int sun8i_codec_add_lineout(struct snd_soc_component *cmpnt)
  573. {
  574. struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(cmpnt);
  575. struct device *dev = cmpnt->dev;
  576. int ret;
  577. ret = snd_soc_add_component_controls(cmpnt,
  578. sun8i_codec_lineout_controls,
  579. ARRAY_SIZE(sun8i_codec_lineout_controls));
  580. if (ret) {
  581. dev_err(dev, "Failed to add Line Out controls: %d\n", ret);
  582. return ret;
  583. }
  584. ret = snd_soc_dapm_new_controls(dapm, sun8i_codec_lineout_widgets,
  585. ARRAY_SIZE(sun8i_codec_lineout_widgets));
  586. if (ret) {
  587. dev_err(dev, "Failed to add Line Out DAPM widgets: %d\n", ret);
  588. return ret;
  589. }
  590. ret = snd_soc_dapm_add_routes(dapm, sun8i_codec_lineout_routes,
  591. ARRAY_SIZE(sun8i_codec_lineout_routes));
  592. if (ret) {
  593. dev_err(dev, "Failed to add Line Out DAPM routes: %d\n", ret);
  594. return ret;
  595. }
  596. return 0;
  597. }
  598. /* mic2 specific controls, widgets and routes */
  599. static const struct snd_kcontrol_new sun8i_codec_mic2_controls[] = {
  600. /* Mixer pre-gain */
  601. SOC_SINGLE_TLV("Mic2 Playback Volume",
  602. SUN8I_ADDA_MICIN_GCTRL, SUN8I_ADDA_MICIN_GCTRL_MIC2G,
  603. 0x7, 0, sun8i_codec_out_mixer_pregain_scale),
  604. /* Microphone Amp boost gain */
  605. SOC_SINGLE_TLV("Mic2 Boost Volume", SUN8I_ADDA_MIC2G_CTRL,
  606. SUN8I_ADDA_MIC2G_CTRL_MIC2BOOST, 0x7, 0,
  607. sun8i_codec_mic_gain_scale),
  608. };
  609. static const struct snd_soc_dapm_widget sun8i_codec_mic2_widgets[] = {
  610. /* Microphone input */
  611. SND_SOC_DAPM_INPUT("MIC2"),
  612. /* Mic input path */
  613. SND_SOC_DAPM_PGA("Mic2 Amplifier", SUN8I_ADDA_MIC2G_CTRL,
  614. SUN8I_ADDA_MIC2G_CTRL_MIC2AMPEN, 0, NULL, 0),
  615. };
  616. static const struct snd_soc_dapm_route sun8i_codec_mic2_routes[] = {
  617. { "Mic2 Amplifier", NULL, "MIC2"},
  618. { "Left Mixer", "Mic2 Playback Switch", "Mic2 Amplifier" },
  619. { "Right Mixer", "Mic2 Playback Switch", "Mic2 Amplifier" },
  620. { "Left ADC Mixer", "Mic2 Capture Switch", "Mic2 Amplifier" },
  621. { "Right ADC Mixer", "Mic2 Capture Switch", "Mic2 Amplifier" },
  622. };
  623. static int sun8i_codec_add_mic2(struct snd_soc_component *cmpnt)
  624. {
  625. struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(cmpnt);
  626. struct device *dev = cmpnt->dev;
  627. int ret;
  628. ret = snd_soc_add_component_controls(cmpnt,
  629. sun8i_codec_mic2_controls,
  630. ARRAY_SIZE(sun8i_codec_mic2_controls));
  631. if (ret) {
  632. dev_err(dev, "Failed to add MIC2 controls: %d\n", ret);
  633. return ret;
  634. }
  635. ret = snd_soc_dapm_new_controls(dapm, sun8i_codec_mic2_widgets,
  636. ARRAY_SIZE(sun8i_codec_mic2_widgets));
  637. if (ret) {
  638. dev_err(dev, "Failed to add MIC2 DAPM widgets: %d\n", ret);
  639. return ret;
  640. }
  641. ret = snd_soc_dapm_add_routes(dapm, sun8i_codec_mic2_routes,
  642. ARRAY_SIZE(sun8i_codec_mic2_routes));
  643. if (ret) {
  644. dev_err(dev, "Failed to add MIC2 DAPM routes: %d\n", ret);
  645. return ret;
  646. }
  647. return 0;
  648. }
  649. struct sun8i_codec_analog_quirks {
  650. bool has_headphone;
  651. bool has_hmic;
  652. bool has_linein;
  653. bool has_lineout;
  654. bool has_mbias;
  655. bool has_mic2;
  656. };
  657. static const struct sun8i_codec_analog_quirks sun8i_a23_quirks = {
  658. .has_headphone = true,
  659. .has_hmic = true,
  660. .has_linein = true,
  661. .has_mbias = true,
  662. .has_mic2 = true,
  663. };
  664. static const struct sun8i_codec_analog_quirks sun8i_h3_quirks = {
  665. .has_linein = true,
  666. .has_lineout = true,
  667. .has_mbias = true,
  668. .has_mic2 = true,
  669. };
  670. static int sun8i_codec_analog_add_mixer(struct snd_soc_component *cmpnt,
  671. const struct sun8i_codec_analog_quirks *quirks)
  672. {
  673. struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(cmpnt);
  674. struct device *dev = cmpnt->dev;
  675. int ret;
  676. if (!quirks->has_mic2 && !quirks->has_linein) {
  677. /*
  678. * Apply the special widget set which has uses a control
  679. * without MIC2 and Line In, for SoCs without these.
  680. * TODO: not all special cases are supported now, this case
  681. * is present because it's the case of V3s.
  682. */
  683. ret = snd_soc_dapm_new_controls(dapm,
  684. sun8i_v3s_codec_mixer_widgets,
  685. ARRAY_SIZE(sun8i_v3s_codec_mixer_widgets));
  686. if (ret) {
  687. dev_err(dev, "Failed to add V3s Mixer DAPM widgets: %d\n", ret);
  688. return ret;
  689. }
  690. } else {
  691. /* Apply the generic mixer widget set. */
  692. ret = snd_soc_dapm_new_controls(dapm,
  693. sun8i_codec_mixer_widgets,
  694. ARRAY_SIZE(sun8i_codec_mixer_widgets));
  695. if (ret) {
  696. dev_err(dev, "Failed to add Mixer DAPM widgets: %d\n", ret);
  697. return ret;
  698. }
  699. }
  700. ret = snd_soc_dapm_add_routes(dapm, sun8i_codec_mixer_routes,
  701. ARRAY_SIZE(sun8i_codec_mixer_routes));
  702. if (ret) {
  703. dev_err(dev, "Failed to add Mixer DAPM routes: %d\n", ret);
  704. return ret;
  705. }
  706. return 0;
  707. }
  708. static const struct sun8i_codec_analog_quirks sun8i_v3s_quirks = {
  709. .has_headphone = true,
  710. .has_hmic = true,
  711. };
  712. static int sun8i_codec_analog_cmpnt_probe(struct snd_soc_component *cmpnt)
  713. {
  714. struct device *dev = cmpnt->dev;
  715. const struct sun8i_codec_analog_quirks *quirks;
  716. int ret;
  717. /*
  718. * This would never return NULL unless someone directly registers a
  719. * platform device matching this driver's name, without specifying a
  720. * device tree node.
  721. */
  722. quirks = of_device_get_match_data(dev);
  723. /* Add controls, widgets, and routes for individual features */
  724. ret = sun8i_codec_analog_add_mixer(cmpnt, quirks);
  725. if (ret)
  726. return ret;
  727. if (quirks->has_headphone) {
  728. ret = sun8i_codec_add_headphone(cmpnt);
  729. if (ret)
  730. return ret;
  731. }
  732. if (quirks->has_hmic) {
  733. ret = sun8i_codec_add_hmic(cmpnt);
  734. if (ret)
  735. return ret;
  736. }
  737. if (quirks->has_linein) {
  738. ret = sun8i_codec_add_linein(cmpnt);
  739. if (ret)
  740. return ret;
  741. }
  742. if (quirks->has_lineout) {
  743. ret = sun8i_codec_add_lineout(cmpnt);
  744. if (ret)
  745. return ret;
  746. }
  747. if (quirks->has_mbias) {
  748. ret = sun8i_codec_add_mbias(cmpnt);
  749. if (ret)
  750. return ret;
  751. }
  752. if (quirks->has_mic2) {
  753. ret = sun8i_codec_add_mic2(cmpnt);
  754. if (ret)
  755. return ret;
  756. }
  757. return 0;
  758. }
  759. static const struct snd_soc_component_driver sun8i_codec_analog_cmpnt_drv = {
  760. .controls = sun8i_codec_common_controls,
  761. .num_controls = ARRAY_SIZE(sun8i_codec_common_controls),
  762. .dapm_widgets = sun8i_codec_common_widgets,
  763. .num_dapm_widgets = ARRAY_SIZE(sun8i_codec_common_widgets),
  764. .dapm_routes = sun8i_codec_common_routes,
  765. .num_dapm_routes = ARRAY_SIZE(sun8i_codec_common_routes),
  766. .probe = sun8i_codec_analog_cmpnt_probe,
  767. };
  768. static const struct of_device_id sun8i_codec_analog_of_match[] = {
  769. {
  770. .compatible = "allwinner,sun8i-a23-codec-analog",
  771. .data = &sun8i_a23_quirks,
  772. },
  773. {
  774. .compatible = "allwinner,sun8i-h3-codec-analog",
  775. .data = &sun8i_h3_quirks,
  776. },
  777. {
  778. .compatible = "allwinner,sun8i-v3s-codec-analog",
  779. .data = &sun8i_v3s_quirks,
  780. },
  781. {}
  782. };
  783. MODULE_DEVICE_TABLE(of, sun8i_codec_analog_of_match);
  784. static int sun8i_codec_analog_probe(struct platform_device *pdev)
  785. {
  786. struct resource *res;
  787. struct regmap *regmap;
  788. void __iomem *base;
  789. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  790. base = devm_ioremap_resource(&pdev->dev, res);
  791. if (IS_ERR(base)) {
  792. dev_err(&pdev->dev, "Failed to map the registers\n");
  793. return PTR_ERR(base);
  794. }
  795. regmap = devm_regmap_init(&pdev->dev, NULL, base, &adda_pr_regmap_cfg);
  796. if (IS_ERR(regmap)) {
  797. dev_err(&pdev->dev, "Failed to create regmap\n");
  798. return PTR_ERR(regmap);
  799. }
  800. return devm_snd_soc_register_component(&pdev->dev,
  801. &sun8i_codec_analog_cmpnt_drv,
  802. NULL, 0);
  803. }
  804. static struct platform_driver sun8i_codec_analog_driver = {
  805. .driver = {
  806. .name = "sun8i-codec-analog",
  807. .of_match_table = sun8i_codec_analog_of_match,
  808. },
  809. .probe = sun8i_codec_analog_probe,
  810. };
  811. module_platform_driver(sun8i_codec_analog_driver);
  812. MODULE_DESCRIPTION("Allwinner internal codec analog controls driver");
  813. MODULE_AUTHOR("Chen-Yu Tsai <wens@csie.org>");
  814. MODULE_LICENSE("GPL");
  815. MODULE_ALIAS("platform:sun8i-codec-analog");