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 cancel_work_sync(&beep->beep_work); in turn_off_beep()
124 if (beep->playing) { in turn_off_beep()
131 * snd_hda_enable_beep_device - Turn on/off beep sound
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
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()
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
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()
284 * snd_hda_mixer_amp_switch_get_beep - Get callback for beep controls
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
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()