Skip to content

Commit f71aba3

Browse files
PatrickRudolphlinusw
authored andcommitted
pinctrl: cy8c95x0: Use single I2C lock
Currently there are 3 locks being used when accessing the chip, one in the driver and one in each regmap. Reduce that to one driver only lock that protects all regmap and regcache accesses. Signed-off-by: Patrick Rudolph <[email protected]> Reviewed-by: Andy Shevchenko <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Linus Walleij <[email protected]>
1 parent c501b78 commit f71aba3

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

drivers/pinctrl/pinctrl-cy8c95x0.c

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,6 @@ cy8c95x0_mux_reg_read(void *context, unsigned int off, unsigned int *val)
453453
u8 port = CY8C95X0_MUX_REGMAP_TO_PORT(off);
454454
int ret, reg = CY8C95X0_MUX_REGMAP_TO_REG(off);
455455

456-
mutex_lock(&chip->i2c_lock);
457456
/* Select the correct bank */
458457
ret = regmap_write(chip->regmap, CY8C95X0_PORTSEL, port);
459458
if (ret < 0)
@@ -463,11 +462,7 @@ cy8c95x0_mux_reg_read(void *context, unsigned int off, unsigned int *val)
463462
* Read the register through direct access regmap. The target range
464463
* is marked volatile.
465464
*/
466-
ret = regmap_read(chip->regmap, reg, val);
467-
out:
468-
mutex_unlock(&chip->i2c_lock);
469-
470-
return ret;
465+
return regmap_read(chip->regmap, reg, val);
471466
}
472467

473468
static int
@@ -477,7 +472,6 @@ cy8c95x0_mux_reg_write(void *context, unsigned int off, unsigned int val)
477472
u8 port = CY8C95X0_MUX_REGMAP_TO_PORT(off);
478473
int ret, reg = CY8C95X0_MUX_REGMAP_TO_REG(off);
479474

480-
mutex_lock(&chip->i2c_lock);
481475
/* Select the correct bank */
482476
ret = regmap_write(chip->regmap, CY8C95X0_PORTSEL, port);
483477
if (ret < 0)
@@ -487,11 +481,7 @@ cy8c95x0_mux_reg_write(void *context, unsigned int off, unsigned int val)
487481
* Write the register through direct access regmap. The target range
488482
* is marked volatile.
489483
*/
490-
ret = regmap_write(chip->regmap, reg, val);
491-
out:
492-
mutex_unlock(&chip->i2c_lock);
493-
494-
return ret;
484+
return regmap_write(chip->regmap, reg, val);
495485
}
496486

497487
static bool cy8c95x0_mux_accessible_register(struct device *dev, unsigned int off)
@@ -524,6 +514,7 @@ static const struct regmap_config cy8c95x0_muxed_regmap = {
524514
.num_reg_defaults_raw = MUXED_STRIDE * BANK_SZ,
525515
.readable_reg = cy8c95x0_mux_accessible_register,
526516
.writeable_reg = cy8c95x0_mux_accessible_register,
517+
.disable_locking = true,
527518
};
528519

529520
/* Direct access regmap */
@@ -542,6 +533,7 @@ static const struct regmap_config cy8c95x0_i2c_regmap = {
542533

543534
.cache_type = REGCACHE_FLAT,
544535
.max_register = CY8C95X0_COMMAND,
536+
.disable_locking = true,
545537
};
546538

547539
static inline int cy8c95x0_regmap_update_bits_base(struct cy8c95x0_pinctrl *chip,
@@ -559,6 +551,8 @@ static inline int cy8c95x0_regmap_update_bits_base(struct cy8c95x0_pinctrl *chip
559551
if (reg == CY8C95X0_PORTSEL)
560552
return -EINVAL;
561553

554+
mutex_lock(&chip->i2c_lock);
555+
562556
/* Registers behind the PORTSEL mux have their own regmap */
563557
if (cy8c95x0_muxed_register(reg)) {
564558
regmap = chip->muxed_regmap;
@@ -574,7 +568,7 @@ static inline int cy8c95x0_regmap_update_bits_base(struct cy8c95x0_pinctrl *chip
574568

575569
ret = regmap_update_bits_base(regmap, off, mask, val, change, async, force);
576570
if (ret < 0)
577-
return ret;
571+
goto out;
578572

579573
/* Update the cache when a WC bit is written */
580574
if (cy8c95x0_wc_register(reg) && (mask & val)) {
@@ -595,6 +589,8 @@ static inline int cy8c95x0_regmap_update_bits_base(struct cy8c95x0_pinctrl *chip
595589
regcache_cache_only(regmap, false);
596590
}
597591
}
592+
out:
593+
mutex_unlock(&chip->i2c_lock);
598594

599595
return ret;
600596
}
@@ -667,7 +663,9 @@ static int cy8c95x0_regmap_read(struct cy8c95x0_pinctrl *chip, unsigned int reg,
667663
unsigned int port, unsigned int *read_val)
668664
{
669665
struct regmap *regmap;
670-
int off;
666+
int off, ret;
667+
668+
mutex_lock(&chip->i2c_lock);
671669

672670
/* Registers behind the PORTSEL mux have their own regmap */
673671
if (cy8c95x0_muxed_register(reg)) {
@@ -682,7 +680,11 @@ static int cy8c95x0_regmap_read(struct cy8c95x0_pinctrl *chip, unsigned int reg,
682680
off = reg;
683681
}
684682

685-
return regmap_read(regmap, off, read_val);
683+
ret = regmap_read(regmap, off, read_val);
684+
685+
mutex_unlock(&chip->i2c_lock);
686+
687+
return ret;
686688
}
687689

688690
static int cy8c95x0_write_regs_mask(struct cy8c95x0_pinctrl *chip, int reg,

0 commit comments

Comments
 (0)