mfd: tps65219: Implement LOCK register handling for TPS65214
Subsystems (2)
PATCH 1/1 mfd: tps65219: Implement LOCK register handling for TPS65214
From: "Kory Maincent (TI.com)" <[email protected]>
The TPS65214 PMIC variant has a LOCK_REG register that prevents writes to nearly all registers.
Implement custom regmap operations that automatically unlock before writes and re-lock afterwards for TPS65214, while leaving other chip variants unaffected.
The implementation follows the regmap-i2c design pattern.
--- drivers/mfd/tps65219.c | 53 +++++++++++++++++++++++++++++++++++- include/linux/mfd/tps65219.h | 3 ++ 2 files changed, 55 insertions(+), 1 deletion(-)
drivers/mfd/tps65219.c +52 -1
@@ -473,6 +473,55 @@ static const struct tps65219_chip_data chip_info_table[] = { }, }; +static int tps65219_reg_write (void *context,unsigned int reg,unsigned int val) +{ +struct i2c_client *i2c = context; +struct tps65219 *tps; +int ret; + +if (val >0xff || reg >0xff ) +return -EINVAL ; + + tps =i2c_get_clientdata (i2c); +if (tps->chip_id ==TPS65214 ) { + ret =i2c_smbus_write_byte_data (i2c,TPS65214_REG_LOCK , +TPS65214_LOCK_ACCESS_CMD ); +if (ret) +return ret; + } + + ret =i2c_smbus_write_byte_data (i2c, reg, val); +if (ret) +return ret; + +if (tps->chip_id ==TPS65214 ) +return i2c_smbus_write_byte_data (i2c,TPS65214_REG_LOCK ,0 ); + +return 0 ; +} + +static int tps65219_reg_read (void *context,unsigned int reg,unsigned int *val) +{ +struct i2c_client *i2c = context; +int ret; + +if (reg >0xff ) +return -EINVAL ; + + ret =i2c_smbus_read_byte_data (i2c, reg); +if (ret <0 ) +return ret; + + *val = ret; + +return 0 ; +} + +static const struct regmap_bus tps65219_regmap_bus = { + .reg_write = tps65219_reg_write, + .reg_read = tps65219_reg_read, +}; +static int tps65219_probe (struct i2c_client *client) {struct tps65219 *tps;
@@ -490,8 +539,10 @@ static int tps65219_probe(struct i2c_client *client) tps->dev = &client->dev; chip_id = (uintptr_t )i2c_get_match_data (client); pmic = &chip_info_table[chip_id]; + tps->chip_id = chip_id; - tps->regmap =devm_regmap_init_i2c (client, &tps65219_regmap_config); + tps->regmap =devm_regmap_init (&client->dev, &tps65219_regmap_bus, client, + &tps65219_regmap_config);if (IS_ERR (tps->regmap)) { ret =PTR_ERR (tps->regmap);dev_err (tps->dev,"Failed to allocate register map: %d\n" , ret);
include/linux/mfd/tps65219.h +3 -0
@@ -149,6 +149,8 @@ enum pmic_id {#define TPS65215_ENABLE_LDO2_EN_MASK BIT(5)#define TPS65214_ENABLE_LDO1_EN_MASK BIT(5)#define TPS65219_ENABLE_LDO4_EN_MASK BIT(6) +/* Register Lock */ +#define TPS65214_LOCK_ACCESS_CMD 0x5a/* power ON-OFF sequence slot */ #define TPS65219_BUCKS_LDOS_SEQUENCE_OFF_SLOT_MASK GENMASK(3, 0)#define TPS65219_BUCKS_LDOS_SEQUENCE_ON_SLOT_MASK GENMASK(7, 4)
@@ -444,6 +446,7 @@ struct tps65219 {struct regmap *regmap;struct regmap_irq_chip_data *irq_data; + enum pmic_id chip_id; };#endif /* MFD_TPS65219_H */
Signature · 1 line
2.43.0
Quoted 78 lines · Kory Maincent
From: "Kory Maincent (TI.com)" <[email protected]>
The TPS65214 PMIC variant has a
LOCK_REGregister that prevents writes to nearly all registers.Implement custom regmap operations that automatically unlock before writes and re-lock afterwards for TPS65214, while leaving other chip variants unaffected.
The implementation follows the regmap-i2c design pattern.
Signed-off-by Kory Maincent (TI.com) <[email protected]>--- drivers/mfd/tps65219.c | 53 +++++++++++++++++++++++++++++++++++- include/linux/mfd/tps65219.h | 3 ++ 2 files changed, 55 insertions(+), 1 deletion(-)drivers/mfd/tps65219.c +49
-0@@ -473,6 +473,55 @@ static const struct tps65219_chip_data chip_info_table[] = { }, }; +static int tps65219_reg_write (void *context,unsigned int reg,unsigned int val) +{ +struct i2c_client *i2c = context; +struct tps65219 *tps; +int ret; + +if (val >0xff || reg >0xff ) +return -EINVAL ; + + tps =i2c_get_clientdata (i2c); +if (tps->chip_id ==TPS65214 ) { + ret =i2c_smbus_write_byte_data (i2c,TPS65214_REG_LOCK , +TPS65214_LOCK_ACCESS_CMD ); +if (ret) +return ret; + } + + ret =i2c_smbus_write_byte_data (i2c, reg, val); +if (ret) +return ret; + +if (tps->chip_id ==TPS65214 ) +return i2c_smbus_write_byte_data (i2c,TPS65214_REG_LOCK ,0 ); + +return 0 ; +} + +static int tps65219_reg_read (void *context,unsigned int reg,unsigned int *val) +{ +struct i2c_client *i2c = context; +int ret; + +if (reg >0xff ) +return -EINVAL ; + + ret =i2c_smbus_read_byte_data (i2c, reg); +if (ret <0 ) +return ret; + + *val = ret; + +return 0 ; +} + +static const struct regmap_bus tps65219_regmap_bus = { + .reg_write = tps65219_reg_write, + .reg_read = tps65219_reg_read, +}; +static int tps65219_probe (struct i2c_client *client) {struct tps65219 *tps;
drivers/mfd/tps65219.c static int tps65219_probe(struct i2c_client *client) · line 545
Quoted 8 lines
drivers/mfd/tps65219.c +3
-1@@ -490,8 +539,10 @@ static int tps65219_probe(struct i2c_client *client) tps->dev = &client->dev; chip_id = (uintptr_t )i2c_get_match_data (client); pmic = &chip_info_table[chip_id]; + tps->chip_id = chip_id; - tps->regmap =devm_regmap_init_i2c (client, &tps65219_regmap_config); + tps->regmap =devm_regmap_init (&client->dev, &tps65219_regmap_bus, client, + &tps65219_regmap_config);
Why not do the (tps->chip_id == TPS65214) check here and only setup the special regmap_bus for the TPS65214. Then you don't need to do the checks every time reg_write is called.
It also means you don't need to store chip_id in the device instance data.
Andrew
Quoted 24 lines
drivers/mfd/tps65219.c +0
-0if (IS_ERR (tps->regmap)) { ret =PTR_ERR (tps->regmap);dev_err (tps->dev,"Failed to allocate register map: %d\n" , ret);include/linux/mfd/tps65219.h +3
-0@@ -149,6 +149,8 @@ enum pmic_id {#define TPS65215_ENABLE_LDO2_EN_MASK BIT(5)#define TPS65214_ENABLE_LDO1_EN_MASK BIT(5)#define TPS65219_ENABLE_LDO4_EN_MASK BIT(6) +/* Register Lock */ +#define TPS65214_LOCK_ACCESS_CMD 0x5a/* power ON-OFF sequence slot */ #define TPS65219_BUCKS_LDOS_SEQUENCE_OFF_SLOT_MASK GENMASK(3, 0)#define TPS65219_BUCKS_LDOS_SEQUENCE_ON_SLOT_MASK GENMASK(7, 4)@@ -444,6 +446,7 @@ struct tps65219 {struct regmap *regmap;struct regmap_irq_chip_data *irq_data; + enum pmic_id chip_id; };#endif /* MFD_TPS65219_H */
Quoted 84 lines · On Wed, 5 Nov 2025 14:52:21 -0600 Andrew Davis <[email protected]> wrote:
Quoted 83 lines · Kory Maincent
From: "Kory Maincent (TI.com)" <[email protected]>
The TPS65214 PMIC variant has a
LOCK_REGregister that prevents writes to nearly all registers.Implement custom regmap operations that automatically unlock before writes and re-lock afterwards for TPS65214, while leaving other chip variants unaffected.
The implementation follows the regmap-i2c design pattern.
Signed-off-by Kory Maincent (TI.com) <[email protected]>--- drivers/mfd/tps65219.c | 53 +++++++++++++++++++++++++++++++++++- include/linux/mfd/tps65219.h | 3 ++ 2 files changed, 55 insertions(+), 1 deletion(-)drivers/mfd/tps65219.c +22
-0@@ -473,6 +473,55 @@ static const struct tps65219_chip_data chip_info_table[] = { }, }; +static int tps65219_reg_write (void *context,unsigned int reg,unsigned int val) +{ +struct i2c_client *i2c = context; +struct tps65219 *tps; +int ret; + +if (val >0xff || reg >0xff ) +return -EINVAL ; + + tps =i2c_get_clientdata (i2c); +if (tps->chip_id ==TPS65214 ) { + ret =i2c_smbus_write_byte_data (i2c,TPS65214_REG_LOCK , +TPS65214_LOCK_ACCESS_CMD ); +if (ret) +return ret; + } + + ret =i2c_smbus_write_byte_data (i2c, reg, val); +if (ret) +return ret; + +if (tps->chip_id ==TPS65214 ) + return i2c_smbus_write_byte_data(i2c, TPS65214_REG_LOCK,0); +
drivers/mfd/tps65219.c +4
-0+return 0 ; +} + +static int tps65219_reg_read(void *context, unsigned int reg, unsigned int*val) +{
drivers/mfd/tps65219.c +21
-0+struct i2c_client *i2c = context; +int ret; + +if (reg >0xff ) +return -EINVAL ; + + ret =i2c_smbus_read_byte_data (i2c, reg); +if (ret <0 ) +return ret; + + *val = ret; + +return 0 ; +} + +static const struct regmap_bus tps65219_regmap_bus = { + .reg_write = tps65219_reg_write, + .reg_read = tps65219_reg_read, +}; +static int tps65219_probe (struct i2c_client *client) {struct tps65219 *tps;@@ -490,8 +539,10 @@ static int tps65219_probe(struct i2c_client *client) tps->dev = &client->dev; chip_id = (uintptr_t )i2c_get_match_data (client); pmic = &chip_info_table[chip_id]; + tps->chip_id = chip_id;
Quoted 9 lines
drivers/mfd/tps65219.c static int tps65219_probe(struct i2c_client *client) · line 547
Quoted 5 lines
drivers/mfd/tps65219.c +2
-1- tps->regmap =devm_regmap_init_i2c (client, &tps65219_regmap_config); + tps->regmap =devm_regmap_init (&client->dev, &tps65219_regmap_bus, client, + &tps65219_regmap_config);Why not do the (
tps->chip_id== TPS65214) check here and only setup the specialregmap_busfor the TPS65214. Then you don't need to do the checks every timereg_writeis called.
Yes indeed that's a better idea!
Thanks,
Signature · 3 lines
Köry Maincent, Bootlin Embedded Linux and kernel engineering https://bootlin.com