tlv320aic3x.c 51 KB

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