diff mbox series

[RFT,1/4] platform/x86: int3472: provide a helper for getting GPIOs from lookups

Message ID 20230926145943.42814-2-brgl@bgdev.pl (mailing list archive)
State Superseded, archived
Headers show
Series platform/x86: int3472: don't use gpiod_toggle_active_low() | expand

Commit Message

Bartosz Golaszewski Sept. 26, 2023, 2:59 p.m. UTC
From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

gpiod_toggle_active_low() should have never existed in the first place
and once it was added, it should have never been used outside the MMC
slot code.

Stop using it in the int3472 driver and use temporary lookup tables
instead. First: add a helper wrapping the common code in one function.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
 drivers/platform/x86/intel/int3472/common.c | 29 +++++++++++++++++++++
 drivers/platform/x86/intel/int3472/common.h |  9 +++++++
 2 files changed, 38 insertions(+)

Comments

Andy Shevchenko Sept. 26, 2023, 3:25 p.m. UTC | #1
On Tue, Sep 26, 2023 at 04:59:40PM +0200, Bartosz Golaszewski wrote:
> From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> 
> gpiod_toggle_active_low() should have never existed in the first place
> and once it was added, it should have never been used outside the MMC
> slot code.
> 
> Stop using it in the int3472 driver and use temporary lookup tables
> instead. First: add a helper wrapping the common code in one function.

>  #include <linux/clk-provider.h>

...

> +#include <linux/device.h>

No need to have this in the header, use forward declaration instead.
diff mbox series

Patch

diff --git a/drivers/platform/x86/intel/int3472/common.c b/drivers/platform/x86/intel/int3472/common.c
index 9db2bb0bbba4..61a8240ed6db 100644
--- a/drivers/platform/x86/intel/int3472/common.c
+++ b/drivers/platform/x86/intel/int3472/common.c
@@ -2,6 +2,10 @@ 
 /* Author: Dan Scally <djrscally@gmail.com> */
 
 #include <linux/acpi.h>
+#include <linux/cleanup.h>
+#include <linux/device.h>
+#include <linux/gpio/machine.h>
+#include <linux/overflow.h>
 #include <linux/slab.h>
 
 #include "common.h"
@@ -80,3 +84,28 @@  int skl_int3472_get_sensor_adev_and_name(struct device *dev,
 
 	return ret;
 }
+
+/* This should *really* only be used when there's no other way... */
+struct gpio_desc *
+skl_int3472_gpiod_get_from_temp_lookup(struct device *dev,
+				       const char *chip_label, u16 hwnum,
+				       const char *con_id,
+				       enum gpio_lookup_flags lflags,
+				       enum gpiod_flags rflags)
+{
+	struct gpio_desc *desc;
+
+	struct gpiod_lookup_table *lookup __free(kfree) =
+			kzalloc(struct_size(lookup, table, 1), GFP_KERNEL);
+	if (!lookup)
+		return ERR_PTR(-ENOMEM);
+
+	lookup->dev_id = dev_name(dev);
+	lookup->table[0] = GPIO_LOOKUP(chip_label, hwnum, con_id, lflags);
+
+	gpiod_add_lookup_table(lookup);
+
+	desc = gpiod_get(dev, con_id, rflags);
+	gpiod_remove_lookup_table(lookup);
+	return desc;
+}
diff --git a/drivers/platform/x86/intel/int3472/common.h b/drivers/platform/x86/intel/int3472/common.h
index 9f29baa13860..85ef9b630044 100644
--- a/drivers/platform/x86/intel/int3472/common.h
+++ b/drivers/platform/x86/intel/int3472/common.h
@@ -5,6 +5,8 @@ 
 #define _INTEL_SKL_INT3472_H
 
 #include <linux/clk-provider.h>
+#include <linux/device.h>
+#include <linux/gpio/consumer.h>
 #include <linux/gpio/machine.h>
 #include <linux/leds.h>
 #include <linux/regulator/driver.h>
@@ -129,4 +131,11 @@  int skl_int3472_register_pled(struct int3472_discrete_device *int3472,
 			      struct acpi_resource_gpio *agpio, u32 polarity);
 void skl_int3472_unregister_pled(struct int3472_discrete_device *int3472);
 
+struct gpio_desc *
+skl_int3472_gpiod_get_from_temp_lookup(struct device *dev,
+				       const char *chip_label, u16 hwnum,
+				       const char *con_id,
+				       enum gpio_lookup_flags lflags,
+				       enum gpiod_flags rflags);
+
 #endif