gus_mixer.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /*
  2. * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
  3. * Routines for control of ICS 2101 chip and "mixer" in GF1 chip
  4. *
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. *
  20. */
  21. #include <linux/time.h>
  22. #include <linux/wait.h>
  23. #include <sound/core.h>
  24. #include <sound/control.h>
  25. #include <sound/gus.h>
  26. /*
  27. *
  28. */
  29. #define GF1_SINGLE(xname, xindex, shift, invert) \
  30. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
  31. .info = snd_gf1_info_single, \
  32. .get = snd_gf1_get_single, .put = snd_gf1_put_single, \
  33. .private_value = shift | (invert << 8) }
  34. #define snd_gf1_info_single snd_ctl_boolean_mono_info
  35. static int snd_gf1_get_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  36. {
  37. struct snd_gus_card *gus = snd_kcontrol_chip(kcontrol);
  38. int shift = kcontrol->private_value & 0xff;
  39. int invert = (kcontrol->private_value >> 8) & 1;
  40. ucontrol->value.integer.value[0] = (gus->mix_cntrl_reg >> shift) & 1;
  41. if (invert)
  42. ucontrol->value.integer.value[0] ^= 1;
  43. return 0;
  44. }
  45. static int snd_gf1_put_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  46. {
  47. struct snd_gus_card *gus = snd_kcontrol_chip(kcontrol);
  48. unsigned long flags;
  49. int shift = kcontrol->private_value & 0xff;
  50. int invert = (kcontrol->private_value >> 8) & 1;
  51. int change;
  52. unsigned char oval, nval;
  53. nval = ucontrol->value.integer.value[0] & 1;
  54. if (invert)
  55. nval ^= 1;
  56. nval <<= shift;
  57. spin_lock_irqsave(&gus->reg_lock, flags);
  58. oval = gus->mix_cntrl_reg;
  59. nval = (oval & ~(1 << shift)) | nval;
  60. change = nval != oval;
  61. outb(gus->mix_cntrl_reg = nval, GUSP(gus, MIXCNTRLREG));
  62. outb(gus->gf1.active_voice = 0, GUSP(gus, GF1PAGE));
  63. spin_unlock_irqrestore(&gus->reg_lock, flags);
  64. return change;
  65. }
  66. #define ICS_DOUBLE(xname, xindex, addr) \
  67. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
  68. .info = snd_ics_info_double, \
  69. .get = snd_ics_get_double, .put = snd_ics_put_double, \
  70. .private_value = addr }
  71. static int snd_ics_info_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  72. {
  73. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  74. uinfo->count = 2;
  75. uinfo->value.integer.min = 0;
  76. uinfo->value.integer.max = 127;
  77. return 0;
  78. }
  79. static int snd_ics_get_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  80. {
  81. struct snd_gus_card *gus = snd_kcontrol_chip(kcontrol);
  82. unsigned long flags;
  83. int addr = kcontrol->private_value & 0xff;
  84. unsigned char left, right;
  85. spin_lock_irqsave(&gus->reg_lock, flags);
  86. left = gus->gf1.ics_regs[addr][0];
  87. right = gus->gf1.ics_regs[addr][1];
  88. spin_unlock_irqrestore(&gus->reg_lock, flags);
  89. ucontrol->value.integer.value[0] = left & 127;
  90. ucontrol->value.integer.value[1] = right & 127;
  91. return 0;
  92. }
  93. static int snd_ics_put_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  94. {
  95. struct snd_gus_card *gus = snd_kcontrol_chip(kcontrol);
  96. unsigned long flags;
  97. int addr = kcontrol->private_value & 0xff;
  98. int change;
  99. unsigned char val1, val2, oval1, oval2, tmp;
  100. val1 = ucontrol->value.integer.value[0] & 127;
  101. val2 = ucontrol->value.integer.value[1] & 127;
  102. spin_lock_irqsave(&gus->reg_lock, flags);
  103. oval1 = gus->gf1.ics_regs[addr][0];
  104. oval2 = gus->gf1.ics_regs[addr][1];
  105. change = val1 != oval1 || val2 != oval2;
  106. gus->gf1.ics_regs[addr][0] = val1;
  107. gus->gf1.ics_regs[addr][1] = val2;
  108. if (gus->ics_flag && gus->ics_flipped &&
  109. (addr == SNDRV_ICS_GF1_DEV || addr == SNDRV_ICS_MASTER_DEV)) {
  110. tmp = val1;
  111. val1 = val2;
  112. val2 = tmp;
  113. }
  114. addr <<= 3;
  115. outb(addr | 0, GUSP(gus, MIXCNTRLPORT));
  116. outb(1, GUSP(gus, MIXDATAPORT));
  117. outb(addr | 2, GUSP(gus, MIXCNTRLPORT));
  118. outb((unsigned char) val1, GUSP(gus, MIXDATAPORT));
  119. outb(addr | 1, GUSP(gus, MIXCNTRLPORT));
  120. outb(2, GUSP(gus, MIXDATAPORT));
  121. outb(addr | 3, GUSP(gus, MIXCNTRLPORT));
  122. outb((unsigned char) val2, GUSP(gus, MIXDATAPORT));
  123. spin_unlock_irqrestore(&gus->reg_lock, flags);
  124. return change;
  125. }
  126. static struct snd_kcontrol_new snd_gf1_controls[] = {
  127. GF1_SINGLE("Master Playback Switch", 0, 1, 1),
  128. GF1_SINGLE("Line Switch", 0, 0, 1),
  129. GF1_SINGLE("Mic Switch", 0, 2, 0)
  130. };
  131. static struct snd_kcontrol_new snd_ics_controls[] = {
  132. GF1_SINGLE("Master Playback Switch", 0, 1, 1),
  133. ICS_DOUBLE("Master Playback Volume", 0, SNDRV_ICS_MASTER_DEV),
  134. ICS_DOUBLE("Synth Playback Volume", 0, SNDRV_ICS_GF1_DEV),
  135. GF1_SINGLE("Line Switch", 0, 0, 1),
  136. ICS_DOUBLE("Line Playback Volume", 0, SNDRV_ICS_LINE_DEV),
  137. GF1_SINGLE("Mic Switch", 0, 2, 0),
  138. ICS_DOUBLE("Mic Playback Volume", 0, SNDRV_ICS_MIC_DEV),
  139. ICS_DOUBLE("CD Playback Volume", 0, SNDRV_ICS_CD_DEV)
  140. };
  141. int snd_gf1_new_mixer(struct snd_gus_card * gus)
  142. {
  143. struct snd_card *card;
  144. unsigned int idx, max;
  145. int err;
  146. if (snd_BUG_ON(!gus))
  147. return -EINVAL;
  148. card = gus->card;
  149. if (snd_BUG_ON(!card))
  150. return -EINVAL;
  151. if (gus->ics_flag)
  152. snd_component_add(card, "ICS2101");
  153. if (card->mixername[0] == '\0') {
  154. strcpy(card->mixername, gus->ics_flag ? "GF1,ICS2101" : "GF1");
  155. } else {
  156. if (gus->ics_flag)
  157. strcat(card->mixername, ",ICS2101");
  158. strcat(card->mixername, ",GF1");
  159. }
  160. if (!gus->ics_flag) {
  161. max = gus->ess_flag ? 1 : ARRAY_SIZE(snd_gf1_controls);
  162. for (idx = 0; idx < max; idx++) {
  163. if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_gf1_controls[idx], gus))) < 0)
  164. return err;
  165. }
  166. } else {
  167. for (idx = 0; idx < ARRAY_SIZE(snd_ics_controls); idx++) {
  168. if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_ics_controls[idx], gus))) < 0)
  169. return err;
  170. }
  171. }
  172. return 0;
  173. }