i2c: pca-platform: unconditionally use devm_gpiod_get_optional
authorChris Packham <chris.packham@alliedtelesis.co.nz>
Wed, 5 Jul 2017 10:13:56 +0000 (22:13 +1200)
committerWolfram Sang <wsa@the-dreams.de>
Sat, 24 Mar 2018 12:26:00 +0000 (13:26 +0100)
Allow for the reset-gpios property to be defined in the device tree
or via a GPIO lookup table.

Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
drivers/i2c/busses/i2c-pca-platform.c

index 853a2abedb05e8a07af93274679ed443a085702b..b90193d09d4b24135e4d374876d692fe8faabab4 100644 (file)
@@ -173,33 +173,20 @@ static int i2c_pca_pf_probe(struct platform_device *pdev)
        i2c->adap.dev.parent = &pdev->dev;
        i2c->adap.dev.of_node = np;
 
+       i2c->gpio = devm_gpiod_get_optional(&pdev->dev, "reset-gpios", GPIOD_OUT_LOW);
+       if (IS_ERR(i2c->gpio))
+               return PTR_ERR(i2c->gpio);
+
        if (platform_data) {
                i2c->adap.timeout = platform_data->timeout;
                i2c->algo_data.i2c_clock = platform_data->i2c_clock_speed;
-               if (gpio_is_valid(platform_data->gpio)) {
-                       ret = devm_gpio_request_one(&pdev->dev,
-                                                   platform_data->gpio,
-                                                   GPIOF_ACTIVE_LOW,
-                                                   i2c->adap.name);
-                       if (ret == 0) {
-                               i2c->gpio = gpio_to_desc(platform_data->gpio);
-                               gpiod_direction_output(i2c->gpio, 0);
-                       } else {
-                               dev_warn(&pdev->dev, "Registering gpio failed!\n");
-                               i2c->gpio = NULL;
-                       }
-               }
        } else if (np) {
                i2c->adap.timeout = HZ;
-               i2c->gpio = devm_gpiod_get_optional(&pdev->dev, "reset-gpios", GPIOD_OUT_LOW);
-               if (IS_ERR(i2c->gpio))
-                       return PTR_ERR(i2c->gpio);
                of_property_read_u32_index(np, "clock-frequency", 0,
                                           &i2c->algo_data.i2c_clock);
        } else {
                i2c->adap.timeout = HZ;
                i2c->algo_data.i2c_clock = 59000;
-               i2c->gpio = NULL;
        }
 
        i2c->algo_data.data = i2c;