aboutsummaryrefslogtreecommitdiffstats
path: root/sound/core/jack.c
diff options
context:
space:
mode:
authorMark Brown <broonie@opensource.wolfsonmicro.com>2009-01-03 11:56:56 -0500
committerMark Brown <broonie@opensource.wolfsonmicro.com>2009-01-03 12:02:21 -0500
commitbd8a71a7b0f50da9350d202d325c3926ffd6b189 (patch)
tree8eb108c7a2eeb432dff8c7caad4589ca1f36cecb /sound/core/jack.c
parent6a94cb73064c952255336cc57731904174b2c58f (diff)
ALSA: Reduce boilerplate for new jack types
Use a lookup table rather than explicit code to map input subsystem jack types into ASoC ones, implemented as suggested by Takashi Iwai. Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'sound/core/jack.c')
-rw-r--r--sound/core/jack.c44
1 files changed, 20 insertions, 24 deletions
diff --git a/sound/core/jack.c b/sound/core/jack.c
index dd4a12dc09a..b2da10c9916 100644
--- a/sound/core/jack.c
+++ b/sound/core/jack.c
@@ -23,6 +23,13 @@
23#include <sound/jack.h> 23#include <sound/jack.h>
24#include <sound/core.h> 24#include <sound/core.h>
25 25
26static int jack_types[] = {
27 SW_HEADPHONE_INSERT,
28 SW_MICROPHONE_INSERT,
29 SW_LINEOUT_INSERT,
30 SW_JACK_PHYSICAL_INSERT,
31};
32
26static int snd_jack_dev_free(struct snd_device *device) 33static int snd_jack_dev_free(struct snd_device *device)
27{ 34{
28 struct snd_jack *jack = device->device_data; 35 struct snd_jack *jack = device->device_data;
@@ -79,6 +86,7 @@ int snd_jack_new(struct snd_card *card, const char *id, int type,
79{ 86{
80 struct snd_jack *jack; 87 struct snd_jack *jack;
81 int err; 88 int err;
89 int i;
82 static struct snd_device_ops ops = { 90 static struct snd_device_ops ops = {
83 .dev_free = snd_jack_dev_free, 91 .dev_free = snd_jack_dev_free,
84 .dev_register = snd_jack_dev_register, 92 .dev_register = snd_jack_dev_register,
@@ -100,18 +108,10 @@ int snd_jack_new(struct snd_card *card, const char *id, int type,
100 108
101 jack->type = type; 109 jack->type = type;
102 110
103 if (type & SND_JACK_HEADPHONE) 111 for (i = 0; i < ARRAY_SIZE(jack_types); i++)
104 input_set_capability(jack->input_dev, EV_SW, 112 if (type & (1 << i))
105 SW_HEADPHONE_INSERT); 113 input_set_capability(jack->input_dev, EV_SW,
106 if (type & SND_JACK_LINEOUT) 114 jack_types[i]);
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);
115 115
116 err = snd_device_new(card, SNDRV_DEV_JACK, jack, &ops); 116 err = snd_device_new(card, SNDRV_DEV_JACK, jack, &ops);
117 if (err < 0) 117 if (err < 0)
@@ -154,21 +154,17 @@ EXPORT_SYMBOL(snd_jack_set_parent);
154 */ 154 */
155void snd_jack_report(struct snd_jack *jack, int status) 155void snd_jack_report(struct snd_jack *jack, int status)
156{ 156{
157 int i;
158
157 if (!jack) 159 if (!jack)
158 return; 160 return;
159 161
160 if (jack->type & SND_JACK_HEADPHONE) 162 for (i = 0; i < ARRAY_SIZE(jack_types); i++) {
161 input_report_switch(jack->input_dev, SW_HEADPHONE_INSERT, 163 int testbit = 1 << i;
162 status & SND_JACK_HEADPHONE); 164 if (jack->type & testbit)
163 if (jack->type & SND_JACK_LINEOUT) 165 input_report_switch(jack->input_dev, jack_types[i],
164 input_report_switch(jack->input_dev, SW_LINEOUT_INSERT, 166 status & testbit);
165 status & SND_JACK_LINEOUT); 167 }
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);
172 168
173 input_sync(jack->input_dev); 169 input_sync(jack->input_dev);
174} 170}