input: Add new sun4i-ts driver for Allwinner sunxi
Subsystems (4)
v3 cover input: Add new sun4i-ts driver for Allwinner sunxi
Hi All,
Here is v3 of my sun4i-ts driver for Allwinner sunxi patch-set.
Changed this version:
-Addressed review comments from Dimitri
-Addressed review comments from Guenter
-Addressed review comments from Maxime
-Initialize ignore_fifo_data to true, the very first coordinate can be
wrong too
Thanks & Regards,
Hans
PATCH v3 1/5 input: Add new sun4i-ts driver for Allwinner sunxi SoC's rtp controller
Note the sun4i-ts controller is capable of detecting a second touch, but when a second touch is present then the accuracy becomes so bad the reported touch location is not useable.
The original android driver contains some complicated heuristics using the aprox. distance between the 2 touches to see if the user is making a pinch open / close movement, and then reports emulated multi-touch events around the last touch coordinate (as the dual-touch coordinates are worthless).
These kinds of heuristics are just asking for trouble (and don't belong in the kernel). So this driver offers straight forward, reliable single touch functionality only.
--- .../bindings/input/touchscreen/sun4i.txt | 15 ++ drivers/input/touchscreen/Kconfig | 10 + drivers/input/touchscreen/Makefile | 1 + drivers/input/touchscreen/sun4i-ts.c | 262 +++++++++++++++++++++ 4 files changed, 288 insertions(+) create mode 100644 Documentation/devicetree/bindings/input/touchscreen/sun4i.txt create mode 100644 drivers/input/touchscreen/sun4i-ts.c
Documentation/devicetree/bindings/input/touchscreen/sun4i.txt new file +15 -0
@@ -0,0 +1,15 @@ +sun4i resistive touchscreen controller +-------------------------------------- + +Required properties: + - compatible: "allwinner,sun4i-ts" + - reg: mmio address range of the chip + - interrupts: interrupt to which the chip is connected + +Example: + + rtp: rtp at 01c25000 { + compatible = "allwinner,sun4i-ts"; + reg = <0x01c25000 0x100>; + interrupts = <29>; + };
drivers/input/touchscreen/Kconfig +10 -0
@@ -906,6 +906,16 @@ config TOUCHSCREEN_STMPE To compile this driver as a module, choose M here: the module will be called stmpe-ts. +config TOUCHSCREEN_SUN4I + tristate "Allwinner sun4i resistive touchscreen controller support" + depends on ARCH_SUNXI + help + This selects support for the resistive touchscreen controller + found on Allwinner sunxi SoCs. + + To compile this driver as a module, choose M here: the + module will be called sun4i-ts. + config TOUCHSCREEN_SUR40 tristate "Samsung SUR40 (Surface 2.0/PixelSense) touchscreen" depends on USB
drivers/input/touchscreen/Makefile +1 -0
@@ -54,6 +54,7 @@ obj-$(CONFIG_TOUCHSCREEN_PIXCIR) += pixcir_i2c_ts.o obj-$(CONFIG_TOUCHSCREEN_S3C2410) += s3c2410_ts.o obj-$(CONFIG_TOUCHSCREEN_ST1232) += st1232.o obj-$(CONFIG_TOUCHSCREEN_STMPE) += stmpe-ts.o +obj-$(CONFIG_TOUCHSCREEN_SUN4I) += sun4i-ts.o obj-$(CONFIG_TOUCHSCREEN_SUR40) += sur40.o obj-$(CONFIG_TOUCHSCREEN_TI_AM335X_TSC) += ti_am335x_tsc.o obj-$(CONFIG_TOUCHSCREEN_TNETV107X) += tnetv107x-ts.o
drivers/input/touchscreen/sun4i-ts.c new file +262 -0
262 lines not on this page · raw message
Signature · 1 line
1.8.4.2
PATCH v3 2/5 input: sun4i-ts: Add support for temperature sensor
In reply to Hans de GoedeThe sun4i resisitive touchscreen controller also comes with a built-in temperature sensor. This commit adds support for it.
This commit also introduces a new "ts-attached" device-tree property, when this is not set, the input part of the driver won't register. This way the internal temperature sensor can be used to measure the SoC temperature independent of there actually being a touchscreen attached to the controller.
--- .../bindings/input/touchscreen/sun4i.txt | 5 + drivers/input/touchscreen/sun4i-ts.c | 140 ++++++++++++++++----- 2 files changed, 114 insertions(+), 31 deletions(-)
Documentation/devicetree/bindings/input/touchscreen/sun4i.txt +5 -0
@@ -6,10 +6,15 @@ Required properties: - reg: mmio address range of the chip - interrupts: interrupt to which the chip is connected +Optional properties: + - allwinner,ts-attached: boolean indicating that an actual touchscreen is + attached to the controller + Example: rtp: rtp at 01c25000 { compatible = "allwinner,sun4i-ts"; reg = <0x01c25000 0x100>; interrupts = <29>; + allwinner,ts-attached; };
drivers/input/touchscreen/sun4i-ts.c +109 -31
209 lines not on this page · raw message
Signature · 1 line
1.8.4.2
PATCH v3 2/5 input: sun4i-ts: Add support for temperature sensor
Quoted 9 lines · Hans de Goede
The sun4i resisitive touchscreen controller also comes with a built-in temperature sensor. This commit adds support for it.
This commit also introduces a new "ts-attached" device-tree property, when this is not set, the input part of the driver won't register. This way the internal temperature sensor can be used to measure the SoC temperature independent of there actually being a touchscreen attached to the controller.
Signed-off-by Hans de Goede <[email protected]>
Couple of minor comments below, though no need to resubmit unless someone else has comments.
Quoted 10 lines
--- .../bindings/input/touchscreen/sun4i.txt | 5 + drivers/input/touchscreen/sun4i-ts.c | 140 ++++++++++++++++----- 2 files changed, 114 insertions(+), 31 deletions(-)Documentation/devicetree/bindings/input/touchscreen/sun4i.txt +0
-0
Documentation/devicetree/bindings/input/touchscreen/sun4i.txt Required properties: · line 12
Quoted 7 lines
Documentation/devicetree/bindings/input/touchscreen/sun4i.txt +4
-0@@ -6,10 +6,15 @@ Required properties: - reg: mmio address range of the chip - interrupts: interrupt to which the chip is connected +Optional properties: + - allwinner,ts-attached: boolean indicating that an actual touchscreen is + attached to the controller +
Brr. While I understand that you were asked to do this, I don't really see the benefit of another "allwinner" here. As if this wasn't implied by the "compatible" property.
Quoted 103 lines
Documentation/devicetree/bindings/input/touchscreen/sun4i.txt +1
-0Example: rtp: rtp at 01c25000 { compatible = "allwinner,sun4i-ts"; reg = <0x01c25000 0x100>; interrupts = <29>; + allwinner,ts-attached; };drivers/input/touchscreen/sun4i-ts.c +39
-10@@ -3,6 +3,9 @@* * Copyright (C) 2013 - 2014 Hans de Goede <[email protected]> * +* The hwmon parts are based on work by Corentin LABBE which is: +* Copyright (C) 2013 Corentin LABBE <[email protected]> +* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or @@ -30,6 +33,7 @@*/ #include <linux/err.h> +#include <linux/hwmon.h> #include <linux/init.h> #include <linux/input.h> #include <linux/interrupt.h> @@ -106,14 +110,12 @@ struct sun4i_ts_data {void __iomem *base;unsigned int irq;bool ignore_fifo_data; +int temp_data; }; -static irqreturn_t sun4i_ts_irq (int irq,void *dev_id) +static void sun4i_ts_irq_handle_input (struct sun4i_ts_data *ts,u32 reg_val) { -struct sun4i_ts_data *ts = dev_id; -u32 reg_val, x, y; - - reg_val =readl (ts->base +TP_INT_FIFOS ); +u32 x, y;if (reg_val &FIFO_DATA_PENDING ) { x =readl (ts->base +TP_DATA );@@ -139,6 +141,20 @@ static irqreturn_t sun4i_ts_irq(int irq, void *dev_id)input_report_key (ts->input,BTN_TOUCH ,0 );input_sync (ts->input); } +} + +static irqreturn_t sun4i_ts_irq (int irq,void *dev_id) +{ +struct sun4i_ts_data *ts = dev_id; +u32 reg_val; + + reg_val =readl (ts->base +TP_INT_FIFOS ); + +if (reg_val &TEMP_DATA_PENDING ) + ts->temp_data =readl (ts->base +TEMP_DATA ); + +if (ts->input) +sun4i_ts_irq_handle_input (ts, reg_val);writel (reg_val, ts->base +TP_INT_FIFOS );@@ -149,9 +165,9 @@ static int sun4i_ts_open(struct input_dev *dev) {struct sun4i_ts_data *ts =input_get_drvdata (dev); -/* Flush, set trig level to 1, enable data and up irqs */ -writel (DATA_IRQ_EN (1 ) |FIFO_TRIG (1 ) |FIFO_FLUSH (1 ) |TP_UP_IRQ_EN (1 ), - ts->base +TP_INT_FIFOC ); +/* Flush, set trig level to 1, enable temp, data and up irqs */ +writel (TEMP_IRQ_EN (1 ) |DATA_IRQ_EN (1 ) |FIFO_TRIG (1 ) |FIFO_FLUSH (1 ) | +TP_UP_IRQ_EN (1 ), ts->base +TP_INT_FIFOC );return 0 ; }@@ -160,15 +176,48 @@ static void sun4i_ts_close(struct input_dev *dev) {struct sun4i_ts_data *ts =input_get_drvdata (dev); -/* Deactivate all IRQs */ -writel (0 , ts->base +TP_INT_FIFOC ); +/* Deactivate all input IRQs */ +writel (TEMP_IRQ_EN (1 ), ts->base +TP_INT_FIFOC ); +} + +static ssize_t show_temp (struct device *dev,struct device_attribute *devattr, +char *buf) +{ +struct sun4i_ts_data *ts =dev_get_drvdata (dev); + +/* No temp_data until the first irq */ +if (ts->temp_data ==-1 ) +return -EAGAIN ; + +return sprintf (buf,"%d\n" , (ts->temp_data -1447 ) *100 ); +}
drivers/input/touchscreen/sun4i-ts.c static void sun4i_ts_close(struct input_dev *dev) · line 203
Quoted 10 lines
drivers/input/touchscreen/sun4i-ts.c +8
-0+ +static ssize_t show_temp_label (struct device *dev, +struct device_attribute *devattr,char *buf) +{ +return sprintf (buf,"SoC temperature\n" ); } +static DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL); +static DEVICE_ATTR(temp1_label, S_IRUGO, show_temp_label, NULL); +
Just remembered ... there is now also a DEVICE_ATTR_RO() macro.
Quoted 118 lines
drivers/input/touchscreen/sun4i-ts.c +62
-21+static struct attribute *sun4i_ts_attrs[] = { + &dev_attr_temp1_input.attr, + &dev_attr_temp1_label.attr, +NULL +}; +ATTRIBUTE_GROUPS (sun4i_ts); +static int sun4i_ts_probe (struct platform_device *pdev) {struct sun4i_ts_data *ts;struct device *dev = &pdev->dev; +struct device_node *np = dev->of_node; +struct device *hwmon;int ret; +bool ts_attached; + + ts_attached =of_property_read_bool (np,"allwinner,ts-attached" ); ts =devm_kzalloc (dev,sizeof (struct sun4i_ts_data ),GFP_KERNEL );if (!ts)@@ -176,24 +225,27 @@ static int sun4i_ts_probe(struct platform_device *pdev) ts->dev = dev; ts->ignore_fifo_data = true; - - ts->input =devm_input_allocate_device (dev); -if (!ts->input) -return -ENOMEM ; - - ts->input->name = pdev->name; - ts->input->phys ="sun4i_ts/input0" ; - ts->input->open = sun4i_ts_open; - ts->input->close = sun4i_ts_close; - ts->input->id.bustype =BUS_HOST ; - ts->input->id.vendor =0x0001 ; - ts->input->id.product =0x0001 ; - ts->input->id.version =0x0100 ; - ts->input->evbit[0 ] =BIT (EV_SYN ) |BIT (EV_KEY ) |BIT (EV_ABS ); -set_bit (BTN_TOUCH , ts->input->keybit); -input_set_abs_params (ts->input,ABS_X ,0 ,4095 ,0 ,0 ); -input_set_abs_params (ts->input,ABS_Y ,0 ,4095 ,0 ,0 ); -input_set_drvdata (ts->input, ts); + ts->temp_data =-1 ; + +if (ts_attached) { + ts->input =devm_input_allocate_device (dev); +if (!ts->input) +return -ENOMEM ; + + ts->input->name = pdev->name; + ts->input->phys ="sun4i_ts/input0" ; + ts->input->open = sun4i_ts_open; + ts->input->close = sun4i_ts_close; + ts->input->id.bustype =BUS_HOST ; + ts->input->id.vendor =0x0001 ; + ts->input->id.product =0x0001 ; + ts->input->id.version =0x0100 ; + ts->input->evbit[0 ] =BIT (EV_SYN ) |BIT (EV_KEY ) |BIT (EV_ABS ); +set_bit (BTN_TOUCH , ts->input->keybit); +input_set_abs_params (ts->input,ABS_X ,0 ,4095 ,0 ,0 ); +input_set_abs_params (ts->input,ABS_Y ,0 ,4095 ,0 ,0 ); +input_set_drvdata (ts->input, ts); + } ts->base =devm_ioremap_resource (dev,platform_get_resource (pdev,IORESOURCE_MEM ,0 ));@@ -232,14 +284,39 @@ static int sun4i_ts_probe(struct platform_device *pdev)writel (STYLUS_UP_DEBOUN (5 ) |STYLUS_UP_DEBOUN_EN (1 ) |TP_MODE_EN (1 ), ts->base +TP_CTRL1 ); - ret =input_register_device (ts->input); -if (ret) -return ret; + hwmon =devm_hwmon_device_register_with_groups (ts->dev,"sun4i_ts" , + ts, sun4i_ts_groups); +if (IS_ERR (hwmon)) +return PTR_ERR (hwmon); + +writel (TEMP_IRQ_EN (1 ), ts->base +TP_INT_FIFOC ); + +if (ts_attached) { + ret =input_register_device (ts->input); +if (ret) { +writel (0 , ts->base +TP_INT_FIFOC ); +return ret; + } + }platform_set_drvdata (pdev, ts);return 0 ; } +static int sun4i_ts_remove (struct platform_device *pdev) +{ +struct sun4i_ts_data *ts =platform_get_drvdata (pdev); + +/* Explicit unregister to avoid open/close changing the imask later */ +if (ts->input) +input_unregister_device (ts->input); + +/* Deactivate all IRQs */ +writel (0 , ts->base +TP_INT_FIFOC ); + +return 0 ; +} +static const struct of_device_id sun4i_ts_of_match[] = { { .compatible ="allwinner,sun4i-ts" , }, {/* sentinel */ }@@ -253,6 +330,7 @@ static struct platform_driver sun4i_ts_driver = { .of_match_table = of_match_ptr(sun4i_ts_of_match), }, .probe = sun4i_ts_probe, + .remove = sun4i_ts_remove, };module_platform_driver (sun4i_ts_driver);
PATCH v3 2/5 input: sun4i-ts: Add support for temperature sensor
Hi Guenter,
Quoted 28 lines · Guenter Roeck
Quoted 9 lines · Hans de Goede
The sun4i resisitive touchscreen controller also comes with a built-in temperature sensor. This commit adds support for it.
This commit also introduces a new "ts-attached" device-tree property, when this is not set, the input part of the driver won't register. This way the internal temperature sensor can be used to measure the SoC temperature independent of there actually being a touchscreen attached to the controller.
Signed-off-by Hans de Goede <[email protected]>Couple of minor comments below, though no need to resubmit unless someone else has comments.
Reviewed-by Guenter Roeck <[email protected]>Quoted 13 lines
--- .../bindings/input/touchscreen/sun4i.txt | 5 + drivers/input/touchscreen/sun4i-ts.c | 140 ++++++++++++++++----- 2 files changed, 114 insertions(+), 31 deletions(-)Documentation/devicetree/bindings/input/touchscreen/sun4i.txt +0
-0@@ -6,10 +6,15 @@ Required properties: - reg: mmio address range of the chip - interrupts: interrupt to which the chip is connected
Quoted 7 lines
Documentation/devicetree/bindings/input/touchscreen/sun4i.txt Required properties: · line 12
Quoted 4 lines
Documentation/devicetree/bindings/input/touchscreen/sun4i.txt +4
-0+Optional properties: + - allwinner,ts-attached: boolean indicating that an actual touchscreen is + attached to the controller +Brr. While I understand that you were asked to do this, I don't really see the benefit of another "allwinner" here. As if this wasn't implied by the "compatible" property.
It's actually the ePAPR that recommends this.
Section 6.1.1, General Principles
"
Some recommended practices includes:
[..]
5. If new properties are needed by the binding, the recommended format for property names is: ?<company>,<property-name>?, where <company> is an OUI or short unique string like a stock ticker that identifies the creator of the binding.
"
Maxime
Signature · 10 lines
Maxime Ripard, Free Electrons Embedded Linux, Kernel and Android engineering http://free-electrons.com -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20140106/24b37344/attachment.sig>
PATCH v3 3/5 ARM: dts: sun4i: Add rtp controller node
In reply to Hans de Goede--- arch/arm/boot/dts/sun4i-a10.dtsi | 6 ++++++ 1 file changed, 6 insertions(+)
arch/arm/boot/dts/sun4i-a10.dtsi +6 -0
@@ -452,6 +452,12 @@ reg = <0x01c23800 0x10>; }; + rtp: rtp at 01c25000 { + compatible = "allwinner,sun4i-ts"; + reg = <0x01c25000 0x100>; + interrupts = <29>; + }; + uart0: serial at 01c28000 { compatible = "snps,dw-apb-uart"; reg = <0x01c28000 0x400>;
Signature · 1 line
1.8.4.2
Maxime Ripard
AppliedPATCH v3 3/5 ARM: dts: sun4i: Add rtp controller node
Quoted 1 line · Hans de Goede
Signed-off-by Hans de Goede <[email protected]>
Applied, together with the patch 4/5 and 5/5, in my sunxi/dt-for-3.14 branch.
Thanks!
Maxime
Signature · 10 lines
Maxime Ripard, Free Electrons Embedded Linux, Kernel and Android engineering http://free-electrons.com -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20140101/70e3dca3/attachment.sig>
PATCH v3 4/5 ARM: dts: sun5i: Add rtp controller node
In reply to Hans de Goede--- arch/arm/boot/dts/sun5i-a10s.dtsi | 6 ++++++ arch/arm/boot/dts/sun5i-a13.dtsi | 6 ++++++ 2 files changed, 12 insertions(+)
arch/arm/boot/dts/sun5i-a10s.dtsi +6 -0
@@ -409,6 +409,12 @@ reg = <0x01c23800 0x10>; }; + rtp: rtp at 01c25000 { + compatible = "allwinner,sun4i-ts"; + reg = <0x01c25000 0x100>; + interrupts = <29>; + }; + uart0: serial at 01c28000 { compatible = "snps,dw-apb-uart"; reg = <0x01c28000 0x400>;
arch/arm/boot/dts/sun5i-a13.dtsi +6 -0
@@ -367,6 +367,12 @@ reg = <0x01c23800 0x10>; }; + rtp: rtp at 01c25000 { + compatible = "allwinner,sun4i-ts"; + reg = <0x01c25000 0x100>; + interrupts = <29>; + }; + uart1: serial at 01c28400 { compatible = "snps,dw-apb-uart"; reg = <0x01c28400 0x400>;
Signature · 1 line
1.8.4.2
PATCH v3 5/5 ARM: dts: sun7i: Add rtp controller node
In reply to Hans de Goede--- arch/arm/boot/dts/sun7i-a20.dtsi | 6 ++++++ 1 file changed, 6 insertions(+)
arch/arm/boot/dts/sun7i-a20.dtsi +6 -0
@@ -536,6 +536,12 @@ reg = <0x01c23800 0x200>; }; + rtp: rtp at 01c25000 { + compatible = "allwinner,sun4i-ts"; + reg = <0x01c25000 0x100>; + interrupts = <0 29 4>; + }; + uart0: serial at 01c28000 { compatible = "snps,dw-apb-uart"; reg = <0x01c28000 0x400>;
Signature · 1 line
1.8.4.2