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", PCSP_RATE());
57 static int pcsp_treble_get(struct snd_kcontrol
*kcontrol
,
58 struct snd_ctl_elem_value
*ucontrol
)
60 struct snd_pcsp
*chip
= snd_kcontrol_chip(kcontrol
);
61 ucontrol
->value
.enumerated
.item
[0] = chip
->treble
;
65 static int pcsp_treble_put(struct snd_kcontrol
*kcontrol
,
66 struct snd_ctl_elem_value
*ucontrol
)
68 struct snd_pcsp
*chip
= snd_kcontrol_chip(kcontrol
);
70 int treble
= ucontrol
->value
.enumerated
.item
[0];
71 if (treble
!= chip
->treble
) {
72 chip
->treble
= treble
;
74 printk(KERN_INFO
"PCSP: rate set to %i\n", PCSP_RATE());
81 static int pcsp_pcspkr_info(struct snd_kcontrol
*kcontrol
,
82 struct snd_ctl_elem_info
*uinfo
)
84 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
86 uinfo
->value
.integer
.min
= 0;
87 uinfo
->value
.integer
.max
= 1;
91 static int pcsp_pcspkr_get(struct snd_kcontrol
*kcontrol
,
92 struct snd_ctl_elem_value
*ucontrol
)
94 struct snd_pcsp
*chip
= snd_kcontrol_chip(kcontrol
);
95 ucontrol
->value
.integer
.value
[0] = chip
->pcspkr
;
99 static int pcsp_pcspkr_put(struct snd_kcontrol
*kcontrol
,
100 struct snd_ctl_elem_value
*ucontrol
)
102 struct snd_pcsp
*chip
= snd_kcontrol_chip(kcontrol
);
104 int spkr
= ucontrol
->value
.integer
.value
[0];
105 if (spkr
!= chip
->pcspkr
) {
112 #define PCSP_MIXER_CONTROL(ctl_type, ctl_name) \
114 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
116 .info = pcsp_##ctl_type##_info, \
117 .get = pcsp_##ctl_type##_get, \
118 .put = pcsp_##ctl_type##_put, \
121 static struct snd_kcontrol_new __devinitdata snd_pcsp_controls
[] = {
122 PCSP_MIXER_CONTROL(enable
, "Master Playback Switch"),
123 PCSP_MIXER_CONTROL(treble
, "BaseFRQ Playback Volume"),
124 PCSP_MIXER_CONTROL(pcspkr
, "PC Speaker Playback Switch"),
127 int __devinit
snd_pcsp_new_mixer(struct snd_pcsp
*chip
)
129 struct snd_card
*card
= chip
->card
;
132 for (i
= 0; i
< ARRAY_SIZE(snd_pcsp_controls
); i
++) {
133 err
= snd_ctl_add(card
,
134 snd_ctl_new1(snd_pcsp_controls
+ i
,
140 strcpy(card
->mixername
, "PC-Speaker");