diff mbox series

[v1,4/7] ASoC: wm8731: Factor our MCLK and mutex initialisation

Message ID 20220325153121.1598494-5-broonie@kernel.org
State Accepted
Commit 8875d104af6c237bfedb47309afd938984a3c05b
Headers show
Series ASoC: wm8731: Overhaul of the driver | expand

Commit Message

Mark Brown March 25, 2022, 3:31 p.m. UTC
The code for initialising the MCLK and mutex is identical in the I2C and SPI
probe functions so just move this out into wm8731_init().

Signed-off-by: Mark Brown <broonie@kernel.org>
---
 sound/soc/codecs/wm8731.c | 44 +++++++++++++--------------------------
 1 file changed, 14 insertions(+), 30 deletions(-)

Comments

Charles Keepax March 28, 2022, 9:40 a.m. UTC | #1
On Fri, Mar 25, 2022 at 03:31:18PM +0000, Mark Brown wrote:
> The code for initialising the MCLK and mutex is identical in the I2C and SPI
> probe functions so just move this out into wm8731_init().
> 
> Signed-off-by: Mark Brown <broonie@kernel.org>
> ---

Acked-by: Charles Keepax <ckeepax@opensource.cirrus.com>

Thanks,
Charles
diff mbox series

Patch

diff --git a/sound/soc/codecs/wm8731.c b/sound/soc/codecs/wm8731.c
index 334332bb5f22..43730aba11fe 100644
--- a/sound/soc/codecs/wm8731.c
+++ b/sound/soc/codecs/wm8731.c
@@ -588,6 +588,20 @@  static int wm8731_init(struct device *dev, struct wm8731_priv *wm8731)
 {
 	int ret = 0, i;
 
+	wm8731->mclk = devm_clk_get(dev, "mclk");
+	if (IS_ERR(wm8731->mclk)) {
+		ret = PTR_ERR(wm8731->mclk);
+		if (ret == -ENOENT) {
+			wm8731->mclk = NULL;
+			dev_warn(dev, "Assuming static MCLK\n");
+		} else {
+			dev_err(dev, "Failed to get MCLK: %d\n", ret);
+			return ret;
+		}
+	}
+
+	mutex_init(&wm8731->lock);
+
 	for (i = 0; i < ARRAY_SIZE(wm8731->supplies); i++)
 		wm8731->supplies[i].supply = wm8731_supply_names[i];
 
@@ -670,21 +684,6 @@  static int wm8731_spi_probe(struct spi_device *spi)
 	if (wm8731 == NULL)
 		return -ENOMEM;
 
-	wm8731->mclk = devm_clk_get(&spi->dev, "mclk");
-	if (IS_ERR(wm8731->mclk)) {
-		ret = PTR_ERR(wm8731->mclk);
-		if (ret == -ENOENT) {
-			wm8731->mclk = NULL;
-			dev_warn(&spi->dev, "Assuming static MCLK\n");
-		} else {
-			dev_err(&spi->dev, "Failed to get MCLK: %d\n",
-				ret);
-			return ret;
-		}
-	}
-
-	mutex_init(&wm8731->lock);
-
 	spi_set_drvdata(spi, wm8731);
 
 	wm8731->regmap = devm_regmap_init_spi(spi, &wm8731_regmap);
@@ -719,21 +718,6 @@  static int wm8731_i2c_probe(struct i2c_client *i2c,
 	if (wm8731 == NULL)
 		return -ENOMEM;
 
-	wm8731->mclk = devm_clk_get(&i2c->dev, "mclk");
-	if (IS_ERR(wm8731->mclk)) {
-		ret = PTR_ERR(wm8731->mclk);
-		if (ret == -ENOENT) {
-			wm8731->mclk = NULL;
-			dev_warn(&i2c->dev, "Assuming static MCLK\n");
-		} else {
-			dev_err(&i2c->dev, "Failed to get MCLK: %d\n",
-				ret);
-			return ret;
-		}
-	}
-
-	mutex_init(&wm8731->lock);
-
 	i2c_set_clientdata(i2c, wm8731);
 
 	wm8731->regmap = devm_regmap_init_i2c(i2c, &wm8731_regmap);