tlv320aic3x.c 47 KB

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