2 * PC-Speaker driver for Linux
4 * Mixer implementation.
5 * Copyright (C) 2001-2008 Stas Sergeev
8 #include <sound/core.h>
9 #include <sound/control.h>
13 static int pcsp_enable_info(struct snd_kcontrol *kcontrol,
14 struct snd_ctl_elem_info *uinfo)
16 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
18 uinfo->value.integer.min = 0;
19 uinfo->value.integer.max = 1;
23 static int pcsp_enable_get(struct snd_kcontrol *kcontrol,
24 struct snd_ctl_elem_value *ucontrol)
26 struct snd_pcsp *chip = snd_kcontrol_chip(kcontrol);
27 ucontrol->value.integer.value[0] = chip->enable;
31 static int pcsp_enable_put(struct snd_kcontrol *kcontrol,
32 struct snd_ctl_elem_value *ucontrol)
34 struct snd_pcsp *chip = snd_kcontrol_chip(kcontrol);
36 int enab = ucontrol->value.integer.value[0];
37 if (enab != chip->enable) {
44 static int pcsp_treble_info(struct snd_kcontrol *kcontrol,
45 struct snd_ctl_elem_info *uinfo)
47 struct snd_pcsp *chip = snd_kcontrol_chip(kcontrol);
48 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
50 uinfo->value.enumerated.items = chip->max_treble + 1;
51 if (uinfo->value.enumerated.item > chip->max_treble)
52 uinfo->value.enumerated.item = chip->max_treble;
53 sprintf(uinfo->value.enumerated.name, "%d",
54 PCSP_CALC_RATE(uinfo->value.enumerated.item));
58 static int pcsp_treble_get(struct snd_kcontrol *kcontrol,
59 struct snd_ctl_elem_value *ucontrol)
61 struct snd_pcsp *chip = snd_kcontrol_chip(kcontrol);
62 ucontrol->value.enumerated.item[0] = chip->treble;
66 static int pcsp_treble_put(struct snd_kcontrol *kcontrol,
67 struct snd_ctl_elem_value *ucontrol)
69 struct snd_pcsp *chip = snd_kcontrol_chip(kcontrol);
71 int treble = ucontrol->value.enumerated.item[0];
72 if (treble != chip->treble) {
73 chip->treble = treble;
75 printk(KERN_INFO "PCSP: rate set to %i\n", PCSP_RATE());
82 static int pcsp_pcspkr_info(struct snd_kcontrol *kcontrol,
83 struct snd_ctl_elem_info *uinfo)
85 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
87 uinfo->value.integer.min = 0;
88 uinfo->value.integer.max = 1;
92 static int pcsp_pcspkr_get(struct snd_kcontrol *kcontrol,
93 struct snd_ctl_elem_value *ucontrol)
95 struct snd_pcsp *chip = snd_kcontrol_chip(kcontrol);
96 ucontrol->value.integer.value[0] = chip->pcspkr;
100 static int pcsp_pcspkr_put(struct snd_kcontrol *kcontrol,
101 struct snd_ctl_elem_value *ucontrol)
103 struct snd_pcsp *chip = snd_kcontrol_chip(kcontrol);
105 int spkr = ucontrol->value.integer.value[0];
106 if (spkr != chip->pcspkr) {
113 #define PCSP_MIXER_CONTROL(ctl_type, ctl_name) \
115 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
117 .info = pcsp_##ctl_type##_info, \
118 .get = pcsp_##ctl_type##_get, \
119 .put = pcsp_##ctl_type##_put, \
122 static struct snd_kcontrol_new __devinitdata snd_pcsp_controls[] = {
123 PCSP_MIXER_CONTROL(enable, "Master Playback Switch"),
124 PCSP_MIXER_CONTROL(treble, "BaseFRQ Playback Volume"),
125 PCSP_MIXER_CONTROL(pcspkr, "PC Speaker Playback Switch"),
128 int __devinit snd_pcsp_new_mixer(struct snd_pcsp *chip)
130 struct snd_card *card = chip->card;
133 for (i = 0; i < ARRAY_SIZE(snd_pcsp_controls); i++) {
134 err = snd_ctl_add(card,
135 snd_ctl_new1(snd_pcsp_controls + i,
141 strcpy(card->mixername, "PC-Speaker");