ak4531_codec.c 17 KB

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