From bd0dda744cdfb93a1907091c4540764593a28fa2 Mon Sep 17 00:00:00 2001 From: Charles Keepax Date: Thu, 3 Apr 2014 15:32:15 +0100 Subject: regulator: core: Add of_node_get to of_regulator_match Currently, of_regulator_match does not increment the reference count of the of_nodes it takes new references to. This could cause the node pointer held to be invalid, by the time it is passed to the regulator core. This patchs adds an of_node_get when we copy each of_node pointer into the match structure. Signed-off-by: Charles Keepax Signed-off-by: Mark Brown --- drivers/regulator/of_regulator.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'drivers/regulator') diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c index ea4f36f2cbe2..c58c8d178948 100644 --- a/drivers/regulator/of_regulator.c +++ b/drivers/regulator/of_regulator.c @@ -119,7 +119,8 @@ EXPORT_SYMBOL_GPL(of_get_regulator_init_data); * regulator. The data parsed from a child node will be matched to a regulator * based on either the deprecated property regulator-compatible if present, * or otherwise the child node's name. Note that the match table is modified - * in place. + * in place and an additional of_node reference is taken for each matched + * regulator. * * Returns the number of matches found or a negative error code on failure. */ @@ -162,7 +163,7 @@ int of_regulator_match(struct device *dev, struct device_node *node, child->name); return -EINVAL; } - match->of_node = child; + match->of_node = of_node_get(child); count++; break; } -- cgit v1.2.3 From 3764806440149ea9024dff039497d1e45d6ed027 Mon Sep 17 00:00:00 2001 From: Charles Keepax Date: Thu, 3 Apr 2014 15:32:16 +0100 Subject: regulator: core: Add helper to put of_nodes from matches As of_regulator_match will take an of_node reference to each matched regulator, it makes sense to provide a helper to put all those references. This patch does that. Signed-off-by: Charles Keepax Signed-off-by: Mark Brown --- drivers/regulator/of_regulator.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'drivers/regulator') diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c index c58c8d178948..188e0cb10d03 100644 --- a/drivers/regulator/of_regulator.c +++ b/drivers/regulator/of_regulator.c @@ -172,3 +172,24 @@ int of_regulator_match(struct device *dev, struct device_node *node, return count; } EXPORT_SYMBOL_GPL(of_regulator_match); + +/** + * of_regulator_put_match - put the of_node references from an + * of_regulator_match structure + * @matches: match table for the regulators + * @num_matches: number of entries in match table + * + * This function goes through a match table and calls of_node_put on each + * of_node. + */ +int of_regulator_put_match(struct of_regulator_match *matches, + unsigned int num_matches) +{ + int i; + + for (i = 0; i < num_matches; i++) + of_node_put(matches[i].of_node); + + return 0; +} +EXPORT_SYMBOL_GPL(of_regulator_put_match); -- cgit v1.2.3 From 63c7c9e16c8e92cc069854f2babdf82d2d38e4c7 Mon Sep 17 00:00:00 2001 From: Charles Keepax Date: Thu, 3 Apr 2014 15:32:17 +0100 Subject: regulator: core: Get and put regulator of_node Currently the regulator core does not take an additional reference to the of_node it is passed. This means that the caller must ensure that the of_node is valid for the duration of the regulator's existance. It is reasonable for the framework to assume it is passed a valid of_node but seems onerous for it to assume the caller will keep the node valid for the life-time of the regulator, especially when devm_regulator_register is used and there will likely be no code in the driver called at the point it would be safe to put the of_node. This patch adds an additional of_node_get when the regulator is registered and an of_node_put when it is unregistered in the core. This means individual drivers are free to put their of_node references at the end of probe letting the regulator core handling it from there. This simplifies code on the driver side. Signed-off-by: Charles Keepax Signed-off-by: Mark Brown --- drivers/regulator/core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'drivers/regulator') diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 9a09f3cdbabb..b97ffd2365d3 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -3447,7 +3447,7 @@ regulator_register(const struct regulator_desc *regulator_desc, /* register with sysfs */ rdev->dev.class = ®ulator_class; - rdev->dev.of_node = config->of_node; + rdev->dev.of_node = of_node_get(config->of_node); rdev->dev.parent = dev; dev_set_name(&rdev->dev, "regulator.%d", atomic_inc_return(®ulator_no) - 1); @@ -3589,6 +3589,7 @@ void regulator_unregister(struct regulator_dev *rdev) list_del(&rdev->list); kfree(rdev->constraints); regulator_ena_gpio_free(rdev); + of_node_put(rdev->dev.of_node); device_unregister(&rdev->dev); mutex_unlock(®ulator_list_mutex); } -- cgit v1.2.3 From 13b3fde808ed287ad23c4549733fb3e3be785114 Mon Sep 17 00:00:00 2001 From: Charles Keepax Date: Tue, 15 Apr 2014 13:34:36 +0100 Subject: regulator: core: Use devres for releasing of_regulator_match of_nodes Rather than requiring individual drivers to put the of_nodes returned from of_regulator_match use devres to put them. This also has the benefit it makes the life-time of the of_nodes match the lifetime of the init data also contained in the of_regulator_match structure, which seems more consistent. Signed-off-by: Charles Keepax Signed-off-by: Mark Brown --- drivers/regulator/of_regulator.c | 47 ++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 21 deletions(-) (limited to 'drivers/regulator') diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c index 188e0cb10d03..4672cd2f4632 100644 --- a/drivers/regulator/of_regulator.c +++ b/drivers/regulator/of_regulator.c @@ -106,6 +106,20 @@ struct regulator_init_data *of_get_regulator_init_data(struct device *dev, } EXPORT_SYMBOL_GPL(of_get_regulator_init_data); +struct devm_of_regulator_matches { + struct of_regulator_match *matches; + unsigned int num_matches; +}; + +static void devm_of_regulator_put_matches(struct device *dev, void *res) +{ + struct devm_of_regulator_matches *devm_matches = res; + int i; + + for (i = 0; i < devm_matches->num_matches; i++) + of_node_put(devm_matches->matches[i].of_node); +} + /** * of_regulator_match - extract multiple regulator init data from device tree. * @dev: device requesting the data @@ -132,10 +146,22 @@ int of_regulator_match(struct device *dev, struct device_node *node, unsigned int i; const char *name; struct device_node *child; + struct devm_of_regulator_matches *devm_matches; if (!dev || !node) return -EINVAL; + devm_matches = devres_alloc(devm_of_regulator_put_matches, + sizeof(struct devm_of_regulator_matches), + GFP_KERNEL); + if (!devm_matches) + return -ENOMEM; + + devm_matches->matches = matches; + devm_matches->num_matches = num_matches; + + devres_add(dev, devm_matches); + for (i = 0; i < num_matches; i++) { struct of_regulator_match *match = &matches[i]; match->init_data = NULL; @@ -172,24 +198,3 @@ int of_regulator_match(struct device *dev, struct device_node *node, return count; } EXPORT_SYMBOL_GPL(of_regulator_match); - -/** - * of_regulator_put_match - put the of_node references from an - * of_regulator_match structure - * @matches: match table for the regulators - * @num_matches: number of entries in match table - * - * This function goes through a match table and calls of_node_put on each - * of_node. - */ -int of_regulator_put_match(struct of_regulator_match *matches, - unsigned int num_matches) -{ - int i; - - for (i = 0; i < num_matches; i++) - of_node_put(matches[i].of_node); - - return 0; -} -EXPORT_SYMBOL_GPL(of_regulator_put_match); -- cgit v1.2.3 From a799baab129cbe0db20a666ceae9145928fc00fe Mon Sep 17 00:00:00 2001 From: Jingoo Han Date: Wed, 7 May 2014 16:55:10 +0900 Subject: regulator: anatop: Make of_device_id array const Make of_device_id array const, because all OF functions handle it as const. Signed-off-by: Jingoo Han Signed-off-by: Mark Brown --- drivers/regulator/anatop-regulator.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/regulator') diff --git a/drivers/regulator/anatop-regulator.c b/drivers/regulator/anatop-regulator.c index 7c397bb81e01..4f730af70e7c 100644 --- a/drivers/regulator/anatop-regulator.c +++ b/drivers/regulator/anatop-regulator.c @@ -300,7 +300,7 @@ static int anatop_regulator_probe(struct platform_device *pdev) return 0; } -static struct of_device_id of_anatop_regulator_match_tbl[] = { +static const struct of_device_id of_anatop_regulator_match_tbl[] = { { .compatible = "fsl,anatop-regulator", }, { /* end */ } }; -- cgit v1.2.3 From 2449df9f900f69edaa1466f27493694c2f9df2b1 Mon Sep 17 00:00:00 2001 From: Jingoo Han Date: Wed, 7 May 2014 17:07:54 +0900 Subject: regulator: palmas: Make of_device_id array const Make of_device_id array const, because all OF functions handle it as const. Signed-off-by: Jingoo Han Signed-off-by: Mark Brown --- drivers/regulator/palmas-regulator.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/regulator') diff --git a/drivers/regulator/palmas-regulator.c b/drivers/regulator/palmas-regulator.c index 9c62b1d34685..671cb9f32dab 100644 --- a/drivers/regulator/palmas-regulator.c +++ b/drivers/regulator/palmas-regulator.c @@ -1199,7 +1199,7 @@ static int palmas_regulators_probe(struct platform_device *pdev) return 0; } -static struct of_device_id of_palmas_match_tbl[] = { +static const struct of_device_id of_palmas_match_tbl[] = { { .compatible = "ti,palmas-pmic", }, { .compatible = "ti,twl6035-pmic", }, { .compatible = "ti,twl6036-pmic", }, -- cgit v1.2.3 From a74cf0c207c4711138831e5a5988e507d4c9ad5a Mon Sep 17 00:00:00 2001 From: Jingoo Han Date: Wed, 7 May 2014 17:08:35 +0900 Subject: regulator: st-pwm: Make of_device_id array const Make of_device_id array const, because all OF functions handle it as const. Signed-off-by: Jingoo Han Acked-by: Lee Jones Signed-off-by: Mark Brown --- drivers/regulator/st-pwm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/regulator') diff --git a/drivers/regulator/st-pwm.c b/drivers/regulator/st-pwm.c index e367af1c5f9d..5ea78df449f8 100644 --- a/drivers/regulator/st-pwm.c +++ b/drivers/regulator/st-pwm.c @@ -118,7 +118,7 @@ static const struct st_pwm_regulator_pdata b2105_info = { .duty_cycle_table = b2105_duty_cycle_table, }; -static struct of_device_id st_pwm_of_match[] = { +static const struct of_device_id st_pwm_of_match[] = { { .compatible = "st,b2105-pwm-regulator", .data = &b2105_info, }, { }, }; -- cgit v1.2.3 From 1439afd8dba5ae552c439309286e54ffd3a97abc Mon Sep 17 00:00:00 2001 From: Jingoo Han Date: Wed, 7 May 2014 17:09:12 +0900 Subject: regulator: vexpress: Make of_device_id array const Make of_device_id array const, because all OF functions handle it as const. Signed-off-by: Jingoo Han Acked-by: Pawel Moll Signed-off-by: Mark Brown --- drivers/regulator/vexpress.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/regulator') diff --git a/drivers/regulator/vexpress.c b/drivers/regulator/vexpress.c index f3ae28a7e663..147ecc7c11bf 100644 --- a/drivers/regulator/vexpress.c +++ b/drivers/regulator/vexpress.c @@ -123,7 +123,7 @@ static int vexpress_regulator_remove(struct platform_device *pdev) return 0; } -static struct of_device_id vexpress_regulator_of_match[] = { +static const struct of_device_id vexpress_regulator_of_match[] = { { .compatible = "arm,vexpress-volt", }, { } }; -- cgit v1.2.3 From cfe6e3334eea1f4539799159e2b6024ae7f71a0d Mon Sep 17 00:00:00 2001 From: Jingoo Han Date: Wed, 7 May 2014 17:06:34 +0900 Subject: regulator: max8952: Make of_device_id array const Make of_device_id array const, because all OF functions handle it as const. Signed-off-by: Jingoo Han Reviewed-by: Krzysztof Kozlowski Signed-off-by: Mark Brown --- drivers/regulator/max8952.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/regulator') diff --git a/drivers/regulator/max8952.c b/drivers/regulator/max8952.c index d920f5a32ec8..c2792f0271ab 100644 --- a/drivers/regulator/max8952.c +++ b/drivers/regulator/max8952.c @@ -129,7 +129,7 @@ static const struct regulator_desc regulator = { }; #ifdef CONFIG_OF -static struct of_device_id max8952_dt_match[] = { +static const struct of_device_id max8952_dt_match[] = { { .compatible = "maxim,max8952" }, {}, }; -- cgit v1.2.3 From 3eb2c7ecb7ea0fad4a53cbedcb87341dcffcea2b Mon Sep 17 00:00:00 2001 From: Philipp Zabel Date: Mon, 26 May 2014 10:38:16 +0200 Subject: regulator: Add LTC3589 support This patch adds support for the Linear Technology LTC3589, LTC3589-1, and LTC3589-2 8-output I2C voltage regulator ICs. Signed-off-by: Lucas Stach Signed-off-by: Philipp Zabel Signed-off-by: Mark Brown --- drivers/regulator/Kconfig | 6 + drivers/regulator/Makefile | 1 + drivers/regulator/ltc3589.c | 565 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 572 insertions(+) create mode 100644 drivers/regulator/ltc3589.c (limited to 'drivers/regulator') diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig index 903eb37f047a..5599a61bd88c 100644 --- a/drivers/regulator/Kconfig +++ b/drivers/regulator/Kconfig @@ -265,6 +265,12 @@ config REGULATOR_LP8788 help This driver supports LP8788 voltage regulator chip. +config REGULATOR_LTC3589 + bool "LTC3589 8-output voltage regulator" + help + This enables support for the LTC3589, LTC3589-1, and LTC3589-2 + 8-output regulators controlled via I2C. + config REGULATOR_MAX14577 tristate "Maxim 14577 regulator" depends on MFD_MAX14577 diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile index 12ef277a48b4..16d429ba8ba2 100644 --- a/drivers/regulator/Makefile +++ b/drivers/regulator/Makefile @@ -37,6 +37,7 @@ obj-$(CONFIG_REGULATOR_LP872X) += lp872x.o obj-$(CONFIG_REGULATOR_LP8788) += lp8788-buck.o obj-$(CONFIG_REGULATOR_LP8788) += lp8788-ldo.o obj-$(CONFIG_REGULATOR_LP8755) += lp8755.o +obj-$(CONFIG_REGULATOR_LTC3589) += ltc3589.o obj-$(CONFIG_REGULATOR_MAX14577) += max14577.o obj-$(CONFIG_REGULATOR_MAX1586) += max1586.o obj-$(CONFIG_REGULATOR_MAX8649) += max8649.o diff --git a/drivers/regulator/ltc3589.c b/drivers/regulator/ltc3589.c new file mode 100644 index 000000000000..fef64ee31185 --- /dev/null +++ b/drivers/regulator/ltc3589.c @@ -0,0 +1,565 @@ +/* + * Linear Technology LTC3589,LTC3589-1 regulator support + * + * Copyright (c) 2014 Philipp Zabel , Pengutronix + * + * See file CREDITS for list of people who contributed to this + * project. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation. + * + * 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 + +#define DRIVER_NAME "ltc3589" + +#define LTC3589_IRQSTAT 0x02 +#define LTC3589_SCR1 0x07 +#define LTC3589_OVEN 0x10 +#define LTC3589_SCR2 0x12 +#define LTC3589_PGSTAT 0x13 +#define LTC3589_VCCR 0x20 +#define LTC3589_CLIRQ 0x21 +#define LTC3589_B1DTV1 0x23 +#define LTC3589_B1DTV2 0x24 +#define LTC3589_VRRCR 0x25 +#define LTC3589_B2DTV1 0x26 +#define LTC3589_B2DTV2 0x27 +#define LTC3589_B3DTV1 0x29 +#define LTC3589_B3DTV2 0x2a +#define LTC3589_L2DTV1 0x32 +#define LTC3589_L2DTV2 0x33 + +#define LTC3589_IRQSTAT_PGOOD_TIMEOUT BIT(3) +#define LTC3589_IRQSTAT_UNDERVOLT_WARN BIT(4) +#define LTC3589_IRQSTAT_UNDERVOLT_FAULT BIT(5) +#define LTC3589_IRQSTAT_THERMAL_WARN BIT(6) +#define LTC3589_IRQSTAT_THERMAL_FAULT BIT(7) + +#define LTC3589_OVEN_SW1 BIT(0) +#define LTC3589_OVEN_SW2 BIT(1) +#define LTC3589_OVEN_SW3 BIT(2) +#define LTC3589_OVEN_BB_OUT BIT(3) +#define LTC3589_OVEN_LDO2 BIT(4) +#define LTC3589_OVEN_LDO3 BIT(5) +#define LTC3589_OVEN_LDO4 BIT(6) +#define LTC3589_OVEN_SW_CTRL BIT(7) + +#define LTC3589_VCCR_SW1_GO BIT(0) +#define LTC3589_VCCR_SW2_GO BIT(2) +#define LTC3589_VCCR_SW3_GO BIT(4) +#define LTC3589_VCCR_LDO2_GO BIT(6) + +enum ltc3589_variant { + LTC3589, + LTC3589_1, + LTC3589_2, +}; + +enum ltc3589_reg { + LTC3589_SW1, + LTC3589_SW2, + LTC3589_SW3, + LTC3589_BB_OUT, + LTC3589_LDO1, + LTC3589_LDO2, + LTC3589_LDO3, + LTC3589_LDO4, + LTC3589_NUM_REGULATORS, +}; + +struct ltc3589_regulator { + struct regulator_desc desc; + + /* External feedback voltage divider */ + unsigned int r1; + unsigned int r2; +}; + +struct ltc3589 { + struct regmap *regmap; + struct device *dev; + enum ltc3589_variant variant; + struct ltc3589_regulator regulator_descs[LTC3589_NUM_REGULATORS]; + struct regulator_dev *regulators[LTC3589_NUM_REGULATORS]; +}; + +static const int ltc3589_ldo4[] = { + 2800000, 2500000, 1800000, 3300000, +}; + +static const int ltc3589_12_ldo4[] = { + 1200000, 1800000, 2500000, 3200000, +}; + +static int ltc3589_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay) +{ + struct ltc3589 *ltc3589 = rdev_get_drvdata(rdev); + int sel, shift; + + if (unlikely(ramp_delay <= 0)) + return -EINVAL; + + /* VRRCR slew rate offsets are the same as VCCR go bit offsets */ + shift = ffs(rdev->desc->apply_bit) - 1; + + /* The slew rate can be set to 0.88, 1.75, 3.5, or 7 mV/uS */ + for (sel = 0; sel < 4; sel++) { + if ((880 << sel) >= ramp_delay) { + return regmap_update_bits(ltc3589->regmap, + LTC3589_VRRCR, + 0x3 << shift, sel << shift); + } + } + return -EINVAL; +} + +static int ltc3589_set_suspend_voltage(struct regulator_dev *rdev, int uV) +{ + struct ltc3589 *ltc3589 = rdev_get_drvdata(rdev); + int sel; + + sel = regulator_map_voltage_linear(rdev, uV, uV); + if (sel < 0) + return sel; + + /* DTV2 register follows right after the corresponding DTV1 register */ + return regmap_update_bits(ltc3589->regmap, rdev->desc->vsel_reg + 1, + rdev->desc->vsel_mask, sel); +} + +static int ltc3589_set_suspend_mode(struct regulator_dev *rdev, + unsigned int mode) +{ + struct ltc3589 *ltc3589 = rdev_get_drvdata(rdev); + int mask, bit = 0; + + /* VCCR reference selects are right next to the VCCR go bits */ + mask = rdev->desc->apply_bit << 1; + + if (mode == REGULATOR_MODE_STANDBY) + bit = mask; /* Select DTV2 */ + + mask |= rdev->desc->apply_bit; + bit |= rdev->desc->apply_bit; + return regmap_update_bits(ltc3589->regmap, LTC3589_VCCR, mask, bit); +} + +static int ltc3589_list_voltage_fixed(struct regulator_dev *rdev, + unsigned int selector) +{ + if (selector) + return -EINVAL; + + return rdev->desc->fixed_uV; +} + +/* SW1, SW2, SW3, LDO2 */ +static struct regulator_ops ltc3589_linear_regulator_ops = { + .enable = regulator_enable_regmap, + .disable = regulator_disable_regmap, + .is_enabled = regulator_is_enabled_regmap, + .list_voltage = regulator_list_voltage_linear, + .set_voltage_sel = regulator_set_voltage_sel_regmap, + .get_voltage_sel = regulator_get_voltage_sel_regmap, + .set_ramp_delay = ltc3589_set_ramp_delay, + .set_voltage_time_sel = regulator_set_voltage_time_sel, + .set_suspend_voltage = ltc3589_set_suspend_voltage, + .set_suspend_mode = ltc3589_set_suspend_mode, +}; + +/* BB_OUT, LDO3 */ +static struct regulator_ops ltc3589_fixed_regulator_ops = { + .enable = regulator_enable_regmap, + .disable = regulator_disable_regmap, + .is_enabled = regulator_is_enabled_regmap, + .list_voltage = ltc3589_list_voltage_fixed, +}; + +/* LDO1 */ +static struct regulator_ops ltc3589_standby_regulator_ops = { + .list_voltage = ltc3589_list_voltage_fixed, +}; + +/* LDO4 */ +static struct regulator_ops ltc3589_table_regulator_ops = { + .enable = regulator_enable_regmap, + .disable = regulator_disable_regmap, + .is_enabled = regulator_is_enabled_regmap, + .list_voltage = regulator_list_voltage_table, + .set_voltage_sel = regulator_set_voltage_sel_regmap, + .get_voltage_sel = regulator_get_voltage_sel_regmap, +}; + + +#define LTC3589_REG(_name, _ops, en_bit, dtv1_reg, dtv_mask, go_bit) \ + [LTC3589_ ## _name] = { \ + .desc = { \ + .name = #_name, \ + .n_voltages = (dtv_mask) + 1, \ + .min_uV = (go_bit) ? 362500 : 0, \ + .uV_step = (go_bit) ? 12500 : 0, \ + .ramp_delay = (go_bit) ? 1750 : 0, \ + .fixed_uV = (dtv_mask) ? 0 : 800000, \ + .ops = <c3589_ ## _ops ## _regulator_ops, \ + .type = REGULATOR_VOLTAGE, \ + .id = LTC3589_ ## _name, \ + .owner = THIS_MODULE, \ + .vsel_reg = (dtv1_reg), \ + .vsel_mask = (dtv_mask), \ + .apply_reg = (go_bit) ? LTC3589_VCCR : 0, \ + .apply_bit = (go_bit), \ + .enable_reg = (en_bit) ? LTC3589_OVEN : 0, \ + .enable_mask = (en_bit), \ + }, \ + } + +#define LTC3589_LINEAR_REG(_name, _dtv1) \ + LTC3589_REG(_name, linear, LTC3589_OVEN_ ## _name, \ + LTC3589_ ## _dtv1, 0x1f, \ + LTC3589_VCCR_ ## _name ## _GO) + +#define LTC3589_FIXED_REG(_name) \ + LTC3589_REG(_name, fixed, LTC3589_OVEN_ ## _name, 0, 0, 0) + +static struct ltc3589_regulator ltc3589_regulators[LTC3589_NUM_REGULATORS] = { + LTC3589_LINEAR_REG(SW1, B1DTV1), + LTC3589_LINEAR_REG(SW2, B2DTV1), + LTC3589_LINEAR_REG(SW3, B3DTV1), + LTC3589_FIXED_REG(BB_OUT), + LTC3589_REG(LDO1, standby, 0, 0, 0, 0), + LTC3589_LINEAR_REG(LDO2, L2DTV1), + LTC3589_FIXED_REG(LDO3), + LTC3589_REG(LDO4, table, LTC3589_OVEN_LDO4, LTC3589_L2DTV2, 0x60, 0), +}; + +#ifdef CONFIG_OF +static struct of_regulator_match ltc3589_matches[LTC3589_NUM_REGULATORS] = { + { .name = "sw1", }, + { .name = "sw2", }, + { .name = "sw3", }, + { .name = "bb-out", }, + { .name = "ldo1", }, /* standby */ + { .name = "ldo2", }, + { .name = "ldo3", }, + { .name = "ldo4", }, +}; + +static int ltc3589_parse_regulators_dt(struct ltc3589 *ltc3589) +{ + struct device *dev = ltc3589->dev; + struct device_node *node; + int i, ret; + + node = of_find_node_by_name(dev->of_node, "regulators"); + if (!node) { + dev_err(dev, "regulators node not found\n"); + return -EINVAL; + } + + ret = of_regulator_match(dev, node, ltc3589_matches, + ARRAY_SIZE(ltc3589_matches)); + of_node_put(node); + if (ret < 0) { + dev_err(dev, "Error parsing regulator init data: %d\n", ret); + return ret; + } + if (ret != LTC3589_NUM_REGULATORS) { + dev_err(dev, "Only %d regulators described in device tree\n", + ret); + return -EINVAL; + } + + /* Parse feedback voltage dividers. LDO3 and LDO4 don't have them */ + for (i = 0; i < LTC3589_LDO3; i++) { + struct ltc3589_regulator *desc = <c3589->regulator_descs[i]; + struct device_node *np = ltc3589_matches[i].of_node; + u32 vdiv[2]; + + ret = of_property_read_u32_array(np, "lltc,fb-voltage-divider", + vdiv, 2); + if (ret) { + dev_err(dev, "Failed to parse voltage divider: %d\n", + ret); + return ret; + } + + desc->r1 = vdiv[0]; + desc->r2 = vdiv[1]; + } + + return 0; +} + +static inline struct regulator_init_data *match_init_data(int index) +{ + return ltc3589_matches[index].init_data; +} + +static inline struct device_node *match_of_node(int index) +{ + return ltc3589_matches[index].of_node; +} +#else +static inline int ltc3589_parse_regulators_dt(struct ltc3589 *ltc3589) +{ + return 0; +} + +static inline struct regulator_init_data *match_init_data(int index) +{ + return NULL; +} + +static inline struct device_node *match_of_node(int index) +{ + return NULL; +} +#endif + +static bool ltc3589_writeable_reg(struct device *dev, unsigned int reg) +{ + switch (reg) { + case LTC3589_IRQSTAT: + case LTC3589_SCR1: + case LTC3589_OVEN: + case LTC3589_SCR2: + case LTC3589_VCCR: + case LTC3589_CLIRQ: + case LTC3589_B1DTV1: + case LTC3589_B1DTV2: + case LTC3589_VRRCR: + case LTC3589_B2DTV1: + case LTC3589_B2DTV2: + case LTC3589_B3DTV1: + case LTC3589_B3DTV2: + case LTC3589_L2DTV1: + case LTC3589_L2DTV2: + return true; + } + return false; +} + +static bool ltc3589_readable_reg(struct device *dev, unsigned int reg) +{ + switch (reg) { + case LTC3589_IRQSTAT: + case LTC3589_SCR1: + case LTC3589_OVEN: + case LTC3589_SCR2: + case LTC3589_PGSTAT: + case LTC3589_VCCR: + case LTC3589_B1DTV1: + case LTC3589_B1DTV2: + case LTC3589_VRRCR: + case LTC3589_B2DTV1: + case LTC3589_B2DTV2: + case LTC3589_B3DTV1: + case LTC3589_B3DTV2: + case LTC3589_L2DTV1: + case LTC3589_L2DTV2: + return true; + } + return false; +} + +static bool ltc3589_volatile_reg(struct device *dev, unsigned int reg) +{ + switch (reg) { + case LTC3589_IRQSTAT: + case LTC3589_PGSTAT: + return true; + } + return false; +} + +struct reg_default ltc3589_reg_defaults[] = { + { LTC3589_SCR1, 0x00 }, + { LTC3589_OVEN, 0x00 }, + { LTC3589_SCR2, 0x00 }, + { LTC3589_VCCR, 0x00 }, + { LTC3589_B1DTV1, 0x19 }, + { LTC3589_B1DTV2, 0x19 }, + { LTC3589_VRRCR, 0xff }, + { LTC3589_B2DTV1, 0x19 }, + { LTC3589_B2DTV2, 0x19 }, + { LTC3589_B3DTV1, 0x19 }, + { LTC3589_B3DTV2, 0x19 }, + { LTC3589_L2DTV1, 0x19 }, + { LTC3589_L2DTV2, 0x19 }, +}; + +static const struct regmap_config ltc3589_regmap_config = { + .reg_bits = 8, + .val_bits = 8, + .writeable_reg = ltc3589_writeable_reg, + .readable_reg = ltc3589_readable_reg, + .volatile_reg = ltc3589_volatile_reg, + .max_register = LTC3589_L2DTV2, + .reg_defaults = ltc3589_reg_defaults, + .num_reg_defaults = ARRAY_SIZE(ltc3589_reg_defaults), + .use_single_rw = true, + .cache_type = REGCACHE_RBTREE, +}; + + +static irqreturn_t ltc3589_isr(int irq, void *dev_id) +{ + struct ltc3589 *ltc3589 = dev_id; + unsigned int i, irqstat, event; + + regmap_read(ltc3589->regmap, LTC3589_IRQSTAT, &irqstat); + + if (irqstat & LTC3589_IRQSTAT_THERMAL_WARN) { + event = REGULATOR_EVENT_OVER_TEMP; + for (i = 0; i < LTC3589_NUM_REGULATORS; i++) + regulator_notifier_call_chain(ltc3589->regulators[i], + event, NULL); + } + + if (irqstat & LTC3589_IRQSTAT_UNDERVOLT_WARN) { + event = REGULATOR_EVENT_UNDER_VOLTAGE; + for (i = 0; i < LTC3589_NUM_REGULATORS; i++) + regulator_notifier_call_chain(ltc3589->regulators[i], + event, NULL); + } + + /* Clear warning condition */ + regmap_write(ltc3589->regmap, LTC3589_CLIRQ, 0); + + return IRQ_HANDLED; +} + +static inline unsigned int ltc3589_scale(unsigned int uV, u32 r1, u32 r2) +{ + uint64_t tmp; + if (uV == 0) + return 0; + tmp = (uint64_t)uV * r1; + do_div(tmp, r2); + return uV + (unsigned int)tmp; +} + +static void ltc3589_apply_fb_voltage_divider(struct ltc3589_regulator *rdesc) +{ + struct regulator_desc *desc = &rdesc->desc; + + if (!rdesc->r1 || !rdesc->r2) + return; + + desc->min_uV = ltc3589_scale(desc->min_uV, rdesc->r1, rdesc->r2); + desc->uV_step = ltc3589_scale(desc->uV_step, rdesc->r1, rdesc->r2); + desc->fixed_uV = ltc3589_scale(desc->fixed_uV, rdesc->r1, rdesc->r2); +} + +static int ltc3589_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct device *dev = &client->dev; + struct ltc3589_regulator *descs; + struct ltc3589 *ltc3589; + int i, ret; + + ltc3589 = devm_kzalloc(dev, sizeof(*ltc3589), GFP_KERNEL); + if (!ltc3589) + return -ENOMEM; + + i2c_set_clientdata(client, ltc3589); + ltc3589->variant = id->driver_data; + ltc3589->dev = dev; + + descs = ltc3589->regulator_descs; + memcpy(descs, ltc3589_regulators, sizeof(ltc3589_regulators)); + if (ltc3589->variant == LTC3589) { + descs[LTC3589_LDO3].desc.fixed_uV = 1800000; + descs[LTC3589_LDO4].desc.volt_table = ltc3589_ldo4; + } else { + descs[LTC3589_LDO3].desc.fixed_uV = 2800000; + descs[LTC3589_LDO4].desc.volt_table = ltc3589_12_ldo4; + } + + ltc3589->regmap = devm_regmap_init_i2c(client, <c3589_regmap_config); + if (IS_ERR(ltc3589->regmap)) { + ret = PTR_ERR(ltc3589->regmap); + dev_err(dev, "failed to initialize regmap: %d\n", ret); + return ret; + } + + ret = ltc3589_parse_regulators_dt(ltc3589); + if (ret) + return ret; + + for (i = 0; i < LTC3589_NUM_REGULATORS; i++) { + struct ltc3589_regulator *rdesc = <c3589->regulator_descs[i]; + struct regulator_desc *desc = &rdesc->desc; + struct regulator_init_data *init_data; + struct regulator_config config = { }; + + init_data = match_init_data(i); + + if (i < LTC3589_LDO3) + ltc3589_apply_fb_voltage_divider(rdesc); + + config.dev = dev; + config.init_data = init_data; + config.driver_data = ltc3589; + config.of_node = match_of_node(i); + + ltc3589->regulators[i] = devm_regulator_register(dev, desc, + &config); + if (IS_ERR(ltc3589->regulators[i])) { + ret = PTR_ERR(ltc3589->regulators[i]); + dev_err(dev, "failed to register regulator %s: %d\n", + desc->name, ret); + return ret; + } + } + + ret = devm_request_threaded_irq(dev, client->irq, NULL, ltc3589_isr, + IRQF_TRIGGER_LOW | IRQF_ONESHOT, + client->name, ltc3589); + if (ret) { + dev_err(dev, "Failed to request IRQ: %d\n", ret); + return ret; + } + + return 0; +} + +static struct i2c_device_id ltc3589_i2c_id[] = { + { "ltc3589", LTC3589 }, + { "ltc3589-1", LTC3589_1 }, + { "ltc3589-2", LTC3589_2 }, + { } +}; +MODULE_DEVICE_TABLE(i2c, ltc3589_i2c_id); + +static struct i2c_driver ltc3589_driver = { + .driver = { + .name = DRIVER_NAME, + .owner = THIS_MODULE, + }, + .probe = ltc3589_probe, + .id_table = ltc3589_i2c_id, +}; +module_i2c_driver(ltc3589_driver); + +MODULE_AUTHOR("Philipp Zabel "); +MODULE_DESCRIPTION("Regulator driver for Linear Technology LTC3589(-1,2)"); +MODULE_LICENSE("GPL v2"); +MODULE_ALIAS("i2c:ltc3589"); -- cgit v1.2.3 From 4127f696f9641afac8b8a05b9dd3dae48d384e08 Mon Sep 17 00:00:00 2001 From: Sergei Shtylyov Date: Sun, 25 May 2014 23:50:39 +0400 Subject: regulator: fixed: use of_property_read_{bool|u32}() Use more compact of_property_read_{bool|u32}() calls instead of the of_{find|get}_property() calls. Signed-off-by: Sergei Shtylyov Signed-off-by: Mark Brown --- drivers/regulator/fixed.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'drivers/regulator') diff --git a/drivers/regulator/fixed.c b/drivers/regulator/fixed.c index c61f7e97e4f8..354105eff1f8 100644 --- a/drivers/regulator/fixed.c +++ b/drivers/regulator/fixed.c @@ -50,7 +50,6 @@ of_get_fixed_voltage_config(struct device *dev) { struct fixed_voltage_config *config; struct device_node *np = dev->of_node; - const __be32 *delay; struct regulator_init_data *init_data; config = devm_kzalloc(dev, sizeof(struct fixed_voltage_config), @@ -91,15 +90,11 @@ of_get_fixed_voltage_config(struct device *dev) if ((config->gpio == -ENODEV) || (config->gpio == -EPROBE_DEFER)) return ERR_PTR(-EPROBE_DEFER); - delay = of_get_property(np, "startup-delay-us", NULL); - if (delay) - config->startup_delay = be32_to_cpu(*delay); + of_property_read_u32(np, "startup-delay-us", &config->startup_delay); - if (of_find_property(np, "enable-active-high", NULL)) - config->enable_high = true; - - if (of_find_property(np, "gpio-open-drain", NULL)) - config->gpio_is_open_drain = true; + config->enable_high = of_property_read_bool(np, "enable-active-high"); + config->gpio_is_open_drain = of_property_read_bool(np, + "gpio-open-drain"); if (of_find_property(np, "vin-supply", NULL)) config->input_supply = "vin"; -- cgit v1.2.3 From ac1d686846d23b2665e9d4791e32af70e251da90 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Tue, 27 May 2014 13:51:49 +0800 Subject: regulator: ltc3589: Fix module dependency Make this driver depend on I2C and select REGMAP_I2C to fix build failure. Also allows this driver to be built as module. Reported-by: Stephen Rothwell Signed-off-by: Axel Lin Acked-by: Philipp Zabel Signed-off-by: Mark Brown --- drivers/regulator/Kconfig | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'drivers/regulator') diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig index 5599a61bd88c..4c12caba37ee 100644 --- a/drivers/regulator/Kconfig +++ b/drivers/regulator/Kconfig @@ -266,7 +266,9 @@ config REGULATOR_LP8788 This driver supports LP8788 voltage regulator chip. config REGULATOR_LTC3589 - bool "LTC3589 8-output voltage regulator" + tristate "LTC3589 8-output voltage regulator" + depends on I2C + select REGMAP_I2C help This enables support for the LTC3589, LTC3589-1, and LTC3589-2 8-output regulators controlled via I2C. -- cgit v1.2.3 From c0c14e6af9ec89479f3ee3895961ef51e97aadd4 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Tue, 27 May 2014 14:05:09 +0800 Subject: regulator: ltc3589: Remove ltc3589_list_voltage_fixed function When fixed_uV is set and n_voltage is 1, regulator core will return rdev->desc->fixed_uV in regulator_get_voltage() and regulator_list_voltage(). Rename ltc3589_standby_regulator_ops to ltc3589_fixed_standby_regulator_ops, this makes the code clear that the ops is for fixed voltage regulator. Signed-off-by: Axel Lin Acked-by: Philipp Zabel Signed-off-by: Mark Brown --- drivers/regulator/ltc3589.c | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) (limited to 'drivers/regulator') diff --git a/drivers/regulator/ltc3589.c b/drivers/regulator/ltc3589.c index fef64ee31185..110a99ee1162 100644 --- a/drivers/regulator/ltc3589.c +++ b/drivers/regulator/ltc3589.c @@ -160,15 +160,6 @@ static int ltc3589_set_suspend_mode(struct regulator_dev *rdev, return regmap_update_bits(ltc3589->regmap, LTC3589_VCCR, mask, bit); } -static int ltc3589_list_voltage_fixed(struct regulator_dev *rdev, - unsigned int selector) -{ - if (selector) - return -EINVAL; - - return rdev->desc->fixed_uV; -} - /* SW1, SW2, SW3, LDO2 */ static struct regulator_ops ltc3589_linear_regulator_ops = { .enable = regulator_enable_regmap, @@ -188,12 +179,10 @@ static struct regulator_ops ltc3589_fixed_regulator_ops = { .enable = regulator_enable_regmap, .disable = regulator_disable_regmap, .is_enabled = regulator_is_enabled_regmap, - .list_voltage = ltc3589_list_voltage_fixed, }; /* LDO1 */ -static struct regulator_ops ltc3589_standby_regulator_ops = { - .list_voltage = ltc3589_list_voltage_fixed, +static struct regulator_ops ltc3589_fixed_standby_regulator_ops = { }; /* LDO4 */ @@ -242,7 +231,7 @@ static struct ltc3589_regulator ltc3589_regulators[LTC3589_NUM_REGULATORS] = { LTC3589_LINEAR_REG(SW2, B2DTV1), LTC3589_LINEAR_REG(SW3, B3DTV1), LTC3589_FIXED_REG(BB_OUT), - LTC3589_REG(LDO1, standby, 0, 0, 0, 0), + LTC3589_REG(LDO1, fixed_standby, 0, 0, 0, 0), LTC3589_LINEAR_REG(LDO2, L2DTV1), LTC3589_FIXED_REG(LDO3), LTC3589_REG(LDO4, table, LTC3589_OVEN_LDO4, LTC3589_L2DTV2, 0x60, 0), -- cgit v1.2.3 From 1e050eabb622ca60640e4714b01cb3caa29505f0 Mon Sep 17 00:00:00 2001 From: Sergei Shtylyov Date: Tue, 27 May 2014 00:27:19 +0400 Subject: regulator: use of_property_read_{bool|u32}() Use more compact of_property_read_{bool|u32}() calls instead of the of_{find|get}_property() calls in of_get_regulation_constraints() where possible (note that of_property_read_{bool|u32}() were already used to read some properties). Signed-off-by: Sergei Shtylyov Signed-off-by: Mark Brown --- drivers/regulator/of_regulator.c | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-) (limited to 'drivers/regulator') diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c index 4672cd2f4632..ee5e67bc8d5b 100644 --- a/drivers/regulator/of_regulator.c +++ b/drivers/regulator/of_regulator.c @@ -19,9 +19,7 @@ static void of_get_regulation_constraints(struct device_node *np, struct regulator_init_data **init_data) { - const __be32 *min_uV, *max_uV, *uV_offset; - const __be32 *min_uA, *max_uA, *ramp_delay; - struct property *prop; + const __be32 *min_uV, *max_uV; struct regulation_constraints *constraints = &(*init_data)->constraints; int ret; u32 pval; @@ -42,36 +40,29 @@ static void of_get_regulation_constraints(struct device_node *np, if (min_uV && max_uV && constraints->min_uV == constraints->max_uV) constraints->apply_uV = true; - uV_offset = of_get_property(np, "regulator-microvolt-offset", NULL); - if (uV_offset) - constraints->uV_offset = be32_to_cpu(*uV_offset); - min_uA = of_get_property(np, "regulator-min-microamp", NULL); - if (min_uA) - constraints->min_uA = be32_to_cpu(*min_uA); - max_uA = of_get_property(np, "regulator-max-microamp", NULL); - if (max_uA) - constraints->max_uA = be32_to_cpu(*max_uA); + if (!of_property_read_u32(np, "regulator-microvolt-offset", &pval)) + constraints->uV_offset = pval; + if (!of_property_read_u32(np, "regulator-min-microamp", &pval)) + constraints->min_uA = pval; + if (!of_property_read_u32(np, "regulator-max-microamp", &pval)) + constraints->max_uA = pval; /* Current change possible? */ if (constraints->min_uA != constraints->max_uA) constraints->valid_ops_mask |= REGULATOR_CHANGE_CURRENT; - if (of_find_property(np, "regulator-boot-on", NULL)) - constraints->boot_on = true; - - if (of_find_property(np, "regulator-always-on", NULL)) - constraints->always_on = true; - else /* status change should be possible if not always on. */ + constraints->boot_on = of_property_read_bool(np, "regulator-boot-on"); + constraints->always_on = of_property_read_bool(np, "regulator-always-on"); + if (!constraints->always_on) /* status change should be possible. */ constraints->valid_ops_mask |= REGULATOR_CHANGE_STATUS; if (of_property_read_bool(np, "regulator-allow-bypass")) constraints->valid_ops_mask |= REGULATOR_CHANGE_BYPASS; - prop = of_find_property(np, "regulator-ramp-delay", NULL); - if (prop && prop->value) { - ramp_delay = prop->value; - if (*ramp_delay) - constraints->ramp_delay = be32_to_cpu(*ramp_delay); + ret = of_property_read_u32(np, "regulator-ramp-delay", &pval); + if (!ret) { + if (pval) + constraints->ramp_delay = pval; else constraints->ramp_disable = true; } -- cgit v1.2.3 From 6e27e99613b36e68bdbee2a8d21b39fc243fef93 Mon Sep 17 00:00:00 2001 From: Jingoo Han Date: Mon, 2 Jun 2014 15:29:57 +0900 Subject: regulator: max8649: remove unnecessary OOM messages The site-specific OOM messages are unnecessary, because they duplicate the MM subsystem generic OOM message. Signed-off-by: Jingoo Han Signed-off-by: Mark Brown --- drivers/regulator/max8649.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'drivers/regulator') diff --git a/drivers/regulator/max8649.c b/drivers/regulator/max8649.c index 3172da847d24..c8bddcc8f911 100644 --- a/drivers/regulator/max8649.c +++ b/drivers/regulator/max8649.c @@ -161,10 +161,8 @@ static int max8649_regulator_probe(struct i2c_client *client, info = devm_kzalloc(&client->dev, sizeof(struct max8649_regulator_info), GFP_KERNEL); - if (!info) { - dev_err(&client->dev, "No enough memory\n"); + if (!info) return -ENOMEM; - } info->regmap = devm_regmap_init_i2c(client, &max8649_regmap_config); if (IS_ERR(info->regmap)) { -- cgit v1.2.3