Hi Krzysztof,
Only a question needs to be clarified, the rest of your comments is
accepted and will be fixed accordingly.
Many thanks and best regards,
Song
在 2024/12/6 16:33, Krzysztof Kozlowski 写道:
On 06/12/2024 06:13, Song Chen wrote:
This converts s5m8767 regulator driver to use GPIO
descriptors.
Please wrap commit message according to Linux coding style / submission
process (neither too early nor over the limit):
https://elixir.bootlin.com/linux/v6.4-rc1/source/Documentation/process/submitting-patches.rst#L597
Subject: missing : after s5m prefix.
Signed-off-by: Song Chen <chensong_2000@xxxxxx>
---
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>
Some development code was left.
#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];
Don't move them.
+
No need.
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);
Why not printing error msg? This should be also return dev_err_probe
return -EINVAL;
}
- pdata->buck_gpios[i] = gpio;
+
+ /* SET GPIO*/
What is a SET GPIO?
+ snprintf(label, sizeof(label), "%s%d", "S5M8767 SET", i + 1);
Why using "SET" as name, not the actual name it is used for? Buck DVS?
from below snippets:
s5m8767_pmic_probe of drivers/regulator/s5m8767.c
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");
and arch/arm/boot/dts/samsung/exynos5250-spring.dts
s5m8767,pmic-buck-dvs-gpios = <&gpd1 0 GPIO_ACTIVE_LOW>, /* DVS1 */
<&gpd1 1 GPIO_ACTIVE_LOW>, /* DVS2 */
<&gpd1 2 GPIO_ACTIVE_LOW>; /* DVS3 */
s5m8767,pmic-buck-ds-gpios = <&gpx2 3 GPIO_ACTIVE_LOW>, /* SET1 */
<&gpx2 4 GPIO_ACTIVE_LOW>, /* SET2 */
<&gpx2 5 GPIO_ACTIVE_LOW>; /* SET3 */
+ gpiod_set_consumer_name(pdata->buck_gpios[i], label);
+ gpiod_direction_output(pdata->buck_gpios[i],
+ (pdata->buck_default_idx >> (2 - i)) & 0x1);
This is not an equivalent code. You set values for GPIOs 0-1 even if
requesting GPIO 2 fails.
On which board did you test it?
You are right ,it's not equivalent with original code, i will fix it.
but i have a question here:
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;
if it fails to request buck_gpios[2] after successfully requests
buck_gpios[0] and buck_gpios[1], the probe fails as well, should it call
gpiod_put to return gpio resource?
}
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
Where do you use ot?
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];
Don't move the code.
unsigned int buck2_voltage[8];
bool buck2_gpiodvs;
unsigned int buck3_voltage[8];
Best regards,
Krzysztof