diff mbox series

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

Message ID 20231004162317.163488-2-hdegoede@redhat.com
State Accepted
Commit 23516fba866c49397594832d407459f30fe3ed60
Headers show
Series platform/x86: int3472: don't use gpiod_toggle_active_low() | expand

Commit Message

Hans de Goede Oct. 4, 2023, 4:23 p.m. UTC
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.

Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 drivers/platform/x86/intel/int3472/discrete.c | 32 +++++++++++++------
 1 file changed, 22 insertions(+), 10 deletions(-)

Comments

Bartosz Golaszewski Oct. 5, 2023, 7:21 p.m. UTC | #1
On Wed, Oct 4, 2023 at 6:23 PM Hans de Goede <hdegoede@redhat.com> wrote:
>
> 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.
>
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> ---
>  drivers/platform/x86/intel/int3472/discrete.c | 32 +++++++++++++------
>  1 file changed, 22 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/platform/x86/intel/int3472/discrete.c b/drivers/platform/x86/intel/int3472/discrete.c
> index e33c2d75975c..351ecf047944 100644
> --- a/drivers/platform/x86/intel/int3472/discrete.c
> +++ b/drivers/platform/x86/intel/int3472/discrete.c
> @@ -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;
> --
> 2.41.0
>

Reviewed-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
diff mbox series

Patch

diff --git a/drivers/platform/x86/intel/int3472/discrete.c b/drivers/platform/x86/intel/int3472/discrete.c
index e33c2d75975c..351ecf047944 100644
--- a/drivers/platform/x86/intel/int3472/discrete.c
+++ b/drivers/platform/x86/intel/int3472/discrete.c
@@ -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;