48
48
#include <linux/module.h>
49
49
#include <linux/pm.h>
50
50
#include <linux/property.h>
51
+ #include <linux/regulator/consumer.h>
51
52
#include <linux/slab.h>
52
53
#include <linux/spinlock.h>
53
54
#include <dt-bindings/mux/mux.h>
@@ -100,6 +101,7 @@ struct pca954x {
100
101
struct irq_domain * irq ;
101
102
unsigned int irq_mask ;
102
103
raw_spinlock_t lock ;
104
+ struct regulator * supply ;
103
105
};
104
106
105
107
/* 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)
447
449
struct pca954x * data = i2c_mux_priv (muxc );
448
450
int c , irq ;
449
451
452
+ regulator_disable (data -> supply );
453
+
450
454
if (data -> irq ) {
451
455
for (c = 0 ; c < data -> chip -> nchans ; c ++ ) {
452
456
irq = irq_find_mapping (data -> irq , c );
@@ -499,10 +503,22 @@ static int pca954x_probe(struct i2c_client *client)
499
503
i2c_set_clientdata (client , muxc );
500
504
data -> client = client ;
501
505
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
+
502
516
/* Reset the mux if a reset GPIO is specified. */
503
517
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
+ }
506
522
if (gpio ) {
507
523
udelay (1 );
508
524
gpiod_set_value_cansleep (gpio , 0 );
@@ -519,15 +535,16 @@ static int pca954x_probe(struct i2c_client *client)
519
535
520
536
ret = i2c_get_device_id (client , & id );
521
537
if (ret && ret != - EOPNOTSUPP )
522
- return ret ;
538
+ goto fail_cleanup ;
523
539
524
540
if (!ret &&
525
541
(id .manufacturer_id != data -> chip -> id .manufacturer_id ||
526
542
id .part_id != data -> chip -> id .part_id )) {
527
543
dev_warn (dev , "unexpected device id %03x-%03x-%x\n" ,
528
544
id .manufacturer_id , id .part_id ,
529
545
id .die_revision );
530
- return - ENODEV ;
546
+ ret = - ENODEV ;
547
+ goto fail_cleanup ;
531
548
}
532
549
}
533
550
@@ -546,7 +563,8 @@ static int pca954x_probe(struct i2c_client *client)
546
563
ret = pca954x_init (client , data );
547
564
if (ret < 0 ) {
548
565
dev_warn (dev , "probe failed\n" );
549
- return - ENODEV ;
566
+ ret = - ENODEV ;
567
+ goto fail_cleanup ;
550
568
}
551
569
552
570
ret = pca954x_irq_setup (muxc );
0 commit comments