aboutsummaryrefslogtreecommitdiffstats
path: root/sound
diff options
context:
space:
mode:
authorDavid Henningsson <david.henningsson@canonical.com>2012-09-25 05:30:59 -0400
committerTakashi Iwai <tiwai@suse.de>2012-10-06 10:43:31 -0400
commit954df2a9686cebbb9cc4067697b370aa9ce77d4a (patch)
treec80b9b5959d14637b3061934c15b348449f0e79b /sound
parent0fd0ba5f9e8ebae66afded580f5f34936f740ac7 (diff)
ALSA: hda - make a generic unsol event handler
Moving towards less duplication of code between codecs - this patch takes some of the common code of unsol event handling and makes it generic. Signed-off-by: David Henningsson <david.henningsson@canonical.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound')
-rw-r--r--sound/pci/hda/hda_jack.c32
-rw-r--r--sound/pci/hda/hda_jack.h9
2 files changed, 39 insertions, 2 deletions
diff --git a/sound/pci/hda/hda_jack.c b/sound/pci/hda/hda_jack.c
index c9333c9688f..5c690cb873d 100644
--- a/sound/pci/hda/hda_jack.c
+++ b/sound/pci/hda/hda_jack.c
@@ -192,8 +192,9 @@ EXPORT_SYMBOL_HDA(snd_hda_jack_detect);
192/** 192/**
193 * snd_hda_jack_detect_enable - enable the jack-detection 193 * snd_hda_jack_detect_enable - enable the jack-detection
194 */ 194 */
195int snd_hda_jack_detect_enable(struct hda_codec *codec, hda_nid_t nid, 195int snd_hda_jack_detect_enable_callback(struct hda_codec *codec, hda_nid_t nid,
196 unsigned char action) 196 unsigned char action,
197 hda_jack_callback cb)
197{ 198{
198 struct hda_jack_tbl *jack = snd_hda_jack_tbl_new(codec, nid); 199 struct hda_jack_tbl *jack = snd_hda_jack_tbl_new(codec, nid);
199 if (!jack) 200 if (!jack)
@@ -203,10 +204,19 @@ int snd_hda_jack_detect_enable(struct hda_codec *codec, hda_nid_t nid,
203 jack->jack_detect = 1; 204 jack->jack_detect = 1;
204 if (action) 205 if (action)
205 jack->action = action; 206 jack->action = action;
207 if (cb)
208 jack->callback = cb;
206 return snd_hda_codec_write_cache(codec, nid, 0, 209 return snd_hda_codec_write_cache(codec, nid, 0,
207 AC_VERB_SET_UNSOLICITED_ENABLE, 210 AC_VERB_SET_UNSOLICITED_ENABLE,
208 AC_USRSP_EN | jack->tag); 211 AC_USRSP_EN | jack->tag);
209} 212}
213EXPORT_SYMBOL_HDA(snd_hda_jack_detect_enable_callback);
214
215int snd_hda_jack_detect_enable(struct hda_codec *codec, hda_nid_t nid,
216 unsigned char action)
217{
218 return snd_hda_jack_detect_enable_callback(codec, nid, action, NULL);
219}
210EXPORT_SYMBOL_HDA(snd_hda_jack_detect_enable); 220EXPORT_SYMBOL_HDA(snd_hda_jack_detect_enable);
211 221
212/** 222/**
@@ -411,3 +421,21 @@ int snd_hda_jack_add_kctls(struct hda_codec *codec,
411 return 0; 421 return 0;
412} 422}
413EXPORT_SYMBOL_HDA(snd_hda_jack_add_kctls); 423EXPORT_SYMBOL_HDA(snd_hda_jack_add_kctls);
424
425void snd_hda_jack_unsol_event(struct hda_codec *codec, unsigned int res)
426{
427 struct hda_jack_tbl *event;
428 int tag = (res >> AC_UNSOL_RES_TAG_SHIFT) & 0x7f;
429
430 event = snd_hda_jack_tbl_get_from_tag(codec, tag);
431 if (!event)
432 return;
433 event->jack_dirty = 1;
434
435 if (event->callback)
436 event->callback(codec, event);
437
438 snd_hda_jack_report_sync(codec);
439}
440EXPORT_SYMBOL_HDA(snd_hda_jack_unsol_event);
441
diff --git a/sound/pci/hda/hda_jack.h b/sound/pci/hda/hda_jack.h
index a9803da633c..af8dd4724da 100644
--- a/sound/pci/hda/hda_jack.h
+++ b/sound/pci/hda/hda_jack.h
@@ -13,12 +13,16 @@
13#define __SOUND_HDA_JACK_H 13#define __SOUND_HDA_JACK_H
14 14
15struct auto_pin_cfg; 15struct auto_pin_cfg;
16struct hda_jack_tbl;
17
18typedef void (*hda_jack_callback) (struct hda_codec *, struct hda_jack_tbl *);
16 19
17struct hda_jack_tbl { 20struct hda_jack_tbl {
18 hda_nid_t nid; 21 hda_nid_t nid;
19 unsigned char action; /* event action (0 = none) */ 22 unsigned char action; /* event action (0 = none) */
20 unsigned char tag; /* unsol event tag */ 23 unsigned char tag; /* unsol event tag */
21 unsigned int private_data; /* arbitrary data */ 24 unsigned int private_data; /* arbitrary data */
25 hda_jack_callback callback;
22 /* jack-detection stuff */ 26 /* jack-detection stuff */
23 unsigned int pin_sense; /* cached pin-sense value */ 27 unsigned int pin_sense; /* cached pin-sense value */
24 unsigned int jack_detect:1; /* capable of jack-detection? */ 28 unsigned int jack_detect:1; /* capable of jack-detection? */
@@ -61,6 +65,10 @@ void snd_hda_jack_set_dirty_all(struct hda_codec *codec);
61 65
62int snd_hda_jack_detect_enable(struct hda_codec *codec, hda_nid_t nid, 66int snd_hda_jack_detect_enable(struct hda_codec *codec, hda_nid_t nid,
63 unsigned char action); 67 unsigned char action);
68int snd_hda_jack_detect_enable_callback(struct hda_codec *codec, hda_nid_t nid,
69 unsigned char action,
70 hda_jack_callback cb);
71
64 72
65u32 snd_hda_pin_sense(struct hda_codec *codec, hda_nid_t nid); 73u32 snd_hda_pin_sense(struct hda_codec *codec, hda_nid_t nid);
66int snd_hda_jack_detect(struct hda_codec *codec, hda_nid_t nid); 74int snd_hda_jack_detect(struct hda_codec *codec, hda_nid_t nid);
@@ -74,5 +82,6 @@ int snd_hda_jack_add_kctls(struct hda_codec *codec,
74 82
75void snd_hda_jack_report_sync(struct hda_codec *codec); 83void snd_hda_jack_report_sync(struct hda_codec *codec);
76 84
85void snd_hda_jack_unsol_event(struct hda_codec *codec, unsigned int res);
77 86
78#endif /* __SOUND_HDA_JACK_H */ 87#endif /* __SOUND_HDA_JACK_H */