tlv320aic3x.c 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469
  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. static const struct snd_soc_dapm_widget aic3007_dapm_widgets[] = {
  541. /* Class-D outputs */
  542. SND_SOC_DAPM_PGA("Left Class-D Out", CLASSD_CTRL, 3, 0, NULL, 0),
  543. SND_SOC_DAPM_PGA("Right Class-D Out", CLASSD_CTRL, 2, 0, NULL, 0),
  544. SND_SOC_DAPM_OUTPUT("SPOP"),
  545. SND_SOC_DAPM_OUTPUT("SPOM"),
  546. };
  547. static const struct snd_soc_dapm_route intercon[] = {
  548. /* Left Input */
  549. {"Left Line1L Mux", "single-ended", "LINE1L"},
  550. {"Left Line1L Mux", "differential", "LINE1L"},
  551. {"Left Line2L Mux", "single-ended", "LINE2L"},
  552. {"Left Line2L Mux", "differential", "LINE2L"},
  553. {"Left PGA Mixer", "Line1L Switch", "Left Line1L Mux"},
  554. {"Left PGA Mixer", "Line1R Switch", "Left Line1R Mux"},
  555. {"Left PGA Mixer", "Line2L Switch", "Left Line2L Mux"},
  556. {"Left PGA Mixer", "Mic3L Switch", "MIC3L"},
  557. {"Left PGA Mixer", "Mic3R Switch", "MIC3R"},
  558. {"Left ADC", NULL, "Left PGA Mixer"},
  559. {"Left ADC", NULL, "GPIO1 dmic modclk"},
  560. /* Right Input */
  561. {"Right Line1R Mux", "single-ended", "LINE1R"},
  562. {"Right Line1R Mux", "differential", "LINE1R"},
  563. {"Right Line2R Mux", "single-ended", "LINE2R"},
  564. {"Right Line2R Mux", "differential", "LINE2R"},
  565. {"Right PGA Mixer", "Line1L Switch", "Right Line1L Mux"},
  566. {"Right PGA Mixer", "Line1R Switch", "Right Line1R Mux"},
  567. {"Right PGA Mixer", "Line2R Switch", "Right Line2R Mux"},
  568. {"Right PGA Mixer", "Mic3L Switch", "MIC3L"},
  569. {"Right PGA Mixer", "Mic3R Switch", "MIC3R"},
  570. {"Right ADC", NULL, "Right PGA Mixer"},
  571. {"Right ADC", NULL, "GPIO1 dmic modclk"},
  572. /*
  573. * Logical path between digital mic enable and GPIO1 modulator clock
  574. * output function
  575. */
  576. {"GPIO1 dmic modclk", NULL, "DMic Rate 128"},
  577. {"GPIO1 dmic modclk", NULL, "DMic Rate 64"},
  578. {"GPIO1 dmic modclk", NULL, "DMic Rate 32"},
  579. /* Left DAC Output */
  580. {"Left DAC Mux", "DAC_L1", "Left DAC"},
  581. {"Left DAC Mux", "DAC_L2", "Left DAC"},
  582. {"Left DAC Mux", "DAC_L3", "Left DAC"},
  583. /* Right DAC Output */
  584. {"Right DAC Mux", "DAC_R1", "Right DAC"},
  585. {"Right DAC Mux", "DAC_R2", "Right DAC"},
  586. {"Right DAC Mux", "DAC_R3", "Right DAC"},
  587. /* Left Line Output */
  588. {"Left Line Mixer", "Line2L Bypass Switch", "Left Line2L Mux"},
  589. {"Left Line Mixer", "PGAL Bypass Switch", "Left PGA Mixer"},
  590. {"Left Line Mixer", "DACL1 Switch", "Left DAC Mux"},
  591. {"Left Line Mixer", "Line2R Bypass Switch", "Right Line2R Mux"},
  592. {"Left Line Mixer", "PGAR Bypass Switch", "Right PGA Mixer"},
  593. {"Left Line Mixer", "DACR1 Switch", "Right DAC Mux"},
  594. {"Left Line Out", NULL, "Left Line Mixer"},
  595. {"Left Line Out", NULL, "Left DAC Mux"},
  596. {"LLOUT", NULL, "Left Line Out"},
  597. /* Right Line Output */
  598. {"Right Line Mixer", "Line2L Bypass Switch", "Left Line2L Mux"},
  599. {"Right Line Mixer", "PGAL Bypass Switch", "Left PGA Mixer"},
  600. {"Right Line Mixer", "DACL1 Switch", "Left DAC Mux"},
  601. {"Right Line Mixer", "Line2R Bypass Switch", "Right Line2R Mux"},
  602. {"Right Line Mixer", "PGAR Bypass Switch", "Right PGA Mixer"},
  603. {"Right Line Mixer", "DACR1 Switch", "Right DAC Mux"},
  604. {"Right Line Out", NULL, "Right Line Mixer"},
  605. {"Right Line Out", NULL, "Right DAC Mux"},
  606. {"RLOUT", NULL, "Right Line Out"},
  607. /* Mono Output */
  608. {"Mono Mixer", "Line2L Bypass Switch", "Left Line2L Mux"},
  609. {"Mono Mixer", "PGAL Bypass Switch", "Left PGA Mixer"},
  610. {"Mono Mixer", "DACL1 Switch", "Left DAC Mux"},
  611. {"Mono Mixer", "Line2R Bypass Switch", "Right Line2R Mux"},
  612. {"Mono Mixer", "PGAR Bypass Switch", "Right PGA Mixer"},
  613. {"Mono Mixer", "DACR1 Switch", "Right DAC Mux"},
  614. {"Mono Out", NULL, "Mono Mixer"},
  615. {"MONO_LOUT", NULL, "Mono Out"},
  616. /* Left HP Output */
  617. {"Left HP Mixer", "Line2L Bypass Switch", "Left Line2L Mux"},
  618. {"Left HP Mixer", "PGAL Bypass Switch", "Left PGA Mixer"},
  619. {"Left HP Mixer", "DACL1 Switch", "Left DAC Mux"},
  620. {"Left HP Mixer", "Line2R Bypass Switch", "Right Line2R Mux"},
  621. {"Left HP Mixer", "PGAR Bypass Switch", "Right PGA Mixer"},
  622. {"Left HP Mixer", "DACR1 Switch", "Right DAC Mux"},
  623. {"Left HP Out", NULL, "Left HP Mixer"},
  624. {"Left HP Out", NULL, "Left DAC Mux"},
  625. {"HPLOUT", NULL, "Left HP Out"},
  626. /* Right HP Output */
  627. {"Right HP Mixer", "Line2L Bypass Switch", "Left Line2L Mux"},
  628. {"Right HP Mixer", "PGAL Bypass Switch", "Left PGA Mixer"},
  629. {"Right HP Mixer", "DACL1 Switch", "Left DAC Mux"},
  630. {"Right HP Mixer", "Line2R Bypass Switch", "Right Line2R Mux"},
  631. {"Right HP Mixer", "PGAR Bypass Switch", "Right PGA Mixer"},
  632. {"Right HP Mixer", "DACR1 Switch", "Right DAC Mux"},
  633. {"Right HP Out", NULL, "Right HP Mixer"},
  634. {"Right HP Out", NULL, "Right DAC Mux"},
  635. {"HPROUT", NULL, "Right HP Out"},
  636. /* Left HPCOM Output */
  637. {"Left HPCOM Mixer", "Line2L Bypass Switch", "Left Line2L Mux"},
  638. {"Left HPCOM Mixer", "PGAL Bypass Switch", "Left PGA Mixer"},
  639. {"Left HPCOM Mixer", "DACL1 Switch", "Left DAC Mux"},
  640. {"Left HPCOM Mixer", "Line2R Bypass Switch", "Right Line2R Mux"},
  641. {"Left HPCOM Mixer", "PGAR Bypass Switch", "Right PGA Mixer"},
  642. {"Left HPCOM Mixer", "DACR1 Switch", "Right DAC Mux"},
  643. {"Left HPCOM Mux", "differential of HPLOUT", "Left HP Mixer"},
  644. {"Left HPCOM Mux", "constant VCM", "Left HPCOM Mixer"},
  645. {"Left HPCOM Mux", "single-ended", "Left HPCOM Mixer"},
  646. {"Left HP Com", NULL, "Left HPCOM Mux"},
  647. {"HPLCOM", NULL, "Left HP Com"},
  648. /* Right HPCOM Output */
  649. {"Right HPCOM Mixer", "Line2L Bypass Switch", "Left Line2L Mux"},
  650. {"Right HPCOM Mixer", "PGAL Bypass Switch", "Left PGA Mixer"},
  651. {"Right HPCOM Mixer", "DACL1 Switch", "Left DAC Mux"},
  652. {"Right HPCOM Mixer", "Line2R Bypass Switch", "Right Line2R Mux"},
  653. {"Right HPCOM Mixer", "PGAR Bypass Switch", "Right PGA Mixer"},
  654. {"Right HPCOM Mixer", "DACR1 Switch", "Right DAC Mux"},
  655. {"Right HPCOM Mux", "differential of HPROUT", "Right HP Mixer"},
  656. {"Right HPCOM Mux", "constant VCM", "Right HPCOM Mixer"},
  657. {"Right HPCOM Mux", "single-ended", "Right HPCOM Mixer"},
  658. {"Right HPCOM Mux", "differential of HPLCOM", "Left HPCOM Mixer"},
  659. {"Right HPCOM Mux", "external feedback", "Right HPCOM Mixer"},
  660. {"Right HP Com", NULL, "Right HPCOM Mux"},
  661. {"HPRCOM", NULL, "Right HP Com"},
  662. };
  663. static const struct snd_soc_dapm_route intercon_3007[] = {
  664. /* Class-D outputs */
  665. {"Left Class-D Out", NULL, "Left Line Out"},
  666. {"Right Class-D Out", NULL, "Left Line Out"},
  667. {"SPOP", NULL, "Left Class-D Out"},
  668. {"SPOM", NULL, "Right Class-D Out"},
  669. };
  670. static int aic3x_add_widgets(struct snd_soc_codec *codec)
  671. {
  672. struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec);
  673. snd_soc_dapm_new_controls(codec, aic3x_dapm_widgets,
  674. ARRAY_SIZE(aic3x_dapm_widgets));
  675. /* set up audio path interconnects */
  676. snd_soc_dapm_add_routes(codec, intercon, ARRAY_SIZE(intercon));
  677. if (aic3x->model == AIC3X_MODEL_3007) {
  678. snd_soc_dapm_new_controls(codec, aic3007_dapm_widgets,
  679. ARRAY_SIZE(aic3007_dapm_widgets));
  680. snd_soc_dapm_add_routes(codec, intercon_3007, ARRAY_SIZE(intercon_3007));
  681. }
  682. return 0;
  683. }
  684. static int aic3x_hw_params(struct snd_pcm_substream *substream,
  685. struct snd_pcm_hw_params *params,
  686. struct snd_soc_dai *dai)
  687. {
  688. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  689. struct snd_soc_codec *codec =rtd->codec;
  690. struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec);
  691. int codec_clk = 0, bypass_pll = 0, fsref, last_clk = 0;
  692. u8 data, j, r, p, pll_q, pll_p = 1, pll_r = 1, pll_j = 1;
  693. u16 d, pll_d = 1;
  694. u8 reg;
  695. int clk;
  696. /* select data word length */
  697. data = snd_soc_read(codec, AIC3X_ASD_INTF_CTRLB) & (~(0x3 << 4));
  698. switch (params_format(params)) {
  699. case SNDRV_PCM_FORMAT_S16_LE:
  700. break;
  701. case SNDRV_PCM_FORMAT_S20_3LE:
  702. data |= (0x01 << 4);
  703. break;
  704. case SNDRV_PCM_FORMAT_S24_LE:
  705. data |= (0x02 << 4);
  706. break;
  707. case SNDRV_PCM_FORMAT_S32_LE:
  708. data |= (0x03 << 4);
  709. break;
  710. }
  711. snd_soc_write(codec, AIC3X_ASD_INTF_CTRLB, data);
  712. /* Fsref can be 44100 or 48000 */
  713. fsref = (params_rate(params) % 11025 == 0) ? 44100 : 48000;
  714. /* Try to find a value for Q which allows us to bypass the PLL and
  715. * generate CODEC_CLK directly. */
  716. for (pll_q = 2; pll_q < 18; pll_q++)
  717. if (aic3x->sysclk / (128 * pll_q) == fsref) {
  718. bypass_pll = 1;
  719. break;
  720. }
  721. if (bypass_pll) {
  722. pll_q &= 0xf;
  723. snd_soc_write(codec, AIC3X_PLL_PROGA_REG, pll_q << PLLQ_SHIFT);
  724. snd_soc_write(codec, AIC3X_GPIOB_REG, CODEC_CLKIN_CLKDIV);
  725. /* disable PLL if it is bypassed */
  726. reg = snd_soc_read(codec, AIC3X_PLL_PROGA_REG);
  727. snd_soc_write(codec, AIC3X_PLL_PROGA_REG, reg & ~PLL_ENABLE);
  728. } else {
  729. snd_soc_write(codec, AIC3X_GPIOB_REG, CODEC_CLKIN_PLLDIV);
  730. /* enable PLL when it is used */
  731. reg = snd_soc_read(codec, AIC3X_PLL_PROGA_REG);
  732. snd_soc_write(codec, AIC3X_PLL_PROGA_REG, reg | PLL_ENABLE);
  733. }
  734. /* Route Left DAC to left channel input and
  735. * right DAC to right channel input */
  736. data = (LDAC2LCH | RDAC2RCH);
  737. data |= (fsref == 44100) ? FSREF_44100 : FSREF_48000;
  738. if (params_rate(params) >= 64000)
  739. data |= DUAL_RATE_MODE;
  740. snd_soc_write(codec, AIC3X_CODEC_DATAPATH_REG, data);
  741. /* codec sample rate select */
  742. data = (fsref * 20) / params_rate(params);
  743. if (params_rate(params) < 64000)
  744. data /= 2;
  745. data /= 5;
  746. data -= 2;
  747. data |= (data << 4);
  748. snd_soc_write(codec, AIC3X_SAMPLE_RATE_SEL_REG, data);
  749. if (bypass_pll)
  750. return 0;
  751. /* Use PLL, compute apropriate setup for j, d, r and p, the closest
  752. * one wins the game. Try with d==0 first, next with d!=0.
  753. * Constraints for j are according to the datasheet.
  754. * The sysclk is divided by 1000 to prevent integer overflows.
  755. */
  756. codec_clk = (2048 * fsref) / (aic3x->sysclk / 1000);
  757. for (r = 1; r <= 16; r++)
  758. for (p = 1; p <= 8; p++) {
  759. for (j = 4; j <= 55; j++) {
  760. /* This is actually 1000*((j+(d/10000))*r)/p
  761. * The term had to be converted to get
  762. * rid of the division by 10000; d = 0 here
  763. */
  764. int tmp_clk = (1000 * j * r) / p;
  765. /* Check whether this values get closer than
  766. * the best ones we had before
  767. */
  768. if (abs(codec_clk - tmp_clk) <
  769. abs(codec_clk - last_clk)) {
  770. pll_j = j; pll_d = 0;
  771. pll_r = r; pll_p = p;
  772. last_clk = tmp_clk;
  773. }
  774. /* Early exit for exact matches */
  775. if (tmp_clk == codec_clk)
  776. goto found;
  777. }
  778. }
  779. /* try with d != 0 */
  780. for (p = 1; p <= 8; p++) {
  781. j = codec_clk * p / 1000;
  782. if (j < 4 || j > 11)
  783. continue;
  784. /* do not use codec_clk here since we'd loose precision */
  785. d = ((2048 * p * fsref) - j * aic3x->sysclk)
  786. * 100 / (aic3x->sysclk/100);
  787. clk = (10000 * j + d) / (10 * p);
  788. /* check whether this values get closer than the best
  789. * ones we had before */
  790. if (abs(codec_clk - clk) < abs(codec_clk - last_clk)) {
  791. pll_j = j; pll_d = d; pll_r = 1; pll_p = p;
  792. last_clk = clk;
  793. }
  794. /* Early exit for exact matches */
  795. if (clk == codec_clk)
  796. goto found;
  797. }
  798. if (last_clk == 0) {
  799. printk(KERN_ERR "%s(): unable to setup PLL\n", __func__);
  800. return -EINVAL;
  801. }
  802. found:
  803. data = snd_soc_read(codec, AIC3X_PLL_PROGA_REG);
  804. snd_soc_write(codec, AIC3X_PLL_PROGA_REG,
  805. data | (pll_p << PLLP_SHIFT));
  806. snd_soc_write(codec, AIC3X_OVRF_STATUS_AND_PLLR_REG,
  807. pll_r << PLLR_SHIFT);
  808. snd_soc_write(codec, AIC3X_PLL_PROGB_REG, pll_j << PLLJ_SHIFT);
  809. snd_soc_write(codec, AIC3X_PLL_PROGC_REG,
  810. (pll_d >> 6) << PLLD_MSB_SHIFT);
  811. snd_soc_write(codec, AIC3X_PLL_PROGD_REG,
  812. (pll_d & 0x3F) << PLLD_LSB_SHIFT);
  813. return 0;
  814. }
  815. static int aic3x_mute(struct snd_soc_dai *dai, int mute)
  816. {
  817. struct snd_soc_codec *codec = dai->codec;
  818. u8 ldac_reg = snd_soc_read(codec, LDAC_VOL) & ~MUTE_ON;
  819. u8 rdac_reg = snd_soc_read(codec, RDAC_VOL) & ~MUTE_ON;
  820. if (mute) {
  821. snd_soc_write(codec, LDAC_VOL, ldac_reg | MUTE_ON);
  822. snd_soc_write(codec, RDAC_VOL, rdac_reg | MUTE_ON);
  823. } else {
  824. snd_soc_write(codec, LDAC_VOL, ldac_reg);
  825. snd_soc_write(codec, RDAC_VOL, rdac_reg);
  826. }
  827. return 0;
  828. }
  829. static int aic3x_set_dai_sysclk(struct snd_soc_dai *codec_dai,
  830. int clk_id, unsigned int freq, int dir)
  831. {
  832. struct snd_soc_codec *codec = codec_dai->codec;
  833. struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec);
  834. aic3x->sysclk = freq;
  835. return 0;
  836. }
  837. static int aic3x_set_dai_fmt(struct snd_soc_dai *codec_dai,
  838. unsigned int fmt)
  839. {
  840. struct snd_soc_codec *codec = codec_dai->codec;
  841. struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec);
  842. u8 iface_areg, iface_breg;
  843. int delay = 0;
  844. iface_areg = snd_soc_read(codec, AIC3X_ASD_INTF_CTRLA) & 0x3f;
  845. iface_breg = snd_soc_read(codec, AIC3X_ASD_INTF_CTRLB) & 0x3f;
  846. /* set master/slave audio interface */
  847. switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  848. case SND_SOC_DAIFMT_CBM_CFM:
  849. aic3x->master = 1;
  850. iface_areg |= BIT_CLK_MASTER | WORD_CLK_MASTER;
  851. break;
  852. case SND_SOC_DAIFMT_CBS_CFS:
  853. aic3x->master = 0;
  854. break;
  855. default:
  856. return -EINVAL;
  857. }
  858. /*
  859. * match both interface format and signal polarities since they
  860. * are fixed
  861. */
  862. switch (fmt & (SND_SOC_DAIFMT_FORMAT_MASK |
  863. SND_SOC_DAIFMT_INV_MASK)) {
  864. case (SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF):
  865. break;
  866. case (SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_IB_NF):
  867. delay = 1;
  868. case (SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_IB_NF):
  869. iface_breg |= (0x01 << 6);
  870. break;
  871. case (SND_SOC_DAIFMT_RIGHT_J | SND_SOC_DAIFMT_NB_NF):
  872. iface_breg |= (0x02 << 6);
  873. break;
  874. case (SND_SOC_DAIFMT_LEFT_J | SND_SOC_DAIFMT_NB_NF):
  875. iface_breg |= (0x03 << 6);
  876. break;
  877. default:
  878. return -EINVAL;
  879. }
  880. /* set iface */
  881. snd_soc_write(codec, AIC3X_ASD_INTF_CTRLA, iface_areg);
  882. snd_soc_write(codec, AIC3X_ASD_INTF_CTRLB, iface_breg);
  883. snd_soc_write(codec, AIC3X_ASD_INTF_CTRLC, delay);
  884. return 0;
  885. }
  886. static int aic3x_set_bias_level(struct snd_soc_codec *codec,
  887. enum snd_soc_bias_level level)
  888. {
  889. struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec);
  890. u8 reg;
  891. switch (level) {
  892. case SND_SOC_BIAS_ON:
  893. break;
  894. case SND_SOC_BIAS_PREPARE:
  895. if (codec->bias_level == SND_SOC_BIAS_STANDBY &&
  896. aic3x->master) {
  897. /* enable pll */
  898. reg = snd_soc_read(codec, AIC3X_PLL_PROGA_REG);
  899. snd_soc_write(codec, AIC3X_PLL_PROGA_REG,
  900. reg | PLL_ENABLE);
  901. }
  902. break;
  903. case SND_SOC_BIAS_STANDBY:
  904. if (codec->bias_level == SND_SOC_BIAS_PREPARE &&
  905. aic3x->master) {
  906. /* disable pll */
  907. reg = snd_soc_read(codec, AIC3X_PLL_PROGA_REG);
  908. snd_soc_write(codec, AIC3X_PLL_PROGA_REG,
  909. reg & ~PLL_ENABLE);
  910. }
  911. break;
  912. case SND_SOC_BIAS_OFF:
  913. break;
  914. }
  915. codec->bias_level = level;
  916. return 0;
  917. }
  918. void aic3x_set_gpio(struct snd_soc_codec *codec, int gpio, int state)
  919. {
  920. u8 reg = gpio ? AIC3X_GPIO2_REG : AIC3X_GPIO1_REG;
  921. u8 bit = gpio ? 3: 0;
  922. u8 val = snd_soc_read(codec, reg) & ~(1 << bit);
  923. snd_soc_write(codec, reg, val | (!!state << bit));
  924. }
  925. EXPORT_SYMBOL_GPL(aic3x_set_gpio);
  926. int aic3x_get_gpio(struct snd_soc_codec *codec, int gpio)
  927. {
  928. u8 reg = gpio ? AIC3X_GPIO2_REG : AIC3X_GPIO1_REG;
  929. u8 val, bit = gpio ? 2: 1;
  930. aic3x_read(codec, reg, &val);
  931. return (val >> bit) & 1;
  932. }
  933. EXPORT_SYMBOL_GPL(aic3x_get_gpio);
  934. void aic3x_set_headset_detection(struct snd_soc_codec *codec, int detect,
  935. int headset_debounce, int button_debounce)
  936. {
  937. u8 val;
  938. val = ((detect & AIC3X_HEADSET_DETECT_MASK)
  939. << AIC3X_HEADSET_DETECT_SHIFT) |
  940. ((headset_debounce & AIC3X_HEADSET_DEBOUNCE_MASK)
  941. << AIC3X_HEADSET_DEBOUNCE_SHIFT) |
  942. ((button_debounce & AIC3X_BUTTON_DEBOUNCE_MASK)
  943. << AIC3X_BUTTON_DEBOUNCE_SHIFT);
  944. if (detect & AIC3X_HEADSET_DETECT_MASK)
  945. val |= AIC3X_HEADSET_DETECT_ENABLED;
  946. snd_soc_write(codec, AIC3X_HEADSET_DETECT_CTRL_A, val);
  947. }
  948. EXPORT_SYMBOL_GPL(aic3x_set_headset_detection);
  949. int aic3x_headset_detected(struct snd_soc_codec *codec)
  950. {
  951. u8 val;
  952. aic3x_read(codec, AIC3X_HEADSET_DETECT_CTRL_B, &val);
  953. return (val >> 4) & 1;
  954. }
  955. EXPORT_SYMBOL_GPL(aic3x_headset_detected);
  956. int aic3x_button_pressed(struct snd_soc_codec *codec)
  957. {
  958. u8 val;
  959. aic3x_read(codec, AIC3X_HEADSET_DETECT_CTRL_B, &val);
  960. return (val >> 5) & 1;
  961. }
  962. EXPORT_SYMBOL_GPL(aic3x_button_pressed);
  963. #define AIC3X_RATES SNDRV_PCM_RATE_8000_96000
  964. #define AIC3X_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
  965. SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S32_LE)
  966. static struct snd_soc_dai_ops aic3x_dai_ops = {
  967. .hw_params = aic3x_hw_params,
  968. .digital_mute = aic3x_mute,
  969. .set_sysclk = aic3x_set_dai_sysclk,
  970. .set_fmt = aic3x_set_dai_fmt,
  971. };
  972. static struct snd_soc_dai_driver aic3x_dai = {
  973. .name = "tlv320aic3x-hifi",
  974. .playback = {
  975. .stream_name = "Playback",
  976. .channels_min = 1,
  977. .channels_max = 2,
  978. .rates = AIC3X_RATES,
  979. .formats = AIC3X_FORMATS,},
  980. .capture = {
  981. .stream_name = "Capture",
  982. .channels_min = 1,
  983. .channels_max = 2,
  984. .rates = AIC3X_RATES,
  985. .formats = AIC3X_FORMATS,},
  986. .ops = &aic3x_dai_ops,
  987. .symmetric_rates = 1,
  988. };
  989. static int aic3x_suspend(struct snd_soc_codec *codec, pm_message_t state)
  990. {
  991. aic3x_set_bias_level(codec, SND_SOC_BIAS_OFF);
  992. return 0;
  993. }
  994. static int aic3x_resume(struct snd_soc_codec *codec)
  995. {
  996. int i;
  997. u8 data[2];
  998. u8 *cache = codec->reg_cache;
  999. /* Sync reg_cache with the hardware */
  1000. for (i = 0; i < ARRAY_SIZE(aic3x_reg); i++) {
  1001. data[0] = i;
  1002. data[1] = cache[i];
  1003. codec->hw_write(codec->control_data, data, 2);
  1004. }
  1005. aic3x_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
  1006. return 0;
  1007. }
  1008. /*
  1009. * initialise the AIC3X driver
  1010. * register the mixer and dsp interfaces with the kernel
  1011. */
  1012. static int aic3x_init(struct snd_soc_codec *codec)
  1013. {
  1014. struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec);
  1015. int reg;
  1016. snd_soc_write(codec, AIC3X_PAGE_SELECT, PAGE0_SELECT);
  1017. snd_soc_write(codec, AIC3X_RESET, SOFT_RESET);
  1018. /* DAC default volume and mute */
  1019. snd_soc_write(codec, LDAC_VOL, DEFAULT_VOL | MUTE_ON);
  1020. snd_soc_write(codec, RDAC_VOL, DEFAULT_VOL | MUTE_ON);
  1021. /* DAC to HP default volume and route to Output mixer */
  1022. snd_soc_write(codec, DACL1_2_HPLOUT_VOL, DEFAULT_VOL | ROUTE_ON);
  1023. snd_soc_write(codec, DACR1_2_HPROUT_VOL, DEFAULT_VOL | ROUTE_ON);
  1024. snd_soc_write(codec, DACL1_2_HPLCOM_VOL, DEFAULT_VOL | ROUTE_ON);
  1025. snd_soc_write(codec, DACR1_2_HPRCOM_VOL, DEFAULT_VOL | ROUTE_ON);
  1026. /* DAC to Line Out default volume and route to Output mixer */
  1027. snd_soc_write(codec, DACL1_2_LLOPM_VOL, DEFAULT_VOL | ROUTE_ON);
  1028. snd_soc_write(codec, DACR1_2_RLOPM_VOL, DEFAULT_VOL | ROUTE_ON);
  1029. /* DAC to Mono Line Out default volume and route to Output mixer */
  1030. snd_soc_write(codec, DACL1_2_MONOLOPM_VOL, DEFAULT_VOL | ROUTE_ON);
  1031. snd_soc_write(codec, DACR1_2_MONOLOPM_VOL, DEFAULT_VOL | ROUTE_ON);
  1032. /* unmute all outputs */
  1033. reg = snd_soc_read(codec, LLOPM_CTRL);
  1034. snd_soc_write(codec, LLOPM_CTRL, reg | UNMUTE);
  1035. reg = snd_soc_read(codec, RLOPM_CTRL);
  1036. snd_soc_write(codec, RLOPM_CTRL, reg | UNMUTE);
  1037. reg = snd_soc_read(codec, MONOLOPM_CTRL);
  1038. snd_soc_write(codec, MONOLOPM_CTRL, reg | UNMUTE);
  1039. reg = snd_soc_read(codec, HPLOUT_CTRL);
  1040. snd_soc_write(codec, HPLOUT_CTRL, reg | UNMUTE);
  1041. reg = snd_soc_read(codec, HPROUT_CTRL);
  1042. snd_soc_write(codec, HPROUT_CTRL, reg | UNMUTE);
  1043. reg = snd_soc_read(codec, HPLCOM_CTRL);
  1044. snd_soc_write(codec, HPLCOM_CTRL, reg | UNMUTE);
  1045. reg = snd_soc_read(codec, HPRCOM_CTRL);
  1046. snd_soc_write(codec, HPRCOM_CTRL, reg | UNMUTE);
  1047. /* ADC default volume and unmute */
  1048. snd_soc_write(codec, LADC_VOL, DEFAULT_GAIN);
  1049. snd_soc_write(codec, RADC_VOL, DEFAULT_GAIN);
  1050. /* By default route Line1 to ADC PGA mixer */
  1051. snd_soc_write(codec, LINE1L_2_LADC_CTRL, 0x0);
  1052. snd_soc_write(codec, LINE1R_2_RADC_CTRL, 0x0);
  1053. /* PGA to HP Bypass default volume, disconnect from Output Mixer */
  1054. snd_soc_write(codec, PGAL_2_HPLOUT_VOL, DEFAULT_VOL);
  1055. snd_soc_write(codec, PGAR_2_HPROUT_VOL, DEFAULT_VOL);
  1056. snd_soc_write(codec, PGAL_2_HPLCOM_VOL, DEFAULT_VOL);
  1057. snd_soc_write(codec, PGAR_2_HPRCOM_VOL, DEFAULT_VOL);
  1058. /* PGA to Line Out default volume, disconnect from Output Mixer */
  1059. snd_soc_write(codec, PGAL_2_LLOPM_VOL, DEFAULT_VOL);
  1060. snd_soc_write(codec, PGAR_2_RLOPM_VOL, DEFAULT_VOL);
  1061. /* PGA to Mono Line Out default volume, disconnect from Output Mixer */
  1062. snd_soc_write(codec, PGAL_2_MONOLOPM_VOL, DEFAULT_VOL);
  1063. snd_soc_write(codec, PGAR_2_MONOLOPM_VOL, DEFAULT_VOL);
  1064. /* Line2 to HP Bypass default volume, disconnect from Output Mixer */
  1065. snd_soc_write(codec, LINE2L_2_HPLOUT_VOL, DEFAULT_VOL);
  1066. snd_soc_write(codec, LINE2R_2_HPROUT_VOL, DEFAULT_VOL);
  1067. snd_soc_write(codec, LINE2L_2_HPLCOM_VOL, DEFAULT_VOL);
  1068. snd_soc_write(codec, LINE2R_2_HPRCOM_VOL, DEFAULT_VOL);
  1069. /* Line2 Line Out default volume, disconnect from Output Mixer */
  1070. snd_soc_write(codec, LINE2L_2_LLOPM_VOL, DEFAULT_VOL);
  1071. snd_soc_write(codec, LINE2R_2_RLOPM_VOL, DEFAULT_VOL);
  1072. /* Line2 to Mono Out default volume, disconnect from Output Mixer */
  1073. snd_soc_write(codec, LINE2L_2_MONOLOPM_VOL, DEFAULT_VOL);
  1074. snd_soc_write(codec, LINE2R_2_MONOLOPM_VOL, DEFAULT_VOL);
  1075. if (aic3x->model == AIC3X_MODEL_3007) {
  1076. /* Class-D speaker driver init; datasheet p. 46 */
  1077. snd_soc_write(codec, AIC3X_PAGE_SELECT, 0x0D);
  1078. snd_soc_write(codec, 0xD, 0x0D);
  1079. snd_soc_write(codec, 0x8, 0x5C);
  1080. snd_soc_write(codec, 0x8, 0x5D);
  1081. snd_soc_write(codec, 0x8, 0x5C);
  1082. snd_soc_write(codec, AIC3X_PAGE_SELECT, 0x00);
  1083. snd_soc_write(codec, CLASSD_CTRL, 0);
  1084. }
  1085. /* off, with power on */
  1086. aic3x_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
  1087. return 0;
  1088. }
  1089. static int aic3x_probe(struct snd_soc_codec *codec)
  1090. {
  1091. struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec);
  1092. int ret;
  1093. codec->control_data = aic3x->control_data;
  1094. ret = snd_soc_codec_set_cache_io(codec, 8, 8, aic3x->control_type);
  1095. if (ret != 0) {
  1096. dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
  1097. return ret;
  1098. }
  1099. aic3x_init(codec);
  1100. if (aic3x->setup) {
  1101. /* setup GPIO functions */
  1102. snd_soc_write(codec, AIC3X_GPIO1_REG,
  1103. (aic3x->setup->gpio_func[0] & 0xf) << 4);
  1104. snd_soc_write(codec, AIC3X_GPIO2_REG,
  1105. (aic3x->setup->gpio_func[1] & 0xf) << 4);
  1106. }
  1107. snd_soc_add_controls(codec, aic3x_snd_controls,
  1108. ARRAY_SIZE(aic3x_snd_controls));
  1109. if (aic3x->model == AIC3X_MODEL_3007)
  1110. snd_soc_add_controls(codec, &aic3x_classd_amp_gain_ctrl, 1);
  1111. aic3x_add_widgets(codec);
  1112. return 0;
  1113. }
  1114. static int aic3x_remove(struct snd_soc_codec *codec)
  1115. {
  1116. aic3x_set_bias_level(codec, SND_SOC_BIAS_OFF);
  1117. return 0;
  1118. }
  1119. static struct snd_soc_codec_driver soc_codec_dev_aic3x = {
  1120. .set_bias_level = aic3x_set_bias_level,
  1121. .reg_cache_size = ARRAY_SIZE(aic3x_reg),
  1122. .reg_word_size = sizeof(u8),
  1123. .reg_cache_default = aic3x_reg,
  1124. .probe = aic3x_probe,
  1125. .remove = aic3x_remove,
  1126. .suspend = aic3x_suspend,
  1127. .resume = aic3x_resume,
  1128. };
  1129. #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
  1130. /*
  1131. * AIC3X 2 wire address can be up to 4 devices with device addresses
  1132. * 0x18, 0x19, 0x1A, 0x1B
  1133. */
  1134. static const struct i2c_device_id aic3x_i2c_id[] = {
  1135. [AIC3X_MODEL_3X] = { "tlv320aic3x", 0 },
  1136. [AIC3X_MODEL_33] = { "tlv320aic33", 0 },
  1137. [AIC3X_MODEL_3007] = { "tlv320aic3007", 0 },
  1138. { }
  1139. };
  1140. MODULE_DEVICE_TABLE(i2c, aic3x_i2c_id);
  1141. /*
  1142. * If the i2c layer weren't so broken, we could pass this kind of data
  1143. * around
  1144. */
  1145. static int aic3x_i2c_probe(struct i2c_client *i2c,
  1146. const struct i2c_device_id *id)
  1147. {
  1148. struct aic3x_pdata *pdata = i2c->dev.platform_data;
  1149. struct aic3x_priv *aic3x;
  1150. int ret, i;
  1151. const struct i2c_device_id *tbl;
  1152. aic3x = kzalloc(sizeof(struct aic3x_priv), GFP_KERNEL);
  1153. if (aic3x == NULL) {
  1154. dev_err(&i2c->dev, "failed to create private data\n");
  1155. return -ENOMEM;
  1156. }
  1157. aic3x->control_data = i2c;
  1158. aic3x->control_type = SND_SOC_I2C;
  1159. i2c_set_clientdata(i2c, aic3x);
  1160. if (pdata) {
  1161. aic3x->gpio_reset = pdata->gpio_reset;
  1162. aic3x->setup = pdata->setup;
  1163. } else {
  1164. aic3x->gpio_reset = -1;
  1165. }
  1166. if (aic3x->gpio_reset >= 0) {
  1167. ret = gpio_request(aic3x->gpio_reset, "tlv320aic3x reset");
  1168. if (ret != 0)
  1169. goto err_gpio;
  1170. gpio_direction_output(aic3x->gpio_reset, 0);
  1171. }
  1172. for (tbl = aic3x_i2c_id; tbl->name[0]; tbl++) {
  1173. if (!strcmp(tbl->name, id->name))
  1174. break;
  1175. }
  1176. aic3x->model = tbl - aic3x_i2c_id;
  1177. for (i = 0; i < ARRAY_SIZE(aic3x->supplies); i++)
  1178. aic3x->supplies[i].supply = aic3x_supply_names[i];
  1179. ret = regulator_bulk_get(&i2c->dev, ARRAY_SIZE(aic3x->supplies),
  1180. aic3x->supplies);
  1181. if (ret != 0) {
  1182. dev_err(&i2c->dev, "Failed to request supplies: %d\n", ret);
  1183. goto err_get;
  1184. }
  1185. ret = regulator_bulk_enable(ARRAY_SIZE(aic3x->supplies),
  1186. aic3x->supplies);
  1187. if (ret != 0) {
  1188. dev_err(&i2c->dev, "Failed to enable supplies: %d\n", ret);
  1189. goto err_enable;
  1190. }
  1191. if (aic3x->gpio_reset >= 0) {
  1192. udelay(1);
  1193. gpio_set_value(aic3x->gpio_reset, 1);
  1194. }
  1195. ret = snd_soc_register_codec(&i2c->dev,
  1196. &soc_codec_dev_aic3x, &aic3x_dai, 1);
  1197. if (ret < 0)
  1198. goto err_enable;
  1199. return ret;
  1200. err_enable:
  1201. regulator_bulk_free(ARRAY_SIZE(aic3x->supplies), aic3x->supplies);
  1202. err_get:
  1203. if (aic3x->gpio_reset >= 0)
  1204. gpio_free(aic3x->gpio_reset);
  1205. err_gpio:
  1206. kfree(aic3x);
  1207. return ret;
  1208. }
  1209. static int aic3x_i2c_remove(struct i2c_client *client)
  1210. {
  1211. struct aic3x_priv *aic3x = i2c_get_clientdata(client);
  1212. if (aic3x->gpio_reset >= 0) {
  1213. gpio_set_value(aic3x->gpio_reset, 0);
  1214. gpio_free(aic3x->gpio_reset);
  1215. }
  1216. regulator_bulk_disable(ARRAY_SIZE(aic3x->supplies), aic3x->supplies);
  1217. regulator_bulk_free(ARRAY_SIZE(aic3x->supplies), aic3x->supplies);
  1218. snd_soc_unregister_codec(&client->dev);
  1219. kfree(i2c_get_clientdata(client));
  1220. return 0;
  1221. }
  1222. /* machine i2c codec control layer */
  1223. static struct i2c_driver aic3x_i2c_driver = {
  1224. .driver = {
  1225. .name = "tlv320aic3x-codec",
  1226. .owner = THIS_MODULE,
  1227. },
  1228. .probe = aic3x_i2c_probe,
  1229. .remove = aic3x_i2c_remove,
  1230. .id_table = aic3x_i2c_id,
  1231. };
  1232. static inline void aic3x_i2c_init(void)
  1233. {
  1234. int ret;
  1235. ret = i2c_add_driver(&aic3x_i2c_driver);
  1236. if (ret)
  1237. printk(KERN_ERR "%s: error regsitering i2c driver, %d\n",
  1238. __func__, ret);
  1239. }
  1240. static inline void aic3x_i2c_exit(void)
  1241. {
  1242. i2c_del_driver(&aic3x_i2c_driver);
  1243. }
  1244. #endif
  1245. static int __init aic3x_modinit(void)
  1246. {
  1247. int ret = 0;
  1248. #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
  1249. ret = i2c_add_driver(&aic3x_i2c_driver);
  1250. if (ret != 0) {
  1251. printk(KERN_ERR "Failed to register TLV320AIC3x I2C driver: %d\n",
  1252. ret);
  1253. }
  1254. #endif
  1255. return ret;
  1256. }
  1257. module_init(aic3x_modinit);
  1258. static void __exit aic3x_exit(void)
  1259. {
  1260. #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
  1261. i2c_del_driver(&aic3x_i2c_driver);
  1262. #endif
  1263. }
  1264. module_exit(aic3x_exit);
  1265. MODULE_DESCRIPTION("ASoC TLV320AIC3X codec driver");
  1266. MODULE_AUTHOR("Vladimir Barinov");
  1267. MODULE_LICENSE("GPL");