From bd8a71a7b0f50da9350d202d325c3926ffd6b189 Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Sat, 3 Jan 2009 16:56:56 +0000 Subject: 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 --- sound/core/jack.c | 44 ++++++++++++++++++++------------------------ 1 file changed, 20 insertions(+), 24 deletions(-) (limited to 'sound/core') diff --git a/sound/core/jack.c b/sound/core/jack.c index dd4a12dc09aa..b2da10c9916a 100644 --- a/sound/core/jack.c +++ b/sound/core/jack.c @@ -23,6 +23,13 @@ #include #include +static int jack_types[] = { + SW_HEADPHONE_INSERT, + SW_MICROPHONE_INSERT, + SW_LINEOUT_INSERT, + SW_JACK_PHYSICAL_INSERT, +}; + static int snd_jack_dev_free(struct snd_device *device) { struct snd_jack *jack = device->device_data; @@ -79,6 +86,7 @@ int snd_jack_new(struct snd_card *card, const char *id, int type, { struct snd_jack *jack; int err; + int i; static struct snd_device_ops ops = { .dev_free = snd_jack_dev_free, .dev_register = snd_jack_dev_register, @@ -100,18 +108,10 @@ int snd_jack_new(struct snd_card *card, const char *id, int type, jack->type = type; - if (type & SND_JACK_HEADPHONE) - input_set_capability(jack->input_dev, EV_SW, - SW_HEADPHONE_INSERT); - if (type & SND_JACK_LINEOUT) - input_set_capability(jack->input_dev, EV_SW, - SW_LINEOUT_INSERT); - if (type & SND_JACK_MICROPHONE) - input_set_capability(jack->input_dev, EV_SW, - SW_MICROPHONE_INSERT); - if (type & SND_JACK_MECHANICAL) - input_set_capability(jack->input_dev, EV_SW, - SW_JACK_PHYSICAL_INSERT); + for (i = 0; i < ARRAY_SIZE(jack_types); i++) + if (type & (1 << i)) + input_set_capability(jack->input_dev, EV_SW, + jack_types[i]); err = snd_device_new(card, SNDRV_DEV_JACK, jack, &ops); if (err < 0) @@ -154,21 +154,17 @@ EXPORT_SYMBOL(snd_jack_set_parent); */ void snd_jack_report(struct snd_jack *jack, int status) { + int i; + if (!jack) return; - if (jack->type & SND_JACK_HEADPHONE) - input_report_switch(jack->input_dev, SW_HEADPHONE_INSERT, - status & SND_JACK_HEADPHONE); - if (jack->type & SND_JACK_LINEOUT) - input_report_switch(jack->input_dev, SW_LINEOUT_INSERT, - status & SND_JACK_LINEOUT); - if (jack->type & SND_JACK_MICROPHONE) - input_report_switch(jack->input_dev, SW_MICROPHONE_INSERT, - status & SND_JACK_MICROPHONE); - if (jack->type & SND_JACK_MECHANICAL) - input_report_switch(jack->input_dev, SW_JACK_PHYSICAL_INSERT, - status & SND_JACK_MECHANICAL); + for (i = 0; i < ARRAY_SIZE(jack_types); i++) { + int testbit = 1 << i; + if (jack->type & testbit) + input_report_switch(jack->input_dev, jack_types[i], + status & testbit); + } input_sync(jack->input_dev); } -- cgit v1.2.3-59-g8ed1b From d506fc322ec2af04fc47be83d796a1c9e1a16022 Mon Sep 17 00:00:00 2001 From: Jani Nikula Date: Wed, 7 Jan 2009 11:54:25 +0200 Subject: ALSA: Add support for video out to the jack reporting API Add support for reporting new jack types SND_JACK_VIDEOOUT and SND_JACK_AVOUT (a combination of LINEOUT and VIDEOOUT) to the jack reporting API. Also add the corresponding SW_VIDEOOUT_INSERT switch to the input system header. Signed-off-by: Jani Nikula Signed-off-by: Mark Brown --- include/linux/input.h | 1 + include/sound/jack.h | 2 ++ sound/core/jack.c | 1 + 3 files changed, 4 insertions(+) (limited to 'sound/core') diff --git a/include/linux/input.h b/include/linux/input.h index 9a6355f74db2..adc13322d1d2 100644 --- a/include/linux/input.h +++ b/include/linux/input.h @@ -661,6 +661,7 @@ struct input_absinfo { #define SW_DOCK 0x05 /* set = plugged into dock */ #define SW_LINEOUT_INSERT 0x06 /* set = inserted */ #define SW_JACK_PHYSICAL_INSERT 0x07 /* set = mechanical switch set */ +#define SW_VIDEOOUT_INSERT 0x08 /* set = inserted */ #define SW_MAX 0x0f #define SW_CNT (SW_MAX+1) diff --git a/include/sound/jack.h b/include/sound/jack.h index 85266a2f5c6f..6b013c6f6a04 100644 --- a/include/sound/jack.h +++ b/include/sound/jack.h @@ -40,6 +40,8 @@ enum snd_jack_types { SND_JACK_HEADSET = SND_JACK_HEADPHONE | SND_JACK_MICROPHONE, SND_JACK_LINEOUT = 0x0004, SND_JACK_MECHANICAL = 0x0008, /* If detected separately */ + SND_JACK_VIDEOOUT = 0x0010, + SND_JACK_AVOUT = SND_JACK_LINEOUT | SND_JACK_VIDEOOUT, }; struct snd_jack { diff --git a/sound/core/jack.c b/sound/core/jack.c index b2da10c9916a..43b10d6e522b 100644 --- a/sound/core/jack.c +++ b/sound/core/jack.c @@ -28,6 +28,7 @@ static int jack_types[] = { SW_MICROPHONE_INSERT, SW_LINEOUT_INSERT, SW_JACK_PHYSICAL_INSERT, + SW_VIDEOOUT_INSERT, }; static int snd_jack_dev_free(struct snd_device *device) -- cgit v1.2.3-59-g8ed1b