Input: improve usage of gpiod API
authorUwe Kleine-König <u.kleine-koenig@pengutronix.de>
Wed, 17 Jun 2015 00:02:13 +0000 (17:02 -0700)
committerDmitry Torokhov <dmitry.torokhov@gmail.com>
Wed, 17 Jun 2015 00:09:14 +0000 (17:09 -0700)
Since 39b2bbe3d715 (gpio: add flags argument to gpiod_get*() functions)
which appeared in v3.17-rc1, the gpiod_get* functions take an additional
parameter that allows to specify direction and initial value for
output. Simplify drivers accordingly.

Note that in the case of the drv260x driver error checking is more
strict now because -ENOSYS is reported to the caller now. But this
should only be returned if GPIOLIB is disabled which shouldn't happen as
the driver depends on GPIOLIB.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
drivers/input/keyboard/clps711x-keypad.c
drivers/input/misc/drv260x.c
drivers/input/misc/gpio-beeper.c

index 27ef29f8fe6adbc8e288a24a37b68b0471027c50..b637f1af842e475369db39056c8579583422a660 100644 (file)
@@ -120,14 +120,9 @@ static int clps711x_keypad_probe(struct platform_device *pdev)
        for (i = 0; i < priv->row_count; i++) {
                struct clps711x_gpio_data *data = &priv->gpio_data[i];
 
-               data->desc = devm_gpiod_get_index(dev, "row", i);
-               if (!data->desc)
-                       return -EINVAL;
-
+               data->desc = devm_gpiod_get_index(dev, "row", i, GPIOD_IN);
                if (IS_ERR(data->desc))
                        return PTR_ERR(data->desc);
-
-               gpiod_direction_input(data->desc);
        }
 
        err = of_property_read_u32(np, "poll-interval", &poll_interval);
index 599578042ea0b578632fd702d4eb7902c5f979cd..e5d60ecd29a4d6adc2ae63cdfe69fea935edeb58 100644 (file)
@@ -580,15 +580,10 @@ static int drv260x_probe(struct i2c_client *client,
                return error;
        }
 
-       haptics->enable_gpio = devm_gpiod_get(&client->dev, "enable");
-       if (IS_ERR(haptics->enable_gpio)) {
-               error = PTR_ERR(haptics->enable_gpio);
-               if (error != -ENOENT && error != -ENOSYS)
-                       return error;
-               haptics->enable_gpio = NULL;
-       } else {
-               gpiod_direction_output(haptics->enable_gpio, 1);
-       }
+       haptics->enable_gpio = devm_gpiod_get_optional(&client->dev, "enable",
+                                                      GPIOD_OUT_HIGH);
+       if (IS_ERR(haptics->enable_gpio))
+               return PTR_ERR(haptics->enable_gpio);
 
        haptics->input_dev = devm_input_allocate_device(&client->dev);
        if (!haptics->input_dev) {
index 4817c5f0c3e436a30bb831ea5ead9e852fd1256b..16272fffeb7ebeb4102255fdfb86acd91094ff78 100644 (file)
@@ -66,13 +66,12 @@ static int gpio_beeper_probe(struct platform_device *pdev)
 {
        struct gpio_beeper *beep;
        struct input_dev *input;
-       int err;
 
        beep = devm_kzalloc(&pdev->dev, sizeof(*beep), GFP_KERNEL);
        if (!beep)
                return -ENOMEM;
 
-       beep->desc = devm_gpiod_get(&pdev->dev, NULL);
+       beep->desc = devm_gpiod_get(&pdev->dev, NULL, GPIOD_OUT_LOW);
        if (IS_ERR(beep->desc))
                return PTR_ERR(beep->desc);
 
@@ -92,10 +91,6 @@ static int gpio_beeper_probe(struct platform_device *pdev)
 
        input_set_capability(input, EV_SND, SND_BELL);
 
-       err = gpiod_direction_output(beep->desc, 0);
-       if (err)
-               return err;
-
        input_set_drvdata(input, beep);
 
        return input_register_device(input);