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

regulator: fan53555: add support for Silergy SYR82x regulators

Silergy SYR82x regulators share the exact same functionality and register layout
as the Fairchild FAN53555 regulators. Therefore extend the driver to add
support for them.

Both types use the same vendor id in their ID1 register, so it's not possible
to distinguish them automatically.

Similarly, the types also do not match. Type 8 used by the SYR827 and SYR828
start at 712.5mV and increment in 12.5mv steps, while the FAN53555 type 8
starts at 600mV and increments in 10mV steps.

Signed-off-by: Heiko Stuebner <heiko@sntech.de>
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Heiko Stuebner and committed by
Mark Brown
ee30928a 91f23d8f

+98 -25
+1 -1
Documentation/devicetree/bindings/regulator/fan53555.txt
··· 1 1 Binding for Fairchild FAN53555 regulators 2 2 3 3 Required properties: 4 - - compatible: "fcs,fan53555" 4 + - compatible: one of "fcs,fan53555", "silergy,syr827", "silergy,syr828" 5 5 - reg: I2C address 6 6 7 7 Optional properties:
+1
Documentation/devicetree/bindings/vendor-prefixes.txt
··· 125 125 silabs Silicon Laboratories 126 126 simtek 127 127 sii Seiko Instruments, Inc. 128 + silergy Silergy Corp. 128 129 sirf SiRF Technology, Inc. 129 130 smsc Standard Microsystems Corporation 130 131 snps Synopsys, Inc.
+96 -24
drivers/regulator/fan53555.c
··· 52 52 53 53 #define FAN53555_NVOLTAGES 64 /* Numbers of voltages */ 54 54 55 + enum fan53555_vendor { 56 + FAN53555_VENDOR_FAIRCHILD = 0, 57 + FAN53555_VENDOR_SILERGY, 58 + }; 59 + 55 60 /* IC Type */ 56 61 enum { 57 62 FAN53555_CHIP_ID_00 = 0, ··· 67 62 FAN53555_CHIP_ID_05, 68 63 }; 69 64 65 + enum { 66 + SILERGY_SYR82X = 8, 67 + }; 68 + 70 69 struct fan53555_device_info { 70 + enum fan53555_vendor vendor; 71 71 struct regmap *regmap; 72 72 struct device *dev; 73 73 struct regulator_desc desc; ··· 193 183 .set_ramp_delay = fan53555_set_ramp, 194 184 }; 195 185 196 - /* For 00,01,03,05 options: 197 - * VOUT = 0.60V + NSELx * 10mV, from 0.60 to 1.23V. 198 - * For 04 option: 199 - * VOUT = 0.603V + NSELx * 12.826mV, from 0.603 to 1.411V. 200 - * */ 201 - static int fan53555_device_setup(struct fan53555_device_info *di, 202 - struct fan53555_platform_data *pdata) 186 + static int fan53555_voltages_setup_fairchild(struct fan53555_device_info *di) 203 187 { 204 - /* Setup voltage control register */ 205 - switch (pdata->sleep_vsel_id) { 206 - case FAN53555_VSEL_ID_0: 207 - di->sleep_reg = FAN53555_VSEL0; 208 - di->vol_reg = FAN53555_VSEL1; 209 - break; 210 - case FAN53555_VSEL_ID_1: 211 - di->sleep_reg = FAN53555_VSEL1; 212 - di->vol_reg = FAN53555_VSEL0; 213 - break; 214 - default: 215 - dev_err(di->dev, "Invalid VSEL ID!\n"); 216 - return -EINVAL; 217 - } 218 188 /* Init voltage range and step */ 219 189 switch (di->chip_id) { 220 190 case FAN53555_CHIP_ID_00: ··· 210 220 break; 211 221 default: 212 222 dev_err(di->dev, 213 - "Chip ID[%d]\n not supported!\n", di->chip_id); 223 + "Chip ID %d not supported!\n", di->chip_id); 214 224 return -EINVAL; 215 225 } 216 226 217 227 return 0; 228 + } 229 + 230 + static int fan53555_voltages_setup_silergy(struct fan53555_device_info *di) 231 + { 232 + /* Init voltage range and step */ 233 + switch (di->chip_id) { 234 + case SILERGY_SYR82X: 235 + di->vsel_min = 712500; 236 + di->vsel_step = 12500; 237 + break; 238 + default: 239 + dev_err(di->dev, 240 + "Chip ID %d not supported!\n", di->chip_id); 241 + return -EINVAL; 242 + } 243 + 244 + return 0; 245 + } 246 + 247 + /* For 00,01,03,05 options: 248 + * VOUT = 0.60V + NSELx * 10mV, from 0.60 to 1.23V. 249 + * For 04 option: 250 + * VOUT = 0.603V + NSELx * 12.826mV, from 0.603 to 1.411V. 251 + * */ 252 + static int fan53555_device_setup(struct fan53555_device_info *di, 253 + struct fan53555_platform_data *pdata) 254 + { 255 + int ret = 0; 256 + 257 + /* Setup voltage control register */ 258 + switch (pdata->sleep_vsel_id) { 259 + case FAN53555_VSEL_ID_0: 260 + di->sleep_reg = FAN53555_VSEL0; 261 + di->vol_reg = FAN53555_VSEL1; 262 + break; 263 + case FAN53555_VSEL_ID_1: 264 + di->sleep_reg = FAN53555_VSEL1; 265 + di->vol_reg = FAN53555_VSEL0; 266 + break; 267 + default: 268 + dev_err(di->dev, "Invalid VSEL ID!\n"); 269 + return -EINVAL; 270 + } 271 + 272 + switch (di->vendor) { 273 + case FAN53555_VENDOR_FAIRCHILD: 274 + ret = fan53555_voltages_setup_fairchild(di); 275 + break; 276 + case FAN53555_VENDOR_SILERGY: 277 + ret = fan53555_voltages_setup_silergy(di); 278 + break; 279 + default: 280 + dev_err(di->dev, 281 + "vendor %d not supported!\n", di->chip_id); 282 + return -EINVAL; 283 + } 284 + 285 + return ret; 218 286 } 219 287 220 288 static int fan53555_regulator_register(struct fan53555_device_info *di, ··· 326 278 static const struct of_device_id fan53555_dt_ids[] = { 327 279 { 328 280 .compatible = "fcs,fan53555", 281 + .data = (void *)FAN53555_VENDOR_FAIRCHILD 282 + }, { 283 + .compatible = "silergy,syr827", 284 + .data = (void *)FAN53555_VENDOR_SILERGY, 285 + }, { 286 + .compatible = "silergy,syr828", 287 + .data = (void *)FAN53555_VENDOR_SILERGY, 329 288 }, 330 289 { } 331 290 }; ··· 362 307 if (!di) 363 308 return -ENOMEM; 364 309 365 - if (!client->dev.of_node) { 310 + if (client->dev.of_node) { 311 + const struct of_device_id *match; 312 + 313 + match = of_match_device(of_match_ptr(fan53555_dt_ids), 314 + &client->dev); 315 + if (!match) 316 + return -ENODEV; 317 + 318 + di->vendor = (int) match->data; 319 + } else { 366 320 /* if no ramp constraint set, get the pdata ramp_delay */ 367 321 if (!di->regulator->constraints.ramp_delay) { 368 322 int slew_idx = (pdata->slew_rate & 0x7) ··· 380 316 di->regulator->constraints.ramp_delay 381 317 = slew_rates[slew_idx]; 382 318 } 319 + 320 + di->vendor = id->driver_data; 383 321 } 384 322 385 323 di->regmap = devm_regmap_init_i2c(client, &fan53555_regmap_config); ··· 429 363 } 430 364 431 365 static const struct i2c_device_id fan53555_id[] = { 432 - {"fan53555", -1}, 366 + { 367 + .name = "fan53555", 368 + .driver_data = FAN53555_VENDOR_FAIRCHILD 369 + }, { 370 + .name = "syr82x", 371 + .driver_data = FAN53555_VENDOR_SILERGY 372 + }, 433 373 { }, 434 374 }; 435 375