diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2024-01-12 13:35:31 -0800 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2024-01-12 13:35:31 -0800 |
commit | 576db73424305036a6aa9e40daf7109742fbb1df (patch) | |
tree | 5410d43ebeadca2ca3a660f73b33ffe11a147ef3 /include/linux | |
parent | 61f4c3e6711477b8a347ca5fe89e5e6613e0a147 (diff) | |
parent | 1979a28075470ef82472a5656ecc969f901e0d3b (diff) | |
download | lwn-576db73424305036a6aa9e40daf7109742fbb1df.tar.gz lwn-576db73424305036a6aa9e40daf7109742fbb1df.zip |
Merge tag 'gpio-updates-for-v6.8-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux
Pull gpio updates from Bartosz Golaszewski:
"We have two new drivers, an assortment of updates and cleanups to many
others, and first part of the big rework of the core GPIOLIB that's
currently underway.
Add to that some code shrink in the character device module and
updates to DT bindings and that's pretty much it.
Core GPIOLIB:
- protect the global list of GPIO devices with a read-write semaphore
as it is rarely modified but can be traversed by multiple readers
at once
- remove GPIO devices from the global list when they are
*unregistered* and not when they are *released* (which only happens
when the last reference is dropped) as this may lead to a
successful lookup of an unregistered device
- remove the unnecessary "extra_checks" switch
- rename functions that are called with a lock taken
- remove duplicate includes
Character device handling:
- use locking guards to reduce the code size
- allocate the big linereq structure using the more suitable
kvzalloc()
- redulce the size of critical sections
- improve documentation
- move the debounce_period_us field out of struct gpio_desc
New drivers:
- Nuvoton NPCM SGPIO driver for BMC NPCM7xx/NPCM8xx
- Realtek DHC (Digital Home Center) SoC GPIO driver
Driver improvements:
- replace gpiochip_is_requested() with a safer alternative in the
form of gpiochip_dup_line_label() as the former returns a pointer
to a string that can be deleted
- implement the dbg_show() callback in gpio-sim
- improve the coding style for local variables by removing
unnecessary tabs
- use generic device properties instead of OF variants in gpio-mmio
- use the preferred coding style for __free() in gpio-mockup
- reuse PM ops from the gpio-tangier in gpio-elkhartlake
- rework PM and use cleanup helpers in gpio-tangier
- fix the EIC configuration in gpio-pmic-eic-sprd
- remove the unneeded call to platform_set_drvdata() in gpio-sifive
- use generic GPIO helpers for driver callbacks in gpio-dwapb
- add clock support on certain pins of gpio-ixp4xx
- don't use the core-specific DEBUG_GPIO switch in drivers
- kerneldoc improvements
DT bindings:
- add bindings for the new Realtek and Nuvoton devices
- allow gpio-ranges in gpio-dwapb
- support GPIO hogs in gpio-rockchip
- describe the label property in gpio-zynqmp-modepin
Other:
- header cleanups
- forward declarations cleanups"
* tag 'gpio-updates-for-v6.8-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux: (55 commits)
gpiolib: replace the GPIO device mutex with a read-write semaphore
gpiolib: remove the GPIO device from the list when it's unregistered
gpio: nuvoton: Add Nuvoton NPCM sgpio driver
dt-bindings: gpio: add NPCM sgpio driver bindings
gpio: rtd: Add support for Realtek DHC(Digital Home Center) RTD SoCs
dt-bindings: gpio: realtek: Add realtek,rtd-gpio
gpio: pmic-eic-sprd: Configure the bit corresponding to the EIC through offset
gpio: dwapb: Use generic request, free and set_config
gpio: sysfs: drop tabs from local variable declarations
gpiolib: drop tabs from local variable declarations
gpiolib: remove extra_checks
gpio: tps65219: don't use CONFIG_DEBUG_GPIO
gpiolib: cdev: replace locking wrappers for gpio_device with guards
gpiolib: cdev: replace locking wrappers for config_mutex with guards
gpiolib: cdev: allocate linereq using kvzalloc()
gpiolib: cdev: include overflow.h
gpiolib: cdev: reduce locking in gpio_desc_to_lineinfo()
gpiolib: cdev: improve documentation of get/set values
gpiolib: cdev: fully adopt guard() and scoped_guard()
gpiolib: remove debounce_period_us from struct gpio_desc
...
Diffstat (limited to 'include/linux')
-rw-r--r-- | include/linux/gpio/driver.h | 43 | ||||
-rw-r--r-- | include/linux/property.h | 26 |
2 files changed, 57 insertions, 12 deletions
diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h index 0aed62f0c633..e846bd4e7559 100644 --- a/include/linux/gpio/driver.h +++ b/include/linux/gpio/driver.h @@ -531,19 +531,40 @@ struct gpio_chip { #endif /* CONFIG_OF_GPIO */ }; -const char *gpiochip_is_requested(struct gpio_chip *gc, unsigned int offset); +char *gpiochip_dup_line_label(struct gpio_chip *gc, unsigned int offset); + + +struct _gpiochip_for_each_data { + const char **label; + unsigned int *i; +}; + +DEFINE_CLASS(_gpiochip_for_each_data, + struct _gpiochip_for_each_data, + if (*_T.label) kfree(*_T.label), + ({ + struct _gpiochip_for_each_data _data = { label, i }; + *_data.i = 0; + _data; + }), + const char **label, int *i) /** * for_each_requested_gpio_in_range - iterates over requested GPIOs in a given range - * @chip: the chip to query - * @i: loop variable - * @base: first GPIO in the range - * @size: amount of GPIOs to check starting from @base - * @label: label of current GPIO + * @_chip: the chip to query + * @_i: loop variable + * @_base: first GPIO in the range + * @_size: amount of GPIOs to check starting from @base + * @_label: label of current GPIO */ -#define for_each_requested_gpio_in_range(chip, i, base, size, label) \ - for (i = 0; i < size; i++) \ - if ((label = gpiochip_is_requested(chip, base + i)) == NULL) {} else +#define for_each_requested_gpio_in_range(_chip, _i, _base, _size, _label) \ + for (CLASS(_gpiochip_for_each_data, _data)(&_label, &_i); \ + *_data.i < _size; \ + (*_data.i)++, kfree(*(_data.label)), *_data.label = NULL) \ + if ((*_data.label = \ + gpiochip_dup_line_label(_chip, _base + *_data.i)) == NULL) {} \ + else if (IS_ERR(*_data.label)) {} \ + else /* Iterates over all requested GPIO of the given @chip */ #define for_each_requested_gpio(chip, i, label) \ @@ -701,7 +722,6 @@ int gpiochip_irqchip_add_domain(struct gpio_chip *gc, #else #include <asm/bug.h> -#include <asm/errno.h> static inline int gpiochip_irqchip_add_domain(struct gpio_chip *gc, struct irq_domain *domain) @@ -786,11 +806,10 @@ struct gpio_device *gpiod_to_gpio_device(struct gpio_desc *desc); /* struct gpio_device getters */ int gpio_device_get_base(struct gpio_device *gdev); +const char *gpio_device_get_label(struct gpio_device *gdev); #else /* CONFIG_GPIOLIB */ -#include <linux/err.h> - #include <asm/bug.h> static inline struct gpio_chip *gpiod_to_chip(const struct gpio_desc *desc) diff --git a/include/linux/property.h b/include/linux/property.h index 97f901c0914e..1f1166133e6b 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -80,6 +80,16 @@ int fwnode_property_match_string(const struct fwnode_handle *fwnode, bool fwnode_device_is_available(const struct fwnode_handle *fwnode); +static inline bool fwnode_device_is_big_endian(const struct fwnode_handle *fwnode) +{ + if (fwnode_property_present(fwnode, "big-endian")) + return true; + if (IS_ENABLED(CONFIG_CPU_BIG_ENDIAN) && + fwnode_property_present(fwnode, "native-endian")) + return true; + return false; +} + static inline bool fwnode_device_is_compatible(const struct fwnode_handle *fwnode, const char *compat) { @@ -87,6 +97,22 @@ bool fwnode_device_is_compatible(const struct fwnode_handle *fwnode, const char } /** + * device_is_big_endian - check if a device has BE registers + * @dev: Pointer to the struct device + * + * Returns: true if the device has a "big-endian" property, or if the kernel + * was compiled for BE *and* the device has a "native-endian" property. + * Returns false otherwise. + * + * Callers would nominally use ioread32be/iowrite32be if + * device_is_big_endian() == true, or readl/writel otherwise. + */ +static inline bool device_is_big_endian(const struct device *dev) +{ + return fwnode_device_is_big_endian(dev_fwnode(dev)); +} + +/** * device_is_compatible - match 'compatible' property of the device with a given string * @dev: Pointer to the struct device * @compat: The string to match 'compatible' property with |