tlv320aic3x.c 52 KB

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