Skip to contentSkip to conversation

platform/x86: int3472: don't use gpiod_toggle_active_low()

PATCH In review Hans de Goede 2 participants 9 messages Oct 4, 2023 – Oct 5, 2023

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v3 cover platform/x86: int3472: don't use gpiod_toggle_active_low()

Hi All,

Here is v3 of Bartosz' and my "don't use gpiod_toggle_active_low()" series.

New in v3:
- Correctly preserve Bartosz as author for 2 of the patches
- Add Reviewed-by tags from Mika and Andy
- Fix wrong size of gpio lookup table allocation in new skl_int3472_gpiod_get_from_temp_lookup() helper. There must also be an empty terminating lookup, so 2 entries must be allocated.

New in v2:
- Rework to deal with ACPI path vs gpiod_lookup.key differences:
acpi_get_handle(path) -> acpi_fetch_acpi_dev(handle) -> acpi_dev_name(adev)

Regards,

Hans

Bartosz Golaszewski (2):
platform/x86: int3472: Add new

    skl_int3472_gpiod_get_from_temp_lookup() helper

gpio: acpi: remove acpi_get_and_request_gpiod()

Hans de Goede (3):
platform/x86: int3472: Add new skl_int3472_fill_gpiod_lookup() helper platform/x86: int3472: Stop using gpiod_toggle_active_low() platform/x86: int3472: Switch to devm_get_gpiod()

 drivers/gpio/gpiolib-acpi.c                   |  28 -----
 .../x86/intel/int3472/clk_and_regulator.c     |  54 ++--------
 drivers/platform/x86/intel/int3472/common.h   |   7 +-
 drivers/platform/x86/intel/int3472/discrete.c | 101 ++++++++++++++----
 drivers/platform/x86/intel/int3472/led.c      |  24 +----
 include/linux/gpio/consumer.h                 |   8 --
 6 files changed, 93 insertions(+), 129 deletions(-)
Signature · 1 line
2.41.0
#1 lore raw

PATCH v3 1/5 platform/x86: int3472: Add new skl_int3472_fill_gpiod_lookup() helper

Add a new skl_int3472_fill_gpiod_lookup() helper.

This is a preparation patch for removing usage of the deprecated gpiod_toggle_active_low() and acpi_get_and_request_gpiod() functions.

---
 drivers/platform/x86/intel/int3472/discrete.c | 32 +++++++++++++------
 1 file changed, 22 insertions(+), 10 deletions(-)
drivers/platform/x86/intel/int3472/discrete.c +22 -10
index e33c2d75975c..351ecf047944 100644
@@ -52,21 +52,15 @@ static void skl_int3472_log_sensor_module_name(struct int3472_discrete_device *i
 	}
 }
 
-static int skl_int3472_map_gpio_to_sensor(struct int3472_discrete_device *int3472,
-					  struct acpi_resource_gpio *agpio,
-					  const char *func, u32 polarity)
+static int skl_int3472_fill_gpiod_lookup(struct gpiod_lookup *table_entry,
+					 struct acpi_resource_gpio *agpio,
+					 const char *func, u32 polarity)
 {
 	char *path = agpio->resource_source.string_ptr;
-	struct gpiod_lookup *table_entry;
 	struct acpi_device *adev;
 	acpi_handle handle;
 	acpi_status status;
 
-	if (int3472->n_sensor_gpios >= INT3472_MAX_SENSOR_GPIOS) {
-		dev_warn(int3472->dev, "Too many GPIOs mapped\n");
-		return -EINVAL;
-	}
-
 	status = acpi_get_handle(NULL, path, &handle);
 	if (ACPI_FAILURE(status))
 		return -EINVAL;
@@ -75,13 +69,31 @@ static int skl_int3472_map_gpio_to_sensor(struct int3472_discrete_device *int347
 	if (!adev)
 		return -ENODEV;
 
-	table_entry = &int3472->gpios.table[int3472->n_sensor_gpios];
 	table_entry->key = acpi_dev_name(adev);
 	table_entry->chip_hwnum = agpio->pin_table[0];
 	table_entry->con_id = func;
 	table_entry->idx = 0;
 	table_entry->flags = polarity;
 
+	return 0;
+}
+
+static int skl_int3472_map_gpio_to_sensor(struct int3472_discrete_device *int3472,
+					  struct acpi_resource_gpio *agpio,
+					  const char *func, u32 polarity)
+{
+	int ret;
+
+	if (int3472->n_sensor_gpios >= INT3472_MAX_SENSOR_GPIOS) {
+		dev_warn(int3472->dev, "Too many GPIOs mapped\n");
+		return -EINVAL;
+	}
+
+	ret = skl_int3472_fill_gpiod_lookup(&int3472->gpios.table[int3472->n_sensor_gpios],
+					    agpio, func, polarity);
+	if (ret)
+		return ret;
+
 	int3472->n_sensor_gpios++;
 
 	return 0;
Signature · 1 line
2.41.0
Reviewed-by on v3 1/5
#2 lore raw

Re: [PATCH v3 1/5] platform/x86: int3472: Add new skl_int3472_fill_gpiod_lookup() helper

Quoted 75 lines · Hans de Goede

Add a new skl_int3472_fill_gpiod_lookup() helper.

This is a preparation patch for removing usage of the deprecated gpiod_toggle_active_low() and acpi_get_and_request_gpiod() functions.

---
 drivers/platform/x86/intel/int3472/discrete.c | 32 +++++++++++++------
 1 file changed, 22 insertions(+), 10 deletions(-)
drivers/platform/x86/intel/int3472/discrete.c +22 -11
index e33c2d75975c..351ecf047944 100644
@@ -52,21 +52,15 @@ static void skl_int3472_log_sensor_module_name(struct int3472_discrete_device *i
        }
 }
 
-static int skl_int3472_map_gpio_to_sensor(struct int3472_discrete_device *int3472,
-                                         struct acpi_resource_gpio *agpio,
-                                         const char *func, u32 polarity)
+static int skl_int3472_fill_gpiod_lookup(struct gpiod_lookup *table_entry,
+                                        struct acpi_resource_gpio *agpio,
+                                        const char *func, u32 polarity)
 {
        char *path = agpio->resource_source.string_ptr;
-       struct gpiod_lookup *table_entry;
        struct acpi_device *adev;
        acpi_handle handle;
        acpi_status status;
 
-       if (int3472->n_sensor_gpios >= INT3472_MAX_SENSOR_GPIOS) {
-               dev_warn(int3472->dev, "Too many GPIOs mapped\n");
-               return -EINVAL;
-       }
-
        status = acpi_get_handle(NULL, path, &handle);
        if (ACPI_FAILURE(status))
                return -EINVAL;
@@ -75,13 +69,31 @@ static int skl_int3472_map_gpio_to_sensor(struct int3472_discrete_device *int347
        if (!adev)
                return -ENODEV;
 
-       table_entry = &int3472->gpios.table[int3472->n_sensor_gpios];
        table_entry->key = acpi_dev_name(adev);
        table_entry->chip_hwnum = agpio->pin_table[0];
        table_entry->con_id = func;
        table_entry->idx = 0;
        table_entry->flags = polarity;
 
+       return 0;
+}
+
+static int skl_int3472_map_gpio_to_sensor(struct int3472_discrete_device *int3472,
+                                         struct acpi_resource_gpio *agpio,
+                                         const char *func, u32 polarity)
+{
+       int ret;
+
+       if (int3472->n_sensor_gpios >= INT3472_MAX_SENSOR_GPIOS) {
+               dev_warn(int3472->dev, "Too many GPIOs mapped\n");
+               return -EINVAL;
+       }
+
+       ret = skl_int3472_fill_gpiod_lookup(&int3472->gpios.table[int3472->n_sensor_gpios],
+                                           agpio, func, polarity);
+       if (ret)
+               return ret;
+
        int3472->n_sensor_gpios++;
 
        return 0;
--
Quoted 2 lines

2.41.0

#3 lore raw

PATCH v3 2/5 platform/x86: int3472: Add new skl_int3472_gpiod_get_from_temp_lookup() helper

In reply to Hans de Goede

From: Bartosz Golaszewski <[email protected]>

Add a new skl_int3472_gpiod_get_from_temp_lookup() helper.

This is a preparation patch for removing usage of the deprecated gpiod_toggle_active_low() and acpi_get_and_request_gpiod() functions.

[[email protected]] use the new skl_int3472_fill_gpiod_lookup() helper

---
Changes in v3:
- Fix wrong size of gpio lookup table allocation. There must also be an empty terminating lookup, so 2 entries must be allocated.

Changes in v2:
- Use the new skl_int3472_fill_gpiod_lookup() helper.

---
 drivers/platform/x86/intel/int3472/discrete.c | 26 +++++++++++++++++++
 1 file changed, 26 insertions(+)
drivers/platform/x86/intel/int3472/discrete.c +26 -0
index 351ecf047944..b69ef63f75ab 100644
@@ -99,6 +99,32 @@ static int skl_int3472_map_gpio_to_sensor(struct int3472_discrete_device *int347
 	return 0;
 }
 
+/* This should *really* only be used when there's no other way... */
+static struct gpio_desc *
+skl_int3472_gpiod_get_from_temp_lookup(struct int3472_discrete_device *int3472,
+				       struct acpi_resource_gpio *agpio,
+				       const char *func, u32 polarity)
+{
+	struct gpio_desc *desc;
+	int ret;
+
+	struct gpiod_lookup_table *lookup __free(kfree) =
+			kzalloc(struct_size(lookup, table, 2), GFP_KERNEL);
+	if (!lookup)
+		return ERR_PTR(-ENOMEM);
+
+	lookup->dev_id = dev_name(int3472->dev);
+	ret = skl_int3472_fill_gpiod_lookup(&lookup->table[0], agpio, func, polarity);
+	if (ret)
+		return ERR_PTR(ret);
+
+	gpiod_add_lookup_table(lookup);
+	desc = gpiod_get(int3472->dev, func, GPIOD_OUT_LOW);
+	gpiod_remove_lookup_table(lookup);
+
+	return desc;
+}
+
 static void int3472_get_func_and_polarity(u8 type, const char **func, u32 *polarity)
 {
 	switch (type) {
Signature · 1 line
2.41.0
#4 lore raw

PATCH v3 3/5 platform/x86: int3472: Stop using gpiod_toggle_active_low()

In reply to Hans de Goede

Use the new skl_int3472_gpiod_get_from_temp_lookup() helper to get a gpio to pass to register_gpio_clock(), skl_int3472_register_regulator() and skl_int3472_register_pled().

This removes all use of the deprecated gpiod_toggle_active_low() and acpi_get_and_request_gpiod() functions.

---
 .../x86/intel/int3472/clk_and_regulator.c     | 31 ++-----------
 drivers/platform/x86/intel/int3472/common.h   |  7 ++-
 drivers/platform/x86/intel/int3472/discrete.c | 43 +++++++++++++------
 drivers/platform/x86/intel/int3472/led.c      | 17 ++------
 4 files changed, 40 insertions(+), 58 deletions(-)
drivers/platform/x86/intel/int3472/clk_and_regulator.c +4 -27
index ef4b3141efcd..459f96c04ca1 100644
@@ -162,9 +162,8 @@ int skl_int3472_register_dsm_clock(struct int3472_discrete_device *int3472)
 }
 
 int skl_int3472_register_gpio_clock(struct int3472_discrete_device *int3472,
-				    struct acpi_resource_gpio *agpio, u32 polarity)
+				    struct gpio_desc *gpio)
 {
-	char *path = agpio->resource_source.string_ptr;
 	struct clk_init_data init = {
 		.ops = &skl_int3472_clock_ops,
 		.flags = CLK_GET_RATE_NOCACHE,
@@ -174,19 +173,7 @@ int skl_int3472_register_gpio_clock(struct int3472_discrete_device *int3472,
 	if (int3472->clock.cl)
 		return -EBUSY;
 
-	int3472->clock.ena_gpio = acpi_get_and_request_gpiod(path, agpio->pin_table[0],
-							     "int3472,clk-enable");
-	if (IS_ERR(int3472->clock.ena_gpio)) {
-		ret = PTR_ERR(int3472->clock.ena_gpio);
-		int3472->clock.ena_gpio = NULL;
-		return dev_err_probe(int3472->dev, ret, "getting clk-enable GPIO\n");
-	}
-
-	if (polarity == GPIO_ACTIVE_LOW)
-		gpiod_toggle_active_low(int3472->clock.ena_gpio);
-
-	/* Ensure the pin is in output mode and non-active state */
-	gpiod_direction_output(int3472->clock.ena_gpio, 0);
+	int3472->clock.ena_gpio = gpio;
 
 	init.name = kasprintf(GFP_KERNEL, "%s-clk",
 			      acpi_dev_name(int3472->adev));
@@ -273,9 +260,8 @@ static const struct dmi_system_id skl_int3472_regulator_second_sensor[] = {
 };
 
 int skl_int3472_register_regulator(struct int3472_discrete_device *int3472,
-				   struct acpi_resource_gpio *agpio)
+				   struct gpio_desc *gpio)
 {
-	char *path = agpio->resource_source.string_ptr;
 	struct regulator_init_data init_data = { };
 	struct regulator_config cfg = { };
 	const char *second_sensor = NULL;
@@ -314,16 +300,7 @@ int skl_int3472_register_regulator(struct int3472_discrete_device *int3472,
 						int3472->regulator.supply_name,
 						&int3472_gpio_regulator_ops);
 
-	int3472->regulator.gpio = acpi_get_and_request_gpiod(path, agpio->pin_table[0],
-							     "int3472,regulator");
-	if (IS_ERR(int3472->regulator.gpio)) {
-		ret = PTR_ERR(int3472->regulator.gpio);
-		int3472->regulator.gpio = NULL;
-		return dev_err_probe(int3472->dev, ret, "getting regulator GPIO\n");
-	}
-
-	/* Ensure the pin is in output mode and non-active state */
-	gpiod_direction_output(int3472->regulator.gpio, 0);
+	int3472->regulator.gpio = gpio;
 
 	cfg.dev = &int3472->adev->dev;
 	cfg.init_data = &init_data;
drivers/platform/x86/intel/int3472/common.h +3 -4
index 9f29baa13860..145dec66df64 100644
@@ -117,16 +117,15 @@ int skl_int3472_get_sensor_adev_and_name(struct device *dev,
 					 const char **name_ret);
 
 int skl_int3472_register_gpio_clock(struct int3472_discrete_device *int3472,
-				    struct acpi_resource_gpio *agpio, u32 polarity);
+				    struct gpio_desc *gpio);
 int skl_int3472_register_dsm_clock(struct int3472_discrete_device *int3472);
 void skl_int3472_unregister_clock(struct int3472_discrete_device *int3472);
 
 int skl_int3472_register_regulator(struct int3472_discrete_device *int3472,
-				   struct acpi_resource_gpio *agpio);
+				   struct gpio_desc *gpio);
 void skl_int3472_unregister_regulator(struct int3472_discrete_device *int3472);
 
-int skl_int3472_register_pled(struct int3472_discrete_device *int3472,
-			      struct acpi_resource_gpio *agpio, u32 polarity);
+int skl_int3472_register_pled(struct int3472_discrete_device *int3472, struct gpio_desc *gpio);
 void skl_int3472_unregister_pled(struct int3472_discrete_device *int3472);
 
 #endif
drivers/platform/x86/intel/int3472/discrete.c +30 -13

58 lines not on this page · raw message

drivers/platform/x86/intel/int3472/led.c +3 -14
index bca1ce7d0d0c..476cd637fc51 100644
@@ -16,26 +16,15 @@ static int int3472_pled_set(struct led_classdev *led_cdev,
 	return 0;
 }
 
-int skl_int3472_register_pled(struct int3472_discrete_device *int3472,
-			      struct acpi_resource_gpio *agpio, u32 polarity)
+int skl_int3472_register_pled(struct int3472_discrete_device *int3472, struct gpio_desc *gpio)
 {
-	char *p, *path = agpio->resource_source.string_ptr;
+	char *p;
 	int ret;
 
 	if (int3472->pled.classdev.dev)
 		return -EBUSY;
 
-	int3472->pled.gpio = acpi_get_and_request_gpiod(path, agpio->pin_table[0],
-							     "int3472,privacy-led");
-	if (IS_ERR(int3472->pled.gpio))
-		return dev_err_probe(int3472->dev, PTR_ERR(int3472->pled.gpio),
-				     "getting privacy LED GPIO\n");
-
-	if (polarity == GPIO_ACTIVE_LOW)
-		gpiod_toggle_active_low(int3472->pled.gpio);
-
-	/* Ensure the pin is in output mode and non-active state */
-	gpiod_direction_output(int3472->pled.gpio, 0);
+	int3472->pled.gpio = gpio;
 
 	/* Generate the name, replacing the ':' in the ACPI devname with '_' */
 	snprintf(int3472->pled.name, sizeof(int3472->pled.name),
Signature · 1 line
2.41.0
Reviewed-by on v3 3/5
#5 lore raw

Re: [PATCH v3 3/5] platform/x86: int3472: Stop using gpiod_toggle_active_low()

Quoted 136 lines · Hans de Goede

Use the new skl_int3472_gpiod_get_from_temp_lookup() helper to get a gpio to pass to register_gpio_clock(), skl_int3472_register_regulator() and skl_int3472_register_pled().

This removes all use of the deprecated gpiod_toggle_active_low() and acpi_get_and_request_gpiod() functions.

---
 .../x86/intel/int3472/clk_and_regulator.c     | 31 ++-----------
 drivers/platform/x86/intel/int3472/common.h   |  7 ++-
 drivers/platform/x86/intel/int3472/discrete.c | 43 +++++++++++++------
 drivers/platform/x86/intel/int3472/led.c      | 17 ++------
 4 files changed, 40 insertions(+), 58 deletions(-)
drivers/platform/x86/intel/int3472/clk_and_regulator.c +4 -27
index ef4b3141efcd..459f96c04ca1 100644
@@ -162,9 +162,8 @@ int skl_int3472_register_dsm_clock(struct int3472_discrete_device *int3472)
 }
 
 int skl_int3472_register_gpio_clock(struct int3472_discrete_device *int3472,
-                                   struct acpi_resource_gpio *agpio, u32 polarity)
+                                   struct gpio_desc *gpio)
 {
-       char *path = agpio->resource_source.string_ptr;
        struct clk_init_data init = {
                .ops = &skl_int3472_clock_ops,
                .flags = CLK_GET_RATE_NOCACHE,
@@ -174,19 +173,7 @@ int skl_int3472_register_gpio_clock(struct int3472_discrete_device *int3472,
        if (int3472->clock.cl)
                return -EBUSY;
 
-       int3472->clock.ena_gpio = acpi_get_and_request_gpiod(path, agpio->pin_table[0],
-                                                            "int3472,clk-enable");
-       if (IS_ERR(int3472->clock.ena_gpio)) {
-               ret = PTR_ERR(int3472->clock.ena_gpio);
-               int3472->clock.ena_gpio = NULL;
-               return dev_err_probe(int3472->dev, ret, "getting clk-enable GPIO\n");
-       }
-
-       if (polarity == GPIO_ACTIVE_LOW)
-               gpiod_toggle_active_low(int3472->clock.ena_gpio);
-
-       /* Ensure the pin is in output mode and non-active state */
-       gpiod_direction_output(int3472->clock.ena_gpio, 0);
+       int3472->clock.ena_gpio = gpio;
 
        init.name = kasprintf(GFP_KERNEL, "%s-clk",
                              acpi_dev_name(int3472->adev));
@@ -273,9 +260,8 @@ static const struct dmi_system_id skl_int3472_regulator_second_sensor[] = {
 };
 
 int skl_int3472_register_regulator(struct int3472_discrete_device *int3472,
-                                  struct acpi_resource_gpio *agpio)
+                                  struct gpio_desc *gpio)
 {
-       char *path = agpio->resource_source.string_ptr;
        struct regulator_init_data init_data = { };
        struct regulator_config cfg = { };
        const char *second_sensor = NULL;
@@ -314,16 +300,7 @@ int skl_int3472_register_regulator(struct int3472_discrete_device *int3472,
                                                int3472->regulator.supply_name,
                                                &int3472_gpio_regulator_ops);
 
-       int3472->regulator.gpio = acpi_get_and_request_gpiod(path, agpio->pin_table[0],
-                                                            "int3472,regulator");
-       if (IS_ERR(int3472->regulator.gpio)) {
-               ret = PTR_ERR(int3472->regulator.gpio);
-               int3472->regulator.gpio = NULL;
-               return dev_err_probe(int3472->dev, ret, "getting regulator GPIO\n");
-       }
-
-       /* Ensure the pin is in output mode and non-active state */
-       gpiod_direction_output(int3472->regulator.gpio, 0);
+       int3472->regulator.gpio = gpio;
 
        cfg.dev = &int3472->adev->dev;
        cfg.init_data = &init_data;
drivers/platform/x86/intel/int3472/common.h +3 -4
index 9f29baa13860..145dec66df64 100644
@@ -117,16 +117,15 @@ int skl_int3472_get_sensor_adev_and_name(struct device *dev,
                                         const char **name_ret);
 
 int skl_int3472_register_gpio_clock(struct int3472_discrete_device *int3472,
-                                   struct acpi_resource_gpio *agpio, u32 polarity);
+                                   struct gpio_desc *gpio);
 int skl_int3472_register_dsm_clock(struct int3472_discrete_device *int3472);
 void skl_int3472_unregister_clock(struct int3472_discrete_device *int3472);
 
 int skl_int3472_register_regulator(struct int3472_discrete_device *int3472,
-                                  struct acpi_resource_gpio *agpio);
+                                  struct gpio_desc *gpio);
 void skl_int3472_unregister_regulator(struct int3472_discrete_device *int3472);
 
-int skl_int3472_register_pled(struct int3472_discrete_device *int3472,
-                             struct acpi_resource_gpio *agpio, u32 polarity);
+int skl_int3472_register_pled(struct int3472_discrete_device *int3472, struct gpio_desc *gpio);
 void skl_int3472_unregister_pled(struct int3472_discrete_device *int3472);
 
 #endif
drivers/platform/x86/intel/int3472/discrete.c +1 -11
index b69ef63f75ab..0bc7cbefd9ae 100644
@@ -194,6 +194,7 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares,
        struct acpi_resource_gpio *agpio;
        u8 active_value, pin, type;
        union acpi_object *obj;
+       struct gpio_desc *gpio;
        const char *err_msg;
        const char *func;
        u32 polarity;
@@ -244,22 +245,38 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares,
 
                break;
        case INT3472_GPIO_TYPE_CLK_ENABLE:
-               ret = skl_int3472_register_gpio_clock(int3472, agpio, polarity);
-               if (ret)
-                       err_msg = "Failed to register clock\n";
-
-               break;
        case INT3472_GPIO_TYPE_PRIVACY_LED:
-               ret = skl_int3472_register_pled(int3472, agpio, polarity);
-               if (ret)
-                       err_msg = "Failed to register LED\n";
-
-               break;
        case INT3472_GPIO_TYPE_POWER_ENABLE:
-               ret = skl_int3472_register_regulator(int3472, agpio);

drivers/platform/x86/intel/int3472/discrete.c static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares, · line 257

Quoted 10 lines
drivers/platform/x86/intel/int3472/discrete.c +7 -2
-               if (ret)
-                       err_msg = "Failed to map regulator to sensor\n";
+               gpio = skl_int3472_gpiod_get_from_temp_lookup(int3472, agpio, func, polarity);
+               if (IS_ERR(gpio)) {
+                       ret = PTR_ERR(gpio);
+                       err_msg = "Failed to get GPIO\n";
+                       break;
+               }
 
+               switch (type) {

My brain refused to parse the diff, I needed to apply the patch to understand what it's doing. I can't say I'm a fan of this double switch construct but I don't have a better idea either, so...

Quoted 62 lines
drivers/platform/x86/intel/int3472/discrete.c +22 -0
+               case INT3472_GPIO_TYPE_CLK_ENABLE:
+                       ret = skl_int3472_register_gpio_clock(int3472, gpio);
+                       if (ret)
+                               err_msg = "Failed to register clock\n";
+
+                       break;
+               case INT3472_GPIO_TYPE_PRIVACY_LED:
+                       ret = skl_int3472_register_pled(int3472, gpio);
+                       if (ret)
+                               err_msg = "Failed to register LED\n";
+
+                       break;
+               case INT3472_GPIO_TYPE_POWER_ENABLE:
+                       ret = skl_int3472_register_regulator(int3472, gpio);
+                       if (ret)
+                               err_msg = "Failed to map regulator to sensor\n";
+
+                       break;
+               default: /* Never reached */
+                       ret = -EINVAL;
+                       break;
+               }
                break;
        default:
                dev_warn(int3472->dev,
drivers/platform/x86/intel/int3472/led.c +3 -15
index bca1ce7d0d0c..476cd637fc51 100644
@@ -16,26 +16,15 @@ static int int3472_pled_set(struct led_classdev *led_cdev,
        return 0;
 }
 
-int skl_int3472_register_pled(struct int3472_discrete_device *int3472,
-                             struct acpi_resource_gpio *agpio, u32 polarity)
+int skl_int3472_register_pled(struct int3472_discrete_device *int3472, struct gpio_desc *gpio)
 {
-       char *p, *path = agpio->resource_source.string_ptr;
+       char *p;
        int ret;
 
        if (int3472->pled.classdev.dev)
                return -EBUSY;
 
-       int3472->pled.gpio = acpi_get_and_request_gpiod(path, agpio->pin_table[0],
-                                                            "int3472,privacy-led");
-       if (IS_ERR(int3472->pled.gpio))
-               return dev_err_probe(int3472->dev, PTR_ERR(int3472->pled.gpio),
-                                    "getting privacy LED GPIO\n");
-
-       if (polarity == GPIO_ACTIVE_LOW)
-               gpiod_toggle_active_low(int3472->pled.gpio);
-
-       /* Ensure the pin is in output mode and non-active state */
-       gpiod_direction_output(int3472->pled.gpio, 0);
+       int3472->pled.gpio = gpio;
 
        /* Generate the name, replacing the ':' in the ACPI devname with '_' */
        snprintf(int3472->pled.name, sizeof(int3472->pled.name),
--

2.41.0

#6 lore raw

PATCH v3 4/5 platform/x86: int3472: Switch to devm_get_gpiod()

In reply to Hans de Goede

Switch to devm_get_gpiod() for discrete GPIOs for clks / regulators / LEDs and let devm do the cleanup for us.

---
 .../x86/intel/int3472/clk_and_regulator.c     | 23 ++++---------------
 drivers/platform/x86/intel/int3472/discrete.c |  2 +-
 drivers/platform/x86/intel/int3472/led.c      |  7 +-----
 3 files changed, 6 insertions(+), 26 deletions(-)
drivers/platform/x86/intel/int3472/clk_and_regulator.c +4 -19
index 459f96c04ca1..16e36ac0a7b4 100644
@@ -177,10 +177,8 @@ int skl_int3472_register_gpio_clock(struct int3472_discrete_device *int3472,
 
 	init.name = kasprintf(GFP_KERNEL, "%s-clk",
 			      acpi_dev_name(int3472->adev));
-	if (!init.name) {
-		ret = -ENOMEM;
-		goto out_put_gpio;
-	}
+	if (!init.name)
+		return -ENOMEM;
 
 	int3472->clock.frequency = skl_int3472_get_clk_frequency(int3472);
 
@@ -206,8 +204,6 @@ int skl_int3472_register_gpio_clock(struct int3472_discrete_device *int3472,
 	clk_unregister(int3472->clock.clk);
 out_free_init_name:
 	kfree(init.name);
-out_put_gpio:
-	gpiod_put(int3472->clock.ena_gpio);
 
 	return ret;
 }
@@ -219,7 +215,6 @@ void skl_int3472_unregister_clock(struct int3472_discrete_device *int3472)
 
 	clkdev_drop(int3472->clock.cl);
 	clk_unregister(int3472->clock.clk);
-	gpiod_put(int3472->clock.ena_gpio);
 }
 
 /*
@@ -266,7 +261,7 @@ int skl_int3472_register_regulator(struct int3472_discrete_device *int3472,
 	struct regulator_config cfg = { };
 	const char *second_sensor = NULL;
 	const struct dmi_system_id *id;
-	int i, j, ret;
+	int i, j;
 
 	id = dmi_first_match(skl_int3472_regulator_second_sensor);
 	if (id)
@@ -309,21 +304,11 @@ int skl_int3472_register_regulator(struct int3472_discrete_device *int3472,
 	int3472->regulator.rdev = regulator_register(int3472->dev,
 						     &int3472->regulator.rdesc,
 						     &cfg);
-	if (IS_ERR(int3472->regulator.rdev)) {
-		ret = PTR_ERR(int3472->regulator.rdev);
-		goto err_free_gpio;
-	}
 
-	return 0;
-
-err_free_gpio:
-	gpiod_put(int3472->regulator.gpio);
-
-	return ret;
+	return PTR_ERR_OR_ZERO(int3472->regulator.rdev);
 }
 
 void skl_int3472_unregister_regulator(struct int3472_discrete_device *int3472)
 {
 	regulator_unregister(int3472->regulator.rdev);
-	gpiod_put(int3472->regulator.gpio);
 }
drivers/platform/x86/intel/int3472/discrete.c +1 -1
index 0bc7cbefd9ae..07b302e09340 100644
@@ -119,7 +119,7 @@ skl_int3472_gpiod_get_from_temp_lookup(struct int3472_discrete_device *int3472,
 		return ERR_PTR(ret);
 
 	gpiod_add_lookup_table(lookup);
-	desc = gpiod_get(int3472->dev, func, GPIOD_OUT_LOW);
+	desc = devm_gpiod_get(int3472->dev, func, GPIOD_OUT_LOW);
 	gpiod_remove_lookup_table(lookup);
 
 	return desc;
drivers/platform/x86/intel/int3472/led.c +1 -6
index 476cd637fc51..9cbed694e2ca 100644
@@ -39,7 +39,7 @@ int skl_int3472_register_pled(struct int3472_discrete_device *int3472, struct gp
 
 	ret = led_classdev_register(int3472->dev, &int3472->pled.classdev);
 	if (ret)
-		goto err_free_gpio;
+		return ret;
 
 	int3472->pled.lookup.provider = int3472->pled.name;
 	int3472->pled.lookup.dev_id = int3472->sensor_name;
@@ -47,10 +47,6 @@ int skl_int3472_register_pled(struct int3472_discrete_device *int3472, struct gp
 	led_add_lookup(&int3472->pled.lookup);
 
 	return 0;
-
-err_free_gpio:
-	gpiod_put(int3472->pled.gpio);
-	return ret;
 }
 
 void skl_int3472_unregister_pled(struct int3472_discrete_device *int3472)
@@ -60,5 +56,4 @@ void skl_int3472_unregister_pled(struct int3472_discrete_device *int3472)
 
 	led_remove_lookup(&int3472->pled.lookup);
 	led_classdev_unregister(&int3472->pled.classdev);
-	gpiod_put(int3472->pled.gpio);
 }
Signature · 1 line
2.41.0
Reviewed-by on v3 4/5
#7 lore raw

Re: [PATCH v3 4/5] platform/x86: int3472: Switch to devm_get_gpiod()

Quoted 122 lines · Hans de Goede

Switch to devm_get_gpiod() for discrete GPIOs for clks / regulators / LEDs and let devm do the cleanup for us.

---
 .../x86/intel/int3472/clk_and_regulator.c     | 23 ++++---------------
 drivers/platform/x86/intel/int3472/discrete.c |  2 +-
 drivers/platform/x86/intel/int3472/led.c      |  7 +-----
 3 files changed, 6 insertions(+), 26 deletions(-)
drivers/platform/x86/intel/int3472/clk_and_regulator.c +4 -19
index 459f96c04ca1..16e36ac0a7b4 100644
@@ -177,10 +177,8 @@ int skl_int3472_register_gpio_clock(struct int3472_discrete_device *int3472,
 
        init.name = kasprintf(GFP_KERNEL, "%s-clk",
                              acpi_dev_name(int3472->adev));
-       if (!init.name) {
-               ret = -ENOMEM;
-               goto out_put_gpio;
-       }
+       if (!init.name)
+               return -ENOMEM;
 
        int3472->clock.frequency = skl_int3472_get_clk_frequency(int3472);
 
@@ -206,8 +204,6 @@ int skl_int3472_register_gpio_clock(struct int3472_discrete_device *int3472,
        clk_unregister(int3472->clock.clk);
 out_free_init_name:
        kfree(init.name);
-out_put_gpio:
-       gpiod_put(int3472->clock.ena_gpio);
 
        return ret;
 }
@@ -219,7 +215,6 @@ void skl_int3472_unregister_clock(struct int3472_discrete_device *int3472)
 
        clkdev_drop(int3472->clock.cl);
        clk_unregister(int3472->clock.clk);
-       gpiod_put(int3472->clock.ena_gpio);
 }
 
 /*
@@ -266,7 +261,7 @@ int skl_int3472_register_regulator(struct int3472_discrete_device *int3472,
        struct regulator_config cfg = { };
        const char *second_sensor = NULL;
        const struct dmi_system_id *id;
-       int i, j, ret;
+       int i, j;
 
        id = dmi_first_match(skl_int3472_regulator_second_sensor);
        if (id)
@@ -309,21 +304,11 @@ int skl_int3472_register_regulator(struct int3472_discrete_device *int3472,
        int3472->regulator.rdev = regulator_register(int3472->dev,
                                                     &int3472->regulator.rdesc,
                                                     &cfg);
-       if (IS_ERR(int3472->regulator.rdev)) {
-               ret = PTR_ERR(int3472->regulator.rdev);
-               goto err_free_gpio;
-       }
 
-       return 0;
-
-err_free_gpio:
-       gpiod_put(int3472->regulator.gpio);
-
-       return ret;
+       return PTR_ERR_OR_ZERO(int3472->regulator.rdev);
 }
 
 void skl_int3472_unregister_regulator(struct int3472_discrete_device *int3472)
 {
        regulator_unregister(int3472->regulator.rdev);
-       gpiod_put(int3472->regulator.gpio);
 }
drivers/platform/x86/intel/int3472/discrete.c +1 -1
index 0bc7cbefd9ae..07b302e09340 100644
@@ -119,7 +119,7 @@ skl_int3472_gpiod_get_from_temp_lookup(struct int3472_discrete_device *int3472,
                return ERR_PTR(ret);
 
        gpiod_add_lookup_table(lookup);
-       desc = gpiod_get(int3472->dev, func, GPIOD_OUT_LOW);
+       desc = devm_gpiod_get(int3472->dev, func, GPIOD_OUT_LOW);
        gpiod_remove_lookup_table(lookup);
 
        return desc;
drivers/platform/x86/intel/int3472/led.c +1 -7
index 476cd637fc51..9cbed694e2ca 100644
@@ -39,7 +39,7 @@ int skl_int3472_register_pled(struct int3472_discrete_device *int3472, struct gp
 
        ret = led_classdev_register(int3472->dev, &int3472->pled.classdev);
        if (ret)
-               goto err_free_gpio;
+               return ret;
 
        int3472->pled.lookup.provider = int3472->pled.name;
        int3472->pled.lookup.dev_id = int3472->sensor_name;
@@ -47,10 +47,6 @@ int skl_int3472_register_pled(struct int3472_discrete_device *int3472, struct gp
        led_add_lookup(&int3472->pled.lookup);
 
        return 0;
-
-err_free_gpio:
-       gpiod_put(int3472->pled.gpio);
-       return ret;
 }
 
 void skl_int3472_unregister_pled(struct int3472_discrete_device *int3472)
@@ -60,5 +56,4 @@ void skl_int3472_unregister_pled(struct int3472_discrete_device *int3472)
 
        led_remove_lookup(&int3472->pled.lookup);
        led_classdev_unregister(&int3472->pled.classdev);
-       gpiod_put(int3472->pled.gpio);
 }
--
Quoted 2 lines

2.41.0

#8 lore raw

PATCH v3 5/5 gpio: acpi: remove acpi_get_and_request_gpiod()

In reply to Hans de Goede

From: Bartosz Golaszewski <[email protected]>

With no more users, we can remove acpi_get_and_request_gpiod().

---
 drivers/gpio/gpiolib-acpi.c   | 28 ----------------------------
 include/linux/gpio/consumer.h |  8 --------
 2 files changed, 36 deletions(-)
drivers/gpio/gpiolib-acpi.c +0 -28
index 17a86bdd9609..89ff93f3b579 100644
@@ -158,34 +158,6 @@ static struct gpio_desc *acpi_get_gpiod(char *path, unsigned int pin)
 	return gpiochip_get_desc(chip, pin);
 }
 
-/**
- * acpi_get_and_request_gpiod - Translate ACPI GPIO pin to GPIO descriptor and
- *                              hold a refcount to the GPIO device.
- * @path:      ACPI GPIO controller full path name, (e.g. "\\_SB.GPO1")
- * @pin:       ACPI GPIO pin number (0-based, controller-relative)
- * @label:     Label to pass to gpiod_request()
- *
- * This function is a simple pass-through to acpi_get_gpiod(), except that
- * as it is intended for use outside of the GPIO layer (in a similar fashion to
- * gpiod_get_index() for example) it also holds a reference to the GPIO device.
- */
-struct gpio_desc *acpi_get_and_request_gpiod(char *path, unsigned int pin, char *label)
-{
-	struct gpio_desc *gpio;
-	int ret;
-
-	gpio = acpi_get_gpiod(path, pin);
-	if (IS_ERR(gpio))
-		return gpio;
-
-	ret = gpiod_request(gpio, label);
-	if (ret)
-		return ERR_PTR(ret);
-
-	return gpio;
-}
-EXPORT_SYMBOL_GPL(acpi_get_and_request_gpiod);
-
 static irqreturn_t acpi_gpio_irq_handler(int irq, void *data)
 {
 	struct acpi_gpio_event *event = data;
include/linux/gpio/consumer.h +0 -8
index 1c4385a00f88..9d1f598b8971 100644
@@ -614,8 +614,6 @@ void acpi_dev_remove_driver_gpios(struct acpi_device *adev);
 int devm_acpi_dev_add_driver_gpios(struct device *dev,
 				   const struct acpi_gpio_mapping *gpios);
 
-struct gpio_desc *acpi_get_and_request_gpiod(char *path, unsigned int pin, char *label);
-
 #else  /* CONFIG_GPIOLIB && CONFIG_ACPI */
 
 #include <linux/err.h>
@@ -633,12 +631,6 @@ static inline int devm_acpi_dev_add_driver_gpios(struct device *dev,
 	return -ENXIO;
 }
 
-static inline struct gpio_desc *acpi_get_and_request_gpiod(char *path, unsigned int pin,
-							   char *label)
-{
-	return ERR_PTR(-ENOSYS);
-}
-
 #endif /* CONFIG_GPIOLIB && CONFIG_ACPI */
 
 
Signature · 1 line
2.41.0