gus_mixer.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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;
  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. swap(val1, val2);
  111. addr <<= 3;
  112. outb(addr | 0, GUSP(gus, MIXCNTRLPORT));
  113. outb(1, GUSP(gus, MIXDATAPORT));
  114. outb(addr | 2, GUSP(gus, MIXCNTRLPORT));
  115. outb((unsigned char) val1, GUSP(gus, MIXDATAPORT));
  116. outb(addr | 1, GUSP(gus, MIXCNTRLPORT));
  117. outb(2, GUSP(gus, MIXDATAPORT));
  118. outb(addr | 3, GUSP(gus, MIXCNTRLPORT));
  119. outb((unsigned char) val2, GUSP(gus, MIXDATAPORT));
  120. spin_unlock_irqrestore(&gus->reg_lock, flags);
  121. return change;
  122. }
  123. static struct snd_kcontrol_new snd_gf1_controls[] = {
  124. GF1_SINGLE("Master Playback Switch", 0, 1, 1),
  125. GF1_SINGLE("Line Switch", 0, 0, 1),
  126. GF1_SINGLE("Mic Switch", 0, 2, 0)
  127. };
  128. static struct snd_kcontrol_new snd_ics_controls[] = {
  129. GF1_SINGLE("Master Playback Switch", 0, 1, 1),
  130. ICS_DOUBLE("Master Playback Volume", 0, SNDRV_ICS_MASTER_DEV),
  131. ICS_DOUBLE("Synth Playback Volume", 0, SNDRV_ICS_GF1_DEV),
  132. GF1_SINGLE("Line Switch", 0, 0, 1),
  133. ICS_DOUBLE("Line Playback Volume", 0, SNDRV_ICS_LINE_DEV),
  134. GF1_SINGLE("Mic Switch", 0, 2, 0),
  135. ICS_DOUBLE("Mic Playback Volume", 0, SNDRV_ICS_MIC_DEV),
  136. ICS_DOUBLE("CD Playback Volume", 0, SNDRV_ICS_CD_DEV)
  137. };
  138. int snd_gf1_new_mixer(struct snd_gus_card * gus)
  139. {
  140. struct snd_card *card;
  141. unsigned int idx, max;
  142. int err;
  143. if (snd_BUG_ON(!gus))
  144. return -EINVAL;
  145. card = gus->card;
  146. if (snd_BUG_ON(!card))
  147. return -EINVAL;
  148. if (gus->ics_flag)
  149. snd_component_add(card, "ICS2101");
  150. if (card->mixername[0] == '\0') {
  151. strcpy(card->mixername, gus->ics_flag ? "GF1,ICS2101" : "GF1");
  152. } else {
  153. if (gus->ics_flag)
  154. strcat(card->mixername, ",ICS2101");
  155. strcat(card->mixername, ",GF1");
  156. }
  157. if (!gus->ics_flag) {
  158. max = gus->ess_flag ? 1 : ARRAY_SIZE(snd_gf1_controls);
  159. for (idx = 0; idx < max; idx++) {
  160. if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_gf1_controls[idx], gus))) < 0)
  161. return err;
  162. }
  163. } else {
  164. for (idx = 0; idx < ARRAY_SIZE(snd_ics_controls); idx++) {
  165. if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_ics_controls[idx], gus))) < 0)
  166. return err;
  167. }
  168. }
  169. return 0;
  170. }