gpio: move interfaces into their own files
cover gpio: move interfaces into their own files
Hi Linus,
I was thinking of doing this since a while already but the recent discussion on shared GPIOs made me think I should push this to you and see what you think.
Right now we have 3 different interfaces for GPIO:
- The core gpiod interface
- The legacy integer interface, which mostly relies on gpiod
- The sysfs interface, which relies on gpiod but should probably rely on the integer interface instead
This series separates the code for the interfaces into their own source file and shares what needs to be through the private gpiolib.h header. Label support is made mandatory in order to reduce the amount of things added into gpiolib.h.
Separating the code should make the various interfaces easier to grasp, and will make it easier to implement interface-specific features. It also points out some direct usages of descriptors/gpiolib core functions that should be gotten rid of in order to make these real "consumers" of the gpiod interface.
This series has been tested and I'm fine with it being merged now if you agree with the idea. It would probably be preferable from a cosmetic point of view to first turn fix the extra consumers and then separate them so less things end up being exported in gpiolib.h, but moving things first has the advantage of clearly highlighting what needs to be done and spares us some rebasing hassle.
Alexandre Courbot (3):
gpio: always compile label support
gpio: move sysfs support to its own file
gpio: move integer GPIO support to its own file
drivers/gpio/Makefile | 2 + drivers/gpio/gpiolib-legacy.c | 112 +++++ drivers/gpio/gpiolib-sysfs.c | 829 ++++++++++++++++++++++++++++++++ drivers/gpio/gpiolib.c | 1043 +---------------------------------------- drivers/gpio/gpiolib.h | 91 ++++ 5 files changed, 1040 insertions(+), 1037 deletions(-) create mode 100644 drivers/gpio/gpiolib-legacy.c create mode 100644 drivers/gpio/gpiolib-sysfs.c
Signature · 1 line
2.0.0
RFC 1/3 gpio: always compile label support
Compiling out GPIO labels results in a space gain so small that it can hardly be justified. Labels can also be useful for printing debug messages, so always keep them around.
--- drivers/gpio/gpiolib.c | 27 ++------------------------- 1 file changed, 2 insertions(+), 25 deletions(-)
drivers/gpio/gpiolib.c +2 -25
@@ -66,9 +66,7 @@ struct gpio_desc {#define GPIO_FLAGS_MASK ((1 << ID_SHIFT) - 1)#define GPIO_TRIGGER_MASK (BIT(FLAG_TRIG_FALL) | BIT(FLAG_TRIG_RISE)) -#ifdef CONFIG_DEBUG_FS const char *label; -#endif };static struct gpio_desc gpio_desc[ARCH_NR_GPIOS ];
@@ -87,7 +85,6 @@ static void gpiod_free(struct gpio_desc *desc);/* With descriptor prefix */ -#ifdef CONFIG_DEBUG_FS #define gpiod_emerg (desc, fmt, ...) \ pr_emerg("gpio-%d (%s): " fmt, desc_to_gpio(desc), desc->label ? : "?",\ ##__VA_ARGS__)
@@ -106,20 +103,6 @@ static void gpiod_free(struct gpio_desc *desc);#define gpiod_dbg (desc, fmt, ...) \ pr_debug("gpio-%d (%s): " fmt, desc_to_gpio(desc), desc->label ? : "?",\ ##__VA_ARGS__) -#else -#define gpiod_emerg (desc, fmt, ...) \ - pr_emerg("gpio-%d: " fmt, desc_to_gpio(desc), ##__VA_ARGS__) -#define gpiod_crit (desc, fmt, ...) \ - pr_crit("gpio-%d: " fmt, desc_to_gpio(desc), ##__VA_ARGS__) -#define gpiod_err (desc, fmt, ...) \ - pr_err("gpio-%d: " fmt, desc_to_gpio(desc), ##__VA_ARGS__) -#define gpiod_warn (desc, fmt, ...) \ - pr_warn("gpio-%d: " fmt, desc_to_gpio(desc), ##__VA_ARGS__) -#define gpiod_info (desc, fmt, ...) \ - pr_info("gpio-%d: " fmt, desc_to_gpio(desc), ##__VA_ARGS__) -#define gpiod_dbg (desc, fmt, ...) \ - pr_debug("gpio-%d: " fmt, desc_to_gpio(desc), ##__VA_ARGS__) -#endif /* With chip prefix */
@@ -138,9 +121,7 @@ static void gpiod_free(struct gpio_desc *desc);static inline void desc_set_label (struct gpio_desc *d,const char *label) { -#ifdef CONFIG_DEBUG_FS d->label = label; -#endif }/*
@@ -1906,8 +1887,8 @@ EXPORT_SYMBOL_GPL(gpio_free_array);* @offset: of signal within controller's 0..(ngpio - 1) range * * Returns NULL if the GPIO is not currently requested, else a string. -* If debugfs support is enabled, the string returned is the label passed -* to gpio_request(); otherwise it is a meaningless constant. +* The string returned is the label passed to gpio_request(); if none has been +* passed it is a meaningless, non-NULL constant. * * This function is for use by GPIO controller drivers. The label can * help with diagnostics, and knowing that the signal is used as a GPIO
@@ -1924,11 +1905,7 @@ const char *gpiochip_is_requested(struct gpio_chip *chip, unsigned offset)if (test_bit (FLAG_REQUESTED , &desc->flags) ==0 )return NULL ; -#ifdef CONFIG_DEBUG_FS return desc->label; -#else -return "?" ; -#endif }EXPORT_SYMBOL_GPL (gpiochip_is_requested);
Signature · 1 line
2.0.0
Re: [RFC 1/3] gpio: always compile label support
Quoted 5 lines · Alexandre Courbot
Compiling out GPIO labels results in a space gain so small that it can hardly be justified. Labels can also be useful for printing debug messages, so always keep them around.
Signed-off-by Alexandre Courbot <[email protected]>
Patch applied.
Yours,
Linus Walleij
RFC 2/3 gpio: move sysfs support to its own file
In reply to Alexandre Courbotsysfs support is currently entangled within the core GPIO support, while it should relly just be a (privileged) user of the integer GPIO API. This patch is a first step towards making the gpiolib code more readable by splitting it into logical parts.
Move all sysfs support to their own source file, and share static members of gpiolib that need to be in the private gpiolib.h file. In the future we will want to put some of them back into gpiolib.c, but this first patch let us at least identify them.
--- drivers/gpio/Makefile | 1 + drivers/gpio/gpiolib-sysfs.c | 829 +++++++++++++++++++++++++++++++++++++++ drivers/gpio/gpiolib.c | 911 +------------------------------------------ drivers/gpio/gpiolib.h | 91 +++++ 4 files changed, 925 insertions(+), 907 deletions(-) create mode 100644 drivers/gpio/gpiolib-sysfs.c
drivers/gpio/Makefile +1 -0
@@ -5,6 +5,7 @@ ccflags-$(CONFIG_DEBUG_GPIO) += -DDEBUG obj-$(CONFIG_GPIO_DEVRES) += devres.o obj-$(CONFIG_GPIOLIB) += gpiolib.o obj-$(CONFIG_OF_GPIO) += gpiolib-of.o +obj-$(CONFIG_GPIO_SYSFS) += gpiolib-sysfs.o obj-$(CONFIG_GPIO_ACPI) += gpiolib-acpi.o # Device drivers. Generally keep list sorted alphabetically
drivers/gpio/gpiolib-sysfs.c new file +829 -0
829 lines not on this page · raw message
drivers/gpio/gpiolib.c +4 -907
948 lines not on this page · raw message
drivers/gpio/gpiolib.h +91 -0
95 lines not on this page · raw message
Signature · 1 line
2.0.0
Re: [RFC 2/3] gpio: move sysfs support to its own file
Quoted 11 lines · Alexandre Courbot
sysfs support is currently entangled within the core GPIO support, while it should relly just be a (privileged) user of the integer GPIO API. This patch is a first step towards making the gpiolib code more readable by splitting it into logical parts.
Move all sysfs support to their own source file, and share static members of gpiolib that need to be in the private
gpiolib.hfile. In the future we will want to put some of them back intogpiolib.c, but this first patch let us at least identify them.Signed-off-by Alexandre Courbot <[email protected]>
Patch applied. We really need to make refactorings like this so thanks a lot.
Yours,
Linus Walleij
Re: [RFC 2/3] gpio: move sysfs support to its own file
Quoted 12 lines · Linus Walleij
Quoted 10 lines · Alexandre Courbot
sysfs support is currently entangled within the core GPIO support, while it should relly just be a (privileged) user of the integer GPIO API. This patch is a first step towards making the gpiolib code more readable by splitting it into logical parts.
Move all sysfs support to their own source file, and share static members of gpiolib that need to be in the private
gpiolib.hfile. In the future we will want to put some of them back intogpiolib.c, but this first patch let us at least identify them.
Quoted 4 lines
Quoted 1 line
Signed-off-by Alexandre Courbot <[email protected]>Patch applied. We really need to make refactorings like this so thanks a lot.
Excellent, glad you approve of this. I actually have some more coming after that, since the current lack of organization stands in the way of a proper multi-consumer GPIO implementation.
Thanks!
Alex.
RFC 3/3 gpio: move integer GPIO support to its own file
In reply to Alexandre CourbotThe old integer GPIO interface is, in effect, a privileged user of the gpiod interface. Reflect this fact further by moving legacy GPIO support into its own source file. This makes the code clearer and will allow us to disable legacy GPIO support in the (far) future.
--- drivers/gpio/Makefile | 1 + drivers/gpio/gpiolib-legacy.c | 112 ++++++++++++++++++++++++++++++++++++++++++ drivers/gpio/gpiolib.c | 105 --------------------------------------- 3 files changed, 113 insertions(+), 105 deletions(-) create mode 100644 drivers/gpio/gpiolib-legacy.c
drivers/gpio/Makefile +1 -0
@@ -4,6 +4,7 @@ ccflags-$(CONFIG_DEBUG_GPIO) += -DDEBUG obj-$(CONFIG_GPIO_DEVRES) += devres.o obj-$(CONFIG_GPIOLIB) += gpiolib.o +obj-$(CONFIG_GPIOLIB) += gpiolib-legacy.o obj-$(CONFIG_OF_GPIO) += gpiolib-of.o obj-$(CONFIG_GPIO_SYSFS) += gpiolib-sysfs.o obj-$(CONFIG_GPIO_ACPI) += gpiolib-acpi.o
drivers/gpio/gpiolib-legacy.c new file +112 -0
112 lines not on this page · raw message
drivers/gpio/gpiolib.c +0 -105
129 lines not on this page · raw message
Signature · 1 line
2.0.0
Re: [RFC 3/3] gpio: move integer GPIO support to its own file
Quoted 6 lines · Alexandre Courbot
The old integer GPIO interface is, in effect, a privileged user of the gpiod interface. Reflect this fact further by moving legacy GPIO support into its own source file. This makes the code clearer and will allow us to disable legacy GPIO support in the (far) future.
Signed-off-by Alexandre Courbot <[email protected]>
Patch applied.
Yours,
Linus Walleij