From 8a2cd6180f8fa00111843c2f4a4f4361995358e0 Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Wed, 7 Jan 2009 17:31:10 +0000 Subject: ASoC: Add jack reporting interface This patch adds a jack reporting interface to ASoC. This wraps the ALSA core jack detection functionality and provides integration with DAPM to automatically update the power state of pins based on the jack state. Since embedded platforms can have multiple detecton methods used for a single jack (eg, separate microphone and headphone detection) the report function allows specification of which bits are being updated on a given report. The expected usage is that machine drivers will create jack objects and then configure jack detection methods to update that jack. Signed-off-by: Mark Brown --- include/sound/soc.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'include/sound/soc.h') diff --git a/include/sound/soc.h b/include/sound/soc.h index 9b930d34211..9c3ef6a3e9f 100644 --- a/include/sound/soc.h +++ b/include/sound/soc.h @@ -154,6 +154,8 @@ enum snd_soc_bias_level { SND_SOC_BIAS_OFF, }; +struct snd_jack; +struct snd_soc_card; struct snd_soc_device; struct snd_soc_pcm_stream; struct snd_soc_ops; @@ -164,6 +166,8 @@ struct snd_soc_platform; struct snd_soc_codec; struct soc_enum; struct snd_soc_ac97_ops; +struct snd_soc_jack; +struct snd_soc_jack_pin; typedef int (*hw_write_t)(void *,const char* ,int); typedef int (*hw_read_t)(void *,char* ,int); @@ -184,6 +188,13 @@ int snd_soc_init_card(struct snd_soc_device *socdev); int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream, const struct snd_pcm_hardware *hw); +/* Jack reporting */ +int snd_soc_jack_new(struct snd_soc_card *card, const char *id, int type, + struct snd_soc_jack *jack); +void snd_soc_jack_report(struct snd_soc_jack *jack, int status, int mask); +int snd_soc_jack_add_pins(struct snd_soc_jack *jack, int count, + struct snd_soc_jack_pin *pins); + /* codec IO */ #define snd_soc_read(codec, reg) codec->read(codec, reg) #define snd_soc_write(codec, reg, value) codec->write(codec, reg, value) @@ -239,6 +250,27 @@ int snd_soc_get_volsw_s8(struct snd_kcontrol *kcontrol, int snd_soc_put_volsw_s8(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol); +/** + * struct snd_soc_jack_pin - Describes a pin to update based on jack detection + * + * @pin: name of the pin to update + * @mask: bits to check for in reported jack status + * @invert: if non-zero then pin is enabled when status is not reported + */ +struct snd_soc_jack_pin { + struct list_head list; + const char *pin; + int mask; + bool invert; +}; + +struct snd_soc_jack { + struct snd_jack *jack; + struct snd_soc_card *card; + struct list_head pins; + int status; +}; + /* SoC PCM stream information */ struct snd_soc_pcm_stream { char *stream_name; -- cgit v1.2.3 From 3e8e1952e3a3dd59b11233a532ca68e6471742d9 Mon Sep 17 00:00:00 2001 From: Ian Molton Date: Fri, 9 Jan 2009 00:23:21 +0000 Subject: ASoC: cleanup duplicated code. Many codec drivers were implementing cookie-cutter copies of the function that adds kcontrols to the codec. This patch moves this code to a common function snd_soc_add_controls() in soc-core.c and updates all drivers using copies of this function to use the new common version. [Edited to raise priority of error log message and document parameters. -- broonie] Signed-off-by: Ian Molton Signed-off-by: Mark Brown --- include/sound/soc.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include/sound/soc.h') diff --git a/include/sound/soc.h b/include/sound/soc.h index 9c3ef6a3e9f..9d5a0362a05 100644 --- a/include/sound/soc.h +++ b/include/sound/soc.h @@ -214,6 +214,8 @@ void snd_soc_free_ac97_codec(struct snd_soc_codec *codec); */ struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template, void *data, char *long_name); +int snd_soc_add_controls(struct snd_soc_codec *codec, + const struct snd_kcontrol_new *controls, int num_controls); int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo); int snd_soc_info_enum_ext(struct snd_kcontrol *kcontrol, -- cgit v1.2.3 From 6627a653bceb3a54e55e5cdc478ec5b8d5c9cc44 Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Fri, 23 Jan 2009 22:55:23 +0000 Subject: ASoC: Push the codec runtime storage into the card structure This is a further stage on the road to refactoring away the ASoC platform device. Signed-off-by: Mark Brown --- include/sound/soc.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'include/sound/soc.h') diff --git a/include/sound/soc.h b/include/sound/soc.h index 7039343e8a7..0e773526416 100644 --- a/include/sound/soc.h +++ b/include/sound/soc.h @@ -418,6 +418,8 @@ struct snd_soc_card { struct snd_soc_device *socdev; + struct snd_soc_codec *codec; + struct snd_soc_platform *platform; struct delayed_work delayed_work; struct work_struct deferred_resume_work; @@ -427,7 +429,6 @@ struct snd_soc_card { struct snd_soc_device { struct device *dev; struct snd_soc_card *card; - struct snd_soc_codec *codec; struct snd_soc_codec_device *codec_dev; void *codec_data; }; -- cgit v1.2.3 From ec67624d33d5639bcc6ee6918cb1fc0bd1bac3a8 Mon Sep 17 00:00:00 2001 From: "Lopez Cruz, Misael" Date: Tue, 3 Mar 2009 15:25:04 -0600 Subject: ASoC: Add GPIO support for jack reporting interface Add GPIO support to jack reporting framework in ASoC using gpiolib calls. The gpio support exports two new functions: snd_soc_jack_add_gpios and snd_soc_jack_free_gpios. Client drivers using gpio feature must pass an array of jack_gpio pins belonging to a specific jack to the snd_soc_jack_add_gpios function. The framework will request the gpios, set the data direction and request irq. The framework will update power status of related jack_pins when an event on the gpio pins comes according to the reporting bits defined for each gpio. All gpio resources allocated when adding jack_gpio pins can be released using snd_soc_jack_free_gpios function. Signed-off-by: Misael Lopez Cruz Signed-off-by: Mark Brown --- include/sound/soc.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'include/sound/soc.h') diff --git a/include/sound/soc.h b/include/sound/soc.h index 0e773526416..a40bc6f316f 100644 --- a/include/sound/soc.h +++ b/include/sound/soc.h @@ -16,6 +16,8 @@ #include #include #include +#include +#include #include #include #include @@ -168,6 +170,9 @@ struct soc_enum; struct snd_soc_ac97_ops; struct snd_soc_jack; struct snd_soc_jack_pin; +#ifdef CONFIG_GPIOLIB +struct snd_soc_jack_gpio; +#endif typedef int (*hw_write_t)(void *,const char* ,int); typedef int (*hw_read_t)(void *,char* ,int); @@ -194,6 +199,12 @@ int snd_soc_jack_new(struct snd_soc_card *card, const char *id, int type, void snd_soc_jack_report(struct snd_soc_jack *jack, int status, int mask); int snd_soc_jack_add_pins(struct snd_soc_jack *jack, int count, struct snd_soc_jack_pin *pins); +#ifdef CONFIG_GPIOLIB +int snd_soc_jack_add_gpios(struct snd_soc_jack *jack, int count, + struct snd_soc_jack_gpio *gpios); +void snd_soc_jack_free_gpios(struct snd_soc_jack *jack, int count, + struct snd_soc_jack_gpio *gpios); +#endif /* codec IO */ #define snd_soc_read(codec, reg) codec->read(codec, reg) @@ -264,6 +275,27 @@ struct snd_soc_jack_pin { bool invert; }; +/** + * struct snd_soc_jack_gpio - Describes a gpio pin for jack detection + * + * @gpio: gpio number + * @name: gpio name + * @report: value to report when jack detected + * @invert: report presence in low state + * @debouce_time: debouce time in ms + */ +#ifdef CONFIG_GPIOLIB +struct snd_soc_jack_gpio { + unsigned int gpio; + const char *name; + int report; + int invert; + int debounce_time; + struct snd_soc_jack *jack; + struct work_struct work; +}; +#endif + struct snd_soc_jack { struct snd_jack *jack; struct snd_soc_card *card; -- cgit v1.2.3