diff mbox series

[1/5] gpiolib: provide gpiod_set_active_[low/high]()

Message ID 20230913115001.23183-2-brgl@bgdev.pl (mailing list archive)
State New, archived
Headers show
Series gpio: remove gpiod_toggle_active_low() | expand

Commit Message

Bartosz Golaszewski Sept. 13, 2023, 11:49 a.m. UTC
From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

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.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
 drivers/gpio/gpiolib.c        | 22 ++++++++++++++++++++++
 include/linux/gpio/consumer.h | 14 ++++++++++++++
 2 files changed, 36 insertions(+)

Comments

kernel test robot Sept. 13, 2023, 3:19 p.m. UTC | #1
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/202309132304.Uw3cYH9C-lkp@intel.com/config)
compiler: s390-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20230913/202309132304.Uw3cYH9C-lkp@intel.com/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 <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202309132304.Uw3cYH9C-lkp@intel.com/

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
kernel test robot Sept. 13, 2023, 6:41 p.m. UTC | #2
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/202309140219.EH2Y6r52-lkp@intel.com/config)
compiler: alpha-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20230914/202309140219.EH2Y6r52-lkp@intel.com/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 <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202309140219.EH2Y6r52-lkp@intel.com/

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
kernel test robot Sept. 13, 2023, 7:23 p.m. UTC | #3
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/202309140338.TPkz7l7g-lkp@intel.com/config)
compiler: m68k-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20230914/202309140338.TPkz7l7g-lkp@intel.com/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 <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202309140338.TPkz7l7g-lkp@intel.com/

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 <nico@fluxnic.net>";
^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
diff mbox series

Patch

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index edffa0d2acaa..131965814a7c 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -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;
diff --git a/include/linux/gpio/consumer.h b/include/linux/gpio/consumer.h
index 6cc345440a5b..ddbf0d8e4a75 100644
--- a/include/linux/gpio/consumer.h
+++ b/include/linux/gpio/consumer.h
@@ -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 */