Skip to content

Commit 3d4c421

Browse files
ukleinekUwe Kleine-König
authored andcommitted
pwm: pca9685: Make use of register caching in regmap
This essentially only caches the PRESCALE register because the per channel registers are affected by the ALL configuration that is used by the virtual pwm #16. The PRESCALE register is read often so caching it saves quite some i2c transfers. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com> Link: https://lore.kernel.org/r/dc25361908ad1dd790f108599bc9dbcc752288a5.1753784092.git.u.kleine-koenig@baylibre.com Signed-off-by: Uwe Kleine-König <ukleinek@kernel.org>
1 parent de58556 commit 3d4c421

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

drivers/pwm/pwm-pca9685.c

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,11 +521,36 @@ static const struct pwm_ops pca9685_pwm_ops = {
521521
.free = pca9685_pwm_free,
522522
};
523523

524+
static bool pca9685_readable_reg(struct device *dev, unsigned int reg)
525+
{
526+
/* The ALL_LED registers are readable but read as zero */
527+
return reg <= REG_OFF_H(15) || reg >= PCA9685_PRESCALE;
528+
}
529+
530+
static bool pca9685_writeable_reg(struct device *dev, unsigned int reg)
531+
{
532+
return reg <= REG_OFF_H(15) || reg >= PCA9685_ALL_LED_ON_L;
533+
}
534+
535+
static bool pca9685_volatile_reg(struct device *dev, unsigned int reg)
536+
{
537+
/*
538+
* Writing to an ALL_LED register affects all LEDi registers, so they
539+
* are not cachable. :-\
540+
*/
541+
return reg < PCA9685_PRESCALE;
542+
}
543+
524544
static const struct regmap_config pca9685_regmap_i2c_config = {
525545
.reg_bits = 8,
526546
.val_bits = 8,
547+
548+
.readable_reg = pca9685_readable_reg,
549+
.writeable_reg = pca9685_writeable_reg,
550+
.volatile_reg = pca9685_volatile_reg,
551+
527552
.max_register = PCA9685_NUMREGS,
528-
.cache_type = REGCACHE_NONE,
553+
.cache_type = REGCACHE_MAPLE,
529554
};
530555

531556
static int pca9685_pwm_probe(struct i2c_client *client)

0 commit comments

Comments
 (0)