Skip to contentSkip to conversation

Input: tsc2007: Add device tree support.

PATCH Superseded Denis Carikli 4 participants 7 messages Oct 23, 2013 – Oct 24, 2013

Subsystems (5)

v5 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

PATCH v5 1/4 Input: tsc2007: Add device tree support.

Cc Rob Herring <[email protected]>
Cc Pawel Moll <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Stephen Warren <[email protected]>
Cc Ian Campbell <[email protected]>
Cc devicetree at vger.kernel.org
Cc Dmitry Torokhov <[email protected]>
Cc linux-input at vger.kernel.org
Cc Sascha Hauer <[email protected]>
Cc linux-arm-kernel at lists.infradead.org
Cc Lothar Wa?mann <[email protected]>
Cc Eric B?nard <[email protected]>

---
ChangeLog v4->v5:
- Most of the "if (ts->of)" were replaced by wrapping them in the tsc2007_is_pen_down_valid and tsc2007_is_pen_down functions.
- Some whitespace cleanups.
- The devm_kzalloc call was fixed to make it compile.

---
 .../bindings/input/touchscreen/tsc2007.txt         |   44 +++++
 drivers/input/touchscreen/tsc2007.c                |  194 +++++++++++++++-----
 2 files changed, 197 insertions(+), 41 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/input/touchscreen/tsc2007.txt
Documentation/devicetree/bindings/input/touchscreen/tsc2007.txt new file +44 -0
new file mode 100644
index 0000000..fadd3f6
@@ -0,0 +1,44 @@
+* Texas Instruments tsc2007 touchscreen controller
+
+Required properties:
+- compatible: must be "ti,tsc2007".
+- reg: I2C address of the chip.
+- pinctrl-0: Should specify pin control groups used for this controller
+  (see pinctrl bindings[0]).
+- pinctrl-names: Should contain only one value - "default"
+  (see pinctrl bindings[0]).
+- interrupt-parent: the phandle for the interrupt controller
+  (see interrupt binding[1]).
+- interrupts: interrupt to which the chip is connected
+  (see interrupt binding[1]).
+- ti,x-plate-ohms: X-plate resistance in ohms.
+
+Optional properties:
+- gpios: the interrupt gpio the chip is connected to (trough the penirq pin)
+  (see GPIO binding[2] for more details).
+- max-rt: maximum pressure.
+- fuzzy: specifies the fuzz value that is used to filter noise from the event
+  stream.
+- poll-period: how much time to wait(in millisecond) before reading again the
+  values from the tsc2007.
+
+[0]: Documentation/devicetree/bindings/pinctrl/pinctrl-bindings.txt
+[1]: Documentation/devicetree/bindings/interrupt-controller/interrupts.txt
+[2]: Documentation/devicetree/bindings/gpio/gpio.txt
+
+Example:
+	&i2c1 {
+		/* ... */
+		tsc2007 at 49 {
+			compatible = "ti,tsc2007";
+			reg = <0x49>;
+			pinctrl-names = "default";
+			pinctrl-0 = <&pinctrl_tsc2007_1>;
+			interrupt-parent = <&gpio4>;
+			interrupts = <0x0 0x8>;
+			gpios = <&gpio4 0 0>;
+			ti,x-plate-ohms = <180>;
+		};
+
+		/* ... */
+	};
drivers/input/touchscreen/tsc2007.c +153 -41

301 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#1 lore raw

PATCH v5 2/4 ARM: dts: cpuimx51 Add touchscreen support.

Cc Rob Herring <[email protected]>
Cc Pawel Moll <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Stephen Warren <[email protected]>
Cc Ian Campbell <[email protected]>
Cc devicetree at vger.kernel.org
Cc Dmitry Torokhov <[email protected]>
Cc linux-input at vger.kernel.org
Cc Sascha Hauer <[email protected]>
Cc linux-arm-kernel at lists.infradead.org
Cc Lothar Wa?mann <[email protected]>
Cc Eric B?nard <[email protected]>
---
 arch/arm/boot/dts/imx51-eukrea-cpuimx51.dtsi |   11 +++++++++++
 1 file changed, 11 insertions(+)
arch/arm/boot/dts/imx51-eukrea-cpuimx51.dtsi +11 -0
index 8638656..34ca8d3a 100644
@@ -42,6 +42,17 @@
 		compatible = "nxp,pcf8563";
 		reg = <0x51>;
 	};
+
+	tsc2007: tsc2007 at 49 {
+		compatible = "ti,tsc2007";
+		reg = <0x49>;
+		pinctrl-names = "default";
+		pinctrl-0 = <&pinctrl_tsc2007_1>;
+		interrupt-parent = <&gpio4>;
+		interrupts = <0x0 0x8>;
+		gpios = <&gpio4 0 0>;
+		ti,x-plate-ohms = <180>;
+	};
 };
 
 &iomuxc {
Signature · 1 line
1.7.9.5
#2 lore raw

PATCH v5 3/4 ARM: dts: cpuimx35 Add touchscreen support.

In reply to Denis Carikli
Cc Rob Herring <[email protected]>
Cc Pawel Moll <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Stephen Warren <[email protected]>
Cc Ian Campbell <[email protected]>
Cc devicetree at vger.kernel.org
Cc Dmitry Torokhov <[email protected]>
Cc linux-input at vger.kernel.org
Cc Sascha Hauer <[email protected]>
Cc linux-arm-kernel at lists.infradead.org
Cc Lothar Wa?mann <[email protected]>
Cc Eric B?nard <[email protected]>
---
 arch/arm/boot/dts/imx35-eukrea-cpuimx35.dtsi |   11 +++++++++++
 1 file changed, 11 insertions(+)
arch/arm/boot/dts/imx35-eukrea-cpuimx35.dtsi +11 -0
index 2c2d4cd..a22230b 100644
@@ -41,6 +41,17 @@
 		compatible = "nxp,pcf8563";
 		reg = <0x51>;
 	};
+
+	tsc2007: tsc2007 at 48 {
+		compatible = "ti,tsc2007";
+		reg = <0x48>;
+		pinctrl-names = "default";
+		pinctrl-0 = <&pinctrl_tsc2007_1>;
+		interrupt-parent = <&gpio3>;
+		interrupts = <0x2 0x8>;
+		gpios = <&gpio3 2 0>;
+		ti,x-plate-ohms = <180>;
+	};
 };
 
 &iomuxc {
Signature · 1 line
1.7.9.5
#3 lore raw

PATCH v5 4/4 ARM: imx_v6_v7_defconfig: Enable tsc2007 support.

In reply to Denis Carikli

The eukrea cpuimx35 and cpuimx51 have a tsc2007 touchscreen controller,
so we turn it on.

Cc Rob Herring <[email protected]>
Cc Pawel Moll <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Stephen Warren <[email protected]>
Cc Ian Campbell <[email protected]>
Cc devicetree at vger.kernel.org
Cc Dmitry Torokhov <[email protected]>
Cc linux-input at vger.kernel.org
Cc Sascha Hauer <[email protected]>
Cc linux-arm-kernel at lists.infradead.org
Cc Lothar Wa?mann <[email protected]>
Cc Fabio Estevam <[email protected]>
Cc Shawn Guo <[email protected]>
Cc Eric B?nard <[email protected]>
---
 arch/arm/configs/imx_v6_v7_defconfig |    1 +
 1 file changed, 1 insertion(+)
arch/arm/configs/imx_v6_v7_defconfig +1 -0
index d8a52a0..23ba17d 100644
@@ -130,6 +130,7 @@ CONFIG_MOUSE_PS2_ELANTECH=y
 CONFIG_INPUT_TOUCHSCREEN=y
 CONFIG_TOUCHSCREEN_EGALAX=y
 CONFIG_TOUCHSCREEN_MC13783=y
+CONFIG_TOUCHSCREEN_TSC2007=y
 CONFIG_INPUT_MISC=y
 CONFIG_INPUT_MMA8450=y
 CONFIG_SERIO_SERPORT=m
Signature · 1 line
1.7.9.5
#4 lore raw

PATCH v5 1/4 Input: tsc2007: Add device tree support.

In reply to Denis Carikli
Quoted 31 lines · Denis Carikli
Cc Rob Herring <[email protected]>
Cc Pawel Moll <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Stephen Warren <[email protected]>
Cc Ian Campbell <[email protected]>
Cc devicetree at vger.kernel.org
Cc Dmitry Torokhov <[email protected]>
Cc linux-input at vger.kernel.org
Cc Sascha Hauer <[email protected]>
Cc linux-arm-kernel at lists.infradead.org
Cc Lothar Wa?mann <[email protected]>
Cc Eric B?nard <[email protected]>

---
ChangeLog v4->v5:
- Most of the "if (ts->of)" were replaced by wrapping them in the tsc2007_is_pen_down_valid and tsc2007_is_pen_down functions.
- Some whitespace cleanups.
- The devm_kzalloc call was fixed to make it compile.

---
 .../bindings/input/touchscreen/tsc2007.txt         |   44 +++++
 drivers/input/touchscreen/tsc2007.c                |  194 +++++++++++++++-----
 2 files changed, 197 insertions(+), 41 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/input/touchscreen/tsc2007.txt
Documentation/devicetree/bindings/input/touchscreen/tsc2007.txt new file +0 -0
new file mode 100644
index 0000000..fadd3f6

Documentation/devicetree/bindings/input/touchscreen/tsc2007.txt line 9

Quoted 9 lines
Documentation/devicetree/bindings/input/touchscreen/tsc2007.txt new file +9 -0
@@ -0,0 +1,44 @@
+* Texas Instruments tsc2007 touchscreen controller
+
+Required properties:
+- compatible: must be "ti,tsc2007".
+- reg: I2C address of the chip.
+- pinctrl-0: Should specify pin control groups used for this controller
+  (see pinctrl bindings[0]).
+- pinctrl-names: Should contain only one value - "default"
+  (see pinctrl bindings[0]).

I'm confused why an i2c slave needs pinctl binding?

Quoted 136 lines
Documentation/devicetree/bindings/input/touchscreen/tsc2007.txt new file +35 -0
+- interrupt-parent: the phandle for the interrupt controller
+  (see interrupt binding[1]).
+- interrupts: interrupt to which the chip is connected
+  (see interrupt binding[1]).
+- ti,x-plate-ohms: X-plate resistance in ohms.
+
+Optional properties:
+- gpios: the interrupt gpio the chip is connected to (trough the penirq pin)
+  (see GPIO binding[2] for more details).
+- max-rt: maximum pressure.
+- fuzzy: specifies the fuzz value that is used to filter noise from the event
+  stream.
+- poll-period: how much time to wait(in millisecond) before reading again the
+  values from the tsc2007.
+
+[0]: Documentation/devicetree/bindings/pinctrl/pinctrl-bindings.txt
+[1]: Documentation/devicetree/bindings/interrupt-controller/interrupts.txt
+[2]: Documentation/devicetree/bindings/gpio/gpio.txt
+
+Example:
+	&i2c1 {
+		/* ... */
+		tsc2007 at 49 {
+			compatible = "ti,tsc2007";
+			reg = <0x49>;
+			pinctrl-names = "default";
+			pinctrl-0 = <&pinctrl_tsc2007_1>;
+			interrupt-parent = <&gpio4>;
+			interrupts = <0x0 0x8>;
+			gpios = <&gpio4 0 0>;
+			ti,x-plate-ohms = <180>;
+		};
+
+		/* ... */
+	};
drivers/input/touchscreen/tsc2007.c +29 -11
index 0b67ba4..0625fe1 100644
@@ -26,6 +26,9 @@
 #include <linux/interrupt.h>
 #include <linux/i2c.h>
 #include <linux/i2c/tsc2007.h>
+#include <linux/of_device.h>
+#include <linux/of.h>
+#include <linux/of_gpio.h>
 
 #define TSC2007_MEASURE_TEMP0		(0x0 << 4)
 #define TSC2007_MEASURE_AUX		(0x2 << 4)
@@ -74,7 +77,10 @@ struct tsc2007 {
 	u16			max_rt;
 	unsigned long		poll_delay;
 	unsigned long		poll_period;
+	int			fuzzy;
+	char			of;
 
+	unsigned		gpio;
 	int			irq;
 
 	wait_queue_head_t	wait;
@@ -84,6 +90,11 @@ struct tsc2007 {
 	void			(*clear_penirq)(void);
 };
 
+static int tsc2007_get_pendown_state_dt(struct tsc2007 *ts)
+{
+	return !gpio_get_value(ts->gpio);
+}
+
 static inline int tsc2007_xfer(struct tsc2007 *tsc, u8 cmd)
 {
 	s32 data;
@@ -142,6 +153,14 @@ static u32 tsc2007_calculate_pressure(struct tsc2007 *tsc, struct ts_event *tc)
 	return rt;
 }
 
+static bool tsc2007_is_pen_down_valid(struct tsc2007 *ts)
+{
+	if (ts->of)
+		return gpio_is_valid(ts->gpio);
+	else
+		return ts->get_pendown_state ? true : false;
+}
+
 static bool tsc2007_is_pen_down(struct tsc2007 *ts)
 {
 	/*
@@ -158,10 +177,13 @@ static bool tsc2007_is_pen_down(struct tsc2007 *ts)
 	 * to fall back on the pressure reading.
 	 */
 
-	if (!ts->get_pendown_state)
+	if (!tsc2007_is_pen_down_valid(ts))
 		return true;
 
-	return ts->get_pendown_state();
+	if (ts->of)
+		return tsc2007_get_pendown_state_dt(ts);
+	else
+		return ts->get_pendown_state();
 }
 
 static irqreturn_t tsc2007_soft_irq(int irq, void *handle)
@@ -178,7 +200,7 @@ static irqreturn_t tsc2007_soft_irq(int irq, void *handle)
 
 		rt = tsc2007_calculate_pressure(ts, &tc);
 
-		if (rt == 0 && !ts->get_pendown_state) {
+		if(!rt && !tsc2007_is_pen_down_valid(ts)) {
 			/*
 			 * If pressure reported is 0 and we don't have
 			 * callback to check pendown state, we have to
@@ -228,7 +250,7 @@ static irqreturn_t tsc2007_hard_irq(int irq, void *handle)
 {
 	struct tsc2007 *ts = handle;
 
-	if (!ts->get_pendown_state || likely(ts->get_pendown_state()))
+	if (tsc2007_is_pen_down(ts))
 		return IRQ_WAKE_THREAD;
 
 	if (ts->clear_penirq)
@@ -273,34 +295,65 @@ static void tsc2007_close(struct input_dev *input_dev)
 	tsc2007_stop(ts);
 }
 
-static int tsc2007_probe(struct i2c_client *client,
-				   const struct i2c_device_id *id)
+#ifdef CONFIG_OF
+static int tsc2007_probe_dt(struct i2c_client *client, struct tsc2007 *ts,
+			    struct device_node *np)
 {
-	struct tsc2007 *ts;
-	struct tsc2007_platform_data *pdata = client->dev.platform_data;
-	struct input_dev *input_dev;
-	int err;
-

drivers/input/touchscreen/tsc2007.c static void tsc2007_close(struct input_dev *input_dev) · line 309

Quoted 10 lines
drivers/input/touchscreen/tsc2007.c +8 -2
-	if (!pdata) {
-		dev_err(&client->dev, "platform data is required!\n");
+	int err = 0;
+	u32 val32;
+	u64 val64;
+
+	if (!of_property_read_u32(np, "max-rt", &val32))
+		ts->max_rt = val32;
+	else
+		ts->max_rt = MAX_12BIT;

These functions don't overwrite the value if the property isn't present. So you can set the values to the defaults and just pass the variable (i.e. ts->max_rt) to of_property_read_u32 directly.

Rob

#5 lore raw

PATCH v5 1/4 Input: tsc2007: Add device tree support.

Hi,

Quoted 1 line · Rob Herring

On 10/23/2013 07:10 AM, Denis Carikli wrote:

[...]

Quoted 1 line
Quoted 1 line

diff --git

a/Documentation/devicetree/bindings/input/touchscreen/tsc2007.txt b/Documentation/devicetree/bindings/input/touchscreen/tsc2007.txt

Quoted 8 lines
Quoted 8 lines

new file mode 100644
index 0000000..fadd3f6

Documentation/devicetree/bindings/input/touchscreen/tsc2007.txt new file +3 -0
@@ -0,0 +1,44 @@
+* Texas Instruments tsc2007 touchscreen controller
+
+Required properties:
Quoted 9 lines

Documentation/devicetree/bindings/input/touchscreen/tsc2007.txt line 9

Quoted 6 lines
Documentation/devicetree/bindings/input/touchscreen/tsc2007.txt new file +6 -0
+- compatible: must be "ti,tsc2007".
+- reg: I2C address of the chip.
+- pinctrl-0: Should specify pin control groups used for this controller
+  (see pinctrl bindings[0]).
+- pinctrl-names: Should contain only one value - "default"
+  (see pinctrl bindings[0]).

I'm confused why an i2c slave needs pinctl binding?

for the pendetect GPIO.

[...]

Quoted 25 lines
Quoted 25 lines
drivers/input/touchscreen/tsc2007.c +6 -0
index 0b67ba4..0625fe1 100644
@@ -26,6 +26,9 @@
 #include <linux/interrupt.h>
 #include <linux/i2c.h>
 #include <linux/i2c/tsc2007.h>
+#include <linux/of_device.h>
+#include <linux/of.h>
+#include <linux/of_gpio.h>
 
 #define TSC2007_MEASURE_TEMP0		(0x0 << 4)
 #define TSC2007_MEASURE_AUX		(0x2 << 4)
@@ -74,7 +77,10 @@ struct tsc2007 {
 	u16			max_rt;
 	unsigned long		poll_delay;
 	unsigned long		poll_period;
+	int			fuzzy;
+	char			of;
 
+	unsigned		gpio;
 	int			irq;
 
 	wait_queue_head_t	wait;

[...]

Quoted 21 lines
Quoted 21 lines
drivers/input/touchscreen/tsc2007.c +7 -9
@@ -273,34 +295,65 @@ static void tsc2007_close(struct input_dev *input_dev)
 	tsc2007_stop(ts);
 }
 
-static int tsc2007_probe(struct i2c_client *client,
-				   const struct i2c_device_id *id)
+#ifdef CONFIG_OF
+static int tsc2007_probe_dt(struct i2c_client *client, struct tsc2007 *ts,
+			    struct device_node *np)
 {
-	struct tsc2007 *ts;
-	struct tsc2007_platform_data *pdata = client->dev.platform_data;
-	struct input_dev *input_dev;
-	int err;
-
-	if (!pdata) {
-		dev_err(&client->dev, "platform data is required!\n");
+	int err = 0;
+	u32 val32;
+	u64 val64;
+
Quoted 9 lines

drivers/input/touchscreen/tsc2007.c static void tsc2007_close(struct input_dev *input_dev) · line 309

Quoted 4 lines
drivers/input/touchscreen/tsc2007.c +4 -0
+	if (!of_property_read_u32(np, "max-rt", &val32))
+		ts->max_rt = val32;
+	else
+		ts->max_rt = MAX_12BIT;

These functions don't overwrite the value if the property isn't present. So you can set the values to the defaults and just pass the variable (i.e. ts->max_rt) to of_property_read_u32 directly.

Not quite. Since max_rt is an u16 you can't pass it to of_property_read_u32(). And using of_property_read_u16() requires the abominable DT notation: "/bits/ 16 <value>;"

Lothar Wa?mann

Signature · 9 lines
___________________________________________________________

Ka-Ro electronics GmbH | Pascalstra?e 22 | D - 52076 Aachen
Phone: +49 2408 1402-0 | Fax: +49 2408 1402-10
Gesch?ftsf?hrer: Matthias Kaussen
Handelsregistereintrag: Amtsgericht Aachen, HRB 4996

www.karo-electronics.de | info at karo-electronics.de
___________________________________________________________
#6 lore raw

PATCH v5 1/4 Input: tsc2007: Add device tree support.

Quoted 25 lines · Lothar Wa?mann

Hi,

Quoted 1 line · Rob Herring

On 10/23/2013 07:10 AM, Denis Carikli wrote:

[...]

Quoted 1 line
Quoted 1 line

diff --git

a/Documentation/devicetree/bindings/input/touchscreen/tsc2007.txt b/Documentation/devicetree/bindings/input/touchscreen/tsc2007.txt

Quoted 8 lines
Quoted 8 lines

new file mode 100644
index 0000000..fadd3f6

Documentation/devicetree/bindings/input/touchscreen/tsc2007.txt new file +3 -0
@@ -0,0 +1,44 @@
+* Texas Instruments tsc2007 touchscreen controller
+
+Required properties:
Quoted 9 lines

Documentation/devicetree/bindings/input/touchscreen/tsc2007.txt line 9

Quoted 6 lines
Documentation/devicetree/bindings/input/touchscreen/tsc2007.txt new file +6 -0
+- compatible: must be "ti,tsc2007".
+- reg: I2C address of the chip.
+- pinctrl-0: Should specify pin control groups used for this controller
+  (see pinctrl bindings[0]).
+- pinctrl-names: Should contain only one value - "default"
+  (see pinctrl bindings[0]).

I'm confused why an i2c slave needs pinctl binding?

Quoted 1 line

for the pendetect GPIO.

Shouldn't that be done transparently to users of the GPIO API? I was under the impression that gpio_request() would set everything up (or return an error if unable to do so) so that the GPIO can be used, including any required pinmuxing.

Quoted 57 lines

[...]

Quoted 25 lines
Quoted 25 lines
drivers/input/touchscreen/tsc2007.c +6 -0
index 0b67ba4..0625fe1 100644
@@ -26,6 +26,9 @@
 #include <linux/interrupt.h>
 #include <linux/i2c.h>
 #include <linux/i2c/tsc2007.h>
+#include <linux/of_device.h>
+#include <linux/of.h>
+#include <linux/of_gpio.h>
 
 #define TSC2007_MEASURE_TEMP0		(0x0 << 4)
 #define TSC2007_MEASURE_AUX		(0x2 << 4)
@@ -74,7 +77,10 @@ struct tsc2007 {
 	u16			max_rt;
 	unsigned long		poll_delay;
 	unsigned long		poll_period;
+	int			fuzzy;
+	char			of;
 
+	unsigned		gpio;
 	int			irq;
 
 	wait_queue_head_t	wait;

[...]

Quoted 21 lines
Quoted 21 lines
drivers/input/touchscreen/tsc2007.c +7 -9
@@ -273,34 +295,65 @@ static void tsc2007_close(struct input_dev *input_dev)
 	tsc2007_stop(ts);
 }
 
-static int tsc2007_probe(struct i2c_client *client,
-				   const struct i2c_device_id *id)
+#ifdef CONFIG_OF
+static int tsc2007_probe_dt(struct i2c_client *client, struct tsc2007 *ts,
+			    struct device_node *np)
 {
-	struct tsc2007 *ts;
-	struct tsc2007_platform_data *pdata = client->dev.platform_data;
-	struct input_dev *input_dev;
-	int err;
-
-	if (!pdata) {
-		dev_err(&client->dev, "platform data is required!\n");
+	int err = 0;
+	u32 val32;
+	u64 val64;
+
Quoted 9 lines

drivers/input/touchscreen/tsc2007.c static void tsc2007_close(struct input_dev *input_dev) · line 309

Quoted 4 lines
drivers/input/touchscreen/tsc2007.c +4 -0
+	if (!of_property_read_u32(np, "max-rt", &val32))
+		ts->max_rt = val32;
+	else
+		ts->max_rt = MAX_12BIT;

These functions don't overwrite the value if the property isn't present. So you can set the values to the defaults and just pass the variable (i.e. ts->max_rt) to of_property_read_u32 directly.

Quoted 3 lines

Not quite. Since max_rt is an u16 you can't pass it to of_property_read_u32(). And using of_property_read_u16() requires the abominable DT notation: "/bits/ 16 <value>;"

In that case perhaps you need to check that whatever u32 value you read from DT is actually in the expected range before assigning to u16?

Thierry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20131024/b4fd58a4/attachment-0001.sig>