tlv320aic3x.c 61 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880
  1. /*
  2. * ALSA SoC TLV320AIC3X codec driver
  3. *
  4. * Author: Vladimir Barinov, <vbarinov@embeddedalley.com>
  5. * Copyright: (C) 2007 MontaVista Software, Inc., <source@mvista.com>
  6. *
  7. * Based on sound/soc/codecs/wm8753.c by Liam Girdwood
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. *
  13. * Notes:
  14. * The AIC3X is a driver for a low power stereo audio
  15. * codecs aic31, aic32, aic33, aic3007.
  16. *
  17. * It supports full aic33 codec functionality.
  18. * The compatibility with aic32, aic31 and aic3007 is as follows:
  19. * aic32/aic3007 | aic31
  20. * ---------------------------------------
  21. * MONO_LOUT -> N/A | MONO_LOUT -> N/A
  22. * | IN1L -> LINE1L
  23. * | IN1R -> LINE1R
  24. * | IN2L -> LINE2L
  25. * | IN2R -> LINE2R
  26. * | MIC3L/R -> N/A
  27. * truncated internal functionality in
  28. * accordance with documentation
  29. * ---------------------------------------
  30. *
  31. * Hence the machine layer should disable unsupported inputs/outputs by
  32. * snd_soc_dapm_disable_pin(codec, "MONO_LOUT"), etc.
  33. */
  34. #include <linux/module.h>
  35. #include <linux/moduleparam.h>
  36. #include <linux/init.h>
  37. #include <linux/delay.h>
  38. #include <linux/pm.h>
  39. #include <linux/i2c.h>
  40. #include <linux/gpio.h>
  41. #include <linux/regulator/consumer.h>
  42. #include <linux/of.h>
  43. #include <linux/of_gpio.h>
  44. #include <linux/slab.h>
  45. #include <sound/core.h>
  46. #include <sound/pcm.h>
  47. #include <sound/pcm_params.h>
  48. #include <sound/soc.h>
  49. #include <sound/initval.h>
  50. #include <sound/tlv.h>
  51. #include <sound/tlv320aic3x.h>
  52. #include "tlv320aic3x.h"
  53. #define AIC3X_NUM_SUPPLIES 4
  54. static const char *aic3x_supply_names[AIC3X_NUM_SUPPLIES] = {
  55. "IOVDD", /* I/O Voltage */
  56. "DVDD", /* Digital Core Voltage */
  57. "AVDD", /* Analog DAC Voltage */
  58. "DRVDD", /* ADC Analog and Output Driver Voltage */
  59. };
  60. static LIST_HEAD(reset_list);
  61. struct aic3x_priv;
  62. struct aic3x_disable_nb {
  63. struct notifier_block nb;
  64. struct aic3x_priv *aic3x;
  65. };
  66. /* codec private data */
  67. struct aic3x_priv {
  68. struct snd_soc_codec *codec;
  69. struct regmap *regmap;
  70. struct regulator_bulk_data supplies[AIC3X_NUM_SUPPLIES];
  71. struct aic3x_disable_nb disable_nb[AIC3X_NUM_SUPPLIES];
  72. struct aic3x_setup_data *setup;
  73. unsigned int sysclk;
  74. unsigned int dai_fmt;
  75. unsigned int tdm_delay;
  76. unsigned int slot_width;
  77. struct list_head list;
  78. int master;
  79. int gpio_reset;
  80. int power;
  81. #define AIC3X_MODEL_3X 0
  82. #define AIC3X_MODEL_33 1
  83. #define AIC3X_MODEL_3007 2
  84. #define AIC3X_MODEL_3104 3
  85. u16 model;
  86. /* Selects the micbias voltage */
  87. enum aic3x_micbias_voltage micbias_vg;
  88. };
  89. static const struct reg_default aic3x_reg[] = {
  90. { 0, 0x00 }, { 1, 0x00 }, { 2, 0x00 }, { 3, 0x10 },
  91. { 4, 0x04 }, { 5, 0x00 }, { 6, 0x00 }, { 7, 0x00 },
  92. { 8, 0x00 }, { 9, 0x00 }, { 10, 0x00 }, { 11, 0x01 },
  93. { 12, 0x00 }, { 13, 0x00 }, { 14, 0x00 }, { 15, 0x80 },
  94. { 16, 0x80 }, { 17, 0xff }, { 18, 0xff }, { 19, 0x78 },
  95. { 20, 0x78 }, { 21, 0x78 }, { 22, 0x78 }, { 23, 0x78 },
  96. { 24, 0x78 }, { 25, 0x00 }, { 26, 0x00 }, { 27, 0xfe },
  97. { 28, 0x00 }, { 29, 0x00 }, { 30, 0xfe }, { 31, 0x00 },
  98. { 32, 0x18 }, { 33, 0x18 }, { 34, 0x00 }, { 35, 0x00 },
  99. { 36, 0x00 }, { 37, 0x00 }, { 38, 0x00 }, { 39, 0x00 },
  100. { 40, 0x00 }, { 41, 0x00 }, { 42, 0x00 }, { 43, 0x80 },
  101. { 44, 0x80 }, { 45, 0x00 }, { 46, 0x00 }, { 47, 0x00 },
  102. { 48, 0x00 }, { 49, 0x00 }, { 50, 0x00 }, { 51, 0x04 },
  103. { 52, 0x00 }, { 53, 0x00 }, { 54, 0x00 }, { 55, 0x00 },
  104. { 56, 0x00 }, { 57, 0x00 }, { 58, 0x04 }, { 59, 0x00 },
  105. { 60, 0x00 }, { 61, 0x00 }, { 62, 0x00 }, { 63, 0x00 },
  106. { 64, 0x00 }, { 65, 0x04 }, { 66, 0x00 }, { 67, 0x00 },
  107. { 68, 0x00 }, { 69, 0x00 }, { 70, 0x00 }, { 71, 0x00 },
  108. { 72, 0x04 }, { 73, 0x00 }, { 74, 0x00 }, { 75, 0x00 },
  109. { 76, 0x00 }, { 77, 0x00 }, { 78, 0x00 }, { 79, 0x00 },
  110. { 80, 0x00 }, { 81, 0x00 }, { 82, 0x00 }, { 83, 0x00 },
  111. { 84, 0x00 }, { 85, 0x00 }, { 86, 0x00 }, { 87, 0x00 },
  112. { 88, 0x00 }, { 89, 0x00 }, { 90, 0x00 }, { 91, 0x00 },
  113. { 92, 0x00 }, { 93, 0x00 }, { 94, 0x00 }, { 95, 0x00 },
  114. { 96, 0x00 }, { 97, 0x00 }, { 98, 0x00 }, { 99, 0x00 },
  115. { 100, 0x00 }, { 101, 0x00 }, { 102, 0x02 }, { 103, 0x00 },
  116. { 104, 0x00 }, { 105, 0x00 }, { 106, 0x00 }, { 107, 0x00 },
  117. { 108, 0x00 }, { 109, 0x00 },
  118. };
  119. static bool aic3x_volatile_reg(struct device *dev, unsigned int reg)
  120. {
  121. switch (reg) {
  122. case AIC3X_RESET:
  123. return true;
  124. default:
  125. return false;
  126. }
  127. }
  128. static const struct regmap_config aic3x_regmap = {
  129. .reg_bits = 8,
  130. .val_bits = 8,
  131. .max_register = DAC_ICC_ADJ,
  132. .reg_defaults = aic3x_reg,
  133. .num_reg_defaults = ARRAY_SIZE(aic3x_reg),
  134. .volatile_reg = aic3x_volatile_reg,
  135. .cache_type = REGCACHE_RBTREE,
  136. };
  137. #define SOC_DAPM_SINGLE_AIC3X(xname, reg, shift, mask, invert) \
  138. SOC_SINGLE_EXT(xname, reg, shift, mask, invert, \
  139. snd_soc_dapm_get_volsw, snd_soc_dapm_put_volsw_aic3x)
  140. /*
  141. * All input lines are connected when !0xf and disconnected with 0xf bit field,
  142. * so we have to use specific dapm_put call for input mixer
  143. */
  144. static int snd_soc_dapm_put_volsw_aic3x(struct snd_kcontrol *kcontrol,
  145. struct snd_ctl_elem_value *ucontrol)
  146. {
  147. struct snd_soc_codec *codec = snd_soc_dapm_kcontrol_codec(kcontrol);
  148. struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
  149. struct soc_mixer_control *mc =
  150. (struct soc_mixer_control *)kcontrol->private_value;
  151. unsigned int reg = mc->reg;
  152. unsigned int shift = mc->shift;
  153. int max = mc->max;
  154. unsigned int mask = (1 << fls(max)) - 1;
  155. unsigned int invert = mc->invert;
  156. unsigned short val;
  157. struct snd_soc_dapm_update update;
  158. int connect, change;
  159. val = (ucontrol->value.integer.value[0] & mask);
  160. mask = 0xf;
  161. if (val)
  162. val = mask;
  163. connect = !!val;
  164. if (invert)
  165. val = mask - val;
  166. mask <<= shift;
  167. val <<= shift;
  168. change = snd_soc_test_bits(codec, reg, mask, val);
  169. if (change) {
  170. update.kcontrol = kcontrol;
  171. update.reg = reg;
  172. update.mask = mask;
  173. update.val = val;
  174. snd_soc_dapm_mixer_update_power(dapm, kcontrol, connect,
  175. &update);
  176. }
  177. return change;
  178. }
  179. /*
  180. * mic bias power on/off share the same register bits with
  181. * output voltage of mic bias. when power on mic bias, we
  182. * need reclaim it to voltage value.
  183. * 0x0 = Powered off
  184. * 0x1 = MICBIAS output is powered to 2.0V,
  185. * 0x2 = MICBIAS output is powered to 2.5V
  186. * 0x3 = MICBIAS output is connected to AVDD
  187. */
  188. static int mic_bias_event(struct snd_soc_dapm_widget *w,
  189. struct snd_kcontrol *kcontrol, int event)
  190. {
  191. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  192. struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec);
  193. switch (event) {
  194. case SND_SOC_DAPM_POST_PMU:
  195. /* change mic bias voltage to user defined */
  196. snd_soc_update_bits(codec, MICBIAS_CTRL,
  197. MICBIAS_LEVEL_MASK,
  198. aic3x->micbias_vg << MICBIAS_LEVEL_SHIFT);
  199. break;
  200. case SND_SOC_DAPM_PRE_PMD:
  201. snd_soc_update_bits(codec, MICBIAS_CTRL,
  202. MICBIAS_LEVEL_MASK, 0);
  203. break;
  204. }
  205. return 0;
  206. }
  207. static const char * const aic3x_left_dac_mux[] = {
  208. "DAC_L1", "DAC_L3", "DAC_L2" };
  209. static SOC_ENUM_SINGLE_DECL(aic3x_left_dac_enum, DAC_LINE_MUX, 6,
  210. aic3x_left_dac_mux);
  211. static const char * const aic3x_right_dac_mux[] = {
  212. "DAC_R1", "DAC_R3", "DAC_R2" };
  213. static SOC_ENUM_SINGLE_DECL(aic3x_right_dac_enum, DAC_LINE_MUX, 4,
  214. aic3x_right_dac_mux);
  215. static const char * const aic3x_left_hpcom_mux[] = {
  216. "differential of HPLOUT", "constant VCM", "single-ended" };
  217. static SOC_ENUM_SINGLE_DECL(aic3x_left_hpcom_enum, HPLCOM_CFG, 4,
  218. aic3x_left_hpcom_mux);
  219. static const char * const aic3x_right_hpcom_mux[] = {
  220. "differential of HPROUT", "constant VCM", "single-ended",
  221. "differential of HPLCOM", "external feedback" };
  222. static SOC_ENUM_SINGLE_DECL(aic3x_right_hpcom_enum, HPRCOM_CFG, 3,
  223. aic3x_right_hpcom_mux);
  224. static const char * const aic3x_linein_mode_mux[] = {
  225. "single-ended", "differential" };
  226. static SOC_ENUM_SINGLE_DECL(aic3x_line1l_2_l_enum, LINE1L_2_LADC_CTRL, 7,
  227. aic3x_linein_mode_mux);
  228. static SOC_ENUM_SINGLE_DECL(aic3x_line1l_2_r_enum, LINE1L_2_RADC_CTRL, 7,
  229. aic3x_linein_mode_mux);
  230. static SOC_ENUM_SINGLE_DECL(aic3x_line1r_2_l_enum, LINE1R_2_LADC_CTRL, 7,
  231. aic3x_linein_mode_mux);
  232. static SOC_ENUM_SINGLE_DECL(aic3x_line1r_2_r_enum, LINE1R_2_RADC_CTRL, 7,
  233. aic3x_linein_mode_mux);
  234. static SOC_ENUM_SINGLE_DECL(aic3x_line2l_2_ldac_enum, LINE2L_2_LADC_CTRL, 7,
  235. aic3x_linein_mode_mux);
  236. static SOC_ENUM_SINGLE_DECL(aic3x_line2r_2_rdac_enum, LINE2R_2_RADC_CTRL, 7,
  237. aic3x_linein_mode_mux);
  238. static const char * const aic3x_adc_hpf[] = {
  239. "Disabled", "0.0045xFs", "0.0125xFs", "0.025xFs" };
  240. static SOC_ENUM_DOUBLE_DECL(aic3x_adc_hpf_enum, AIC3X_CODEC_DFILT_CTRL, 6, 4,
  241. aic3x_adc_hpf);
  242. static const char * const aic3x_agc_level[] = {
  243. "-5.5dB", "-8dB", "-10dB", "-12dB",
  244. "-14dB", "-17dB", "-20dB", "-24dB" };
  245. static SOC_ENUM_SINGLE_DECL(aic3x_lagc_level_enum, LAGC_CTRL_A, 4,
  246. aic3x_agc_level);
  247. static SOC_ENUM_SINGLE_DECL(aic3x_ragc_level_enum, RAGC_CTRL_A, 4,
  248. aic3x_agc_level);
  249. static const char * const aic3x_agc_attack[] = {
  250. "8ms", "11ms", "16ms", "20ms" };
  251. static SOC_ENUM_SINGLE_DECL(aic3x_lagc_attack_enum, LAGC_CTRL_A, 2,
  252. aic3x_agc_attack);
  253. static SOC_ENUM_SINGLE_DECL(aic3x_ragc_attack_enum, RAGC_CTRL_A, 2,
  254. aic3x_agc_attack);
  255. static const char * const aic3x_agc_decay[] = {
  256. "100ms", "200ms", "400ms", "500ms" };
  257. static SOC_ENUM_SINGLE_DECL(aic3x_lagc_decay_enum, LAGC_CTRL_A, 0,
  258. aic3x_agc_decay);
  259. static SOC_ENUM_SINGLE_DECL(aic3x_ragc_decay_enum, RAGC_CTRL_A, 0,
  260. aic3x_agc_decay);
  261. static const char * const aic3x_poweron_time[] = {
  262. "0us", "10us", "100us", "1ms", "10ms", "50ms",
  263. "100ms", "200ms", "400ms", "800ms", "2s", "4s" };
  264. static SOC_ENUM_SINGLE_DECL(aic3x_poweron_time_enum, HPOUT_POP_REDUCTION, 4,
  265. aic3x_poweron_time);
  266. static const char * const aic3x_rampup_step[] = { "0ms", "1ms", "2ms", "4ms" };
  267. static SOC_ENUM_SINGLE_DECL(aic3x_rampup_step_enum, HPOUT_POP_REDUCTION, 2,
  268. aic3x_rampup_step);
  269. /*
  270. * DAC digital volumes. From -63.5 to 0 dB in 0.5 dB steps
  271. */
  272. static DECLARE_TLV_DB_SCALE(dac_tlv, -6350, 50, 0);
  273. /* ADC PGA gain volumes. From 0 to 59.5 dB in 0.5 dB steps */
  274. static DECLARE_TLV_DB_SCALE(adc_tlv, 0, 50, 0);
  275. /*
  276. * Output stage volumes. From -78.3 to 0 dB. Muted below -78.3 dB.
  277. * Step size is approximately 0.5 dB over most of the scale but increasing
  278. * near the very low levels.
  279. * Define dB scale so that it is mostly correct for range about -55 to 0 dB
  280. * but having increasing dB difference below that (and where it doesn't count
  281. * so much). This setting shows -50 dB (actual is -50.3 dB) for register
  282. * value 100 and -58.5 dB (actual is -78.3 dB) for register value 117.
  283. */
  284. static DECLARE_TLV_DB_SCALE(output_stage_tlv, -5900, 50, 1);
  285. static const struct snd_kcontrol_new aic3x_snd_controls[] = {
  286. /* Output */
  287. SOC_DOUBLE_R_TLV("PCM Playback Volume",
  288. LDAC_VOL, RDAC_VOL, 0, 0x7f, 1, dac_tlv),
  289. /*
  290. * Output controls that map to output mixer switches. Note these are
  291. * only for swapped L-to-R and R-to-L routes. See below stereo controls
  292. * for direct L-to-L and R-to-R routes.
  293. */
  294. SOC_SINGLE_TLV("Left Line Mixer PGAR Bypass Volume",
  295. PGAR_2_LLOPM_VOL, 0, 118, 1, output_stage_tlv),
  296. SOC_SINGLE_TLV("Left Line Mixer DACR1 Playback Volume",
  297. DACR1_2_LLOPM_VOL, 0, 118, 1, output_stage_tlv),
  298. SOC_SINGLE_TLV("Right Line Mixer PGAL Bypass Volume",
  299. PGAL_2_RLOPM_VOL, 0, 118, 1, output_stage_tlv),
  300. SOC_SINGLE_TLV("Right Line Mixer DACL1 Playback Volume",
  301. DACL1_2_RLOPM_VOL, 0, 118, 1, output_stage_tlv),
  302. SOC_SINGLE_TLV("Left HP Mixer PGAR Bypass Volume",
  303. PGAR_2_HPLOUT_VOL, 0, 118, 1, output_stage_tlv),
  304. SOC_SINGLE_TLV("Left HP Mixer DACR1 Playback Volume",
  305. DACR1_2_HPLOUT_VOL, 0, 118, 1, output_stage_tlv),
  306. SOC_SINGLE_TLV("Right HP Mixer PGAL Bypass Volume",
  307. PGAL_2_HPROUT_VOL, 0, 118, 1, output_stage_tlv),
  308. SOC_SINGLE_TLV("Right HP Mixer DACL1 Playback Volume",
  309. DACL1_2_HPROUT_VOL, 0, 118, 1, output_stage_tlv),
  310. SOC_SINGLE_TLV("Left HPCOM Mixer PGAR Bypass Volume",
  311. PGAR_2_HPLCOM_VOL, 0, 118, 1, output_stage_tlv),
  312. SOC_SINGLE_TLV("Left HPCOM Mixer DACR1 Playback Volume",
  313. DACR1_2_HPLCOM_VOL, 0, 118, 1, output_stage_tlv),
  314. SOC_SINGLE_TLV("Right HPCOM Mixer PGAL Bypass Volume",
  315. PGAL_2_HPRCOM_VOL, 0, 118, 1, output_stage_tlv),
  316. SOC_SINGLE_TLV("Right HPCOM Mixer DACL1 Playback Volume",
  317. DACL1_2_HPRCOM_VOL, 0, 118, 1, output_stage_tlv),
  318. /* Stereo output controls for direct L-to-L and R-to-R routes */
  319. SOC_DOUBLE_R_TLV("Line PGA Bypass Volume",
  320. PGAL_2_LLOPM_VOL, PGAR_2_RLOPM_VOL,
  321. 0, 118, 1, output_stage_tlv),
  322. SOC_DOUBLE_R_TLV("Line DAC Playback Volume",
  323. DACL1_2_LLOPM_VOL, DACR1_2_RLOPM_VOL,
  324. 0, 118, 1, output_stage_tlv),
  325. SOC_DOUBLE_R_TLV("HP PGA Bypass Volume",
  326. PGAL_2_HPLOUT_VOL, PGAR_2_HPROUT_VOL,
  327. 0, 118, 1, output_stage_tlv),
  328. SOC_DOUBLE_R_TLV("HP DAC Playback Volume",
  329. DACL1_2_HPLOUT_VOL, DACR1_2_HPROUT_VOL,
  330. 0, 118, 1, output_stage_tlv),
  331. SOC_DOUBLE_R_TLV("HPCOM PGA Bypass Volume",
  332. PGAL_2_HPLCOM_VOL, PGAR_2_HPRCOM_VOL,
  333. 0, 118, 1, output_stage_tlv),
  334. SOC_DOUBLE_R_TLV("HPCOM DAC Playback Volume",
  335. DACL1_2_HPLCOM_VOL, DACR1_2_HPRCOM_VOL,
  336. 0, 118, 1, output_stage_tlv),
  337. /* Output pin mute controls */
  338. SOC_DOUBLE_R("Line Playback Switch", LLOPM_CTRL, RLOPM_CTRL, 3,
  339. 0x01, 0),
  340. SOC_DOUBLE_R("HP Playback Switch", HPLOUT_CTRL, HPROUT_CTRL, 3,
  341. 0x01, 0),
  342. SOC_DOUBLE_R("HPCOM Playback Switch", HPLCOM_CTRL, HPRCOM_CTRL, 3,
  343. 0x01, 0),
  344. /*
  345. * Note: enable Automatic input Gain Controller with care. It can
  346. * adjust PGA to max value when ADC is on and will never go back.
  347. */
  348. SOC_DOUBLE_R("AGC Switch", LAGC_CTRL_A, RAGC_CTRL_A, 7, 0x01, 0),
  349. SOC_ENUM("Left AGC Target level", aic3x_lagc_level_enum),
  350. SOC_ENUM("Right AGC Target level", aic3x_ragc_level_enum),
  351. SOC_ENUM("Left AGC Attack time", aic3x_lagc_attack_enum),
  352. SOC_ENUM("Right AGC Attack time", aic3x_ragc_attack_enum),
  353. SOC_ENUM("Left AGC Decay time", aic3x_lagc_decay_enum),
  354. SOC_ENUM("Right AGC Decay time", aic3x_ragc_decay_enum),
  355. /* De-emphasis */
  356. SOC_DOUBLE("De-emphasis Switch", AIC3X_CODEC_DFILT_CTRL, 2, 0, 0x01, 0),
  357. /* Input */
  358. SOC_DOUBLE_R_TLV("PGA Capture Volume", LADC_VOL, RADC_VOL,
  359. 0, 119, 0, adc_tlv),
  360. SOC_DOUBLE_R("PGA Capture Switch", LADC_VOL, RADC_VOL, 7, 0x01, 1),
  361. SOC_ENUM("ADC HPF Cut-off", aic3x_adc_hpf_enum),
  362. /* Pop reduction */
  363. SOC_ENUM("Output Driver Power-On time", aic3x_poweron_time_enum),
  364. SOC_ENUM("Output Driver Ramp-up step", aic3x_rampup_step_enum),
  365. };
  366. /* For other than tlv320aic3104 */
  367. static const struct snd_kcontrol_new aic3x_extra_snd_controls[] = {
  368. /*
  369. * Output controls that map to output mixer switches. Note these are
  370. * only for swapped L-to-R and R-to-L routes. See below stereo controls
  371. * for direct L-to-L and R-to-R routes.
  372. */
  373. SOC_SINGLE_TLV("Left Line Mixer Line2R Bypass Volume",
  374. LINE2R_2_LLOPM_VOL, 0, 118, 1, output_stage_tlv),
  375. SOC_SINGLE_TLV("Right Line Mixer Line2L Bypass Volume",
  376. LINE2L_2_RLOPM_VOL, 0, 118, 1, output_stage_tlv),
  377. SOC_SINGLE_TLV("Left HP Mixer Line2R Bypass Volume",
  378. LINE2R_2_HPLOUT_VOL, 0, 118, 1, output_stage_tlv),
  379. SOC_SINGLE_TLV("Right HP Mixer Line2L Bypass Volume",
  380. LINE2L_2_HPROUT_VOL, 0, 118, 1, output_stage_tlv),
  381. SOC_SINGLE_TLV("Left HPCOM Mixer Line2R Bypass Volume",
  382. LINE2R_2_HPLCOM_VOL, 0, 118, 1, output_stage_tlv),
  383. SOC_SINGLE_TLV("Right HPCOM Mixer Line2L Bypass Volume",
  384. LINE2L_2_HPRCOM_VOL, 0, 118, 1, output_stage_tlv),
  385. /* Stereo output controls for direct L-to-L and R-to-R routes */
  386. SOC_DOUBLE_R_TLV("Line Line2 Bypass Volume",
  387. LINE2L_2_LLOPM_VOL, LINE2R_2_RLOPM_VOL,
  388. 0, 118, 1, output_stage_tlv),
  389. SOC_DOUBLE_R_TLV("HP Line2 Bypass Volume",
  390. LINE2L_2_HPLOUT_VOL, LINE2R_2_HPROUT_VOL,
  391. 0, 118, 1, output_stage_tlv),
  392. SOC_DOUBLE_R_TLV("HPCOM Line2 Bypass Volume",
  393. LINE2L_2_HPLCOM_VOL, LINE2R_2_HPRCOM_VOL,
  394. 0, 118, 1, output_stage_tlv),
  395. };
  396. static const struct snd_kcontrol_new aic3x_mono_controls[] = {
  397. SOC_DOUBLE_R_TLV("Mono Line2 Bypass Volume",
  398. LINE2L_2_MONOLOPM_VOL, LINE2R_2_MONOLOPM_VOL,
  399. 0, 118, 1, output_stage_tlv),
  400. SOC_DOUBLE_R_TLV("Mono PGA Bypass Volume",
  401. PGAL_2_MONOLOPM_VOL, PGAR_2_MONOLOPM_VOL,
  402. 0, 118, 1, output_stage_tlv),
  403. SOC_DOUBLE_R_TLV("Mono DAC Playback Volume",
  404. DACL1_2_MONOLOPM_VOL, DACR1_2_MONOLOPM_VOL,
  405. 0, 118, 1, output_stage_tlv),
  406. SOC_SINGLE("Mono Playback Switch", MONOLOPM_CTRL, 3, 0x01, 0),
  407. };
  408. /*
  409. * Class-D amplifier gain. From 0 to 18 dB in 6 dB steps
  410. */
  411. static DECLARE_TLV_DB_SCALE(classd_amp_tlv, 0, 600, 0);
  412. static const struct snd_kcontrol_new aic3x_classd_amp_gain_ctrl =
  413. SOC_DOUBLE_TLV("Class-D Playback Volume", CLASSD_CTRL, 6, 4, 3, 0, classd_amp_tlv);
  414. /* Left DAC Mux */
  415. static const struct snd_kcontrol_new aic3x_left_dac_mux_controls =
  416. SOC_DAPM_ENUM("Route", aic3x_left_dac_enum);
  417. /* Right DAC Mux */
  418. static const struct snd_kcontrol_new aic3x_right_dac_mux_controls =
  419. SOC_DAPM_ENUM("Route", aic3x_right_dac_enum);
  420. /* Left HPCOM Mux */
  421. static const struct snd_kcontrol_new aic3x_left_hpcom_mux_controls =
  422. SOC_DAPM_ENUM("Route", aic3x_left_hpcom_enum);
  423. /* Right HPCOM Mux */
  424. static const struct snd_kcontrol_new aic3x_right_hpcom_mux_controls =
  425. SOC_DAPM_ENUM("Route", aic3x_right_hpcom_enum);
  426. /* Left Line Mixer */
  427. static const struct snd_kcontrol_new aic3x_left_line_mixer_controls[] = {
  428. SOC_DAPM_SINGLE("PGAL Bypass Switch", PGAL_2_LLOPM_VOL, 7, 1, 0),
  429. SOC_DAPM_SINGLE("DACL1 Switch", DACL1_2_LLOPM_VOL, 7, 1, 0),
  430. SOC_DAPM_SINGLE("PGAR Bypass Switch", PGAR_2_LLOPM_VOL, 7, 1, 0),
  431. SOC_DAPM_SINGLE("DACR1 Switch", DACR1_2_LLOPM_VOL, 7, 1, 0),
  432. /* Not on tlv320aic3104 */
  433. SOC_DAPM_SINGLE("Line2L Bypass Switch", LINE2L_2_LLOPM_VOL, 7, 1, 0),
  434. SOC_DAPM_SINGLE("Line2R Bypass Switch", LINE2R_2_LLOPM_VOL, 7, 1, 0),
  435. };
  436. /* Right Line Mixer */
  437. static const struct snd_kcontrol_new aic3x_right_line_mixer_controls[] = {
  438. SOC_DAPM_SINGLE("PGAL Bypass Switch", PGAL_2_RLOPM_VOL, 7, 1, 0),
  439. SOC_DAPM_SINGLE("DACL1 Switch", DACL1_2_RLOPM_VOL, 7, 1, 0),
  440. SOC_DAPM_SINGLE("PGAR Bypass Switch", PGAR_2_RLOPM_VOL, 7, 1, 0),
  441. SOC_DAPM_SINGLE("DACR1 Switch", DACR1_2_RLOPM_VOL, 7, 1, 0),
  442. /* Not on tlv320aic3104 */
  443. SOC_DAPM_SINGLE("Line2L Bypass Switch", LINE2L_2_RLOPM_VOL, 7, 1, 0),
  444. SOC_DAPM_SINGLE("Line2R Bypass Switch", LINE2R_2_RLOPM_VOL, 7, 1, 0),
  445. };
  446. /* Mono Mixer */
  447. static const struct snd_kcontrol_new aic3x_mono_mixer_controls[] = {
  448. SOC_DAPM_SINGLE("Line2L Bypass Switch", LINE2L_2_MONOLOPM_VOL, 7, 1, 0),
  449. SOC_DAPM_SINGLE("PGAL Bypass Switch", PGAL_2_MONOLOPM_VOL, 7, 1, 0),
  450. SOC_DAPM_SINGLE("DACL1 Switch", DACL1_2_MONOLOPM_VOL, 7, 1, 0),
  451. SOC_DAPM_SINGLE("Line2R Bypass Switch", LINE2R_2_MONOLOPM_VOL, 7, 1, 0),
  452. SOC_DAPM_SINGLE("PGAR Bypass Switch", PGAR_2_MONOLOPM_VOL, 7, 1, 0),
  453. SOC_DAPM_SINGLE("DACR1 Switch", DACR1_2_MONOLOPM_VOL, 7, 1, 0),
  454. };
  455. /* Left HP Mixer */
  456. static const struct snd_kcontrol_new aic3x_left_hp_mixer_controls[] = {
  457. SOC_DAPM_SINGLE("PGAL Bypass Switch", PGAL_2_HPLOUT_VOL, 7, 1, 0),
  458. SOC_DAPM_SINGLE("DACL1 Switch", DACL1_2_HPLOUT_VOL, 7, 1, 0),
  459. SOC_DAPM_SINGLE("PGAR Bypass Switch", PGAR_2_HPLOUT_VOL, 7, 1, 0),
  460. SOC_DAPM_SINGLE("DACR1 Switch", DACR1_2_HPLOUT_VOL, 7, 1, 0),
  461. /* Not on tlv320aic3104 */
  462. SOC_DAPM_SINGLE("Line2L Bypass Switch", LINE2L_2_HPLOUT_VOL, 7, 1, 0),
  463. SOC_DAPM_SINGLE("Line2R Bypass Switch", LINE2R_2_HPLOUT_VOL, 7, 1, 0),
  464. };
  465. /* Right HP Mixer */
  466. static const struct snd_kcontrol_new aic3x_right_hp_mixer_controls[] = {
  467. SOC_DAPM_SINGLE("PGAL Bypass Switch", PGAL_2_HPROUT_VOL, 7, 1, 0),
  468. SOC_DAPM_SINGLE("DACL1 Switch", DACL1_2_HPROUT_VOL, 7, 1, 0),
  469. SOC_DAPM_SINGLE("PGAR Bypass Switch", PGAR_2_HPROUT_VOL, 7, 1, 0),
  470. SOC_DAPM_SINGLE("DACR1 Switch", DACR1_2_HPROUT_VOL, 7, 1, 0),
  471. /* Not on tlv320aic3104 */
  472. SOC_DAPM_SINGLE("Line2L Bypass Switch", LINE2L_2_HPROUT_VOL, 7, 1, 0),
  473. SOC_DAPM_SINGLE("Line2R Bypass Switch", LINE2R_2_HPROUT_VOL, 7, 1, 0),
  474. };
  475. /* Left HPCOM Mixer */
  476. static const struct snd_kcontrol_new aic3x_left_hpcom_mixer_controls[] = {
  477. SOC_DAPM_SINGLE("PGAL Bypass Switch", PGAL_2_HPLCOM_VOL, 7, 1, 0),
  478. SOC_DAPM_SINGLE("DACL1 Switch", DACL1_2_HPLCOM_VOL, 7, 1, 0),
  479. SOC_DAPM_SINGLE("PGAR Bypass Switch", PGAR_2_HPLCOM_VOL, 7, 1, 0),
  480. SOC_DAPM_SINGLE("DACR1 Switch", DACR1_2_HPLCOM_VOL, 7, 1, 0),
  481. /* Not on tlv320aic3104 */
  482. SOC_DAPM_SINGLE("Line2L Bypass Switch", LINE2L_2_HPLCOM_VOL, 7, 1, 0),
  483. SOC_DAPM_SINGLE("Line2R Bypass Switch", LINE2R_2_HPLCOM_VOL, 7, 1, 0),
  484. };
  485. /* Right HPCOM Mixer */
  486. static const struct snd_kcontrol_new aic3x_right_hpcom_mixer_controls[] = {
  487. SOC_DAPM_SINGLE("PGAL Bypass Switch", PGAL_2_HPRCOM_VOL, 7, 1, 0),
  488. SOC_DAPM_SINGLE("DACL1 Switch", DACL1_2_HPRCOM_VOL, 7, 1, 0),
  489. SOC_DAPM_SINGLE("PGAR Bypass Switch", PGAR_2_HPRCOM_VOL, 7, 1, 0),
  490. SOC_DAPM_SINGLE("DACR1 Switch", DACR1_2_HPRCOM_VOL, 7, 1, 0),
  491. /* Not on tlv320aic3104 */
  492. SOC_DAPM_SINGLE("Line2L Bypass Switch", LINE2L_2_HPRCOM_VOL, 7, 1, 0),
  493. SOC_DAPM_SINGLE("Line2R Bypass Switch", LINE2R_2_HPRCOM_VOL, 7, 1, 0),
  494. };
  495. /* Left PGA Mixer */
  496. static const struct snd_kcontrol_new aic3x_left_pga_mixer_controls[] = {
  497. SOC_DAPM_SINGLE_AIC3X("Line1L Switch", LINE1L_2_LADC_CTRL, 3, 1, 1),
  498. SOC_DAPM_SINGLE_AIC3X("Line1R Switch", LINE1R_2_LADC_CTRL, 3, 1, 1),
  499. SOC_DAPM_SINGLE_AIC3X("Line2L Switch", LINE2L_2_LADC_CTRL, 3, 1, 1),
  500. SOC_DAPM_SINGLE_AIC3X("Mic3L Switch", MIC3LR_2_LADC_CTRL, 4, 1, 1),
  501. SOC_DAPM_SINGLE_AIC3X("Mic3R Switch", MIC3LR_2_LADC_CTRL, 0, 1, 1),
  502. };
  503. /* Right PGA Mixer */
  504. static const struct snd_kcontrol_new aic3x_right_pga_mixer_controls[] = {
  505. SOC_DAPM_SINGLE_AIC3X("Line1R Switch", LINE1R_2_RADC_CTRL, 3, 1, 1),
  506. SOC_DAPM_SINGLE_AIC3X("Line1L Switch", LINE1L_2_RADC_CTRL, 3, 1, 1),
  507. SOC_DAPM_SINGLE_AIC3X("Line2R Switch", LINE2R_2_RADC_CTRL, 3, 1, 1),
  508. SOC_DAPM_SINGLE_AIC3X("Mic3L Switch", MIC3LR_2_RADC_CTRL, 4, 1, 1),
  509. SOC_DAPM_SINGLE_AIC3X("Mic3R Switch", MIC3LR_2_RADC_CTRL, 0, 1, 1),
  510. };
  511. /* Left PGA Mixer for tlv320aic3104 */
  512. static const struct snd_kcontrol_new aic3104_left_pga_mixer_controls[] = {
  513. SOC_DAPM_SINGLE_AIC3X("Line1L Switch", LINE1L_2_LADC_CTRL, 3, 1, 1),
  514. SOC_DAPM_SINGLE_AIC3X("Line1R Switch", LINE1R_2_LADC_CTRL, 3, 1, 1),
  515. SOC_DAPM_SINGLE_AIC3X("Mic2L Switch", MIC3LR_2_LADC_CTRL, 4, 1, 1),
  516. SOC_DAPM_SINGLE_AIC3X("Mic2R Switch", MIC3LR_2_LADC_CTRL, 0, 1, 1),
  517. };
  518. /* Right PGA Mixer for tlv320aic3104 */
  519. static const struct snd_kcontrol_new aic3104_right_pga_mixer_controls[] = {
  520. SOC_DAPM_SINGLE_AIC3X("Line1R Switch", LINE1R_2_RADC_CTRL, 3, 1, 1),
  521. SOC_DAPM_SINGLE_AIC3X("Line1L Switch", LINE1L_2_RADC_CTRL, 3, 1, 1),
  522. SOC_DAPM_SINGLE_AIC3X("Mic2L Switch", MIC3LR_2_RADC_CTRL, 4, 1, 1),
  523. SOC_DAPM_SINGLE_AIC3X("Mic2R Switch", MIC3LR_2_RADC_CTRL, 0, 1, 1),
  524. };
  525. /* Left Line1 Mux */
  526. static const struct snd_kcontrol_new aic3x_left_line1l_mux_controls =
  527. SOC_DAPM_ENUM("Route", aic3x_line1l_2_l_enum);
  528. static const struct snd_kcontrol_new aic3x_right_line1l_mux_controls =
  529. SOC_DAPM_ENUM("Route", aic3x_line1l_2_r_enum);
  530. /* Right Line1 Mux */
  531. static const struct snd_kcontrol_new aic3x_right_line1r_mux_controls =
  532. SOC_DAPM_ENUM("Route", aic3x_line1r_2_r_enum);
  533. static const struct snd_kcontrol_new aic3x_left_line1r_mux_controls =
  534. SOC_DAPM_ENUM("Route", aic3x_line1r_2_l_enum);
  535. /* Left Line2 Mux */
  536. static const struct snd_kcontrol_new aic3x_left_line2_mux_controls =
  537. SOC_DAPM_ENUM("Route", aic3x_line2l_2_ldac_enum);
  538. /* Right Line2 Mux */
  539. static const struct snd_kcontrol_new aic3x_right_line2_mux_controls =
  540. SOC_DAPM_ENUM("Route", aic3x_line2r_2_rdac_enum);
  541. static const struct snd_soc_dapm_widget aic3x_dapm_widgets[] = {
  542. /* Left DAC to Left Outputs */
  543. SND_SOC_DAPM_DAC("Left DAC", "Left Playback", DAC_PWR, 7, 0),
  544. SND_SOC_DAPM_MUX("Left DAC Mux", SND_SOC_NOPM, 0, 0,
  545. &aic3x_left_dac_mux_controls),
  546. SND_SOC_DAPM_MUX("Left HPCOM Mux", SND_SOC_NOPM, 0, 0,
  547. &aic3x_left_hpcom_mux_controls),
  548. SND_SOC_DAPM_PGA("Left Line Out", LLOPM_CTRL, 0, 0, NULL, 0),
  549. SND_SOC_DAPM_PGA("Left HP Out", HPLOUT_CTRL, 0, 0, NULL, 0),
  550. SND_SOC_DAPM_PGA("Left HP Com", HPLCOM_CTRL, 0, 0, NULL, 0),
  551. /* Right DAC to Right Outputs */
  552. SND_SOC_DAPM_DAC("Right DAC", "Right Playback", DAC_PWR, 6, 0),
  553. SND_SOC_DAPM_MUX("Right DAC Mux", SND_SOC_NOPM, 0, 0,
  554. &aic3x_right_dac_mux_controls),
  555. SND_SOC_DAPM_MUX("Right HPCOM Mux", SND_SOC_NOPM, 0, 0,
  556. &aic3x_right_hpcom_mux_controls),
  557. SND_SOC_DAPM_PGA("Right Line Out", RLOPM_CTRL, 0, 0, NULL, 0),
  558. SND_SOC_DAPM_PGA("Right HP Out", HPROUT_CTRL, 0, 0, NULL, 0),
  559. SND_SOC_DAPM_PGA("Right HP Com", HPRCOM_CTRL, 0, 0, NULL, 0),
  560. /* Inputs to Left ADC */
  561. SND_SOC_DAPM_ADC("Left ADC", "Left Capture", LINE1L_2_LADC_CTRL, 2, 0),
  562. SND_SOC_DAPM_MUX("Left Line1L Mux", SND_SOC_NOPM, 0, 0,
  563. &aic3x_left_line1l_mux_controls),
  564. SND_SOC_DAPM_MUX("Left Line1R Mux", SND_SOC_NOPM, 0, 0,
  565. &aic3x_left_line1r_mux_controls),
  566. /* Inputs to Right ADC */
  567. SND_SOC_DAPM_ADC("Right ADC", "Right Capture",
  568. LINE1R_2_RADC_CTRL, 2, 0),
  569. SND_SOC_DAPM_MUX("Right Line1L Mux", SND_SOC_NOPM, 0, 0,
  570. &aic3x_right_line1l_mux_controls),
  571. SND_SOC_DAPM_MUX("Right Line1R Mux", SND_SOC_NOPM, 0, 0,
  572. &aic3x_right_line1r_mux_controls),
  573. /* Mic Bias */
  574. SND_SOC_DAPM_SUPPLY("Mic Bias", MICBIAS_CTRL, 6, 0,
  575. mic_bias_event,
  576. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
  577. SND_SOC_DAPM_OUTPUT("LLOUT"),
  578. SND_SOC_DAPM_OUTPUT("RLOUT"),
  579. SND_SOC_DAPM_OUTPUT("HPLOUT"),
  580. SND_SOC_DAPM_OUTPUT("HPROUT"),
  581. SND_SOC_DAPM_OUTPUT("HPLCOM"),
  582. SND_SOC_DAPM_OUTPUT("HPRCOM"),
  583. SND_SOC_DAPM_INPUT("LINE1L"),
  584. SND_SOC_DAPM_INPUT("LINE1R"),
  585. /*
  586. * Virtual output pin to detection block inside codec. This can be
  587. * used to keep codec bias on if gpio or detection features are needed.
  588. * Force pin on or construct a path with an input jack and mic bias
  589. * widgets.
  590. */
  591. SND_SOC_DAPM_OUTPUT("Detection"),
  592. };
  593. /* For other than tlv320aic3104 */
  594. static const struct snd_soc_dapm_widget aic3x_extra_dapm_widgets[] = {
  595. /* Inputs to Left ADC */
  596. SND_SOC_DAPM_MIXER("Left PGA Mixer", SND_SOC_NOPM, 0, 0,
  597. &aic3x_left_pga_mixer_controls[0],
  598. ARRAY_SIZE(aic3x_left_pga_mixer_controls)),
  599. SND_SOC_DAPM_MUX("Left Line2L Mux", SND_SOC_NOPM, 0, 0,
  600. &aic3x_left_line2_mux_controls),
  601. /* Inputs to Right ADC */
  602. SND_SOC_DAPM_MIXER("Right PGA Mixer", SND_SOC_NOPM, 0, 0,
  603. &aic3x_right_pga_mixer_controls[0],
  604. ARRAY_SIZE(aic3x_right_pga_mixer_controls)),
  605. SND_SOC_DAPM_MUX("Right Line2R Mux", SND_SOC_NOPM, 0, 0,
  606. &aic3x_right_line2_mux_controls),
  607. /*
  608. * Not a real mic bias widget but similar function. This is for dynamic
  609. * control of GPIO1 digital mic modulator clock output function when
  610. * using digital mic.
  611. */
  612. SND_SOC_DAPM_REG(snd_soc_dapm_micbias, "GPIO1 dmic modclk",
  613. AIC3X_GPIO1_REG, 4, 0xf,
  614. AIC3X_GPIO1_FUNC_DIGITAL_MIC_MODCLK,
  615. AIC3X_GPIO1_FUNC_DISABLED),
  616. /*
  617. * Also similar function like mic bias. Selects digital mic with
  618. * configurable oversampling rate instead of ADC converter.
  619. */
  620. SND_SOC_DAPM_REG(snd_soc_dapm_micbias, "DMic Rate 128",
  621. AIC3X_ASD_INTF_CTRLA, 0, 3, 1, 0),
  622. SND_SOC_DAPM_REG(snd_soc_dapm_micbias, "DMic Rate 64",
  623. AIC3X_ASD_INTF_CTRLA, 0, 3, 2, 0),
  624. SND_SOC_DAPM_REG(snd_soc_dapm_micbias, "DMic Rate 32",
  625. AIC3X_ASD_INTF_CTRLA, 0, 3, 3, 0),
  626. /* Output mixers */
  627. SND_SOC_DAPM_MIXER("Left Line Mixer", SND_SOC_NOPM, 0, 0,
  628. &aic3x_left_line_mixer_controls[0],
  629. ARRAY_SIZE(aic3x_left_line_mixer_controls)),
  630. SND_SOC_DAPM_MIXER("Right Line Mixer", SND_SOC_NOPM, 0, 0,
  631. &aic3x_right_line_mixer_controls[0],
  632. ARRAY_SIZE(aic3x_right_line_mixer_controls)),
  633. SND_SOC_DAPM_MIXER("Left HP Mixer", SND_SOC_NOPM, 0, 0,
  634. &aic3x_left_hp_mixer_controls[0],
  635. ARRAY_SIZE(aic3x_left_hp_mixer_controls)),
  636. SND_SOC_DAPM_MIXER("Right HP Mixer", SND_SOC_NOPM, 0, 0,
  637. &aic3x_right_hp_mixer_controls[0],
  638. ARRAY_SIZE(aic3x_right_hp_mixer_controls)),
  639. SND_SOC_DAPM_MIXER("Left HPCOM Mixer", SND_SOC_NOPM, 0, 0,
  640. &aic3x_left_hpcom_mixer_controls[0],
  641. ARRAY_SIZE(aic3x_left_hpcom_mixer_controls)),
  642. SND_SOC_DAPM_MIXER("Right HPCOM Mixer", SND_SOC_NOPM, 0, 0,
  643. &aic3x_right_hpcom_mixer_controls[0],
  644. ARRAY_SIZE(aic3x_right_hpcom_mixer_controls)),
  645. SND_SOC_DAPM_INPUT("MIC3L"),
  646. SND_SOC_DAPM_INPUT("MIC3R"),
  647. SND_SOC_DAPM_INPUT("LINE2L"),
  648. SND_SOC_DAPM_INPUT("LINE2R"),
  649. };
  650. /* For tlv320aic3104 */
  651. static const struct snd_soc_dapm_widget aic3104_extra_dapm_widgets[] = {
  652. /* Inputs to Left ADC */
  653. SND_SOC_DAPM_MIXER("Left PGA Mixer", SND_SOC_NOPM, 0, 0,
  654. &aic3104_left_pga_mixer_controls[0],
  655. ARRAY_SIZE(aic3104_left_pga_mixer_controls)),
  656. /* Inputs to Right ADC */
  657. SND_SOC_DAPM_MIXER("Right PGA Mixer", SND_SOC_NOPM, 0, 0,
  658. &aic3104_right_pga_mixer_controls[0],
  659. ARRAY_SIZE(aic3104_right_pga_mixer_controls)),
  660. /* Output mixers */
  661. SND_SOC_DAPM_MIXER("Left Line Mixer", SND_SOC_NOPM, 0, 0,
  662. &aic3x_left_line_mixer_controls[0],
  663. ARRAY_SIZE(aic3x_left_line_mixer_controls) - 2),
  664. SND_SOC_DAPM_MIXER("Right Line Mixer", SND_SOC_NOPM, 0, 0,
  665. &aic3x_right_line_mixer_controls[0],
  666. ARRAY_SIZE(aic3x_right_line_mixer_controls) - 2),
  667. SND_SOC_DAPM_MIXER("Left HP Mixer", SND_SOC_NOPM, 0, 0,
  668. &aic3x_left_hp_mixer_controls[0],
  669. ARRAY_SIZE(aic3x_left_hp_mixer_controls) - 2),
  670. SND_SOC_DAPM_MIXER("Right HP Mixer", SND_SOC_NOPM, 0, 0,
  671. &aic3x_right_hp_mixer_controls[0],
  672. ARRAY_SIZE(aic3x_right_hp_mixer_controls) - 2),
  673. SND_SOC_DAPM_MIXER("Left HPCOM Mixer", SND_SOC_NOPM, 0, 0,
  674. &aic3x_left_hpcom_mixer_controls[0],
  675. ARRAY_SIZE(aic3x_left_hpcom_mixer_controls) - 2),
  676. SND_SOC_DAPM_MIXER("Right HPCOM Mixer", SND_SOC_NOPM, 0, 0,
  677. &aic3x_right_hpcom_mixer_controls[0],
  678. ARRAY_SIZE(aic3x_right_hpcom_mixer_controls) - 2),
  679. SND_SOC_DAPM_INPUT("MIC2L"),
  680. SND_SOC_DAPM_INPUT("MIC2R"),
  681. };
  682. static const struct snd_soc_dapm_widget aic3x_dapm_mono_widgets[] = {
  683. /* Mono Output */
  684. SND_SOC_DAPM_PGA("Mono Out", MONOLOPM_CTRL, 0, 0, NULL, 0),
  685. SND_SOC_DAPM_MIXER("Mono Mixer", SND_SOC_NOPM, 0, 0,
  686. &aic3x_mono_mixer_controls[0],
  687. ARRAY_SIZE(aic3x_mono_mixer_controls)),
  688. SND_SOC_DAPM_OUTPUT("MONO_LOUT"),
  689. };
  690. static const struct snd_soc_dapm_widget aic3007_dapm_widgets[] = {
  691. /* Class-D outputs */
  692. SND_SOC_DAPM_PGA("Left Class-D Out", CLASSD_CTRL, 3, 0, NULL, 0),
  693. SND_SOC_DAPM_PGA("Right Class-D Out", CLASSD_CTRL, 2, 0, NULL, 0),
  694. SND_SOC_DAPM_OUTPUT("SPOP"),
  695. SND_SOC_DAPM_OUTPUT("SPOM"),
  696. };
  697. static const struct snd_soc_dapm_route intercon[] = {
  698. /* Left Input */
  699. {"Left Line1L Mux", "single-ended", "LINE1L"},
  700. {"Left Line1L Mux", "differential", "LINE1L"},
  701. {"Left Line1R Mux", "single-ended", "LINE1R"},
  702. {"Left Line1R Mux", "differential", "LINE1R"},
  703. {"Left PGA Mixer", "Line1L Switch", "Left Line1L Mux"},
  704. {"Left PGA Mixer", "Line1R Switch", "Left Line1R Mux"},
  705. {"Left ADC", NULL, "Left PGA Mixer"},
  706. /* Right Input */
  707. {"Right Line1R Mux", "single-ended", "LINE1R"},
  708. {"Right Line1R Mux", "differential", "LINE1R"},
  709. {"Right Line1L Mux", "single-ended", "LINE1L"},
  710. {"Right Line1L Mux", "differential", "LINE1L"},
  711. {"Right PGA Mixer", "Line1L Switch", "Right Line1L Mux"},
  712. {"Right PGA Mixer", "Line1R Switch", "Right Line1R Mux"},
  713. {"Right ADC", NULL, "Right PGA Mixer"},
  714. /* Left DAC Output */
  715. {"Left DAC Mux", "DAC_L1", "Left DAC"},
  716. {"Left DAC Mux", "DAC_L2", "Left DAC"},
  717. {"Left DAC Mux", "DAC_L3", "Left DAC"},
  718. /* Right DAC Output */
  719. {"Right DAC Mux", "DAC_R1", "Right DAC"},
  720. {"Right DAC Mux", "DAC_R2", "Right DAC"},
  721. {"Right DAC Mux", "DAC_R3", "Right DAC"},
  722. /* Left Line Output */
  723. {"Left Line Mixer", "PGAL Bypass Switch", "Left PGA Mixer"},
  724. {"Left Line Mixer", "DACL1 Switch", "Left DAC Mux"},
  725. {"Left Line Mixer", "PGAR Bypass Switch", "Right PGA Mixer"},
  726. {"Left Line Mixer", "DACR1 Switch", "Right DAC Mux"},
  727. {"Left Line Out", NULL, "Left Line Mixer"},
  728. {"Left Line Out", NULL, "Left DAC Mux"},
  729. {"LLOUT", NULL, "Left Line Out"},
  730. /* Right Line Output */
  731. {"Right Line Mixer", "PGAL Bypass Switch", "Left PGA Mixer"},
  732. {"Right Line Mixer", "DACL1 Switch", "Left DAC Mux"},
  733. {"Right Line Mixer", "PGAR Bypass Switch", "Right PGA Mixer"},
  734. {"Right Line Mixer", "DACR1 Switch", "Right DAC Mux"},
  735. {"Right Line Out", NULL, "Right Line Mixer"},
  736. {"Right Line Out", NULL, "Right DAC Mux"},
  737. {"RLOUT", NULL, "Right Line Out"},
  738. /* Left HP Output */
  739. {"Left HP Mixer", "PGAL Bypass Switch", "Left PGA Mixer"},
  740. {"Left HP Mixer", "DACL1 Switch", "Left DAC Mux"},
  741. {"Left HP Mixer", "PGAR Bypass Switch", "Right PGA Mixer"},
  742. {"Left HP Mixer", "DACR1 Switch", "Right DAC Mux"},
  743. {"Left HP Out", NULL, "Left HP Mixer"},
  744. {"Left HP Out", NULL, "Left DAC Mux"},
  745. {"HPLOUT", NULL, "Left HP Out"},
  746. /* Right HP Output */
  747. {"Right HP Mixer", "PGAL Bypass Switch", "Left PGA Mixer"},
  748. {"Right HP Mixer", "DACL1 Switch", "Left DAC Mux"},
  749. {"Right HP Mixer", "PGAR Bypass Switch", "Right PGA Mixer"},
  750. {"Right HP Mixer", "DACR1 Switch", "Right DAC Mux"},
  751. {"Right HP Out", NULL, "Right HP Mixer"},
  752. {"Right HP Out", NULL, "Right DAC Mux"},
  753. {"HPROUT", NULL, "Right HP Out"},
  754. /* Left HPCOM Output */
  755. {"Left HPCOM Mixer", "PGAL Bypass Switch", "Left PGA Mixer"},
  756. {"Left HPCOM Mixer", "DACL1 Switch", "Left DAC Mux"},
  757. {"Left HPCOM Mixer", "PGAR Bypass Switch", "Right PGA Mixer"},
  758. {"Left HPCOM Mixer", "DACR1 Switch", "Right DAC Mux"},
  759. {"Left HPCOM Mux", "differential of HPLOUT", "Left HP Mixer"},
  760. {"Left HPCOM Mux", "constant VCM", "Left HPCOM Mixer"},
  761. {"Left HPCOM Mux", "single-ended", "Left HPCOM Mixer"},
  762. {"Left HP Com", NULL, "Left HPCOM Mux"},
  763. {"HPLCOM", NULL, "Left HP Com"},
  764. /* Right HPCOM Output */
  765. {"Right HPCOM Mixer", "PGAL Bypass Switch", "Left PGA Mixer"},
  766. {"Right HPCOM Mixer", "DACL1 Switch", "Left DAC Mux"},
  767. {"Right HPCOM Mixer", "PGAR Bypass Switch", "Right PGA Mixer"},
  768. {"Right HPCOM Mixer", "DACR1 Switch", "Right DAC Mux"},
  769. {"Right HPCOM Mux", "differential of HPROUT", "Right HP Mixer"},
  770. {"Right HPCOM Mux", "constant VCM", "Right HPCOM Mixer"},
  771. {"Right HPCOM Mux", "single-ended", "Right HPCOM Mixer"},
  772. {"Right HPCOM Mux", "differential of HPLCOM", "Left HPCOM Mixer"},
  773. {"Right HPCOM Mux", "external feedback", "Right HPCOM Mixer"},
  774. {"Right HP Com", NULL, "Right HPCOM Mux"},
  775. {"HPRCOM", NULL, "Right HP Com"},
  776. };
  777. /* For other than tlv320aic3104 */
  778. static const struct snd_soc_dapm_route intercon_extra[] = {
  779. /* Left Input */
  780. {"Left Line2L Mux", "single-ended", "LINE2L"},
  781. {"Left Line2L Mux", "differential", "LINE2L"},
  782. {"Left PGA Mixer", "Line2L Switch", "Left Line2L Mux"},
  783. {"Left PGA Mixer", "Mic3L Switch", "MIC3L"},
  784. {"Left PGA Mixer", "Mic3R Switch", "MIC3R"},
  785. {"Left ADC", NULL, "GPIO1 dmic modclk"},
  786. /* Right Input */
  787. {"Right Line2R Mux", "single-ended", "LINE2R"},
  788. {"Right Line2R Mux", "differential", "LINE2R"},
  789. {"Right PGA Mixer", "Line2R Switch", "Right Line2R Mux"},
  790. {"Right PGA Mixer", "Mic3L Switch", "MIC3L"},
  791. {"Right PGA Mixer", "Mic3R Switch", "MIC3R"},
  792. {"Right ADC", NULL, "GPIO1 dmic modclk"},
  793. /*
  794. * Logical path between digital mic enable and GPIO1 modulator clock
  795. * output function
  796. */
  797. {"GPIO1 dmic modclk", NULL, "DMic Rate 128"},
  798. {"GPIO1 dmic modclk", NULL, "DMic Rate 64"},
  799. {"GPIO1 dmic modclk", NULL, "DMic Rate 32"},
  800. /* Left Line Output */
  801. {"Left Line Mixer", "Line2L Bypass Switch", "Left Line2L Mux"},
  802. {"Left Line Mixer", "Line2R Bypass Switch", "Right Line2R Mux"},
  803. /* Right Line Output */
  804. {"Right Line Mixer", "Line2L Bypass Switch", "Left Line2L Mux"},
  805. {"Right Line Mixer", "Line2R Bypass Switch", "Right Line2R Mux"},
  806. /* Left HP Output */
  807. {"Left HP Mixer", "Line2L Bypass Switch", "Left Line2L Mux"},
  808. {"Left HP Mixer", "Line2R Bypass Switch", "Right Line2R Mux"},
  809. /* Right HP Output */
  810. {"Right HP Mixer", "Line2L Bypass Switch", "Left Line2L Mux"},
  811. {"Right HP Mixer", "Line2R Bypass Switch", "Right Line2R Mux"},
  812. /* Left HPCOM Output */
  813. {"Left HPCOM Mixer", "Line2L Bypass Switch", "Left Line2L Mux"},
  814. {"Left HPCOM Mixer", "Line2R Bypass Switch", "Right Line2R Mux"},
  815. /* Right HPCOM Output */
  816. {"Right HPCOM Mixer", "Line2L Bypass Switch", "Left Line2L Mux"},
  817. {"Right HPCOM Mixer", "Line2R Bypass Switch", "Right Line2R Mux"},
  818. };
  819. /* For tlv320aic3104 */
  820. static const struct snd_soc_dapm_route intercon_extra_3104[] = {
  821. /* Left Input */
  822. {"Left PGA Mixer", "Mic2L Switch", "MIC2L"},
  823. {"Left PGA Mixer", "Mic2R Switch", "MIC2R"},
  824. /* Right Input */
  825. {"Right PGA Mixer", "Mic2L Switch", "MIC2L"},
  826. {"Right PGA Mixer", "Mic2R Switch", "MIC2R"},
  827. };
  828. static const struct snd_soc_dapm_route intercon_mono[] = {
  829. /* Mono Output */
  830. {"Mono Mixer", "Line2L Bypass Switch", "Left Line2L Mux"},
  831. {"Mono Mixer", "PGAL Bypass Switch", "Left PGA Mixer"},
  832. {"Mono Mixer", "DACL1 Switch", "Left DAC Mux"},
  833. {"Mono Mixer", "Line2R Bypass Switch", "Right Line2R Mux"},
  834. {"Mono Mixer", "PGAR Bypass Switch", "Right PGA Mixer"},
  835. {"Mono Mixer", "DACR1 Switch", "Right DAC Mux"},
  836. {"Mono Out", NULL, "Mono Mixer"},
  837. {"MONO_LOUT", NULL, "Mono Out"},
  838. };
  839. static const struct snd_soc_dapm_route intercon_3007[] = {
  840. /* Class-D outputs */
  841. {"Left Class-D Out", NULL, "Left Line Out"},
  842. {"Right Class-D Out", NULL, "Left Line Out"},
  843. {"SPOP", NULL, "Left Class-D Out"},
  844. {"SPOM", NULL, "Right Class-D Out"},
  845. };
  846. static int aic3x_add_widgets(struct snd_soc_codec *codec)
  847. {
  848. struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec);
  849. struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
  850. switch (aic3x->model) {
  851. case AIC3X_MODEL_3X:
  852. case AIC3X_MODEL_33:
  853. snd_soc_dapm_new_controls(dapm, aic3x_extra_dapm_widgets,
  854. ARRAY_SIZE(aic3x_extra_dapm_widgets));
  855. snd_soc_dapm_add_routes(dapm, intercon_extra,
  856. ARRAY_SIZE(intercon_extra));
  857. snd_soc_dapm_new_controls(dapm, aic3x_dapm_mono_widgets,
  858. ARRAY_SIZE(aic3x_dapm_mono_widgets));
  859. snd_soc_dapm_add_routes(dapm, intercon_mono,
  860. ARRAY_SIZE(intercon_mono));
  861. break;
  862. case AIC3X_MODEL_3007:
  863. snd_soc_dapm_new_controls(dapm, aic3x_extra_dapm_widgets,
  864. ARRAY_SIZE(aic3x_extra_dapm_widgets));
  865. snd_soc_dapm_add_routes(dapm, intercon_extra,
  866. ARRAY_SIZE(intercon_extra));
  867. snd_soc_dapm_new_controls(dapm, aic3007_dapm_widgets,
  868. ARRAY_SIZE(aic3007_dapm_widgets));
  869. snd_soc_dapm_add_routes(dapm, intercon_3007,
  870. ARRAY_SIZE(intercon_3007));
  871. break;
  872. case AIC3X_MODEL_3104:
  873. snd_soc_dapm_new_controls(dapm, aic3104_extra_dapm_widgets,
  874. ARRAY_SIZE(aic3104_extra_dapm_widgets));
  875. snd_soc_dapm_add_routes(dapm, intercon_extra_3104,
  876. ARRAY_SIZE(intercon_extra_3104));
  877. break;
  878. }
  879. return 0;
  880. }
  881. static int aic3x_hw_params(struct snd_pcm_substream *substream,
  882. struct snd_pcm_hw_params *params,
  883. struct snd_soc_dai *dai)
  884. {
  885. struct snd_soc_codec *codec = dai->codec;
  886. struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec);
  887. int codec_clk = 0, bypass_pll = 0, fsref, last_clk = 0;
  888. u8 data, j, r, p, pll_q, pll_p = 1, pll_r = 1, pll_j = 1;
  889. u16 d, pll_d = 1;
  890. int clk;
  891. int width = aic3x->slot_width;
  892. if (!width)
  893. width = params_width(params);
  894. /* select data word length */
  895. data = snd_soc_read(codec, AIC3X_ASD_INTF_CTRLB) & (~(0x3 << 4));
  896. switch (width) {
  897. case 16:
  898. break;
  899. case 20:
  900. data |= (0x01 << 4);
  901. break;
  902. case 24:
  903. data |= (0x02 << 4);
  904. break;
  905. case 32:
  906. data |= (0x03 << 4);
  907. break;
  908. }
  909. snd_soc_write(codec, AIC3X_ASD_INTF_CTRLB, data);
  910. /* Fsref can be 44100 or 48000 */
  911. fsref = (params_rate(params) % 11025 == 0) ? 44100 : 48000;
  912. /* Try to find a value for Q which allows us to bypass the PLL and
  913. * generate CODEC_CLK directly. */
  914. for (pll_q = 2; pll_q < 18; pll_q++)
  915. if (aic3x->sysclk / (128 * pll_q) == fsref) {
  916. bypass_pll = 1;
  917. break;
  918. }
  919. if (bypass_pll) {
  920. pll_q &= 0xf;
  921. snd_soc_write(codec, AIC3X_PLL_PROGA_REG, pll_q << PLLQ_SHIFT);
  922. snd_soc_write(codec, AIC3X_GPIOB_REG, CODEC_CLKIN_CLKDIV);
  923. /* disable PLL if it is bypassed */
  924. snd_soc_update_bits(codec, AIC3X_PLL_PROGA_REG, PLL_ENABLE, 0);
  925. } else {
  926. snd_soc_write(codec, AIC3X_GPIOB_REG, CODEC_CLKIN_PLLDIV);
  927. /* enable PLL when it is used */
  928. snd_soc_update_bits(codec, AIC3X_PLL_PROGA_REG,
  929. PLL_ENABLE, PLL_ENABLE);
  930. }
  931. /* Route Left DAC to left channel input and
  932. * right DAC to right channel input */
  933. data = (LDAC2LCH | RDAC2RCH);
  934. data |= (fsref == 44100) ? FSREF_44100 : FSREF_48000;
  935. if (params_rate(params) >= 64000)
  936. data |= DUAL_RATE_MODE;
  937. snd_soc_write(codec, AIC3X_CODEC_DATAPATH_REG, data);
  938. /* codec sample rate select */
  939. data = (fsref * 20) / params_rate(params);
  940. if (params_rate(params) < 64000)
  941. data /= 2;
  942. data /= 5;
  943. data -= 2;
  944. data |= (data << 4);
  945. snd_soc_write(codec, AIC3X_SAMPLE_RATE_SEL_REG, data);
  946. if (bypass_pll)
  947. return 0;
  948. /* Use PLL, compute appropriate setup for j, d, r and p, the closest
  949. * one wins the game. Try with d==0 first, next with d!=0.
  950. * Constraints for j are according to the datasheet.
  951. * The sysclk is divided by 1000 to prevent integer overflows.
  952. */
  953. codec_clk = (2048 * fsref) / (aic3x->sysclk / 1000);
  954. for (r = 1; r <= 16; r++)
  955. for (p = 1; p <= 8; p++) {
  956. for (j = 4; j <= 55; j++) {
  957. /* This is actually 1000*((j+(d/10000))*r)/p
  958. * The term had to be converted to get
  959. * rid of the division by 10000; d = 0 here
  960. */
  961. int tmp_clk = (1000 * j * r) / p;
  962. /* Check whether this values get closer than
  963. * the best ones we had before
  964. */
  965. if (abs(codec_clk - tmp_clk) <
  966. abs(codec_clk - last_clk)) {
  967. pll_j = j; pll_d = 0;
  968. pll_r = r; pll_p = p;
  969. last_clk = tmp_clk;
  970. }
  971. /* Early exit for exact matches */
  972. if (tmp_clk == codec_clk)
  973. goto found;
  974. }
  975. }
  976. /* try with d != 0 */
  977. for (p = 1; p <= 8; p++) {
  978. j = codec_clk * p / 1000;
  979. if (j < 4 || j > 11)
  980. continue;
  981. /* do not use codec_clk here since we'd loose precision */
  982. d = ((2048 * p * fsref) - j * aic3x->sysclk)
  983. * 100 / (aic3x->sysclk/100);
  984. clk = (10000 * j + d) / (10 * p);
  985. /* check whether this values get closer than the best
  986. * ones we had before */
  987. if (abs(codec_clk - clk) < abs(codec_clk - last_clk)) {
  988. pll_j = j; pll_d = d; pll_r = 1; pll_p = p;
  989. last_clk = clk;
  990. }
  991. /* Early exit for exact matches */
  992. if (clk == codec_clk)
  993. goto found;
  994. }
  995. if (last_clk == 0) {
  996. printk(KERN_ERR "%s(): unable to setup PLL\n", __func__);
  997. return -EINVAL;
  998. }
  999. found:
  1000. snd_soc_update_bits(codec, AIC3X_PLL_PROGA_REG, PLLP_MASK, pll_p);
  1001. snd_soc_write(codec, AIC3X_OVRF_STATUS_AND_PLLR_REG,
  1002. pll_r << PLLR_SHIFT);
  1003. snd_soc_write(codec, AIC3X_PLL_PROGB_REG, pll_j << PLLJ_SHIFT);
  1004. snd_soc_write(codec, AIC3X_PLL_PROGC_REG,
  1005. (pll_d >> 6) << PLLD_MSB_SHIFT);
  1006. snd_soc_write(codec, AIC3X_PLL_PROGD_REG,
  1007. (pll_d & 0x3F) << PLLD_LSB_SHIFT);
  1008. return 0;
  1009. }
  1010. static int aic3x_prepare(struct snd_pcm_substream *substream,
  1011. struct snd_soc_dai *dai)
  1012. {
  1013. struct snd_soc_codec *codec = dai->codec;
  1014. struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec);
  1015. int delay = 0;
  1016. int width = aic3x->slot_width;
  1017. if (!width)
  1018. width = substream->runtime->sample_bits;
  1019. /* TDM slot selection only valid in DSP_A/_B mode */
  1020. if (aic3x->dai_fmt == SND_SOC_DAIFMT_DSP_A)
  1021. delay += (aic3x->tdm_delay*width + 1);
  1022. else if (aic3x->dai_fmt == SND_SOC_DAIFMT_DSP_B)
  1023. delay += aic3x->tdm_delay*width;
  1024. /* Configure data delay */
  1025. snd_soc_write(codec, AIC3X_ASD_INTF_CTRLC, delay);
  1026. return 0;
  1027. }
  1028. static int aic3x_mute(struct snd_soc_dai *dai, int mute)
  1029. {
  1030. struct snd_soc_codec *codec = dai->codec;
  1031. u8 ldac_reg = snd_soc_read(codec, LDAC_VOL) & ~MUTE_ON;
  1032. u8 rdac_reg = snd_soc_read(codec, RDAC_VOL) & ~MUTE_ON;
  1033. if (mute) {
  1034. snd_soc_write(codec, LDAC_VOL, ldac_reg | MUTE_ON);
  1035. snd_soc_write(codec, RDAC_VOL, rdac_reg | MUTE_ON);
  1036. } else {
  1037. snd_soc_write(codec, LDAC_VOL, ldac_reg);
  1038. snd_soc_write(codec, RDAC_VOL, rdac_reg);
  1039. }
  1040. return 0;
  1041. }
  1042. static int aic3x_set_dai_sysclk(struct snd_soc_dai *codec_dai,
  1043. int clk_id, unsigned int freq, int dir)
  1044. {
  1045. struct snd_soc_codec *codec = codec_dai->codec;
  1046. struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec);
  1047. /* set clock on MCLK or GPIO2 or BCLK */
  1048. snd_soc_update_bits(codec, AIC3X_CLKGEN_CTRL_REG, PLLCLK_IN_MASK,
  1049. clk_id << PLLCLK_IN_SHIFT);
  1050. snd_soc_update_bits(codec, AIC3X_CLKGEN_CTRL_REG, CLKDIV_IN_MASK,
  1051. clk_id << CLKDIV_IN_SHIFT);
  1052. aic3x->sysclk = freq;
  1053. return 0;
  1054. }
  1055. static int aic3x_set_dai_fmt(struct snd_soc_dai *codec_dai,
  1056. unsigned int fmt)
  1057. {
  1058. struct snd_soc_codec *codec = codec_dai->codec;
  1059. struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec);
  1060. u8 iface_areg, iface_breg;
  1061. iface_areg = snd_soc_read(codec, AIC3X_ASD_INTF_CTRLA) & 0x3f;
  1062. iface_breg = snd_soc_read(codec, AIC3X_ASD_INTF_CTRLB) & 0x3f;
  1063. /* set master/slave audio interface */
  1064. switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  1065. case SND_SOC_DAIFMT_CBM_CFM:
  1066. aic3x->master = 1;
  1067. iface_areg |= BIT_CLK_MASTER | WORD_CLK_MASTER;
  1068. break;
  1069. case SND_SOC_DAIFMT_CBS_CFS:
  1070. aic3x->master = 0;
  1071. iface_areg &= ~(BIT_CLK_MASTER | WORD_CLK_MASTER);
  1072. break;
  1073. default:
  1074. return -EINVAL;
  1075. }
  1076. /*
  1077. * match both interface format and signal polarities since they
  1078. * are fixed
  1079. */
  1080. switch (fmt & (SND_SOC_DAIFMT_FORMAT_MASK |
  1081. SND_SOC_DAIFMT_INV_MASK)) {
  1082. case (SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF):
  1083. break;
  1084. case (SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_IB_NF):
  1085. case (SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_IB_NF):
  1086. iface_breg |= (0x01 << 6);
  1087. break;
  1088. case (SND_SOC_DAIFMT_RIGHT_J | SND_SOC_DAIFMT_NB_NF):
  1089. iface_breg |= (0x02 << 6);
  1090. break;
  1091. case (SND_SOC_DAIFMT_LEFT_J | SND_SOC_DAIFMT_NB_NF):
  1092. iface_breg |= (0x03 << 6);
  1093. break;
  1094. default:
  1095. return -EINVAL;
  1096. }
  1097. aic3x->dai_fmt = fmt & SND_SOC_DAIFMT_FORMAT_MASK;
  1098. /* set iface */
  1099. snd_soc_write(codec, AIC3X_ASD_INTF_CTRLA, iface_areg);
  1100. snd_soc_write(codec, AIC3X_ASD_INTF_CTRLB, iface_breg);
  1101. return 0;
  1102. }
  1103. static int aic3x_set_dai_tdm_slot(struct snd_soc_dai *codec_dai,
  1104. unsigned int tx_mask, unsigned int rx_mask,
  1105. int slots, int slot_width)
  1106. {
  1107. struct snd_soc_codec *codec = codec_dai->codec;
  1108. struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec);
  1109. unsigned int lsb;
  1110. if (tx_mask != rx_mask) {
  1111. dev_err(codec->dev, "tx and rx masks must be symmetric\n");
  1112. return -EINVAL;
  1113. }
  1114. if (unlikely(!tx_mask)) {
  1115. dev_err(codec->dev, "tx and rx masks need to be non 0\n");
  1116. return -EINVAL;
  1117. }
  1118. /* TDM based on DSP mode requires slots to be adjacent */
  1119. lsb = __ffs(tx_mask);
  1120. if ((lsb + 1) != __fls(tx_mask)) {
  1121. dev_err(codec->dev, "Invalid mask, slots must be adjacent\n");
  1122. return -EINVAL;
  1123. }
  1124. switch (slot_width) {
  1125. case 16:
  1126. case 20:
  1127. case 24:
  1128. case 32:
  1129. break;
  1130. default:
  1131. dev_err(codec->dev, "Unsupported slot width %d\n", slot_width);
  1132. return -EINVAL;
  1133. }
  1134. aic3x->tdm_delay = lsb;
  1135. aic3x->slot_width = slot_width;
  1136. /* DOUT in high-impedance on inactive bit clocks */
  1137. snd_soc_update_bits(codec, AIC3X_ASD_INTF_CTRLA,
  1138. DOUT_TRISTATE, DOUT_TRISTATE);
  1139. return 0;
  1140. }
  1141. static int aic3x_regulator_event(struct notifier_block *nb,
  1142. unsigned long event, void *data)
  1143. {
  1144. struct aic3x_disable_nb *disable_nb =
  1145. container_of(nb, struct aic3x_disable_nb, nb);
  1146. struct aic3x_priv *aic3x = disable_nb->aic3x;
  1147. if (event & REGULATOR_EVENT_DISABLE) {
  1148. /*
  1149. * Put codec to reset and require cache sync as at least one
  1150. * of the supplies was disabled
  1151. */
  1152. if (gpio_is_valid(aic3x->gpio_reset))
  1153. gpio_set_value(aic3x->gpio_reset, 0);
  1154. regcache_mark_dirty(aic3x->regmap);
  1155. }
  1156. return 0;
  1157. }
  1158. static int aic3x_set_power(struct snd_soc_codec *codec, int power)
  1159. {
  1160. struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec);
  1161. unsigned int pll_c, pll_d;
  1162. int ret;
  1163. if (power) {
  1164. ret = regulator_bulk_enable(ARRAY_SIZE(aic3x->supplies),
  1165. aic3x->supplies);
  1166. if (ret)
  1167. goto out;
  1168. aic3x->power = 1;
  1169. if (gpio_is_valid(aic3x->gpio_reset)) {
  1170. udelay(1);
  1171. gpio_set_value(aic3x->gpio_reset, 1);
  1172. }
  1173. /* Sync reg_cache with the hardware */
  1174. regcache_cache_only(aic3x->regmap, false);
  1175. regcache_sync(aic3x->regmap);
  1176. /* Rewrite paired PLL D registers in case cached sync skipped
  1177. * writing one of them and thus caused other one also not
  1178. * being written
  1179. */
  1180. pll_c = snd_soc_read(codec, AIC3X_PLL_PROGC_REG);
  1181. pll_d = snd_soc_read(codec, AIC3X_PLL_PROGD_REG);
  1182. if (pll_c == aic3x_reg[AIC3X_PLL_PROGC_REG].def ||
  1183. pll_d == aic3x_reg[AIC3X_PLL_PROGD_REG].def) {
  1184. snd_soc_write(codec, AIC3X_PLL_PROGC_REG, pll_c);
  1185. snd_soc_write(codec, AIC3X_PLL_PROGD_REG, pll_d);
  1186. }
  1187. } else {
  1188. /*
  1189. * Do soft reset to this codec instance in order to clear
  1190. * possible VDD leakage currents in case the supply regulators
  1191. * remain on
  1192. */
  1193. snd_soc_write(codec, AIC3X_RESET, SOFT_RESET);
  1194. regcache_mark_dirty(aic3x->regmap);
  1195. aic3x->power = 0;
  1196. /* HW writes are needless when bias is off */
  1197. regcache_cache_only(aic3x->regmap, true);
  1198. ret = regulator_bulk_disable(ARRAY_SIZE(aic3x->supplies),
  1199. aic3x->supplies);
  1200. }
  1201. out:
  1202. return ret;
  1203. }
  1204. static int aic3x_set_bias_level(struct snd_soc_codec *codec,
  1205. enum snd_soc_bias_level level)
  1206. {
  1207. struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec);
  1208. switch (level) {
  1209. case SND_SOC_BIAS_ON:
  1210. break;
  1211. case SND_SOC_BIAS_PREPARE:
  1212. if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_STANDBY &&
  1213. aic3x->master) {
  1214. /* enable pll */
  1215. snd_soc_update_bits(codec, AIC3X_PLL_PROGA_REG,
  1216. PLL_ENABLE, PLL_ENABLE);
  1217. }
  1218. break;
  1219. case SND_SOC_BIAS_STANDBY:
  1220. if (!aic3x->power)
  1221. aic3x_set_power(codec, 1);
  1222. if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_PREPARE &&
  1223. aic3x->master) {
  1224. /* disable pll */
  1225. snd_soc_update_bits(codec, AIC3X_PLL_PROGA_REG,
  1226. PLL_ENABLE, 0);
  1227. }
  1228. break;
  1229. case SND_SOC_BIAS_OFF:
  1230. if (aic3x->power)
  1231. aic3x_set_power(codec, 0);
  1232. break;
  1233. }
  1234. return 0;
  1235. }
  1236. #define AIC3X_RATES SNDRV_PCM_RATE_8000_96000
  1237. #define AIC3X_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
  1238. SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S24_LE | \
  1239. SNDRV_PCM_FMTBIT_S32_LE)
  1240. static const struct snd_soc_dai_ops aic3x_dai_ops = {
  1241. .hw_params = aic3x_hw_params,
  1242. .prepare = aic3x_prepare,
  1243. .digital_mute = aic3x_mute,
  1244. .set_sysclk = aic3x_set_dai_sysclk,
  1245. .set_fmt = aic3x_set_dai_fmt,
  1246. .set_tdm_slot = aic3x_set_dai_tdm_slot,
  1247. };
  1248. static struct snd_soc_dai_driver aic3x_dai = {
  1249. .name = "tlv320aic3x-hifi",
  1250. .playback = {
  1251. .stream_name = "Playback",
  1252. .channels_min = 2,
  1253. .channels_max = 2,
  1254. .rates = AIC3X_RATES,
  1255. .formats = AIC3X_FORMATS,},
  1256. .capture = {
  1257. .stream_name = "Capture",
  1258. .channels_min = 2,
  1259. .channels_max = 2,
  1260. .rates = AIC3X_RATES,
  1261. .formats = AIC3X_FORMATS,},
  1262. .ops = &aic3x_dai_ops,
  1263. .symmetric_rates = 1,
  1264. };
  1265. static void aic3x_mono_init(struct snd_soc_codec *codec)
  1266. {
  1267. /* DAC to Mono Line Out default volume and route to Output mixer */
  1268. snd_soc_write(codec, DACL1_2_MONOLOPM_VOL, DEFAULT_VOL | ROUTE_ON);
  1269. snd_soc_write(codec, DACR1_2_MONOLOPM_VOL, DEFAULT_VOL | ROUTE_ON);
  1270. /* unmute all outputs */
  1271. snd_soc_update_bits(codec, MONOLOPM_CTRL, UNMUTE, UNMUTE);
  1272. /* PGA to Mono Line Out default volume, disconnect from Output Mixer */
  1273. snd_soc_write(codec, PGAL_2_MONOLOPM_VOL, DEFAULT_VOL);
  1274. snd_soc_write(codec, PGAR_2_MONOLOPM_VOL, DEFAULT_VOL);
  1275. /* Line2 to Mono Out default volume, disconnect from Output Mixer */
  1276. snd_soc_write(codec, LINE2L_2_MONOLOPM_VOL, DEFAULT_VOL);
  1277. snd_soc_write(codec, LINE2R_2_MONOLOPM_VOL, DEFAULT_VOL);
  1278. }
  1279. /*
  1280. * initialise the AIC3X driver
  1281. * register the mixer and dsp interfaces with the kernel
  1282. */
  1283. static int aic3x_init(struct snd_soc_codec *codec)
  1284. {
  1285. struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec);
  1286. snd_soc_write(codec, AIC3X_PAGE_SELECT, PAGE0_SELECT);
  1287. snd_soc_write(codec, AIC3X_RESET, SOFT_RESET);
  1288. /* DAC default volume and mute */
  1289. snd_soc_write(codec, LDAC_VOL, DEFAULT_VOL | MUTE_ON);
  1290. snd_soc_write(codec, RDAC_VOL, DEFAULT_VOL | MUTE_ON);
  1291. /* DAC to HP default volume and route to Output mixer */
  1292. snd_soc_write(codec, DACL1_2_HPLOUT_VOL, DEFAULT_VOL | ROUTE_ON);
  1293. snd_soc_write(codec, DACR1_2_HPROUT_VOL, DEFAULT_VOL | ROUTE_ON);
  1294. snd_soc_write(codec, DACL1_2_HPLCOM_VOL, DEFAULT_VOL | ROUTE_ON);
  1295. snd_soc_write(codec, DACR1_2_HPRCOM_VOL, DEFAULT_VOL | ROUTE_ON);
  1296. /* DAC to Line Out default volume and route to Output mixer */
  1297. snd_soc_write(codec, DACL1_2_LLOPM_VOL, DEFAULT_VOL | ROUTE_ON);
  1298. snd_soc_write(codec, DACR1_2_RLOPM_VOL, DEFAULT_VOL | ROUTE_ON);
  1299. /* unmute all outputs */
  1300. snd_soc_update_bits(codec, LLOPM_CTRL, UNMUTE, UNMUTE);
  1301. snd_soc_update_bits(codec, RLOPM_CTRL, UNMUTE, UNMUTE);
  1302. snd_soc_update_bits(codec, HPLOUT_CTRL, UNMUTE, UNMUTE);
  1303. snd_soc_update_bits(codec, HPROUT_CTRL, UNMUTE, UNMUTE);
  1304. snd_soc_update_bits(codec, HPLCOM_CTRL, UNMUTE, UNMUTE);
  1305. snd_soc_update_bits(codec, HPRCOM_CTRL, UNMUTE, UNMUTE);
  1306. /* ADC default volume and unmute */
  1307. snd_soc_write(codec, LADC_VOL, DEFAULT_GAIN);
  1308. snd_soc_write(codec, RADC_VOL, DEFAULT_GAIN);
  1309. /* By default route Line1 to ADC PGA mixer */
  1310. snd_soc_write(codec, LINE1L_2_LADC_CTRL, 0x0);
  1311. snd_soc_write(codec, LINE1R_2_RADC_CTRL, 0x0);
  1312. /* PGA to HP Bypass default volume, disconnect from Output Mixer */
  1313. snd_soc_write(codec, PGAL_2_HPLOUT_VOL, DEFAULT_VOL);
  1314. snd_soc_write(codec, PGAR_2_HPROUT_VOL, DEFAULT_VOL);
  1315. snd_soc_write(codec, PGAL_2_HPLCOM_VOL, DEFAULT_VOL);
  1316. snd_soc_write(codec, PGAR_2_HPRCOM_VOL, DEFAULT_VOL);
  1317. /* PGA to Line Out default volume, disconnect from Output Mixer */
  1318. snd_soc_write(codec, PGAL_2_LLOPM_VOL, DEFAULT_VOL);
  1319. snd_soc_write(codec, PGAR_2_RLOPM_VOL, DEFAULT_VOL);
  1320. /* On tlv320aic3104, these registers are reserved and must not be written */
  1321. if (aic3x->model != AIC3X_MODEL_3104) {
  1322. /* Line2 to HP Bypass default volume, disconnect from Output Mixer */
  1323. snd_soc_write(codec, LINE2L_2_HPLOUT_VOL, DEFAULT_VOL);
  1324. snd_soc_write(codec, LINE2R_2_HPROUT_VOL, DEFAULT_VOL);
  1325. snd_soc_write(codec, LINE2L_2_HPLCOM_VOL, DEFAULT_VOL);
  1326. snd_soc_write(codec, LINE2R_2_HPRCOM_VOL, DEFAULT_VOL);
  1327. /* Line2 Line Out default volume, disconnect from Output Mixer */
  1328. snd_soc_write(codec, LINE2L_2_LLOPM_VOL, DEFAULT_VOL);
  1329. snd_soc_write(codec, LINE2R_2_RLOPM_VOL, DEFAULT_VOL);
  1330. }
  1331. switch (aic3x->model) {
  1332. case AIC3X_MODEL_3X:
  1333. case AIC3X_MODEL_33:
  1334. aic3x_mono_init(codec);
  1335. break;
  1336. case AIC3X_MODEL_3007:
  1337. snd_soc_write(codec, CLASSD_CTRL, 0);
  1338. break;
  1339. }
  1340. return 0;
  1341. }
  1342. static bool aic3x_is_shared_reset(struct aic3x_priv *aic3x)
  1343. {
  1344. struct aic3x_priv *a;
  1345. list_for_each_entry(a, &reset_list, list) {
  1346. if (gpio_is_valid(aic3x->gpio_reset) &&
  1347. aic3x->gpio_reset == a->gpio_reset)
  1348. return true;
  1349. }
  1350. return false;
  1351. }
  1352. static int aic3x_probe(struct snd_soc_codec *codec)
  1353. {
  1354. struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec);
  1355. int ret, i;
  1356. INIT_LIST_HEAD(&aic3x->list);
  1357. aic3x->codec = codec;
  1358. for (i = 0; i < ARRAY_SIZE(aic3x->supplies); i++) {
  1359. aic3x->disable_nb[i].nb.notifier_call = aic3x_regulator_event;
  1360. aic3x->disable_nb[i].aic3x = aic3x;
  1361. ret = regulator_register_notifier(aic3x->supplies[i].consumer,
  1362. &aic3x->disable_nb[i].nb);
  1363. if (ret) {
  1364. dev_err(codec->dev,
  1365. "Failed to request regulator notifier: %d\n",
  1366. ret);
  1367. goto err_notif;
  1368. }
  1369. }
  1370. regcache_mark_dirty(aic3x->regmap);
  1371. aic3x_init(codec);
  1372. if (aic3x->setup) {
  1373. if (aic3x->model != AIC3X_MODEL_3104) {
  1374. /* setup GPIO functions */
  1375. snd_soc_write(codec, AIC3X_GPIO1_REG,
  1376. (aic3x->setup->gpio_func[0] & 0xf) << 4);
  1377. snd_soc_write(codec, AIC3X_GPIO2_REG,
  1378. (aic3x->setup->gpio_func[1] & 0xf) << 4);
  1379. } else {
  1380. dev_warn(codec->dev, "GPIO functionality is not supported on tlv320aic3104\n");
  1381. }
  1382. }
  1383. switch (aic3x->model) {
  1384. case AIC3X_MODEL_3X:
  1385. case AIC3X_MODEL_33:
  1386. snd_soc_add_codec_controls(codec, aic3x_extra_snd_controls,
  1387. ARRAY_SIZE(aic3x_extra_snd_controls));
  1388. snd_soc_add_codec_controls(codec, aic3x_mono_controls,
  1389. ARRAY_SIZE(aic3x_mono_controls));
  1390. break;
  1391. case AIC3X_MODEL_3007:
  1392. snd_soc_add_codec_controls(codec, aic3x_extra_snd_controls,
  1393. ARRAY_SIZE(aic3x_extra_snd_controls));
  1394. snd_soc_add_codec_controls(codec,
  1395. &aic3x_classd_amp_gain_ctrl, 1);
  1396. break;
  1397. case AIC3X_MODEL_3104:
  1398. break;
  1399. }
  1400. /* set mic bias voltage */
  1401. switch (aic3x->micbias_vg) {
  1402. case AIC3X_MICBIAS_2_0V:
  1403. case AIC3X_MICBIAS_2_5V:
  1404. case AIC3X_MICBIAS_AVDDV:
  1405. snd_soc_update_bits(codec, MICBIAS_CTRL,
  1406. MICBIAS_LEVEL_MASK,
  1407. (aic3x->micbias_vg) << MICBIAS_LEVEL_SHIFT);
  1408. break;
  1409. case AIC3X_MICBIAS_OFF:
  1410. /*
  1411. * noting to do. target won't enter here. This is just to avoid
  1412. * compile time warning "warning: enumeration value
  1413. * 'AIC3X_MICBIAS_OFF' not handled in switch"
  1414. */
  1415. break;
  1416. }
  1417. aic3x_add_widgets(codec);
  1418. return 0;
  1419. err_notif:
  1420. while (i--)
  1421. regulator_unregister_notifier(aic3x->supplies[i].consumer,
  1422. &aic3x->disable_nb[i].nb);
  1423. return ret;
  1424. }
  1425. static int aic3x_remove(struct snd_soc_codec *codec)
  1426. {
  1427. struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec);
  1428. int i;
  1429. list_del(&aic3x->list);
  1430. for (i = 0; i < ARRAY_SIZE(aic3x->supplies); i++)
  1431. regulator_unregister_notifier(aic3x->supplies[i].consumer,
  1432. &aic3x->disable_nb[i].nb);
  1433. return 0;
  1434. }
  1435. static struct snd_soc_codec_driver soc_codec_dev_aic3x = {
  1436. .set_bias_level = aic3x_set_bias_level,
  1437. .idle_bias_off = true,
  1438. .probe = aic3x_probe,
  1439. .remove = aic3x_remove,
  1440. .component_driver = {
  1441. .controls = aic3x_snd_controls,
  1442. .num_controls = ARRAY_SIZE(aic3x_snd_controls),
  1443. .dapm_widgets = aic3x_dapm_widgets,
  1444. .num_dapm_widgets = ARRAY_SIZE(aic3x_dapm_widgets),
  1445. .dapm_routes = intercon,
  1446. .num_dapm_routes = ARRAY_SIZE(intercon),
  1447. },
  1448. };
  1449. /*
  1450. * AIC3X 2 wire address can be up to 4 devices with device addresses
  1451. * 0x18, 0x19, 0x1A, 0x1B
  1452. */
  1453. static const struct i2c_device_id aic3x_i2c_id[] = {
  1454. { "tlv320aic3x", AIC3X_MODEL_3X },
  1455. { "tlv320aic33", AIC3X_MODEL_33 },
  1456. { "tlv320aic3007", AIC3X_MODEL_3007 },
  1457. { "tlv320aic3106", AIC3X_MODEL_3X },
  1458. { "tlv320aic3104", AIC3X_MODEL_3104 },
  1459. { }
  1460. };
  1461. MODULE_DEVICE_TABLE(i2c, aic3x_i2c_id);
  1462. static const struct reg_sequence aic3007_class_d[] = {
  1463. /* Class-D speaker driver init; datasheet p. 46 */
  1464. { AIC3X_PAGE_SELECT, 0x0D },
  1465. { 0xD, 0x0D },
  1466. { 0x8, 0x5C },
  1467. { 0x8, 0x5D },
  1468. { 0x8, 0x5C },
  1469. { AIC3X_PAGE_SELECT, 0x00 },
  1470. };
  1471. /*
  1472. * If the i2c layer weren't so broken, we could pass this kind of data
  1473. * around
  1474. */
  1475. static int aic3x_i2c_probe(struct i2c_client *i2c,
  1476. const struct i2c_device_id *id)
  1477. {
  1478. struct aic3x_pdata *pdata = i2c->dev.platform_data;
  1479. struct aic3x_priv *aic3x;
  1480. struct aic3x_setup_data *ai3x_setup;
  1481. struct device_node *np = i2c->dev.of_node;
  1482. int ret, i;
  1483. u32 value;
  1484. aic3x = devm_kzalloc(&i2c->dev, sizeof(struct aic3x_priv), GFP_KERNEL);
  1485. if (!aic3x)
  1486. return -ENOMEM;
  1487. aic3x->regmap = devm_regmap_init_i2c(i2c, &aic3x_regmap);
  1488. if (IS_ERR(aic3x->regmap)) {
  1489. ret = PTR_ERR(aic3x->regmap);
  1490. return ret;
  1491. }
  1492. regcache_cache_only(aic3x->regmap, true);
  1493. i2c_set_clientdata(i2c, aic3x);
  1494. if (pdata) {
  1495. aic3x->gpio_reset = pdata->gpio_reset;
  1496. aic3x->setup = pdata->setup;
  1497. aic3x->micbias_vg = pdata->micbias_vg;
  1498. } else if (np) {
  1499. ai3x_setup = devm_kzalloc(&i2c->dev, sizeof(*ai3x_setup),
  1500. GFP_KERNEL);
  1501. if (!ai3x_setup)
  1502. return -ENOMEM;
  1503. ret = of_get_named_gpio(np, "gpio-reset", 0);
  1504. if (ret >= 0)
  1505. aic3x->gpio_reset = ret;
  1506. else
  1507. aic3x->gpio_reset = -1;
  1508. if (of_property_read_u32_array(np, "ai3x-gpio-func",
  1509. ai3x_setup->gpio_func, 2) >= 0) {
  1510. aic3x->setup = ai3x_setup;
  1511. }
  1512. if (!of_property_read_u32(np, "ai3x-micbias-vg", &value)) {
  1513. switch (value) {
  1514. case 1 :
  1515. aic3x->micbias_vg = AIC3X_MICBIAS_2_0V;
  1516. break;
  1517. case 2 :
  1518. aic3x->micbias_vg = AIC3X_MICBIAS_2_5V;
  1519. break;
  1520. case 3 :
  1521. aic3x->micbias_vg = AIC3X_MICBIAS_AVDDV;
  1522. break;
  1523. default :
  1524. aic3x->micbias_vg = AIC3X_MICBIAS_OFF;
  1525. dev_err(&i2c->dev, "Unsuitable MicBias voltage "
  1526. "found in DT\n");
  1527. }
  1528. } else {
  1529. aic3x->micbias_vg = AIC3X_MICBIAS_OFF;
  1530. }
  1531. } else {
  1532. aic3x->gpio_reset = -1;
  1533. }
  1534. aic3x->model = id->driver_data;
  1535. if (gpio_is_valid(aic3x->gpio_reset) &&
  1536. !aic3x_is_shared_reset(aic3x)) {
  1537. ret = gpio_request(aic3x->gpio_reset, "tlv320aic3x reset");
  1538. if (ret != 0)
  1539. goto err;
  1540. gpio_direction_output(aic3x->gpio_reset, 0);
  1541. }
  1542. for (i = 0; i < ARRAY_SIZE(aic3x->supplies); i++)
  1543. aic3x->supplies[i].supply = aic3x_supply_names[i];
  1544. ret = devm_regulator_bulk_get(&i2c->dev, ARRAY_SIZE(aic3x->supplies),
  1545. aic3x->supplies);
  1546. if (ret != 0) {
  1547. dev_err(&i2c->dev, "Failed to request supplies: %d\n", ret);
  1548. goto err_gpio;
  1549. }
  1550. if (aic3x->model == AIC3X_MODEL_3007) {
  1551. ret = regmap_register_patch(aic3x->regmap, aic3007_class_d,
  1552. ARRAY_SIZE(aic3007_class_d));
  1553. if (ret != 0)
  1554. dev_err(&i2c->dev, "Failed to init class D: %d\n",
  1555. ret);
  1556. }
  1557. ret = snd_soc_register_codec(&i2c->dev,
  1558. &soc_codec_dev_aic3x, &aic3x_dai, 1);
  1559. if (ret != 0)
  1560. goto err_gpio;
  1561. list_add(&aic3x->list, &reset_list);
  1562. return 0;
  1563. err_gpio:
  1564. if (gpio_is_valid(aic3x->gpio_reset) &&
  1565. !aic3x_is_shared_reset(aic3x))
  1566. gpio_free(aic3x->gpio_reset);
  1567. err:
  1568. return ret;
  1569. }
  1570. static int aic3x_i2c_remove(struct i2c_client *client)
  1571. {
  1572. struct aic3x_priv *aic3x = i2c_get_clientdata(client);
  1573. snd_soc_unregister_codec(&client->dev);
  1574. if (gpio_is_valid(aic3x->gpio_reset) &&
  1575. !aic3x_is_shared_reset(aic3x)) {
  1576. gpio_set_value(aic3x->gpio_reset, 0);
  1577. gpio_free(aic3x->gpio_reset);
  1578. }
  1579. return 0;
  1580. }
  1581. #if defined(CONFIG_OF)
  1582. static const struct of_device_id tlv320aic3x_of_match[] = {
  1583. { .compatible = "ti,tlv320aic3x", },
  1584. { .compatible = "ti,tlv320aic33" },
  1585. { .compatible = "ti,tlv320aic3007" },
  1586. { .compatible = "ti,tlv320aic3106" },
  1587. { .compatible = "ti,tlv320aic3104" },
  1588. {},
  1589. };
  1590. MODULE_DEVICE_TABLE(of, tlv320aic3x_of_match);
  1591. #endif
  1592. /* machine i2c codec control layer */
  1593. static struct i2c_driver aic3x_i2c_driver = {
  1594. .driver = {
  1595. .name = "tlv320aic3x-codec",
  1596. .of_match_table = of_match_ptr(tlv320aic3x_of_match),
  1597. },
  1598. .probe = aic3x_i2c_probe,
  1599. .remove = aic3x_i2c_remove,
  1600. .id_table = aic3x_i2c_id,
  1601. };
  1602. module_i2c_driver(aic3x_i2c_driver);
  1603. MODULE_DESCRIPTION("ASoC TLV320AIC3X codec driver");
  1604. MODULE_AUTHOR("Vladimir Barinov");
  1605. MODULE_LICENSE("GPL");