serio: PS2 gpio bit banging driver for the serio bus
Subsystems (4)
PATCH v2 1/1 serio: PS2 gpio bit banging driver for the serio bus
This driver provides PS2 serio bus support by implementing bit banging with the GPIO API. The GPIO pins, data and clock, can be configured with a node in the device tree or by static platform data.
Writing to a device is supported as well, though it is not recommended as the timings to be halt given by libps2 are very tough and difficult to reach with bit banging. Therefore it can be configured (also in DT and pdata) whether the serio write function should be available for clients.
This driver is for development purposes and not for productive use. However, this driver can be useful e.g. when no USB port is available or using old peripherals is desired as PS2 controllers getting rare.
This driver was tested on a RPI1 and on Hikey960 and it worked well together with the atkbd driver.
---
v2: Removed one verbose print statement, changed another one to dev_dbg.
--- .../devicetree/bindings/serio/ps2-gpio.txt | 20 + Documentation/gpio/drivers-on-gpio.txt | 5 + drivers/input/serio/Kconfig | 10 + drivers/input/serio/Makefile | 1 + drivers/input/serio/ps2-gpio.c | 438 +++++++++++++++++++++ include/linux/ps2-gpio.h | 27 ++ 6 files changed, 501 insertions(+) create mode 100644 Documentation/devicetree/bindings/serio/ps2-gpio.txt create mode 100644 drivers/input/serio/ps2-gpio.c create mode 100644 include/linux/ps2-gpio.h
Documentation/devicetree/bindings/serio/ps2-gpio.txt new file +20 -0
@@ -0,0 +1,20 @@ +Device-Tree bindings for ps2 gpio driver + +Required properties: + - compatible = "ps2-gpio"; + - gpios: data and clock gpio + +Optional properties: + - ps2-gpio,write-enable: Indicates whether write function is provided + to serio device. Most probably providing the write fn will not work, + because of the tough timing libps2 requires. + +Example nodes: + +ps2@0 { + compatible = "ps2-gpio"; + gpios = <&gpio 24 0 /* data */ + &gpio 23 0 /* clock */ + >; + i2c-gpio,write-enable = <0>; +};
Documentation/gpio/drivers-on-gpio.txt +5 -0
@@ -84,6 +84,11 @@ hardware descriptions such as device tree or ACPI: NAND flash MTD subsystem and provides chip access and partition parsing like any other NAND driving hardware. +- ps2-gpio: drivers/input/serio/ps2-gpio.c is used to drive an PS2 serio bus, + data and clock line, by bit banging two GPIO lines. It will appear as any + other serio bus to the system and makes it possible to connect drivers for + e.g. keyboards and other PS2 protocol based devices. + Apart from this there are special GPIO drivers in subsystems like MMC/SD to read card detect and write protect GPIO lines, and in the TTY serial subsystem to emulate MCTRL (modem control) signals CTS/RTS by using two GPIO lines. The
drivers/input/serio/Kconfig +10 -0
@@ -292,6 +292,16 @@ config SERIO_SUN4I_PS2 To compile this driver as a module, choose M here: the module will be called sun4i-ps2. +config SERIO_GPIO_PS2 + tristate "GPIO PS/2 bit banging driver" + help + Say Y here if you want PS/2 bit banging support via GPIO. + + To compile this driver as a module, choose M here: the + module will be called gpio-ps2. + + If you are unsure, say N. + config USERIO tristate "User space serio port driver support" help
drivers/input/serio/Makefile +1 -0
@@ -30,4 +30,5 @@ obj-$(CONFIG_SERIO_APBPS2) += apbps2.o obj-$(CONFIG_SERIO_OLPC_APSP) += olpc_apsp.o obj-$(CONFIG_HYPERV_KEYBOARD) += hyperv-keyboard.o obj-$(CONFIG_SERIO_SUN4I_PS2) += sun4i-ps2.o +obj-$(CONFIG_SERIO_GPIO_PS2) += ps2-gpio.o obj-$(CONFIG_USERIO) += userio.o
drivers/input/serio/ps2-gpio.c new file +438 -0
438 lines not on this page · raw message
include/linux/ps2-gpio.h new file +27 -0
@@ -0,0 +1,27 @@ +/* +* ps2-gpio interface to platform code +* +* Author: Danilo Krummrich <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ +#ifndef _LINUX_PS2_GPIO_H +#define _LINUX_PS2_GPIO_H + +/** +* struct ps2_gpio_platform_data - Platform-dependent data for ps2-gpio +* @gpio_data: GPIO pin ID to use for DATA +* @gpio_clk: GPIO pin ID to use for CLOCK +* @write_enable: Indicates whether write function is provided to serio +* device. Most probably providing the write fn will not work, +* because of the tough timing libps2 requires. +*/ +struct ps2_gpio_platform_data { +unsigned int gpio_data; +unsigned int gpio_clk; +unsigned int write_enable; +}; + +#endif /* _LINUX_PS2_GPIO_H */
Signature · 1 line
2.9.3
Randy Dunlap
reviewerDocumentation/gpio/drivers-on-gpio.txt hardware descriptions such as device tree or ACPI: · line 87
Quoted 9 lines · Danilo Krummrich
Documentation/gpio/drivers-on-gpio.txt +1
-0@@ -84,6 +84,11 @@ hardware descriptions such as device tree or ACPI: NAND flash MTD subsystem and provides chip access and partition parsing like any other NAND driving hardware. +- ps2-gpio: drivers/input/serio/ps2-gpio.c is used to drive an PS2 serio bus,
drive a PS2
Is this PS2 as in IBM Micro Channel or PlayStation 2?
Quoted 12 lines
Documentation/gpio/drivers-on-gpio.txt +4
-0+ data and clock line, by bit banging two GPIO lines. It will appear as any + other serio bus to the system and makes it possible to connect drivers for + e.g. keyboards and other PS2 protocol based devices. + Apart from this there are special GPIO drivers in subsystems like MMC/SD to read card detect and write protect GPIO lines, and in the TTY serial subsystem to emulate MCTRL (modem control) signals CTS/RTS by using two GPIO lines. Thedrivers/input/serio/Kconfig +0
-0
drivers/input/serio/Kconfig config SERIO_SUN4I_PS2 · line 296
Quoted 5 lines
drivers/input/serio/Kconfig +2
-0@@ -292,6 +292,16 @@ config SERIO_SUN4I_PS2 To compile this driver as a module, choose M here: the module will be called sun4i-ps2. +config SERIO_GPIO_PS2 + tristate "GPIO PS/2 bit banging driver"
depends on GPIO
??
Quoted 11 lines
drivers/input/serio/Kconfig +8
-0+ help + Say Y here if you want PS/2 bit banging support via GPIO. + + To compile this driver as a module, choose M here: the + module will be called gpio-ps2. + + If you are unsure, say N. + config USERIO tristate "User space serio port driver support" help
Signature · 1 line
~Randy
Quoted 11 lines · Randy Dunlap
Quoted 9 lines · Danilo Krummrich
Documentation/gpio/drivers-on-gpio.txt +0
-0@@ -84,6 +84,11 @@ hardware descriptions such as device tree or ACPI: NAND flash MTD subsystem and provides chip access and partitionparsing like
any other NAND driving hardware.
Quoted 6 lines
Quoted 2 lines
+- ps2-gpio:
drivers/input/serio/ps2-gpio.cis used to drive an PS2 serio bus,drive a PS2
Is this PS2 as in IBM Micro Channel or PlayStation 2?
It's the PS/2 mouse/keyboard protocol introduced by IBM.
Quoted 20 lines
Quoted 20 lines
+ data and clock line, by bit banging two GPIO lines. It will appear as any
+ other serio bus to the system and makes it possible to connect drivers forDocumentation/gpio/drivers-on-gpio.txt +2
-0+ e.g. keyboards and other PS2 protocol based devices. + Apart from this there are special GPIO drivers in subsystems likeMMC/SD to
read card detect and write protect GPIO lines, and in the TTY serial
subsystem
to emulate MCTRL (modem control) signals CTS/RTS by using two GPIO
lines. Thedrivers/input/serio/Kconfig +0
-0@@ -292,6 +292,16 @@ config SERIO_SUN4I_PS2 To compile this driver as a module, choose M here: the module will be called sun4i-ps2.
Quoted 6 lines
drivers/input/serio/Kconfig config SERIO_SUN4I_PS2 · line 296
Quoted 2 lines
drivers/input/serio/Kconfig +2
-0+config SERIO_GPIO_PS2 + tristate "GPIO PS/2 bit banging driver"depends on GPIO
??
Thank you, missed that.
Quoted 11 lines
Quoted 11 lines
drivers/input/serio/Kconfig +8
-0+ help + Say Y here if you want PS/2 bit banging support via GPIO. + + To compile this driver as a module, choose M here: the + module will be called gpio-ps2. + + If you are unsure, say N. + config USERIO tristate "User space serio port driver support" help
kbuild test robot
build botreproduce: wget https://raw.githubusercontent.com/01org/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # save the attached .config to linux build tree make.cross…
Hi Danilo,
[auto build test WARNING on input/next]
[also build test WARNING on v4.13-rc3 next-20170731]
[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/Danilo-Krummrich/serio-PS2-gpio-bit-banging-driver-for-the-serio-bus/20170801-081531 base: https://git.kernel.org/pub/scm/linux/kernel/git/dtor/input.git next config: blackfin-allyesconfig (attached as .config) compiler: bfin-uclinux-gcc (GCC) 6.2.0
reproduce:
wget https://raw.githubusercontent.com/01org/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=blackfin
Note: it may well be a FALSE warning. FWIW you are at least aware of it now.
http://gcc.gnu.org/wiki/Better_Uninitialized_Warnings
All warnings (new ones prefixed by >>):
In file included from arch/blackfin/include/asm/gpio.h:191:0,
from include/linux/gpio.h:48,
from drivers/input/serio/ps2-gpio.c:11:
drivers/input/serio/ps2-gpio.c: In function 'ps2_gpio_irq':
>> include/asm-generic/gpio.h:103:9: warning: 'data' may be used uninitialized in this function [-Wmaybe-uninitialized]
return gpiod_set_raw_value(gpio_to_desc(gpio), value);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/input/serio/ps2-gpio.c:191:6: note: 'data' was declared here
int data;
^~~~vim +/data +103 include/asm-generic/gpio.h
d2876d08 David Brownell 2008-02-04 91
d2876d08 David Brownell 2008-02-04 92
d2876d08 David Brownell 2008-02-04 93 /* A platform's <asm/gpio.h> code may want to inline the I/O calls when
d2876d08 David Brownell 2008-02-04 94 * the GPIO is constant and refers to some always-present controller,
d2876d08 David Brownell 2008-02-04 95 * giving direct access to chip registers and tight bitbanging loops.
d2876d08 David Brownell 2008-02-04 96 */
79a9becd Alexandre Courbot 2013-10-17 97 static inline int __gpio_get_value(unsigned gpio)
79a9becd Alexandre Courbot 2013-10-17 98 {
79a9becd Alexandre Courbot 2013-10-17 99 return gpiod_get_raw_value(gpio_to_desc(gpio));
79a9becd Alexandre Courbot 2013-10-17 100 }
79a9becd Alexandre Courbot 2013-10-17 101 static inline void __gpio_set_value(unsigned gpio, int value)
79a9becd Alexandre Courbot 2013-10-17 102 {
79a9becd Alexandre Courbot 2013-10-17 @103 return gpiod_set_raw_value(gpio_to_desc(gpio), value);
79a9becd Alexandre Courbot 2013-10-17 104 }d2876d08 David Brownell 2008-02-04 105
:::::: The code at line 103 was first introduced by commit
:::::: 79a9becda8940deb2274b5aa4577c86d52ee7ecb gpiolib: export descriptor-based GPIO interface
:::::: TO: Alexandre Courbot <[email protected]> :::::: CC: Linus Walleij <[email protected]>
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation