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_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. if (aic3x->model == AIC3X_MODEL_3007) {
  716. snd_soc_dapm_new_controls(dapm, aic3007_dapm_widgets,
  717. ARRAY_SIZE(aic3007_dapm_widgets));
  718. snd_soc_dapm_add_routes(dapm, intercon_3007,
  719. ARRAY_SIZE(intercon_3007));
  720. }
  721. return 0;
  722. }
  723. static int aic3x_hw_params(struct snd_pcm_substream *substream,
  724. struct snd_pcm_hw_params *params,
  725. struct snd_soc_dai *dai)
  726. {
  727. struct snd_soc_codec *codec = dai->codec;
  728. struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec);
  729. int codec_clk = 0, bypass_pll = 0, fsref, last_clk = 0;
  730. u8 data, j, r, p, pll_q, pll_p = 1, pll_r = 1, pll_j = 1;
  731. u16 d, pll_d = 1;
  732. int clk;
  733. /* select data word length */
  734. data = snd_soc_read(codec, AIC3X_ASD_INTF_CTRLB) & (~(0x3 << 4));
  735. switch (params_format(params)) {
  736. case SNDRV_PCM_FORMAT_S16_LE:
  737. break;
  738. case SNDRV_PCM_FORMAT_S20_3LE:
  739. data |= (0x01 << 4);
  740. break;
  741. case SNDRV_PCM_FORMAT_S24_LE:
  742. data |= (0x02 << 4);
  743. break;
  744. case SNDRV_PCM_FORMAT_S32_LE:
  745. data |= (0x03 << 4);
  746. break;
  747. }
  748. snd_soc_write(codec, AIC3X_ASD_INTF_CTRLB, data);
  749. /* Fsref can be 44100 or 48000 */
  750. fsref = (params_rate(params) % 11025 == 0) ? 44100 : 48000;
  751. /* Try to find a value for Q which allows us to bypass the PLL and
  752. * generate CODEC_CLK directly. */
  753. for (pll_q = 2; pll_q < 18; pll_q++)
  754. if (aic3x->sysclk / (128 * pll_q) == fsref) {
  755. bypass_pll = 1;
  756. break;
  757. }
  758. if (bypass_pll) {
  759. pll_q &= 0xf;
  760. snd_soc_write(codec, AIC3X_PLL_PROGA_REG, pll_q << PLLQ_SHIFT);
  761. snd_soc_write(codec, AIC3X_GPIOB_REG, CODEC_CLKIN_CLKDIV);
  762. /* disable PLL if it is bypassed */
  763. snd_soc_update_bits(codec, AIC3X_PLL_PROGA_REG, PLL_ENABLE, 0);
  764. } else {
  765. snd_soc_write(codec, AIC3X_GPIOB_REG, CODEC_CLKIN_PLLDIV);
  766. /* enable PLL when it is used */
  767. snd_soc_update_bits(codec, AIC3X_PLL_PROGA_REG,
  768. PLL_ENABLE, PLL_ENABLE);
  769. }
  770. /* Route Left DAC to left channel input and
  771. * right DAC to right channel input */
  772. data = (LDAC2LCH | RDAC2RCH);
  773. data |= (fsref == 44100) ? FSREF_44100 : FSREF_48000;
  774. if (params_rate(params) >= 64000)
  775. data |= DUAL_RATE_MODE;
  776. snd_soc_write(codec, AIC3X_CODEC_DATAPATH_REG, data);
  777. /* codec sample rate select */
  778. data = (fsref * 20) / params_rate(params);
  779. if (params_rate(params) < 64000)
  780. data /= 2;
  781. data /= 5;
  782. data -= 2;
  783. data |= (data << 4);
  784. snd_soc_write(codec, AIC3X_SAMPLE_RATE_SEL_REG, data);
  785. if (bypass_pll)
  786. return 0;
  787. /* Use PLL, compute appropriate setup for j, d, r and p, the closest
  788. * one wins the game. Try with d==0 first, next with d!=0.
  789. * Constraints for j are according to the datasheet.
  790. * The sysclk is divided by 1000 to prevent integer overflows.
  791. */
  792. codec_clk = (2048 * fsref) / (aic3x->sysclk / 1000);
  793. for (r = 1; r <= 16; r++)
  794. for (p = 1; p <= 8; p++) {
  795. for (j = 4; j <= 55; j++) {
  796. /* This is actually 1000*((j+(d/10000))*r)/p
  797. * The term had to be converted to get
  798. * rid of the division by 10000; d = 0 here
  799. */
  800. int tmp_clk = (1000 * j * r) / p;
  801. /* Check whether this values get closer than
  802. * the best ones we had before
  803. */
  804. if (abs(codec_clk - tmp_clk) <
  805. abs(codec_clk - last_clk)) {
  806. pll_j = j; pll_d = 0;
  807. pll_r = r; pll_p = p;
  808. last_clk = tmp_clk;
  809. }
  810. /* Early exit for exact matches */
  811. if (tmp_clk == codec_clk)
  812. goto found;
  813. }
  814. }
  815. /* try with d != 0 */
  816. for (p = 1; p <= 8; p++) {
  817. j = codec_clk * p / 1000;
  818. if (j < 4 || j > 11)
  819. continue;
  820. /* do not use codec_clk here since we'd loose precision */
  821. d = ((2048 * p * fsref) - j * aic3x->sysclk)
  822. * 100 / (aic3x->sysclk/100);
  823. clk = (10000 * j + d) / (10 * p);
  824. /* check whether this values get closer than the best
  825. * ones we had before */
  826. if (abs(codec_clk - clk) < abs(codec_clk - last_clk)) {
  827. pll_j = j; pll_d = d; pll_r = 1; pll_p = p;
  828. last_clk = clk;
  829. }
  830. /* Early exit for exact matches */
  831. if (clk == codec_clk)
  832. goto found;
  833. }
  834. if (last_clk == 0) {
  835. printk(KERN_ERR "%s(): unable to setup PLL\n", __func__);
  836. return -EINVAL;
  837. }
  838. found:
  839. snd_soc_update_bits(codec, AIC3X_PLL_PROGA_REG, PLLP_MASK, pll_p);
  840. snd_soc_write(codec, AIC3X_OVRF_STATUS_AND_PLLR_REG,
  841. pll_r << PLLR_SHIFT);
  842. snd_soc_write(codec, AIC3X_PLL_PROGB_REG, pll_j << PLLJ_SHIFT);
  843. snd_soc_write(codec, AIC3X_PLL_PROGC_REG,
  844. (pll_d >> 6) << PLLD_MSB_SHIFT);
  845. snd_soc_write(codec, AIC3X_PLL_PROGD_REG,
  846. (pll_d & 0x3F) << PLLD_LSB_SHIFT);
  847. return 0;
  848. }
  849. static int aic3x_mute(struct snd_soc_dai *dai, int mute)
  850. {
  851. struct snd_soc_codec *codec = dai->codec;
  852. u8 ldac_reg = snd_soc_read(codec, LDAC_VOL) & ~MUTE_ON;
  853. u8 rdac_reg = snd_soc_read(codec, RDAC_VOL) & ~MUTE_ON;
  854. if (mute) {
  855. snd_soc_write(codec, LDAC_VOL, ldac_reg | MUTE_ON);
  856. snd_soc_write(codec, RDAC_VOL, rdac_reg | MUTE_ON);
  857. } else {
  858. snd_soc_write(codec, LDAC_VOL, ldac_reg);
  859. snd_soc_write(codec, RDAC_VOL, rdac_reg);
  860. }
  861. return 0;
  862. }
  863. static int aic3x_set_dai_sysclk(struct snd_soc_dai *codec_dai,
  864. int clk_id, unsigned int freq, int dir)
  865. {
  866. struct snd_soc_codec *codec = codec_dai->codec;
  867. struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec);
  868. /* set clock on MCLK or GPIO2 or BCLK */
  869. snd_soc_update_bits(codec, AIC3X_CLKGEN_CTRL_REG, PLLCLK_IN_MASK,
  870. clk_id << PLLCLK_IN_SHIFT);
  871. snd_soc_update_bits(codec, AIC3X_CLKGEN_CTRL_REG, CLKDIV_IN_MASK,
  872. clk_id << CLKDIV_IN_SHIFT);
  873. aic3x->sysclk = freq;
  874. return 0;
  875. }
  876. static int aic3x_set_dai_fmt(struct snd_soc_dai *codec_dai,
  877. unsigned int fmt)
  878. {
  879. struct snd_soc_codec *codec = codec_dai->codec;
  880. struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec);
  881. u8 iface_areg, iface_breg;
  882. int delay = 0;
  883. iface_areg = snd_soc_read(codec, AIC3X_ASD_INTF_CTRLA) & 0x3f;
  884. iface_breg = snd_soc_read(codec, AIC3X_ASD_INTF_CTRLB) & 0x3f;
  885. /* set master/slave audio interface */
  886. switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  887. case SND_SOC_DAIFMT_CBM_CFM:
  888. aic3x->master = 1;
  889. iface_areg |= BIT_CLK_MASTER | WORD_CLK_MASTER;
  890. break;
  891. case SND_SOC_DAIFMT_CBS_CFS:
  892. aic3x->master = 0;
  893. iface_areg &= ~(BIT_CLK_MASTER | WORD_CLK_MASTER);
  894. break;
  895. default:
  896. return -EINVAL;
  897. }
  898. /*
  899. * match both interface format and signal polarities since they
  900. * are fixed
  901. */
  902. switch (fmt & (SND_SOC_DAIFMT_FORMAT_MASK |
  903. SND_SOC_DAIFMT_INV_MASK)) {
  904. case (SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF):
  905. break;
  906. case (SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_IB_NF):
  907. delay = 1;
  908. case (SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_IB_NF):
  909. iface_breg |= (0x01 << 6);
  910. break;
  911. case (SND_SOC_DAIFMT_RIGHT_J | SND_SOC_DAIFMT_NB_NF):
  912. iface_breg |= (0x02 << 6);
  913. break;
  914. case (SND_SOC_DAIFMT_LEFT_J | SND_SOC_DAIFMT_NB_NF):
  915. iface_breg |= (0x03 << 6);
  916. break;
  917. default:
  918. return -EINVAL;
  919. }
  920. /* set iface */
  921. snd_soc_write(codec, AIC3X_ASD_INTF_CTRLA, iface_areg);
  922. snd_soc_write(codec, AIC3X_ASD_INTF_CTRLB, iface_breg);
  923. snd_soc_write(codec, AIC3X_ASD_INTF_CTRLC, delay);
  924. return 0;
  925. }
  926. static int aic3x_init_3007(struct snd_soc_codec *codec)
  927. {
  928. unsigned int tmp1, tmp2;
  929. /*
  930. * There is no need to cache writes to undocumented page 0xD but
  931. * respective page 0 register cache entries must be preserved
  932. */
  933. tmp1 = snd_soc_read(codec, 0xD);
  934. tmp2 = snd_soc_read(codec, 0x8);
  935. /* Class-D speaker driver init; datasheet p. 46 */
  936. snd_soc_write(codec, AIC3X_PAGE_SELECT, 0x0D);
  937. snd_soc_write(codec, 0xD, 0x0D);
  938. snd_soc_write(codec, 0x8, 0x5C);
  939. snd_soc_write(codec, 0x8, 0x5D);
  940. snd_soc_write(codec, 0x8, 0x5C);
  941. snd_soc_write(codec, AIC3X_PAGE_SELECT, 0x00);
  942. snd_soc_write(codec, 0xD, tmp1);
  943. snd_soc_write(codec, 0x8, tmp2);
  944. return 0;
  945. }
  946. static int aic3x_regulator_event(struct notifier_block *nb,
  947. unsigned long event, void *data)
  948. {
  949. struct aic3x_disable_nb *disable_nb =
  950. container_of(nb, struct aic3x_disable_nb, nb);
  951. struct aic3x_priv *aic3x = disable_nb->aic3x;
  952. if (event & REGULATOR_EVENT_DISABLE) {
  953. /*
  954. * Put codec to reset and require cache sync as at least one
  955. * of the supplies was disabled
  956. */
  957. if (gpio_is_valid(aic3x->gpio_reset))
  958. gpio_set_value(aic3x->gpio_reset, 0);
  959. aic3x->codec->cache_sync = 1;
  960. }
  961. return 0;
  962. }
  963. static int aic3x_set_power(struct snd_soc_codec *codec, int power)
  964. {
  965. struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec);
  966. int i, ret;
  967. u8 *cache = codec->reg_cache;
  968. if (power) {
  969. ret = regulator_bulk_enable(ARRAY_SIZE(aic3x->supplies),
  970. aic3x->supplies);
  971. if (ret)
  972. goto out;
  973. aic3x->power = 1;
  974. /*
  975. * Reset release and cache sync is necessary only if some
  976. * supply was off or if there were cached writes
  977. */
  978. if (!codec->cache_sync)
  979. goto out;
  980. if (gpio_is_valid(aic3x->gpio_reset)) {
  981. udelay(1);
  982. gpio_set_value(aic3x->gpio_reset, 1);
  983. }
  984. /* Sync reg_cache with the hardware */
  985. codec->cache_only = 0;
  986. for (i = AIC3X_SAMPLE_RATE_SEL_REG; i < ARRAY_SIZE(aic3x_reg); i++)
  987. snd_soc_write(codec, i, cache[i]);
  988. if (aic3x->model == AIC3X_MODEL_3007)
  989. aic3x_init_3007(codec);
  990. codec->cache_sync = 0;
  991. } else {
  992. /*
  993. * Do soft reset to this codec instance in order to clear
  994. * possible VDD leakage currents in case the supply regulators
  995. * remain on
  996. */
  997. snd_soc_write(codec, AIC3X_RESET, SOFT_RESET);
  998. codec->cache_sync = 1;
  999. aic3x->power = 0;
  1000. /* HW writes are needless when bias is off */
  1001. codec->cache_only = 1;
  1002. ret = regulator_bulk_disable(ARRAY_SIZE(aic3x->supplies),
  1003. aic3x->supplies);
  1004. }
  1005. out:
  1006. return ret;
  1007. }
  1008. static int aic3x_set_bias_level(struct snd_soc_codec *codec,
  1009. enum snd_soc_bias_level level)
  1010. {
  1011. struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec);
  1012. switch (level) {
  1013. case SND_SOC_BIAS_ON:
  1014. break;
  1015. case SND_SOC_BIAS_PREPARE:
  1016. if (codec->dapm.bias_level == SND_SOC_BIAS_STANDBY &&
  1017. aic3x->master) {
  1018. /* enable pll */
  1019. snd_soc_update_bits(codec, AIC3X_PLL_PROGA_REG,
  1020. PLL_ENABLE, PLL_ENABLE);
  1021. }
  1022. break;
  1023. case SND_SOC_BIAS_STANDBY:
  1024. if (!aic3x->power)
  1025. aic3x_set_power(codec, 1);
  1026. if (codec->dapm.bias_level == SND_SOC_BIAS_PREPARE &&
  1027. aic3x->master) {
  1028. /* disable pll */
  1029. snd_soc_update_bits(codec, AIC3X_PLL_PROGA_REG,
  1030. PLL_ENABLE, 0);
  1031. }
  1032. break;
  1033. case SND_SOC_BIAS_OFF:
  1034. if (aic3x->power)
  1035. aic3x_set_power(codec, 0);
  1036. break;
  1037. }
  1038. codec->dapm.bias_level = level;
  1039. return 0;
  1040. }
  1041. #define AIC3X_RATES SNDRV_PCM_RATE_8000_96000
  1042. #define AIC3X_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
  1043. SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S32_LE)
  1044. static const struct snd_soc_dai_ops aic3x_dai_ops = {
  1045. .hw_params = aic3x_hw_params,
  1046. .digital_mute = aic3x_mute,
  1047. .set_sysclk = aic3x_set_dai_sysclk,
  1048. .set_fmt = aic3x_set_dai_fmt,
  1049. };
  1050. static struct snd_soc_dai_driver aic3x_dai = {
  1051. .name = "tlv320aic3x-hifi",
  1052. .playback = {
  1053. .stream_name = "Playback",
  1054. .channels_min = 2,
  1055. .channels_max = 2,
  1056. .rates = AIC3X_RATES,
  1057. .formats = AIC3X_FORMATS,},
  1058. .capture = {
  1059. .stream_name = "Capture",
  1060. .channels_min = 2,
  1061. .channels_max = 2,
  1062. .rates = AIC3X_RATES,
  1063. .formats = AIC3X_FORMATS,},
  1064. .ops = &aic3x_dai_ops,
  1065. .symmetric_rates = 1,
  1066. };
  1067. static int aic3x_suspend(struct snd_soc_codec *codec)
  1068. {
  1069. aic3x_set_bias_level(codec, SND_SOC_BIAS_OFF);
  1070. return 0;
  1071. }
  1072. static int aic3x_resume(struct snd_soc_codec *codec)
  1073. {
  1074. aic3x_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
  1075. return 0;
  1076. }
  1077. /*
  1078. * initialise the AIC3X driver
  1079. * register the mixer and dsp interfaces with the kernel
  1080. */
  1081. static int aic3x_init(struct snd_soc_codec *codec)
  1082. {
  1083. struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec);
  1084. snd_soc_write(codec, AIC3X_PAGE_SELECT, PAGE0_SELECT);
  1085. snd_soc_write(codec, AIC3X_RESET, SOFT_RESET);
  1086. /* DAC default volume and mute */
  1087. snd_soc_write(codec, LDAC_VOL, DEFAULT_VOL | MUTE_ON);
  1088. snd_soc_write(codec, RDAC_VOL, DEFAULT_VOL | MUTE_ON);
  1089. /* DAC to HP default volume and route to Output mixer */
  1090. snd_soc_write(codec, DACL1_2_HPLOUT_VOL, DEFAULT_VOL | ROUTE_ON);
  1091. snd_soc_write(codec, DACR1_2_HPROUT_VOL, DEFAULT_VOL | ROUTE_ON);
  1092. snd_soc_write(codec, DACL1_2_HPLCOM_VOL, DEFAULT_VOL | ROUTE_ON);
  1093. snd_soc_write(codec, DACR1_2_HPRCOM_VOL, DEFAULT_VOL | ROUTE_ON);
  1094. /* DAC to Line Out default volume and route to Output mixer */
  1095. snd_soc_write(codec, DACL1_2_LLOPM_VOL, DEFAULT_VOL | ROUTE_ON);
  1096. snd_soc_write(codec, DACR1_2_RLOPM_VOL, DEFAULT_VOL | ROUTE_ON);
  1097. /* DAC to Mono Line Out default volume and route to Output mixer */
  1098. snd_soc_write(codec, DACL1_2_MONOLOPM_VOL, DEFAULT_VOL | ROUTE_ON);
  1099. snd_soc_write(codec, DACR1_2_MONOLOPM_VOL, DEFAULT_VOL | ROUTE_ON);
  1100. /* unmute all outputs */
  1101. snd_soc_update_bits(codec, LLOPM_CTRL, UNMUTE, UNMUTE);
  1102. snd_soc_update_bits(codec, RLOPM_CTRL, UNMUTE, UNMUTE);
  1103. snd_soc_update_bits(codec, MONOLOPM_CTRL, UNMUTE, UNMUTE);
  1104. snd_soc_update_bits(codec, HPLOUT_CTRL, UNMUTE, UNMUTE);
  1105. snd_soc_update_bits(codec, HPROUT_CTRL, UNMUTE, UNMUTE);
  1106. snd_soc_update_bits(codec, HPLCOM_CTRL, UNMUTE, UNMUTE);
  1107. snd_soc_update_bits(codec, HPRCOM_CTRL, UNMUTE, UNMUTE);
  1108. /* ADC default volume and unmute */
  1109. snd_soc_write(codec, LADC_VOL, DEFAULT_GAIN);
  1110. snd_soc_write(codec, RADC_VOL, DEFAULT_GAIN);
  1111. /* By default route Line1 to ADC PGA mixer */
  1112. snd_soc_write(codec, LINE1L_2_LADC_CTRL, 0x0);
  1113. snd_soc_write(codec, LINE1R_2_RADC_CTRL, 0x0);
  1114. /* PGA to HP Bypass default volume, disconnect from Output Mixer */
  1115. snd_soc_write(codec, PGAL_2_HPLOUT_VOL, DEFAULT_VOL);
  1116. snd_soc_write(codec, PGAR_2_HPROUT_VOL, DEFAULT_VOL);
  1117. snd_soc_write(codec, PGAL_2_HPLCOM_VOL, DEFAULT_VOL);
  1118. snd_soc_write(codec, PGAR_2_HPRCOM_VOL, DEFAULT_VOL);
  1119. /* PGA to Line Out default volume, disconnect from Output Mixer */
  1120. snd_soc_write(codec, PGAL_2_LLOPM_VOL, DEFAULT_VOL);
  1121. snd_soc_write(codec, PGAR_2_RLOPM_VOL, DEFAULT_VOL);
  1122. /* PGA to Mono Line Out default volume, disconnect from Output Mixer */
  1123. snd_soc_write(codec, PGAL_2_MONOLOPM_VOL, DEFAULT_VOL);
  1124. snd_soc_write(codec, PGAR_2_MONOLOPM_VOL, DEFAULT_VOL);
  1125. /* Line2 to HP Bypass default volume, disconnect from Output Mixer */
  1126. snd_soc_write(codec, LINE2L_2_HPLOUT_VOL, DEFAULT_VOL);
  1127. snd_soc_write(codec, LINE2R_2_HPROUT_VOL, DEFAULT_VOL);
  1128. snd_soc_write(codec, LINE2L_2_HPLCOM_VOL, DEFAULT_VOL);
  1129. snd_soc_write(codec, LINE2R_2_HPRCOM_VOL, DEFAULT_VOL);
  1130. /* Line2 Line Out default volume, disconnect from Output Mixer */
  1131. snd_soc_write(codec, LINE2L_2_LLOPM_VOL, DEFAULT_VOL);
  1132. snd_soc_write(codec, LINE2R_2_RLOPM_VOL, DEFAULT_VOL);
  1133. /* Line2 to Mono Out default volume, disconnect from Output Mixer */
  1134. snd_soc_write(codec, LINE2L_2_MONOLOPM_VOL, DEFAULT_VOL);
  1135. snd_soc_write(codec, LINE2R_2_MONOLOPM_VOL, DEFAULT_VOL);
  1136. if (aic3x->model == AIC3X_MODEL_3007) {
  1137. aic3x_init_3007(codec);
  1138. snd_soc_write(codec, CLASSD_CTRL, 0);
  1139. }
  1140. return 0;
  1141. }
  1142. static bool aic3x_is_shared_reset(struct aic3x_priv *aic3x)
  1143. {
  1144. struct aic3x_priv *a;
  1145. list_for_each_entry(a, &reset_list, list) {
  1146. if (gpio_is_valid(aic3x->gpio_reset) &&
  1147. aic3x->gpio_reset == a->gpio_reset)
  1148. return true;
  1149. }
  1150. return false;
  1151. }
  1152. static int aic3x_probe(struct snd_soc_codec *codec)
  1153. {
  1154. struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec);
  1155. int ret, i;
  1156. INIT_LIST_HEAD(&aic3x->list);
  1157. aic3x->codec = codec;
  1158. ret = snd_soc_codec_set_cache_io(codec, 8, 8, aic3x->control_type);
  1159. if (ret != 0) {
  1160. dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
  1161. return ret;
  1162. }
  1163. for (i = 0; i < ARRAY_SIZE(aic3x->supplies); i++) {
  1164. aic3x->disable_nb[i].nb.notifier_call = aic3x_regulator_event;
  1165. aic3x->disable_nb[i].aic3x = aic3x;
  1166. ret = regulator_register_notifier(aic3x->supplies[i].consumer,
  1167. &aic3x->disable_nb[i].nb);
  1168. if (ret) {
  1169. dev_err(codec->dev,
  1170. "Failed to request regulator notifier: %d\n",
  1171. ret);
  1172. goto err_notif;
  1173. }
  1174. }
  1175. codec->cache_only = 1;
  1176. aic3x_init(codec);
  1177. if (aic3x->setup) {
  1178. /* setup GPIO functions */
  1179. snd_soc_write(codec, AIC3X_GPIO1_REG,
  1180. (aic3x->setup->gpio_func[0] & 0xf) << 4);
  1181. snd_soc_write(codec, AIC3X_GPIO2_REG,
  1182. (aic3x->setup->gpio_func[1] & 0xf) << 4);
  1183. }
  1184. if (aic3x->model == AIC3X_MODEL_3007)
  1185. snd_soc_add_codec_controls(codec, &aic3x_classd_amp_gain_ctrl, 1);
  1186. /* set mic bias voltage */
  1187. switch (aic3x->micbias_vg) {
  1188. case AIC3X_MICBIAS_2_0V:
  1189. case AIC3X_MICBIAS_2_5V:
  1190. case AIC3X_MICBIAS_AVDDV:
  1191. snd_soc_update_bits(codec, MICBIAS_CTRL,
  1192. MICBIAS_LEVEL_MASK,
  1193. (aic3x->micbias_vg) << MICBIAS_LEVEL_SHIFT);
  1194. break;
  1195. case AIC3X_MICBIAS_OFF:
  1196. /*
  1197. * noting to do. target won't enter here. This is just to avoid
  1198. * compile time warning "warning: enumeration value
  1199. * 'AIC3X_MICBIAS_OFF' not handled in switch"
  1200. */
  1201. break;
  1202. }
  1203. aic3x_add_widgets(codec);
  1204. list_add(&aic3x->list, &reset_list);
  1205. return 0;
  1206. err_notif:
  1207. while (i--)
  1208. regulator_unregister_notifier(aic3x->supplies[i].consumer,
  1209. &aic3x->disable_nb[i].nb);
  1210. return ret;
  1211. }
  1212. static int aic3x_remove(struct snd_soc_codec *codec)
  1213. {
  1214. struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec);
  1215. int i;
  1216. aic3x_set_bias_level(codec, SND_SOC_BIAS_OFF);
  1217. list_del(&aic3x->list);
  1218. for (i = 0; i < ARRAY_SIZE(aic3x->supplies); i++)
  1219. regulator_unregister_notifier(aic3x->supplies[i].consumer,
  1220. &aic3x->disable_nb[i].nb);
  1221. return 0;
  1222. }
  1223. static struct snd_soc_codec_driver soc_codec_dev_aic3x = {
  1224. .set_bias_level = aic3x_set_bias_level,
  1225. .idle_bias_off = true,
  1226. .reg_cache_size = ARRAY_SIZE(aic3x_reg),
  1227. .reg_word_size = sizeof(u8),
  1228. .reg_cache_default = aic3x_reg,
  1229. .probe = aic3x_probe,
  1230. .remove = aic3x_remove,
  1231. .suspend = aic3x_suspend,
  1232. .resume = aic3x_resume,
  1233. .controls = aic3x_snd_controls,
  1234. .num_controls = ARRAY_SIZE(aic3x_snd_controls),
  1235. .dapm_widgets = aic3x_dapm_widgets,
  1236. .num_dapm_widgets = ARRAY_SIZE(aic3x_dapm_widgets),
  1237. .dapm_routes = intercon,
  1238. .num_dapm_routes = ARRAY_SIZE(intercon),
  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");