From 71979aa3c431f0b2e00c4151f399813fceea6e0d Mon Sep 17 00:00:00 2001 From: Charles Keepax Date: Fri, 15 Nov 2013 13:13:32 +0000 Subject: regulator: arizona-micsupp: Convert to use linear ranges Signed-off-by: Charles Keepax Signed-off-by: Mark Brown --- drivers/regulator/arizona-micsupp.c | 52 ++++++++----------------------------- 1 file changed, 11 insertions(+), 41 deletions(-) (limited to 'drivers/regulator') diff --git a/drivers/regulator/arizona-micsupp.c b/drivers/regulator/arizona-micsupp.c index 724706a97dc4..3c75bf82eeb5 100644 --- a/drivers/regulator/arizona-micsupp.c +++ b/drivers/regulator/arizona-micsupp.c @@ -28,8 +28,6 @@ #include #include -#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,16 @@ 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, @@ -169,6 +136,9 @@ static const struct regulator_desc arizona_micsupp = { .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, -- cgit v1.2.3 From 34c040ce1a9d9c13121c95101164383ce516ddd6 Mon Sep 17 00:00:00 2001 From: Linus Walleij Date: Tue, 3 Dec 2013 15:08:22 +0100 Subject: regulator: ab8500: delete non-devicetree probe path The Ux500 platform has been converted to do device-tree only boots, no longer supports platform data passing, so this probe path is unused. Delete it, simplifying the driver a whole lot. Signed-off-by: Linus Walleij Acked-by: Lee Jones Signed-off-by: Mark Brown --- drivers/regulator/ab8500.c | 102 ++++----------------------------------------- 1 file changed, 8 insertions(+), 94 deletions(-) (limited to 'drivers/regulator') diff --git a/drivers/regulator/ab8500.c b/drivers/regulator/ab8500.c index 603f192e84f1..0f86695b737a 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) @@ -3095,9 +3064,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,68 +3073,15 @@ 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) -- cgit v1.2.3 From baafdc1d20a97c5c243f78981c95eadbd3b40caf Mon Sep 17 00:00:00 2001 From: Jingoo Han Date: Fri, 6 Dec 2013 16:07:09 +0900 Subject: regulator: ab8500: use devm_regulator_register() Use devm_regulator_register() to make cleanup paths simpler. Signed-off-by: Jingoo Han Acked-by: Lee Jones Signed-off-by: Mark Brown --- drivers/regulator/ab8500.c | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) (limited to 'drivers/regulator') diff --git a/drivers/regulator/ab8500.c b/drivers/regulator/ab8500.c index 0f86695b737a..c625468c7f2c 100644 --- a/drivers/regulator/ab8500.c +++ b/drivers/regulator/ab8500.c @@ -3005,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]; @@ -3027,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; @@ -3086,17 +3080,7 @@ static int ab8500_regulator_probe(struct platform_device *pdev) 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); -- cgit v1.2.3 From bc2571f4ba375101c9d0b7d46d8c241822652433 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Fri, 20 Dec 2013 10:57:49 +0800 Subject: regulator: as3722: Don't set min_uV/uV_step/linear_min_sel for linear_ranges These settings are not used when using linear_ranges and it makes the code looks confusing. Thus remove them. Signed-off-by: Axel Lin Acked-by: Laxman Dewangan Signed-off-by: Mark Brown --- drivers/regulator/as3722-regulator.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'drivers/regulator') diff --git a/drivers/regulator/as3722-regulator.c b/drivers/regulator/as3722-regulator.c index 5917fe3dc983..fdb31371a232 100644 --- a/drivers/regulator/as3722-regulator.c +++ b/drivers/regulator/as3722-regulator.c @@ -842,9 +842,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 = -- cgit v1.2.3 From 33036f48d13caaa31a568dc677cc76739f440e6e Mon Sep 17 00:00:00 2001 From: Wenyou Yang Date: Tue, 24 Dec 2013 10:34:28 +0800 Subject: regulator: act8865: add PMIC act8865 driver Signed-off-by: Wenyou Yang Signed-off-by: Mark Brown --- drivers/regulator/Kconfig | 8 + drivers/regulator/Makefile | 1 + drivers/regulator/act8865-regulator.c | 368 ++++++++++++++++++++++++++++++++++ 3 files changed, 377 insertions(+) create mode 100644 drivers/regulator/act8865-regulator.c (limited to 'drivers/regulator') 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/act8865-regulator.c b/drivers/regulator/act8865-regulator.c new file mode 100644 index 000000000000..db048f20745b --- /dev/null +++ b/drivers/regulator/act8865-regulator.c @@ -0,0 +1,368 @@ +/* + * 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* + * 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, + .set_suspend_enable = regulator_enable_regmap, + .set_suspend_disable = regulator_disable_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) * matched, + 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 < matched; i++) { + if (!act8865_matches[i].init_data) + continue; + + 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) + + sizeof(struct regulator_dev *) * ACT8865_REG_NUM, + 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 < pdata->num_regulators; 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 int act8865_pmic_remove(struct i2c_client *client) +{ + struct act8865 *act8865 = i2c_get_clientdata(client); + int i; + + for (i = 0; i < ACT8865_REG_NUM; i++) + regulator_unregister(act8865->rdev[i]); + + 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, + .remove = act8865_pmic_remove, + .id_table = act8865_ids, +}; + +module_i2c_driver(act8865_pmic_driver); + +MODULE_DESCRIPTION("active-semi act8865 voltage regulator driver"); +MODULE_AUTHOR("Wenyou Yang "); +MODULE_LICENSE("GPL v2"); -- cgit v1.2.3 From d5e17e2634a4370188e65c8839ff33911adb207b Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Tue, 24 Dec 2013 23:41:22 +0800 Subject: regulator: act8865: Remove unneeded regulator_unregister() calls This is not required because current code use devm_regulator_register() to register regulators. Signed-off-by: Axel Lin Signed-off-by: Mark Brown --- drivers/regulator/act8865-regulator.c | 12 ------------ 1 file changed, 12 deletions(-) (limited to 'drivers/regulator') diff --git a/drivers/regulator/act8865-regulator.c b/drivers/regulator/act8865-regulator.c index db048f20745b..dfae29488f1c 100644 --- a/drivers/regulator/act8865-regulator.c +++ b/drivers/regulator/act8865-regulator.c @@ -334,17 +334,6 @@ static int act8865_pmic_probe(struct i2c_client *client, return 0; } -static int act8865_pmic_remove(struct i2c_client *client) -{ - struct act8865 *act8865 = i2c_get_clientdata(client); - int i; - - for (i = 0; i < ACT8865_REG_NUM; i++) - regulator_unregister(act8865->rdev[i]); - - return 0; -} - static const struct i2c_device_id act8865_ids[] = { { "act8865", 0 }, { }, @@ -357,7 +346,6 @@ static struct i2c_driver act8865_pmic_driver = { .owner = THIS_MODULE, }, .probe = act8865_pmic_probe, - .remove = act8865_pmic_remove, .id_table = act8865_ids, }; -- cgit v1.2.3 From 7da98aafa2bee3583d675235c6113a57b4f20697 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Wed, 25 Dec 2013 12:37:58 +0800 Subject: regulator: act8865: Remove set_suspend_[en|dis]able implementation There is no suspend enable/disable settings mentioned in datasheet, so just don't implement .set_suspend_[en|dis]able callbacks. Signed-off-by: Axel Lin Signed-off-by: Mark Brown --- drivers/regulator/act8865-regulator.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'drivers/regulator') diff --git a/drivers/regulator/act8865-regulator.c b/drivers/regulator/act8865-regulator.c index dfae29488f1c..e7dbdc046683 100644 --- a/drivers/regulator/act8865-regulator.c +++ b/drivers/regulator/act8865-regulator.c @@ -85,8 +85,6 @@ static struct regulator_ops act8865_ops = { .enable = regulator_enable_regmap, .disable = regulator_disable_regmap, .is_enabled = regulator_is_enabled_regmap, - .set_suspend_enable = regulator_enable_regmap, - .set_suspend_disable = regulator_disable_regmap, }; static const struct regulator_desc act8865_reg[] = { -- cgit v1.2.3 From f1de2c2f2749ba42b87a49ae57deb346301dec02 Mon Sep 17 00:00:00 2001 From: Wenyou Yang Date: Thu, 26 Dec 2013 14:52:43 +0800 Subject: regulator: act8865: fix incorrect devm_kzalloc for act8865 Which cause to allocate more needless memory. Signed-off-by: Wenyou Yang Signed-off-by: Mark Brown --- drivers/regulator/act8865-regulator.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'drivers/regulator') diff --git a/drivers/regulator/act8865-regulator.c b/drivers/regulator/act8865-regulator.c index e7dbdc046683..f816ad866a43 100644 --- a/drivers/regulator/act8865-regulator.c +++ b/drivers/regulator/act8865-regulator.c @@ -291,9 +291,7 @@ static int act8865_pmic_probe(struct i2c_client *client, return -EINVAL; } - act8865 = devm_kzalloc(dev, sizeof(struct act8865) + - sizeof(struct regulator_dev *) * ACT8865_REG_NUM, - GFP_KERNEL); + act8865 = devm_kzalloc(dev, sizeof(struct act8865), GFP_KERNEL); if (!act8865) return -ENOMEM; -- cgit v1.2.3 From 89705b9e35026ad75a8ba940d641aa2be7a16611 Mon Sep 17 00:00:00 2001 From: Fabio Estevam Date: Tue, 31 Dec 2013 10:56:00 -0200 Subject: regulator: anatop-regulator: Add MODULE_ALIAS() Provide a MODULE_ALIAS() entry to the driver. Signed-off-by: Fabio Estevam Signed-off-by: Mark Brown --- drivers/regulator/anatop-regulator.c | 1 + 1 file changed, 1 insertion(+) (limited to 'drivers/regulator') diff --git a/drivers/regulator/anatop-regulator.c b/drivers/regulator/anatop-regulator.c index c734d0980826..a0041447ef00 100644 --- a/drivers/regulator/anatop-regulator.c +++ b/drivers/regulator/anatop-regulator.c @@ -259,3 +259,4 @@ MODULE_AUTHOR("Nancy Chen "); MODULE_AUTHOR("Ying-Chun Liu (PaulLiu) "); MODULE_DESCRIPTION("ANATOP Regulator driver"); MODULE_LICENSE("GPL v2"); +MODULE_ALIAS("platform:anatop_regulator"); -- cgit v1.2.3 From d04b755273683ed31043563b8a3a2716bd8aa6a9 Mon Sep 17 00:00:00 2001 From: Wenyou Yang Date: Tue, 31 Dec 2013 09:27:52 +0800 Subject: regulator: act8865: register all regulators regardless of how many are used As Mark pointed out, the driver should register all regulators regardless of how many are used in the system in order to aid diagnostics. But in the previous patch, only register the regulators that are used. Signed-off-by: Wenyou Yang Signed-off-by: Mark Brown --- drivers/regulator/act8865-regulator.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'drivers/regulator') diff --git a/drivers/regulator/act8865-regulator.c b/drivers/regulator/act8865-regulator.c index f816ad866a43..5e3e1d270328 100644 --- a/drivers/regulator/act8865-regulator.c +++ b/drivers/regulator/act8865-regulator.c @@ -225,8 +225,8 @@ static int act8865_pdata_from_dt(struct device *dev, return matched; pdata->regulators = devm_kzalloc(dev, - sizeof(struct act8865_regulator_data) * matched, - GFP_KERNEL); + 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__); @@ -236,10 +236,7 @@ static int act8865_pdata_from_dt(struct device *dev, pdata->num_regulators = matched; regulator = pdata->regulators; - for (i = 0; i < matched; i++) { - if (!act8865_matches[i].init_data) - continue; - + 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; @@ -306,7 +303,7 @@ static int act8865_pmic_probe(struct i2c_client *client, } /* Finally register devices */ - for (i = 0; i < pdata->num_regulators; i++) { + for (i = 0; i < ARRAY_SIZE(act8865_matches); i++) { id = pdata->regulators[i].id; -- cgit v1.2.3 From a8659ba461a13ef1a8a28968b3bd10220684be02 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Mon, 6 Jan 2014 15:42:53 +0800 Subject: regulator: act8865: Fix build error when !OF Fix below build error when !OF: CC [M] drivers/regulator/act8865-regulator.o drivers/regulator/act8865-regulator.c: In function 'act8865_pmic_probe': drivers/regulator/act8865-regulator.c:306:18: error: 'act8865_matches' undeclared (first use in this function) drivers/regulator/act8865-regulator.c:306:18: note: each undeclared identifier is reported only once for each function it appears in drivers/regulator/act8865-regulator.c:306:18: error: negative width in bit-field '' make[2]: *** [drivers/regulator/act8865-regulator.o] Error 1 make[1]: *** [drivers/regulator] Error 2 make: *** [drivers] Error 2 Reported-by: Stephen Rothwell Signed-off-by: Axel Lin Signed-off-by: Mark Brown --- drivers/regulator/act8865-regulator.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/regulator') diff --git a/drivers/regulator/act8865-regulator.c b/drivers/regulator/act8865-regulator.c index 5e3e1d270328..084cc0819a52 100644 --- a/drivers/regulator/act8865-regulator.c +++ b/drivers/regulator/act8865-regulator.c @@ -303,7 +303,7 @@ static int act8865_pmic_probe(struct i2c_client *client, } /* Finally register devices */ - for (i = 0; i < ARRAY_SIZE(act8865_matches); i++) { + for (i = 0; i < ACT8865_REG_NUM; i++) { id = pdata->regulators[i].id; -- cgit v1.2.3 From f2b269b83de35a022a8df5d0133f64021f08592c Mon Sep 17 00:00:00 2001 From: Fabio Estevam Date: Mon, 6 Jan 2014 10:13:15 -0200 Subject: regulator: anatop-regulator: Remove unneeded kstrdup() We can simply pass the regulator name via of_get_property() instead of making a copy via kstrdup(). This leads to some code simplification. Suggested-by: Dmitry Torokhov Signed-off-by: Fabio Estevam Signed-off-by: Mark Brown --- drivers/regulator/anatop-regulator.c | 34 ++++++++-------------------------- 1 file changed, 8 insertions(+), 26 deletions(-) (limited to 'drivers/regulator') diff --git a/drivers/regulator/anatop-regulator.c b/drivers/regulator/anatop-regulator.c index a0041447ef00..3d4997aede1d 100644 --- a/drivers/regulator/anatop-regulator.c +++ b/drivers/regulator/anatop-regulator.c @@ -122,8 +122,7 @@ static int anatop_regulator_probe(struct platform_device *pdev) if (!sreg) return -ENOMEM; sreg->initdata = initdata; - sreg->name = kstrdup(of_get_property(np, "regulator-name", NULL), - GFP_KERNEL); + sreg->name = of_get_property(np, "regulator-name", NULL); rdesc = &sreg->rdesc; memset(rdesc, 0, sizeof(*rdesc)); rdesc->name = sreg->name; @@ -143,37 +142,37 @@ static int anatop_regulator_probe(struct platform_device *pdev) &sreg->control_reg); if (ret) { dev_err(dev, "no anatop-reg-offset property set\n"); - goto anatop_probe_end; + return ret; } ret = of_property_read_u32(np, "anatop-vol-bit-width", &sreg->vol_bit_width); if (ret) { dev_err(dev, "no anatop-vol-bit-width property set\n"); - goto anatop_probe_end; + return ret; } ret = of_property_read_u32(np, "anatop-vol-bit-shift", &sreg->vol_bit_shift); if (ret) { dev_err(dev, "no anatop-vol-bit-shift property set\n"); - goto anatop_probe_end; + return ret; } ret = of_property_read_u32(np, "anatop-min-bit-val", &sreg->min_bit_val); if (ret) { dev_err(dev, "no anatop-min-bit-val property set\n"); - goto anatop_probe_end; + return ret; } ret = of_property_read_u32(np, "anatop-min-voltage", &sreg->min_voltage); if (ret) { dev_err(dev, "no anatop-min-voltage property set\n"); - goto anatop_probe_end; + return ret; } ret = of_property_read_u32(np, "anatop-max-voltage", &sreg->max_voltage); if (ret) { dev_err(dev, "no anatop-max-voltage property set\n"); - goto anatop_probe_end; + return ret; } /* read LDO ramp up setting, only for core reg */ @@ -204,27 +203,11 @@ static int anatop_regulator_probe(struct platform_device *pdev) if (IS_ERR(rdev)) { dev_err(dev, "failed to register %s\n", rdesc->name); - ret = PTR_ERR(rdev); - goto anatop_probe_end; + return PTR_ERR(rdev); } platform_set_drvdata(pdev, rdev); -anatop_probe_end: - if (ret) - kfree(sreg->name); - - return ret; -} - -static int anatop_regulator_remove(struct platform_device *pdev) -{ - struct regulator_dev *rdev = platform_get_drvdata(pdev); - struct anatop_regulator *sreg = rdev_get_drvdata(rdev); - const char *name = sreg->name; - - kfree(name); - return 0; } @@ -240,7 +223,6 @@ static struct platform_driver anatop_regulator_driver = { .of_match_table = of_anatop_regulator_match_tbl, }, .probe = anatop_regulator_probe, - .remove = anatop_regulator_remove, }; static int __init anatop_regulator_init(void) -- cgit v1.2.3 From 762a8ee808972354ce4bca988309aa7fb63ed5ae Mon Sep 17 00:00:00 2001 From: Andrew Bresticker Date: Thu, 26 Dec 2013 13:48:46 -0800 Subject: regulator: as3722: detect SD0 low-voltage mode SD0 may operate in low-voltage mode, with a minimum of 0.41V and a maximum of 1.5V. This is indicated by bit 4 of FUSE7. Signed-off-by: Andrew Bresticker Signed-off-by: Vince Hsu broonie.e6264@m.evernote.com Signed-off-by: Mark Brown --- drivers/regulator/as3722-regulator.c | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'drivers/regulator') diff --git a/drivers/regulator/as3722-regulator.c b/drivers/regulator/as3722-regulator.c index fdb31371a232..3d7fbc21181d 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, @@ -595,6 +592,22 @@ static int as3722_sd016_set_current_limit(struct regulator_dev *rdev, 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,7 +833,16 @@ 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; break; -- cgit v1.2.3 From fb04f1b0c0731467190d7953cf7cf1105698a666 Mon Sep 17 00:00:00 2001 From: Vince Hsu Date: Thu, 26 Dec 2013 13:48:47 -0800 Subject: regulator: as3722: set enable time for SD0/1/6 Add an enable time of 600us for SD0/1/6 to ensure that we have enough setup time for the power rail. Signed-off-by: Vince Hsu Signed-off-by: Andrew Bresticker Signed-off-by: Mark Brown --- drivers/regulator/as3722-regulator.c | 1 + 1 file changed, 1 insertion(+) (limited to 'drivers/regulator') diff --git a/drivers/regulator/as3722-regulator.c b/drivers/regulator/as3722-regulator.c index 3d7fbc21181d..5c84ff4c38a2 100644 --- a/drivers/regulator/as3722-regulator.c +++ b/drivers/regulator/as3722-regulator.c @@ -845,6 +845,7 @@ static int as3722_regulator_probe(struct platform_device *pdev) } 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: -- cgit v1.2.3 From 06e57b6c1e6cfabdaf6fb95207dcefe03c20b06d Mon Sep 17 00:00:00 2001 From: Fabio Estevam Date: Mon, 6 Jan 2014 10:29:08 -0200 Subject: regulator: anatop-regulator: Remove unneeded memset() sreg is allocated via devm_kzalloc(), so there is no need to explicitly zero out rdesc via memset(). Signed-off-by: Fabio Estevam Signed-off-by: Mark Brown --- drivers/regulator/anatop-regulator.c | 1 - 1 file changed, 1 deletion(-) (limited to 'drivers/regulator') diff --git a/drivers/regulator/anatop-regulator.c b/drivers/regulator/anatop-regulator.c index 3d4997aede1d..862e63e451d0 100644 --- a/drivers/regulator/anatop-regulator.c +++ b/drivers/regulator/anatop-regulator.c @@ -124,7 +124,6 @@ static int anatop_regulator_probe(struct platform_device *pdev) sreg->initdata = initdata; sreg->name = of_get_property(np, "regulator-name", NULL); rdesc = &sreg->rdesc; - memset(rdesc, 0, sizeof(*rdesc)); rdesc->name = sreg->name; rdesc->ops = &anatop_rops; rdesc->type = REGULATOR_VOLTAGE; -- cgit v1.2.3 From f2694383680838573262f3099f03dc4722d5efa4 Mon Sep 17 00:00:00 2001 From: Fabio Estevam Date: Mon, 20 Jan 2014 18:53:56 -0200 Subject: regulator: pfuze100-regulator: Improve dev_info() message 'lay' is not very meaningful, so use it 'layer' instead to let the dev_info() clearer. Signed-off-by: Fabio Estevam Signed-off-by: Mark Brown --- drivers/regulator/pfuze100-regulator.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/regulator') diff --git a/drivers/regulator/pfuze100-regulator.c b/drivers/regulator/pfuze100-regulator.c index 8b5e4c712a01..c31e0485de25 100644 --- a/drivers/regulator/pfuze100-regulator.c +++ b/drivers/regulator/pfuze100-regulator.c @@ -323,7 +323,7 @@ static int pfuze_identify(struct pfuze_chip *pfuze_chip) 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); -- cgit v1.2.3