pcsp_mixer.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. * PC-Speaker driver for Linux
  3. *
  4. * Mixer implementation.
  5. * Copyright (C) 2001-2008 Stas Sergeev
  6. */
  7. #include <sound/core.h>
  8. #include <sound/control.h>
  9. #include "pcsp.h"
  10. static int pcsp_enable_info(struct snd_kcontrol *kcontrol,
  11. struct snd_ctl_elem_info *uinfo)
  12. {
  13. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  14. uinfo->count = 1;
  15. uinfo->value.integer.min = 0;
  16. uinfo->value.integer.max = 1;
  17. return 0;
  18. }
  19. static int pcsp_enable_get(struct snd_kcontrol *kcontrol,
  20. struct snd_ctl_elem_value *ucontrol)
  21. {
  22. struct snd_pcsp *chip = snd_kcontrol_chip(kcontrol);
  23. ucontrol->value.integer.value[0] = chip->enable;
  24. return 0;
  25. }
  26. static int pcsp_enable_put(struct snd_kcontrol *kcontrol,
  27. struct snd_ctl_elem_value *ucontrol)
  28. {
  29. struct snd_pcsp *chip = snd_kcontrol_chip(kcontrol);
  30. int changed = 0;
  31. int enab = ucontrol->value.integer.value[0];
  32. if (enab != chip->enable) {
  33. chip->enable = enab;
  34. changed = 1;
  35. }
  36. return changed;
  37. }
  38. static int pcsp_treble_info(struct snd_kcontrol *kcontrol,
  39. struct snd_ctl_elem_info *uinfo)
  40. {
  41. struct snd_pcsp *chip = snd_kcontrol_chip(kcontrol);
  42. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  43. uinfo->count = 1;
  44. uinfo->value.enumerated.items = chip->max_treble + 1;
  45. if (uinfo->value.enumerated.item > chip->max_treble)
  46. uinfo->value.enumerated.item = chip->max_treble;
  47. sprintf(uinfo->value.enumerated.name, "%lu",
  48. (unsigned long)PCSP_CALC_RATE(uinfo->value.enumerated.item));
  49. return 0;
  50. }
  51. static int pcsp_treble_get(struct snd_kcontrol *kcontrol,
  52. struct snd_ctl_elem_value *ucontrol)
  53. {
  54. struct snd_pcsp *chip = snd_kcontrol_chip(kcontrol);
  55. ucontrol->value.enumerated.item[0] = chip->treble;
  56. return 0;
  57. }
  58. static int pcsp_treble_put(struct snd_kcontrol *kcontrol,
  59. struct snd_ctl_elem_value *ucontrol)
  60. {
  61. struct snd_pcsp *chip = snd_kcontrol_chip(kcontrol);
  62. int changed = 0;
  63. int treble = ucontrol->value.enumerated.item[0];
  64. if (treble != chip->treble) {
  65. chip->treble = treble;
  66. #if PCSP_DEBUG
  67. printk(KERN_INFO "PCSP: rate set to %li\n", PCSP_RATE());
  68. #endif
  69. changed = 1;
  70. }
  71. return changed;
  72. }
  73. static int pcsp_pcspkr_info(struct snd_kcontrol *kcontrol,
  74. struct snd_ctl_elem_info *uinfo)
  75. {
  76. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  77. uinfo->count = 1;
  78. uinfo->value.integer.min = 0;
  79. uinfo->value.integer.max = 1;
  80. return 0;
  81. }
  82. static int pcsp_pcspkr_get(struct snd_kcontrol *kcontrol,
  83. struct snd_ctl_elem_value *ucontrol)
  84. {
  85. struct snd_pcsp *chip = snd_kcontrol_chip(kcontrol);
  86. ucontrol->value.integer.value[0] = chip->pcspkr;
  87. return 0;
  88. }
  89. static int pcsp_pcspkr_put(struct snd_kcontrol *kcontrol,
  90. struct snd_ctl_elem_value *ucontrol)
  91. {
  92. struct snd_pcsp *chip = snd_kcontrol_chip(kcontrol);
  93. int changed = 0;
  94. int spkr = ucontrol->value.integer.value[0];
  95. if (spkr != chip->pcspkr) {
  96. chip->pcspkr = spkr;
  97. changed = 1;
  98. }
  99. return changed;
  100. }
  101. #define PCSP_MIXER_CONTROL(ctl_type, ctl_name) \
  102. { \
  103. .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  104. .name = ctl_name, \
  105. .info = pcsp_##ctl_type##_info, \
  106. .get = pcsp_##ctl_type##_get, \
  107. .put = pcsp_##ctl_type##_put, \
  108. }
  109. static struct snd_kcontrol_new snd_pcsp_controls_pcm[] = {
  110. PCSP_MIXER_CONTROL(enable, "Master Playback Switch"),
  111. PCSP_MIXER_CONTROL(treble, "BaseFRQ Playback Volume"),
  112. };
  113. static struct snd_kcontrol_new snd_pcsp_controls_spkr[] = {
  114. PCSP_MIXER_CONTROL(pcspkr, "Beep Playback Switch"),
  115. };
  116. static int snd_pcsp_ctls_add(struct snd_pcsp *chip,
  117. struct snd_kcontrol_new *ctls, int num)
  118. {
  119. int i, err;
  120. struct snd_card *card = chip->card;
  121. for (i = 0; i < num; i++) {
  122. err = snd_ctl_add(card, snd_ctl_new1(ctls + i, chip));
  123. if (err < 0)
  124. return err;
  125. }
  126. return 0;
  127. }
  128. int snd_pcsp_new_mixer(struct snd_pcsp *chip, int nopcm)
  129. {
  130. int err;
  131. struct snd_card *card = chip->card;
  132. if (!nopcm) {
  133. err = snd_pcsp_ctls_add(chip, snd_pcsp_controls_pcm,
  134. ARRAY_SIZE(snd_pcsp_controls_pcm));
  135. if (err < 0)
  136. return err;
  137. }
  138. err = snd_pcsp_ctls_add(chip, snd_pcsp_controls_spkr,
  139. ARRAY_SIZE(snd_pcsp_controls_spkr));
  140. if (err < 0)
  141. return err;
  142. strcpy(card->mixername, "PC-Speaker");
  143. return 0;
  144. }