Create a general function for codec jack detection
diff mbox

Message ID ABFD875FF5FB574BA706497D987D48D701C3ED04@RTITEXTEMP.realtek.com.tw
State New
Headers show

Commit Message

Bard Liao March 14, 2017, 5:54 a.m. UTC
Mark,

There are many codecs with the capability of jack detection. Usually, we
create a jack on machine driver and call an exported codec function,
like rt5670_set_jack_detect, to use the jack and report the jack type.
Could we create a general function for such exported functions?
The benefit is we don't need to use different function names for each
codecs. So we can have a general machine driver with jack detection
function.

Below is what I am thinking the patch will look like.

--

Thanks.

Bard Liao

Comments

Mark Brown April 5, 2017, 5:29 p.m. UTC | #1
On Tue, Mar 14, 2017 at 05:54:35AM +0000, Bard Liao wrote:

> Below is what I am thinking the patch will look like.

It's better to just write the patch for something like this and present
it as such rather than ask to send the patch - it makes things a lot
easier to handle.

> +int snd_soc_codec_set_jack(struct snd_soc_codec *codec,
> +                          struct snd_soc_jack *jack);

We have enough things that have no meaningful configuration to make this
useful I think so OK.

Patch
diff mbox

diff --git a/include/sound/soc.h b/include/sound/soc.h
index cdfb55f..e5a863a 100644
--- a/include/sound/soc.h
+++ b/include/sound/soc.h
@@ -434,6 +434,8 @@  int snd_soc_codec_set_sysclk(struct snd_soc_codec *codec, int clk_id,
                             int source, unsigned int freq, int dir);
 int snd_soc_codec_set_pll(struct snd_soc_codec *codec, int pll_id, int source,
                          unsigned int freq_in, unsigned int freq_out);
+int snd_soc_codec_set_jack(struct snd_soc_codec *codec,
+                          struct snd_soc_jack *jack);

 int snd_soc_register_card(struct snd_soc_card *card);
 int snd_soc_unregister_card(struct snd_soc_card *card);
@@ -913,6 +915,7 @@  struct snd_soc_codec_driver {
                          int clk_id, int source, unsigned int freq, int dir);
        int (*set_pll)(struct snd_soc_codec *codec, int pll_id, int source,
                unsigned int freq_in, unsigned int freq_out);
+       int (*set_jack)(struct snd_soc_codec *codec, struct snd_soc_jack *jack);

        /* codec IO */
        struct regmap *(*get_regmap)(struct device *);
diff --git a/sound/soc/soc-jack.c b/sound/soc/soc-jack.c
index fbaa1bb..ec49577 100644
--- a/sound/soc/soc-jack.c
+++ b/sound/soc/soc-jack.c
@@ -22,6 +22,23 @@ 
 #include <trace/events/asoc.h>

 /**
+ * snd_soc_codec_set_jack - configure codec jack.
+ * @codec: CODEC
+ * @jack: structure to use for the jack
+ *
+ * Configures and enables jack detection function.
+ */
+int snd_soc_codec_set_jack(struct snd_soc_codec *codec,
+       struct snd_soc_jack *jack)
+{
+       if (codec->driver->set_jack)
+               return codec->driver->set_jack(codec, jack);
+       else
+               return -EINVAL;
+}
+EXPORT_SYMBOL_GPL(snd_soc_codec_set_jack);
+
+/**
  * snd_soc_card_jack_new - Create a new jack
  * @card:  ASoC card
  * @id:    an identifying string for this jack