--- zzzz-none-000/linux-3.10.107/sound/pci/hda/hda_beep.c 2017-06-27 09:49:32.000000000 +0000 +++ scorpion-7490-727/linux-3.10.107/sound/pci/hda/hda_beep.c 2021-02-04 17:41:59.000000000 +0000 @@ -1,7 +1,7 @@ /* * Digital Beep Input Interface for HD-audio codec * - * Author: Matthew Ranostay + * Author: Matt Ranostay * Copyright (c) 2008 Embedded Alley Solutions Inc * * This driver is free software; you can redistribute it and/or modify @@ -20,7 +20,6 @@ */ #include -#include #include #include #include @@ -34,30 +33,36 @@ DIGBEEP_HZ_MAX = 12000000, /* 12 KHz */ }; -static void snd_hda_generate_beep(struct work_struct *work) +/* generate or stop tone */ +static void generate_tone(struct hda_beep *beep, int tone) { - struct hda_beep *beep = - container_of(work, struct hda_beep, beep_work); struct hda_codec *codec = beep->codec; - int tone; - if (!beep->enabled) - return; - - tone = beep->tone; if (tone && !beep->playing) { snd_hda_power_up(codec); + if (beep->power_hook) + beep->power_hook(beep, true); beep->playing = 1; } - /* generate tone */ snd_hda_codec_write(codec, beep->nid, 0, AC_VERB_SET_BEEP_CONTROL, tone); if (!tone && beep->playing) { beep->playing = 0; + if (beep->power_hook) + beep->power_hook(beep, false); snd_hda_power_down(codec); } } +static void snd_hda_generate_beep(struct work_struct *work) +{ + struct hda_beep *beep = + container_of(work, struct hda_beep, beep_work); + + if (beep->enabled) + generate_tone(beep, beep->tone); +} + /* (non-standard) Linear beep tone calculation for IDT/STAC codecs * * The tone frequency of beep generator on IDT/STAC codecs is @@ -110,6 +115,7 @@ case SND_BELL: if (hz) hz = 1000; + /* fallthru */ case SND_TONE: if (beep->linear_tone) beep->tone = beep_linear_tone(beep, hz); @@ -130,16 +136,16 @@ cancel_work_sync(&beep->beep_work); if (beep->playing) { /* turn off beep */ - snd_hda_codec_write(beep->codec, beep->nid, 0, - AC_VERB_SET_BEEP_CONTROL, 0); - beep->playing = 0; - snd_hda_power_down(beep->codec); + generate_tone(beep, 0); } } static void snd_hda_do_detach(struct hda_beep *beep) { - input_unregister_device(beep->dev); + if (beep->registered) + input_unregister_device(beep->dev); + else + input_free_device(beep->dev); beep->dev = NULL; turn_off_beep(beep); } @@ -148,39 +154,35 @@ { struct input_dev *input_dev; struct hda_codec *codec = beep->codec; - int err; input_dev = input_allocate_device(); - if (!input_dev) { - printk(KERN_INFO "hda_beep: unable to allocate input device\n"); + if (!input_dev) return -ENOMEM; - } /* setup digital beep device */ input_dev->name = "HDA Digital PCBeep"; input_dev->phys = beep->phys; input_dev->id.bustype = BUS_PCI; + input_dev->dev.parent = &codec->card->card_dev; - input_dev->id.vendor = codec->vendor_id >> 16; - input_dev->id.product = codec->vendor_id & 0xffff; + input_dev->id.vendor = codec->core.vendor_id >> 16; + input_dev->id.product = codec->core.vendor_id & 0xffff; input_dev->id.version = 0x01; input_dev->evbit[0] = BIT_MASK(EV_SND); input_dev->sndbit[0] = BIT_MASK(SND_BELL) | BIT_MASK(SND_TONE); input_dev->event = snd_hda_beep_event; - input_dev->dev.parent = &codec->bus->pci->dev; input_set_drvdata(input_dev, beep); - err = input_register_device(input_dev); - if (err < 0) { - input_free_device(input_dev); - printk(KERN_INFO "hda_beep: unable to register input device\n"); - return err; - } beep->dev = input_dev; return 0; } +/** + * snd_hda_enable_beep_device - Turn on/off beep sound + * @codec: the HDA codec + * @enable: flag to turn on/off + */ int snd_hda_enable_beep_device(struct hda_codec *codec, int enable) { struct hda_beep *beep = codec->beep; @@ -195,8 +197,22 @@ } return 0; } -EXPORT_SYMBOL_HDA(snd_hda_enable_beep_device); +EXPORT_SYMBOL_GPL(snd_hda_enable_beep_device); +/** + * snd_hda_attach_beep_device - Attach a beep input device + * @codec: the HDA codec + * @nid: beep NID + * + * Attach a beep object to the given widget. If beep hint is turned off + * explicitly or beep_mode of the codec is turned off, this doesn't nothing. + * + * The attached beep device has to be registered via + * snd_hda_register_beep_device() and released via snd_hda_detach_beep_device() + * appropriately. + * + * Currently, only one beep device is allowed to each codec. + */ int snd_hda_attach_beep_device(struct hda_codec *codec, int nid) { struct hda_beep *beep; @@ -211,7 +227,7 @@ if (beep == NULL) return -ENOMEM; snprintf(beep->phys, sizeof(beep->phys), - "card%d/codec#%d/beep0", codec->bus->card->number, codec->addr); + "card%d/codec#%d/beep0", codec->card->number, codec->addr); /* enable linear scale */ snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_2, 0x01); @@ -232,8 +248,12 @@ return 0; } -EXPORT_SYMBOL_HDA(snd_hda_attach_beep_device); +EXPORT_SYMBOL_GPL(snd_hda_attach_beep_device); +/** + * snd_hda_detach_beep_device - Detach the beep device + * @codec: the HDA codec + */ void snd_hda_detach_beep_device(struct hda_codec *codec) { struct hda_beep *beep = codec->beep; @@ -244,7 +264,32 @@ kfree(beep); } } -EXPORT_SYMBOL_HDA(snd_hda_detach_beep_device); +EXPORT_SYMBOL_GPL(snd_hda_detach_beep_device); + +/** + * snd_hda_register_beep_device - Register the beep device + * @codec: the HDA codec + */ +int snd_hda_register_beep_device(struct hda_codec *codec) +{ + struct hda_beep *beep = codec->beep; + int err; + + if (!beep || !beep->dev) + return 0; + + err = input_register_device(beep->dev); + if (err < 0) { + codec_err(codec, "hda_beep: unable to register input device\n"); + input_free_device(beep->dev); + codec->beep = NULL; + kfree(beep); + return err; + } + beep->registered = true; + return 0; +} +EXPORT_SYMBOL_GPL(snd_hda_register_beep_device); static bool ctl_has_mute(struct snd_kcontrol *kcontrol) { @@ -254,6 +299,12 @@ } /* get/put callbacks for beep mute mixer switches */ + +/** + * snd_hda_mixer_amp_switch_get_beep - Get callback for beep controls + * @kcontrol: ctl element + * @ucontrol: pointer to get/store the data + */ int snd_hda_mixer_amp_switch_get_beep(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { @@ -266,8 +317,13 @@ } return snd_hda_mixer_amp_switch_get(kcontrol, ucontrol); } -EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_switch_get_beep); +EXPORT_SYMBOL_GPL(snd_hda_mixer_amp_switch_get_beep); +/** + * snd_hda_mixer_amp_switch_put_beep - Put callback for beep controls + * @kcontrol: ctl element + * @ucontrol: pointer to get/store the data + */ int snd_hda_mixer_amp_switch_put_beep(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { @@ -289,4 +345,4 @@ return 0; return snd_hda_mixer_amp_switch_put(kcontrol, ucontrol); } -EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_switch_put_beep); +EXPORT_SYMBOL_GPL(snd_hda_mixer_amp_switch_put_beep);