sun8i-codec.c 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * This driver supports the digital controls for the internal codec
  4. * found in Allwinner's A33 SoCs.
  5. *
  6. * (C) Copyright 2010-2016
  7. * Reuuimlla Technology Co., Ltd. <www.reuuimllatech.com>
  8. * huangxin <huangxin@Reuuimllatech.com>
  9. * Mylène Josserand <mylene.josserand@free-electrons.com>
  10. */
  11. #include <linux/module.h>
  12. #include <linux/delay.h>
  13. #include <linux/clk.h>
  14. #include <linux/input.h>
  15. #include <linux/io.h>
  16. #include <linux/irq.h>
  17. #include <linux/mutex.h>
  18. #include <linux/of.h>
  19. #include <linux/pm_runtime.h>
  20. #include <linux/regmap.h>
  21. #include <linux/log2.h>
  22. #include <sound/jack.h>
  23. #include <sound/pcm_params.h>
  24. #include <sound/soc.h>
  25. #include <sound/soc-dapm.h>
  26. #include <sound/tlv.h>
  27. #define SUN8I_SYSCLK_CTL 0x00c
  28. #define SUN8I_SYSCLK_CTL_AIF1CLK_ENA 11
  29. #define SUN8I_SYSCLK_CTL_AIF1CLK_SRC_PLL (0x2 << 8)
  30. #define SUN8I_SYSCLK_CTL_AIF2CLK_ENA 7
  31. #define SUN8I_SYSCLK_CTL_AIF2CLK_SRC_PLL (0x2 << 4)
  32. #define SUN8I_SYSCLK_CTL_SYSCLK_ENA 3
  33. #define SUN8I_SYSCLK_CTL_SYSCLK_SRC 0
  34. #define SUN8I_SYSCLK_CTL_SYSCLK_SRC_AIF1CLK (0x0 << 0)
  35. #define SUN8I_SYSCLK_CTL_SYSCLK_SRC_AIF2CLK (0x1 << 0)
  36. #define SUN8I_MOD_CLK_ENA 0x010
  37. #define SUN8I_MOD_CLK_ENA_AIF1 15
  38. #define SUN8I_MOD_CLK_ENA_AIF2 14
  39. #define SUN8I_MOD_CLK_ENA_AIF3 13
  40. #define SUN8I_MOD_CLK_ENA_ADC 3
  41. #define SUN8I_MOD_CLK_ENA_DAC 2
  42. #define SUN8I_MOD_RST_CTL 0x014
  43. #define SUN8I_MOD_RST_CTL_AIF1 15
  44. #define SUN8I_MOD_RST_CTL_AIF2 14
  45. #define SUN8I_MOD_RST_CTL_AIF3 13
  46. #define SUN8I_MOD_RST_CTL_ADC 3
  47. #define SUN8I_MOD_RST_CTL_DAC 2
  48. #define SUN8I_SYS_SR_CTRL 0x018
  49. #define SUN8I_SYS_SR_CTRL_AIF1_FS 12
  50. #define SUN8I_SYS_SR_CTRL_AIF2_FS 8
  51. #define SUN8I_AIF_CLK_CTRL(n) (0x040 * (1 + (n)))
  52. #define SUN8I_AIF_CLK_CTRL_MSTR_MOD 15
  53. #define SUN8I_AIF_CLK_CTRL_CLK_INV 13
  54. #define SUN8I_AIF_CLK_CTRL_BCLK_DIV 9
  55. #define SUN8I_AIF_CLK_CTRL_LRCK_DIV 6
  56. #define SUN8I_AIF_CLK_CTRL_WORD_SIZ 4
  57. #define SUN8I_AIF_CLK_CTRL_DATA_FMT 2
  58. #define SUN8I_AIF1_ADCDAT_CTRL 0x044
  59. #define SUN8I_AIF1_ADCDAT_CTRL_AIF1_AD0L_ENA 15
  60. #define SUN8I_AIF1_ADCDAT_CTRL_AIF1_AD0R_ENA 14
  61. #define SUN8I_AIF1_ADCDAT_CTRL_AIF1_AD0L_SRC 10
  62. #define SUN8I_AIF1_ADCDAT_CTRL_AIF1_AD0R_SRC 8
  63. #define SUN8I_AIF1_DACDAT_CTRL 0x048
  64. #define SUN8I_AIF1_DACDAT_CTRL_AIF1_DA0L_ENA 15
  65. #define SUN8I_AIF1_DACDAT_CTRL_AIF1_DA0R_ENA 14
  66. #define SUN8I_AIF1_DACDAT_CTRL_AIF1_DA0L_SRC 10
  67. #define SUN8I_AIF1_DACDAT_CTRL_AIF1_DA0R_SRC 8
  68. #define SUN8I_AIF1_MXR_SRC 0x04c
  69. #define SUN8I_AIF1_MXR_SRC_AD0L_MXR_SRC_AIF1DA0L 15
  70. #define SUN8I_AIF1_MXR_SRC_AD0L_MXR_SRC_AIF2DACL 14
  71. #define SUN8I_AIF1_MXR_SRC_AD0L_MXR_SRC_ADCL 13
  72. #define SUN8I_AIF1_MXR_SRC_AD0L_MXR_SRC_AIF2DACR 12
  73. #define SUN8I_AIF1_MXR_SRC_AD0R_MXR_SRC_AIF1DA0R 11
  74. #define SUN8I_AIF1_MXR_SRC_AD0R_MXR_SRC_AIF2DACR 10
  75. #define SUN8I_AIF1_MXR_SRC_AD0R_MXR_SRC_ADCR 9
  76. #define SUN8I_AIF1_MXR_SRC_AD0R_MXR_SRC_AIF2DACL 8
  77. #define SUN8I_AIF1_VOL_CTRL1 0x050
  78. #define SUN8I_AIF1_VOL_CTRL1_AD0L_VOL 8
  79. #define SUN8I_AIF1_VOL_CTRL1_AD0R_VOL 0
  80. #define SUN8I_AIF1_VOL_CTRL3 0x058
  81. #define SUN8I_AIF1_VOL_CTRL3_DA0L_VOL 8
  82. #define SUN8I_AIF1_VOL_CTRL3_DA0R_VOL 0
  83. #define SUN8I_AIF2_ADCDAT_CTRL 0x084
  84. #define SUN8I_AIF2_ADCDAT_CTRL_AIF2_ADCL_ENA 15
  85. #define SUN8I_AIF2_ADCDAT_CTRL_AIF2_ADCR_ENA 14
  86. #define SUN8I_AIF2_ADCDAT_CTRL_AIF2_ADCL_SRC 10
  87. #define SUN8I_AIF2_ADCDAT_CTRL_AIF2_ADCR_SRC 8
  88. #define SUN8I_AIF2_DACDAT_CTRL 0x088
  89. #define SUN8I_AIF2_DACDAT_CTRL_AIF2_DACL_ENA 15
  90. #define SUN8I_AIF2_DACDAT_CTRL_AIF2_DACR_ENA 14
  91. #define SUN8I_AIF2_DACDAT_CTRL_AIF2_DACL_SRC 10
  92. #define SUN8I_AIF2_DACDAT_CTRL_AIF2_DACR_SRC 8
  93. #define SUN8I_AIF2_MXR_SRC 0x08c
  94. #define SUN8I_AIF2_MXR_SRC_ADCL_MXR_SRC_AIF1DA0L 15
  95. #define SUN8I_AIF2_MXR_SRC_ADCL_MXR_SRC_AIF1DA1L 14
  96. #define SUN8I_AIF2_MXR_SRC_ADCL_MXR_SRC_AIF2DACR 13
  97. #define SUN8I_AIF2_MXR_SRC_ADCL_MXR_SRC_ADCL 12
  98. #define SUN8I_AIF2_MXR_SRC_ADCR_MXR_SRC_AIF1DA0R 11
  99. #define SUN8I_AIF2_MXR_SRC_ADCR_MXR_SRC_AIF1DA1R 10
  100. #define SUN8I_AIF2_MXR_SRC_ADCR_MXR_SRC_AIF2DACL 9
  101. #define SUN8I_AIF2_MXR_SRC_ADCR_MXR_SRC_ADCR 8
  102. #define SUN8I_AIF2_VOL_CTRL1 0x090
  103. #define SUN8I_AIF2_VOL_CTRL1_ADCL_VOL 8
  104. #define SUN8I_AIF2_VOL_CTRL1_ADCR_VOL 0
  105. #define SUN8I_AIF2_VOL_CTRL2 0x098
  106. #define SUN8I_AIF2_VOL_CTRL2_DACL_VOL 8
  107. #define SUN8I_AIF2_VOL_CTRL2_DACR_VOL 0
  108. #define SUN8I_AIF3_CLK_CTRL_AIF3_CLK_SRC_AIF1 (0x0 << 0)
  109. #define SUN8I_AIF3_CLK_CTRL_AIF3_CLK_SRC_AIF2 (0x1 << 0)
  110. #define SUN8I_AIF3_CLK_CTRL_AIF3_CLK_SRC_AIF1CLK (0x2 << 0)
  111. #define SUN8I_AIF3_PATH_CTRL 0x0cc
  112. #define SUN8I_AIF3_PATH_CTRL_AIF3_ADC_SRC 10
  113. #define SUN8I_AIF3_PATH_CTRL_AIF2_DAC_SRC 8
  114. #define SUN8I_AIF3_PATH_CTRL_AIF3_PINS_TRI 7
  115. #define SUN8I_ADC_DIG_CTRL 0x100
  116. #define SUN8I_ADC_DIG_CTRL_ENAD 15
  117. #define SUN8I_ADC_DIG_CTRL_ADOUT_DTS 2
  118. #define SUN8I_ADC_DIG_CTRL_ADOUT_DLY 1
  119. #define SUN8I_ADC_VOL_CTRL 0x104
  120. #define SUN8I_ADC_VOL_CTRL_ADCL_VOL 8
  121. #define SUN8I_ADC_VOL_CTRL_ADCR_VOL 0
  122. #define SUN8I_HMIC_CTRL1 0x110
  123. #define SUN8I_HMIC_CTRL1_HMIC_M 12
  124. #define SUN8I_HMIC_CTRL1_HMIC_N 8
  125. #define SUN8I_HMIC_CTRL1_MDATA_THRESHOLD_DB 5
  126. #define SUN8I_HMIC_CTRL1_JACK_OUT_IRQ_EN 4
  127. #define SUN8I_HMIC_CTRL1_JACK_IN_IRQ_EN 3
  128. #define SUN8I_HMIC_CTRL1_HMIC_DATA_IRQ_EN 0
  129. #define SUN8I_HMIC_CTRL2 0x114
  130. #define SUN8I_HMIC_CTRL2_HMIC_SAMPLE 14
  131. #define SUN8I_HMIC_CTRL2_HMIC_MDATA_THRESHOLD 8
  132. #define SUN8I_HMIC_CTRL2_HMIC_SF 6
  133. #define SUN8I_HMIC_STS 0x118
  134. #define SUN8I_HMIC_STS_MDATA_DISCARD 13
  135. #define SUN8I_HMIC_STS_HMIC_DATA 8
  136. #define SUN8I_HMIC_STS_JACK_OUT_IRQ_ST 4
  137. #define SUN8I_HMIC_STS_JACK_IN_IRQ_ST 3
  138. #define SUN8I_HMIC_STS_HMIC_DATA_IRQ_ST 0
  139. #define SUN8I_DAC_DIG_CTRL 0x120
  140. #define SUN8I_DAC_DIG_CTRL_ENDA 15
  141. #define SUN8I_DAC_VOL_CTRL 0x124
  142. #define SUN8I_DAC_VOL_CTRL_DACL_VOL 8
  143. #define SUN8I_DAC_VOL_CTRL_DACR_VOL 0
  144. #define SUN8I_DAC_MXR_SRC 0x130
  145. #define SUN8I_DAC_MXR_SRC_DACL_MXR_SRC_AIF1DA0L 15
  146. #define SUN8I_DAC_MXR_SRC_DACL_MXR_SRC_AIF1DA1L 14
  147. #define SUN8I_DAC_MXR_SRC_DACL_MXR_SRC_AIF2DACL 13
  148. #define SUN8I_DAC_MXR_SRC_DACL_MXR_SRC_ADCL 12
  149. #define SUN8I_DAC_MXR_SRC_DACR_MXR_SRC_AIF1DA0R 11
  150. #define SUN8I_DAC_MXR_SRC_DACR_MXR_SRC_AIF1DA1R 10
  151. #define SUN8I_DAC_MXR_SRC_DACR_MXR_SRC_AIF2DACR 9
  152. #define SUN8I_DAC_MXR_SRC_DACR_MXR_SRC_ADCR 8
  153. #define SUN8I_SYSCLK_CTL_AIF1CLK_SRC_MASK GENMASK(9, 8)
  154. #define SUN8I_SYSCLK_CTL_AIF2CLK_SRC_MASK GENMASK(5, 4)
  155. #define SUN8I_SYS_SR_CTRL_AIF1_FS_MASK GENMASK(15, 12)
  156. #define SUN8I_SYS_SR_CTRL_AIF2_FS_MASK GENMASK(11, 8)
  157. #define SUN8I_AIF_CLK_CTRL_CLK_INV_MASK GENMASK(14, 13)
  158. #define SUN8I_AIF_CLK_CTRL_BCLK_DIV_MASK GENMASK(12, 9)
  159. #define SUN8I_AIF_CLK_CTRL_LRCK_DIV_MASK GENMASK(8, 6)
  160. #define SUN8I_AIF_CLK_CTRL_WORD_SIZ_MASK GENMASK(5, 4)
  161. #define SUN8I_AIF_CLK_CTRL_DATA_FMT_MASK GENMASK(3, 2)
  162. #define SUN8I_AIF3_CLK_CTRL_AIF3_CLK_SRC_MASK GENMASK(1, 0)
  163. #define SUN8I_HMIC_CTRL1_HMIC_M_MASK GENMASK(15, 12)
  164. #define SUN8I_HMIC_CTRL1_HMIC_N_MASK GENMASK(11, 8)
  165. #define SUN8I_HMIC_CTRL1_MDATA_THRESHOLD_DB_MASK GENMASK(6, 5)
  166. #define SUN8I_HMIC_CTRL2_HMIC_SAMPLE_MASK GENMASK(15, 14)
  167. #define SUN8I_HMIC_CTRL2_HMIC_SF_MASK GENMASK(7, 6)
  168. #define SUN8I_HMIC_STS_HMIC_DATA_MASK GENMASK(12, 8)
  169. #define SUN8I_CODEC_BUTTONS (SND_JACK_BTN_0|\
  170. SND_JACK_BTN_1|\
  171. SND_JACK_BTN_2|\
  172. SND_JACK_BTN_3)
  173. #define SUN8I_CODEC_PASSTHROUGH_SAMPLE_RATE 48000
  174. #define SUN8I_CODEC_PCM_FORMATS (SNDRV_PCM_FMTBIT_S8 |\
  175. SNDRV_PCM_FMTBIT_S16_LE |\
  176. SNDRV_PCM_FMTBIT_S20_LE |\
  177. SNDRV_PCM_FMTBIT_S24_LE |\
  178. SNDRV_PCM_FMTBIT_S20_3LE|\
  179. SNDRV_PCM_FMTBIT_S24_3LE)
  180. #define SUN8I_CODEC_PCM_RATES (SNDRV_PCM_RATE_8000_48000|\
  181. SNDRV_PCM_RATE_88200 |\
  182. SNDRV_PCM_RATE_96000 |\
  183. SNDRV_PCM_RATE_176400 |\
  184. SNDRV_PCM_RATE_192000 |\
  185. SNDRV_PCM_RATE_KNOT)
  186. enum {
  187. SUN8I_CODEC_AIF1,
  188. SUN8I_CODEC_AIF2,
  189. SUN8I_CODEC_AIF3,
  190. SUN8I_CODEC_NAIFS
  191. };
  192. struct sun8i_codec_aif {
  193. unsigned int lrck_div_order;
  194. unsigned int sample_rate;
  195. unsigned int slots;
  196. unsigned int slot_width;
  197. unsigned int active_streams : 2;
  198. unsigned int open_streams : 2;
  199. };
  200. struct sun8i_codec_quirks {
  201. bool bus_clock : 1;
  202. bool jack_detection : 1;
  203. bool legacy_widgets : 1;
  204. bool lrck_inversion : 1;
  205. };
  206. enum {
  207. SUN8I_JACK_STATUS_DISCONNECTED,
  208. SUN8I_JACK_STATUS_WAITING_HBIAS,
  209. SUN8I_JACK_STATUS_CONNECTED,
  210. };
  211. struct sun8i_codec {
  212. struct snd_soc_component *component;
  213. struct regmap *regmap;
  214. struct clk *clk_bus;
  215. struct clk *clk_module;
  216. const struct sun8i_codec_quirks *quirks;
  217. struct sun8i_codec_aif aifs[SUN8I_CODEC_NAIFS];
  218. struct snd_soc_jack *jack;
  219. struct delayed_work jack_work;
  220. int jack_irq;
  221. int jack_status;
  222. int jack_type;
  223. int jack_last_sample;
  224. ktime_t jack_hbias_ready;
  225. struct mutex jack_mutex;
  226. int last_hmic_irq;
  227. unsigned int sysclk_rate;
  228. int sysclk_refcnt;
  229. };
  230. static struct snd_soc_dai_driver sun8i_codec_dais[];
  231. static int sun8i_codec_runtime_resume(struct device *dev)
  232. {
  233. struct sun8i_codec *scodec = dev_get_drvdata(dev);
  234. int ret;
  235. if (scodec->clk_bus) {
  236. ret = clk_prepare_enable(scodec->clk_bus);
  237. if (ret) {
  238. dev_err(dev, "Failed to enable the bus clock\n");
  239. return ret;
  240. }
  241. }
  242. regcache_cache_only(scodec->regmap, false);
  243. ret = regcache_sync(scodec->regmap);
  244. if (ret) {
  245. dev_err(dev, "Failed to sync regmap cache\n");
  246. return ret;
  247. }
  248. return 0;
  249. }
  250. static int sun8i_codec_runtime_suspend(struct device *dev)
  251. {
  252. struct sun8i_codec *scodec = dev_get_drvdata(dev);
  253. regcache_cache_only(scodec->regmap, true);
  254. regcache_mark_dirty(scodec->regmap);
  255. if (scodec->clk_bus)
  256. clk_disable_unprepare(scodec->clk_bus);
  257. return 0;
  258. }
  259. static int sun8i_codec_get_hw_rate(unsigned int sample_rate)
  260. {
  261. switch (sample_rate) {
  262. case 7350:
  263. case 8000:
  264. return 0x0;
  265. case 11025:
  266. return 0x1;
  267. case 12000:
  268. return 0x2;
  269. case 14700:
  270. case 16000:
  271. return 0x3;
  272. case 22050:
  273. return 0x4;
  274. case 24000:
  275. return 0x5;
  276. case 29400:
  277. case 32000:
  278. return 0x6;
  279. case 44100:
  280. return 0x7;
  281. case 48000:
  282. return 0x8;
  283. case 88200:
  284. case 96000:
  285. return 0x9;
  286. case 176400:
  287. case 192000:
  288. return 0xa;
  289. default:
  290. return -EINVAL;
  291. }
  292. }
  293. static int sun8i_codec_update_sample_rate(struct sun8i_codec *scodec)
  294. {
  295. unsigned int max_rate = 0;
  296. int hw_rate, i;
  297. for (i = SUN8I_CODEC_AIF1; i < SUN8I_CODEC_NAIFS; ++i) {
  298. struct sun8i_codec_aif *aif = &scodec->aifs[i];
  299. if (aif->active_streams)
  300. max_rate = max(max_rate, aif->sample_rate);
  301. }
  302. /* Set the sample rate for ADC->DAC passthrough when no AIF is active. */
  303. if (!max_rate)
  304. max_rate = SUN8I_CODEC_PASSTHROUGH_SAMPLE_RATE;
  305. hw_rate = sun8i_codec_get_hw_rate(max_rate);
  306. if (hw_rate < 0)
  307. return hw_rate;
  308. regmap_update_bits(scodec->regmap, SUN8I_SYS_SR_CTRL,
  309. SUN8I_SYS_SR_CTRL_AIF1_FS_MASK,
  310. hw_rate << SUN8I_SYS_SR_CTRL_AIF1_FS);
  311. return 0;
  312. }
  313. static int sun8i_codec_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
  314. {
  315. struct sun8i_codec *scodec = snd_soc_dai_get_drvdata(dai);
  316. u32 dsp_format, format, invert, value;
  317. /* clock masters */
  318. switch (fmt & SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK) {
  319. case SND_SOC_DAIFMT_CBC_CFC: /* Codec slave, DAI master */
  320. value = 0x1;
  321. break;
  322. case SND_SOC_DAIFMT_CBP_CFP: /* Codec Master, DAI slave */
  323. value = 0x0;
  324. break;
  325. default:
  326. return -EINVAL;
  327. }
  328. if (dai->id == SUN8I_CODEC_AIF3) {
  329. /* AIF3 only supports master mode. */
  330. if (value)
  331. return -EINVAL;
  332. /* Use the AIF2 BCLK and LRCK for AIF3. */
  333. regmap_update_bits(scodec->regmap, SUN8I_AIF_CLK_CTRL(dai->id),
  334. SUN8I_AIF3_CLK_CTRL_AIF3_CLK_SRC_MASK,
  335. SUN8I_AIF3_CLK_CTRL_AIF3_CLK_SRC_AIF2);
  336. } else {
  337. regmap_update_bits(scodec->regmap, SUN8I_AIF_CLK_CTRL(dai->id),
  338. BIT(SUN8I_AIF_CLK_CTRL_MSTR_MOD),
  339. value << SUN8I_AIF_CLK_CTRL_MSTR_MOD);
  340. }
  341. /* DAI format */
  342. switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  343. case SND_SOC_DAIFMT_I2S:
  344. format = 0x0;
  345. break;
  346. case SND_SOC_DAIFMT_LEFT_J:
  347. format = 0x1;
  348. break;
  349. case SND_SOC_DAIFMT_RIGHT_J:
  350. format = 0x2;
  351. break;
  352. case SND_SOC_DAIFMT_DSP_A:
  353. format = 0x3;
  354. dsp_format = 0x0; /* Set LRCK_INV to 0 */
  355. break;
  356. case SND_SOC_DAIFMT_DSP_B:
  357. format = 0x3;
  358. dsp_format = 0x1; /* Set LRCK_INV to 1 */
  359. break;
  360. default:
  361. return -EINVAL;
  362. }
  363. if (dai->id == SUN8I_CODEC_AIF3) {
  364. /* AIF3 only supports DSP mode. */
  365. if (format != 3)
  366. return -EINVAL;
  367. } else {
  368. regmap_update_bits(scodec->regmap, SUN8I_AIF_CLK_CTRL(dai->id),
  369. SUN8I_AIF_CLK_CTRL_DATA_FMT_MASK,
  370. format << SUN8I_AIF_CLK_CTRL_DATA_FMT);
  371. }
  372. /* clock inversion */
  373. switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
  374. case SND_SOC_DAIFMT_NB_NF: /* Normal */
  375. invert = 0x0;
  376. break;
  377. case SND_SOC_DAIFMT_NB_IF: /* Inverted LRCK */
  378. invert = 0x1;
  379. break;
  380. case SND_SOC_DAIFMT_IB_NF: /* Inverted BCLK */
  381. invert = 0x2;
  382. break;
  383. case SND_SOC_DAIFMT_IB_IF: /* Both inverted */
  384. invert = 0x3;
  385. break;
  386. default:
  387. return -EINVAL;
  388. }
  389. if (format == 0x3) {
  390. /* Inverted LRCK is not available in DSP mode. */
  391. if (invert & BIT(0))
  392. return -EINVAL;
  393. /* Instead, the bit selects between DSP A/B formats. */
  394. invert |= dsp_format;
  395. } else {
  396. /*
  397. * It appears that the DAI and the codec in the A33 SoC don't
  398. * share the same polarity for the LRCK signal when they mean
  399. * 'normal' and 'inverted' in the datasheet.
  400. *
  401. * Since the DAI here is our regular i2s driver that have been
  402. * tested with way more codecs than just this one, it means
  403. * that the codec probably gets it backward, and we have to
  404. * invert the value here.
  405. */
  406. invert ^= scodec->quirks->lrck_inversion;
  407. }
  408. regmap_update_bits(scodec->regmap, SUN8I_AIF_CLK_CTRL(dai->id),
  409. SUN8I_AIF_CLK_CTRL_CLK_INV_MASK,
  410. invert << SUN8I_AIF_CLK_CTRL_CLK_INV);
  411. return 0;
  412. }
  413. static int sun8i_codec_set_tdm_slot(struct snd_soc_dai *dai,
  414. unsigned int tx_mask, unsigned int rx_mask,
  415. int slots, int slot_width)
  416. {
  417. struct sun8i_codec *scodec = snd_soc_dai_get_drvdata(dai);
  418. struct sun8i_codec_aif *aif = &scodec->aifs[dai->id];
  419. if (slot_width && !is_power_of_2(slot_width))
  420. return -EINVAL;
  421. aif->slots = slots;
  422. aif->slot_width = slot_width;
  423. return 0;
  424. }
  425. static const unsigned int sun8i_codec_rates[] = {
  426. 7350, 8000, 11025, 12000, 14700, 16000, 22050, 24000,
  427. 29400, 32000, 44100, 48000, 88200, 96000, 176400, 192000,
  428. };
  429. static const struct snd_pcm_hw_constraint_list sun8i_codec_all_rates = {
  430. .list = sun8i_codec_rates,
  431. .count = ARRAY_SIZE(sun8i_codec_rates),
  432. };
  433. static const struct snd_pcm_hw_constraint_list sun8i_codec_22M_rates = {
  434. .list = sun8i_codec_rates,
  435. .count = ARRAY_SIZE(sun8i_codec_rates),
  436. .mask = 0x5555,
  437. };
  438. static const struct snd_pcm_hw_constraint_list sun8i_codec_24M_rates = {
  439. .list = sun8i_codec_rates,
  440. .count = ARRAY_SIZE(sun8i_codec_rates),
  441. .mask = 0xaaaa,
  442. };
  443. static int sun8i_codec_startup(struct snd_pcm_substream *substream,
  444. struct snd_soc_dai *dai)
  445. {
  446. struct sun8i_codec *scodec = snd_soc_dai_get_drvdata(dai);
  447. const struct snd_pcm_hw_constraint_list *list;
  448. /* hw_constraints is not relevant for codec2codec DAIs. */
  449. if (dai->id != SUN8I_CODEC_AIF1)
  450. return 0;
  451. if (!scodec->sysclk_refcnt)
  452. list = &sun8i_codec_all_rates;
  453. else if (scodec->sysclk_rate == 22579200)
  454. list = &sun8i_codec_22M_rates;
  455. else if (scodec->sysclk_rate == 24576000)
  456. list = &sun8i_codec_24M_rates;
  457. else
  458. return -EINVAL;
  459. return snd_pcm_hw_constraint_list(substream->runtime, 0,
  460. SNDRV_PCM_HW_PARAM_RATE, list);
  461. }
  462. struct sun8i_codec_clk_div {
  463. u8 div;
  464. u8 val;
  465. };
  466. static const struct sun8i_codec_clk_div sun8i_codec_bclk_div[] = {
  467. { .div = 1, .val = 0 },
  468. { .div = 2, .val = 1 },
  469. { .div = 4, .val = 2 },
  470. { .div = 6, .val = 3 },
  471. { .div = 8, .val = 4 },
  472. { .div = 12, .val = 5 },
  473. { .div = 16, .val = 6 },
  474. { .div = 24, .val = 7 },
  475. { .div = 32, .val = 8 },
  476. { .div = 48, .val = 9 },
  477. { .div = 64, .val = 10 },
  478. { .div = 96, .val = 11 },
  479. { .div = 128, .val = 12 },
  480. { .div = 192, .val = 13 },
  481. };
  482. static int sun8i_codec_get_bclk_div(unsigned int sysclk_rate,
  483. unsigned int lrck_div_order,
  484. unsigned int sample_rate)
  485. {
  486. unsigned int div = sysclk_rate / sample_rate >> lrck_div_order;
  487. int i;
  488. for (i = 0; i < ARRAY_SIZE(sun8i_codec_bclk_div); i++) {
  489. const struct sun8i_codec_clk_div *bdiv = &sun8i_codec_bclk_div[i];
  490. if (bdiv->div == div)
  491. return bdiv->val;
  492. }
  493. return -EINVAL;
  494. }
  495. static int sun8i_codec_get_lrck_div_order(unsigned int slots,
  496. unsigned int slot_width)
  497. {
  498. unsigned int div = slots * slot_width;
  499. if (div < 16 || div > 256)
  500. return -EINVAL;
  501. return order_base_2(div);
  502. }
  503. static unsigned int sun8i_codec_get_sysclk_rate(unsigned int sample_rate)
  504. {
  505. return (sample_rate % 4000) ? 22579200 : 24576000;
  506. }
  507. static int sun8i_codec_hw_params(struct snd_pcm_substream *substream,
  508. struct snd_pcm_hw_params *params,
  509. struct snd_soc_dai *dai)
  510. {
  511. struct sun8i_codec *scodec = snd_soc_dai_get_drvdata(dai);
  512. struct sun8i_codec_aif *aif = &scodec->aifs[dai->id];
  513. unsigned int sample_rate = params_rate(params);
  514. unsigned int slots = aif->slots ?: params_channels(params);
  515. unsigned int slot_width = aif->slot_width ?: params_width(params);
  516. unsigned int sysclk_rate = sun8i_codec_get_sysclk_rate(sample_rate);
  517. int bclk_div, lrck_div_order, ret, word_size;
  518. u32 clk_reg;
  519. /* word size */
  520. switch (params_width(params)) {
  521. case 8:
  522. word_size = 0x0;
  523. break;
  524. case 16:
  525. word_size = 0x1;
  526. break;
  527. case 20:
  528. word_size = 0x2;
  529. break;
  530. case 24:
  531. word_size = 0x3;
  532. break;
  533. default:
  534. return -EINVAL;
  535. }
  536. regmap_update_bits(scodec->regmap, SUN8I_AIF_CLK_CTRL(dai->id),
  537. SUN8I_AIF_CLK_CTRL_WORD_SIZ_MASK,
  538. word_size << SUN8I_AIF_CLK_CTRL_WORD_SIZ);
  539. /* LRCK divider (BCLK/LRCK ratio) */
  540. lrck_div_order = sun8i_codec_get_lrck_div_order(slots, slot_width);
  541. if (lrck_div_order < 0)
  542. return lrck_div_order;
  543. if (dai->id == SUN8I_CODEC_AIF2 || dai->id == SUN8I_CODEC_AIF3) {
  544. /* AIF2 and AIF3 share AIF2's BCLK and LRCK generation circuitry. */
  545. int partner = (SUN8I_CODEC_AIF2 + SUN8I_CODEC_AIF3) - dai->id;
  546. const struct sun8i_codec_aif *partner_aif = &scodec->aifs[partner];
  547. const char *partner_name = sun8i_codec_dais[partner].name;
  548. if (partner_aif->open_streams &&
  549. (lrck_div_order != partner_aif->lrck_div_order ||
  550. sample_rate != partner_aif->sample_rate)) {
  551. dev_err(dai->dev,
  552. "%s sample and bit rates must match %s when both are used\n",
  553. dai->name, partner_name);
  554. return -EBUSY;
  555. }
  556. clk_reg = SUN8I_AIF_CLK_CTRL(SUN8I_CODEC_AIF2);
  557. } else {
  558. clk_reg = SUN8I_AIF_CLK_CTRL(dai->id);
  559. }
  560. regmap_update_bits(scodec->regmap, clk_reg,
  561. SUN8I_AIF_CLK_CTRL_LRCK_DIV_MASK,
  562. (lrck_div_order - 4) << SUN8I_AIF_CLK_CTRL_LRCK_DIV);
  563. /* BCLK divider (SYSCLK/BCLK ratio) */
  564. bclk_div = sun8i_codec_get_bclk_div(sysclk_rate, lrck_div_order, sample_rate);
  565. if (bclk_div < 0)
  566. return bclk_div;
  567. regmap_update_bits(scodec->regmap, clk_reg,
  568. SUN8I_AIF_CLK_CTRL_BCLK_DIV_MASK,
  569. bclk_div << SUN8I_AIF_CLK_CTRL_BCLK_DIV);
  570. /*
  571. * SYSCLK rate
  572. *
  573. * Clock rate protection is reference counted; but hw_params may be
  574. * called many times per substream, without matching calls to hw_free.
  575. * Protect the clock rate once per AIF, on the first hw_params call
  576. * for the first substream. clk_set_rate() will allow clock rate
  577. * changes on subsequent calls if only one AIF has open streams.
  578. */
  579. ret = (aif->open_streams ? clk_set_rate : clk_set_rate_exclusive)(scodec->clk_module,
  580. sysclk_rate);
  581. if (ret == -EBUSY)
  582. dev_err(dai->dev,
  583. "%s sample rate (%u Hz) conflicts with other audio streams\n",
  584. dai->name, sample_rate);
  585. if (ret < 0)
  586. return ret;
  587. if (!aif->open_streams)
  588. scodec->sysclk_refcnt++;
  589. scodec->sysclk_rate = sysclk_rate;
  590. aif->lrck_div_order = lrck_div_order;
  591. aif->sample_rate = sample_rate;
  592. aif->open_streams |= BIT(substream->stream);
  593. return sun8i_codec_update_sample_rate(scodec);
  594. }
  595. static int sun8i_codec_hw_free(struct snd_pcm_substream *substream,
  596. struct snd_soc_dai *dai)
  597. {
  598. struct sun8i_codec *scodec = snd_soc_dai_get_drvdata(dai);
  599. struct sun8i_codec_aif *aif = &scodec->aifs[dai->id];
  600. /* Drop references when the last substream for the AIF is freed. */
  601. if (aif->open_streams != BIT(substream->stream))
  602. goto done;
  603. clk_rate_exclusive_put(scodec->clk_module);
  604. scodec->sysclk_refcnt--;
  605. aif->lrck_div_order = 0;
  606. aif->sample_rate = 0;
  607. done:
  608. aif->open_streams &= ~BIT(substream->stream);
  609. return 0;
  610. }
  611. static const struct snd_soc_dai_ops sun8i_codec_dai_ops = {
  612. .set_fmt = sun8i_codec_set_fmt,
  613. .set_tdm_slot = sun8i_codec_set_tdm_slot,
  614. .startup = sun8i_codec_startup,
  615. .hw_params = sun8i_codec_hw_params,
  616. .hw_free = sun8i_codec_hw_free,
  617. };
  618. static struct snd_soc_dai_driver sun8i_codec_dais[] = {
  619. {
  620. .name = "sun8i-codec-aif1",
  621. .id = SUN8I_CODEC_AIF1,
  622. .ops = &sun8i_codec_dai_ops,
  623. /* capture capabilities */
  624. .capture = {
  625. .stream_name = "AIF1 Capture",
  626. .channels_min = 1,
  627. .channels_max = 2,
  628. .rates = SUN8I_CODEC_PCM_RATES,
  629. .formats = SUN8I_CODEC_PCM_FORMATS,
  630. .sig_bits = 24,
  631. },
  632. /* playback capabilities */
  633. .playback = {
  634. .stream_name = "AIF1 Playback",
  635. .channels_min = 1,
  636. .channels_max = 2,
  637. .rates = SUN8I_CODEC_PCM_RATES,
  638. .formats = SUN8I_CODEC_PCM_FORMATS,
  639. },
  640. .symmetric_rate = true,
  641. .symmetric_channels = true,
  642. .symmetric_sample_bits = true,
  643. },
  644. {
  645. .name = "sun8i-codec-aif2",
  646. .id = SUN8I_CODEC_AIF2,
  647. .ops = &sun8i_codec_dai_ops,
  648. /* capture capabilities */
  649. .capture = {
  650. .stream_name = "AIF2 Capture",
  651. .channels_min = 1,
  652. .channels_max = 2,
  653. .rates = SUN8I_CODEC_PCM_RATES,
  654. .formats = SUN8I_CODEC_PCM_FORMATS,
  655. .sig_bits = 24,
  656. },
  657. /* playback capabilities */
  658. .playback = {
  659. .stream_name = "AIF2 Playback",
  660. .channels_min = 1,
  661. .channels_max = 2,
  662. .rates = SUN8I_CODEC_PCM_RATES,
  663. .formats = SUN8I_CODEC_PCM_FORMATS,
  664. },
  665. .symmetric_rate = true,
  666. .symmetric_channels = true,
  667. .symmetric_sample_bits = true,
  668. },
  669. {
  670. .name = "sun8i-codec-aif3",
  671. .id = SUN8I_CODEC_AIF3,
  672. .ops = &sun8i_codec_dai_ops,
  673. /* capture capabilities */
  674. .capture = {
  675. .stream_name = "AIF3 Capture",
  676. .channels_min = 1,
  677. .channels_max = 1,
  678. .rates = SUN8I_CODEC_PCM_RATES,
  679. .formats = SUN8I_CODEC_PCM_FORMATS,
  680. .sig_bits = 24,
  681. },
  682. /* playback capabilities */
  683. .playback = {
  684. .stream_name = "AIF3 Playback",
  685. .channels_min = 1,
  686. .channels_max = 1,
  687. .rates = SUN8I_CODEC_PCM_RATES,
  688. .formats = SUN8I_CODEC_PCM_FORMATS,
  689. },
  690. .symmetric_rate = true,
  691. .symmetric_channels = true,
  692. .symmetric_sample_bits = true,
  693. },
  694. };
  695. static const DECLARE_TLV_DB_SCALE(sun8i_codec_vol_scale, -12000, 75, 1);
  696. static const struct snd_kcontrol_new sun8i_codec_controls[] = {
  697. SOC_DOUBLE_TLV("AIF1 AD0 Capture Volume",
  698. SUN8I_AIF1_VOL_CTRL1,
  699. SUN8I_AIF1_VOL_CTRL1_AD0L_VOL,
  700. SUN8I_AIF1_VOL_CTRL1_AD0R_VOL,
  701. 0xc0, 0, sun8i_codec_vol_scale),
  702. SOC_DOUBLE_TLV("AIF1 DA0 Playback Volume",
  703. SUN8I_AIF1_VOL_CTRL3,
  704. SUN8I_AIF1_VOL_CTRL3_DA0L_VOL,
  705. SUN8I_AIF1_VOL_CTRL3_DA0R_VOL,
  706. 0xc0, 0, sun8i_codec_vol_scale),
  707. SOC_DOUBLE_TLV("AIF2 ADC Capture Volume",
  708. SUN8I_AIF2_VOL_CTRL1,
  709. SUN8I_AIF2_VOL_CTRL1_ADCL_VOL,
  710. SUN8I_AIF2_VOL_CTRL1_ADCR_VOL,
  711. 0xc0, 0, sun8i_codec_vol_scale),
  712. SOC_DOUBLE_TLV("AIF2 DAC Playback Volume",
  713. SUN8I_AIF2_VOL_CTRL2,
  714. SUN8I_AIF2_VOL_CTRL2_DACL_VOL,
  715. SUN8I_AIF2_VOL_CTRL2_DACR_VOL,
  716. 0xc0, 0, sun8i_codec_vol_scale),
  717. SOC_DOUBLE_TLV("ADC Capture Volume",
  718. SUN8I_ADC_VOL_CTRL,
  719. SUN8I_ADC_VOL_CTRL_ADCL_VOL,
  720. SUN8I_ADC_VOL_CTRL_ADCR_VOL,
  721. 0xc0, 0, sun8i_codec_vol_scale),
  722. SOC_DOUBLE_TLV("DAC Playback Volume",
  723. SUN8I_DAC_VOL_CTRL,
  724. SUN8I_DAC_VOL_CTRL_DACL_VOL,
  725. SUN8I_DAC_VOL_CTRL_DACR_VOL,
  726. 0xc0, 0, sun8i_codec_vol_scale),
  727. };
  728. static int sun8i_codec_aif_event(struct snd_soc_dapm_widget *w,
  729. struct snd_kcontrol *kcontrol, int event)
  730. {
  731. struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
  732. struct sun8i_codec *scodec = snd_soc_component_get_drvdata(component);
  733. struct sun8i_codec_aif *aif = &scodec->aifs[w->sname[3] - '1'];
  734. int stream = w->id == snd_soc_dapm_aif_out;
  735. if (SND_SOC_DAPM_EVENT_ON(event))
  736. aif->active_streams |= BIT(stream);
  737. else
  738. aif->active_streams &= ~BIT(stream);
  739. return sun8i_codec_update_sample_rate(scodec);
  740. }
  741. static const char *const sun8i_aif_stereo_mux_enum_values[] = {
  742. "Stereo", "Reverse Stereo", "Sum Mono", "Mix Mono"
  743. };
  744. static SOC_ENUM_DOUBLE_DECL(sun8i_aif1_ad0_stereo_mux_enum,
  745. SUN8I_AIF1_ADCDAT_CTRL,
  746. SUN8I_AIF1_ADCDAT_CTRL_AIF1_AD0L_SRC,
  747. SUN8I_AIF1_ADCDAT_CTRL_AIF1_AD0R_SRC,
  748. sun8i_aif_stereo_mux_enum_values);
  749. static const struct snd_kcontrol_new sun8i_aif1_ad0_stereo_mux_control =
  750. SOC_DAPM_ENUM("AIF1 AD0 Stereo Capture Route",
  751. sun8i_aif1_ad0_stereo_mux_enum);
  752. static SOC_ENUM_DOUBLE_DECL(sun8i_aif2_adc_stereo_mux_enum,
  753. SUN8I_AIF2_ADCDAT_CTRL,
  754. SUN8I_AIF2_ADCDAT_CTRL_AIF2_ADCL_SRC,
  755. SUN8I_AIF2_ADCDAT_CTRL_AIF2_ADCR_SRC,
  756. sun8i_aif_stereo_mux_enum_values);
  757. static const struct snd_kcontrol_new sun8i_aif2_adc_stereo_mux_control =
  758. SOC_DAPM_ENUM("AIF2 ADC Stereo Capture Route",
  759. sun8i_aif2_adc_stereo_mux_enum);
  760. static const char *const sun8i_aif3_adc_mux_enum_values[] = {
  761. "None", "AIF2 ADCL", "AIF2 ADCR"
  762. };
  763. static SOC_ENUM_SINGLE_DECL(sun8i_aif3_adc_mux_enum,
  764. SUN8I_AIF3_PATH_CTRL,
  765. SUN8I_AIF3_PATH_CTRL_AIF3_ADC_SRC,
  766. sun8i_aif3_adc_mux_enum_values);
  767. static const struct snd_kcontrol_new sun8i_aif3_adc_mux_control =
  768. SOC_DAPM_ENUM("AIF3 ADC Source Capture Route",
  769. sun8i_aif3_adc_mux_enum);
  770. static const struct snd_kcontrol_new sun8i_aif1_ad0_mixer_controls[] = {
  771. SOC_DAPM_DOUBLE("AIF1 Slot 0 Digital ADC Capture Switch",
  772. SUN8I_AIF1_MXR_SRC,
  773. SUN8I_AIF1_MXR_SRC_AD0L_MXR_SRC_AIF1DA0L,
  774. SUN8I_AIF1_MXR_SRC_AD0R_MXR_SRC_AIF1DA0R, 1, 0),
  775. SOC_DAPM_DOUBLE("AIF2 Digital ADC Capture Switch",
  776. SUN8I_AIF1_MXR_SRC,
  777. SUN8I_AIF1_MXR_SRC_AD0L_MXR_SRC_AIF2DACL,
  778. SUN8I_AIF1_MXR_SRC_AD0R_MXR_SRC_AIF2DACR, 1, 0),
  779. SOC_DAPM_DOUBLE("AIF1 Data Digital ADC Capture Switch",
  780. SUN8I_AIF1_MXR_SRC,
  781. SUN8I_AIF1_MXR_SRC_AD0L_MXR_SRC_ADCL,
  782. SUN8I_AIF1_MXR_SRC_AD0R_MXR_SRC_ADCR, 1, 0),
  783. SOC_DAPM_DOUBLE("AIF2 Inv Digital ADC Capture Switch",
  784. SUN8I_AIF1_MXR_SRC,
  785. SUN8I_AIF1_MXR_SRC_AD0L_MXR_SRC_AIF2DACR,
  786. SUN8I_AIF1_MXR_SRC_AD0R_MXR_SRC_AIF2DACL, 1, 0),
  787. };
  788. static const struct snd_kcontrol_new sun8i_aif2_adc_mixer_controls[] = {
  789. SOC_DAPM_DOUBLE("AIF2 ADC Mixer AIF1 DA0 Capture Switch",
  790. SUN8I_AIF2_MXR_SRC,
  791. SUN8I_AIF2_MXR_SRC_ADCL_MXR_SRC_AIF1DA0L,
  792. SUN8I_AIF2_MXR_SRC_ADCR_MXR_SRC_AIF1DA0R, 1, 0),
  793. SOC_DAPM_DOUBLE("AIF2 ADC Mixer AIF1 DA1 Capture Switch",
  794. SUN8I_AIF2_MXR_SRC,
  795. SUN8I_AIF2_MXR_SRC_ADCL_MXR_SRC_AIF1DA1L,
  796. SUN8I_AIF2_MXR_SRC_ADCR_MXR_SRC_AIF1DA1R, 1, 0),
  797. SOC_DAPM_DOUBLE("AIF2 ADC Mixer AIF2 DAC Rev Capture Switch",
  798. SUN8I_AIF2_MXR_SRC,
  799. SUN8I_AIF2_MXR_SRC_ADCL_MXR_SRC_AIF2DACR,
  800. SUN8I_AIF2_MXR_SRC_ADCR_MXR_SRC_AIF2DACL, 1, 0),
  801. SOC_DAPM_DOUBLE("AIF2 ADC Mixer ADC Capture Switch",
  802. SUN8I_AIF2_MXR_SRC,
  803. SUN8I_AIF2_MXR_SRC_ADCL_MXR_SRC_ADCL,
  804. SUN8I_AIF2_MXR_SRC_ADCR_MXR_SRC_ADCR, 1, 0),
  805. };
  806. static const char *const sun8i_aif2_dac_mux_enum_values[] = {
  807. "AIF2", "AIF3+2", "AIF2+3"
  808. };
  809. static SOC_ENUM_SINGLE_DECL(sun8i_aif2_dac_mux_enum,
  810. SUN8I_AIF3_PATH_CTRL,
  811. SUN8I_AIF3_PATH_CTRL_AIF2_DAC_SRC,
  812. sun8i_aif2_dac_mux_enum_values);
  813. static const struct snd_kcontrol_new sun8i_aif2_dac_mux_control =
  814. SOC_DAPM_ENUM("AIF2 DAC Source Playback Route",
  815. sun8i_aif2_dac_mux_enum);
  816. static SOC_ENUM_DOUBLE_DECL(sun8i_aif1_da0_stereo_mux_enum,
  817. SUN8I_AIF1_DACDAT_CTRL,
  818. SUN8I_AIF1_DACDAT_CTRL_AIF1_DA0L_SRC,
  819. SUN8I_AIF1_DACDAT_CTRL_AIF1_DA0R_SRC,
  820. sun8i_aif_stereo_mux_enum_values);
  821. static const struct snd_kcontrol_new sun8i_aif1_da0_stereo_mux_control =
  822. SOC_DAPM_ENUM("AIF1 DA0 Stereo Playback Route",
  823. sun8i_aif1_da0_stereo_mux_enum);
  824. static SOC_ENUM_DOUBLE_DECL(sun8i_aif2_dac_stereo_mux_enum,
  825. SUN8I_AIF2_DACDAT_CTRL,
  826. SUN8I_AIF2_DACDAT_CTRL_AIF2_DACL_SRC,
  827. SUN8I_AIF2_DACDAT_CTRL_AIF2_DACR_SRC,
  828. sun8i_aif_stereo_mux_enum_values);
  829. static const struct snd_kcontrol_new sun8i_aif2_dac_stereo_mux_control =
  830. SOC_DAPM_ENUM("AIF2 DAC Stereo Playback Route",
  831. sun8i_aif2_dac_stereo_mux_enum);
  832. static const struct snd_kcontrol_new sun8i_dac_mixer_controls[] = {
  833. SOC_DAPM_DOUBLE("AIF1 Slot 0 Digital DAC Playback Switch",
  834. SUN8I_DAC_MXR_SRC,
  835. SUN8I_DAC_MXR_SRC_DACL_MXR_SRC_AIF1DA0L,
  836. SUN8I_DAC_MXR_SRC_DACR_MXR_SRC_AIF1DA0R, 1, 0),
  837. SOC_DAPM_DOUBLE("AIF1 Slot 1 Digital DAC Playback Switch",
  838. SUN8I_DAC_MXR_SRC,
  839. SUN8I_DAC_MXR_SRC_DACL_MXR_SRC_AIF1DA1L,
  840. SUN8I_DAC_MXR_SRC_DACR_MXR_SRC_AIF1DA1R, 1, 0),
  841. SOC_DAPM_DOUBLE("AIF2 Digital DAC Playback Switch", SUN8I_DAC_MXR_SRC,
  842. SUN8I_DAC_MXR_SRC_DACL_MXR_SRC_AIF2DACL,
  843. SUN8I_DAC_MXR_SRC_DACR_MXR_SRC_AIF2DACR, 1, 0),
  844. SOC_DAPM_DOUBLE("ADC Digital DAC Playback Switch", SUN8I_DAC_MXR_SRC,
  845. SUN8I_DAC_MXR_SRC_DACL_MXR_SRC_ADCL,
  846. SUN8I_DAC_MXR_SRC_DACR_MXR_SRC_ADCR, 1, 0),
  847. };
  848. static const struct snd_soc_dapm_widget sun8i_codec_dapm_widgets[] = {
  849. /* System Clocks */
  850. SND_SOC_DAPM_CLOCK_SUPPLY("mod"),
  851. SND_SOC_DAPM_SUPPLY("AIF1CLK",
  852. SUN8I_SYSCLK_CTL,
  853. SUN8I_SYSCLK_CTL_AIF1CLK_ENA, 0, NULL, 0),
  854. SND_SOC_DAPM_SUPPLY("AIF2CLK",
  855. SUN8I_SYSCLK_CTL,
  856. SUN8I_SYSCLK_CTL_AIF2CLK_ENA, 0, NULL, 0),
  857. SND_SOC_DAPM_SUPPLY("SYSCLK",
  858. SUN8I_SYSCLK_CTL,
  859. SUN8I_SYSCLK_CTL_SYSCLK_ENA, 0, NULL, 0),
  860. /* Module Clocks */
  861. SND_SOC_DAPM_SUPPLY("CLK AIF1",
  862. SUN8I_MOD_CLK_ENA,
  863. SUN8I_MOD_CLK_ENA_AIF1, 0, NULL, 0),
  864. SND_SOC_DAPM_SUPPLY("CLK AIF2",
  865. SUN8I_MOD_CLK_ENA,
  866. SUN8I_MOD_CLK_ENA_AIF2, 0, NULL, 0),
  867. SND_SOC_DAPM_SUPPLY("CLK AIF3",
  868. SUN8I_MOD_CLK_ENA,
  869. SUN8I_MOD_CLK_ENA_AIF3, 0, NULL, 0),
  870. SND_SOC_DAPM_SUPPLY("CLK ADC",
  871. SUN8I_MOD_CLK_ENA,
  872. SUN8I_MOD_CLK_ENA_ADC, 0, NULL, 0),
  873. SND_SOC_DAPM_SUPPLY("CLK DAC",
  874. SUN8I_MOD_CLK_ENA,
  875. SUN8I_MOD_CLK_ENA_DAC, 0, NULL, 0),
  876. /* Module Resets */
  877. SND_SOC_DAPM_SUPPLY("RST AIF1",
  878. SUN8I_MOD_RST_CTL,
  879. SUN8I_MOD_RST_CTL_AIF1, 0, NULL, 0),
  880. SND_SOC_DAPM_SUPPLY("RST AIF2",
  881. SUN8I_MOD_RST_CTL,
  882. SUN8I_MOD_RST_CTL_AIF2, 0, NULL, 0),
  883. SND_SOC_DAPM_SUPPLY("RST AIF3",
  884. SUN8I_MOD_RST_CTL,
  885. SUN8I_MOD_RST_CTL_AIF3, 0, NULL, 0),
  886. SND_SOC_DAPM_SUPPLY("RST ADC",
  887. SUN8I_MOD_RST_CTL,
  888. SUN8I_MOD_RST_CTL_ADC, 0, NULL, 0),
  889. SND_SOC_DAPM_SUPPLY("RST DAC",
  890. SUN8I_MOD_RST_CTL,
  891. SUN8I_MOD_RST_CTL_DAC, 0, NULL, 0),
  892. /* Module Supplies */
  893. SND_SOC_DAPM_SUPPLY("ADC",
  894. SUN8I_ADC_DIG_CTRL,
  895. SUN8I_ADC_DIG_CTRL_ENAD, 0, NULL, 0),
  896. SND_SOC_DAPM_SUPPLY("DAC",
  897. SUN8I_DAC_DIG_CTRL,
  898. SUN8I_DAC_DIG_CTRL_ENDA, 0, NULL, 0),
  899. /* AIF "ADC" Outputs */
  900. SND_SOC_DAPM_AIF_OUT_E("AIF1 AD0L", "AIF1 Capture", 0,
  901. SUN8I_AIF1_ADCDAT_CTRL,
  902. SUN8I_AIF1_ADCDAT_CTRL_AIF1_AD0L_ENA, 0,
  903. sun8i_codec_aif_event,
  904. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  905. SND_SOC_DAPM_AIF_OUT("AIF1 AD0R", "AIF1 Capture", 1,
  906. SUN8I_AIF1_ADCDAT_CTRL,
  907. SUN8I_AIF1_ADCDAT_CTRL_AIF1_AD0R_ENA, 0),
  908. SND_SOC_DAPM_AIF_OUT_E("AIF2 ADCL", "AIF2 Capture", 0,
  909. SUN8I_AIF2_ADCDAT_CTRL,
  910. SUN8I_AIF2_ADCDAT_CTRL_AIF2_ADCL_ENA, 0,
  911. sun8i_codec_aif_event,
  912. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  913. SND_SOC_DAPM_AIF_OUT("AIF2 ADCR", "AIF2 Capture", 1,
  914. SUN8I_AIF2_ADCDAT_CTRL,
  915. SUN8I_AIF2_ADCDAT_CTRL_AIF2_ADCR_ENA, 0),
  916. SND_SOC_DAPM_AIF_OUT_E("AIF3 ADC", "AIF3 Capture", 0,
  917. SND_SOC_NOPM, 0, 0,
  918. sun8i_codec_aif_event,
  919. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  920. /* AIF "ADC" Mono/Stereo Muxes */
  921. SND_SOC_DAPM_MUX("AIF1 AD0L Stereo Mux", SND_SOC_NOPM, 0, 0,
  922. &sun8i_aif1_ad0_stereo_mux_control),
  923. SND_SOC_DAPM_MUX("AIF1 AD0R Stereo Mux", SND_SOC_NOPM, 0, 0,
  924. &sun8i_aif1_ad0_stereo_mux_control),
  925. SND_SOC_DAPM_MUX("AIF2 ADCL Stereo Mux", SND_SOC_NOPM, 0, 0,
  926. &sun8i_aif2_adc_stereo_mux_control),
  927. SND_SOC_DAPM_MUX("AIF2 ADCR Stereo Mux", SND_SOC_NOPM, 0, 0,
  928. &sun8i_aif2_adc_stereo_mux_control),
  929. /* AIF "ADC" Output Muxes */
  930. SND_SOC_DAPM_MUX("AIF3 ADC Source Capture Route", SND_SOC_NOPM, 0, 0,
  931. &sun8i_aif3_adc_mux_control),
  932. /* AIF "ADC" Mixers */
  933. SOC_MIXER_ARRAY("AIF1 AD0L Mixer", SND_SOC_NOPM, 0, 0,
  934. sun8i_aif1_ad0_mixer_controls),
  935. SOC_MIXER_ARRAY("AIF1 AD0R Mixer", SND_SOC_NOPM, 0, 0,
  936. sun8i_aif1_ad0_mixer_controls),
  937. SOC_MIXER_ARRAY("AIF2 ADCL Mixer", SND_SOC_NOPM, 0, 0,
  938. sun8i_aif2_adc_mixer_controls),
  939. SOC_MIXER_ARRAY("AIF2 ADCR Mixer", SND_SOC_NOPM, 0, 0,
  940. sun8i_aif2_adc_mixer_controls),
  941. /* AIF "DAC" Input Muxes */
  942. SND_SOC_DAPM_MUX("AIF2 DACL Source", SND_SOC_NOPM, 0, 0,
  943. &sun8i_aif2_dac_mux_control),
  944. SND_SOC_DAPM_MUX("AIF2 DACR Source", SND_SOC_NOPM, 0, 0,
  945. &sun8i_aif2_dac_mux_control),
  946. /* AIF "DAC" Mono/Stereo Muxes */
  947. SND_SOC_DAPM_MUX("AIF1 DA0L Stereo Mux", SND_SOC_NOPM, 0, 0,
  948. &sun8i_aif1_da0_stereo_mux_control),
  949. SND_SOC_DAPM_MUX("AIF1 DA0R Stereo Mux", SND_SOC_NOPM, 0, 0,
  950. &sun8i_aif1_da0_stereo_mux_control),
  951. SND_SOC_DAPM_MUX("AIF2 DACL Stereo Mux", SND_SOC_NOPM, 0, 0,
  952. &sun8i_aif2_dac_stereo_mux_control),
  953. SND_SOC_DAPM_MUX("AIF2 DACR Stereo Mux", SND_SOC_NOPM, 0, 0,
  954. &sun8i_aif2_dac_stereo_mux_control),
  955. /* AIF "DAC" Inputs */
  956. SND_SOC_DAPM_AIF_IN_E("AIF1 DA0L", "AIF1 Playback", 0,
  957. SUN8I_AIF1_DACDAT_CTRL,
  958. SUN8I_AIF1_DACDAT_CTRL_AIF1_DA0L_ENA, 0,
  959. sun8i_codec_aif_event,
  960. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  961. SND_SOC_DAPM_AIF_IN("AIF1 DA0R", "AIF1 Playback", 1,
  962. SUN8I_AIF1_DACDAT_CTRL,
  963. SUN8I_AIF1_DACDAT_CTRL_AIF1_DA0R_ENA, 0),
  964. SND_SOC_DAPM_AIF_IN_E("AIF2 DACL", "AIF2 Playback", 0,
  965. SUN8I_AIF2_DACDAT_CTRL,
  966. SUN8I_AIF2_DACDAT_CTRL_AIF2_DACL_ENA, 0,
  967. sun8i_codec_aif_event,
  968. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  969. SND_SOC_DAPM_AIF_IN("AIF2 DACR", "AIF2 Playback", 1,
  970. SUN8I_AIF2_DACDAT_CTRL,
  971. SUN8I_AIF2_DACDAT_CTRL_AIF2_DACR_ENA, 0),
  972. SND_SOC_DAPM_AIF_IN_E("AIF3 DAC", "AIF3 Playback", 0,
  973. SND_SOC_NOPM, 0, 0,
  974. sun8i_codec_aif_event,
  975. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  976. /* ADC Inputs (connected to analog codec DAPM context) */
  977. SND_SOC_DAPM_ADC("ADCL", NULL, SND_SOC_NOPM, 0, 0),
  978. SND_SOC_DAPM_ADC("ADCR", NULL, SND_SOC_NOPM, 0, 0),
  979. /* DAC Outputs (connected to analog codec DAPM context) */
  980. SND_SOC_DAPM_DAC("DACL", NULL, SND_SOC_NOPM, 0, 0),
  981. SND_SOC_DAPM_DAC("DACR", NULL, SND_SOC_NOPM, 0, 0),
  982. /* DAC Mixers */
  983. SOC_MIXER_ARRAY("DACL Mixer", SND_SOC_NOPM, 0, 0,
  984. sun8i_dac_mixer_controls),
  985. SOC_MIXER_ARRAY("DACR Mixer", SND_SOC_NOPM, 0, 0,
  986. sun8i_dac_mixer_controls),
  987. };
  988. static const struct snd_soc_dapm_route sun8i_codec_dapm_routes[] = {
  989. /* Clock Routes */
  990. { "AIF1CLK", NULL, "mod" },
  991. { "SYSCLK", NULL, "AIF1CLK" },
  992. { "CLK AIF1", NULL, "AIF1CLK" },
  993. { "CLK AIF1", NULL, "SYSCLK" },
  994. { "RST AIF1", NULL, "CLK AIF1" },
  995. { "AIF1 AD0L", NULL, "RST AIF1" },
  996. { "AIF1 AD0R", NULL, "RST AIF1" },
  997. { "AIF1 DA0L", NULL, "RST AIF1" },
  998. { "AIF1 DA0R", NULL, "RST AIF1" },
  999. { "CLK AIF2", NULL, "AIF2CLK" },
  1000. { "CLK AIF2", NULL, "SYSCLK" },
  1001. { "RST AIF2", NULL, "CLK AIF2" },
  1002. { "AIF2 ADCL", NULL, "RST AIF2" },
  1003. { "AIF2 ADCR", NULL, "RST AIF2" },
  1004. { "AIF2 DACL", NULL, "RST AIF2" },
  1005. { "AIF2 DACR", NULL, "RST AIF2" },
  1006. { "CLK AIF3", NULL, "AIF1CLK" },
  1007. { "CLK AIF3", NULL, "SYSCLK" },
  1008. { "RST AIF3", NULL, "CLK AIF3" },
  1009. { "AIF3 ADC", NULL, "RST AIF3" },
  1010. { "AIF3 DAC", NULL, "RST AIF3" },
  1011. { "CLK ADC", NULL, "SYSCLK" },
  1012. { "RST ADC", NULL, "CLK ADC" },
  1013. { "ADC", NULL, "RST ADC" },
  1014. { "ADCL", NULL, "ADC" },
  1015. { "ADCR", NULL, "ADC" },
  1016. { "CLK DAC", NULL, "SYSCLK" },
  1017. { "RST DAC", NULL, "CLK DAC" },
  1018. { "DAC", NULL, "RST DAC" },
  1019. { "DACL", NULL, "DAC" },
  1020. { "DACR", NULL, "DAC" },
  1021. /* AIF "ADC" Output Routes */
  1022. { "AIF1 AD0L", NULL, "AIF1 AD0L Stereo Mux" },
  1023. { "AIF1 AD0R", NULL, "AIF1 AD0R Stereo Mux" },
  1024. { "AIF2 ADCL", NULL, "AIF2 ADCL Stereo Mux" },
  1025. { "AIF2 ADCR", NULL, "AIF2 ADCR Stereo Mux" },
  1026. { "AIF3 ADC", NULL, "AIF3 ADC Source Capture Route" },
  1027. /* AIF "ADC" Mono/Stereo Mux Routes */
  1028. { "AIF1 AD0L Stereo Mux", "Stereo", "AIF1 AD0L Mixer" },
  1029. { "AIF1 AD0L Stereo Mux", "Reverse Stereo", "AIF1 AD0R Mixer" },
  1030. { "AIF1 AD0L Stereo Mux", "Sum Mono", "AIF1 AD0L Mixer" },
  1031. { "AIF1 AD0L Stereo Mux", "Sum Mono", "AIF1 AD0R Mixer" },
  1032. { "AIF1 AD0L Stereo Mux", "Mix Mono", "AIF1 AD0L Mixer" },
  1033. { "AIF1 AD0L Stereo Mux", "Mix Mono", "AIF1 AD0R Mixer" },
  1034. { "AIF1 AD0R Stereo Mux", "Stereo", "AIF1 AD0R Mixer" },
  1035. { "AIF1 AD0R Stereo Mux", "Reverse Stereo", "AIF1 AD0L Mixer" },
  1036. { "AIF1 AD0R Stereo Mux", "Sum Mono", "AIF1 AD0L Mixer" },
  1037. { "AIF1 AD0R Stereo Mux", "Sum Mono", "AIF1 AD0R Mixer" },
  1038. { "AIF1 AD0R Stereo Mux", "Mix Mono", "AIF1 AD0L Mixer" },
  1039. { "AIF1 AD0R Stereo Mux", "Mix Mono", "AIF1 AD0R Mixer" },
  1040. { "AIF2 ADCL Stereo Mux", "Stereo", "AIF2 ADCL Mixer" },
  1041. { "AIF2 ADCL Stereo Mux", "Reverse Stereo", "AIF2 ADCR Mixer" },
  1042. { "AIF2 ADCL Stereo Mux", "Sum Mono", "AIF2 ADCL Mixer" },
  1043. { "AIF2 ADCL Stereo Mux", "Sum Mono", "AIF2 ADCR Mixer" },
  1044. { "AIF2 ADCL Stereo Mux", "Mix Mono", "AIF2 ADCL Mixer" },
  1045. { "AIF2 ADCL Stereo Mux", "Mix Mono", "AIF2 ADCR Mixer" },
  1046. { "AIF2 ADCR Stereo Mux", "Stereo", "AIF2 ADCR Mixer" },
  1047. { "AIF2 ADCR Stereo Mux", "Reverse Stereo", "AIF2 ADCL Mixer" },
  1048. { "AIF2 ADCR Stereo Mux", "Sum Mono", "AIF2 ADCL Mixer" },
  1049. { "AIF2 ADCR Stereo Mux", "Sum Mono", "AIF2 ADCR Mixer" },
  1050. { "AIF2 ADCR Stereo Mux", "Mix Mono", "AIF2 ADCL Mixer" },
  1051. { "AIF2 ADCR Stereo Mux", "Mix Mono", "AIF2 ADCR Mixer" },
  1052. /* AIF "ADC" Output Mux Routes */
  1053. { "AIF3 ADC Source Capture Route", "AIF2 ADCL", "AIF2 ADCL Mixer" },
  1054. { "AIF3 ADC Source Capture Route", "AIF2 ADCR", "AIF2 ADCR Mixer" },
  1055. /* AIF "ADC" Mixer Routes */
  1056. { "AIF1 AD0L Mixer", "AIF1 Slot 0 Digital ADC Capture Switch", "AIF1 DA0L Stereo Mux" },
  1057. { "AIF1 AD0L Mixer", "AIF2 Digital ADC Capture Switch", "AIF2 DACL Source" },
  1058. { "AIF1 AD0L Mixer", "AIF1 Data Digital ADC Capture Switch", "ADCL" },
  1059. { "AIF1 AD0L Mixer", "AIF2 Inv Digital ADC Capture Switch", "AIF2 DACR Source" },
  1060. { "AIF1 AD0R Mixer", "AIF1 Slot 0 Digital ADC Capture Switch", "AIF1 DA0R Stereo Mux" },
  1061. { "AIF1 AD0R Mixer", "AIF2 Digital ADC Capture Switch", "AIF2 DACR Source" },
  1062. { "AIF1 AD0R Mixer", "AIF1 Data Digital ADC Capture Switch", "ADCR" },
  1063. { "AIF1 AD0R Mixer", "AIF2 Inv Digital ADC Capture Switch", "AIF2 DACL Source" },
  1064. { "AIF2 ADCL Mixer", "AIF2 ADC Mixer AIF1 DA0 Capture Switch", "AIF1 DA0L Stereo Mux" },
  1065. { "AIF2 ADCL Mixer", "AIF2 ADC Mixer AIF2 DAC Rev Capture Switch", "AIF2 DACR Source" },
  1066. { "AIF2 ADCL Mixer", "AIF2 ADC Mixer ADC Capture Switch", "ADCL" },
  1067. { "AIF2 ADCR Mixer", "AIF2 ADC Mixer AIF1 DA0 Capture Switch", "AIF1 DA0R Stereo Mux" },
  1068. { "AIF2 ADCR Mixer", "AIF2 ADC Mixer AIF2 DAC Rev Capture Switch", "AIF2 DACL Source" },
  1069. { "AIF2 ADCR Mixer", "AIF2 ADC Mixer ADC Capture Switch", "ADCR" },
  1070. /* AIF "DAC" Input Mux Routes */
  1071. { "AIF2 DACL Source", "AIF2", "AIF2 DACL Stereo Mux" },
  1072. { "AIF2 DACL Source", "AIF3+2", "AIF3 DAC" },
  1073. { "AIF2 DACL Source", "AIF2+3", "AIF2 DACL Stereo Mux" },
  1074. { "AIF2 DACR Source", "AIF2", "AIF2 DACR Stereo Mux" },
  1075. { "AIF2 DACR Source", "AIF3+2", "AIF2 DACR Stereo Mux" },
  1076. { "AIF2 DACR Source", "AIF2+3", "AIF3 DAC" },
  1077. /* AIF "DAC" Mono/Stereo Mux Routes */
  1078. { "AIF1 DA0L Stereo Mux", "Stereo", "AIF1 DA0L" },
  1079. { "AIF1 DA0L Stereo Mux", "Reverse Stereo", "AIF1 DA0R" },
  1080. { "AIF1 DA0L Stereo Mux", "Sum Mono", "AIF1 DA0L" },
  1081. { "AIF1 DA0L Stereo Mux", "Sum Mono", "AIF1 DA0R" },
  1082. { "AIF1 DA0L Stereo Mux", "Mix Mono", "AIF1 DA0L" },
  1083. { "AIF1 DA0L Stereo Mux", "Mix Mono", "AIF1 DA0R" },
  1084. { "AIF1 DA0R Stereo Mux", "Stereo", "AIF1 DA0R" },
  1085. { "AIF1 DA0R Stereo Mux", "Reverse Stereo", "AIF1 DA0L" },
  1086. { "AIF1 DA0R Stereo Mux", "Sum Mono", "AIF1 DA0L" },
  1087. { "AIF1 DA0R Stereo Mux", "Sum Mono", "AIF1 DA0R" },
  1088. { "AIF1 DA0R Stereo Mux", "Mix Mono", "AIF1 DA0L" },
  1089. { "AIF1 DA0R Stereo Mux", "Mix Mono", "AIF1 DA0R" },
  1090. { "AIF2 DACL Stereo Mux", "Stereo", "AIF2 DACL" },
  1091. { "AIF2 DACL Stereo Mux", "Reverse Stereo", "AIF2 DACR" },
  1092. { "AIF2 DACL Stereo Mux", "Sum Mono", "AIF2 DACL" },
  1093. { "AIF2 DACL Stereo Mux", "Sum Mono", "AIF2 DACR" },
  1094. { "AIF2 DACL Stereo Mux", "Mix Mono", "AIF2 DACL" },
  1095. { "AIF2 DACL Stereo Mux", "Mix Mono", "AIF2 DACR" },
  1096. { "AIF2 DACR Stereo Mux", "Stereo", "AIF2 DACR" },
  1097. { "AIF2 DACR Stereo Mux", "Reverse Stereo", "AIF2 DACL" },
  1098. { "AIF2 DACR Stereo Mux", "Sum Mono", "AIF2 DACL" },
  1099. { "AIF2 DACR Stereo Mux", "Sum Mono", "AIF2 DACR" },
  1100. { "AIF2 DACR Stereo Mux", "Mix Mono", "AIF2 DACL" },
  1101. { "AIF2 DACR Stereo Mux", "Mix Mono", "AIF2 DACR" },
  1102. /* DAC Output Routes */
  1103. { "DACL", NULL, "DACL Mixer" },
  1104. { "DACR", NULL, "DACR Mixer" },
  1105. /* DAC Mixer Routes */
  1106. { "DACL Mixer", "AIF1 Slot 0 Digital DAC Playback Switch", "AIF1 DA0L Stereo Mux" },
  1107. { "DACL Mixer", "AIF2 Digital DAC Playback Switch", "AIF2 DACL Source" },
  1108. { "DACL Mixer", "ADC Digital DAC Playback Switch", "ADCL" },
  1109. { "DACR Mixer", "AIF1 Slot 0 Digital DAC Playback Switch", "AIF1 DA0R Stereo Mux" },
  1110. { "DACR Mixer", "AIF2 Digital DAC Playback Switch", "AIF2 DACR Source" },
  1111. { "DACR Mixer", "ADC Digital DAC Playback Switch", "ADCR" },
  1112. };
  1113. static const struct snd_soc_dapm_widget sun8i_codec_legacy_widgets[] = {
  1114. /* Legacy ADC Inputs (connected to analog codec DAPM context) */
  1115. SND_SOC_DAPM_ADC("AIF1 Slot 0 Left ADC", NULL, SND_SOC_NOPM, 0, 0),
  1116. SND_SOC_DAPM_ADC("AIF1 Slot 0 Right ADC", NULL, SND_SOC_NOPM, 0, 0),
  1117. /* Legacy DAC Outputs (connected to analog codec DAPM context) */
  1118. SND_SOC_DAPM_DAC("AIF1 Slot 0 Left", NULL, SND_SOC_NOPM, 0, 0),
  1119. SND_SOC_DAPM_DAC("AIF1 Slot 0 Right", NULL, SND_SOC_NOPM, 0, 0),
  1120. };
  1121. static const struct snd_soc_dapm_route sun8i_codec_legacy_routes[] = {
  1122. /* Legacy ADC Routes */
  1123. { "ADCL", NULL, "AIF1 Slot 0 Left ADC" },
  1124. { "ADCR", NULL, "AIF1 Slot 0 Right ADC" },
  1125. /* Legacy DAC Routes */
  1126. { "AIF1 Slot 0 Left", NULL, "DACL" },
  1127. { "AIF1 Slot 0 Right", NULL, "DACR" },
  1128. };
  1129. static int sun8i_codec_component_probe(struct snd_soc_component *component)
  1130. {
  1131. struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component);
  1132. struct sun8i_codec *scodec = snd_soc_component_get_drvdata(component);
  1133. int ret;
  1134. scodec->component = component;
  1135. /* Add widgets for backward compatibility with old device trees. */
  1136. if (scodec->quirks->legacy_widgets) {
  1137. ret = snd_soc_dapm_new_controls(dapm, sun8i_codec_legacy_widgets,
  1138. ARRAY_SIZE(sun8i_codec_legacy_widgets));
  1139. if (ret)
  1140. return ret;
  1141. ret = snd_soc_dapm_add_routes(dapm, sun8i_codec_legacy_routes,
  1142. ARRAY_SIZE(sun8i_codec_legacy_routes));
  1143. if (ret)
  1144. return ret;
  1145. }
  1146. /*
  1147. * AIF1CLK and AIF2CLK share a pair of clock parents: PLL_AUDIO ("mod")
  1148. * and MCLK (from the CPU DAI connected to AIF1). MCLK's parent is also
  1149. * PLL_AUDIO, so using it adds no additional flexibility. Use PLL_AUDIO
  1150. * directly to simplify the clock tree.
  1151. */
  1152. regmap_update_bits(scodec->regmap, SUN8I_SYSCLK_CTL,
  1153. SUN8I_SYSCLK_CTL_AIF1CLK_SRC_MASK |
  1154. SUN8I_SYSCLK_CTL_AIF2CLK_SRC_MASK,
  1155. SUN8I_SYSCLK_CTL_AIF1CLK_SRC_PLL |
  1156. SUN8I_SYSCLK_CTL_AIF2CLK_SRC_PLL);
  1157. /* Use AIF1CLK as the SYSCLK parent since AIF1 is used most often. */
  1158. regmap_update_bits(scodec->regmap, SUN8I_SYSCLK_CTL,
  1159. BIT(SUN8I_SYSCLK_CTL_SYSCLK_SRC),
  1160. SUN8I_SYSCLK_CTL_SYSCLK_SRC_AIF1CLK);
  1161. /* Program the default sample rate. */
  1162. sun8i_codec_update_sample_rate(scodec);
  1163. return 0;
  1164. }
  1165. static void sun8i_codec_set_hmic_bias(struct sun8i_codec *scodec, bool enable)
  1166. {
  1167. struct snd_soc_dapm_context *dapm = &scodec->component->card->dapm;
  1168. int irq_mask = BIT(SUN8I_HMIC_CTRL1_HMIC_DATA_IRQ_EN);
  1169. if (enable)
  1170. snd_soc_dapm_force_enable_pin(dapm, "HBIAS");
  1171. else
  1172. snd_soc_dapm_disable_pin(dapm, "HBIAS");
  1173. snd_soc_dapm_sync(dapm);
  1174. regmap_update_bits(scodec->regmap, SUN8I_HMIC_CTRL1,
  1175. irq_mask, enable ? irq_mask : 0);
  1176. }
  1177. static void sun8i_codec_jack_work(struct work_struct *work)
  1178. {
  1179. struct sun8i_codec *scodec = container_of(work, struct sun8i_codec,
  1180. jack_work.work);
  1181. unsigned int mdata;
  1182. int type;
  1183. guard(mutex)(&scodec->jack_mutex);
  1184. if (scodec->jack_status == SUN8I_JACK_STATUS_DISCONNECTED) {
  1185. if (scodec->last_hmic_irq != SUN8I_HMIC_STS_JACK_IN_IRQ_ST)
  1186. return;
  1187. scodec->jack_last_sample = -1;
  1188. if (scodec->jack_type & SND_JACK_MICROPHONE) {
  1189. /*
  1190. * If we were in disconnected state, we enable HBIAS and
  1191. * wait 600ms before reading initial HDATA value.
  1192. */
  1193. scodec->jack_hbias_ready = ktime_add_ms(ktime_get(), 600);
  1194. sun8i_codec_set_hmic_bias(scodec, true);
  1195. queue_delayed_work(system_power_efficient_wq,
  1196. &scodec->jack_work,
  1197. msecs_to_jiffies(610));
  1198. scodec->jack_status = SUN8I_JACK_STATUS_WAITING_HBIAS;
  1199. } else {
  1200. snd_soc_jack_report(scodec->jack, SND_JACK_HEADPHONE,
  1201. scodec->jack_type);
  1202. scodec->jack_status = SUN8I_JACK_STATUS_CONNECTED;
  1203. }
  1204. } else if (scodec->jack_status == SUN8I_JACK_STATUS_WAITING_HBIAS) {
  1205. /*
  1206. * If we're waiting for HBIAS to stabilize, and we get plug-out
  1207. * interrupt and nothing more for > 100ms, just cancel the
  1208. * initialization.
  1209. */
  1210. if (scodec->last_hmic_irq == SUN8I_HMIC_STS_JACK_OUT_IRQ_ST) {
  1211. scodec->jack_status = SUN8I_JACK_STATUS_DISCONNECTED;
  1212. sun8i_codec_set_hmic_bias(scodec, false);
  1213. return;
  1214. }
  1215. /*
  1216. * If we're not done waiting for HBIAS to stabilize, wait more.
  1217. */
  1218. if (!ktime_after(ktime_get(), scodec->jack_hbias_ready)) {
  1219. s64 msecs = ktime_ms_delta(scodec->jack_hbias_ready,
  1220. ktime_get());
  1221. queue_delayed_work(system_power_efficient_wq,
  1222. &scodec->jack_work,
  1223. msecs_to_jiffies(msecs + 10));
  1224. return;
  1225. }
  1226. /*
  1227. * Everything is stabilized, determine jack type and report it.
  1228. */
  1229. regmap_read(scodec->regmap, SUN8I_HMIC_STS, &mdata);
  1230. mdata &= SUN8I_HMIC_STS_HMIC_DATA_MASK;
  1231. mdata >>= SUN8I_HMIC_STS_HMIC_DATA;
  1232. regmap_write(scodec->regmap, SUN8I_HMIC_STS, 0);
  1233. type = mdata < 16 ? SND_JACK_HEADPHONE : SND_JACK_HEADSET;
  1234. if (type == SND_JACK_HEADPHONE)
  1235. sun8i_codec_set_hmic_bias(scodec, false);
  1236. snd_soc_jack_report(scodec->jack, type, scodec->jack_type);
  1237. scodec->jack_status = SUN8I_JACK_STATUS_CONNECTED;
  1238. } else if (scodec->jack_status == SUN8I_JACK_STATUS_CONNECTED) {
  1239. if (scodec->last_hmic_irq != SUN8I_HMIC_STS_JACK_OUT_IRQ_ST)
  1240. return;
  1241. scodec->jack_status = SUN8I_JACK_STATUS_DISCONNECTED;
  1242. if (scodec->jack_type & SND_JACK_MICROPHONE)
  1243. sun8i_codec_set_hmic_bias(scodec, false);
  1244. snd_soc_jack_report(scodec->jack, 0, scodec->jack_type);
  1245. }
  1246. }
  1247. static irqreturn_t sun8i_codec_jack_irq(int irq, void *dev_id)
  1248. {
  1249. struct sun8i_codec *scodec = dev_id;
  1250. int type = SND_JACK_HEADSET;
  1251. unsigned int status, value;
  1252. guard(mutex)(&scodec->jack_mutex);
  1253. regmap_read(scodec->regmap, SUN8I_HMIC_STS, &status);
  1254. regmap_write(scodec->regmap, SUN8I_HMIC_STS, status);
  1255. /*
  1256. * De-bounce in/out interrupts via a delayed work re-scheduling to
  1257. * 100ms after each interrupt..
  1258. */
  1259. if (status & BIT(SUN8I_HMIC_STS_JACK_OUT_IRQ_ST)) {
  1260. /*
  1261. * Out interrupt has priority over in interrupt so that if
  1262. * we get both, we assume the disconnected state, which is
  1263. * safer.
  1264. */
  1265. scodec->last_hmic_irq = SUN8I_HMIC_STS_JACK_OUT_IRQ_ST;
  1266. mod_delayed_work(system_power_efficient_wq, &scodec->jack_work,
  1267. msecs_to_jiffies(100));
  1268. } else if (status & BIT(SUN8I_HMIC_STS_JACK_IN_IRQ_ST)) {
  1269. scodec->last_hmic_irq = SUN8I_HMIC_STS_JACK_IN_IRQ_ST;
  1270. mod_delayed_work(system_power_efficient_wq, &scodec->jack_work,
  1271. msecs_to_jiffies(100));
  1272. } else if (status & BIT(SUN8I_HMIC_STS_HMIC_DATA_IRQ_ST)) {
  1273. /*
  1274. * Ignore data interrupts until jack status turns to connected
  1275. * state, which is after HMIC enable stabilization is completed.
  1276. * Until then tha data are bogus.
  1277. */
  1278. if (scodec->jack_status != SUN8I_JACK_STATUS_CONNECTED)
  1279. return IRQ_HANDLED;
  1280. value = (status & SUN8I_HMIC_STS_HMIC_DATA_MASK) >>
  1281. SUN8I_HMIC_STS_HMIC_DATA;
  1282. /*
  1283. * Assumes 60 mV per ADC LSB increment, 2V bias voltage, 2.2kOhm
  1284. * bias resistor.
  1285. */
  1286. if (value == 0)
  1287. type |= SND_JACK_BTN_0;
  1288. else if (value == 1)
  1289. type |= SND_JACK_BTN_3;
  1290. else if (value <= 3)
  1291. type |= SND_JACK_BTN_1;
  1292. else if (value <= 8)
  1293. type |= SND_JACK_BTN_2;
  1294. /*
  1295. * De-bounce. Only report button after two consecutive A/D
  1296. * samples are identical.
  1297. */
  1298. if (scodec->jack_last_sample >= 0 &&
  1299. scodec->jack_last_sample == value)
  1300. snd_soc_jack_report(scodec->jack, type,
  1301. scodec->jack_type);
  1302. scodec->jack_last_sample = value;
  1303. }
  1304. return IRQ_HANDLED;
  1305. }
  1306. static int sun8i_codec_enable_jack_detect(struct snd_soc_component *component,
  1307. struct snd_soc_jack *jack, void *data)
  1308. {
  1309. struct sun8i_codec *scodec = snd_soc_component_get_drvdata(component);
  1310. struct platform_device *pdev = to_platform_device(component->dev);
  1311. int ret;
  1312. if (!scodec->quirks->jack_detection)
  1313. return 0;
  1314. scodec->jack = jack;
  1315. scodec->jack_irq = platform_get_irq(pdev, 0);
  1316. if (scodec->jack_irq < 0)
  1317. return scodec->jack_irq;
  1318. /* Reserved value required for jack IRQs to trigger. */
  1319. regmap_write(scodec->regmap, SUN8I_HMIC_CTRL1,
  1320. 0xf << SUN8I_HMIC_CTRL1_HMIC_N |
  1321. 0x0 << SUN8I_HMIC_CTRL1_MDATA_THRESHOLD_DB |
  1322. 0x4 << SUN8I_HMIC_CTRL1_HMIC_M);
  1323. /* Sample the ADC at 128 Hz; bypass smooth filter. */
  1324. regmap_write(scodec->regmap, SUN8I_HMIC_CTRL2,
  1325. 0x0 << SUN8I_HMIC_CTRL2_HMIC_SAMPLE |
  1326. 0x17 << SUN8I_HMIC_CTRL2_HMIC_MDATA_THRESHOLD |
  1327. 0x0 << SUN8I_HMIC_CTRL2_HMIC_SF);
  1328. /* Do not discard any MDATA, enable user written MDATA threshold. */
  1329. regmap_write(scodec->regmap, SUN8I_HMIC_STS, 0);
  1330. regmap_set_bits(scodec->regmap, SUN8I_HMIC_CTRL1,
  1331. BIT(SUN8I_HMIC_CTRL1_JACK_OUT_IRQ_EN) |
  1332. BIT(SUN8I_HMIC_CTRL1_JACK_IN_IRQ_EN));
  1333. ret = devm_request_threaded_irq(&pdev->dev, scodec->jack_irq,
  1334. NULL, sun8i_codec_jack_irq,
  1335. IRQF_ONESHOT,
  1336. dev_name(&pdev->dev), scodec);
  1337. if (ret)
  1338. return ret;
  1339. return 0;
  1340. }
  1341. static void sun8i_codec_disable_jack_detect(struct snd_soc_component *component)
  1342. {
  1343. struct sun8i_codec *scodec = snd_soc_component_get_drvdata(component);
  1344. if (!scodec->quirks->jack_detection)
  1345. return;
  1346. devm_free_irq(component->dev, scodec->jack_irq, scodec);
  1347. cancel_delayed_work_sync(&scodec->jack_work);
  1348. regmap_clear_bits(scodec->regmap, SUN8I_HMIC_CTRL1,
  1349. BIT(SUN8I_HMIC_CTRL1_JACK_OUT_IRQ_EN) |
  1350. BIT(SUN8I_HMIC_CTRL1_JACK_IN_IRQ_EN) |
  1351. BIT(SUN8I_HMIC_CTRL1_HMIC_DATA_IRQ_EN));
  1352. scodec->jack = NULL;
  1353. }
  1354. static int sun8i_codec_component_set_jack(struct snd_soc_component *component,
  1355. struct snd_soc_jack *jack, void *data)
  1356. {
  1357. int ret = 0;
  1358. if (jack)
  1359. ret = sun8i_codec_enable_jack_detect(component, jack, data);
  1360. else
  1361. sun8i_codec_disable_jack_detect(component);
  1362. return ret;
  1363. }
  1364. static const struct snd_soc_component_driver sun8i_soc_component = {
  1365. .controls = sun8i_codec_controls,
  1366. .num_controls = ARRAY_SIZE(sun8i_codec_controls),
  1367. .dapm_widgets = sun8i_codec_dapm_widgets,
  1368. .num_dapm_widgets = ARRAY_SIZE(sun8i_codec_dapm_widgets),
  1369. .dapm_routes = sun8i_codec_dapm_routes,
  1370. .num_dapm_routes = ARRAY_SIZE(sun8i_codec_dapm_routes),
  1371. .set_jack = sun8i_codec_component_set_jack,
  1372. .probe = sun8i_codec_component_probe,
  1373. .idle_bias_on = 1,
  1374. .suspend_bias_off = 1,
  1375. .endianness = 1,
  1376. };
  1377. static bool sun8i_codec_volatile_reg(struct device *dev, unsigned int reg)
  1378. {
  1379. return reg == SUN8I_HMIC_STS;
  1380. }
  1381. static const struct regmap_config sun8i_codec_regmap_config = {
  1382. .reg_bits = 32,
  1383. .reg_stride = 4,
  1384. .val_bits = 32,
  1385. .volatile_reg = sun8i_codec_volatile_reg,
  1386. .max_register = SUN8I_DAC_MXR_SRC,
  1387. .cache_type = REGCACHE_FLAT,
  1388. };
  1389. static int sun8i_codec_probe(struct platform_device *pdev)
  1390. {
  1391. struct sun8i_codec *scodec;
  1392. void __iomem *base;
  1393. int ret;
  1394. scodec = devm_kzalloc(&pdev->dev, sizeof(*scodec), GFP_KERNEL);
  1395. if (!scodec)
  1396. return -ENOMEM;
  1397. scodec->quirks = of_device_get_match_data(&pdev->dev);
  1398. INIT_DELAYED_WORK(&scodec->jack_work, sun8i_codec_jack_work);
  1399. mutex_init(&scodec->jack_mutex);
  1400. platform_set_drvdata(pdev, scodec);
  1401. if (scodec->quirks->bus_clock) {
  1402. scodec->clk_bus = devm_clk_get(&pdev->dev, "bus");
  1403. if (IS_ERR(scodec->clk_bus)) {
  1404. dev_err(&pdev->dev, "Failed to get the bus clock\n");
  1405. return PTR_ERR(scodec->clk_bus);
  1406. }
  1407. }
  1408. scodec->clk_module = devm_clk_get(&pdev->dev, "mod");
  1409. if (IS_ERR(scodec->clk_module)) {
  1410. dev_err(&pdev->dev, "Failed to get the module clock\n");
  1411. return PTR_ERR(scodec->clk_module);
  1412. }
  1413. base = devm_platform_ioremap_resource(pdev, 0);
  1414. if (IS_ERR(base)) {
  1415. dev_err(&pdev->dev, "Failed to map the registers\n");
  1416. return PTR_ERR(base);
  1417. }
  1418. scodec->regmap = devm_regmap_init_mmio(&pdev->dev, base,
  1419. &sun8i_codec_regmap_config);
  1420. if (IS_ERR(scodec->regmap)) {
  1421. dev_err(&pdev->dev, "Failed to create our regmap\n");
  1422. return PTR_ERR(scodec->regmap);
  1423. }
  1424. regcache_cache_only(scodec->regmap, true);
  1425. pm_runtime_enable(&pdev->dev);
  1426. if (!pm_runtime_enabled(&pdev->dev)) {
  1427. ret = sun8i_codec_runtime_resume(&pdev->dev);
  1428. if (ret)
  1429. goto err_pm_disable;
  1430. }
  1431. ret = devm_snd_soc_register_component(&pdev->dev, &sun8i_soc_component,
  1432. sun8i_codec_dais,
  1433. ARRAY_SIZE(sun8i_codec_dais));
  1434. if (ret) {
  1435. dev_err(&pdev->dev, "Failed to register codec\n");
  1436. goto err_suspend;
  1437. }
  1438. return ret;
  1439. err_suspend:
  1440. if (!pm_runtime_status_suspended(&pdev->dev))
  1441. sun8i_codec_runtime_suspend(&pdev->dev);
  1442. err_pm_disable:
  1443. pm_runtime_disable(&pdev->dev);
  1444. return ret;
  1445. }
  1446. static void sun8i_codec_remove(struct platform_device *pdev)
  1447. {
  1448. pm_runtime_disable(&pdev->dev);
  1449. if (!pm_runtime_status_suspended(&pdev->dev))
  1450. sun8i_codec_runtime_suspend(&pdev->dev);
  1451. }
  1452. static const struct sun8i_codec_quirks sun8i_a33_quirks = {
  1453. .bus_clock = true,
  1454. .legacy_widgets = true,
  1455. .lrck_inversion = true,
  1456. };
  1457. static const struct sun8i_codec_quirks sun50i_a64_quirks = {
  1458. .bus_clock = true,
  1459. .jack_detection = true,
  1460. };
  1461. static const struct of_device_id sun8i_codec_of_match[] = {
  1462. { .compatible = "allwinner,sun8i-a33-codec", .data = &sun8i_a33_quirks },
  1463. { .compatible = "allwinner,sun50i-a64-codec", .data = &sun50i_a64_quirks },
  1464. {}
  1465. };
  1466. MODULE_DEVICE_TABLE(of, sun8i_codec_of_match);
  1467. static const struct dev_pm_ops sun8i_codec_pm_ops = {
  1468. SET_RUNTIME_PM_OPS(sun8i_codec_runtime_suspend,
  1469. sun8i_codec_runtime_resume, NULL)
  1470. };
  1471. static struct platform_driver sun8i_codec_driver = {
  1472. .driver = {
  1473. .name = "sun8i-codec",
  1474. .of_match_table = sun8i_codec_of_match,
  1475. .pm = &sun8i_codec_pm_ops,
  1476. },
  1477. .probe = sun8i_codec_probe,
  1478. .remove = sun8i_codec_remove,
  1479. };
  1480. module_platform_driver(sun8i_codec_driver);
  1481. MODULE_DESCRIPTION("Allwinner A33 (sun8i) codec driver");
  1482. MODULE_AUTHOR("Mylène Josserand <mylene.josserand@free-electrons.com>");
  1483. MODULE_LICENSE("GPL");
  1484. MODULE_ALIAS("platform:sun8i-codec");