[alsa-devel] Create a general function for codec jack detection

Bard Liao bardliao at realtek.com
Tue Mar 14 06:54:35 CET 2017


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.

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
--

Thanks.

Bard Liao


More information about the Alsa-devel mailing list