diff options
Diffstat (limited to 'drivers/regulator')
-rw-r--r-- | drivers/regulator/Kconfig | 8 | ||||
-rw-r--r-- | drivers/regulator/Makefile | 1 | ||||
-rw-r--r-- | drivers/regulator/ab8500.c | 126 | ||||
-rw-r--r-- | drivers/regulator/act8865-regulator.c | 349 | ||||
-rw-r--r-- | drivers/regulator/arizona-micsupp.c | 106 | ||||
-rw-r--r-- | drivers/regulator/as3722-regulator.c | 36 | ||||
-rw-r--r-- | drivers/regulator/core.c | 29 | ||||
-rw-r--r-- | drivers/regulator/gpio-regulator.c | 7 | ||||
-rw-r--r-- | drivers/regulator/pfuze100-regulator.c | 16 | ||||
-rw-r--r-- | drivers/regulator/s2mps11.c | 2 | ||||
-rw-r--r-- | drivers/regulator/s5m8767.c | 2 |
11 files changed, 498 insertions, 184 deletions
diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig index ce785f481281..63bc1bab37e3 100644 --- a/drivers/regulator/Kconfig +++ b/drivers/regulator/Kconfig @@ -70,6 +70,14 @@ config REGULATOR_88PM8607 help This driver supports 88PM8607 voltage regulator chips. +config REGULATOR_ACT8865 + tristate "Active-semi act8865 voltage regulator" + depends on I2C + select REGMAP_I2C + help + This driver controls a active-semi act8865 voltage output + regulator via I2C bus. + config REGULATOR_AD5398 tristate "Analog Devices AD5398/AD5821 regulators" depends on I2C diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile index 01c597ea1744..3bb3a5591b95 100644 --- a/drivers/regulator/Makefile +++ b/drivers/regulator/Makefile @@ -14,6 +14,7 @@ obj-$(CONFIG_REGULATOR_88PM8607) += 88pm8607.o obj-$(CONFIG_REGULATOR_AAT2870) += aat2870-regulator.o obj-$(CONFIG_REGULATOR_AB3100) += ab3100.o obj-$(CONFIG_REGULATOR_AB8500) += ab8500-ext.o ab8500.o +obj-$(CONFIG_REGULATOR_ACT8865) += act8865-regulator.o obj-$(CONFIG_REGULATOR_AD5398) += ad5398.o obj-$(CONFIG_REGULATOR_ANATOP) += anatop-regulator.o obj-$(CONFIG_REGULATOR_ARIZONA) += arizona-micsupp.o arizona-ldo1.o diff --git a/drivers/regulator/ab8500.c b/drivers/regulator/ab8500.c index 603f192e84f1..c625468c7f2c 100644 --- a/drivers/regulator/ab8500.c +++ b/drivers/regulator/ab8500.c @@ -2998,37 +2998,6 @@ static void abx500_get_regulator_info(struct ab8500 *ab8500) } } -static int ab8500_regulator_init_registers(struct platform_device *pdev, - int id, int mask, int value) -{ - struct ab8500_reg_init *reg_init = abx500_regulator.init; - int err; - - BUG_ON(value & ~mask); - BUG_ON(mask & ~reg_init[id].mask); - - /* initialize register */ - err = abx500_mask_and_set_register_interruptible( - &pdev->dev, - reg_init[id].bank, - reg_init[id].addr, - mask, value); - if (err < 0) { - dev_err(&pdev->dev, - "Failed to initialize 0x%02x, 0x%02x.\n", - reg_init[id].bank, - reg_init[id].addr); - return err; - } - dev_vdbg(&pdev->dev, - " init: 0x%02x, 0x%02x, 0x%02x, 0x%02x\n", - reg_init[id].bank, - reg_init[id].addr, - mask, value); - - return 0; -} - static int ab8500_regulator_register(struct platform_device *pdev, struct regulator_init_data *init_data, int id, struct device_node *np) @@ -3036,7 +3005,6 @@ static int ab8500_regulator_register(struct platform_device *pdev, struct ab8500 *ab8500 = dev_get_drvdata(pdev->dev.parent); struct ab8500_regulator_info *info = NULL; struct regulator_config config = { }; - int err; /* assign per-regulator data */ info = &abx500_regulator.info[id]; @@ -3058,17 +3026,12 @@ static int ab8500_regulator_register(struct platform_device *pdev, } /* register regulator with framework */ - info->regulator = regulator_register(&info->desc, &config); + info->regulator = devm_regulator_register(&pdev->dev, &info->desc, + &config); if (IS_ERR(info->regulator)) { - err = PTR_ERR(info->regulator); dev_err(&pdev->dev, "failed to register regulator %s\n", info->desc.name); - /* when we fail, un-register all earlier regulators */ - while (--id >= 0) { - info = &abx500_regulator.info[id]; - regulator_unregister(info->regulator); - } - return err; + return PTR_ERR(info->regulator); } return 0; @@ -3095,9 +3058,7 @@ static int ab8500_regulator_probe(struct platform_device *pdev) { struct ab8500 *ab8500 = dev_get_drvdata(pdev->dev.parent); struct device_node *np = pdev->dev.of_node; - struct ab8500_platform_data *ppdata; - struct ab8500_regulator_platform_data *pdata; - int i, err; + int err; if (!ab8500) { dev_err(&pdev->dev, "null mfd parent\n"); @@ -3106,83 +3067,20 @@ static int ab8500_regulator_probe(struct platform_device *pdev) abx500_get_regulator_info(ab8500); - if (np) { - err = of_regulator_match(&pdev->dev, np, - abx500_regulator.match, - abx500_regulator.match_size); - if (err < 0) { - dev_err(&pdev->dev, - "Error parsing regulator init data: %d\n", err); - return err; - } - - err = ab8500_regulator_of_probe(pdev, np); - return err; - } - - ppdata = dev_get_platdata(ab8500->dev); - if (!ppdata) { - dev_err(&pdev->dev, "null parent pdata\n"); - return -EINVAL; - } - - pdata = ppdata->regulator; - if (!pdata) { - dev_err(&pdev->dev, "null pdata\n"); - return -EINVAL; - } - - /* make sure the platform data has the correct size */ - if (pdata->num_regulator != abx500_regulator.info_size) { - dev_err(&pdev->dev, "Configuration error: size mismatch.\n"); - return -EINVAL; - } - - /* initialize debug (initial state is recorded with this call) */ - err = ab8500_regulator_debug_init(pdev); - if (err) + err = of_regulator_match(&pdev->dev, np, + abx500_regulator.match, + abx500_regulator.match_size); + if (err < 0) { + dev_err(&pdev->dev, + "Error parsing regulator init data: %d\n", err); return err; - - /* initialize registers */ - for (i = 0; i < pdata->num_reg_init; i++) { - int id, mask, value; - - id = pdata->reg_init[i].id; - mask = pdata->reg_init[i].mask; - value = pdata->reg_init[i].value; - - /* check for configuration errors */ - BUG_ON(id >= abx500_regulator.init_size); - - err = ab8500_regulator_init_registers(pdev, id, mask, value); - if (err < 0) - return err; } - - /* register all regulators */ - for (i = 0; i < abx500_regulator.info_size; i++) { - err = ab8500_regulator_register(pdev, &pdata->regulator[i], - i, NULL); - if (err < 0) - return err; - } - - return 0; + return ab8500_regulator_of_probe(pdev, np); } static int ab8500_regulator_remove(struct platform_device *pdev) { - int i, err; - - for (i = 0; i < abx500_regulator.info_size; i++) { - struct ab8500_regulator_info *info = NULL; - info = &abx500_regulator.info[i]; - - dev_vdbg(rdev_get_dev(info->regulator), - "%s-remove\n", info->desc.name); - - regulator_unregister(info->regulator); - } + int err; /* remove regulator debug */ err = ab8500_regulator_debug_exit(pdev); diff --git a/drivers/regulator/act8865-regulator.c b/drivers/regulator/act8865-regulator.c new file mode 100644 index 000000000000..084cc0819a52 --- /dev/null +++ b/drivers/regulator/act8865-regulator.c @@ -0,0 +1,349 @@ +/* + * act8865-regulator.c - Voltage regulation for the active-semi ACT8865 + * http://www.active-semi.com/sheets/ACT8865_Datasheet.pdf + * + * Copyright (C) 2013 Atmel Corporation + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include <linux/module.h> +#include <linux/init.h> +#include <linux/i2c.h> +#include <linux/err.h> +#include <linux/platform_device.h> +#include <linux/regulator/driver.h> +#include <linux/regulator/act8865.h> +#include <linux/of.h> +#include <linux/of_device.h> +#include <linux/regulator/of_regulator.h> +#include <linux/regmap.h> + +/* + * ACT8865 Global Register Map. + */ +#define ACT8865_SYS_MODE 0x00 +#define ACT8865_SYS_CTRL 0x01 +#define ACT8865_DCDC1_VSET1 0x20 +#define ACT8865_DCDC1_VSET2 0x21 +#define ACT8865_DCDC1_CTRL 0x22 +#define ACT8865_DCDC2_VSET1 0x30 +#define ACT8865_DCDC2_VSET2 0x31 +#define ACT8865_DCDC2_CTRL 0x32 +#define ACT8865_DCDC3_VSET1 0x40 +#define ACT8865_DCDC3_VSET2 0x41 +#define ACT8865_DCDC3_CTRL 0x42 +#define ACT8865_LDO1_VSET 0x50 +#define ACT8865_LDO1_CTRL 0x51 +#define ACT8865_LDO2_VSET 0x54 +#define ACT8865_LDO2_CTRL 0x55 +#define ACT8865_LDO3_VSET 0x60 +#define ACT8865_LDO3_CTRL 0x61 +#define ACT8865_LDO4_VSET 0x64 +#define ACT8865_LDO4_CTRL 0x65 + +/* + * Field Definitions. + */ +#define ACT8865_ENA 0x80 /* ON - [7] */ +#define ACT8865_VSEL_MASK 0x3F /* VSET - [5:0] */ + +/* + * ACT8865 voltage number + */ +#define ACT8865_VOLTAGE_NUM 64 + +struct act8865 { + struct regulator_dev *rdev[ACT8865_REG_NUM]; + struct regmap *regmap; +}; + +static const struct regmap_config act8865_regmap_config = { + .reg_bits = 8, + .val_bits = 8, +}; + +static const struct regulator_linear_range act8865_volatge_ranges[] = { + REGULATOR_LINEAR_RANGE(600000, 0, 23, 25000), + REGULATOR_LINEAR_RANGE(1200000, 24, 47, 50000), + REGULATOR_LINEAR_RANGE(2400000, 48, 63, 100000), +}; + +static struct regulator_ops act8865_ops = { + .list_voltage = regulator_list_voltage_linear_range, + .map_voltage = regulator_map_voltage_linear_range, + .get_voltage_sel = regulator_get_voltage_sel_regmap, + .set_voltage_sel = regulator_set_voltage_sel_regmap, + .enable = regulator_enable_regmap, + .disable = regulator_disable_regmap, + .is_enabled = regulator_is_enabled_regmap, +}; + +static const struct regulator_desc act8865_reg[] = { + { + .name = "DCDC_REG1", + .id = ACT8865_ID_DCDC1, + .ops = &act8865_ops, + .type = REGULATOR_VOLTAGE, + .n_voltages = ACT8865_VOLTAGE_NUM, + .linear_ranges = act8865_volatge_ranges, + .n_linear_ranges = ARRAY_SIZE(act8865_volatge_ranges), + .vsel_reg = ACT8865_DCDC1_VSET1, + .vsel_mask = ACT8865_VSEL_MASK, + .enable_reg = ACT8865_DCDC1_CTRL, + .enable_mask = ACT8865_ENA, + .owner = THIS_MODULE, + }, + { + .name = "DCDC_REG2", + .id = ACT8865_ID_DCDC2, + .ops = &act8865_ops, + .type = REGULATOR_VOLTAGE, + .n_voltages = ACT8865_VOLTAGE_NUM, + .linear_ranges = act8865_volatge_ranges, + .n_linear_ranges = ARRAY_SIZE(act8865_volatge_ranges), + .vsel_reg = ACT8865_DCDC2_VSET1, + .vsel_mask = ACT8865_VSEL_MASK, + .enable_reg = ACT8865_DCDC2_CTRL, + .enable_mask = ACT8865_ENA, + .owner = THIS_MODULE, + }, + { + .name = "DCDC_REG3", + .id = ACT8865_ID_DCDC3, + .ops = &act8865_ops, + .type = REGULATOR_VOLTAGE, + .n_voltages = ACT8865_VOLTAGE_NUM, + .linear_ranges = act8865_volatge_ranges, + .n_linear_ranges = ARRAY_SIZE(act8865_volatge_ranges), + .vsel_reg = ACT8865_DCDC3_VSET1, + .vsel_mask = ACT8865_VSEL_MASK, + .enable_reg = ACT8865_DCDC3_CTRL, + .enable_mask = ACT8865_ENA, + .owner = THIS_MODULE, + }, + { + .name = "LDO_REG1", + .id = ACT8865_ID_LDO1, + .ops = &act8865_ops, + .type = REGULATOR_VOLTAGE, + .n_voltages = ACT8865_VOLTAGE_NUM, + .linear_ranges = act8865_volatge_ranges, + .n_linear_ranges = ARRAY_SIZE(act8865_volatge_ranges), + .vsel_reg = ACT8865_LDO1_VSET, + .vsel_mask = ACT8865_VSEL_MASK, + .enable_reg = ACT8865_LDO1_CTRL, + .enable_mask = ACT8865_ENA, + .owner = THIS_MODULE, + }, + { + .name = "LDO_REG2", + .id = ACT8865_ID_LDO2, + .ops = &act8865_ops, + .type = REGULATOR_VOLTAGE, + .n_voltages = ACT8865_VOLTAGE_NUM, + .linear_ranges = act8865_volatge_ranges, + .n_linear_ranges = ARRAY_SIZE(act8865_volatge_ranges), + .vsel_reg = ACT8865_LDO2_VSET, + .vsel_mask = ACT8865_VSEL_MASK, + .enable_reg = ACT8865_LDO2_CTRL, + .enable_mask = ACT8865_ENA, + .owner = THIS_MODULE, + }, + { + .name = "LDO_REG3", + .id = ACT8865_ID_LDO3, + .ops = &act8865_ops, + .type = REGULATOR_VOLTAGE, + .n_voltages = ACT8865_VOLTAGE_NUM, + .linear_ranges = act8865_volatge_ranges, + .n_linear_ranges = ARRAY_SIZE(act8865_volatge_ranges), + .vsel_reg = ACT8865_LDO3_VSET, + .vsel_mask = ACT8865_VSEL_MASK, + .enable_reg = ACT8865_LDO3_CTRL, + .enable_mask = ACT8865_ENA, + .owner = THIS_MODULE, + }, + { + .name = "LDO_REG4", + .id = ACT8865_ID_LDO4, + .ops = &act8865_ops, + .type = REGULATOR_VOLTAGE, + .n_voltages = ACT8865_VOLTAGE_NUM, + .linear_ranges = act8865_volatge_ranges, + .n_linear_ranges = ARRAY_SIZE(act8865_volatge_ranges), + .vsel_reg = ACT8865_LDO4_VSET, + .vsel_mask = ACT8865_VSEL_MASK, + .enable_reg = ACT8865_LDO4_CTRL, + .enable_mask = ACT8865_ENA, + .owner = THIS_MODULE, + }, +}; + +#ifdef CONFIG_OF +static const struct of_device_id act8865_dt_ids[] = { + { .compatible = "active-semi,act8865" }, + { } +}; +MODULE_DEVICE_TABLE(of, act8865_dt_ids); + +static struct of_regulator_match act8865_matches[] = { + [ACT8865_ID_DCDC1] = { .name = "DCDC_REG1"}, + [ACT8865_ID_DCDC2] = { .name = "DCDC_REG2"}, + [ACT8865_ID_DCDC3] = { .name = "DCDC_REG3"}, + [ACT8865_ID_LDO1] = { .name = "LDO_REG1"}, + [ACT8865_ID_LDO2] = { .name = "LDO_REG2"}, + [ACT8865_ID_LDO3] = { .name = "LDO_REG3"}, + [ACT8865_ID_LDO4] = { .name = "LDO_REG4"}, +}; + +static int act8865_pdata_from_dt(struct device *dev, + struct device_node **of_node, + struct act8865_platform_data *pdata) +{ + int matched, i; + struct device_node *np; + struct act8865_regulator_data *regulator; + + np = of_find_node_by_name(dev->of_node, "regulators"); + if (!np) { + dev_err(dev, "missing 'regulators' subnode in DT\n"); + return -EINVAL; + } + + matched = of_regulator_match(dev, np, + act8865_matches, ARRAY_SIZE(act8865_matches)); + if (matched <= 0) + return matched; + + pdata->regulators = devm_kzalloc(dev, + sizeof(struct act8865_regulator_data) * + ARRAY_SIZE(act8865_matches), GFP_KERNEL); + if (!pdata->regulators) { + dev_err(dev, "%s: failed to allocate act8865 registor\n", + __func__); + return -ENOMEM; + } + + pdata->num_regulators = matched; + regulator = pdata->regulators; + + for (i = 0; i < ARRAY_SIZE(act8865_matches); i++) { + regulator->id = i; + regulator->name = act8865_matches[i].name; + regulator->platform_data = act8865_matches[i].init_data; + of_node[i] = act8865_matches[i].of_node; + regulator++; + } + + return 0; +} +#else +static inline int act8865_pdata_from_dt(struct device *dev, + struct device_node **of_node, + struct act8865_platform_data *pdata) +{ + return 0; +} +#endif + +static int act8865_pmic_probe(struct i2c_client *client, + const struct i2c_device_id *i2c_id) +{ + struct regulator_dev **rdev; + struct device *dev = &client->dev; + struct act8865_platform_data *pdata = dev_get_platdata(dev); + struct regulator_config config = { }; + struct act8865 *act8865; + struct device_node *of_node[ACT8865_REG_NUM]; + int i, id; + int ret = -EINVAL; + int error; + + if (dev->of_node && !pdata) { + const struct of_device_id *id; + struct act8865_platform_data pdata_of; + + id = of_match_device(of_match_ptr(act8865_dt_ids), dev); + if (!id) + return -ENODEV; + + ret = act8865_pdata_from_dt(dev, of_node, &pdata_of); + if (ret < 0) + return ret; + + pdata = &pdata_of; + } + + if (pdata->num_regulators > ACT8865_REG_NUM) { + dev_err(dev, "Too many regulators found!\n"); + return -EINVAL; + } + + act8865 = devm_kzalloc(dev, sizeof(struct act8865), GFP_KERNEL); + if (!act8865) + return -ENOMEM; + + rdev = act8865->rdev; + + act8865->regmap = devm_regmap_init_i2c(client, &act8865_regmap_config); + if (IS_ERR(act8865->regmap)) { + error = PTR_ERR(act8865->regmap); + dev_err(&client->dev, "Failed to allocate register map: %d\n", + error); + return error; + } + + /* Finally register devices */ + for (i = 0; i < ACT8865_REG_NUM; i++) { + + id = pdata->regulators[i].id; + + config.dev = dev; + config.init_data = pdata->regulators[i].platform_data; + config.of_node = of_node[i]; + config.driver_data = act8865; + config.regmap = act8865->regmap; + + rdev[i] = devm_regulator_register(&client->dev, + &act8865_reg[i], &config); + if (IS_ERR(rdev[i])) { + dev_err(dev, "failed to register %s\n", + act8865_reg[id].name); + return PTR_ERR(rdev[i]); + } + } + + i2c_set_clientdata(client, act8865); + + return 0; +} + +static const struct i2c_device_id act8865_ids[] = { + { "act8865", 0 }, + { }, +}; +MODULE_DEVICE_TABLE(i2c, act8865_ids); + +static struct i2c_driver act8865_pmic_driver = { + .driver = { + .name = "act8865", + .owner = THIS_MODULE, + }, + .probe = act8865_pmic_probe, + .id_table = act8865_ids, +}; + +module_i2c_driver(act8865_pmic_driver); + +MODULE_DESCRIPTION("active-semi act8865 voltage regulator driver"); +MODULE_AUTHOR("Wenyou Yang <wenyou.yang@atmel.com>"); +MODULE_LICENSE("GPL v2"); diff --git a/drivers/regulator/arizona-micsupp.c b/drivers/regulator/arizona-micsupp.c index 724706a97dc4..034ece707083 100644 --- a/drivers/regulator/arizona-micsupp.c +++ b/drivers/regulator/arizona-micsupp.c @@ -28,8 +28,6 @@ #include <linux/mfd/arizona/pdata.h> #include <linux/mfd/arizona/registers.h> -#define ARIZONA_MICSUPP_MAX_SELECTOR 0x1f - struct arizona_micsupp { struct regulator_dev *regulator; struct arizona *arizona; @@ -40,42 +38,6 @@ struct arizona_micsupp { struct work_struct check_cp_work; }; -static int arizona_micsupp_list_voltage(struct regulator_dev *rdev, - unsigned int selector) -{ - if (selector > ARIZONA_MICSUPP_MAX_SELECTOR) - return -EINVAL; - - if (selector == ARIZONA_MICSUPP_MAX_SELECTOR) - return 3300000; - else - return (selector * 50000) + 1700000; -} - -static int arizona_micsupp_map_voltage(struct regulator_dev *rdev, - int min_uV, int max_uV) -{ - unsigned int voltage; - int selector; - - if (min_uV < 1700000) - min_uV = 1700000; - - if (min_uV > 3200000) - selector = ARIZONA_MICSUPP_MAX_SELECTOR; - else - selector = DIV_ROUND_UP(min_uV - 1700000, 50000); - - if (selector < 0) - return -EINVAL; - - voltage = arizona_micsupp_list_voltage(rdev, selector); - if (voltage < min_uV || voltage > max_uV) - return -EINVAL; - - return selector; -} - static void arizona_micsupp_check_cp(struct work_struct *work) { struct arizona_micsupp *micsupp = @@ -145,8 +107,8 @@ static struct regulator_ops arizona_micsupp_ops = { .disable = arizona_micsupp_disable, .is_enabled = regulator_is_enabled_regmap, - .list_voltage = arizona_micsupp_list_voltage, - .map_voltage = arizona_micsupp_map_voltage, + .list_voltage = regulator_list_voltage_linear_range, + .map_voltage = regulator_map_voltage_linear_range, .get_voltage_sel = regulator_get_voltage_sel_regmap, .set_voltage_sel = regulator_set_voltage_sel_regmap, @@ -155,11 +117,43 @@ static struct regulator_ops arizona_micsupp_ops = { .set_bypass = arizona_micsupp_set_bypass, }; +static const struct regulator_linear_range arizona_micsupp_ranges[] = { + REGULATOR_LINEAR_RANGE(1700000, 0, 0x1e, 50000), + REGULATOR_LINEAR_RANGE(3300000, 0x1f, 0x1f, 0), +}; + static const struct regulator_desc arizona_micsupp = { .name = "MICVDD", .supply_name = "CPVDD", .type = REGULATOR_VOLTAGE, - .n_voltages = ARIZONA_MICSUPP_MAX_SELECTOR + 1, + .n_voltages = 32, + .ops = &arizona_micsupp_ops, + + .vsel_reg = ARIZONA_LDO2_CONTROL_1, + .vsel_mask = ARIZONA_LDO2_VSEL_MASK, + .enable_reg = ARIZONA_MIC_CHARGE_PUMP_1, + .enable_mask = ARIZONA_CPMIC_ENA, + .bypass_reg = ARIZONA_MIC_CHARGE_PUMP_1, + .bypass_mask = ARIZONA_CPMIC_BYPASS, + + .linear_ranges = arizona_micsupp_ranges, + .n_linear_ranges = ARRAY_SIZE(arizona_micsupp_ranges), + + .enable_time = 3000, + + .owner = THIS_MODULE, +}; + +static const struct regulator_linear_range arizona_micsupp_ext_ranges[] = { + REGULATOR_LINEAR_RANGE(900000, 0, 0x14, 25000), + REGULATOR_LINEAR_RANGE(1500000, 0x15, 0x27, 100000), +}; + +static const struct regulator_desc arizona_micsupp_ext = { + .name = "MICVDD", + .supply_name = "CPVDD", + .type = REGULATOR_VOLTAGE, + .n_voltages = 40, .ops = &arizona_micsupp_ops, .vsel_reg = ARIZONA_LDO2_CONTROL_1, @@ -169,6 +163,9 @@ static const struct regulator_desc arizona_micsupp = { .bypass_reg = ARIZONA_MIC_CHARGE_PUMP_1, .bypass_mask = ARIZONA_CPMIC_BYPASS, + .linear_ranges = arizona_micsupp_ext_ranges, + .n_linear_ranges = ARRAY_SIZE(arizona_micsupp_ext_ranges), + .enable_time = 3000, .owner = THIS_MODULE, @@ -186,9 +183,22 @@ static const struct regulator_init_data arizona_micsupp_default = { .num_consumer_supplies = 1, }; +static const struct regulator_init_data arizona_micsupp_ext_default = { + .constraints = { + .valid_ops_mask = REGULATOR_CHANGE_STATUS | + REGULATOR_CHANGE_VOLTAGE | + REGULATOR_CHANGE_BYPASS, + .min_uV = 900000, + .max_uV = 3300000, + }, + + .num_consumer_supplies = 1, +}; + static int arizona_micsupp_probe(struct platform_device *pdev) { struct arizona *arizona = dev_get_drvdata(pdev->dev.parent); + const struct regulator_desc *desc; struct regulator_config config = { }; struct arizona_micsupp *micsupp; int ret; @@ -207,7 +217,17 @@ static int arizona_micsupp_probe(struct platform_device *pdev) * default init_data for it. This will be overridden with * platform data if provided. */ - micsupp->init_data = arizona_micsupp_default; + switch (arizona->type) { + case WM5110: + desc = &arizona_micsupp_ext; + micsupp->init_data = arizona_micsupp_ext_default; + break; + default: + desc = &arizona_micsupp; + micsupp->init_data = arizona_micsupp_default; + break; + } + micsupp->init_data.consumer_supplies = &micsupp->supply; micsupp->supply.supply = "MICVDD"; micsupp->supply.dev_name = dev_name(arizona->dev); @@ -226,7 +246,7 @@ static int arizona_micsupp_probe(struct platform_device *pdev) ARIZONA_CPMIC_BYPASS, 0); micsupp->regulator = devm_regulator_register(&pdev->dev, - &arizona_micsupp, + desc, &config); if (IS_ERR(micsupp->regulator)) { ret = PTR_ERR(micsupp->regulator); diff --git a/drivers/regulator/as3722-regulator.c b/drivers/regulator/as3722-regulator.c index 5917fe3dc983..8b17d786cb71 100644 --- a/drivers/regulator/as3722-regulator.c +++ b/drivers/regulator/as3722-regulator.c @@ -99,7 +99,6 @@ static const struct as3722_register_mapping as3722_reg_lookup[] = { .sleep_ctrl_mask = AS3722_SD0_EXT_ENABLE_MASK, .control_reg = AS3722_SD0_CONTROL_REG, .mode_mask = AS3722_SD0_MODE_FAST, - .n_voltages = AS3722_SD0_VSEL_MAX + 1, }, { .regulator_id = AS3722_REGULATOR_ID_SD1, @@ -112,7 +111,6 @@ static const struct as3722_register_mapping as3722_reg_lookup[] = { .sleep_ctrl_mask = AS3722_SD1_EXT_ENABLE_MASK, .control_reg = AS3722_SD1_CONTROL_REG, .mode_mask = AS3722_SD1_MODE_FAST, - .n_voltages = AS3722_SD0_VSEL_MAX + 1, }, { .regulator_id = AS3722_REGULATOR_ID_SD2, @@ -181,7 +179,6 @@ static const struct as3722_register_mapping as3722_reg_lookup[] = { .sleep_ctrl_mask = AS3722_SD6_EXT_ENABLE_MASK, .control_reg = AS3722_SD6_CONTROL_REG, .mode_mask = AS3722_SD6_MODE_FAST, - .n_voltages = AS3722_SD0_VSEL_MAX + 1, }, { .regulator_id = AS3722_REGULATOR_ID_LDO0, @@ -590,11 +587,27 @@ static int as3722_sd016_set_current_limit(struct regulator_dev *rdev, default: return -EINVAL; } + ret <<= ffs(mask) - 1; val = ret & mask; - val <<= ffs(mask) - 1; return as3722_update_bits(as3722, reg, mask, val); } +static bool as3722_sd0_is_low_voltage(struct as3722_regulators *as3722_regs) +{ + int err; + unsigned val; + + err = as3722_read(as3722_regs->as3722, AS3722_FUSE7_REG, &val); + if (err < 0) { + dev_err(as3722_regs->dev, "Reg 0x%02x read failed: %d\n", + AS3722_FUSE7_REG, err); + return false; + } + if (val & AS3722_FUSE7_SD0_LOW_VOLTAGE) + return true; + return false; +} + static const struct regulator_linear_range as3722_sd2345_ranges[] = { REGULATOR_LINEAR_RANGE(612500, 0x01, 0x40, 12500), REGULATOR_LINEAR_RANGE(1425000, 0x41, 0x70, 25000), @@ -820,9 +833,19 @@ static int as3722_regulator_probe(struct platform_device *pdev) ops = &as3722_sd016_extcntrl_ops; else ops = &as3722_sd016_ops; - as3722_regs->desc[id].min_uV = 610000; + if (id == AS3722_REGULATOR_ID_SD0 && + as3722_sd0_is_low_voltage(as3722_regs)) { + as3722_regs->desc[id].n_voltages = + AS3722_SD0_VSEL_LOW_VOL_MAX + 1; + as3722_regs->desc[id].min_uV = 410000; + } else { + as3722_regs->desc[id].n_voltages = + AS3722_SD0_VSEL_MAX + 1, + as3722_regs->desc[id].min_uV = 610000; + } as3722_regs->desc[id].uV_step = 10000; as3722_regs->desc[id].linear_min_sel = 1; + as3722_regs->desc[id].enable_time = 600; break; case AS3722_REGULATOR_ID_SD2: case AS3722_REGULATOR_ID_SD3: @@ -842,9 +865,6 @@ static int as3722_regulator_probe(struct platform_device *pdev) ops = &as3722_ldo_extcntrl_ops; else ops = &as3722_ldo_ops; - as3722_regs->desc[id].min_uV = 825000; - as3722_regs->desc[id].uV_step = 25000; - as3722_regs->desc[id].linear_min_sel = 1; as3722_regs->desc[id].enable_time = 500; as3722_regs->desc[id].linear_ranges = as3722_ldo_ranges; as3722_regs->desc[id].n_linear_ranges = diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 6382f0af353b..b38a6b669e8c 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -119,6 +119,11 @@ static const char *rdev_get_name(struct regulator_dev *rdev) return ""; } +static bool have_full_constraints(void) +{ + return has_full_constraints || of_have_populated_dt(); +} + /** * of_get_regulator - get a regulator device node based on supply name * @dev: Device pointer for the consumer (of regulator) device @@ -1329,9 +1334,8 @@ static struct regulator *_regulator_get(struct device *dev, const char *id, * If we have return value from dev_lookup fail, we do not expect to * succeed, so, quit with appropriate error value */ - if (ret && ret != -ENODEV) { + if (ret && ret != -ENODEV) goto out; - } if (!devname) devname = "deviceless"; @@ -1340,13 +1344,14 @@ static struct regulator *_regulator_get(struct device *dev, const char *id, * Assume that a regulator is physically present and enabled * even if it isn't hooked up and just provide a dummy. */ - if (has_full_constraints && allow_dummy) { + if (have_full_constraints() && allow_dummy) { pr_warn("%s supply %s not found, using dummy regulator\n", devname, id); rdev = dummy_regulator_rdev; goto found; - } else { + /* Don't log an error when called from regulator_get_optional() */ + } else if (!have_full_constraints() || exclusive) { dev_err(dev, "dummy supplies not allowed\n"); } @@ -2184,6 +2189,9 @@ int regulator_list_voltage(struct regulator *regulator, unsigned selector) struct regulator_ops *ops = rdev->desc->ops; int ret; + if (rdev->desc->fixed_uV && rdev->desc->n_voltages == 1 && !selector) + return rdev->desc->fixed_uV; + if (!ops->list_voltage || selector >= rdev->desc->n_voltages) return -EINVAL; @@ -2236,7 +2244,7 @@ int regulator_is_supported_voltage(struct regulator *regulator, if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_VOLTAGE)) { ret = regulator_get_voltage(regulator); if (ret >= 0) - return (min_uV <= ret && ret <= max_uV); + return min_uV <= ret && ret <= max_uV; else return ret; } @@ -2408,7 +2416,7 @@ int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV) ret = regulator_check_voltage(rdev, &min_uV, &max_uV); if (ret < 0) goto out; - + /* restore original values in case of error */ old_min_uV = regulator->min_uV; old_max_uV = regulator->max_uV; @@ -2422,7 +2430,7 @@ int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV) ret = _regulator_do_set_voltage(rdev, min_uV, max_uV); if (ret < 0) goto out2; - + out: mutex_unlock(&rdev->mutex); return ret; @@ -3624,7 +3632,7 @@ int regulator_suspend_finish(void) if (error) ret = error; } else { - if (!has_full_constraints) + if (!have_full_constraints()) goto unlock; if (!ops->disable) goto unlock; @@ -3822,14 +3830,13 @@ static int __init regulator_init_complete(void) if (!enabled) goto unlock; - if (has_full_constraints) { + if (have_full_constraints()) { /* We log since this may kill the system if it * goes wrong. */ rdev_info(rdev, "disabling\n"); ret = ops->disable(rdev); - if (ret != 0) { + if (ret != 0) rdev_err(rdev, "couldn't disable: %d\n", ret); - } } else { /* The intention is that in future we will * assume that full constraints are provided diff --git a/drivers/regulator/gpio-regulator.c b/drivers/regulator/gpio-regulator.c index 04406a918c04..234960dc9607 100644 --- a/drivers/regulator/gpio-regulator.c +++ b/drivers/regulator/gpio-regulator.c @@ -139,6 +139,7 @@ of_get_gpio_regulator_config(struct device *dev, struct device_node *np) struct property *prop; const char *regtype; int proplen, gpio, i; + int ret; config = devm_kzalloc(dev, sizeof(struct gpio_regulator_config), @@ -202,7 +203,11 @@ of_get_gpio_regulator_config(struct device *dev, struct device_node *np) } config->nr_states = i; - of_property_read_string(np, "regulator-type", ®type); + ret = of_property_read_string(np, "regulator-type", ®type); + if (ret < 0) { + dev_err(dev, "Missing 'regulator-type' property\n"); + return ERR_PTR(-EINVAL); + } if (!strncmp("voltage", regtype, 7)) config->type = REGULATOR_VOLTAGE; diff --git a/drivers/regulator/pfuze100-regulator.c b/drivers/regulator/pfuze100-regulator.c index ba67b2c4e2e7..c31e0485de25 100644 --- a/drivers/regulator/pfuze100-regulator.c +++ b/drivers/regulator/pfuze100-regulator.c @@ -38,7 +38,7 @@ #define PFUZE100_DEVICEID 0x0 #define PFUZE100_REVID 0x3 -#define PFUZE100_FABID 0x3 +#define PFUZE100_FABID 0x4 #define PFUZE100_SW1ABVOL 0x20 #define PFUZE100_SW1CVOL 0x2e @@ -308,16 +308,22 @@ static int pfuze_identify(struct pfuze_chip *pfuze_chip) if (ret) return ret; - if (value & 0x0f) { - dev_warn(pfuze_chip->dev, "Illegal ID: %x\n", value); - return -ENODEV; + switch (value & 0x0f) { + /* Freescale misprogrammed 1-3% of parts prior to week 8 of 2013 as ID=8 */ + case 0x8: + dev_info(pfuze_chip->dev, "Assuming misprogrammed ID=0x8"); + case 0x0: + break; + default: + dev_warn(pfuze_chip->dev, "Illegal ID: %x\n", value); + return -ENODEV; } ret = regmap_read(pfuze_chip->regmap, PFUZE100_REVID, &value); if (ret) return ret; dev_info(pfuze_chip->dev, - "Full lay: %x, Metal lay: %x\n", + "Full layer: %x, Metal layer: %x\n", (value & 0xf0) >> 4, value & 0x0f); ret = regmap_read(pfuze_chip->regmap, PFUZE100_FABID, &value); diff --git a/drivers/regulator/s2mps11.c b/drivers/regulator/s2mps11.c index 333677d68d0e..9e61922d8230 100644 --- a/drivers/regulator/s2mps11.c +++ b/drivers/regulator/s2mps11.c @@ -438,7 +438,7 @@ common_reg: platform_set_drvdata(pdev, s2mps11); config.dev = &pdev->dev; - config.regmap = iodev->regmap; + config.regmap = iodev->regmap_pmic; config.driver_data = s2mps11; for (i = 0; i < S2MPS11_REGULATOR_MAX; i++) { if (!reg_np) { diff --git a/drivers/regulator/s5m8767.c b/drivers/regulator/s5m8767.c index cbf91e25cf7f..aeb40aad0ae7 100644 --- a/drivers/regulator/s5m8767.c +++ b/drivers/regulator/s5m8767.c @@ -925,7 +925,7 @@ static int s5m8767_pmic_probe(struct platform_device *pdev) config.dev = s5m8767->dev; config.init_data = pdata->regulators[i].initdata; config.driver_data = s5m8767; - config.regmap = iodev->regmap; + config.regmap = iodev->regmap_pmic; config.of_node = pdata->regulators[i].reg_node; rdev[i] = devm_regulator_register(&pdev->dev, ®ulators[id], |