]> Git Repo - linux.git/commitdiff
Input: mpr121 - use devm_regulator_get_enable_read_voltage()
authorDavid Lechner <[email protected]>
Tue, 19 Nov 2024 22:27:40 +0000 (16:27 -0600)
committerDmitry Torokhov <[email protected]>
Wed, 20 Nov 2024 05:37:41 +0000 (21:37 -0800)
We can reduce boilerplate code by using
devm_regulator_get_enable_read_voltage().

Reviewed-by: Jonathan Cameron <[email protected]>
Signed-off-by: David Lechner <[email protected]>
Link: https://lore.kernel.org/r/20241119-input-mpr121-regulator-get-enable-read-voltage-v3-1-1d8ee5c22f6c@baylibre.com
Signed-off-by: Dmitry Torokhov <[email protected]>
drivers/input/keyboard/mpr121_touchkey.c

index 21827d2497fa7c8296a62989cca7fc4188d9f4e7..bd1a944ded46fd0f278fb1c1f1696b7e11fb6891 100644 (file)
@@ -82,42 +82,6 @@ static const struct mpr121_init_register init_reg_table[] = {
        { AUTO_CONFIG_CTRL_ADDR, 0x0b },
 };
 
-static void mpr121_vdd_supply_disable(void *data)
-{
-       struct regulator *vdd_supply = data;
-
-       regulator_disable(vdd_supply);
-}
-
-static struct regulator *mpr121_vdd_supply_init(struct device *dev)
-{
-       struct regulator *vdd_supply;
-       int err;
-
-       vdd_supply = devm_regulator_get(dev, "vdd");
-       if (IS_ERR(vdd_supply)) {
-               dev_err(dev, "failed to get vdd regulator: %ld\n",
-                       PTR_ERR(vdd_supply));
-               return vdd_supply;
-       }
-
-       err = regulator_enable(vdd_supply);
-       if (err) {
-               dev_err(dev, "failed to enable vdd regulator: %d\n", err);
-               return ERR_PTR(err);
-       }
-
-       err = devm_add_action_or_reset(dev, mpr121_vdd_supply_disable,
-                                      vdd_supply);
-       if (err) {
-               dev_err(dev, "failed to add disable regulator action: %d\n",
-                       err);
-               return ERR_PTR(err);
-       }
-
-       return vdd_supply;
-}
-
 static void mpr_touchkey_report(struct input_dev *dev)
 {
        struct mpr121_touchkey *mpr121 = input_get_drvdata(dev);
@@ -233,7 +197,6 @@ err_i2c_write:
 static int mpr_touchkey_probe(struct i2c_client *client)
 {
        struct device *dev = &client->dev;
-       struct regulator *vdd_supply;
        int vdd_uv;
        struct mpr121_touchkey *mpr121;
        struct input_dev *input_dev;
@@ -241,11 +204,9 @@ static int mpr_touchkey_probe(struct i2c_client *client)
        int error;
        int i;
 
-       vdd_supply = mpr121_vdd_supply_init(dev);
-       if (IS_ERR(vdd_supply))
-               return PTR_ERR(vdd_supply);
-
-       vdd_uv = regulator_get_voltage(vdd_supply);
+       vdd_uv = devm_regulator_get_enable_read_voltage(dev, "vdd");
+       if (vdd_uv < 0)
+               return dev_err_probe(dev, vdd_uv, "failed to get vdd voltage\n");
 
        mpr121 = devm_kzalloc(dev, sizeof(*mpr121), GFP_KERNEL);
        if (!mpr121)
This page took 0.063612 seconds and 4 git commands to generate.