gpio: aspeed: remove the "gpiolib.h" include
Subsystems (3)
cover gpio: aspeed: remove the "gpiolib.h" include
gpiolib.h is a header internal to the GPIO core. Drivers should not include them. gpio-aspeed only needs to be able to determine the hardware offset of the GPIO given the descriptor. Expose the relevant symbol in the consumer header which allows us to stop pulling in the private one.
---
Bartosz Golaszewski (3):
gpio: rename gpio_chip_hwgpio() to gpiod_hwgpio()
gpio: export gpiod_hwgpio()
gpio: aspeed: remove unneeded include
drivers/gpio/gpio-aspeed.c | 7 +++-- drivers/gpio/gpiolib-cdev.c | 12 ++++----- drivers/gpio/gpiolib-sysfs.c | 14 +++++----- drivers/gpio/gpiolib.c | 59 ++++++++++++++++++++++++++----------------- drivers/gpio/gpiolib.h | 8 ------ include/linux/gpio/consumer.h | 2 ++ 6 files changed, 54 insertions(+), 48 deletions(-)
---
base-commit: 13863a59e410cab46d26751941980dc8f088b9b3
change-id: 20251015-aspeed-gpiolib-include-249a3529efd5
Best regards,
Signature · 1 line
Bartosz Golaszewski <[email protected]>
PATCH 1/3 gpio: rename gpio_chip_hwgpio() to gpiod_hwgpio()
From: Bartosz Golaszewski <[email protected]>
This function takes a GPIO descriptor as first argument. Make its naming consistent with the rest of the GPIO codebase and use the gpiod_ prefix.
--- drivers/gpio/gpio-aspeed.c | 6 +++--- drivers/gpio/gpiolib-cdev.c | 12 ++++++------ drivers/gpio/gpiolib-sysfs.c | 14 +++++++------- drivers/gpio/gpiolib.c | 46 ++++++++++++++++++++++---------------------- drivers/gpio/gpiolib.h | 2 +- 5 files changed, 40 insertions(+), 40 deletions(-)
drivers/gpio/gpio-aspeed.c +3 -3
@@ -24,7 +24,7 @@/* * These two headers aren't meant to be used by GPIO drivers. We need -* them in order to access gpio_chip_hwgpio() which we need to implement +* them in order to access gpiod_hwgpio() which we need to implement * the aspeed specific API which allows the coprocessor to request * access to some GPIOs and to arbitrate between coprocessor and ARM. */
@@ -942,7 +942,7 @@ int aspeed_gpio_copro_grab_gpio(struct gpio_desc *desc, {struct gpio_chip *chip =gpiod_to_chip (desc);struct aspeed_gpio *gpio =gpiochip_get_data (chip); -int rc =0 , bindex, offset =gpio_chip_hwgpio (desc); +int rc =0 , bindex, offset =gpiod_hwgpio (desc);const struct aspeed_gpio_bank *bank =to_bank (offset);if (!aspeed_gpio_support_copro (gpio))
@@ -987,7 +987,7 @@ int aspeed_gpio_copro_release_gpio(struct gpio_desc *desc) {struct gpio_chip *chip =gpiod_to_chip (desc);struct aspeed_gpio *gpio =gpiochip_get_data (chip); -int rc =0 , bindex, offset =gpio_chip_hwgpio (desc); +int rc =0 , bindex, offset =gpiod_hwgpio (desc);if (!aspeed_gpio_support_copro (gpio))return -EOPNOTSUPP ;
drivers/gpio/gpiolib-cdev.c +6 -6
@@ -676,7 +676,7 @@ static enum hte_return process_hw_ts_thread(void *p) } le.line_seqno = line->line_seqno; le.seqno = (lr->num_lines ==1 ) ? le.line_seqno : line->req_seqno; - le.offset =gpio_chip_hwgpio (line->desc); + le.offset =gpiod_hwgpio (line->desc);linereq_put_event (lr, &le);
@@ -793,7 +793,7 @@ static irqreturn_t edge_irq_thread(int irq, void *p) line->line_seqno++; le.line_seqno = line->line_seqno; le.seqno = (lr->num_lines ==1 ) ? le.line_seqno : line->req_seqno; - le.offset =gpio_chip_hwgpio (line->desc); + le.offset =gpiod_hwgpio (line->desc);linereq_put_event (lr, &le);
@@ -891,7 +891,7 @@ static void debounce_work_func(struct work_struct *work) lr = line->req; le.timestamp_ns =line_event_timestamp (line); - le.offset =gpio_chip_hwgpio (line->desc); + le.offset =gpiod_hwgpio (line->desc);#ifdef CONFIG_HTE if (edflags &GPIO_V2_LINE_FLAG_EVENT_CLOCK_HTE ) {/* discard events except the last one */
@@ -1591,7 +1591,7 @@ static void linereq_show_fdinfo(struct seq_file *out, struct file *file)for (i =0 ; i < lr->num_lines; i++)seq_printf (out,"gpio-line:\t%d\n" , - gpio_chip_hwgpio(lr->lines[i].desc)); + gpiod_hwgpio(lr->lines[i].desc)); }#endif
@@ -2244,7 +2244,7 @@ static void gpio_desc_to_lineinfo(struct gpio_desc *desc,return ;memset (info,0 ,sizeof (*info)); - info->offset =gpio_chip_hwgpio (desc); + info->offset =gpiod_hwgpio (desc);if (desc->name)strscpy (info->name, desc->name,sizeof (info->name));
@@ -2549,7 +2549,7 @@ static int lineinfo_changed_notify(struct notifier_block *nb,struct lineinfo_changed_ctx *ctx;struct gpio_desc *desc = data; -if (!test_bit (gpio_chip_hwgpio (desc), cdev->watched_lines)) +if (!test_bit (gpiod_hwgpio (desc), cdev->watched_lines))return NOTIFY_DONE ;/*
drivers/gpio/gpiolib-sysfs.c +7 -7
@@ -244,7 +244,7 @@ static int gpio_sysfs_request_irq(struct gpiod_data *data, unsigned char flags)* Remove this redundant call (along with the corresponding unlock) * when those drivers have been fixed. */ - ret =gpiochip_lock_as_irq (guard.gc,gpio_chip_hwgpio (desc)); + ret =gpiochip_lock_as_irq (guard.gc,gpiod_hwgpio (desc));if (ret <0 ) goto err_clr_bits;
@@ -258,7 +258,7 @@ static int gpio_sysfs_request_irq(struct gpiod_data *data, unsigned char flags)return 0 ; err_unlock: -gpiochip_unlock_as_irq (guard.gc,gpio_chip_hwgpio (desc)); +gpiochip_unlock_as_irq (guard.gc,gpiod_hwgpio (desc)); err_clr_bits:clear_bit (GPIOD_FLAG_EDGE_RISING , &desc->flags);clear_bit (GPIOD_FLAG_EDGE_FALLING , &desc->flags);
@@ -280,7 +280,7 @@ static void gpio_sysfs_free_irq(struct gpiod_data *data) data->irq_flags =0 ;free_irq (data->irq, data); -gpiochip_unlock_as_irq (guard.gc,gpio_chip_hwgpio (desc)); +gpiochip_unlock_as_irq (guard.gc,gpiod_hwgpio (desc));clear_bit (GPIOD_FLAG_EDGE_RISING , &desc->flags);clear_bit (GPIOD_FLAG_EDGE_FALLING , &desc->flags); }
@@ -478,10 +478,10 @@ static int export_gpio_desc(struct gpio_desc *desc)if (!guard.gc)return -ENODEV ; - offset =gpio_chip_hwgpio (desc); + offset =gpiod_hwgpio (desc);if (!gpiochip_line_is_valid (guard.gc, offset)) {pr_debug_ratelimited ("%s: GPIO %d masked\n" , __func__, -gpio_chip_hwgpio (desc)); +gpiod_hwgpio (desc));return -EINVAL ; }
@@ -823,7 +823,7 @@ int gpiod_export(struct gpio_desc *desc, bool direction_may_change) } desc_data->chip_attr_group.name =kasprintf (GFP_KERNEL ,"gpio%u" , -gpio_chip_hwgpio (desc)); +gpiod_hwgpio (desc));if (!desc_data->chip_attr_group.name) { status = -ENOMEM ; goto err_put_dirent;
@@ -843,7 +843,7 @@ int gpiod_export(struct gpio_desc *desc, bool direction_may_change)if (status) goto err_free_name; - path =kasprintf (GFP_KERNEL ,"gpio%u/value" ,gpio_chip_hwgpio (desc)); + path =kasprintf (GFP_KERNEL ,"gpio%u/value" ,gpiod_hwgpio (desc));if (!path) { status = -ENOMEM ; goto err_remove_groups;
drivers/gpio/gpiolib.c +23 -23
177 lines not on this page · raw message
drivers/gpio/gpiolib.h +1 -1
@@ -276,7 +276,7 @@ const char *gpiod_get_label(struct gpio_desc *desc);/* * Return the GPIO number of the passed descriptor relative to its chip */ -static inline int gpio_chip_hwgpio (const struct gpio_desc *desc) +static inline int gpiod_hwgpio (const struct gpio_desc *desc) {return desc - &desc->gdev->descs[0 ]; }
Signature · 1 line
2.48.1
PATCH 2/3 gpio: export gpiod_hwgpio()
In reply to Bartosz GolaszewskiFrom: Bartosz Golaszewski <[email protected]>
Reading the GPIO hardware number from a descriptor is a valid use-case outside of the GPIO core. Export the symbol to consumers of GPIO descriptors.
--- drivers/gpio/gpiolib.c | 13 +++++++++++++ drivers/gpio/gpiolib.h | 8 -------- include/linux/gpio/consumer.h | 2 ++ 3 files changed, 15 insertions(+), 8 deletions(-)
drivers/gpio/gpiolib.c +13 -0
@@ -235,6 +235,19 @@ int desc_to_gpio(const struct gpio_desc *desc) }EXPORT_SYMBOL_GPL (desc_to_gpio); +/** +* gpiod_hwgpio - Return the GPIO number of the passed descriptor relative to +* its chip. +* @desc: GPIO descriptor +* +* Returns: +* Hardware offset of the GPIO represented by the descriptor. +*/ +int gpiod_hwgpio (const struct gpio_desc *desc) +{ +return desc - &desc->gdev->descs[0 ]; +} +EXPORT_SYMBOL_GPL (gpiod_hwgpio);/** * gpiod_to_chip - Return the GPIO chip to which a GPIO descriptor belongs
drivers/gpio/gpiolib.h +0 -8
@@ -273,14 +273,6 @@ int gpiochip_get_ngpios(struct gpio_chip *gc, struct device *dev);struct gpio_desc *gpiochip_get_desc (struct gpio_chip *gc,unsigned int hwnum);const char *gpiod_get_label (struct gpio_desc *desc); -/* -* Return the GPIO number of the passed descriptor relative to its chip -*/ -static inline int gpiod_hwgpio (const struct gpio_desc *desc) -{ -return desc - &desc->gdev->descs[0 ]; -} -/* With descriptor prefix */ #define __gpiod_pr (level, desc, fmt, ...) \
include/linux/gpio/consumer.h +2 -0
@@ -171,6 +171,8 @@ int gpiod_set_consumer_name(struct gpio_desc *desc, const char *name);struct gpio_desc *gpio_to_desc (unsigned gpio);int desc_to_gpio (const struct gpio_desc *desc); +int gpiod_hwgpio (const struct gpio_desc *desc); + struct gpio_desc *fwnode_gpiod_get_index(struct fwnode_handle *fwnode, const char *con_id, int index, enum gpiod_flags flags,
Signature · 1 line
2.48.1
PATCH 3/3 gpio: aspeed: remove unneeded include
In reply to Bartosz GolaszewskiFrom: Bartosz Golaszewski <[email protected]>
This driver no longer uses any symbols from the GPIOLIB internal header. We can now drop the gpiolib.h include.
--- drivers/gpio/gpio-aspeed.c | 1 - 1 file changed, 1 deletion(-)
drivers/gpio/gpio-aspeed.c +0 -1
@@ -29,7 +29,6 @@* access to some GPIOs and to arbitrate between coprocessor and ARM. */ #include <linux/gpio/consumer.h> -#include "gpiolib.h" /* Non-constant mask variant of FIELD_GET() and FIELD_PREP() */ #define field_get (_mask, _reg) (((_reg) & (_mask)) >> (ffs(_mask) - 1))
Signature · 1 line
2.48.1
Quoted 7 lines · Bartosz Golaszewski
gpiolib.his a header internal to the GPIO core. Drivers should not include them. gpio-aspeed only needs to be able to determine the hardware offset of the GPIO given the descriptor. Expose the relevant symbol in the consumer header which allows us to stop pulling in the private one.Signed-off-by Bartosz Golaszewski <[email protected]>
For the series:
Quoted 7 lines · Bartosz Golaszewski
gpiolib.his a header internal to the GPIO core. Drivers should not include them. gpio-aspeed only needs to be able to determine the hardware offset of the GPIO given the descriptor. Expose the relevant symbol in the consumer header which allows us to stop pulling in the private one.Signed-off-by Bartosz Golaszewski <[email protected]>
Thanks for cleaning this up!
Yours,
Linus Walleij
Bartosz Golaszewski
AppliedFrom: Bartosz Golaszewski <[email protected]>
Quoted 8 lines · Bartosz Golaszewski
gpiolib.his a header internal to the GPIO core. Drivers should not include them. gpio-aspeed only needs to be able to determine the hardware offset of the GPIO given the descriptor. Expose the relevant symbol in the consumer header which allows us to stop pulling in the private one.[...]
Applied, thanks!
[1/3] gpio: rename gpio_chip_hwgpio() to gpiod_hwgpio()
https://git.kernel.org/brgl/linux/c/df900536e85819f6168783d5f6b3908d47811fdd [2/3] gpio: export gpiod_hwgpio() https://git.kernel.org/brgl/linux/c/d19f6451c6feefd6537b97efa5f3859681f243cb [3/3] gpio: aspeed: remove unneeded include https://git.kernel.org/brgl/linux/c/0efa5b2ca6fa7baab4c523b34cfb9495ec143d61
Best regards,
Signature · 1 line
Bartosz Golaszewski <[email protected]>