tlv320aic3x.c 51 KB

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