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

Merge remote-tracking branches 'regulator/topic/88pg86x', 'regulator/topic/dt', 'regulator/topic/formatting' and 'regulator/topic/gpio' into regulator-next

+196 -35
+22
Documentation/devicetree/bindings/regulator/88pg86x.txt
··· 1 + Marvell 88PG867/88PG868 voltage regulators 2 + 3 + Required properties: 4 + - compatible: one of "marvell,88pg867", "marvell,88pg868"; 5 + - reg: I2C slave address. 6 + 7 + Optional subnodes for regulators: "buck1", "buck2", using common regulator 8 + bindings given in <Documentation/devicetree/bindings/regulator/regulator.txt>. 9 + 10 + Example: 11 + 12 + pg868@19 { 13 + compatible = "marvell,88pg868"; 14 + reg = <0x19>; 15 + 16 + vcpu: buck1 { 17 + regulator-boot-on; 18 + regulator-always-on; 19 + regulator-min-microvolt = <1000000>; 20 + regulator-max-microvolt = <1350000>; 21 + }; 22 + };
+1
Documentation/devicetree/bindings/regulator/fixed-regulator.txt
··· 2 2 3 3 Required properties: 4 4 - compatible: Must be "regulator-fixed"; 5 + - regulator-name: Defined in regulator.txt as optional, but required here. 5 6 6 7 Optional properties: 7 8 - gpio: gpio to use for enable control
+2
Documentation/devicetree/bindings/regulator/gpio-regulator.txt
··· 2 2 3 3 Required properties: 4 4 - compatible : Must be "regulator-gpio". 5 + - regulator-name : Defined in regulator.txt as optional, but required 6 + here. 5 7 - states : Selection of available voltages and GPIO configs. 6 8 if there are no states, then use a fixed regulator 7 9
+114
drivers/regulator/88pg86x.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + #include <linux/module.h> 3 + #include <linux/i2c.h> 4 + #include <linux/of.h> 5 + #include <linux/regulator/driver.h> 6 + #include <linux/regmap.h> 7 + 8 + static const struct regulator_ops pg86x_ops = { 9 + .set_voltage_sel = regulator_set_voltage_sel_regmap, 10 + .get_voltage_sel = regulator_get_voltage_sel_regmap, 11 + .list_voltage = regulator_list_voltage_linear_range, 12 + }; 13 + 14 + static const struct regulator_linear_range pg86x_buck1_ranges[] = { 15 + REGULATOR_LINEAR_RANGE( 0, 0, 10, 0), 16 + REGULATOR_LINEAR_RANGE(1000000, 11, 34, 25000), 17 + REGULATOR_LINEAR_RANGE(1600000, 35, 47, 50000), 18 + }; 19 + 20 + static const struct regulator_linear_range pg86x_buck2_ranges[] = { 21 + REGULATOR_LINEAR_RANGE( 0, 0, 15, 0), 22 + REGULATOR_LINEAR_RANGE(1000000, 16, 39, 25000), 23 + REGULATOR_LINEAR_RANGE(1600000, 40, 52, 50000), 24 + }; 25 + 26 + static const struct regulator_desc pg86x_regulators[] = { 27 + { 28 + .id = 0, 29 + .type = REGULATOR_VOLTAGE, 30 + .name = "buck1", 31 + .of_match = of_match_ptr("buck1"), 32 + .n_voltages = 11 + 24 + 13, 33 + .linear_ranges = pg86x_buck1_ranges, 34 + .n_linear_ranges = 3, 35 + .vsel_reg = 0x24, 36 + .vsel_mask = 0xff, 37 + .ops = &pg86x_ops, 38 + .owner = THIS_MODULE 39 + }, 40 + { 41 + .id = 1, 42 + .type = REGULATOR_VOLTAGE, 43 + .name = "buck2", 44 + .of_match = of_match_ptr("buck2"), 45 + .n_voltages = 16 + 24 + 13, 46 + .linear_ranges = pg86x_buck2_ranges, 47 + .n_linear_ranges = 3, 48 + .vsel_reg = 0x13, 49 + .vsel_mask = 0xff, 50 + .ops = &pg86x_ops, 51 + .owner = THIS_MODULE 52 + }, 53 + }; 54 + 55 + static const struct regmap_config pg86x_regmap = { 56 + .reg_bits = 8, 57 + .val_bits = 8, 58 + }; 59 + 60 + static int pg86x_i2c_probe(struct i2c_client *i2c) 61 + { 62 + int id, ret; 63 + struct regulator_config config = {.dev = &i2c->dev}; 64 + struct regmap *regmap = devm_regmap_init_i2c(i2c, &pg86x_regmap); 65 + 66 + if (IS_ERR(regmap)) { 67 + ret = PTR_ERR(regmap); 68 + dev_err(&i2c->dev, "regmap init failed: %d\n", ret); 69 + return ret; 70 + } 71 + 72 + for (id = 0; id < ARRAY_SIZE(pg86x_regulators); id++) { 73 + struct regulator_dev *rdev; 74 + rdev = devm_regulator_register(&i2c->dev, 75 + &pg86x_regulators[id], 76 + &config); 77 + if (IS_ERR(rdev)) { 78 + ret = PTR_ERR(rdev); 79 + dev_err(&i2c->dev, "failed to register %s: %d\n", 80 + pg86x_regulators[id].name, ret); 81 + return ret; 82 + } 83 + } 84 + return 0; 85 + } 86 + 87 + static const struct of_device_id pg86x_dt_ids [] = { 88 + { .compatible = "marvell,88pg867" }, 89 + { .compatible = "marvell,88pg868" }, 90 + { } 91 + }; 92 + MODULE_DEVICE_TABLE(of, pg86x_dt_ids); 93 + 94 + static const struct i2c_device_id pg86x_i2c_id[] = { 95 + { "88pg867", }, 96 + { "88pg868", }, 97 + { } 98 + }; 99 + MODULE_DEVICE_TABLE(i2c, pg86x_i2c_id); 100 + 101 + static struct i2c_driver pg86x_regulator_driver = { 102 + .driver = { 103 + .name = "88pg86x", 104 + .of_match_table = of_match_ptr(pg86x_dt_ids), 105 + }, 106 + .probe_new = pg86x_i2c_probe, 107 + .id_table = pg86x_i2c_id, 108 + }; 109 + 110 + module_i2c_driver(pg86x_regulator_driver); 111 + 112 + MODULE_DESCRIPTION("Marvell 88PG86X voltage regulator"); 113 + MODULE_AUTHOR("Alexander Monakov <amonakov@gmail.com>"); 114 + MODULE_LICENSE("GPL");
+9
drivers/regulator/Kconfig
··· 54 54 55 55 If unsure, say no. 56 56 57 + config REGULATOR_88PG86X 58 + tristate "Marvell 88PG86X voltage regulators" 59 + depends on I2C 60 + select REGMAP_I2C 61 + help 62 + This driver supports Marvell 88PG867 and 88PG868 voltage regulators. 63 + They provide two I2C-controlled DC/DC step-down converters with 64 + sleep mode and separate enable pins. 65 + 57 66 config REGULATOR_88PM800 58 67 tristate "Marvell 88PM800 Power regulators" 59 68 depends on MFD_88PM800
+1
drivers/regulator/Makefile
··· 10 10 obj-$(CONFIG_REGULATOR_VIRTUAL_CONSUMER) += virtual.o 11 11 obj-$(CONFIG_REGULATOR_USERSPACE_CONSUMER) += userspace-consumer.o 12 12 13 + obj-$(CONFIG_REGULATOR_88PG86X) += 88pg86x.o 13 14 obj-$(CONFIG_REGULATOR_88PM800) += 88pm800.o 14 15 obj-$(CONFIG_REGULATOR_88PM8607) += 88pm8607.o 15 16 obj-$(CONFIG_REGULATOR_CPCAP) += cpcap-regulator.o
+17 -9
drivers/regulator/core.c
··· 1937 1937 struct gpio_desc *gpiod; 1938 1938 int ret; 1939 1939 1940 - gpiod = gpio_to_desc(config->ena_gpio); 1940 + if (config->ena_gpiod) 1941 + gpiod = config->ena_gpiod; 1942 + else 1943 + gpiod = gpio_to_desc(config->ena_gpio); 1941 1944 1942 1945 list_for_each_entry(pin, &regulator_ena_gpio_list, list) { 1943 1946 if (pin->gpiod == gpiod) { ··· 1950 1947 } 1951 1948 } 1952 1949 1953 - ret = gpio_request_one(config->ena_gpio, 1954 - GPIOF_DIR_OUT | config->ena_gpio_flags, 1955 - rdev_get_name(rdev)); 1956 - if (ret) 1957 - return ret; 1950 + if (!config->ena_gpiod) { 1951 + ret = gpio_request_one(config->ena_gpio, 1952 + GPIOF_DIR_OUT | config->ena_gpio_flags, 1953 + rdev_get_name(rdev)); 1954 + if (ret) 1955 + return ret; 1956 + } 1958 1957 1959 1958 pin = kzalloc(sizeof(struct regulator_enable_gpio), GFP_KERNEL); 1960 1959 if (pin == NULL) { 1961 - gpio_free(config->ena_gpio); 1960 + if (!config->ena_gpiod) 1961 + gpio_free(config->ena_gpio); 1962 1962 return -ENOMEM; 1963 1963 } 1964 1964 ··· 4160 4154 goto clean; 4161 4155 } 4162 4156 4163 - if ((config->ena_gpio || config->ena_gpio_initialized) && 4164 - gpio_is_valid(config->ena_gpio)) { 4157 + if (config->ena_gpiod || 4158 + ((config->ena_gpio || config->ena_gpio_initialized) && 4159 + gpio_is_valid(config->ena_gpio))) { 4165 4160 mutex_lock(&regulator_list_mutex); 4166 4161 ret = regulator_ena_gpio_request(rdev, config); 4167 4162 mutex_unlock(&regulator_list_mutex); ··· 4308 4301 return class_for_each_device(&regulator_class, NULL, &state, 4309 4302 _regulator_suspend_late); 4310 4303 } 4304 + 4311 4305 static int _regulator_resume_early(struct device *dev, void *data) 4312 4306 { 4313 4307 int ret = 0;
+2 -2
drivers/regulator/da9055-regulator.c
··· 16 16 #include <linux/init.h> 17 17 #include <linux/err.h> 18 18 #include <linux/gpio.h> 19 + #include <linux/gpio/consumer.h> 19 20 #include <linux/platform_device.h> 20 21 #include <linux/regulator/driver.h> 21 22 #include <linux/regulator/machine.h> ··· 456 455 char name[18]; 457 456 int gpio_mux = pdata->gpio_ren[id]; 458 457 459 - config->ena_gpio = pdata->ena_gpio[id]; 460 - config->ena_gpio_flags = GPIOF_OUT_INIT_HIGH; 458 + config->ena_gpiod = pdata->ena_gpiods[id]; 461 459 config->ena_gpio_invert = 1; 462 460 463 461 /*
+11 -12
drivers/regulator/da9211-regulator.c
··· 15 15 */ 16 16 17 17 #include <linux/err.h> 18 - #include <linux/gpio.h> 19 18 #include <linux/i2c.h> 20 19 #include <linux/module.h> 21 20 #include <linux/init.h> ··· 24 25 #include <linux/regmap.h> 25 26 #include <linux/irq.h> 26 27 #include <linux/interrupt.h> 27 - #include <linux/of_gpio.h> 28 + #include <linux/gpio/consumer.h> 28 29 #include <linux/regulator/of_regulator.h> 29 30 #include <linux/regulator/da9211.h> 30 31 #include "da9211-regulator.h" ··· 293 294 294 295 pdata->init_data[n] = da9211_matches[i].init_data; 295 296 pdata->reg_node[n] = da9211_matches[i].of_node; 296 - pdata->gpio_ren[n] = 297 - of_get_named_gpio(da9211_matches[i].of_node, 298 - "enable-gpios", 0); 297 + pdata->gpiod_ren[n] = devm_gpiod_get_from_of_node(dev, 298 + da9211_matches[i].of_node, 299 + "enable", 300 + 0, 301 + GPIOD_OUT_HIGH, 302 + "da9211-enable"); 299 303 n++; 300 304 } 301 305 ··· 384 382 config.regmap = chip->regmap; 385 383 config.of_node = chip->pdata->reg_node[i]; 386 384 387 - if (gpio_is_valid(chip->pdata->gpio_ren[i])) { 388 - config.ena_gpio = chip->pdata->gpio_ren[i]; 389 - config.ena_gpio_initialized = true; 390 - } else { 391 - config.ena_gpio = -EINVAL; 392 - config.ena_gpio_initialized = false; 393 - } 385 + if (chip->pdata->gpiod_ren[i]) 386 + config.ena_gpiod = chip->pdata->gpiod_ren[i]; 387 + else 388 + config.ena_gpiod = NULL; 394 389 395 390 chip->rdev[i] = devm_regulator_register(chip->dev, 396 391 &da9211_regulators[i], &config);
+8 -9
drivers/regulator/gpio-regulator.c
··· 196 196 break; 197 197 } 198 198 config->gpios[i].gpio = gpio; 199 + config->gpios[i].label = config->supply_name; 199 200 if (proplen > 0) { 200 201 of_property_read_u32_index(np, "gpios-states", 201 202 i, &ret); ··· 272 271 drvdata->desc.name = kstrdup(config->supply_name, GFP_KERNEL); 273 272 if (drvdata->desc.name == NULL) { 274 273 dev_err(&pdev->dev, "Failed to allocate supply name\n"); 275 - ret = -ENOMEM; 276 - goto err; 274 + return -ENOMEM; 277 275 } 278 276 279 277 if (config->nr_gpios != 0) { ··· 292 292 dev_err(&pdev->dev, 293 293 "Could not obtain regulator setting GPIOs: %d\n", 294 294 ret); 295 - goto err_memstate; 295 + goto err_memgpio; 296 296 } 297 297 } 298 298 ··· 303 303 if (drvdata->states == NULL) { 304 304 dev_err(&pdev->dev, "Failed to allocate state data\n"); 305 305 ret = -ENOMEM; 306 - goto err_memgpio; 306 + goto err_stategpio; 307 307 } 308 308 drvdata->nr_states = config->nr_states; 309 309 ··· 324 324 default: 325 325 dev_err(&pdev->dev, "No regulator type set\n"); 326 326 ret = -EINVAL; 327 - goto err_memgpio; 327 + goto err_memstate; 328 328 } 329 329 330 330 /* build initial state from gpio init data. */ ··· 361 361 if (IS_ERR(drvdata->dev)) { 362 362 ret = PTR_ERR(drvdata->dev); 363 363 dev_err(&pdev->dev, "Failed to register regulator: %d\n", ret); 364 - goto err_stategpio; 364 + goto err_memstate; 365 365 } 366 366 367 367 platform_set_drvdata(pdev, drvdata); 368 368 369 369 return 0; 370 370 371 - err_stategpio: 372 - gpio_free_array(drvdata->gpios, drvdata->nr_gpios); 373 371 err_memstate: 374 372 kfree(drvdata->states); 373 + err_stategpio: 374 + gpio_free_array(drvdata->gpios, drvdata->nr_gpios); 375 375 err_memgpio: 376 376 kfree(drvdata->gpios); 377 377 err_name: 378 378 kfree(drvdata->desc.name); 379 - err: 380 379 return ret; 381 380 } 382 381
+3 -2
include/linux/mfd/da9055/pdata.h
··· 12 12 #define DA9055_MAX_REGULATORS 8 13 13 14 14 struct da9055; 15 + struct gpio_desc; 15 16 16 17 enum gpio_select { 17 18 NO_GPIO = 0, ··· 48 47 * controls the regulator set A/B, 0 if not available. 49 48 */ 50 49 enum gpio_select *reg_rsel; 51 - /* GPIOs to enable regulator, 0 if not available */ 52 - int *ena_gpio; 50 + /* GPIO descriptors to enable regulator, NULL if not available */ 51 + struct gpio_desc **ena_gpiods; 53 52 }; 54 53 #endif /* __DA9055_PDATA_H */
+3 -1
include/linux/regulator/da9211.h
··· 21 21 22 22 #define DA9211_MAX_REGULATORS 2 23 23 24 + struct gpio_desc; 25 + 24 26 enum da9211_chip_id { 25 27 DA9211, 26 28 DA9212, ··· 41 39 * 2 : 2 phase 2 buck 42 40 */ 43 41 int num_buck; 44 - int gpio_ren[DA9211_MAX_REGULATORS]; 42 + struct gpio_desc *gpiod_ren[DA9211_MAX_REGULATORS]; 45 43 struct device_node *reg_node[DA9211_MAX_REGULATORS]; 46 44 struct regulator_init_data *init_data[DA9211_MAX_REGULATORS]; 47 45 };
+3
include/linux/regulator/driver.h
··· 19 19 #include <linux/notifier.h> 20 20 #include <linux/regulator/consumer.h> 21 21 22 + struct gpio_desc; 22 23 struct regmap; 23 24 struct regulator_dev; 24 25 struct regulator_config; ··· 388 387 * initialized, meaning that >= 0 is a valid gpio 389 388 * identifier and < 0 is a non existent gpio. 390 389 * @ena_gpio: GPIO controlling regulator enable. 390 + * @ena_gpiod: GPIO descriptor controlling regulator enable. 391 391 * @ena_gpio_invert: Sense for GPIO enable control. 392 392 * @ena_gpio_flags: Flags to use when calling gpio_request_one() 393 393 */ ··· 401 399 402 400 bool ena_gpio_initialized; 403 401 int ena_gpio; 402 + struct gpio_desc *ena_gpiod; 404 403 unsigned int ena_gpio_invert:1; 405 404 unsigned int ena_gpio_flags; 406 405 };