Skip to contentSkip to conversation

input: keyboard: add qci keyboard driver

PATCH In review Neil Leeder 3 participants 12 messages Aug 27, 2010 – Sep 7, 2010

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover input: keyboard: add qci keyboard driver

This is an update of the keyboard driver which Quanta previously posted to linux-input. Like the touchpad driver, I'm taking over maintenance for code aurora forum.

The keyboard is attached to an embedded controller which is accessed through I2C. It has a dedicated I2C address and its own interrupt line, so it is not treated as an mfd. Although a PS/2 command, 0xF4, is used to initialize the keyboard, the EC does not respond to other PS/2 commands. I have tried a serio driver on the port and attempted to use keyboard drivers like xtkbd to communicate with it. These fail for similar reasons to those discussed in the qci touchpad thread. This is the reason for having this as a stand-alone driver.

--
Neil

Signature · 2 lines
Sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
#1 lore raw

PATCH 1/1 input: keyboard: add qci keyboard driver

This driver is for the QCI i2c keyboard used on Quanta smartbooks.

[[email protected]: cleanup to latest kernel standards]
---
 drivers/input/keyboard/Kconfig     |   12 ++
 drivers/input/keyboard/Makefile    |    1 +
 drivers/input/keyboard/qci_gkbd.c  |  258 ++++++++++++++++++++++++++++++++++++
 include/linux/input/qci_keyboard.h |   25 ++++
 4 files changed, 296 insertions(+), 0 deletions(-)
 create mode 100644 drivers/input/keyboard/qci_gkbd.c
 create mode 100644 include/linux/input/qci_keyboard.h
drivers/input/keyboard/Kconfig +12 -0
index 1ba2514..e610755 100644
@@ -342,6 +342,18 @@ config KEYBOARD_PXA930_ROTARY
 	  To compile this driver as a module, choose M here: the
 	  module will be called pxa930_rotary.
 
+config KEYBOARD_QCIGKBD
+	tristate "Quanta Computer Inc. keyboard"
+	depends on I2C
+	help
+	  This driver supports the i2c keyboard on Quanta smartbook devices.
+
+	  Say Y here if you have a Quanta-based smartbook or notepad
+	  device and want to use the Quanta i2c keyboard driver.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called qci_gkbd.
+
 config KEYBOARD_STOWAWAY
 	tristate "Stowaway keyboard"
 	select SERIO
drivers/input/keyboard/Makefile +1 -0
index 4596d0c..103adc2 100644
@@ -31,6 +31,7 @@ obj-$(CONFIG_KEYBOARD_OMAP)		+= omap-keypad.o
 obj-$(CONFIG_KEYBOARD_OPENCORES)	+= opencores-kbd.o
 obj-$(CONFIG_KEYBOARD_PXA27x)		+= pxa27x_keypad.o
 obj-$(CONFIG_KEYBOARD_PXA930_ROTARY)	+= pxa930_rotary.o
+obj-$(CONFIG_KEYBOARD_QCIGKBD)		+= qci_gkbd.o
 obj-$(CONFIG_KEYBOARD_QT2160)		+= qt2160.o
 obj-$(CONFIG_KEYBOARD_SH_KEYSC)		+= sh_keysc.o
 obj-$(CONFIG_KEYBOARD_STOWAWAY)		+= stowaway.o
drivers/input/keyboard/qci_gkbd.c new file +258 -0

258 lines not on this page · raw message

include/linux/input/qci_keyboard.h new file +25 -0
new file mode 100644
index 0000000..b32b7fc
@@ -0,0 +1,25 @@
+/* Copyright (c) 2010, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef __QCI_KEYBOARD_H
+#define __QCI_KEYBOARD_H
+
+struct qci_keyboard_platform_data {
+	unsigned long irq_trigger_type;
+};
+
+#endif
Signature · 4 lines
1.7.0
--
Sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
#2 lore raw

Hi Neil,

drivers/input/keyboard/qci_gkbd.c line 180

Quoted 2 lines · Neil Leeder
drivers/input/keyboard/qci_gkbd.c new file +2 -0
+	__set_bit(EV_KEY, context->qcikbd_dev->evbit);
+	__set_bit(EV_REP, context->qcikbd_dev->evbit);

If you are going to roll out new version of this patch to address the last comment from Dmitry, then I have couple of suggestions. If possible then please incorporate.

Make EV_REP optional, not all the systems needs it by default. Better to introduce pdata->rep.

Some of the systems would need each key press to wake up the system, so disable_irq in suspend would not be what they want. How about introducing pdata->wakeup flag and then using device_init_wakeup, device_may_wakeup, enable/disable_irq_wake friends in probe and .suspend/.resume functions.

---Trilok Soni

Signature · 2 lines
Sent by a consultant of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
maintainer
#3 lore raw
In reply to Neil Leeder
Quoted 4 lines · Neil Leeder

This is an update of the keyboard driver which Quanta previously posted to linux-input. Like the touchpad driver, I'm taking over maintenance for code aurora forum.

Quoted 9 lines

The keyboard is attached to an embedded controller which is accessed through I2C. It has a dedicated I2C address and its own interrupt line, so it is not treated as an mfd. Although a PS/2 command, 0xF4, is used to initialize the keyboard, the EC does not respond to other PS/2 commands. I have tried a serio driver on the port and attempted to use keyboard drivers like xtkbd to communicate with it. These fail for similar reasons to those discussed in the qci touchpad thread. This is the reason for having this as a stand-alone driver.

No, this is crazy... This is a twin-brother of the touchpad driver and I really do not understand why chip claiming to have PS/2 interface (3 ports if I were to believe the diagram) would not allow us talk to the devices...

Signature · 1 line
Dmitry
#4 lore raw
Quoted 4 lines · Dmitry Torokhov

No, this is crazy... This is a twin-brother of the touchpad driver and I really do not understand why chip claiming to have PS/2 interface (3 ports if I were to believe the diagram) would not allow us talk to the devices...

I didn't provide a key bit of information, sorry. The keyboard is not attached to the EC's PS/2 port. It is on a matrix of GPIOs.

I was trying to explain that even though the firmware on the EC uses 0xF4 written over i2c to initialize it, it doesn't appear to support other PS/2 commands directed to the keyboard on the GPIO matrix.

--
Neil

Signature · 2 lines
Sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
maintainer
#5 lore raw
Quoted 8 lines · Neil Leeder
Quoted 4 lines · Dmitry Torokhov

No, this is crazy... This is a twin-brother of the touchpad driver and I really do not understand why chip claiming to have PS/2 interface (3 ports if I were to believe the diagram) would not allow us talk to the devices...

I didn't provide a key bit of information, sorry. The keyboard is not attached to the EC's PS/2 port. It is on a matrix of GPIOs.

And still you are using only one GPIO in your driver? While WPCE775x does seem to have matrix keypad support I think that you are using one of the 3 PS/2 ports, like your touchpad does.

Quoted 5 lines

I was trying to explain that even though the firmware on the EC uses 0xF4 written over i2c to initialize it, it doesn't appear to support other PS/2 commands directed to the keyboard on the GPIO matrix.

The device is initialized with 0xf4; the device is supposed to respond with 0xfa; I wonder what scancodes the device reports... It smells strongly of PS/2.

Also, it is not controller that supports PS/2 commands but rather the device itself so I am still hopeful that we could make use of the standard drivers.

Wan, you worked at Nuvoton, do you know if wpce775 fully supports PS/2 interface?

Signature · 1 line
Dmitry
#6 lore raw
Quoted 3 lines · Dmitry Torokhov

And still you are using only one GPIO in your driver? While WPCE775x does seem to have matrix keypad support I think that you are using one of the 3 PS/2 ports, like your touchpad does.

Hi Dmitry,

I can assure you that the keyboard is on the 8*18 GPIO matrix on the Nuvoton EC (only 8*16 being used in the current design). There certainly are 3 PS/2 ports on the EC, but in the board designs I have only one of those is used as a PS/2 port, and that is for the touchpad. The other two ports are muxed with GPIOs and the pins are being used as GPIOs for other functions, not PS/2 ports.

The firmware on the EC converts keypresses on the GPIO matrix to scancodes and sends them over I2C. The single GPIO used by the keyboard driver is an interrupt.

Quoted 7 lines

The device is initialized with 0xf4; the device is supposed to respond with 0xfa; I wonder what scancodes the device reports... It smells strongly of PS/2.

Also, it is not controller that supports PS/2 commands but rather the device itself so I am still hopeful that we could make use of the standard drivers.

We can speculate on the reasons that the firmware on the EC uses 0xF4 & 0xFA for init and ack - my guess would be for a minimal amount of commonality with the PS/2 protocol - but it doesn't emulate the rest of the PS/2 protocol for the GPIO matrix device. I tried with atkbd. It issues reset, getid, setleds - all of which fail with no response from the EC. It only responds to F4.

The scancodes reported are whatever the firmware provides. A previous version of firmware had some non-standard values and the driver had to use a look-up table to convert them to something useful. With the change to the current keyboard layout Quanta changed the scancodes reported to match the KEY_* values in input.h, which is why there is no table in the current driver.

--
Neil

Signature · 2 lines
Sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
maintainer
#7 lore raw
Quoted 26 lines · Neil Leeder
Quoted 3 lines · Dmitry Torokhov

And still you are using only one GPIO in your driver? While WPCE775x does seem to have matrix keypad support I think that you are using one of the 3 PS/2 ports, like your touchpad does.

Hi Dmitry,

I can assure you that the keyboard is on the 8*18 GPIO matrix on the Nuvoton EC (only 8*16 being used in the current design). There certainly are 3 PS/2 ports on the EC, but in the board designs I have only one of those is used as a PS/2 port, and that is for the touchpad. The other two ports are muxed with GPIOs and the pins are being used as GPIOs for other functions, not PS/2 ports.

The firmware on the EC converts keypresses on the GPIO matrix to scancodes and sends them over I2C. The single GPIO used by the keyboard driver is an interrupt.

Quoted 7 lines

The device is initialized with 0xf4; the device is supposed to respond with 0xfa; I wonder what scancodes the device reports... It smells strongly of PS/2.

Also, it is not controller that supports PS/2 commands but rather the device itself so I am still hopeful that we could make use of the standard drivers.

Quoted 6 lines

We can speculate on the reasons that the firmware on the EC uses 0xF4 & 0xFA for init and ack - my guess would be for a minimal amount of commonality with the PS/2 protocol - but it doesn't emulate the rest of the PS/2 protocol for the GPIO matrix device. I tried with atkbd. It issues reset, getid, setleds - all of which fail with no response from the EC. It only responds to F4.

OK, I give up on pursuit of serio solution. Again ;)

Quoted 7 lines

The scancodes reported are whatever the firmware provides. A previous version of firmware had some non-standard values and the driver had to use a look-up table to convert them to something useful. With the change to the current keyboard layout Quanta changed the scancodes reported to match the KEY_* values in input.h, which is why there is no table in the current driver.

I believe we still should support changing keymap via EVIOCSKEYCODE so we need to have the keymap even though the initial seed is 1:1 with scancodes.

Signature · 1 line
Dmitry
#8 lore raw
Quoted 2 lines · Dmitry Torokhov

OK, I give up on pursuit of serio solution. Again ;)

Dmitry,

Don't give up yet... I've been talking to Quanta and they are using a different EC in their new products, which should have better firmware support for serio over i2c. When I get the new hardware I will try again to overcome the issues that showed up on the previous firmware, and I'll submit new patches for both touchpad and keyboard.

Thanks.

--
Neil

Signature · 2 lines
Sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
maintainer
#9 lore raw

Hi Neil,

Quoted 9 lines · Neil Leeder
Quoted 2 lines · Dmitry Torokhov

OK, I give up on pursuit of serio solution. Again ;)

Dmitry,

Don't give up yet... I've been talking to Quanta and they are using a different EC in their new products, which should have better firmware support for serio over i2c.

This is great!

Quoted 5 lines

When I get the new hardware I
will try again to overcome the issues that showed up on the previous firmware, and I'll submit new patches for both touchpad and keyboard.

Does this mean you are not interested in getting drivers for the current generation of hardware to mainline?

Otherwise, please take a glance at these patches (I did some renaming/reformatting) and let me know if I broke them. The main question is whether 0xF5 works for shutting off the keyboard and the touchpad - I rather dislike that the drivers are asymmetrical in sense that they implement open() methods but not close().

Thanks.

Signature · 1 line
Dmitry

Input: add qci keyboard driver

From: Neil Leeder <[email protected]>

This driver is for the QCI i2c keyboard used on Quanta smartbooks.

[[email protected]: cleanup to latest kernel standards]

---

 drivers/input/keyboard/Kconfig     |   12 ++
 drivers/input/keyboard/Makefile    |    1 
 drivers/input/keyboard/qci_gkbd.c  |  259 ++++++++++++++++++++++++++++++++++++
 include/linux/input/qci_keyboard.h |   25 +++
 4 files changed, 297 insertions(+), 0 deletions(-)
 create mode 100644 drivers/input/keyboard/qci_gkbd.c
 create mode 100644 include/linux/input/qci_keyboard.h
drivers/input/keyboard/Kconfig +12 -0
index d63f566..2f38feb 100644
@@ -373,6 +373,18 @@ config KEYBOARD_SAMSUNG
 	  To compile this driver as a module, choose M here: the
 	  module will be called samsung-keypad.
 
+config KEYBOARD_QCIGKBD
+	tristate "Quanta Computer Inc. keyboard"
+	depends on I2C
+	help
+	  This driver supports the i2c keyboard on Quanta smartbook devices.
+
+	  Say Y here if you have a Quanta-based smartbook or notepad
+	  device and want to use the Quanta i2c keyboard driver.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called qci_gkbd.
+
 config KEYBOARD_STOWAWAY
 	tristate "Stowaway keyboard"
 	select SERIO
drivers/input/keyboard/Makefile +1 -0
index c13809c..82f69f7 100644
@@ -34,6 +34,7 @@ obj-$(CONFIG_KEYBOARD_OMAP4)		+= omap4-keypad.o
 obj-$(CONFIG_KEYBOARD_OPENCORES)	+= opencores-kbd.o
 obj-$(CONFIG_KEYBOARD_PXA27x)		+= pxa27x_keypad.o
 obj-$(CONFIG_KEYBOARD_PXA930_ROTARY)	+= pxa930_rotary.o
+obj-$(CONFIG_KEYBOARD_QCIGKBD)		+= qci_gkbd.o
 obj-$(CONFIG_KEYBOARD_QT2160)		+= qt2160.o
 obj-$(CONFIG_KEYBOARD_SAMSUNG)		+= samsung-keypad.o
 obj-$(CONFIG_KEYBOARD_SH_KEYSC)		+= sh_keysc.o
drivers/input/keyboard/qci_gkbd.c new file +259 -0

259 lines not on this page · raw message

include/linux/input/qci_keyboard.h new file +25 -0
new file mode 100644
index 0000000..b32b7fc
@@ -0,0 +1,25 @@
+/* Copyright (c) 2010, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef __QCI_KEYBOARD_H
+#define __QCI_KEYBOARD_H
+
+struct qci_keyboard_platform_data {
+	unsigned long irq_trigger_type;
+};
+
+#endif

Input: add qci touchpad driver

From: Neil Leeder <[email protected]>

This driver is for the QCI trackpad used on Quanta smartbooks

[[email protected]: cleanup i2c calls, address review comments etc]

---

 drivers/input/mouse/Kconfig        |   12 ++
 drivers/input/mouse/Makefile       |    1 
 drivers/input/mouse/qci_touchpad.c |  279 ++++++++++++++++++++++++++++++++++++
 include/linux/input/qci_touchpad.h |   25 +++
 4 files changed, 317 insertions(+), 0 deletions(-)
 create mode 100644 drivers/input/mouse/qci_touchpad.c
 create mode 100644 include/linux/input/qci_touchpad.h
drivers/input/mouse/Kconfig +12 -0
index c714ca2..fec262a 100644
@@ -303,6 +303,18 @@ config MOUSE_MAPLE
 	  To compile this driver as a module choose M here: the module will be
 	  called maplemouse.
 
+config MOUSE_QCITP
+	tristate "Quanta Computer Inc. I2C Touchpad"
+	depends on I2C
+	help
+	  This driver supports the touchpad on Quanta smartbook devices.
+
+	  Say Y here if you have a Quanta-based smartbook or notepad
+	  device and want to use the Quanta i2c touchpad driver.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called qci_touchpad.
+
 config MOUSE_SYNAPTICS_I2C
 	tristate "Synaptics I2C Touchpad support"
 	depends on I2C
drivers/input/mouse/Makefile +1 -0
index 570c84a4..6eda35d 100644
@@ -15,6 +15,7 @@ obj-$(CONFIG_MOUSE_MAPLE)		+= maplemouse.o
 obj-$(CONFIG_MOUSE_PC110PAD)		+= pc110pad.o
 obj-$(CONFIG_MOUSE_PS2)			+= psmouse.o
 obj-$(CONFIG_MOUSE_PXA930_TRKBALL)	+= pxa930_trkball.o
+obj-$(CONFIG_MOUSE_QCITP)		+= qci_touchpad.o
 obj-$(CONFIG_MOUSE_RISCPC)		+= rpcmouse.o
 obj-$(CONFIG_MOUSE_SERIAL)		+= sermouse.o
 obj-$(CONFIG_MOUSE_SYNAPTICS_I2C)	+= synaptics_i2c.o
drivers/input/mouse/qci_touchpad.c new file +279 -0

279 lines not on this page · raw message

include/linux/input/qci_touchpad.h new file +25 -0
new file mode 100644
index 0000000..8e266e4
@@ -0,0 +1,25 @@
+/* Copyright (c) 2010, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef __QCI_TOUCHPAD_H
+#define __QCI_TOUCHPAD_H
+
+struct qci_touchpad_platform_data {
+	unsigned long irq_trigger_type;
+};
+
+#endif

Input: qci_gkbd - allow changing keymap from userspace

From: Dmitry Torokhov <[email protected]>

Wire up input->keycode, input->keycodemax and input->keycodesize so that EVIOGSKEYCODE ioctl works for the device and users can adjust keymap from userspace.

---

 drivers/input/keyboard/qci_gkbd.c |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)
drivers/input/keyboard/qci_gkbd.c +10 -2
index 6cc06c4..905d76b 100644
@@ -46,6 +46,7 @@ struct qci_keyboard {
 	struct input_dev *input;
 	unsigned int gpio;
 	unsigned int irq;
+	unsigned short keymap[QCI_KEYBOARD_MAX_KEY + 1];
 };
 
 #ifdef CONFIG_PM
@@ -96,7 +97,7 @@ static irqreturn_t qcikbd_interrupt(int irq, void *dev_id)
 
 	if (scancode) {
 		input_event(input, EV_MSC, MSC_SCAN, scancode);
-		input_report_key(input, scancode, down);
+		input_report_key(input, qcikbd->keymap[scancode], down);
 		input_sync(input);
 	}
 
@@ -161,9 +162,16 @@ static int __devinit qcikbd_probe(struct i2c_client *client,
 	__set_bit(EV_REP, input->evbit);
 	__set_bit(MSC_SCAN, input->mscbit);
 
+	input->keycode = qcikbd->keymap;
+	input->keycodesize = sizeof(qcikbd->keymap[0]);
+	input->keycodemax = ARRAY_SIZE(qcikbd->keymap);
+
 	/* Enable all supported keys */
-	for (i = 1; i <= QCI_KEYBOARD_MAX_KEY; i++)
+	for (i = 1; i <= QCI_KEYBOARD_MAX_KEY; i++) {
+		/* Initial keymap has 1:1 scancode - keycode mapping */
+		qcikbd->keymap[i] = i;
 		__set_bit(i, input->keybit);
+	}
 
 	input_set_drvdata(qcikbd->input, qcikbd);
 
#10 lore raw
Quoted 3 lines · Dmitry Torokhov

Does this mean you are not interested in getting drivers for the current generation of hardware to mainline?

Hi Dmitry,

That's correct - I don't think there is much future for the current hardware if we can come up with a cleaner solution for the new versions.
I will test 0xF5 with the new hardware. I think we may still need a
new keyboard driver, just rewritten to have a serio backend. If so, I will incorporate your changes as well as Trilok's review comments. Thanks for your reviews and code suggestions.

--
Neil

Signature · 2 lines
Sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
maintainer
#11 lore raw
Quoted 10 lines · Neil Leeder
Quoted 3 lines · Dmitry Torokhov

Does this mean you are not interested in getting drivers for the current generation of hardware to mainline?

Hi Dmitry,

That's correct - I don't think there is much future for the current hardware if we can come up with a cleaner solution for the new versions.

Ah, OK, I see.

Quoted 3 lines

I will test 0xF5 with the new hardware. I think we may still need a new keyboard driver, just rewritten to have a serio backend.

It would be great if newer hardware could make use of the atkbd driver (if it is going to use serio + PS/2 ports on the EC).

Thanks.

Signature · 1 line
Dmitry