lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20241206051358.496832-1-chensong_2000@189.cn>
Date: Fri,  6 Dec 2024 13:13:58 +0800
From: Song Chen <chensong_2000@....cn>
To: krzk@...nel.org,
	lgirdwood@...il.com,
	broonie@...nel.org,
	lee@...nel.org,
	linus.walleij@...aro.org,
	brgl@...ev.pl
Cc: linux-kernel@...r.kernel.org,
	linux-gpio@...r.kernel.org,
	linux-samsung-soc@...r.kernel.org,
	Song Chen <chensong_2000@....cn>
Subject: [PATCH] regulator:s5m8767 Fully convert to GPIO descriptors

This converts s5m8767 regulator driver to use GPIO
descriptors.

Signed-off-by: Song Chen <chensong_2000@....cn>
---
 drivers/regulator/s5m8767.c      | 110 ++++++++++---------------------
 include/linux/mfd/samsung/core.h |   5 +-
 2 files changed, 37 insertions(+), 78 deletions(-)

diff --git a/drivers/regulator/s5m8767.c b/drivers/regulator/s5m8767.c
index d25cd81e3f36..d0b1eed4dfa0 100644
--- a/drivers/regulator/s5m8767.c
+++ b/drivers/regulator/s5m8767.c
@@ -5,7 +5,7 @@
 
 #include <linux/cleanup.h>
 #include <linux/err.h>
-#include <linux/of_gpio.h>
+//#include <linux/of_gpio.h>
 #include <linux/gpio/consumer.h>
 #include <linux/module.h>
 #include <linux/platform_device.h>
@@ -15,6 +15,7 @@
 #include <linux/mfd/samsung/s5m8767.h>
 #include <linux/regulator/of_regulator.h>
 #include <linux/regmap.h>
+#include <linux/of.h>
 
 #define S5M8767_OPMODE_NORMAL_MODE 0x1
 
@@ -23,6 +24,8 @@ struct s5m8767_info {
 	struct sec_pmic_dev *iodev;
 	int num_regulators;
 	struct sec_opmode_data *opmode;
+	struct gpio_desc *buck_gpios[3];
+	struct gpio_desc *buck_ds[3];
 
 	int ramp_delay;
 	bool buck2_ramp;
@@ -35,8 +38,7 @@ struct s5m8767_info {
 	u8 buck2_vol[8];
 	u8 buck3_vol[8];
 	u8 buck4_vol[8];
-	int buck_gpios[3];
-	int buck_ds[3];
+
 	int buck_gpioindex;
 };
 
@@ -272,9 +274,9 @@ static inline int s5m8767_set_high(struct s5m8767_info *s5m8767)
 {
 	int temp_index = s5m8767->buck_gpioindex;
 
-	gpio_set_value(s5m8767->buck_gpios[0], (temp_index >> 2) & 0x1);
-	gpio_set_value(s5m8767->buck_gpios[1], (temp_index >> 1) & 0x1);
-	gpio_set_value(s5m8767->buck_gpios[2], temp_index & 0x1);
+	gpiod_set_value(s5m8767->buck_gpios[0], (temp_index >> 2) & 0x1);
+	gpiod_set_value(s5m8767->buck_gpios[1], (temp_index >> 1) & 0x1);
+	gpiod_set_value(s5m8767->buck_gpios[2], temp_index & 0x1);
 
 	return 0;
 }
@@ -283,9 +285,9 @@ static inline int s5m8767_set_low(struct s5m8767_info *s5m8767)
 {
 	int temp_index = s5m8767->buck_gpioindex;
 
-	gpio_set_value(s5m8767->buck_gpios[2], temp_index & 0x1);
-	gpio_set_value(s5m8767->buck_gpios[1], (temp_index >> 1) & 0x1);
-	gpio_set_value(s5m8767->buck_gpios[0], (temp_index >> 2) & 0x1);
+	gpiod_set_value(s5m8767->buck_gpios[2], temp_index & 0x1);
+	gpiod_set_value(s5m8767->buck_gpios[1], (temp_index >> 1) & 0x1);
+	gpiod_set_value(s5m8767->buck_gpios[0], (temp_index >> 2) & 0x1);
 
 	return 0;
 }
@@ -486,16 +488,22 @@ static int s5m8767_pmic_dt_parse_dvs_gpio(struct sec_pmic_dev *iodev,
 			struct sec_platform_data *pdata,
 			struct device_node *pmic_np)
 {
-	int i, gpio;
+	int i;
+	char label[32];
 
 	for (i = 0; i < 3; i++) {
-		gpio = of_get_named_gpio(pmic_np,
-					"s5m8767,pmic-buck-dvs-gpios", i);
-		if (!gpio_is_valid(gpio)) {
-			dev_err(iodev->dev, "invalid gpio[%d]: %d\n", i, gpio);
+		pdata->buck_gpios[i] = devm_gpiod_get_index(iodev->dev,
+					"s5m8767,pmic-buck-dvs", i, GPIOD_OUT_LOW);
+		if (IS_ERR(pdata->buck_gpios[i])) {
+			dev_err(iodev->dev, "invalid gpio[%d]\n", i);
 			return -EINVAL;
 		}
-		pdata->buck_gpios[i] = gpio;
+
+		/* SET GPIO*/
+		snprintf(label, sizeof(label), "%s%d", "S5M8767 SET", i + 1);
+		gpiod_set_consumer_name(pdata->buck_gpios[i], label);
+		gpiod_direction_output(pdata->buck_gpios[i],
+					(pdata->buck_default_idx >> (2 - i)) & 0x1);
 	}
 	return 0;
 }
@@ -504,16 +512,21 @@ static int s5m8767_pmic_dt_parse_ds_gpio(struct sec_pmic_dev *iodev,
 			struct sec_platform_data *pdata,
 			struct device_node *pmic_np)
 {
-	int i, gpio;
+	int i;
+	char label[32];
 
 	for (i = 0; i < 3; i++) {
-		gpio = of_get_named_gpio(pmic_np,
-					"s5m8767,pmic-buck-ds-gpios", i);
-		if (!gpio_is_valid(gpio)) {
-			dev_err(iodev->dev, "invalid gpio[%d]: %d\n", i, gpio);
+		pdata->buck_ds[i] = devm_gpiod_get_index(iodev->dev,
+					"s5m8767,pmic-buck-ds", i, GPIOD_OUT_LOW);
+		if (IS_ERR(pdata->buck_ds[i])) {
+			dev_err(iodev->dev, "invalid gpio[%d]\n", i);
 			return -EINVAL;
 		}
-		pdata->buck_ds[i] = gpio;
+
+		/* SET GPIO*/
+		snprintf(label, sizeof(label), "%s%d", "S5M8767 DS", i + 2);
+		gpiod_set_consumer_name(pdata->buck_gpios[i], label);
+		gpiod_direction_output(pdata->buck_gpios[i], 0);
 	}
 	return 0;
 }
@@ -785,61 +798,6 @@ static int s5m8767_pmic_probe(struct platform_device *pdev)
 		}
 	}
 
-	if (pdata->buck2_gpiodvs || pdata->buck3_gpiodvs ||
-						pdata->buck4_gpiodvs) {
-
-		if (!gpio_is_valid(pdata->buck_gpios[0]) ||
-			!gpio_is_valid(pdata->buck_gpios[1]) ||
-			!gpio_is_valid(pdata->buck_gpios[2])) {
-			dev_err(&pdev->dev, "GPIO NOT VALID\n");
-			return -EINVAL;
-		}
-
-		ret = devm_gpio_request(&pdev->dev, pdata->buck_gpios[0],
-					"S5M8767 SET1");
-		if (ret)
-			return ret;
-
-		ret = devm_gpio_request(&pdev->dev, pdata->buck_gpios[1],
-					"S5M8767 SET2");
-		if (ret)
-			return ret;
-
-		ret = devm_gpio_request(&pdev->dev, pdata->buck_gpios[2],
-					"S5M8767 SET3");
-		if (ret)
-			return ret;
-
-		/* SET1 GPIO */
-		gpio_direction_output(pdata->buck_gpios[0],
-				(s5m8767->buck_gpioindex >> 2) & 0x1);
-		/* SET2 GPIO */
-		gpio_direction_output(pdata->buck_gpios[1],
-				(s5m8767->buck_gpioindex >> 1) & 0x1);
-		/* SET3 GPIO */
-		gpio_direction_output(pdata->buck_gpios[2],
-				(s5m8767->buck_gpioindex >> 0) & 0x1);
-	}
-
-	ret = devm_gpio_request(&pdev->dev, pdata->buck_ds[0], "S5M8767 DS2");
-	if (ret)
-		return ret;
-
-	ret = devm_gpio_request(&pdev->dev, pdata->buck_ds[1], "S5M8767 DS3");
-	if (ret)
-		return ret;
-
-	ret = devm_gpio_request(&pdev->dev, pdata->buck_ds[2], "S5M8767 DS4");
-	if (ret)
-		return ret;
-
-	/* DS2 GPIO */
-	gpio_direction_output(pdata->buck_ds[0], 0x0);
-	/* DS3 GPIO */
-	gpio_direction_output(pdata->buck_ds[1], 0x0);
-	/* DS4 GPIO */
-	gpio_direction_output(pdata->buck_ds[2], 0x0);
-
 	regmap_update_bits(s5m8767->iodev->regmap_pmic,
 			   S5M8767_REG_BUCK2CTRL, 1 << 1,
 			   (pdata->buck2_gpiodvs) ? (1 << 1) : (0 << 1));
diff --git a/include/linux/mfd/samsung/core.h b/include/linux/mfd/samsung/core.h
index 750274d41fc0..b757f15877a3 100644
--- a/include/linux/mfd/samsung/core.h
+++ b/include/linux/mfd/samsung/core.h
@@ -33,6 +33,7 @@
 #define STEP_12_5_MV		12500
 #define STEP_6_25_MV		6250
 
+#define BULK_GPIO_COUNT		3
 struct gpio_desc;
 
 enum sec_device_type {
@@ -77,10 +78,10 @@ int sec_irq_resume(struct sec_pmic_dev *sec_pmic);
 struct sec_platform_data {
 	struct sec_regulator_data	*regulators;
 	struct sec_opmode_data		*opmode;
+	struct gpio_desc			*buck_gpios[3];
+	struct gpio_desc			*buck_ds[3];
 	int				num_regulators;
 
-	int				buck_gpios[3];
-	int				buck_ds[3];
 	unsigned int			buck2_voltage[8];
 	bool				buck2_gpiodvs;
 	unsigned int			buck3_voltage[8];
-- 
2.25.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ