gus_mixer.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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 <sound/driver.h>
  22. #include <linux/time.h>
  23. #include <linux/wait.h>
  24. #include <sound/core.h>
  25. #include <sound/control.h>
  26. #include <sound/gus.h>
  27. /*
  28. *
  29. */
  30. #define GF1_SINGLE(xname, xindex, shift, invert) \
  31. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
  32. .info = snd_gf1_info_single, \
  33. .get = snd_gf1_get_single, .put = snd_gf1_put_single, \
  34. .private_value = shift | (invert << 8) }
  35. #define snd_gf1_info_single snd_ctl_boolean_mono_info
  36. static int snd_gf1_get_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  37. {
  38. struct snd_gus_card *gus = snd_kcontrol_chip(kcontrol);
  39. int shift = kcontrol->private_value & 0xff;
  40. int invert = (kcontrol->private_value >> 8) & 1;
  41. ucontrol->value.integer.value[0] = (gus->mix_cntrl_reg >> shift) & 1;
  42. if (invert)
  43. ucontrol->value.integer.value[0] ^= 1;
  44. return 0;
  45. }
  46. static int snd_gf1_put_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  47. {
  48. struct snd_gus_card *gus = snd_kcontrol_chip(kcontrol);
  49. unsigned long flags;
  50. int shift = kcontrol->private_value & 0xff;
  51. int invert = (kcontrol->private_value >> 8) & 1;
  52. int change;
  53. unsigned char oval, nval;
  54. nval = ucontrol->value.integer.value[0] & 1;
  55. if (invert)
  56. nval ^= 1;
  57. nval <<= shift;
  58. spin_lock_irqsave(&gus->reg_lock, flags);
  59. oval = gus->mix_cntrl_reg;
  60. nval = (oval & ~(1 << shift)) | nval;
  61. change = nval != oval;
  62. outb(gus->mix_cntrl_reg = nval, GUSP(gus, MIXCNTRLREG));
  63. outb(gus->gf1.active_voice = 0, GUSP(gus, GF1PAGE));
  64. spin_unlock_irqrestore(&gus->reg_lock, flags);
  65. return change;
  66. }
  67. #define ICS_DOUBLE(xname, xindex, addr) \
  68. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
  69. .info = snd_ics_info_double, \
  70. .get = snd_ics_get_double, .put = snd_ics_put_double, \
  71. .private_value = addr }
  72. static int snd_ics_info_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  73. {
  74. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  75. uinfo->count = 2;
  76. uinfo->value.integer.min = 0;
  77. uinfo->value.integer.max = 127;
  78. return 0;
  79. }
  80. static int snd_ics_get_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  81. {
  82. struct snd_gus_card *gus = snd_kcontrol_chip(kcontrol);
  83. unsigned long flags;
  84. int addr = kcontrol->private_value & 0xff;
  85. unsigned char left, right;
  86. spin_lock_irqsave(&gus->reg_lock, flags);
  87. left = gus->gf1.ics_regs[addr][0];
  88. right = gus->gf1.ics_regs[addr][1];
  89. spin_unlock_irqrestore(&gus->reg_lock, flags);
  90. ucontrol->value.integer.value[0] = left & 127;
  91. ucontrol->value.integer.value[1] = right & 127;
  92. return 0;
  93. }
  94. static int snd_ics_put_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  95. {
  96. struct snd_gus_card *gus = snd_kcontrol_chip(kcontrol);
  97. unsigned long flags;
  98. int addr = kcontrol->private_value & 0xff;
  99. int change;
  100. unsigned char val1, val2, oval1, oval2, tmp;
  101. val1 = ucontrol->value.integer.value[0] & 127;
  102. val2 = ucontrol->value.integer.value[1] & 127;
  103. spin_lock_irqsave(&gus->reg_lock, flags);
  104. oval1 = gus->gf1.ics_regs[addr][0];
  105. oval2 = gus->gf1.ics_regs[addr][1];
  106. change = val1 != oval1 || val2 != oval2;
  107. gus->gf1.ics_regs[addr][0] = val1;
  108. gus->gf1.ics_regs[addr][1] = val2;
  109. if (gus->ics_flag && gus->ics_flipped &&
  110. (addr == SNDRV_ICS_GF1_DEV || addr == SNDRV_ICS_MASTER_DEV)) {
  111. tmp = val1;
  112. val1 = val2;
  113. val2 = tmp;
  114. }
  115. addr <<= 3;
  116. outb(addr | 0, GUSP(gus, MIXCNTRLPORT));
  117. outb(1, GUSP(gus, MIXDATAPORT));
  118. outb(addr | 2, GUSP(gus, MIXCNTRLPORT));
  119. outb((unsigned char) val1, GUSP(gus, MIXDATAPORT));
  120. outb(addr | 1, GUSP(gus, MIXCNTRLPORT));
  121. outb(2, GUSP(gus, MIXDATAPORT));
  122. outb(addr | 3, GUSP(gus, MIXCNTRLPORT));
  123. outb((unsigned char) val2, GUSP(gus, MIXDATAPORT));
  124. spin_unlock_irqrestore(&gus->reg_lock, flags);
  125. return change;
  126. }
  127. static struct snd_kcontrol_new snd_gf1_controls[] = {
  128. GF1_SINGLE("Master Playback Switch", 0, 1, 1),
  129. GF1_SINGLE("Line Switch", 0, 0, 1),
  130. GF1_SINGLE("Mic Switch", 0, 2, 0)
  131. };
  132. static struct snd_kcontrol_new snd_ics_controls[] = {
  133. GF1_SINGLE("Master Playback Switch", 0, 1, 1),
  134. ICS_DOUBLE("Master Playback Volume", 0, SNDRV_ICS_MASTER_DEV),
  135. ICS_DOUBLE("Synth Playback Volume", 0, SNDRV_ICS_GF1_DEV),
  136. GF1_SINGLE("Line Switch", 0, 0, 1),
  137. ICS_DOUBLE("Line Playback Volume", 0, SNDRV_ICS_LINE_DEV),
  138. GF1_SINGLE("Mic Switch", 0, 2, 0),
  139. ICS_DOUBLE("Mic Playback Volume", 0, SNDRV_ICS_MIC_DEV),
  140. ICS_DOUBLE("CD Playback Volume", 0, SNDRV_ICS_CD_DEV)
  141. };
  142. int snd_gf1_new_mixer(struct snd_gus_card * gus)
  143. {
  144. struct snd_card *card;
  145. unsigned int idx, max;
  146. int err;
  147. snd_assert(gus != NULL, return -EINVAL);
  148. card = gus->card;
  149. snd_assert(card != NULL, return -EINVAL);
  150. if (gus->ics_flag)
  151. snd_component_add(card, "ICS2101");
  152. if (card->mixername[0] == '\0') {
  153. strcpy(card->mixername, gus->ics_flag ? "GF1,ICS2101" : "GF1");
  154. } else {
  155. if (gus->ics_flag)
  156. strcat(card->mixername, ",ICS2101");
  157. strcat(card->mixername, ",GF1");
  158. }
  159. if (!gus->ics_flag) {
  160. max = gus->ess_flag ? 1 : ARRAY_SIZE(snd_gf1_controls);
  161. for (idx = 0; idx < max; idx++) {
  162. if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_gf1_controls[idx], gus))) < 0)
  163. return err;
  164. }
  165. } else {
  166. for (idx = 0; idx < ARRAY_SIZE(snd_ics_controls); idx++) {
  167. if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_ics_controls[idx], gus))) < 0)
  168. return err;
  169. }
  170. }
  171. return 0;
  172. }