diff options
author | David Henningsson <david.henningsson@canonical.com> | 2012-09-25 05:30:59 -0400 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2012-10-06 10:43:31 -0400 |
commit | 954df2a9686cebbb9cc4067697b370aa9ce77d4a (patch) | |
tree | c80b9b5959d14637b3061934c15b348449f0e79b /sound | |
parent | 0fd0ba5f9e8ebae66afded580f5f34936f740ac7 (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.c | 32 | ||||
-rw-r--r-- | sound/pci/hda/hda_jack.h | 9 |
2 files changed, 39 insertions, 2 deletions
diff --git a/sound/pci/hda/hda_jack.c b/sound/pci/hda/hda_jack.c index c9333c9688fb..5c690cb873d4 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 | */ |
195 | int snd_hda_jack_detect_enable(struct hda_codec *codec, hda_nid_t nid, | 195 | int 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 | } |
213 | EXPORT_SYMBOL_HDA(snd_hda_jack_detect_enable_callback); | ||
214 | |||
215 | int 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 | } | ||
210 | EXPORT_SYMBOL_HDA(snd_hda_jack_detect_enable); | 220 | EXPORT_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 | } |
413 | EXPORT_SYMBOL_HDA(snd_hda_jack_add_kctls); | 423 | EXPORT_SYMBOL_HDA(snd_hda_jack_add_kctls); |
424 | |||
425 | void 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 | } | ||
440 | EXPORT_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 a9803da633c0..af8dd4724da5 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 | ||
15 | struct auto_pin_cfg; | 15 | struct auto_pin_cfg; |
16 | struct hda_jack_tbl; | ||
17 | |||
18 | typedef void (*hda_jack_callback) (struct hda_codec *, struct hda_jack_tbl *); | ||
16 | 19 | ||
17 | struct hda_jack_tbl { | 20 | struct 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 | ||
62 | int snd_hda_jack_detect_enable(struct hda_codec *codec, hda_nid_t nid, | 66 | int snd_hda_jack_detect_enable(struct hda_codec *codec, hda_nid_t nid, |
63 | unsigned char action); | 67 | unsigned char action); |
68 | int 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 | ||
65 | u32 snd_hda_pin_sense(struct hda_codec *codec, hda_nid_t nid); | 73 | u32 snd_hda_pin_sense(struct hda_codec *codec, hda_nid_t nid); |
66 | int snd_hda_jack_detect(struct hda_codec *codec, hda_nid_t nid); | 74 | int 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 | ||
75 | void snd_hda_jack_report_sync(struct hda_codec *codec); | 83 | void snd_hda_jack_report_sync(struct hda_codec *codec); |
76 | 84 | ||
85 | void 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 */ |