tlv320aic3x.c 51 KB

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