diff options
Diffstat (limited to 'sound/pci/hda/hda_jack.c')
-rw-r--r-- | sound/pci/hda/hda_jack.c | 56 |
1 files changed, 8 insertions, 48 deletions
diff --git a/sound/pci/hda/hda_jack.c b/sound/pci/hda/hda_jack.c index 8829d5c83fec..a2ab52b27265 100644 --- a/sound/pci/hda/hda_jack.c +++ b/sound/pci/hda/hda_jack.c | |||
@@ -97,12 +97,8 @@ static void jack_detect_update(struct hda_codec *codec, | |||
97 | struct hda_jack_tbl *jack) | 97 | struct hda_jack_tbl *jack) |
98 | { | 98 | { |
99 | if (jack->jack_dirty || !jack->jack_detect) { | 99 | if (jack->jack_dirty || !jack->jack_detect) { |
100 | unsigned int val = read_pin_sense(codec, jack->nid); | 100 | jack->pin_sense = read_pin_sense(codec, jack->nid); |
101 | jack->jack_dirty = 0; | 101 | jack->jack_dirty = 0; |
102 | if (val != jack->pin_sense) { | ||
103 | jack->need_notify = 1; | ||
104 | jack->pin_sense = val; | ||
105 | } | ||
106 | } | 102 | } |
107 | } | 103 | } |
108 | 104 | ||
@@ -142,6 +138,8 @@ u32 snd_hda_pin_sense(struct hda_codec *codec, hda_nid_t nid) | |||
142 | } | 138 | } |
143 | EXPORT_SYMBOL_HDA(snd_hda_pin_sense); | 139 | EXPORT_SYMBOL_HDA(snd_hda_pin_sense); |
144 | 140 | ||
141 | #define get_jack_plug_state(sense) !!(sense & AC_PINSENSE_PRESENCE) | ||
142 | |||
145 | /** | 143 | /** |
146 | * snd_hda_jack_detect - query pin Presence Detect status | 144 | * snd_hda_jack_detect - query pin Presence Detect status |
147 | * @codec: the CODEC to sense | 145 | * @codec: the CODEC to sense |
@@ -152,7 +150,7 @@ EXPORT_SYMBOL_HDA(snd_hda_pin_sense); | |||
152 | int snd_hda_jack_detect(struct hda_codec *codec, hda_nid_t nid) | 150 | int snd_hda_jack_detect(struct hda_codec *codec, hda_nid_t nid) |
153 | { | 151 | { |
154 | u32 sense = snd_hda_pin_sense(codec, nid); | 152 | u32 sense = snd_hda_pin_sense(codec, nid); |
155 | return !!(sense & AC_PINSENSE_PRESENCE); | 153 | return get_jack_plug_state(sense); |
156 | } | 154 | } |
157 | EXPORT_SYMBOL_HDA(snd_hda_jack_detect); | 155 | EXPORT_SYMBOL_HDA(snd_hda_jack_detect); |
158 | 156 | ||
@@ -176,58 +174,23 @@ int snd_hda_jack_detect_enable(struct hda_codec *codec, hda_nid_t nid, | |||
176 | } | 174 | } |
177 | EXPORT_SYMBOL_HDA(snd_hda_jack_detect_enable); | 175 | EXPORT_SYMBOL_HDA(snd_hda_jack_detect_enable); |
178 | 176 | ||
179 | /* queue the notification when needed */ | ||
180 | static void jack_detect_report(struct hda_codec *codec, | ||
181 | struct hda_jack_tbl *jack) | ||
182 | { | ||
183 | jack_detect_update(codec, jack); | ||
184 | if (jack->need_notify) { | ||
185 | snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE, | ||
186 | &jack->kctl->id); | ||
187 | jack->need_notify = 0; | ||
188 | } | ||
189 | } | ||
190 | |||
191 | /** | 177 | /** |
192 | * snd_hda_jack_report_sync - sync the states of all jacks and report if changed | 178 | * snd_hda_jack_report_sync - sync the states of all jacks and report if changed |
193 | */ | 179 | */ |
194 | void snd_hda_jack_report_sync(struct hda_codec *codec) | 180 | void snd_hda_jack_report_sync(struct hda_codec *codec) |
195 | { | 181 | { |
196 | struct hda_jack_tbl *jack = codec->jacktbl.list; | 182 | struct hda_jack_tbl *jack = codec->jacktbl.list; |
197 | int i; | 183 | int i, state; |
198 | 184 | ||
199 | for (i = 0; i < codec->jacktbl.used; i++, jack++) | 185 | for (i = 0; i < codec->jacktbl.used; i++, jack++) |
200 | if (jack->nid) { | 186 | if (jack->nid) { |
201 | jack_detect_update(codec, jack); | 187 | jack_detect_update(codec, jack); |
202 | jack_detect_report(codec, jack); | 188 | state = get_jack_plug_state(jack->pin_sense); |
189 | snd_kctl_jack_notify(codec->bus->card, jack->kctl, state); | ||
203 | } | 190 | } |
204 | } | 191 | } |
205 | EXPORT_SYMBOL_HDA(snd_hda_jack_report_sync); | 192 | EXPORT_SYMBOL_HDA(snd_hda_jack_report_sync); |
206 | 193 | ||
207 | /* | ||
208 | * jack-detection kcontrols | ||
209 | */ | ||
210 | |||
211 | #define jack_detect_kctl_info snd_ctl_boolean_mono_info | ||
212 | |||
213 | static int jack_detect_kctl_get(struct snd_kcontrol *kcontrol, | ||
214 | struct snd_ctl_elem_value *ucontrol) | ||
215 | { | ||
216 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | ||
217 | hda_nid_t nid = kcontrol->private_value; | ||
218 | |||
219 | ucontrol->value.integer.value[0] = snd_hda_jack_detect(codec, nid); | ||
220 | return 0; | ||
221 | } | ||
222 | |||
223 | static struct snd_kcontrol_new jack_detect_kctl = { | ||
224 | /* name is filled later */ | ||
225 | .iface = SNDRV_CTL_ELEM_IFACE_CARD, | ||
226 | .access = SNDRV_CTL_ELEM_ACCESS_READ, | ||
227 | .info = jack_detect_kctl_info, | ||
228 | .get = jack_detect_kctl_get, | ||
229 | }; | ||
230 | |||
231 | /** | 194 | /** |
232 | * snd_hda_jack_add_kctl - Add a kctl for the given pin | 195 | * snd_hda_jack_add_kctl - Add a kctl for the given pin |
233 | * | 196 | * |
@@ -245,12 +208,9 @@ int snd_hda_jack_add_kctl(struct hda_codec *codec, hda_nid_t nid, | |||
245 | return 0; | 208 | return 0; |
246 | if (jack->kctl) | 209 | if (jack->kctl) |
247 | return 0; /* already created */ | 210 | return 0; /* already created */ |
248 | kctl = snd_ctl_new1(&jack_detect_kctl, codec); | 211 | kctl = snd_kctl_jack_new(name, idx, codec); |
249 | if (!kctl) | 212 | if (!kctl) |
250 | return -ENOMEM; | 213 | return -ENOMEM; |
251 | snprintf(kctl->id.name, sizeof(kctl->id.name), "%s Jack", name); | ||
252 | kctl->id.index = idx; | ||
253 | kctl->private_value = nid; | ||
254 | if (snd_hda_ctl_add(codec, nid, kctl) < 0) | 214 | if (snd_hda_ctl_add(codec, nid, kctl) < 0) |
255 | return -ENOMEM; | 215 | return -ENOMEM; |
256 | jack->kctl = kctl; | 216 | jack->kctl = kctl; |