tlv320aic3x.c 48 KB

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