aboutsummaryrefslogtreecommitdiffstats
path: root/sound/pci
diff options
context:
space:
mode:
authorDavid Henningsson <david.henningsson@canonical.com>2012-10-09 09:04:21 -0400
committerTakashi Iwai <tiwai@suse.de>2012-10-15 03:58:28 -0400
commit26a6cb6cca225f652acf4bfac3028019be73dadd (patch)
tree883cf924a81b442d5dd9b9a375d6aa12968c1fa6 /sound/pci
parent239fb862e8e26287212bdefabb021ef8c5ef1b53 (diff)
ALSA: hda - Implement a poll loop for jacks as a module parameter
Now that we have a generic unsol mechanism, we can implement a generic poll loop, which can be used for debugging, or if a codec's unsol mechanism is broken. Signed-off-by: David Henningsson <david.henningsson@canonical.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/pci')
-rw-r--r--sound/pci/hda/hda_codec.c32
-rw-r--r--sound/pci/hda/hda_codec.h2
-rw-r--r--sound/pci/hda/hda_intel.c20
-rw-r--r--sound/pci/hda/hda_jack.c22
-rw-r--r--sound/pci/hda/hda_jack.h2
5 files changed, 74 insertions, 4 deletions
diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
index 70d4848b5cd0..ee958a7d1647 100644
--- a/sound/pci/hda/hda_codec.c
+++ b/sound/pci/hda/hda_codec.c
@@ -1135,6 +1135,19 @@ static void restore_shutup_pins(struct hda_codec *codec)
1135} 1135}
1136#endif 1136#endif
1137 1137
1138static void hda_jackpoll_work(struct work_struct *work)
1139{
1140 struct hda_codec *codec =
1141 container_of(work, struct hda_codec, jackpoll_work.work);
1142 if (!codec->jackpoll_interval)
1143 return;
1144
1145 snd_hda_jack_set_dirty_all(codec);
1146 snd_hda_jack_poll_all(codec);
1147 queue_delayed_work(codec->bus->workq, &codec->jackpoll_work,
1148 codec->jackpoll_interval);
1149}
1150
1138static void init_hda_cache(struct hda_cache_rec *cache, 1151static void init_hda_cache(struct hda_cache_rec *cache,
1139 unsigned int record_size); 1152 unsigned int record_size);
1140static void free_hda_cache(struct hda_cache_rec *cache); 1153static void free_hda_cache(struct hda_cache_rec *cache);
@@ -1190,6 +1203,7 @@ static void snd_hda_codec_free(struct hda_codec *codec)
1190{ 1203{
1191 if (!codec) 1204 if (!codec)
1192 return; 1205 return;
1206 cancel_delayed_work_sync(&codec->jackpoll_work);
1193 snd_hda_jack_tbl_clear(codec); 1207 snd_hda_jack_tbl_clear(codec);
1194 restore_init_pincfgs(codec); 1208 restore_init_pincfgs(codec);
1195#ifdef CONFIG_PM 1209#ifdef CONFIG_PM
@@ -1273,6 +1287,7 @@ int /*__devinit*/ snd_hda_codec_new(struct hda_bus *bus,
1273 snd_array_init(&codec->cvt_setups, sizeof(struct hda_cvt_setup), 8); 1287 snd_array_init(&codec->cvt_setups, sizeof(struct hda_cvt_setup), 8);
1274 snd_array_init(&codec->conn_lists, sizeof(hda_nid_t), 64); 1288 snd_array_init(&codec->conn_lists, sizeof(hda_nid_t), 64);
1275 snd_array_init(&codec->spdif_out, sizeof(struct hda_spdif_out), 16); 1289 snd_array_init(&codec->spdif_out, sizeof(struct hda_spdif_out), 16);
1290 INIT_DELAYED_WORK(&codec->jackpoll_work, hda_jackpoll_work);
1276 1291
1277#ifdef CONFIG_PM 1292#ifdef CONFIG_PM
1278 spin_lock_init(&codec->power_lock); 1293 spin_lock_init(&codec->power_lock);
@@ -2349,7 +2364,7 @@ int snd_hda_codec_reset(struct hda_codec *codec)
2349 return -EBUSY; 2364 return -EBUSY;
2350 2365
2351 /* OK, let it free */ 2366 /* OK, let it free */
2352 2367 cancel_delayed_work_sync(&codec->jackpoll_work);
2353#ifdef CONFIG_PM 2368#ifdef CONFIG_PM
2354 cancel_delayed_work_sync(&codec->power_work); 2369 cancel_delayed_work_sync(&codec->power_work);
2355 codec->power_on = 0; 2370 codec->power_on = 0;
@@ -3646,7 +3661,6 @@ static void hda_call_codec_resume(struct hda_codec *codec)
3646 restore_pincfgs(codec); /* restore all current pin configs */ 3661 restore_pincfgs(codec); /* restore all current pin configs */
3647 restore_shutup_pins(codec); 3662 restore_shutup_pins(codec);
3648 hda_exec_init_verbs(codec); 3663 hda_exec_init_verbs(codec);
3649 snd_hda_jack_set_dirty_all(codec);
3650 if (codec->patch_ops.resume) 3664 if (codec->patch_ops.resume)
3651 codec->patch_ops.resume(codec); 3665 codec->patch_ops.resume(codec);
3652 else { 3666 else {
@@ -3655,7 +3669,13 @@ static void hda_call_codec_resume(struct hda_codec *codec)
3655 snd_hda_codec_resume_amp(codec); 3669 snd_hda_codec_resume_amp(codec);
3656 snd_hda_codec_resume_cache(codec); 3670 snd_hda_codec_resume_cache(codec);
3657 } 3671 }
3658 snd_hda_jack_report_sync(codec); 3672
3673 if (codec->jackpoll_interval)
3674 hda_jackpoll_work(&codec->jackpoll_work.work);
3675 else {
3676 snd_hda_jack_set_dirty_all(codec);
3677 snd_hda_jack_report_sync(codec);
3678 }
3659 snd_hda_power_down(codec); /* flag down before returning */ 3679 snd_hda_power_down(codec); /* flag down before returning */
3660} 3680}
3661#endif /* CONFIG_PM */ 3681#endif /* CONFIG_PM */
@@ -3737,7 +3757,10 @@ int snd_hda_codec_build_controls(struct hda_codec *codec)
3737 if (err < 0) 3757 if (err < 0)
3738 return err; 3758 return err;
3739 3759
3740 snd_hda_jack_report_sync(codec); /* call at the last init point */ 3760 if (codec->jackpoll_interval)
3761 hda_jackpoll_work(&codec->jackpoll_work.work);
3762 else
3763 snd_hda_jack_report_sync(codec); /* call at the last init point */
3741 return 0; 3764 return 0;
3742} 3765}
3743 3766
@@ -5128,6 +5151,7 @@ int snd_hda_suspend(struct hda_bus *bus)
5128 struct hda_codec *codec; 5151 struct hda_codec *codec;
5129 5152
5130 list_for_each_entry(codec, &bus->codec_list, list) { 5153 list_for_each_entry(codec, &bus->codec_list, list) {
5154 cancel_delayed_work_sync(&codec->jackpoll_work);
5131 if (hda_codec_is_power_on(codec)) 5155 if (hda_codec_is_power_on(codec))
5132 hda_call_codec_suspend(codec, false); 5156 hda_call_codec_suspend(codec, false);
5133 } 5157 }
diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h
index 507fe8a917b6..10a03b049bed 100644
--- a/sound/pci/hda/hda_codec.h
+++ b/sound/pci/hda/hda_codec.h
@@ -884,6 +884,8 @@ struct hda_codec {
884 884
885 /* jack detection */ 885 /* jack detection */
886 struct snd_array jacktbl; 886 struct snd_array jacktbl;
887 unsigned long jackpoll_interval; /* In jiffies. Zero means no poll, rely on unsol events */
888 struct delayed_work jackpoll_work;
887 889
888#ifdef CONFIG_SND_HDA_INPUT_JACK 890#ifdef CONFIG_SND_HDA_INPUT_JACK
889 /* jack detection */ 891 /* jack detection */
diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c
index ecf277506ad1..d327ffa5b753 100644
--- a/sound/pci/hda/hda_intel.c
+++ b/sound/pci/hda/hda_intel.c
@@ -68,6 +68,7 @@ static int position_fix[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = -1};
68static int bdl_pos_adj[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = -1}; 68static int bdl_pos_adj[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = -1};
69static int probe_mask[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = -1}; 69static int probe_mask[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = -1};
70static int probe_only[SNDRV_CARDS]; 70static int probe_only[SNDRV_CARDS];
71static int jackpoll_ms[SNDRV_CARDS];
71static bool single_cmd; 72static bool single_cmd;
72static int enable_msi = -1; 73static int enable_msi = -1;
73#ifdef CONFIG_SND_HDA_PATCH_LOADER 74#ifdef CONFIG_SND_HDA_PATCH_LOADER
@@ -95,6 +96,8 @@ module_param_array(probe_mask, int, NULL, 0444);
95MODULE_PARM_DESC(probe_mask, "Bitmask to probe codecs (default = -1)."); 96MODULE_PARM_DESC(probe_mask, "Bitmask to probe codecs (default = -1).");
96module_param_array(probe_only, int, NULL, 0444); 97module_param_array(probe_only, int, NULL, 0444);
97MODULE_PARM_DESC(probe_only, "Only probing and no codec initialization."); 98MODULE_PARM_DESC(probe_only, "Only probing and no codec initialization.");
99module_param_array(jackpoll_ms, int, NULL, 0444);
100MODULE_PARM_DESC(jackpoll_ms, "Ms between polling for jack events (default = 0, using unsol events only)");
98module_param(single_cmd, bool, 0444); 101module_param(single_cmd, bool, 0444);
99MODULE_PARM_DESC(single_cmd, "Use single command to communicate with codecs " 102MODULE_PARM_DESC(single_cmd, "Use single command to communicate with codecs "
100 "(for debugging only)."); 103 "(for debugging only).");
@@ -1582,6 +1585,22 @@ static void azx_bus_reset(struct hda_bus *bus)
1582 bus->in_reset = 0; 1585 bus->in_reset = 0;
1583} 1586}
1584 1587
1588static int get_jackpoll_interval(struct azx *chip)
1589{
1590 int i = jackpoll_ms[chip->dev_index];
1591 unsigned int j;
1592 if (i == 0)
1593 return 0;
1594 if (i < 50 || i > 60000)
1595 j = 0;
1596 else
1597 j = msecs_to_jiffies(i);
1598 if (j == 0)
1599 snd_printk(KERN_WARNING SFX
1600 "jackpoll_ms value out of range: %d\n", i);
1601 return j;
1602}
1603
1585/* 1604/*
1586 * Codec initialization 1605 * Codec initialization
1587 */ 1606 */
@@ -1666,6 +1685,7 @@ static int DELAYED_INIT_MARK azx_codec_create(struct azx *chip, const char *mode
1666 err = snd_hda_codec_new(chip->bus, c, &codec); 1685 err = snd_hda_codec_new(chip->bus, c, &codec);
1667 if (err < 0) 1686 if (err < 0)
1668 continue; 1687 continue;
1688 codec->jackpoll_interval = get_jackpoll_interval(chip);
1669 codec->beep_mode = chip->beep_mode; 1689 codec->beep_mode = chip->beep_mode;
1670 codecs++; 1690 codecs++;
1671 } 1691 }
diff --git a/sound/pci/hda/hda_jack.c b/sound/pci/hda/hda_jack.c
index 5c690cb873d4..07d5288ce8cf 100644
--- a/sound/pci/hda/hda_jack.c
+++ b/sound/pci/hda/hda_jack.c
@@ -439,3 +439,25 @@ void snd_hda_jack_unsol_event(struct hda_codec *codec, unsigned int res)
439} 439}
440EXPORT_SYMBOL_HDA(snd_hda_jack_unsol_event); 440EXPORT_SYMBOL_HDA(snd_hda_jack_unsol_event);
441 441
442void snd_hda_jack_poll_all(struct hda_codec *codec)
443{
444 struct hda_jack_tbl *jack = codec->jacktbl.list;
445 int i, changes = 0;
446
447 for (i = 0; i < codec->jacktbl.used; i++, jack++) {
448 unsigned int old_sense;
449 if (!jack->nid || !jack->jack_dirty || jack->phantom_jack)
450 continue;
451 old_sense = get_jack_plug_state(jack->pin_sense);
452 jack_detect_update(codec, jack);
453 if (old_sense == get_jack_plug_state(jack->pin_sense))
454 continue;
455 changes = 1;
456 if (jack->callback)
457 jack->callback(codec, jack);
458 }
459 if (changes)
460 snd_hda_jack_report_sync(codec);
461}
462EXPORT_SYMBOL_HDA(snd_hda_jack_poll_all);
463
diff --git a/sound/pci/hda/hda_jack.h b/sound/pci/hda/hda_jack.h
index af8dd4724da5..4487785adf34 100644
--- a/sound/pci/hda/hda_jack.h
+++ b/sound/pci/hda/hda_jack.h
@@ -84,4 +84,6 @@ void snd_hda_jack_report_sync(struct hda_codec *codec);
84 84
85void snd_hda_jack_unsol_event(struct hda_codec *codec, unsigned int res); 85void snd_hda_jack_unsol_event(struct hda_codec *codec, unsigned int res);
86 86
87void snd_hda_jack_poll_all(struct hda_codec *codec);
88
87#endif /* __SOUND_HDA_JACK_H */ 89#endif /* __SOUND_HDA_JACK_H */