tlv320aic3x.c 47 KB

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