]> git.karo-electronics.de Git - linux-beck.git/commitdiff
ASoC: cs53l30: Add MUTE pin control support via GPIO
authorNicolin Chen <nicoleotsuka@gmail.com>
Tue, 21 Jun 2016 23:50:13 +0000 (16:50 -0700)
committerMark Brown <broonie@kernel.org>
Thu, 23 Jun 2016 10:35:52 +0000 (11:35 +0100)
The codec chip has a physical MUTE pin to let users control it via
GPIO. So this patch add a mute control support to the driver.

Signed-off-by: Nicolin Chen <nicoleotsuka@gmail.com>
Acked-by: Paul Handrigan <Paul.Handrigan@cirrus.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
Documentation/devicetree/bindings/sound/cs53l30.txt
sound/soc/codecs/cs53l30.c
sound/soc/codecs/cs53l30.h

index 18d6b99e0a2d7439433ff066a0031c8734e682cd..4dbfb8274cd9b5b86261655678fe2cff24f20bd4 100644 (file)
@@ -13,6 +13,10 @@ Optional properties:
 
   - reset-gpios : a GPIO spec for the reset pin.
 
+  - mute-gpios : a GPIO spec for the MUTE pin. The active state can be either
+                GPIO_ACTIVE_HIGH or GPIO_ACTIVE_LOW, which would be handled
+                by the driver automatically.
+
   - cirrus,micbias-lvl : Set the output voltage level on the MICBIAS Pin.
                         0 = Hi-Z
                         1 = 1.80 V
index b0a64a19a04594b41b80985e77c7897b979267b1..5988b5c672fe76c013d8d33955d8dc6f09c79054 100644 (file)
@@ -35,6 +35,7 @@ struct cs53l30_private {
        struct regulator_bulk_data      supplies[CS53L30_NUM_SUPPLIES];
        struct regmap                   *regmap;
        struct gpio_desc                *reset_gpio;
+       struct gpio_desc                *mute_gpio;
        struct clk                      *mclk;
        bool                            use_sdout2;
        u32                             mclk_rate;
@@ -833,6 +834,16 @@ static int cs53l30_set_dai_tdm_slot(struct snd_soc_dai *dai,
        return 0;
 }
 
+static int cs53l30_mute_stream(struct snd_soc_dai *dai, int mute, int stream)
+{
+       struct cs53l30_private *priv = snd_soc_codec_get_drvdata(dai->codec);
+
+       if (priv->mute_gpio)
+               gpiod_set_value_cansleep(priv->mute_gpio, mute);
+
+       return 0;
+}
+
 /* SNDRV_PCM_RATE_KNOT -> 12000, 24000 Hz, limit with constraint list */
 #define CS53L30_RATES (SNDRV_PCM_RATE_8000_48000 | SNDRV_PCM_RATE_KNOT)
 
@@ -846,6 +857,7 @@ static const struct snd_soc_dai_ops cs53l30_ops = {
        .set_sysclk = cs53l30_set_sysclk,
        .set_tristate = cs53l30_set_tristate,
        .set_tdm_slot = cs53l30_set_dai_tdm_slot,
+       .mute_stream = cs53l30_mute_stream,
 };
 
 static struct snd_soc_dai_driver cs53l30_dai = {
@@ -991,6 +1003,24 @@ static int cs53l30_i2c_probe(struct i2c_client *client,
                cs53l30->mclk = NULL;
        }
 
+       /* Fetch the MUTE control */
+       cs53l30->mute_gpio = devm_gpiod_get_optional(dev, "mute",
+                                                    GPIOD_OUT_HIGH);
+       if (IS_ERR(cs53l30->mute_gpio)) {
+               ret = PTR_ERR(cs53l30->mute_gpio);
+               goto error;
+       }
+
+       if (cs53l30->mute_gpio) {
+               /* Enable MUTE controls via MUTE pin */
+               regmap_write(cs53l30->regmap, CS53L30_MUTEP_CTL1,
+                            CS53L30_MUTEP_CTL1_MUTEALL);
+               /* Flip the polarity of MUTE pin */
+               if (gpiod_is_active_low(cs53l30->mute_gpio))
+                       regmap_update_bits(cs53l30->regmap, CS53L30_MUTEP_CTL2,
+                                          CS53L30_MUTE_PIN_POLARITY, 0);
+       }
+
        if (!of_property_read_u8(np, "cirrus,micbias-lvl", &val))
                regmap_update_bits(cs53l30->regmap, CS53L30_MICBIAS_CTL,
                                   CS53L30_MIC_BIAS_CTRL_MASK, val);
index 0dd4afbb5c6424a2767e1cca37158971d0dbd045..5e39da568749790afbf9eb687cd8570454e760d9 100644 (file)
 #define CS53L30_MUTE_MB_ALL_PDN_MASK   (1 << CS53L30_MUTE_MB_ALL_PDN_SHIFT)
 #define CS53L30_MUTE_MB_ALL_PDN                (1 << CS53L30_MUTE_MB_ALL_PDN_SHIFT)
 
+#define CS53L30_MUTEP_CTL1_MUTEALL     (0xdf)
 #define CS53L30_MUTEP_CTL1_DEFAULT     (0)
 
 /* R32 (0x20) CS53L30_MUTEP_CTL2 - MUTE Pin Control 2 */