All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/3] Add device tree support to the cyttsp driver
@ 2016-01-05 12:59 ` Oreste Salerno
  0 siblings, 0 replies; 11+ messages in thread
From: Oreste Salerno @ 2016-01-05 12:59 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-input, fery, dmitry.torokhov, robh+dt, pawel.moll,
	mark.rutland, ijc+devicetree, galak, devicetree, oreste.salerno

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

-- 
1.9.1


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH v2 0/3] Add device tree support to the cyttsp driver
@ 2016-01-05 12:59 ` Oreste Salerno
  0 siblings, 0 replies; 11+ messages in thread
From: Oreste Salerno @ 2016-01-05 12:59 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-input, fery, dmitry.torokhov, robh+dt, pawel.moll,
	mark.rutland, ijc+devicetree, galak, devicetree, oreste.salerno

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

-- 
1.9.1


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH v2 1/3] Input: cyttsp - remove unused irq_gpio from platform_data
  2016-01-05 12:59 ` Oreste Salerno
@ 2016-01-05 12:59   ` Oreste Salerno
  -1 siblings, 0 replies; 11+ messages in thread
From: Oreste Salerno @ 2016-01-05 12:59 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-input, fery, dmitry.torokhov, robh+dt, pawel.moll,
	mark.rutland, ijc+devicetree, galak, devicetree, oreste.salerno

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

Signed-off-by: Oreste Salerno <oreste.salerno@tomtom.com>
---
 include/linux/input/cyttsp.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/include/linux/input/cyttsp.h b/include/linux/input/cyttsp.h
index 5af7c66..d7c2520 100644
--- a/include/linux/input/cyttsp.h
+++ b/include/linux/input/cyttsp.h
@@ -51,7 +51,6 @@ struct cyttsp_platform_data {
 	int (*init)(void);
 	void (*exit)(void);
 	char *name;
-	s16 irq_gpio;
 	u8 *bl_keys;
 };
 
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v2 1/3] Input: cyttsp - remove unused irq_gpio from platform_data
@ 2016-01-05 12:59   ` Oreste Salerno
  0 siblings, 0 replies; 11+ messages in thread
From: Oreste Salerno @ 2016-01-05 12:59 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-input, fery, dmitry.torokhov, robh+dt, pawel.moll,
	mark.rutland, ijc+devicetree, galak, devicetree, oreste.salerno

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

Signed-off-by: Oreste Salerno <oreste.salerno@tomtom.com>
---
 include/linux/input/cyttsp.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/include/linux/input/cyttsp.h b/include/linux/input/cyttsp.h
index 5af7c66..d7c2520 100644
--- a/include/linux/input/cyttsp.h
+++ b/include/linux/input/cyttsp.h
@@ -51,7 +51,6 @@ struct cyttsp_platform_data {
 	int (*init)(void);
 	void (*exit)(void);
 	char *name;
-	s16 irq_gpio;
 	u8 *bl_keys;
 };
 
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v2 2/3] Input: cyttsp - add device tree support
  2016-01-05 12:59 ` Oreste Salerno
@ 2016-01-05 12:59   ` Oreste Salerno
  -1 siblings, 0 replies; 11+ messages in thread
From: Oreste Salerno @ 2016-01-05 12:59 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-input, fery, dmitry.torokhov, robh+dt, pawel.moll,
	mark.rutland, ijc+devicetree, galak, devicetree, oreste.salerno

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

Signed-off-by: Oreste Salerno <oreste.salerno@tomtom.com>
---
 .../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

diff --git a/Documentation/devicetree/bindings/input/touchscreen/cyttsp.txt b/Documentation/devicetree/bindings/input/touchscreen/cyttsp.txt
new file mode 100644
index 0000000..8e0bcc73
--- /dev/null
+++ b/Documentation/devicetree/bindings/input/touchscreen/cyttsp.txt
@@ -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>;
+		};
+
+		/* ... */
+	};
diff --git a/drivers/input/touchscreen/cyttsp_core.c b/drivers/input/touchscreen/cyttsp_core.c
index 5b74e8b..8390236 100644
--- a/drivers/input/touchscreen/cyttsp_core.c
+++ b/drivers/input/touchscreen/cyttsp_core.c
@@ -33,6 +33,8 @@
 #include <linux/gpio.h>
 #include <linux/interrupt.h>
 #include <linux/slab.h>
+#include <linux/of.h>
+#include <linux/gpio/consumer.h>
 
 #include "cyttsp_core.h"
 
@@ -528,18 +530,111 @@ static void cyttsp_close(struct input_dev *dev)
 		cyttsp_disable(ts);
 }
 
+#ifdef CONFIG_OF
+static const struct cyttsp_platform_data *cyttsp_parse_dt(struct device *dev)
+{
+	struct device_node *np = dev->of_node;
+	struct cyttsp_platform_data *pdata;
+	u8 dt_value;
+	int ret;
+	static const char err_msg[] =
+		"property not provided in the device tree";
+
+	if (!np)
+		return ERR_PTR(-ENOENT);
+
+	pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
+	if (!pdata)
+		return ERR_PTR(-ENOMEM);
+
+	pdata->bl_keys = devm_kzalloc(dev, CY_NUM_BL_KEYS, GFP_KERNEL);
+	if (!pdata->bl_keys)
+		return ERR_PTR(-ENOMEM);
+
+	/* Set some default values */
+	pdata->act_dist = CY_ACT_DIST_DFLT;
+	pdata->act_intrvl = CY_ACT_INTRVL_DFLT;
+	pdata->tch_tmout = CY_TCH_TMOUT_DFLT;
+	pdata->lp_intrvl = CY_LP_INTRVL_DFLT;
+	pdata->name = "cyttsp";
+
+	ret = of_property_read_u32(np, "maxx", &pdata->maxx);
+	if (ret) {
+		dev_err(dev, "maxx %s\n", err_msg);
+		return ERR_PTR(ret);
+	}
+
+	ret = of_property_read_u32(np, "maxy", &pdata->maxy);
+	if (ret) {
+		dev_err(dev, "maxy %s\n", err_msg);
+		return ERR_PTR(ret);
+	}
+
+	pdata->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW);
+	if (IS_ERR(pdata->reset_gpio)) {
+		ret = PTR_ERR(pdata->reset_gpio);
+		dev_err(dev, "error acquiring reset gpio: %d\n", ret);
+		return ERR_PTR(ret);
+	}
+
+	ret = of_property_read_u8_array(np, "bootloader-key",
+			pdata->bl_keys, CY_NUM_BL_KEYS);
+	if (ret) {
+		dev_err(dev, "bootloader-key %s\n", err_msg);
+		return ERR_PTR(ret);
+	}
+
+	pdata->use_hndshk = of_property_read_bool(np, "use_hndshk");
+
+	if (!of_property_read_u8(np, "act_dist", &dt_value))
+		pdata->act_dist = dt_value;
+
+	if (!of_property_read_u8(np, "act_intrvl", &dt_value))
+		pdata->act_intrvl = dt_value;
+
+	if (!of_property_read_u8(np, "tch_tmout", &dt_value))
+		pdata->tch_tmout = dt_value;
+
+	if (!of_property_read_u8(np, "lp_intrvl", &dt_value))
+		pdata->lp_intrvl = dt_value;
+
+	return pdata;
+}
+#else
+static const struct cyttsp_platform_data *cyttsp_parse_dt(struct device *dev)
+{
+	return ERR_PTR(-ENOENT);
+}
+#endif
+
+static const struct cyttsp_platform_data *
+cyttsp_get_platform_data(struct device *dev)
+{
+	const struct cyttsp_platform_data *pdata;
+
+	pdata = dev_get_platdata(dev);
+	if (pdata)
+		return pdata;
+
+	pdata = cyttsp_parse_dt(dev);
+	if (!IS_ERR(pdata) || PTR_ERR(pdata) != -ENOENT)
+		return pdata;
+
+	dev_err(dev, "No platform data specified\n");
+	return ERR_PTR(-EINVAL);
+}
+
 struct cyttsp *cyttsp_probe(const struct cyttsp_bus_ops *bus_ops,
 			    struct device *dev, int irq, size_t xfer_buf_size)
 {
-	const struct cyttsp_platform_data *pdata = dev_get_platdata(dev);
+	const struct cyttsp_platform_data *pdata;
 	struct cyttsp *ts;
 	struct input_dev *input_dev;
 	int error;
 
-	if (!pdata || !pdata->name || irq <= 0) {
-		error = -EINVAL;
-		goto err_out;
-	}
+	pdata = cyttsp_get_platform_data(dev);
+	if (IS_ERR(pdata))
+		return ERR_CAST(pdata);
 
 	ts = kzalloc(sizeof(*ts) + xfer_buf_size, GFP_KERNEL);
 	input_dev = input_allocate_device();
@@ -550,7 +645,7 @@ struct cyttsp *cyttsp_probe(const struct cyttsp_bus_ops *bus_ops,
 
 	ts->dev = dev;
 	ts->input = input_dev;
-	ts->pdata = dev_get_platdata(dev);
+	ts->pdata = pdata;
 	ts->bus_ops = bus_ops;
 	ts->irq = irq;
 
@@ -618,7 +713,6 @@ err_platform_exit:
 err_free_mem:
 	input_free_device(input_dev);
 	kfree(ts);
-err_out:
 	return ERR_PTR(error);
 }
 EXPORT_SYMBOL_GPL(cyttsp_probe);
diff --git a/include/linux/input/cyttsp.h b/include/linux/input/cyttsp.h
index d7c2520..92a9d52 100644
--- a/include/linux/input/cyttsp.h
+++ b/include/linux/input/cyttsp.h
@@ -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;
 };
 
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v2 2/3] Input: cyttsp - add device tree support
@ 2016-01-05 12:59   ` Oreste Salerno
  0 siblings, 0 replies; 11+ messages in thread
From: Oreste Salerno @ 2016-01-05 12:59 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-input, fery, dmitry.torokhov, robh+dt, pawel.moll,
	mark.rutland, ijc+devicetree, galak, devicetree, oreste.salerno

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

Signed-off-by: Oreste Salerno <oreste.salerno@tomtom.com>
---
 .../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

diff --git a/Documentation/devicetree/bindings/input/touchscreen/cyttsp.txt b/Documentation/devicetree/bindings/input/touchscreen/cyttsp.txt
new file mode 100644
index 0000000..8e0bcc73
--- /dev/null
+++ b/Documentation/devicetree/bindings/input/touchscreen/cyttsp.txt
@@ -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>;
+		};
+
+		/* ... */
+	};
diff --git a/drivers/input/touchscreen/cyttsp_core.c b/drivers/input/touchscreen/cyttsp_core.c
index 5b74e8b..8390236 100644
--- a/drivers/input/touchscreen/cyttsp_core.c
+++ b/drivers/input/touchscreen/cyttsp_core.c
@@ -33,6 +33,8 @@
 #include <linux/gpio.h>
 #include <linux/interrupt.h>
 #include <linux/slab.h>
+#include <linux/of.h>
+#include <linux/gpio/consumer.h>
 
 #include "cyttsp_core.h"
 
@@ -528,18 +530,111 @@ static void cyttsp_close(struct input_dev *dev)
 		cyttsp_disable(ts);
 }
 
+#ifdef CONFIG_OF
+static const struct cyttsp_platform_data *cyttsp_parse_dt(struct device *dev)
+{
+	struct device_node *np = dev->of_node;
+	struct cyttsp_platform_data *pdata;
+	u8 dt_value;
+	int ret;
+	static const char err_msg[] =
+		"property not provided in the device tree";
+
+	if (!np)
+		return ERR_PTR(-ENOENT);
+
+	pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
+	if (!pdata)
+		return ERR_PTR(-ENOMEM);
+
+	pdata->bl_keys = devm_kzalloc(dev, CY_NUM_BL_KEYS, GFP_KERNEL);
+	if (!pdata->bl_keys)
+		return ERR_PTR(-ENOMEM);
+
+	/* Set some default values */
+	pdata->act_dist = CY_ACT_DIST_DFLT;
+	pdata->act_intrvl = CY_ACT_INTRVL_DFLT;
+	pdata->tch_tmout = CY_TCH_TMOUT_DFLT;
+	pdata->lp_intrvl = CY_LP_INTRVL_DFLT;
+	pdata->name = "cyttsp";
+
+	ret = of_property_read_u32(np, "maxx", &pdata->maxx);
+	if (ret) {
+		dev_err(dev, "maxx %s\n", err_msg);
+		return ERR_PTR(ret);
+	}
+
+	ret = of_property_read_u32(np, "maxy", &pdata->maxy);
+	if (ret) {
+		dev_err(dev, "maxy %s\n", err_msg);
+		return ERR_PTR(ret);
+	}
+
+	pdata->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW);
+	if (IS_ERR(pdata->reset_gpio)) {
+		ret = PTR_ERR(pdata->reset_gpio);
+		dev_err(dev, "error acquiring reset gpio: %d\n", ret);
+		return ERR_PTR(ret);
+	}
+
+	ret = of_property_read_u8_array(np, "bootloader-key",
+			pdata->bl_keys, CY_NUM_BL_KEYS);
+	if (ret) {
+		dev_err(dev, "bootloader-key %s\n", err_msg);
+		return ERR_PTR(ret);
+	}
+
+	pdata->use_hndshk = of_property_read_bool(np, "use_hndshk");
+
+	if (!of_property_read_u8(np, "act_dist", &dt_value))
+		pdata->act_dist = dt_value;
+
+	if (!of_property_read_u8(np, "act_intrvl", &dt_value))
+		pdata->act_intrvl = dt_value;
+
+	if (!of_property_read_u8(np, "tch_tmout", &dt_value))
+		pdata->tch_tmout = dt_value;
+
+	if (!of_property_read_u8(np, "lp_intrvl", &dt_value))
+		pdata->lp_intrvl = dt_value;
+
+	return pdata;
+}
+#else
+static const struct cyttsp_platform_data *cyttsp_parse_dt(struct device *dev)
+{
+	return ERR_PTR(-ENOENT);
+}
+#endif
+
+static const struct cyttsp_platform_data *
+cyttsp_get_platform_data(struct device *dev)
+{
+	const struct cyttsp_platform_data *pdata;
+
+	pdata = dev_get_platdata(dev);
+	if (pdata)
+		return pdata;
+
+	pdata = cyttsp_parse_dt(dev);
+	if (!IS_ERR(pdata) || PTR_ERR(pdata) != -ENOENT)
+		return pdata;
+
+	dev_err(dev, "No platform data specified\n");
+	return ERR_PTR(-EINVAL);
+}
+
 struct cyttsp *cyttsp_probe(const struct cyttsp_bus_ops *bus_ops,
 			    struct device *dev, int irq, size_t xfer_buf_size)
 {
-	const struct cyttsp_platform_data *pdata = dev_get_platdata(dev);
+	const struct cyttsp_platform_data *pdata;
 	struct cyttsp *ts;
 	struct input_dev *input_dev;
 	int error;
 
-	if (!pdata || !pdata->name || irq <= 0) {
-		error = -EINVAL;
-		goto err_out;
-	}
+	pdata = cyttsp_get_platform_data(dev);
+	if (IS_ERR(pdata))
+		return ERR_CAST(pdata);
 
 	ts = kzalloc(sizeof(*ts) + xfer_buf_size, GFP_KERNEL);
 	input_dev = input_allocate_device();
@@ -550,7 +645,7 @@ struct cyttsp *cyttsp_probe(const struct cyttsp_bus_ops *bus_ops,
 
 	ts->dev = dev;
 	ts->input = input_dev;
-	ts->pdata = dev_get_platdata(dev);
+	ts->pdata = pdata;
 	ts->bus_ops = bus_ops;
 	ts->irq = irq;
 
@@ -618,7 +713,6 @@ err_platform_exit:
 err_free_mem:
 	input_free_device(input_dev);
 	kfree(ts);
-err_out:
 	return ERR_PTR(error);
 }
 EXPORT_SYMBOL_GPL(cyttsp_probe);
diff --git a/include/linux/input/cyttsp.h b/include/linux/input/cyttsp.h
index d7c2520..92a9d52 100644
--- a/include/linux/input/cyttsp.h
+++ b/include/linux/input/cyttsp.h
@@ -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;
 };
 
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v2 3/3] Input: cyttsp - add default init function
  2016-01-05 12:59 ` Oreste Salerno
@ 2016-01-05 12:59   ` Oreste Salerno
  -1 siblings, 0 replies; 11+ messages in thread
From: Oreste Salerno @ 2016-01-05 12:59 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-input, fery, dmitry.torokhov, robh+dt, pawel.moll,
	mark.rutland, ijc+devicetree, galak, devicetree, 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.

Signed-off-by: Oreste Salerno <oreste.salerno@tomtom.com>
---
 drivers/input/touchscreen/cyttsp_core.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/drivers/input/touchscreen/cyttsp_core.c b/drivers/input/touchscreen/cyttsp_core.c
index 8390236..9872333 100644
--- a/drivers/input/touchscreen/cyttsp_core.c
+++ b/drivers/input/touchscreen/cyttsp_core.c
@@ -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;
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v2 3/3] Input: cyttsp - add default init function
@ 2016-01-05 12:59   ` Oreste Salerno
  0 siblings, 0 replies; 11+ messages in thread
From: Oreste Salerno @ 2016-01-05 12:59 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-input, fery, dmitry.torokhov, robh+dt, pawel.moll,
	mark.rutland, ijc+devicetree, galak, devicetree, 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.

Signed-off-by: Oreste Salerno <oreste.salerno@tomtom.com>
---
 drivers/input/touchscreen/cyttsp_core.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/drivers/input/touchscreen/cyttsp_core.c b/drivers/input/touchscreen/cyttsp_core.c
index 8390236..9872333 100644
--- a/drivers/input/touchscreen/cyttsp_core.c
+++ b/drivers/input/touchscreen/cyttsp_core.c
@@ -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;
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 2/3] Input: cyttsp - add device tree support
  2016-01-05 12:59   ` Oreste Salerno
  (?)
@ 2016-01-06 15:02   ` Rob Herring
  2016-01-07 21:35       ` Oreste Salerno
  -1 siblings, 1 reply; 11+ messages in thread
From: Rob Herring @ 2016-01-06 15:02 UTC (permalink / raw)
  To: Oreste Salerno
  Cc: linux-kernel, linux-input, fery, dmitry.torokhov, pawel.moll,
	mark.rutland, ijc+devicetree, galak, devicetree

On Tue, Jan 05, 2016 at 01:59:14PM +0100, Oreste Salerno wrote:
> 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.

> Signed-off-by: Oreste Salerno <oreste.salerno@tomtom.com>
> ---
>  .../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
> 
> diff --git a/Documentation/devicetree/bindings/input/touchscreen/cyttsp.txt b/Documentation/devicetree/bindings/input/touchscreen/cyttsp.txt
> new file mode 100644
> index 0000000..8e0bcc73
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/input/touchscreen/cyttsp.txt
> @@ -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

> +- 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...

> +- bootloader-key	: the bootloader key used to exit bootloader mode

I don't understand what this is.

> +
> +Optional properties:
> +- use_hndshk		: enable handshake bit
> +- act_dist		: active distance
> +- act_intrvl		: active refresh interval in ms

Is this sampling frequency?

> +- 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).

> +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>;

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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 2/3] Input: cyttsp - add device tree support
  2016-01-06 15:02   ` Rob Herring
@ 2016-01-07 21:35       ` Oreste Salerno
  0 siblings, 0 replies; 11+ messages in thread
From: Oreste Salerno @ 2016-01-07 21:35 UTC (permalink / raw)
  To: Rob Herring
  Cc: linux-kernel, linux-input, fery, dmitry.torokhov, pawel.moll,
	mark.rutland, ijc+devicetree, galak, devicetree

Hi Rob,

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

On Wed, Jan 06, 2016 at 09:02:56AM -0600, Rob Herring wrote:
> On Tue, Jan 05, 2016 at 01:59:14PM +0100, Oreste Salerno wrote:
> > 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.

> > Signed-off-by: Oreste Salerno <oreste.salerno@tomtom.com>
> > ---
> >  .../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
> > 
> > diff --git a/Documentation/devicetree/bindings/input/touchscreen/cyttsp.txt b/Documentation/devicetree/bindings/input/touchscreen/cyttsp.txt
> > new file mode 100644
> > index 0000000..8e0bcc73
> > --- /dev/null
> > +++ b/Documentation/devicetree/bindings/input/touchscreen/cyttsp.txt
> > @@ -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
> 
> > +- 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)") .

> > +- 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).

> > +
> > +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.
 
> > +- 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.
 
> > +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>;
> 
> 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

> Rob

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 2/3] Input: cyttsp - add device tree support
@ 2016-01-07 21:35       ` Oreste Salerno
  0 siblings, 0 replies; 11+ messages in thread
From: Oreste Salerno @ 2016-01-07 21:35 UTC (permalink / raw)
  To: Rob Herring
  Cc: linux-kernel, linux-input, fery, dmitry.torokhov, pawel.moll,
	mark.rutland, ijc+devicetree, galak, devicetree

Hi Rob,

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

On Wed, Jan 06, 2016 at 09:02:56AM -0600, Rob Herring wrote:
> On Tue, Jan 05, 2016 at 01:59:14PM +0100, Oreste Salerno wrote:
> > 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.

> > Signed-off-by: Oreste Salerno <oreste.salerno@tomtom.com>
> > ---
> >  .../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
> > 
> > diff --git a/Documentation/devicetree/bindings/input/touchscreen/cyttsp.txt b/Documentation/devicetree/bindings/input/touchscreen/cyttsp.txt
> > new file mode 100644
> > index 0000000..8e0bcc73
> > --- /dev/null
> > +++ b/Documentation/devicetree/bindings/input/touchscreen/cyttsp.txt
> > @@ -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
> 
> > +- 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)") .

> > +- 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).

> > +
> > +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.
 
> > +- 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.
 
> > +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>;
> 
> 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

> Rob

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2016-01-07 21:35 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-05 12:59 [PATCH v2 0/3] Add device tree support to the cyttsp driver Oreste Salerno
2016-01-05 12:59 ` Oreste Salerno
2016-01-05 12:59 ` [PATCH v2 1/3] Input: cyttsp - remove unused irq_gpio from platform_data Oreste Salerno
2016-01-05 12:59   ` Oreste Salerno
2016-01-05 12:59 ` [PATCH v2 2/3] Input: cyttsp - add device tree support Oreste Salerno
2016-01-05 12:59   ` Oreste Salerno
2016-01-06 15:02   ` Rob Herring
2016-01-07 21:35     ` Oreste Salerno
2016-01-07 21:35       ` Oreste Salerno
2016-01-05 12:59 ` [PATCH v2 3/3] Input: cyttsp - add default init function Oreste Salerno
2016-01-05 12:59   ` Oreste Salerno

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.