Lines Matching +full:off +full:- +full:codec

1 // SPDX-License-Identifier: GPL-2.0+
3 * Digital Beep Input Interface for HD-audio codec
26 struct hda_codec *codec = beep->codec;
28 if (tone && !beep->playing) {
29 snd_hda_power_up(codec);
30 if (beep->power_hook)
31 beep->power_hook(beep, true);
32 beep->playing = 1;
34 if (!codec->beep_just_power_on)
35 snd_hda_codec_write(codec, beep->nid, 0,
37 if (!tone && beep->playing) {
38 beep->playing = 0;
39 if (beep->power_hook)
40 beep->power_hook(beep, false);
41 snd_hda_power_down(codec);
50 if (beep->enabled)
51 generate_tone(beep, beep->tone);
54 /* (non-standard) Linear beep tone calculation for IDT/STAC codecs
58 * freq = 48000 * (257 - tone) / 1024
66 hz = hz - DIGBEEP_HZ_MIN
69 hz = 0; /* turn off PC beep*/
70 else if (hz >= (DIGBEEP_HZ_MAX - DIGBEEP_HZ_MIN))
74 hz = 255 - hz;
79 /* HD-audio standard beep tone parameter calculation
108 if (beep->linear_tone)
109 beep->tone = beep_linear_tone(beep, hz);
111 beep->tone = beep_standard_tone(beep, hz);
114 return -1;
118 schedule_work(&beep->beep_work);
124 if (beep->keep_power_at_enable)
125 snd_hda_power_up_pm(beep->codec);
130 cancel_work_sync(&beep->beep_work);
131 if (beep->playing) {
132 /* turn off beep */
135 if (beep->keep_power_at_enable)
136 snd_hda_power_down_pm(beep->codec);
140 * snd_hda_enable_beep_device - Turn on/off beep sound
141 * @codec: the HDA codec
142 * @enable: flag to turn on/off
144 int snd_hda_enable_beep_device(struct hda_codec *codec, int enable)
146 struct hda_beep *beep = codec->beep;
150 if (beep->enabled != enable) {
151 beep->enabled = enable;
164 struct hda_beep *beep = device->device_data;
167 err = input_register_device(beep->dev);
169 beep->registered = true;
175 struct hda_beep *beep = device->device_data;
177 if (beep->registered)
178 input_unregister_device(beep->dev);
180 input_free_device(beep->dev);
181 if (beep->enabled)
188 struct hda_beep *beep = device->device_data;
190 beep->codec->beep = NULL;
196 * snd_hda_attach_beep_device - Attach a beep input device
197 * @codec: the HDA codec
200 * Attach a beep object to the given widget. If beep hint is turned off
201 * explicitly or beep_mode of the codec is turned off, this doesn't nothing.
203 * Currently, only one beep device is allowed to each codec.
205 int snd_hda_attach_beep_device(struct hda_codec *codec, int nid)
216 if (!codec->beep_just_power_on) {
217 if (!snd_hda_get_bool_hint(codec, "beep"))
219 if (codec->beep_mode == HDA_BEEP_MODE_OFF)
225 return -ENOMEM;
226 snprintf(beep->phys, sizeof(beep->phys),
227 "card%d/codec#%d/beep0", codec->card->number, codec->addr);
229 snd_hda_codec_write_cache(codec, nid, 0,
232 beep->nid = nid;
233 beep->codec = codec;
234 codec->beep = beep;
236 INIT_WORK(&beep->beep_work, &snd_hda_generate_beep);
240 err = -ENOMEM;
245 input_dev->name = "HDA Digital PCBeep";
246 input_dev->phys = beep->phys;
247 input_dev->id.bustype = BUS_PCI;
248 input_dev->dev.parent = &codec->card->card_dev;
250 input_dev->id.vendor = codec->core.vendor_id >> 16;
251 input_dev->id.product = codec->core.vendor_id & 0xffff;
252 input_dev->id.version = 0x01;
254 input_dev->evbit[0] = BIT_MASK(EV_SND);
255 input_dev->sndbit[0] = BIT_MASK(SND_BELL) | BIT_MASK(SND_TONE);
256 input_dev->event = snd_hda_beep_event;
259 beep->dev = input_dev;
261 err = snd_device_new(codec->card, SNDRV_DEV_JACK, beep, &ops);
268 input_free_device(beep->dev);
271 codec->beep = NULL;
277 * snd_hda_detach_beep_device - Detach the beep device
278 * @codec: the HDA codec
280 void snd_hda_detach_beep_device(struct hda_codec *codec)
282 if (!codec->bus->shutdown && codec->beep)
283 snd_device_free(codec->card, codec->beep);
289 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
290 return query_amp_caps(codec, get_amp_nid(kcontrol),
297 * snd_hda_mixer_amp_switch_get_beep - Get callback for beep controls
304 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
305 struct hda_beep *beep = codec->beep;
308 if (beep && (!beep->enabled || !ctl_has_mute(kcontrol))) {
310 ucontrol->value.integer.value[0] = beep->enabled;
312 ucontrol->value.integer.value[1] = beep->enabled;
320 * snd_hda_mixer_amp_switch_put_beep - Put callback for beep controls
327 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
328 struct hda_beep *beep = codec->beep;
332 long *valp = ucontrol->value.integer.value;
339 snd_hda_enable_beep_device(codec, enable);