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; in generate_tone() local
28 if (tone && !beep->playing) { in generate_tone()
29 snd_hda_power_up(codec); in generate_tone()
30 if (beep->power_hook) in generate_tone()
31 beep->power_hook(beep, true); in generate_tone()
32 beep->playing = 1; in generate_tone()
34 snd_hda_codec_write(codec, beep->nid, 0, in generate_tone()
36 if (!tone && beep->playing) { in generate_tone()
37 beep->playing = 0; in generate_tone()
38 if (beep->power_hook) in generate_tone()
39 beep->power_hook(beep, false); in generate_tone()
40 snd_hda_power_down(codec); in generate_tone()
49 if (beep->enabled) in snd_hda_generate_beep()
50 generate_tone(beep, beep->tone); in snd_hda_generate_beep()
53 /* (non-standard) Linear beep tone calculation for IDT/STAC codecs
57 * freq = 48000 * (257 - tone) / 1024
65 hz = hz - DIGBEEP_HZ_MIN in beep_linear_tone()
68 hz = 0; /* turn off PC beep*/ in beep_linear_tone()
69 else if (hz >= (DIGBEEP_HZ_MAX - DIGBEEP_HZ_MIN)) in beep_linear_tone()
73 hz = 255 - hz; in beep_linear_tone()
78 /* HD-audio standard beep tone parameter calculation
107 if (beep->linear_tone) in snd_hda_beep_event()
108 beep->tone = beep_linear_tone(beep, hz); in snd_hda_beep_event()
110 beep->tone = beep_standard_tone(beep, hz); in snd_hda_beep_event()
113 return -1; in snd_hda_beep_event()
117 schedule_work(&beep->beep_work); in snd_hda_beep_event()
123 cancel_work_sync(&beep->beep_work); in turn_off_beep()
124 if (beep->playing) { in turn_off_beep()
125 /* turn off beep */ in turn_off_beep()
131 * snd_hda_enable_beep_device - Turn on/off beep sound
132 * @codec: the HDA codec
133 * @enable: flag to turn on/off
135 int snd_hda_enable_beep_device(struct hda_codec *codec, int enable) in snd_hda_enable_beep_device() argument
137 struct hda_beep *beep = codec->beep; in snd_hda_enable_beep_device()
141 if (beep->enabled != enable) { in snd_hda_enable_beep_device()
142 beep->enabled = enable; in snd_hda_enable_beep_device()
153 struct hda_beep *beep = device->device_data; in beep_dev_register()
156 err = input_register_device(beep->dev); in beep_dev_register()
158 beep->registered = true; in beep_dev_register()
164 struct hda_beep *beep = device->device_data; in beep_dev_disconnect()
166 if (beep->registered) in beep_dev_disconnect()
167 input_unregister_device(beep->dev); in beep_dev_disconnect()
169 input_free_device(beep->dev); in beep_dev_disconnect()
176 struct hda_beep *beep = device->device_data; in beep_dev_free()
178 beep->codec->beep = NULL; in beep_dev_free()
184 * snd_hda_attach_beep_device - Attach a beep input device
185 * @codec: the HDA codec
188 * Attach a beep object to the given widget. If beep hint is turned off
189 * explicitly or beep_mode of the codec is turned off, this doesn't nothing.
191 * Currently, only one beep device is allowed to each codec.
193 int snd_hda_attach_beep_device(struct hda_codec *codec, int nid) in snd_hda_attach_beep_device() argument
204 if (!snd_hda_get_bool_hint(codec, "beep")) in snd_hda_attach_beep_device()
206 if (codec->beep_mode == HDA_BEEP_MODE_OFF) in snd_hda_attach_beep_device()
211 return -ENOMEM; in snd_hda_attach_beep_device()
212 snprintf(beep->phys, sizeof(beep->phys), in snd_hda_attach_beep_device()
213 "card%d/codec#%d/beep0", codec->card->number, codec->addr); in snd_hda_attach_beep_device()
215 snd_hda_codec_write_cache(codec, nid, 0, in snd_hda_attach_beep_device()
218 beep->nid = nid; in snd_hda_attach_beep_device()
219 beep->codec = codec; in snd_hda_attach_beep_device()
220 codec->beep = beep; in snd_hda_attach_beep_device()
222 INIT_WORK(&beep->beep_work, &snd_hda_generate_beep); in snd_hda_attach_beep_device()
223 mutex_init(&beep->mutex); in snd_hda_attach_beep_device()
227 err = -ENOMEM; in snd_hda_attach_beep_device()
232 input_dev->name = "HDA Digital PCBeep"; in snd_hda_attach_beep_device()
233 input_dev->phys = beep->phys; in snd_hda_attach_beep_device()
234 input_dev->id.bustype = BUS_PCI; in snd_hda_attach_beep_device()
235 input_dev->dev.parent = &codec->card->card_dev; in snd_hda_attach_beep_device()
237 input_dev->id.vendor = codec->core.vendor_id >> 16; in snd_hda_attach_beep_device()
238 input_dev->id.product = codec->core.vendor_id & 0xffff; in snd_hda_attach_beep_device()
239 input_dev->id.version = 0x01; in snd_hda_attach_beep_device()
241 input_dev->evbit[0] = BIT_MASK(EV_SND); in snd_hda_attach_beep_device()
242 input_dev->sndbit[0] = BIT_MASK(SND_BELL) | BIT_MASK(SND_TONE); in snd_hda_attach_beep_device()
243 input_dev->event = snd_hda_beep_event; in snd_hda_attach_beep_device()
246 beep->dev = input_dev; in snd_hda_attach_beep_device()
248 err = snd_device_new(codec->card, SNDRV_DEV_JACK, beep, &ops); in snd_hda_attach_beep_device()
255 input_free_device(beep->dev); in snd_hda_attach_beep_device()
258 codec->beep = NULL; in snd_hda_attach_beep_device()
264 * snd_hda_detach_beep_device - Detach the beep device
265 * @codec: the HDA codec
267 void snd_hda_detach_beep_device(struct hda_codec *codec) in snd_hda_detach_beep_device() argument
269 if (!codec->bus->shutdown && codec->beep) in snd_hda_detach_beep_device()
270 snd_device_free(codec->card, codec->beep); in snd_hda_detach_beep_device()
276 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in ctl_has_mute() local
277 return query_amp_caps(codec, get_amp_nid(kcontrol), in ctl_has_mute()
284 * snd_hda_mixer_amp_switch_get_beep - Get callback for beep controls
291 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_mixer_amp_switch_get_beep() local
292 struct hda_beep *beep = codec->beep; in snd_hda_mixer_amp_switch_get_beep()
295 if (beep && (!beep->enabled || !ctl_has_mute(kcontrol))) { in snd_hda_mixer_amp_switch_get_beep()
297 ucontrol->value.integer.value[0] = beep->enabled; in snd_hda_mixer_amp_switch_get_beep()
299 ucontrol->value.integer.value[1] = beep->enabled; in snd_hda_mixer_amp_switch_get_beep()
307 * snd_hda_mixer_amp_switch_put_beep - Put callback for beep controls
314 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_mixer_amp_switch_put_beep() local
315 struct hda_beep *beep = codec->beep; in snd_hda_mixer_amp_switch_put_beep()
319 long *valp = ucontrol->value.integer.value; in snd_hda_mixer_amp_switch_put_beep()
326 snd_hda_enable_beep_device(codec, enable); in snd_hda_mixer_amp_switch_put_beep()