Lines Matching +full:codec +full:- +full:1
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()
69 else if (hz >= (DIGBEEP_HZ_MAX - DIGBEEP_HZ_MIN)) in beep_linear_tone()
70 hz = 1; /* max frequency */ in beep_linear_tone()
73 hz = 255 - hz; in beep_linear_tone()
78 /* HD-audio standard beep tone parameter calculation
92 return 1; in beep_standard_tone()
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 if (beep->keep_power_at_enable) in turn_on_beep()
124 snd_hda_power_up_pm(beep->codec); in turn_on_beep()
129 cancel_work_sync(&beep->beep_work); in turn_off_beep()
130 if (beep->playing) { in turn_off_beep()
134 if (beep->keep_power_at_enable) in turn_off_beep()
135 snd_hda_power_down_pm(beep->codec); in turn_off_beep()
139 * snd_hda_enable_beep_device - Turn on/off beep sound
140 * @codec: the HDA codec
143 int snd_hda_enable_beep_device(struct hda_codec *codec, int enable) in snd_hda_enable_beep_device() argument
145 struct hda_beep *beep = codec->beep; in snd_hda_enable_beep_device()
149 if (beep->enabled != enable) { in snd_hda_enable_beep_device()
150 beep->enabled = enable; in snd_hda_enable_beep_device()
155 return 1; in snd_hda_enable_beep_device()
163 struct hda_beep *beep = device->device_data; in beep_dev_register()
166 err = input_register_device(beep->dev); in beep_dev_register()
168 beep->registered = true; in beep_dev_register()
174 struct hda_beep *beep = device->device_data; in beep_dev_disconnect()
176 if (beep->registered) in beep_dev_disconnect()
177 input_unregister_device(beep->dev); in beep_dev_disconnect()
179 input_free_device(beep->dev); in beep_dev_disconnect()
180 if (beep->enabled) in beep_dev_disconnect()
187 struct hda_beep *beep = device->device_data; in beep_dev_free()
189 beep->codec->beep = NULL; in beep_dev_free()
195 * snd_hda_attach_beep_device - Attach a beep input device
196 * @codec: the HDA codec
200 * explicitly or beep_mode of the codec is turned off, this doesn't nothing.
202 * Currently, only one beep device is allowed to each codec.
204 int snd_hda_attach_beep_device(struct hda_codec *codec, int nid) in snd_hda_attach_beep_device() argument
215 if (!snd_hda_get_bool_hint(codec, "beep")) in snd_hda_attach_beep_device()
217 if (codec->beep_mode == HDA_BEEP_MODE_OFF) in snd_hda_attach_beep_device()
222 return -ENOMEM; in snd_hda_attach_beep_device()
223 snprintf(beep->phys, sizeof(beep->phys), in snd_hda_attach_beep_device()
224 "card%d/codec#%d/beep0", codec->card->number, codec->addr); in snd_hda_attach_beep_device()
226 snd_hda_codec_write_cache(codec, nid, 0, in snd_hda_attach_beep_device()
229 beep->nid = nid; in snd_hda_attach_beep_device()
230 beep->codec = codec; in snd_hda_attach_beep_device()
231 codec->beep = beep; in snd_hda_attach_beep_device()
233 INIT_WORK(&beep->beep_work, &snd_hda_generate_beep); in snd_hda_attach_beep_device()
234 mutex_init(&beep->mutex); in snd_hda_attach_beep_device()
238 err = -ENOMEM; in snd_hda_attach_beep_device()
243 input_dev->name = "HDA Digital PCBeep"; in snd_hda_attach_beep_device()
244 input_dev->phys = beep->phys; in snd_hda_attach_beep_device()
245 input_dev->id.bustype = BUS_PCI; in snd_hda_attach_beep_device()
246 input_dev->dev.parent = &codec->card->card_dev; in snd_hda_attach_beep_device()
248 input_dev->id.vendor = codec->core.vendor_id >> 16; in snd_hda_attach_beep_device()
249 input_dev->id.product = codec->core.vendor_id & 0xffff; in snd_hda_attach_beep_device()
250 input_dev->id.version = 0x01; in snd_hda_attach_beep_device()
252 input_dev->evbit[0] = BIT_MASK(EV_SND); in snd_hda_attach_beep_device()
253 input_dev->sndbit[0] = BIT_MASK(SND_BELL) | BIT_MASK(SND_TONE); in snd_hda_attach_beep_device()
254 input_dev->event = snd_hda_beep_event; in snd_hda_attach_beep_device()
257 beep->dev = input_dev; in snd_hda_attach_beep_device()
259 err = snd_device_new(codec->card, SNDRV_DEV_JACK, beep, &ops); in snd_hda_attach_beep_device()
266 input_free_device(beep->dev); in snd_hda_attach_beep_device()
269 codec->beep = NULL; in snd_hda_attach_beep_device()
275 * snd_hda_detach_beep_device - Detach the beep device
276 * @codec: the HDA codec
278 void snd_hda_detach_beep_device(struct hda_codec *codec) in snd_hda_detach_beep_device() argument
280 if (!codec->bus->shutdown && codec->beep) in snd_hda_detach_beep_device()
281 snd_device_free(codec->card, codec->beep); in snd_hda_detach_beep_device()
287 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in ctl_has_mute() local
288 return query_amp_caps(codec, get_amp_nid(kcontrol), in ctl_has_mute()
295 * snd_hda_mixer_amp_switch_get_beep - Get callback for beep controls
302 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_mixer_amp_switch_get_beep() local
303 struct hda_beep *beep = codec->beep; in snd_hda_mixer_amp_switch_get_beep()
306 if (beep && (!beep->enabled || !ctl_has_mute(kcontrol))) { in snd_hda_mixer_amp_switch_get_beep()
307 if (chs & 1) in snd_hda_mixer_amp_switch_get_beep()
308 ucontrol->value.integer.value[0] = beep->enabled; in snd_hda_mixer_amp_switch_get_beep()
310 ucontrol->value.integer.value[1] = beep->enabled; in snd_hda_mixer_amp_switch_get_beep()
318 * snd_hda_mixer_amp_switch_put_beep - Put callback for beep controls
325 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in snd_hda_mixer_amp_switch_put_beep() local
326 struct hda_beep *beep = codec->beep; in snd_hda_mixer_amp_switch_put_beep()
330 long *valp = ucontrol->value.integer.value; in snd_hda_mixer_amp_switch_put_beep()
331 if (chs & 1) { in snd_hda_mixer_amp_switch_put_beep()
337 snd_hda_enable_beep_device(codec, enable); in snd_hda_mixer_amp_switch_put_beep()