tlv320aic32x4.c 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * linux/sound/soc/codecs/tlv320aic32x4.c
  4. *
  5. * Copyright 2011 Vista Silicon S.L.
  6. *
  7. * Author: Javier Martin <[email protected]>
  8. *
  9. * Based on sound/soc/codecs/wm8974 and TI driver for kernel 2.6.27.
  10. */
  11. #include <linux/module.h>
  12. #include <linux/moduleparam.h>
  13. #include <linux/init.h>
  14. #include <linux/delay.h>
  15. #include <linux/pm.h>
  16. #include <linux/gpio.h>
  17. #include <linux/of_gpio.h>
  18. #include <linux/cdev.h>
  19. #include <linux/slab.h>
  20. #include <linux/clk.h>
  21. #include <linux/of_clk.h>
  22. #include <linux/regulator/consumer.h>
  23. #include <sound/tlv320aic32x4.h>
  24. #include <sound/core.h>
  25. #include <sound/pcm.h>
  26. #include <sound/pcm_params.h>
  27. #include <sound/soc.h>
  28. #include <sound/soc-dapm.h>
  29. #include <sound/initval.h>
  30. #include <sound/tlv.h>
  31. #include "tlv320aic32x4.h"
  32. struct aic32x4_priv {
  33. struct regmap *regmap;
  34. u32 power_cfg;
  35. u32 micpga_routing;
  36. bool swapdacs;
  37. int rstn_gpio;
  38. const char *mclk_name;
  39. struct regulator *supply_ldo;
  40. struct regulator *supply_iov;
  41. struct regulator *supply_dv;
  42. struct regulator *supply_av;
  43. struct aic32x4_setup_data *setup;
  44. struct device *dev;
  45. enum aic32x4_type type;
  46. unsigned int fmt;
  47. };
  48. static int aic32x4_reset_adc(struct snd_soc_dapm_widget *w,
  49. struct snd_kcontrol *kcontrol, int event)
  50. {
  51. struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
  52. u32 adc_reg;
  53. /*
  54. * Workaround: the datasheet does not mention a required programming
  55. * sequence but experiments show the ADC needs to be reset after each
  56. * capture to avoid audible artifacts.
  57. */
  58. switch (event) {
  59. case SND_SOC_DAPM_POST_PMD:
  60. adc_reg = snd_soc_component_read(component, AIC32X4_ADCSETUP);
  61. snd_soc_component_write(component, AIC32X4_ADCSETUP, adc_reg |
  62. AIC32X4_LADC_EN | AIC32X4_RADC_EN);
  63. snd_soc_component_write(component, AIC32X4_ADCSETUP, adc_reg);
  64. break;
  65. }
  66. return 0;
  67. };
  68. static int mic_bias_event(struct snd_soc_dapm_widget *w,
  69. struct snd_kcontrol *kcontrol, int event)
  70. {
  71. struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
  72. switch (event) {
  73. case SND_SOC_DAPM_POST_PMU:
  74. /* Change Mic Bias Registor */
  75. snd_soc_component_update_bits(component, AIC32X4_MICBIAS,
  76. AIC32x4_MICBIAS_MASK,
  77. AIC32X4_MICBIAS_LDOIN |
  78. AIC32X4_MICBIAS_2075V);
  79. printk(KERN_DEBUG "%s: Mic Bias will be turned ON\n", __func__);
  80. break;
  81. case SND_SOC_DAPM_PRE_PMD:
  82. snd_soc_component_update_bits(component, AIC32X4_MICBIAS,
  83. AIC32x4_MICBIAS_MASK, 0);
  84. printk(KERN_DEBUG "%s: Mic Bias will be turned OFF\n",
  85. __func__);
  86. break;
  87. }
  88. return 0;
  89. }
  90. static int aic32x4_get_mfp1_gpio(struct snd_kcontrol *kcontrol,
  91. struct snd_ctl_elem_value *ucontrol)
  92. {
  93. struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
  94. u8 val;
  95. val = snd_soc_component_read(component, AIC32X4_DINCTL);
  96. ucontrol->value.integer.value[0] = (val & 0x01);
  97. return 0;
  98. };
  99. static int aic32x4_set_mfp2_gpio(struct snd_kcontrol *kcontrol,
  100. struct snd_ctl_elem_value *ucontrol)
  101. {
  102. struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
  103. u8 val;
  104. u8 gpio_check;
  105. val = snd_soc_component_read(component, AIC32X4_DOUTCTL);
  106. gpio_check = (val & AIC32X4_MFP_GPIO_ENABLED);
  107. if (gpio_check != AIC32X4_MFP_GPIO_ENABLED) {
  108. printk(KERN_ERR "%s: MFP2 is not configure as a GPIO output\n",
  109. __func__);
  110. return -EINVAL;
  111. }
  112. if (ucontrol->value.integer.value[0] == (val & AIC32X4_MFP2_GPIO_OUT_HIGH))
  113. return 0;
  114. if (ucontrol->value.integer.value[0])
  115. val |= ucontrol->value.integer.value[0];
  116. else
  117. val &= ~AIC32X4_MFP2_GPIO_OUT_HIGH;
  118. snd_soc_component_write(component, AIC32X4_DOUTCTL, val);
  119. return 0;
  120. };
  121. static int aic32x4_get_mfp3_gpio(struct snd_kcontrol *kcontrol,
  122. struct snd_ctl_elem_value *ucontrol)
  123. {
  124. struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
  125. u8 val;
  126. val = snd_soc_component_read(component, AIC32X4_SCLKCTL);
  127. ucontrol->value.integer.value[0] = (val & 0x01);
  128. return 0;
  129. };
  130. static int aic32x4_set_mfp4_gpio(struct snd_kcontrol *kcontrol,
  131. struct snd_ctl_elem_value *ucontrol)
  132. {
  133. struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
  134. u8 val;
  135. u8 gpio_check;
  136. val = snd_soc_component_read(component, AIC32X4_MISOCTL);
  137. gpio_check = (val & AIC32X4_MFP_GPIO_ENABLED);
  138. if (gpio_check != AIC32X4_MFP_GPIO_ENABLED) {
  139. printk(KERN_ERR "%s: MFP4 is not configure as a GPIO output\n",
  140. __func__);
  141. return -EINVAL;
  142. }
  143. if (ucontrol->value.integer.value[0] == (val & AIC32X4_MFP5_GPIO_OUT_HIGH))
  144. return 0;
  145. if (ucontrol->value.integer.value[0])
  146. val |= ucontrol->value.integer.value[0];
  147. else
  148. val &= ~AIC32X4_MFP5_GPIO_OUT_HIGH;
  149. snd_soc_component_write(component, AIC32X4_MISOCTL, val);
  150. return 0;
  151. };
  152. static int aic32x4_get_mfp5_gpio(struct snd_kcontrol *kcontrol,
  153. struct snd_ctl_elem_value *ucontrol)
  154. {
  155. struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
  156. u8 val;
  157. val = snd_soc_component_read(component, AIC32X4_GPIOCTL);
  158. ucontrol->value.integer.value[0] = ((val & 0x2) >> 1);
  159. return 0;
  160. };
  161. static int aic32x4_set_mfp5_gpio(struct snd_kcontrol *kcontrol,
  162. struct snd_ctl_elem_value *ucontrol)
  163. {
  164. struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
  165. u8 val;
  166. u8 gpio_check;
  167. val = snd_soc_component_read(component, AIC32X4_GPIOCTL);
  168. gpio_check = (val & AIC32X4_MFP5_GPIO_OUTPUT);
  169. if (gpio_check != AIC32X4_MFP5_GPIO_OUTPUT) {
  170. printk(KERN_ERR "%s: MFP5 is not configure as a GPIO output\n",
  171. __func__);
  172. return -EINVAL;
  173. }
  174. if (ucontrol->value.integer.value[0] == (val & 0x1))
  175. return 0;
  176. if (ucontrol->value.integer.value[0])
  177. val |= ucontrol->value.integer.value[0];
  178. else
  179. val &= 0xfe;
  180. snd_soc_component_write(component, AIC32X4_GPIOCTL, val);
  181. return 0;
  182. };
  183. static const struct snd_kcontrol_new aic32x4_mfp1[] = {
  184. SOC_SINGLE_BOOL_EXT("MFP1 GPIO", 0, aic32x4_get_mfp1_gpio, NULL),
  185. };
  186. static const struct snd_kcontrol_new aic32x4_mfp2[] = {
  187. SOC_SINGLE_BOOL_EXT("MFP2 GPIO", 0, NULL, aic32x4_set_mfp2_gpio),
  188. };
  189. static const struct snd_kcontrol_new aic32x4_mfp3[] = {
  190. SOC_SINGLE_BOOL_EXT("MFP3 GPIO", 0, aic32x4_get_mfp3_gpio, NULL),
  191. };
  192. static const struct snd_kcontrol_new aic32x4_mfp4[] = {
  193. SOC_SINGLE_BOOL_EXT("MFP4 GPIO", 0, NULL, aic32x4_set_mfp4_gpio),
  194. };
  195. static const struct snd_kcontrol_new aic32x4_mfp5[] = {
  196. SOC_SINGLE_BOOL_EXT("MFP5 GPIO", 0, aic32x4_get_mfp5_gpio,
  197. aic32x4_set_mfp5_gpio),
  198. };
  199. /* 0dB min, 0.5dB steps */
  200. static DECLARE_TLV_DB_SCALE(tlv_step_0_5, 0, 50, 0);
  201. /* -63.5dB min, 0.5dB steps */
  202. static DECLARE_TLV_DB_SCALE(tlv_pcm, -6350, 50, 0);
  203. /* -6dB min, 1dB steps */
  204. static DECLARE_TLV_DB_SCALE(tlv_driver_gain, -600, 100, 0);
  205. /* -12dB min, 0.5dB steps */
  206. static DECLARE_TLV_DB_SCALE(tlv_adc_vol, -1200, 50, 0);
  207. /* -6dB min, 1dB steps */
  208. static DECLARE_TLV_DB_SCALE(tlv_tas_driver_gain, -5850, 50, 0);
  209. static DECLARE_TLV_DB_SCALE(tlv_amp_vol, 0, 600, 1);
  210. static const char * const lo_cm_text[] = {
  211. "Full Chip", "1.65V",
  212. };
  213. static SOC_ENUM_SINGLE_DECL(lo_cm_enum, AIC32X4_CMMODE, 3, lo_cm_text);
  214. static const char * const ptm_text[] = {
  215. "P3", "P2", "P1",
  216. };
  217. static SOC_ENUM_SINGLE_DECL(l_ptm_enum, AIC32X4_LPLAYBACK, 2, ptm_text);
  218. static SOC_ENUM_SINGLE_DECL(r_ptm_enum, AIC32X4_RPLAYBACK, 2, ptm_text);
  219. static const struct snd_kcontrol_new aic32x4_snd_controls[] = {
  220. SOC_DOUBLE_R_S_TLV("PCM Playback Volume", AIC32X4_LDACVOL,
  221. AIC32X4_RDACVOL, 0, -0x7f, 0x30, 7, 0, tlv_pcm),
  222. SOC_ENUM("DAC Left Playback PowerTune Switch", l_ptm_enum),
  223. SOC_ENUM("DAC Right Playback PowerTune Switch", r_ptm_enum),
  224. SOC_DOUBLE_R_S_TLV("HP Driver Gain Volume", AIC32X4_HPLGAIN,
  225. AIC32X4_HPRGAIN, 0, -0x6, 0x1d, 5, 0,
  226. tlv_driver_gain),
  227. SOC_DOUBLE_R_S_TLV("LO Driver Gain Volume", AIC32X4_LOLGAIN,
  228. AIC32X4_LORGAIN, 0, -0x6, 0x1d, 5, 0,
  229. tlv_driver_gain),
  230. SOC_DOUBLE_R("HP DAC Playback Switch", AIC32X4_HPLGAIN,
  231. AIC32X4_HPRGAIN, 6, 0x01, 1),
  232. SOC_DOUBLE_R("LO DAC Playback Switch", AIC32X4_LOLGAIN,
  233. AIC32X4_LORGAIN, 6, 0x01, 1),
  234. SOC_ENUM("LO Playback Common Mode Switch", lo_cm_enum),
  235. SOC_DOUBLE_R("Mic PGA Switch", AIC32X4_LMICPGAVOL,
  236. AIC32X4_RMICPGAVOL, 7, 0x01, 1),
  237. SOC_SINGLE("ADCFGA Left Mute Switch", AIC32X4_ADCFGA, 7, 1, 0),
  238. SOC_SINGLE("ADCFGA Right Mute Switch", AIC32X4_ADCFGA, 3, 1, 0),
  239. SOC_DOUBLE_R_S_TLV("ADC Level Volume", AIC32X4_LADCVOL,
  240. AIC32X4_RADCVOL, 0, -0x18, 0x28, 6, 0, tlv_adc_vol),
  241. SOC_DOUBLE_R_TLV("PGA Level Volume", AIC32X4_LMICPGAVOL,
  242. AIC32X4_RMICPGAVOL, 0, 0x5f, 0, tlv_step_0_5),
  243. SOC_SINGLE("Auto-mute Switch", AIC32X4_DACMUTE, 4, 7, 0),
  244. SOC_SINGLE("AGC Left Switch", AIC32X4_LAGC1, 7, 1, 0),
  245. SOC_SINGLE("AGC Right Switch", AIC32X4_RAGC1, 7, 1, 0),
  246. SOC_DOUBLE_R("AGC Target Level", AIC32X4_LAGC1, AIC32X4_RAGC1,
  247. 4, 0x07, 0),
  248. SOC_DOUBLE_R("AGC Gain Hysteresis", AIC32X4_LAGC1, AIC32X4_RAGC1,
  249. 0, 0x03, 0),
  250. SOC_DOUBLE_R("AGC Hysteresis", AIC32X4_LAGC2, AIC32X4_RAGC2,
  251. 6, 0x03, 0),
  252. SOC_DOUBLE_R("AGC Noise Threshold", AIC32X4_LAGC2, AIC32X4_RAGC2,
  253. 1, 0x1F, 0),
  254. SOC_DOUBLE_R("AGC Max PGA", AIC32X4_LAGC3, AIC32X4_RAGC3,
  255. 0, 0x7F, 0),
  256. SOC_DOUBLE_R("AGC Attack Time", AIC32X4_LAGC4, AIC32X4_RAGC4,
  257. 3, 0x1F, 0),
  258. SOC_DOUBLE_R("AGC Decay Time", AIC32X4_LAGC5, AIC32X4_RAGC5,
  259. 3, 0x1F, 0),
  260. SOC_DOUBLE_R("AGC Noise Debounce", AIC32X4_LAGC6, AIC32X4_RAGC6,
  261. 0, 0x1F, 0),
  262. SOC_DOUBLE_R("AGC Signal Debounce", AIC32X4_LAGC7, AIC32X4_RAGC7,
  263. 0, 0x0F, 0),
  264. };
  265. static const struct snd_kcontrol_new hpl_output_mixer_controls[] = {
  266. SOC_DAPM_SINGLE("L_DAC Switch", AIC32X4_HPLROUTE, 3, 1, 0),
  267. SOC_DAPM_SINGLE("IN1_L Switch", AIC32X4_HPLROUTE, 2, 1, 0),
  268. };
  269. static const struct snd_kcontrol_new hpr_output_mixer_controls[] = {
  270. SOC_DAPM_SINGLE("R_DAC Switch", AIC32X4_HPRROUTE, 3, 1, 0),
  271. SOC_DAPM_SINGLE("IN1_R Switch", AIC32X4_HPRROUTE, 2, 1, 0),
  272. };
  273. static const struct snd_kcontrol_new lol_output_mixer_controls[] = {
  274. SOC_DAPM_SINGLE("L_DAC Switch", AIC32X4_LOLROUTE, 3, 1, 0),
  275. };
  276. static const struct snd_kcontrol_new lor_output_mixer_controls[] = {
  277. SOC_DAPM_SINGLE("R_DAC Switch", AIC32X4_LORROUTE, 3, 1, 0),
  278. };
  279. static const char * const resistor_text[] = {
  280. "Off", "10 kOhm", "20 kOhm", "40 kOhm",
  281. };
  282. /* Left mixer pins */
  283. static SOC_ENUM_SINGLE_DECL(in1l_lpga_p_enum, AIC32X4_LMICPGAPIN, 6, resistor_text);
  284. static SOC_ENUM_SINGLE_DECL(in2l_lpga_p_enum, AIC32X4_LMICPGAPIN, 4, resistor_text);
  285. static SOC_ENUM_SINGLE_DECL(in3l_lpga_p_enum, AIC32X4_LMICPGAPIN, 2, resistor_text);
  286. static SOC_ENUM_SINGLE_DECL(in1r_lpga_p_enum, AIC32X4_LMICPGAPIN, 0, resistor_text);
  287. static SOC_ENUM_SINGLE_DECL(cml_lpga_n_enum, AIC32X4_LMICPGANIN, 6, resistor_text);
  288. static SOC_ENUM_SINGLE_DECL(in2r_lpga_n_enum, AIC32X4_LMICPGANIN, 4, resistor_text);
  289. static SOC_ENUM_SINGLE_DECL(in3r_lpga_n_enum, AIC32X4_LMICPGANIN, 2, resistor_text);
  290. static const struct snd_kcontrol_new in1l_to_lmixer_controls[] = {
  291. SOC_DAPM_ENUM("IN1_L L+ Switch", in1l_lpga_p_enum),
  292. };
  293. static const struct snd_kcontrol_new in2l_to_lmixer_controls[] = {
  294. SOC_DAPM_ENUM("IN2_L L+ Switch", in2l_lpga_p_enum),
  295. };
  296. static const struct snd_kcontrol_new in3l_to_lmixer_controls[] = {
  297. SOC_DAPM_ENUM("IN3_L L+ Switch", in3l_lpga_p_enum),
  298. };
  299. static const struct snd_kcontrol_new in1r_to_lmixer_controls[] = {
  300. SOC_DAPM_ENUM("IN1_R L+ Switch", in1r_lpga_p_enum),
  301. };
  302. static const struct snd_kcontrol_new cml_to_lmixer_controls[] = {
  303. SOC_DAPM_ENUM("CM_L L- Switch", cml_lpga_n_enum),
  304. };
  305. static const struct snd_kcontrol_new in2r_to_lmixer_controls[] = {
  306. SOC_DAPM_ENUM("IN2_R L- Switch", in2r_lpga_n_enum),
  307. };
  308. static const struct snd_kcontrol_new in3r_to_lmixer_controls[] = {
  309. SOC_DAPM_ENUM("IN3_R L- Switch", in3r_lpga_n_enum),
  310. };
  311. /* Right mixer pins */
  312. static SOC_ENUM_SINGLE_DECL(in1r_rpga_p_enum, AIC32X4_RMICPGAPIN, 6, resistor_text);
  313. static SOC_ENUM_SINGLE_DECL(in2r_rpga_p_enum, AIC32X4_RMICPGAPIN, 4, resistor_text);
  314. static SOC_ENUM_SINGLE_DECL(in3r_rpga_p_enum, AIC32X4_RMICPGAPIN, 2, resistor_text);
  315. static SOC_ENUM_SINGLE_DECL(in2l_rpga_p_enum, AIC32X4_RMICPGAPIN, 0, resistor_text);
  316. static SOC_ENUM_SINGLE_DECL(cmr_rpga_n_enum, AIC32X4_RMICPGANIN, 6, resistor_text);
  317. static SOC_ENUM_SINGLE_DECL(in1l_rpga_n_enum, AIC32X4_RMICPGANIN, 4, resistor_text);
  318. static SOC_ENUM_SINGLE_DECL(in3l_rpga_n_enum, AIC32X4_RMICPGANIN, 2, resistor_text);
  319. static const struct snd_kcontrol_new in1r_to_rmixer_controls[] = {
  320. SOC_DAPM_ENUM("IN1_R R+ Switch", in1r_rpga_p_enum),
  321. };
  322. static const struct snd_kcontrol_new in2r_to_rmixer_controls[] = {
  323. SOC_DAPM_ENUM("IN2_R R+ Switch", in2r_rpga_p_enum),
  324. };
  325. static const struct snd_kcontrol_new in3r_to_rmixer_controls[] = {
  326. SOC_DAPM_ENUM("IN3_R R+ Switch", in3r_rpga_p_enum),
  327. };
  328. static const struct snd_kcontrol_new in2l_to_rmixer_controls[] = {
  329. SOC_DAPM_ENUM("IN2_L R+ Switch", in2l_rpga_p_enum),
  330. };
  331. static const struct snd_kcontrol_new cmr_to_rmixer_controls[] = {
  332. SOC_DAPM_ENUM("CM_R R- Switch", cmr_rpga_n_enum),
  333. };
  334. static const struct snd_kcontrol_new in1l_to_rmixer_controls[] = {
  335. SOC_DAPM_ENUM("IN1_L R- Switch", in1l_rpga_n_enum),
  336. };
  337. static const struct snd_kcontrol_new in3l_to_rmixer_controls[] = {
  338. SOC_DAPM_ENUM("IN3_L R- Switch", in3l_rpga_n_enum),
  339. };
  340. static const struct snd_soc_dapm_widget aic32x4_dapm_widgets[] = {
  341. SND_SOC_DAPM_DAC("Left DAC", "Left Playback", AIC32X4_DACSETUP, 7, 0),
  342. SND_SOC_DAPM_MIXER("HPL Output Mixer", SND_SOC_NOPM, 0, 0,
  343. &hpl_output_mixer_controls[0],
  344. ARRAY_SIZE(hpl_output_mixer_controls)),
  345. SND_SOC_DAPM_PGA("HPL Power", AIC32X4_OUTPWRCTL, 5, 0, NULL, 0),
  346. SND_SOC_DAPM_MIXER("LOL Output Mixer", SND_SOC_NOPM, 0, 0,
  347. &lol_output_mixer_controls[0],
  348. ARRAY_SIZE(lol_output_mixer_controls)),
  349. SND_SOC_DAPM_PGA("LOL Power", AIC32X4_OUTPWRCTL, 3, 0, NULL, 0),
  350. SND_SOC_DAPM_DAC("Right DAC", "Right Playback", AIC32X4_DACSETUP, 6, 0),
  351. SND_SOC_DAPM_MIXER("HPR Output Mixer", SND_SOC_NOPM, 0, 0,
  352. &hpr_output_mixer_controls[0],
  353. ARRAY_SIZE(hpr_output_mixer_controls)),
  354. SND_SOC_DAPM_PGA("HPR Power", AIC32X4_OUTPWRCTL, 4, 0, NULL, 0),
  355. SND_SOC_DAPM_MIXER("LOR Output Mixer", SND_SOC_NOPM, 0, 0,
  356. &lor_output_mixer_controls[0],
  357. ARRAY_SIZE(lor_output_mixer_controls)),
  358. SND_SOC_DAPM_PGA("LOR Power", AIC32X4_OUTPWRCTL, 2, 0, NULL, 0),
  359. SND_SOC_DAPM_ADC("Right ADC", "Right Capture", AIC32X4_ADCSETUP, 6, 0),
  360. SND_SOC_DAPM_MUX("IN1_R to Right Mixer Positive Resistor", SND_SOC_NOPM, 0, 0,
  361. in1r_to_rmixer_controls),
  362. SND_SOC_DAPM_MUX("IN2_R to Right Mixer Positive Resistor", SND_SOC_NOPM, 0, 0,
  363. in2r_to_rmixer_controls),
  364. SND_SOC_DAPM_MUX("IN3_R to Right Mixer Positive Resistor", SND_SOC_NOPM, 0, 0,
  365. in3r_to_rmixer_controls),
  366. SND_SOC_DAPM_MUX("IN2_L to Right Mixer Positive Resistor", SND_SOC_NOPM, 0, 0,
  367. in2l_to_rmixer_controls),
  368. SND_SOC_DAPM_MUX("CM_R to Right Mixer Negative Resistor", SND_SOC_NOPM, 0, 0,
  369. cmr_to_rmixer_controls),
  370. SND_SOC_DAPM_MUX("IN1_L to Right Mixer Negative Resistor", SND_SOC_NOPM, 0, 0,
  371. in1l_to_rmixer_controls),
  372. SND_SOC_DAPM_MUX("IN3_L to Right Mixer Negative Resistor", SND_SOC_NOPM, 0, 0,
  373. in3l_to_rmixer_controls),
  374. SND_SOC_DAPM_ADC("Left ADC", "Left Capture", AIC32X4_ADCSETUP, 7, 0),
  375. SND_SOC_DAPM_MUX("IN1_L to Left Mixer Positive Resistor", SND_SOC_NOPM, 0, 0,
  376. in1l_to_lmixer_controls),
  377. SND_SOC_DAPM_MUX("IN2_L to Left Mixer Positive Resistor", SND_SOC_NOPM, 0, 0,
  378. in2l_to_lmixer_controls),
  379. SND_SOC_DAPM_MUX("IN3_L to Left Mixer Positive Resistor", SND_SOC_NOPM, 0, 0,
  380. in3l_to_lmixer_controls),
  381. SND_SOC_DAPM_MUX("IN1_R to Left Mixer Positive Resistor", SND_SOC_NOPM, 0, 0,
  382. in1r_to_lmixer_controls),
  383. SND_SOC_DAPM_MUX("CM_L to Left Mixer Negative Resistor", SND_SOC_NOPM, 0, 0,
  384. cml_to_lmixer_controls),
  385. SND_SOC_DAPM_MUX("IN2_R to Left Mixer Negative Resistor", SND_SOC_NOPM, 0, 0,
  386. in2r_to_lmixer_controls),
  387. SND_SOC_DAPM_MUX("IN3_R to Left Mixer Negative Resistor", SND_SOC_NOPM, 0, 0,
  388. in3r_to_lmixer_controls),
  389. SND_SOC_DAPM_SUPPLY("Mic Bias", AIC32X4_MICBIAS, 6, 0, mic_bias_event,
  390. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
  391. SND_SOC_DAPM_POST("ADC Reset", aic32x4_reset_adc),
  392. SND_SOC_DAPM_OUTPUT("HPL"),
  393. SND_SOC_DAPM_OUTPUT("HPR"),
  394. SND_SOC_DAPM_OUTPUT("LOL"),
  395. SND_SOC_DAPM_OUTPUT("LOR"),
  396. SND_SOC_DAPM_INPUT("IN1_L"),
  397. SND_SOC_DAPM_INPUT("IN1_R"),
  398. SND_SOC_DAPM_INPUT("IN2_L"),
  399. SND_SOC_DAPM_INPUT("IN2_R"),
  400. SND_SOC_DAPM_INPUT("IN3_L"),
  401. SND_SOC_DAPM_INPUT("IN3_R"),
  402. SND_SOC_DAPM_INPUT("CM_L"),
  403. SND_SOC_DAPM_INPUT("CM_R"),
  404. };
  405. static const struct snd_soc_dapm_route aic32x4_dapm_routes[] = {
  406. /* Left Output */
  407. {"HPL Output Mixer", "L_DAC Switch", "Left DAC"},
  408. {"HPL Output Mixer", "IN1_L Switch", "IN1_L"},
  409. {"HPL Power", NULL, "HPL Output Mixer"},
  410. {"HPL", NULL, "HPL Power"},
  411. {"LOL Output Mixer", "L_DAC Switch", "Left DAC"},
  412. {"LOL Power", NULL, "LOL Output Mixer"},
  413. {"LOL", NULL, "LOL Power"},
  414. /* Right Output */
  415. {"HPR Output Mixer", "R_DAC Switch", "Right DAC"},
  416. {"HPR Output Mixer", "IN1_R Switch", "IN1_R"},
  417. {"HPR Power", NULL, "HPR Output Mixer"},
  418. {"HPR", NULL, "HPR Power"},
  419. {"LOR Output Mixer", "R_DAC Switch", "Right DAC"},
  420. {"LOR Power", NULL, "LOR Output Mixer"},
  421. {"LOR", NULL, "LOR Power"},
  422. /* Right Input */
  423. {"Right ADC", NULL, "IN1_R to Right Mixer Positive Resistor"},
  424. {"IN1_R to Right Mixer Positive Resistor", "10 kOhm", "IN1_R"},
  425. {"IN1_R to Right Mixer Positive Resistor", "20 kOhm", "IN1_R"},
  426. {"IN1_R to Right Mixer Positive Resistor", "40 kOhm", "IN1_R"},
  427. {"Right ADC", NULL, "IN2_R to Right Mixer Positive Resistor"},
  428. {"IN2_R to Right Mixer Positive Resistor", "10 kOhm", "IN2_R"},
  429. {"IN2_R to Right Mixer Positive Resistor", "20 kOhm", "IN2_R"},
  430. {"IN2_R to Right Mixer Positive Resistor", "40 kOhm", "IN2_R"},
  431. {"Right ADC", NULL, "IN3_R to Right Mixer Positive Resistor"},
  432. {"IN3_R to Right Mixer Positive Resistor", "10 kOhm", "IN3_R"},
  433. {"IN3_R to Right Mixer Positive Resistor", "20 kOhm", "IN3_R"},
  434. {"IN3_R to Right Mixer Positive Resistor", "40 kOhm", "IN3_R"},
  435. {"Right ADC", NULL, "IN2_L to Right Mixer Positive Resistor"},
  436. {"IN2_L to Right Mixer Positive Resistor", "10 kOhm", "IN2_L"},
  437. {"IN2_L to Right Mixer Positive Resistor", "20 kOhm", "IN2_L"},
  438. {"IN2_L to Right Mixer Positive Resistor", "40 kOhm", "IN2_L"},
  439. {"Right ADC", NULL, "CM_R to Right Mixer Negative Resistor"},
  440. {"CM_R to Right Mixer Negative Resistor", "10 kOhm", "CM_R"},
  441. {"CM_R to Right Mixer Negative Resistor", "20 kOhm", "CM_R"},
  442. {"CM_R to Right Mixer Negative Resistor", "40 kOhm", "CM_R"},
  443. {"Right ADC", NULL, "IN1_L to Right Mixer Negative Resistor"},
  444. {"IN1_L to Right Mixer Negative Resistor", "10 kOhm", "IN1_L"},
  445. {"IN1_L to Right Mixer Negative Resistor", "20 kOhm", "IN1_L"},
  446. {"IN1_L to Right Mixer Negative Resistor", "40 kOhm", "IN1_L"},
  447. {"Right ADC", NULL, "IN3_L to Right Mixer Negative Resistor"},
  448. {"IN3_L to Right Mixer Negative Resistor", "10 kOhm", "IN3_L"},
  449. {"IN3_L to Right Mixer Negative Resistor", "20 kOhm", "IN3_L"},
  450. {"IN3_L to Right Mixer Negative Resistor", "40 kOhm", "IN3_L"},
  451. /* Left Input */
  452. {"Left ADC", NULL, "IN1_L to Left Mixer Positive Resistor"},
  453. {"IN1_L to Left Mixer Positive Resistor", "10 kOhm", "IN1_L"},
  454. {"IN1_L to Left Mixer Positive Resistor", "20 kOhm", "IN1_L"},
  455. {"IN1_L to Left Mixer Positive Resistor", "40 kOhm", "IN1_L"},
  456. {"Left ADC", NULL, "IN2_L to Left Mixer Positive Resistor"},
  457. {"IN2_L to Left Mixer Positive Resistor", "10 kOhm", "IN2_L"},
  458. {"IN2_L to Left Mixer Positive Resistor", "20 kOhm", "IN2_L"},
  459. {"IN2_L to Left Mixer Positive Resistor", "40 kOhm", "IN2_L"},
  460. {"Left ADC", NULL, "IN3_L to Left Mixer Positive Resistor"},
  461. {"IN3_L to Left Mixer Positive Resistor", "10 kOhm", "IN3_L"},
  462. {"IN3_L to Left Mixer Positive Resistor", "20 kOhm", "IN3_L"},
  463. {"IN3_L to Left Mixer Positive Resistor", "40 kOhm", "IN3_L"},
  464. {"Left ADC", NULL, "IN1_R to Left Mixer Positive Resistor"},
  465. {"IN1_R to Left Mixer Positive Resistor", "10 kOhm", "IN1_R"},
  466. {"IN1_R to Left Mixer Positive Resistor", "20 kOhm", "IN1_R"},
  467. {"IN1_R to Left Mixer Positive Resistor", "40 kOhm", "IN1_R"},
  468. {"Left ADC", NULL, "CM_L to Left Mixer Negative Resistor"},
  469. {"CM_L to Left Mixer Negative Resistor", "10 kOhm", "CM_L"},
  470. {"CM_L to Left Mixer Negative Resistor", "20 kOhm", "CM_L"},
  471. {"CM_L to Left Mixer Negative Resistor", "40 kOhm", "CM_L"},
  472. {"Left ADC", NULL, "IN2_R to Left Mixer Negative Resistor"},
  473. {"IN2_R to Left Mixer Negative Resistor", "10 kOhm", "IN2_R"},
  474. {"IN2_R to Left Mixer Negative Resistor", "20 kOhm", "IN2_R"},
  475. {"IN2_R to Left Mixer Negative Resistor", "40 kOhm", "IN2_R"},
  476. {"Left ADC", NULL, "IN3_R to Left Mixer Negative Resistor"},
  477. {"IN3_R to Left Mixer Negative Resistor", "10 kOhm", "IN3_R"},
  478. {"IN3_R to Left Mixer Negative Resistor", "20 kOhm", "IN3_R"},
  479. {"IN3_R to Left Mixer Negative Resistor", "40 kOhm", "IN3_R"},
  480. };
  481. static const struct regmap_range_cfg aic32x4_regmap_pages[] = {
  482. {
  483. .selector_reg = 0,
  484. .selector_mask = 0xff,
  485. .window_start = 0,
  486. .window_len = 128,
  487. .range_min = 0,
  488. .range_max = AIC32X4_REFPOWERUP,
  489. },
  490. };
  491. const struct regmap_config aic32x4_regmap_config = {
  492. .max_register = AIC32X4_REFPOWERUP,
  493. .ranges = aic32x4_regmap_pages,
  494. .num_ranges = ARRAY_SIZE(aic32x4_regmap_pages),
  495. };
  496. EXPORT_SYMBOL(aic32x4_regmap_config);
  497. static int aic32x4_set_dai_sysclk(struct snd_soc_dai *codec_dai,
  498. int clk_id, unsigned int freq, int dir)
  499. {
  500. struct snd_soc_component *component = codec_dai->component;
  501. struct clk *mclk;
  502. struct clk *pll;
  503. pll = devm_clk_get(component->dev, "pll");
  504. if (IS_ERR(pll))
  505. return PTR_ERR(pll);
  506. mclk = clk_get_parent(pll);
  507. return clk_set_rate(mclk, freq);
  508. }
  509. static int aic32x4_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
  510. {
  511. struct snd_soc_component *component = codec_dai->component;
  512. struct aic32x4_priv *aic32x4 = snd_soc_component_get_drvdata(component);
  513. u8 iface_reg_1 = 0;
  514. u8 iface_reg_2 = 0;
  515. u8 iface_reg_3 = 0;
  516. switch (fmt & SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK) {
  517. case SND_SOC_DAIFMT_CBP_CFP:
  518. iface_reg_1 |= AIC32X4_BCLKMASTER | AIC32X4_WCLKMASTER;
  519. break;
  520. case SND_SOC_DAIFMT_CBC_CFC:
  521. break;
  522. default:
  523. printk(KERN_ERR "aic32x4: invalid clock provider\n");
  524. return -EINVAL;
  525. }
  526. switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  527. case SND_SOC_DAIFMT_I2S:
  528. break;
  529. case SND_SOC_DAIFMT_DSP_A:
  530. iface_reg_1 |= (AIC32X4_DSP_MODE <<
  531. AIC32X4_IFACE1_DATATYPE_SHIFT);
  532. iface_reg_3 |= AIC32X4_BCLKINV_MASK; /* invert bit clock */
  533. iface_reg_2 = 0x01; /* add offset 1 */
  534. break;
  535. case SND_SOC_DAIFMT_DSP_B:
  536. iface_reg_1 |= (AIC32X4_DSP_MODE <<
  537. AIC32X4_IFACE1_DATATYPE_SHIFT);
  538. iface_reg_3 |= AIC32X4_BCLKINV_MASK; /* invert bit clock */
  539. break;
  540. case SND_SOC_DAIFMT_RIGHT_J:
  541. iface_reg_1 |= (AIC32X4_RIGHT_JUSTIFIED_MODE <<
  542. AIC32X4_IFACE1_DATATYPE_SHIFT);
  543. break;
  544. case SND_SOC_DAIFMT_LEFT_J:
  545. iface_reg_1 |= (AIC32X4_LEFT_JUSTIFIED_MODE <<
  546. AIC32X4_IFACE1_DATATYPE_SHIFT);
  547. break;
  548. default:
  549. printk(KERN_ERR "aic32x4: invalid DAI interface format\n");
  550. return -EINVAL;
  551. }
  552. aic32x4->fmt = fmt;
  553. snd_soc_component_update_bits(component, AIC32X4_IFACE1,
  554. AIC32X4_IFACE1_DATATYPE_MASK |
  555. AIC32X4_IFACE1_MASTER_MASK, iface_reg_1);
  556. snd_soc_component_update_bits(component, AIC32X4_IFACE2,
  557. AIC32X4_DATA_OFFSET_MASK, iface_reg_2);
  558. snd_soc_component_update_bits(component, AIC32X4_IFACE3,
  559. AIC32X4_BCLKINV_MASK, iface_reg_3);
  560. return 0;
  561. }
  562. static int aic32x4_set_aosr(struct snd_soc_component *component, u8 aosr)
  563. {
  564. return snd_soc_component_write(component, AIC32X4_AOSR, aosr);
  565. }
  566. static int aic32x4_set_dosr(struct snd_soc_component *component, u16 dosr)
  567. {
  568. snd_soc_component_write(component, AIC32X4_DOSRMSB, dosr >> 8);
  569. snd_soc_component_write(component, AIC32X4_DOSRLSB,
  570. (dosr & 0xff));
  571. return 0;
  572. }
  573. static int aic32x4_set_processing_blocks(struct snd_soc_component *component,
  574. u8 r_block, u8 p_block)
  575. {
  576. struct aic32x4_priv *aic32x4 = snd_soc_component_get_drvdata(component);
  577. if (aic32x4->type == AIC32X4_TYPE_TAS2505) {
  578. if (r_block || p_block > 3)
  579. return -EINVAL;
  580. snd_soc_component_write(component, AIC32X4_DACSPB, p_block);
  581. } else { /* AIC32x4 */
  582. if (r_block > 18 || p_block > 25)
  583. return -EINVAL;
  584. snd_soc_component_write(component, AIC32X4_ADCSPB, r_block);
  585. snd_soc_component_write(component, AIC32X4_DACSPB, p_block);
  586. }
  587. return 0;
  588. }
  589. static int aic32x4_setup_clocks(struct snd_soc_component *component,
  590. unsigned int sample_rate, unsigned int channels,
  591. unsigned int bit_depth)
  592. {
  593. struct aic32x4_priv *aic32x4 = snd_soc_component_get_drvdata(component);
  594. u8 aosr;
  595. u16 dosr;
  596. u8 adc_resource_class, dac_resource_class;
  597. u8 madc, nadc, mdac, ndac, max_nadc, min_mdac, max_ndac;
  598. u8 dosr_increment;
  599. u16 max_dosr, min_dosr;
  600. unsigned long adc_clock_rate, dac_clock_rate;
  601. int ret;
  602. static struct clk_bulk_data clocks[] = {
  603. { .id = "pll" },
  604. { .id = "nadc" },
  605. { .id = "madc" },
  606. { .id = "ndac" },
  607. { .id = "mdac" },
  608. { .id = "bdiv" },
  609. };
  610. ret = devm_clk_bulk_get(component->dev, ARRAY_SIZE(clocks), clocks);
  611. if (ret)
  612. return ret;
  613. if (sample_rate <= 48000) {
  614. aosr = 128;
  615. adc_resource_class = 6;
  616. dac_resource_class = 8;
  617. dosr_increment = 8;
  618. if (aic32x4->type == AIC32X4_TYPE_TAS2505)
  619. aic32x4_set_processing_blocks(component, 0, 1);
  620. else
  621. aic32x4_set_processing_blocks(component, 1, 1);
  622. } else if (sample_rate <= 96000) {
  623. aosr = 64;
  624. adc_resource_class = 6;
  625. dac_resource_class = 8;
  626. dosr_increment = 4;
  627. if (aic32x4->type == AIC32X4_TYPE_TAS2505)
  628. aic32x4_set_processing_blocks(component, 0, 1);
  629. else
  630. aic32x4_set_processing_blocks(component, 1, 9);
  631. } else if (sample_rate == 192000) {
  632. aosr = 32;
  633. adc_resource_class = 3;
  634. dac_resource_class = 4;
  635. dosr_increment = 2;
  636. if (aic32x4->type == AIC32X4_TYPE_TAS2505)
  637. aic32x4_set_processing_blocks(component, 0, 1);
  638. else
  639. aic32x4_set_processing_blocks(component, 13, 19);
  640. } else {
  641. dev_err(component->dev, "Sampling rate not supported\n");
  642. return -EINVAL;
  643. }
  644. /* PCM over I2S is always 2-channel */
  645. if ((aic32x4->fmt & SND_SOC_DAIFMT_FORMAT_MASK) == SND_SOC_DAIFMT_I2S)
  646. channels = 2;
  647. madc = DIV_ROUND_UP((32 * adc_resource_class), aosr);
  648. max_dosr = (AIC32X4_MAX_DOSR_FREQ / sample_rate / dosr_increment) *
  649. dosr_increment;
  650. min_dosr = (AIC32X4_MIN_DOSR_FREQ / sample_rate / dosr_increment) *
  651. dosr_increment;
  652. max_nadc = AIC32X4_MAX_CODEC_CLKIN_FREQ / (madc * aosr * sample_rate);
  653. for (nadc = max_nadc; nadc > 0; --nadc) {
  654. adc_clock_rate = nadc * madc * aosr * sample_rate;
  655. for (dosr = max_dosr; dosr >= min_dosr;
  656. dosr -= dosr_increment) {
  657. min_mdac = DIV_ROUND_UP((32 * dac_resource_class), dosr);
  658. max_ndac = AIC32X4_MAX_CODEC_CLKIN_FREQ /
  659. (min_mdac * dosr * sample_rate);
  660. for (mdac = min_mdac; mdac <= 128; ++mdac) {
  661. for (ndac = max_ndac; ndac > 0; --ndac) {
  662. dac_clock_rate = ndac * mdac * dosr *
  663. sample_rate;
  664. if (dac_clock_rate == adc_clock_rate) {
  665. if (clk_round_rate(clocks[0].clk, dac_clock_rate) == 0)
  666. continue;
  667. clk_set_rate(clocks[0].clk,
  668. dac_clock_rate);
  669. clk_set_rate(clocks[1].clk,
  670. sample_rate * aosr *
  671. madc);
  672. clk_set_rate(clocks[2].clk,
  673. sample_rate * aosr);
  674. aic32x4_set_aosr(component,
  675. aosr);
  676. clk_set_rate(clocks[3].clk,
  677. sample_rate * dosr *
  678. mdac);
  679. clk_set_rate(clocks[4].clk,
  680. sample_rate * dosr);
  681. aic32x4_set_dosr(component,
  682. dosr);
  683. clk_set_rate(clocks[5].clk,
  684. sample_rate * channels *
  685. bit_depth);
  686. return 0;
  687. }
  688. }
  689. }
  690. }
  691. }
  692. dev_err(component->dev,
  693. "Could not set clocks to support sample rate.\n");
  694. return -EINVAL;
  695. }
  696. static int aic32x4_hw_params(struct snd_pcm_substream *substream,
  697. struct snd_pcm_hw_params *params,
  698. struct snd_soc_dai *dai)
  699. {
  700. struct snd_soc_component *component = dai->component;
  701. struct aic32x4_priv *aic32x4 = snd_soc_component_get_drvdata(component);
  702. u8 iface1_reg = 0;
  703. u8 dacsetup_reg = 0;
  704. aic32x4_setup_clocks(component, params_rate(params),
  705. params_channels(params),
  706. params_physical_width(params));
  707. switch (params_physical_width(params)) {
  708. case 16:
  709. iface1_reg |= (AIC32X4_WORD_LEN_16BITS <<
  710. AIC32X4_IFACE1_DATALEN_SHIFT);
  711. break;
  712. case 20:
  713. iface1_reg |= (AIC32X4_WORD_LEN_20BITS <<
  714. AIC32X4_IFACE1_DATALEN_SHIFT);
  715. break;
  716. case 24:
  717. iface1_reg |= (AIC32X4_WORD_LEN_24BITS <<
  718. AIC32X4_IFACE1_DATALEN_SHIFT);
  719. break;
  720. case 32:
  721. iface1_reg |= (AIC32X4_WORD_LEN_32BITS <<
  722. AIC32X4_IFACE1_DATALEN_SHIFT);
  723. break;
  724. }
  725. snd_soc_component_update_bits(component, AIC32X4_IFACE1,
  726. AIC32X4_IFACE1_DATALEN_MASK, iface1_reg);
  727. if (params_channels(params) == 1) {
  728. dacsetup_reg = AIC32X4_RDAC2LCHN | AIC32X4_LDAC2LCHN;
  729. } else {
  730. if (aic32x4->swapdacs)
  731. dacsetup_reg = AIC32X4_RDAC2LCHN | AIC32X4_LDAC2RCHN;
  732. else
  733. dacsetup_reg = AIC32X4_LDAC2LCHN | AIC32X4_RDAC2RCHN;
  734. }
  735. snd_soc_component_update_bits(component, AIC32X4_DACSETUP,
  736. AIC32X4_DAC_CHAN_MASK, dacsetup_reg);
  737. return 0;
  738. }
  739. static int aic32x4_mute(struct snd_soc_dai *dai, int mute, int direction)
  740. {
  741. struct snd_soc_component *component = dai->component;
  742. snd_soc_component_update_bits(component, AIC32X4_DACMUTE,
  743. AIC32X4_MUTEON, mute ? AIC32X4_MUTEON : 0);
  744. return 0;
  745. }
  746. static int aic32x4_set_bias_level(struct snd_soc_component *component,
  747. enum snd_soc_bias_level level)
  748. {
  749. int ret;
  750. static struct clk_bulk_data clocks[] = {
  751. { .id = "madc" },
  752. { .id = "mdac" },
  753. { .id = "bdiv" },
  754. };
  755. ret = devm_clk_bulk_get(component->dev, ARRAY_SIZE(clocks), clocks);
  756. if (ret)
  757. return ret;
  758. switch (level) {
  759. case SND_SOC_BIAS_ON:
  760. ret = clk_bulk_prepare_enable(ARRAY_SIZE(clocks), clocks);
  761. if (ret) {
  762. dev_err(component->dev, "Failed to enable clocks\n");
  763. return ret;
  764. }
  765. break;
  766. case SND_SOC_BIAS_PREPARE:
  767. break;
  768. case SND_SOC_BIAS_STANDBY:
  769. /* Initial cold start */
  770. if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_OFF)
  771. break;
  772. clk_bulk_disable_unprepare(ARRAY_SIZE(clocks), clocks);
  773. break;
  774. case SND_SOC_BIAS_OFF:
  775. break;
  776. }
  777. return 0;
  778. }
  779. #define AIC32X4_RATES SNDRV_PCM_RATE_8000_192000
  780. #define AIC32X4_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE \
  781. | SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_3LE \
  782. | SNDRV_PCM_FMTBIT_S32_LE)
  783. static const struct snd_soc_dai_ops aic32x4_ops = {
  784. .hw_params = aic32x4_hw_params,
  785. .mute_stream = aic32x4_mute,
  786. .set_fmt = aic32x4_set_dai_fmt,
  787. .set_sysclk = aic32x4_set_dai_sysclk,
  788. .no_capture_mute = 1,
  789. };
  790. static struct snd_soc_dai_driver aic32x4_dai = {
  791. .name = "tlv320aic32x4-hifi",
  792. .playback = {
  793. .stream_name = "Playback",
  794. .channels_min = 1,
  795. .channels_max = 2,
  796. .rates = AIC32X4_RATES,
  797. .formats = AIC32X4_FORMATS,},
  798. .capture = {
  799. .stream_name = "Capture",
  800. .channels_min = 1,
  801. .channels_max = 8,
  802. .rates = AIC32X4_RATES,
  803. .formats = AIC32X4_FORMATS,},
  804. .ops = &aic32x4_ops,
  805. .symmetric_rate = 1,
  806. };
  807. static void aic32x4_setup_gpios(struct snd_soc_component *component)
  808. {
  809. struct aic32x4_priv *aic32x4 = snd_soc_component_get_drvdata(component);
  810. /* setup GPIO functions */
  811. /* MFP1 */
  812. if (aic32x4->setup->gpio_func[0] != AIC32X4_MFPX_DEFAULT_VALUE) {
  813. snd_soc_component_write(component, AIC32X4_DINCTL,
  814. aic32x4->setup->gpio_func[0]);
  815. snd_soc_add_component_controls(component, aic32x4_mfp1,
  816. ARRAY_SIZE(aic32x4_mfp1));
  817. }
  818. /* MFP2 */
  819. if (aic32x4->setup->gpio_func[1] != AIC32X4_MFPX_DEFAULT_VALUE) {
  820. snd_soc_component_write(component, AIC32X4_DOUTCTL,
  821. aic32x4->setup->gpio_func[1]);
  822. snd_soc_add_component_controls(component, aic32x4_mfp2,
  823. ARRAY_SIZE(aic32x4_mfp2));
  824. }
  825. /* MFP3 */
  826. if (aic32x4->setup->gpio_func[2] != AIC32X4_MFPX_DEFAULT_VALUE) {
  827. snd_soc_component_write(component, AIC32X4_SCLKCTL,
  828. aic32x4->setup->gpio_func[2]);
  829. snd_soc_add_component_controls(component, aic32x4_mfp3,
  830. ARRAY_SIZE(aic32x4_mfp3));
  831. }
  832. /* MFP4 */
  833. if (aic32x4->setup->gpio_func[3] != AIC32X4_MFPX_DEFAULT_VALUE) {
  834. snd_soc_component_write(component, AIC32X4_MISOCTL,
  835. aic32x4->setup->gpio_func[3]);
  836. snd_soc_add_component_controls(component, aic32x4_mfp4,
  837. ARRAY_SIZE(aic32x4_mfp4));
  838. }
  839. /* MFP5 */
  840. if (aic32x4->setup->gpio_func[4] != AIC32X4_MFPX_DEFAULT_VALUE) {
  841. snd_soc_component_write(component, AIC32X4_GPIOCTL,
  842. aic32x4->setup->gpio_func[4]);
  843. snd_soc_add_component_controls(component, aic32x4_mfp5,
  844. ARRAY_SIZE(aic32x4_mfp5));
  845. }
  846. }
  847. static int aic32x4_component_probe(struct snd_soc_component *component)
  848. {
  849. struct aic32x4_priv *aic32x4 = snd_soc_component_get_drvdata(component);
  850. u32 tmp_reg;
  851. int ret;
  852. static struct clk_bulk_data clocks[] = {
  853. { .id = "codec_clkin" },
  854. { .id = "pll" },
  855. { .id = "bdiv" },
  856. { .id = "mdac" },
  857. };
  858. ret = devm_clk_bulk_get(component->dev, ARRAY_SIZE(clocks), clocks);
  859. if (ret)
  860. return ret;
  861. if (aic32x4->setup)
  862. aic32x4_setup_gpios(component);
  863. clk_set_parent(clocks[0].clk, clocks[1].clk);
  864. clk_set_parent(clocks[2].clk, clocks[3].clk);
  865. /* Power platform configuration */
  866. if (aic32x4->power_cfg & AIC32X4_PWR_MICBIAS_2075_LDOIN) {
  867. snd_soc_component_write(component, AIC32X4_MICBIAS,
  868. AIC32X4_MICBIAS_LDOIN | AIC32X4_MICBIAS_2075V);
  869. }
  870. if (aic32x4->power_cfg & AIC32X4_PWR_AVDD_DVDD_WEAK_DISABLE)
  871. snd_soc_component_write(component, AIC32X4_PWRCFG, AIC32X4_AVDDWEAKDISABLE);
  872. tmp_reg = (aic32x4->power_cfg & AIC32X4_PWR_AIC32X4_LDO_ENABLE) ?
  873. AIC32X4_LDOCTLEN : 0;
  874. snd_soc_component_write(component, AIC32X4_LDOCTL, tmp_reg);
  875. tmp_reg = snd_soc_component_read(component, AIC32X4_CMMODE);
  876. if (aic32x4->power_cfg & AIC32X4_PWR_CMMODE_LDOIN_RANGE_18_36)
  877. tmp_reg |= AIC32X4_LDOIN_18_36;
  878. if (aic32x4->power_cfg & AIC32X4_PWR_CMMODE_HP_LDOIN_POWERED)
  879. tmp_reg |= AIC32X4_LDOIN2HP;
  880. snd_soc_component_write(component, AIC32X4_CMMODE, tmp_reg);
  881. /* Mic PGA routing */
  882. if (aic32x4->micpga_routing & AIC32X4_MICPGA_ROUTE_LMIC_IN2R_10K)
  883. snd_soc_component_write(component, AIC32X4_LMICPGANIN,
  884. AIC32X4_LMICPGANIN_IN2R_10K);
  885. else
  886. snd_soc_component_write(component, AIC32X4_LMICPGANIN,
  887. AIC32X4_LMICPGANIN_CM1L_10K);
  888. if (aic32x4->micpga_routing & AIC32X4_MICPGA_ROUTE_RMIC_IN1L_10K)
  889. snd_soc_component_write(component, AIC32X4_RMICPGANIN,
  890. AIC32X4_RMICPGANIN_IN1L_10K);
  891. else
  892. snd_soc_component_write(component, AIC32X4_RMICPGANIN,
  893. AIC32X4_RMICPGANIN_CM1R_10K);
  894. /*
  895. * Workaround: for an unknown reason, the ADC needs to be powered up
  896. * and down for the first capture to work properly. It seems related to
  897. * a HW BUG or some kind of behavior not documented in the datasheet.
  898. */
  899. tmp_reg = snd_soc_component_read(component, AIC32X4_ADCSETUP);
  900. snd_soc_component_write(component, AIC32X4_ADCSETUP, tmp_reg |
  901. AIC32X4_LADC_EN | AIC32X4_RADC_EN);
  902. snd_soc_component_write(component, AIC32X4_ADCSETUP, tmp_reg);
  903. /*
  904. * Enable the fast charging feature and ensure the needed 40ms ellapsed
  905. * before using the analog circuits.
  906. */
  907. snd_soc_component_write(component, AIC32X4_REFPOWERUP,
  908. AIC32X4_REFPOWERUP_40MS);
  909. msleep(40);
  910. return 0;
  911. }
  912. static const struct snd_soc_component_driver soc_component_dev_aic32x4 = {
  913. .probe = aic32x4_component_probe,
  914. .set_bias_level = aic32x4_set_bias_level,
  915. .controls = aic32x4_snd_controls,
  916. .num_controls = ARRAY_SIZE(aic32x4_snd_controls),
  917. .dapm_widgets = aic32x4_dapm_widgets,
  918. .num_dapm_widgets = ARRAY_SIZE(aic32x4_dapm_widgets),
  919. .dapm_routes = aic32x4_dapm_routes,
  920. .num_dapm_routes = ARRAY_SIZE(aic32x4_dapm_routes),
  921. .suspend_bias_off = 1,
  922. .idle_bias_on = 1,
  923. .use_pmdown_time = 1,
  924. .endianness = 1,
  925. };
  926. static const struct snd_kcontrol_new aic32x4_tas2505_snd_controls[] = {
  927. SOC_SINGLE_S8_TLV("PCM Playback Volume",
  928. AIC32X4_LDACVOL, -0x7f, 0x30, tlv_pcm),
  929. SOC_ENUM("DAC Playback PowerTune Switch", l_ptm_enum),
  930. SOC_SINGLE_TLV("HP Driver Gain Volume",
  931. AIC32X4_HPLGAIN, 0, 0x74, 1, tlv_tas_driver_gain),
  932. SOC_SINGLE("HP DAC Playback Switch", AIC32X4_HPLGAIN, 6, 1, 1),
  933. SOC_SINGLE_TLV("Speaker Driver Playback Volume",
  934. TAS2505_SPKVOL1, 0, 0x74, 1, tlv_tas_driver_gain),
  935. SOC_SINGLE_TLV("Speaker Amplifier Playback Volume",
  936. TAS2505_SPKVOL2, 4, 5, 0, tlv_amp_vol),
  937. SOC_SINGLE("Auto-mute Switch", AIC32X4_DACMUTE, 4, 7, 0),
  938. };
  939. static const struct snd_kcontrol_new hp_output_mixer_controls[] = {
  940. SOC_DAPM_SINGLE("DAC Switch", AIC32X4_HPLROUTE, 3, 1, 0),
  941. };
  942. static const struct snd_soc_dapm_widget aic32x4_tas2505_dapm_widgets[] = {
  943. SND_SOC_DAPM_DAC("DAC", "Playback", AIC32X4_DACSETUP, 7, 0),
  944. SND_SOC_DAPM_MIXER("HP Output Mixer", SND_SOC_NOPM, 0, 0,
  945. &hp_output_mixer_controls[0],
  946. ARRAY_SIZE(hp_output_mixer_controls)),
  947. SND_SOC_DAPM_PGA("HP Power", AIC32X4_OUTPWRCTL, 5, 0, NULL, 0),
  948. SND_SOC_DAPM_PGA("Speaker Driver", TAS2505_SPK, 1, 0, NULL, 0),
  949. SND_SOC_DAPM_OUTPUT("HP"),
  950. SND_SOC_DAPM_OUTPUT("Speaker"),
  951. };
  952. static const struct snd_soc_dapm_route aic32x4_tas2505_dapm_routes[] = {
  953. /* Left Output */
  954. {"HP Output Mixer", "DAC Switch", "DAC"},
  955. {"HP Power", NULL, "HP Output Mixer"},
  956. {"HP", NULL, "HP Power"},
  957. {"Speaker Driver", NULL, "DAC"},
  958. {"Speaker", NULL, "Speaker Driver"},
  959. };
  960. static struct snd_soc_dai_driver aic32x4_tas2505_dai = {
  961. .name = "tas2505-hifi",
  962. .playback = {
  963. .stream_name = "Playback",
  964. .channels_min = 1,
  965. .channels_max = 2,
  966. .rates = SNDRV_PCM_RATE_8000_96000,
  967. .formats = AIC32X4_FORMATS,},
  968. .ops = &aic32x4_ops,
  969. .symmetric_rate = 1,
  970. };
  971. static int aic32x4_tas2505_component_probe(struct snd_soc_component *component)
  972. {
  973. struct aic32x4_priv *aic32x4 = snd_soc_component_get_drvdata(component);
  974. u32 tmp_reg;
  975. int ret;
  976. static struct clk_bulk_data clocks[] = {
  977. { .id = "codec_clkin" },
  978. { .id = "pll" },
  979. { .id = "bdiv" },
  980. { .id = "mdac" },
  981. };
  982. ret = devm_clk_bulk_get(component->dev, ARRAY_SIZE(clocks), clocks);
  983. if (ret)
  984. return ret;
  985. if (aic32x4->setup)
  986. aic32x4_setup_gpios(component);
  987. clk_set_parent(clocks[0].clk, clocks[1].clk);
  988. clk_set_parent(clocks[2].clk, clocks[3].clk);
  989. /* Power platform configuration */
  990. if (aic32x4->power_cfg & AIC32X4_PWR_AVDD_DVDD_WEAK_DISABLE)
  991. snd_soc_component_write(component, AIC32X4_PWRCFG, AIC32X4_AVDDWEAKDISABLE);
  992. tmp_reg = (aic32x4->power_cfg & AIC32X4_PWR_AIC32X4_LDO_ENABLE) ?
  993. AIC32X4_LDOCTLEN : 0;
  994. snd_soc_component_write(component, AIC32X4_LDOCTL, tmp_reg);
  995. tmp_reg = snd_soc_component_read(component, AIC32X4_CMMODE);
  996. if (aic32x4->power_cfg & AIC32X4_PWR_CMMODE_LDOIN_RANGE_18_36)
  997. tmp_reg |= AIC32X4_LDOIN_18_36;
  998. if (aic32x4->power_cfg & AIC32X4_PWR_CMMODE_HP_LDOIN_POWERED)
  999. tmp_reg |= AIC32X4_LDOIN2HP;
  1000. snd_soc_component_write(component, AIC32X4_CMMODE, tmp_reg);
  1001. /*
  1002. * Enable the fast charging feature and ensure the needed 40ms ellapsed
  1003. * before using the analog circuits.
  1004. */
  1005. snd_soc_component_write(component, TAS2505_REFPOWERUP,
  1006. AIC32X4_REFPOWERUP_40MS);
  1007. msleep(40);
  1008. return 0;
  1009. }
  1010. static const struct snd_soc_component_driver soc_component_dev_aic32x4_tas2505 = {
  1011. .probe = aic32x4_tas2505_component_probe,
  1012. .set_bias_level = aic32x4_set_bias_level,
  1013. .controls = aic32x4_tas2505_snd_controls,
  1014. .num_controls = ARRAY_SIZE(aic32x4_tas2505_snd_controls),
  1015. .dapm_widgets = aic32x4_tas2505_dapm_widgets,
  1016. .num_dapm_widgets = ARRAY_SIZE(aic32x4_tas2505_dapm_widgets),
  1017. .dapm_routes = aic32x4_tas2505_dapm_routes,
  1018. .num_dapm_routes = ARRAY_SIZE(aic32x4_tas2505_dapm_routes),
  1019. .suspend_bias_off = 1,
  1020. .idle_bias_on = 1,
  1021. .use_pmdown_time = 1,
  1022. .endianness = 1,
  1023. };
  1024. static int aic32x4_parse_dt(struct aic32x4_priv *aic32x4,
  1025. struct device_node *np)
  1026. {
  1027. struct aic32x4_setup_data *aic32x4_setup;
  1028. int ret;
  1029. aic32x4_setup = devm_kzalloc(aic32x4->dev, sizeof(*aic32x4_setup),
  1030. GFP_KERNEL);
  1031. if (!aic32x4_setup)
  1032. return -ENOMEM;
  1033. ret = of_property_match_string(np, "clock-names", "mclk");
  1034. if (ret < 0)
  1035. return -EINVAL;
  1036. aic32x4->mclk_name = of_clk_get_parent_name(np, ret);
  1037. aic32x4->swapdacs = false;
  1038. aic32x4->micpga_routing = 0;
  1039. aic32x4->rstn_gpio = of_get_named_gpio(np, "reset-gpios", 0);
  1040. if (of_property_read_u32_array(np, "aic32x4-gpio-func",
  1041. aic32x4_setup->gpio_func, 5) >= 0)
  1042. aic32x4->setup = aic32x4_setup;
  1043. return 0;
  1044. }
  1045. static void aic32x4_disable_regulators(struct aic32x4_priv *aic32x4)
  1046. {
  1047. regulator_disable(aic32x4->supply_iov);
  1048. if (!IS_ERR(aic32x4->supply_ldo))
  1049. regulator_disable(aic32x4->supply_ldo);
  1050. if (!IS_ERR(aic32x4->supply_dv))
  1051. regulator_disable(aic32x4->supply_dv);
  1052. if (!IS_ERR(aic32x4->supply_av))
  1053. regulator_disable(aic32x4->supply_av);
  1054. }
  1055. static int aic32x4_setup_regulators(struct device *dev,
  1056. struct aic32x4_priv *aic32x4)
  1057. {
  1058. int ret = 0;
  1059. aic32x4->supply_ldo = devm_regulator_get_optional(dev, "ldoin");
  1060. aic32x4->supply_iov = devm_regulator_get(dev, "iov");
  1061. aic32x4->supply_dv = devm_regulator_get_optional(dev, "dv");
  1062. aic32x4->supply_av = devm_regulator_get_optional(dev, "av");
  1063. /* Check if the regulator requirements are fulfilled */
  1064. if (IS_ERR(aic32x4->supply_iov)) {
  1065. dev_err(dev, "Missing supply 'iov'\n");
  1066. return PTR_ERR(aic32x4->supply_iov);
  1067. }
  1068. if (IS_ERR(aic32x4->supply_ldo)) {
  1069. if (PTR_ERR(aic32x4->supply_ldo) == -EPROBE_DEFER)
  1070. return -EPROBE_DEFER;
  1071. if (IS_ERR(aic32x4->supply_dv)) {
  1072. dev_err(dev, "Missing supply 'dv' or 'ldoin'\n");
  1073. return PTR_ERR(aic32x4->supply_dv);
  1074. }
  1075. if (IS_ERR(aic32x4->supply_av)) {
  1076. dev_err(dev, "Missing supply 'av' or 'ldoin'\n");
  1077. return PTR_ERR(aic32x4->supply_av);
  1078. }
  1079. } else {
  1080. if (PTR_ERR(aic32x4->supply_dv) == -EPROBE_DEFER)
  1081. return -EPROBE_DEFER;
  1082. if (PTR_ERR(aic32x4->supply_av) == -EPROBE_DEFER)
  1083. return -EPROBE_DEFER;
  1084. }
  1085. ret = regulator_enable(aic32x4->supply_iov);
  1086. if (ret) {
  1087. dev_err(dev, "Failed to enable regulator iov\n");
  1088. return ret;
  1089. }
  1090. if (!IS_ERR(aic32x4->supply_ldo)) {
  1091. ret = regulator_enable(aic32x4->supply_ldo);
  1092. if (ret) {
  1093. dev_err(dev, "Failed to enable regulator ldo\n");
  1094. goto error_ldo;
  1095. }
  1096. }
  1097. if (!IS_ERR(aic32x4->supply_dv)) {
  1098. ret = regulator_enable(aic32x4->supply_dv);
  1099. if (ret) {
  1100. dev_err(dev, "Failed to enable regulator dv\n");
  1101. goto error_dv;
  1102. }
  1103. }
  1104. if (!IS_ERR(aic32x4->supply_av)) {
  1105. ret = regulator_enable(aic32x4->supply_av);
  1106. if (ret) {
  1107. dev_err(dev, "Failed to enable regulator av\n");
  1108. goto error_av;
  1109. }
  1110. }
  1111. if (!IS_ERR(aic32x4->supply_ldo) && IS_ERR(aic32x4->supply_av))
  1112. aic32x4->power_cfg |= AIC32X4_PWR_AIC32X4_LDO_ENABLE;
  1113. return 0;
  1114. error_av:
  1115. if (!IS_ERR(aic32x4->supply_dv))
  1116. regulator_disable(aic32x4->supply_dv);
  1117. error_dv:
  1118. if (!IS_ERR(aic32x4->supply_ldo))
  1119. regulator_disable(aic32x4->supply_ldo);
  1120. error_ldo:
  1121. regulator_disable(aic32x4->supply_iov);
  1122. return ret;
  1123. }
  1124. int aic32x4_probe(struct device *dev, struct regmap *regmap)
  1125. {
  1126. struct aic32x4_priv *aic32x4;
  1127. struct aic32x4_pdata *pdata = dev->platform_data;
  1128. struct device_node *np = dev->of_node;
  1129. int ret;
  1130. if (IS_ERR(regmap))
  1131. return PTR_ERR(regmap);
  1132. aic32x4 = devm_kzalloc(dev, sizeof(struct aic32x4_priv),
  1133. GFP_KERNEL);
  1134. if (aic32x4 == NULL)
  1135. return -ENOMEM;
  1136. aic32x4->dev = dev;
  1137. aic32x4->type = (enum aic32x4_type)dev_get_drvdata(dev);
  1138. dev_set_drvdata(dev, aic32x4);
  1139. if (pdata) {
  1140. aic32x4->power_cfg = pdata->power_cfg;
  1141. aic32x4->swapdacs = pdata->swapdacs;
  1142. aic32x4->micpga_routing = pdata->micpga_routing;
  1143. aic32x4->rstn_gpio = pdata->rstn_gpio;
  1144. aic32x4->mclk_name = "mclk";
  1145. } else if (np) {
  1146. ret = aic32x4_parse_dt(aic32x4, np);
  1147. if (ret) {
  1148. dev_err(dev, "Failed to parse DT node\n");
  1149. return ret;
  1150. }
  1151. } else {
  1152. aic32x4->power_cfg = 0;
  1153. aic32x4->swapdacs = false;
  1154. aic32x4->micpga_routing = 0;
  1155. aic32x4->rstn_gpio = -1;
  1156. aic32x4->mclk_name = "mclk";
  1157. }
  1158. if (gpio_is_valid(aic32x4->rstn_gpio)) {
  1159. ret = devm_gpio_request_one(dev, aic32x4->rstn_gpio,
  1160. GPIOF_OUT_INIT_LOW, "tlv320aic32x4 rstn");
  1161. if (ret != 0)
  1162. return ret;
  1163. }
  1164. ret = aic32x4_setup_regulators(dev, aic32x4);
  1165. if (ret) {
  1166. dev_err(dev, "Failed to setup regulators\n");
  1167. return ret;
  1168. }
  1169. if (gpio_is_valid(aic32x4->rstn_gpio)) {
  1170. ndelay(10);
  1171. gpio_set_value_cansleep(aic32x4->rstn_gpio, 1);
  1172. mdelay(1);
  1173. }
  1174. ret = regmap_write(regmap, AIC32X4_RESET, 0x01);
  1175. if (ret)
  1176. goto err_disable_regulators;
  1177. ret = aic32x4_register_clocks(dev, aic32x4->mclk_name);
  1178. if (ret)
  1179. goto err_disable_regulators;
  1180. switch (aic32x4->type) {
  1181. case AIC32X4_TYPE_TAS2505:
  1182. ret = devm_snd_soc_register_component(dev,
  1183. &soc_component_dev_aic32x4_tas2505, &aic32x4_tas2505_dai, 1);
  1184. break;
  1185. default:
  1186. ret = devm_snd_soc_register_component(dev,
  1187. &soc_component_dev_aic32x4, &aic32x4_dai, 1);
  1188. }
  1189. if (ret) {
  1190. dev_err(dev, "Failed to register component\n");
  1191. goto err_disable_regulators;
  1192. }
  1193. return 0;
  1194. err_disable_regulators:
  1195. aic32x4_disable_regulators(aic32x4);
  1196. return ret;
  1197. }
  1198. EXPORT_SYMBOL(aic32x4_probe);
  1199. void aic32x4_remove(struct device *dev)
  1200. {
  1201. struct aic32x4_priv *aic32x4 = dev_get_drvdata(dev);
  1202. aic32x4_disable_regulators(aic32x4);
  1203. }
  1204. EXPORT_SYMBOL(aic32x4_remove);
  1205. MODULE_DESCRIPTION("ASoC tlv320aic32x4 codec driver");
  1206. MODULE_AUTHOR("Javier Martin <[email protected]>");
  1207. MODULE_LICENSE("GPL");