Lines Matching +full:switch +full:- +full:frequency +full:- +full:hz

1 // SPDX-License-Identifier: GPL-2.0+
3 * Digital Beep Input Interface for HD-audio codec
18 DIGBEEP_HZ_STEP = 46875, /* 46.875 Hz */
19 DIGBEEP_HZ_MIN = 93750, /* 93.750 Hz */
26 struct hda_codec *codec = beep->codec; in generate_tone()
28 if (tone && !beep->playing) { 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()
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
55 * The tone frequency of beep generator on IDT/STAC codecs is
56 * defined from the 8bit tone parameter, in Hz,
57 * freq = 48000 * (257 - tone) / 1024
58 * that is from 12kHz to 93.75Hz in steps of 46.875 Hz
60 static int beep_linear_tone(struct hda_beep *beep, int hz) in beep_linear_tone() argument
62 if (hz <= 0) in beep_linear_tone()
64 hz *= 1000; /* fixed point */ in beep_linear_tone()
65 hz = hz - DIGBEEP_HZ_MIN in beep_linear_tone()
67 if (hz < 0) 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()
70 hz = 1; /* max frequency */ in beep_linear_tone()
72 hz /= DIGBEEP_HZ_STEP; in beep_linear_tone()
73 hz = 255 - hz; in beep_linear_tone()
75 return hz; in beep_linear_tone()
78 /* HD-audio standard beep tone parameter calculation
80 * The tone frequency in Hz is calculated as
82 * from 47Hz to 12kHz
84 static int beep_standard_tone(struct hda_beep *beep, int hz) in beep_standard_tone() argument
86 if (hz <= 0) in beep_standard_tone()
88 hz = 12000 / hz; in beep_standard_tone()
89 if (hz > 0xff) in beep_standard_tone()
91 if (hz <= 0) in beep_standard_tone()
93 return hz; in beep_standard_tone()
97 unsigned int code, int hz) in snd_hda_beep_event() argument
101 switch (code) { in snd_hda_beep_event()
103 if (hz) in snd_hda_beep_event()
104 hz = 1000; in snd_hda_beep_event()
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
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()
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
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()
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()
237 err = -ENOMEM; in snd_hda_attach_beep_device()
242 input_dev->name = "HDA Digital PCBeep"; in snd_hda_attach_beep_device()
243 input_dev->phys = beep->phys; in snd_hda_attach_beep_device()
244 input_dev->id.bustype = BUS_PCI; in snd_hda_attach_beep_device()
245 input_dev->dev.parent = &codec->card->card_dev; in snd_hda_attach_beep_device()
247 input_dev->id.vendor = codec->core.vendor_id >> 16; in snd_hda_attach_beep_device()
248 input_dev->id.product = codec->core.vendor_id & 0xffff; in snd_hda_attach_beep_device()
249 input_dev->id.version = 0x01; in snd_hda_attach_beep_device()
251 input_dev->evbit[0] = BIT_MASK(EV_SND); in snd_hda_attach_beep_device()
252 input_dev->sndbit[0] = BIT_MASK(SND_BELL) | BIT_MASK(SND_TONE); in snd_hda_attach_beep_device()
253 input_dev->event = snd_hda_beep_event; in snd_hda_attach_beep_device()
256 beep->dev = input_dev; in snd_hda_attach_beep_device()
258 err = snd_device_new(codec->card, SNDRV_DEV_JACK, beep, &ops); in snd_hda_attach_beep_device()
265 input_free_device(beep->dev); in snd_hda_attach_beep_device()
268 codec->beep = NULL; in snd_hda_attach_beep_device()
274 * snd_hda_detach_beep_device - Detach the beep device
279 if (!codec->bus->shutdown && codec->beep) in snd_hda_detach_beep_device()
280 snd_device_free(codec->card, codec->beep); in snd_hda_detach_beep_device()
294 * snd_hda_mixer_amp_switch_get_beep - Get callback for beep controls
302 struct hda_beep *beep = codec->beep; in snd_hda_mixer_amp_switch_get_beep()
305 if (beep && (!beep->enabled || !ctl_has_mute(kcontrol))) { in snd_hda_mixer_amp_switch_get_beep()
307 ucontrol->value.integer.value[0] = beep->enabled; in snd_hda_mixer_amp_switch_get_beep()
309 ucontrol->value.integer.value[1] = beep->enabled; in snd_hda_mixer_amp_switch_get_beep()
317 * snd_hda_mixer_amp_switch_put_beep - Put callback for beep controls
325 struct hda_beep *beep = codec->beep; in snd_hda_mixer_amp_switch_put_beep()
329 long *valp = ucontrol->value.integer.value; in snd_hda_mixer_amp_switch_put_beep()