ak4xxx-adda.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  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, unsigned char val)
  35. {
  36. ak->ops.lock(ak, chip);
  37. ak->ops.write(ak, chip, reg, val);
  38. /* save the data */
  39. if (ak->type == SND_AK4524 || ak->type == SND_AK4528) {
  40. if ((reg != 0x04 && reg != 0x05) || (val & 0x80) == 0)
  41. snd_akm4xxx_set(ak, chip, reg, val);
  42. else
  43. snd_akm4xxx_set_ipga(ak, chip, reg, val);
  44. } else {
  45. /* AK4529, or else */
  46. snd_akm4xxx_set(ak, chip, reg, val);
  47. }
  48. ak->ops.unlock(ak, chip);
  49. }
  50. /*
  51. * reset the AKM codecs
  52. * @state: 1 = reset codec, 0 = restore the registers
  53. *
  54. * assert the reset operation and restores the register values to the chips.
  55. */
  56. void snd_akm4xxx_reset(struct snd_akm4xxx *ak, int state)
  57. {
  58. unsigned int chip;
  59. unsigned char reg;
  60. switch (ak->type) {
  61. case SND_AK4524:
  62. case SND_AK4528:
  63. for (chip = 0; chip < ak->num_dacs/2; chip++) {
  64. snd_akm4xxx_write(ak, chip, 0x01, state ? 0x00 : 0x03);
  65. if (state)
  66. continue;
  67. /* DAC volumes */
  68. for (reg = 0x04; reg < (ak->type == SND_AK4528 ? 0x06 : 0x08); reg++)
  69. snd_akm4xxx_write(ak, chip, reg, snd_akm4xxx_get(ak, chip, reg));
  70. if (ak->type == SND_AK4528)
  71. continue;
  72. /* IPGA */
  73. for (reg = 0x04; reg < 0x06; reg++)
  74. snd_akm4xxx_write(ak, chip, reg, snd_akm4xxx_get_ipga(ak, chip, reg));
  75. }
  76. break;
  77. case SND_AK4529:
  78. /* FIXME: needed for ak4529? */
  79. break;
  80. case SND_AK4355:
  81. case SND_AK4358:
  82. if (state) {
  83. snd_akm4xxx_write(ak, 0, 0x01, 0x02); /* reset and soft-mute */
  84. return;
  85. }
  86. for (reg = 0x00; reg < 0x0b; reg++)
  87. if (reg != 0x01)
  88. snd_akm4xxx_write(ak, 0, reg, snd_akm4xxx_get(ak, 0, reg));
  89. snd_akm4xxx_write(ak, 0, 0x01, 0x01); /* un-reset, unmute */
  90. break;
  91. case SND_AK4381:
  92. for (chip = 0; chip < ak->num_dacs/2; chip++) {
  93. snd_akm4xxx_write(ak, chip, 0x00, state ? 0x0c : 0x0f);
  94. if (state)
  95. continue;
  96. for (reg = 0x01; reg < 0x05; reg++)
  97. snd_akm4xxx_write(ak, chip, reg, snd_akm4xxx_get(ak, chip, reg));
  98. }
  99. break;
  100. }
  101. }
  102. /*
  103. * initialize all the ak4xxx chips
  104. */
  105. void snd_akm4xxx_init(struct snd_akm4xxx *ak)
  106. {
  107. static unsigned char inits_ak4524[] = {
  108. 0x00, 0x07, /* 0: all power up */
  109. 0x01, 0x00, /* 1: ADC/DAC reset */
  110. 0x02, 0x60, /* 2: 24bit I2S */
  111. 0x03, 0x19, /* 3: deemphasis off */
  112. 0x01, 0x03, /* 1: ADC/DAC enable */
  113. 0x04, 0x00, /* 4: ADC left muted */
  114. 0x05, 0x00, /* 5: ADC right muted */
  115. 0x04, 0x80, /* 4: ADC IPGA gain 0dB */
  116. 0x05, 0x80, /* 5: ADC IPGA gain 0dB */
  117. 0x06, 0x00, /* 6: DAC left muted */
  118. 0x07, 0x00, /* 7: DAC right muted */
  119. 0xff, 0xff
  120. };
  121. static unsigned char inits_ak4528[] = {
  122. 0x00, 0x07, /* 0: all power up */
  123. 0x01, 0x00, /* 1: ADC/DAC reset */
  124. 0x02, 0x60, /* 2: 24bit I2S */
  125. 0x03, 0x0d, /* 3: deemphasis off, turn LR highpass filters on */
  126. 0x01, 0x03, /* 1: ADC/DAC enable */
  127. 0x04, 0x00, /* 4: ADC left muted */
  128. 0x05, 0x00, /* 5: ADC right muted */
  129. 0xff, 0xff
  130. };
  131. static unsigned char inits_ak4529[] = {
  132. 0x09, 0x01, /* 9: ATS=0, RSTN=1 */
  133. 0x0a, 0x3f, /* A: all power up, no zero/overflow detection */
  134. 0x00, 0x0c, /* 0: TDM=0, 24bit I2S, SMUTE=0 */
  135. 0x01, 0x00, /* 1: ACKS=0, ADC, loop off */
  136. 0x02, 0xff, /* 2: LOUT1 muted */
  137. 0x03, 0xff, /* 3: ROUT1 muted */
  138. 0x04, 0xff, /* 4: LOUT2 muted */
  139. 0x05, 0xff, /* 5: ROUT2 muted */
  140. 0x06, 0xff, /* 6: LOUT3 muted */
  141. 0x07, 0xff, /* 7: ROUT3 muted */
  142. 0x0b, 0xff, /* B: LOUT4 muted */
  143. 0x0c, 0xff, /* C: ROUT4 muted */
  144. 0x08, 0x55, /* 8: deemphasis all off */
  145. 0xff, 0xff
  146. };
  147. static unsigned char inits_ak4355[] = {
  148. 0x01, 0x02, /* 1: reset and soft-mute */
  149. 0x00, 0x06, /* 0: mode3(i2s), disable auto-clock detect, disable DZF, sharp roll-off, RSTN#=0 */
  150. 0x02, 0x0e, /* 2: DA's power up, normal speed, RSTN#=0 */
  151. // 0x02, 0x2e, /* quad speed */
  152. 0x03, 0x01, /* 3: de-emphasis off */
  153. 0x04, 0x00, /* 4: LOUT1 volume muted */
  154. 0x05, 0x00, /* 5: ROUT1 volume muted */
  155. 0x06, 0x00, /* 6: LOUT2 volume muted */
  156. 0x07, 0x00, /* 7: ROUT2 volume muted */
  157. 0x08, 0x00, /* 8: LOUT3 volume muted */
  158. 0x09, 0x00, /* 9: ROUT3 volume muted */
  159. 0x0a, 0x00, /* a: DATT speed=0, ignore DZF */
  160. 0x01, 0x01, /* 1: un-reset, unmute */
  161. 0xff, 0xff
  162. };
  163. static unsigned char inits_ak4358[] = {
  164. 0x01, 0x02, /* 1: reset and soft-mute */
  165. 0x00, 0x06, /* 0: mode3(i2s), disable auto-clock detect, disable DZF, sharp roll-off, RSTN#=0 */
  166. 0x02, 0x0e, /* 2: DA's power up, normal speed, RSTN#=0 */
  167. // 0x02, 0x2e, /* quad speed */
  168. 0x03, 0x01, /* 3: de-emphasis off */
  169. 0x04, 0x00, /* 4: LOUT1 volume muted */
  170. 0x05, 0x00, /* 5: ROUT1 volume muted */
  171. 0x06, 0x00, /* 6: LOUT2 volume muted */
  172. 0x07, 0x00, /* 7: ROUT2 volume muted */
  173. 0x08, 0x00, /* 8: LOUT3 volume muted */
  174. 0x09, 0x00, /* 9: ROUT3 volume muted */
  175. 0x0b, 0x00, /* b: LOUT4 volume muted */
  176. 0x0c, 0x00, /* c: ROUT4 volume muted */
  177. 0x0a, 0x00, /* a: DATT speed=0, ignore DZF */
  178. 0x01, 0x01, /* 1: un-reset, unmute */
  179. 0xff, 0xff
  180. };
  181. static unsigned char inits_ak4381[] = {
  182. 0x00, 0x0c, /* 0: mode3(i2s), disable auto-clock detect */
  183. 0x01, 0x02, /* 1: de-emphasis off, normal speed, sharp roll-off, DZF off */
  184. // 0x01, 0x12, /* quad speed */
  185. 0x02, 0x00, /* 2: DZF disabled */
  186. 0x03, 0x00, /* 3: LATT 0 */
  187. 0x04, 0x00, /* 4: RATT 0 */
  188. 0x00, 0x0f, /* 0: power-up, un-reset */
  189. 0xff, 0xff
  190. };
  191. int chip, num_chips;
  192. unsigned char *ptr, reg, data, *inits;
  193. switch (ak->type) {
  194. case SND_AK4524:
  195. inits = inits_ak4524;
  196. num_chips = ak->num_dacs / 2;
  197. break;
  198. case SND_AK4528:
  199. inits = inits_ak4528;
  200. num_chips = ak->num_dacs / 2;
  201. break;
  202. case SND_AK4529:
  203. inits = inits_ak4529;
  204. num_chips = 1;
  205. break;
  206. case SND_AK4355:
  207. inits = inits_ak4355;
  208. num_chips = 1;
  209. break;
  210. case SND_AK4358:
  211. inits = inits_ak4358;
  212. num_chips = 1;
  213. break;
  214. case SND_AK4381:
  215. inits = inits_ak4381;
  216. num_chips = ak->num_dacs / 2;
  217. break;
  218. default:
  219. snd_BUG();
  220. return;
  221. }
  222. for (chip = 0; chip < num_chips; chip++) {
  223. ptr = inits;
  224. while (*ptr != 0xff) {
  225. reg = *ptr++;
  226. data = *ptr++;
  227. snd_akm4xxx_write(ak, chip, reg, data);
  228. }
  229. }
  230. }
  231. #define AK_GET_CHIP(val) (((val) >> 8) & 0xff)
  232. #define AK_GET_ADDR(val) ((val) & 0xff)
  233. #define AK_GET_SHIFT(val) (((val) >> 16) & 0x7f)
  234. #define AK_GET_INVERT(val) (((val) >> 23) & 1)
  235. #define AK_GET_MASK(val) (((val) >> 24) & 0xff)
  236. #define AK_COMPOSE(chip,addr,shift,mask) (((chip) << 8) | (addr) | ((shift) << 16) | ((mask) << 24))
  237. #define AK_INVERT (1<<23)
  238. static int snd_akm4xxx_volume_info(struct snd_kcontrol *kcontrol,
  239. struct snd_ctl_elem_info *uinfo)
  240. {
  241. unsigned int mask = AK_GET_MASK(kcontrol->private_value);
  242. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  243. uinfo->count = 1;
  244. uinfo->value.integer.min = 0;
  245. uinfo->value.integer.max = mask;
  246. return 0;
  247. }
  248. static int snd_akm4xxx_volume_get(struct snd_kcontrol *kcontrol,
  249. struct snd_ctl_elem_value *ucontrol)
  250. {
  251. struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol);
  252. int chip = AK_GET_CHIP(kcontrol->private_value);
  253. int addr = AK_GET_ADDR(kcontrol->private_value);
  254. int invert = AK_GET_INVERT(kcontrol->private_value);
  255. unsigned int mask = AK_GET_MASK(kcontrol->private_value);
  256. unsigned char val = snd_akm4xxx_get(ak, chip, addr);
  257. ucontrol->value.integer.value[0] = invert ? mask - val : val;
  258. return 0;
  259. }
  260. static int snd_akm4xxx_volume_put(struct snd_kcontrol *kcontrol,
  261. struct snd_ctl_elem_value *ucontrol)
  262. {
  263. struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol);
  264. int chip = AK_GET_CHIP(kcontrol->private_value);
  265. int addr = AK_GET_ADDR(kcontrol->private_value);
  266. int invert = AK_GET_INVERT(kcontrol->private_value);
  267. unsigned int mask = AK_GET_MASK(kcontrol->private_value);
  268. unsigned char nval = ucontrol->value.integer.value[0] % (mask+1);
  269. int change;
  270. if (invert)
  271. nval = mask - nval;
  272. change = snd_akm4xxx_get(ak, chip, addr) != nval;
  273. if (change)
  274. snd_akm4xxx_write(ak, chip, addr, nval);
  275. return change;
  276. }
  277. static int snd_akm4xxx_stereo_volume_info(struct snd_kcontrol *kcontrol,
  278. struct snd_ctl_elem_info *uinfo)
  279. {
  280. unsigned int mask = AK_GET_MASK(kcontrol->private_value);
  281. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  282. uinfo->count = 2;
  283. uinfo->value.integer.min = 0;
  284. uinfo->value.integer.max = mask;
  285. return 0;
  286. }
  287. static int snd_akm4xxx_stereo_volume_get(struct snd_kcontrol *kcontrol,
  288. struct snd_ctl_elem_value *ucontrol)
  289. {
  290. struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol);
  291. int chip = AK_GET_CHIP(kcontrol->private_value);
  292. int addr = AK_GET_ADDR(kcontrol->private_value);
  293. int invert = AK_GET_INVERT(kcontrol->private_value);
  294. unsigned int mask = AK_GET_MASK(kcontrol->private_value);
  295. unsigned char val = snd_akm4xxx_get(ak, chip, addr);
  296. ucontrol->value.integer.value[0] = invert ? mask - val : val;
  297. val = snd_akm4xxx_get(ak, chip, addr+1);
  298. ucontrol->value.integer.value[1] = invert ? mask - val : val;
  299. return 0;
  300. }
  301. static int snd_akm4xxx_stereo_volume_put(struct snd_kcontrol *kcontrol,
  302. struct snd_ctl_elem_value *ucontrol)
  303. {
  304. struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol);
  305. int chip = AK_GET_CHIP(kcontrol->private_value);
  306. int addr = AK_GET_ADDR(kcontrol->private_value);
  307. int invert = AK_GET_INVERT(kcontrol->private_value);
  308. unsigned int mask = AK_GET_MASK(kcontrol->private_value);
  309. unsigned char nval = ucontrol->value.integer.value[0] % (mask+1);
  310. int change0, change1;
  311. if (invert)
  312. nval = mask - nval;
  313. change0 = snd_akm4xxx_get(ak, chip, addr) != nval;
  314. if (change0)
  315. snd_akm4xxx_write(ak, chip, addr, nval);
  316. nval = ucontrol->value.integer.value[1] % (mask+1);
  317. if (invert)
  318. nval = mask - nval;
  319. change1 = snd_akm4xxx_get(ak, chip, addr+1) != nval;
  320. if (change1)
  321. snd_akm4xxx_write(ak, chip, addr+1, nval);
  322. return change0 || change1;
  323. }
  324. static int snd_akm4xxx_ipga_gain_info(struct snd_kcontrol *kcontrol,
  325. struct snd_ctl_elem_info *uinfo)
  326. {
  327. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  328. uinfo->count = 1;
  329. uinfo->value.integer.min = 0;
  330. uinfo->value.integer.max = 36;
  331. return 0;
  332. }
  333. static int snd_akm4xxx_ipga_gain_get(struct snd_kcontrol *kcontrol,
  334. struct snd_ctl_elem_value *ucontrol)
  335. {
  336. struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol);
  337. int chip = AK_GET_CHIP(kcontrol->private_value);
  338. int addr = AK_GET_ADDR(kcontrol->private_value);
  339. ucontrol->value.integer.value[0] = snd_akm4xxx_get_ipga(ak, chip, addr) & 0x7f;
  340. return 0;
  341. }
  342. static int snd_akm4xxx_ipga_gain_put(struct snd_kcontrol *kcontrol,
  343. struct snd_ctl_elem_value *ucontrol)
  344. {
  345. struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol);
  346. int chip = AK_GET_CHIP(kcontrol->private_value);
  347. int addr = AK_GET_ADDR(kcontrol->private_value);
  348. unsigned char nval = (ucontrol->value.integer.value[0] % 37) | 0x80;
  349. int change = snd_akm4xxx_get_ipga(ak, chip, addr) != nval;
  350. if (change)
  351. snd_akm4xxx_write(ak, chip, addr, nval);
  352. return change;
  353. }
  354. static int snd_akm4xxx_deemphasis_info(struct snd_kcontrol *kcontrol,
  355. struct snd_ctl_elem_info *uinfo)
  356. {
  357. static char *texts[4] = {
  358. "44.1kHz", "Off", "48kHz", "32kHz",
  359. };
  360. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  361. uinfo->count = 1;
  362. uinfo->value.enumerated.items = 4;
  363. if (uinfo->value.enumerated.item >= 4)
  364. uinfo->value.enumerated.item = 3;
  365. strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
  366. return 0;
  367. }
  368. static int snd_akm4xxx_deemphasis_get(struct snd_kcontrol *kcontrol,
  369. struct snd_ctl_elem_value *ucontrol)
  370. {
  371. struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol);
  372. int chip = AK_GET_CHIP(kcontrol->private_value);
  373. int addr = AK_GET_ADDR(kcontrol->private_value);
  374. int shift = AK_GET_SHIFT(kcontrol->private_value);
  375. ucontrol->value.enumerated.item[0] = (snd_akm4xxx_get(ak, chip, addr) >> shift) & 3;
  376. return 0;
  377. }
  378. static int snd_akm4xxx_deemphasis_put(struct snd_kcontrol *kcontrol,
  379. struct snd_ctl_elem_value *ucontrol)
  380. {
  381. struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol);
  382. int chip = AK_GET_CHIP(kcontrol->private_value);
  383. int addr = AK_GET_ADDR(kcontrol->private_value);
  384. int shift = AK_GET_SHIFT(kcontrol->private_value);
  385. unsigned char nval = ucontrol->value.enumerated.item[0] & 3;
  386. int change;
  387. nval = (nval << shift) | (snd_akm4xxx_get(ak, chip, addr) & ~(3 << shift));
  388. change = snd_akm4xxx_get(ak, chip, addr) != nval;
  389. if (change)
  390. snd_akm4xxx_write(ak, chip, addr, nval);
  391. return change;
  392. }
  393. /*
  394. * build AK4xxx controls
  395. */
  396. int snd_akm4xxx_build_controls(struct snd_akm4xxx *ak)
  397. {
  398. unsigned int idx, num_emphs;
  399. struct snd_kcontrol *ctl;
  400. int err;
  401. int mixer_ch = 0;
  402. int num_stereo;
  403. ctl = kmalloc(sizeof(*ctl), GFP_KERNEL);
  404. if (! ctl)
  405. return -ENOMEM;
  406. for (idx = 0; idx < ak->num_dacs; ) {
  407. memset(ctl, 0, sizeof(*ctl));
  408. if (ak->channel_names == NULL) {
  409. strcpy(ctl->id.name, "DAC Volume");
  410. num_stereo = 1;
  411. ctl->id.index = mixer_ch + ak->idx_offset * 2;
  412. } else {
  413. strcpy(ctl->id.name, ak->channel_names[mixer_ch]);
  414. num_stereo = ak->num_stereo[mixer_ch];
  415. ctl->id.index = 0; //mixer_ch + ak->idx_offset * 2;
  416. }
  417. ctl->id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
  418. ctl->count = 1;
  419. if (num_stereo == 2) {
  420. ctl->info = snd_akm4xxx_stereo_volume_info;
  421. ctl->get = snd_akm4xxx_stereo_volume_get;
  422. ctl->put = snd_akm4xxx_stereo_volume_put;
  423. } else {
  424. ctl->info = snd_akm4xxx_volume_info;
  425. ctl->get = snd_akm4xxx_volume_get;
  426. ctl->put = snd_akm4xxx_volume_put;
  427. }
  428. switch (ak->type) {
  429. case SND_AK4524:
  430. ctl->private_value = AK_COMPOSE(idx/2, (idx%2) + 6, 0, 127); /* register 6 & 7 */
  431. break;
  432. case SND_AK4528:
  433. ctl->private_value = AK_COMPOSE(idx/2, (idx%2) + 4, 0, 127); /* register 4 & 5 */
  434. break;
  435. case SND_AK4529: {
  436. int val = idx < 6 ? idx + 2 : (idx - 6) + 0xb; /* registers 2-7 and b,c */
  437. ctl->private_value = AK_COMPOSE(0, val, 0, 255) | AK_INVERT;
  438. break;
  439. }
  440. case SND_AK4355:
  441. ctl->private_value = AK_COMPOSE(0, idx + 4, 0, 255); /* register 4-9, chip #0 only */
  442. break;
  443. case SND_AK4358:
  444. if (idx >= 6)
  445. ctl->private_value = AK_COMPOSE(0, idx + 5, 0, 255); /* register 4-9, chip #0 only */
  446. else
  447. ctl->private_value = AK_COMPOSE(0, idx + 4, 0, 255); /* register 4-9, chip #0 only */
  448. break;
  449. case SND_AK4381:
  450. ctl->private_value = AK_COMPOSE(idx/2, (idx%2) + 3, 0, 255); /* register 3 & 4 */
  451. break;
  452. default:
  453. err = -EINVAL;
  454. goto __error;
  455. }
  456. ctl->private_data = ak;
  457. if ((err = snd_ctl_add(ak->card, snd_ctl_new(ctl, SNDRV_CTL_ELEM_ACCESS_READ|SNDRV_CTL_ELEM_ACCESS_WRITE))) < 0)
  458. goto __error;
  459. idx += num_stereo;
  460. mixer_ch++;
  461. }
  462. for (idx = 0; idx < ak->num_adcs && ak->type == SND_AK4524; ++idx) {
  463. memset(ctl, 0, sizeof(*ctl));
  464. strcpy(ctl->id.name, "ADC Volume");
  465. ctl->id.index = idx + ak->idx_offset * 2;
  466. ctl->id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
  467. ctl->count = 1;
  468. ctl->info = snd_akm4xxx_volume_info;
  469. ctl->get = snd_akm4xxx_volume_get;
  470. ctl->put = snd_akm4xxx_volume_put;
  471. ctl->private_value = AK_COMPOSE(idx/2, (idx%2) + 4, 0, 127); /* register 4 & 5 */
  472. ctl->private_data = ak;
  473. if ((err = snd_ctl_add(ak->card, snd_ctl_new(ctl, SNDRV_CTL_ELEM_ACCESS_READ|SNDRV_CTL_ELEM_ACCESS_WRITE))) < 0)
  474. goto __error;
  475. memset(ctl, 0, sizeof(*ctl));
  476. strcpy(ctl->id.name, "IPGA Analog Capture Volume");
  477. ctl->id.index = idx + ak->idx_offset * 2;
  478. ctl->id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
  479. ctl->count = 1;
  480. ctl->info = snd_akm4xxx_ipga_gain_info;
  481. ctl->get = snd_akm4xxx_ipga_gain_get;
  482. ctl->put = snd_akm4xxx_ipga_gain_put;
  483. ctl->private_value = AK_COMPOSE(idx/2, (idx%2) + 4, 0, 0); /* register 4 & 5 */
  484. ctl->private_data = ak;
  485. if ((err = snd_ctl_add(ak->card, snd_ctl_new(ctl, SNDRV_CTL_ELEM_ACCESS_READ|SNDRV_CTL_ELEM_ACCESS_WRITE))) < 0)
  486. goto __error;
  487. }
  488. if (ak->type == SND_AK4355 || ak->type == SND_AK4358)
  489. num_emphs = 1;
  490. else
  491. num_emphs = ak->num_dacs / 2;
  492. for (idx = 0; idx < num_emphs; idx++) {
  493. memset(ctl, 0, sizeof(*ctl));
  494. strcpy(ctl->id.name, "Deemphasis");
  495. ctl->id.index = idx + ak->idx_offset;
  496. ctl->id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
  497. ctl->count = 1;
  498. ctl->info = snd_akm4xxx_deemphasis_info;
  499. ctl->get = snd_akm4xxx_deemphasis_get;
  500. ctl->put = snd_akm4xxx_deemphasis_put;
  501. switch (ak->type) {
  502. case SND_AK4524:
  503. case SND_AK4528:
  504. ctl->private_value = AK_COMPOSE(idx, 3, 0, 0); /* register 3 */
  505. break;
  506. case SND_AK4529: {
  507. int shift = idx == 3 ? 6 : (2 - idx) * 2;
  508. ctl->private_value = AK_COMPOSE(0, 8, shift, 0); /* register 8 with shift */
  509. break;
  510. }
  511. case SND_AK4355:
  512. case SND_AK4358:
  513. ctl->private_value = AK_COMPOSE(idx, 3, 0, 0);
  514. break;
  515. case SND_AK4381:
  516. ctl->private_value = AK_COMPOSE(idx, 1, 1, 0);
  517. break;
  518. }
  519. ctl->private_data = ak;
  520. if ((err = snd_ctl_add(ak->card, snd_ctl_new(ctl, SNDRV_CTL_ELEM_ACCESS_READ|SNDRV_CTL_ELEM_ACCESS_WRITE))) < 0)
  521. goto __error;
  522. }
  523. err = 0;
  524. __error:
  525. kfree(ctl);
  526. return err;
  527. }
  528. static int __init alsa_akm4xxx_module_init(void)
  529. {
  530. return 0;
  531. }
  532. static void __exit alsa_akm4xxx_module_exit(void)
  533. {
  534. }
  535. module_init(alsa_akm4xxx_module_init)
  536. module_exit(alsa_akm4xxx_module_exit)
  537. EXPORT_SYMBOL(snd_akm4xxx_write);
  538. EXPORT_SYMBOL(snd_akm4xxx_reset);
  539. EXPORT_SYMBOL(snd_akm4xxx_init);
  540. EXPORT_SYMBOL(snd_akm4xxx_build_controls);