]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
ASoC: rockchip: Make RK3328 GPIO_MUTE control explicit
authorRobin Murphy <robin.murphy@arm.com>
Tue, 18 Feb 2020 21:31:59 +0000 (21:31 +0000)
committerMark Brown <broonie@kernel.org>
Wed, 19 Feb 2020 17:43:21 +0000 (17:43 +0000)
The RK3328 reference design uses an external line driver IC as a buffer
on the analog codec output, enabled by the GPIO_MUTE pin, and such a
configuration is currently assumed in the codec driver's direct poking
of GRF_SOC_CON10 to control the GPIO_MUTE output value. However, some
boards wire up analog audio yet use that pin for some other purpose, so
that assumption doesn't always hold. Update this functionality to rely
on an explicit GPIO descriptor, such that it can be managed at the
board level.

Signed-off-by: Robin Murphy <robin.murphy@arm.com>
Link: https://lore.kernel.org/r/5bc383ed1832f0f5d1dcb3c97ad92fd68e5217e3.1581376744.git.robin.murphy@arm.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/codecs/rk3328_codec.c

index 287c962ba00d7126ef5320682f2501cf7add1b53..115706a55577d13189cd56032bd1950f845a13e9 100644 (file)
@@ -7,6 +7,7 @@
 #include <linux/clk.h>
 #include <linux/delay.h>
 #include <linux/device.h>
+#include <linux/gpio/consumer.h>
 #include <linux/module.h>
 #include <linux/of.h>
 #include <linux/platform_device.h>
@@ -31,7 +32,7 @@
 
 struct rk3328_codec_priv {
        struct regmap *regmap;
-       struct regmap *grf;
+       struct gpio_desc *mute;
        struct clk *mclk;
        struct clk *pclk;
        unsigned int sclk;
@@ -106,16 +107,6 @@ static int rk3328_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
        return 0;
 }
 
-static void rk3328_analog_output(struct rk3328_codec_priv *rk3328, int mute)
-{
-       unsigned int val = BIT(17);
-
-       if (mute)
-               val |= BIT(1);
-
-       regmap_write(rk3328->grf, RK3328_GRF_SOC_CON10, val);
-}
-
 static int rk3328_digital_mute(struct snd_soc_dai *dai, int mute)
 {
        struct rk3328_codec_priv *rk3328 =
@@ -205,7 +196,7 @@ static int rk3328_codec_open_playback(struct rk3328_codec_priv *rk3328)
        }
 
        msleep(rk3328->spk_depop_time);
-       rk3328_analog_output(rk3328, 1);
+       gpiod_set_value(rk3328->mute, 0);
 
        regmap_update_bits(rk3328->regmap, HPOUTL_GAIN_CTRL,
                           HPOUTL_GAIN_MASK, OUT_VOLUME);
@@ -246,7 +237,7 @@ static int rk3328_codec_close_playback(struct rk3328_codec_priv *rk3328)
 {
        size_t i;
 
-       rk3328_analog_output(rk3328, 0);
+       gpiod_set_value(rk3328->mute, 1);
 
        regmap_update_bits(rk3328->regmap, HPOUTL_GAIN_CTRL,
                           HPOUTL_GAIN_MASK, 0);
@@ -446,7 +437,6 @@ static int rk3328_platform_probe(struct platform_device *pdev)
                dev_err(&pdev->dev, "missing 'rockchip,grf'\n");
                return PTR_ERR(grf);
        }
-       rk3328->grf = grf;
        /* enable i2s_acodec_en */
        regmap_write(grf, RK3328_GRF_SOC_CON2,
                     (BIT(14) << 16 | BIT(14)));
@@ -458,7 +448,18 @@ static int rk3328_platform_probe(struct platform_device *pdev)
                rk3328->spk_depop_time = 200;
        }
 
-       rk3328_analog_output(rk3328, 0);
+       rk3328->mute = gpiod_get_optional(&pdev->dev, "mute", GPIOD_OUT_HIGH);
+       if (IS_ERR(rk3328->mute))
+               return PTR_ERR(rk3328->mute);
+       /*
+        * Rock64 is the only supported platform to have widely relied on
+        * this; if we do happen to come across an old DTB, just leave the
+        * external mute forced off.
+        */
+       if (!rk3328->mute && of_machine_is_compatible("pine64,rock64")) {
+               dev_warn(&pdev->dev, "assuming implicit control of GPIO_MUTE; update devicetree if possible\n");
+               regmap_write(grf, RK3328_GRF_SOC_CON10, BIT(17) | BIT(1));
+       }
 
        rk3328->mclk = devm_clk_get(&pdev->dev, "mclk");
        if (IS_ERR(rk3328->mclk))