tlv320aic3x.c 47 KB

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