From a3db6c055e80c3ccc138f537647ed3da4831aecf Mon Sep 17 00:00:00 2001
From: Ondrej Jirman <megi@xff.cz>
Date: Thu, 7 Sep 2023 22:58:22 +0200
Subject: [PATCH 340/463] ASoC: codecs: rt5640: Add support for power supplies

Signed-off-by: Ondrej Jirman <megi@xff.cz>
---
 sound/soc/codecs/rt5640.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/sound/soc/codecs/rt5640.c b/sound/soc/codecs/rt5640.c
index 96e687401653d..15070e9372e99 100644
--- a/sound/soc/codecs/rt5640.c
+++ b/sound/soc/codecs/rt5640.c
@@ -17,6 +17,7 @@
 #include <linux/regmap.h>
 #include <linux/of.h>
 #include <linux/platform_device.h>
+#include <linux/regulator/consumer.h>
 #include <linux/spi/spi.h>
 #include <linux/acpi.h>
 #include <sound/core.h>
@@ -38,6 +39,13 @@
 
 #define RT5640_PR_BASE (RT5640_PR_RANGE_BASE + (0 * RT5640_PR_SPACING))
 
+static const char *const rt5640_supply_names[] = {
+	"avdd",
+	"cpvdd",
+	"dbvdd",
+	"spkvdd",
+};
+
 static const struct regmap_range_cfg rt5640_ranges[] = {
 	{ .name = "PR", .range_min = RT5640_PR_BASE,
 	  .range_max = RT5640_PR_BASE + 0xb4,
@@ -3025,6 +3033,14 @@ static int rt5640_i2c_probe(struct i2c_client *i2c)
 		msleep(400);
 	}
 
+	ret = devm_regulator_bulk_get_enable(&i2c->dev,
+					     ARRAY_SIZE(rt5640_supply_names),
+					     rt5640_supply_names);
+	if (ret) {
+		dev_err(&i2c->dev, "Failed to request supplies: %d\n", ret);
+		return ret;
+	}
+
 	rt5640->regmap = devm_regmap_init_i2c(i2c, &rt5640_regmap);
 	if (IS_ERR(rt5640->regmap)) {
 		ret = PTR_ERR(rt5640->regmap);
-- 
2.46.0

