gus_mixer.c 6.2 KB

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