Commit 375b9424 authored by Bartosz Golaszewski's avatar Bartosz Golaszewski

gpio: max732x: use i2c_new_dummy_device()

We now have a resource managed version of i2c_new_dummy_device() that
also returns an actual error code instead of a NULL-pointer. Use it
in the max732x GPIO driver and simplify code in the process.
Signed-off-by: default avatarBartosz Golaszewski <bgolaszewski@baylibre.com>
parent 8764c4ca
...@@ -652,12 +652,12 @@ static int max732x_probe(struct i2c_client *client, ...@@ -652,12 +652,12 @@ static int max732x_probe(struct i2c_client *client,
case 0x60: case 0x60:
chip->client_group_a = client; chip->client_group_a = client;
if (nr_port > 8) { if (nr_port > 8) {
c = i2c_new_dummy(client->adapter, addr_b); c = devm_i2c_new_dummy_device(&client->dev,
if (!c) { client->adapter, addr_b);
if (IS_ERR(c)) {
dev_err(&client->dev, dev_err(&client->dev,
"Failed to allocate I2C device\n"); "Failed to allocate I2C device\n");
ret = -ENODEV; return PTR_ERR(c);
goto out_failed;
} }
chip->client_group_b = chip->client_dummy = c; chip->client_group_b = chip->client_dummy = c;
} }
...@@ -665,12 +665,12 @@ static int max732x_probe(struct i2c_client *client, ...@@ -665,12 +665,12 @@ static int max732x_probe(struct i2c_client *client,
case 0x50: case 0x50:
chip->client_group_b = client; chip->client_group_b = client;
if (nr_port > 8) { if (nr_port > 8) {
c = i2c_new_dummy(client->adapter, addr_a); c = devm_i2c_new_dummy_device(&client->dev,
if (!c) { client->adapter, addr_a);
if (IS_ERR(c)) {
dev_err(&client->dev, dev_err(&client->dev,
"Failed to allocate I2C device\n"); "Failed to allocate I2C device\n");
ret = -ENODEV; return PTR_ERR(c);
goto out_failed;
} }
chip->client_group_a = chip->client_dummy = c; chip->client_group_a = chip->client_dummy = c;
} }
...@@ -678,36 +678,34 @@ static int max732x_probe(struct i2c_client *client, ...@@ -678,36 +678,34 @@ static int max732x_probe(struct i2c_client *client,
default: default:
dev_err(&client->dev, "invalid I2C address specified %02x\n", dev_err(&client->dev, "invalid I2C address specified %02x\n",
client->addr); client->addr);
ret = -EINVAL; return -EINVAL;
goto out_failed;
} }
if (nr_port > 8 && !chip->client_dummy) { if (nr_port > 8 && !chip->client_dummy) {
dev_err(&client->dev, dev_err(&client->dev,
"Failed to allocate second group I2C device\n"); "Failed to allocate second group I2C device\n");
ret = -ENODEV; return -ENODEV;
goto out_failed;
} }
mutex_init(&chip->lock); mutex_init(&chip->lock);
ret = max732x_readb(chip, is_group_a(chip, 0), &chip->reg_out[0]); ret = max732x_readb(chip, is_group_a(chip, 0), &chip->reg_out[0]);
if (ret) if (ret)
goto out_failed; return ret;
if (nr_port > 8) { if (nr_port > 8) {
ret = max732x_readb(chip, is_group_a(chip, 8), &chip->reg_out[1]); ret = max732x_readb(chip, is_group_a(chip, 8), &chip->reg_out[1]);
if (ret) if (ret)
goto out_failed; return ret;
} }
ret = gpiochip_add_data(&chip->gpio_chip, chip); ret = gpiochip_add_data(&chip->gpio_chip, chip);
if (ret) if (ret)
goto out_failed; return ret;
ret = max732x_irq_setup(chip, id); ret = max732x_irq_setup(chip, id);
if (ret) { if (ret) {
gpiochip_remove(&chip->gpio_chip); gpiochip_remove(&chip->gpio_chip);
goto out_failed; return ret;
} }
if (pdata && pdata->setup) { if (pdata && pdata->setup) {
...@@ -719,10 +717,6 @@ static int max732x_probe(struct i2c_client *client, ...@@ -719,10 +717,6 @@ static int max732x_probe(struct i2c_client *client,
i2c_set_clientdata(client, chip); i2c_set_clientdata(client, chip);
return 0; return 0;
out_failed:
i2c_unregister_device(chip->client_dummy);
return ret;
} }
static int max732x_remove(struct i2c_client *client) static int max732x_remove(struct i2c_client *client)
...@@ -744,9 +738,6 @@ static int max732x_remove(struct i2c_client *client) ...@@ -744,9 +738,6 @@ static int max732x_remove(struct i2c_client *client)
gpiochip_remove(&chip->gpio_chip); gpiochip_remove(&chip->gpio_chip);
/* unregister any dummy i2c_client */
i2c_unregister_device(chip->client_dummy);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment