gpio: remove gpiod_toggle_active_low()
Subsystems (9)
cover gpio: remove gpiod_toggle_active_low()
From: Bartosz Golaszewski <[email protected]>
The semantics of gpiod_toggle_active_low() are just bad and in almost all cases require users to check the current state anyway. Let's replace it with something clearer and more useful.
For getting this upstream: I'm thinking that I should apply patch 1/5, provide other subsystems with an immutable tag and then we can apply patch 5/5 for the next release once first four are in master.
Bartosz Golaszewski (5):
gpiolib: provide gpiod_set_active_[low/high]()
mtd: rawnand: ingenic: use gpiod_set_active_high()
mmc: slot-gpio: use gpiod_set_active_[low|high]() platform/x86: int3472/discrete: use gpiod_set_active_low()
gpiolib: remove gpiod_toggle_active_low()
drivers/gpio/gpiolib.c | 21 ++++++++++++++----- drivers/mmc/core/slot-gpio.c | 11 +++++----- .../mtd/nand/raw/ingenic/ingenic_nand_drv.c | 5 ++--- .../x86/intel/int3472/clk_and_regulator.c | 2 +- drivers/platform/x86/intel/int3472/led.c | 2 +- include/linux/gpio/consumer.h | 11 ++++++++-- 6 files changed, 34 insertions(+), 18 deletions(-)
Signature · 1 line
2.39.2
PATCH 1/5 gpiolib: provide gpiod_set_active_[low/high]()
From: Bartosz Golaszewski <[email protected]>
Out current interface for changing line polarity is quite cumbersome to use as it only "toggles" the current state instead of deterministically setting it. Because of that all but one user in the kernel first need check the current state anyway. Let's provide two new functions that allow users to set this value explicitly with the aim of removing the existing function.
--- drivers/gpio/gpiolib.c | 22 ++++++++++++++++++++++ include/linux/gpio/consumer.h | 14 ++++++++++++++ 2 files changed, 36 insertions(+)
drivers/gpio/gpiolib.c +22 -0
@@ -2725,6 +2725,28 @@ void gpiod_toggle_active_low(struct gpio_desc *desc) }EXPORT_SYMBOL_GPL (gpiod_toggle_active_low); +/** +* gpiod_set_active_low() - set the GPIO as active-low +* @desc: the GPIO descriptor to set the active-low setting for +*/ +void gpiod_set_active_low (struct gpio_desc *desc) +{ +VALIDATE_DESC_VOID (desc); +set_bit (FLAG_ACTIVE_LOW , &desc->flags); +} +EXPORT_SYMBOL_GPL (gpiod_set_active_low); + +/** +* gpiod_set_active_high() - set the GPIO as active-high +* @desc: the GPIO descriptor to set the active-low setting for +*/ +void gpiod_set_active_high (struct gpio_desc *desc) +{ +VALIDATE_DESC_VOID (desc); +clear_bit (FLAG_ACTIVE_LOW , &desc->flags); +} +EXPORT_SYMBOL_GPL (gpiod_set_active_high); +static int gpio_chip_get_value (struct gpio_chip *gc,const struct gpio_desc *desc) {return gc->get ? gc->get (gc,gpio_chip_hwgpio (desc)) : -EIO ;
include/linux/gpio/consumer.h +14 -0
@@ -160,6 +160,8 @@ int gpiod_set_raw_array_value_cansleep(unsigned int array_size,int gpiod_set_config (struct gpio_desc *desc,unsigned long config);int gpiod_set_debounce (struct gpio_desc *desc,unsigned int debounce);void gpiod_toggle_active_low (struct gpio_desc *desc); +void gpiod_set_active_low (struct gpio_desc *desc); +void gpiod_set_active_high (struct gpio_desc *desc);int gpiod_is_active_low (const struct gpio_desc *desc);int gpiod_cansleep (const struct gpio_desc *desc);
@@ -499,6 +501,18 @@ static inline void gpiod_toggle_active_low(struct gpio_desc *desc)WARN_ON (desc); } +static inline void gpiod_set_active_low(struct gpio_desc *desc +{ +/* GPIO can never have been requested */ +WARN_ON (desc); +} + +static inline void gpiod_set_active_high (struct gpio_desc *desc) +{ +/* GPIO can never have been requested */ +WARN_ON (desc); +} +static inline int gpiod_is_active_low (const struct gpio_desc *desc) {/* GPIO can never have been requested */
Signature · 1 line
2.39.2
PATCH 2/5 mtd: rawnand: ingenic: use gpiod_set_active_high()
In reply to Bartosz GolaszewskiFrom: Bartosz Golaszewski <[email protected]>
Use the new, less cumbersome interface for setting the GPIO as active-high that doesn't require first checking the current state.
--- drivers/mtd/nand/raw/ingenic/ingenic_nand_drv.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/mtd/nand/raw/ingenic/ingenic_nand_drv.c +2 -3
@@ -388,9 +388,8 @@ static int ingenic_nand_init_chip(struct platform_device *pdev,* here for older DTs so we can re-use the generic nand_gpio_waitrdy() * helper, and be consistent with what other drivers do. */ -if (of_machine_is_compatible ("qi,lb60" ) && -gpiod_is_active_low (nand->busy_gpio)) -gpiod_toggle_active_low (nand->busy_gpio); +if (of_machine_is_compatible ("qi,lb60" )) +gpiod_set_active_high (nand->busy_gpio); nand->wp_gpio =devm_gpiod_get_optional (dev,"wp" ,GPIOD_OUT_LOW );
Signature · 1 line
2.39.2
PATCH 3/5 mmc: slot-gpio: use gpiod_set_active_[low|high]()
In reply to Bartosz GolaszewskiFrom: Bartosz Golaszewski <[email protected]>
We have new, less cumbersome and clearer interfaces for controlling GPIO polarity. Use them in the MMC code.
--- drivers/mmc/core/slot-gpio.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/mmc/core/slot-gpio.c +5 -6
@@ -204,12 +204,11 @@ int mmc_gpiod_request_cd(struct mmc_host *host, const char *con_id, }/* override forces default (active-low) polarity ... */ -if (override_active_level && !gpiod_is_active_low (desc)) -gpiod_toggle_active_low (desc); - +if (override_active_level) +gpiod_set_active_low (desc);/* ... or active-high */ -if (host->caps2 &MMC_CAP2_CD_ACTIVE_HIGH ) -gpiod_toggle_active_low (desc); +else if (host->caps2 &MMC_CAP2_CD_ACTIVE_HIGH ) +gpiod_set_active_high (desc); ctx->cd_gpio = desc;
@@ -256,7 +255,7 @@ int mmc_gpiod_request_ro(struct mmc_host *host, const char *con_id, }if (host->caps2 &MMC_CAP2_RO_ACTIVE_HIGH ) -gpiod_toggle_active_low (desc); +gpiod_set_active_high (desc); ctx->ro_gpio = desc;
Signature · 1 line
2.39.2
PATCH 4/5 platform/x86: int3472/discrete: use gpiod_set_active_low()
In reply to Bartosz GolaszewskiFrom: Bartosz Golaszewski <[email protected]>
Use the new polarity setter instead of the more cumbersome toggle function.
--- drivers/platform/x86/intel/int3472/clk_and_regulator.c | 2 +- drivers/platform/x86/intel/int3472/led.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/platform/x86/intel/int3472/clk_and_regulator.c +1 -1
@@ -183,7 +183,7 @@ int skl_int3472_register_gpio_clock(struct int3472_discrete_device *int3472, }if (polarity ==GPIO_ACTIVE_LOW ) -gpiod_toggle_active_low (int3472->clock.ena_gpio); +gpiod_set_active_low (int3472->clock.ena_gpio);/* Ensure the pin is in output mode and non-active state */ gpiod_direction_output (int3472->clock.ena_gpio,0 );
drivers/platform/x86/intel/int3472/led.c +1 -1
@@ -32,7 +32,7 @@ int skl_int3472_register_pled(struct int3472_discrete_device *int3472, "getting privacy LED GPIO\n");if (polarity ==GPIO_ACTIVE_LOW ) -gpiod_toggle_active_low (int3472->pled.gpio); +gpiod_set_active_low (int3472->pled.gpio);/* Ensure the pin is in output mode and non-active state */ gpiod_direction_output (int3472->pled.gpio,0 );
Signature · 1 line
2.39.2
PATCH 5/5 gpiolib: remove gpiod_toggle_active_low()
In reply to Bartosz GolaszewskiFrom: Bartosz Golaszewski <[email protected]>
With all users now having switched to gpiod_set_active_[low|high](), we can now remove gpiod_toggle_active_low().
--- drivers/gpio/gpiolib.c | 11 ----------- include/linux/gpio/consumer.h | 7 ------- 2 files changed, 18 deletions(-)
drivers/gpio/gpiolib.c +0 -11
@@ -2714,17 +2714,6 @@ int gpiod_is_active_low(const struct gpio_desc *desc) }EXPORT_SYMBOL_GPL (gpiod_is_active_low); -/** -* gpiod_toggle_active_low - toggle whether a GPIO is active-low or not -* @desc: the gpio descriptor to change -*/ -void gpiod_toggle_active_low (struct gpio_desc *desc) -{ -VALIDATE_DESC_VOID (desc); -change_bit (FLAG_ACTIVE_LOW , &desc->flags); -} -EXPORT_SYMBOL_GPL (gpiod_toggle_active_low); -/** * gpiod_set_active_low() - set the GPIO as active-low * @desc: the GPIO descriptor to set the active-low setting for
include/linux/gpio/consumer.h +0 -7
@@ -159,7 +159,6 @@ int gpiod_set_raw_array_value_cansleep(unsigned int array_size,int gpiod_set_config (struct gpio_desc *desc,unsigned long config);int gpiod_set_debounce (struct gpio_desc *desc,unsigned int debounce); -void gpiod_toggle_active_low (struct gpio_desc *desc);void gpiod_set_active_low (struct gpio_desc *desc);void gpiod_set_active_high (struct gpio_desc *desc);
@@ -495,12 +494,6 @@ static inline int gpiod_set_debounce(struct gpio_desc *desc, unsigned int debounreturn -ENOSYS ; } -static inline void gpiod_toggle_active_low (struct gpio_desc *desc) -{ -/* GPIO can never have been requested */ -WARN_ON (desc); -} - static inline void gpiod_set_active_low(struct gpio_desc *desc {/* GPIO can never have been requested */
Signature · 1 line
2.39.2
Re: [PATCH 2/5] mtd: rawnand: ingenic: use gpiod_set_active_high()
In reply to Bartosz GolaszewskiHi,
Le mercredi 13 septembre 2023 à 13:49 +0200, Bartosz Golaszewski a écrit :
Quoted 6 lines
From: Bartosz Golaszewski <[email protected]>
Use the new, less cumbersome interface for setting the GPIO as active-high that doesn't require first checking the current state.
Signed-off-by Bartosz Golaszewski <[email protected]>
Works for me.
Cheers,
-Paul
Quoted 24 lines
---
drivers/mtd/nand/raw/ingenic/ingenic_nand_drv.c | 5 ++---1 file changed, 2 insertions(+), 3 deletions(-)drivers/mtd/nand/raw/ingenic/ingenic_nand_drv.c +2
-3@@ -388,9 +388,8 @@ static int ingenic_nand_init_chip(structplatform_device *pdev, * here for older DTs so we can re-use the generic nand_gpio_waitrdy() * helper, and be consistent with what other drivers do. */ - if (of_machine_is_compatible("qi,lb60") && - gpiod_is_active_low(nand->busy_gpio)) - gpiod_toggle_active_low(nand->busy_gpio); + if (of_machine_is_compatible("qi,lb60")) + gpiod_set_active_high(nand->busy_gpio);
nand->wp_gpio =devm_gpiod_get_optional(dev, "wp", GPIOD_OUT_LOW);
Re: [PATCH 3/5] mmc: slot-gpio: use gpiod_set_active_[low|high]()
In reply to Bartosz GolaszewskiQuoted 6 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
We have new, less cumbersome and clearer interfaces for controlling GPIO polarity. Use them in the MMC code.
Signed-off-by Bartosz Golaszewski <[email protected]>
I like the looks of the code better, obviously but this looks like this for a reason unfortunately.
See the following from Documentation/devicetree/bindings/mmc/mmc-controller.yaml:
# CD and WP lines can be implemented on the hardware in one of two # ways: as GPIOs, specified in cd-gpios and wp-gpios properties, or
# as dedicated pins. Polarity of dedicated pins can be specified, # using *-inverted properties. GPIO polarity can also be specified # using the GPIO_ACTIVE_LOW flag. This creates an ambiguity in the # latter case. We choose to use the XOR logic for GPIO CD and WP # lines. This means, the two properties are "superimposed," for # example leaving the GPIO_ACTIVE_LOW flag clear and specifying the # respective *-inverted property property results in a # double-inversion and actually means the "normal" line polarity is # in effect.
Will you still provide the desired "double inversion" after this patch?
Yours,
Linus Walleij
Re: [PATCH 3/5] mmc: slot-gpio: use gpiod_set_active_[low|high]()
Quoted 18 lines · Linus Walleij
Quoted 6 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
We have new, less cumbersome and clearer interfaces for controlling GPIO polarity. Use them in the MMC code.
Signed-off-by Bartosz Golaszewski <[email protected]>I like the looks of the code better, obviously but this looks like this for a reason unfortunately.
See the following from
Documentation/devicetree/bindings/mmc/mmc-controller.yaml:# CD and WP lines can be implemented on the hardware in one of two # ways: as GPIOs, specified in cd-gpios and wp-gpios properties, or
Quoted 10 lines
# as dedicated pins. Polarity of dedicated pins can be specified, # using *-inverted properties. GPIO polarity can also be specified # using the GPIO_ACTIVE_LOW flag. This creates an ambiguity in the # latter case. We choose to use the XOR logic for GPIO CD and WP # lines. This means, the two properties are "superimposed," for # example leaving the GPIO_ACTIVE_LOW flag clear and specifying the # respective *-inverted property property results in a # double-inversion and actually means the "normal" line polarity is # in effect.
I hate it, thanks. :)
Quoted 2 lines
Will you still provide the desired "double inversion" after this patch?
Not in the current form. Would it work to go:
if (override_active_level) {
if (!(host->caps2 & MMC_CAP2_CD_ACTIVE_HIGH))
gpiod_set_active_high(desc);
else
gpiod_set_active_low(desc);
} else {
if (host->caps2 & MMC_CAP2_CD_ACTIVE_HIGH)
gpiod_set_active_high(desc);
else
gpiod_set_active_low(desc);
}?
Alternatively we could reimplement the toggle semantics locally in a helper function in order to get rid of it from GPIOLIB.
Bart
Re: [PATCH 4/5] platform/x86: int3472/discrete: use gpiod_set_active_low()
In reply to Bartosz GolaszewskiHi,
Quoted 29 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
Use the new polarity setter instead of the more cumbersome toggle function.
Signed-off-by Bartosz Golaszewski <[email protected]>--- drivers/platform/x86/intel/int3472/clk_and_regulator.c | 2 +- drivers/platform/x86/intel/int3472/led.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)drivers/platform/x86/intel/int3472/clk_and_regulator.c +1
-1@@ -183,7 +183,7 @@ int skl_int3472_register_gpio_clock(struct int3472_discrete_device *int3472, }if (polarity ==GPIO_ACTIVE_LOW ) -gpiod_toggle_active_low (int3472->clock.ena_gpio); +gpiod_set_active_low (int3472->clock.ena_gpio);/* Ensure the pin is in output mode and non-active state */ gpiod_direction_output (int3472->clock.ena_gpio,0 );drivers/platform/x86/intel/int3472/led.c +0
-0
drivers/platform/x86/intel/int3472/led.c int skl_int3472_register_pled(struct int3472_discrete_device *int3472, · line 38
Quoted 8 lines
drivers/platform/x86/intel/int3472/led.c +1
-1@@ -32,7 +32,7 @@ int skl_int3472_register_pled(struct int3472_discrete_device *int3472, "getting privacy LED GPIO\n");if (polarity ==GPIO_ACTIVE_LOW ) -gpiod_toggle_active_low (int3472->pled.gpio); +gpiod_set_active_low (int3472->pled.gpio);/* Ensure the pin is in output mode and non-active state */ gpiod_direction_output (int3472->pled.gpio,0 );
Thanks. I agree that the new API is much better:
Feel free to merge this through the GPIO tree.
Regards,
Hans
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
kernel test robot
build botRe: [PATCH 1/5] gpiolib: provide gpiod_set_active_[low/high]()
In reply to Bartosz Golaszewskikernel test robot noticed the following build errors:
Hi Bartosz,
kernel test robot noticed the following build errors:
[auto build test ERROR on brgl/gpio/for-next]
[also build test ERROR on mtd/nand/next linus/master ulf-hansson-mmc-mirror/next v6.6-rc1 next-20230913] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Bartosz-Golaszewski/gpiolib-provide-gpiod_set_active_-low-high/20230913-195053 base: https://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux.git gpio/for-next patch link: https://lore.kernel.org/r/20230913115001.23183-2-brgl%40bgdev.pl patch subject: [PATCH 1/5] gpiolib: provide gpiod_set_active_[low/high]() config: s390-allnoconfig (https://download.01.org/0day-ci/archive/20230913/[email protected]/config) compiler: s390-linux-gcc (GCC) 13.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20230913/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
In file included from include/linux/nvmem-provider.h:15,
from include/linux/rtc.h:18, from include/linux/efi.h:20, from block/partitions/efi.h:19, from block/partitions/msdos.c:32:
>> include/linux/gpio/consumer.h:505:1: error: expected ';', ',' or ')' before '{' token
505 | {
| ^vim +505 include/linux/gpio/consumer.h
503
504 static inline void gpiod_set_active_low(struct gpio_desc *desc
> 505 { 506 /* GPIO can never have been requested */
507 WARN_ON(desc);
508 }
509
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Re: [PATCH 2/5] mtd: rawnand: ingenic: use gpiod_set_active_high()
In reply to Paul CercueilHi Bartosz,
[email protected] wrote on Wed, 13 Sep 2023 14:01:47 +0200:
Quoted 6 lines
Hi,
Le mercredi 13 septembre 2023 à 13:49 +0200, Bartosz Golaszewski a écrit :
Quoted 2 lines
From: Bartosz Golaszewski <[email protected]>
Quoted 8 lines
Quoted 4 lines
Use the new, less cumbersome interface for setting the GPIO as active-high that doesn't require first checking the current state.
Signed-off-by Bartosz Golaszewski <[email protected]>Works for me.
Acked-by Paul Cercueil <[email protected]>
For me as well, the new API looks much better.
I saw Hans is fine with you merging the platform/x86 patch. I am also fine if all maintainers agree on that. In this case:
However, if you finally need to produce an immutable tag, let me know and I will take the patch through our tree.
Thanks,
Miquèl
kernel test robot
build botRe: [PATCH 1/5] gpiolib: provide gpiod_set_active_[low/high]()
In reply to Bartosz Golaszewskikernel test robot noticed the following build warnings:
Hi Bartosz,
kernel test robot noticed the following build warnings:
[auto build test WARNING on brgl/gpio/for-next]
[also build test WARNING on mtd/nand/next linus/master ulf-hansson-mmc-mirror/next v6.6-rc1 next-20230913] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Bartosz-Golaszewski/gpiolib-provide-gpiod_set_active_-low-high/20230913-195053 base: https://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux.git gpio/for-next patch link: https://lore.kernel.org/r/20230913115001.23183-2-brgl%40bgdev.pl patch subject: [PATCH 1/5] gpiolib: provide gpiod_set_active_[low/high]() config: alpha-defconfig (https://download.01.org/0day-ci/archive/20230914/[email protected]/config) compiler: alpha-linux-gcc (GCC) 13.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20230914/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
In file included from include/linux/nvmem-provider.h:15,
from include/linux/rtc.h:18,
from include/linux/mc146818rtc.h:15,
from drivers/block/floppy.c:183:
include/linux/gpio/consumer.h:505:1: error: expected ';', ',' or ')' before '{' token
505 | {
| ^
>> drivers/block/floppy.c:165:12: warning: 'print_unex' defined but not used [-Wunused-variable]
165 | static int print_unex = 1;
| ^~~~~~~~~~vim +/print_unex +165 drivers/block/floppy.c
87f530d8f17336 Joe Perches 2010-03-10 163 ^1da177e4c3f41 Linus Torvalds 2005-04-16 164 /* do print messages for unexpected interrupts */ ^1da177e4c3f41 Linus Torvalds 2005-04-16 @165 static int print_unex = 1; ^1da177e4c3f41 Linus Torvalds 2005-04-16 166 #include <linux/module.h> ^1da177e4c3f41 Linus Torvalds 2005-04-16 167 #include <linux/sched.h> ^1da177e4c3f41 Linus Torvalds 2005-04-16 168 #include <linux/fs.h> ^1da177e4c3f41 Linus Torvalds 2005-04-16 169 #include <linux/kernel.h> ^1da177e4c3f41 Linus Torvalds 2005-04-16 170 #include <linux/timer.h> ^1da177e4c3f41 Linus Torvalds 2005-04-16 171 #include <linux/workqueue.h> ^1da177e4c3f41 Linus Torvalds 2005-04-16 172 #include <linux/fdreg.h> ^1da177e4c3f41 Linus Torvalds 2005-04-16 173 #include <linux/fd.h> ^1da177e4c3f41 Linus Torvalds 2005-04-16 174 #include <linux/hdreg.h> ^1da177e4c3f41 Linus Torvalds 2005-04-16 175 #include <linux/errno.h> ^1da177e4c3f41 Linus Torvalds 2005-04-16 176 #include <linux/slab.h> ^1da177e4c3f41 Linus Torvalds 2005-04-16 177 #include <linux/mm.h> ^1da177e4c3f41 Linus Torvalds 2005-04-16 178 #include <linux/bio.h> ^1da177e4c3f41 Linus Torvalds 2005-04-16 179 #include <linux/string.h> 50297cbf07427b Marcelo Feitoza Parisi 2006-03-28 180 #include <linux/jiffies.h> ^1da177e4c3f41 Linus Torvalds 2005-04-16 181 #include <linux/fcntl.h> ^1da177e4c3f41 Linus Torvalds 2005-04-16 182 #include <linux/delay.h> ^1da177e4c3f41 Linus Torvalds 2005-04-16 @183 #include <linux/mc146818rtc.h> /* CMOS defines */ ^1da177e4c3f41 Linus Torvalds 2005-04-16 184 #include <linux/ioport.h> ^1da177e4c3f41 Linus Torvalds 2005-04-16 185 #include <linux/interrupt.h> ^1da177e4c3f41 Linus Torvalds 2005-04-16 186 #include <linux/init.h> b81e0c2372e65e Christoph Hellwig 2021-09-20 187 #include <linux/major.h> d052d1beff7069 Russell King 2005-10-29 188 #include <linux/platform_device.h> 83f9ef463bcb4b Scott James Remnant 2009-04-02 189 #include <linux/mod_devicetable.h> b1c82b5c55851b Jes Sorensen 2006-03-23 190 #include <linux/mutex.h> d49375434ec011 Joe Perches 2010-03-10 191 #include <linux/io.h> d49375434ec011 Joe Perches 2010-03-10 192 #include <linux/uaccess.h> 0cc15d03bcccdf Andi Kleen 2012-07-02 193 #include <linux/async.h> 229b53c9bf4e11 Al Viro 2017-06-27 194 #include <linux/compat.h>
^1da177e4c3f41 Linus Torvalds 2005-04-16 195
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
kernel test robot
build botRe: [PATCH 1/5] gpiolib: provide gpiod_set_active_[low/high]()
In reply to Bartosz Golaszewskikernel test robot noticed the following build warnings:
Hi Bartosz,
kernel test robot noticed the following build warnings:
[auto build test WARNING on brgl/gpio/for-next]
[also build test WARNING on mtd/nand/next linus/master ulf-hansson-mmc-mirror/next v6.6-rc1 next-20230913] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Bartosz-Golaszewski/gpiolib-provide-gpiod_set_active_-low-high/20230913-195053 base: https://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux.git gpio/for-next patch link: https://lore.kernel.org/r/20230913115001.23183-2-brgl%40bgdev.pl patch subject: [PATCH 1/5] gpiolib: provide gpiod_set_active_[low/high]() config: m68k-defconfig (https://download.01.org/0day-ci/archive/20230914/[email protected]/config) compiler: m68k-linux-gcc (GCC) 13.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20230914/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
In file included from drivers/net/ethernet/smsc/smc91x.c:60:
include/linux/gpio/consumer.h:505:1: error: expected ';', ',' or ')' before '{' token
505 | {
| ^
>> drivers/net/ethernet/smsc/smc91x.c:47:19: warning: 'version' defined but not used [-Wunused-const-variable=]
47 | static const char version[] =
| ^~~~~~~vim +/version +47 drivers/net/ethernet/smsc/smc91x.c
^1da177e4c3f41 drivers/net/smc91x.c Linus Torvalds 2005-04-16 @47 static const char version[] = 6389aa458ed995 drivers/net/ethernet/smsc/smc91x.c Ben Boeckel 2013-11-01 48 "smc91x.c: v1.1, sep 22 2004 by Nicolas Pitre <[email protected]>"; ^1da177e4c3f41 drivers/net/smc91x.c Linus Torvalds 2005-04-16 49 ^1da177e4c3f41 drivers/net/smc91x.c Linus Torvalds 2005-04-16 50 /* Debugging level */ ^1da177e4c3f41 drivers/net/smc91x.c Linus Torvalds 2005-04-16 51 #ifndef SMC_DEBUG ^1da177e4c3f41 drivers/net/smc91x.c Linus Torvalds 2005-04-16 52 #define SMC_DEBUG 0 ^1da177e4c3f41 drivers/net/smc91x.c Linus Torvalds 2005-04-16 53 #endif ^1da177e4c3f41 drivers/net/smc91x.c Linus Torvalds 2005-04-16 54 ^1da177e4c3f41 drivers/net/smc91x.c Linus Torvalds 2005-04-16 55 ^1da177e4c3f41 drivers/net/smc91x.c Linus Torvalds 2005-04-16 56 #include <linux/module.h> ^1da177e4c3f41 drivers/net/smc91x.c Linus Torvalds 2005-04-16 57 #include <linux/kernel.h> ^1da177e4c3f41 drivers/net/smc91x.c Linus Torvalds 2005-04-16 58 #include <linux/sched.h> ^1da177e4c3f41 drivers/net/smc91x.c Linus Torvalds 2005-04-16 59 #include <linux/delay.h> c0e906a953f03c drivers/net/ethernet/smsc/smc91x.c Andy Shevchenko 2023-03-16 @60 #include <linux/gpio/consumer.h> ^1da177e4c3f41 drivers/net/smc91x.c Linus Torvalds 2005-04-16 61 #include <linux/interrupt.h> 476c32c47a84fc drivers/net/smc91x.c David Howells 2010-10-07 62 #include <linux/irq.h> ^1da177e4c3f41 drivers/net/smc91x.c Linus Torvalds 2005-04-16 63 #include <linux/errno.h> ^1da177e4c3f41 drivers/net/smc91x.c Linus Torvalds 2005-04-16 64 #include <linux/ioport.h> ^1da177e4c3f41 drivers/net/smc91x.c Linus Torvalds 2005-04-16 65 #include <linux/crc32.h> d052d1beff7069 drivers/net/smc91x.c Russell King 2005-10-29 66 #include <linux/platform_device.h> ^1da177e4c3f41 drivers/net/smc91x.c Linus Torvalds 2005-04-16 67 #include <linux/spinlock.h> ^1da177e4c3f41 drivers/net/smc91x.c Linus Torvalds 2005-04-16 68 #include <linux/ethtool.h> ^1da177e4c3f41 drivers/net/smc91x.c Linus Torvalds 2005-04-16 69 #include <linux/mii.h> ^1da177e4c3f41 drivers/net/smc91x.c Linus Torvalds 2005-04-16 70 #include <linux/workqueue.h> 682a1694115ec1 drivers/net/smc91x.c Thomas Chou 2011-01-25 71 #include <linux/of.h> 3f823c15d53dc7 drivers/net/ethernet/smsc/smc91x.c Tony Lindgren 2013-12-11 72 #include <linux/of_device.h>
^1da177e4c3f41 drivers/net/smc91x.c Linus Torvalds 2005-04-16 73
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Re: [PATCH 2/5] mtd: rawnand: ingenic: use gpiod_set_active_high()
In reply to Bartosz GolaszewskiQuoted 5 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
Use the new, less cumbersome interface for setting the GPIO as active-high that doesn't require first checking the current state.
...
drivers/mtd/nand/raw/ingenic/ingenic_nand_drv.c static int ingenic_nand_init_chip(struct platform_device *pdev, · line 392
Quoted 8 lines
* here for older DTs so we can re-use the generic
nand_gpio_waitrdy()
* helper, and be consistent with what other drivers do. */drivers/mtd/nand/raw/ingenic/ingenic_nand_drv.c +2
-3-if (of_machine_is_compatible ("qi,lb60" ) && -gpiod_is_active_low (nand->busy_gpio)) -gpiod_toggle_active_low (nand->busy_gpio); +if (of_machine_is_compatible ("qi,lb60" )) +gpiod_set_active_high (nand->busy_gpio);
Why not moving this quirk to gpiolib-of.c?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 2/5] mtd: rawnand: ingenic: use gpiod_set_active_high()
Quoted 18 lines · Andy Shevchenko
Quoted 5 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
Use the new, less cumbersome interface for setting the GPIO as active-high that doesn't require first checking the current state.
...
drivers/mtd/nand/raw/ingenic/ingenic_nand_drv.c static int ingenic_nand_init_chip(struct platform_device *pdev, · line 392
Quoted 8 lines
* here for older DTs so we can re-use the generic
nand_gpio_waitrdy()
* helper, and be consistent with what other drivers do. */drivers/mtd/nand/raw/ingenic/ingenic_nand_drv.c +2
-3-if (of_machine_is_compatible ("qi,lb60" ) && -gpiod_is_active_low (nand->busy_gpio)) -gpiod_toggle_active_low (nand->busy_gpio); +if (of_machine_is_compatible ("qi,lb60" )) +gpiod_set_active_high (nand->busy_gpio);
Quoted 1 line
Why not moving this quirk to
gpiolib-of.c?
That's a better idea here I think, it's clearly a quirk for a buggy device tree.
Yours,
Linus Walleij
Miquel Raynal
maintainerRe: [PATCH 2/5] mtd: rawnand: ingenic: use gpiod_set_active_high()
Hi Andy,
[email protected] wrote on Wed, 13 Sep 2023 22:12:40 +0200:
Quoted 20 lines
Quoted 18 lines · Andy Shevchenko
Quoted 5 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
Use the new, less cumbersome interface for setting the GPIO as active-high that doesn't require first checking the current state.
...
Quoted 8 lines
* here for older DTs so we can re-use the generic
nand_gpio_waitrdy()
* helper, and be consistent with what other drivers do. */drivers/mtd/nand/raw/ingenic/ingenic_nand_drv.c +2
-3-if (of_machine_is_compatible ("qi,lb60" ) && -gpiod_is_active_low (nand->busy_gpio)) -gpiod_toggle_active_low (nand->busy_gpio); +if (of_machine_is_compatible ("qi,lb60" )) +gpiod_set_active_high (nand->busy_gpio);
Quoted 4 lines
Quoted 1 line
Why not moving this quirk to
gpiolib-of.c?That's a better idea here I think, it's clearly a quirk for a buggy device tree.
Agreed, it's just for backward compatibility purposes in a single driver. I believe it should stay here.
Thanks,
Miquèl
Re: [PATCH 2/5] mtd: rawnand: ingenic: use gpiod_set_active_high()
Quoted 4 lines · Miquel Raynal
[email protected] wrote on Wed, 13 Sep 2023 22:12:40 +0200:
Quoted 3 lines
Quoted 1 line · Andy Shevchenko
On Wed, Sep 13, 2023 at 2:50 PM Bartosz Golaszewski <[email protected]> wrote:
...
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Why not moving this quirk to
gpiolib-of.c?That's a better idea here I think, it's clearly a quirk for a buggy device tree.
Agreed, it's just for backward compatibility purposes in a single driver. I believe it should stay here.
I believe Linus was for moving.
gpiolib-of.c contains a lot of quirks, including this one. Calling these new (or old) APIs for overriding polarity in many cases shouldn't be needed if were no issues with DT or something like that.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 2/5] mtd: rawnand: ingenic: use gpiod_set_active_high()
Quoted 15 lines · Andy Shevchenko
Quoted 4 lines · Miquel Raynal
[email protected] wrote on Wed, 13 Sep 2023 22:12:40 +0200:
Quoted 3 lines
Quoted 1 line · Andy Shevchenko
On Wed, Sep 13, 2023 at 2:50 PM Bartosz Golaszewski <[email protected]> wrote:
...
Quoted 5 lines
Quoted 4 lines
Quoted 1 line
Why not moving this quirk to
gpiolib-of.c?That's a better idea here I think, it's clearly a quirk for a buggy device tree.
Quoted 6 lines
Quoted 2 lines
Agreed, it's just for backward compatibility purposes in a single driver. I believe it should stay here.
I believe Linus was for moving.
gpiolib-of.ccontains a lot of quirks, including this one. Calling
To be clear:
"including one for the same issue"
Quoted 2 lines
these new (or old) APIs for overriding polarity in many cases shouldn't be needed if there were no issues with DT or something like that.
To be clear:
The less we call these APIs from drivers the better. Ideally these APIs shouldn't have existed.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Paul Cercueil
maintainerRe: [PATCH 2/5] mtd: rawnand: ingenic: use gpiod_set_active_high()
In reply to Andy ShevchenkoHi,
Le jeudi 14 septembre 2023 à 10:02 +0300, Andy Shevchenko a écrit :
Quoted 12 lines
Quoted 5 lines · Miquel Raynal
[email protected] wrote on Wed, 13 Sep 2023 22:12:40 +0200:
Quoted 4 lines
Quoted 2 lines · Andy Shevchenko
On Wed, Sep 13, 2023 at 2:50 PM Bartosz Golaszewski <[email protected]> wrote:
...
Quoted 2 lines
Quoted 2 lines
Quoted 1 line
Why not moving this quirk to
gpiolib-of.c?
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
That's a better idea here I think, it's clearly a quirk for a buggy device tree.
Agreed, it's just for backward compatibility purposes in a single driver. I believe it should stay here.
I believe Linus was for moving.
Which Linus? Because the one who's also the gpio maintainer just wrote above that it was better to keep it in the driver.
Cheers,
-Paul
Quoted 5 lines
gpiolib-of.ccontains a lot of quirks, including this one. Calling these new (or old) APIs for overriding polarity in many cases shouldn't be needed if were no issues with DT or something like that.
Re: [PATCH 3/5] mmc: slot-gpio: use gpiod_set_active_[low|high]()
In reply to Bartosz GolaszewskiQuoted 49 lines · Bartosz Golaszewski
Quoted 18 lines · Linus Walleij
Quoted 6 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
We have new, less cumbersome and clearer interfaces for controlling GPIO polarity. Use them in the MMC code.
Signed-off-by Bartosz Golaszewski <[email protected]>I like the looks of the code better, obviously but this looks like this for a reason unfortunately.
See the following from
Documentation/devicetree/bindings/mmc/mmc-controller.yaml:# CD and WP lines can be implemented on the hardware in one of two # ways: as GPIOs, specified in cd-gpios and wp-gpios properties, or
Quoted 10 lines
# as dedicated pins. Polarity of dedicated pins can be specified, # using *-inverted properties. GPIO polarity can also be specified # using the GPIO_ACTIVE_LOW flag. This creates an ambiguity in the # latter case. We choose to use the XOR logic for GPIO CD and WP # lines. This means, the two properties are "superimposed," for # example leaving the GPIO_ACTIVE_LOW flag clear and specifying the # respective *-inverted property property results in a # double-inversion and actually means the "normal" line polarity is # in effect.I hate it, thanks. :)
Quoted 2 lines
Will you still provide the desired "double inversion" after this patch?
Not in the current form. Would it work to go:
if (override_active_level) { if (!(host->caps2 & MMC_CAP2_CD_ACTIVE_HIGH)) gpiod_set_active_high(desc); else gpiod_set_active_low(desc); } else { if (host->caps2 & MMC_CAP2_CD_ACTIVE_HIGH) gpiod_set_active_high(desc); else gpiod_set_active_low(desc); }
Quoted 1 line
?
I *think* so but my boolean parser i known to be flawed since I have screwed up double inversions repeatedly over the years, so it should not be trusted at all.
Quoted 2 lines
Alternatively we could reimplement the toggle semantics locally in a helper function in order to get rid of it from GPIOLIB.
I don't know about that, the flag is inside gpio_desc so we cannot access it (struct is private to gpiolib...)
Yours,
Linus Walleij
Re: [PATCH 3/5] mmc: slot-gpio: use gpiod_set_active_[low|high]()
Quoted 7 lines · Linus Walleij
Quoted 2 lines · Bartosz Golaszewski
Alternatively we could reimplement the toggle semantics locally in a helper function in order to get rid of it from GPIOLIB.
I don't know about that, the flag is inside
gpio_descso we cannot access it (struct is private to gpiolib...)
Actually I think the way the toggle call came about was for this one MMC usecase.
Then other subsystems have used it without asking the GPIO maintainers or without implementing the more proper accessors or patching drivers/gpio/gpiolib-of.c because why not, probably thinking something like "hey weird that it is just toggle I guess they are not so smart, but it works, ship it".
Yours,
Linus Walleij
Re: [PATCH 2/5] mtd: rawnand: ingenic: use gpiod_set_active_high()
In reply to Paul CercueilQuoted 19 lines · Paul Cercueil
Hi,
Quoted 15 lines · Andy Shevchenko
Quoted 5 lines · Miquel Raynal
[email protected] wrote on Wed, 13 Sep 2023 22:12:40 +0200:
Quoted 4 lines
Quoted 2 lines · Andy Shevchenko
On Wed, Sep 13, 2023 at 2:50 PM Bartosz Golaszewski <[email protected]> wrote:
...
Quoted 5 lines
Quoted 4 lines
Quoted 1 line
Why not moving this quirk to
gpiolib-of.c?That's a better idea here I think, it's clearly a quirk for a buggy device tree.
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Agreed, it's just for backward compatibility purposes in a single driver. I believe it should stay here.
I believe Linus was for moving.
Which Linus? Because the one who's also the gpio maintainer just wrote above that it was better to keep it in the driver.
I'm also under the impression that Linus meant moving it to gpiolib-of.c. Let's
Linus: Could you clarify?
Bart
Quoted 9 lines
Cheers,
-PaulQuoted 5 lines
gpiolib-of.ccontains a lot of quirks, including this one. Calling these new (or old) APIs for overriding polarity in many cases shouldn't be needed if were no issues with DT or something like that.
Re: [PATCH 2/5] mtd: rawnand: ingenic: use gpiod_set_active_high()
Quoted 3 lines · Bartosz Golaszewski
Quoted 1 line · Paul Cercueil
Quoted 1 line
I believe Linus was for moving.
Yes.
Quoted 2 lines
Quoted 2 lines
Which Linus? Because the one who's also the gpio maintainer just wrote above that it was better to keep it in the driver.
What. No. I expressed myself unclearly:
Quoted 4 lines
Quoted 1 line
Why not moving this quirk to
gpiolib-of.c?That's a better idea here I think, it's clearly a quirk for a buggy device tree.
"That's a better idea here I think"
means
"That's a better idea [IN THIS CASE] I think"
i.e. in this case it is a better idea to move it into gpiolib-of.c
Quoted 3 lines
I'm also under the impression that Linus meant moving it to
gpiolib-of.c. Let'sLinus: Could you clarify?
Yes.
I invented that thing so I'm a fan of it.
Yours,
Linus Walleij