Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 193256
b: refs/heads/master
c: ebb812c
h: refs/heads/master
v: v3
  • Loading branch information
Mark Brown committed Mar 17, 2010
1 parent c3751da commit 5162c45
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 2 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 1c6e555c3a66af29a51690748ca54314e62c16d5
refs/heads/master: ebb812cb8df48e299b3d4ab75cbb0042384ef70d
8 changes: 8 additions & 0 deletions trunk/include/sound/jack.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ enum snd_jack_types {
SND_JACK_MECHANICAL = 0x0008, /* If detected separately */
SND_JACK_VIDEOOUT = 0x0010,
SND_JACK_AVOUT = SND_JACK_LINEOUT | SND_JACK_VIDEOOUT,

/* Kept separate from switches to facilitate implementation */
SND_JACK_BTN_0 = 0x4000,
SND_JACK_BTN_1 = 0x2000,
SND_JACK_BTN_2 = 0x1000,
};

struct snd_jack {
Expand All @@ -50,6 +55,7 @@ struct snd_jack {
int type;
const char *id;
char name[100];
unsigned int key[3]; /* Keep in sync with definitions above */
void *private_data;
void (*private_free)(struct snd_jack *);
};
Expand All @@ -59,6 +65,8 @@ struct snd_jack {
int snd_jack_new(struct snd_card *card, const char *id, int type,
struct snd_jack **jack);
void snd_jack_set_parent(struct snd_jack *jack, struct device *parent);
int snd_jack_set_key(struct snd_jack *jack, enum snd_jack_types type,
int keytype);

void snd_jack_report(struct snd_jack *jack, int status);

Expand Down
60 changes: 59 additions & 1 deletion trunk/sound/core/jack.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ static int snd_jack_dev_register(struct snd_device *device)
{
struct snd_jack *jack = device->device_data;
struct snd_card *card = device->card;
int err;
int err, i;

snprintf(jack->name, sizeof(jack->name), "%s %s",
card->shortname, jack->id);
Expand All @@ -65,6 +65,19 @@ static int snd_jack_dev_register(struct snd_device *device)
if (!jack->input_dev->dev.parent)
jack->input_dev->dev.parent = snd_card_get_device_link(card);

/* Add capabilities for any keys that are enabled */
for (i = 0; i < ARRAY_SIZE(jack->key); i++) {
int testbit = SND_JACK_BTN_0 >> i;

if (!(jack->type & testbit))
continue;

if (!jack->key[i])
jack->key[i] = BTN_0 + i;

input_set_capability(jack->input_dev, EV_KEY, jack->key[i]);
}

err = input_register_device(jack->input_dev);
if (err == 0)
jack->registered = 1;
Expand Down Expand Up @@ -150,6 +163,43 @@ void snd_jack_set_parent(struct snd_jack *jack, struct device *parent)
}
EXPORT_SYMBOL(snd_jack_set_parent);

/**
* snd_jack_set_key - Set a key mapping on a jack
*
* @jack: The jack to configure
* @type: Jack report type for this key
* @keytype: Input layer key type to be reported
*
* Map a SND_JACK_BTN_ button type to an input layer key, allowing
* reporting of keys on accessories via the jack abstraction. If no
* mapping is provided but keys are enabled in the jack type then
* BTN_n numeric buttons will be reported.
*
* Note that this is intended to be use by simple devices with small
* numbers of keys that can be reported. It is also possible to
* access the input device directly - devices with complex input
* capabilities on accessories should consider doing this rather than
* using this abstraction.
*
* This function may only be called prior to registration of the jack.
*/
int snd_jack_set_key(struct snd_jack *jack, enum snd_jack_types type,
int keytype)
{
int key = fls(SND_JACK_BTN_0) - fls(type);

WARN_ON(jack->registered);

if (!keytype || key >= ARRAY_SIZE(jack->key))
return -EINVAL;

jack->type |= type;
jack->key[key] = keytype;

return 0;
}
EXPORT_SYMBOL(snd_jack_set_key);

/**
* snd_jack_report - Report the current status of a jack
*
Expand All @@ -163,6 +213,14 @@ void snd_jack_report(struct snd_jack *jack, int status)
if (!jack)
return;

for (i = 0; i < ARRAY_SIZE(jack->key); i++) {
int testbit = SND_JACK_BTN_0 >> i;

if (jack->type & testbit)
input_report_key(jack->input_dev, jack->key[i],
status & testbit);
}

for (i = 0; i < ARRAY_SIZE(jack_switch_types); i++) {
int testbit = 1 << i;
if (jack->type & testbit)
Expand Down

0 comments on commit 5162c45

Please sign in to comment.