1 // SPDX-License-Identifier: GPL-2.0
3 * PC-Speaker driver for Linux
5 * Mixer implementation.
6 * Copyright (C) 2001-2008 Stas Sergeev
9 #include <sound/core.h>
10 #include <sound/control.h>
14 static int pcsp_enable_info(struct snd_kcontrol
*kcontrol
,
15 struct snd_ctl_elem_info
*uinfo
)
17 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
19 uinfo
->value
.integer
.min
= 0;
20 uinfo
->value
.integer
.max
= 1;
24 static int pcsp_enable_get(struct snd_kcontrol
*kcontrol
,
25 struct snd_ctl_elem_value
*ucontrol
)
27 struct snd_pcsp
*chip
= snd_kcontrol_chip(kcontrol
);
28 ucontrol
->value
.integer
.value
[0] = chip
->enable
;
32 static int pcsp_enable_put(struct snd_kcontrol
*kcontrol
,
33 struct snd_ctl_elem_value
*ucontrol
)
35 struct snd_pcsp
*chip
= snd_kcontrol_chip(kcontrol
);
37 int enab
= ucontrol
->value
.integer
.value
[0];
38 if (enab
!= chip
->enable
) {
45 static int pcsp_treble_info(struct snd_kcontrol
*kcontrol
,
46 struct snd_ctl_elem_info
*uinfo
)
48 struct snd_pcsp
*chip
= snd_kcontrol_chip(kcontrol
);
49 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
51 uinfo
->value
.enumerated
.items
= chip
->max_treble
+ 1;
52 if (uinfo
->value
.enumerated
.item
> chip
->max_treble
)
53 uinfo
->value
.enumerated
.item
= chip
->max_treble
;
54 sprintf(uinfo
->value
.enumerated
.name
, "%lu",
55 (unsigned long)PCSP_CALC_RATE(uinfo
->value
.enumerated
.item
));
59 static int pcsp_treble_get(struct snd_kcontrol
*kcontrol
,
60 struct snd_ctl_elem_value
*ucontrol
)
62 struct snd_pcsp
*chip
= snd_kcontrol_chip(kcontrol
);
63 ucontrol
->value
.enumerated
.item
[0] = chip
->treble
;
67 static int pcsp_treble_put(struct snd_kcontrol
*kcontrol
,
68 struct snd_ctl_elem_value
*ucontrol
)
70 struct snd_pcsp
*chip
= snd_kcontrol_chip(kcontrol
);
72 int treble
= ucontrol
->value
.enumerated
.item
[0];
73 if (treble
!= chip
->treble
) {
74 chip
->treble
= treble
;
76 printk(KERN_INFO
"PCSP: rate set to %li\n", PCSP_RATE());
83 static int pcsp_pcspkr_info(struct snd_kcontrol
*kcontrol
,
84 struct snd_ctl_elem_info
*uinfo
)
86 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
88 uinfo
->value
.integer
.min
= 0;
89 uinfo
->value
.integer
.max
= 1;
93 static int pcsp_pcspkr_get(struct snd_kcontrol
*kcontrol
,
94 struct snd_ctl_elem_value
*ucontrol
)
96 struct snd_pcsp
*chip
= snd_kcontrol_chip(kcontrol
);
97 ucontrol
->value
.integer
.value
[0] = chip
->pcspkr
;
101 static int pcsp_pcspkr_put(struct snd_kcontrol
*kcontrol
,
102 struct snd_ctl_elem_value
*ucontrol
)
104 struct snd_pcsp
*chip
= snd_kcontrol_chip(kcontrol
);
106 int spkr
= ucontrol
->value
.integer
.value
[0];
107 if (spkr
!= chip
->pcspkr
) {
114 #define PCSP_MIXER_CONTROL(ctl_type, ctl_name) \
116 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
118 .info = pcsp_##ctl_type##_info, \
119 .get = pcsp_##ctl_type##_get, \
120 .put = pcsp_##ctl_type##_put, \
123 static const struct snd_kcontrol_new snd_pcsp_controls_pcm
[] = {
124 PCSP_MIXER_CONTROL(enable
, "Master Playback Switch"),
125 PCSP_MIXER_CONTROL(treble
, "BaseFRQ Playback Volume"),
128 static const struct snd_kcontrol_new snd_pcsp_controls_spkr
[] = {
129 PCSP_MIXER_CONTROL(pcspkr
, "Beep Playback Switch"),
132 static int snd_pcsp_ctls_add(struct snd_pcsp
*chip
,
133 const struct snd_kcontrol_new
*ctls
, int num
)
136 struct snd_card
*card
= chip
->card
;
137 for (i
= 0; i
< num
; i
++) {
138 err
= snd_ctl_add(card
, snd_ctl_new1(ctls
+ i
, chip
));
145 int snd_pcsp_new_mixer(struct snd_pcsp
*chip
, int nopcm
)
148 struct snd_card
*card
= chip
->card
;
151 err
= snd_pcsp_ctls_add(chip
, snd_pcsp_controls_pcm
,
152 ARRAY_SIZE(snd_pcsp_controls_pcm
));
156 err
= snd_pcsp_ctls_add(chip
, snd_pcsp_controls_spkr
,
157 ARRAY_SIZE(snd_pcsp_controls_spkr
));
161 strcpy(card
->mixername
, "PC-Speaker");