emumixer.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000
  1. /*
  2. * Copyright (c) by Jaroslav Kysela <perex@suse.cz>,
  3. * Takashi Iwai <tiwai@suse.de>
  4. * Creative Labs, Inc.
  5. * Routines for control of EMU10K1 chips / mixer routines
  6. * Multichannel PCM support Copyright (c) Lee Revell <rlrevell@joe-job.com>
  7. *
  8. * BUGS:
  9. * --
  10. *
  11. * TODO:
  12. * --
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation; either version 2 of the License, or
  17. * (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  27. *
  28. */
  29. #include <sound/driver.h>
  30. #include <linux/time.h>
  31. #include <linux/init.h>
  32. #include <sound/core.h>
  33. #include <sound/emu10k1.h>
  34. #define AC97_ID_STAC9758 0x83847658
  35. static int snd_emu10k1_spdif_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  36. {
  37. uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
  38. uinfo->count = 1;
  39. return 0;
  40. }
  41. static int snd_emu10k1_spdif_get(struct snd_kcontrol *kcontrol,
  42. struct snd_ctl_elem_value *ucontrol)
  43. {
  44. struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
  45. unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  46. unsigned long flags;
  47. spin_lock_irqsave(&emu->reg_lock, flags);
  48. ucontrol->value.iec958.status[0] = (emu->spdif_bits[idx] >> 0) & 0xff;
  49. ucontrol->value.iec958.status[1] = (emu->spdif_bits[idx] >> 8) & 0xff;
  50. ucontrol->value.iec958.status[2] = (emu->spdif_bits[idx] >> 16) & 0xff;
  51. ucontrol->value.iec958.status[3] = (emu->spdif_bits[idx] >> 24) & 0xff;
  52. spin_unlock_irqrestore(&emu->reg_lock, flags);
  53. return 0;
  54. }
  55. static int snd_emu10k1_spdif_get_mask(struct snd_kcontrol *kcontrol,
  56. struct snd_ctl_elem_value *ucontrol)
  57. {
  58. ucontrol->value.iec958.status[0] = 0xff;
  59. ucontrol->value.iec958.status[1] = 0xff;
  60. ucontrol->value.iec958.status[2] = 0xff;
  61. ucontrol->value.iec958.status[3] = 0xff;
  62. return 0;
  63. }
  64. #if 0
  65. static int snd_audigy_spdif_output_rate_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  66. {
  67. static char *texts[] = {"44100", "48000", "96000"};
  68. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  69. uinfo->count = 1;
  70. uinfo->value.enumerated.items = 3;
  71. if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
  72. uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
  73. strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
  74. return 0;
  75. }
  76. static int snd_audigy_spdif_output_rate_get(struct snd_kcontrol *kcontrol,
  77. struct snd_ctl_elem_value *ucontrol)
  78. {
  79. struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
  80. unsigned int tmp;
  81. unsigned long flags;
  82. spin_lock_irqsave(&emu->reg_lock, flags);
  83. tmp = snd_emu10k1_ptr_read(emu, A_SPDIF_SAMPLERATE, 0);
  84. switch (tmp & A_SPDIF_RATE_MASK) {
  85. case A_SPDIF_44100:
  86. ucontrol->value.enumerated.item[0] = 0;
  87. break;
  88. case A_SPDIF_48000:
  89. ucontrol->value.enumerated.item[0] = 1;
  90. break;
  91. case A_SPDIF_96000:
  92. ucontrol->value.enumerated.item[0] = 2;
  93. break;
  94. default:
  95. ucontrol->value.enumerated.item[0] = 1;
  96. }
  97. spin_unlock_irqrestore(&emu->reg_lock, flags);
  98. return 0;
  99. }
  100. static int snd_audigy_spdif_output_rate_put(struct snd_kcontrol *kcontrol,
  101. struct snd_ctl_elem_value *ucontrol)
  102. {
  103. struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
  104. int change;
  105. unsigned int reg, val, tmp;
  106. unsigned long flags;
  107. switch(ucontrol->value.enumerated.item[0]) {
  108. case 0:
  109. val = A_SPDIF_44100;
  110. break;
  111. case 1:
  112. val = A_SPDIF_48000;
  113. break;
  114. case 2:
  115. val = A_SPDIF_96000;
  116. break;
  117. default:
  118. val = A_SPDIF_48000;
  119. break;
  120. }
  121. spin_lock_irqsave(&emu->reg_lock, flags);
  122. reg = snd_emu10k1_ptr_read(emu, A_SPDIF_SAMPLERATE, 0);
  123. tmp = reg & ~A_SPDIF_RATE_MASK;
  124. tmp |= val;
  125. if ((change = (tmp != reg)))
  126. snd_emu10k1_ptr_write(emu, A_SPDIF_SAMPLERATE, 0, tmp);
  127. spin_unlock_irqrestore(&emu->reg_lock, flags);
  128. return change;
  129. }
  130. static struct snd_kcontrol_new snd_audigy_spdif_output_rate =
  131. {
  132. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  133. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  134. .name = "Audigy SPDIF Output Sample Rate",
  135. .count = 1,
  136. .info = snd_audigy_spdif_output_rate_info,
  137. .get = snd_audigy_spdif_output_rate_get,
  138. .put = snd_audigy_spdif_output_rate_put
  139. };
  140. #endif
  141. static int snd_emu10k1_spdif_put(struct snd_kcontrol *kcontrol,
  142. struct snd_ctl_elem_value *ucontrol)
  143. {
  144. struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
  145. unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  146. int change;
  147. unsigned int val;
  148. unsigned long flags;
  149. val = (ucontrol->value.iec958.status[0] << 0) |
  150. (ucontrol->value.iec958.status[1] << 8) |
  151. (ucontrol->value.iec958.status[2] << 16) |
  152. (ucontrol->value.iec958.status[3] << 24);
  153. spin_lock_irqsave(&emu->reg_lock, flags);
  154. change = val != emu->spdif_bits[idx];
  155. if (change) {
  156. snd_emu10k1_ptr_write(emu, SPCS0 + idx, 0, val);
  157. emu->spdif_bits[idx] = val;
  158. }
  159. spin_unlock_irqrestore(&emu->reg_lock, flags);
  160. return change;
  161. }
  162. static struct snd_kcontrol_new snd_emu10k1_spdif_mask_control =
  163. {
  164. .access = SNDRV_CTL_ELEM_ACCESS_READ,
  165. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  166. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,MASK),
  167. .count = 4,
  168. .info = snd_emu10k1_spdif_info,
  169. .get = snd_emu10k1_spdif_get_mask
  170. };
  171. static struct snd_kcontrol_new snd_emu10k1_spdif_control =
  172. {
  173. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  174. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
  175. .count = 4,
  176. .info = snd_emu10k1_spdif_info,
  177. .get = snd_emu10k1_spdif_get,
  178. .put = snd_emu10k1_spdif_put
  179. };
  180. static void update_emu10k1_fxrt(struct snd_emu10k1 *emu, int voice, unsigned char *route)
  181. {
  182. if (emu->audigy) {
  183. snd_emu10k1_ptr_write(emu, A_FXRT1, voice,
  184. snd_emu10k1_compose_audigy_fxrt1(route));
  185. snd_emu10k1_ptr_write(emu, A_FXRT2, voice,
  186. snd_emu10k1_compose_audigy_fxrt2(route));
  187. } else {
  188. snd_emu10k1_ptr_write(emu, FXRT, voice,
  189. snd_emu10k1_compose_send_routing(route));
  190. }
  191. }
  192. static void update_emu10k1_send_volume(struct snd_emu10k1 *emu, int voice, unsigned char *volume)
  193. {
  194. snd_emu10k1_ptr_write(emu, PTRX_FXSENDAMOUNT_A, voice, volume[0]);
  195. snd_emu10k1_ptr_write(emu, PTRX_FXSENDAMOUNT_B, voice, volume[1]);
  196. snd_emu10k1_ptr_write(emu, PSST_FXSENDAMOUNT_C, voice, volume[2]);
  197. snd_emu10k1_ptr_write(emu, DSL_FXSENDAMOUNT_D, voice, volume[3]);
  198. if (emu->audigy) {
  199. unsigned int val = ((unsigned int)volume[4] << 24) |
  200. ((unsigned int)volume[5] << 16) |
  201. ((unsigned int)volume[6] << 8) |
  202. (unsigned int)volume[7];
  203. snd_emu10k1_ptr_write(emu, A_SENDAMOUNTS, voice, val);
  204. }
  205. }
  206. /* PCM stream controls */
  207. static int snd_emu10k1_send_routing_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  208. {
  209. struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
  210. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  211. uinfo->count = emu->audigy ? 3*8 : 3*4;
  212. uinfo->value.integer.min = 0;
  213. uinfo->value.integer.max = emu->audigy ? 0x3f : 0x0f;
  214. return 0;
  215. }
  216. static int snd_emu10k1_send_routing_get(struct snd_kcontrol *kcontrol,
  217. struct snd_ctl_elem_value *ucontrol)
  218. {
  219. unsigned long flags;
  220. struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
  221. struct snd_emu10k1_pcm_mixer *mix =
  222. &emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
  223. int voice, idx;
  224. int num_efx = emu->audigy ? 8 : 4;
  225. int mask = emu->audigy ? 0x3f : 0x0f;
  226. spin_lock_irqsave(&emu->reg_lock, flags);
  227. for (voice = 0; voice < 3; voice++)
  228. for (idx = 0; idx < num_efx; idx++)
  229. ucontrol->value.integer.value[(voice * num_efx) + idx] =
  230. mix->send_routing[voice][idx] & mask;
  231. spin_unlock_irqrestore(&emu->reg_lock, flags);
  232. return 0;
  233. }
  234. static int snd_emu10k1_send_routing_put(struct snd_kcontrol *kcontrol,
  235. struct snd_ctl_elem_value *ucontrol)
  236. {
  237. unsigned long flags;
  238. struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
  239. struct snd_emu10k1_pcm_mixer *mix =
  240. &emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
  241. int change = 0, voice, idx, val;
  242. int num_efx = emu->audigy ? 8 : 4;
  243. int mask = emu->audigy ? 0x3f : 0x0f;
  244. spin_lock_irqsave(&emu->reg_lock, flags);
  245. for (voice = 0; voice < 3; voice++)
  246. for (idx = 0; idx < num_efx; idx++) {
  247. val = ucontrol->value.integer.value[(voice * num_efx) + idx] & mask;
  248. if (mix->send_routing[voice][idx] != val) {
  249. mix->send_routing[voice][idx] = val;
  250. change = 1;
  251. }
  252. }
  253. if (change && mix->epcm) {
  254. if (mix->epcm->voices[0] && mix->epcm->voices[1]) {
  255. update_emu10k1_fxrt(emu, mix->epcm->voices[0]->number,
  256. &mix->send_routing[1][0]);
  257. update_emu10k1_fxrt(emu, mix->epcm->voices[1]->number,
  258. &mix->send_routing[2][0]);
  259. } else if (mix->epcm->voices[0]) {
  260. update_emu10k1_fxrt(emu, mix->epcm->voices[0]->number,
  261. &mix->send_routing[0][0]);
  262. }
  263. }
  264. spin_unlock_irqrestore(&emu->reg_lock, flags);
  265. return change;
  266. }
  267. static struct snd_kcontrol_new snd_emu10k1_send_routing_control =
  268. {
  269. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
  270. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  271. .name = "EMU10K1 PCM Send Routing",
  272. .count = 32,
  273. .info = snd_emu10k1_send_routing_info,
  274. .get = snd_emu10k1_send_routing_get,
  275. .put = snd_emu10k1_send_routing_put
  276. };
  277. static int snd_emu10k1_send_volume_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  278. {
  279. struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
  280. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  281. uinfo->count = emu->audigy ? 3*8 : 3*4;
  282. uinfo->value.integer.min = 0;
  283. uinfo->value.integer.max = 255;
  284. return 0;
  285. }
  286. static int snd_emu10k1_send_volume_get(struct snd_kcontrol *kcontrol,
  287. struct snd_ctl_elem_value *ucontrol)
  288. {
  289. unsigned long flags;
  290. struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
  291. struct snd_emu10k1_pcm_mixer *mix =
  292. &emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
  293. int idx;
  294. int num_efx = emu->audigy ? 8 : 4;
  295. spin_lock_irqsave(&emu->reg_lock, flags);
  296. for (idx = 0; idx < 3*num_efx; idx++)
  297. ucontrol->value.integer.value[idx] = mix->send_volume[idx/num_efx][idx%num_efx];
  298. spin_unlock_irqrestore(&emu->reg_lock, flags);
  299. return 0;
  300. }
  301. static int snd_emu10k1_send_volume_put(struct snd_kcontrol *kcontrol,
  302. struct snd_ctl_elem_value *ucontrol)
  303. {
  304. unsigned long flags;
  305. struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
  306. struct snd_emu10k1_pcm_mixer *mix =
  307. &emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
  308. int change = 0, idx, val;
  309. int num_efx = emu->audigy ? 8 : 4;
  310. spin_lock_irqsave(&emu->reg_lock, flags);
  311. for (idx = 0; idx < 3*num_efx; idx++) {
  312. val = ucontrol->value.integer.value[idx] & 255;
  313. if (mix->send_volume[idx/num_efx][idx%num_efx] != val) {
  314. mix->send_volume[idx/num_efx][idx%num_efx] = val;
  315. change = 1;
  316. }
  317. }
  318. if (change && mix->epcm) {
  319. if (mix->epcm->voices[0] && mix->epcm->voices[1]) {
  320. update_emu10k1_send_volume(emu, mix->epcm->voices[0]->number,
  321. &mix->send_volume[1][0]);
  322. update_emu10k1_send_volume(emu, mix->epcm->voices[1]->number,
  323. &mix->send_volume[2][0]);
  324. } else if (mix->epcm->voices[0]) {
  325. update_emu10k1_send_volume(emu, mix->epcm->voices[0]->number,
  326. &mix->send_volume[0][0]);
  327. }
  328. }
  329. spin_unlock_irqrestore(&emu->reg_lock, flags);
  330. return change;
  331. }
  332. static struct snd_kcontrol_new snd_emu10k1_send_volume_control =
  333. {
  334. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
  335. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  336. .name = "EMU10K1 PCM Send Volume",
  337. .count = 32,
  338. .info = snd_emu10k1_send_volume_info,
  339. .get = snd_emu10k1_send_volume_get,
  340. .put = snd_emu10k1_send_volume_put
  341. };
  342. static int snd_emu10k1_attn_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  343. {
  344. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  345. uinfo->count = 3;
  346. uinfo->value.integer.min = 0;
  347. uinfo->value.integer.max = 0xffff;
  348. return 0;
  349. }
  350. static int snd_emu10k1_attn_get(struct snd_kcontrol *kcontrol,
  351. struct snd_ctl_elem_value *ucontrol)
  352. {
  353. struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
  354. struct snd_emu10k1_pcm_mixer *mix =
  355. &emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
  356. unsigned long flags;
  357. int idx;
  358. spin_lock_irqsave(&emu->reg_lock, flags);
  359. for (idx = 0; idx < 3; idx++)
  360. ucontrol->value.integer.value[idx] = mix->attn[idx];
  361. spin_unlock_irqrestore(&emu->reg_lock, flags);
  362. return 0;
  363. }
  364. static int snd_emu10k1_attn_put(struct snd_kcontrol *kcontrol,
  365. struct snd_ctl_elem_value *ucontrol)
  366. {
  367. unsigned long flags;
  368. struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
  369. struct snd_emu10k1_pcm_mixer *mix =
  370. &emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
  371. int change = 0, idx, val;
  372. spin_lock_irqsave(&emu->reg_lock, flags);
  373. for (idx = 0; idx < 3; idx++) {
  374. val = ucontrol->value.integer.value[idx] & 0xffff;
  375. if (mix->attn[idx] != val) {
  376. mix->attn[idx] = val;
  377. change = 1;
  378. }
  379. }
  380. if (change && mix->epcm) {
  381. if (mix->epcm->voices[0] && mix->epcm->voices[1]) {
  382. snd_emu10k1_ptr_write(emu, VTFT_VOLUMETARGET, mix->epcm->voices[0]->number, mix->attn[1]);
  383. snd_emu10k1_ptr_write(emu, VTFT_VOLUMETARGET, mix->epcm->voices[1]->number, mix->attn[2]);
  384. } else if (mix->epcm->voices[0]) {
  385. snd_emu10k1_ptr_write(emu, VTFT_VOLUMETARGET, mix->epcm->voices[0]->number, mix->attn[0]);
  386. }
  387. }
  388. spin_unlock_irqrestore(&emu->reg_lock, flags);
  389. return change;
  390. }
  391. static struct snd_kcontrol_new snd_emu10k1_attn_control =
  392. {
  393. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
  394. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  395. .name = "EMU10K1 PCM Volume",
  396. .count = 32,
  397. .info = snd_emu10k1_attn_info,
  398. .get = snd_emu10k1_attn_get,
  399. .put = snd_emu10k1_attn_put
  400. };
  401. /* Mutichannel PCM stream controls */
  402. static int snd_emu10k1_efx_send_routing_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  403. {
  404. struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
  405. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  406. uinfo->count = emu->audigy ? 8 : 4;
  407. uinfo->value.integer.min = 0;
  408. uinfo->value.integer.max = emu->audigy ? 0x3f : 0x0f;
  409. return 0;
  410. }
  411. static int snd_emu10k1_efx_send_routing_get(struct snd_kcontrol *kcontrol,
  412. struct snd_ctl_elem_value *ucontrol)
  413. {
  414. unsigned long flags;
  415. struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
  416. struct snd_emu10k1_pcm_mixer *mix =
  417. &emu->efx_pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
  418. int idx;
  419. int num_efx = emu->audigy ? 8 : 4;
  420. int mask = emu->audigy ? 0x3f : 0x0f;
  421. spin_lock_irqsave(&emu->reg_lock, flags);
  422. for (idx = 0; idx < num_efx; idx++)
  423. ucontrol->value.integer.value[idx] =
  424. mix->send_routing[0][idx] & mask;
  425. spin_unlock_irqrestore(&emu->reg_lock, flags);
  426. return 0;
  427. }
  428. static int snd_emu10k1_efx_send_routing_put(struct snd_kcontrol *kcontrol,
  429. struct snd_ctl_elem_value *ucontrol)
  430. {
  431. unsigned long flags;
  432. struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
  433. int ch = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  434. struct snd_emu10k1_pcm_mixer *mix = &emu->efx_pcm_mixer[ch];
  435. int change = 0, idx, val;
  436. int num_efx = emu->audigy ? 8 : 4;
  437. int mask = emu->audigy ? 0x3f : 0x0f;
  438. spin_lock_irqsave(&emu->reg_lock, flags);
  439. for (idx = 0; idx < num_efx; idx++) {
  440. val = ucontrol->value.integer.value[idx] & mask;
  441. if (mix->send_routing[0][idx] != val) {
  442. mix->send_routing[0][idx] = val;
  443. change = 1;
  444. }
  445. }
  446. if (change && mix->epcm) {
  447. if (mix->epcm->voices[ch]) {
  448. update_emu10k1_fxrt(emu, mix->epcm->voices[ch]->number,
  449. &mix->send_routing[0][0]);
  450. }
  451. }
  452. spin_unlock_irqrestore(&emu->reg_lock, flags);
  453. return change;
  454. }
  455. static struct snd_kcontrol_new snd_emu10k1_efx_send_routing_control =
  456. {
  457. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
  458. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  459. .name = "Multichannel PCM Send Routing",
  460. .count = 16,
  461. .info = snd_emu10k1_efx_send_routing_info,
  462. .get = snd_emu10k1_efx_send_routing_get,
  463. .put = snd_emu10k1_efx_send_routing_put
  464. };
  465. static int snd_emu10k1_efx_send_volume_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  466. {
  467. struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
  468. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  469. uinfo->count = emu->audigy ? 8 : 4;
  470. uinfo->value.integer.min = 0;
  471. uinfo->value.integer.max = 255;
  472. return 0;
  473. }
  474. static int snd_emu10k1_efx_send_volume_get(struct snd_kcontrol *kcontrol,
  475. struct snd_ctl_elem_value *ucontrol)
  476. {
  477. unsigned long flags;
  478. struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
  479. struct snd_emu10k1_pcm_mixer *mix =
  480. &emu->efx_pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
  481. int idx;
  482. int num_efx = emu->audigy ? 8 : 4;
  483. spin_lock_irqsave(&emu->reg_lock, flags);
  484. for (idx = 0; idx < num_efx; idx++)
  485. ucontrol->value.integer.value[idx] = mix->send_volume[0][idx];
  486. spin_unlock_irqrestore(&emu->reg_lock, flags);
  487. return 0;
  488. }
  489. static int snd_emu10k1_efx_send_volume_put(struct snd_kcontrol *kcontrol,
  490. struct snd_ctl_elem_value *ucontrol)
  491. {
  492. unsigned long flags;
  493. struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
  494. int ch = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  495. struct snd_emu10k1_pcm_mixer *mix = &emu->efx_pcm_mixer[ch];
  496. int change = 0, idx, val;
  497. int num_efx = emu->audigy ? 8 : 4;
  498. spin_lock_irqsave(&emu->reg_lock, flags);
  499. for (idx = 0; idx < num_efx; idx++) {
  500. val = ucontrol->value.integer.value[idx] & 255;
  501. if (mix->send_volume[0][idx] != val) {
  502. mix->send_volume[0][idx] = val;
  503. change = 1;
  504. }
  505. }
  506. if (change && mix->epcm) {
  507. if (mix->epcm->voices[ch]) {
  508. update_emu10k1_send_volume(emu, mix->epcm->voices[ch]->number,
  509. &mix->send_volume[0][0]);
  510. }
  511. }
  512. spin_unlock_irqrestore(&emu->reg_lock, flags);
  513. return change;
  514. }
  515. static struct snd_kcontrol_new snd_emu10k1_efx_send_volume_control =
  516. {
  517. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
  518. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  519. .name = "Multichannel PCM Send Volume",
  520. .count = 16,
  521. .info = snd_emu10k1_efx_send_volume_info,
  522. .get = snd_emu10k1_efx_send_volume_get,
  523. .put = snd_emu10k1_efx_send_volume_put
  524. };
  525. static int snd_emu10k1_efx_attn_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  526. {
  527. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  528. uinfo->count = 1;
  529. uinfo->value.integer.min = 0;
  530. uinfo->value.integer.max = 0xffff;
  531. return 0;
  532. }
  533. static int snd_emu10k1_efx_attn_get(struct snd_kcontrol *kcontrol,
  534. struct snd_ctl_elem_value *ucontrol)
  535. {
  536. struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
  537. struct snd_emu10k1_pcm_mixer *mix =
  538. &emu->efx_pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
  539. unsigned long flags;
  540. spin_lock_irqsave(&emu->reg_lock, flags);
  541. ucontrol->value.integer.value[0] = mix->attn[0];
  542. spin_unlock_irqrestore(&emu->reg_lock, flags);
  543. return 0;
  544. }
  545. static int snd_emu10k1_efx_attn_put(struct snd_kcontrol *kcontrol,
  546. struct snd_ctl_elem_value *ucontrol)
  547. {
  548. unsigned long flags;
  549. struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
  550. int ch = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  551. struct snd_emu10k1_pcm_mixer *mix = &emu->efx_pcm_mixer[ch];
  552. int change = 0, val;
  553. spin_lock_irqsave(&emu->reg_lock, flags);
  554. val = ucontrol->value.integer.value[0] & 0xffff;
  555. if (mix->attn[0] != val) {
  556. mix->attn[0] = val;
  557. change = 1;
  558. }
  559. if (change && mix->epcm) {
  560. if (mix->epcm->voices[ch]) {
  561. snd_emu10k1_ptr_write(emu, VTFT_VOLUMETARGET, mix->epcm->voices[ch]->number, mix->attn[0]);
  562. }
  563. }
  564. spin_unlock_irqrestore(&emu->reg_lock, flags);
  565. return change;
  566. }
  567. static struct snd_kcontrol_new snd_emu10k1_efx_attn_control =
  568. {
  569. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
  570. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  571. .name = "Multichannel PCM Volume",
  572. .count = 16,
  573. .info = snd_emu10k1_efx_attn_info,
  574. .get = snd_emu10k1_efx_attn_get,
  575. .put = snd_emu10k1_efx_attn_put
  576. };
  577. static int snd_emu10k1_shared_spdif_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  578. {
  579. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  580. uinfo->count = 1;
  581. uinfo->value.integer.min = 0;
  582. uinfo->value.integer.max = 1;
  583. return 0;
  584. }
  585. static int snd_emu10k1_shared_spdif_get(struct snd_kcontrol *kcontrol,
  586. struct snd_ctl_elem_value *ucontrol)
  587. {
  588. struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
  589. if (emu->audigy)
  590. ucontrol->value.integer.value[0] = inl(emu->port + A_IOCFG) & A_IOCFG_GPOUT0 ? 1 : 0;
  591. else
  592. ucontrol->value.integer.value[0] = inl(emu->port + HCFG) & HCFG_GPOUT0 ? 1 : 0;
  593. return 0;
  594. }
  595. static int snd_emu10k1_shared_spdif_put(struct snd_kcontrol *kcontrol,
  596. struct snd_ctl_elem_value *ucontrol)
  597. {
  598. unsigned long flags;
  599. struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
  600. unsigned int reg, val;
  601. int change = 0;
  602. spin_lock_irqsave(&emu->reg_lock, flags);
  603. if (emu->audigy) {
  604. reg = inl(emu->port + A_IOCFG);
  605. val = ucontrol->value.integer.value[0] ? A_IOCFG_GPOUT0 : 0;
  606. change = (reg & A_IOCFG_GPOUT0) != val;
  607. if (change) {
  608. reg &= ~A_IOCFG_GPOUT0;
  609. reg |= val;
  610. outl(reg | val, emu->port + A_IOCFG);
  611. }
  612. }
  613. reg = inl(emu->port + HCFG);
  614. val = ucontrol->value.integer.value[0] ? HCFG_GPOUT0 : 0;
  615. change |= (reg & HCFG_GPOUT0) != val;
  616. if (change) {
  617. reg &= ~HCFG_GPOUT0;
  618. reg |= val;
  619. outl(reg | val, emu->port + HCFG);
  620. }
  621. spin_unlock_irqrestore(&emu->reg_lock, flags);
  622. return change;
  623. }
  624. static struct snd_kcontrol_new snd_emu10k1_shared_spdif __devinitdata =
  625. {
  626. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  627. .name = "SB Live Analog/Digital Output Jack",
  628. .info = snd_emu10k1_shared_spdif_info,
  629. .get = snd_emu10k1_shared_spdif_get,
  630. .put = snd_emu10k1_shared_spdif_put
  631. };
  632. static struct snd_kcontrol_new snd_audigy_shared_spdif __devinitdata =
  633. {
  634. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  635. .name = "Audigy Analog/Digital Output Jack",
  636. .info = snd_emu10k1_shared_spdif_info,
  637. .get = snd_emu10k1_shared_spdif_get,
  638. .put = snd_emu10k1_shared_spdif_put
  639. };
  640. /*
  641. */
  642. static void snd_emu10k1_mixer_free_ac97(struct snd_ac97 *ac97)
  643. {
  644. struct snd_emu10k1 *emu = ac97->private_data;
  645. emu->ac97 = NULL;
  646. }
  647. /*
  648. */
  649. static int remove_ctl(struct snd_card *card, const char *name)
  650. {
  651. struct snd_ctl_elem_id id;
  652. memset(&id, 0, sizeof(id));
  653. strcpy(id.name, name);
  654. id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
  655. return snd_ctl_remove_id(card, &id);
  656. }
  657. static struct snd_kcontrol *ctl_find(struct snd_card *card, const char *name)
  658. {
  659. struct snd_ctl_elem_id sid;
  660. memset(&sid, 0, sizeof(sid));
  661. strcpy(sid.name, name);
  662. sid.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
  663. return snd_ctl_find_id(card, &sid);
  664. }
  665. static int rename_ctl(struct snd_card *card, const char *src, const char *dst)
  666. {
  667. struct snd_kcontrol *kctl = ctl_find(card, src);
  668. if (kctl) {
  669. strcpy(kctl->id.name, dst);
  670. return 0;
  671. }
  672. return -ENOENT;
  673. }
  674. int __devinit snd_emu10k1_mixer(struct snd_emu10k1 *emu,
  675. int pcm_device, int multi_device)
  676. {
  677. int err, pcm;
  678. struct snd_kcontrol *kctl;
  679. struct snd_card *card = emu->card;
  680. char **c;
  681. static char *emu10k1_remove_ctls[] = {
  682. /* no AC97 mono, surround, center/lfe */
  683. "Master Mono Playback Switch",
  684. "Master Mono Playback Volume",
  685. "PCM Out Path & Mute",
  686. "Mono Output Select",
  687. "Front Playback Switch",
  688. "Front Playback Volume",
  689. "Surround Playback Switch",
  690. "Surround Playback Volume",
  691. "Center Playback Switch",
  692. "Center Playback Volume",
  693. "LFE Playback Switch",
  694. "LFE Playback Volume",
  695. NULL
  696. };
  697. static char *emu10k1_rename_ctls[] = {
  698. "Surround Digital Playback Volume", "Surround Playback Volume",
  699. "Center Digital Playback Volume", "Center Playback Volume",
  700. "LFE Digital Playback Volume", "LFE Playback Volume",
  701. NULL
  702. };
  703. static char *audigy_remove_ctls[] = {
  704. /* Master/PCM controls on ac97 of Audigy has no effect */
  705. "PCM Playback Switch",
  706. "PCM Playback Volume",
  707. "Master Mono Playback Switch",
  708. "Master Mono Playback Volume",
  709. "Master Playback Switch",
  710. "Master Playback Volume",
  711. "PCM Out Path & Mute",
  712. "Mono Output Select",
  713. /* remove unused AC97 capture controls */
  714. "Capture Source",
  715. "Capture Switch",
  716. "Capture Volume",
  717. "Mic Select",
  718. "Video Playback Switch",
  719. "Video Playback Volume",
  720. "Mic Playback Switch",
  721. "Mic Playback Volume",
  722. NULL
  723. };
  724. static char *audigy_rename_ctls[] = {
  725. /* use conventional names */
  726. "Wave Playback Volume", "PCM Playback Volume",
  727. /* "Wave Capture Volume", "PCM Capture Volume", */
  728. "Wave Master Playback Volume", "Master Playback Volume",
  729. "AMic Playback Volume", "Mic Playback Volume",
  730. NULL
  731. };
  732. if (emu->card_capabilities->ac97_chip) {
  733. struct snd_ac97_bus *pbus;
  734. struct snd_ac97_template ac97;
  735. static struct snd_ac97_bus_ops ops = {
  736. .write = snd_emu10k1_ac97_write,
  737. .read = snd_emu10k1_ac97_read,
  738. };
  739. if ((err = snd_ac97_bus(emu->card, 0, &ops, NULL, &pbus)) < 0)
  740. return err;
  741. pbus->no_vra = 1; /* we don't need VRA */
  742. memset(&ac97, 0, sizeof(ac97));
  743. ac97.private_data = emu;
  744. ac97.private_free = snd_emu10k1_mixer_free_ac97;
  745. ac97.scaps = AC97_SCAP_NO_SPDIF;
  746. if ((err = snd_ac97_mixer(pbus, &ac97, &emu->ac97)) < 0) {
  747. if (emu->card_capabilities->ac97_chip == 1)
  748. return err;
  749. snd_printd(KERN_INFO "emu10k1: AC97 is optional on this board\n");
  750. snd_printd(KERN_INFO" Proceeding without ac97 mixers...\n");
  751. snd_device_free(emu->card, pbus);
  752. goto no_ac97; /* FIXME: get rid of ugly gotos.. */
  753. }
  754. if (emu->audigy) {
  755. /* set master volume to 0 dB */
  756. snd_ac97_write_cache(emu->ac97, AC97_MASTER, 0x0000);
  757. /* set capture source to mic */
  758. snd_ac97_write_cache(emu->ac97, AC97_REC_SEL, 0x0000);
  759. c = audigy_remove_ctls;
  760. } else {
  761. /*
  762. * Credits for cards based on STAC9758:
  763. * James Courtier-Dutton <James@superbug.demon.co.uk>
  764. * Voluspa <voluspa@comhem.se>
  765. */
  766. if (emu->ac97->id == AC97_ID_STAC9758) {
  767. emu->rear_ac97 = 1;
  768. snd_emu10k1_ptr_write(emu, AC97SLOT, 0, AC97SLOT_CNTR|AC97SLOT_LFE|AC97SLOT_REAR_LEFT|AC97SLOT_REAR_RIGHT);
  769. }
  770. /* remove unused AC97 controls */
  771. snd_ac97_write_cache(emu->ac97, AC97_SURROUND_MASTER, 0x0202);
  772. snd_ac97_write_cache(emu->ac97, AC97_CENTER_LFE_MASTER, 0x0202);
  773. c = emu10k1_remove_ctls;
  774. }
  775. for (; *c; c++)
  776. remove_ctl(card, *c);
  777. } else {
  778. no_ac97:
  779. if (emu->card_capabilities->ecard)
  780. strcpy(emu->card->mixername, "EMU APS");
  781. else if (emu->audigy)
  782. strcpy(emu->card->mixername, "SB Audigy");
  783. else
  784. strcpy(emu->card->mixername, "Emu10k1");
  785. }
  786. if (emu->audigy)
  787. c = audigy_rename_ctls;
  788. else
  789. c = emu10k1_rename_ctls;
  790. for (; *c; c += 2)
  791. rename_ctl(card, c[0], c[1]);
  792. if (emu->card_capabilities->subsystem == 0x20071102) { /* Audigy 4 Pro */
  793. rename_ctl(card, "Line2 Capture Volume", "Line1/Mic Capture Volume");
  794. rename_ctl(card, "Analog Mix Capture Volume", "Line2 Capture Volume");
  795. rename_ctl(card, "Aux2 Capture Volume", "Line3 Capture Volume");
  796. rename_ctl(card, "Mic Capture Volume", "Unknown1 Capture Volume");
  797. remove_ctl(card, "Headphone Playback Switch");
  798. remove_ctl(card, "Headphone Playback Volume");
  799. remove_ctl(card, "3D Control - Center");
  800. remove_ctl(card, "3D Control - Depth");
  801. remove_ctl(card, "3D Control - Switch");
  802. }
  803. if ((kctl = emu->ctl_send_routing = snd_ctl_new1(&snd_emu10k1_send_routing_control, emu)) == NULL)
  804. return -ENOMEM;
  805. kctl->id.device = pcm_device;
  806. if ((err = snd_ctl_add(card, kctl)))
  807. return err;
  808. if ((kctl = emu->ctl_send_volume = snd_ctl_new1(&snd_emu10k1_send_volume_control, emu)) == NULL)
  809. return -ENOMEM;
  810. kctl->id.device = pcm_device;
  811. if ((err = snd_ctl_add(card, kctl)))
  812. return err;
  813. if ((kctl = emu->ctl_attn = snd_ctl_new1(&snd_emu10k1_attn_control, emu)) == NULL)
  814. return -ENOMEM;
  815. kctl->id.device = pcm_device;
  816. if ((err = snd_ctl_add(card, kctl)))
  817. return err;
  818. if ((kctl = emu->ctl_efx_send_routing = snd_ctl_new1(&snd_emu10k1_efx_send_routing_control, emu)) == NULL)
  819. return -ENOMEM;
  820. kctl->id.device = multi_device;
  821. if ((err = snd_ctl_add(card, kctl)))
  822. return err;
  823. if ((kctl = emu->ctl_efx_send_volume = snd_ctl_new1(&snd_emu10k1_efx_send_volume_control, emu)) == NULL)
  824. return -ENOMEM;
  825. kctl->id.device = multi_device;
  826. if ((err = snd_ctl_add(card, kctl)))
  827. return err;
  828. if ((kctl = emu->ctl_efx_attn = snd_ctl_new1(&snd_emu10k1_efx_attn_control, emu)) == NULL)
  829. return -ENOMEM;
  830. kctl->id.device = multi_device;
  831. if ((err = snd_ctl_add(card, kctl)))
  832. return err;
  833. /* initialize the routing and volume table for each pcm playback stream */
  834. for (pcm = 0; pcm < 32; pcm++) {
  835. struct snd_emu10k1_pcm_mixer *mix;
  836. int v;
  837. mix = &emu->pcm_mixer[pcm];
  838. mix->epcm = NULL;
  839. for (v = 0; v < 4; v++)
  840. mix->send_routing[0][v] =
  841. mix->send_routing[1][v] =
  842. mix->send_routing[2][v] = v;
  843. memset(&mix->send_volume, 0, sizeof(mix->send_volume));
  844. mix->send_volume[0][0] = mix->send_volume[0][1] =
  845. mix->send_volume[1][0] = mix->send_volume[2][1] = 255;
  846. mix->attn[0] = mix->attn[1] = mix->attn[2] = 0xffff;
  847. }
  848. /* initialize the routing and volume table for the multichannel playback stream */
  849. for (pcm = 0; pcm < NUM_EFX_PLAYBACK; pcm++) {
  850. struct snd_emu10k1_pcm_mixer *mix;
  851. int v;
  852. mix = &emu->efx_pcm_mixer[pcm];
  853. mix->epcm = NULL;
  854. mix->send_routing[0][0] = pcm;
  855. mix->send_routing[0][1] = (pcm == 0) ? 1 : 0;
  856. for (v = 0; v < 2; v++)
  857. mix->send_routing[0][2+v] = 13+v;
  858. if (emu->audigy)
  859. for (v = 0; v < 4; v++)
  860. mix->send_routing[0][4+v] = 60+v;
  861. memset(&mix->send_volume, 0, sizeof(mix->send_volume));
  862. mix->send_volume[0][0] = 255;
  863. mix->attn[0] = 0xffff;
  864. }
  865. if (! emu->card_capabilities->ecard) { /* FIXME: APS has these controls? */
  866. /* sb live! and audigy */
  867. if ((kctl = snd_ctl_new1(&snd_emu10k1_spdif_mask_control, emu)) == NULL)
  868. return -ENOMEM;
  869. if (!emu->audigy)
  870. kctl->id.device = emu->pcm_efx->device;
  871. if ((err = snd_ctl_add(card, kctl)))
  872. return err;
  873. if ((kctl = snd_ctl_new1(&snd_emu10k1_spdif_control, emu)) == NULL)
  874. return -ENOMEM;
  875. if (!emu->audigy)
  876. kctl->id.device = emu->pcm_efx->device;
  877. if ((err = snd_ctl_add(card, kctl)))
  878. return err;
  879. }
  880. if ( emu->card_capabilities->emu1212m) {
  881. ; /* Disable the snd_audigy_spdif_shared_spdif */
  882. } else if (emu->audigy) {
  883. if ((kctl = snd_ctl_new1(&snd_audigy_shared_spdif, emu)) == NULL)
  884. return -ENOMEM;
  885. if ((err = snd_ctl_add(card, kctl)))
  886. return err;
  887. #if 0
  888. if ((kctl = snd_ctl_new1(&snd_audigy_spdif_output_rate, emu)) == NULL)
  889. return -ENOMEM;
  890. if ((err = snd_ctl_add(card, kctl)))
  891. return err;
  892. #endif
  893. } else if (! emu->card_capabilities->ecard) {
  894. /* sb live! */
  895. if ((kctl = snd_ctl_new1(&snd_emu10k1_shared_spdif, emu)) == NULL)
  896. return -ENOMEM;
  897. if ((err = snd_ctl_add(card, kctl)))
  898. return err;
  899. }
  900. if (emu->card_capabilities->ca0151_chip) { /* P16V */
  901. if ((err = snd_p16v_mixer(emu)))
  902. return err;
  903. }
  904. return 0;
  905. }