tlv320aic3x.c 50 KB

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