@@ -142,7 +142,6 @@ static const struct pca953x_reg_config pca957x_regs = {
142
142
struct pca953x_chip {
143
143
unsigned gpio_start ;
144
144
u8 reg_output [MAX_BANK ];
145
- u8 reg_direction [MAX_BANK ];
146
145
struct mutex i2c_lock ;
147
146
struct regmap * regmap ;
148
147
@@ -387,18 +386,13 @@ static int pca953x_read_regs(struct pca953x_chip *chip, int reg, u8 *val)
387
386
static int pca953x_gpio_direction_input (struct gpio_chip * gc , unsigned off )
388
387
{
389
388
struct pca953x_chip * chip = gpiochip_get_data (gc );
390
- u8 reg_val ;
389
+ u8 dirreg = pca953x_recalc_addr (chip , chip -> regs -> direction , off ,
390
+ true, false);
391
+ u8 bit = BIT (off % BANK_SZ );
391
392
int ret ;
392
393
393
394
mutex_lock (& chip -> i2c_lock );
394
- reg_val = chip -> reg_direction [off / BANK_SZ ] | (1u << (off % BANK_SZ ));
395
-
396
- ret = pca953x_write_single (chip , chip -> regs -> direction , reg_val , off );
397
- if (ret )
398
- goto exit ;
399
-
400
- chip -> reg_direction [off / BANK_SZ ] = reg_val ;
401
- exit :
395
+ ret = regmap_write_bits (chip -> regmap , dirreg , bit , bit );
402
396
mutex_unlock (& chip -> i2c_lock );
403
397
return ret ;
404
398
}
@@ -407,6 +401,9 @@ static int pca953x_gpio_direction_output(struct gpio_chip *gc,
407
401
unsigned off , int val )
408
402
{
409
403
struct pca953x_chip * chip = gpiochip_get_data (gc );
404
+ u8 dirreg = pca953x_recalc_addr (chip , chip -> regs -> direction , off ,
405
+ true, false);
406
+ u8 bit = BIT (off % BANK_SZ );
410
407
u8 reg_val ;
411
408
int ret ;
412
409
@@ -426,12 +423,7 @@ static int pca953x_gpio_direction_output(struct gpio_chip *gc,
426
423
chip -> reg_output [off / BANK_SZ ] = reg_val ;
427
424
428
425
/* then direction */
429
- reg_val = chip -> reg_direction [off / BANK_SZ ] & ~(1u << (off % BANK_SZ ));
430
- ret = pca953x_write_single (chip , chip -> regs -> direction , reg_val , off );
431
- if (ret )
432
- goto exit ;
433
-
434
- chip -> reg_direction [off / BANK_SZ ] = reg_val ;
426
+ ret = regmap_write_bits (chip -> regmap , dirreg , bit , 0 );
435
427
exit :
436
428
mutex_unlock (& chip -> i2c_lock );
437
429
return ret ;
@@ -483,16 +475,19 @@ static void pca953x_gpio_set_value(struct gpio_chip *gc, unsigned off, int val)
483
475
static int pca953x_gpio_get_direction (struct gpio_chip * gc , unsigned off )
484
476
{
485
477
struct pca953x_chip * chip = gpiochip_get_data (gc );
478
+ u8 dirreg = pca953x_recalc_addr (chip , chip -> regs -> direction , off ,
479
+ true, false);
480
+ u8 bit = BIT (off % BANK_SZ );
486
481
u32 reg_val ;
487
482
int ret ;
488
483
489
484
mutex_lock (& chip -> i2c_lock );
490
- ret = pca953x_read_single (chip , chip -> regs -> direction , & reg_val , off );
485
+ ret = regmap_read (chip -> regmap , dirreg , & reg_val );
491
486
mutex_unlock (& chip -> i2c_lock );
492
487
if (ret < 0 )
493
488
return ret ;
494
489
495
- return !!(reg_val & ( 1u << ( off % BANK_SZ )) );
490
+ return !!(reg_val & bit );
496
491
}
497
492
498
493
static void pca953x_gpio_set_multiple (struct gpio_chip * gc ,
@@ -580,6 +575,10 @@ static void pca953x_irq_bus_sync_unlock(struct irq_data *d)
580
575
u8 new_irqs ;
581
576
int level , i ;
582
577
u8 invert_irq_mask [MAX_BANK ];
578
+ int reg_direction [MAX_BANK ];
579
+
580
+ regmap_bulk_read (chip -> regmap , chip -> regs -> direction , reg_direction ,
581
+ NBANK (chip ));
583
582
584
583
if (chip -> driver_data & PCA_PCAL ) {
585
584
/* Enable latch on interrupt-enabled inputs */
@@ -595,7 +594,7 @@ static void pca953x_irq_bus_sync_unlock(struct irq_data *d)
595
594
/* Look for any newly setup interrupt */
596
595
for (i = 0 ; i < NBANK (chip ); i ++ ) {
597
596
new_irqs = chip -> irq_trig_fall [i ] | chip -> irq_trig_raise [i ];
598
- new_irqs &= ~ chip -> reg_direction [i ];
597
+ new_irqs &= reg_direction [i ];
599
598
600
599
while (new_irqs ) {
601
600
level = __ffs (new_irqs );
@@ -660,6 +659,7 @@ static bool pca953x_irq_pending(struct pca953x_chip *chip, u8 *pending)
660
659
bool pending_seen = false;
661
660
bool trigger_seen = false;
662
661
u8 trigger [MAX_BANK ];
662
+ int reg_direction [MAX_BANK ];
663
663
int ret , i ;
664
664
665
665
if (chip -> driver_data & PCA_PCAL ) {
@@ -690,8 +690,10 @@ static bool pca953x_irq_pending(struct pca953x_chip *chip, u8 *pending)
690
690
return false;
691
691
692
692
/* Remove output pins from the equation */
693
+ regmap_bulk_read (chip -> regmap , chip -> regs -> direction , reg_direction ,
694
+ NBANK (chip ));
693
695
for (i = 0 ; i < NBANK (chip ); i ++ )
694
- cur_stat [i ] &= chip -> reg_direction [i ];
696
+ cur_stat [i ] &= reg_direction [i ];
695
697
696
698
memcpy (old_stat , chip -> irq_stat , NBANK (chip ));
697
699
@@ -745,6 +747,7 @@ static int pca953x_irq_setup(struct pca953x_chip *chip,
745
747
int irq_base )
746
748
{
747
749
struct i2c_client * client = chip -> client ;
750
+ int reg_direction [MAX_BANK ];
748
751
int ret , i ;
749
752
750
753
if (client -> irq && irq_base != -1
@@ -759,8 +762,10 @@ static int pca953x_irq_setup(struct pca953x_chip *chip,
759
762
* interrupt. We have to rely on the previous read for
760
763
* this purpose.
761
764
*/
765
+ regmap_bulk_read (chip -> regmap , chip -> regs -> direction ,
766
+ reg_direction , NBANK (chip ));
762
767
for (i = 0 ; i < NBANK (chip ); i ++ )
763
- chip -> irq_stat [i ] &= chip -> reg_direction [i ];
768
+ chip -> irq_stat [i ] &= reg_direction [i ];
764
769
mutex_init (& chip -> irq_lock );
765
770
766
771
ret = devm_request_threaded_irq (& client -> dev ,
@@ -817,9 +822,9 @@ static int device_pca95xx_init(struct pca953x_chip *chip, u32 invert)
817
822
if (ret )
818
823
goto out ;
819
824
820
- ret = pca953x_read_regs (chip , chip -> regs -> direction ,
821
- chip -> reg_direction );
822
- if (ret )
825
+ ret = regcache_sync_region (chip -> regmap , chip -> regs -> direction ,
826
+ chip -> regs -> direction + NBANK ( chip ) );
827
+ if (ret != 0 )
823
828
goto out ;
824
829
825
830
/* set platform specific polarity inversion */
@@ -937,6 +942,8 @@ static int pca953x_probe(struct i2c_client *client,
937
942
goto err_exit ;
938
943
}
939
944
945
+ regcache_mark_dirty (chip -> regmap );
946
+
940
947
mutex_init (& chip -> i2c_lock );
941
948
/*
942
949
* In case we have an i2c-mux controlled by a GPIO provided by an
0 commit comments