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>
This commit is contained in:
parent
6a94cb7306
commit
bd8a71a7b0
|
@ -30,6 +30,9 @@ struct input_dev;
|
||||||
/**
|
/**
|
||||||
* Jack types which can be reported. These values are used as a
|
* Jack types which can be reported. These values are used as a
|
||||||
* bitmask.
|
* bitmask.
|
||||||
|
*
|
||||||
|
* Note that this must be kept in sync with the lookup table in
|
||||||
|
* sound/core/jack.c.
|
||||||
*/
|
*/
|
||||||
enum snd_jack_types {
|
enum snd_jack_types {
|
||||||
SND_JACK_HEADPHONE = 0x0001,
|
SND_JACK_HEADPHONE = 0x0001,
|
||||||
|
|
|
@ -23,6 +23,13 @@
|
||||||
#include <sound/jack.h>
|
#include <sound/jack.h>
|
||||||
#include <sound/core.h>
|
#include <sound/core.h>
|
||||||
|
|
||||||
|
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)
|
static int snd_jack_dev_free(struct snd_device *device)
|
||||||
{
|
{
|
||||||
struct snd_jack *jack = device->device_data;
|
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;
|
struct snd_jack *jack;
|
||||||
int err;
|
int err;
|
||||||
|
int i;
|
||||||
static struct snd_device_ops ops = {
|
static struct snd_device_ops ops = {
|
||||||
.dev_free = snd_jack_dev_free,
|
.dev_free = snd_jack_dev_free,
|
||||||
.dev_register = snd_jack_dev_register,
|
.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;
|
jack->type = type;
|
||||||
|
|
||||||
if (type & SND_JACK_HEADPHONE)
|
for (i = 0; i < ARRAY_SIZE(jack_types); i++)
|
||||||
input_set_capability(jack->input_dev, EV_SW,
|
if (type & (1 << i))
|
||||||
SW_HEADPHONE_INSERT);
|
input_set_capability(jack->input_dev, EV_SW,
|
||||||
if (type & SND_JACK_LINEOUT)
|
jack_types[i]);
|
||||||
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);
|
|
||||||
|
|
||||||
err = snd_device_new(card, SNDRV_DEV_JACK, jack, &ops);
|
err = snd_device_new(card, SNDRV_DEV_JACK, jack, &ops);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
|
@ -154,21 +154,17 @@ EXPORT_SYMBOL(snd_jack_set_parent);
|
||||||
*/
|
*/
|
||||||
void snd_jack_report(struct snd_jack *jack, int status)
|
void snd_jack_report(struct snd_jack *jack, int status)
|
||||||
{
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
if (!jack)
|
if (!jack)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (jack->type & SND_JACK_HEADPHONE)
|
for (i = 0; i < ARRAY_SIZE(jack_types); i++) {
|
||||||
input_report_switch(jack->input_dev, SW_HEADPHONE_INSERT,
|
int testbit = 1 << i;
|
||||||
status & SND_JACK_HEADPHONE);
|
if (jack->type & testbit)
|
||||||
if (jack->type & SND_JACK_LINEOUT)
|
input_report_switch(jack->input_dev, jack_types[i],
|
||||||
input_report_switch(jack->input_dev, SW_LINEOUT_INSERT,
|
status & testbit);
|
||||||
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);
|
|
||||||
|
|
||||||
input_sync(jack->input_dev);
|
input_sync(jack->input_dev);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue