Skip to contentSkip to conversation

serio: PS/2 gpio bit banging driver for serio bus

PATCH Superseded Danilo Krummrich 2 participants 3 messages Aug 11, 2017 – Aug 17, 2017

Subsystems (4)

v7 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

PATCH v7 1/1 serio: PS/2 gpio bit banging driver for serio bus

This driver provides PS/2 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 generic device properties (GDP).

Writing to a device is supported as well, though it is possible timings can not be halt as they are tough and difficult to reach with bit banging. Therefore it can be configured (also in DT and GDP) whether the serio write function should be available for clients.

This driver is for development purposes and not recommended for productive use. However, this driver can be useful e.g. when no USB port is available or using old peripherals is desired as PS/2 controller chips getting rare.

This driver was tested on RPI1 and on Hikey960 and it worked well together with the atkbd and psmouse driver.

---
v2: Removed one verbose print statement, changed another one to dev_dbg.
v3: - fixed compiler warning on blackfin
- depends on GPIOLIB
- clarify documentation
v4: - fixed concurrent calls to ps2_gpio_write (serio->write)
- use gpiod API
- use generic device properties
- request irq separately, do not use gpiod_to_irq
- abort when gpio is connected via slow bus
- Fixed a bug where PS2_CMD_RESEND is always send after tx failed once. The makes the write functionallity work better, tough timing is still critical.
- disable irq initially until ps2_gpip_open (serio->open) is called
v5: Checked again why timings are that hard to reach while in tx mode and
discovered that there is an extra clock pulse between stop bit sent from host and acknowledgement from device. By just skipping this clock pulse tx works fine now, though it still happens sometimes that the timing can not be reached of course.
v6: - fixed typos
- use of_match_ptr
v7: remove unnecessary barriers

Sorry for resending, forgot der version tag in the subject.

---
 .../devicetree/bindings/serio/ps2-gpio.txt         |  22 +
 Documentation/gpio/drivers-on-gpio.txt             |   5 +
 drivers/input/serio/Kconfig                        |  11 +
 drivers/input/serio/Makefile                       |   1 +
 drivers/input/serio/ps2-gpio.c                     | 453 +++++++++++++++++++++
 5 files changed, 492 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/serio/ps2-gpio.txt
 create mode 100644 drivers/input/serio/ps2-gpio.c
Documentation/devicetree/bindings/serio/ps2-gpio.txt new file +22 -0
new file mode 100644
index 000000000000..099dd6d46cb3
@@ -0,0 +1,22 @@
+Device-Tree bindings for ps/2 gpio driver
+
+Required properties:
+	- compatible = "ps2-gpio"
+	- gpios: data and clock gpio
+	- interrupts: Should trigger on the falling edge of the clock line.
+
+Optional properties:
+	- ps2-gpio,write-enable: Indicates whether write function is provided
+	to serio device. Possibly providing the write fn will not work, because
+	of the tough timing requirements.
+
+Example nodes:
+
+ps2@0 {
+	compatible = "ps2-gpio";
+	interrupt-parent = <&gpio>;
+	interrupts = <23 IRQ_TYPE_EDGE_FALLING>;
+	data-gpios = <&gpio 24 GPIO_ACTIVE_HIGH>;
+	clk-gpios = <&gpio 23 GPIO_ACTIVE_HIGH>;
+	ps2-gpio,write-enable;
+};
Documentation/gpio/drivers-on-gpio.txt +5 -0
index 306513251713..9a78d385b92e 100644
@@ -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 a PS/2 (IBM) 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 PS/2 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 +11 -0
index c3d05b4d3118..21488c048fa3 100644
@@ -292,6 +292,17 @@ 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 GPIOLIB
+	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 ps2-gpio.
+
+	  If you are unsure, say N.
+
 config USERIO
 	tristate "User space serio port driver support"
 	help
drivers/input/serio/Makefile +1 -0
index 2374ef9b33d7..767bd9b6e1ed 100644
@@ -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 +453 -0

453 lines not on this page · raw message

Signature · 1 line
2.14.1
maintainer
#1 lore raw
Quoted 40 lines · Danilo Krummrich

This driver provides PS/2 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 generic device properties (GDP).

Writing to a device is supported as well, though it is possible timings can not be halt as they are tough and difficult to reach with bit banging. Therefore it can be configured (also in DT and GDP) whether the serio write function should be available for clients.

This driver is for development purposes and not recommended for productive use. However, this driver can be useful e.g. when no USB port is available or using old peripherals is desired as PS/2 controller chips getting rare.

This driver was tested on RPI1 and on Hikey960 and it worked well together with the atkbd and psmouse driver.

---
v2: Removed one verbose print statement, changed another one to dev_dbg.
v3: - fixed compiler warning on blackfin
- depends on GPIOLIB
- clarify documentation
v4: - fixed concurrent calls to ps2_gpio_write (serio->write)
- use gpiod API
- use generic device properties
- request irq separately, do not use gpiod_to_irq
- abort when gpio is connected via slow bus
- Fixed a bug where PS2_CMD_RESEND is always send after tx failed once. The makes the write functionallity work better, tough timing is still critical.
- disable irq initially until ps2_gpip_open (serio->open) is called
v5: Checked again why timings are that hard to reach while in tx mode and
discovered that there is an extra clock pulse between stop bit sent from host and acknowledgement from device. By just skipping this clock pulse tx works fine now, though it still happens sometimes that the timing can not be reached of course.
v6: - fixed typos
- use of_match_ptr
v7: remove unnecessary barriers

Quoted 3 lines

Sorry for resending, forgot der version tag in the subject.

---
 .../devicetree/bindings/serio/ps2-gpio.txt         |  22 +

It's preferred to split bindings to separate patch.

Quoted 14 lines
 Documentation/gpio/drivers-on-gpio.txt             |   5 +
 drivers/input/serio/Kconfig                        |  11 +
 drivers/input/serio/Makefile                       |   1 +
 drivers/input/serio/ps2-gpio.c                     | 453 +++++++++++++++++++++
 5 files changed, 492 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/serio/ps2-gpio.txt
 create mode 100644 drivers/input/serio/ps2-gpio.c
Documentation/devicetree/bindings/serio/ps2-gpio.txt new file +0 -0
new file mode 100644
index 000000000000..099dd6d46cb3

Documentation/devicetree/bindings/serio/ps2-gpio.txt line 1

Quoted 1 line
Documentation/devicetree/bindings/serio/ps2-gpio.txt new file +1 -0
@@ -0,0 +1,22 @@
+Device-Tree bindings for ps/2 gpio driver

Bindings don't describe drivers.

Documentation/devicetree/bindings/serio/ps2-gpio.txt line 9

Quoted 8 lines
Documentation/devicetree/bindings/serio/ps2-gpio.txt new file +8 -0
+
+Required properties:
+	- compatible = "ps2-gpio"
+	- gpios: data and clock gpio
+	- interrupts: Should trigger on the falling edge of the clock line.
+
+Optional properties:
+	- ps2-gpio,write-enable: Indicates whether write function is provided

ps2-gpio is not a vendor prefix, so drop it.

Quoted 13 lines
Documentation/devicetree/bindings/serio/ps2-gpio.txt new file +13 -0
+	to serio device. Possibly providing the write fn will not work, because
+	of the tough timing requirements.
+
+Example nodes:
+
+ps2@0 {
+	compatible = "ps2-gpio";
+	interrupt-parent = <&gpio>;
+	interrupts = <23 IRQ_TYPE_EDGE_FALLING>;
+	data-gpios = <&gpio 24 GPIO_ACTIVE_HIGH>;
+	clk-gpios = <&gpio 23 GPIO_ACTIVE_HIGH>;
+	ps2-gpio,write-enable;
+};
#2 lore raw

Hi Bob,

thanks for reviewing.

Quoted 47 lines · Rob Herring
Quoted 46 lines · Danilo Krummrich

This driver provides PS/2 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 generic device properties (GDP).

Writing to a device is supported as well, though it is possible timings can not be halt as they are tough and difficult to reach with bit banging. Therefore it can be configured (also in DT and GDP) whether the serio write function should be available for clients.

This driver is for development purposes and not recommended for productive use. However, this driver can be useful e.g. when no USB port is available or using old peripherals is desired as PS/2 controller chips getting rare.

This driver was tested on RPI1 and on Hikey960 and it worked well together with the atkbd and psmouse driver.

---
v2: Removed one verbose print statement, changed another one to dev_dbg.
v3: - fixed compiler warning on blackfin
- depends on GPIOLIB
- clarify documentation
v4: - fixed concurrent calls to ps2_gpio_write (serio->write)
- use gpiod API
- use generic device properties
- request irq separately, do not use gpiod_to_irq
- abort when gpio is connected via slow bus
- Fixed a bug where PS2_CMD_RESEND is always send after tx failed
once.
The makes the write functionallity work better, tough timing is
still
critical.
- disable irq initially until ps2_gpip_open (serio->open) is
called
v5: Checked again why timings are that hard to reach while in tx mode and
discovered that there is an extra clock pulse between stop bit
sent from
host and acknowledgement from device. By just skipping this clock
pulse
tx works fine now, though it still happens sometimes that the
timing can
not be reached of course.
v6: - fixed typos
- use of_match_ptr
v7: remove unnecessary barriers

Quoted 6 lines
Quoted 3 lines

Sorry for resending, forgot der version tag in the subject.

---
 .../devicetree/bindings/serio/ps2-gpio.txt         |  22 +

It's preferred to split bindings to separate patch.

Together with Documentation/gpio/drivers-on-gpio.txt or would you prefer to have a separate patch for this as well?

Quoted 10 lines
Quoted 10 lines
 Documentation/gpio/drivers-on-gpio.txt             |   5 +
 drivers/input/serio/Kconfig                        |  11 +
 drivers/input/serio/Makefile                       |   1 +
 drivers/input/serio/ps2-gpio.c                     | 453 
+++++++++++++++++++++
 5 files changed, 492 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/serio/ps2-gpio.txt
 create mode 100644 drivers/input/serio/ps2-gpio.c
Quoted 10 lines

Documentation/devicetree/bindings/serio/ps2-gpio.txt line 1

Quoted 7 lines
Documentation/devicetree/bindings/serio/ps2-gpio.txt new file +1 -0
new file mode 100644
index 000000000000..099dd6d46cb3
@@ -0,0 +1,22 @@
+Device-Tree bindings for ps/2 gpio driver

Bindings don't describe drivers.

Will fix.

Quoted 12 lines
Quoted 9 lines
Documentation/devicetree/bindings/serio/ps2-gpio.txt new file +8 -0
+
+Required properties:
+	- compatible = "ps2-gpio"
+	- gpios: data and clock gpio
+	- interrupts: Should trigger on the falling edge of the clock line.
+
+Optional properties:
+	- ps2-gpio,write-enable: Indicates whether write function is 

provided

ps2-gpio is not a vendor prefix, so drop it.

I will do.

Quoted 6 lines
Quoted 6 lines
Documentation/devicetree/bindings/serio/ps2-gpio.txt new file +1 -0
+	to serio device. Possibly providing the write fn will not work, 

because

Documentation/devicetree/bindings/serio/ps2-gpio.txt new file +4 -0
+	of the tough timing requirements.
+
+Example nodes:
+
Quoted 8 lines

Documentation/devicetree/bindings/serio/ps2-gpio.txt line 22

Quoted 8 lines
Documentation/devicetree/bindings/serio/ps2-gpio.txt new file +8 -0
+ps2@0 {
+	compatible = "ps2-gpio";
+	interrupt-parent = <&gpio>;
+	interrupts = <23 IRQ_TYPE_EDGE_FALLING>;
+	data-gpios = <&gpio 24 GPIO_ACTIVE_HIGH>;
+	clk-gpios = <&gpio 23 GPIO_ACTIVE_HIGH>;
+	ps2-gpio,write-enable;
+};

Thanks,
Danilo
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html