ak4531_codec.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  1. /*
  2. * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
  3. * Universal routines for AK4531 codec
  4. *
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. *
  20. */
  21. #include <linux/delay.h>
  22. #include <linux/init.h>
  23. #include <linux/slab.h>
  24. #include <linux/mutex.h>
  25. #include <linux/module.h>
  26. #include <sound/core.h>
  27. #include <sound/ak4531_codec.h>
  28. #include <sound/tlv.h>
  29. /*
  30. MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
  31. MODULE_DESCRIPTION("Universal routines for AK4531 codec");
  32. MODULE_LICENSE("GPL");
  33. */
  34. #ifdef CONFIG_PROC_FS
  35. static void snd_ak4531_proc_init(struct snd_card *card, struct snd_ak4531 *ak4531);
  36. #else
  37. #define snd_ak4531_proc_init(card,ak)
  38. #endif
  39. /*
  40. *
  41. */
  42. #if 0
  43. static void snd_ak4531_dump(struct snd_ak4531 *ak4531)
  44. {
  45. int idx;
  46. for (idx = 0; idx < 0x19; idx++)
  47. printk(KERN_DEBUG "ak4531 0x%x: 0x%x\n",
  48. idx, ak4531->regs[idx]);
  49. }
  50. #endif
  51. /*
  52. *
  53. */
  54. #define AK4531_SINGLE(xname, xindex, reg, shift, mask, invert) \
  55. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
  56. .info = snd_ak4531_info_single, \
  57. .get = snd_ak4531_get_single, .put = snd_ak4531_put_single, \
  58. .private_value = reg | (shift << 16) | (mask << 24) | (invert << 22) }
  59. #define AK4531_SINGLE_TLV(xname, xindex, reg, shift, mask, invert, xtlv) \
  60. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  61. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ, \
  62. .name = xname, .index = xindex, \
  63. .info = snd_ak4531_info_single, \
  64. .get = snd_ak4531_get_single, .put = snd_ak4531_put_single, \
  65. .private_value = reg | (shift << 16) | (mask << 24) | (invert << 22), \
  66. .tlv = { .p = (xtlv) } }
  67. static int snd_ak4531_info_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  68. {
  69. int mask = (kcontrol->private_value >> 24) & 0xff;
  70. uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
  71. uinfo->count = 1;
  72. uinfo->value.integer.min = 0;
  73. uinfo->value.integer.max = mask;
  74. return 0;
  75. }
  76. static int snd_ak4531_get_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  77. {
  78. struct snd_ak4531 *ak4531 = snd_kcontrol_chip(kcontrol);
  79. int reg = kcontrol->private_value & 0xff;
  80. int shift = (kcontrol->private_value >> 16) & 0x07;
  81. int mask = (kcontrol->private_value >> 24) & 0xff;
  82. int invert = (kcontrol->private_value >> 22) & 1;
  83. int val;
  84. mutex_lock(&ak4531->reg_mutex);
  85. val = (ak4531->regs[reg] >> shift) & mask;
  86. mutex_unlock(&ak4531->reg_mutex);
  87. if (invert) {
  88. val = mask - val;
  89. }
  90. ucontrol->value.integer.value[0] = val;
  91. return 0;
  92. }
  93. static int snd_ak4531_put_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  94. {
  95. struct snd_ak4531 *ak4531 = snd_kcontrol_chip(kcontrol);
  96. int reg = kcontrol->private_value & 0xff;
  97. int shift = (kcontrol->private_value >> 16) & 0x07;
  98. int mask = (kcontrol->private_value >> 24) & 0xff;
  99. int invert = (kcontrol->private_value >> 22) & 1;
  100. int change;
  101. int val;
  102. val = ucontrol->value.integer.value[0] & mask;
  103. if (invert) {
  104. val = mask - val;
  105. }
  106. val <<= shift;
  107. mutex_lock(&ak4531->reg_mutex);
  108. val = (ak4531->regs[reg] & ~(mask << shift)) | val;
  109. change = val != ak4531->regs[reg];
  110. ak4531->write(ak4531, reg, ak4531->regs[reg] = val);
  111. mutex_unlock(&ak4531->reg_mutex);
  112. return change;
  113. }
  114. #define AK4531_DOUBLE(xname, xindex, left_reg, right_reg, left_shift, right_shift, mask, invert) \
  115. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
  116. .info = snd_ak4531_info_double, \
  117. .get = snd_ak4531_get_double, .put = snd_ak4531_put_double, \
  118. .private_value = left_reg | (right_reg << 8) | (left_shift << 16) | (right_shift << 19) | (mask << 24) | (invert << 22) }
  119. #define AK4531_DOUBLE_TLV(xname, xindex, left_reg, right_reg, left_shift, right_shift, mask, invert, xtlv) \
  120. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  121. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ, \
  122. .name = xname, .index = xindex, \
  123. .info = snd_ak4531_info_double, \
  124. .get = snd_ak4531_get_double, .put = snd_ak4531_put_double, \
  125. .private_value = left_reg | (right_reg << 8) | (left_shift << 16) | (right_shift << 19) | (mask << 24) | (invert << 22), \
  126. .tlv = { .p = (xtlv) } }
  127. static int snd_ak4531_info_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  128. {
  129. int mask = (kcontrol->private_value >> 24) & 0xff;
  130. uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
  131. uinfo->count = 2;
  132. uinfo->value.integer.min = 0;
  133. uinfo->value.integer.max = mask;
  134. return 0;
  135. }
  136. static int snd_ak4531_get_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  137. {
  138. struct snd_ak4531 *ak4531 = snd_kcontrol_chip(kcontrol);
  139. int left_reg = kcontrol->private_value & 0xff;
  140. int right_reg = (kcontrol->private_value >> 8) & 0xff;
  141. int left_shift = (kcontrol->private_value >> 16) & 0x07;
  142. int right_shift = (kcontrol->private_value >> 19) & 0x07;
  143. int mask = (kcontrol->private_value >> 24) & 0xff;
  144. int invert = (kcontrol->private_value >> 22) & 1;
  145. int left, right;
  146. mutex_lock(&ak4531->reg_mutex);
  147. left = (ak4531->regs[left_reg] >> left_shift) & mask;
  148. right = (ak4531->regs[right_reg] >> right_shift) & mask;
  149. mutex_unlock(&ak4531->reg_mutex);
  150. if (invert) {
  151. left = mask - left;
  152. right = mask - right;
  153. }
  154. ucontrol->value.integer.value[0] = left;
  155. ucontrol->value.integer.value[1] = right;
  156. return 0;
  157. }
  158. static int snd_ak4531_put_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  159. {
  160. struct snd_ak4531 *ak4531 = snd_kcontrol_chip(kcontrol);
  161. int left_reg = kcontrol->private_value & 0xff;
  162. int right_reg = (kcontrol->private_value >> 8) & 0xff;
  163. int left_shift = (kcontrol->private_value >> 16) & 0x07;
  164. int right_shift = (kcontrol->private_value >> 19) & 0x07;
  165. int mask = (kcontrol->private_value >> 24) & 0xff;
  166. int invert = (kcontrol->private_value >> 22) & 1;
  167. int change;
  168. int left, right;
  169. left = ucontrol->value.integer.value[0] & mask;
  170. right = ucontrol->value.integer.value[1] & mask;
  171. if (invert) {
  172. left = mask - left;
  173. right = mask - right;
  174. }
  175. left <<= left_shift;
  176. right <<= right_shift;
  177. mutex_lock(&ak4531->reg_mutex);
  178. if (left_reg == right_reg) {
  179. left = (ak4531->regs[left_reg] & ~((mask << left_shift) | (mask << right_shift))) | left | right;
  180. change = left != ak4531->regs[left_reg];
  181. ak4531->write(ak4531, left_reg, ak4531->regs[left_reg] = left);
  182. } else {
  183. left = (ak4531->regs[left_reg] & ~(mask << left_shift)) | left;
  184. right = (ak4531->regs[right_reg] & ~(mask << right_shift)) | right;
  185. change = left != ak4531->regs[left_reg] || right != ak4531->regs[right_reg];
  186. ak4531->write(ak4531, left_reg, ak4531->regs[left_reg] = left);
  187. ak4531->write(ak4531, right_reg, ak4531->regs[right_reg] = right);
  188. }
  189. mutex_unlock(&ak4531->reg_mutex);
  190. return change;
  191. }
  192. #define AK4531_INPUT_SW(xname, xindex, reg1, reg2, left_shift, right_shift) \
  193. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
  194. .info = snd_ak4531_info_input_sw, \
  195. .get = snd_ak4531_get_input_sw, .put = snd_ak4531_put_input_sw, \
  196. .private_value = reg1 | (reg2 << 8) | (left_shift << 16) | (right_shift << 24) }
  197. static int snd_ak4531_info_input_sw(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  198. {
  199. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  200. uinfo->count = 4;
  201. uinfo->value.integer.min = 0;
  202. uinfo->value.integer.max = 1;
  203. return 0;
  204. }
  205. static int snd_ak4531_get_input_sw(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  206. {
  207. struct snd_ak4531 *ak4531 = snd_kcontrol_chip(kcontrol);
  208. int reg1 = kcontrol->private_value & 0xff;
  209. int reg2 = (kcontrol->private_value >> 8) & 0xff;
  210. int left_shift = (kcontrol->private_value >> 16) & 0x0f;
  211. int right_shift = (kcontrol->private_value >> 24) & 0x0f;
  212. mutex_lock(&ak4531->reg_mutex);
  213. ucontrol->value.integer.value[0] = (ak4531->regs[reg1] >> left_shift) & 1;
  214. ucontrol->value.integer.value[1] = (ak4531->regs[reg2] >> left_shift) & 1;
  215. ucontrol->value.integer.value[2] = (ak4531->regs[reg1] >> right_shift) & 1;
  216. ucontrol->value.integer.value[3] = (ak4531->regs[reg2] >> right_shift) & 1;
  217. mutex_unlock(&ak4531->reg_mutex);
  218. return 0;
  219. }
  220. static int snd_ak4531_put_input_sw(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  221. {
  222. struct snd_ak4531 *ak4531 = snd_kcontrol_chip(kcontrol);
  223. int reg1 = kcontrol->private_value & 0xff;
  224. int reg2 = (kcontrol->private_value >> 8) & 0xff;
  225. int left_shift = (kcontrol->private_value >> 16) & 0x0f;
  226. int right_shift = (kcontrol->private_value >> 24) & 0x0f;
  227. int change;
  228. int val1, val2;
  229. mutex_lock(&ak4531->reg_mutex);
  230. val1 = ak4531->regs[reg1] & ~((1 << left_shift) | (1 << right_shift));
  231. val2 = ak4531->regs[reg2] & ~((1 << left_shift) | (1 << right_shift));
  232. val1 |= (ucontrol->value.integer.value[0] & 1) << left_shift;
  233. val2 |= (ucontrol->value.integer.value[1] & 1) << left_shift;
  234. val1 |= (ucontrol->value.integer.value[2] & 1) << right_shift;
  235. val2 |= (ucontrol->value.integer.value[3] & 1) << right_shift;
  236. change = val1 != ak4531->regs[reg1] || val2 != ak4531->regs[reg2];
  237. ak4531->write(ak4531, reg1, ak4531->regs[reg1] = val1);
  238. ak4531->write(ak4531, reg2, ak4531->regs[reg2] = val2);
  239. mutex_unlock(&ak4531->reg_mutex);
  240. return change;
  241. }
  242. static const DECLARE_TLV_DB_SCALE(db_scale_master, -6200, 200, 0);
  243. static const DECLARE_TLV_DB_SCALE(db_scale_mono, -2800, 400, 0);
  244. static const DECLARE_TLV_DB_SCALE(db_scale_input, -5000, 200, 0);
  245. static struct snd_kcontrol_new snd_ak4531_controls[] __devinitdata = {
  246. AK4531_DOUBLE_TLV("Master Playback Switch", 0,
  247. AK4531_LMASTER, AK4531_RMASTER, 7, 7, 1, 1,
  248. db_scale_master),
  249. AK4531_DOUBLE("Master Playback Volume", 0, AK4531_LMASTER, AK4531_RMASTER, 0, 0, 0x1f, 1),
  250. AK4531_SINGLE_TLV("Master Mono Playback Switch", 0, AK4531_MONO_OUT, 7, 1, 1,
  251. db_scale_mono),
  252. AK4531_SINGLE("Master Mono Playback Volume", 0, AK4531_MONO_OUT, 0, 0x07, 1),
  253. AK4531_DOUBLE("PCM Switch", 0, AK4531_LVOICE, AK4531_RVOICE, 7, 7, 1, 1),
  254. AK4531_DOUBLE_TLV("PCM Volume", 0, AK4531_LVOICE, AK4531_RVOICE, 0, 0, 0x1f, 1,
  255. db_scale_input),
  256. AK4531_DOUBLE("PCM Playback Switch", 0, AK4531_OUT_SW2, AK4531_OUT_SW2, 3, 2, 1, 0),
  257. AK4531_DOUBLE("PCM Capture Switch", 0, AK4531_LIN_SW2, AK4531_RIN_SW2, 2, 2, 1, 0),
  258. AK4531_DOUBLE("PCM Switch", 1, AK4531_LFM, AK4531_RFM, 7, 7, 1, 1),
  259. AK4531_DOUBLE_TLV("PCM Volume", 1, AK4531_LFM, AK4531_RFM, 0, 0, 0x1f, 1,
  260. db_scale_input),
  261. AK4531_DOUBLE("PCM Playback Switch", 1, AK4531_OUT_SW1, AK4531_OUT_SW1, 6, 5, 1, 0),
  262. AK4531_INPUT_SW("PCM Capture Route", 1, AK4531_LIN_SW1, AK4531_RIN_SW1, 6, 5),
  263. AK4531_DOUBLE("CD Switch", 0, AK4531_LCD, AK4531_RCD, 7, 7, 1, 1),
  264. AK4531_DOUBLE_TLV("CD Volume", 0, AK4531_LCD, AK4531_RCD, 0, 0, 0x1f, 1,
  265. db_scale_input),
  266. AK4531_DOUBLE("CD Playback Switch", 0, AK4531_OUT_SW1, AK4531_OUT_SW1, 2, 1, 1, 0),
  267. AK4531_INPUT_SW("CD Capture Route", 0, AK4531_LIN_SW1, AK4531_RIN_SW1, 2, 1),
  268. AK4531_DOUBLE("Line Switch", 0, AK4531_LLINE, AK4531_RLINE, 7, 7, 1, 1),
  269. AK4531_DOUBLE_TLV("Line Volume", 0, AK4531_LLINE, AK4531_RLINE, 0, 0, 0x1f, 1,
  270. db_scale_input),
  271. AK4531_DOUBLE("Line Playback Switch", 0, AK4531_OUT_SW1, AK4531_OUT_SW1, 4, 3, 1, 0),
  272. AK4531_INPUT_SW("Line Capture Route", 0, AK4531_LIN_SW1, AK4531_RIN_SW1, 4, 3),
  273. AK4531_DOUBLE("Aux Switch", 0, AK4531_LAUXA, AK4531_RAUXA, 7, 7, 1, 1),
  274. AK4531_DOUBLE_TLV("Aux Volume", 0, AK4531_LAUXA, AK4531_RAUXA, 0, 0, 0x1f, 1,
  275. db_scale_input),
  276. AK4531_DOUBLE("Aux Playback Switch", 0, AK4531_OUT_SW2, AK4531_OUT_SW2, 5, 4, 1, 0),
  277. AK4531_INPUT_SW("Aux Capture Route", 0, AK4531_LIN_SW2, AK4531_RIN_SW2, 4, 3),
  278. AK4531_SINGLE("Mono Switch", 0, AK4531_MONO1, 7, 1, 1),
  279. AK4531_SINGLE_TLV("Mono Volume", 0, AK4531_MONO1, 0, 0x1f, 1, db_scale_input),
  280. AK4531_SINGLE("Mono Playback Switch", 0, AK4531_OUT_SW2, 0, 1, 0),
  281. AK4531_DOUBLE("Mono Capture Switch", 0, AK4531_LIN_SW2, AK4531_RIN_SW2, 0, 0, 1, 0),
  282. AK4531_SINGLE("Mono Switch", 1, AK4531_MONO2, 7, 1, 1),
  283. AK4531_SINGLE_TLV("Mono Volume", 1, AK4531_MONO2, 0, 0x1f, 1, db_scale_input),
  284. AK4531_SINGLE("Mono Playback Switch", 1, AK4531_OUT_SW2, 1, 1, 0),
  285. AK4531_DOUBLE("Mono Capture Switch", 1, AK4531_LIN_SW2, AK4531_RIN_SW2, 1, 1, 1, 0),
  286. AK4531_SINGLE_TLV("Mic Volume", 0, AK4531_MIC, 0, 0x1f, 1, db_scale_input),
  287. AK4531_SINGLE("Mic Switch", 0, AK4531_MIC, 7, 1, 1),
  288. AK4531_SINGLE("Mic Playback Switch", 0, AK4531_OUT_SW1, 0, 1, 0),
  289. AK4531_DOUBLE("Mic Capture Switch", 0, AK4531_LIN_SW1, AK4531_RIN_SW1, 0, 0, 1, 0),
  290. AK4531_DOUBLE("Mic Bypass Capture Switch", 0, AK4531_LIN_SW2, AK4531_RIN_SW2, 7, 7, 1, 0),
  291. AK4531_DOUBLE("Mono1 Bypass Capture Switch", 0, AK4531_LIN_SW2, AK4531_RIN_SW2, 6, 6, 1, 0),
  292. AK4531_DOUBLE("Mono2 Bypass Capture Switch", 0, AK4531_LIN_SW2, AK4531_RIN_SW2, 5, 5, 1, 0),
  293. AK4531_SINGLE("AD Input Select", 0, AK4531_AD_IN, 0, 1, 0),
  294. AK4531_SINGLE("Mic Boost (+30dB)", 0, AK4531_MIC_GAIN, 0, 1, 0)
  295. };
  296. static int snd_ak4531_free(struct snd_ak4531 *ak4531)
  297. {
  298. if (ak4531) {
  299. if (ak4531->private_free)
  300. ak4531->private_free(ak4531);
  301. kfree(ak4531);
  302. }
  303. return 0;
  304. }
  305. static int snd_ak4531_dev_free(struct snd_device *device)
  306. {
  307. struct snd_ak4531 *ak4531 = device->device_data;
  308. return snd_ak4531_free(ak4531);
  309. }
  310. static u8 snd_ak4531_initial_map[0x19 + 1] = {
  311. 0x9f, /* 00: Master Volume Lch */
  312. 0x9f, /* 01: Master Volume Rch */
  313. 0x9f, /* 02: Voice Volume Lch */
  314. 0x9f, /* 03: Voice Volume Rch */
  315. 0x9f, /* 04: FM Volume Lch */
  316. 0x9f, /* 05: FM Volume Rch */
  317. 0x9f, /* 06: CD Audio Volume Lch */
  318. 0x9f, /* 07: CD Audio Volume Rch */
  319. 0x9f, /* 08: Line Volume Lch */
  320. 0x9f, /* 09: Line Volume Rch */
  321. 0x9f, /* 0a: Aux Volume Lch */
  322. 0x9f, /* 0b: Aux Volume Rch */
  323. 0x9f, /* 0c: Mono1 Volume */
  324. 0x9f, /* 0d: Mono2 Volume */
  325. 0x9f, /* 0e: Mic Volume */
  326. 0x87, /* 0f: Mono-out Volume */
  327. 0x00, /* 10: Output Mixer SW1 */
  328. 0x00, /* 11: Output Mixer SW2 */
  329. 0x00, /* 12: Lch Input Mixer SW1 */
  330. 0x00, /* 13: Rch Input Mixer SW1 */
  331. 0x00, /* 14: Lch Input Mixer SW2 */
  332. 0x00, /* 15: Rch Input Mixer SW2 */
  333. 0x00, /* 16: Reset & Power Down */
  334. 0x00, /* 17: Clock Select */
  335. 0x00, /* 18: AD Input Select */
  336. 0x01 /* 19: Mic Amp Setup */
  337. };
  338. int __devinit snd_ak4531_mixer(struct snd_card *card,
  339. struct snd_ak4531 *_ak4531,
  340. struct snd_ak4531 **rak4531)
  341. {
  342. unsigned int idx;
  343. int err;
  344. struct snd_ak4531 *ak4531;
  345. static struct snd_device_ops ops = {
  346. .dev_free = snd_ak4531_dev_free,
  347. };
  348. if (snd_BUG_ON(!card || !_ak4531))
  349. return -EINVAL;
  350. if (rak4531)
  351. *rak4531 = NULL;
  352. ak4531 = kzalloc(sizeof(*ak4531), GFP_KERNEL);
  353. if (ak4531 == NULL)
  354. return -ENOMEM;
  355. *ak4531 = *_ak4531;
  356. mutex_init(&ak4531->reg_mutex);
  357. if ((err = snd_component_add(card, "AK4531")) < 0) {
  358. snd_ak4531_free(ak4531);
  359. return err;
  360. }
  361. strcpy(card->mixername, "Asahi Kasei AK4531");
  362. ak4531->write(ak4531, AK4531_RESET, 0x03); /* no RST, PD */
  363. udelay(100);
  364. ak4531->write(ak4531, AK4531_CLOCK, 0x00); /* CODEC ADC and CODEC DAC use {LR,B}CLK2 and run off LRCLK2 PLL */
  365. for (idx = 0; idx <= 0x19; idx++) {
  366. if (idx == AK4531_RESET || idx == AK4531_CLOCK)
  367. continue;
  368. ak4531->write(ak4531, idx, ak4531->regs[idx] = snd_ak4531_initial_map[idx]); /* recording source is mixer */
  369. }
  370. for (idx = 0; idx < ARRAY_SIZE(snd_ak4531_controls); idx++) {
  371. if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_ak4531_controls[idx], ak4531))) < 0) {
  372. snd_ak4531_free(ak4531);
  373. return err;
  374. }
  375. }
  376. snd_ak4531_proc_init(card, ak4531);
  377. if ((err = snd_device_new(card, SNDRV_DEV_CODEC, ak4531, &ops)) < 0) {
  378. snd_ak4531_free(ak4531);
  379. return err;
  380. }
  381. #if 0
  382. snd_ak4531_dump(ak4531);
  383. #endif
  384. if (rak4531)
  385. *rak4531 = ak4531;
  386. return 0;
  387. }
  388. /*
  389. * power management
  390. */
  391. #ifdef CONFIG_PM
  392. void snd_ak4531_suspend(struct snd_ak4531 *ak4531)
  393. {
  394. /* mute */
  395. ak4531->write(ak4531, AK4531_LMASTER, 0x9f);
  396. ak4531->write(ak4531, AK4531_RMASTER, 0x9f);
  397. /* powerdown */
  398. ak4531->write(ak4531, AK4531_RESET, 0x01);
  399. }
  400. void snd_ak4531_resume(struct snd_ak4531 *ak4531)
  401. {
  402. int idx;
  403. /* initialize */
  404. ak4531->write(ak4531, AK4531_RESET, 0x03);
  405. udelay(100);
  406. ak4531->write(ak4531, AK4531_CLOCK, 0x00);
  407. /* restore mixer registers */
  408. for (idx = 0; idx <= 0x19; idx++) {
  409. if (idx == AK4531_RESET || idx == AK4531_CLOCK)
  410. continue;
  411. ak4531->write(ak4531, idx, ak4531->regs[idx]);
  412. }
  413. }
  414. #endif
  415. #ifdef CONFIG_PROC_FS
  416. /*
  417. * /proc interface
  418. */
  419. static void snd_ak4531_proc_read(struct snd_info_entry *entry,
  420. struct snd_info_buffer *buffer)
  421. {
  422. struct snd_ak4531 *ak4531 = entry->private_data;
  423. snd_iprintf(buffer, "Asahi Kasei AK4531\n\n");
  424. snd_iprintf(buffer, "Recording source : %s\n"
  425. "MIC gain : %s\n",
  426. ak4531->regs[AK4531_AD_IN] & 1 ? "external" : "mixer",
  427. ak4531->regs[AK4531_MIC_GAIN] & 1 ? "+30dB" : "+0dB");
  428. }
  429. static void __devinit
  430. snd_ak4531_proc_init(struct snd_card *card, struct snd_ak4531 *ak4531)
  431. {
  432. struct snd_info_entry *entry;
  433. if (! snd_card_proc_new(card, "ak4531", &entry))
  434. snd_info_set_text_ops(entry, ak4531, snd_ak4531_proc_read);
  435. }
  436. #endif