Skip to contentSkip to conversation

input: Add new sun4i-lradc-keys driver

PATCH RESEND Superseded Hans de Goede 2 participants 4 messages Dec 17, 2014 – Dec 18, 2014

Subsystems (5)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH RESEND v2 1/1 input: Add new sun4i-lradc-keys driver

Hi Dmitry,

AFAIK everyone likes the new dt interface from v2, so this one should have been merged, but it appears to have fallen through the cracks.

Can you please queue this up for 3.19 or 3.20 ?

Note this is an unmodified resend of the v2 I send a while back, for completeness sake here is the changelog:

Changes in v2:
-Change devicetree bindings to use a per key subnode, like gpio-keys does

Thanks & Regards,

Hans

#1 lore raw

PATCH RESEND v2 1/1 input: Add new sun4i-lradc-keys driver

Allwinnner sunxi SoCs have a low resolution adc (called lradc) which is specifically designed to have various (tablet) keys (ie home, back, search, etc). attached to it using a resistor network. This adds a driver for this.

There are 2 channels, currently this driver only supports chan0 since there are no boards known to use chan1.

This has been tested on an olimex a10s-olinuxino-micro, a13-olinuxino, and a20-olinuxino-micro.

--
Changes in v2:
-Change devicetree bindings to use a per key subnode, like gpio-keys does

---
 .../devicetree/bindings/input/sun4i-lradc-keys.txt |  62 +++++
 MAINTAINERS                                        |   7 +
 drivers/input/keyboard/Kconfig                     |  10 +
 drivers/input/keyboard/Makefile                    |   1 +
 drivers/input/keyboard/sun4i-lradc-keys.c          | 258 +++++++++++++++++++++
 5 files changed, 338 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/sun4i-lradc-keys.txt
 create mode 100644 drivers/input/keyboard/sun4i-lradc-keys.c
Documentation/devicetree/bindings/input/sun4i-lradc-keys.txt new file +62 -0
new file mode 100644
index 0000000..b9c32f6
@@ -0,0 +1,62 @@
+Allwinner sun4i low res adc attached tablet keys
+------------------------------------------------
+
+Required properties:
+ - compatible: "allwinner,sun4i-a10-lradc-keys"
+ - reg: mmio address range of the chip
+ - interrupts: interrupt to which the chip is connected
+ - vref-supply: powersupply for the lradc reference voltage
+
+Each key is represented as a sub-node of "allwinner,sun4i-a10-lradc-keys":
+
+Required subnode-properties:
+	- label: Descriptive name of the key.
+	- linux,code: Keycode to emit.
+	- channel: Channel this key is attached to, mut be 0 or 1.
+	- voltage: Voltage in ?V at lradc input when this key is pressed.
+
+Example:
+
+#include <dt-bindings/input/input.h>
+
+	lradc: lradc at 01c22800 {
+		compatible = "allwinner,sun4i-a10-lradc-keys";
+		reg = <0x01c22800 0x100>;
+		interrupts = <31>;
+		vref-supply = <&reg_vcc3v0>;
+
+		button at 191 {
+			label = "Volume Up";
+			linux,code = <KEY_VOLUMEUP>;
+			channel = <0>;
+			voltage = <191274>;
+		};
+
+		button at 392 {
+			label = "Volume Down";
+			linux,code = <KEY_VOLUMEDOWN>;
+			channel = <0>;
+			voltage = <392644>;
+		};
+
+		button at 601 {
+			label = "Menu";
+			linux,code = <KEY_MENU>;
+			channel = <0>;
+			voltage = <601151>;
+		};
+
+		button at 795 {
+			label = "Enter";
+			linux,code = <KEY_ENTER>;
+			channel = <0>;
+			voltage = <795090>;
+		};
+
+		button at 987 {
+			label = "Home";
+			linux,code = <KEY_HOMEPAGE>;
+			channel = <0>;
+			voltage = <987387>;
+		};
+	};
MAINTAINERS +7 -0
index fdffe96..fb3d33e 100644
@@ -9193,6 +9193,13 @@ F:	arch/m68k/sun3*/
 F:	arch/m68k/include/asm/sun3*
 F:	drivers/net/ethernet/i825xx/sun3*
 
+SUN4I LOW RES ADC ATTACHED TABLET KEYS DRIVER
+M:	Hans de Goede <[email protected]>
+L:	linux-input at vger.kernel.org
+S:	Maintained
+F:	Documentation/devicetree/bindings/input/sun4i-lradc-keys.txt
+F:	drivers/input/keyboard/sun4i-lradc-keys.c
+
 SUNDANCE NETWORK DRIVER
 M:	Denis Kirjanov <[email protected]>
 L:	netdev at vger.kernel.org
drivers/input/keyboard/Kconfig +10 -0
index a3958c6..2d11b44 100644
@@ -567,6 +567,16 @@ config KEYBOARD_STMPE
 	  To compile this driver as a module, choose M here: the module will be
 	  called stmpe-keypad.
 
+config KEYBOARD_SUN4I_LRADC
+	tristate "Allwinner sun4i low res adc attached tablet keys support"
+	depends on ARCH_SUNXI
+	help
+	  This selects support for the Allwinner low res adc attached tablet
+	  keys found on Allwinner sunxi SoCs.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called sun4i-lradc-keys.
+
 config KEYBOARD_DAVINCI
 	tristate "TI DaVinci Key Scan"
 	depends on ARCH_DAVINCI_DM365
drivers/input/keyboard/Makefile +1 -0
index 0a33456..a35269a 100644
@@ -53,6 +53,7 @@ obj-$(CONFIG_KEYBOARD_SPEAR)		+= spear-keyboard.o
 obj-$(CONFIG_KEYBOARD_STMPE)		+= stmpe-keypad.o
 obj-$(CONFIG_KEYBOARD_STOWAWAY)		+= stowaway.o
 obj-$(CONFIG_KEYBOARD_ST_KEYSCAN)	+= st-keyscan.o
+obj-$(CONFIG_KEYBOARD_SUN4I_LRADC)	+= sun4i-lradc-keys.o
 obj-$(CONFIG_KEYBOARD_SUNKBD)		+= sunkbd.o
 obj-$(CONFIG_KEYBOARD_TC3589X)		+= tc3589x-keypad.o
 obj-$(CONFIG_KEYBOARD_TEGRA)		+= tegra-kbc.o
drivers/input/keyboard/sun4i-lradc-keys.c new file +258 -0

258 lines not on this page · raw message

Signature · 1 line
2.1.0
maintainer
#2 lore raw

PATCH RESEND v2 1/1 input: Add new sun4i-lradc-keys driver

Quoted 14 lines · Hans de Goede
drivers/input/keyboard/sun4i-lradc-keys.c new file +14 -0
+       /*
+        * lradc supports only one keypress at a time, release does not give
+        * any info as to which key was released, so we cache the keycode.
+        */
+       if ((ints & CHAN0_KEYDOWN_IRQ) && lradc->chan0_keycode == 0) {
+               val = readl(lradc->base + LRADC_DATA0) & 0x3f;
+               voltage = val * lradc->vref / 63;
+
+               for (i = 0; i < lradc->chan0_map_count; i++) {
+                       diff = abs(lradc->chan0_map[i].voltage - voltage);
+                       if (diff < closest) {
+                               closest = diff;
+                               keycode = lradc->chan0_map[i].keycode;
+                       }

drivers/input/keyboard/sun4i-lradc-keys.c line 112

Quoted 10 lines
drivers/input/keyboard/sun4i-lradc-keys.c new file +10 -0
+               }
+
+               lradc->chan0_keycode = keycode;
+               input_report_key(lradc->input, lradc->chan0_keycode, 1);
+       }
+
+       if (ints & CHAN0_KEYUP_IRQ) {
+               input_report_key(lradc->input, lradc->chan0_keycode, 0);
+               lradc->chan0_keycode = 0;
+       }

Can release and press be reported simultaneously? Should we process release first?

Thanks.

Signature · 1 line
Dmitry
#3 lore raw

PATCH RESEND v2 1/1 input: Add new sun4i-lradc-keys driver

Hi,

Quoted 20 lines · Dmitry Torokhov
Quoted 19 lines · Hans de Goede
drivers/input/keyboard/sun4i-lradc-keys.c new file +19 -0
+       /*
+        * lradc supports only one keypress at a time, release does not give
+        * any info as to which key was released, so we cache the keycode.
+        */
+       if ((ints & CHAN0_KEYDOWN_IRQ) && lradc->chan0_keycode == 0) {
+               val = readl(lradc->base + LRADC_DATA0) & 0x3f;
+               voltage = val * lradc->vref / 63;
+
+               for (i = 0; i < lradc->chan0_map_count; i++) {
+                       diff = abs(lradc->chan0_map[i].voltage - voltage);
+                       if (diff < closest) {
+                               closest = diff;
+                               keycode = lradc->chan0_map[i].keycode;
+                       }
+               }
+
+               lradc->chan0_keycode = keycode;
+               input_report_key(lradc->input, lradc->chan0_keycode, 1);
+       }
Quoted 8 lines

drivers/input/keyboard/sun4i-lradc-keys.c line 112

Quoted 5 lines
drivers/input/keyboard/sun4i-lradc-keys.c new file +5 -0
+
+       if (ints & CHAN0_KEYUP_IRQ) {
+               input_report_key(lradc->input, lradc->chan0_keycode, 0);
+               lradc->chan0_keycode = 0;
+       }

Can release and press be reported simultaneously? Should we process release first?

Good question, I guess if we are somehow really slow with processing the interrupt that this may happen. So I'll do a v3 swapping the 2.

Regards,

Hans