2323#include <sound/jack.h>
2424#include <sound/core.h>
2525
26+ static int jack_types [] = {
27+ SW_HEADPHONE_INSERT ,
28+ SW_MICROPHONE_INSERT ,
29+ SW_LINEOUT_INSERT ,
30+ SW_JACK_PHYSICAL_INSERT ,
31+ };
32+
2633static int snd_jack_dev_free (struct snd_device * device )
2734{
2835 struct snd_jack * jack = device -> device_data ;
@@ -79,6 +86,7 @@ int snd_jack_new(struct snd_card *card, const char *id, int type,
7986{
8087 struct snd_jack * jack ;
8188 int err ;
89+ int i ;
8290 static struct snd_device_ops ops = {
8391 .dev_free = snd_jack_dev_free ,
8492 .dev_register = snd_jack_dev_register ,
@@ -100,18 +108,10 @@ int snd_jack_new(struct snd_card *card, const char *id, int type,
100108
101109 jack -> type = type ;
102110
103- if (type & SND_JACK_HEADPHONE )
104- input_set_capability (jack -> input_dev , EV_SW ,
105- SW_HEADPHONE_INSERT );
106- if (type & SND_JACK_LINEOUT )
107- input_set_capability (jack -> input_dev , EV_SW ,
108- SW_LINEOUT_INSERT );
109- if (type & SND_JACK_MICROPHONE )
110- input_set_capability (jack -> input_dev , EV_SW ,
111- SW_MICROPHONE_INSERT );
112- if (type & SND_JACK_MECHANICAL )
113- input_set_capability (jack -> input_dev , EV_SW ,
114- SW_JACK_PHYSICAL_INSERT );
111+ for (i = 0 ; i < ARRAY_SIZE (jack_types ); i ++ )
112+ if (type & (1 << i ))
113+ input_set_capability (jack -> input_dev , EV_SW ,
114+ jack_types [i ]);
115115
116116 err = snd_device_new (card , SNDRV_DEV_JACK , jack , & ops );
117117 if (err < 0 )
@@ -154,21 +154,17 @@ EXPORT_SYMBOL(snd_jack_set_parent);
154154 */
155155void snd_jack_report (struct snd_jack * jack , int status )
156156{
157+ int i ;
158+
157159 if (!jack )
158160 return ;
159161
160- if (jack -> type & SND_JACK_HEADPHONE )
161- input_report_switch (jack -> input_dev , SW_HEADPHONE_INSERT ,
162- status & SND_JACK_HEADPHONE );
163- if (jack -> type & SND_JACK_LINEOUT )
164- input_report_switch (jack -> input_dev , SW_LINEOUT_INSERT ,
165- status & SND_JACK_LINEOUT );
166- if (jack -> type & SND_JACK_MICROPHONE )
167- input_report_switch (jack -> input_dev , SW_MICROPHONE_INSERT ,
168- status & SND_JACK_MICROPHONE );
169- if (jack -> type & SND_JACK_MECHANICAL )
170- input_report_switch (jack -> input_dev , SW_JACK_PHYSICAL_INSERT ,
171- status & SND_JACK_MECHANICAL );
162+ for (i = 0 ; i < ARRAY_SIZE (jack_types ); i ++ ) {
163+ int testbit = 1 << i ;
164+ if (jack -> type & testbit )
165+ input_report_switch (jack -> input_dev , jack_types [i ],
166+ status & testbit );
167+ }
172168
173169 input_sync (jack -> input_dev );
174170}
0 commit comments