tlv320aic3x.c 47 KB

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