tlv320aic3x.c 42 KB

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