Skip to content

Commit

Permalink
pinctrl: cy8c95x0: switch to using devm_regulator_get_enable()
Browse files Browse the repository at this point in the history
The driver does not actively manage regulator state past probe() time,
so we can use devm_regulator_get_enable() to simplify the code.

Signed-off-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Link: https://lore.kernel.org/20241110210040.18918-3-andy.shevchenko@gmail.com
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
  • Loading branch information
Andy Shevchenko authored and Linus Walleij committed Nov 13, 2024
1 parent b7e9fc3 commit c13411c
Showing 1 changed file with 11 additions and 47 deletions.
58 changes: 11 additions & 47 deletions drivers/pinctrl/pinctrl-cy8c95x0.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ static const struct dmi_system_id cy8c95x0_dmi_acpi_irq_info[] = {
* @nport: Number of Gports in this chip
* @gpio_chip: gpiolib chip
* @driver_data: private driver data
* @regulator: Pointer to the regulator for the IC
* @dev: struct device
* @pctldev: pin controller device
* @pinctrl_desc: pin controller description
Expand All @@ -163,7 +162,6 @@ struct cy8c95x0_pinctrl {
int nport;
struct gpio_chip gpio_chip;
unsigned long driver_data;
struct regulator *regulator;
struct device *dev;
struct pinctrl_dev *pctldev;
struct pinctrl_desc pinctrl_desc;
Expand Down Expand Up @@ -1434,7 +1432,6 @@ static int cy8c95x0_probe(struct i2c_client *client)
struct cy8c95x0_pinctrl *chip;
struct regmap_config regmap_conf;
struct regmap_range_cfg regmap_range_conf;
struct regulator *reg;
int ret;

chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL);
Expand All @@ -1448,8 +1445,6 @@ static int cy8c95x0_probe(struct i2c_client *client)
if (!chip->driver_data)
return -ENODEV;

i2c_set_clientdata(client, chip);

chip->tpin = chip->driver_data & CY8C95X0_GPIO_MASK;
chip->nport = DIV_ROUND_UP(CY8C95X0_PIN_TO_OFFSET(chip->tpin), BANK_SZ);

Expand All @@ -1472,26 +1467,15 @@ static int cy8c95x0_probe(struct i2c_client *client)
return -ENODEV;
}

reg = devm_regulator_get(&client->dev, "vdd");
if (IS_ERR(reg)) {
if (PTR_ERR(reg) == -EPROBE_DEFER)
return -EPROBE_DEFER;
} else {
ret = regulator_enable(reg);
if (ret) {
dev_err(&client->dev, "failed to enable regulator vdd: %d\n", ret);
return ret;
}
chip->regulator = reg;
}
ret = devm_regulator_get_enable(&client->dev, "vdd");
if (ret)
return dev_err_probe(&client->dev, ret, "failed to enable regulator vdd\n");

/* bring the chip out of reset if reset pin is provided */
chip->gpio_reset = devm_gpiod_get_optional(&client->dev, "reset", GPIOD_OUT_HIGH);
if (IS_ERR(chip->gpio_reset)) {
ret = dev_err_probe(chip->dev, PTR_ERR(chip->gpio_reset),
"Failed to get GPIO 'reset'\n");
goto err_exit;
} else if (chip->gpio_reset) {
if (IS_ERR(chip->gpio_reset))
return dev_err_probe(chip->dev, PTR_ERR(chip->gpio_reset), "Failed to get GPIO 'reset'\n");
if (chip->gpio_reset) {
usleep_range(1000, 2000);
gpiod_set_value_cansleep(chip->gpio_reset, 0);
usleep_range(250000, 300000);
Expand All @@ -1506,10 +1490,8 @@ static int cy8c95x0_probe(struct i2c_client *client)
regmap_conf.num_reg_defaults_raw = regmap_range_conf.range_max;

chip->regmap = devm_regmap_init_i2c(client, &regmap_conf);
if (IS_ERR(chip->regmap)) {
ret = PTR_ERR(chip->regmap);
goto err_exit;
}
if (IS_ERR(chip->regmap))
return PTR_ERR(chip->regmap);

bitmap_zero(chip->push_pull, MAX_LINE);
bitmap_zero(chip->shiftmask, MAX_LINE);
Expand All @@ -1525,31 +1507,14 @@ static int cy8c95x0_probe(struct i2c_client *client)
if (client->irq) {
ret = cy8c95x0_irq_setup(chip, client->irq);
if (ret)
goto err_exit;
return ret;
}

ret = cy8c95x0_setup_pinctrl(chip);
if (ret)
goto err_exit;

ret = cy8c95x0_setup_gpiochip(chip);
if (ret)
goto err_exit;

return 0;

err_exit:
if (!IS_ERR_OR_NULL(chip->regulator))
regulator_disable(chip->regulator);
return ret;
}

static void cy8c95x0_remove(struct i2c_client *client)
{
struct cy8c95x0_pinctrl *chip = i2c_get_clientdata(client);
return ret;

if (!IS_ERR_OR_NULL(chip->regulator))
regulator_disable(chip->regulator);
return cy8c95x0_setup_gpiochip(chip);
}

static const struct acpi_device_id cy8c95x0_acpi_ids[] = {
Expand All @@ -1565,7 +1530,6 @@ static struct i2c_driver cy8c95x0_driver = {
.acpi_match_table = cy8c95x0_acpi_ids,
},
.probe = cy8c95x0_probe,
.remove = cy8c95x0_remove,
.id_table = cy8c95x0_id,
.detect = cy8c95x0_detect,
};
Expand Down

0 comments on commit c13411c

Please sign in to comment.