Input: zforce - add devicetree support
authorHeiko Stübner <heiko.stuebner@bqreaders.com>
Mon, 27 Jan 2014 20:37:21 +0000 (12:37 -0800)
committerDmitry Torokhov <dmitry.torokhov@gmail.com>
Tue, 28 Jan 2014 06:35:42 +0000 (22:35 -0800)
This makes the zforce driver usable on devicetree-based platforms too.

Signed-off-by: Heiko Stuebner <heiko.stuebner@bqreaders.com>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Documentation/devicetree/bindings/input/touchscreen/zforce_ts.txt [new file with mode: 0644]
drivers/input/touchscreen/zforce_ts.c

diff --git a/Documentation/devicetree/bindings/input/touchscreen/zforce_ts.txt b/Documentation/devicetree/bindings/input/touchscreen/zforce_ts.txt
new file mode 100644 (file)
index 0000000..2faf1f1
--- /dev/null
@@ -0,0 +1,30 @@
+* Neonode infrared touchscreen controller
+
+Required properties:
+- compatible: must be "neonode,zforce"
+- reg: I2C address of the chip
+- interrupts: interrupt to which the chip is connected
+- gpios: gpios the chip is connected to
+  first one is the interrupt gpio and second one the reset gpio
+- x-size: horizontal resolution of touchscreen
+- y-size: vertical resolution of touchscreen
+
+Example:
+
+       i2c@00000000 {
+               /* ... */
+
+               zforce_ts@50 {
+                       compatible = "neonode,zforce";
+                       reg = <0x50>;
+                       interrupts = <2 0>;
+
+                       gpios = <&gpio5 6 0>, /* INT */
+                               <&gpio5 9 0>; /* RST */
+
+                       x-size = <800>;
+                       y-size = <600>;
+               };
+
+               /* ... */
+       };
index 91f4c7cb5dd5155b37211f48496c8bb76bf4af00..bdc936cb844542ec55d9bbb9c5f63a062798f69d 100644 (file)
@@ -29,6 +29,8 @@
 #include <linux/sysfs.h>
 #include <linux/input/mt.h>
 #include <linux/platform_data/zforce_ts.h>
+#include <linux/of.h>
+#include <linux/of_gpio.h>
 
 #define WAIT_TIMEOUT           msecs_to_jiffies(1000)
 
@@ -681,6 +683,45 @@ static void zforce_reset(void *data)
        gpio_set_value(ts->pdata->gpio_rst, 0);
 }
 
+static struct zforce_ts_platdata *zforce_parse_dt(struct device *dev)
+{
+       struct zforce_ts_platdata *pdata;
+       struct device_node *np = dev->of_node;
+
+       if (!np)
+               return ERR_PTR(-ENOENT);
+
+       pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
+       if (!pdata) {
+               dev_err(dev, "failed to allocate platform data\n");
+               return ERR_PTR(-ENOMEM);
+       }
+
+       pdata->gpio_int = of_get_gpio(np, 0);
+       if (!gpio_is_valid(pdata->gpio_int)) {
+               dev_err(dev, "failed to get interrupt gpio\n");
+               return ERR_PTR(-EINVAL);
+       }
+
+       pdata->gpio_rst = of_get_gpio(np, 1);
+       if (!gpio_is_valid(pdata->gpio_rst)) {
+               dev_err(dev, "failed to get reset gpio\n");
+               return ERR_PTR(-EINVAL);
+       }
+
+       if (of_property_read_u32(np, "x-size", &pdata->x_max)) {
+               dev_err(dev, "failed to get x-size property\n");
+               return ERR_PTR(-EINVAL);
+       }
+
+       if (of_property_read_u32(np, "y-size", &pdata->y_max)) {
+               dev_err(dev, "failed to get y-size property\n");
+               return ERR_PTR(-EINVAL);
+       }
+
+       return pdata;
+}
+
 static int zforce_probe(struct i2c_client *client,
                        const struct i2c_device_id *id)
 {
@@ -689,8 +730,11 @@ static int zforce_probe(struct i2c_client *client,
        struct input_dev *input_dev;
        int ret;
 
-       if (!pdata)
-               return -EINVAL;
+       if (!pdata) {
+               pdata = zforce_parse_dt(&client->dev);
+               if (IS_ERR(pdata))
+                       return PTR_ERR(pdata);
+       }
 
        ts = devm_kzalloc(&client->dev, sizeof(struct zforce_ts), GFP_KERNEL);
        if (!ts)
@@ -826,11 +870,20 @@ static struct i2c_device_id zforce_idtable[] = {
 };
 MODULE_DEVICE_TABLE(i2c, zforce_idtable);
 
+#ifdef CONFIG_OF
+static struct of_device_id zforce_dt_idtable[] = {
+       { .compatible = "neonode,zforce" },
+       {},
+};
+MODULE_DEVICE_TABLE(of, zforce_dt_idtable);
+#endif
+
 static struct i2c_driver zforce_driver = {
        .driver = {
                .owner  = THIS_MODULE,
                .name   = "zforce-ts",
                .pm     = &zforce_pm_ops,
+               .of_match_table = of_match_ptr(zforce_dt_idtable),
        },
        .probe          = zforce_probe,
        .id_table       = zforce_idtable,