From: Andy Shevchenko <andy.shevchenko@gmail.com>
To: Patrick Rudolph <patrick.rudolph@9elements.com>,
linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Linus Walleij <linus.walleij@linaro.org>,
Andy Shevchenko <andy.shevchenko@gmail.com>
Subject: [PATCH v1 2/6] pinctrl: cy8c95x0: switch to using devm_regulator_get_enable()
Date: Sun, 10 Nov 2024 22:59:42 +0200 [thread overview]
Message-ID: <20241110210040.18918-3-andy.shevchenko@gmail.com> (raw)
In-Reply-To: <20241110210040.18918-1-andy.shevchenko@gmail.com>
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>
---
drivers/pinctrl/pinctrl-cy8c95x0.c | 58 ++++++------------------------
1 file changed, 11 insertions(+), 47 deletions(-)
diff --git a/drivers/pinctrl/pinctrl-cy8c95x0.c b/drivers/pinctrl/pinctrl-cy8c95x0.c
index 5f533dff4417..cb6d9458c1e8 100644
--- a/drivers/pinctrl/pinctrl-cy8c95x0.c
+++ b/drivers/pinctrl/pinctrl-cy8c95x0.c
@@ -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
@@ -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;
@@ -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);
@@ -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);
@@ -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);
@@ -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, ®map_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);
@@ -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;
+ return ret;
- 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);
-
- 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[] = {
@@ -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,
};
--
2.47.0
next prev parent reply other threads:[~2024-11-10 21:00 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-10 20:59 [PATCH v1 0/6] pinctrl: cy8c95x0: A portion of cleanups Andy Shevchenko
2024-11-10 20:59 ` [PATCH v1 1/6] pinctrl: cy8c95x0: Use 2-argument strscpy() Andy Shevchenko
2024-11-10 20:59 ` Andy Shevchenko [this message]
2024-11-10 20:59 ` [PATCH v1 3/6] pinctrl: cy8c95x0: use flexible sleeping in reset function Andy Shevchenko
2024-11-10 20:59 ` [PATCH v1 4/6] pinctrl: cy8c95x0: Use temporary variable for struct device Andy Shevchenko
2024-11-10 20:59 ` [PATCH v1 5/6] pinctrl: cy8c95x0: embed iterator to the for-loop Andy Shevchenko
2024-11-10 20:59 ` [PATCH v1 6/6] pinctrl: cy8c95x0: remove unneeded goto labels Andy Shevchenko
2024-11-13 13:18 ` [PATCH v1 0/6] pinctrl: cy8c95x0: A portion of cleanups Linus Walleij
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241110210040.18918-3-andy.shevchenko@gmail.com \
--to=andy.shevchenko@gmail.com \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=patrick.rudolph@9elements.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®