tlv320aic3x.c 52 KB

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