nvmem: core: Mark nWP GPIO as non-exclusive
Subsystems (3)
PATCH 1/1 nvmem: core: Mark nWP GPIO as non-exclusive
Mark the nWP GPIO as non-exclusive, because there is hardware in the field which has multiple AT24 EEPROMs with nWP GPIO line tied to a single GPIO. This allows such hardware to be described in DT and the nWP GPIO operated via NVMEM force_ro sysfs attribute.
Note that GPIOD_FLAGS_BIT_NONEXCLUSIVE is a deprecated flag and should not be used, but thus far there seems to be no replacement.
---
Cc: Arnd Bergmann <[email protected]>
Cc: Bartosz Golaszewski <[email protected]>
Cc: Greg Kroah-Hartman <[email protected]>
Cc: Srinivas Kandagatla <[email protected]>
Cc: [email protected]
Cc: [email protected]
--- drivers/nvmem/core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/nvmem/core.c +2 -1
@@ -928,7 +928,8 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)if (!config->ignore_wp) nvmem->wp_gpio =gpiod_get_optional (config->dev,"wp" , -GPIOD_OUT_HIGH ); +GPIOD_OUT_HIGH | +GPIOD_FLAGS_BIT_NONEXCLUSIVE );if (IS_ERR (nvmem->wp_gpio)) { rval =PTR_ERR (nvmem->wp_gpio); nvmem->wp_gpio =NULL ;
Signature · 1 line
2.53.0
Quoted 9 lines · Marek Vasut
Mark the nWP GPIO as non-exclusive, because there is hardware in the field which has multiple AT24 EEPROMs with nWP GPIO line tied to a single GPIO. This allows such hardware to be described in DT and the nWP GPIO operated via NVMEM
force_rosysfs attribute.Note that
GPIOD_FLAGS_BIT_NONEXCLUSIVEis a deprecated flag and should not be used, but thus far there seems to be no replacement.
There is a replacement now. It lives under drivers/gpio/gpiolib-shared.c and drivers/gpio/gpio-shared-proxy.c. Though the voting mechanism I implemented is hard-coded to drive the line high if there's at least one consumer sharing the line that votes high. I'm now thinking that this may be too rigid as yesterday, within two hours I had two submissions wanting to do it the other way around
- drive the line low if there's at least one consumer that wants it low.
I'll try to modify the gpio-shared-proxy driver to take into account the value set when the line is first requested and treat it as the "default" in the voting mechanism. IOW: when the first user requests it out-high, we'll drive it low on the first user that votes for low and drive it high again when the last user drivers it high. This should work for both the Qualcomm shared GPIOs for audio use-cases and the WP pin here as well as the SCL recovery shared GPIO we have in I2C.
With that said: I'd prefer you not set the GPIOD_FLAGS_BIT_NONEXCLUSIVE and see if you can make gpio-shared-proxy work for you instead. I'll submit something soon for you to test.
Bart
Quoted 20 lines · Bartosz Golaszewski
Quoted 9 lines · Marek Vasut
Mark the nWP GPIO as non-exclusive, because there is hardware in the field which has multiple AT24 EEPROMs with nWP GPIO line tied to a single GPIO. This allows such hardware to be described in DT and the nWP GPIO operated via NVMEM
force_rosysfs attribute.Note that
GPIOD_FLAGS_BIT_NONEXCLUSIVEis a deprecated flag and should not be used, but thus far there seems to be no replacement.There is a replacement now. It lives under
drivers/gpio/gpiolib-shared.canddrivers/gpio/gpio-shared-proxy.c. Though the voting mechanism I implemented is hard-coded to drive the line high if there's at least one consumer sharing the line that votes high. I'm now thinking that this may be too rigid as yesterday, within two hours I had two submissions wanting to do it the other way around
- drive the line low if there's at least one consumer that wants it low.
Quoted 8 lines
I'll try to modify the gpio-shared-proxy driver to take into account the value set when the line is first requested and treat it as the "default" in the voting mechanism. IOW: when the first user requests it out-high, we'll drive it low on the first user that votes for low and drive it high again when the last user drivers it high. This should work for both the Qualcomm shared GPIOs for audio use-cases and the WP pin here as well as the SCL recovery shared GPIO we have in I2C.
Shouldn't the polarity inversion be handled by DT GPIO_ACTIVE_* flags instead ?
Quoted 29 lines · Bartosz Golaszewski
Quoted 9 lines · Marek Vasut
Mark the nWP GPIO as non-exclusive, because there is hardware in the field which has multiple AT24 EEPROMs with nWP GPIO line tied to a single GPIO. This allows such hardware to be described in DT and the nWP GPIO operated via NVMEM
force_rosysfs attribute.Note that
GPIOD_FLAGS_BIT_NONEXCLUSIVEis a deprecated flag and should not be used, but thus far there seems to be no replacement.There is a replacement now. It lives under
drivers/gpio/gpiolib-shared.canddrivers/gpio/gpio-shared-proxy.c. Though the voting mechanism I implemented is hard-coded to drive the line high if there's at least one consumer sharing the line that votes high. I'm now thinking that this may be too rigid as yesterday, within two hours I had two submissions wanting to do it the other way around
- drive the line low if there's at least one consumer that wants it low.I'll try to modify the gpio-shared-proxy driver to take into account the value set when the line is first requested and treat it as the "default" in the voting mechanism. IOW: when the first user requests it out-high, we'll drive it low on the first user that votes for low and drive it high again when the last user drivers it high. This should work for both the Qualcomm shared GPIOs for audio use-cases and the WP pin here as well as the SCL recovery shared GPIO we have in I2C.
Quoted 3 lines
With that said: I'd prefer you not set the
GPIOD_FLAGS_BIT_NONEXCLUSIVEand see if you can make gpio-shared-proxy work for you instead. I'll submit something soon for you to test.
I'm sorry for my late reply, I was completely overwhelmed by emails.
I tried to look into the gpio-shared* , but I couldn't figure out how to describe it in DT. Do you have any examples?
Take for example this DT snippet:
gpio: gpio-controller { ... };
i2c {
eeprom@0 {
wp-gpios = <&gpio 0 0>;
...};
eeprom@1 {
wp-gpios = <&gpio 0 0>;
... };
};
I assume there has to be some new glue node between the eeproms and the GPIO controller somewhere ?
Thank you for your help !
Signature · 2 lines
Best regards, Marek Vasut
Quoted 55 lines · Marek Vasut
Quoted 29 lines · Bartosz Golaszewski
Quoted 9 lines · Marek Vasut
Mark the nWP GPIO as non-exclusive, because there is hardware in the field which has multiple AT24 EEPROMs with nWP GPIO line tied to a single GPIO. This allows such hardware to be described in DT and the nWP GPIO operated via NVMEM
force_rosysfs attribute.Note that
GPIOD_FLAGS_BIT_NONEXCLUSIVEis a deprecated flag and should not be used, but thus far there seems to be no replacement.There is a replacement now. It lives under
drivers/gpio/gpiolib-shared.canddrivers/gpio/gpio-shared-proxy.c. Though the voting mechanism I implemented is hard-coded to drive the line high if there's at least one consumer sharing the line that votes high. I'm now thinking that this may be too rigid as yesterday, within two hours I had two submissions wanting to do it the other way around
- drive the line low if there's at least one consumer that wants it low.I'll try to modify the gpio-shared-proxy driver to take into account the value set when the line is first requested and treat it as the "default" in the voting mechanism. IOW: when the first user requests it out-high, we'll drive it low on the first user that votes for low and drive it high again when the last user drivers it high. This should work for both the Qualcomm shared GPIOs for audio use-cases and the WP pin here as well as the SCL recovery shared GPIO we have in I2C.
Quoted 3 lines
With that said: I'd prefer you not set the
GPIOD_FLAGS_BIT_NONEXCLUSIVEand see if you can make gpio-shared-proxy work for you instead. I'll submit something soon for you to test.I'm sorry for my late reply, I was completely overwhelmed by emails.
I tried to look into the gpio-shared* , but I couldn't figure out how to describe it in DT. Do you have any examples?
Take for example this DT snippet:
gpio: gpio-controller { ... };
i2c { eeprom@0 { wp-gpios = <&gpio 0 0>; ... }; eeprom@1 { wp-gpios = <&gpio 0 0>; ... }; };
Quoted 5 lines
I assume there has to be some new glue node between the eeproms and the GPIO controller somewhere ?
Thank you for your help !
No, this is literally how you do it. If you enable HAVE_SHARED_GPIOs and DEBUG_GPIO, you should see it being picked up in the kernel log.
Bartosz
On 7/24/26 9:30 AM, Bartosz Golaszewski wrote:
Hello Bartosz,
Quoted 19 lines
Quoted 19 lines
I tried to look into the gpio-shared* , but I couldn't figure out how to describe it in DT. Do you have any examples?
Take for example this DT snippet:
gpio: gpio-controller { ... };
i2c { eeprom@0 { wp-gpios = <&gpio 0 0>; ... }; eeprom@1 { wp-gpios = <&gpio 0 0>; ... }; };
Quoted 8 lines
Quoted 5 lines
I assume there has to be some new glue node between the eeproms and the GPIO controller somewhere ?
Thank you for your help !
No, this is literally how you do it. If you enable
HAVE_SHARED_GPIOsandDEBUG_GPIO, you should see it being picked up in the kernel log.
Ah, HAVE_SHARED_GPIOS is what I did not have enabled. Is there any reason why this is not enabled by default ?
Thank you !
Quoted 26 lines · Marek Vasut
On 7/24/26 9:30 AM, Bartosz Golaszewski wrote:
Hello Bartosz,
Quoted 22 lines
Quoted 22 lines
I tried to look into the gpio-shared* , but I couldn't figure out how to describe it in DT. Do you have any examples?
Take for example this DT snippet:
gpio: gpio-controller { ... };
i2c { eeprom@0 { wp-gpios = <&gpio 0 0>; ... }; eeprom@1 { wp-gpios = <&gpio 0 0>; ... }; };I assume there has to be some new glue node between the eeproms and the GPIO controller somewhere ?
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Thank you for your help !
No, this is literally how you do it. If you enable
HAVE_SHARED_GPIOsandDEBUG_GPIO, you should see it being picked up in the kernel log.Ah,
HAVE_SHARED_GPIOSis what I did not have enabled. Is there any reason why this is not enabled by default ?
It will be. I'm doing it gradually. It's enabled for Qualcomm platforms by default and - by extension - in arm64 defconfig. I plan to enable it for other platforms and architectures too, I just don't want to rush it. Enabling it for arm64 defconfig had caused quite a lot of regressions a few months ago so I prefer to be careful.
What platform are you running this on?
Bart
On 7/27/26 3:10 PM, Bartosz Golaszewski wrote:
Hello Bartosz,
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines
No, this is literally how you do it. If you enable
HAVE_SHARED_GPIOsandDEBUG_GPIO, you should see it being picked up in the kernel log.Ah,
HAVE_SHARED_GPIOSis what I did not have enabled. Is there any reason why this is not enabled by default ?
Quoted 7 lines
It will be. I'm doing it gradually. It's enabled for Qualcomm platforms by default and - by extension - in arm64 defconfig. I plan to enable it for other platforms and architectures too, I just don't want to rush it. Enabling it for arm64 defconfig had caused quite a lot of regressions a few months ago so I prefer to be careful.
What platform are you running this on?
NXP i.MX8M Nano (arm64)
Quoted 10 lines · Marek Vasut
On 7/27/26 3:10 PM, Bartosz Golaszewski wrote:
Hello Bartosz,
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines
No, this is literally how you do it. If you enable
HAVE_SHARED_GPIOsandDEBUG_GPIO, you should see it being picked up in the kernel log.Ah,
HAVE_SHARED_GPIOSis what I did not have enabled. Is there any reason why this is not enabled by default ?
Quoted 9 lines
Quoted 7 lines
It will be. I'm doing it gradually. It's enabled for Qualcomm platforms by default and - by extension - in arm64 defconfig. I plan to enable it for other platforms and architectures too, I just don't want to rush it. Enabling it for arm64 defconfig had caused quite a lot of regressions a few months ago so I prefer to be careful.
What platform are you running this on?
NXP i.MX8M Nano (arm64)
Just consider sending the following once you can make this work for you?
arch/arm64/Kconfig.platforms +1 -0
@@ -281,6 +281,7 @@ config ARCH_MXC select PM_GENERIC_DOMAINS select SOC_BUS select TIMER_IMX_SYS_CTR + select HAVE_SHARED_GPIOS help This enables support for the ARMv8 based SoCs in the NXP i.MX family.
Thanks,
Bartosz
On 7/28/26 10:32 AM, Bartosz Golaszewski wrote:
Hello Bartosz,
Quoted 17 lines
Quoted 9 lines
Quoted 7 lines
It will be. I'm doing it gradually. It's enabled for Qualcomm platforms by default and - by extension - in arm64 defconfig. I plan to enable it for other platforms and architectures too, I just don't want to rush it. Enabling it for arm64 defconfig had caused quite a lot of regressions a few months ago so I prefer to be careful.
What platform are you running this on?
NXP i.MX8M Nano (arm64)
Just consider sending the following once you can make this work for you?
arch/arm64/Kconfig.platforms +0
-0
arch/arm64/Kconfig.platforms config ARCH_MXC · line 287
Quoted 7 lines
arch/arm64/Kconfig.platforms +1
-0@@ -281,6 +281,7 @@ config ARCH_MXC select PM_GENERIC_DOMAINS select SOC_BUS select TIMER_IMX_SYS_CTR + select HAVE_SHARED_GPIOS help This enables support for the ARMv8 based SoCs in the NXP i.MX family.
Will do (sorted alphabetically).
Thank you !