ak4531_codec.c 16 KB

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