aboutsummaryrefslogtreecommitdiffstats
path: root/sound/pci/hda/hda_beep.c
diff options
context:
space:
mode:
Diffstat (limited to 'sound/pci/hda/hda_beep.c')
-rw-r--r--sound/pci/hda/hda_beep.c36
1 files changed, 26 insertions, 10 deletions
diff --git a/sound/pci/hda/hda_beep.c b/sound/pci/hda/hda_beep.c
index 0589b39cda6e..8c6c50afc0b7 100644
--- a/sound/pci/hda/hda_beep.c
+++ b/sound/pci/hda/hda_beep.c
@@ -20,7 +20,6 @@
20 */ 20 */
21 21
22#include <linux/input.h> 22#include <linux/input.h>
23#include <linux/pci.h>
24#include <linux/slab.h> 23#include <linux/slab.h>
25#include <linux/workqueue.h> 24#include <linux/workqueue.h>
26#include <linux/export.h> 25#include <linux/export.h>
@@ -140,7 +139,10 @@ static void turn_off_beep(struct hda_beep *beep)
140 139
141static void snd_hda_do_detach(struct hda_beep *beep) 140static void snd_hda_do_detach(struct hda_beep *beep)
142{ 141{
143 input_unregister_device(beep->dev); 142 if (beep->registered)
143 input_unregister_device(beep->dev);
144 else
145 input_free_device(beep->dev);
144 beep->dev = NULL; 146 beep->dev = NULL;
145 turn_off_beep(beep); 147 turn_off_beep(beep);
146} 148}
@@ -149,7 +151,6 @@ static int snd_hda_do_attach(struct hda_beep *beep)
149{ 151{
150 struct input_dev *input_dev; 152 struct input_dev *input_dev;
151 struct hda_codec *codec = beep->codec; 153 struct hda_codec *codec = beep->codec;
152 int err;
153 154
154 input_dev = input_allocate_device(); 155 input_dev = input_allocate_device();
155 if (!input_dev) 156 if (!input_dev)
@@ -167,15 +168,9 @@ static int snd_hda_do_attach(struct hda_beep *beep)
167 input_dev->evbit[0] = BIT_MASK(EV_SND); 168 input_dev->evbit[0] = BIT_MASK(EV_SND);
168 input_dev->sndbit[0] = BIT_MASK(SND_BELL) | BIT_MASK(SND_TONE); 169 input_dev->sndbit[0] = BIT_MASK(SND_BELL) | BIT_MASK(SND_TONE);
169 input_dev->event = snd_hda_beep_event; 170 input_dev->event = snd_hda_beep_event;
170 input_dev->dev.parent = &codec->bus->pci->dev; 171 input_dev->dev.parent = &codec->dev;
171 input_set_drvdata(input_dev, beep); 172 input_set_drvdata(input_dev, beep);
172 173
173 err = input_register_device(input_dev);
174 if (err < 0) {
175 input_free_device(input_dev);
176 printk(KERN_INFO "hda_beep: unable to register input device\n");
177 return err;
178 }
179 beep->dev = input_dev; 174 beep->dev = input_dev;
180 return 0; 175 return 0;
181} 176}
@@ -245,6 +240,27 @@ void snd_hda_detach_beep_device(struct hda_codec *codec)
245} 240}
246EXPORT_SYMBOL_GPL(snd_hda_detach_beep_device); 241EXPORT_SYMBOL_GPL(snd_hda_detach_beep_device);
247 242
243int snd_hda_register_beep_device(struct hda_codec *codec)
244{
245 struct hda_beep *beep = codec->beep;
246 int err;
247
248 if (!beep || !beep->dev)
249 return 0;
250
251 err = input_register_device(beep->dev);
252 if (err < 0) {
253 codec_err(codec, "hda_beep: unable to register input device\n");
254 input_free_device(beep->dev);
255 codec->beep = NULL;
256 kfree(beep);
257 return err;
258 }
259 beep->registered = true;
260 return 0;
261}
262EXPORT_SYMBOL_GPL(snd_hda_register_beep_device);
263
248static bool ctl_has_mute(struct snd_kcontrol *kcontrol) 264static bool ctl_has_mute(struct snd_kcontrol *kcontrol)
249{ 265{
250 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 266 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);