tlv320aic3x.c 51 KB

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