i2c: mux: pca954x: make pullup regulator optional
Laxman Dewangan [Wed, 15 Jan 2014 14:08:46 +0000 (19:08 +0530)]
The PCA954X driver require two supply, one for self as vcc and
other for output bus pullup as vcc-pullup.

Making vcc-pullup as optional as this is not mandatory regulator
for device and if it is not available then just do not enable it
and not cause to driver fail.

Change-Id: I1c63a13d01ac609af0a74934742daca7e68b4d00
Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com>
Reviewed-on: http://git-master/r/356050
Reviewed-by: Jihoon Bang <jbang@nvidia.com>

drivers/i2c/muxes/i2c-mux-pca954x.c

index 46f4593..6be47ed 100644 (file)
@@ -66,7 +66,7 @@ struct pca954x {
 
        u8 last_chan;           /* last register value */
        struct regulator *vcc_reg;
-       struct regulator *i2c_reg;
+       struct regulator *pullup_reg;
 };
 
 struct chip_desc {
@@ -139,13 +139,13 @@ static int pca954x_reg_write(struct i2c_adapter *adap,
                        goto vcc_regulator_failed;
                }
        }
-       /* Increase ref count for pca954x vcc_i2c */
-       if (data->i2c_reg) {
-               ret = regulator_enable(data->i2c_reg);
+       /* Increase ref count for pca954x vcc-pullup */
+       if (data->pullup_reg) {
+               ret = regulator_enable(data->pullup_reg);
                if (ret) {
-                       dev_err(&client->dev, "%s: failed to enable vcc_i2c\n",
+                       dev_err(&client->dev, "%s: failed to enable vcc-pullup\n",
                                __func__);
-                       goto i2c_regulator_failed;
+                       goto pullup_regulator_failed;
                }
        }
 
@@ -167,11 +167,11 @@ static int pca954x_reg_write(struct i2c_adapter *adap,
                                             val, I2C_SMBUS_BYTE, &data);
        }
 
-       /* Decrease ref count for pca954x vcc_i2c */
-       if (data->i2c_reg)
-               regulator_disable(data->i2c_reg);
+       /* Decrease ref count for pca954x vcc-pullup */
+       if (data->pullup_reg)
+               regulator_disable(data->pullup_reg);
 
-i2c_regulator_failed:
+pullup_regulator_failed:
        /* Decrease ref count for pca954x vcc */
        if (data->vcc_reg)
                regulator_disable(data->vcc_reg);
@@ -245,16 +245,11 @@ static int pca954x_probe(struct i2c_client *client,
                ret = PTR_ERR(data->vcc_reg);
                goto exit_free;
        }
-       /* Get regulator pointer for pca954x vcc_i2c */
-       data->i2c_reg = regulator_get(&client->dev, "vcc_i2c");
-       if (PTR_ERR(data->i2c_reg) == -EPROBE_DEFER)
-               data->i2c_reg = NULL;
-       else if (IS_ERR(data->i2c_reg)) {
-               dev_err(&client->dev, "%s: failed to get vcc_i2c\n",
-                       __func__);
-               ret = PTR_ERR(data->i2c_reg);
-               regulator_put(data->vcc_reg);
-               goto exit_free;
+       /* Get regulator pointer for pca954x vcc-pullup */
+       data->pullup_reg = regulator_get(&client->dev, "vcc-pullup");
+       if (IS_ERR(data->pullup_reg)) {
+               dev_info(&client->dev, "vcc-pullup regulator not found\n");
+               data->pullup_reg = NULL;
        }
 
        /* Increase ref count for pca954x vcc */
@@ -267,12 +262,12 @@ static int pca954x_probe(struct i2c_client *client,
                        goto exit_regulator_put;
                }
        }
-       /* Increase ref count for pca954x vcc_i2c */
-       if (data->i2c_reg) {
-               pr_info("%s: enable vcc_i2c\n", __func__);
-               ret = regulator_enable(data->i2c_reg);
+       /* Increase ref count for pca954x vcc-pullup */
+       if (data->pullup_reg) {
+               pr_info("%s: enable vcc-pullup\n", __func__);
+               ret = regulator_enable(data->pullup_reg);
                if (ret) {
-                       dev_err(&client->dev, "%s: failed to enable vcc_i2c\n",
+                       dev_err(&client->dev, "%s: failed to enable vcc-pullup\n",
                                __func__);
                        goto exit_vcc_regulator_disable;
                }
@@ -296,9 +291,9 @@ static int pca954x_probe(struct i2c_client *client,
        /* Decrease ref count for pca954x vcc */
        if (data->vcc_reg)
                regulator_disable(data->vcc_reg);
-       /* Decrease ref count for pca954x vcc_i2c */
-       if (data->i2c_reg)
-               regulator_disable(data->i2c_reg);
+       /* Decrease ref count for pca954x vcc-pullup */
+       if (data->pullup_reg)
+               regulator_disable(data->pullup_reg);
 
        data->type = id->driver_data;
        data->last_chan = 0;               /* force the first selection */
@@ -349,13 +344,14 @@ virt_reg_failed:
        for (num--; num >= 0; num--)
                i2c_del_mux_adapter(data->virt_adaps[num]);
 exit_regulator_disable:
-       if (data->i2c_reg)
-               regulator_disable(data->i2c_reg);
+       if (data->pullup_reg)
+               regulator_disable(data->pullup_reg);
 exit_vcc_regulator_disable:
        if (data->vcc_reg)
                regulator_disable(data->vcc_reg);
 exit_regulator_put:
-       regulator_put(data->i2c_reg);
+       if (data->pullup_reg)
+               regulator_put(data->pullup_reg);
        regulator_put(data->vcc_reg);
 exit_free:
        kfree(data);
@@ -375,7 +371,8 @@ static int pca954x_remove(struct i2c_client *client)
                        data->virt_adaps[i] = NULL;
                }
 
-       regulator_put(data->i2c_reg);
+       if (data->pullup_reg)
+               regulator_put(data->pullup_reg);
        regulator_put(data->vcc_reg);
 
        kfree(data);