From 79b53d199b83a44811cd57091751ef122351ae85 Mon Sep 17 00:00:00 2001 From: Krzysztof Kozlowski Date: Tue, 10 Dec 2013 10:09:42 +0100 Subject: regulator: s5m8767: Define symbol for buck control mask Replace hard-coded value for mask used in BUCKX_CTRL registers (for BUCKX_EN field) with a symbol. This also removes two local variables. Signed-off-by: Krzysztof Kozlowski Acked-by: Lee Jones Reviewed-by: Sachin Kamat Signed-off-by: Mark Brown --- include/linux/mfd/samsung/s5m8767.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/linux/mfd/samsung/s5m8767.h b/include/linux/mfd/samsung/s5m8767.h index 306a95fc558c..9198377ee859 100644 --- a/include/linux/mfd/samsung/s5m8767.h +++ b/include/linux/mfd/samsung/s5m8767.h @@ -183,6 +183,7 @@ enum s5m8767_regulators { S5M8767_REG_MAX, }; -#define S5M8767_ENCTRL_SHIFT 6 +#define S5M8767_ENCTRL_SHIFT 6 +#define S5M8767_ENCTRL_MASK (0x3 << S5M8767_ENCTRL_SHIFT) #endif /* __LINUX_MFD_S5M8767_H */ -- cgit v1.2.3 From f37ff6b6ab9bff6f78dbfbdd123673a09e04cb7f Mon Sep 17 00:00:00 2001 From: Krzysztof Kozlowski Date: Tue, 17 Dec 2013 14:23:17 +0100 Subject: regulator: s5m8767: Add symbols for hard-coded DVS_RAMP register Add symbols for hard-coded values of BUCK_RAMP field in DVS_RAMP register. This simplifies a little the code as register update is called only once. Signed-off-by: Krzysztof Kozlowski Acked-by: Lee Jones Signed-off-by: Mark Brown --- drivers/regulator/s5m8767.c | 22 ++++++++++------------ include/linux/mfd/samsung/s5m8767.h | 15 +++++++++++++++ 2 files changed, 25 insertions(+), 12 deletions(-) (limited to 'include') diff --git a/drivers/regulator/s5m8767.c b/drivers/regulator/s5m8767.c index 9b14faa3bf91..27741df28ad7 100644 --- a/drivers/regulator/s5m8767.c +++ b/drivers/regulator/s5m8767.c @@ -881,31 +881,29 @@ static int s5m8767_pmic_probe(struct platform_device *pdev) if (s5m8767->buck2_ramp || s5m8767->buck3_ramp || s5m8767->buck4_ramp) { + unsigned int val; switch (s5m8767->ramp_delay) { case 5: - sec_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, - 0x40, 0xf0); + val = S5M8767_DVS_BUCK_RAMP_5; break; case 10: - sec_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, - 0x90, 0xf0); + val = S5M8767_DVS_BUCK_RAMP_10; break; case 25: - sec_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, - 0xd0, 0xf0); + val = S5M8767_DVS_BUCK_RAMP_25; break; case 50: - sec_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, - 0xe0, 0xf0); + val = S5M8767_DVS_BUCK_RAMP_50; break; case 100: - sec_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, - 0xf0, 0xf0); + val = S5M8767_DVS_BUCK_RAMP_100; break; default: - sec_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, - 0x90, 0xf0); + val = S5M8767_DVS_BUCK_RAMP_10; } + sec_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, + val << S5M8767_DVS_BUCK_RAMP_SHIFT, + S5M8767_DVS_BUCK_RAMP_MASK); } for (i = 0; i < pdata->num_regulators; i++) { diff --git a/include/linux/mfd/samsung/s5m8767.h b/include/linux/mfd/samsung/s5m8767.h index 9198377ee859..2ab0b0f03641 100644 --- a/include/linux/mfd/samsung/s5m8767.h +++ b/include/linux/mfd/samsung/s5m8767.h @@ -186,4 +186,19 @@ enum s5m8767_regulators { #define S5M8767_ENCTRL_SHIFT 6 #define S5M8767_ENCTRL_MASK (0x3 << S5M8767_ENCTRL_SHIFT) +/* + * Values for BUCK_RAMP field in DVS_RAMP register, matching raw values + * in mV/us. + */ +enum s5m8767_dvs_buck_ramp_values { + S5M8767_DVS_BUCK_RAMP_5 = 0x4, + S5M8767_DVS_BUCK_RAMP_10 = 0x9, + S5M8767_DVS_BUCK_RAMP_12_5 = 0xb, + S5M8767_DVS_BUCK_RAMP_25 = 0xd, + S5M8767_DVS_BUCK_RAMP_50 = 0xe, + S5M8767_DVS_BUCK_RAMP_100 = 0xf, +}; +#define S5M8767_DVS_BUCK_RAMP_SHIFT 4 +#define S5M8767_DVS_BUCK_RAMP_MASK (0xf << S5M8767_DVS_BUCK_RAMP_SHIFT) + #endif /* __LINUX_MFD_S5M8767_H */ -- cgit v1.2.3 From ee5182b59f65e7975d8fec73d511f4d6c44f6ed3 Mon Sep 17 00:00:00 2001 From: Krzysztof Kozlowski Date: Tue, 17 Dec 2013 14:23:19 +0100 Subject: mfd: sec: Remove sec_reg* regmap helpers Remove sec_reg* helpers as they are not used anymore. These helpers were error-prone as they mixed u8 with unsigned int and they changed order of some of parameters (val and mask in sec_reg_update()). Also the helpers didn't give any way of useful abstraction as they just called corresponding regmap function. Signed-off-by: Krzysztof Kozlowski Acked-by: Lee Jones Signed-off-by: Mark Brown --- drivers/mfd/sec-core.c | 30 ------------------------------ include/linux/mfd/samsung/core.h | 6 ------ 2 files changed, 36 deletions(-) (limited to 'include') diff --git a/drivers/mfd/sec-core.c b/drivers/mfd/sec-core.c index 54cc25546592..1d158d5ba8b8 100644 --- a/drivers/mfd/sec-core.c +++ b/drivers/mfd/sec-core.c @@ -79,36 +79,6 @@ static struct of_device_id sec_dt_match[] = { }; #endif -int sec_reg_read(struct sec_pmic_dev *sec_pmic, u8 reg, void *dest) -{ - return regmap_read(sec_pmic->regmap_pmic, reg, dest); -} -EXPORT_SYMBOL_GPL(sec_reg_read); - -int sec_bulk_read(struct sec_pmic_dev *sec_pmic, u8 reg, int count, u8 *buf) -{ - return regmap_bulk_read(sec_pmic->regmap_pmic, reg, buf, count); -} -EXPORT_SYMBOL_GPL(sec_bulk_read); - -int sec_reg_write(struct sec_pmic_dev *sec_pmic, u8 reg, u8 value) -{ - return regmap_write(sec_pmic->regmap_pmic, reg, value); -} -EXPORT_SYMBOL_GPL(sec_reg_write); - -int sec_bulk_write(struct sec_pmic_dev *sec_pmic, u8 reg, int count, u8 *buf) -{ - return regmap_raw_write(sec_pmic->regmap_pmic, reg, buf, count); -} -EXPORT_SYMBOL_GPL(sec_bulk_write); - -int sec_reg_update(struct sec_pmic_dev *sec_pmic, u8 reg, u8 val, u8 mask) -{ - return regmap_update_bits(sec_pmic->regmap_pmic, reg, mask, val); -} -EXPORT_SYMBOL_GPL(sec_reg_update); - static bool s2mps11_volatile(struct device *dev, unsigned int reg) { switch (reg) { diff --git a/include/linux/mfd/samsung/core.h b/include/linux/mfd/samsung/core.h index cab2dd279076..41c9bde410c5 100644 --- a/include/linux/mfd/samsung/core.h +++ b/include/linux/mfd/samsung/core.h @@ -59,12 +59,6 @@ int sec_irq_init(struct sec_pmic_dev *sec_pmic); void sec_irq_exit(struct sec_pmic_dev *sec_pmic); int sec_irq_resume(struct sec_pmic_dev *sec_pmic); -extern int sec_reg_read(struct sec_pmic_dev *sec_pmic, u8 reg, void *dest); -extern int sec_bulk_read(struct sec_pmic_dev *sec_pmic, u8 reg, int count, u8 *buf); -extern int sec_reg_write(struct sec_pmic_dev *sec_pmic, u8 reg, u8 value); -extern int sec_bulk_write(struct sec_pmic_dev *sec_pmic, u8 reg, int count, u8 *buf); -extern int sec_reg_update(struct sec_pmic_dev *sec_pmic, u8 reg, u8 val, u8 mask); - struct sec_platform_data { struct sec_regulator_data *regulators; struct sec_opmode_data *opmode; -- cgit v1.2.3 From 03746dcbde75fc2b0ee8a9d65e3fb3efee8deb4a Mon Sep 17 00:00:00 2001 From: Markus Pargmann Date: Fri, 20 Dec 2013 12:43:27 +0100 Subject: regulator: tps65910: Add backup battery regulator tps65910 has a backup battery charger with a configurable voltage. This patch adds a regulator for the backup battery. Signed-off-by: Markus Pargmann Signed-off-by: Mark Brown --- Documentation/devicetree/bindings/mfd/tps65910.txt | 4 +- drivers/regulator/tps65910-regulator.c | 56 +++++++++++++++++++++- include/linux/mfd/tps65910.h | 3 +- 3 files changed, 59 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/Documentation/devicetree/bindings/mfd/tps65910.txt b/Documentation/devicetree/bindings/mfd/tps65910.txt index 2e3304888ffc..b4bd98af1cc7 100644 --- a/Documentation/devicetree/bindings/mfd/tps65910.txt +++ b/Documentation/devicetree/bindings/mfd/tps65910.txt @@ -21,7 +21,7 @@ Required properties: The valid regulator-compatible values are: tps65910: vrtc, vio, vdd1, vdd2, vdd3, vdig1, vdig2, vpll, vdac, vaux1, - vaux2, vaux33, vmmc + vaux2, vaux33, vmmc, vbb tps65911: vrtc, vio, vdd1, vdd3, vddctrl, ldo1, ldo2, ldo3, ldo4, ldo5, ldo6, ldo7, ldo8 @@ -38,7 +38,7 @@ Required properties: vcc4-supply: VAUX1 and VAUX2 input. vcc5-supply: VPLL and VDAC input. vcc6-supply: VDIG1 and VDIG2 input. - vcc7-supply: VRTC input. + vcc7-supply: VRTC and VBB input. vccio-supply: VIO input. tps65911: vcc1-supply: VDD1 input. diff --git a/drivers/regulator/tps65910-regulator.c b/drivers/regulator/tps65910-regulator.c index a00132e31ec7..979ea0a99a79 100644 --- a/drivers/regulator/tps65910-regulator.c +++ b/drivers/regulator/tps65910-regulator.c @@ -88,6 +88,11 @@ static const unsigned int VMMC_VSEL_table[] = { 1800000, 2800000, 3000000, 3300000, }; +/* supported BBCH voltages in microvolts */ +static const unsigned int VBB_VSEL_table[] = { + 3000000, 2520000, 3150000, 5000000, +}; + struct tps_info { const char *name; const char *vin_name; @@ -183,6 +188,12 @@ static struct tps_info tps65910_regs[] = { .voltage_table = VMMC_VSEL_table, .enable_time_us = 100, }, + { + .name = "vbb", + .vin_name = "vcc7", + .n_voltages = ARRAY_SIZE(VBB_VSEL_table), + .voltage_table = VBB_VSEL_table, + }, }; static struct tps_info tps65911_regs[] = { @@ -339,6 +350,8 @@ static int tps65910_get_ctrl_register(int id) return TPS65910_VAUX33; case TPS65910_REG_VMMC: return TPS65910_VMMC; + case TPS65910_REG_VBB: + return TPS65910_BBCH; default: return -EINVAL; } @@ -528,6 +541,10 @@ static int tps65910_get_voltage_sel(struct regulator_dev *dev) value &= LDO_SEL_MASK; value >>= LDO_SEL_SHIFT; break; + case TPS65910_REG_VBB: + value &= BBCH_BBSEL_MASK; + value >>= BBCH_BBSEL_SHIFT; + break; default: return -EINVAL; } @@ -638,6 +655,9 @@ static int tps65910_set_voltage_sel(struct regulator_dev *dev, case TPS65910_REG_VMMC: return tps65910_reg_update_bits(pmic->mfd, reg, LDO_SEL_MASK, selector << LDO_SEL_SHIFT); + case TPS65910_REG_VBB: + return tps65910_reg_update_bits(pmic->mfd, reg, BBCH_BBSEL_MASK, + selector << BBCH_BBSEL_SHIFT); } return -EINVAL; @@ -669,6 +689,9 @@ static int tps65911_set_voltage_sel(struct regulator_dev *dev, case TPS65910_REG_VIO: return tps65910_reg_update_bits(pmic->mfd, reg, LDO_SEL_MASK, selector << LDO_SEL_SHIFT); + case TPS65910_REG_VBB: + return tps65910_reg_update_bits(pmic->mfd, reg, BBCH_BBSEL_MASK, + selector << BBCH_BBSEL_SHIFT); } return -EINVAL; @@ -762,6 +785,18 @@ static struct regulator_ops tps65910_ops_vdd3 = { .map_voltage = regulator_map_voltage_ascend, }; +static struct regulator_ops tps65910_ops_vbb = { + .is_enabled = regulator_is_enabled_regmap, + .enable = regulator_enable_regmap, + .disable = regulator_disable_regmap, + .set_mode = tps65910_set_mode, + .get_mode = tps65910_get_mode, + .get_voltage_sel = tps65910_get_voltage_sel, + .set_voltage_sel = tps65910_set_voltage_sel, + .list_voltage = regulator_list_voltage_table, + .map_voltage = regulator_map_voltage_iterate, +}; + static struct regulator_ops tps65910_ops = { .is_enabled = regulator_is_enabled_regmap, .enable = regulator_enable_regmap, @@ -944,6 +979,7 @@ static struct of_regulator_match tps65910_matches[] = { { .name = "vaux2", .driver_data = (void *) &tps65910_regs[10] }, { .name = "vaux33", .driver_data = (void *) &tps65910_regs[11] }, { .name = "vmmc", .driver_data = (void *) &tps65910_regs[12] }, + { .name = "vbb", .driver_data = (void *) &tps65910_regs[13] }, }; static struct of_regulator_match tps65911_matches[] = { @@ -1145,6 +1181,10 @@ static int tps65910_probe(struct platform_device *pdev) pmic->desc[i].ops = &tps65910_ops_dcdc; pmic->desc[i].ramp_delay = 5000; } + } else if (i == TPS65910_REG_VBB && + tps65910_chip_id(tps65910) == TPS65910) { + pmic->desc[i].ops = &tps65910_ops_vbb; + pmic->desc[i].volt_table = info->voltage_table; } else { if (tps65910_chip_id(tps65910) == TPS65910) { pmic->desc[i].ops = &tps65910_ops; @@ -1167,7 +1207,21 @@ static int tps65910_probe(struct platform_device *pdev) pmic->desc[i].type = REGULATOR_VOLTAGE; pmic->desc[i].owner = THIS_MODULE; pmic->desc[i].enable_reg = pmic->get_ctrl_reg(i); - pmic->desc[i].enable_mask = TPS65910_SUPPLY_STATE_ENABLED; + + switch (i) { + case TPS65910_REG_VBB: + if (tps65910_chip_id(tps65910) == TPS65910) + pmic->desc[i].enable_mask = BBCH_BBCHEN_MASK; + else + pmic->desc[i].enable_mask = + TPS65910_SUPPLY_STATE_ENABLED; + break; + + default: + pmic->desc[i].enable_mask = + TPS65910_SUPPLY_STATE_ENABLED; + break; + } config.dev = tps65910->dev; config.init_data = reg_data; diff --git a/include/linux/mfd/tps65910.h b/include/linux/mfd/tps65910.h index 20e433e551e3..1adeee186194 100644 --- a/include/linux/mfd/tps65910.h +++ b/include/linux/mfd/tps65910.h @@ -833,6 +833,7 @@ #define TPS65910_REG_VAUX2 10 #define TPS65910_REG_VAUX33 11 #define TPS65910_REG_VMMC 12 +#define TPS65910_REG_VBB 13 #define TPS65911_REG_VDDCTRL 4 #define TPS65911_REG_LDO1 5 @@ -845,7 +846,7 @@ #define TPS65911_REG_LDO8 12 /* Max number of TPS65910/11 regulators */ -#define TPS65910_NUM_REGS 13 +#define TPS65910_NUM_REGS 14 /* External sleep controls through EN1/EN2/EN3/SLEEP inputs */ #define TPS65910_SLEEP_CONTROL_EXT_INPUT_EN1 0x1 -- 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 ++++++++++++++++++++++++++++++++++ include/linux/regulator/act8865.h | 53 +++++ 4 files changed, 430 insertions(+) create mode 100644 drivers/regulator/act8865-regulator.c create mode 100644 include/linux/regulator/act8865.h (limited to 'include') 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"); diff --git a/include/linux/regulator/act8865.h b/include/linux/regulator/act8865.h new file mode 100644 index 000000000000..49206c1b4905 --- /dev/null +++ b/include/linux/regulator/act8865.h @@ -0,0 +1,53 @@ +/* + * act8865.h -- Voltage regulation for the active-semi act8865 + * + * 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; version 2 of the License. + * + * 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. + */ + +#ifndef __LINUX_REGULATOR_ACT8865_H +#define __LINUX_REGULATOR_ACT8865_H + +#include + +enum { + ACT8865_ID_DCDC1, + ACT8865_ID_DCDC2, + ACT8865_ID_DCDC3, + ACT8865_ID_LDO1, + ACT8865_ID_LDO2, + ACT8865_ID_LDO3, + ACT8865_ID_LDO4, + ACT8865_REG_NUM, +}; + +/** + * act8865_regulator_data - regulator data + * @id: regulator id + * @name: regulator name + * @platform_data: regulator init data + */ +struct act8865_regulator_data { + int id; + const char *name; + struct regulator_init_data *platform_data; +}; + +/** + * act8865_platform_data - platform data for act8865 + * @num_regulators: number of regulators used + * @regulators: pointer to regulators used + */ +struct act8865_platform_data { + int num_regulators; + struct act8865_regulator_data *regulators; +}; +#endif -- cgit v1.2.3 From b8903eb9836e4e968d1bf9758b501de2c38cfb83 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Sun, 29 Dec 2013 17:00:20 +0800 Subject: regulator: tps65910: Simplify setting enable_mask for regulators BBCH_BBCHEN_MASK is equivalent to TPS65910_SUPPLY_STATE_ENABLED. So all regulators have the same enable_mask setting. BBCH_BBCHEN_MASK and BBCH_BBCHEN_SHIFT are not used now, remove them. Signed-off-by: Axel Lin Signed-off-by: Mark Brown --- drivers/regulator/tps65910-regulator.c | 16 +--------------- include/linux/mfd/tps65910.h | 2 -- 2 files changed, 1 insertion(+), 17 deletions(-) (limited to 'include') diff --git a/drivers/regulator/tps65910-regulator.c b/drivers/regulator/tps65910-regulator.c index 979ea0a99a79..f50dd847eebc 100644 --- a/drivers/regulator/tps65910-regulator.c +++ b/drivers/regulator/tps65910-regulator.c @@ -1207,21 +1207,7 @@ static int tps65910_probe(struct platform_device *pdev) pmic->desc[i].type = REGULATOR_VOLTAGE; pmic->desc[i].owner = THIS_MODULE; pmic->desc[i].enable_reg = pmic->get_ctrl_reg(i); - - switch (i) { - case TPS65910_REG_VBB: - if (tps65910_chip_id(tps65910) == TPS65910) - pmic->desc[i].enable_mask = BBCH_BBCHEN_MASK; - else - pmic->desc[i].enable_mask = - TPS65910_SUPPLY_STATE_ENABLED; - break; - - default: - pmic->desc[i].enable_mask = - TPS65910_SUPPLY_STATE_ENABLED; - break; - } + pmic->desc[i].enable_mask = TPS65910_SUPPLY_STATE_ENABLED; config.dev = tps65910->dev; config.init_data = reg_data; diff --git a/include/linux/mfd/tps65910.h b/include/linux/mfd/tps65910.h index 1adeee186194..16c2335c2856 100644 --- a/include/linux/mfd/tps65910.h +++ b/include/linux/mfd/tps65910.h @@ -358,8 +358,6 @@ /*Register BBCH (0x80) register.RegisterDescription */ #define BBCH_BBSEL_MASK 0x06 #define BBCH_BBSEL_SHIFT 1 -#define BBCH_BBCHEN_MASK 0x01 -#define BBCH_BBCHEN_SHIFT 0 /*Register DCDCCTRL (0x80) register.RegisterDescription */ -- 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 ++++++++++++++++++++++++++---- include/linux/mfd/as3722.h | 4 ++++ 2 files changed, 30 insertions(+), 4 deletions(-) (limited to 'include') 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; diff --git a/include/linux/mfd/as3722.h b/include/linux/mfd/as3722.h index 16bf8a0dcd97..bb9616dc0efa 100644 --- a/include/linux/mfd/as3722.h +++ b/include/linux/mfd/as3722.h @@ -151,6 +151,7 @@ #define AS3722_ASIC_ID1_REG 0x90 #define AS3722_ASIC_ID2_REG 0x91 #define AS3722_LOCK_REG 0x9E +#define AS3722_FUSE7_REG 0xA7 #define AS3722_MAX_REGISTER 0xF4 #define AS3722_SD0_EXT_ENABLE_MASK 0x03 @@ -224,6 +225,7 @@ #define AS3722_SD_VSEL_MASK 0x7F #define AS3722_SD0_VSEL_MIN 0x01 #define AS3722_SD0_VSEL_MAX 0x5A +#define AS3722_SD0_VSEL_LOW_VOL_MAX 0x6E #define AS3722_SD2_VSEL_MIN 0x01 #define AS3722_SD2_VSEL_MAX 0x7F @@ -341,6 +343,8 @@ #define AS3722_EXT_CONTROL_ENABLE2 0x2 #define AS3722_EXT_CONTROL_ENABLE3 0x3 +#define AS3722_FUSE7_SD0_LOW_VOLTAGE BIT(4) + /* Interrupt IDs */ enum as3722_irq { AS3722_IRQ_LID, -- cgit v1.2.3