Skip to content

Commit 6c30ac9

Browse files
PatrickRudolphwsakernel
authored andcommitted
i2c: muxes: pca954x: Add regulator support
Add a vdd regulator and enable it for boards that have the mux powered off by default. Signed-off-by: Patrick Rudolph <[email protected]> Reviewed-by: Andi Shyti <[email protected]> Acked-by: Peter Rosin <[email protected]> Signed-off-by: Wolfram Sang <[email protected]>
1 parent 8169443 commit 6c30ac9

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

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

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
#include <linux/module.h>
4949
#include <linux/pm.h>
5050
#include <linux/property.h>
51+
#include <linux/regulator/consumer.h>
5152
#include <linux/slab.h>
5253
#include <linux/spinlock.h>
5354
#include <dt-bindings/mux/mux.h>
@@ -100,6 +101,7 @@ struct pca954x {
100101
struct irq_domain *irq;
101102
unsigned int irq_mask;
102103
raw_spinlock_t lock;
104+
struct regulator *supply;
103105
};
104106

105107
/* Provide specs for the MAX735x, PCA954x and PCA984x types we know about */
@@ -447,6 +449,8 @@ static void pca954x_cleanup(struct i2c_mux_core *muxc)
447449
struct pca954x *data = i2c_mux_priv(muxc);
448450
int c, irq;
449451

452+
regulator_disable(data->supply);
453+
450454
if (data->irq) {
451455
for (c = 0; c < data->chip->nchans; c++) {
452456
irq = irq_find_mapping(data->irq, c);
@@ -499,10 +503,22 @@ static int pca954x_probe(struct i2c_client *client)
499503
i2c_set_clientdata(client, muxc);
500504
data->client = client;
501505

506+
data->supply = devm_regulator_get(dev, "vdd");
507+
if (IS_ERR(data->supply))
508+
return dev_err_probe(dev, PTR_ERR(data->supply),
509+
"Failed to request regulator\n");
510+
511+
ret = regulator_enable(data->supply);
512+
if (ret)
513+
return dev_err_probe(dev, ret,
514+
"Failed to enable vdd supply\n");
515+
502516
/* Reset the mux if a reset GPIO is specified. */
503517
gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
504-
if (IS_ERR(gpio))
505-
return PTR_ERR(gpio);
518+
if (IS_ERR(gpio)) {
519+
ret = PTR_ERR(gpio);
520+
goto fail_cleanup;
521+
}
506522
if (gpio) {
507523
udelay(1);
508524
gpiod_set_value_cansleep(gpio, 0);
@@ -519,15 +535,16 @@ static int pca954x_probe(struct i2c_client *client)
519535

520536
ret = i2c_get_device_id(client, &id);
521537
if (ret && ret != -EOPNOTSUPP)
522-
return ret;
538+
goto fail_cleanup;
523539

524540
if (!ret &&
525541
(id.manufacturer_id != data->chip->id.manufacturer_id ||
526542
id.part_id != data->chip->id.part_id)) {
527543
dev_warn(dev, "unexpected device id %03x-%03x-%x\n",
528544
id.manufacturer_id, id.part_id,
529545
id.die_revision);
530-
return -ENODEV;
546+
ret = -ENODEV;
547+
goto fail_cleanup;
531548
}
532549
}
533550

@@ -546,7 +563,8 @@ static int pca954x_probe(struct i2c_client *client)
546563
ret = pca954x_init(client, data);
547564
if (ret < 0) {
548565
dev_warn(dev, "probe failed\n");
549-
return -ENODEV;
566+
ret = -ENODEV;
567+
goto fail_cleanup;
550568
}
551569

552570
ret = pca954x_irq_setup(muxc);

0 commit comments

Comments
 (0)