tlv320aic3x.c 52 KB

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