[PATCH 14/30] backports: add gpiochip_request_own_desc()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The signature of the gpiochip_request_own_desc() function changes
multiple times, adapt this in the backports layer as good as possible.
brcmfmac is using this function.

Signed-off-by: Hauke Mehrtens <hauke@xxxxxxxxxx>
---
 backport/backport-include/linux/gpio/driver.h | 12 +++
 backport/compat/Makefile                      |  1 +
 backport/compat/backport-5.3.c                | 74 +++++++++++++++++++
 3 files changed, 87 insertions(+)
 create mode 100644 backport/compat/backport-5.3.c

diff --git a/backport/backport-include/linux/gpio/driver.h b/backport/backport-include/linux/gpio/driver.h
index 8df5c298..cebeb482 100644
--- a/backport/backport-include/linux/gpio/driver.h
+++ b/backport/backport-include/linux/gpio/driver.h
@@ -7,4 +7,16 @@
 #include_next <linux/gpio/driver.h>
 #endif
 
+#if LINUX_VERSION_IN_RANGE(3,17,0, 5,3,0)
+enum gpiod_flags;
+enum gpio_lookup_flags;
+
+#define gpiochip_request_own_desc LINUX_BACKPORT(gpiochip_request_own_desc)
+struct gpio_desc *backport_gpiochip_request_own_desc(struct gpio_chip *gc,
+					    unsigned int hwnum,
+					    const char *label,
+					    enum gpio_lookup_flags lflags,
+					    enum gpiod_flags dflags);
+#endif /* 3.17.0 <= x < 5.3.0 */
+
 #endif /* __BP_GPIO_DRIVER_H */
diff --git a/backport/compat/Makefile b/backport/compat/Makefile
index 6f1b0a89..8d917622 100644
--- a/backport/compat/Makefile
+++ b/backport/compat/Makefile
@@ -38,6 +38,7 @@ compat-$(CPTCFG_KERNEL_4_8) += backport-4.8.o
 compat-$(CPTCFG_KERNEL_4_10) += backport-4.10.o
 compat-$(CPTCFG_KERNEL_4_18) += backport-4.18.o
 compat-$(CPTCFG_KERNEL_5_2) += backport-5.2.o backport-genetlink.o
+compat-$(CPTCFG_KERNEL_5_3) += backport-5.3.o
 compat-$(CPTCFG_KERNEL_5_5) += backport-5.5.o
 
 compat-$(CPTCFG_BPAUTO_BUILD_SYSTEM_DATA_VERIFICATION) += verification/verify.o
diff --git a/backport/compat/backport-5.3.c b/backport/compat/backport-5.3.c
new file mode 100644
index 00000000..f501448e
--- /dev/null
+++ b/backport/compat/backport-5.3.c
@@ -0,0 +1,74 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <linux/export.h>
+#include <linux/gpio.h>
+#if LINUX_VERSION_IS_GEQ(3,17,0)
+#include <linux/gpio/driver.h>
+#include <linux/gpio/consumer.h>
+#include <linux/gpio/machine.h>
+
+/**
+ * gpiod_configure_flags - helper function to configure a given GPIO
+ * @desc:	gpio whose value will be assigned
+ * @con_id:	function within the GPIO consumer
+ * @lflags:	bitmask of gpio_lookup_flags GPIO_* values - returned from
+ *		of_find_gpio() or of_get_gpio_hog()
+ * @dflags:	gpiod_flags - optional GPIO initialization flags
+ *
+ * Return 0 on success, -ENOENT if no GPIO has been assigned to the
+ * requested function and/or index, or another IS_ERR() code if an error
+ * occurred while trying to acquire the GPIO.
+ */
+static int gpiod_configure_flags(struct gpio_desc *desc, const char *con_id,
+		unsigned long lflags, enum gpiod_flags dflags)
+{
+	int ret;
+
+#ifdef GPIO_TRANSITORY
+	ret = gpiod_set_transitory(desc, (lflags & GPIO_TRANSITORY));
+	if (ret < 0)
+		return ret;
+#endif
+
+	/* No particular flag request, return here... */
+	if (!(dflags & GPIOD_FLAGS_BIT_DIR_SET))
+		return 0;
+
+	/* Process flags */
+	if (dflags & GPIOD_FLAGS_BIT_DIR_OUT)
+		ret = gpiod_direction_output(desc,
+				!!(dflags & GPIOD_FLAGS_BIT_DIR_VAL));
+	else
+		ret = gpiod_direction_input(desc);
+
+	return ret;
+}
+
+#undef gpiochip_request_own_desc
+struct gpio_desc *backport_gpiochip_request_own_desc(struct gpio_chip *gc,
+					    unsigned int hwnum,
+					    const char *label,
+					    enum gpio_lookup_flags lflags,
+					    enum gpiod_flags dflags)
+{
+	struct gpio_desc *desc;
+	int ret;
+
+#if LINUX_VERSION_IS_GEQ(5,0,0)
+	desc = gpiochip_request_own_desc(gc, hwnum, label, dflags);
+#else
+	desc = gpiochip_request_own_desc(gc, hwnum, label);
+#endif
+	if (IS_ERR(desc))
+		return desc;
+
+	ret = gpiod_configure_flags(desc, label, lflags, dflags);
+	if (ret) {
+		gpiochip_free_own_desc(desc);
+		return ERR_PTR(ret);
+	}
+
+	return desc;
+}
+EXPORT_SYMBOL_GPL(backport_gpiochip_request_own_desc);
+#endif /* > 3.17 */
-- 
2.20.1

--
To unsubscribe from this list: send the line "unsubscribe backports" in



[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux