pcsp_mixer.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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, "%d", PCSP_RATE());
  48. return 0;
  49. }
  50. static int pcsp_treble_get(struct snd_kcontrol *kcontrol,
  51. struct snd_ctl_elem_value *ucontrol)
  52. {
  53. struct snd_pcsp *chip = snd_kcontrol_chip(kcontrol);
  54. ucontrol->value.enumerated.item[0] = chip->treble;
  55. return 0;
  56. }
  57. static int pcsp_treble_put(struct snd_kcontrol *kcontrol,
  58. struct snd_ctl_elem_value *ucontrol)
  59. {
  60. struct snd_pcsp *chip = snd_kcontrol_chip(kcontrol);
  61. int changed = 0;
  62. int treble = ucontrol->value.enumerated.item[0];
  63. if (treble != chip->treble) {
  64. chip->treble = treble;
  65. #if PCSP_DEBUG
  66. printk(KERN_INFO "PCSP: rate set to %i\n", PCSP_RATE());
  67. #endif
  68. changed = 1;
  69. }
  70. return changed;
  71. }
  72. static int pcsp_pcspkr_info(struct snd_kcontrol *kcontrol,
  73. struct snd_ctl_elem_info *uinfo)
  74. {
  75. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  76. uinfo->count = 1;
  77. uinfo->value.integer.min = 0;
  78. uinfo->value.integer.max = 1;
  79. return 0;
  80. }
  81. static int pcsp_pcspkr_get(struct snd_kcontrol *kcontrol,
  82. struct snd_ctl_elem_value *ucontrol)
  83. {
  84. struct snd_pcsp *chip = snd_kcontrol_chip(kcontrol);
  85. ucontrol->value.integer.value[0] = chip->pcspkr;
  86. return 0;
  87. }
  88. static int pcsp_pcspkr_put(struct snd_kcontrol *kcontrol,
  89. struct snd_ctl_elem_value *ucontrol)
  90. {
  91. struct snd_pcsp *chip = snd_kcontrol_chip(kcontrol);
  92. int changed = 0;
  93. int spkr = ucontrol->value.integer.value[0];
  94. if (spkr != chip->pcspkr) {
  95. chip->pcspkr = spkr;
  96. changed = 1;
  97. }
  98. return changed;
  99. }
  100. #define PCSP_MIXER_CONTROL(ctl_type, ctl_name) \
  101. { \
  102. .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  103. .name = ctl_name, \
  104. .info = pcsp_##ctl_type##_info, \
  105. .get = pcsp_##ctl_type##_get, \
  106. .put = pcsp_##ctl_type##_put, \
  107. }
  108. static struct snd_kcontrol_new __devinitdata snd_pcsp_controls[] = {
  109. PCSP_MIXER_CONTROL(enable, "Master Playback Switch"),
  110. PCSP_MIXER_CONTROL(treble, "BaseFRQ Playback Volume"),
  111. PCSP_MIXER_CONTROL(pcspkr, "PC Speaker Playback Switch"),
  112. };
  113. int __devinit snd_pcsp_new_mixer(struct snd_pcsp *chip)
  114. {
  115. struct snd_card *card = chip->card;
  116. int i, err;
  117. for (i = 0; i < ARRAY_SIZE(snd_pcsp_controls); i++) {
  118. err = snd_ctl_add(card,
  119. snd_ctl_new1(snd_pcsp_controls + i,
  120. chip));
  121. if (err < 0)
  122. return err;
  123. }
  124. strcpy(card->mixername, "PC-Speaker");
  125. return 0;
  126. }