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

Configure Feed

Select the types of activity you want to include in your feed.

regulator: s2mps11: refactor handling of external rail control

Refactor s2mps14_pmic_enable_ext_control() and s2mps11_of_parse_cb()
slightly as a preparation for adding S2MPG10 and S2MPG11 support, as
both of those PMICs also support control of rails via GPIOs.

This also includes the following to avoid further updates in follow-up
commits:
* On S2MPG10 and S2MPG11, external rail control can be via GPIO or via
non-GPIO signals, hence passing a GPIO is allowed to be optional.
This avoids inappropriate verbose driver messages.
* Prepare to allow use of standard DT property name 'enable-gpios' for
newer platforms instead of vendor-specific 'samsung,ext-control'.

Signed-off-by: André Draszik <andre.draszik@linaro.org>
Link: https://patch.msgid.link/20260122-s2mpg1x-regulators-v7-15-3b1f9831fffd@linaro.org
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

André Draszik and committed by
Mark Brown
0042c880 5b3c9573

+77 -43
+77 -43
drivers/regulator/s2mps11.c
··· 328 328 rdev->desc->enable_mask, state); 329 329 } 330 330 331 + static int s2mps11_of_parse_gpiod(struct device_node *np, 332 + const char *con_id, bool optional, 333 + const struct regulator_desc *desc, 334 + struct regulator_config *config) 335 + { 336 + struct gpio_desc *ena_gpiod; 337 + int ret; 338 + 339 + ena_gpiod = fwnode_gpiod_get_index(of_fwnode_handle(np), con_id, 0, 340 + GPIOD_OUT_HIGH | 341 + GPIOD_FLAGS_BIT_NONEXCLUSIVE, 342 + "s2mps11-regulator"); 343 + if (IS_ERR(ena_gpiod)) { 344 + ret = PTR_ERR(ena_gpiod); 345 + 346 + /* Ignore all errors except probe defer. */ 347 + if (ret == -EPROBE_DEFER) 348 + return ret; 349 + 350 + if (ret == -ENOENT) { 351 + if (optional) 352 + return 0; 353 + 354 + dev_info(config->dev, 355 + "No entry for control GPIO for %d/%s in node %pOF\n", 356 + desc->id, desc->name, np); 357 + } else { 358 + dev_warn_probe(config->dev, ret, 359 + "Failed to get control GPIO for %d/%s in node %pOF\n", 360 + desc->id, desc->name, np); 361 + } 362 + 363 + return 0; 364 + } 365 + 366 + dev_info(config->dev, "Using GPIO for ext-control over %d/%s\n", 367 + desc->id, desc->name); 368 + 369 + config->ena_gpiod = ena_gpiod; 370 + 371 + return 0; 372 + } 373 + 331 374 static int s2mps11_of_parse_cb(struct device_node *np, 332 375 const struct regulator_desc *desc, 333 376 struct regulator_config *config) 334 377 { 335 378 const struct s2mps11_info *s2mps11 = config->driver_data; 336 - struct gpio_desc *ena_gpiod; 337 - int ret; 338 379 339 380 if (s2mps11->dev_type == S2MPS14X) 340 381 switch (desc->id) { ··· 390 349 else 391 350 return 0; 392 351 393 - ena_gpiod = fwnode_gpiod_get_index(of_fwnode_handle(np), 394 - "samsung,ext-control", 0, 395 - GPIOD_OUT_HIGH | 396 - GPIOD_FLAGS_BIT_NONEXCLUSIVE, 397 - "s2mps11-regulator"); 398 - if (IS_ERR(ena_gpiod)) { 399 - ret = PTR_ERR(ena_gpiod); 400 - 401 - /* Ignore all errors except probe defer. */ 402 - if (ret == -EPROBE_DEFER) 403 - return ret; 404 - 405 - if (ret == -ENOENT) 406 - dev_info(config->dev, 407 - "No entry for control GPIO for %d/%s in node %pOF\n", 408 - desc->id, desc->name, np); 409 - else 410 - dev_warn_probe(config->dev, ret, 411 - "Failed to get control GPIO for %d/%s in node %pOF\n", 412 - desc->id, desc->name, np); 413 - return 0; 414 - } 415 - 416 - dev_info(config->dev, "Using GPIO for ext-control over %d/%s\n", 417 - desc->id, desc->name); 418 - 419 - config->ena_gpiod = ena_gpiod; 420 - 421 - return 0; 352 + return s2mps11_of_parse_gpiod(np, "samsung,ext-control", false, desc, 353 + config); 422 354 } 423 355 424 356 static const struct regulator_ops s2mps11_ldo_ops = { ··· 917 903 }; 918 904 919 905 static int s2mps14_pmic_enable_ext_control(struct s2mps11_info *s2mps11, 920 - struct regulator_dev *rdev) 906 + struct regulator_dev *rdev) 921 907 { 922 - return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, 923 - rdev->desc->enable_mask, S2MPS14_ENABLE_EXT_CONTROL); 908 + int ret = regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, 909 + rdev->desc->enable_mask, 910 + S2MPS14_ENABLE_EXT_CONTROL); 911 + if (ret < 0) 912 + return dev_err_probe(rdev_get_dev(rdev), ret, 913 + "failed to enable GPIO control over %d/%s\n", 914 + rdev->desc->id, rdev->desc->name); 915 + return 0; 924 916 } 925 917 926 918 static int s2mpu02_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay) ··· 1264 1244 regulator_desc_s2mpu05_buck45(5), 1265 1245 }; 1266 1246 1247 + static int s2mps11_handle_ext_control(struct s2mps11_info *s2mps11, 1248 + struct regulator_dev *rdev) 1249 + { 1250 + int ret; 1251 + 1252 + switch (s2mps11->dev_type) { 1253 + case S2MPS14X: 1254 + if (!rdev->ena_pin) 1255 + return 0; 1256 + 1257 + ret = s2mps14_pmic_enable_ext_control(s2mps11, rdev); 1258 + break; 1259 + 1260 + default: 1261 + return 0; 1262 + } 1263 + 1264 + return ret; 1265 + } 1266 + 1267 1267 static int s2mps11_pmic_probe(struct platform_device *pdev) 1268 1268 { 1269 1269 struct sec_pmic_dev *iodev = dev_get_drvdata(pdev->dev.parent); ··· 1354 1314 regulators[i].id, 1355 1315 regulators[i].name); 1356 1316 1357 - if (regulator->ena_pin) { 1358 - ret = s2mps14_pmic_enable_ext_control(s2mps11, 1359 - regulator); 1360 - if (ret < 0) 1361 - return dev_err_probe(&pdev->dev, ret, 1362 - "failed to enable GPIO control over %d/%s\n", 1363 - regulator->desc->id, 1364 - regulator->desc->name); 1365 - } 1317 + ret = s2mps11_handle_ext_control(s2mps11, regulator); 1318 + if (ret < 0) 1319 + return ret; 1366 1320 } 1367 1321 1368 1322 return 0;