[alsa-devel] [PATCH/RFC 1/2] Add jack reporting API for ALSA

Takashi Iwai tiwai at suse.de
Fri May 30 10:15:43 CEST 2008


At Thu, 29 May 2008 22:09:04 +0100,
Mark Brown wrote:
> 
> Currently very few systems provide information about jack status to user
> space, even though many have hardware facilities to do detection. Those
> systems that do use an input device with the existing SW_HEADPHONE_INSERT
> switch type to do so, often independently of ALSA.
> 
> This patch introduces a standard method for representing jacks to user
> space into ALSA. It allows drivers to register jacks for a sound card with
> the input subsystem, binding the input device to the card to help user
> space associate the input devices with their sound cards. The created
> input devices are named in the form "card longname jack" where jack is
> provided by the driver when allocating a jack.
> 
> The existing user space API with SW_HEADPHONE_INSERT is preserved.

The implementation looks good, simple enough.

> diff --git a/sound/core/Kconfig b/sound/core/Kconfig
> index 829ca38..4e8e52d 100644
> --- a/sound/core/Kconfig
> +++ b/sound/core/Kconfig
> @@ -16,6 +16,11 @@ config SND_RAWMIDI
>  	tristate
>  	depends on SND
>  
> +config SND_JACK
> +	tristate
> +	depends on SND
> +	depends on INPUT

If you suppose to "select" SND_JACK, depends have no meaning.

> diff --git a/sound/core/Makefile b/sound/core/Makefile
> index 5a01c76..e1cb6d6 100644
> --- a/sound/core/Makefile
> +++ b/sound/core/Makefile
> @@ -20,9 +20,11 @@ snd-rawmidi-objs  := rawmidi.o
>  snd-timer-objs    := timer.o
>  snd-rtctimer-objs := rtctimer.o
>  snd-hwdep-objs    := hwdep.o
> +snd-jack-objs     := jack.o
>  
>  obj-$(CONFIG_SND) 		+= snd.o
>  obj-$(CONFIG_SND_HWDEP)		+= snd-hwdep.o
> +obj-$(CONFIG_SND_JACK)		+= snd-jack.o

The code is small, and I don't see a big merit to make it a module.

> +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;
> +
> +	snprintf(jack->name, sizeof(jack->name), "%s %s",
> +		 card->longname, jack->id);

The longname field could be sometimes really too long and verbose.
I guess shortname would match better.

> +int snd_jack_new(struct snd_card *card, const char *id, int type,
> +		 struct snd_jack **jjack)
(snip)
> +	jack->input_dev->phys = "ALSA";
> +	jack->input_dev->dev.parent = card->dev;

The card->dev pointer might not be initialized always at this stage.
You should check rather at register.

Also, someone may want to pass a different device pointer for this.
Passing struct device * to snd_jack_new would be an alternative.


thanks,

Takashi


More information about the Alsa-devel mailing list