ak4xxx-adda.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. /*
  2. * ALSA driver for AK4524 / AK4528 / AK4529 / AK4355 / AK4358 / AK4381
  3. * AD and DA converters
  4. *
  5. * Copyright (c) 2000-2004 Jaroslav Kysela <perex@suse.cz>,
  6. * Takashi Iwai <tiwai@suse.de>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. *
  22. */
  23. #include <sound/driver.h>
  24. #include <asm/io.h>
  25. #include <linux/delay.h>
  26. #include <linux/interrupt.h>
  27. #include <linux/init.h>
  28. #include <sound/core.h>
  29. #include <sound/control.h>
  30. #include <sound/ak4xxx-adda.h>
  31. MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>, Takashi Iwai <tiwai@suse.de>");
  32. MODULE_DESCRIPTION("Routines for control of AK452x / AK43xx AD/DA converters");
  33. MODULE_LICENSE("GPL");
  34. void snd_akm4xxx_write(struct snd_akm4xxx *ak, int chip, unsigned char reg,
  35. unsigned char val)
  36. {
  37. ak->ops.lock(ak, chip);
  38. ak->ops.write(ak, chip, reg, val);
  39. /* save the data */
  40. if (ak->type == SND_AK4524 || ak->type == SND_AK4528) {
  41. if ((reg != 0x04 && reg != 0x05) || (val & 0x80) == 0)
  42. snd_akm4xxx_set(ak, chip, reg, val);
  43. else
  44. snd_akm4xxx_set_ipga(ak, chip, reg, val);
  45. } else {
  46. /* AK4529, or else */
  47. snd_akm4xxx_set(ak, chip, reg, val);
  48. }
  49. ak->ops.unlock(ak, chip);
  50. }
  51. EXPORT_SYMBOL(snd_akm4xxx_write);
  52. /* reset procedure for AK4524 and AK4528 */
  53. static void ak4524_reset(struct snd_akm4xxx *ak, int state)
  54. {
  55. unsigned int chip;
  56. unsigned char reg, maxreg;
  57. if (ak->type == SND_AK4528)
  58. maxreg = 0x06;
  59. else
  60. maxreg = 0x08;
  61. for (chip = 0; chip < ak->num_dacs/2; chip++) {
  62. snd_akm4xxx_write(ak, chip, 0x01, state ? 0x00 : 0x03);
  63. if (state)
  64. continue;
  65. /* DAC volumes */
  66. for (reg = 0x04; reg < maxreg; reg++)
  67. snd_akm4xxx_write(ak, chip, reg,
  68. snd_akm4xxx_get(ak, chip, reg));
  69. if (ak->type == SND_AK4528)
  70. continue;
  71. /* IPGA */
  72. for (reg = 0x04; reg < 0x06; reg++)
  73. snd_akm4xxx_write(ak, chip, reg,
  74. snd_akm4xxx_get_ipga(ak, chip, reg));
  75. }
  76. }
  77. /* reset procedure for AK4355 and AK4358 */
  78. static void ak4355_reset(struct snd_akm4xxx *ak, int state)
  79. {
  80. unsigned char reg;
  81. if (state) {
  82. snd_akm4xxx_write(ak, 0, 0x01, 0x02); /* reset and soft-mute */
  83. return;
  84. }
  85. for (reg = 0x00; reg < 0x0b; reg++)
  86. if (reg != 0x01)
  87. snd_akm4xxx_write(ak, 0, reg,
  88. snd_akm4xxx_get(ak, 0, reg));
  89. snd_akm4xxx_write(ak, 0, 0x01, 0x01); /* un-reset, unmute */
  90. }
  91. /* reset procedure for AK4381 */
  92. static void ak4381_reset(struct snd_akm4xxx *ak, int state)
  93. {
  94. unsigned int chip;
  95. unsigned char reg;
  96. for (chip = 0; chip < ak->num_dacs/2; chip++) {
  97. snd_akm4xxx_write(ak, chip, 0x00, state ? 0x0c : 0x0f);
  98. if (state)
  99. continue;
  100. for (reg = 0x01; reg < 0x05; reg++)
  101. snd_akm4xxx_write(ak, chip, reg,
  102. snd_akm4xxx_get(ak, chip, reg));
  103. }
  104. }
  105. /*
  106. * reset the AKM codecs
  107. * @state: 1 = reset codec, 0 = restore the registers
  108. *
  109. * assert the reset operation and restores the register values to the chips.
  110. */
  111. void snd_akm4xxx_reset(struct snd_akm4xxx *ak, int state)
  112. {
  113. switch (ak->type) {
  114. case SND_AK4524:
  115. case SND_AK4528:
  116. ak4524_reset(ak, state);
  117. break;
  118. case SND_AK4529:
  119. /* FIXME: needed for ak4529? */
  120. break;
  121. case SND_AK4355:
  122. case SND_AK4358:
  123. ak4355_reset(ak, state);
  124. break;
  125. case SND_AK4381:
  126. ak4381_reset(ak, state);
  127. break;
  128. }
  129. }
  130. EXPORT_SYMBOL(snd_akm4xxx_reset);
  131. /*
  132. * initialize all the ak4xxx chips
  133. */
  134. void snd_akm4xxx_init(struct snd_akm4xxx *ak)
  135. {
  136. static unsigned char inits_ak4524[] = {
  137. 0x00, 0x07, /* 0: all power up */
  138. 0x01, 0x00, /* 1: ADC/DAC reset */
  139. 0x02, 0x60, /* 2: 24bit I2S */
  140. 0x03, 0x19, /* 3: deemphasis off */
  141. 0x01, 0x03, /* 1: ADC/DAC enable */
  142. 0x04, 0x00, /* 4: ADC left muted */
  143. 0x05, 0x00, /* 5: ADC right muted */
  144. 0x04, 0x80, /* 4: ADC IPGA gain 0dB */
  145. 0x05, 0x80, /* 5: ADC IPGA gain 0dB */
  146. 0x06, 0x00, /* 6: DAC left muted */
  147. 0x07, 0x00, /* 7: DAC right muted */
  148. 0xff, 0xff
  149. };
  150. static unsigned char inits_ak4528[] = {
  151. 0x00, 0x07, /* 0: all power up */
  152. 0x01, 0x00, /* 1: ADC/DAC reset */
  153. 0x02, 0x60, /* 2: 24bit I2S */
  154. 0x03, 0x0d, /* 3: deemphasis off, turn LR highpass filters on */
  155. 0x01, 0x03, /* 1: ADC/DAC enable */
  156. 0x04, 0x00, /* 4: ADC left muted */
  157. 0x05, 0x00, /* 5: ADC right muted */
  158. 0xff, 0xff
  159. };
  160. static unsigned char inits_ak4529[] = {
  161. 0x09, 0x01, /* 9: ATS=0, RSTN=1 */
  162. 0x0a, 0x3f, /* A: all power up, no zero/overflow detection */
  163. 0x00, 0x0c, /* 0: TDM=0, 24bit I2S, SMUTE=0 */
  164. 0x01, 0x00, /* 1: ACKS=0, ADC, loop off */
  165. 0x02, 0xff, /* 2: LOUT1 muted */
  166. 0x03, 0xff, /* 3: ROUT1 muted */
  167. 0x04, 0xff, /* 4: LOUT2 muted */
  168. 0x05, 0xff, /* 5: ROUT2 muted */
  169. 0x06, 0xff, /* 6: LOUT3 muted */
  170. 0x07, 0xff, /* 7: ROUT3 muted */
  171. 0x0b, 0xff, /* B: LOUT4 muted */
  172. 0x0c, 0xff, /* C: ROUT4 muted */
  173. 0x08, 0x55, /* 8: deemphasis all off */
  174. 0xff, 0xff
  175. };
  176. static unsigned char inits_ak4355[] = {
  177. 0x01, 0x02, /* 1: reset and soft-mute */
  178. 0x00, 0x06, /* 0: mode3(i2s), disable auto-clock detect,
  179. * disable DZF, sharp roll-off, RSTN#=0 */
  180. 0x02, 0x0e, /* 2: DA's power up, normal speed, RSTN#=0 */
  181. // 0x02, 0x2e, /* quad speed */
  182. 0x03, 0x01, /* 3: de-emphasis off */
  183. 0x04, 0x00, /* 4: LOUT1 volume muted */
  184. 0x05, 0x00, /* 5: ROUT1 volume muted */
  185. 0x06, 0x00, /* 6: LOUT2 volume muted */
  186. 0x07, 0x00, /* 7: ROUT2 volume muted */
  187. 0x08, 0x00, /* 8: LOUT3 volume muted */
  188. 0x09, 0x00, /* 9: ROUT3 volume muted */
  189. 0x0a, 0x00, /* a: DATT speed=0, ignore DZF */
  190. 0x01, 0x01, /* 1: un-reset, unmute */
  191. 0xff, 0xff
  192. };
  193. static unsigned char inits_ak4358[] = {
  194. 0x01, 0x02, /* 1: reset and soft-mute */
  195. 0x00, 0x06, /* 0: mode3(i2s), disable auto-clock detect,
  196. * disable DZF, sharp roll-off, RSTN#=0 */
  197. 0x02, 0x0e, /* 2: DA's power up, normal speed, RSTN#=0 */
  198. // 0x02, 0x2e, /* quad speed */
  199. 0x03, 0x01, /* 3: de-emphasis off */
  200. 0x04, 0x00, /* 4: LOUT1 volume muted */
  201. 0x05, 0x00, /* 5: ROUT1 volume muted */
  202. 0x06, 0x00, /* 6: LOUT2 volume muted */
  203. 0x07, 0x00, /* 7: ROUT2 volume muted */
  204. 0x08, 0x00, /* 8: LOUT3 volume muted */
  205. 0x09, 0x00, /* 9: ROUT3 volume muted */
  206. 0x0b, 0x00, /* b: LOUT4 volume muted */
  207. 0x0c, 0x00, /* c: ROUT4 volume muted */
  208. 0x0a, 0x00, /* a: DATT speed=0, ignore DZF */
  209. 0x01, 0x01, /* 1: un-reset, unmute */
  210. 0xff, 0xff
  211. };
  212. static unsigned char inits_ak4381[] = {
  213. 0x00, 0x0c, /* 0: mode3(i2s), disable auto-clock detect */
  214. 0x01, 0x02, /* 1: de-emphasis off, normal speed,
  215. * sharp roll-off, DZF off */
  216. // 0x01, 0x12, /* quad speed */
  217. 0x02, 0x00, /* 2: DZF disabled */
  218. 0x03, 0x00, /* 3: LATT 0 */
  219. 0x04, 0x00, /* 4: RATT 0 */
  220. 0x00, 0x0f, /* 0: power-up, un-reset */
  221. 0xff, 0xff
  222. };
  223. int chip, num_chips;
  224. unsigned char *ptr, reg, data, *inits;
  225. switch (ak->type) {
  226. case SND_AK4524:
  227. inits = inits_ak4524;
  228. num_chips = ak->num_dacs / 2;
  229. break;
  230. case SND_AK4528:
  231. inits = inits_ak4528;
  232. num_chips = ak->num_dacs / 2;
  233. break;
  234. case SND_AK4529:
  235. inits = inits_ak4529;
  236. num_chips = 1;
  237. break;
  238. case SND_AK4355:
  239. inits = inits_ak4355;
  240. num_chips = 1;
  241. break;
  242. case SND_AK4358:
  243. inits = inits_ak4358;
  244. num_chips = 1;
  245. break;
  246. case SND_AK4381:
  247. inits = inits_ak4381;
  248. num_chips = ak->num_dacs / 2;
  249. break;
  250. default:
  251. snd_BUG();
  252. return;
  253. }
  254. for (chip = 0; chip < num_chips; chip++) {
  255. ptr = inits;
  256. while (*ptr != 0xff) {
  257. reg = *ptr++;
  258. data = *ptr++;
  259. snd_akm4xxx_write(ak, chip, reg, data);
  260. }
  261. }
  262. }
  263. EXPORT_SYMBOL(snd_akm4xxx_init);
  264. #define AK_GET_CHIP(val) (((val) >> 8) & 0xff)
  265. #define AK_GET_ADDR(val) ((val) & 0xff)
  266. #define AK_GET_SHIFT(val) (((val) >> 16) & 0x7f)
  267. #define AK_GET_INVERT(val) (((val) >> 23) & 1)
  268. #define AK_GET_MASK(val) (((val) >> 24) & 0xff)
  269. #define AK_COMPOSE(chip,addr,shift,mask) \
  270. (((chip) << 8) | (addr) | ((shift) << 16) | ((mask) << 24))
  271. #define AK_INVERT (1<<23)
  272. static int snd_akm4xxx_volume_info(struct snd_kcontrol *kcontrol,
  273. struct snd_ctl_elem_info *uinfo)
  274. {
  275. unsigned int mask = AK_GET_MASK(kcontrol->private_value);
  276. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  277. uinfo->count = 1;
  278. uinfo->value.integer.min = 0;
  279. uinfo->value.integer.max = mask;
  280. return 0;
  281. }
  282. static int snd_akm4xxx_volume_get(struct snd_kcontrol *kcontrol,
  283. struct snd_ctl_elem_value *ucontrol)
  284. {
  285. struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol);
  286. int chip = AK_GET_CHIP(kcontrol->private_value);
  287. int addr = AK_GET_ADDR(kcontrol->private_value);
  288. int invert = AK_GET_INVERT(kcontrol->private_value);
  289. unsigned int mask = AK_GET_MASK(kcontrol->private_value);
  290. unsigned char val = snd_akm4xxx_get(ak, chip, addr);
  291. ucontrol->value.integer.value[0] = invert ? mask - val : val;
  292. return 0;
  293. }
  294. static int snd_akm4xxx_volume_put(struct snd_kcontrol *kcontrol,
  295. struct snd_ctl_elem_value *ucontrol)
  296. {
  297. struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol);
  298. int chip = AK_GET_CHIP(kcontrol->private_value);
  299. int addr = AK_GET_ADDR(kcontrol->private_value);
  300. int invert = AK_GET_INVERT(kcontrol->private_value);
  301. unsigned int mask = AK_GET_MASK(kcontrol->private_value);
  302. unsigned char nval = ucontrol->value.integer.value[0] % (mask+1);
  303. int change;
  304. if (invert)
  305. nval = mask - nval;
  306. change = snd_akm4xxx_get(ak, chip, addr) != nval;
  307. if (change)
  308. snd_akm4xxx_write(ak, chip, addr, nval);
  309. return change;
  310. }
  311. static int snd_akm4xxx_stereo_volume_info(struct snd_kcontrol *kcontrol,
  312. struct snd_ctl_elem_info *uinfo)
  313. {
  314. unsigned int mask = AK_GET_MASK(kcontrol->private_value);
  315. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  316. uinfo->count = 2;
  317. uinfo->value.integer.min = 0;
  318. uinfo->value.integer.max = mask;
  319. return 0;
  320. }
  321. static int snd_akm4xxx_stereo_volume_get(struct snd_kcontrol *kcontrol,
  322. struct snd_ctl_elem_value *ucontrol)
  323. {
  324. struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol);
  325. int chip = AK_GET_CHIP(kcontrol->private_value);
  326. int addr = AK_GET_ADDR(kcontrol->private_value);
  327. int invert = AK_GET_INVERT(kcontrol->private_value);
  328. unsigned int mask = AK_GET_MASK(kcontrol->private_value);
  329. unsigned char val = snd_akm4xxx_get(ak, chip, addr);
  330. ucontrol->value.integer.value[0] = invert ? mask - val : val;
  331. val = snd_akm4xxx_get(ak, chip, addr+1);
  332. ucontrol->value.integer.value[1] = invert ? mask - val : val;
  333. return 0;
  334. }
  335. static int snd_akm4xxx_stereo_volume_put(struct snd_kcontrol *kcontrol,
  336. struct snd_ctl_elem_value *ucontrol)
  337. {
  338. struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol);
  339. int chip = AK_GET_CHIP(kcontrol->private_value);
  340. int addr = AK_GET_ADDR(kcontrol->private_value);
  341. int invert = AK_GET_INVERT(kcontrol->private_value);
  342. unsigned int mask = AK_GET_MASK(kcontrol->private_value);
  343. unsigned char nval = ucontrol->value.integer.value[0] % (mask+1);
  344. int change0, change1;
  345. if (invert)
  346. nval = mask - nval;
  347. change0 = snd_akm4xxx_get(ak, chip, addr) != nval;
  348. if (change0)
  349. snd_akm4xxx_write(ak, chip, addr, nval);
  350. nval = ucontrol->value.integer.value[1] % (mask+1);
  351. if (invert)
  352. nval = mask - nval;
  353. change1 = snd_akm4xxx_get(ak, chip, addr+1) != nval;
  354. if (change1)
  355. snd_akm4xxx_write(ak, chip, addr+1, nval);
  356. return change0 || change1;
  357. }
  358. static int snd_akm4xxx_ipga_gain_info(struct snd_kcontrol *kcontrol,
  359. struct snd_ctl_elem_info *uinfo)
  360. {
  361. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  362. uinfo->count = 1;
  363. uinfo->value.integer.min = 0;
  364. uinfo->value.integer.max = 36;
  365. return 0;
  366. }
  367. static int snd_akm4xxx_ipga_gain_get(struct snd_kcontrol *kcontrol,
  368. struct snd_ctl_elem_value *ucontrol)
  369. {
  370. struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol);
  371. int chip = AK_GET_CHIP(kcontrol->private_value);
  372. int addr = AK_GET_ADDR(kcontrol->private_value);
  373. ucontrol->value.integer.value[0] =
  374. snd_akm4xxx_get_ipga(ak, chip, addr) & 0x7f;
  375. return 0;
  376. }
  377. static int snd_akm4xxx_ipga_gain_put(struct snd_kcontrol *kcontrol,
  378. struct snd_ctl_elem_value *ucontrol)
  379. {
  380. struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol);
  381. int chip = AK_GET_CHIP(kcontrol->private_value);
  382. int addr = AK_GET_ADDR(kcontrol->private_value);
  383. unsigned char nval = (ucontrol->value.integer.value[0] % 37) | 0x80;
  384. int change = snd_akm4xxx_get_ipga(ak, chip, addr) != nval;
  385. if (change)
  386. snd_akm4xxx_write(ak, chip, addr, nval);
  387. return change;
  388. }
  389. static int snd_akm4xxx_deemphasis_info(struct snd_kcontrol *kcontrol,
  390. struct snd_ctl_elem_info *uinfo)
  391. {
  392. static char *texts[4] = {
  393. "44.1kHz", "Off", "48kHz", "32kHz",
  394. };
  395. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  396. uinfo->count = 1;
  397. uinfo->value.enumerated.items = 4;
  398. if (uinfo->value.enumerated.item >= 4)
  399. uinfo->value.enumerated.item = 3;
  400. strcpy(uinfo->value.enumerated.name,
  401. texts[uinfo->value.enumerated.item]);
  402. return 0;
  403. }
  404. static int snd_akm4xxx_deemphasis_get(struct snd_kcontrol *kcontrol,
  405. struct snd_ctl_elem_value *ucontrol)
  406. {
  407. struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol);
  408. int chip = AK_GET_CHIP(kcontrol->private_value);
  409. int addr = AK_GET_ADDR(kcontrol->private_value);
  410. int shift = AK_GET_SHIFT(kcontrol->private_value);
  411. ucontrol->value.enumerated.item[0] =
  412. (snd_akm4xxx_get(ak, chip, addr) >> shift) & 3;
  413. return 0;
  414. }
  415. static int snd_akm4xxx_deemphasis_put(struct snd_kcontrol *kcontrol,
  416. struct snd_ctl_elem_value *ucontrol)
  417. {
  418. struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol);
  419. int chip = AK_GET_CHIP(kcontrol->private_value);
  420. int addr = AK_GET_ADDR(kcontrol->private_value);
  421. int shift = AK_GET_SHIFT(kcontrol->private_value);
  422. unsigned char nval = ucontrol->value.enumerated.item[0] & 3;
  423. int change;
  424. nval = (nval << shift) |
  425. (snd_akm4xxx_get(ak, chip, addr) & ~(3 << shift));
  426. change = snd_akm4xxx_get(ak, chip, addr) != nval;
  427. if (change)
  428. snd_akm4xxx_write(ak, chip, addr, nval);
  429. return change;
  430. }
  431. /*
  432. * build AK4xxx controls
  433. */
  434. int snd_akm4xxx_build_controls(struct snd_akm4xxx *ak)
  435. {
  436. unsigned int idx, num_emphs;
  437. struct snd_kcontrol *ctl;
  438. int err;
  439. int mixer_ch = 0;
  440. int num_stereo;
  441. ctl = kmalloc(sizeof(*ctl), GFP_KERNEL);
  442. if (! ctl)
  443. return -ENOMEM;
  444. for (idx = 0; idx < ak->num_dacs; ) {
  445. memset(ctl, 0, sizeof(*ctl));
  446. if (ak->channel_names == NULL) {
  447. strcpy(ctl->id.name, "DAC Volume");
  448. num_stereo = 1;
  449. ctl->id.index = mixer_ch + ak->idx_offset * 2;
  450. } else {
  451. strcpy(ctl->id.name, ak->channel_names[mixer_ch]);
  452. num_stereo = ak->num_stereo[mixer_ch];
  453. ctl->id.index = 0;
  454. }
  455. ctl->id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
  456. ctl->count = 1;
  457. if (num_stereo == 2) {
  458. ctl->info = snd_akm4xxx_stereo_volume_info;
  459. ctl->get = snd_akm4xxx_stereo_volume_get;
  460. ctl->put = snd_akm4xxx_stereo_volume_put;
  461. } else {
  462. ctl->info = snd_akm4xxx_volume_info;
  463. ctl->get = snd_akm4xxx_volume_get;
  464. ctl->put = snd_akm4xxx_volume_put;
  465. }
  466. switch (ak->type) {
  467. case SND_AK4524:
  468. /* register 6 & 7 */
  469. ctl->private_value =
  470. AK_COMPOSE(idx/2, (idx%2) + 6, 0, 127);
  471. break;
  472. case SND_AK4528:
  473. /* register 4 & 5 */
  474. ctl->private_value =
  475. AK_COMPOSE(idx/2, (idx%2) + 4, 0, 127);
  476. break;
  477. case SND_AK4529: {
  478. /* registers 2-7 and b,c */
  479. int val = idx < 6 ? idx + 2 : (idx - 6) + 0xb;
  480. ctl->private_value =
  481. AK_COMPOSE(0, val, 0, 255) | AK_INVERT;
  482. break;
  483. }
  484. case SND_AK4355:
  485. /* register 4-9, chip #0 only */
  486. ctl->private_value = AK_COMPOSE(0, idx + 4, 0, 255);
  487. break;
  488. case SND_AK4358:
  489. if (idx >= 6)
  490. /* register 4-9, chip #0 only */
  491. ctl->private_value =
  492. AK_COMPOSE(0, idx + 5, 0, 255);
  493. else
  494. /* register 4-9, chip #0 only */
  495. ctl->private_value =
  496. AK_COMPOSE(0, idx + 4, 0, 255);
  497. break;
  498. case SND_AK4381:
  499. /* register 3 & 4 */
  500. ctl->private_value =
  501. AK_COMPOSE(idx/2, (idx%2) + 3, 0, 255);
  502. break;
  503. default:
  504. err = -EINVAL;
  505. goto __error;
  506. }
  507. ctl->private_data = ak;
  508. err = snd_ctl_add(ak->card,
  509. snd_ctl_new(ctl, SNDRV_CTL_ELEM_ACCESS_READ|
  510. SNDRV_CTL_ELEM_ACCESS_WRITE));
  511. if (err < 0)
  512. goto __error;
  513. idx += num_stereo;
  514. mixer_ch++;
  515. }
  516. for (idx = 0; idx < ak->num_adcs && ak->type == SND_AK4524; ++idx) {
  517. memset(ctl, 0, sizeof(*ctl));
  518. strcpy(ctl->id.name, "ADC Volume");
  519. ctl->id.index = idx + ak->idx_offset * 2;
  520. ctl->id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
  521. ctl->count = 1;
  522. ctl->info = snd_akm4xxx_volume_info;
  523. ctl->get = snd_akm4xxx_volume_get;
  524. ctl->put = snd_akm4xxx_volume_put;
  525. /* register 4 & 5 */
  526. ctl->private_value =
  527. AK_COMPOSE(idx/2, (idx%2) + 4, 0, 127);
  528. ctl->private_data = ak;
  529. err = snd_ctl_add(ak->card,
  530. snd_ctl_new(ctl, SNDRV_CTL_ELEM_ACCESS_READ|
  531. SNDRV_CTL_ELEM_ACCESS_WRITE));
  532. if (err < 0)
  533. goto __error;
  534. memset(ctl, 0, sizeof(*ctl));
  535. strcpy(ctl->id.name, "IPGA Analog Capture Volume");
  536. ctl->id.index = idx + ak->idx_offset * 2;
  537. ctl->id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
  538. ctl->count = 1;
  539. ctl->info = snd_akm4xxx_ipga_gain_info;
  540. ctl->get = snd_akm4xxx_ipga_gain_get;
  541. ctl->put = snd_akm4xxx_ipga_gain_put;
  542. /* register 4 & 5 */
  543. ctl->private_value = AK_COMPOSE(idx/2, (idx%2) + 4, 0, 0);
  544. ctl->private_data = ak;
  545. err = snd_ctl_add(ak->card,
  546. snd_ctl_new(ctl, SNDRV_CTL_ELEM_ACCESS_READ|
  547. SNDRV_CTL_ELEM_ACCESS_WRITE));
  548. if (err < 0)
  549. goto __error;
  550. }
  551. if (ak->type == SND_AK4355 || ak->type == SND_AK4358)
  552. num_emphs = 1;
  553. else
  554. num_emphs = ak->num_dacs / 2;
  555. for (idx = 0; idx < num_emphs; idx++) {
  556. memset(ctl, 0, sizeof(*ctl));
  557. strcpy(ctl->id.name, "Deemphasis");
  558. ctl->id.index = idx + ak->idx_offset;
  559. ctl->id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
  560. ctl->count = 1;
  561. ctl->info = snd_akm4xxx_deemphasis_info;
  562. ctl->get = snd_akm4xxx_deemphasis_get;
  563. ctl->put = snd_akm4xxx_deemphasis_put;
  564. switch (ak->type) {
  565. case SND_AK4524:
  566. case SND_AK4528:
  567. /* register 3 */
  568. ctl->private_value = AK_COMPOSE(idx, 3, 0, 0);
  569. break;
  570. case SND_AK4529: {
  571. int shift = idx == 3 ? 6 : (2 - idx) * 2;
  572. /* register 8 with shift */
  573. ctl->private_value = AK_COMPOSE(0, 8, shift, 0);
  574. break;
  575. }
  576. case SND_AK4355:
  577. case SND_AK4358:
  578. ctl->private_value = AK_COMPOSE(idx, 3, 0, 0);
  579. break;
  580. case SND_AK4381:
  581. ctl->private_value = AK_COMPOSE(idx, 1, 1, 0);
  582. break;
  583. }
  584. ctl->private_data = ak;
  585. err = snd_ctl_add(ak->card,
  586. snd_ctl_new(ctl, SNDRV_CTL_ELEM_ACCESS_READ|
  587. SNDRV_CTL_ELEM_ACCESS_WRITE));
  588. if (err < 0)
  589. goto __error;
  590. }
  591. err = 0;
  592. __error:
  593. kfree(ctl);
  594. return err;
  595. }
  596. EXPORT_SYMBOL(snd_akm4xxx_build_controls);
  597. static int __init alsa_akm4xxx_module_init(void)
  598. {
  599. return 0;
  600. }
  601. static void __exit alsa_akm4xxx_module_exit(void)
  602. {
  603. }
  604. module_init(alsa_akm4xxx_module_init)
  605. module_exit(alsa_akm4xxx_module_exit)