Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

regulator: rt5739: Add DID check and compatible for rt5733

Add compatible and use DID to check rt5733.

The only difference bwtween rt5733 and rt5739 is the output range and
voltage step. These two chips can be distinguished from the DIE id.

Signed-off-by: ChiYuan Huang <cy_huang@richtek.com>
Link: https://lore.kernel.org/r/1688048996-25606-3-git-send-email-cy_huang@richtek.com
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

ChiYuan Huang and committed by
Mark Brown
6f5e2858 8978af5e

+29 -7
+29 -7
drivers/regulator/rt5739.c
··· 31 31 #define RT5739_MODEVSEL1_MASK BIT(1) 32 32 #define RT5739_MODEVSEL0_MASK BIT(0) 33 33 #define RT5739_VID_MASK GENMASK(7, 5) 34 + #define RT5739_DID_MASK GENMASK(3, 0) 34 35 #define RT5739_ACTD_MASK BIT(7) 35 36 #define RT5739_ENVSEL1_MASK BIT(1) 36 37 #define RT5739_ENVSEL0_MASK BIT(0) 38 + 39 + #define RT5733_CHIPDIE_ID 0x1 40 + #define RT5733_VOLT_MINUV 270000 41 + #define RT5733_VOLT_MAXUV 1401250 42 + #define RT5733_VOLT_STPUV 6250 43 + #define RT5733_N_VOLTS 182 37 44 38 45 #define RT5739_VOLT_MINUV 300000 39 46 #define RT5739_VOLT_MAXUV 1300000 ··· 100 93 const struct regulator_desc *desc = rdev->desc; 101 94 struct regmap *regmap = rdev_get_regmap(rdev); 102 95 unsigned int reg, vsel; 96 + int max_uV; 103 97 104 - if (uV < RT5739_VOLT_MINUV || uV > RT5739_VOLT_MAXUV) 98 + max_uV = desc->min_uV + desc->uV_step * (desc->n_voltages - 1); 99 + 100 + if (uV < desc->min_uV || uV > max_uV) 105 101 return -EINVAL; 106 102 107 103 if (desc->vsel_reg == RT5739_REG_NSEL0) ··· 112 102 else 113 103 reg = RT5739_REG_NSEL0; 114 104 115 - vsel = (uV - RT5739_VOLT_MINUV) / RT5739_VOLT_STPUV; 105 + vsel = (uV - desc->min_uV) / desc->uV_step; 116 106 return regmap_write(regmap, reg, vsel); 117 107 } 118 108 ··· 199 189 } 200 190 201 191 static void rt5739_init_regulator_desc(struct regulator_desc *desc, 202 - bool vsel_active_high) 192 + bool vsel_active_high, u8 did) 203 193 { 204 194 /* Fixed */ 205 195 desc->name = "rt5739-regulator"; 206 196 desc->owner = THIS_MODULE; 207 197 desc->ops = &rt5739_regulator_ops; 208 - desc->n_voltages = RT5739_N_VOLTS; 209 - desc->min_uV = RT5739_VOLT_MINUV; 210 - desc->uV_step = RT5739_VOLT_STPUV; 211 198 desc->vsel_mask = RT5739_VSEL_MASK; 212 199 desc->enable_reg = RT5739_REG_CNTL2; 213 200 desc->active_discharge_reg = RT5739_REG_CNTL1; ··· 219 212 } else { 220 213 desc->vsel_reg = RT5739_REG_NSEL0; 221 214 desc->enable_mask = RT5739_ENVSEL0_MASK; 215 + } 216 + 217 + /* Assigned by CHIPDIE ID */ 218 + switch (did) { 219 + case RT5733_CHIPDIE_ID: 220 + desc->n_voltages = RT5733_N_VOLTS; 221 + desc->min_uV = RT5733_VOLT_MINUV; 222 + desc->uV_step = RT5733_VOLT_STPUV; 223 + break; 224 + default: 225 + desc->n_voltages = RT5739_N_VOLTS; 226 + desc->min_uV = RT5739_VOLT_MINUV; 227 + desc->uV_step = RT5739_VOLT_STPUV; 228 + break; 222 229 } 223 230 } 224 231 ··· 279 258 280 259 vsel_acth = device_property_read_bool(dev, "richtek,vsel-active-high"); 281 260 282 - rt5739_init_regulator_desc(desc, vsel_acth); 261 + rt5739_init_regulator_desc(desc, vsel_acth, vid & RT5739_DID_MASK); 283 262 284 263 cfg.dev = dev; 285 264 cfg.of_node = dev_of_node(dev); ··· 292 271 } 293 272 294 273 static const struct of_device_id rt5739_device_table[] = { 274 + { .compatible = "richtek,rt5733" }, 295 275 { .compatible = "richtek,rt5739" }, 296 276 { /* sentinel */ } 297 277 };