Input: ad7879 - allow exporting AUX/VBAT/GPIO pin via device property
authorDmitry Torokhov <dmitry.torokhov@gmail.com>
Fri, 17 Feb 2017 18:45:59 +0000 (10:45 -0800)
committerDmitry Torokhov <dmitry.torokhov@gmail.com>
Thu, 23 Feb 2017 17:21:27 +0000 (09:21 -0800)
Up until now only platforms using legacy platform data were able to switch
AUX/VBAT/GPIO pin in GPIO mode and use it as regular GPIO line. Let's
allow platforms using generic device properties to do the same.

Reviewed-by: Michael Hennerich <michael.hennerich@analog.com>
Tested-by: Michael Hennerich <michael.hennerich@analog.com>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Documentation/devicetree/bindings/input/touchscreen/ad7879.txt
drivers/input/touchscreen/ad7879.c

index e3f22d23fc8fa8b91db6521afe540a46daeef5a8..323b6098be19191238d71e158c9c6b0aea7351ff 100644 (file)
@@ -35,6 +35,7 @@ Optional properties:
 - adi,conversion-interval:     : 0    : convert one time only
                                  1-255: 515us + val * 35us (up to 9.440ms)
                                  This property has to be a '/bits/ 8' value
+- gpio-controller              : Switch AUX/VBAT/GPIO pin to GPIO mode
 
 Example:
 
index b7ab7f9767cabca9f3c1f38fdf93046501775b03..b6da5cee80eb8b6dfe30d983f3219edaaf19a80b 100644 (file)
@@ -454,17 +454,28 @@ static void ad7879_gpio_set_value(struct gpio_chip *chip,
 static int ad7879_gpio_add(struct ad7879 *ts,
                           const struct ad7879_platform_data *pdata)
 {
+       bool gpio_export;
+       int gpio_base;
        int ret = 0;
 
+       if (pdata) {
+               gpio_export = pdata->gpio_export;
+               gpio_base = pdata->gpio_base;
+       } else {
+               gpio_export = device_property_read_bool(ts->dev,
+                                                       "gpio-controller");
+               gpio_base = -1;
+       }
+
        mutex_init(&ts->mutex);
 
-       if (pdata && pdata->gpio_export) {
+       if (gpio_export) {
                ts->gc.direction_input = ad7879_gpio_direction_input;
                ts->gc.direction_output = ad7879_gpio_direction_output;
                ts->gc.get = ad7879_gpio_get_value;
                ts->gc.set = ad7879_gpio_set_value;
                ts->gc.can_sleep = 1;
-               ts->gc.base = pdata->gpio_base;
+               ts->gc.base = gpio_base;
                ts->gc.ngpio = 1;
                ts->gc.label = "AD7879-GPIO";
                ts->gc.owner = THIS_MODULE;