gpiolib: add hogs support for machine code
Subsystems (2)
PATCH 1/1 gpiolib: add hogs support for machine code
Board files constitute a significant part of the users of the legacy GPIO framework. In many cases they only export a line and set its desired value. We could use GPIO hogs for that like we do for DT and ACPI but there's no support for that in machine code.
This patch proposes to extend the machine.h API with support for registering hog tables in board files.
--- Documentation/driver-api/gpio/board.rst | 16 ++++++ drivers/gpio/gpiolib.c | 67 +++++++++++++++++++++++++ include/linux/gpio/machine.h | 31 ++++++++++++ 3 files changed, 114 insertions(+)
Documentation/driver-api/gpio/board.rst +16 -0
@@ -177,3 +177,19 @@ mapping and is thus transparent to GPIO consumers. A set of functions such as gpiod_set_value() is available to work with the new descriptor-oriented interface. + +Boards using platform data can also hog GPIO lines by defining GPIO hog tables. + +.. code-block:: c + + struct gpiod_hog gpio_hog_table[] = { + GPIO_HOG("gpio.0", 10, "foo", GPIO_ACTIVE_LOW, GPIOD_OUT_HIGH), + { } + }; + +And the table can be added to the board code as follows:: + + gpiod_add_hogs(gpio_hog_table); + +The line will be hogged as soon as the gpiochip is created or - in case the +chip was created earlier - when the hog table is registered.
drivers/gpio/gpiolib.c +67 -0
91 lines not on this page · raw message
include/linux/gpio/machine.h +31 -0
@@ -39,6 +39,23 @@ struct gpiod_lookup_table {struct gpiod_lookup table[]; }; +/** +* struct gpiod_hog - GPIO line hog table +* @chip_label: name of the chip the GPIO belongs to +* @chip_hwnum: hardware number (i.e. relative to the chip) of the GPIO +* @line_name: consumer name for the hogged line +* @lflags: mask of GPIO lookup flags +* @dflags: GPIO flags used to specify the direction and value +*/ +struct gpiod_hog { +struct list_head list; +const char *chip_label; +u16 chip_hwnum; +const char *line_name; +enum gpio_lookup_flags lflags; +enum gpiod_flags dflags; +}; +/* * Simple definition of a single GPIO under a con_id */
@@ -59,10 +76,23 @@ struct gpiod_lookup_table { .flags = _flags, \ } +/* +* Simple definition of a single GPIO hog in an array. +*/ +#define GPIO_HOG (_chip_label, _chip_hwnum, _line_name, _lflags, _dflags) \ +{ \ + .chip_label = _chip_label, \ + .chip_hwnum = _chip_hwnum, \ + .line_name = _line_name, \ + .lflags = _lflags, \ + .dflags = _dflags, \ +} +#ifdef CONFIG_GPIOLIB void gpiod_add_lookup_table (struct gpiod_lookup_table *table);void gpiod_add_lookup_tables (struct gpiod_lookup_table **tables,size_t n);void gpiod_remove_lookup_table (struct gpiod_lookup_table *table); +void gpiod_add_hogs (struct gpiod_hog *hogs);#else static inline void gpiod_add_lookup_table (struct gpiod_lookup_table *table) {}
@@ -70,6 +100,7 @@ static inlinevoid gpiod_add_lookup_tables (struct gpiod_lookup_table **tables,size_t n) {}static inline void gpiod_remove_lookup_table (struct gpiod_lookup_table *table) {} +static inline void gpiod_add_hogs (struct gpiod_hog *hogs) {}#endif #endif /* __LINUX_GPIO_MACHINE_H */
Signature · 1 line
2.17.0
kbuild test robot
build botI love your patch! Yet something to improve:
Hi Bartosz,
I love your patch! Yet something to improve:
[auto build test ERROR on gpio/for-next]
[also build test ERROR on v4.16 next-20180410]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Bartosz-Golaszewski/gpiolib-add-hogs-support-for-machine-code/20180410-232047 base: https://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio.git for-next config: i386-randconfig-a0-201814 (attached as .config) compiler: gcc-4.9 (Debian 4.9.4-2) 4.9.4 reproduce: # save the attached .config to linux build tree make ARCH=i386
All errors (new ones prefixed by >>):
In file included from drivers//mfd/sm501.c:23:0:
>> include/linux/gpio/machine.h:56:19: error: field 'dflags' has incomplete type
enum gpiod_flags dflags;
^vim +/dflags +56 include/linux/gpio/machine.h
41
42 /**
43 * struct gpiod_hog - GPIO line hog table
44 * @chip_label: name of the chip the GPIO belongs to
45 * @chip_hwnum: hardware number (i.e. relative to the chip) of the GPIO
46 * @line_name: consumer name for the hogged line
47 * @lflags: mask of GPIO lookup flags
48 * @dflags: GPIO flags used to specify the direction and value
49 */
50 struct gpiod_hog {
51 struct list_head list;
52 const char *chip_label;
53 u16 chip_hwnum;
54 const char *line_name;
55 enum gpio_lookup_flags lflags;
> 56 enum gpiod_flags dflags;
57 };
58 ---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
2018-04-10 19:05 GMT+02:00 kbuild test robot <[email protected]>:
Quoted 40 lines
Hi Bartosz,
I love your patch! Yet something to improve:
[auto build test ERROR on gpio/for-next]
[also build test ERROR on v4.16 next-20180410]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]url: https://github.com/0day-ci/linux/commits/Bartosz-Golaszewski/gpiolib-add-hogs-support-for-machine-code/20180410-232047 base: https://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio.git for-next config: i386-randconfig-a0-201814 (attached as .config) compiler: gcc-4.9 (Debian 4.9.4-2) 4.9.4 reproduce: # save the attached .config to linux build tree make ARCH=i386All errors (new ones prefixed by >>):
In file included from drivers//mfd/sm501.c:23:0:Quoted 1 line
Quoted 1 line
include/linux/gpio/machine.h:56:19: error: field 'dflags' has incomplete typeenum gpiod_flags dflags; ^vim +/dflags +56
include/linux/gpio/machine.h41 42 /** 43 * struct gpiod_hog - GPIO line hog table 44 * @chip_label: name of the chip the GPIO belongs to 45 * @chip_hwnum: hardware number (i.e. relative to the chip) of the GPIO 46 * @line_name: consumer name for the hogged line 47 * @lflags: mask of GPIO lookup flags 48 * @dflags: GPIO flags used to specify the direction and value 49 */ 50 struct gpiod_hog { 51 struct list_head list; 52 const char *chip_label; 53 u16 chip_hwnum; 54 const char *line_name; 55 enum gpio_lookup_flags lflags;
Quoted 7 lines
Quoted 1 line
56 enum
gpiod_flagsdflags;57 }; 58---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
Superseded by v2.