ASoC: wm8960: Support headphone jack detection function
authorShengjiu Wang <shengjiu.wang@nxp.com>
Wed, 3 Jun 2020 10:26:53 +0000 (18:26 +0800)
committerMark Brown <broonie@kernel.org>
Mon, 15 Jun 2020 19:58:33 +0000 (20:58 +0100)
Add two platform variables for headphone jack detection.
"hp_cfg" is for configuration of heaphone jack detection.
"gpio_cfg" is for configuration of gpio, the gpio is used
for plug & unplug interrupt on SoC.

Signed-off-by: Shengjiu Wang <shengjiu.wang@nxp.com>
Link: https://lore.kernel.org/r/1591180013-12416-2-git-send-email-shengjiu.wang@nxp.com
Signed-off-by: Mark Brown <broonie@kernel.org>
include/sound/wm8960.h
sound/soc/codecs/wm8960.c

index d22e848..275fd5b 100644 (file)
@@ -16,6 +16,23 @@ struct wm8960_data {
        bool capless;  /* Headphone outputs configured in capless mode */
 
        bool shared_lrclk;  /* DAC and ADC LRCLKs are wired together */
+
+       /*
+        * Setup for headphone detection
+        *
+        * hp_cfg[0]: HPSEL[1:0] of R48 (Additional Control 4)
+        * hp_cfg[1]: {HPSWEN:HPSWPOL} of R24 (Additional Control 2).
+        * hp_cfg[2]: {TOCLKSEL:TOEN} of R23 (Additional Control 1).
+        */
+       u32 hp_cfg[3];
+
+       /*
+        * Setup for gpio configuration
+        *
+        * gpio_cfg[0]: ALRCGPIO of R9 (Audio interface)
+        * gpio_cfg[1]: {GPIOPOL:GPIOSEL[2:0]} of R48 (Additional Control 4).
+        */
+       u32 gpio_cfg[2];
 };
 
 #endif
index 6cf0f66..2f7f049 100644 (file)
@@ -1389,6 +1389,12 @@ static void wm8960_set_pdata_from_of(struct i2c_client *i2c,
 
        if (of_property_read_bool(np, "wlf,shared-lrclk"))
                pdata->shared_lrclk = true;
+
+       of_property_read_u32_array(np, "wlf,gpio-cfg", pdata->gpio_cfg,
+                                  ARRAY_SIZE(pdata->gpio_cfg));
+
+       of_property_read_u32_array(np, "wlf,hp-cfg", pdata->hp_cfg,
+                                  ARRAY_SIZE(pdata->hp_cfg));
 }
 
 static int wm8960_i2c_probe(struct i2c_client *i2c,
@@ -1446,6 +1452,20 @@ static int wm8960_i2c_probe(struct i2c_client *i2c,
        regmap_update_bits(wm8960->regmap, WM8960_LOUT2, 0x100, 0x100);
        regmap_update_bits(wm8960->regmap, WM8960_ROUT2, 0x100, 0x100);
 
+       /* ADCLRC pin configured as GPIO. */
+       regmap_update_bits(wm8960->regmap, WM8960_IFACE2, 1 << 6,
+                          wm8960->pdata.gpio_cfg[0] << 6);
+       regmap_update_bits(wm8960->regmap, WM8960_ADDCTL4, 0xF << 4,
+                          wm8960->pdata.gpio_cfg[1] << 4);
+
+       /* Enable headphone jack detect */
+       regmap_update_bits(wm8960->regmap, WM8960_ADDCTL4, 3 << 2,
+                          wm8960->pdata.hp_cfg[0] << 2);
+       regmap_update_bits(wm8960->regmap, WM8960_ADDCTL2, 3 << 5,
+                          wm8960->pdata.hp_cfg[1] << 5);
+       regmap_update_bits(wm8960->regmap, WM8960_ADDCTL1, 3,
+                          wm8960->pdata.hp_cfg[2]);
+
        i2c_set_clientdata(i2c, wm8960);
 
        ret = devm_snd_soc_register_component(&i2c->dev,