emumixer.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998
  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. "Surround Playback Switch",
  688. "Surround Playback Volume",
  689. "Center Playback Switch",
  690. "Center Playback Volume",
  691. "LFE Playback Switch",
  692. "LFE Playback Volume",
  693. NULL
  694. };
  695. static char *emu10k1_rename_ctls[] = {
  696. "Surround Digital Playback Volume", "Surround Playback Volume",
  697. "Center Digital Playback Volume", "Center Playback Volume",
  698. "LFE Digital Playback Volume", "LFE Playback Volume",
  699. NULL
  700. };
  701. static char *audigy_remove_ctls[] = {
  702. /* Master/PCM controls on ac97 of Audigy has no effect */
  703. "PCM Playback Switch",
  704. "PCM Playback Volume",
  705. "Master Mono Playback Switch",
  706. "Master Mono Playback Volume",
  707. "Master Playback Switch",
  708. "Master Playback Volume",
  709. "PCM Out Path & Mute",
  710. "Mono Output Select",
  711. /* remove unused AC97 capture controls */
  712. "Capture Source",
  713. "Capture Switch",
  714. "Capture Volume",
  715. "Mic Select",
  716. "Video Playback Switch",
  717. "Video Playback Volume",
  718. "Mic Playback Switch",
  719. "Mic Playback Volume",
  720. NULL
  721. };
  722. static char *audigy_rename_ctls[] = {
  723. /* use conventional names */
  724. "Wave Playback Volume", "PCM Playback Volume",
  725. /* "Wave Capture Volume", "PCM Capture Volume", */
  726. "Wave Master Playback Volume", "Master Playback Volume",
  727. "AMic Playback Volume", "Mic Playback Volume",
  728. NULL
  729. };
  730. if (emu->card_capabilities->ac97_chip) {
  731. struct snd_ac97_bus *pbus;
  732. struct snd_ac97_template ac97;
  733. static struct snd_ac97_bus_ops ops = {
  734. .write = snd_emu10k1_ac97_write,
  735. .read = snd_emu10k1_ac97_read,
  736. };
  737. if ((err = snd_ac97_bus(emu->card, 0, &ops, NULL, &pbus)) < 0)
  738. return err;
  739. pbus->no_vra = 1; /* we don't need VRA */
  740. memset(&ac97, 0, sizeof(ac97));
  741. ac97.private_data = emu;
  742. ac97.private_free = snd_emu10k1_mixer_free_ac97;
  743. ac97.scaps = AC97_SCAP_NO_SPDIF;
  744. if ((err = snd_ac97_mixer(pbus, &ac97, &emu->ac97)) < 0) {
  745. if (emu->card_capabilities->ac97_chip == 1)
  746. return err;
  747. snd_printd(KERN_INFO "emu10k1: AC97 is optional on this board\n");
  748. snd_printd(KERN_INFO" Proceeding without ac97 mixers...\n");
  749. snd_device_free(emu->card, pbus);
  750. goto no_ac97; /* FIXME: get rid of ugly gotos.. */
  751. }
  752. if (emu->audigy) {
  753. /* set master volume to 0 dB */
  754. snd_ac97_write_cache(emu->ac97, AC97_MASTER, 0x0000);
  755. /* set capture source to mic */
  756. snd_ac97_write_cache(emu->ac97, AC97_REC_SEL, 0x0000);
  757. c = audigy_remove_ctls;
  758. } else {
  759. /*
  760. * Credits for cards based on STAC9758:
  761. * James Courtier-Dutton <James@superbug.demon.co.uk>
  762. * Voluspa <voluspa@comhem.se>
  763. */
  764. if (emu->ac97->id == AC97_ID_STAC9758) {
  765. emu->rear_ac97 = 1;
  766. snd_emu10k1_ptr_write(emu, AC97SLOT, 0, AC97SLOT_CNTR|AC97SLOT_LFE|AC97SLOT_REAR_LEFT|AC97SLOT_REAR_RIGHT);
  767. }
  768. /* remove unused AC97 controls */
  769. snd_ac97_write_cache(emu->ac97, AC97_SURROUND_MASTER, 0x0202);
  770. snd_ac97_write_cache(emu->ac97, AC97_CENTER_LFE_MASTER, 0x0202);
  771. c = emu10k1_remove_ctls;
  772. }
  773. for (; *c; c++)
  774. remove_ctl(card, *c);
  775. } else {
  776. no_ac97:
  777. if (emu->card_capabilities->ecard)
  778. strcpy(emu->card->mixername, "EMU APS");
  779. else if (emu->audigy)
  780. strcpy(emu->card->mixername, "SB Audigy");
  781. else
  782. strcpy(emu->card->mixername, "Emu10k1");
  783. }
  784. if (emu->audigy)
  785. c = audigy_rename_ctls;
  786. else
  787. c = emu10k1_rename_ctls;
  788. for (; *c; c += 2)
  789. rename_ctl(card, c[0], c[1]);
  790. if (emu->card_capabilities->subsystem == 0x20071102) { /* Audigy 4 Pro */
  791. rename_ctl(card, "Line2 Capture Volume", "Line1/Mic Capture Volume");
  792. rename_ctl(card, "Analog Mix Capture Volume", "Line2 Capture Volume");
  793. rename_ctl(card, "Aux2 Capture Volume", "Line3 Capture Volume");
  794. rename_ctl(card, "Mic Capture Volume", "Unknown1 Capture Volume");
  795. remove_ctl(card, "Headphone Playback Switch");
  796. remove_ctl(card, "Headphone Playback Volume");
  797. remove_ctl(card, "3D Control - Center");
  798. remove_ctl(card, "3D Control - Depth");
  799. remove_ctl(card, "3D Control - Switch");
  800. }
  801. if ((kctl = emu->ctl_send_routing = snd_ctl_new1(&snd_emu10k1_send_routing_control, emu)) == NULL)
  802. return -ENOMEM;
  803. kctl->id.device = pcm_device;
  804. if ((err = snd_ctl_add(card, kctl)))
  805. return err;
  806. if ((kctl = emu->ctl_send_volume = snd_ctl_new1(&snd_emu10k1_send_volume_control, emu)) == NULL)
  807. return -ENOMEM;
  808. kctl->id.device = pcm_device;
  809. if ((err = snd_ctl_add(card, kctl)))
  810. return err;
  811. if ((kctl = emu->ctl_attn = snd_ctl_new1(&snd_emu10k1_attn_control, emu)) == NULL)
  812. return -ENOMEM;
  813. kctl->id.device = pcm_device;
  814. if ((err = snd_ctl_add(card, kctl)))
  815. return err;
  816. if ((kctl = emu->ctl_efx_send_routing = snd_ctl_new1(&snd_emu10k1_efx_send_routing_control, emu)) == NULL)
  817. return -ENOMEM;
  818. kctl->id.device = multi_device;
  819. if ((err = snd_ctl_add(card, kctl)))
  820. return err;
  821. if ((kctl = emu->ctl_efx_send_volume = snd_ctl_new1(&snd_emu10k1_efx_send_volume_control, emu)) == NULL)
  822. return -ENOMEM;
  823. kctl->id.device = multi_device;
  824. if ((err = snd_ctl_add(card, kctl)))
  825. return err;
  826. if ((kctl = emu->ctl_efx_attn = snd_ctl_new1(&snd_emu10k1_efx_attn_control, emu)) == NULL)
  827. return -ENOMEM;
  828. kctl->id.device = multi_device;
  829. if ((err = snd_ctl_add(card, kctl)))
  830. return err;
  831. /* initialize the routing and volume table for each pcm playback stream */
  832. for (pcm = 0; pcm < 32; pcm++) {
  833. struct snd_emu10k1_pcm_mixer *mix;
  834. int v;
  835. mix = &emu->pcm_mixer[pcm];
  836. mix->epcm = NULL;
  837. for (v = 0; v < 4; v++)
  838. mix->send_routing[0][v] =
  839. mix->send_routing[1][v] =
  840. mix->send_routing[2][v] = v;
  841. memset(&mix->send_volume, 0, sizeof(mix->send_volume));
  842. mix->send_volume[0][0] = mix->send_volume[0][1] =
  843. mix->send_volume[1][0] = mix->send_volume[2][1] = 255;
  844. mix->attn[0] = mix->attn[1] = mix->attn[2] = 0xffff;
  845. }
  846. /* initialize the routing and volume table for the multichannel playback stream */
  847. for (pcm = 0; pcm < NUM_EFX_PLAYBACK; pcm++) {
  848. struct snd_emu10k1_pcm_mixer *mix;
  849. int v;
  850. mix = &emu->efx_pcm_mixer[pcm];
  851. mix->epcm = NULL;
  852. mix->send_routing[0][0] = pcm;
  853. mix->send_routing[0][1] = (pcm == 0) ? 1 : 0;
  854. for (v = 0; v < 2; v++)
  855. mix->send_routing[0][2+v] = 13+v;
  856. if (emu->audigy)
  857. for (v = 0; v < 4; v++)
  858. mix->send_routing[0][4+v] = 60+v;
  859. memset(&mix->send_volume, 0, sizeof(mix->send_volume));
  860. mix->send_volume[0][0] = 255;
  861. mix->attn[0] = 0xffff;
  862. }
  863. if (! emu->card_capabilities->ecard) { /* FIXME: APS has these controls? */
  864. /* sb live! and audigy */
  865. if ((kctl = snd_ctl_new1(&snd_emu10k1_spdif_mask_control, emu)) == NULL)
  866. return -ENOMEM;
  867. if (!emu->audigy)
  868. kctl->id.device = emu->pcm_efx->device;
  869. if ((err = snd_ctl_add(card, kctl)))
  870. return err;
  871. if ((kctl = snd_ctl_new1(&snd_emu10k1_spdif_control, emu)) == NULL)
  872. return -ENOMEM;
  873. if (!emu->audigy)
  874. kctl->id.device = emu->pcm_efx->device;
  875. if ((err = snd_ctl_add(card, kctl)))
  876. return err;
  877. }
  878. if ( emu->card_capabilities->emu1212m) {
  879. ; /* Disable the snd_audigy_spdif_shared_spdif */
  880. } else if (emu->audigy) {
  881. if ((kctl = snd_ctl_new1(&snd_audigy_shared_spdif, emu)) == NULL)
  882. return -ENOMEM;
  883. if ((err = snd_ctl_add(card, kctl)))
  884. return err;
  885. #if 0
  886. if ((kctl = snd_ctl_new1(&snd_audigy_spdif_output_rate, emu)) == NULL)
  887. return -ENOMEM;
  888. if ((err = snd_ctl_add(card, kctl)))
  889. return err;
  890. #endif
  891. } else if (! emu->card_capabilities->ecard) {
  892. /* sb live! */
  893. if ((kctl = snd_ctl_new1(&snd_emu10k1_shared_spdif, emu)) == NULL)
  894. return -ENOMEM;
  895. if ((err = snd_ctl_add(card, kctl)))
  896. return err;
  897. }
  898. if (emu->card_capabilities->ca0151_chip) { /* P16V */
  899. if ((err = snd_p16v_mixer(emu)))
  900. return err;
  901. }
  902. return 0;
  903. }