Skip to contentSkip to conversation

Add device tree support to the cyttsp driver

PATCH Superseded Oreste Salerno 2 participants 6 messages Jan 5, 2016 – Jan 7, 2016

Subsystems (4)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v2 cover Add device tree support to the cyttsp driver

This set of patches adds support to the cyttsp touchscreen driver to retrieve platform data details from the device tree. Additionally, they define a default init function that performs a hard reset of the chip on boot.

---
Changes in v2:
- Fix err_cast.cocci warning in patch 2/3

Oreste Salerno (3):
Input: cyttsp - remove unused irq_gpio from platform_data
Input: cyttsp - add device tree support
Input: cyttsp - add default init function

 .../bindings/input/touchscreen/cyttsp.txt          |  73 +++++++++++++
 drivers/input/touchscreen/cyttsp_core.c            | 120 +++++++++++++++++++--
 include/linux/input/cyttsp.h                       |   4 +-
 3 files changed, 189 insertions(+), 8 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/input/touchscreen/cyttsp.txt
Signature · 1 line
1.9.1
#1 lore raw

PATCH v2 1/3 Input: cyttsp - remove unused irq_gpio from platform_data

This field is not being used and the irq is anyway passed via the 'irq' parameter to cyttsp_probe.

---
 include/linux/input/cyttsp.h | 1 -
 1 file changed, 1 deletion(-)
include/linux/input/cyttsp.h +0 -1
index 5af7c66..d7c2520 100644
@@ -51,7 +51,6 @@ struct cyttsp_platform_data {
 	int (*init)(void);
 	void (*exit)(void);
 	char *name;
-	s16 irq_gpio;
 	u8 *bl_keys;
 };
 
Signature · 1 line
1.9.1
#2 lore raw

PATCH v2 2/3 Input: cyttsp - add device tree support

In reply to Oreste Salerno

Add support for retrieving the platform data from the device tree.

---
 .../bindings/input/touchscreen/cyttsp.txt          |  73 ++++++++++++++
 drivers/input/touchscreen/cyttsp_core.c            | 108 +++++++++++++++++++--
 include/linux/input/cyttsp.h                       |   3 +
 3 files changed, 177 insertions(+), 7 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/input/touchscreen/cyttsp.txt
Documentation/devicetree/bindings/input/touchscreen/cyttsp.txt new file +73 -0
new file mode 100644
index 0000000..8e0bcc73
@@ -0,0 +1,73 @@
+* Cypress cyttsp touchscreen controller
+
+Required properties:
+- compatible		: must be "cypress,cyttsp-i2c" or "cypress,cyttsp-spi"
+- reg			: Device address
+- spi-max-frequency 	: Maximum SPI clocking speed of the device (for cyttsp-spi)
+- interrupt-parent	: the phandle for the gpio controller
+			  (see interrupt binding[0]).
+- interrupts		: (gpio) interrupt to which the chip is connected
+			  (see interrupt binding[0]).
+- reset-gpios		: the reset gpio the chip is connected to
+			  (see GPIO binding[1] for more details).
+- maxx			: horizontal resolution of touchscreen (in pixels)
+- maxy			: vertical resolution of touchscreen (in pixels)
+- bootloader-key	: the bootloader key used to exit bootloader mode
+
+Optional properties:
+- use_hndshk		: enable handshake bit
+- act_dist		: active distance
+- act_intrvl		: active refresh interval in ms
+- tch_tmout		: active touch timeout in ms
+- lp_intrvl		: low power refresh interval in ms
+
+[0]: Documentation/devicetree/bindings/interrupt-controller/interrupts.txt
+[1]: Documentation/devicetree/bindings/gpio/gpio.txt
+
+Example:
+	&i2c1 {
+		/* ... */
+		cyttsp@a {
+			compatible = "cypress,cyttsp-i2c";
+			reg = <0xa>;
+			interrupt-parent = <&msm_gpio>;
+			interrupts = <13 0x2008>;
+			reset-gpios = <&msm_gpio 12 0x00>;
+
+			maxx = <800>;
+			maxy = <480>;
+			bootloader-key = /bits/ 8 <0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08>;
+
+			use_hndshk;
+			act_dist = /bits/ 8 <0xF8>;
+			act_intrvl = /bits/ 8 <0x00>;
+			tch_tmout = /bits/ 8 <0xFF>;
+			lp_intrvl = /bits/ 8 <0x0A>;
+		};
+
+		/* ... */
+	};
+
+	&mcspi1 {
+		/* ... */
+		cyttsp@0 {
+			compatible = "cypress,cyttsp-spi";
+			spi-max-frequency = <6000000>;
+			reg = <0>;
+			interrupt-parent = <&msm_gpio>;
+			interrupts = <13 0x2008>;
+			reset-gpios = <&msm_gpio 12 0x00>;
+
+			maxx = <800>;
+			maxy = <480>;
+			bootloader-key = /bits/ 8 <0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08>;
+
+			use_hndshk;
+			act_dist = /bits/ 8 <0xF8>;
+			act_intrvl = /bits/ 8 <0x00>;
+			tch_tmout = /bits/ 8 <0xFF>;
+			lp_intrvl = /bits/ 8 <0x0A>;
+		};
+
+		/* ... */
+	};
drivers/input/touchscreen/cyttsp_core.c +101 -7

139 lines not on this page · raw message

include/linux/input/cyttsp.h +3 -0
index d7c2520..92a9d52 100644
@@ -29,6 +29,8 @@
 #ifndef _CYTTSP_H_
 #define _CYTTSP_H_
 
+#include <linux/gpio/consumer.h>
+
 #define CY_SPI_NAME "cyttsp-spi"
 #define CY_I2C_NAME "cyttsp-i2c"
 /* Active Power state scanning/processing refresh interval */
@@ -51,6 +53,7 @@ struct cyttsp_platform_data {
 	int (*init)(void);
 	void (*exit)(void);
 	char *name;
+	struct gpio_desc *reset_gpio;
 	u8 *bl_keys;
 };
 
Signature · 1 line
1.9.1
maintainer
#3 lore raw

Re: [PATCH v2 2/3] Input: cyttsp - add device tree support

Quoted 2 lines · Oreste Salerno

Add support for retrieving the platform data from the device tree.

Converting platform data to DT as is is typically not the right thing to do. There's some overlap, but it is not typically 1-1.

Quoted 14 lines
---
 .../bindings/input/touchscreen/cyttsp.txt          |  73 ++++++++++++++
 drivers/input/touchscreen/cyttsp_core.c            | 108 +++++++++++++++++++--
 include/linux/input/cyttsp.h                       |   3 +
 3 files changed, 177 insertions(+), 7 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/input/touchscreen/cyttsp.txt
Documentation/devicetree/bindings/input/touchscreen/cyttsp.txt new file +0 -0
new file mode 100644
index 0000000..8e0bcc73

Documentation/devicetree/bindings/input/touchscreen/cyttsp.txt line 5

Quoted 5 lines
Documentation/devicetree/bindings/input/touchscreen/cyttsp.txt new file +5 -0
@@ -0,0 +1,73 @@
+* Cypress cyttsp touchscreen controller
+
+Required properties:
+- compatible		: must be "cypress,cyttsp-i2c" or "cypress,cyttsp-spi"
+- reg			: Device address

...or SPI chip select number

Documentation/devicetree/bindings/input/touchscreen/cyttsp.txt line 14

Quoted 9 lines
Documentation/devicetree/bindings/input/touchscreen/cyttsp.txt new file +9 -0
+- spi-max-frequency 	: Maximum SPI clocking speed of the device (for cyttsp-spi)
+- interrupt-parent	: the phandle for the gpio controller
+			  (see interrupt binding[0]).
+- interrupts		: (gpio) interrupt to which the chip is connected
+			  (see interrupt binding[0]).
+- reset-gpios		: the reset gpio the chip is connected to
+			  (see GPIO binding[1] for more details).
+- maxx			: horizontal resolution of touchscreen (in pixels)
+- maxy			: vertical resolution of touchscreen (in pixels)

IIRC, we have standard properties for these. Touchscreens don't really have pixels...

Documentation/devicetree/bindings/input/touchscreen/cyttsp.txt line 15

Quoted 1 line
Documentation/devicetree/bindings/input/touchscreen/cyttsp.txt new file +1 -0
+- bootloader-key	: the bootloader key used to exit bootloader mode

I don't understand what this is.

Documentation/devicetree/bindings/input/touchscreen/cyttsp.txt line 20

Quoted 5 lines
Documentation/devicetree/bindings/input/touchscreen/cyttsp.txt new file +5 -0
+
+Optional properties:
+- use_hndshk		: enable handshake bit
+- act_dist		: active distance
+- act_intrvl		: active refresh interval in ms

Is this sampling frequency?

Documentation/devicetree/bindings/input/touchscreen/cyttsp.txt line 22

Quoted 2 lines
Documentation/devicetree/bindings/input/touchscreen/cyttsp.txt new file +2 -0
+- tch_tmout		: active touch timeout in ms
+- lp_intrvl		: low power refresh interval in ms

Look whether other touchscreens bindings have similar properties already and copy those. These need better definitions in general.

Don't use '_' in property names and append units to the name of properties that have units (e.g. ms).

Quoted 9 lines
Documentation/devicetree/bindings/input/touchscreen/cyttsp.txt new file +9 -0
+Example:
+	&i2c1 {
+		/* ... */
+		cyttsp@a {
+			compatible = "cypress,cyttsp-i2c";
+			reg = <0xa>;
+			interrupt-parent = <&msm_gpio>;
+			interrupts = <13 0x2008>;
+			reset-gpios = <&msm_gpio 12 0x00>;

Documentation/devicetree/bindings/input/touchscreen/cyttsp.txt line 45

Quoted 10 lines
Documentation/devicetree/bindings/input/touchscreen/cyttsp.txt new file +10 -0
+
+			maxx = <800>;
+			maxy = <480>;
+			bootloader-key = /bits/ 8 <0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08>;
+
+			use_hndshk;
+			act_dist = /bits/ 8 <0xF8>;
+			act_intrvl = /bits/ 8 <0x00>;
+			tch_tmout = /bits/ 8 <0xFF>;
+			lp_intrvl = /bits/ 8 <0x0A>;

If the size is not 32-bits, you need to state that in the description. There is not really much point in making these 8-bit though.

Rob

#4 lore raw

Re: [PATCH v2 2/3] Input: cyttsp - add device tree support

Hi Rob,

Thanks a lot for reviewing the patch. I have some comments.

Quoted 7 lines · Rob Herring
Quoted 2 lines · Oreste Salerno

Add support for retrieving the platform data from the device tree.

Converting platform data to DT as is is typically not the right thing to do. There's some overlap, but it is not typically 1-1.

What would be the criteria? I believe that the required properties are platform-specific values that need to be defined here.
As for the optional properties, they can be useful to tweak the touchscreen performance based on the use case and the hardware using the touchscreen controller.

Quoted 22 lines
Quoted 14 lines
---
 .../bindings/input/touchscreen/cyttsp.txt          |  73 ++++++++++++++
 drivers/input/touchscreen/cyttsp_core.c            | 108 +++++++++++++++++++--
 include/linux/input/cyttsp.h                       |   3 +
 3 files changed, 177 insertions(+), 7 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/input/touchscreen/cyttsp.txt
Documentation/devicetree/bindings/input/touchscreen/cyttsp.txt new file +0 -0
new file mode 100644
index 0000000..8e0bcc73

Documentation/devicetree/bindings/input/touchscreen/cyttsp.txt line 5

Quoted 5 lines
Documentation/devicetree/bindings/input/touchscreen/cyttsp.txt new file +5 -0
@@ -0,0 +1,73 @@
+* Cypress cyttsp touchscreen controller
+
+Required properties:
+- compatible		: must be "cypress,cyttsp-i2c" or "cypress,cyttsp-spi"
+- reg			: Device address

...or SPI chip select number

Quoted 13 lines

Documentation/devicetree/bindings/input/touchscreen/cyttsp.txt line 14

Quoted 9 lines
Documentation/devicetree/bindings/input/touchscreen/cyttsp.txt new file +9 -0
+- spi-max-frequency 	: Maximum SPI clocking speed of the device (for cyttsp-spi)
+- interrupt-parent	: the phandle for the gpio controller
+			  (see interrupt binding[0]).
+- interrupts		: (gpio) interrupt to which the chip is connected
+			  (see interrupt binding[0]).
+- reset-gpios		: the reset gpio the chip is connected to
+			  (see GPIO binding[1] for more details).
+- maxx			: horizontal resolution of touchscreen (in pixels)
+- maxy			: vertical resolution of touchscreen (in pixels)

IIRC, we have standard properties for these. Touchscreens don't really have pixels...

Indeed, there are touchscreen-size-x and touchscreen-size-y, I will rename them using the standard properties.
To be fair, though, the description for them in touchscreen.txt is identical to what I wrote ("horizontal resolution of touchscreen (in pixels)") .

Quoted 4 lines

Documentation/devicetree/bindings/input/touchscreen/cyttsp.txt line 15

Quoted 1 line
Documentation/devicetree/bindings/input/touchscreen/cyttsp.txt new file +1 -0
+- bootloader-key	: the bootloader key used to exit bootloader mode

I don't understand what this is.

This is a 8-byte key that is required to switch the chip from bootloader mode (default mode) to application mode. It's platform-specific because it's set by the customer using the chip (or by Cypress on behalf of the customer).

Quoted 8 lines

Documentation/devicetree/bindings/input/touchscreen/cyttsp.txt line 20

Quoted 5 lines
Documentation/devicetree/bindings/input/touchscreen/cyttsp.txt new file +5 -0
+
+Optional properties:
+- use_hndshk		: enable handshake bit
+- act_dist		: active distance
+- act_intrvl		: active refresh interval in ms

Is this sampling frequency?

Yes, it's basically the period between consecutive scanning/processing cycles when the chip is in active mode. The higher the value, the higher the response time but the lower the power consumption.
The value below (lp_intrvl) is the equivalent for when the chip is in low power mode.

Quoted 9 lines

Documentation/devicetree/bindings/input/touchscreen/cyttsp.txt line 22

Quoted 2 lines
Documentation/devicetree/bindings/input/touchscreen/cyttsp.txt new file +2 -0
+- tch_tmout		: active touch timeout in ms
+- lp_intrvl		: low power refresh interval in ms

Look whether other touchscreens bindings have similar properties already and copy those. These need better definitions in general.

Don't use '_' in property names and append units to the name of properties that have units (e.g. ms).

The only binding that I found to have somewhat similar properies is brcm,iproc-touchscreen.txt which calls scanning_period what I call act_intrvl and touch_timeout what I call tch_tmout.
As I said, these properties are not strictly required but can be useful to tweak the touchscreen performance.
I'll improve the descriptions and the namings as you suggested.

Quoted 14 lines
Quoted 14 lines
Documentation/devicetree/bindings/input/touchscreen/cyttsp.txt new file +14 -0
+Example:
+	&i2c1 {
+		/* ... */
+		cyttsp@a {
+			compatible = "cypress,cyttsp-i2c";
+			reg = <0xa>;
+			interrupt-parent = <&msm_gpio>;
+			interrupts = <13 0x2008>;
+			reset-gpios = <&msm_gpio 12 0x00>;
+
+			maxx = <800>;
+			maxy = <480>;
+			bootloader-key = /bits/ 8 <0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08>;
+
Quoted 9 lines

Documentation/devicetree/bindings/input/touchscreen/cyttsp.txt line 45

Quoted 5 lines
Documentation/devicetree/bindings/input/touchscreen/cyttsp.txt new file +5 -0
+			use_hndshk;
+			act_dist = /bits/ 8 <0xF8>;
+			act_intrvl = /bits/ 8 <0x00>;
+			tch_tmout = /bits/ 8 <0xFF>;
+			lp_intrvl = /bits/ 8 <0x0A>;

If the size is not 32-bits, you need to state that in the description. There is not really much point in making these 8-bit though.

These 8-bit properties are written as-is to 8-bit registers, so I thought it would be a way to enforce that the binding user cannot specify bigger values than 0xFF. Would you suggest changing them to 32-bits and handle possible bigger values as errors in the driver?

Thanks,
Oreste

Quoted 1 line

Rob

#5 lore raw

PATCH v2 3/3 Input: cyttsp - add default init function

In reply to Oreste Salerno

When using device trees, it's not possible to assign an init() function in the platform data.
In case the init function has not been assigned, attempt to perform a hard reset of the chip, using reset gpio defined in the platform data / device tree.

---
 drivers/input/touchscreen/cyttsp_core.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/input/touchscreen/cyttsp_core.c +12 -0
index 8390236..9872333 100644
@@ -238,6 +238,16 @@ static int cyttsp_set_sysinfo_regs(struct cyttsp *ts)
 	return retval;
 }
 
+static void cyttsp_hard_reset(struct cyttsp *ts)
+{
+	if (ts->pdata->reset_gpio) {
+		gpiod_set_value_cansleep(ts->pdata->reset_gpio, 1);
+		msleep(CY_DELAY_DFLT);
+		gpiod_set_value_cansleep(ts->pdata->reset_gpio, 0);
+		msleep(CY_DELAY_DFLT);
+	}
+}
+
 static int cyttsp_soft_reset(struct cyttsp *ts)
 {
 	unsigned long timeout;
@@ -659,6 +669,8 @@ struct cyttsp *cyttsp_probe(const struct cyttsp_bus_ops *bus_ops,
 				error);
 			goto err_free_mem;
 		}
+	} else {
+		cyttsp_hard_reset(ts);
 	}
 
 	input_dev->name = pdata->name;
Signature · 1 line
1.9.1