From 6219929f5f82708309b3054ec7db6cb6e3ee47d5 Mon Sep 17 00:00:00 2001 From: Laxman Dewangan Date: Mon, 9 Jan 2012 20:27:41 +0530 Subject: regulator: TPS62360: Add tps62360 regulator driver The regulator module consists of 1 DCDC. The output voltage is configurable and is meant for supply power to the core voltage of Soc. Signed-off-by: Laxman Dewangan Signed-off-by: Mark Brown diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig index 7a61b17..b9ad3d8e 100644 --- a/drivers/regulator/Kconfig +++ b/drivers/regulator/Kconfig @@ -328,6 +328,16 @@ config REGULATOR_TPS65910 help This driver supports TPS65910 voltage regulator chips. +config REGULATOR_TPS62360 + tristate "TI TPS62360 Power Regulator" + depends on I2C + select REGMAP_I2C + help + This driver supports TPS62360 voltage regulator chip. This + regulator is meant for processor core supply. This chip is + high-frequency synchronous step down dc-dc converter optimized + for battery-powered portable applications. + config REGULATOR_AAT2870 tristate "AnalogicTech AAT2870 Regulators" depends on MFD_AAT2870_CORE diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile index 503bac8..1668b2e 100644 --- a/drivers/regulator/Makefile +++ b/drivers/regulator/Makefile @@ -47,6 +47,7 @@ obj-$(CONFIG_REGULATOR_ISL6271A) += isl6271a-regulator.o obj-$(CONFIG_REGULATOR_AB8500) += ab8500.o obj-$(CONFIG_REGULATOR_DB8500_PRCMU) += db8500-prcmu.o obj-$(CONFIG_REGULATOR_TPS65910) += tps65910-regulator.o +obj-$(CONFIG_REGULATOR_TPS62360) += tps62360-regulator.o obj-$(CONFIG_REGULATOR_AAT2870) += aat2870-regulator.o ccflags-$(CONFIG_REGULATOR_DEBUG) += -DDEBUG diff --git a/drivers/regulator/tps62360-regulator.c b/drivers/regulator/tps62360-regulator.c new file mode 100644 index 0000000..f778ef0 --- /dev/null +++ b/drivers/regulator/tps62360-regulator.c @@ -0,0 +1,472 @@ +/* + * tps62360.c -- TI tps62360 + * + * Driver for processor core supply tps62360 and tps62361B + * + * Copyright (c) 2012, NVIDIA Corporation. + * + * Author: Laxman Dewangan + * + * 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. + * + * This program is distributed "as is" WITHOUT ANY WARRANTY of any kind, + * whether express or implied; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307, USA + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* Register definitions */ +#define REG_VSET0 0 +#define REG_VSET1 1 +#define REG_VSET2 2 +#define REG_VSET3 3 +#define REG_CONTROL 4 +#define REG_TEMP 5 +#define REG_RAMPCTRL 6 +#define REG_CHIPID 8 + +enum chips {TPS62360, TPS62361}; + +#define TPS62360_BASE_VOLTAGE 770 +#define TPS62360_N_VOLTAGES 64 + +#define TPS62361_BASE_VOLTAGE 500 +#define TPS62361_N_VOLTAGES 128 + +/* tps 62360 chip information */ +struct tps62360_chip { + const char *name; + struct device *dev; + struct regulator_desc desc; + struct i2c_client *client; + struct regulator_dev *rdev; + struct regmap *regmap; + int chip_id; + int vsel0_gpio; + int vsel1_gpio; + int voltage_base; + u8 voltage_reg_mask; + bool en_internal_pulldn; + bool en_force_pwm; + bool en_discharge; + bool valid_gpios; + int lru_index[4]; + int curr_vset_vsel[4]; + int curr_vset_id; +}; + +/* + * find_voltage_set_register: Find new voltage configuration register + * (VSET) id. + * The finding of the new VSET register will be based on the LRU mechanism. + * Each VSET register will have different voltage configured . This + * Function will look if any of the VSET register have requested voltage set + * or not. + * - If it is already there then it will make that register as most + * recently used and return as found so that caller need not to set + * the VSET register but need to set the proper gpios to select this + * VSET register. + * - If requested voltage is not found then it will use the least + * recently mechanism to get new VSET register for new configuration + * and will return not_found so that caller need to set new VSET + * register and then gpios (both). + */ +static bool find_voltage_set_register(struct tps62360_chip *tps, + int req_vsel, int *vset_reg_id) +{ + int i; + bool found = false; + int new_vset_reg = tps->lru_index[3]; + int found_index = 3; + for (i = 0; i < 4; ++i) { + if (tps->curr_vset_vsel[tps->lru_index[i]] == req_vsel) { + new_vset_reg = tps->lru_index[i]; + found_index = i; + found = true; + goto update_lru_index; + } + } + +update_lru_index: + for (i = found_index; i > 0; i--) + tps->lru_index[i] = tps->lru_index[i - 1]; + + tps->lru_index[0] = new_vset_reg; + *vset_reg_id = new_vset_reg; + return found; +} + +static int tps62360_dcdc_get_voltage(struct regulator_dev *dev) +{ + struct tps62360_chip *tps = rdev_get_drvdata(dev); + int vsel; + unsigned int data; + int ret; + + ret = regmap_read(tps->regmap, REG_VSET0 + tps->curr_vset_id, &data); + if (ret < 0) { + dev_err(tps->dev, "%s: Error in reading register %d\n", + __func__, REG_VSET0 + tps->curr_vset_id); + return ret; + } + vsel = (int)data & tps->voltage_reg_mask; + return (tps->voltage_base + vsel * 10) * 1000; +} + +static int tps62360_dcdc_set_voltage(struct regulator_dev *dev, + int min_uV, int max_uV, unsigned *selector) +{ + struct tps62360_chip *tps = rdev_get_drvdata(dev); + int vsel; + int ret; + bool found = false; + int new_vset_id = tps->curr_vset_id; + + if (max_uV < min_uV) + return -EINVAL; + + if (min_uV > + ((tps->voltage_base + (tps->desc.n_voltages - 1) * 10) * 1000)) + return -EINVAL; + + if (max_uV < tps->voltage_base * 1000) + return -EINVAL; + + vsel = DIV_ROUND_UP(min_uV - (tps->voltage_base * 1000), 10000); + if (selector) + *selector = (vsel & tps->voltage_reg_mask); + + /* + * If gpios are available to select the VSET register then least + * recently used register for new configuration. + */ + if (tps->valid_gpios) + found = find_voltage_set_register(tps, vsel, &new_vset_id); + + if (!found) { + ret = regmap_update_bits(tps->regmap, REG_VSET0 + new_vset_id, + tps->voltage_reg_mask, vsel); + if (ret < 0) { + dev_err(tps->dev, "%s: Error in updating register %d\n", + __func__, REG_VSET0 + new_vset_id); + return ret; + } + tps->curr_vset_id = new_vset_id; + tps->curr_vset_vsel[new_vset_id] = vsel; + } + + /* Select proper VSET register vio gpios */ + if (tps->valid_gpios) { + gpio_set_value_cansleep(tps->vsel0_gpio, + new_vset_id & 0x1); + gpio_set_value_cansleep(tps->vsel1_gpio, + (new_vset_id >> 1) & 0x1); + } + return 0; +} + +static int tps62360_dcdc_list_voltage(struct regulator_dev *dev, + unsigned selector) +{ + struct tps62360_chip *tps = rdev_get_drvdata(dev); + + if ((selector < 0) || (selector >= tps->desc.n_voltages)) + return -EINVAL; + return (tps->voltage_base + selector * 10) * 1000; +} + +static struct regulator_ops tps62360_dcdc_ops = { + .get_voltage = tps62360_dcdc_get_voltage, + .set_voltage = tps62360_dcdc_set_voltage, + .list_voltage = tps62360_dcdc_list_voltage, +}; + +static int tps62360_init_force_pwm(struct tps62360_chip *tps, + struct tps62360_regulator_platform_data *pdata, + int vset_id) +{ + unsigned int data; + int ret; + ret = regmap_read(tps->regmap, REG_VSET0 + vset_id, &data); + if (ret < 0) { + dev_err(tps->dev, "%s() fails in writing reg %d\n", + __func__, REG_VSET0 + vset_id); + return ret; + } + tps->curr_vset_vsel[vset_id] = data & tps->voltage_reg_mask; + if (pdata->en_force_pwm) + data |= BIT(7); + else + data &= ~BIT(7); + ret = regmap_write(tps->regmap, REG_VSET0 + vset_id, data); + if (ret < 0) + dev_err(tps->dev, "%s() fails in writing reg %d\n", + __func__, REG_VSET0 + vset_id); + return ret; +} + +static int tps62360_init_dcdc(struct tps62360_chip *tps, + struct tps62360_regulator_platform_data *pdata) +{ + int ret; + int i; + + /* Initailize internal pull up/down control */ + if (tps->en_internal_pulldn) + ret = regmap_write(tps->regmap, REG_CONTROL, 0xE0); + else + ret = regmap_write(tps->regmap, REG_CONTROL, 0x0); + if (ret < 0) { + dev_err(tps->dev, "%s() fails in writing reg %d\n", + __func__, REG_CONTROL); + return ret; + } + + /* Initailize force PWM mode */ + if (tps->valid_gpios) { + for (i = 0; i < 4; ++i) { + ret = tps62360_init_force_pwm(tps, pdata, i); + if (ret < 0) + return ret; + } + } else { + ret = tps62360_init_force_pwm(tps, pdata, tps->curr_vset_id); + if (ret < 0) + return ret; + } + + /* Reset output discharge path to reduce power consumption */ + ret = regmap_update_bits(tps->regmap, REG_RAMPCTRL, BIT(2), 0); + if (ret < 0) + dev_err(tps->dev, "%s() fails in updating reg %d\n", + __func__, REG_RAMPCTRL); + return ret; +} + +static const struct regmap_config tps62360_regmap_config = { + .reg_bits = 8, + .val_bits = 8, +}; + +static int __devinit tps62360_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct tps62360_regulator_platform_data *pdata; + struct regulator_dev *rdev; + struct tps62360_chip *tps; + int ret; + int i; + + pdata = client->dev.platform_data; + if (!pdata) { + dev_err(&client->dev, "%s() Err: Platform data not found\n", + __func__); + return -EIO; + } + + tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL); + if (!tps) { + dev_err(&client->dev, "%s() Err: Memory allocation fails\n", + __func__); + return -ENOMEM; + } + + tps->en_force_pwm = pdata->en_force_pwm; + tps->en_discharge = pdata->en_discharge; + tps->en_internal_pulldn = pdata->en_internal_pulldn; + tps->vsel0_gpio = pdata->vsel0_gpio; + tps->vsel1_gpio = pdata->vsel1_gpio; + tps->client = client; + tps->dev = &client->dev; + tps->name = id->name; + tps->voltage_base = (id->driver_data == TPS62360) ? + TPS62360_BASE_VOLTAGE : TPS62361_BASE_VOLTAGE; + tps->voltage_reg_mask = (id->driver_data == TPS62360) ? 0x3F : 0x7F; + + tps->desc.name = id->name; + tps->desc.id = 0; + tps->desc.n_voltages = (id->driver_data == TPS62360) ? + TPS62360_N_VOLTAGES : TPS62361_N_VOLTAGES; + tps->desc.ops = &tps62360_dcdc_ops; + tps->desc.type = REGULATOR_VOLTAGE; + tps->desc.owner = THIS_MODULE; + tps->regmap = regmap_init_i2c(client, &tps62360_regmap_config); + if (IS_ERR(tps->regmap)) { + ret = PTR_ERR(tps->regmap); + dev_err(&client->dev, "%s() Err: Failed to allocate register" + "map: %d\n", __func__, ret); + return ret; + } + i2c_set_clientdata(client, tps); + + tps->curr_vset_id = (pdata->vsel1_def_state & 1) * 2 + + (pdata->vsel0_def_state & 1); + tps->lru_index[0] = tps->curr_vset_id; + tps->valid_gpios = false; + + if (gpio_is_valid(tps->vsel0_gpio) && gpio_is_valid(tps->vsel1_gpio)) { + ret = gpio_request(tps->vsel0_gpio, "tps62360-vsel0"); + if (ret) { + dev_err(&client->dev, + "Err: Could not obtain vsel0 GPIO %d: %d\n", + tps->vsel0_gpio, ret); + goto err_gpio0; + } + ret = gpio_direction_output(tps->vsel0_gpio, + pdata->vsel0_def_state); + if (ret) { + dev_err(&client->dev, "Err: Could not set direction of" + "vsel0 GPIO %d: %d\n", tps->vsel0_gpio, ret); + gpio_free(tps->vsel0_gpio); + goto err_gpio0; + } + + ret = gpio_request(tps->vsel1_gpio, "tps62360-vsel1"); + if (ret) { + dev_err(&client->dev, + "Err: Could not obtain vsel1 GPIO %d: %d\n", + tps->vsel1_gpio, ret); + goto err_gpio1; + } + ret = gpio_direction_output(tps->vsel1_gpio, + pdata->vsel1_def_state); + if (ret) { + dev_err(&client->dev, "Err: Could not set direction of" + "vsel1 GPIO %d: %d\n", tps->vsel1_gpio, ret); + gpio_free(tps->vsel1_gpio); + goto err_gpio1; + } + tps->valid_gpios = true; + + /* + * Initialize the lru index with vset_reg id + * The index 0 will be most recently used and + * set with the tps->curr_vset_id */ + for (i = 0; i < 4; ++i) + tps->lru_index[i] = i; + tps->lru_index[0] = tps->curr_vset_id; + tps->lru_index[tps->curr_vset_id] = 0; + } + + ret = tps62360_init_dcdc(tps, pdata); + if (ret < 0) { + dev_err(tps->dev, "%s() Err: Init fails with = %d\n", + __func__, ret); + goto err_init; + } + + /* Register the regulators */ + rdev = regulator_register(&tps->desc, &client->dev, + &pdata->reg_init_data, tps, NULL); + if (IS_ERR(rdev)) { + dev_err(tps->dev, "%s() Err: Failed to register %s\n", + __func__, id->name); + ret = PTR_ERR(rdev); + goto err_init; + } + + tps->rdev = rdev; + return 0; + +err_init: + if (gpio_is_valid(tps->vsel1_gpio)) + gpio_free(tps->vsel1_gpio); +err_gpio1: + if (gpio_is_valid(tps->vsel0_gpio)) + gpio_free(tps->vsel0_gpio); +err_gpio0: + regmap_exit(tps->regmap); + return ret; +} + +/** + * tps62360_remove - tps62360 driver i2c remove handler + * @client: i2c driver client device structure + * + * Unregister TPS driver as an i2c client device driver + */ +static int __devexit tps62360_remove(struct i2c_client *client) +{ + struct tps62360_chip *tps = i2c_get_clientdata(client); + + if (gpio_is_valid(tps->vsel1_gpio)) + gpio_free(tps->vsel1_gpio); + + if (gpio_is_valid(tps->vsel0_gpio)) + gpio_free(tps->vsel0_gpio); + + regulator_unregister(tps->rdev); + regmap_exit(tps->regmap); + return 0; +} + +static void tps62360_shutdown(struct i2c_client *client) +{ + struct tps62360_chip *tps = i2c_get_clientdata(client); + int st; + + if (!tps->en_discharge) + return; + + /* Configure the output discharge path */ + st = regmap_update_bits(tps->regmap, REG_RAMPCTRL, BIT(2), BIT(2)); + if (st < 0) + dev_err(tps->dev, "%s() fails in updating reg %d\n", + __func__, REG_RAMPCTRL); +} + +static const struct i2c_device_id tps62360_id[] = { + {.name = "tps62360", .driver_data = TPS62360}, + {.name = "tps62361", .driver_data = TPS62361}, + {}, +}; + +MODULE_DEVICE_TABLE(i2c, tps62360_id); + +static struct i2c_driver tps62360_i2c_driver = { + .driver = { + .name = "tps62360", + .owner = THIS_MODULE, + }, + .probe = tps62360_probe, + .remove = __devexit_p(tps62360_remove), + .shutdown = tps62360_shutdown, + .id_table = tps62360_id, +}; + +static int __init tps62360_init(void) +{ + return i2c_add_driver(&tps62360_i2c_driver); +} +subsys_initcall(tps62360_init); + +static void __exit tps62360_cleanup(void) +{ + i2c_del_driver(&tps62360_i2c_driver); +} +module_exit(tps62360_cleanup); + +MODULE_AUTHOR("Laxman Dewangan "); +MODULE_DESCRIPTION("TPS62360 voltage regulator driver"); +MODULE_LICENSE("GPL v2"); diff --git a/include/linux/regulator/tps62360.h b/include/linux/regulator/tps62360.h new file mode 100644 index 0000000..6a5c1b2 --- /dev/null +++ b/include/linux/regulator/tps62360.h @@ -0,0 +1,57 @@ +/* + * tps62360.h -- TI tps62360 + * + * Interface for regulator driver for TI TPS62360 Processor core supply + * + * Copyright (C) 2012 NVIDIA Corporation + + * Author: Laxman Dewangan + * + * 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. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#ifndef __LINUX_REGULATOR_TPS62360_H +#define __LINUX_REGULATOR_TPS62360_H + +#include + +/* + * struct tps62360_regulator_platform_data - tps62360 regulator platform data. + * + * @reg_init_data: The regulator init data. + * @en_force_pwm: Enable force pwm or not. + * @en_discharge: Enable discharge the output capacitor via internal + * register. + * @en_internal_pulldn: internal pull down enable or not. + * @vsel0_gpio: Gpio number for vsel0. It should be -1 if this is tied with + * fixed logic. + * @vsel1_gpio: Gpio number for vsel1. It should be -1 if this is tied with + * fixed logic. + * @vsel0_def_state: Default state of vsel0. 1 if it is high else 0. + * @vsel1_def_state: Default state of vsel1. 1 if it is high else 0. + */ +struct tps62360_regulator_platform_data { + struct regulator_init_data reg_init_data; + bool en_force_pwm; + bool en_discharge; + bool en_internal_pulldn; + int vsel0_gpio; + int vsel1_gpio; + int vsel0_def_state; + int vsel1_def_state; +}; + +#endif /* __LINUX_REGULATOR_TPS62360_H */ -- cgit v0.10.2 From 9767ec7fe8d9bf00e764f1d0ca0176988255be11 Mon Sep 17 00:00:00 2001 From: Sangbeom Kim Date: Mon, 9 Jan 2012 19:10:25 +0900 Subject: regulator: Add S5M8767A regulator driver S5M8767A is a cost-effective PMIC which is designed for mobile applications. It includes high efficient 9 Buck converters, 28 LDOs. Especially, S5M8767A is optimized for Multi-core SOCs. And during DVFS operation, S5M8767A output stable voltage. This patch implement regulator driver for S5M8767A. Signed-off-by: Sangbeom Kim Signed-off-by: Mark Brown diff --git a/drivers/regulator/s5m8767.c b/drivers/regulator/s5m8767.c new file mode 100644 index 0000000..b3d356f --- /dev/null +++ b/drivers/regulator/s5m8767.c @@ -0,0 +1,834 @@ +/* + * s5m8767.c + * + * Copyright (c) 2011 Samsung Electronics Co., Ltd + * http://www.samsung.com + * + * 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. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct s5m8767_info { + struct device *dev; + struct s5m87xx_dev *iodev; + int num_regulators; + struct regulator_dev **rdev; + + int ramp_delay; + bool buck2_ramp; + bool buck3_ramp; + bool buck4_ramp; + + bool buck2_gpiodvs; + bool buck3_gpiodvs; + bool buck4_gpiodvs; + u8 buck2_vol[8]; + u8 buck3_vol[8]; + u8 buck4_vol[8]; + int buck_gpios[3]; + int buck_gpioindex; +}; + +struct s5m_voltage_desc { + int max; + int min; + int step; +}; + +static const struct s5m_voltage_desc buck_voltage_val1 = { + .max = 2225000, + .min = 650000, + .step = 6250, +}; + +static const struct s5m_voltage_desc buck_voltage_val2 = { + .max = 1600000, + .min = 600000, + .step = 6250, +}; + +static const struct s5m_voltage_desc buck_voltage_val3 = { + .max = 3000000, + .min = 750000, + .step = 12500, +}; + +static const struct s5m_voltage_desc ldo_voltage_val1 = { + .max = 3950000, + .min = 800000, + .step = 50000, +}; + +static const struct s5m_voltage_desc ldo_voltage_val2 = { + .max = 2375000, + .min = 800000, + .step = 25000, +}; + +static const struct s5m_voltage_desc *reg_voltage_map[] = { + [S5M8767_LDO1] = &ldo_voltage_val2, + [S5M8767_LDO2] = &ldo_voltage_val2, + [S5M8767_LDO3] = &ldo_voltage_val1, + [S5M8767_LDO4] = &ldo_voltage_val1, + [S5M8767_LDO5] = &ldo_voltage_val1, + [S5M8767_LDO6] = &ldo_voltage_val2, + [S5M8767_LDO7] = &ldo_voltage_val2, + [S5M8767_LDO8] = &ldo_voltage_val2, + [S5M8767_LDO9] = &ldo_voltage_val1, + [S5M8767_LDO10] = &ldo_voltage_val1, + [S5M8767_LDO11] = &ldo_voltage_val1, + [S5M8767_LDO12] = &ldo_voltage_val1, + [S5M8767_LDO13] = &ldo_voltage_val1, + [S5M8767_LDO14] = &ldo_voltage_val1, + [S5M8767_LDO15] = &ldo_voltage_val2, + [S5M8767_LDO16] = &ldo_voltage_val1, + [S5M8767_LDO17] = &ldo_voltage_val1, + [S5M8767_LDO18] = &ldo_voltage_val1, + [S5M8767_LDO19] = &ldo_voltage_val1, + [S5M8767_LDO20] = &ldo_voltage_val1, + [S5M8767_LDO21] = &ldo_voltage_val1, + [S5M8767_LDO22] = &ldo_voltage_val1, + [S5M8767_LDO23] = &ldo_voltage_val1, + [S5M8767_LDO24] = &ldo_voltage_val1, + [S5M8767_LDO25] = &ldo_voltage_val1, + [S5M8767_LDO26] = &ldo_voltage_val1, + [S5M8767_LDO27] = &ldo_voltage_val1, + [S5M8767_LDO28] = &ldo_voltage_val1, + [S5M8767_BUCK1] = &buck_voltage_val1, + [S5M8767_BUCK2] = &buck_voltage_val2, + [S5M8767_BUCK3] = &buck_voltage_val2, + [S5M8767_BUCK4] = &buck_voltage_val2, + [S5M8767_BUCK5] = &buck_voltage_val1, + [S5M8767_BUCK6] = &buck_voltage_val1, + [S5M8767_BUCK7] = NULL, + [S5M8767_BUCK8] = NULL, + [S5M8767_BUCK9] = &buck_voltage_val3, +}; + +static inline int s5m8767_get_reg_id(struct regulator_dev *rdev) +{ + return rdev_get_id(rdev); +} + +static int s5m8767_list_voltage(struct regulator_dev *rdev, + unsigned int selector) +{ + const struct s5m_voltage_desc *desc; + int reg_id = s5m8767_get_reg_id(rdev); + int val; + + if (reg_id >= ARRAY_SIZE(reg_voltage_map) || reg_id < 0) + return -EINVAL; + + desc = reg_voltage_map[reg_id]; + if (desc == NULL) + return -EINVAL; + + val = desc->min + desc->step * selector; + if (val > desc->max) + return -EINVAL; + + return val; +} + +static int s5m8767_get_register(struct regulator_dev *rdev, int *reg) +{ + int reg_id = s5m8767_get_reg_id(rdev); + + switch (reg_id) { + case S5M8767_LDO1 ... S5M8767_LDO2: + *reg = S5M8767_REG_LDO1CTRL + (reg_id - S5M8767_LDO1); + break; + case S5M8767_LDO3 ... S5M8767_LDO28: + *reg = S5M8767_REG_LDO3CTRL + (reg_id - S5M8767_LDO3); + break; + case S5M8767_BUCK1: + *reg = S5M8767_REG_BUCK1CTRL1; + break; + case S5M8767_BUCK2 ... S5M8767_BUCK4: + *reg = S5M8767_REG_BUCK2CTRL + (reg_id - S5M8767_BUCK2) * 9; + break; + case S5M8767_BUCK5: + *reg = S5M8767_REG_BUCK5CTRL1; + break; + case S5M8767_BUCK6 ... S5M8767_BUCK9: + *reg = S5M8767_REG_BUCK6CTRL1 + (reg_id - S5M8767_BUCK6) * 2; + break; + default: + return -EINVAL; + } + + return 0; +} + +static int s5m8767_reg_is_enabled(struct regulator_dev *rdev) +{ + struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev); + int ret, reg; + int mask = 0xc0, pattern = 0xc0; + u8 val; + + ret = s5m8767_get_register(rdev, ®); + if (ret == -EINVAL) + return 1; + else if (ret) + return ret; + + ret = s5m_reg_read(s5m8767->iodev, reg, &val); + if (ret) + return ret; + + return (val & mask) == pattern; +} + +static int s5m8767_reg_enable(struct regulator_dev *rdev) +{ + struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev); + int ret, reg; + int mask = 0xc0, pattern = 0xc0; + + ret = s5m8767_get_register(rdev, ®); + if (ret) + return ret; + + return s5m_reg_update(s5m8767->iodev, reg, pattern, mask); +} + +static int s5m8767_reg_disable(struct regulator_dev *rdev) +{ + struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev); + int ret, reg; + int mask = 0xc0, pattern = 0xc0; + + ret = s5m8767_get_register(rdev, ®); + if (ret) + return ret; + + return s5m_reg_update(s5m8767->iodev, reg, ~pattern, mask); +} + +static int s5m8767_get_voltage_register(struct regulator_dev *rdev, int *_reg) +{ + int reg_id = s5m8767_get_reg_id(rdev); + int reg; + + switch (reg_id) { + case S5M8767_LDO1 ... S5M8767_LDO2: + reg = S5M8767_REG_LDO1CTRL + (reg_id - S5M8767_LDO1); + break; + case S5M8767_LDO3 ... S5M8767_LDO28: + reg = S5M8767_REG_LDO3CTRL + (reg_id - S5M8767_LDO3); + break; + case S5M8767_BUCK1: + reg = S5M8767_REG_BUCK1CTRL2; + break; + case S5M8767_BUCK2: + reg = S5M8767_REG_BUCK2DVS1; + break; + case S5M8767_BUCK3: + reg = S5M8767_REG_BUCK3DVS1; + break; + case S5M8767_BUCK4: + reg = S5M8767_REG_BUCK4DVS1; + break; + case S5M8767_BUCK5: + reg = S5M8767_REG_BUCK5CTRL2; + break; + case S5M8767_BUCK6 ... S5M8767_BUCK9: + reg = S5M8767_REG_BUCK6CTRL2 + (reg_id - S5M8767_BUCK6) * 2; + break; + default: + return -EINVAL; + } + + *_reg = reg; + + return 0; +} + +static int s5m8767_get_voltage_sel(struct regulator_dev *rdev) +{ + struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev); + int reg, mask = 0xff, ret; + int reg_id = s5m8767_get_reg_id(rdev); + u8 val; + + ret = s5m8767_get_voltage_register(rdev, ®); + if (ret) + return ret; + + switch (reg_id) { + case S5M8767_LDO1 ... S5M8767_LDO28: + mask = 0x3f; + break; + case S5M8767_BUCK2: + if (s5m8767->buck2_gpiodvs) + reg += s5m8767->buck_gpioindex; + break; + case S5M8767_BUCK3: + if (s5m8767->buck3_gpiodvs) + reg += s5m8767->buck_gpioindex; + break; + case S5M8767_BUCK4: + if (s5m8767->buck4_gpiodvs) + reg += s5m8767->buck_gpioindex; + break; + } + + ret = s5m_reg_read(s5m8767->iodev, reg, &val); + if (ret) + return ret; + + val &= mask; + + return val; +} + +static inline int s5m8767_convert_voltage( + const struct s5m_voltage_desc *desc, + int min_vol, int max_vol) +{ + int out_vol = 0; + + if (desc == NULL) + return -EINVAL; + + if (max_vol < desc->min || min_vol > desc->max) + return -EINVAL; + + out_vol = (min_vol - desc->min) / desc->step; + + if (desc->min + desc->step * out_vol > max_vol) + return -EINVAL; + + return out_vol; +} + +static int s5m8767_set_voltage(struct regulator_dev *rdev, + int min_uV, int max_uV, unsigned *selector) +{ + struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev); + int min_vol = min_uV, max_vol = max_uV; + const struct s5m_voltage_desc *desc; + int reg_id = s5m8767_get_reg_id(rdev); + int reg, mask, ret; + int i; + u8 val; + + switch (reg_id) { + case S5M8767_LDO1 ... S5M8767_LDO28: + mask = 0x3f; + break; + case S5M8767_BUCK1 ... S5M8767_BUCK6: + mask = 0xff; + break; + case S5M8767_BUCK7 ... S5M8767_BUCK8: + return -EINVAL; + case S5M8767_BUCK9: + mask = 0xff; + break; + default: + return -EINVAL; + } + + desc = reg_voltage_map[reg_id]; + + i = s5m8767_convert_voltage(desc, min_vol, max_vol); + if (i < 0) + return i; + + ret = s5m8767_get_voltage_register(rdev, ®); + if (ret) + return ret; + + s5m_reg_read(s5m8767->iodev, reg, &val); + val = val & mask; + + ret = s5m_reg_write(s5m8767->iodev, reg, val); + *selector = i; + + return ret; +} + +static inline void s5m8767_set_high(struct s5m8767_info *s5m8767) +{ + int temp_index = s5m8767->buck_gpioindex; + + gpio_set_value(s5m8767->buck_gpios[0], (temp_index >> 2) & 0x1); + gpio_set_value(s5m8767->buck_gpios[1], (temp_index >> 1) & 0x1); + gpio_set_value(s5m8767->buck_gpios[2], temp_index & 0x1); +} + +static inline void s5m8767_set_low(struct s5m8767_info *s5m8767) +{ + int temp_index = s5m8767->buck_gpioindex; + + gpio_set_value(s5m8767->buck_gpios[2], temp_index & 0x1); + gpio_set_value(s5m8767->buck_gpios[1], (temp_index >> 1) & 0x1); + gpio_set_value(s5m8767->buck_gpios[0], (temp_index >> 2) & 0x1); +} + +static int s5m8767_set_voltage_buck(struct regulator_dev *rdev, + int min_uV, int max_uV, unsigned *selector) +{ + struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev); + int reg_id = s5m8767_get_reg_id(rdev); + const struct s5m_voltage_desc *desc; + int new_val, old_val, i = 0; + int min_vol = min_uV, max_vol = max_uV; + + if (reg_id < S5M8767_BUCK1 || reg_id > S5M8767_BUCK6) + return -EINVAL; + + switch (reg_id) { + case S5M8767_BUCK1: + return s5m8767_set_voltage(rdev, min_uV, max_uV, selector); + case S5M8767_BUCK2 ... S5M8767_BUCK4: + break; + case S5M8767_BUCK5 ... S5M8767_BUCK6: + return s5m8767_set_voltage(rdev, min_uV, max_uV, selector); + case S5M8767_BUCK9: + return s5m8767_set_voltage(rdev, min_uV, max_uV, selector); + } + + desc = reg_voltage_map[reg_id]; + new_val = s5m8767_convert_voltage(desc, min_vol, max_vol); + if (new_val < 0) + return new_val; + + switch (reg_id) { + case S5M8767_BUCK2: + if (s5m8767->buck2_gpiodvs) { + while (s5m8767->buck2_vol[i] != new_val) + i++; + } else + return s5m8767_set_voltage(rdev, min_uV, + max_uV, selector); + break; + case S5M8767_BUCK3: + if (s5m8767->buck3_gpiodvs) { + while (s5m8767->buck3_vol[i] != new_val) + i++; + } else + return s5m8767_set_voltage(rdev, min_uV, + max_uV, selector); + break; + case S5M8767_BUCK4: + if (s5m8767->buck3_gpiodvs) { + while (s5m8767->buck4_vol[i] != new_val) + i++; + } else + return s5m8767_set_voltage(rdev, min_uV, + max_uV, selector); + break; + } + + old_val = s5m8767->buck_gpioindex; + s5m8767->buck_gpioindex = i; + + if (i > old_val) + s5m8767_set_high(s5m8767); + else + s5m8767_set_low(s5m8767); + + *selector = new_val; + return 0; +} + +static int s5m8767_set_voltage_time_sel(struct regulator_dev *rdev, + unsigned int old_sel, + unsigned int new_sel) +{ + struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev); + const struct s5m_voltage_desc *desc; + int reg_id = s5m8767_get_reg_id(rdev); + int mask; + int new_val, old_val; + + switch (reg_id) { + case S5M8767_LDO1 ... S5M8767_LDO28: + mask = 0x3f; + break; + case S5M8767_BUCK1 ... S5M8767_BUCK6: + mask = 0xff; + break; + case S5M8767_BUCK7 ... S5M8767_BUCK8: + return -EINVAL; + case S5M8767_BUCK9: + mask = 0xff; + break; + default: + return -EINVAL; + } + desc = reg_voltage_map[reg_id]; + + new_val = s5m8767_convert_voltage(desc, new_sel, new_sel); + if (new_val < 0) + return new_val; + + old_val = s5m8767_convert_voltage(desc, old_sel, old_sel); + if (old_val < 0) + return old_val; + + if (old_sel < new_sel) + return DIV_ROUND_UP(desc->step * (new_val - old_val), + s5m8767->ramp_delay); + else + return 0; +} + +static struct regulator_ops s5m8767_ldo_ops = { + .list_voltage = s5m8767_list_voltage, + .is_enabled = s5m8767_reg_is_enabled, + .enable = s5m8767_reg_enable, + .disable = s5m8767_reg_disable, + .get_voltage_sel = s5m8767_get_voltage_sel, + .set_voltage = s5m8767_set_voltage, + .set_voltage_time_sel = s5m8767_set_voltage_time_sel, +}; + +static struct regulator_ops s5m8767_buck_ops = { + .list_voltage = s5m8767_list_voltage, + .is_enabled = s5m8767_reg_is_enabled, + .enable = s5m8767_reg_enable, + .disable = s5m8767_reg_disable, + .get_voltage_sel = s5m8767_get_voltage_sel, + .set_voltage = s5m8767_set_voltage_buck, + .set_voltage_time_sel = s5m8767_set_voltage_time_sel, +}; + +#define regulator_desc_ldo(num) { \ + .name = "LDO"#num, \ + .id = S5M8767_LDO##num, \ + .ops = &s5m8767_ldo_ops, \ + .type = REGULATOR_VOLTAGE, \ + .owner = THIS_MODULE, \ +} +#define regulator_desc_buck(num) { \ + .name = "BUCK"#num, \ + .id = S5M8767_BUCK##num, \ + .ops = &s5m8767_buck_ops, \ + .type = REGULATOR_VOLTAGE, \ + .owner = THIS_MODULE, \ +} + +static struct regulator_desc regulators[] = { + regulator_desc_ldo(1), + regulator_desc_ldo(2), + regulator_desc_ldo(3), + regulator_desc_ldo(4), + regulator_desc_ldo(5), + regulator_desc_ldo(6), + regulator_desc_ldo(7), + regulator_desc_ldo(8), + regulator_desc_ldo(9), + regulator_desc_ldo(10), + regulator_desc_ldo(11), + regulator_desc_ldo(12), + regulator_desc_ldo(13), + regulator_desc_ldo(14), + regulator_desc_ldo(15), + regulator_desc_ldo(16), + regulator_desc_ldo(17), + regulator_desc_ldo(18), + regulator_desc_ldo(19), + regulator_desc_ldo(20), + regulator_desc_ldo(21), + regulator_desc_ldo(22), + regulator_desc_ldo(23), + regulator_desc_ldo(24), + regulator_desc_ldo(25), + regulator_desc_ldo(26), + regulator_desc_ldo(27), + regulator_desc_ldo(28), + regulator_desc_buck(1), + regulator_desc_buck(2), + regulator_desc_buck(3), + regulator_desc_buck(4), + regulator_desc_buck(5), + regulator_desc_buck(6), + regulator_desc_buck(7), + regulator_desc_buck(8), + regulator_desc_buck(9), +}; + +static __devinit int s5m8767_pmic_probe(struct platform_device *pdev) +{ + struct s5m87xx_dev *iodev = dev_get_drvdata(pdev->dev.parent); + struct s5m_platform_data *pdata = dev_get_platdata(iodev->dev); + struct regulator_dev **rdev; + struct s5m8767_info *s5m8767; + struct i2c_client *i2c; + int i, ret, size, reg; + + if (!pdata) { + dev_err(pdev->dev.parent, "Platform data not supplied\n"); + return -ENODEV; + } + + s5m8767 = devm_kzalloc(&pdev->dev, sizeof(struct s5m8767_info), + GFP_KERNEL); + if (!s5m8767) + return -ENOMEM; + + size = sizeof(struct regulator_dev *) * (S5M8767_REG_MAX - 2); + s5m8767->rdev = devm_kzalloc(&pdev->dev, size, GFP_KERNEL); + if (!s5m8767->rdev) + return -ENOMEM; + + rdev = s5m8767->rdev; + s5m8767->dev = &pdev->dev; + s5m8767->iodev = iodev; + s5m8767->num_regulators = S5M8767_REG_MAX - 2; + platform_set_drvdata(pdev, s5m8767); + i2c = s5m8767->iodev->i2c; + + s5m8767->buck_gpioindex = pdata->buck_default_idx; + s5m8767->buck2_gpiodvs = pdata->buck2_gpiodvs; + s5m8767->buck3_gpiodvs = pdata->buck3_gpiodvs; + s5m8767->buck4_gpiodvs = pdata->buck4_gpiodvs; + s5m8767->buck_gpios[0] = pdata->buck_gpios[0]; + s5m8767->buck_gpios[1] = pdata->buck_gpios[1]; + s5m8767->buck_gpios[2] = pdata->buck_gpios[2]; + s5m8767->ramp_delay = pdata->buck_ramp_delay; + s5m8767->buck2_ramp = pdata->buck2_ramp_enable; + s5m8767->buck3_ramp = pdata->buck3_ramp_enable; + s5m8767->buck4_ramp = pdata->buck4_ramp_enable; + + for (i = 0; i < 8; i++) { + if (s5m8767->buck2_gpiodvs) { + s5m8767->buck2_vol[i] = + s5m8767_convert_voltage( + &buck_voltage_val2, + pdata->buck2_voltage[i], + pdata->buck2_voltage[i] + + buck_voltage_val2.step); + } + + if (s5m8767->buck3_gpiodvs) { + s5m8767->buck3_vol[i] = + s5m8767_convert_voltage( + &buck_voltage_val2, + pdata->buck3_voltage[i], + pdata->buck3_voltage[i] + + buck_voltage_val2.step); + } + + if (s5m8767->buck4_gpiodvs) { + s5m8767->buck4_vol[i] = + s5m8767_convert_voltage( + &buck_voltage_val2, + pdata->buck4_voltage[i], + pdata->buck4_voltage[i] + + buck_voltage_val2.step); + } + } + + if (pdata->buck2_gpiodvs || pdata->buck3_gpiodvs || + pdata->buck4_gpiodvs) { + if (gpio_is_valid(pdata->buck_gpios[0]) && + gpio_is_valid(pdata->buck_gpios[1]) && + gpio_is_valid(pdata->buck_gpios[2])) { + ret = gpio_request(pdata->buck_gpios[0], + "S5M8767 SET1"); + if (ret == -EBUSY) + dev_warn(&pdev->dev, "Duplicated gpio request for SET1\n"); + + ret = gpio_request(pdata->buck_gpios[1], + "S5M8767 SET2"); + if (ret == -EBUSY) + dev_warn(&pdev->dev, "Duplicated gpio request for SET2\n"); + + ret = gpio_request(pdata->buck_gpios[2], + "S5M8767 SET3"); + if (ret == -EBUSY) + dev_warn(&pdev->dev, "Duplicated gpio request for SET3\n"); + /* SET1 GPIO */ + gpio_direction_output(pdata->buck_gpios[0], + (s5m8767->buck_gpioindex >> 2) & 0x1); + /* SET2 GPIO */ + gpio_direction_output(pdata->buck_gpios[1], + (s5m8767->buck_gpioindex >> 1) & 0x1); + /* SET3 GPIO */ + gpio_direction_output(pdata->buck_gpios[2], + (s5m8767->buck_gpioindex >> 0) & 0x1); + ret = 0; + } else { + dev_err(&pdev->dev, "GPIO NOT VALID\n"); + ret = -EINVAL; + return ret; + } + } + + if (pdata->buck2_gpiodvs) { + if (pdata->buck3_gpiodvs || pdata->buck4_gpiodvs) { + dev_err(&pdev->dev, "S5M8767 GPIO DVS NOT VALID\n"); + ret = -EINVAL; + return ret; + } + } + + if (pdata->buck3_gpiodvs) { + if (pdata->buck2_gpiodvs || pdata->buck4_gpiodvs) { + dev_err(&pdev->dev, "S5M8767 GPIO DVS NOT VALID\n"); + ret = -EINVAL; + return ret; + } + } + + if (pdata->buck4_gpiodvs) { + if (pdata->buck2_gpiodvs || pdata->buck3_gpiodvs) { + dev_err(&pdev->dev, "S5M8767 GPIO DVS NOT VALID\n"); + ret = -EINVAL; + return ret; + } + } + + s5m_reg_update(s5m8767->iodev, S5M8767_REG_BUCK2CTRL, + (pdata->buck2_gpiodvs) ? (1 << 1) : (0 << 1), 1 << 1); + s5m_reg_update(s5m8767->iodev, S5M8767_REG_BUCK3CTRL, + (pdata->buck3_gpiodvs) ? (1 << 1) : (0 << 1), 1 << 1); + s5m_reg_update(s5m8767->iodev, S5M8767_REG_BUCK4CTRL, + (pdata->buck4_gpiodvs) ? (1 << 1) : (0 << 1), 1 << 1); + + /* Initialize GPIO DVS registers */ + for (i = 0; i < 8; i++) { + if (s5m8767->buck2_gpiodvs) { + s5m_reg_write(s5m8767->iodev, S5M8767_REG_BUCK2DVS1 + i, + s5m8767->buck2_vol[i]); + } + + if (s5m8767->buck3_gpiodvs) { + s5m_reg_write(s5m8767->iodev, S5M8767_REG_BUCK3DVS1 + i, + s5m8767->buck3_vol[i]); + } + + if (s5m8767->buck4_gpiodvs) { + s5m_reg_write(s5m8767->iodev, S5M8767_REG_BUCK4DVS1 + i, + s5m8767->buck4_vol[i]); + } + } + s5m_reg_update(s5m8767->iodev, S5M8767_REG_BUCK2CTRL, 0x78, 0xff); + s5m_reg_update(s5m8767->iodev, S5M8767_REG_BUCK3CTRL, 0x58, 0xff); + s5m_reg_update(s5m8767->iodev, S5M8767_REG_BUCK4CTRL, 0x78, 0xff); + + if (s5m8767->buck2_ramp) + s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, 0x08, 0x08); + + if (s5m8767->buck3_ramp) + s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, 0x04, 0x04); + + if (s5m8767->buck4_ramp) + s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, 0x02, 0x02); + + if (s5m8767->buck2_ramp || s5m8767->buck3_ramp + || s5m8767->buck4_ramp) { + switch (s5m8767->ramp_delay) { + case 15: + s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, + 0xc0, 0xf0); + case 25: + s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, + 0xd0, 0xf0); + case 50: + s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, + 0xe0, 0xf0); + case 100: + s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, + 0xf0, 0xf0); + default: + s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, + 0x90, 0xf0); + } + } + + for (i = 0; i < pdata->num_regulators; i++) { + const struct s5m_voltage_desc *desc; + int id = pdata->regulators[i].id; + + desc = reg_voltage_map[id]; + if (desc) + regulators[id].n_voltages = + (desc->max - desc->min) / desc->step + 1; + + rdev[i] = regulator_register(®ulators[id], s5m8767->dev, + pdata->regulators[i].initdata, s5m8767); + if (IS_ERR(rdev[i])) { + ret = PTR_ERR(rdev[i]); + dev_err(s5m8767->dev, "regulator init failed for %d\n", + id); + rdev[i] = NULL; + goto err; + } + } + + return 0; +err: + for (i = 0; i < s5m8767->num_regulators; i++) + if (rdev[i]) + regulator_unregister(rdev[i]); + + return ret; +} + +static int __devexit s5m8767_pmic_remove(struct platform_device *pdev) +{ + struct s5m8767_info *s5m8767 = platform_get_drvdata(pdev); + struct regulator_dev **rdev = s5m8767->rdev; + int i; + + for (i = 0; i < s5m8767->num_regulators; i++) + if (rdev[i]) + regulator_unregister(rdev[i]); + + return 0; +} + +static const struct platform_device_id s5m8767_pmic_id[] = { + { "s5m8767-pmic", 0}, + { }, +}; +MODULE_DEVICE_TABLE(platform, s5m8767_pmic_id); + +static struct platform_driver s5m8767_pmic_driver = { + .driver = { + .name = "s5m8767-pmic", + .owner = THIS_MODULE, + }, + .probe = s5m8767_pmic_probe, + .remove = __devexit_p(s5m8767_pmic_remove), + .id_table = s5m8767_pmic_id, +}; + +static int __init s5m8767_pmic_init(void) +{ + return platform_driver_register(&s5m8767_pmic_driver); +} +subsys_initcall(s5m8767_pmic_init); + +static void __exit s5m8767_pmic_exit(void) +{ + platform_driver_unregister(&s5m8767_pmic_driver); +} +module_exit(s5m8767_pmic_exit); + +/* Module information */ +MODULE_AUTHOR("Sangbeom Kim "); +MODULE_DESCRIPTION("SAMSUNG S5M8767 Regulator Driver"); +MODULE_LICENSE("GPL"); +MODULE_ALIAS("platform:s5m8767-pmic"); -- cgit v0.10.2 From 047ec220a49f96ab0f8bd0bc574368e2cae8f1f7 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Thu, 12 Jan 2012 14:57:09 +0800 Subject: regulator: s5m8767: Add missing breaks Signed-off-by: Axel Lin Acked-by: Sangbeom Kim Signed-off-by: Mark Brown diff --git a/drivers/regulator/s5m8767.c b/drivers/regulator/s5m8767.c index b3d356f..4061012 100644 --- a/drivers/regulator/s5m8767.c +++ b/drivers/regulator/s5m8767.c @@ -742,15 +742,19 @@ static __devinit int s5m8767_pmic_probe(struct platform_device *pdev) case 15: s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, 0xc0, 0xf0); + break; case 25: s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, 0xd0, 0xf0); + break; case 50: s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, 0xe0, 0xf0); + break; case 100: s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, 0xf0, 0xf0); + break; default: s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, 0x90, 0xf0); -- cgit v0.10.2 From c835e1c00eda6f8f6c6bce49b2d89208f3a184dc Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Thu, 12 Jan 2012 14:58:25 +0800 Subject: regulator: s5m8767: Remove redundant MODULE_ALIAS The MODULE_DEVICE_TABLE will setup the modalias, thus adding a MODULE_ALIAS for an entry already in s5m8767_pmic_id is redundant. Signed-off-by: Axel Lin Acked-by: Sangbeom Kim Signed-off-by: Mark Brown diff --git a/drivers/regulator/s5m8767.c b/drivers/regulator/s5m8767.c index 4061012..caf0117b 100644 --- a/drivers/regulator/s5m8767.c +++ b/drivers/regulator/s5m8767.c @@ -835,4 +835,3 @@ module_exit(s5m8767_pmic_exit); MODULE_AUTHOR("Sangbeom Kim "); MODULE_DESCRIPTION("SAMSUNG S5M8767 Regulator Driver"); MODULE_LICENSE("GPL"); -MODULE_ALIAS("platform:s5m8767-pmic"); -- cgit v0.10.2 From 38e968380b27d6c0f4b68bdd6e3161f8a7effe38 Mon Sep 17 00:00:00 2001 From: Bengt Jonsson Date: Fri, 13 Jan 2012 16:30:31 +0100 Subject: regulators/db8500: split off shared dbx500 code As we progress with DB5500 and future voltage domain regulators based on very similar hardware as found in the DB8500 PRCMU, it makes sense to split off the generic parts and introduce some generic debug code for the DBx500 regulators. This patch accoplish a basic abstraction of the DBx500 voltage domain regulators. Signed-off-by: Bengt Jonsson Signed-off-by: Linus Walleij Signed-off-by: Mark Brown diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig index b9ad3d8e..c7e49b1 100644 --- a/drivers/regulator/Kconfig +++ b/drivers/regulator/Kconfig @@ -299,9 +299,13 @@ config REGULATOR_AB8500 This driver supports the regulators found on the ST-Ericsson mixed signal AB8500 PMIC +config REGULATOR_DBX500_PRCMU + bool + config REGULATOR_DB8500_PRCMU bool "ST-Ericsson DB8500 Voltage Domain Regulators" depends on MFD_DB8500_PRCMU + select REGULATOR_DBX500_PRCMU help This driver supports the voltage domain regulators controlled by the DB8500 PRCMU diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile index 1668b2e..bf59513 100644 --- a/drivers/regulator/Makefile +++ b/drivers/regulator/Makefile @@ -45,6 +45,7 @@ obj-$(CONFIG_REGULATOR_TPS65912) += tps65912-regulator.o obj-$(CONFIG_REGULATOR_88PM8607) += 88pm8607.o obj-$(CONFIG_REGULATOR_ISL6271A) += isl6271a-regulator.o obj-$(CONFIG_REGULATOR_AB8500) += ab8500.o +obj-$(CONFIG_REGULATOR_DBX500_PRCMU) += dbx500-prcmu.o obj-$(CONFIG_REGULATOR_DB8500_PRCMU) += db8500-prcmu.o obj-$(CONFIG_REGULATOR_TPS65910) += tps65910-regulator.o obj-$(CONFIG_REGULATOR_TPS62360) += tps62360-regulator.o diff --git a/drivers/regulator/db8500-prcmu.c b/drivers/regulator/db8500-prcmu.c index 515443f..4bd25e7 100644 --- a/drivers/regulator/db8500-prcmu.c +++ b/drivers/regulator/db8500-prcmu.c @@ -18,74 +18,11 @@ #include #include #include - -/* - * power state reference count - */ -static int power_state_active_cnt; /* will initialize to zero */ -static DEFINE_SPINLOCK(power_state_active_lock); - -static void power_state_active_enable(void) -{ - unsigned long flags; - - spin_lock_irqsave(&power_state_active_lock, flags); - power_state_active_cnt++; - spin_unlock_irqrestore(&power_state_active_lock, flags); -} - -static int power_state_active_disable(void) -{ - int ret = 0; - unsigned long flags; - - spin_lock_irqsave(&power_state_active_lock, flags); - if (power_state_active_cnt <= 0) { - pr_err("power state: unbalanced enable/disable calls\n"); - ret = -EINVAL; - goto out; - } - - power_state_active_cnt--; -out: - spin_unlock_irqrestore(&power_state_active_lock, flags); - return ret; -} - -/* - * Exported interface for CPUIdle only. This function is called when interrupts - * are turned off. Hence, no locking. - */ -int power_state_active_is_enabled(void) -{ - return (power_state_active_cnt > 0); -} - -/** - * struct db8500_regulator_info - db8500 regulator information - * @dev: device pointer - * @desc: regulator description - * @rdev: regulator device pointer - * @is_enabled: status of the regulator - * @epod_id: id for EPOD (power domain) - * @is_ramret: RAM retention switch for EPOD (power domain) - * @operating_point: operating point (only for vape, to be removed) - * - */ -struct db8500_regulator_info { - struct device *dev; - struct regulator_desc desc; - struct regulator_dev *rdev; - bool is_enabled; - u16 epod_id; - bool is_ramret; - bool exclude_from_power_state; - unsigned int operating_point; -}; +#include "dbx500-prcmu.h" static int db8500_regulator_enable(struct regulator_dev *rdev) { - struct db8500_regulator_info *info = rdev_get_drvdata(rdev); + struct dbx500_regulator_info *info = rdev_get_drvdata(rdev); if (info == NULL) return -EINVAL; @@ -93,16 +30,18 @@ static int db8500_regulator_enable(struct regulator_dev *rdev) dev_vdbg(rdev_get_dev(rdev), "regulator-%s-enable\n", info->desc.name); - info->is_enabled = true; - if (!info->exclude_from_power_state) - power_state_active_enable(); + if (!info->is_enabled) { + info->is_enabled = true; + if (!info->exclude_from_power_state) + power_state_active_enable(); + } return 0; } static int db8500_regulator_disable(struct regulator_dev *rdev) { - struct db8500_regulator_info *info = rdev_get_drvdata(rdev); + struct dbx500_regulator_info *info = rdev_get_drvdata(rdev); int ret = 0; if (info == NULL) @@ -111,16 +50,18 @@ static int db8500_regulator_disable(struct regulator_dev *rdev) dev_vdbg(rdev_get_dev(rdev), "regulator-%s-disable\n", info->desc.name); - info->is_enabled = false; - if (!info->exclude_from_power_state) - ret = power_state_active_disable(); + if (info->is_enabled) { + info->is_enabled = false; + if (!info->exclude_from_power_state) + ret = power_state_active_disable(); + } return ret; } static int db8500_regulator_is_enabled(struct regulator_dev *rdev) { - struct db8500_regulator_info *info = rdev_get_drvdata(rdev); + struct dbx500_regulator_info *info = rdev_get_drvdata(rdev); if (info == NULL) return -EINVAL; @@ -197,7 +138,7 @@ static int disable_epod(u16 epod_id, bool ramret) */ static int db8500_regulator_switch_enable(struct regulator_dev *rdev) { - struct db8500_regulator_info *info = rdev_get_drvdata(rdev); + struct dbx500_regulator_info *info = rdev_get_drvdata(rdev); int ret; if (info == NULL) @@ -221,7 +162,7 @@ out: static int db8500_regulator_switch_disable(struct regulator_dev *rdev) { - struct db8500_regulator_info *info = rdev_get_drvdata(rdev); + struct dbx500_regulator_info *info = rdev_get_drvdata(rdev); int ret; if (info == NULL) @@ -245,7 +186,7 @@ out: static int db8500_regulator_switch_is_enabled(struct regulator_dev *rdev) { - struct db8500_regulator_info *info = rdev_get_drvdata(rdev); + struct dbx500_regulator_info *info = rdev_get_drvdata(rdev); if (info == NULL) return -EINVAL; @@ -266,8 +207,8 @@ static struct regulator_ops db8500_regulator_switch_ops = { /* * Regulator information */ -static struct db8500_regulator_info -db8500_regulator_info[DB8500_NUM_REGULATORS] = { +static struct dbx500_regulator_info +dbx500_regulator_info[DB8500_NUM_REGULATORS] = { [DB8500_REGULATOR_VAPE] = { .desc = { .name = "db8500-vape", @@ -476,12 +417,12 @@ static int __devinit db8500_regulator_probe(struct platform_device *pdev) int i, err; /* register all regulators */ - for (i = 0; i < ARRAY_SIZE(db8500_regulator_info); i++) { - struct db8500_regulator_info *info; + for (i = 0; i < ARRAY_SIZE(dbx500_regulator_info); i++) { + struct dbx500_regulator_info *info; struct regulator_init_data *init_data = &db8500_init_data[i]; /* assign per-regulator data */ - info = &db8500_regulator_info[i]; + info = &dbx500_regulator_info[i]; info->dev = &pdev->dev; /* register with the regulator framework */ @@ -494,7 +435,7 @@ static int __devinit db8500_regulator_probe(struct platform_device *pdev) /* if failing, unregister all earlier regulators */ while (--i >= 0) { - info = &db8500_regulator_info[i]; + info = &dbx500_regulator_info[i]; regulator_unregister(info->rdev); } return err; @@ -503,17 +444,22 @@ static int __devinit db8500_regulator_probe(struct platform_device *pdev) dev_dbg(rdev_get_dev(info->rdev), "regulator-%s-probed\n", info->desc.name); } + err = ux500_regulator_debug_init(pdev, + dbx500_regulator_info, + ARRAY_SIZE(dbx500_regulator_info)); - return 0; + return err; } static int __exit db8500_regulator_remove(struct platform_device *pdev) { int i; - for (i = 0; i < ARRAY_SIZE(db8500_regulator_info); i++) { - struct db8500_regulator_info *info; - info = &db8500_regulator_info[i]; + ux500_regulator_debug_exit(); + + for (i = 0; i < ARRAY_SIZE(dbx500_regulator_info); i++) { + struct dbx500_regulator_info *info; + info = &dbx500_regulator_info[i]; dev_vdbg(rdev_get_dev(info->rdev), "regulator-%s-remove\n", info->desc.name); diff --git a/drivers/regulator/dbx500-prcmu.c b/drivers/regulator/dbx500-prcmu.c new file mode 100644 index 0000000..f2e5ecd --- /dev/null +++ b/drivers/regulator/dbx500-prcmu.c @@ -0,0 +1,241 @@ +/* + * Copyright (C) ST-Ericsson SA 2010 + * + * License Terms: GNU General Public License v2 + * Authors: Sundar Iyer for ST-Ericsson + * Bengt Jonsson for ST-Ericsson + * + * UX500 common part of Power domain regulators + */ + +#include +#include +#include +#include +#include +#include + +#include "dbx500-prcmu.h" + +/* + * power state reference count + */ +static int power_state_active_cnt; /* will initialize to zero */ +static DEFINE_SPINLOCK(power_state_active_lock); + +int power_state_active_get(void) +{ + unsigned long flags; + int cnt; + + spin_lock_irqsave(&power_state_active_lock, flags); + cnt = power_state_active_cnt; + spin_unlock_irqrestore(&power_state_active_lock, flags); + + return cnt; +} + +void power_state_active_enable(void) +{ + unsigned long flags; + + spin_lock_irqsave(&power_state_active_lock, flags); + power_state_active_cnt++; + spin_unlock_irqrestore(&power_state_active_lock, flags); +} + +int power_state_active_disable(void) +{ + int ret = 0; + unsigned long flags; + + spin_lock_irqsave(&power_state_active_lock, flags); + if (power_state_active_cnt <= 0) { + pr_err("power state: unbalanced enable/disable calls\n"); + ret = -EINVAL; + goto out; + } + + power_state_active_cnt--; +out: + spin_unlock_irqrestore(&power_state_active_lock, flags); + return ret; +} + +#ifdef CONFIG_REGULATOR_DEBUG + +static struct ux500_regulator_debug { + struct dentry *dir; + struct dentry *status_file; + struct dentry *power_state_cnt_file; + struct dbx500_regulator_info *regulator_array; + int num_regulators; + u8 *state_before_suspend; + u8 *state_after_suspend; +} rdebug; + +void ux500_regulator_suspend_debug(void) +{ + int i; + for (i = 0; i < rdebug.num_regulators; i++) + rdebug.state_before_suspend[i] = + rdebug.regulator_array[i].is_enabled; +} + +void ux500_regulator_resume_debug(void) +{ + int i; + for (i = 0; i < rdebug.num_regulators; i++) + rdebug.state_after_suspend[i] = + rdebug.regulator_array[i].is_enabled; +} + +static int ux500_regulator_power_state_cnt_print(struct seq_file *s, void *p) +{ + struct device *dev = s->private; + int err; + + /* print power state count */ + err = seq_printf(s, "ux500-regulator power state count: %i\n", + power_state_active_get()); + if (err < 0) + dev_err(dev, "seq_printf overflow\n"); + + return 0; +} + +static int ux500_regulator_power_state_cnt_open(struct inode *inode, + struct file *file) +{ + return single_open(file, ux500_regulator_power_state_cnt_print, + inode->i_private); +} + +static const struct file_operations ux500_regulator_power_state_cnt_fops = { + .open = ux500_regulator_power_state_cnt_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, + .owner = THIS_MODULE, +}; + +static int ux500_regulator_status_print(struct seq_file *s, void *p) +{ + struct device *dev = s->private; + int err; + int i; + + /* print dump header */ + err = seq_printf(s, "ux500-regulator status:\n"); + if (err < 0) + dev_err(dev, "seq_printf overflow\n"); + + err = seq_printf(s, "%31s : %8s : %8s\n", "current", + "before", "after"); + if (err < 0) + dev_err(dev, "seq_printf overflow\n"); + + for (i = 0; i < rdebug.num_regulators; i++) { + struct dbx500_regulator_info *info; + /* Access per-regulator data */ + info = &rdebug.regulator_array[i]; + + /* print status */ + err = seq_printf(s, "%20s : %8s : %8s : %8s\n", info->desc.name, + info->is_enabled ? "enabled" : "disabled", + rdebug.state_before_suspend[i] ? "enabled" : "disabled", + rdebug.state_after_suspend[i] ? "enabled" : "disabled"); + if (err < 0) + dev_err(dev, "seq_printf overflow\n"); + } + + return 0; +} + +static int ux500_regulator_status_open(struct inode *inode, struct file *file) +{ + return single_open(file, ux500_regulator_status_print, + inode->i_private); +} + +static const struct file_operations ux500_regulator_status_fops = { + .open = ux500_regulator_status_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, + .owner = THIS_MODULE, +}; + +int __attribute__((weak)) dbx500_regulator_testcase( + struct dbx500_regulator_info *regulator_info, + int num_regulators) +{ + return 0; +} + +int __devinit +ux500_regulator_debug_init(struct platform_device *pdev, + struct dbx500_regulator_info *regulator_info, + int num_regulators) +{ + /* create directory */ + rdebug.dir = debugfs_create_dir("ux500-regulator", NULL); + if (!rdebug.dir) + goto exit_no_debugfs; + + /* create "status" file */ + rdebug.status_file = debugfs_create_file("status", + S_IRUGO, rdebug.dir, &pdev->dev, + &ux500_regulator_status_fops); + if (!rdebug.status_file) + goto exit_destroy_dir; + + /* create "power-state-count" file */ + rdebug.power_state_cnt_file = debugfs_create_file("power-state-count", + S_IRUGO, rdebug.dir, &pdev->dev, + &ux500_regulator_power_state_cnt_fops); + if (!rdebug.power_state_cnt_file) + goto exit_destroy_status; + + rdebug.regulator_array = regulator_info; + rdebug.num_regulators = num_regulators; + + rdebug.state_before_suspend = kzalloc(num_regulators, GFP_KERNEL); + if (!rdebug.state_before_suspend) { + dev_err(&pdev->dev, + "could not allocate memory for saving state\n"); + goto exit_destroy_power_state; + } + + rdebug.state_after_suspend = kzalloc(num_regulators, GFP_KERNEL); + if (!rdebug.state_after_suspend) { + dev_err(&pdev->dev, + "could not allocate memory for saving state\n"); + goto exit_free; + } + + dbx500_regulator_testcase(regulator_info, num_regulators); + return 0; + +exit_free: + kfree(rdebug.state_before_suspend); +exit_destroy_power_state: + debugfs_remove(rdebug.power_state_cnt_file); +exit_destroy_status: + debugfs_remove(rdebug.status_file); +exit_destroy_dir: + debugfs_remove(rdebug.dir); +exit_no_debugfs: + dev_err(&pdev->dev, "failed to create debugfs entries.\n"); + return -ENOMEM; +} + +int __devexit ux500_regulator_debug_exit(void) +{ + debugfs_remove_recursive(rdebug.dir); + kfree(rdebug.state_after_suspend); + kfree(rdebug.state_before_suspend); + + return 0; +} +#endif diff --git a/drivers/regulator/dbx500-prcmu.h b/drivers/regulator/dbx500-prcmu.h new file mode 100644 index 0000000..e763883 --- /dev/null +++ b/drivers/regulator/dbx500-prcmu.h @@ -0,0 +1,63 @@ +/* + * Copyright (C) ST-Ericsson SA 2010 + * + * Author: Bengt Jonsson for ST-Ericsson, + * Jonas Aaberg for ST-Ericsson + * + * License Terms: GNU General Public License v2 + * + */ + +#ifndef DBX500_REGULATOR_H +#define DBX500_REGULATOR_H + +#include + +/** + * struct dbx500_regulator_info - dbx500 regulator information + * @dev: device pointer + * @desc: regulator description + * @rdev: regulator device pointer + * @is_enabled: status of the regulator + * @epod_id: id for EPOD (power domain) + * @is_ramret: RAM retention switch for EPOD (power domain) + * @operating_point: operating point (only for vape, to be removed) + * + */ +struct dbx500_regulator_info { + struct device *dev; + struct regulator_desc desc; + struct regulator_dev *rdev; + bool is_enabled; + u16 epod_id; + bool is_ramret; + bool exclude_from_power_state; + unsigned int operating_point; +}; + +void power_state_active_enable(void); +int power_state_active_disable(void); + + +#ifdef CONFIG_REGULATOR_DEBUG +int ux500_regulator_debug_init(struct platform_device *pdev, + struct dbx500_regulator_info *regulator_info, + int num_regulators); + +int ux500_regulator_debug_exit(void); +#else + +static inline int ux500_regulator_debug_init(struct platform_device *pdev, + struct dbx500_regulator_info *regulator_info, + int num_regulators) +{ + return 0; +} + +static inline int ux500_regulator_debug_exit(void) +{ + return 0; +} + +#endif +#endif -- cgit v0.10.2 From 62aa492582cd6ce9f5e797ac3197239e63de1df9 Mon Sep 17 00:00:00 2001 From: Sangbeom Kim Date: Fri, 13 Jan 2012 10:13:13 +0900 Subject: regulator: Add S5M8767 configuration This patch add Samsung S5M8767A pmic configuration. Signed-off-by: Sangbeom Kim Signed-off-by: Mark Brown diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig index c7e49b1..4792d66 100644 --- a/drivers/regulator/Kconfig +++ b/drivers/regulator/Kconfig @@ -136,6 +136,14 @@ config REGULATOR_MAX8998 via I2C bus. The provided regulator is suitable for S3C6410 and S5PC1XX chips to control VCC_CORE and VCC_USIM voltages. +config REGULATOR_S5M8767 + tristate "Samsung S5M8767A voltage regulator" + depends on MFD_S5M_CORE + help + This driver supports a Samsung S5M8767A voltage output regulator + via I2C bus. S5M8767A have 9 Bucks and 28 LDOs output and + supports DVS mode with 8bits of output voltage control. + config REGULATOR_TWL4030 bool "TI TWL4030/TWL5030/TWL6030/TPS659x0 PMIC" depends on TWL4030_CORE diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile index bf59513..66be54a 100644 --- a/drivers/regulator/Makefile +++ b/drivers/regulator/Makefile @@ -50,5 +50,7 @@ obj-$(CONFIG_REGULATOR_DB8500_PRCMU) += db8500-prcmu.o obj-$(CONFIG_REGULATOR_TPS65910) += tps65910-regulator.o obj-$(CONFIG_REGULATOR_TPS62360) += tps62360-regulator.o obj-$(CONFIG_REGULATOR_AAT2870) += aat2870-regulator.o +obj-$(CONFIG_REGULATOR_S5M8767) += s5m8767.o + ccflags-$(CONFIG_REGULATOR_DEBUG) += -DDEBUG -- cgit v0.10.2 From a493077f1883a627d6ba2659b0a82888e58d31dd Mon Sep 17 00:00:00 2001 From: AnilKumar Ch Date: Wed, 11 Jan 2012 16:11:49 +0530 Subject: regulator: tps65217: Add tps65217 regulator driver This patch adds tps65217 PMIC as a regulator The regulator module consists of 3 DCDCs and 4 LDOs. The output voltages are configurable and are meant to supply power to the main processor and other components Signed-off-by: AnilKumar Ch Signed-off-by: Mark Brown diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig index 4792d66..376824b 100644 --- a/drivers/regulator/Kconfig +++ b/drivers/regulator/Kconfig @@ -275,6 +275,15 @@ config REGULATOR_TPS6507X three step-down converters and two general-purpose LDO voltage regulators. It supports TI's software based Class-2 SmartReflex implementation. +config REGULATOR_TPS65217 + tristate "TI TPS65217 Power regulators" + depends on MFD_TPS65217 + help + This driver supports TPS65217 voltage regulator chips. TPS65217 + provides three step-down converters and four general-purpose LDO + voltage regulators. It supports software based voltage control + for different voltage domains + config REGULATOR_TPS65912 tristate "TI TPS65912 Power regulator" depends on (MFD_TPS65912_I2C || MFD_TPS65912_SPI) diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile index 66be54a..4cbf8c5 100644 --- a/drivers/regulator/Makefile +++ b/drivers/regulator/Makefile @@ -40,6 +40,7 @@ obj-$(CONFIG_REGULATOR_AB3100) += ab3100.o obj-$(CONFIG_REGULATOR_TPS6105X) += tps6105x-regulator.o obj-$(CONFIG_REGULATOR_TPS65023) += tps65023-regulator.o obj-$(CONFIG_REGULATOR_TPS6507X) += tps6507x-regulator.o +obj-$(CONFIG_REGULATOR_TPS65217) += tps65217-regulator.o obj-$(CONFIG_REGULATOR_TPS6524X) += tps6524x-regulator.o obj-$(CONFIG_REGULATOR_TPS65912) += tps65912-regulator.o obj-$(CONFIG_REGULATOR_88PM8607) += 88pm8607.o diff --git a/drivers/regulator/tps65217-regulator.c b/drivers/regulator/tps65217-regulator.c new file mode 100644 index 0000000..6665566 --- /dev/null +++ b/drivers/regulator/tps65217-regulator.c @@ -0,0 +1,493 @@ +/* + * tps65217-regulator.c + * + * Regulator driver for TPS65217 PMIC + * + * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ + * + * 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. + * + * This program is distributed "as is" WITHOUT ANY WARRANTY of any + * kind, whether express or implied; 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 TPS65217_REGULATOR(_name, _id, _ops, _n) \ + { \ + .name = _name, \ + .id = _id, \ + .ops = &_ops, \ + .n_voltages = _n, \ + .type = REGULATOR_VOLTAGE, \ + .owner = THIS_MODULE, \ + } \ + +#define TPS65217_INFO(_nm, _min, _max, _f1, _f2, _t, _n, _em, _vr, _vm) \ + { \ + .name = _nm, \ + .min_uV = _min, \ + .max_uV = _max, \ + .vsel_to_uv = _f1, \ + .uv_to_vsel = _f2, \ + .table = _t, \ + .table_len = _n, \ + .enable_mask = _em, \ + .set_vout_reg = _vr, \ + .set_vout_mask = _vm, \ + } + +static const int LDO1_VSEL_table[] = { + 1000000, 1100000, 1200000, 1250000, + 1300000, 1350000, 1400000, 1500000, + 1600000, 1800000, 2500000, 2750000, + 2800000, 3000000, 3100000, 3300000, +}; + +static int tps65217_vsel_to_uv1(unsigned int vsel) +{ + int uV = 0; + + if (vsel > 63) + return -EINVAL; + + if (vsel <= 24) + uV = vsel * 25000 + 900000; + else if (vsel <= 52) + uV = (vsel - 24) * 50000 + 1500000; + else if (vsel < 56) + uV = (vsel - 52) * 100000 + 2900000; + else + uV = 3300000; + + return uV; +} + +static int tps65217_uv_to_vsel1(int uV, unsigned int *vsel) +{ + if ((uV < 0) && (uV > 3300000)) + return -EINVAL; + + if (uV <= 1500000) + *vsel = (uV - 875001) / 25000; + else if (uV <= 2900000) + *vsel = 24 + (uV - 1450001) / 50000; + else if (uV < 3300000) + *vsel = 52 + (uV - 2800001) / 100000; + else + *vsel = 56; + + return 0; +} + +static int tps65217_vsel_to_uv2(unsigned int vsel) +{ + int uV = 0; + + if (vsel > 31) + return -EINVAL; + + if (vsel <= 8) + uV = vsel * 50000 + 1500000; + else if (vsel <= 13) + uV = (vsel - 8) * 100000 + 1900000; + else + uV = (vsel - 13) * 50000 + 2400000; + + return uV; +} + +static int tps65217_uv_to_vsel2(int uV, unsigned int *vsel) +{ + if ((uV < 0) && (uV > 3300000)) + return -EINVAL; + + if (uV <= 1900000) + *vsel = (uV - 1450001) / 50000; + else if (uV <= 2400000) + *vsel = 8 + (uV - 1800001) / 100000; + else + *vsel = 13 + (uV - 2350001) / 50000; + + return 0; +} + +static struct tps_info tps65217_pmic_regs[] = { + TPS65217_INFO("DCDC1", 900000, 1800000, tps65217_vsel_to_uv1, + tps65217_uv_to_vsel1, NULL, 64, TPS65217_ENABLE_DC1_EN, + TPS65217_REG_DEFDCDC1, TPS65217_DEFDCDCX_DCDC_MASK), + TPS65217_INFO("DCDC2", 900000, 3300000, tps65217_vsel_to_uv1, + tps65217_uv_to_vsel1, NULL, 64, TPS65217_ENABLE_DC2_EN, + TPS65217_REG_DEFDCDC2, TPS65217_DEFDCDCX_DCDC_MASK), + TPS65217_INFO("DCDC3", 900000, 1500000, tps65217_vsel_to_uv1, + tps65217_uv_to_vsel1, NULL, 64, TPS65217_ENABLE_DC3_EN, + TPS65217_REG_DEFDCDC3, TPS65217_DEFDCDCX_DCDC_MASK), + TPS65217_INFO("LDO1", 1000000, 3300000, NULL, NULL, LDO1_VSEL_table, + 16, TPS65217_ENABLE_LDO1_EN, TPS65217_REG_DEFLDO1, + TPS65217_DEFLDO1_LDO1_MASK), + TPS65217_INFO("LDO2", 900000, 3300000, tps65217_vsel_to_uv1, + tps65217_uv_to_vsel1, NULL, 64, TPS65217_ENABLE_LDO2_EN, + TPS65217_REG_DEFLDO2, TPS65217_DEFLDO2_LDO2_MASK), + TPS65217_INFO("LDO3", 1800000, 3300000, tps65217_vsel_to_uv2, + tps65217_uv_to_vsel2, NULL, 32, + TPS65217_ENABLE_LS1_EN | TPS65217_DEFLDO3_LDO3_EN, + TPS65217_REG_DEFLS1, TPS65217_DEFLDO3_LDO3_MASK), + TPS65217_INFO("LDO4", 1800000, 3300000, tps65217_vsel_to_uv2, + tps65217_uv_to_vsel2, NULL, 32, + TPS65217_ENABLE_LS2_EN | TPS65217_DEFLDO4_LDO4_EN, + TPS65217_REG_DEFLS2, TPS65217_DEFLDO4_LDO4_MASK), +}; + +static int tps65217_pmic_dcdc_is_enabled(struct regulator_dev *dev) +{ + int ret; + struct tps65217 *tps = rdev_get_drvdata(dev); + unsigned int data, dcdc = rdev_get_id(dev); + + if (dcdc < TPS65217_DCDC_1 || dcdc > TPS65217_DCDC_3) + return -EINVAL; + + ret = tps65217_reg_read(tps, TPS65217_REG_ENABLE, &data); + if (ret) + return ret; + + return (data & tps->info[dcdc]->enable_mask) ? 1 : 0; +} + +static int tps65217_pmic_ldo_is_enabled(struct regulator_dev *dev) +{ + int ret; + struct tps65217 *tps = rdev_get_drvdata(dev); + unsigned int data, ldo = rdev_get_id(dev); + + if (ldo < TPS65217_LDO_1 || ldo > TPS65217_LDO_4) + return -EINVAL; + + ret = tps65217_reg_read(tps, TPS65217_REG_ENABLE, &data); + if (ret) + return ret; + + return (data & tps->info[ldo]->enable_mask) ? 1 : 0; +} + +static int tps65217_pmic_dcdc_enable(struct regulator_dev *dev) +{ + struct tps65217 *tps = rdev_get_drvdata(dev); + unsigned int dcdc = rdev_get_id(dev); + + if (dcdc < TPS65217_DCDC_1 || dcdc > TPS65217_DCDC_3) + return -EINVAL; + + /* Enable the regulator and password protection is level 1 */ + return tps65217_set_bits(tps, TPS65217_REG_ENABLE, + tps->info[dcdc]->enable_mask, + tps->info[dcdc]->enable_mask, + TPS65217_PROTECT_L1); +} + +static int tps65217_pmic_dcdc_disable(struct regulator_dev *dev) +{ + struct tps65217 *tps = rdev_get_drvdata(dev); + unsigned int dcdc = rdev_get_id(dev); + + if (dcdc < TPS65217_DCDC_1 || dcdc > TPS65217_DCDC_3) + return -EINVAL; + + /* Disable the regulator and password protection is level 1 */ + return tps65217_clear_bits(tps, TPS65217_REG_ENABLE, + tps->info[dcdc]->enable_mask, TPS65217_PROTECT_L1); +} + +static int tps65217_pmic_ldo_enable(struct regulator_dev *dev) +{ + struct tps65217 *tps = rdev_get_drvdata(dev); + unsigned int ldo = rdev_get_id(dev); + + if (ldo < TPS65217_LDO_1 || ldo > TPS65217_LDO_4) + return -EINVAL; + + /* Enable the regulator and password protection is level 1 */ + return tps65217_set_bits(tps, TPS65217_REG_ENABLE, + tps->info[ldo]->enable_mask, + tps->info[ldo]->enable_mask, + TPS65217_PROTECT_L1); +} + +static int tps65217_pmic_ldo_disable(struct regulator_dev *dev) +{ + struct tps65217 *tps = rdev_get_drvdata(dev); + unsigned int ldo = rdev_get_id(dev); + + if (ldo < TPS65217_LDO_1 || ldo > TPS65217_LDO_4) + return -EINVAL; + + /* Disable the regulator and password protection is level 1 */ + return tps65217_clear_bits(tps, TPS65217_REG_ENABLE, + tps->info[ldo]->enable_mask, TPS65217_PROTECT_L1); +} + +static int tps65217_pmic_dcdc_get_voltage_sel(struct regulator_dev *dev) +{ + int ret; + struct tps65217 *tps = rdev_get_drvdata(dev); + unsigned int selector, dcdc = rdev_get_id(dev); + + if (dcdc < TPS65217_DCDC_1 || dcdc > TPS65217_DCDC_3) + return -EINVAL; + + ret = tps65217_reg_read(tps, tps->info[dcdc]->set_vout_reg, &selector); + if (ret) + return ret; + + selector &= tps->info[dcdc]->set_vout_mask; + + return selector; +} + +static int tps65217_pmic_dcdc_set_voltage(struct regulator_dev *dev, + int min_uV, int max_uV, unsigned *selector) +{ + int ret; + struct tps65217 *tps = rdev_get_drvdata(dev); + unsigned int dcdc = rdev_get_id(dev); + + if (dcdc < TPS65217_DCDC_1 || dcdc > TPS65217_DCDC_3) + return -EINVAL; + + if (min_uV < tps->info[dcdc]->min_uV + || min_uV > tps->info[dcdc]->max_uV) + return -EINVAL; + + if (max_uV < tps->info[dcdc]->min_uV + || max_uV > tps->info[dcdc]->max_uV) + return -EINVAL; + + ret = tps->info[dcdc]->uv_to_vsel(min_uV, selector); + if (ret) + return ret; + + /* Set the voltage based on vsel value and write protect level is 2 */ + ret = tps65217_set_bits(tps, tps->info[dcdc]->set_vout_reg, + tps->info[dcdc]->set_vout_mask, + *selector, TPS65217_PROTECT_L2); + if (ret) + return ret; + + /* Set GO bit to initiate voltage transistion */ + return tps65217_set_bits(tps, TPS65217_REG_DEFSLEW, + TPS65217_DEFSLEW_GO, TPS65217_DEFSLEW_GO, + TPS65217_PROTECT_L2); +} + +static int tps65217_pmic_ldo_get_voltage_sel(struct regulator_dev *dev) +{ + int ret; + struct tps65217 *tps = rdev_get_drvdata(dev); + unsigned int selector, ldo = rdev_get_id(dev); + + if (ldo < TPS65217_LDO_1 || ldo > TPS65217_LDO_4) + return -EINVAL; + + ret = tps65217_reg_read(tps, tps->info[ldo]->set_vout_reg, &selector); + if (ret) + return ret; + + selector &= tps->info[ldo]->set_vout_mask; + + return selector; +} + +static int tps65217_pmic_ldo_set_voltage_sel(struct regulator_dev *dev, + unsigned selector) +{ + struct tps65217 *tps = rdev_get_drvdata(dev); + int ldo = rdev_get_id(dev); + + if (ldo != TPS65217_LDO_1) + return -EINVAL; + + if (selector >= tps->info[ldo]->table_len) + return -EINVAL; + + /* Set the voltage based on vsel value and write protect level is 2 */ + return tps65217_set_bits(tps, tps->info[ldo]->set_vout_reg, + tps->info[ldo]->set_vout_mask, + selector, TPS65217_PROTECT_L2); +} + +static int tps65217_pmic_ldo_set_voltage(struct regulator_dev *dev, + int min_uV, int max_uV, unsigned *selector) +{ + int ret; + struct tps65217 *tps = rdev_get_drvdata(dev); + unsigned int ldo = rdev_get_id(dev); + + if (ldo < TPS65217_LDO_2 || ldo > TPS65217_LDO_4) + return -EINVAL; + + if (min_uV < tps->info[ldo]->min_uV + || min_uV > tps->info[ldo]->max_uV) + return -EINVAL; + + if (max_uV < tps->info[ldo]->min_uV + || max_uV > tps->info[ldo]->max_uV) + return -EINVAL; + + ret = tps->info[ldo]->uv_to_vsel(min_uV, selector); + if (ret) + return ret; + + /* Set the voltage based on vsel value and write protect level is 2 */ + return tps65217_set_bits(tps, tps->info[ldo]->set_vout_reg, + tps->info[ldo]->set_vout_mask, + *selector, TPS65217_PROTECT_L2); +} + +static int tps65217_pmic_dcdc_list_voltage(struct regulator_dev *dev, + unsigned selector) +{ + struct tps65217 *tps = rdev_get_drvdata(dev); + unsigned int dcdc = rdev_get_id(dev); + + if (dcdc < TPS65217_DCDC_1 || dcdc > TPS65217_DCDC_3) + return -EINVAL; + + if (selector >= tps->info[dcdc]->table_len) + return -EINVAL; + + return tps->info[dcdc]->vsel_to_uv(selector); +} + +static int tps65217_pmic_ldo_list_voltage(struct regulator_dev *dev, + unsigned selector) +{ + struct tps65217 *tps = rdev_get_drvdata(dev); + unsigned int ldo = rdev_get_id(dev); + + if (ldo < TPS65217_LDO_1 || ldo > TPS65217_LDO_4) + return -EINVAL; + + if (selector >= tps->info[ldo]->table_len) + return -EINVAL; + + if (tps->info[ldo]->table) + return tps->info[ldo]->table[selector]; + + return tps->info[ldo]->vsel_to_uv(selector); +} + +/* Operations permitted on DCDCx */ +static struct regulator_ops tps65217_pmic_dcdc_ops = { + .is_enabled = tps65217_pmic_dcdc_is_enabled, + .enable = tps65217_pmic_dcdc_enable, + .disable = tps65217_pmic_dcdc_disable, + .get_voltage_sel = tps65217_pmic_dcdc_get_voltage_sel, + .set_voltage = tps65217_pmic_dcdc_set_voltage, + .list_voltage = tps65217_pmic_dcdc_list_voltage, +}; + +/* Operations permitted on LDO1 */ +static struct regulator_ops tps65217_pmic_ldo1_ops = { + .is_enabled = tps65217_pmic_ldo_is_enabled, + .enable = tps65217_pmic_ldo_enable, + .disable = tps65217_pmic_ldo_disable, + .get_voltage_sel = tps65217_pmic_ldo_get_voltage_sel, + .set_voltage_sel = tps65217_pmic_ldo_set_voltage_sel, + .list_voltage = tps65217_pmic_ldo_list_voltage, +}; + +/* Operations permitted on LDO2, LDO3 and LDO4 */ +static struct regulator_ops tps65217_pmic_ldo234_ops = { + .is_enabled = tps65217_pmic_ldo_is_enabled, + .enable = tps65217_pmic_ldo_enable, + .disable = tps65217_pmic_ldo_disable, + .get_voltage_sel = tps65217_pmic_ldo_get_voltage_sel, + .set_voltage = tps65217_pmic_ldo_set_voltage, + .list_voltage = tps65217_pmic_ldo_list_voltage, +}; + +static struct regulator_desc regulators[] = { + TPS65217_REGULATOR("DCDC1", TPS65217_DCDC_1, + tps65217_pmic_dcdc_ops, 64), + TPS65217_REGULATOR("DCDC2",TPS65217_DCDC_2, + tps65217_pmic_dcdc_ops, 64), + TPS65217_REGULATOR("DCDC3", TPS65217_DCDC_3, + tps65217_pmic_dcdc_ops, 64), + TPS65217_REGULATOR("LDO1", TPS65217_LDO_1, + tps65217_pmic_ldo1_ops, 16), + TPS65217_REGULATOR("LDO2", TPS65217_LDO_2, + tps65217_pmic_ldo234_ops, 64), + TPS65217_REGULATOR("LDO3", TPS65217_LDO_3, + tps65217_pmic_ldo234_ops, 32), + TPS65217_REGULATOR("LDO4", TPS65217_LDO_4, + tps65217_pmic_ldo234_ops, 32), +}; + +static int __devinit tps65217_regulator_probe(struct platform_device *pdev) +{ + struct regulator_dev *rdev; + struct tps65217 *tps; + struct tps_info *info = &tps65217_pmic_regs[pdev->id]; + + /* Already set by core driver */ + tps = dev_to_tps65217(pdev->dev.parent); + tps->info[pdev->id] = info; + + rdev = regulator_register(®ulators[pdev->id], &pdev->dev, + pdev->dev.platform_data, tps); + if (IS_ERR(rdev)) + return PTR_ERR(rdev); + + platform_set_drvdata(pdev, rdev); + + return 0; +} + +static int __devexit tps65217_regulator_remove(struct platform_device *pdev) +{ + struct regulator_dev *rdev = platform_get_drvdata(pdev); + + platform_set_drvdata(pdev, NULL); + regulator_unregister(rdev); + + return 0; +} + +static struct platform_driver tps65217_regulator_driver = { + .driver = { + .name = "tps65217-pmic", + }, + .probe = tps65217_regulator_probe, + .remove = __devexit_p(tps65217_regulator_remove), +}; + +static int __init tps65217_regulator_init(void) +{ + return platform_driver_register(&tps65217_regulator_driver); +} +subsys_initcall(tps65217_regulator_init); + +static void __exit tps65217_regulator_exit(void) +{ + platform_driver_unregister(&tps65217_regulator_driver); +} +module_exit(tps65217_regulator_exit); + + +MODULE_AUTHOR("AnilKumar Ch "); +MODULE_DESCRIPTION("TPS65217 voltage regulator driver"); +MODULE_ALIAS("platform:tps65217-pmic"); +MODULE_LICENSE("GPL v2"); -- cgit v0.10.2 From b683d980d8cd91f95a00c9be95ea5116a7db7537 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Sun, 15 Jan 2012 20:25:22 +0800 Subject: regulator: Update tps65217-regulator for DT changes Signed-off-by: Axel Lin Signed-off-by: Mark Brown diff --git a/drivers/regulator/tps65217-regulator.c b/drivers/regulator/tps65217-regulator.c index 6665566..28a10ea 100644 --- a/drivers/regulator/tps65217-regulator.c +++ b/drivers/regulator/tps65217-regulator.c @@ -447,7 +447,7 @@ static int __devinit tps65217_regulator_probe(struct platform_device *pdev) tps->info[pdev->id] = info; rdev = regulator_register(®ulators[pdev->id], &pdev->dev, - pdev->dev.platform_data, tps); + pdev->dev.platform_data, tps, NULL); if (IS_ERR(rdev)) return PTR_ERR(rdev); -- cgit v0.10.2 From 0ce6987345a739fc3b2ac5da9c727c3b0133bb9c Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Tue, 17 Jan 2012 11:25:45 +0000 Subject: regulator: Update s5m8767 for device tree API changes Signed-off-by: Mark Brown diff --git a/drivers/regulator/s5m8767.c b/drivers/regulator/s5m8767.c index caf0117b..a5b9d83 100644 --- a/drivers/regulator/s5m8767.c +++ b/drivers/regulator/s5m8767.c @@ -771,7 +771,7 @@ static __devinit int s5m8767_pmic_probe(struct platform_device *pdev) (desc->max - desc->min) / desc->step + 1; rdev[i] = regulator_register(®ulators[id], s5m8767->dev, - pdata->regulators[i].initdata, s5m8767); + pdata->regulators[i].initdata, s5m8767, NULL); if (IS_ERR(rdev[i])) { ret = PTR_ERR(rdev[i]); dev_err(s5m8767->dev, "regulator init failed for %d\n", -- cgit v0.10.2 From c2f8efd7641b1b10b73ffa6f216a45209a5705dd Mon Sep 17 00:00:00 2001 From: Laxman Dewangan Date: Wed, 18 Jan 2012 20:46:56 +0530 Subject: regulator: tps65910: Add regulator info for RTC rail Adding missing regulator info for VRTC rail for device tps65911. The regulator voltage rail index start from VRTC which is defined as 0. Signed-off-by: Laxman Dewangan Signed-off-by: Mark Brown diff --git a/drivers/regulator/tps65910-regulator.c b/drivers/regulator/tps65910-regulator.c index 5c15ba0..6742418 100644 --- a/drivers/regulator/tps65910-regulator.c +++ b/drivers/regulator/tps65910-regulator.c @@ -175,6 +175,9 @@ static struct tps_info tps65910_regs[] = { static struct tps_info tps65911_regs[] = { { + .name = "VRTC", + }, + { .name = "VIO", .min_uV = 1500000, .max_uV = 3300000, -- cgit v0.10.2 From 070b9079226d4f3e3e7c9f4eb81f2e02e7d99572 Mon Sep 17 00:00:00 2001 From: Stephen Boyd Date: Mon, 16 Jan 2012 19:39:58 -0800 Subject: regulator: Add devm_regulator_get() Add a resource managed regulator_get() to simplify regulator usage in drivers. This allows driver authors to "get and forget" about their regulators by automatically calling regulator_put() when the driver is detached. [Fixed up a couple of coding style issues -- broonie] Signed-off-by: Stephen Boyd Signed-off-by: Mark Brown diff --git a/Documentation/driver-model/devres.txt b/Documentation/driver-model/devres.txt index 10c64c8..016fd2b 100644 --- a/Documentation/driver-model/devres.txt +++ b/Documentation/driver-model/devres.txt @@ -267,3 +267,6 @@ IOMAP pcim_iounmap() pcim_iomap_table() : array of mapped addresses indexed by BAR pcim_iomap_regions() : do request_region() and iomap() on multiple BARs + +REGULATOR + devm_regulator_get() diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index ca86f39..214640d 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -1320,6 +1320,40 @@ struct regulator *regulator_get(struct device *dev, const char *id) } EXPORT_SYMBOL_GPL(regulator_get); +static void devm_regulator_release(struct device *dev, void *res) +{ + regulator_put(*(struct regulator **)res); +} + +/** + * devm_regulator_get - Resource managed regulator_get() + * @dev: device for regulator "consumer" + * @id: Supply name or regulator ID. + * + * Managed regulator_get(). Regulators returned from this function are + * automatically regulator_put() on driver detach. See regulator_get() for more + * information. + */ +struct regulator *devm_regulator_get(struct device *dev, const char *id) +{ + struct regulator **ptr, *regulator; + + ptr = devres_alloc(devm_regulator_release, sizeof(*ptr), GFP_KERNEL); + if (!ptr) + return ERR_PTR(-ENOMEM); + + regulator = regulator_get(dev, id); + if (!IS_ERR(regulator)) { + *ptr = regulator; + devres_add(dev, ptr); + } else { + devres_free(ptr); + } + + return regulator; +} +EXPORT_SYMBOL_GPL(devm_regulator_get); + /** * regulator_get_exclusive - obtain exclusive access to a regulator. * @dev: device for regulator "consumer" diff --git a/include/linux/regulator/consumer.h b/include/linux/regulator/consumer.h index f2698a0..bcfe106 100644 --- a/include/linux/regulator/consumer.h +++ b/include/linux/regulator/consumer.h @@ -132,6 +132,8 @@ struct regulator_bulk_data { /* regulator get and put */ struct regulator *__must_check regulator_get(struct device *dev, const char *id); +struct regulator *__must_check devm_regulator_get(struct device *dev, + const char *id); struct regulator *__must_check regulator_get_exclusive(struct device *dev, const char *id); void regulator_put(struct regulator *regulator); @@ -200,6 +202,13 @@ static inline struct regulator *__must_check regulator_get(struct device *dev, */ return NULL; } + +static inline struct regulator *__must_check +devm_regulator_get(struct device *dev, const char *id) +{ + return NULL; +} + static inline void regulator_put(struct regulator *regulator) { } -- cgit v0.10.2 From 51ced5e288b4381705df173fb05f561dea35bfac Mon Sep 17 00:00:00 2001 From: Laxman Dewangan Date: Wed, 18 Jan 2012 20:47:16 +0530 Subject: regulator: tps65910: Initialize n_voltages for rails. Initializing the number of voltages supported by different rails of pmic device tps65911. Signed-off-by: Laxman Dewangan Signed-off-by: Mark Brown diff --git a/drivers/regulator/tps65910-regulator.c b/drivers/regulator/tps65910-regulator.c index 6742418..3ac5f91 100644 --- a/drivers/regulator/tps65910-regulator.c +++ b/drivers/regulator/tps65910-regulator.c @@ -188,56 +188,67 @@ static struct tps_info tps65911_regs[] = { .name = "VDD1", .min_uV = 600000, .max_uV = 4500000, + .table_len = 73, }, { .name = "VDD2", .min_uV = 600000, .max_uV = 4500000, + .table_len = 73, }, { .name = "VDDCTRL", .min_uV = 600000, .max_uV = 1400000, + .table_len = 65, }, { .name = "LDO1", .min_uV = 1000000, .max_uV = 3300000, + .table_len = 47, }, { .name = "LDO2", .min_uV = 1000000, .max_uV = 3300000, + .table_len = 47, }, { .name = "LDO3", .min_uV = 1000000, .max_uV = 3300000, + .table_len = 24, }, { .name = "LDO4", .min_uV = 1000000, .max_uV = 3300000, + .table_len = 47, }, { .name = "LDO5", .min_uV = 1000000, .max_uV = 3300000, + .table_len = 24, }, { .name = "LDO6", .min_uV = 1000000, .max_uV = 3300000, + .table_len = 24, }, { .name = "LDO7", .min_uV = 1000000, .max_uV = 3300000, + .table_len = 24, }, { .name = "LDO8", .min_uV = 1000000, .max_uV = 3300000, + .table_len = 24, }, }; -- cgit v0.10.2 From 7d38a3cb9b9f6a6d31b1d19e4f07a7c0b71407d5 Mon Sep 17 00:00:00 2001 From: Laxman Dewangan Date: Fri, 20 Jan 2012 16:36:22 +0530 Subject: regulator: tps65910: use appropriate variable names. Renaming the variables "table" to "voltage_table" and "table_len" to "n_voltages" of regulator information to have more meaningful. Signed-off-by: Laxman Dewangan Signed-off-by: Mark Brown diff --git a/drivers/regulator/tps65910-regulator.c b/drivers/regulator/tps65910-regulator.c index 3ac5f91..1d13cf9 100644 --- a/drivers/regulator/tps65910-regulator.c +++ b/drivers/regulator/tps65910-regulator.c @@ -83,8 +83,8 @@ struct tps_info { const char *name; unsigned min_uV; unsigned max_uV; - u8 table_len; - const u16 *table; + u8 n_voltages; + const u16 *voltage_table; }; static struct tps_info tps65910_regs[] = { @@ -95,8 +95,8 @@ static struct tps_info tps65910_regs[] = { .name = "VIO", .min_uV = 1500000, .max_uV = 3300000, - .table_len = ARRAY_SIZE(VIO_VSEL_table), - .table = VIO_VSEL_table, + .n_voltages = ARRAY_SIZE(VIO_VSEL_table), + .voltage_table = VIO_VSEL_table, }, { .name = "VDD1", @@ -112,64 +112,64 @@ static struct tps_info tps65910_regs[] = { .name = "VDD3", .min_uV = 5000000, .max_uV = 5000000, - .table_len = ARRAY_SIZE(VDD3_VSEL_table), - .table = VDD3_VSEL_table, + .n_voltages = ARRAY_SIZE(VDD3_VSEL_table), + .voltage_table = VDD3_VSEL_table, }, { .name = "VDIG1", .min_uV = 1200000, .max_uV = 2700000, - .table_len = ARRAY_SIZE(VDIG1_VSEL_table), - .table = VDIG1_VSEL_table, + .n_voltages = ARRAY_SIZE(VDIG1_VSEL_table), + .voltage_table = VDIG1_VSEL_table, }, { .name = "VDIG2", .min_uV = 1000000, .max_uV = 1800000, - .table_len = ARRAY_SIZE(VDIG2_VSEL_table), - .table = VDIG2_VSEL_table, + .n_voltages = ARRAY_SIZE(VDIG2_VSEL_table), + .voltage_table = VDIG2_VSEL_table, }, { .name = "VPLL", .min_uV = 1000000, .max_uV = 2500000, - .table_len = ARRAY_SIZE(VPLL_VSEL_table), - .table = VPLL_VSEL_table, + .n_voltages = ARRAY_SIZE(VPLL_VSEL_table), + .voltage_table = VPLL_VSEL_table, }, { .name = "VDAC", .min_uV = 1800000, .max_uV = 2850000, - .table_len = ARRAY_SIZE(VDAC_VSEL_table), - .table = VDAC_VSEL_table, + .n_voltages = ARRAY_SIZE(VDAC_VSEL_table), + .voltage_table = VDAC_VSEL_table, }, { .name = "VAUX1", .min_uV = 1800000, .max_uV = 2850000, - .table_len = ARRAY_SIZE(VAUX1_VSEL_table), - .table = VAUX1_VSEL_table, + .n_voltages = ARRAY_SIZE(VAUX1_VSEL_table), + .voltage_table = VAUX1_VSEL_table, }, { .name = "VAUX2", .min_uV = 1800000, .max_uV = 3300000, - .table_len = ARRAY_SIZE(VAUX2_VSEL_table), - .table = VAUX2_VSEL_table, + .n_voltages = ARRAY_SIZE(VAUX2_VSEL_table), + .voltage_table = VAUX2_VSEL_table, }, { .name = "VAUX33", .min_uV = 1800000, .max_uV = 3300000, - .table_len = ARRAY_SIZE(VAUX33_VSEL_table), - .table = VAUX33_VSEL_table, + .n_voltages = ARRAY_SIZE(VAUX33_VSEL_table), + .voltage_table = VAUX33_VSEL_table, }, { .name = "VMMC", .min_uV = 1800000, .max_uV = 3300000, - .table_len = ARRAY_SIZE(VMMC_VSEL_table), - .table = VMMC_VSEL_table, + .n_voltages = ARRAY_SIZE(VMMC_VSEL_table), + .voltage_table = VMMC_VSEL_table, }, }; @@ -181,74 +181,74 @@ static struct tps_info tps65911_regs[] = { .name = "VIO", .min_uV = 1500000, .max_uV = 3300000, - .table_len = ARRAY_SIZE(VIO_VSEL_table), - .table = VIO_VSEL_table, + .n_voltages = ARRAY_SIZE(VIO_VSEL_table), + .voltage_table = VIO_VSEL_table, }, { .name = "VDD1", .min_uV = 600000, .max_uV = 4500000, - .table_len = 73, + .n_voltages = 73, }, { .name = "VDD2", .min_uV = 600000, .max_uV = 4500000, - .table_len = 73, + .n_voltages = 73, }, { .name = "VDDCTRL", .min_uV = 600000, .max_uV = 1400000, - .table_len = 65, + .n_voltages = 65, }, { .name = "LDO1", .min_uV = 1000000, .max_uV = 3300000, - .table_len = 47, + .n_voltages = 47, }, { .name = "LDO2", .min_uV = 1000000, .max_uV = 3300000, - .table_len = 47, + .n_voltages = 47, }, { .name = "LDO3", .min_uV = 1000000, .max_uV = 3300000, - .table_len = 24, + .n_voltages = 24, }, { .name = "LDO4", .min_uV = 1000000, .max_uV = 3300000, - .table_len = 47, + .n_voltages = 47, }, { .name = "LDO5", .min_uV = 1000000, .max_uV = 3300000, - .table_len = 24, + .n_voltages = 24, }, { .name = "LDO6", .min_uV = 1000000, .max_uV = 3300000, - .table_len = 24, + .n_voltages = 24, }, { .name = "LDO7", .min_uV = 1000000, .max_uV = 3300000, - .table_len = 24, + .n_voltages = 24, }, { .name = "LDO8", .min_uV = 1000000, .max_uV = 3300000, - .table_len = 24, + .n_voltages = 24, }, }; @@ -586,7 +586,7 @@ static int tps65910_get_voltage(struct regulator_dev *dev) return -EINVAL; } - voltage = pmic->info[id]->table[value] * 1000; + voltage = pmic->info[id]->voltage_table[value] * 1000; return voltage; } @@ -636,7 +636,7 @@ static int tps65911_get_voltage(struct regulator_dev *dev) step_mv = 100; break; case TPS65910_REG_VIO: - return pmic->info[id]->table[value] * 1000; + return pmic->info[id]->voltage_table[value] * 1000; break; default: return -EINVAL; @@ -770,10 +770,10 @@ static int tps65910_list_voltage(struct regulator_dev *dev, if (id < TPS65910_REG_VIO || id > TPS65910_REG_VMMC) return -EINVAL; - if (selector >= pmic->info[id]->table_len) + if (selector >= pmic->info[id]->n_voltages) return -EINVAL; else - voltage = pmic->info[id]->table[selector] * 1000; + voltage = pmic->info[id]->voltage_table[selector] * 1000; return voltage; } @@ -809,7 +809,7 @@ static int tps65911_list_voltage(struct regulator_dev *dev, unsigned selector) step_mv = 100; break; case TPS65910_REG_VIO: - return pmic->info[id]->table[selector] * 1000; + return pmic->info[id]->voltage_table[selector] * 1000; default: return -EINVAL; } @@ -940,7 +940,7 @@ static __devinit int tps65910_probe(struct platform_device *pdev) pmic->desc[i].name = info->name; pmic->desc[i].id = i; - pmic->desc[i].n_voltages = info->table_len; + pmic->desc[i].n_voltages = info->n_voltages; if (i == TPS65910_REG_VDD1 || i == TPS65910_REG_VDD2) { pmic->desc[i].ops = &tps65910_ops_dcdc; -- cgit v0.10.2 From d5ad34f7cb8b23ab165cabef69577a2a20d53195 Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Fri, 20 Jan 2012 20:09:18 +0000 Subject: regulator: Implement devm_regulator_free() Allow consumers to free regulators allocated using devm_regulator_get() if they need to. This will not normally be required. Signed-off-by: Mark Brown diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 214640d..88bcb11 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -1421,6 +1421,34 @@ void regulator_put(struct regulator *regulator) } EXPORT_SYMBOL_GPL(regulator_put); +static int devm_regulator_match(struct device *dev, void *res, void *data) +{ + struct regulator **r = res; + if (!r || !*r) { + WARN_ON(!r || !*r); + return 0; + } + return *r == data; +} + +/** + * devm_regulator_put - Resource managed regulator_put() + * @regulator: regulator to free + * + * Deallocate a regulator allocated with devm_regulator_get(). Normally + * this function will not need to be called and the resource management + * code will ensure that the resource is freed. + */ +void devm_regulator_put(struct regulator *regulator) +{ + int rc; + + rc = devres_destroy(regulator->dev, devm_regulator_release, + devm_regulator_match, regulator); + WARN_ON(rc); +} +EXPORT_SYMBOL_GPL(devm_regulator_put); + static int _regulator_can_change_status(struct regulator_dev *rdev) { if (!rdev->constraints) diff --git a/include/linux/regulator/consumer.h b/include/linux/regulator/consumer.h index bcfe106..60c2f99 100644 --- a/include/linux/regulator/consumer.h +++ b/include/linux/regulator/consumer.h @@ -137,6 +137,7 @@ struct regulator *__must_check devm_regulator_get(struct device *dev, struct regulator *__must_check regulator_get_exclusive(struct device *dev, const char *id); void regulator_put(struct regulator *regulator); +void devm_regulator_free(struct regulator *regulator); /* regulator output control and status */ int regulator_enable(struct regulator *regulator); -- cgit v0.10.2 From e6e740304aa2a49ef09497e6c0bb906ed7987f6b Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Fri, 20 Jan 2012 20:10:08 +0000 Subject: regulator: Provide devm_regulator_bulk_get() Allow drivers to benefit from both the bulk APIs and managed resources simultaneously. Signed-off-by: Mark Brown diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 88bcb11..1432c22 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -2463,6 +2463,52 @@ err: } EXPORT_SYMBOL_GPL(regulator_bulk_get); +/** + * devm_regulator_bulk_get - managed get multiple regulator consumers + * + * @dev: Device to supply + * @num_consumers: Number of consumers to register + * @consumers: Configuration of consumers; clients are stored here. + * + * @return 0 on success, an errno on failure. + * + * This helper function allows drivers to get several regulator + * consumers in one operation with management, the regulators will + * automatically be freed when the device is unbound. If any of the + * regulators cannot be acquired then any regulators that were + * allocated will be freed before returning to the caller. + */ +int devm_regulator_bulk_get(struct device *dev, int num_consumers, + struct regulator_bulk_data *consumers) +{ + int i; + int ret; + + for (i = 0; i < num_consumers; i++) + consumers[i].consumer = NULL; + + for (i = 0; i < num_consumers; i++) { + consumers[i].consumer = devm_regulator_get(dev, + consumers[i].supply); + if (IS_ERR(consumers[i].consumer)) { + ret = PTR_ERR(consumers[i].consumer); + dev_err(dev, "Failed to get supply '%s': %d\n", + consumers[i].supply, ret); + consumers[i].consumer = NULL; + goto err; + } + } + + return 0; + +err: + for (i = 0; i < num_consumers && consumers[i].consumer; i++) + devm_regulator_put(consumers[i].consumer); + + return ret; +} +EXPORT_SYMBOL_GPL(devm_regulator_bulk_get); + static void regulator_bulk_enable_async(void *data, async_cookie_t cookie) { struct regulator_bulk_data *bulk = data; diff --git a/include/linux/regulator/consumer.h b/include/linux/regulator/consumer.h index 60c2f99..35c4283 100644 --- a/include/linux/regulator/consumer.h +++ b/include/linux/regulator/consumer.h @@ -148,6 +148,8 @@ int regulator_disable_deferred(struct regulator *regulator, int ms); int regulator_bulk_get(struct device *dev, int num_consumers, struct regulator_bulk_data *consumers); +int devm_regulator_bulk_get(struct device *dev, int num_consumers, + struct regulator_bulk_data *consumers); int regulator_bulk_enable(int num_consumers, struct regulator_bulk_data *consumers); int regulator_bulk_disable(int num_consumers, -- cgit v0.10.2 From e371ceb89f531280d30cadbdb8371656468705b1 Mon Sep 17 00:00:00 2001 From: Karol Lewandowski Date: Tue, 24 Jan 2012 12:31:11 +0100 Subject: regulator: max8997: Avoid spaces in regulator names max8997-pmic instantiated from device tree uses names, not numerical ids to distinguish between outputs. Replace spaces with underscores in said names to make it possible to describe these outputs as regulators in DTS. Signed-off-by: Karol Lewandowski Signed-off-by: Kyungmin Park Signed-off-by: Mark Brown diff --git a/drivers/regulator/max8997.c b/drivers/regulator/max8997.c index d26e864..bb7cd9d 100644 --- a/drivers/regulator/max8997.c +++ b/drivers/regulator/max8997.c @@ -908,13 +908,13 @@ static struct regulator_desc regulators[] = { }, regulator_desc_buck(7), { - .name = "EN32KHz AP", + .name = "EN32KHz_AP", .id = MAX8997_EN32KHZ_AP, .ops = &max8997_fixedvolt_ops, .type = REGULATOR_VOLTAGE, .owner = THIS_MODULE, }, { - .name = "EN32KHz CP", + .name = "EN32KHz_CP", .id = MAX8997_EN32KHZ_CP, .ops = &max8997_fixedvolt_ops, .type = REGULATOR_VOLTAGE, @@ -938,7 +938,7 @@ static struct regulator_desc regulators[] = { .type = REGULATOR_VOLTAGE, .owner = THIS_MODULE, }, { - .name = "CHARGER CV", + .name = "CHARGER_CV", .id = MAX8997_CHARGER_CV, .ops = &max8997_fixedstate_ops, .type = REGULATOR_VOLTAGE, @@ -950,7 +950,7 @@ static struct regulator_desc regulators[] = { .type = REGULATOR_CURRENT, .owner = THIS_MODULE, }, { - .name = "CHARGER TOPOFF", + .name = "CHARGER_TOPOFF", .id = MAX8997_CHARGER_TOPOFF, .ops = &max8997_charger_fixedstate_ops, .type = REGULATOR_CURRENT, -- cgit v0.10.2 From 2343933921efd553dea888fc844abb653824c4c8 Mon Sep 17 00:00:00 2001 From: Fabio Estevam Date: Tue, 24 Jan 2012 18:37:16 -0200 Subject: regulator: mc13xxx-regulator-core: Fix the build when driver is selected as module Fix the following build error when mc138xxx driver is built as module: ERROR: "mc13xxx_parse_regulators_dt" [drivers/regulator/mc13892-regulator.ko] undefined! ERROR: "mc13xxx_get_num_regulators_dt" [drivers/regulator/mc13892-regulator.ko] undefined! Reported-by: Randy Dunlap Signed-off-by: Fabio Estevam Signed-off-by: Mark Brown diff --git a/drivers/regulator/mc13xxx-regulator-core.c b/drivers/regulator/mc13xxx-regulator-core.c index 80ecafe..62dcd0a 100644 --- a/drivers/regulator/mc13xxx-regulator-core.c +++ b/drivers/regulator/mc13xxx-regulator-core.c @@ -254,6 +254,7 @@ int __devinit mc13xxx_get_num_regulators_dt(struct platform_device *pdev) return num; } +EXPORT_SYMBOL_GPL(mc13xxx_get_num_regulators_dt); struct mc13xxx_regulator_init_data * __devinit mc13xxx_parse_regulators_dt( struct platform_device *pdev, struct mc13xxx_regulator *regulators, @@ -291,6 +292,7 @@ struct mc13xxx_regulator_init_data * __devinit mc13xxx_parse_regulators_dt( return data; } +EXPORT_SYMBOL_GPL(mc13xxx_parse_regulators_dt); #endif MODULE_LICENSE("GPL v2"); -- cgit v0.10.2 From 49e226323d462785582750d9f38acca5ffa5dd48 Mon Sep 17 00:00:00 2001 From: Sylwester Nawrocki Date: Wed, 25 Jan 2012 12:35:38 +0100 Subject: regulator: Reverse the disable sequence in regulator_bulk_disable() Often there is a need for disabling a set of regulators in order opposite to the enable order. Currently the function regulator_bulk_disable() walks list of regulators in same order as regulator_bulk_enable(). This may cause trouble, especially for devices with mixed analogue and digital circuits. So reverse the disabling sequence of regulator_bulk_disable(). While at it, also correct the comment. Signed-off-by: Sylwester Nawrocki Signed-off-by: Kyungmin Park Signed-off-by: Mark Brown diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index ca86f39..daba2f6 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -2463,8 +2463,8 @@ EXPORT_SYMBOL_GPL(regulator_bulk_enable); * @return 0 on success, an errno on failure * * This convenience API allows consumers to disable multiple regulator - * clients in a single API call. If any consumers cannot be enabled - * then any others that were disabled will be disabled again prior to + * clients in a single API call. If any consumers cannot be disabled + * then any others that were disabled will be enabled again prior to * return. */ int regulator_bulk_disable(int num_consumers, @@ -2473,7 +2473,7 @@ int regulator_bulk_disable(int num_consumers, int i; int ret; - for (i = 0; i < num_consumers; i++) { + for (i = num_consumers - 1; i >= 0; --i) { ret = regulator_disable(consumers[i].consumer); if (ret != 0) goto err; @@ -2483,7 +2483,7 @@ int regulator_bulk_disable(int num_consumers, err: pr_err("Failed to disable %s: %d\n", consumers[i].supply, ret); - for (--i; i >= 0; --i) + for (++i; i < num_consumers; ++i) regulator_enable(consumers[i].consumer); return ret; -- cgit v0.10.2 From e24abd6ec6c2dabccb825dc41d1725bc496b3a54 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Fri, 27 Jan 2012 12:55:28 +0800 Subject: regulator: Add empty devm_regulator_bulk_get for !CONFIG_REGULATOR MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes below build error if CONFIG_REGULATOR is disabled. CC sound/soc/codecs/wm5100.o sound/soc/codecs/wm5100.c: In function ‘wm5100_i2c_probe’: sound/soc/codecs/wm5100.c:2462: error: implicit declaration of function ‘devm_regulator_bulk_get’ make[3]: *** [sound/soc/codecs/wm5100.o] Error 1 make[2]: *** [sound/soc/codecs] Error 2 make[1]: *** [sound/soc] Error 2 make: *** [sound] Error 2 Signed-off-by: Axel Lin Signed-off-by: Mark Brown diff --git a/include/linux/regulator/consumer.h b/include/linux/regulator/consumer.h index 35c4283..cef8f04 100644 --- a/include/linux/regulator/consumer.h +++ b/include/linux/regulator/consumer.h @@ -249,6 +249,12 @@ static inline int regulator_bulk_get(struct device *dev, return 0; } +static inline int devm_regulator_bulk_get(struct device *dev, int num_consumers, + struct regulator_bulk_data *consumers) +{ + return 0; +} + static inline int regulator_bulk_enable(int num_consumers, struct regulator_bulk_data *consumers) { -- cgit v0.10.2 From 2950c4bbf397fc7d3d778a97c32bba0e955b47fe Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Sun, 29 Jan 2012 17:52:37 +0800 Subject: regulator: Add devm_regulator_put in consumer.h Commit d5ad34f7cb "regulator: Implement devm_regulator_free()" actually implements devm_regulator_put. Thus rename devm_regulator_free to devm_regulator_put. Also add empty devm_regulator_put for !CONFIG_REGULATOR Signed-off-by: Axel Lin Signed-off-by: Mark Brown diff --git a/include/linux/regulator/consumer.h b/include/linux/regulator/consumer.h index cef8f04..b6c8d71 100644 --- a/include/linux/regulator/consumer.h +++ b/include/linux/regulator/consumer.h @@ -137,7 +137,7 @@ struct regulator *__must_check devm_regulator_get(struct device *dev, struct regulator *__must_check regulator_get_exclusive(struct device *dev, const char *id); void regulator_put(struct regulator *regulator); -void devm_regulator_free(struct regulator *regulator); +void devm_regulator_put(struct regulator *regulator); /* regulator output control and status */ int regulator_enable(struct regulator *regulator); @@ -216,6 +216,10 @@ static inline void regulator_put(struct regulator *regulator) { } +static inline void devm_regulator_put(struct regulator *regulator) +{ +} + static inline int regulator_enable(struct regulator *regulator) { return 0; -- cgit v0.10.2 From 1e0c66f49762fa1866ab20b1feb6e86a9aa4838f Mon Sep 17 00:00:00 2001 From: Laxman Dewangan Date: Sat, 28 Jan 2012 15:07:57 +0530 Subject: regulator: tps65910: Sleep control through external inputs Add support for sleep controls of different regulator through external inputs EN1, EN2 or EN3. Each regulator's output will be active when its external input is high and turns to OFF/Low power mode when its external input is low. The configuration parameters for sleep control is provided through board specific platform data. Signed-off-by: Laxman Dewangan Signed-off-by: Mark Brown diff --git a/drivers/regulator/tps65910-regulator.c b/drivers/regulator/tps65910-regulator.c index 1d13cf9..9092b7f 100644 --- a/drivers/regulator/tps65910-regulator.c +++ b/drivers/regulator/tps65910-regulator.c @@ -26,6 +26,9 @@ #include #define TPS65910_SUPPLY_STATE_ENABLED 0x1 +#define EXT_SLEEP_CONTROL (TPS65910_SLEEP_CONTROL_EXT_INPUT_EN1 | \ + TPS65910_SLEEP_CONTROL_EXT_INPUT_EN2 | \ + TPS65910_SLEEP_CONTROL_EXT_INPUT_EN3) /* supported VIO voltages in milivolts */ static const u16 VIO_VSEL_table[] = { @@ -252,6 +255,39 @@ static struct tps_info tps65911_regs[] = { }, }; +#define EXT_CONTROL_REG_BITS(id, regs_offs, bits) (((regs_offs) << 8) | (bits)) +static unsigned int tps65910_ext_sleep_control[] = { + 0, + EXT_CONTROL_REG_BITS(VIO, 1, 0), + EXT_CONTROL_REG_BITS(VDD1, 1, 1), + EXT_CONTROL_REG_BITS(VDD2, 1, 2), + EXT_CONTROL_REG_BITS(VDD3, 1, 3), + EXT_CONTROL_REG_BITS(VDIG1, 0, 1), + EXT_CONTROL_REG_BITS(VDIG2, 0, 2), + EXT_CONTROL_REG_BITS(VPLL, 0, 6), + EXT_CONTROL_REG_BITS(VDAC, 0, 7), + EXT_CONTROL_REG_BITS(VAUX1, 0, 3), + EXT_CONTROL_REG_BITS(VAUX2, 0, 4), + EXT_CONTROL_REG_BITS(VAUX33, 0, 5), + EXT_CONTROL_REG_BITS(VMMC, 0, 0), +}; + +static unsigned int tps65911_ext_sleep_control[] = { + 0, + EXT_CONTROL_REG_BITS(VIO, 1, 0), + EXT_CONTROL_REG_BITS(VDD1, 1, 1), + EXT_CONTROL_REG_BITS(VDD2, 1, 2), + EXT_CONTROL_REG_BITS(VDDCTRL, 1, 3), + EXT_CONTROL_REG_BITS(LDO1, 0, 1), + EXT_CONTROL_REG_BITS(LDO2, 0, 2), + EXT_CONTROL_REG_BITS(LDO3, 0, 7), + EXT_CONTROL_REG_BITS(LDO4, 0, 6), + EXT_CONTROL_REG_BITS(LDO5, 0, 3), + EXT_CONTROL_REG_BITS(LDO6, 0, 0), + EXT_CONTROL_REG_BITS(LDO7, 0, 5), + EXT_CONTROL_REG_BITS(LDO8, 0, 4), +}; + struct tps65910_reg { struct regulator_desc *desc; struct tps65910 *mfd; @@ -261,6 +297,8 @@ struct tps65910_reg { int num_regulators; int mode; int (*get_ctrl_reg)(int); + unsigned int *ext_sleep_control; + unsigned int board_ext_control[TPS65910_NUM_REGS]; }; static inline int tps65910_read(struct tps65910_reg *pmic, u8 reg) @@ -861,6 +899,131 @@ static struct regulator_ops tps65911_ops = { .list_voltage = tps65911_list_voltage, }; +static int tps65910_set_ext_sleep_config(struct tps65910_reg *pmic, + int id, int ext_sleep_config) +{ + struct tps65910 *mfd = pmic->mfd; + u8 regoffs = (pmic->ext_sleep_control[id] >> 8) & 0xFF; + u8 bit_pos = (1 << pmic->ext_sleep_control[id] & 0xFF); + int ret; + + /* + * Regulator can not be control from multiple external input EN1, EN2 + * and EN3 together. + */ + if (ext_sleep_config & EXT_SLEEP_CONTROL) { + int en_count; + en_count = ((ext_sleep_config & + TPS65910_SLEEP_CONTROL_EXT_INPUT_EN1) != 0); + en_count += ((ext_sleep_config & + TPS65910_SLEEP_CONTROL_EXT_INPUT_EN2) != 0); + en_count += ((ext_sleep_config & + TPS65910_SLEEP_CONTROL_EXT_INPUT_EN3) != 0); + if (en_count > 1) { + dev_err(mfd->dev, + "External sleep control flag is not proper\n"); + return -EINVAL; + } + } + + pmic->board_ext_control[id] = ext_sleep_config; + + /* External EN1 control */ + if (ext_sleep_config & TPS65910_SLEEP_CONTROL_EXT_INPUT_EN1) + ret = tps65910_set_bits(mfd, + TPS65910_EN1_LDO_ASS + regoffs, bit_pos); + else + ret = tps65910_clear_bits(mfd, + TPS65910_EN1_LDO_ASS + regoffs, bit_pos); + if (ret < 0) { + dev_err(mfd->dev, + "Error in configuring external control EN1\n"); + return ret; + } + + /* External EN2 control */ + if (ext_sleep_config & TPS65910_SLEEP_CONTROL_EXT_INPUT_EN2) + ret = tps65910_set_bits(mfd, + TPS65910_EN2_LDO_ASS + regoffs, bit_pos); + else + ret = tps65910_clear_bits(mfd, + TPS65910_EN2_LDO_ASS + regoffs, bit_pos); + if (ret < 0) { + dev_err(mfd->dev, + "Error in configuring external control EN2\n"); + return ret; + } + + /* External EN3 control for TPS65910 LDO only */ + if ((tps65910_chip_id(mfd) == TPS65910) && + (id >= TPS65910_REG_VDIG1)) { + if (ext_sleep_config & TPS65910_SLEEP_CONTROL_EXT_INPUT_EN3) + ret = tps65910_set_bits(mfd, + TPS65910_EN3_LDO_ASS + regoffs, bit_pos); + else + ret = tps65910_clear_bits(mfd, + TPS65910_EN3_LDO_ASS + regoffs, bit_pos); + if (ret < 0) { + dev_err(mfd->dev, + "Error in configuring external control EN3\n"); + return ret; + } + } + + /* Return if no external control is selected */ + if (!(ext_sleep_config & EXT_SLEEP_CONTROL)) { + /* Clear all sleep controls */ + ret = tps65910_clear_bits(mfd, + TPS65910_SLEEP_KEEP_LDO_ON + regoffs, bit_pos); + if (!ret) + ret = tps65910_clear_bits(mfd, + TPS65910_SLEEP_SET_LDO_OFF + regoffs, bit_pos); + if (ret < 0) + dev_err(mfd->dev, + "Error in configuring SLEEP register\n"); + return ret; + } + + /* + * For regulator that has separate operational and sleep register make + * sure that operational is used and clear sleep register to turn + * regulator off when external control is inactive + */ + if ((id == TPS65910_REG_VDD1) || + (id == TPS65910_REG_VDD2) || + ((id == TPS65911_REG_VDDCTRL) && + (tps65910_chip_id(mfd) == TPS65911))) { + int op_reg_add = pmic->get_ctrl_reg(id) + 1; + int sr_reg_add = pmic->get_ctrl_reg(id) + 2; + int opvsel = tps65910_reg_read(pmic, op_reg_add); + int srvsel = tps65910_reg_read(pmic, sr_reg_add); + if (opvsel & VDD1_OP_CMD_MASK) { + u8 reg_val = srvsel & VDD1_OP_SEL_MASK; + ret = tps65910_reg_write(pmic, op_reg_add, reg_val); + if (ret < 0) { + dev_err(mfd->dev, + "Error in configuring op register\n"); + return ret; + } + } + ret = tps65910_reg_write(pmic, sr_reg_add, 0); + if (ret < 0) { + dev_err(mfd->dev, "Error in settting sr register\n"); + return ret; + } + } + + ret = tps65910_clear_bits(mfd, + TPS65910_SLEEP_KEEP_LDO_ON + regoffs, bit_pos); + if (!ret) + ret = tps65910_set_bits(mfd, + TPS65910_SLEEP_SET_LDO_OFF + regoffs, bit_pos); + if (ret < 0) + dev_err(mfd->dev, + "Error in configuring SLEEP register\n"); + return ret; +} + static __devinit int tps65910_probe(struct platform_device *pdev) { struct tps65910 *tps65910 = dev_get_drvdata(pdev->dev.parent); @@ -891,11 +1054,13 @@ static __devinit int tps65910_probe(struct platform_device *pdev) case TPS65910: pmic->get_ctrl_reg = &tps65910_get_ctrl_register; pmic->num_regulators = ARRAY_SIZE(tps65910_regs); + pmic->ext_sleep_control = tps65910_ext_sleep_control; info = tps65910_regs; break; case TPS65911: pmic->get_ctrl_reg = &tps65911_get_ctrl_register; pmic->num_regulators = ARRAY_SIZE(tps65911_regs); + pmic->ext_sleep_control = tps65911_ext_sleep_control; info = tps65911_regs; break; default: @@ -958,6 +1123,16 @@ static __devinit int tps65910_probe(struct platform_device *pdev) pmic->desc[i].ops = &tps65911_ops; } + err = tps65910_set_ext_sleep_config(pmic, i, + pmic_plat_data->regulator_ext_sleep_control[i]); + /* + * Failing on regulator for configuring externally control + * is not a serious issue, just throw warning. + */ + if (err < 0) + dev_warn(tps65910->dev, + "Failed to initialise ext control config\n"); + pmic->desc[i].type = REGULATOR_VOLTAGE; pmic->desc[i].owner = THIS_MODULE; @@ -1004,6 +1179,36 @@ static int __devexit tps65910_remove(struct platform_device *pdev) return 0; } +static void tps65910_shutdown(struct platform_device *pdev) +{ + struct tps65910_reg *pmic = platform_get_drvdata(pdev); + int i; + + /* + * Before bootloader jumps to kernel, it makes sure that required + * external control signals are in desired state so that given rails + * can be configure accordingly. + * If rails are configured to be controlled from external control + * then before shutting down/rebooting the system, the external + * control configuration need to be remove from the rails so that + * its output will be available as per register programming even + * if external controls are removed. This is require when the POR + * value of the control signals are not in active state and before + * bootloader initializes it, the system requires the rail output + * to be active for booting. + */ + for (i = 0; i < pmic->num_regulators; i++) { + int err; + if (!pmic->rdev[i]) + continue; + + err = tps65910_set_ext_sleep_config(pmic, i, 0); + if (err < 0) + dev_err(&pdev->dev, + "Error in clearing external control\n"); + } +} + static struct platform_driver tps65910_driver = { .driver = { .name = "tps65910-pmic", @@ -1011,6 +1216,7 @@ static struct platform_driver tps65910_driver = { }, .probe = tps65910_probe, .remove = __devexit_p(tps65910_remove), + .shutdown = tps65910_shutdown, }; static int __init tps65910_init(void) diff --git a/include/linux/mfd/tps65910.h b/include/linux/mfd/tps65910.h index d0cb12e..fa6c6bf 100644 --- a/include/linux/mfd/tps65910.h +++ b/include/linux/mfd/tps65910.h @@ -768,6 +768,13 @@ /* Max number of TPS65910/11 regulators */ #define TPS65910_NUM_REGS 13 +/* External sleep controls through EN1/EN2/EN3 inputs*/ +#define TPS65910_SLEEP_CONTROL_EXT_INPUT_EN1 0x1 +#define TPS65910_SLEEP_CONTROL_EXT_INPUT_EN2 0x2 +#define TPS65910_SLEEP_CONTROL_EXT_INPUT_EN3 0x4 +/* TPS65911 names the EN3 signal as SLEEP */ +#define TPS65911_SLEEP_CONTROL_EXT_INPUT_SLEEP 0x4 + /** * struct tps65910_board * Board platform data may be used to initialize regulators. @@ -779,6 +786,7 @@ struct tps65910_board { int irq_base; int vmbch_threshold; int vmbch2_threshold; + unsigned long regulator_ext_sleep_control[TPS65910_NUM_REGS]; struct regulator_init_data *tps65910_pmic_init_data[TPS65910_NUM_REGS]; }; -- cgit v0.10.2 From c1432b1ebc684890ac81915695617ff4adfec357 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Tue, 31 Jan 2012 14:44:01 +0800 Subject: regulator: add devm_regulator_* to the list of managed interfaces Add devm_regulator_put() and devm_regulator_bulk_get() to the list of managed interfaces. Signed-off-by: Axel Lin Acked-by: Tejun Heo Signed-off-by: Mark Brown diff --git a/Documentation/driver-model/devres.txt b/Documentation/driver-model/devres.txt index 016fd2b..0cab4af 100644 --- a/Documentation/driver-model/devres.txt +++ b/Documentation/driver-model/devres.txt @@ -270,3 +270,5 @@ IOMAP REGULATOR devm_regulator_get() + devm_regulator_put() + devm_regulator_bulk_get() -- cgit v0.10.2 From 34ce8d07e63baa37d21aeca87f3248b008114899 Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Thu, 2 Feb 2012 13:45:09 +0000 Subject: regulator: wm8350: Don't specify consumer supplies with struct device Very, very deprecated. Signed-off-by: Mark Brown diff --git a/drivers/regulator/wm8350-regulator.c b/drivers/regulator/wm8350-regulator.c index 6894009..4f46067 100644 --- a/drivers/regulator/wm8350-regulator.c +++ b/drivers/regulator/wm8350-regulator.c @@ -1544,7 +1544,7 @@ int wm8350_register_led(struct wm8350 *wm8350, int lednum, int dcdc, int isink, return -ENOMEM; } - led->isink_consumer.dev = &pdev->dev; + led->isink_consumer.dev_name = dev_name(&pdev->dev); led->isink_consumer.supply = "led_isink"; led->isink_init.num_consumer_supplies = 1; led->isink_init.consumer_supplies = &led->isink_consumer; @@ -1559,7 +1559,7 @@ int wm8350_register_led(struct wm8350 *wm8350, int lednum, int dcdc, int isink, return ret; } - led->dcdc_consumer.dev = &pdev->dev; + led->dcdc_consumer.dev_name = dev_name(&pdev->dev); led->dcdc_consumer.supply = "led_vcc"; led->dcdc_init.num_consumer_supplies = 1; led->dcdc_init.consumer_supplies = &led->dcdc_consumer; -- cgit v0.10.2 From 20a14b84f8d62ba9ad7acad1d67a2ffa3c06468b Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Tue, 31 Jan 2012 15:13:31 +0800 Subject: regulator: Kill s5m8767_get_reg_id function Calling s5m8767_get_reg_id() is exactly the same as calling rdev_get_id(). It is pointless to add s5m8767_get_reg_id() function. Use rdev_get_id() directly and remove s5m8767_get_reg_id() function. Signed-off-by: Axel Lin Signed-off-by: Mark Brown diff --git a/drivers/regulator/s5m8767.c b/drivers/regulator/s5m8767.c index a5b9d83..5b00e5a 100644 --- a/drivers/regulator/s5m8767.c +++ b/drivers/regulator/s5m8767.c @@ -120,16 +120,11 @@ static const struct s5m_voltage_desc *reg_voltage_map[] = { [S5M8767_BUCK9] = &buck_voltage_val3, }; -static inline int s5m8767_get_reg_id(struct regulator_dev *rdev) -{ - return rdev_get_id(rdev); -} - static int s5m8767_list_voltage(struct regulator_dev *rdev, unsigned int selector) { const struct s5m_voltage_desc *desc; - int reg_id = s5m8767_get_reg_id(rdev); + int reg_id = rdev_get_id(rdev); int val; if (reg_id >= ARRAY_SIZE(reg_voltage_map) || reg_id < 0) @@ -148,7 +143,7 @@ static int s5m8767_list_voltage(struct regulator_dev *rdev, static int s5m8767_get_register(struct regulator_dev *rdev, int *reg) { - int reg_id = s5m8767_get_reg_id(rdev); + int reg_id = rdev_get_id(rdev); switch (reg_id) { case S5M8767_LDO1 ... S5M8767_LDO2: @@ -224,7 +219,7 @@ static int s5m8767_reg_disable(struct regulator_dev *rdev) static int s5m8767_get_voltage_register(struct regulator_dev *rdev, int *_reg) { - int reg_id = s5m8767_get_reg_id(rdev); + int reg_id = rdev_get_id(rdev); int reg; switch (reg_id) { @@ -265,7 +260,7 @@ static int s5m8767_get_voltage_sel(struct regulator_dev *rdev) { struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev); int reg, mask = 0xff, ret; - int reg_id = s5m8767_get_reg_id(rdev); + int reg_id = rdev_get_id(rdev); u8 val; ret = s5m8767_get_voltage_register(rdev, ®); @@ -325,7 +320,7 @@ static int s5m8767_set_voltage(struct regulator_dev *rdev, struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev); int min_vol = min_uV, max_vol = max_uV; const struct s5m_voltage_desc *desc; - int reg_id = s5m8767_get_reg_id(rdev); + int reg_id = rdev_get_id(rdev); int reg, mask, ret; int i; u8 val; @@ -387,7 +382,7 @@ static int s5m8767_set_voltage_buck(struct regulator_dev *rdev, int min_uV, int max_uV, unsigned *selector) { struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev); - int reg_id = s5m8767_get_reg_id(rdev); + int reg_id = rdev_get_id(rdev); const struct s5m_voltage_desc *desc; int new_val, old_val, i = 0; int min_vol = min_uV, max_vol = max_uV; @@ -456,7 +451,7 @@ static int s5m8767_set_voltage_time_sel(struct regulator_dev *rdev, { struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev); const struct s5m_voltage_desc *desc; - int reg_id = s5m8767_get_reg_id(rdev); + int reg_id = rdev_get_id(rdev); int mask; int new_val, old_val; -- cgit v0.10.2 From 737f360d5bef5e01c6cfa755dca0b449a154c1e0 Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Thu, 2 Feb 2012 00:10:51 +0000 Subject: regulator: Remove support for supplies specified by struct device This has been deprecated for a very long time now. Signed-off-by: Mark Brown Reviewed-by: Linus Walleij Acked-by: Liam Girdwood diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index e9a83f8..b9c900e 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -996,7 +996,6 @@ static int set_supply(struct regulator_dev *rdev, /** * set_consumer_device_supply - Bind a regulator to a symbolic supply * @rdev: regulator source - * @consumer_dev: device the supply applies to * @consumer_dev_name: dev_name() string for device supply applies to * @supply: symbolic name for supply * @@ -1008,18 +1007,12 @@ static int set_supply(struct regulator_dev *rdev, * Only one of consumer_dev and consumer_dev_name may be specified. */ static int set_consumer_device_supply(struct regulator_dev *rdev, - struct device *consumer_dev, const char *consumer_dev_name, - const char *supply) + const char *consumer_dev_name, + const char *supply) { struct regulator_map *node; int has_dev; - if (consumer_dev && consumer_dev_name) - return -EINVAL; - - if (!consumer_dev_name && consumer_dev) - consumer_dev_name = dev_name(consumer_dev); - if (supply == NULL) return -EINVAL; @@ -1039,11 +1032,12 @@ static int set_consumer_device_supply(struct regulator_dev *rdev, if (strcmp(node->supply, supply) != 0) continue; - dev_dbg(consumer_dev, "%s/%s is '%s' supply; fail %s/%s\n", - dev_name(&node->regulator->dev), - node->regulator->desc->name, - supply, - dev_name(&rdev->dev), rdev_get_name(rdev)); + pr_debug("%s: %s/%s is '%s' supply; fail %s/%s\n", + consumer_dev_name, + dev_name(&node->regulator->dev), + node->regulator->desc->name, + supply, + dev_name(&rdev->dev), rdev_get_name(rdev)); return -EBUSY; } @@ -2855,7 +2849,6 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, if (init_data) { for (i = 0; i < init_data->num_consumer_supplies; i++) { ret = set_consumer_device_supply(rdev, - init_data->consumer_supplies[i].dev, init_data->consumer_supplies[i].dev_name, init_data->consumer_supplies[i].supply); if (ret < 0) { diff --git a/include/linux/regulator/machine.h b/include/linux/regulator/machine.h index f3f13fd..7abb160 100644 --- a/include/linux/regulator/machine.h +++ b/include/linux/regulator/machine.h @@ -139,12 +139,10 @@ struct regulation_constraints { * make struct device available late such as I2C and is the preferred * form. * - * @dev: Device structure for the consumer. * @dev_name: Result of dev_name() for the consumer. * @supply: Name for the supply. */ struct regulator_consumer_supply { - struct device *dev; /* consumer */ const char *dev_name; /* dev_name() for consumer */ const char *supply; /* consumer supply - e.g. "vcc" */ }; -- cgit v0.10.2 From 1b65fa8496059d919a16b8431672d11e199ae515 Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Fri, 3 Feb 2012 11:02:58 +0000 Subject: mfd: twl-core: Don't specify regulator consumers by struct device This has been deprecated for considerable time now and support has been removed from the regulator API. dev_name should be used instead. Signed-off-by: Mark Brown diff --git a/drivers/mfd/twl-core.c b/drivers/mfd/twl-core.c index e04e04d..8dcf70f 100644 --- a/drivers/mfd/twl-core.c +++ b/drivers/mfd/twl-core.c @@ -751,9 +751,9 @@ add_children(struct twl4030_platform_data *pdata, unsigned long features) /* we need to connect regulators to this transceiver */ if (twl_has_regulator() && child) { - usb1v5.dev = child; - usb1v8.dev = child; - usb3v1.dev = child; + usb1v5.dev_name = dev_name(child); + usb1v8.dev_name = dev_name(child); + usb3v1.dev_name = dev_name(child); } } if (twl_has_usb() && pdata->usb && twl_class_is_6030()) { @@ -799,7 +799,7 @@ add_children(struct twl4030_platform_data *pdata, unsigned long features) return PTR_ERR(child); /* we need to connect regulators to this transceiver */ if (twl_has_regulator() && child) - usb3v3.dev = child; + usb3v3.dev_name = dev_name(child); } else if (twl_has_regulator() && twl_class_is_6030()) { if (features & TWL6025_SUBCLASS) child = add_regulator(TWL6025_REG_LDOUSB, -- cgit v0.10.2 From 0c3d0b20cf9cee1023b1a2e27cfd79db95b578b5 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Mon, 6 Feb 2012 21:01:14 +0800 Subject: regulator: Remove redundant regmap_update_bits call for TPS65023_REG_CON_CTRL2 This looks like a merge mistake. Calling regmap_update_bits once is enough. Signed-off-by: Axel Lin Signed-off-by: Mark Brown diff --git a/drivers/regulator/tps65023-regulator.c b/drivers/regulator/tps65023-regulator.c index 18d61a0..43e4902 100644 --- a/drivers/regulator/tps65023-regulator.c +++ b/drivers/regulator/tps65023-regulator.c @@ -491,10 +491,6 @@ static int __devinit tps_65023_probe(struct i2c_client *client, regmap_update_bits(tps->regmap, TPS65023_REG_CON_CTRL2, TPS65023_REG_CTRL2_CORE_ADJ, TPS65023_REG_CTRL2_CORE_ADJ); - /* Enable setting output voltage by I2C */ - regmap_update_bits(tps->regmap, TPS65023_REG_CON_CTRL2, - TPS65023_REG_CTRL2_CORE_ADJ, TPS65023_REG_CTRL2_CORE_ADJ); - return 0; fail: -- cgit v0.10.2 From da7de6a161d280736f399a378e43ea9e6861bd04 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Mon, 6 Feb 2012 20:37:46 +0800 Subject: regulator: Show correct chip id for max8649 Signed-off-by: Axel Lin Signed-off-by: Mark Brown diff --git a/drivers/regulator/max8649.c b/drivers/regulator/max8649.c index b06a239..636dfd4 100644 --- a/drivers/regulator/max8649.c +++ b/drivers/regulator/max8649.c @@ -270,7 +270,7 @@ static int __devinit max8649_regulator_probe(struct i2c_client *client, ret); goto out; } - dev_info(info->dev, "Detected MAX8649 (ID:%x)\n", ret); + dev_info(info->dev, "Detected MAX8649 (ID:%x)\n", val); /* enable VID0 & VID1 */ regmap_update_bits(info->regmap, MAX8649_CONTROL, MAX8649_VID_MASK, 0); -- cgit v0.10.2 From 43f674a322aa8a3404df5785f84dc1351a5d84b6 Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Thu, 9 Feb 2012 13:08:39 +0000 Subject: regulator: Don't add the function name to pr_fmt Liam pointed out via IM that since we now use the pure function name for all regulator logging a lot of the messages such as those logging the constraints are getting a bit noisy due to the implementation detail that is the function name: print_constraints: VDDARM: 1000 <--> 1300 mV at 1300 mV at 0 mA In discussion it seemed like the best thing was to just drop the pr_fmt and clarify individual log messages where there is an issue otherwise we get into silly things like renaming the functions to suit the logging. This is mostly an issue as we have a moderate amount of non-error logging in the boot sequence to aid debug if something goes wrong since regulator misconfiguration can kill the system pretty quickly. Signed-off-by: Mark Brown Acked-by: Liam Girdwood diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index daba2f6..e3271da 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -13,8 +13,6 @@ * */ -#define pr_fmt(fmt) "%s: " fmt, __func__ - #include #include #include -- cgit v0.10.2 From 4a682922817fde4d82fed4303dc902c29d7b2e4e Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Thu, 9 Feb 2012 13:26:13 +0000 Subject: regulator: Complain if a voltage range is specified but can't be used It doesn't make much sense to specify a range of voltages consumers can use if they haven't been given permission to change the voltage. Log if this happens, probably the user forgot to specify CHANGE_VOLTAGE. Signed-off-by: Mark Brown Acked-by: Liam Girdwood diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index e3271da..9a143ae 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -805,6 +805,11 @@ static void print_constraints(struct regulator_dev *rdev) count += sprintf(buf + count, "standby"); rdev_info(rdev, "%s\n", buf); + + if ((constraints->min_uV != constraints->max_uV) && + !(constraints->valid_ops_mask & REGULATOR_CHANGE_VOLTAGE)) + rdev_warn(rdev, + "Voltage range but no REGULATOR_CHANGE_VOLTAGE\n"); } static int machine_constraints_voltage(struct regulator_dev *rdev, -- cgit v0.10.2 From fde297bb4d8075229b8985e9d4f96d32339a8e68 Mon Sep 17 00:00:00 2001 From: "Kim, Milo" Date: Thu, 16 Feb 2012 22:41:32 -0800 Subject: regulator: fix wrong header name in description The 'mode' is defined in consumer.h. * patch base version : linux-3.2.4 Signed-off-by: Milo(Woogyom) Kim Signed-off-by: Mark Brown diff --git a/include/linux/regulator/driver.h b/include/linux/regulator/driver.h index 4214b9a..aeaf3a7 100644 --- a/include/linux/regulator/driver.h +++ b/include/linux/regulator/driver.h @@ -104,7 +104,7 @@ struct regulator_ops { int (*disable) (struct regulator_dev *); int (*is_enabled) (struct regulator_dev *); - /* get/set regulator operating mode (defined in regulator.h) */ + /* get/set regulator operating mode (defined in consumer.h) */ int (*set_mode) (struct regulator_dev *, unsigned int mode); unsigned int (*get_mode) (struct regulator_dev *); @@ -135,7 +135,7 @@ struct regulator_ops { int (*set_suspend_enable) (struct regulator_dev *); int (*set_suspend_disable) (struct regulator_dev *); - /* set regulator suspend operating mode (defined in regulator.h) */ + /* set regulator suspend operating mode (defined in consumer.h) */ int (*set_suspend_mode) (struct regulator_dev *, unsigned int mode); }; -- cgit v0.10.2 From 0e2576ceffd4b5362023b765b11ed647c06ffc2d Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Fri, 17 Feb 2012 11:23:49 +0800 Subject: ARM: U300: Don't specify regulator consumers by struct device The dev field is remove from struct regulator_consumer_supply since commit 737f36 "regulator: Remove support for supplies specified by struct device". This fixes below build error: CC arch/arm/mach-u300/i2c.o arch/arm/mach-u300/i2c.c:63: error: unknown field 'dev' specified in initializer arch/arm/mach-u300/i2c.c:95: error: unknown field 'dev' specified in initializer make[1]: *** [arch/arm/mach-u300/i2c.o] Error 1 make: *** [arch/arm/mach-u300] Error 2 Signed-off-by: Axel Lin Acked-by: Linus Walleij Signed-off-by: Mark Brown diff --git a/arch/arm/mach-u300/i2c.c b/arch/arm/mach-u300/i2c.c index 5140dee..a38f802 100644 --- a/arch/arm/mach-u300/i2c.c +++ b/arch/arm/mach-u300/i2c.c @@ -60,7 +60,6 @@ static struct regulator_consumer_supply supply_ldo_c[] = { */ static struct regulator_consumer_supply supply_ldo_d[] = { { - .dev = NULL, .supply = "vana15", /* Powers the SoC (CPU etc) */ }, }; @@ -92,7 +91,6 @@ static struct regulator_consumer_supply supply_ldo_k[] = { */ static struct regulator_consumer_supply supply_ldo_ext[] = { { - .dev = NULL, .supply = "vext", /* External power */ }, }; -- cgit v0.10.2 From 5bc78015998e14bf0362a01fc47e8b63053dbfd8 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Sat, 18 Feb 2012 22:53:15 +0800 Subject: regulator: Remove obsolete consumer_dev related comment consumer_dev is remove by commit 737f36 "regulator: Remove support for supplies specified by struct device". Thus remove the obsolete comment. Signed-off-by: Axel Lin Signed-off-by: Mark Brown diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index b9c900e..645c122 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -1003,8 +1003,6 @@ static int set_supply(struct regulator_dev *rdev, * sources to symbolic names for supplies for use by devices. Devices * should use these symbolic names to request regulators, avoiding the * need to provide board-specific regulator names as platform data. - * - * Only one of consumer_dev and consumer_dev_name may be specified. */ static int set_consumer_device_supply(struct regulator_dev *rdev, const char *consumer_dev_name, -- cgit v0.10.2 From b29c7690a764b9829b1034f873f97b7bbfa19565 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Mon, 20 Feb 2012 10:32:16 +0800 Subject: regulator: Simplify regulator_bulk_get and regulator_bulk_enable error paths Start unwind from the point the error happens instead of iterating over all consumers, then unwind code can be simpler. Signed-off-by: Axel Lin Signed-off-by: Mark Brown diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 9a143ae..6c84520 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -2397,7 +2397,7 @@ int regulator_bulk_get(struct device *dev, int num_consumers, return 0; err: - for (i = 0; i < num_consumers && consumers[i].consumer; i++) + while (--i >= 0) regulator_put(consumers[i].consumer); return ret; @@ -2447,12 +2447,9 @@ int regulator_bulk_enable(int num_consumers, return 0; err: - for (i = 0; i < num_consumers; i++) - if (consumers[i].ret == 0) - regulator_disable(consumers[i].consumer); - else - pr_err("Failed to enable %s: %d\n", - consumers[i].supply, consumers[i].ret); + pr_err("Failed to enable %s: %d\n", consumers[i].supply, ret); + while (--i >= 0) + regulator_disable(consumers[i].consumer); return ret; } -- cgit v0.10.2 From f4d562c6e616bb686f43d38752b2e5b83359e1fc Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Mon, 20 Feb 2012 21:01:04 +0000 Subject: regulator: Clean up debugfs error handling a bit Use IS_ERR_OR_NULL() rather than open coding it and ignore errors from failure to create the supply map. Signed-off-by: Mark Brown diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 6c84520..81ea66d 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -2712,7 +2712,7 @@ static void rdev_init_debugfs(struct regulator_dev *rdev) { #ifdef CONFIG_DEBUG_FS rdev->debugfs = debugfs_create_dir(rdev_get_name(rdev), debugfs_root); - if (IS_ERR(rdev->debugfs) || !rdev->debugfs) { + if (IS_ERR_OR_NULL(rdev->debugfs)) { rdev_warn(rdev, "Failed to create debugfs directory\n"); rdev->debugfs = NULL; return; @@ -3127,14 +3127,13 @@ static int __init regulator_init(void) #ifdef CONFIG_DEBUG_FS debugfs_root = debugfs_create_dir("regulator", NULL); - if (IS_ERR(debugfs_root) || !debugfs_root) { + if (IS_ERR_OR_NULL(debugfs_root)) { pr_warn("regulator: Failed to create debugfs directory\n"); debugfs_root = NULL; } - if (IS_ERR(debugfs_create_file("supply_map", 0444, debugfs_root, - NULL, &supply_map_fops))) - pr_warn("regulator: Failed to create supplies debugfs\n"); + debugfs_create_file("supply_map", 0444, debugfs_root, NULL, + &supply_map_fops); #endif regulator_dummy_init(); -- cgit v0.10.2 From 247514344492a0cf602317d2089bab1301922624 Mon Sep 17 00:00:00 2001 From: Stephen Boyd Date: Mon, 20 Feb 2012 22:50:42 -0800 Subject: regulator: Remove ifdefs for debugfs code If CONFIG_DEBUG_FS=y debugfs functions will never return an ERR_PTR. Instead they'll return NULL. The intent is to remove ifdefs in calling code. Update the code to reflect this. We gain an extra dentry pointer per struct regulator and struct regulator_dev but that should be ok because most distros have debugfs compiled in anyway. Signed-off-by: Stephen Boyd Signed-off-by: Mark Brown diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 81ea66d..603e39f 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -52,9 +52,7 @@ static LIST_HEAD(regulator_map_list); static bool has_full_constraints; static bool board_wants_dummy_regulator; -#ifdef CONFIG_DEBUG_FS static struct dentry *debugfs_root; -#endif /* * struct regulator_map @@ -82,9 +80,7 @@ struct regulator { char *supply_name; struct device_attribute dev_attr; struct regulator_dev *rdev; -#ifdef CONFIG_DEBUG_FS struct dentry *debugfs; -#endif }; static int _regulator_is_enabled(struct regulator_dev *rdev); @@ -1145,12 +1141,10 @@ static struct regulator *create_regulator(struct regulator_dev *rdev, goto attr_err; } -#ifdef CONFIG_DEBUG_FS regulator->debugfs = debugfs_create_dir(regulator->supply_name, rdev->debugfs); - if (IS_ERR_OR_NULL(regulator->debugfs)) { + if (!regulator->debugfs) { rdev_warn(rdev, "Failed to create debugfs directory\n"); - regulator->debugfs = NULL; } else { debugfs_create_u32("uA_load", 0444, regulator->debugfs, ®ulator->uA_load); @@ -1159,7 +1153,6 @@ static struct regulator *create_regulator(struct regulator_dev *rdev, debugfs_create_u32("max_uV", 0444, regulator->debugfs, ®ulator->max_uV); } -#endif mutex_unlock(&rdev->mutex); return regulator; @@ -1368,9 +1361,7 @@ void regulator_put(struct regulator *regulator) mutex_lock(®ulator_list_mutex); rdev = regulator->rdev; -#ifdef CONFIG_DEBUG_FS debugfs_remove_recursive(regulator->debugfs); -#endif /* remove any sysfs entries */ if (regulator->dev) { @@ -2710,11 +2701,9 @@ static int add_regulator_attributes(struct regulator_dev *rdev) static void rdev_init_debugfs(struct regulator_dev *rdev) { -#ifdef CONFIG_DEBUG_FS rdev->debugfs = debugfs_create_dir(rdev_get_name(rdev), debugfs_root); - if (IS_ERR_OR_NULL(rdev->debugfs)) { + if (!rdev->debugfs) { rdev_warn(rdev, "Failed to create debugfs directory\n"); - rdev->debugfs = NULL; return; } @@ -2722,7 +2711,6 @@ static void rdev_init_debugfs(struct regulator_dev *rdev) &rdev->use_count); debugfs_create_u32("open_count", 0444, rdev->debugfs, &rdev->open_count); -#endif } /** @@ -2900,9 +2888,7 @@ void regulator_unregister(struct regulator_dev *rdev) return; mutex_lock(®ulator_list_mutex); -#ifdef CONFIG_DEBUG_FS debugfs_remove_recursive(rdev->debugfs); -#endif flush_work_sync(&rdev->disable_work.work); WARN_ON(rdev->open_count); unset_regulator_supplies(rdev); @@ -3112,12 +3098,14 @@ static ssize_t supply_map_read_file(struct file *file, char __user *user_buf, return ret; } +#endif static const struct file_operations supply_map_fops = { +#ifdef CONFIG_DEBUG_FS .read = supply_map_read_file, .llseek = default_llseek, -}; #endif +}; static int __init regulator_init(void) { @@ -3125,16 +3113,12 @@ static int __init regulator_init(void) ret = class_register(®ulator_class); -#ifdef CONFIG_DEBUG_FS debugfs_root = debugfs_create_dir("regulator", NULL); - if (IS_ERR_OR_NULL(debugfs_root)) { + if (!debugfs_root) pr_warn("regulator: Failed to create debugfs directory\n"); - debugfs_root = NULL; - } debugfs_create_file("supply_map", 0444, debugfs_root, NULL, &supply_map_fops); -#endif regulator_dummy_init(); diff --git a/include/linux/regulator/driver.h b/include/linux/regulator/driver.h index aeaf3a7..fa8b55b 100644 --- a/include/linux/regulator/driver.h +++ b/include/linux/regulator/driver.h @@ -207,9 +207,7 @@ struct regulator_dev { void *reg_data; /* regulator_dev data */ -#ifdef CONFIG_DEBUG_FS struct dentry *debugfs; -#endif }; struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, -- cgit v0.10.2 From 073512336e6333ffcaabbb2b92f8e616db3a0789 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Fri, 24 Feb 2012 23:13:19 +0800 Subject: regulator: Set delay to 0 if set_voltage_time_sel callback returns error rdev->desc->ops->set_voltage_time_sel may return negative error code. Set delay to 0 and also show warning if set_voltage_time_sel returns error. Signed-off-by: Axel Lin Signed-off-by: Mark Brown diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 603e39f..b97c4a2 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -1836,8 +1836,12 @@ static int _regulator_do_set_voltage(struct regulator_dev *rdev, if (ret < 0) return ret; old_selector = ret; - delay = rdev->desc->ops->set_voltage_time_sel(rdev, + ret = rdev->desc->ops->set_voltage_time_sel(rdev, old_selector, selector); + if (ret < 0) + rdev_warn(rdev, "set_voltage_time_sel() failed: %d\n", ret); + else + delay = ret; } if (best_val != INT_MAX) { -- cgit v0.10.2 From 613330a0f73b2698b2210ea89092eb56635fc5d8 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Sat, 3 Mar 2012 12:40:02 +0100 Subject: regulator: provide a helper for registering a fixed regulator Some devices require a regulator to work, but boards may not have a software controllable regulator for this device. Provide a helper function to make it simpler for these boards to register a fixed regulator as a dummy regulator. Signed-off-by: Sascha Hauer Signed-off-by: Mark Brown diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile index 503bac8..f76deb9 100644 --- a/drivers/regulator/Makefile +++ b/drivers/regulator/Makefile @@ -3,7 +3,7 @@ # -obj-$(CONFIG_REGULATOR) += core.o dummy.o +obj-$(CONFIG_REGULATOR) += core.o dummy.o fixed-helper.o obj-$(CONFIG_OF) += of_regulator.o obj-$(CONFIG_REGULATOR_FIXED_VOLTAGE) += fixed.o obj-$(CONFIG_REGULATOR_VIRTUAL_CONSUMER) += virtual.o diff --git a/drivers/regulator/fixed-helper.c b/drivers/regulator/fixed-helper.c new file mode 100644 index 0000000..30d0a15 --- /dev/null +++ b/drivers/regulator/fixed-helper.c @@ -0,0 +1,53 @@ +#include +#include +#include +#include + +struct fixed_regulator_data { + struct fixed_voltage_config cfg; + struct regulator_init_data init_data; + struct platform_device pdev; +}; + +static void regulator_fixed_release(struct device *dev) +{ + struct fixed_regulator_data *data = container_of(dev, + struct fixed_regulator_data, pdev.dev); + kfree(data); +} + +/** + * regulator_register_fixed - register a no-op fixed regulator + * @name: supply name + * @id: platform device id + * @supplies: consumers for this regulator + * @num_supplies: number of consumers + */ +struct platform_device *regulator_register_fixed(int id, + struct regulator_consumer_supply *supplies, int num_supplies) +{ + struct fixed_regulator_data *data; + + data = kzalloc(sizeof(*data), GFP_KERNEL); + if (!data) + return NULL; + + data->cfg.supply_name = "dummy"; + data->cfg.microvolts = 0; + data->cfg.gpio = -EINVAL; + data->cfg.enabled_at_boot = 1; + data->cfg.init_data = &data->init_data; + + data->init_data.constraints.always_on = 1; + data->init_data.consumer_supplies = supplies; + data->init_data.num_consumer_supplies = num_supplies; + + data->pdev.name = "reg-fixed-voltage"; + data->pdev.id = id; + data->pdev.dev.platform_data = &data->cfg; + data->pdev.dev.release = regulator_fixed_release; + + platform_device_register(&data->pdev); + + return &data->pdev; +} diff --git a/include/linux/regulator/fixed.h b/include/linux/regulator/fixed.h index ffd7d50..936a7d8 100644 --- a/include/linux/regulator/fixed.h +++ b/include/linux/regulator/fixed.h @@ -48,4 +48,17 @@ struct fixed_voltage_config { struct regulator_init_data *init_data; }; +struct regulator_consumer_supply; + +#if IS_ENABLED(CONFIG_REGULATOR) +struct platform_device *regulator_register_fixed(int id, + struct regulator_consumer_supply *supplies, int num_supplies); +#else +static inline struct platform_device *regulator_register_fixed(int id, + struct regulator_consumer_supply *supplies, int num_supplies) +{ + return NULL; +} +#endif + #endif -- cgit v0.10.2 From 7dc3a6a562aecb2931734424e00cc4ca78cf2dc0 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Sat, 3 Mar 2012 12:40:03 +0100 Subject: ARM i.MX pcm037: register a dummy regulator for the smsc911x device Signed-off-by: Sascha Hauer Signed-off-by: Mark Brown diff --git a/arch/arm/mach-imx/mach-pcm037.c b/arch/arm/mach-imx/mach-pcm037.c index e48854b..5fddf94 100644 --- a/arch/arm/mach-imx/mach-pcm037.c +++ b/arch/arm/mach-imx/mach-pcm037.c @@ -32,6 +32,8 @@ #include #include #include +#include +#include #include @@ -570,6 +572,11 @@ static int __init pcm037_otg_mode(char *options) } __setup("otg_mode=", pcm037_otg_mode); +static struct regulator_consumer_supply dummy_supplies[] = { + REGULATOR_SUPPLY("vdd33a", "smsc911x"), + REGULATOR_SUPPLY("vddvario", "smsc911x"), +}; + /* * Board specific initialization. */ @@ -579,6 +586,8 @@ static void __init pcm037_init(void) imx31_soc_init(); + regulator_register_fixed(0, dummy_supplies, ARRAY_SIZE(dummy_supplies)); + mxc_iomux_set_gpr(MUX_PGP_UH2, 1); mxc_iomux_setup_multiple_pins(pcm037_pins, ARRAY_SIZE(pcm037_pins), -- cgit v0.10.2 From 33499df88b711725ee473ab5478e17efd21de4b0 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Sat, 3 Mar 2012 12:40:04 +0100 Subject: ARM i.MX 3ds debugboard: register a dummy regulator for the smsc911x device Signed-off-by: Sascha Hauer Signed-off-by: Mark Brown diff --git a/arch/arm/plat-mxc/3ds_debugboard.c b/arch/arm/plat-mxc/3ds_debugboard.c index f0ba072..d1e31fa 100644 --- a/arch/arm/plat-mxc/3ds_debugboard.c +++ b/arch/arm/plat-mxc/3ds_debugboard.c @@ -16,6 +16,8 @@ #include #include #include +#include +#include #include @@ -148,6 +150,11 @@ static struct irq_chip expio_irq_chip = { .irq_unmask = expio_unmask_irq, }; +static struct regulator_consumer_supply dummy_supplies[] = { + REGULATOR_SUPPLY("vdd33a", "smsc911x"), + REGULATOR_SUPPLY("vddvario", "smsc911x"), +}; + int __init mxc_expio_init(u32 base, u32 p_irq) { int i; @@ -188,6 +195,8 @@ int __init mxc_expio_init(u32 base, u32 p_irq) irq_set_chained_handler(p_irq, mxc_expio_irq_handler); /* Register Lan device on the debugboard */ + regulator_register_fixed(0, dummy_supplies, ARRAY_SIZE(dummy_supplies)); + smsc911x_resources[0].start = LAN9217_BASE_ADDR(base); smsc911x_resources[0].end = LAN9217_BASE_ADDR(base) + 0x100 - 1; platform_device_register(&smsc_lan9217_device); -- cgit v0.10.2 From a33b6e5a8fb5fadeef206bacef13117e8a3080c4 Mon Sep 17 00:00:00 2001 From: Laxman Dewangan Date: Fri, 3 Feb 2012 12:54:38 +0530 Subject: regulator: twl6030: Fix voltage selection logic The voltage selection logic for the twl6030 smps fails if min:max is such that min < 1300mV and max > 1300mV although this is in valid range for a regulator e.g. [x, 1350] where x < 1300. Fixing the voltage selection logic such that first it will check for min_uV for a range and then calculated value will be checked against max_uV. Signed-off-by: Laxman Dewangan Signed-off-by: Mark Brown diff --git a/drivers/regulator/twl-regulator.c b/drivers/regulator/twl-regulator.c index 181a2cf..e5d2223 100644 --- a/drivers/regulator/twl-regulator.c +++ b/drivers/regulator/twl-regulator.c @@ -755,12 +755,16 @@ twl6030smps_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV, case 0: if (min_uV == 0) vsel = 0; - else if ((min_uV >= 600000) && (max_uV <= 1300000)) { + else if ((min_uV >= 600000) && (min_uV <= 1300000)) { + int calc_uV; vsel = (min_uV - 600000) / 125; if (vsel % 100) vsel += 100; vsel /= 100; vsel++; + calc_uV = twl6030smps_list_voltage(rdev, vsel); + if (calc_uV > max_uV) + return -EINVAL; } /* Values 1..57 for vsel are linear and can be calculated * values 58..62 are non linear. @@ -781,12 +785,16 @@ twl6030smps_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV, case SMPS_OFFSET_EN: if (min_uV == 0) vsel = 0; - else if ((min_uV >= 700000) && (max_uV <= 1420000)) { + else if ((min_uV >= 700000) && (min_uV <= 1420000)) { + int calc_uV; vsel = (min_uV - 700000) / 125; if (vsel % 100) vsel += 100; vsel /= 100; vsel++; + calc_uV = twl6030smps_list_voltage(rdev, vsel); + if (calc_uV > max_uV) + return -EINVAL; } /* Values 1..57 for vsel are linear and can be calculated * values 58..62 are non linear. @@ -819,7 +827,7 @@ twl6030smps_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV, if (min_uV == 0) vsel = 0; else if ((min_uV >= 2161000) && (max_uV <= 4321000)) { - vsel = (min_uV - 1852000) / 386; + vsel = (min_uV - 2161000) / 386; if (vsel % 100) vsel += 100; vsel /= 100; -- cgit v0.10.2 From 63bfff4e20211b464cbea6e79e5fd36df227c154 Mon Sep 17 00:00:00 2001 From: Tero Kristo Date: Thu, 16 Feb 2012 12:27:52 +0200 Subject: regulator: twl4030: add support for external voltage get/set This is needed for SMPS regulators, which use the OMAP voltage processor for voltage get/set functions instead of the normal I2C channel. For this purpose, regulator_init_data->driver_data contents are expanded, it is now a struct which contains function pointers for the set/get voltage operations, a data pointer for these, and the previously used features bitmask. Signed-off-by: Tero Kristo Acked-by: Samuel Ortiz [for the MFD part] Signed-off-by: Mark Brown diff --git a/drivers/mfd/twl-core.c b/drivers/mfd/twl-core.c index e04e04d..fae5f76 100644 --- a/drivers/mfd/twl-core.c +++ b/drivers/mfd/twl-core.c @@ -619,6 +619,8 @@ add_regulator_linked(int num, struct regulator_init_data *pdata, unsigned num_consumers, unsigned long features) { unsigned sub_chip_id; + struct twl_regulator_driver_data drv_data; + /* regulator framework demands init_data ... */ if (!pdata) return NULL; @@ -628,7 +630,19 @@ add_regulator_linked(int num, struct regulator_init_data *pdata, pdata->num_consumer_supplies = num_consumers; } - pdata->driver_data = (void *)features; + if (pdata->driver_data) { + /* If we have existing drv_data, just add the flags */ + struct twl_regulator_driver_data *tmp; + tmp = pdata->driver_data; + tmp->features |= features; + } else { + /* add new driver data struct, used only during init */ + drv_data.features = features; + drv_data.set_voltage = NULL; + drv_data.get_voltage = NULL; + drv_data.data = NULL; + pdata->driver_data = &drv_data; + } /* NOTE: we currently ignore regulator IRQs, e.g. for short circuits */ sub_chip_id = twl_map[TWL_MODULE_PM_MASTER].sid; diff --git a/drivers/regulator/twl-regulator.c b/drivers/regulator/twl-regulator.c index e5d2223..7ff8bb22 100644 --- a/drivers/regulator/twl-regulator.c +++ b/drivers/regulator/twl-regulator.c @@ -58,6 +58,16 @@ struct twlreg_info { /* chip specific features */ unsigned long features; + + /* + * optional override functions for voltage set/get + * these are currently only used for SMPS regulators + */ + int (*get_voltage)(void *data); + int (*set_voltage)(void *data, int target_uV); + + /* data passed from board for external get/set voltage */ + void *data; }; @@ -522,15 +532,25 @@ twl4030smps_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV, struct twlreg_info *info = rdev_get_drvdata(rdev); int vsel = DIV_ROUND_UP(min_uV - 600000, 12500); - twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE_SMPS_4030, - vsel); + if (info->set_voltage) { + return info->set_voltage(info->data, min_uV); + } else { + twlreg_write(info, TWL_MODULE_PM_RECEIVER, + VREG_VOLTAGE_SMPS_4030, vsel); + } + return 0; } static int twl4030smps_get_voltage(struct regulator_dev *rdev) { struct twlreg_info *info = rdev_get_drvdata(rdev); - int vsel = twlreg_read(info, TWL_MODULE_PM_RECEIVER, + int vsel; + + if (info->get_voltage) + return info->get_voltage(info->data); + + vsel = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE_SMPS_4030); return vsel * 12500 + 600000; @@ -1060,6 +1080,7 @@ static int __devinit twlreg_probe(struct platform_device *pdev) struct regulator_init_data *initdata; struct regulation_constraints *c; struct regulator_dev *rdev; + struct twl_regulator_driver_data *drvdata; for (i = 0, info = NULL; i < ARRAY_SIZE(twl_regs); i++) { if (twl_regs[i].desc.id != pdev->id) @@ -1074,8 +1095,16 @@ static int __devinit twlreg_probe(struct platform_device *pdev) if (!initdata) return -EINVAL; - /* copy the features into regulator data */ - info->features = (unsigned long)initdata->driver_data; + drvdata = initdata->driver_data; + + if (!drvdata) + return -EINVAL; + + /* copy the driver data into regulator data */ + info->features = drvdata->features; + info->data = drvdata->data; + info->set_voltage = drvdata->set_voltage; + info->get_voltage = drvdata->get_voltage; /* Constrain board-specific capabilities according to what * this driver and the chip itself can actually do. diff --git a/include/linux/i2c/twl.h b/include/linux/i2c/twl.h index 78d3465..08a82d3 100644 --- a/include/linux/i2c/twl.h +++ b/include/linux/i2c/twl.h @@ -749,6 +749,13 @@ struct twl4030_platform_data { struct regulator_init_data *vio6025; }; +struct twl_regulator_driver_data { + int (*set_voltage)(void *data, int target_uV); + int (*get_voltage)(void *data); + void *data; + unsigned long features; +}; + /*----------------------------------------------------------------------*/ int twl4030_sih_setup(int module); -- cgit v0.10.2 From 34a38440689b06a515104d668494e0ff8a4e1537 Mon Sep 17 00:00:00 2001 From: Tero Kristo Date: Tue, 28 Feb 2012 15:09:10 +0530 Subject: regulator: twl6030: add support for vdd1, vdd2 and vdd3 regulators vdd1 and vdd2 are now common regulators for twl4030 and twl6030. Also added vdd3 as a new regulator for twl6030. twl6030 vdd1...vdd3 smps regulator voltages can only be controlled through the smartreflex voltage channel, thus the support for the voltage_get and set is minimal and requires external controller. Signed-off-by: Tero Kristo Signed-off-by: Rajendra Nayak Acked-by: Samuel Ortiz Signed-off-by: Mark Brown diff --git a/drivers/mfd/twl-core.c b/drivers/mfd/twl-core.c index fae5f76..c788e36 100644 --- a/drivers/mfd/twl-core.c +++ b/drivers/mfd/twl-core.c @@ -949,6 +949,21 @@ add_children(struct twl4030_platform_data *pdata, unsigned long features) /* twl6030 regulators */ if (twl_has_regulator() && twl_class_is_6030() && !(features & TWL6025_SUBCLASS)) { + child = add_regulator(TWL6030_REG_VDD1, pdata->vdd1, + features); + if (IS_ERR(child)) + return PTR_ERR(child); + + child = add_regulator(TWL6030_REG_VDD2, pdata->vdd2, + features); + if (IS_ERR(child)) + return PTR_ERR(child); + + child = add_regulator(TWL6030_REG_VDD3, pdata->vdd3, + features); + if (IS_ERR(child)) + return PTR_ERR(child); + child = add_regulator(TWL6030_REG_VMMC, pdata->vmmc, features); if (IS_ERR(child)) diff --git a/drivers/regulator/twl-regulator.c b/drivers/regulator/twl-regulator.c index 7ff8bb22..8611282 100644 --- a/drivers/regulator/twl-regulator.c +++ b/drivers/regulator/twl-regulator.c @@ -561,6 +561,32 @@ static struct regulator_ops twl4030smps_ops = { .get_voltage = twl4030smps_get_voltage, }; +static int twl6030coresmps_set_voltage(struct regulator_dev *rdev, int min_uV, + int max_uV, unsigned *selector) +{ + struct twlreg_info *info = rdev_get_drvdata(rdev); + + if (info->set_voltage) + return info->set_voltage(info->data, min_uV); + + return -ENODEV; +} + +static int twl6030coresmps_get_voltage(struct regulator_dev *rdev) +{ + struct twlreg_info *info = rdev_get_drvdata(rdev); + + if (info->get_voltage) + return info->get_voltage(info->data); + + return -ENODEV; +} + +static struct regulator_ops twl6030coresmps_ops = { + .set_voltage = twl6030coresmps_set_voltage, + .get_voltage = twl6030coresmps_get_voltage, +}; + static int twl6030ldo_list_voltage(struct regulator_dev *rdev, unsigned index) { struct twlreg_info *info = rdev_get_drvdata(rdev); @@ -926,6 +952,16 @@ static struct regulator_ops twlsmps_ops = { }, \ } +#define TWL6030_ADJUSTABLE_SMPS(label) { \ + .desc = { \ + .name = #label, \ + .id = TWL6030_REG_##label, \ + .ops = &twl6030coresmps_ops, \ + .type = REGULATOR_VOLTAGE, \ + .owner = THIS_MODULE, \ + }, \ + } + #define TWL6030_ADJUSTABLE_LDO(label, offset, min_mVolts, max_mVolts) { \ .base = offset, \ .min_mV = min_mVolts, \ @@ -1027,6 +1063,9 @@ static struct twlreg_info twl_regs[] = { /* 6030 REG with base as PMC Slave Misc : 0x0030 */ /* Turnon-delay and remap configuration values for 6030 are not verified since the specification is not public */ + TWL6030_ADJUSTABLE_SMPS(VDD1), + TWL6030_ADJUSTABLE_SMPS(VDD2), + TWL6030_ADJUSTABLE_SMPS(VDD3), TWL6030_ADJUSTABLE_LDO(VAUX1_6030, 0x54, 1000, 3300), TWL6030_ADJUSTABLE_LDO(VAUX2_6030, 0x58, 1000, 3300), TWL6030_ADJUSTABLE_LDO(VAUX3_6030, 0x5c, 1000, 3300), diff --git a/include/linux/i2c/twl.h b/include/linux/i2c/twl.h index 08a82d3..f66c031 100644 --- a/include/linux/i2c/twl.h +++ b/include/linux/i2c/twl.h @@ -712,6 +712,9 @@ struct twl4030_platform_data { struct regulator_init_data *vaux1; struct regulator_init_data *vaux2; struct regulator_init_data *vaux3; + struct regulator_init_data *vdd1; + struct regulator_init_data *vdd2; + struct regulator_init_data *vdd3; /* TWL4030 LDO regulators */ struct regulator_init_data *vpll1; struct regulator_init_data *vpll2; @@ -720,8 +723,6 @@ struct twl4030_platform_data { struct regulator_init_data *vsim; struct regulator_init_data *vaux4; struct regulator_init_data *vio; - struct regulator_init_data *vdd1; - struct regulator_init_data *vdd2; struct regulator_init_data *vintana1; struct regulator_init_data *vintana2; struct regulator_init_data *vintdig; -- cgit v0.10.2 From 2098e95ce9bb039ff2e7bf836df358d18a176139 Mon Sep 17 00:00:00 2001 From: Rajendra Nayak Date: Tue, 28 Feb 2012 15:09:11 +0530 Subject: regulator: twl: adapt twl-regulator driver to dt Modify the twl regulator driver to extract the regulator_init_data from device tree when passed, instead of getting it through platform_data structures (on non-DT builds) Also add documentation for TWL regulator specific bindings. Signed-off-by: Rajendra Nayak Signed-off-by: Mark Brown diff --git a/Documentation/devicetree/bindings/regulator/twl-regulator.txt b/Documentation/devicetree/bindings/regulator/twl-regulator.txt new file mode 100644 index 0000000..ba9d2cc --- /dev/null +++ b/Documentation/devicetree/bindings/regulator/twl-regulator.txt @@ -0,0 +1,66 @@ +TWL family of regulators + +Required properties: +For twl6030 regulators/LDOs +- compatible: + - "ti,twl6030-vaux1" for VAUX1 LDO + - "ti,twl6030-vaux2" for VAUX2 LDO + - "ti,twl6030-vaux3" for VAUX3 LDO + - "ti,twl6030-vmmc" for VMMC LDO + - "ti,twl6030-vpp" for VPP LDO + - "ti,twl6030-vusim" for VUSIM LDO + - "ti,twl6030-vana" for VANA LDO + - "ti,twl6030-vcxio" for VCXIO LDO + - "ti,twl6030-vdac" for VDAC LDO + - "ti,twl6030-vusb" for VUSB LDO + - "ti,twl6030-clk32kg" for CLK32KG RESOURCE + - "ti,twl6030-vdd1" for VDD1 SMPS + - "ti,twl6030-vdd2" for VDD2 SMPS + - "ti,twl6030-vdd3" for VDD3 SMPS +For twl6025 regulators/LDOs +- compatible: + - "ti,twl6025-ldo1" for LDO1 LDO + - "ti,twl6025-ldo2" for LDO2 LDO + - "ti,twl6025-ldo3" for LDO3 LDO + - "ti,twl6025-ldo4" for LDO4 LDO + - "ti,twl6025-ldo5" for LDO5 LDO + - "ti,twl6025-ldo6" for LDO6 LDO + - "ti,twl6025-ldo7" for LDO7 LDO + - "ti,twl6025-ldoln" for LDOLN LDO + - "ti,twl6025-ldousb" for LDOUSB LDO + - "ti,twl6025-smps3" for SMPS3 SMPS + - "ti,twl6025-smps4" for SMPS4 SMPS + - "ti,twl6025-vio" for VIO SMPS +For twl4030 regulators/LDOs +- compatible: + - "ti,twl4030-vaux1" for VAUX1 LDO + - "ti,twl4030-vaux2" for VAUX2 LDO + - "ti,twl5030-vaux2" for VAUX2 LDO + - "ti,twl4030-vaux3" for VAUX3 LDO + - "ti,twl4030-vaux4" for VAUX4 LDO + - "ti,twl4030-vmmc1" for VMMC1 LDO + - "ti,twl4030-vmmc2" for VMMC2 LDO + - "ti,twl4030-vpll1" for VPLL1 LDO + - "ti,twl4030-vpll2" for VPLL2 LDO + - "ti,twl4030-vsim" for VSIM LDO + - "ti,twl4030-vdac" for VDAC LDO + - "ti,twl4030-vintana2" for VINTANA2 LDO + - "ti,twl4030-vio" for VIO LDO + - "ti,twl4030-vdd1" for VDD1 SMPS + - "ti,twl4030-vdd2" for VDD2 SMPS + - "ti,twl4030-vintana1" for VINTANA1 LDO + - "ti,twl4030-vintdig" for VINTDIG LDO + - "ti,twl4030-vusb1v5" for VUSB1V5 LDO + - "ti,twl4030-vusb1v8" for VUSB1V8 LDO + - "ti,twl4030-vusb3v1" for VUSB3V1 LDO + +Optional properties: +- Any optional property defined in bindings/regulator/regulator.txt + +Example: + + xyz: regulator@0 { + compatible = "ti,twl6030-vaux1"; + regulator-min-microvolt = <1000000>; + regulator-max-microvolt = <3000000>; + }; diff --git a/drivers/regulator/twl-regulator.c b/drivers/regulator/twl-regulator.c index 8611282..2a13211 100644 --- a/drivers/regulator/twl-regulator.c +++ b/drivers/regulator/twl-regulator.c @@ -14,8 +14,11 @@ #include #include #include +#include +#include #include #include +#include #include @@ -920,7 +923,8 @@ static struct regulator_ops twlsmps_ops = { TWL_FIXED_LDO(label, offset, mVolts, 0x0, turnon_delay, \ 0x0, TWL6030, twl6030fixed_ops) -#define TWL4030_ADJUSTABLE_LDO(label, offset, num, turnon_delay, remap_conf) { \ +#define TWL4030_ADJUSTABLE_LDO(label, offset, num, turnon_delay, remap_conf) \ +static struct twlreg_info TWL4030_INFO_##label = { \ .base = offset, \ .id = num, \ .table_len = ARRAY_SIZE(label##_VSEL_table), \ @@ -938,7 +942,7 @@ static struct regulator_ops twlsmps_ops = { } #define TWL4030_ADJUSTABLE_SMPS(label, offset, num, turnon_delay, remap_conf) \ - { \ +static struct twlreg_info TWL4030_INFO_##label = { \ .base = offset, \ .id = num, \ .delay = turnon_delay, \ @@ -952,7 +956,8 @@ static struct regulator_ops twlsmps_ops = { }, \ } -#define TWL6030_ADJUSTABLE_SMPS(label) { \ +#define TWL6030_ADJUSTABLE_SMPS(label) \ +static struct twlreg_info TWL6030_INFO_##label = { \ .desc = { \ .name = #label, \ .id = TWL6030_REG_##label, \ @@ -962,7 +967,8 @@ static struct regulator_ops twlsmps_ops = { }, \ } -#define TWL6030_ADJUSTABLE_LDO(label, offset, min_mVolts, max_mVolts) { \ +#define TWL6030_ADJUSTABLE_LDO(label, offset, min_mVolts, max_mVolts) \ +static struct twlreg_info TWL6030_INFO_##label = { \ .base = offset, \ .min_mV = min_mVolts, \ .max_mV = max_mVolts, \ @@ -976,7 +982,8 @@ static struct regulator_ops twlsmps_ops = { }, \ } -#define TWL6025_ADJUSTABLE_LDO(label, offset, min_mVolts, max_mVolts) { \ +#define TWL6025_ADJUSTABLE_LDO(label, offset, min_mVolts, max_mVolts) \ +static struct twlreg_info TWL6025_INFO_##label = { \ .base = offset, \ .min_mV = min_mVolts, \ .max_mV = max_mVolts, \ @@ -991,7 +998,8 @@ static struct regulator_ops twlsmps_ops = { } #define TWL_FIXED_LDO(label, offset, mVolts, num, turnon_delay, remap_conf, \ - family, operations) { \ + family, operations) \ +static struct twlreg_info TWLFIXED_INFO_##label = { \ .base = offset, \ .id = num, \ .min_mV = mVolts, \ @@ -1007,7 +1015,8 @@ static struct regulator_ops twlsmps_ops = { }, \ } -#define TWL6030_FIXED_RESOURCE(label, offset, turnon_delay) { \ +#define TWL6030_FIXED_RESOURCE(label, offset, turnon_delay) \ +static struct twlreg_info TWLRES_INFO_##label = { \ .base = offset, \ .delay = turnon_delay, \ .desc = { \ @@ -1019,7 +1028,8 @@ static struct regulator_ops twlsmps_ops = { }, \ } -#define TWL6025_ADJUSTABLE_SMPS(label, offset) { \ +#define TWL6025_ADJUSTABLE_SMPS(label, offset) \ +static struct twlreg_info TWLSMPS_INFO_##label = { \ .base = offset, \ .min_mV = 600, \ .max_mV = 2100, \ @@ -1037,62 +1047,57 @@ static struct regulator_ops twlsmps_ops = { * We list regulators here if systems need some level of * software control over them after boot. */ -static struct twlreg_info twl_regs[] = { - TWL4030_ADJUSTABLE_LDO(VAUX1, 0x17, 1, 100, 0x08), - TWL4030_ADJUSTABLE_LDO(VAUX2_4030, 0x1b, 2, 100, 0x08), - TWL4030_ADJUSTABLE_LDO(VAUX2, 0x1b, 2, 100, 0x08), - TWL4030_ADJUSTABLE_LDO(VAUX3, 0x1f, 3, 100, 0x08), - TWL4030_ADJUSTABLE_LDO(VAUX4, 0x23, 4, 100, 0x08), - TWL4030_ADJUSTABLE_LDO(VMMC1, 0x27, 5, 100, 0x08), - TWL4030_ADJUSTABLE_LDO(VMMC2, 0x2b, 6, 100, 0x08), - TWL4030_ADJUSTABLE_LDO(VPLL1, 0x2f, 7, 100, 0x00), - TWL4030_ADJUSTABLE_LDO(VPLL2, 0x33, 8, 100, 0x08), - TWL4030_ADJUSTABLE_LDO(VSIM, 0x37, 9, 100, 0x00), - TWL4030_ADJUSTABLE_LDO(VDAC, 0x3b, 10, 100, 0x08), - TWL4030_FIXED_LDO(VINTANA1, 0x3f, 1500, 11, 100, 0x08), - TWL4030_ADJUSTABLE_LDO(VINTANA2, 0x43, 12, 100, 0x08), - TWL4030_FIXED_LDO(VINTDIG, 0x47, 1500, 13, 100, 0x08), - TWL4030_ADJUSTABLE_LDO(VIO, 0x4b, 14, 1000, 0x08), - TWL4030_ADJUSTABLE_SMPS(VDD1, 0x55, 15, 1000, 0x08), - TWL4030_ADJUSTABLE_SMPS(VDD2, 0x63, 16, 1000, 0x08), - TWL4030_FIXED_LDO(VUSB1V5, 0x71, 1500, 17, 100, 0x08), - TWL4030_FIXED_LDO(VUSB1V8, 0x74, 1800, 18, 100, 0x08), - TWL4030_FIXED_LDO(VUSB3V1, 0x77, 3100, 19, 150, 0x08), - /* VUSBCP is managed *only* by the USB subchip */ - - /* 6030 REG with base as PMC Slave Misc : 0x0030 */ - /* Turnon-delay and remap configuration values for 6030 are not - verified since the specification is not public */ - TWL6030_ADJUSTABLE_SMPS(VDD1), - TWL6030_ADJUSTABLE_SMPS(VDD2), - TWL6030_ADJUSTABLE_SMPS(VDD3), - TWL6030_ADJUSTABLE_LDO(VAUX1_6030, 0x54, 1000, 3300), - TWL6030_ADJUSTABLE_LDO(VAUX2_6030, 0x58, 1000, 3300), - TWL6030_ADJUSTABLE_LDO(VAUX3_6030, 0x5c, 1000, 3300), - TWL6030_ADJUSTABLE_LDO(VMMC, 0x68, 1000, 3300), - TWL6030_ADJUSTABLE_LDO(VPP, 0x6c, 1000, 3300), - TWL6030_ADJUSTABLE_LDO(VUSIM, 0x74, 1000, 3300), - TWL6030_FIXED_LDO(VANA, 0x50, 2100, 0), - TWL6030_FIXED_LDO(VCXIO, 0x60, 1800, 0), - TWL6030_FIXED_LDO(VDAC, 0x64, 1800, 0), - TWL6030_FIXED_LDO(VUSB, 0x70, 3300, 0), - TWL6030_FIXED_RESOURCE(CLK32KG, 0x8C, 0), - - /* 6025 are renamed compared to 6030 versions */ - TWL6025_ADJUSTABLE_LDO(LDO2, 0x54, 1000, 3300), - TWL6025_ADJUSTABLE_LDO(LDO4, 0x58, 1000, 3300), - TWL6025_ADJUSTABLE_LDO(LDO3, 0x5c, 1000, 3300), - TWL6025_ADJUSTABLE_LDO(LDO5, 0x68, 1000, 3300), - TWL6025_ADJUSTABLE_LDO(LDO1, 0x6c, 1000, 3300), - TWL6025_ADJUSTABLE_LDO(LDO7, 0x74, 1000, 3300), - TWL6025_ADJUSTABLE_LDO(LDO6, 0x60, 1000, 3300), - TWL6025_ADJUSTABLE_LDO(LDOLN, 0x64, 1000, 3300), - TWL6025_ADJUSTABLE_LDO(LDOUSB, 0x70, 1000, 3300), - - TWL6025_ADJUSTABLE_SMPS(SMPS3, 0x34), - TWL6025_ADJUSTABLE_SMPS(SMPS4, 0x10), - TWL6025_ADJUSTABLE_SMPS(VIO, 0x16), -}; +TWL4030_ADJUSTABLE_LDO(VAUX1, 0x17, 1, 100, 0x08); +TWL4030_ADJUSTABLE_LDO(VAUX2_4030, 0x1b, 2, 100, 0x08); +TWL4030_ADJUSTABLE_LDO(VAUX2, 0x1b, 2, 100, 0x08); +TWL4030_ADJUSTABLE_LDO(VAUX3, 0x1f, 3, 100, 0x08); +TWL4030_ADJUSTABLE_LDO(VAUX4, 0x23, 4, 100, 0x08); +TWL4030_ADJUSTABLE_LDO(VMMC1, 0x27, 5, 100, 0x08); +TWL4030_ADJUSTABLE_LDO(VMMC2, 0x2b, 6, 100, 0x08); +TWL4030_ADJUSTABLE_LDO(VPLL1, 0x2f, 7, 100, 0x00); +TWL4030_ADJUSTABLE_LDO(VPLL2, 0x33, 8, 100, 0x08); +TWL4030_ADJUSTABLE_LDO(VSIM, 0x37, 9, 100, 0x00); +TWL4030_ADJUSTABLE_LDO(VDAC, 0x3b, 10, 100, 0x08); +TWL4030_ADJUSTABLE_LDO(VINTANA2, 0x43, 12, 100, 0x08); +TWL4030_ADJUSTABLE_LDO(VIO, 0x4b, 14, 1000, 0x08); +TWL4030_ADJUSTABLE_SMPS(VDD1, 0x55, 15, 1000, 0x08); +TWL4030_ADJUSTABLE_SMPS(VDD2, 0x63, 16, 1000, 0x08); +/* VUSBCP is managed *only* by the USB subchip */ +/* 6030 REG with base as PMC Slave Misc : 0x0030 */ +/* Turnon-delay and remap configuration values for 6030 are not + verified since the specification is not public */ +TWL6030_ADJUSTABLE_SMPS(VDD1); +TWL6030_ADJUSTABLE_SMPS(VDD2); +TWL6030_ADJUSTABLE_SMPS(VDD3); +TWL6030_ADJUSTABLE_LDO(VAUX1_6030, 0x54, 1000, 3300); +TWL6030_ADJUSTABLE_LDO(VAUX2_6030, 0x58, 1000, 3300); +TWL6030_ADJUSTABLE_LDO(VAUX3_6030, 0x5c, 1000, 3300); +TWL6030_ADJUSTABLE_LDO(VMMC, 0x68, 1000, 3300); +TWL6030_ADJUSTABLE_LDO(VPP, 0x6c, 1000, 3300); +TWL6030_ADJUSTABLE_LDO(VUSIM, 0x74, 1000, 3300); +/* 6025 are renamed compared to 6030 versions */ +TWL6025_ADJUSTABLE_LDO(LDO2, 0x54, 1000, 3300); +TWL6025_ADJUSTABLE_LDO(LDO4, 0x58, 1000, 3300); +TWL6025_ADJUSTABLE_LDO(LDO3, 0x5c, 1000, 3300); +TWL6025_ADJUSTABLE_LDO(LDO5, 0x68, 1000, 3300); +TWL6025_ADJUSTABLE_LDO(LDO1, 0x6c, 1000, 3300); +TWL6025_ADJUSTABLE_LDO(LDO7, 0x74, 1000, 3300); +TWL6025_ADJUSTABLE_LDO(LDO6, 0x60, 1000, 3300); +TWL6025_ADJUSTABLE_LDO(LDOLN, 0x64, 1000, 3300); +TWL6025_ADJUSTABLE_LDO(LDOUSB, 0x70, 1000, 3300); +TWL4030_FIXED_LDO(VINTANA2, 0x3f, 1500, 11, 100, 0x08); +TWL4030_FIXED_LDO(VINTDIG, 0x47, 1500, 13, 100, 0x08); +TWL4030_FIXED_LDO(VUSB1V5, 0x71, 1500, 17, 100, 0x08); +TWL4030_FIXED_LDO(VUSB1V8, 0x74, 1800, 18, 100, 0x08); +TWL4030_FIXED_LDO(VUSB3V1, 0x77, 3100, 19, 150, 0x08); +TWL6030_FIXED_LDO(VANA, 0x50, 2100, 0); +TWL6030_FIXED_LDO(VCXIO, 0x60, 1800, 0); +TWL6030_FIXED_LDO(VDAC, 0x64, 1800, 0); +TWL6030_FIXED_LDO(VUSB, 0x70, 3300, 0); +TWL6030_FIXED_RESOURCE(CLK32KG, 0x8C, 0); +TWL6025_ADJUSTABLE_SMPS(SMPS3, 0x34); +TWL6025_ADJUSTABLE_SMPS(SMPS4, 0x10); +TWL6025_ADJUSTABLE_SMPS(VIO, 0x16); static u8 twl_get_smps_offset(void) { @@ -1112,38 +1117,114 @@ static u8 twl_get_smps_mult(void) return value; } +#define TWL_OF_MATCH(comp, family, label) \ + { \ + .compatible = comp, \ + .data = &family##_INFO_##label, \ + } + +#define TWL4030_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWL4030, label) +#define TWL6030_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWL6030, label) +#define TWL6025_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWL6025, label) +#define TWLFIXED_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWLFIXED, label) +#define TWLRES_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWLRES, label) +#define TWLSMPS_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWLSMPS, label) + +static const struct of_device_id twl_of_match[] __devinitconst = { + TWL4030_OF_MATCH("ti,twl4030-vaux1", VAUX1), + TWL4030_OF_MATCH("ti,twl4030-vaux2", VAUX2_4030), + TWL4030_OF_MATCH("ti,twl5030-vaux2", VAUX2), + TWL4030_OF_MATCH("ti,twl4030-vaux3", VAUX3), + TWL4030_OF_MATCH("ti,twl4030-vaux4", VAUX4), + TWL4030_OF_MATCH("ti,twl4030-vmmc1", VMMC1), + TWL4030_OF_MATCH("ti,twl4030-vmmc2", VMMC2), + TWL4030_OF_MATCH("ti,twl4030-vpll1", VPLL1), + TWL4030_OF_MATCH("ti,twl4030-vpll2", VPLL2), + TWL4030_OF_MATCH("ti,twl4030-vsim", VSIM), + TWL4030_OF_MATCH("ti,twl4030-vdac", VDAC), + TWL4030_OF_MATCH("ti,twl4030-vintana2", VINTANA2), + TWL4030_OF_MATCH("ti,twl4030-vio", VIO), + TWL4030_OF_MATCH("ti,twl4030-vdd1", VDD1), + TWL4030_OF_MATCH("ti,twl4030-vdd2", VDD2), + TWL6030_OF_MATCH("ti,twl6030-vdd1", VDD1), + TWL6030_OF_MATCH("ti,twl6030-vdd2", VDD2), + TWL6030_OF_MATCH("ti,twl6030-vdd3", VDD3), + TWL6030_OF_MATCH("ti,twl6030-vaux1", VAUX1_6030), + TWL6030_OF_MATCH("ti,twl6030-vaux2", VAUX2_6030), + TWL6030_OF_MATCH("ti,twl6030-vaux3", VAUX3_6030), + TWL6030_OF_MATCH("ti,twl6030-vmmc", VMMC), + TWL6030_OF_MATCH("ti,twl6030-vpp", VPP), + TWL6030_OF_MATCH("ti,twl6030-vusim", VUSIM), + TWL6025_OF_MATCH("ti,twl6025-ldo2", LDO2), + TWL6025_OF_MATCH("ti,twl6025-ldo4", LDO4), + TWL6025_OF_MATCH("ti,twl6025-ldo3", LDO3), + TWL6025_OF_MATCH("ti,twl6025-ldo5", LDO5), + TWL6025_OF_MATCH("ti,twl6025-ldo1", LDO1), + TWL6025_OF_MATCH("ti,twl6025-ldo7", LDO7), + TWL6025_OF_MATCH("ti,twl6025-ldo6", LDO6), + TWL6025_OF_MATCH("ti,twl6025-ldoln", LDOLN), + TWL6025_OF_MATCH("ti,twl6025-ldousb", LDOUSB), + TWLFIXED_OF_MATCH("ti,twl4030-vintana2", VINTANA2), + TWLFIXED_OF_MATCH("ti,twl4030-vintdig", VINTDIG), + TWLFIXED_OF_MATCH("ti,twl4030-vusb1v5", VUSB1V5), + TWLFIXED_OF_MATCH("ti,twl4030-vusb1v8", VUSB1V8), + TWLFIXED_OF_MATCH("ti,twl4030-vusb3v1", VUSB3V1), + TWLFIXED_OF_MATCH("ti,twl6030-vana", VANA), + TWLFIXED_OF_MATCH("ti,twl6030-vcxio", VCXIO), + TWLFIXED_OF_MATCH("ti,twl6030-vdac", VDAC), + TWLFIXED_OF_MATCH("ti,twl6030-vusb", VUSB), + TWLRES_OF_MATCH("ti,twl6030-clk32kg", CLK32KG), + TWLSMPS_OF_MATCH("ti,twl6025-smps3", SMPS3), + TWLSMPS_OF_MATCH("ti,twl6025-smps4", SMPS4), + TWLSMPS_OF_MATCH("ti,twl6025-vio", VIO), + {}, +}; +MODULE_DEVICE_TABLE(of, twl_of_match); + static int __devinit twlreg_probe(struct platform_device *pdev) { - int i; + int i, id; struct twlreg_info *info; struct regulator_init_data *initdata; struct regulation_constraints *c; struct regulator_dev *rdev; struct twl_regulator_driver_data *drvdata; - - for (i = 0, info = NULL; i < ARRAY_SIZE(twl_regs); i++) { - if (twl_regs[i].desc.id != pdev->id) - continue; - info = twl_regs + i; - break; + const struct of_device_id *match; + + match = of_match_device(twl_of_match, &pdev->dev); + if (match) { + info = match->data; + id = info->desc.id; + initdata = of_get_regulator_init_data(&pdev->dev, + pdev->dev.of_node); + drvdata = NULL; + } else { + id = pdev->id; + initdata = pdev->dev.platform_data; + for (i = 0, info = NULL; i < ARRAY_SIZE(twl_of_match); i++) { + info = twl_of_match[i].data; + if (!info || info->desc.id != id) + continue; + break; + } + drvdata = initdata->driver_data; + if (!drvdata) + return -EINVAL; } + if (!info) return -ENODEV; - initdata = pdev->dev.platform_data; if (!initdata) return -EINVAL; - drvdata = initdata->driver_data; - - if (!drvdata) - return -EINVAL; - - /* copy the driver data into regulator data */ - info->features = drvdata->features; - info->data = drvdata->data; - info->set_voltage = drvdata->set_voltage; - info->get_voltage = drvdata->get_voltage; + if (drvdata) { + /* copy the driver data into regulator data */ + info->features = drvdata->features; + info->data = drvdata->data; + info->set_voltage = drvdata->set_voltage; + info->get_voltage = drvdata->get_voltage; + } /* Constrain board-specific capabilities according to what * this driver and the chip itself can actually do. @@ -1153,7 +1234,7 @@ static int __devinit twlreg_probe(struct platform_device *pdev) c->valid_ops_mask &= REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE | REGULATOR_CHANGE_STATUS; - switch (pdev->id) { + switch (id) { case TWL4030_REG_VIO: case TWL4030_REG_VDD1: case TWL4030_REG_VDD2: @@ -1167,7 +1248,7 @@ static int __devinit twlreg_probe(struct platform_device *pdev) break; } - switch (pdev->id) { + switch (id) { case TWL6025_REG_SMPS3: if (twl_get_smps_mult() & SMPS_MULTOFFSET_SMPS3) info->flags |= SMPS_EXTENDED_EN; @@ -1188,7 +1269,8 @@ static int __devinit twlreg_probe(struct platform_device *pdev) break; } - rdev = regulator_register(&info->desc, &pdev->dev, initdata, info, NULL); + rdev = regulator_register(&info->desc, &pdev->dev, initdata, info, + pdev->dev.of_node); if (IS_ERR(rdev)) { dev_err(&pdev->dev, "can't register %s, %ld\n", info->desc.name, PTR_ERR(rdev)); @@ -1225,8 +1307,11 @@ static struct platform_driver twlreg_driver = { /* NOTE: short name, to work around driver model truncation of * "twl_regulator.12" (and friends) to "twl_regulator.1". */ - .driver.name = "twl_reg", - .driver.owner = THIS_MODULE, + .driver = { + .name = "twl_reg", + .owner = THIS_MODULE, + .of_match_table = of_match_ptr(twl_of_match), + }, }; static int __init twlreg_init(void) -- cgit v0.10.2 From e9d47fa4ebb9382bc3282fc13ad28a4e2a1a089e Mon Sep 17 00:00:00 2001 From: Peter Ujfalusi Date: Tue, 28 Feb 2012 15:09:12 +0530 Subject: regulator: twl-regulator: Add fixed LDO for V1V8, V2V1 supply V1V8 supply most common use is to provide VIO for the system. V2V1 supply is used on SDP4430/PandaBoards to provide 2.1V to twl6040, and also as an input to VCXIO_IN, VDAC_IN of twl6030. Also update the bindings documentation with the new compatible property for these additional LDOs. Signed-off-by: Peter Ujfalusi Signed-off-by: Rajendra Nayak Signed-off-by: Mark Brown diff --git a/Documentation/devicetree/bindings/regulator/twl-regulator.txt b/Documentation/devicetree/bindings/regulator/twl-regulator.txt index ba9d2cc..0c3395d 100644 --- a/Documentation/devicetree/bindings/regulator/twl-regulator.txt +++ b/Documentation/devicetree/bindings/regulator/twl-regulator.txt @@ -13,6 +13,8 @@ For twl6030 regulators/LDOs - "ti,twl6030-vcxio" for VCXIO LDO - "ti,twl6030-vdac" for VDAC LDO - "ti,twl6030-vusb" for VUSB LDO + - "ti,twl6030-v1v8" for V1V8 LDO + - "ti,twl6030-v2v1" for V2V1 LDO - "ti,twl6030-clk32kg" for CLK32KG RESOURCE - "ti,twl6030-vdd1" for VDD1 SMPS - "ti,twl6030-vdd2" for VDD2 SMPS diff --git a/drivers/regulator/twl-regulator.c b/drivers/regulator/twl-regulator.c index 2a13211..9cdfc38 100644 --- a/drivers/regulator/twl-regulator.c +++ b/drivers/regulator/twl-regulator.c @@ -1094,6 +1094,8 @@ TWL6030_FIXED_LDO(VANA, 0x50, 2100, 0); TWL6030_FIXED_LDO(VCXIO, 0x60, 1800, 0); TWL6030_FIXED_LDO(VDAC, 0x64, 1800, 0); TWL6030_FIXED_LDO(VUSB, 0x70, 3300, 0); +TWL6030_FIXED_LDO(V1V8, 0x16, 1800, 0); +TWL6030_FIXED_LDO(V2V1, 0x1c, 2100, 0); TWL6030_FIXED_RESOURCE(CLK32KG, 0x8C, 0); TWL6025_ADJUSTABLE_SMPS(SMPS3, 0x34); TWL6025_ADJUSTABLE_SMPS(SMPS4, 0x10); @@ -1173,6 +1175,8 @@ static const struct of_device_id twl_of_match[] __devinitconst = { TWLFIXED_OF_MATCH("ti,twl6030-vcxio", VCXIO), TWLFIXED_OF_MATCH("ti,twl6030-vdac", VDAC), TWLFIXED_OF_MATCH("ti,twl6030-vusb", VUSB), + TWLFIXED_OF_MATCH("ti,twl6030-v1v8", V1V8), + TWLFIXED_OF_MATCH("ti,twl6030-v2v1", V2V1), TWLRES_OF_MATCH("ti,twl6030-clk32kg", CLK32KG), TWLSMPS_OF_MATCH("ti,twl6025-smps3", SMPS3), TWLSMPS_OF_MATCH("ti,twl6025-smps4", SMPS4), -- cgit v0.10.2 From 46eda3e96a65b378041c79c51ff2e02009f7e2d0 Mon Sep 17 00:00:00 2001 From: Peter Ujfalusi Date: Tue, 28 Feb 2012 15:09:13 +0530 Subject: mfd: twl-core: regulator configuration for twl6030 V1V8, V2V1 SMPS To be able to attach consumers to these supplies from board files we need to have regulator_init_data for them. Signed-off-by: Peter Ujfalusi Signed-off-by: Rajendra Nayak Signed-off-by: Mark Brown diff --git a/drivers/mfd/twl-core.c b/drivers/mfd/twl-core.c index c788e36..d3cf5e8 100644 --- a/drivers/mfd/twl-core.c +++ b/drivers/mfd/twl-core.c @@ -964,6 +964,16 @@ add_children(struct twl4030_platform_data *pdata, unsigned long features) if (IS_ERR(child)) return PTR_ERR(child); + child = add_regulator(TWL6030_REG_V1V8, pdata->v1v8, + features); + if (IS_ERR(child)) + return PTR_ERR(child); + + child = add_regulator(TWL6030_REG_V2V1, pdata->v2v1, + features); + if (IS_ERR(child)) + return PTR_ERR(child); + child = add_regulator(TWL6030_REG_VMMC, pdata->vmmc, features); if (IS_ERR(child)) diff --git a/include/linux/i2c/twl.h b/include/linux/i2c/twl.h index f66c031..7fcab23 100644 --- a/include/linux/i2c/twl.h +++ b/include/linux/i2c/twl.h @@ -734,6 +734,8 @@ struct twl4030_platform_data { struct regulator_init_data *vcxio; struct regulator_init_data *vusb; struct regulator_init_data *clk32kg; + struct regulator_init_data *v1v8; + struct regulator_init_data *v2v1; /* TWL6025 LDO regulators */ struct regulator_init_data *ldo1; struct regulator_init_data *ldo2; -- cgit v0.10.2 From 22cd2fefba7bddd31dad892f5923854defac0da2 Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Mon, 6 Feb 2012 11:34:36 +0000 Subject: regulator: s5m8767: Fix unused variable warning in probe() Signed-off-by: Mark Brown Acked-by: Sangbeom Kim diff --git a/drivers/regulator/s5m8767.c b/drivers/regulator/s5m8767.c index 5b00e5a..2fb2add 100644 --- a/drivers/regulator/s5m8767.c +++ b/drivers/regulator/s5m8767.c @@ -569,7 +569,7 @@ static __devinit int s5m8767_pmic_probe(struct platform_device *pdev) struct regulator_dev **rdev; struct s5m8767_info *s5m8767; struct i2c_client *i2c; - int i, ret, size, reg; + int i, ret, size; if (!pdata) { dev_err(pdev->dev.parent, "Platform data not supplied\n"); -- cgit v0.10.2 From 46783a046e13588f0459271ad6db9785fa8dcb8b Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Tue, 7 Feb 2012 11:06:20 +0800 Subject: regulator: tps62360: Remove pointless test for unsigned less than zero The variable 'selector' is a 'unsigned int', so it can never be less than zero. Signed-off-by: Axel Lin Acked-by: Laxman Dewangan Signed-off-by: Mark Brown diff --git a/drivers/regulator/tps62360-regulator.c b/drivers/regulator/tps62360-regulator.c index f778ef0..e2ec730 100644 --- a/drivers/regulator/tps62360-regulator.c +++ b/drivers/regulator/tps62360-regulator.c @@ -191,7 +191,7 @@ static int tps62360_dcdc_list_voltage(struct regulator_dev *dev, { struct tps62360_chip *tps = rdev_get_drvdata(dev); - if ((selector < 0) || (selector >= tps->desc.n_voltages)) + if (selector >= tps->desc.n_voltages) return -EINVAL; return (tps->voltage_base + selector * 10) * 1000; } -- cgit v0.10.2 From b9e0348f2051358318e5ef0fd5b91c4d335a370d Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Wed, 15 Feb 2012 23:12:17 -0800 Subject: regulator: wm8994: Convert to devm_kzalloc() Signed-off-by: Mark Brown diff --git a/drivers/regulator/wm8994-regulator.c b/drivers/regulator/wm8994-regulator.c index 435e335..75ed402 100644 --- a/drivers/regulator/wm8994-regulator.c +++ b/drivers/regulator/wm8994-regulator.c @@ -241,7 +241,7 @@ static __devinit int wm8994_ldo_probe(struct platform_device *pdev) if (!pdata) return -ENODEV; - ldo = kzalloc(sizeof(struct wm8994_ldo), GFP_KERNEL); + ldo = devm_kzalloc(&pdev->dev, sizeof(struct wm8994_ldo), GFP_KERNEL); if (ldo == NULL) { dev_err(&pdev->dev, "Unable to allocate private data\n"); return -ENOMEM; @@ -285,7 +285,6 @@ err_gpio: if (gpio_is_valid(ldo->enable)) gpio_free(ldo->enable); err: - kfree(ldo); return ret; } @@ -298,7 +297,6 @@ static __devexit int wm8994_ldo_remove(struct platform_device *pdev) regulator_unregister(ldo->regulator); if (gpio_is_valid(ldo->enable)) gpio_free(ldo->enable); - kfree(ldo); return 0; } -- cgit v0.10.2 From e882eae80f37fac922c6faa25e5ba535f29f2d38 Mon Sep 17 00:00:00 2001 From: Laxman Dewangan Date: Fri, 17 Feb 2012 18:56:11 +0530 Subject: regulator: tps65910: Correct VIO voltage configuration The VIO regulator register specify the voltage configuration on bit3:2 of its register. And hence only these bits should be modified when setting voltage and used when reading voltage from register setting. Signed-off-by: Laxman Dewangan Signed-off-by: Mark Brown diff --git a/drivers/regulator/tps65910-regulator.c b/drivers/regulator/tps65910-regulator.c index 9092b7f..a9bb6d4 100644 --- a/drivers/regulator/tps65910-regulator.c +++ b/drivers/regulator/tps65910-regulator.c @@ -674,8 +674,9 @@ static int tps65911_get_voltage(struct regulator_dev *dev) step_mv = 100; break; case TPS65910_REG_VIO: + value &= LDO_SEL_MASK; + value >>= LDO_SEL_SHIFT; return pmic->info[id]->voltage_table[value] * 1000; - break; default: return -EINVAL; } @@ -767,9 +768,11 @@ static int tps65911_set_voltage(struct regulator_dev *dev, unsigned selector) case TPS65911_REG_LDO6: case TPS65911_REG_LDO7: case TPS65911_REG_LDO8: - case TPS65910_REG_VIO: return tps65910_modify_bits(pmic, reg, (selector << LDO_SEL_SHIFT), LDO3_SEL_MASK); + case TPS65910_REG_VIO: + return tps65910_modify_bits(pmic, reg, + (selector << LDO_SEL_SHIFT), LDO_SEL_MASK); } return -EINVAL; -- cgit v0.10.2 From ae0e6544347d6e114b6fa7eea66ebd062e4d8858 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Tue, 21 Feb 2012 10:14:55 +0800 Subject: regulator: Fix module desciption for tps65910 regulator Fix the module desciption and also update Kconfig to include supporting tps65911 chip. Signed-off-by: Axel Lin Acked-by: Laxman Dewangan Signed-off-by: Mark Brown diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig index 376824b..edcd9e2 100644 --- a/drivers/regulator/Kconfig +++ b/drivers/regulator/Kconfig @@ -344,10 +344,10 @@ config REGULATOR_TPS6524X port controller. config REGULATOR_TPS65910 - tristate "TI TPS65910 Power Regulator" + tristate "TI TPS65910/TPS65911 Power Regulators" depends on MFD_TPS65910 help - This driver supports TPS65910 voltage regulator chips. + This driver supports TPS65910/TPS65911 voltage regulator chips. config REGULATOR_TPS62360 tristate "TI TPS62360 Power Regulator" diff --git a/drivers/regulator/tps65910-regulator.c b/drivers/regulator/tps65910-regulator.c index a9bb6d4..15b5f1e 100644 --- a/drivers/regulator/tps65910-regulator.c +++ b/drivers/regulator/tps65910-regulator.c @@ -1235,6 +1235,6 @@ static void __exit tps65910_cleanup(void) module_exit(tps65910_cleanup); MODULE_AUTHOR("Graeme Gregory "); -MODULE_DESCRIPTION("TPS6507x voltage regulator driver"); +MODULE_DESCRIPTION("TPS65910/TPS65911 voltage regulator driver"); MODULE_LICENSE("GPL v2"); MODULE_ALIAS("platform:tps65910-pmic"); -- cgit v0.10.2 From dfb9b8a4f3ed7b85c9d65cb0e47ec07543ce317d Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Wed, 22 Feb 2012 09:29:16 +0800 Subject: regulator: Sort Kconfig and Makefile entries Sort Kconfig entries by company name/driver in alphabetical order. Sort Makefile entries by alphabetical order. In order to group all the Kconfig entries by company name, this patch also adds company name to some Kconfig entries. Signed-off-by: Axel Lin Acked-by: Laxman Dewangan Signed-off-by: Mark Brown diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig index edcd9e2..c733df5 100644 --- a/drivers/regulator/Kconfig +++ b/drivers/regulator/Kconfig @@ -74,13 +74,64 @@ config REGULATOR_GPIO and the platform has to provide a mapping of GPIO-states to target volts/amps. -config REGULATOR_BQ24022 - tristate "TI bq24022 Dual Input 1-Cell Li-Ion Charger IC" +config REGULATOR_AD5398 + tristate "Analog Devices AD5398/AD5821 regulators" + depends on I2C help - This driver controls a TI bq24022 Charger attached via - GPIOs. The provided current regulator can enable/disable - charging select between 100 mA and 500 mA charging current - limit. + This driver supports AD5398 and AD5821 current regulator chips. + If building into module, its name is ad5398.ko. + +config REGULATOR_AAT2870 + tristate "AnalogicTech AAT2870 Regulators" + depends on MFD_AAT2870_CORE + help + If you have a AnalogicTech AAT2870 say Y to enable the + regulator driver. + +config REGULATOR_DA903X + tristate "Dialog Semiconductor DA9030/DA9034 regulators" + depends on PMIC_DA903X + help + Say y here to support the BUCKs and LDOs regulators found on + Dialog Semiconductor DA9030/DA9034 PMIC. + +config REGULATOR_DA9052 + tristate "Dialog Semiconductor DA9052/DA9053 regulators" + depends on PMIC_DA9052 + help + This driver supports the voltage regulators of DA9052-BC and + DA9053-AA/Bx PMIC. + +config REGULATOR_MC13XXX_CORE + tristate + +config REGULATOR_MC13783 + tristate "Freescale MC13783 regulator driver" + depends on MFD_MC13783 + select REGULATOR_MC13XXX_CORE + help + Say y here to support the regulators found on the Freescale MC13783 + PMIC. + +config REGULATOR_MC13892 + tristate "Freescale MC13892 regulator driver" + depends on MFD_MC13XXX + select REGULATOR_MC13XXX_CORE + help + Say y here to support the regulators found on the Freescale MC13892 + PMIC. + +config REGULATOR_ISL6271A + tristate "Intersil ISL6271A Power regulator" + depends on I2C + help + This driver supports ISL6271A voltage regulator chip. + +config REGULATOR_88PM8607 + bool "Marvell 88PM8607 Power regulators" + depends on MFD_88PM860X=y + help + This driver supports 88PM8607 voltage regulator chips. config REGULATOR_MAX1586 tristate "Maxim 1586/1587 voltage regulator" @@ -136,69 +187,12 @@ config REGULATOR_MAX8998 via I2C bus. The provided regulator is suitable for S3C6410 and S5PC1XX chips to control VCC_CORE and VCC_USIM voltages. -config REGULATOR_S5M8767 - tristate "Samsung S5M8767A voltage regulator" - depends on MFD_S5M_CORE - help - This driver supports a Samsung S5M8767A voltage output regulator - via I2C bus. S5M8767A have 9 Bucks and 28 LDOs output and - supports DVS mode with 8bits of output voltage control. - -config REGULATOR_TWL4030 - bool "TI TWL4030/TWL5030/TWL6030/TPS659x0 PMIC" - depends on TWL4030_CORE - help - This driver supports the voltage regulators provided by - this family of companion chips. - -config REGULATOR_WM831X - tristate "Wolfson Microelcronics WM831x PMIC regulators" - depends on MFD_WM831X - help - Support the voltage and current regulators of the WM831x series - of PMIC devices. - -config REGULATOR_WM8350 - tristate "Wolfson Microelectronics WM8350 AudioPlus PMIC" - depends on MFD_WM8350 - help - This driver provides support for the voltage and current regulators - of the WM8350 AudioPlus PMIC. - -config REGULATOR_WM8400 - tristate "Wolfson Microelectronics WM8400 AudioPlus PMIC" - depends on MFD_WM8400 - help - This driver provides support for the voltage regulators of the - WM8400 AudioPlus PMIC. - -config REGULATOR_WM8994 - tristate "Wolfson Microelectronics WM8994 CODEC" - depends on MFD_WM8994 - help - This driver provides support for the voltage regulators on the - WM8994 CODEC. - -config REGULATOR_DA903X - tristate "Support regulators on Dialog Semiconductor DA9030/DA9034 PMIC" - depends on PMIC_DA903X - help - Say y here to support the BUCKs and LDOs regulators found on - Dialog Semiconductor DA9030/DA9034 PMIC. - -config REGULATOR_DA9052 - tristate "Dialog DA9052/DA9053 regulators" - depends on PMIC_DA9052 - help - This driver supports the voltage regulators of DA9052-BC and - DA9053-AA/Bx PMIC. - -config REGULATOR_PCF50633 - tristate "PCF50633 regulator driver" - depends on MFD_PCF50633 +config REGULATOR_PCAP + tristate "Motorola PCAP2 regulator driver" + depends on EZX_PCAP help - Say Y here to support the voltage regulators and convertors - on PCF50633 + This driver provides support for the voltage regulators of the + PCAP2 PMIC. config REGULATOR_LP3971 tristate "National Semiconductors LP3971 PMIC regulator driver" @@ -214,31 +208,20 @@ config REGULATOR_LP3972 Say Y here to support the voltage regulators and convertors on National Semiconductors LP3972 PMIC -config REGULATOR_PCAP - tristate "PCAP2 regulator driver" - depends on EZX_PCAP - help - This driver provides support for the voltage regulators of the - PCAP2 PMIC. - -config REGULATOR_MC13XXX_CORE - tristate - -config REGULATOR_MC13783 - tristate "Support regulators on Freescale MC13783 PMIC" - depends on MFD_MC13783 - select REGULATOR_MC13XXX_CORE +config REGULATOR_PCF50633 + tristate "NXP PCF50633 regulator driver" + depends on MFD_PCF50633 help - Say y here to support the regulators found on the Freescale MC13783 - PMIC. + Say Y here to support the voltage regulators and convertors + on PCF50633 -config REGULATOR_MC13892 - tristate "Support regulators on Freescale MC13892 PMIC" - depends on MFD_MC13XXX - select REGULATOR_MC13XXX_CORE +config REGULATOR_S5M8767 + tristate "Samsung S5M8767A voltage regulator" + depends on MFD_S5M_CORE help - Say y here to support the regulators found on the Freescale MC13892 - PMIC. + This driver supports a Samsung S5M8767A voltage output regulator + via I2C bus. S5M8767A have 9 Bucks and 28 LDOs output and + supports DVS mode with 8bits of output voltage control. config REGULATOR_AB3100 tristate "ST-Ericsson AB3100 Regulator functions" @@ -249,6 +232,32 @@ config REGULATOR_AB3100 AB3100 analog baseband dealing with power regulators for the system. +config REGULATOR_AB8500 + bool "ST-Ericsson AB8500 Power Regulators" + depends on AB8500_CORE + help + This driver supports the regulators found on the ST-Ericsson mixed + signal AB8500 PMIC + +config REGULATOR_DBX500_PRCMU + bool + +config REGULATOR_DB8500_PRCMU + bool "ST-Ericsson DB8500 Voltage Domain Regulators" + depends on MFD_DB8500_PRCMU + select REGULATOR_DBX500_PRCMU + help + This driver supports the voltage domain regulators controlled by the + DB8500 PRCMU + +config REGULATOR_BQ24022 + tristate "TI bq24022 Dual Input 1-Cell Li-Ion Charger IC" + help + This driver controls a TI bq24022 Charger attached via + GPIOs. The provided current regulator can enable/disable + charging select between 100 mA and 500 mA charging current + limit. + config REGULATOR_TPS6105X tristate "TI TPS6105X Power regulators" depends on TPS6105X @@ -258,6 +267,16 @@ config REGULATOR_TPS6105X It is a single boost converter primarily for white LEDs and audio amplifiers. +config REGULATOR_TPS62360 + tristate "TI TPS62360 Power Regulator" + depends on I2C + select REGMAP_I2C + help + This driver supports TPS62360 voltage regulator chip. This + regulator is meant for processor core supply. This chip is + high-frequency synchronous step down dc-dc converter optimized + for battery-powered portable applications. + config REGULATOR_TPS65023 tristate "TI TPS65023 Power regulators" depends on I2C @@ -284,55 +303,6 @@ config REGULATOR_TPS65217 voltage regulators. It supports software based voltage control for different voltage domains -config REGULATOR_TPS65912 - tristate "TI TPS65912 Power regulator" - depends on (MFD_TPS65912_I2C || MFD_TPS65912_SPI) - help - This driver supports TPS65912 voltage regulator chip. - -config REGULATOR_88PM8607 - bool "Marvell 88PM8607 Power regulators" - depends on MFD_88PM860X=y - help - This driver supports 88PM8607 voltage regulator chips. - -config REGULATOR_ISL6271A - tristate "Intersil ISL6271A Power regulator" - depends on I2C - help - This driver supports ISL6271A voltage regulator chip. - -config REGULATOR_AD5398 - tristate "Analog Devices AD5398/AD5821 regulators" - depends on I2C - help - This driver supports AD5398 and AD5821 current regulator chips. - If building into module, its name is ad5398.ko. - -config REGULATOR_AB8500 - bool "ST-Ericsson AB8500 Power Regulators" - depends on AB8500_CORE - help - This driver supports the regulators found on the ST-Ericsson mixed - signal AB8500 PMIC - -config REGULATOR_DBX500_PRCMU - bool - -config REGULATOR_DB8500_PRCMU - bool "ST-Ericsson DB8500 Voltage Domain Regulators" - depends on MFD_DB8500_PRCMU - select REGULATOR_DBX500_PRCMU - help - This driver supports the voltage domain regulators controlled by the - DB8500 PRCMU - -config REGULATOR_TPS6586X - tristate "TI TPS6586X Power regulators" - depends on MFD_TPS6586X - help - This driver supports TPS6586X voltage regulator chips. - config REGULATOR_TPS6524X tristate "TI TPS6524X Power regulators" depends on SPI @@ -343,28 +313,58 @@ config REGULATOR_TPS6524X serial interface currently supported on the sequencer serial port controller. +config REGULATOR_TPS6586X + tristate "TI TPS6586X Power regulators" + depends on MFD_TPS6586X + help + This driver supports TPS6586X voltage regulator chips. + config REGULATOR_TPS65910 tristate "TI TPS65910/TPS65911 Power Regulators" depends on MFD_TPS65910 help This driver supports TPS65910/TPS65911 voltage regulator chips. -config REGULATOR_TPS62360 - tristate "TI TPS62360 Power Regulator" - depends on I2C - select REGMAP_I2C +config REGULATOR_TPS65912 + tristate "TI TPS65912 Power regulator" + depends on (MFD_TPS65912_I2C || MFD_TPS65912_SPI) help - This driver supports TPS62360 voltage regulator chip. This - regulator is meant for processor core supply. This chip is - high-frequency synchronous step down dc-dc converter optimized - for battery-powered portable applications. + This driver supports TPS65912 voltage regulator chip. -config REGULATOR_AAT2870 - tristate "AnalogicTech AAT2870 Regulators" - depends on MFD_AAT2870_CORE +config REGULATOR_TWL4030 + bool "TI TWL4030/TWL5030/TWL6030/TPS659x0 PMIC" + depends on TWL4030_CORE help - If you have a AnalogicTech AAT2870 say Y to enable the - regulator driver. + This driver supports the voltage regulators provided by + this family of companion chips. + +config REGULATOR_WM831X + tristate "Wolfson Microelectronics WM831x PMIC regulators" + depends on MFD_WM831X + help + Support the voltage and current regulators of the WM831x series + of PMIC devices. + +config REGULATOR_WM8350 + tristate "Wolfson Microelectronics WM8350 AudioPlus PMIC" + depends on MFD_WM8350 + help + This driver provides support for the voltage and current regulators + of the WM8350 AudioPlus PMIC. + +config REGULATOR_WM8400 + tristate "Wolfson Microelectronics WM8400 AudioPlus PMIC" + depends on MFD_WM8400 + help + This driver provides support for the voltage regulators of the + WM8400 AudioPlus PMIC. + +config REGULATOR_WM8994 + tristate "Wolfson Microelectronics WM8994 CODEC" + depends on MFD_WM8994 + help + This driver provides support for the voltage regulators on the + WM8994 CODEC. endif diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile index 4cbf8c5..cf0934b 100644 --- a/drivers/regulator/Makefile +++ b/drivers/regulator/Makefile @@ -10,48 +10,48 @@ obj-$(CONFIG_REGULATOR_VIRTUAL_CONSUMER) += virtual.o obj-$(CONFIG_REGULATOR_USERSPACE_CONSUMER) += userspace-consumer.o obj-$(CONFIG_REGULATOR_GPIO) += gpio-regulator.o +obj-$(CONFIG_REGULATOR_88PM8607) += 88pm8607.o +obj-$(CONFIG_REGULATOR_AAT2870) += aat2870-regulator.o +obj-$(CONFIG_REGULATOR_AB3100) += ab3100.o +obj-$(CONFIG_REGULATOR_AB8500) += ab8500.o obj-$(CONFIG_REGULATOR_AD5398) += ad5398.o obj-$(CONFIG_REGULATOR_BQ24022) += bq24022.o +obj-$(CONFIG_REGULATOR_DA903X) += da903x.o +obj-$(CONFIG_REGULATOR_DA9052) += da9052-regulator.o +obj-$(CONFIG_REGULATOR_DBX500_PRCMU) += dbx500-prcmu.o +obj-$(CONFIG_REGULATOR_DB8500_PRCMU) += db8500-prcmu.o +obj-$(CONFIG_REGULATOR_ISL6271A) += isl6271a-regulator.o obj-$(CONFIG_REGULATOR_LP3971) += lp3971.o obj-$(CONFIG_REGULATOR_LP3972) += lp3972.o obj-$(CONFIG_REGULATOR_MAX1586) += max1586.o -obj-$(CONFIG_REGULATOR_TWL4030) += twl-regulator.o obj-$(CONFIG_REGULATOR_MAX8649) += max8649.o obj-$(CONFIG_REGULATOR_MAX8660) += max8660.o obj-$(CONFIG_REGULATOR_MAX8925) += max8925-regulator.o obj-$(CONFIG_REGULATOR_MAX8952) += max8952.o obj-$(CONFIG_REGULATOR_MAX8997) += max8997.o obj-$(CONFIG_REGULATOR_MAX8998) += max8998.o -obj-$(CONFIG_REGULATOR_WM831X) += wm831x-dcdc.o -obj-$(CONFIG_REGULATOR_WM831X) += wm831x-isink.o -obj-$(CONFIG_REGULATOR_WM831X) += wm831x-ldo.o -obj-$(CONFIG_REGULATOR_WM8350) += wm8350-regulator.o -obj-$(CONFIG_REGULATOR_WM8400) += wm8400-regulator.o -obj-$(CONFIG_REGULATOR_WM8994) += wm8994-regulator.o -obj-$(CONFIG_REGULATOR_TPS6586X) += tps6586x-regulator.o -obj-$(CONFIG_REGULATOR_DA903X) += da903x.o -obj-$(CONFIG_REGULATOR_DA9052) += da9052-regulator.o -obj-$(CONFIG_REGULATOR_PCF50633) += pcf50633-regulator.o -obj-$(CONFIG_REGULATOR_PCAP) += pcap-regulator.o obj-$(CONFIG_REGULATOR_MC13783) += mc13783-regulator.o obj-$(CONFIG_REGULATOR_MC13892) += mc13892-regulator.o obj-$(CONFIG_REGULATOR_MC13XXX_CORE) += mc13xxx-regulator-core.o -obj-$(CONFIG_REGULATOR_AB3100) += ab3100.o +obj-$(CONFIG_REGULATOR_PCAP) += pcap-regulator.o +obj-$(CONFIG_REGULATOR_PCF50633) += pcf50633-regulator.o +obj-$(CONFIG_REGULATOR_S5M8767) += s5m8767.o obj-$(CONFIG_REGULATOR_TPS6105X) += tps6105x-regulator.o +obj-$(CONFIG_REGULATOR_TPS62360) += tps62360-regulator.o obj-$(CONFIG_REGULATOR_TPS65023) += tps65023-regulator.o obj-$(CONFIG_REGULATOR_TPS6507X) += tps6507x-regulator.o obj-$(CONFIG_REGULATOR_TPS65217) += tps65217-regulator.o obj-$(CONFIG_REGULATOR_TPS6524X) += tps6524x-regulator.o -obj-$(CONFIG_REGULATOR_TPS65912) += tps65912-regulator.o -obj-$(CONFIG_REGULATOR_88PM8607) += 88pm8607.o -obj-$(CONFIG_REGULATOR_ISL6271A) += isl6271a-regulator.o -obj-$(CONFIG_REGULATOR_AB8500) += ab8500.o -obj-$(CONFIG_REGULATOR_DBX500_PRCMU) += dbx500-prcmu.o -obj-$(CONFIG_REGULATOR_DB8500_PRCMU) += db8500-prcmu.o +obj-$(CONFIG_REGULATOR_TPS6586X) += tps6586x-regulator.o obj-$(CONFIG_REGULATOR_TPS65910) += tps65910-regulator.o -obj-$(CONFIG_REGULATOR_TPS62360) += tps62360-regulator.o -obj-$(CONFIG_REGULATOR_AAT2870) += aat2870-regulator.o -obj-$(CONFIG_REGULATOR_S5M8767) += s5m8767.o +obj-$(CONFIG_REGULATOR_TPS65912) += tps65912-regulator.o +obj-$(CONFIG_REGULATOR_TWL4030) += twl-regulator.o +obj-$(CONFIG_REGULATOR_WM831X) += wm831x-dcdc.o +obj-$(CONFIG_REGULATOR_WM831X) += wm831x-isink.o +obj-$(CONFIG_REGULATOR_WM831X) += wm831x-ldo.o +obj-$(CONFIG_REGULATOR_WM8350) += wm8350-regulator.o +obj-$(CONFIG_REGULATOR_WM8400) += wm8400-regulator.o +obj-$(CONFIG_REGULATOR_WM8994) += wm8994-regulator.o ccflags-$(CONFIG_REGULATOR_DEBUG) += -DDEBUG -- cgit v0.10.2 From 3bf6e90e476fb34ca47b6dda270f41d9cebcb1ac Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Fri, 24 Feb 2012 17:15:45 +0800 Subject: regulator: Convert ab8499 to use get_voltage_sel() This change is required to make ab8500_regulator_get_voltage_sel work. The regulator core will call set_voltage_time_sel only when get_voltage_sel is implemented. Signed-off-by: Axel Lin Tested-by: Linus Walleij Signed-off-by: Mark Brown diff --git a/drivers/regulator/ab8500.c b/drivers/regulator/ab8500.c index c9b92531..c7ee4c1 100644 --- a/drivers/regulator/ab8500.c +++ b/drivers/regulator/ab8500.c @@ -201,7 +201,7 @@ static int ab8500_list_voltage(struct regulator_dev *rdev, unsigned selector) return info->voltages[selector]; } -static int ab8500_regulator_get_voltage(struct regulator_dev *rdev) +static int ab8500_regulator_get_voltage_sel(struct regulator_dev *rdev) { int ret, val; struct ab8500_regulator_info *info = rdev_get_drvdata(rdev); @@ -229,11 +229,9 @@ static int ab8500_regulator_get_voltage(struct regulator_dev *rdev) /* vintcore has a different layout */ val = regval & info->voltage_mask; if (info->desc.id == AB8500_LDO_INTCORE) - ret = info->voltages[val >> 0x3]; + return val >> 0x3; else - ret = info->voltages[val]; - - return ret; + return val; } static int ab8500_get_best_voltage_index(struct regulator_dev *rdev, @@ -320,7 +318,7 @@ static struct regulator_ops ab8500_regulator_ops = { .enable = ab8500_regulator_enable, .disable = ab8500_regulator_disable, .is_enabled = ab8500_regulator_is_enabled, - .get_voltage = ab8500_regulator_get_voltage, + .get_voltage_sel = ab8500_regulator_get_voltage_sel, .set_voltage = ab8500_regulator_set_voltage, .list_voltage = ab8500_list_voltage, .enable_time = ab8500_regulator_enable_time, -- cgit v0.10.2 From 0757b6020f5aaa9f770068ca0396c0ea5cb0740d Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Wed, 29 Feb 2012 09:01:40 +0100 Subject: regulator: mc13783: bail out without platform data the platform data pointer is used without checking it. Bail out in the driver instead of crashing the kernel. Signed-off-by: Sascha Hauer Signed-off-by: Mark Brown diff --git a/drivers/regulator/mc13783-regulator.c b/drivers/regulator/mc13783-regulator.c index 8e9b90a..6c0face 100644 --- a/drivers/regulator/mc13783-regulator.c +++ b/drivers/regulator/mc13783-regulator.c @@ -344,6 +344,9 @@ static int __devinit mc13783_regulator_probe(struct platform_device *pdev) dev_dbg(&pdev->dev, "%s id %d\n", __func__, pdev->id); + if (!pdata) + return -EINVAL; + priv = devm_kzalloc(&pdev->dev, sizeof(*priv) + pdata->num_regulators * sizeof(priv->regulators[0]), GFP_KERNEL); -- cgit v0.10.2 From 89e0f0e40002e0d95b7be079fa2c2133304ce09f Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Fri, 24 Feb 2012 14:52:45 +0800 Subject: regulator: Fix the logic of s5m8767_set_voltage_time_sel This patch includes below fixes: 1. The mask variable is not used at all here, remove it. 2. We already have the new_sel and old_sel, simply returns the delay by: DIV_ROUND_UP(desc->step * (new_sel - old_sel), s5m8767->ramp_delay); Signed-off-by: Axel Lin Signed-off-by: Mark Brown diff --git a/drivers/regulator/s5m8767.c b/drivers/regulator/s5m8767.c index 2fb2add..9b97aa3 100644 --- a/drivers/regulator/s5m8767.c +++ b/drivers/regulator/s5m8767.c @@ -452,39 +452,13 @@ static int s5m8767_set_voltage_time_sel(struct regulator_dev *rdev, struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev); const struct s5m_voltage_desc *desc; int reg_id = rdev_get_id(rdev); - int mask; - int new_val, old_val; - switch (reg_id) { - case S5M8767_LDO1 ... S5M8767_LDO28: - mask = 0x3f; - break; - case S5M8767_BUCK1 ... S5M8767_BUCK6: - mask = 0xff; - break; - case S5M8767_BUCK7 ... S5M8767_BUCK8: - return -EINVAL; - case S5M8767_BUCK9: - mask = 0xff; - break; - default: - return -EINVAL; - } desc = reg_voltage_map[reg_id]; - new_val = s5m8767_convert_voltage(desc, new_sel, new_sel); - if (new_val < 0) - return new_val; - - old_val = s5m8767_convert_voltage(desc, old_sel, old_sel); - if (old_val < 0) - return old_val; - if (old_sel < new_sel) - return DIV_ROUND_UP(desc->step * (new_val - old_val), + return DIV_ROUND_UP(desc->step * (new_sel - old_sel), s5m8767->ramp_delay); - else - return 0; + return 0; } static struct regulator_ops s5m8767_ldo_ops = { -- cgit v0.10.2 From ba51c6c022b64b7f3f68d7e2936a37f6ffbc7c4d Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Wed, 29 Feb 2012 12:45:35 +0800 Subject: regulator: Fix n_voltage settings for pcf50633 regulator MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Current code has off-by-one n_voltage settings for AUTO/DOWN*/LDO* regulators. Take ldo1 as example: n_voltage should be (3.6 - 0.9) / 0.1 + 1 = 28 Table 76. LDO1OUT - LDO1 output voltage select register (address 2Dh) bit description[1] Bit Symbol Access Description 4:0 ldo1_out R/W VO(prog) = 0.9 + ldo1_out × 0.1 V (max 3.6V); e.g. 00000 : 0.9 V 00001 : 1.0 V 11000 : 3.3 V 11011 : 3.6 V 11111 : 3.6 V The n_voltage settings for HCLDO and MEMLDO are also wrong. n_voltage for HCLDO and MEMLDO should be (3.6 - 0.9) / 0.1 + 1 = 28 Table 88. HCLDOOUT - HCLDO output voltage select register (addr. 39h) bit description[1] Bit Symbol Access Description 4:0 hcldo_out R/W VO(prog) = 0.9 + hcldo_out × 0.1 V (max 3.6 V); e.g. 00000 : 0.9 V 00001 : 1.0 V 11011 : 3.6 V 11111 : 3.6 V Table 62. MEMLDOOUT - MEMLDO o/p voltage select reg. (address 26h) bit description[1] Bit Symbol Access Description 4:0 memldo_out R/W VO(prog) = 0.9 + memldo_out × 0.1 V; e.g. 00000: 0.9 V 00001: 1.0 V 11000 : 3.3 V 11011 : 3.6 V 11111 : 3.6 V Signed-off-by: Axel Lin Signed-off-by: Mark Brown diff --git a/drivers/regulator/pcf50633-regulator.c b/drivers/regulator/pcf50633-regulator.c index 1d1c310..6db46c6 100644 --- a/drivers/regulator/pcf50633-regulator.c +++ b/drivers/regulator/pcf50633-regulator.c @@ -142,6 +142,7 @@ static int pcf50633_regulator_set_voltage(struct regulator_dev *rdev, case PCF50633_REGULATOR_LDO5: case PCF50633_REGULATOR_LDO6: case PCF50633_REGULATOR_HCLDO: + case PCF50633_REGULATOR_MEMLDO: volt_bits = ldo_voltage_bits(millivolts); break; default: @@ -175,6 +176,7 @@ static int pcf50633_regulator_voltage_value(enum pcf50633_regulator_id id, case PCF50633_REGULATOR_LDO5: case PCF50633_REGULATOR_LDO6: case PCF50633_REGULATOR_HCLDO: + case PCF50633_REGULATOR_MEMLDO: millivolts = ldo_voltage_value(bits); break; default: @@ -217,9 +219,6 @@ static int pcf50633_regulator_list_voltage(struct regulator_dev *rdev, case PCF50633_REGULATOR_AUTO: index += 0x2f; break; - case PCF50633_REGULATOR_HCLDO: - index += 0x01; - break; default: break; } @@ -288,27 +287,27 @@ static struct regulator_ops pcf50633_regulator_ops = { static struct regulator_desc regulators[] = { [PCF50633_REGULATOR_AUTO] = - PCF50633_REGULATOR("auto", PCF50633_REGULATOR_AUTO, 80), + PCF50633_REGULATOR("auto", PCF50633_REGULATOR_AUTO, 81), [PCF50633_REGULATOR_DOWN1] = - PCF50633_REGULATOR("down1", PCF50633_REGULATOR_DOWN1, 95), + PCF50633_REGULATOR("down1", PCF50633_REGULATOR_DOWN1, 96), [PCF50633_REGULATOR_DOWN2] = - PCF50633_REGULATOR("down2", PCF50633_REGULATOR_DOWN2, 95), + PCF50633_REGULATOR("down2", PCF50633_REGULATOR_DOWN2, 96), [PCF50633_REGULATOR_LDO1] = - PCF50633_REGULATOR("ldo1", PCF50633_REGULATOR_LDO1, 27), + PCF50633_REGULATOR("ldo1", PCF50633_REGULATOR_LDO1, 28), [PCF50633_REGULATOR_LDO2] = - PCF50633_REGULATOR("ldo2", PCF50633_REGULATOR_LDO2, 27), + PCF50633_REGULATOR("ldo2", PCF50633_REGULATOR_LDO2, 28), [PCF50633_REGULATOR_LDO3] = - PCF50633_REGULATOR("ldo3", PCF50633_REGULATOR_LDO3, 27), + PCF50633_REGULATOR("ldo3", PCF50633_REGULATOR_LDO3, 28), [PCF50633_REGULATOR_LDO4] = - PCF50633_REGULATOR("ldo4", PCF50633_REGULATOR_LDO4, 27), + PCF50633_REGULATOR("ldo4", PCF50633_REGULATOR_LDO4, 28), [PCF50633_REGULATOR_LDO5] = - PCF50633_REGULATOR("ldo5", PCF50633_REGULATOR_LDO5, 27), + PCF50633_REGULATOR("ldo5", PCF50633_REGULATOR_LDO5, 28), [PCF50633_REGULATOR_LDO6] = - PCF50633_REGULATOR("ldo6", PCF50633_REGULATOR_LDO6, 27), + PCF50633_REGULATOR("ldo6", PCF50633_REGULATOR_LDO6, 28), [PCF50633_REGULATOR_HCLDO] = - PCF50633_REGULATOR("hcldo", PCF50633_REGULATOR_HCLDO, 26), + PCF50633_REGULATOR("hcldo", PCF50633_REGULATOR_HCLDO, 28), [PCF50633_REGULATOR_MEMLDO] = - PCF50633_REGULATOR("memldo", PCF50633_REGULATOR_MEMLDO, 0), + PCF50633_REGULATOR("memldo", PCF50633_REGULATOR_MEMLDO, 28), }; static int __devinit pcf50633_regulator_probe(struct platform_device *pdev) -- cgit v0.10.2 From b3e1348e2753a8c8d17e620ae79ce0c9fa43f40c Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Thu, 1 Mar 2012 09:26:27 +0800 Subject: regulator: Kill max8997_get_rid function Use rdev_get_id() directly. Signed-off-by: Axel Lin Signed-off-by: Mark Brown diff --git a/drivers/regulator/max8997.c b/drivers/regulator/max8997.c index bb7cd9d..9657929 100644 --- a/drivers/regulator/max8997.c +++ b/drivers/regulator/max8997.c @@ -130,15 +130,10 @@ static const struct voltage_map_desc *reg_voltage_map[] = { [MAX8997_CHARGER_TOPOFF] = &topoff_current_map_desc, }; -static inline int max8997_get_rid(struct regulator_dev *rdev) -{ - return rdev_get_id(rdev); -} - static int max8997_list_voltage_safeout(struct regulator_dev *rdev, unsigned int selector) { - int rid = max8997_get_rid(rdev); + int rid = rdev_get_id(rdev); if (rid == MAX8997_ESAFEOUT1 || rid == MAX8997_ESAFEOUT2) { switch (selector) { @@ -161,7 +156,7 @@ static int max8997_list_voltage_safeout(struct regulator_dev *rdev, static int max8997_list_voltage_charger_cv(struct regulator_dev *rdev, unsigned int selector) { - int rid = max8997_get_rid(rdev); + int rid = rdev_get_id(rdev); if (rid != MAX8997_CHARGER_CV) goto err; @@ -184,7 +179,7 @@ static int max8997_list_voltage(struct regulator_dev *rdev, unsigned int selector) { const struct voltage_map_desc *desc; - int rid = max8997_get_rid(rdev); + int rid = rdev_get_id(rdev); int val; if (rid >= ARRAY_SIZE(reg_voltage_map) || @@ -205,7 +200,7 @@ static int max8997_list_voltage(struct regulator_dev *rdev, static int max8997_get_enable_register(struct regulator_dev *rdev, int *reg, int *mask, int *pattern) { - int rid = max8997_get_rid(rdev); + int rid = rdev_get_id(rdev); switch (rid) { case MAX8997_LDO1 ... MAX8997_LDO21: @@ -325,7 +320,7 @@ static int max8997_reg_disable(struct regulator_dev *rdev) static int max8997_get_voltage_register(struct regulator_dev *rdev, int *_reg, int *_shift, int *_mask) { - int rid = max8997_get_rid(rdev); + int rid = rdev_get_id(rdev); int reg, shift = 0, mask = 0x3f; switch (rid) { @@ -386,7 +381,7 @@ static int max8997_get_voltage(struct regulator_dev *rdev) struct max8997_data *max8997 = rdev_get_drvdata(rdev); struct i2c_client *i2c = max8997->iodev->i2c; int reg, shift, mask, ret; - int rid = max8997_get_rid(rdev); + int rid = rdev_get_id(rdev); u8 val; ret = max8997_get_voltage_register(rdev, ®, &shift, &mask); @@ -446,7 +441,7 @@ static int max8997_set_voltage_charger_cv(struct regulator_dev *rdev, { struct max8997_data *max8997 = rdev_get_drvdata(rdev); struct i2c_client *i2c = max8997->iodev->i2c; - int rid = max8997_get_rid(rdev); + int rid = rdev_get_id(rdev); int lb, ub; int reg, shift = 0, mask, ret = 0; u8 val = 0x0; @@ -503,7 +498,7 @@ static int max8997_set_voltage_ldobuck(struct regulator_dev *rdev, struct i2c_client *i2c = max8997->iodev->i2c; int min_vol = min_uV / 1000, max_vol = max_uV / 1000; const struct voltage_map_desc *desc; - int rid = max8997_get_rid(rdev); + int rid = rdev_get_id(rdev); int reg, shift = 0, mask, ret; int i; u8 org; @@ -564,7 +559,7 @@ static int max8997_assess_side_effect(struct regulator_dev *rdev, u8 new_val, int *best) { struct max8997_data *max8997 = rdev_get_drvdata(rdev); - int rid = max8997_get_rid(rdev); + int rid = rdev_get_id(rdev); u8 *buckx_val[3]; bool buckx_gpiodvs[3]; int side_effect[8]; @@ -641,7 +636,7 @@ static int max8997_set_voltage_buck(struct regulator_dev *rdev, int min_uV, int max_uV, unsigned *selector) { struct max8997_data *max8997 = rdev_get_drvdata(rdev); - int rid = max8997_get_rid(rdev); + int rid = rdev_get_id(rdev); const struct voltage_map_desc *desc; int new_val, new_idx, damage, tmp_val, tmp_idx, tmp_dmg; bool gpio_dvs_mode = false; @@ -724,7 +719,7 @@ static int max8997_set_voltage_safeout(struct regulator_dev *rdev, { struct max8997_data *max8997 = rdev_get_drvdata(rdev); struct i2c_client *i2c = max8997->iodev->i2c; - int rid = max8997_get_rid(rdev); + int rid = rdev_get_id(rdev); int reg, shift = 0, mask, ret; int i = 0; u8 val; @@ -766,7 +761,7 @@ static int max8997_reg_disable_suspend(struct regulator_dev *rdev) struct max8997_data *max8997 = rdev_get_drvdata(rdev); struct i2c_client *i2c = max8997->iodev->i2c; int ret, reg, mask, pattern; - int rid = max8997_get_rid(rdev); + int rid = rdev_get_id(rdev); ret = max8997_get_enable_register(rdev, ®, &mask, &pattern); if (ret) -- cgit v0.10.2 From 7b94791be6fb1c52c5ccb2cfde793da6c6b541b0 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Thu, 1 Mar 2012 09:27:29 +0800 Subject: regulator: Kill max8998_get_ldo function Use rdev_get_id() directly. Signed-off-by: Axel Lin Signed-off-by: Mark Brown diff --git a/drivers/regulator/max8998.c b/drivers/regulator/max8998.c index 2d38c24..634f257 100644 --- a/drivers/regulator/max8998.c +++ b/drivers/regulator/max8998.c @@ -112,16 +112,11 @@ static const struct voltage_map_desc *ldo_voltage_map[] = { &buck4_voltage_map_desc, /* BUCK4 */ }; -static inline int max8998_get_ldo(struct regulator_dev *rdev) -{ - return rdev_get_id(rdev); -} - static int max8998_list_voltage(struct regulator_dev *rdev, unsigned int selector) { const struct voltage_map_desc *desc; - int ldo = max8998_get_ldo(rdev); + int ldo = rdev_get_id(rdev); int val; if (ldo >= ARRAY_SIZE(ldo_voltage_map)) @@ -141,7 +136,7 @@ static int max8998_list_voltage(struct regulator_dev *rdev, static int max8998_get_enable_register(struct regulator_dev *rdev, int *reg, int *shift) { - int ldo = max8998_get_ldo(rdev); + int ldo = rdev_get_id(rdev); switch (ldo) { case MAX8998_LDO2 ... MAX8998_LDO5: @@ -222,7 +217,7 @@ static int max8998_ldo_disable(struct regulator_dev *rdev) static int max8998_get_voltage_register(struct regulator_dev *rdev, int *_reg, int *_shift, int *_mask) { - int ldo = max8998_get_ldo(rdev); + int ldo = rdev_get_id(rdev); struct max8998_data *max8998 = rdev_get_drvdata(rdev); int reg, shift = 0, mask = 0xff; @@ -310,7 +305,7 @@ static int max8998_set_voltage_ldo(struct regulator_dev *rdev, struct i2c_client *i2c = max8998->iodev->i2c; int min_vol = min_uV / 1000, max_vol = max_uV / 1000; const struct voltage_map_desc *desc; - int ldo = max8998_get_ldo(rdev); + int ldo = rdev_get_id(rdev); int reg, shift = 0, mask, ret; int i = 0; @@ -362,7 +357,7 @@ static int max8998_set_voltage_buck(struct regulator_dev *rdev, struct i2c_client *i2c = max8998->iodev->i2c; int min_vol = min_uV / 1000, max_vol = max_uV / 1000; const struct voltage_map_desc *desc; - int buck = max8998_get_ldo(rdev); + int buck = rdev_get_id(rdev); int reg, shift = 0, mask, ret; int difference = 0, i = 0, j = 0, previous_vol = 0; u8 val = 0; -- cgit v0.10.2 From 48ee1160a44b6f404f5553a6fce8447507982311 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Fri, 2 Mar 2012 09:19:02 +0800 Subject: regulator: Simplify the code to get selector in isl6271a_set_voltage Signed-off-by: Axel Lin Acked-by: Marek Vasut Signed-off-by: Mark Brown diff --git a/drivers/regulator/isl6271a-regulator.c b/drivers/regulator/isl6271a-regulator.c index c1a456c..775f5fd 100644 --- a/drivers/regulator/isl6271a-regulator.c +++ b/drivers/regulator/isl6271a-regulator.c @@ -63,23 +63,15 @@ static int isl6271a_set_voltage(struct regulator_dev *dev, unsigned *selector) { struct isl_pmic *pmic = rdev_get_drvdata(dev); - int vsel, err, data; + int err, data; if (minuV < ISL6271A_VOLTAGE_MIN || minuV > ISL6271A_VOLTAGE_MAX) return -EINVAL; if (maxuV < ISL6271A_VOLTAGE_MIN || maxuV > ISL6271A_VOLTAGE_MAX) return -EINVAL; - /* Align to 50000 mV */ - vsel = minuV - (minuV % ISL6271A_VOLTAGE_STEP); - - /* If the result fell out of [minuV,maxuV] range, put it back */ - if (vsel < minuV) - vsel += ISL6271A_VOLTAGE_STEP; - - /* Convert the microvolts to data for the chip */ - data = (vsel - ISL6271A_VOLTAGE_MIN) / ISL6271A_VOLTAGE_STEP; - + data = DIV_ROUND_UP(minuV - ISL6271A_VOLTAGE_MIN, + ISL6271A_VOLTAGE_STEP); *selector = data; mutex_lock(&pmic->mtx); -- cgit v0.10.2 From b21bcd1ada026cd90243311e89dd8d999fe0a227 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Fri, 2 Mar 2012 09:28:44 +0800 Subject: regulator: Add a pointer to aat2870_data in struct aat2870_regulator The reason we add *pdev in struct aat2870_regulator is to use it to get a pointer to struct aat2870_data. Save a pointer to struct aat2870_data instead of pdev in struct aat2870_regulator, this change makes the intention more clear. Signed-off-by: Axel Lin Acked-by: Jin Park Signed-off-by: Mark Brown diff --git a/drivers/regulator/aat2870-regulator.c b/drivers/regulator/aat2870-regulator.c index 685ad43..9ed5c5d 100644 --- a/drivers/regulator/aat2870-regulator.c +++ b/drivers/regulator/aat2870-regulator.c @@ -31,7 +31,7 @@ #include struct aat2870_regulator { - struct platform_device *pdev; + struct aat2870_data *aat2870; struct regulator_desc desc; const int *voltages; /* uV */ @@ -60,7 +60,7 @@ static int aat2870_ldo_set_voltage_sel(struct regulator_dev *rdev, unsigned selector) { struct aat2870_regulator *ri = rdev_get_drvdata(rdev); - struct aat2870_data *aat2870 = dev_get_drvdata(ri->pdev->dev.parent); + struct aat2870_data *aat2870 = ri->aat2870; return aat2870->update(aat2870, ri->voltage_addr, ri->voltage_mask, selector << ri->voltage_shift); @@ -69,7 +69,7 @@ static int aat2870_ldo_set_voltage_sel(struct regulator_dev *rdev, static int aat2870_ldo_get_voltage_sel(struct regulator_dev *rdev) { struct aat2870_regulator *ri = rdev_get_drvdata(rdev); - struct aat2870_data *aat2870 = dev_get_drvdata(ri->pdev->dev.parent); + struct aat2870_data *aat2870 = ri->aat2870; u8 val; int ret; @@ -83,7 +83,7 @@ static int aat2870_ldo_get_voltage_sel(struct regulator_dev *rdev) static int aat2870_ldo_enable(struct regulator_dev *rdev) { struct aat2870_regulator *ri = rdev_get_drvdata(rdev); - struct aat2870_data *aat2870 = dev_get_drvdata(ri->pdev->dev.parent); + struct aat2870_data *aat2870 = ri->aat2870; return aat2870->update(aat2870, ri->enable_addr, ri->enable_mask, ri->enable_mask); @@ -92,7 +92,7 @@ static int aat2870_ldo_enable(struct regulator_dev *rdev) static int aat2870_ldo_disable(struct regulator_dev *rdev) { struct aat2870_regulator *ri = rdev_get_drvdata(rdev); - struct aat2870_data *aat2870 = dev_get_drvdata(ri->pdev->dev.parent); + struct aat2870_data *aat2870 = ri->aat2870; return aat2870->update(aat2870, ri->enable_addr, ri->enable_mask, 0); } @@ -100,7 +100,7 @@ static int aat2870_ldo_disable(struct regulator_dev *rdev) static int aat2870_ldo_is_enabled(struct regulator_dev *rdev) { struct aat2870_regulator *ri = rdev_get_drvdata(rdev); - struct aat2870_data *aat2870 = dev_get_drvdata(ri->pdev->dev.parent); + struct aat2870_data *aat2870 = ri->aat2870; u8 val; int ret; @@ -185,7 +185,7 @@ static int aat2870_regulator_probe(struct platform_device *pdev) dev_err(&pdev->dev, "Invalid device ID, %d\n", pdev->id); return -EINVAL; } - ri->pdev = pdev; + ri->aat2870 = dev_get_drvdata(pdev->dev.parent); rdev = regulator_register(&ri->desc, &pdev->dev, pdev->dev.platform_data, ri, NULL); -- cgit v0.10.2 From 8148ed6e6618598729efa53d3a1f905379de801e Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Fri, 2 Mar 2012 16:20:54 +0800 Subject: regulator: ad5398: Use DIV_ROUND_UP macro to calculate selector Signed-off-by: Axel Lin Acked-by: Sonic Zhang Signed-off-by: Mark Brown diff --git a/drivers/regulator/ad5398.c b/drivers/regulator/ad5398.c index 483c809..26d23ad 100644 --- a/drivers/regulator/ad5398.c +++ b/drivers/regulator/ad5398.c @@ -94,8 +94,8 @@ static int ad5398_set_current_limit(struct regulator_dev *rdev, int min_uA, int if (max_uA > chip->max_uA || max_uA < chip->min_uA) return -EINVAL; - selector = ((min_uA - chip->min_uA) * chip->current_level + - range_uA - 1) / range_uA; + selector = DIV_ROUND_UP((min_uA - chip->min_uA) * chip->current_level, + range_uA); if (ad5398_calc_current(chip, selector) > max_uA) return -EINVAL; -- cgit v0.10.2 From 7d530d32b0b71f1735a73f5b03e22955a5460b7f Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Fri, 2 Mar 2012 16:22:01 +0800 Subject: regulator: max1586: Use DIV_ROUND_UP macro to calculate selector Signed-off-by: Axel Lin Signed-off-by: Mark Brown diff --git a/drivers/regulator/max1586.c b/drivers/regulator/max1586.c index 40e7a4d..282d2ee 100644 --- a/drivers/regulator/max1586.c +++ b/drivers/regulator/max1586.c @@ -76,8 +76,8 @@ static int max1586_v3_set(struct regulator_dev *rdev, int min_uV, int max_uV, if (min_uV < max1586->min_uV) min_uV = max1586->min_uV; - *selector = ((min_uV - max1586->min_uV) * MAX1586_V3_MAX_VSEL + - range_uV - 1) / range_uV; + *selector = DIV_ROUND_UP((min_uV - max1586->min_uV) * + MAX1586_V3_MAX_VSEL, range_uV); if (max1586_v3_calc_voltage(max1586, *selector) > max_uV) return -EINVAL; -- cgit v0.10.2 From ab353c2375258fced2967dfe66ff109098797cf1 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Fri, 2 Mar 2012 16:23:39 +0800 Subject: regulator: max8660: Use DIV_ROUND_UP macro to calculate selector Signed-off-by: Axel Lin Signed-off-by: Mark Brown diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c index a838e66..4c5b053 100644 --- a/drivers/regulator/max8660.c +++ b/drivers/regulator/max8660.c @@ -153,14 +153,15 @@ static int max8660_dcdc_set(struct regulator_dev *rdev, int min_uV, int max_uV, if (max_uV < MAX8660_DCDC_MIN_UV || max_uV > MAX8660_DCDC_MAX_UV) return -EINVAL; - selector = (min_uV - (MAX8660_DCDC_MIN_UV - MAX8660_DCDC_STEP + 1)) - / MAX8660_DCDC_STEP; - *s = selector; + selector = DIV_ROUND_UP(min_uV - MAX8660_DCDC_MIN_UV, + MAX8660_DCDC_STEP); ret = max8660_dcdc_list(rdev, selector); if (ret < 0 || ret > max_uV) return -EINVAL; + *s = selector; + reg = (rdev_get_id(rdev) == MAX8660_V3) ? MAX8660_ADTV2 : MAX8660_SDTV2; ret = max8660_write(max8660, reg, 0, selector); if (ret) @@ -210,8 +211,9 @@ static int max8660_ldo5_set(struct regulator_dev *rdev, int min_uV, int max_uV, if (max_uV < MAX8660_LDO5_MIN_UV || max_uV > MAX8660_LDO5_MAX_UV) return -EINVAL; - selector = (min_uV - (MAX8660_LDO5_MIN_UV - MAX8660_LDO5_STEP + 1)) - / MAX8660_LDO5_STEP; + selector = DIV_ROUND_UP(min_uV - MAX8660_LDO5_MIN_UV, + MAX8660_LDO5_STEP); + ret = max8660_ldo5_list(rdev, selector); if (ret < 0 || ret > max_uV) return -EINVAL; @@ -287,8 +289,8 @@ static int max8660_ldo67_set(struct regulator_dev *rdev, int min_uV, if (max_uV < MAX8660_LDO67_MIN_UV || max_uV > MAX8660_LDO67_MAX_UV) return -EINVAL; - selector = (min_uV - (MAX8660_LDO67_MIN_UV - MAX8660_LDO67_STEP + 1)) - / MAX8660_LDO67_STEP; + selector = DIV_ROUND_UP(min_uV - MAX8660_LDO67_MIN_UV, + MAX8660_LDO67_STEP); ret = max8660_ldo67_list(rdev, selector); if (ret < 0 || ret > max_uV) -- cgit v0.10.2 From 1c37f8a838fa8b1e98a984893bd4f1a8a9849421 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Sat, 3 Mar 2012 12:40:01 +0100 Subject: regulator fixed: Do not report enumaratable voltages if there are none If used as a dummy voltage provider the fixed regulator should not set n_voltages to make the core accept the device. Signed-off-by: Sascha Hauer Signed-off-by: Mark Brown diff --git a/drivers/regulator/fixed.c b/drivers/regulator/fixed.c index e24e3a1..40f3803 100644 --- a/drivers/regulator/fixed.c +++ b/drivers/regulator/fixed.c @@ -192,7 +192,9 @@ static int __devinit reg_fixed_voltage_probe(struct platform_device *pdev) drvdata->desc.type = REGULATOR_VOLTAGE; drvdata->desc.owner = THIS_MODULE; drvdata->desc.ops = &fixed_voltage_ops; - drvdata->desc.n_voltages = 1; + + if (config->microvolts) + drvdata->desc.n_voltages = 1; drvdata->microvolts = config->microvolts; drvdata->gpio = config->gpio; -- cgit v0.10.2 From e9a15c8cad2a23e86a8e6457a3ab0ab3bda50d35 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Tue, 6 Mar 2012 09:56:05 +0800 Subject: regulator: wm8400: Use DIV_ROUND_UP macro to calculate selector Use DIV_ROUND_UP macro for better readability. Signed-off-by: Axel Lin Signed-off-by: Mark Brown diff --git a/drivers/regulator/wm8400-regulator.c b/drivers/regulator/wm8400-regulator.c index 706f395..8477153 100644 --- a/drivers/regulator/wm8400-regulator.c +++ b/drivers/regulator/wm8400-regulator.c @@ -78,14 +78,14 @@ static int wm8400_ldo_set_voltage(struct regulator_dev *dev, if (min_uV < 1700000) { /* Steps of 50mV from 900mV; */ - val = (min_uV - 850001) / 50000; + val = DIV_ROUND_UP(min_uV - 900000, 50000); if ((val * 50000) + 900000 > max_uV) return -EINVAL; BUG_ON((val * 50000) + 900000 < min_uV); } else { /* Steps of 100mV from 1700mV */ - val = ((min_uV - 1600001) / 100000); + val = DIV_ROUND_UP(min_uV - 1700000, 100000); if ((val * 100000) + 1700000 > max_uV) return -EINVAL; @@ -168,7 +168,7 @@ static int wm8400_dcdc_set_voltage(struct regulator_dev *dev, if (min_uV < 850000) return -EINVAL; - val = (min_uV - 825001) / 25000; + val = DIV_ROUND_UP(min_uV - 850000, 25000); if (850000 + (25000 * val) > max_uV) return -EINVAL; -- cgit v0.10.2 From ae76e8307ff2812a57692a54322c6898a949ae76 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Tue, 6 Mar 2012 06:54:40 +0800 Subject: regulator: da903x: Use DIV_ROUND_UP macro to calculate selector Signed-off-by: Axel Lin Signed-off-by: Mark Brown diff --git a/drivers/regulator/da903x.c b/drivers/regulator/da903x.c index 8dbc54d..1851f09 100644 --- a/drivers/regulator/da903x.c +++ b/drivers/regulator/da903x.c @@ -119,7 +119,7 @@ static int da903x_set_ldo_voltage(struct regulator_dev *rdev, return -EINVAL; } - val = (min_uV - info->min_uV + info->step_uV - 1) / info->step_uV; + val = DIV_ROUND_UP(min_uV - info->min_uV, info->step_uV); *selector = val; val <<= info->vol_shift; mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; @@ -202,7 +202,7 @@ static int da9030_set_ldo1_15_voltage(struct regulator_dev *rdev, return -EINVAL; } - val = (min_uV - info->min_uV + info->step_uV - 1) / info->step_uV; + val = DIV_ROUND_UP(min_uV - info->min_uV, info->step_uV); *selector = val; val <<= info->vol_shift; mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; @@ -233,10 +233,10 @@ static int da9030_set_ldo14_voltage(struct regulator_dev *rdev, thresh = (info->max_uV + info->min_uV) / 2; if (min_uV < thresh) { - val = (thresh - min_uV + info->step_uV - 1) / info->step_uV; + val = DIV_ROUND_UP(thresh - min_uV, info->step_uV); val |= 0x4; } else { - val = (min_uV - thresh + info->step_uV - 1) / info->step_uV; + val = DIV_ROUND_UP(min_uV - thresh, info->step_uV); } *selector = val; @@ -281,7 +281,7 @@ static int da9034_set_dvc_voltage(struct regulator_dev *rdev, return -EINVAL; } - val = (min_uV - info->min_uV + info->step_uV - 1) / info->step_uV; + val = DIV_ROUND_UP(min_uV - info->min_uV, info->step_uV); *selector = val; val <<= info->vol_shift; mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; @@ -307,7 +307,7 @@ static int da9034_set_ldo12_voltage(struct regulator_dev *rdev, return -EINVAL; } - val = (min_uV - info->min_uV + info->step_uV - 1) / info->step_uV; + val = DIV_ROUND_UP(min_uV - info->min_uV, info->step_uV); val = (val >= 20) ? val - 12 : ((val > 7) ? 8 : val); *selector = val; val <<= info->vol_shift; -- cgit v0.10.2 From 2fe4e0259dfd6d66f2a094b5109f11f8d253e764 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Tue, 6 Mar 2012 09:54:22 +0800 Subject: regulator: tps65217: Use DIV_ROUND_UP macro to calculate selector Use DIV_ROUND_UP macro for better readability. Signed-off-by: Axel Lin Signed-off-by: Mark Brown diff --git a/drivers/regulator/tps65217-regulator.c b/drivers/regulator/tps65217-regulator.c index 28a10ea..15f2fa0 100644 --- a/drivers/regulator/tps65217-regulator.c +++ b/drivers/regulator/tps65217-regulator.c @@ -82,11 +82,11 @@ static int tps65217_uv_to_vsel1(int uV, unsigned int *vsel) return -EINVAL; if (uV <= 1500000) - *vsel = (uV - 875001) / 25000; + *vsel = DIV_ROUND_UP(uV - 900000, 25000); else if (uV <= 2900000) - *vsel = 24 + (uV - 1450001) / 50000; + *vsel = 24 + DIV_ROUND_UP(uV - 1500000, 50000); else if (uV < 3300000) - *vsel = 52 + (uV - 2800001) / 100000; + *vsel = 52 + DIV_ROUND_UP(uV - 2900000, 100000); else *vsel = 56; @@ -116,11 +116,11 @@ static int tps65217_uv_to_vsel2(int uV, unsigned int *vsel) return -EINVAL; if (uV <= 1900000) - *vsel = (uV - 1450001) / 50000; + *vsel = DIV_ROUND_UP(uV - 1500000, 50000); else if (uV <= 2400000) - *vsel = 8 + (uV - 1800001) / 100000; + *vsel = 8 + DIV_ROUND_UP(uV - 1900000, 100000); else - *vsel = 13 + (uV - 2350001) / 50000; + *vsel = 13 + DIV_ROUND_UP(uV - 2400000, 50000); return 0; } -- cgit v0.10.2 From 535bca2037ce89349cb5ed80ab3ab6d0c0ef1938 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Wed, 7 Mar 2012 10:02:12 +0800 Subject: regulator: Remove unused i2c variable in s5m8767_pmic_probe Signed-off-by: Axel Lin Acked-by: Sangbeom Kim Signed-off-by: Mark Brown diff --git a/drivers/regulator/s5m8767.c b/drivers/regulator/s5m8767.c index 9b97aa3..e369d9e 100644 --- a/drivers/regulator/s5m8767.c +++ b/drivers/regulator/s5m8767.c @@ -542,7 +542,6 @@ static __devinit int s5m8767_pmic_probe(struct platform_device *pdev) struct s5m_platform_data *pdata = dev_get_platdata(iodev->dev); struct regulator_dev **rdev; struct s5m8767_info *s5m8767; - struct i2c_client *i2c; int i, ret, size; if (!pdata) { @@ -565,7 +564,6 @@ static __devinit int s5m8767_pmic_probe(struct platform_device *pdev) s5m8767->iodev = iodev; s5m8767->num_regulators = S5M8767_REG_MAX - 2; platform_set_drvdata(pdev, s5m8767); - i2c = s5m8767->iodev->i2c; s5m8767->buck_gpioindex = pdata->buck_default_idx; s5m8767->buck2_gpiodvs = pdata->buck2_gpiodvs; -- cgit v0.10.2 From f08f5de54f419776e8133693d152ff3a016f2a9a Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Wed, 7 Mar 2012 15:15:40 +0800 Subject: regulator: Silence error message in max8998_pmic_probe This looks like a mistakenly committed debug logging. Signed-off-by: Axel Lin Signed-off-by: Mark Brown diff --git a/drivers/regulator/max8998.c b/drivers/regulator/max8998.c index 634f257..5890265 100644 --- a/drivers/regulator/max8998.c +++ b/drivers/regulator/max8998.c @@ -824,7 +824,6 @@ static __devinit int max8998_pmic_probe(struct platform_device *pdev) buck12_voltage_map_desc.step*i < (pdata->buck2_voltage2 / 1000)) i++; - printk(KERN_ERR "i2:%d, buck2_idx:%d\n", i, max8998->buck2_idx); max8998->buck2_vol[1] = i; ret = max8998_write_reg(i2c, MAX8998_REG_BUCK2_VOLTAGE2, i); if (ret) -- cgit v0.10.2 From 21c9e5f19ee68632d939f94a90fb33d3e6a111df Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Thu, 8 Mar 2012 10:05:24 +0800 Subject: regulator: max8649: Use DIV_ROUND_UP macro to calculate selector Use DIV_ROUND_UP macro for better readability. Signed-off-by: Axel Lin Signed-off-by: Mark Brown diff --git a/drivers/regulator/max8649.c b/drivers/regulator/max8649.c index 636dfd4..82505fc 100644 --- a/drivers/regulator/max8649.c +++ b/drivers/regulator/max8649.c @@ -101,8 +101,7 @@ static int max8649_set_voltage(struct regulator_dev *rdev, min_uV, max_uV); return -EINVAL; } - data = (min_uV - MAX8649_DCDC_VMIN + MAX8649_DCDC_STEP - 1) - / MAX8649_DCDC_STEP; + data = DIV_ROUND_UP(min_uV - MAX8649_DCDC_VMIN, MAX8649_DCDC_STEP); mask = MAX8649_VOL_MASK; *selector = data & mask; -- cgit v0.10.2 From 844775ef987aaf09a1ddea668f9acd17f9548062 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Thu, 8 Mar 2012 12:07:37 +0800 Subject: regulator: Simplify the implementation of tps65912_get_voltage_dcdc Call tps65912_list_voltage_dcdc instead of duplicating the same code. Signed-off-by: Axel Lin Signed-off-by: Mark Brown diff --git a/drivers/regulator/tps65912-regulator.c b/drivers/regulator/tps65912-regulator.c index da00d88..b685757 100644 --- a/drivers/regulator/tps65912-regulator.c +++ b/drivers/regulator/tps65912-regulator.c @@ -506,66 +506,88 @@ static unsigned int tps65912_get_mode(struct regulator_dev *dev) return mode; } -static int tps65912_get_voltage_dcdc(struct regulator_dev *dev) +static int tps65912_list_voltage_dcdc(struct regulator_dev *dev, + unsigned selector) { struct tps65912_reg *pmic = rdev_get_drvdata(dev); - struct tps65912 *mfd = pmic->mfd; - int id = rdev_get_id(dev), voltage = 0, range; - int opvsel = 0, avsel = 0, sr, vsel; + int range, voltage = 0, id = rdev_get_id(dev); switch (id) { case TPS65912_REG_DCDC1: - opvsel = tps65912_reg_read(mfd, TPS65912_DCDC1_OP); - avsel = tps65912_reg_read(mfd, TPS65912_DCDC1_AVS); range = pmic->dcdc1_range; break; case TPS65912_REG_DCDC2: - opvsel = tps65912_reg_read(mfd, TPS65912_DCDC2_OP); - avsel = tps65912_reg_read(mfd, TPS65912_DCDC2_AVS); range = pmic->dcdc2_range; break; case TPS65912_REG_DCDC3: - opvsel = tps65912_reg_read(mfd, TPS65912_DCDC3_OP); - avsel = tps65912_reg_read(mfd, TPS65912_DCDC3_AVS); range = pmic->dcdc3_range; break; case TPS65912_REG_DCDC4: - opvsel = tps65912_reg_read(mfd, TPS65912_DCDC4_OP); - avsel = tps65912_reg_read(mfd, TPS65912_DCDC4_AVS); range = pmic->dcdc4_range; break; default: return -EINVAL; } - sr = (opvsel & OP_SELREG_MASK) >> OP_SELREG_SHIFT; - if (sr) - vsel = avsel; - else - vsel = opvsel; - vsel &= 0x3F; - switch (range) { case 0: /* 0.5 - 1.2875V in 12.5mV steps */ - voltage = tps65912_vsel_to_uv_range0(vsel); + voltage = tps65912_vsel_to_uv_range0(selector); break; case 1: /* 0.7 - 1.4875V in 12.5mV steps */ - voltage = tps65912_vsel_to_uv_range1(vsel); + voltage = tps65912_vsel_to_uv_range1(selector); break; case 2: /* 0.5 - 2.075V in 25mV steps */ - voltage = tps65912_vsel_to_uv_range2(vsel); + voltage = tps65912_vsel_to_uv_range2(selector); break; case 3: /* 0.5 - 3.8V in 50mV steps */ - voltage = tps65912_vsel_to_uv_range3(vsel); + voltage = tps65912_vsel_to_uv_range3(selector); break; } return voltage; } +static int tps65912_get_voltage_dcdc(struct regulator_dev *dev) +{ + struct tps65912_reg *pmic = rdev_get_drvdata(dev); + struct tps65912 *mfd = pmic->mfd; + int id = rdev_get_id(dev); + int opvsel = 0, avsel = 0, sr, vsel; + + switch (id) { + case TPS65912_REG_DCDC1: + opvsel = tps65912_reg_read(mfd, TPS65912_DCDC1_OP); + avsel = tps65912_reg_read(mfd, TPS65912_DCDC1_AVS); + break; + case TPS65912_REG_DCDC2: + opvsel = tps65912_reg_read(mfd, TPS65912_DCDC2_OP); + avsel = tps65912_reg_read(mfd, TPS65912_DCDC2_AVS); + break; + case TPS65912_REG_DCDC3: + opvsel = tps65912_reg_read(mfd, TPS65912_DCDC3_OP); + avsel = tps65912_reg_read(mfd, TPS65912_DCDC3_AVS); + break; + case TPS65912_REG_DCDC4: + opvsel = tps65912_reg_read(mfd, TPS65912_DCDC4_OP); + avsel = tps65912_reg_read(mfd, TPS65912_DCDC4_AVS); + break; + default: + return -EINVAL; + } + + sr = (opvsel & OP_SELREG_MASK) >> OP_SELREG_SHIFT; + if (sr) + vsel = avsel; + else + vsel = opvsel; + vsel &= 0x3F; + + return tps65912_list_voltage_dcdc(dev, vsel); +} + static int tps65912_set_voltage_dcdc(struct regulator_dev *dev, unsigned selector) { @@ -609,50 +631,6 @@ static int tps65912_set_voltage_ldo(struct regulator_dev *dev, return tps65912_reg_write(mfd, reg, selector | value); } -static int tps65912_list_voltage_dcdc(struct regulator_dev *dev, - unsigned selector) -{ - struct tps65912_reg *pmic = rdev_get_drvdata(dev); - int range, voltage = 0, id = rdev_get_id(dev); - - switch (id) { - case TPS65912_REG_DCDC1: - range = pmic->dcdc1_range; - break; - case TPS65912_REG_DCDC2: - range = pmic->dcdc2_range; - break; - case TPS65912_REG_DCDC3: - range = pmic->dcdc3_range; - break; - case TPS65912_REG_DCDC4: - range = pmic->dcdc4_range; - break; - default: - return -EINVAL; - } - - switch (range) { - case 0: - /* 0.5 - 1.2875V in 12.5mV steps */ - voltage = tps65912_vsel_to_uv_range0(selector); - break; - case 1: - /* 0.7 - 1.4875V in 12.5mV steps */ - voltage = tps65912_vsel_to_uv_range1(selector); - break; - case 2: - /* 0.5 - 2.075V in 25mV steps */ - voltage = tps65912_vsel_to_uv_range2(selector); - break; - case 3: - /* 0.5 - 3.8V in 50mV steps */ - voltage = tps65912_vsel_to_uv_range3(selector); - break; - } - return voltage; -} - static int tps65912_list_voltage_ldo(struct regulator_dev *dev, unsigned selector) { -- cgit v0.10.2 From f30b0716feaedc0cf432ed8eca82c46104d64c0d Mon Sep 17 00:00:00 2001 From: Laxman Dewangan Date: Wed, 7 Mar 2012 18:21:49 +0530 Subject: regulator: tps65910: Sleep off rails when ext sleep configured Keep the rails OFF in sleep mode only when the rails are controlled by external sleep control. The devices tps65910 and tps65911, both has the sleep input. The tps65911's sleep input is not same as tps65910's EN3 and hence taking care of SLEEP input as separate external sleep control input. Signed-off-by: Laxman Dewangan Signed-off-by: Mark Brown diff --git a/drivers/regulator/tps65910-regulator.c b/drivers/regulator/tps65910-regulator.c index 15b5f1e..b0533c1 100644 --- a/drivers/regulator/tps65910-regulator.c +++ b/drivers/regulator/tps65910-regulator.c @@ -28,7 +28,8 @@ #define TPS65910_SUPPLY_STATE_ENABLED 0x1 #define EXT_SLEEP_CONTROL (TPS65910_SLEEP_CONTROL_EXT_INPUT_EN1 | \ TPS65910_SLEEP_CONTROL_EXT_INPUT_EN2 | \ - TPS65910_SLEEP_CONTROL_EXT_INPUT_EN3) + TPS65910_SLEEP_CONTROL_EXT_INPUT_EN3 | \ + TPS65911_SLEEP_CONTROL_EXT_INPUT_SLEEP) /* supported VIO voltages in milivolts */ static const u16 VIO_VSEL_table[] = { @@ -922,6 +923,8 @@ static int tps65910_set_ext_sleep_config(struct tps65910_reg *pmic, TPS65910_SLEEP_CONTROL_EXT_INPUT_EN2) != 0); en_count += ((ext_sleep_config & TPS65910_SLEEP_CONTROL_EXT_INPUT_EN3) != 0); + en_count += ((ext_sleep_config & + TPS65911_SLEEP_CONTROL_EXT_INPUT_SLEEP) != 0); if (en_count > 1) { dev_err(mfd->dev, "External sleep control flag is not proper\n"); @@ -1018,12 +1021,18 @@ static int tps65910_set_ext_sleep_config(struct tps65910_reg *pmic, ret = tps65910_clear_bits(mfd, TPS65910_SLEEP_KEEP_LDO_ON + regoffs, bit_pos); - if (!ret) - ret = tps65910_set_bits(mfd, - TPS65910_SLEEP_SET_LDO_OFF + regoffs, bit_pos); + if (!ret) { + if (ext_sleep_config & TPS65911_SLEEP_CONTROL_EXT_INPUT_SLEEP) + ret = tps65910_set_bits(mfd, + TPS65910_SLEEP_SET_LDO_OFF + regoffs, bit_pos); + else + ret = tps65910_clear_bits(mfd, + TPS65910_SLEEP_SET_LDO_OFF + regoffs, bit_pos); + } if (ret < 0) dev_err(mfd->dev, "Error in configuring SLEEP register\n"); + return ret; } diff --git a/include/linux/mfd/tps65910.h b/include/linux/mfd/tps65910.h index fa6c6bf..76700b5 100644 --- a/include/linux/mfd/tps65910.h +++ b/include/linux/mfd/tps65910.h @@ -768,12 +768,11 @@ /* Max number of TPS65910/11 regulators */ #define TPS65910_NUM_REGS 13 -/* External sleep controls through EN1/EN2/EN3 inputs*/ +/* External sleep controls through EN1/EN2/EN3/SLEEP inputs */ #define TPS65910_SLEEP_CONTROL_EXT_INPUT_EN1 0x1 #define TPS65910_SLEEP_CONTROL_EXT_INPUT_EN2 0x2 #define TPS65910_SLEEP_CONTROL_EXT_INPUT_EN3 0x4 -/* TPS65911 names the EN3 signal as SLEEP */ -#define TPS65911_SLEEP_CONTROL_EXT_INPUT_SLEEP 0x4 +#define TPS65911_SLEEP_CONTROL_EXT_INPUT_SLEEP 0x8 /** * struct tps65910_board -- cgit v0.10.2 From 394ee3d5bea96b6dd29ec42a797d1ee4c2af5f1d Mon Sep 17 00:00:00 2001 From: Thierry Reding Date: Thu, 8 Mar 2012 15:51:24 +0100 Subject: regulator: tps6586x: fix typo in debug message Signed-off-by: Thierry Reding Signed-off-by: Mark Brown diff --git a/drivers/regulator/tps6586x-regulator.c b/drivers/regulator/tps6586x-regulator.c index c75fb20..29b615c 100644 --- a/drivers/regulator/tps6586x-regulator.c +++ b/drivers/regulator/tps6586x-regulator.c @@ -383,7 +383,7 @@ static int __devinit tps6586x_regulator_probe(struct platform_device *pdev) int id = pdev->id; int err; - dev_dbg(&pdev->dev, "Probing reulator %d\n", id); + dev_dbg(&pdev->dev, "Probing regulator %d\n", id); ri = find_regulator_info(id); if (ri == NULL) { -- cgit v0.10.2 From 0f8b9c774442fa0ada36e5a0de9567588cc964cd Mon Sep 17 00:00:00 2001 From: Sangbeom Kim Date: Fri, 9 Mar 2012 16:28:10 +0900 Subject: regulator: Fix s5m8767_set_voltage_time_sel calculation value In the s5m8767_set_voltage_time_sel function, divisor unit is wrong. ramp_delay is usec unit. So 1000 should be multiplied. Signed-off-by: Sangbeom Kim Signed-off-by: Mark Brown diff --git a/drivers/regulator/s5m8767.c b/drivers/regulator/s5m8767.c index e369d9e..3592ccb 100644 --- a/drivers/regulator/s5m8767.c +++ b/drivers/regulator/s5m8767.c @@ -457,7 +457,7 @@ static int s5m8767_set_voltage_time_sel(struct regulator_dev *rdev, if (old_sel < new_sel) return DIV_ROUND_UP(desc->step * (new_sel - old_sel), - s5m8767->ramp_delay); + s5m8767->ramp_delay * 1000); return 0; } -- cgit v0.10.2 From 94732b97c39859427cf99c34fc9de9750be7e5a5 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Fri, 9 Mar 2012 10:22:20 +0800 Subject: regulator: Rename set_voltage_sel callback function name to *_sel This change improves readability. Signed-off-by: Axel Lin Acked-by: Laxman Dewangan Signed-off-by: Mark Brown diff --git a/drivers/regulator/tps65910-regulator.c b/drivers/regulator/tps65910-regulator.c index b0533c1..4ac0058 100644 --- a/drivers/regulator/tps65910-regulator.c +++ b/drivers/regulator/tps65910-regulator.c @@ -685,8 +685,8 @@ static int tps65911_get_voltage(struct regulator_dev *dev) return (LDO_MIN_VOLT + value * step_mv) * 1000; } -static int tps65910_set_voltage_dcdc(struct regulator_dev *dev, - unsigned selector) +static int tps65910_set_voltage_dcdc_sel(struct regulator_dev *dev, + unsigned selector) { struct tps65910_reg *pmic = rdev_get_drvdata(dev); int id = rdev_get_id(dev), vsel; @@ -723,7 +723,8 @@ static int tps65910_set_voltage_dcdc(struct regulator_dev *dev, return 0; } -static int tps65910_set_voltage(struct regulator_dev *dev, unsigned selector) +static int tps65910_set_voltage_sel(struct regulator_dev *dev, + unsigned selector) { struct tps65910_reg *pmic = rdev_get_drvdata(dev); int reg, id = rdev_get_id(dev); @@ -749,7 +750,8 @@ static int tps65910_set_voltage(struct regulator_dev *dev, unsigned selector) return -EINVAL; } -static int tps65911_set_voltage(struct regulator_dev *dev, unsigned selector) +static int tps65911_set_voltage_sel(struct regulator_dev *dev, + unsigned selector) { struct tps65910_reg *pmic = rdev_get_drvdata(dev); int reg, id = rdev_get_id(dev); @@ -867,7 +869,7 @@ static struct regulator_ops tps65910_ops_dcdc = { .set_mode = tps65910_set_mode, .get_mode = tps65910_get_mode, .get_voltage = tps65910_get_voltage_dcdc, - .set_voltage_sel = tps65910_set_voltage_dcdc, + .set_voltage_sel = tps65910_set_voltage_dcdc_sel, .list_voltage = tps65910_list_voltage_dcdc, }; @@ -888,7 +890,7 @@ static struct regulator_ops tps65910_ops = { .set_mode = tps65910_set_mode, .get_mode = tps65910_get_mode, .get_voltage = tps65910_get_voltage, - .set_voltage_sel = tps65910_set_voltage, + .set_voltage_sel = tps65910_set_voltage_sel, .list_voltage = tps65910_list_voltage, }; @@ -899,7 +901,7 @@ static struct regulator_ops tps65911_ops = { .set_mode = tps65910_set_mode, .get_mode = tps65910_get_mode, .get_voltage = tps65911_get_voltage, - .set_voltage_sel = tps65911_set_voltage, + .set_voltage_sel = tps65911_set_voltage_sel, .list_voltage = tps65911_list_voltage, }; diff --git a/drivers/regulator/tps65912-regulator.c b/drivers/regulator/tps65912-regulator.c index b685757..6797095 100644 --- a/drivers/regulator/tps65912-regulator.c +++ b/drivers/regulator/tps65912-regulator.c @@ -588,8 +588,8 @@ static int tps65912_get_voltage_dcdc(struct regulator_dev *dev) return tps65912_list_voltage_dcdc(dev, vsel); } -static int tps65912_set_voltage_dcdc(struct regulator_dev *dev, - unsigned selector) +static int tps65912_set_voltage_dcdc_sel(struct regulator_dev *dev, + unsigned selector) { struct tps65912_reg *pmic = rdev_get_drvdata(dev); struct tps65912 *mfd = pmic->mfd; @@ -618,8 +618,8 @@ static int tps65912_get_voltage_ldo(struct regulator_dev *dev) return tps65912_vsel_to_uv_ldo(vsel); } -static int tps65912_set_voltage_ldo(struct regulator_dev *dev, - unsigned selector) +static int tps65912_set_voltage_ldo_sel(struct regulator_dev *dev, + unsigned selector) { struct tps65912_reg *pmic = rdev_get_drvdata(dev); struct tps65912 *mfd = pmic->mfd; @@ -650,7 +650,7 @@ static struct regulator_ops tps65912_ops_dcdc = { .set_mode = tps65912_set_mode, .get_mode = tps65912_get_mode, .get_voltage = tps65912_get_voltage_dcdc, - .set_voltage_sel = tps65912_set_voltage_dcdc, + .set_voltage_sel = tps65912_set_voltage_dcdc_sel, .list_voltage = tps65912_list_voltage_dcdc, }; @@ -660,7 +660,7 @@ static struct regulator_ops tps65912_ops_ldo = { .enable = tps65912_reg_enable, .disable = tps65912_reg_disable, .get_voltage = tps65912_get_voltage_ldo, - .set_voltage_sel = tps65912_set_voltage_ldo, + .set_voltage_sel = tps65912_set_voltage_ldo_sel, .list_voltage = tps65912_list_voltage_ldo, }; -- cgit v0.10.2 From 4d984d1cd838435cf1180ab9ffbab24cfdbf7515 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Fri, 9 Mar 2012 11:37:30 +0800 Subject: regulator: tps6524x: Remove unneeded comment for N_REGULATORS Signed-off-by: Axel Lin Signed-off-by: Mark Brown diff --git a/drivers/regulator/tps6524x-regulator.c b/drivers/regulator/tps6524x-regulator.c index 70b7b1f..60846e0 100644 --- a/drivers/regulator/tps6524x-regulator.c +++ b/drivers/regulator/tps6524x-regulator.c @@ -108,9 +108,7 @@ #define N_DCDC 3 #define N_LDO 2 #define N_SWITCH 2 -#define N_REGULATORS (3 /* DCDC */ + \ - 2 /* LDO */ + \ - 2 /* switch */) +#define N_REGULATORS (N_DCDC + N_LDO + N_SWITCH) #define FIXED_ILIMSEL BIT(0) #define FIXED_VOLTAGE BIT(1) -- cgit v0.10.2 From 5b5e977ce71cab973d9f8c7d5303832a2bafa92c Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Fri, 9 Mar 2012 11:31:08 +0800 Subject: regulator: Rename s5m8767_convert_voltage to s5m8767_convert_voltage_to_sel This function finds the smallest voltage that falls within the specified range, and then returns the selector. This rename makes the intention more clear. Also remove unneeded local variables min_vol and max_vol in s5m8767_set_voltage and s5m8767_set_voltage_buck. Signed-off-by: Axel Lin Acked-by: Sangbeom Kim Signed-off-by: Mark Brown diff --git a/drivers/regulator/s5m8767.c b/drivers/regulator/s5m8767.c index 3592ccb..9d5d915 100644 --- a/drivers/regulator/s5m8767.c +++ b/drivers/regulator/s5m8767.c @@ -294,11 +294,11 @@ static int s5m8767_get_voltage_sel(struct regulator_dev *rdev) return val; } -static inline int s5m8767_convert_voltage( +static int s5m8767_convert_voltage_to_sel( const struct s5m_voltage_desc *desc, int min_vol, int max_vol) { - int out_vol = 0; + int selector = 0; if (desc == NULL) return -EINVAL; @@ -306,19 +306,18 @@ static inline int s5m8767_convert_voltage( if (max_vol < desc->min || min_vol > desc->max) return -EINVAL; - out_vol = (min_vol - desc->min) / desc->step; + selector = (min_vol - desc->min) / desc->step; - if (desc->min + desc->step * out_vol > max_vol) + if (desc->min + desc->step * selector > max_vol) return -EINVAL; - return out_vol; + return selector; } static int s5m8767_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV, unsigned *selector) { struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev); - int min_vol = min_uV, max_vol = max_uV; const struct s5m_voltage_desc *desc; int reg_id = rdev_get_id(rdev); int reg, mask, ret; @@ -343,7 +342,7 @@ static int s5m8767_set_voltage(struct regulator_dev *rdev, desc = reg_voltage_map[reg_id]; - i = s5m8767_convert_voltage(desc, min_vol, max_vol); + i = s5m8767_convert_voltage_to_sel(desc, min_uV, max_uV); if (i < 0) return i; @@ -385,7 +384,6 @@ static int s5m8767_set_voltage_buck(struct regulator_dev *rdev, int reg_id = rdev_get_id(rdev); const struct s5m_voltage_desc *desc; int new_val, old_val, i = 0; - int min_vol = min_uV, max_vol = max_uV; if (reg_id < S5M8767_BUCK1 || reg_id > S5M8767_BUCK6) return -EINVAL; @@ -402,7 +400,7 @@ static int s5m8767_set_voltage_buck(struct regulator_dev *rdev, } desc = reg_voltage_map[reg_id]; - new_val = s5m8767_convert_voltage(desc, min_vol, max_vol); + new_val = s5m8767_convert_voltage_to_sel(desc, min_uV, max_uV); if (new_val < 0) return new_val; @@ -580,7 +578,7 @@ static __devinit int s5m8767_pmic_probe(struct platform_device *pdev) for (i = 0; i < 8; i++) { if (s5m8767->buck2_gpiodvs) { s5m8767->buck2_vol[i] = - s5m8767_convert_voltage( + s5m8767_convert_voltage_to_sel( &buck_voltage_val2, pdata->buck2_voltage[i], pdata->buck2_voltage[i] + @@ -589,7 +587,7 @@ static __devinit int s5m8767_pmic_probe(struct platform_device *pdev) if (s5m8767->buck3_gpiodvs) { s5m8767->buck3_vol[i] = - s5m8767_convert_voltage( + s5m8767_convert_voltage_to_sel( &buck_voltage_val2, pdata->buck3_voltage[i], pdata->buck3_voltage[i] + @@ -598,7 +596,7 @@ static __devinit int s5m8767_pmic_probe(struct platform_device *pdev) if (s5m8767->buck4_gpiodvs) { s5m8767->buck4_vol[i] = - s5m8767_convert_voltage( + s5m8767_convert_voltage_to_sel( &buck_voltage_val2, pdata->buck4_voltage[i], pdata->buck4_voltage[i] + -- cgit v0.10.2 From 85c5d86d0e87bd843d711dcb7427c6ba64f736d1 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Fri, 9 Mar 2012 07:05:41 +0800 Subject: regulator: Use array to store dcdc_range settings for tps65912 Then we can use the regulator id as array index to access the array. This change makes the code simpler. Signed-off-by: Axel Lin Signed-off-by: Mark Brown diff --git a/drivers/regulator/tps65912-regulator.c b/drivers/regulator/tps65912-regulator.c index 6797095..3ab1722 100644 --- a/drivers/regulator/tps65912-regulator.c +++ b/drivers/regulator/tps65912-regulator.c @@ -114,10 +114,7 @@ struct tps65912_reg { struct mutex io_lock; int mode; int (*get_ctrl_reg)(int); - int dcdc1_range; - int dcdc2_range; - int dcdc3_range; - int dcdc4_range; + int dcdc_range[TPS65912_NUM_DCDC]; int pwm_mode_reg; int eco_reg; }; @@ -125,46 +122,31 @@ struct tps65912_reg { static int tps65912_get_range(struct tps65912_reg *pmic, int id) { struct tps65912 *mfd = pmic->mfd; - - if (id > TPS65912_REG_DCDC4) - return 0; + int range; switch (id) { case TPS65912_REG_DCDC1: - pmic->dcdc1_range = tps65912_reg_read(mfd, - TPS65912_DCDC1_LIMIT); - if (pmic->dcdc1_range < 0) - return pmic->dcdc1_range; - pmic->dcdc1_range = (pmic->dcdc1_range & - DCDC_LIMIT_RANGE_MASK) >> DCDC_LIMIT_RANGE_SHIFT; - return pmic->dcdc1_range; + range = tps65912_reg_read(mfd, TPS65912_DCDC1_LIMIT); + break; case TPS65912_REG_DCDC2: - pmic->dcdc2_range = tps65912_reg_read(mfd, - TPS65912_DCDC2_LIMIT); - if (pmic->dcdc2_range < 0) - return pmic->dcdc2_range; - pmic->dcdc2_range = (pmic->dcdc2_range & - DCDC_LIMIT_RANGE_MASK) >> DCDC_LIMIT_RANGE_SHIFT; - return pmic->dcdc2_range; + range = tps65912_reg_read(mfd, TPS65912_DCDC2_LIMIT); + break; case TPS65912_REG_DCDC3: - pmic->dcdc3_range = tps65912_reg_read(mfd, - TPS65912_DCDC3_LIMIT); - if (pmic->dcdc3_range < 0) - return pmic->dcdc3_range; - pmic->dcdc3_range = (pmic->dcdc3_range & - DCDC_LIMIT_RANGE_MASK) >> DCDC_LIMIT_RANGE_SHIFT; - return pmic->dcdc3_range; + range = tps65912_reg_read(mfd, TPS65912_DCDC3_LIMIT); + break; case TPS65912_REG_DCDC4: - pmic->dcdc4_range = tps65912_reg_read(mfd, - TPS65912_DCDC4_LIMIT); - if (pmic->dcdc4_range < 0) - return pmic->dcdc4_range; - pmic->dcdc4_range = (pmic->dcdc4_range & - DCDC_LIMIT_RANGE_MASK) >> DCDC_LIMIT_RANGE_SHIFT; - return pmic->dcdc4_range; + range = tps65912_reg_read(mfd, TPS65912_DCDC4_LIMIT); + break; default: return 0; } + + if (range >= 0) + range = (range & DCDC_LIMIT_RANGE_MASK) + >> DCDC_LIMIT_RANGE_SHIFT; + + pmic->dcdc_range[id] = range; + return range; } static unsigned long tps65912_vsel_to_uv_range0(u8 vsel) @@ -512,22 +494,10 @@ static int tps65912_list_voltage_dcdc(struct regulator_dev *dev, struct tps65912_reg *pmic = rdev_get_drvdata(dev); int range, voltage = 0, id = rdev_get_id(dev); - switch (id) { - case TPS65912_REG_DCDC1: - range = pmic->dcdc1_range; - break; - case TPS65912_REG_DCDC2: - range = pmic->dcdc2_range; - break; - case TPS65912_REG_DCDC3: - range = pmic->dcdc3_range; - break; - case TPS65912_REG_DCDC4: - range = pmic->dcdc4_range; - break; - default: + if (id > TPS65912_REG_DCDC4) return -EINVAL; - } + + range = pmic->dcdc_range[id]; switch (range) { case 0: -- cgit v0.10.2 From dce7304f4b8ea9e12c1bd58747f16f579c4d7b2d Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Mon, 12 Mar 2012 10:17:56 +0800 Subject: regulator: Use DIV_ROUND_CLOSEST in wm8350_isink_get_current DIV_ROUND_CLOSEST performs the computation (x + d/2)/d with better readability. Signed-off-by: Axel Lin Signed-off-by: Mark Brown diff --git a/drivers/regulator/wm8350-regulator.c b/drivers/regulator/wm8350-regulator.c index 4f46067..ab1e183 100644 --- a/drivers/regulator/wm8350-regulator.c +++ b/drivers/regulator/wm8350-regulator.c @@ -186,7 +186,7 @@ static int wm8350_isink_get_current(struct regulator_dev *rdev) return 0; } - return (isink_cur[val] + 50) / 100; + return DIV_ROUND_CLOSEST(isink_cur[val], 100); } /* turn on ISINK followed by DCDC */ -- cgit v0.10.2 From fc56911bc6468c165894e0ca985b1130bb537955 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Mon, 12 Mar 2012 12:11:46 +0800 Subject: regulator: Merge tps65217_pmic_ldo234_ops and tps65217_pmic_dcdc_ops to tps65217_pmic_ops Most callback functions implementation for tps65217_pmic_ldo234_ops and tps65217_pmic_dcdc_ops are the same except the rid range checking. This patch uses tps65217_pmic_ops for all DCDCx, LDO2, LDO3, and LDO4. And rework tps65217_pmic_set_voltage to make it can be called for DCDCx, LDO2, LDO3, and LDO4. Signed-off-by: Axel Lin Signed-off-by: Mark Brown diff --git a/drivers/regulator/tps65217-regulator.c b/drivers/regulator/tps65217-regulator.c index 15f2fa0..e39521b 100644 --- a/drivers/regulator/tps65217-regulator.c +++ b/drivers/regulator/tps65217-regulator.c @@ -151,166 +151,69 @@ static struct tps_info tps65217_pmic_regs[] = { TPS65217_REG_DEFLS2, TPS65217_DEFLDO4_LDO4_MASK), }; -static int tps65217_pmic_dcdc_is_enabled(struct regulator_dev *dev) +static int tps65217_pmic_is_enabled(struct regulator_dev *dev) { int ret; struct tps65217 *tps = rdev_get_drvdata(dev); - unsigned int data, dcdc = rdev_get_id(dev); + unsigned int data, rid = rdev_get_id(dev); - if (dcdc < TPS65217_DCDC_1 || dcdc > TPS65217_DCDC_3) + if (rid < TPS65217_DCDC_1 || rid > TPS65217_LDO_4) return -EINVAL; ret = tps65217_reg_read(tps, TPS65217_REG_ENABLE, &data); if (ret) return ret; - return (data & tps->info[dcdc]->enable_mask) ? 1 : 0; + return (data & tps->info[rid]->enable_mask) ? 1 : 0; } -static int tps65217_pmic_ldo_is_enabled(struct regulator_dev *dev) +static int tps65217_pmic_enable(struct regulator_dev *dev) { - int ret; struct tps65217 *tps = rdev_get_drvdata(dev); - unsigned int data, ldo = rdev_get_id(dev); + unsigned int rid = rdev_get_id(dev); - if (ldo < TPS65217_LDO_1 || ldo > TPS65217_LDO_4) - return -EINVAL; - - ret = tps65217_reg_read(tps, TPS65217_REG_ENABLE, &data); - if (ret) - return ret; - - return (data & tps->info[ldo]->enable_mask) ? 1 : 0; -} - -static int tps65217_pmic_dcdc_enable(struct regulator_dev *dev) -{ - struct tps65217 *tps = rdev_get_drvdata(dev); - unsigned int dcdc = rdev_get_id(dev); - - if (dcdc < TPS65217_DCDC_1 || dcdc > TPS65217_DCDC_3) + if (rid < TPS65217_DCDC_1 || rid > TPS65217_LDO_4) return -EINVAL; /* Enable the regulator and password protection is level 1 */ return tps65217_set_bits(tps, TPS65217_REG_ENABLE, - tps->info[dcdc]->enable_mask, - tps->info[dcdc]->enable_mask, + tps->info[rid]->enable_mask, + tps->info[rid]->enable_mask, TPS65217_PROTECT_L1); } -static int tps65217_pmic_dcdc_disable(struct regulator_dev *dev) +static int tps65217_pmic_disable(struct regulator_dev *dev) { struct tps65217 *tps = rdev_get_drvdata(dev); - unsigned int dcdc = rdev_get_id(dev); + unsigned int rid = rdev_get_id(dev); - if (dcdc < TPS65217_DCDC_1 || dcdc > TPS65217_DCDC_3) + if (rid < TPS65217_DCDC_1 || rid > TPS65217_LDO_4) return -EINVAL; /* Disable the regulator and password protection is level 1 */ return tps65217_clear_bits(tps, TPS65217_REG_ENABLE, - tps->info[dcdc]->enable_mask, TPS65217_PROTECT_L1); -} - -static int tps65217_pmic_ldo_enable(struct regulator_dev *dev) -{ - struct tps65217 *tps = rdev_get_drvdata(dev); - unsigned int ldo = rdev_get_id(dev); - - if (ldo < TPS65217_LDO_1 || ldo > TPS65217_LDO_4) - return -EINVAL; - - /* Enable the regulator and password protection is level 1 */ - return tps65217_set_bits(tps, TPS65217_REG_ENABLE, - tps->info[ldo]->enable_mask, - tps->info[ldo]->enable_mask, - TPS65217_PROTECT_L1); -} - -static int tps65217_pmic_ldo_disable(struct regulator_dev *dev) -{ - struct tps65217 *tps = rdev_get_drvdata(dev); - unsigned int ldo = rdev_get_id(dev); - - if (ldo < TPS65217_LDO_1 || ldo > TPS65217_LDO_4) - return -EINVAL; - - /* Disable the regulator and password protection is level 1 */ - return tps65217_clear_bits(tps, TPS65217_REG_ENABLE, - tps->info[ldo]->enable_mask, TPS65217_PROTECT_L1); -} - -static int tps65217_pmic_dcdc_get_voltage_sel(struct regulator_dev *dev) -{ - int ret; - struct tps65217 *tps = rdev_get_drvdata(dev); - unsigned int selector, dcdc = rdev_get_id(dev); - - if (dcdc < TPS65217_DCDC_1 || dcdc > TPS65217_DCDC_3) - return -EINVAL; - - ret = tps65217_reg_read(tps, tps->info[dcdc]->set_vout_reg, &selector); - if (ret) - return ret; - - selector &= tps->info[dcdc]->set_vout_mask; - - return selector; + tps->info[rid]->enable_mask, TPS65217_PROTECT_L1); } -static int tps65217_pmic_dcdc_set_voltage(struct regulator_dev *dev, - int min_uV, int max_uV, unsigned *selector) +static int tps65217_pmic_get_voltage_sel(struct regulator_dev *dev) { int ret; struct tps65217 *tps = rdev_get_drvdata(dev); - unsigned int dcdc = rdev_get_id(dev); - - if (dcdc < TPS65217_DCDC_1 || dcdc > TPS65217_DCDC_3) - return -EINVAL; + unsigned int selector, rid = rdev_get_id(dev); - if (min_uV < tps->info[dcdc]->min_uV - || min_uV > tps->info[dcdc]->max_uV) + if (rid < TPS65217_DCDC_1 || rid > TPS65217_LDO_4) return -EINVAL; - if (max_uV < tps->info[dcdc]->min_uV - || max_uV > tps->info[dcdc]->max_uV) - return -EINVAL; - - ret = tps->info[dcdc]->uv_to_vsel(min_uV, selector); + ret = tps65217_reg_read(tps, tps->info[rid]->set_vout_reg, &selector); if (ret) return ret; - /* Set the voltage based on vsel value and write protect level is 2 */ - ret = tps65217_set_bits(tps, tps->info[dcdc]->set_vout_reg, - tps->info[dcdc]->set_vout_mask, - *selector, TPS65217_PROTECT_L2); - if (ret) - return ret; - - /* Set GO bit to initiate voltage transistion */ - return tps65217_set_bits(tps, TPS65217_REG_DEFSLEW, - TPS65217_DEFSLEW_GO, TPS65217_DEFSLEW_GO, - TPS65217_PROTECT_L2); -} - -static int tps65217_pmic_ldo_get_voltage_sel(struct regulator_dev *dev) -{ - int ret; - struct tps65217 *tps = rdev_get_drvdata(dev); - unsigned int selector, ldo = rdev_get_id(dev); - - if (ldo < TPS65217_LDO_1 || ldo > TPS65217_LDO_4) - return -EINVAL; - - ret = tps65217_reg_read(tps, tps->info[ldo]->set_vout_reg, &selector); - if (ret) - return ret; - - selector &= tps->info[ldo]->set_vout_mask; + selector &= tps->info[rid]->set_vout_mask; return selector; } -static int tps65217_pmic_ldo_set_voltage_sel(struct regulator_dev *dev, +static int tps65217_pmic_ldo1_set_voltage_sel(struct regulator_dev *dev, unsigned selector) { struct tps65217 *tps = rdev_get_drvdata(dev); @@ -328,112 +231,95 @@ static int tps65217_pmic_ldo_set_voltage_sel(struct regulator_dev *dev, selector, TPS65217_PROTECT_L2); } -static int tps65217_pmic_ldo_set_voltage(struct regulator_dev *dev, +static int tps65217_pmic_set_voltage(struct regulator_dev *dev, int min_uV, int max_uV, unsigned *selector) { int ret; struct tps65217 *tps = rdev_get_drvdata(dev); - unsigned int ldo = rdev_get_id(dev); + unsigned int rid = rdev_get_id(dev); - if (ldo < TPS65217_LDO_2 || ldo > TPS65217_LDO_4) + /* LDO1 implements set_voltage_sel callback */ + if (rid == TPS65217_LDO_1) return -EINVAL; - if (min_uV < tps->info[ldo]->min_uV - || min_uV > tps->info[ldo]->max_uV) + if (rid < TPS65217_DCDC_1 || rid > TPS65217_LDO_4) return -EINVAL; - if (max_uV < tps->info[ldo]->min_uV - || max_uV > tps->info[ldo]->max_uV) + if (min_uV < tps->info[rid]->min_uV + || min_uV > tps->info[rid]->max_uV) return -EINVAL; - ret = tps->info[ldo]->uv_to_vsel(min_uV, selector); + if (max_uV < tps->info[rid]->min_uV + || max_uV > tps->info[rid]->max_uV) + return -EINVAL; + + ret = tps->info[rid]->uv_to_vsel(min_uV, selector); if (ret) return ret; /* Set the voltage based on vsel value and write protect level is 2 */ - return tps65217_set_bits(tps, tps->info[ldo]->set_vout_reg, - tps->info[ldo]->set_vout_mask, - *selector, TPS65217_PROTECT_L2); -} - -static int tps65217_pmic_dcdc_list_voltage(struct regulator_dev *dev, - unsigned selector) -{ - struct tps65217 *tps = rdev_get_drvdata(dev); - unsigned int dcdc = rdev_get_id(dev); - - if (dcdc < TPS65217_DCDC_1 || dcdc > TPS65217_DCDC_3) - return -EINVAL; - - if (selector >= tps->info[dcdc]->table_len) - return -EINVAL; + ret = tps65217_set_bits(tps, tps->info[rid]->set_vout_reg, + tps->info[rid]->set_vout_mask, + *selector, TPS65217_PROTECT_L2); + + /* Set GO bit for DCDCx to initiate voltage transistion */ + switch (rid) { + case TPS65217_DCDC_1 ... TPS65217_DCDC_3: + ret = tps65217_set_bits(tps, TPS65217_REG_DEFSLEW, + TPS65217_DEFSLEW_GO, TPS65217_DEFSLEW_GO, + TPS65217_PROTECT_L2); + break; + } - return tps->info[dcdc]->vsel_to_uv(selector); + return ret; } -static int tps65217_pmic_ldo_list_voltage(struct regulator_dev *dev, +static int tps65217_pmic_list_voltage(struct regulator_dev *dev, unsigned selector) { struct tps65217 *tps = rdev_get_drvdata(dev); - unsigned int ldo = rdev_get_id(dev); + unsigned int rid = rdev_get_id(dev); - if (ldo < TPS65217_LDO_1 || ldo > TPS65217_LDO_4) + if (rid < TPS65217_DCDC_1 || rid > TPS65217_LDO_4) return -EINVAL; - if (selector >= tps->info[ldo]->table_len) + if (selector >= tps->info[rid]->table_len) return -EINVAL; - if (tps->info[ldo]->table) - return tps->info[ldo]->table[selector]; + if (tps->info[rid]->table) + return tps->info[rid]->table[selector]; - return tps->info[ldo]->vsel_to_uv(selector); + return tps->info[rid]->vsel_to_uv(selector); } -/* Operations permitted on DCDCx */ -static struct regulator_ops tps65217_pmic_dcdc_ops = { - .is_enabled = tps65217_pmic_dcdc_is_enabled, - .enable = tps65217_pmic_dcdc_enable, - .disable = tps65217_pmic_dcdc_disable, - .get_voltage_sel = tps65217_pmic_dcdc_get_voltage_sel, - .set_voltage = tps65217_pmic_dcdc_set_voltage, - .list_voltage = tps65217_pmic_dcdc_list_voltage, +/* Operations permitted on DCDCx, LDO2, LDO3 and LDO4 */ +static struct regulator_ops tps65217_pmic_ops = { + .is_enabled = tps65217_pmic_is_enabled, + .enable = tps65217_pmic_enable, + .disable = tps65217_pmic_disable, + .get_voltage_sel = tps65217_pmic_get_voltage_sel, + .set_voltage = tps65217_pmic_set_voltage, + .list_voltage = tps65217_pmic_list_voltage, }; /* Operations permitted on LDO1 */ static struct regulator_ops tps65217_pmic_ldo1_ops = { - .is_enabled = tps65217_pmic_ldo_is_enabled, - .enable = tps65217_pmic_ldo_enable, - .disable = tps65217_pmic_ldo_disable, - .get_voltage_sel = tps65217_pmic_ldo_get_voltage_sel, - .set_voltage_sel = tps65217_pmic_ldo_set_voltage_sel, - .list_voltage = tps65217_pmic_ldo_list_voltage, -}; - -/* Operations permitted on LDO2, LDO3 and LDO4 */ -static struct regulator_ops tps65217_pmic_ldo234_ops = { - .is_enabled = tps65217_pmic_ldo_is_enabled, - .enable = tps65217_pmic_ldo_enable, - .disable = tps65217_pmic_ldo_disable, - .get_voltage_sel = tps65217_pmic_ldo_get_voltage_sel, - .set_voltage = tps65217_pmic_ldo_set_voltage, - .list_voltage = tps65217_pmic_ldo_list_voltage, + .is_enabled = tps65217_pmic_is_enabled, + .enable = tps65217_pmic_enable, + .disable = tps65217_pmic_disable, + .get_voltage_sel = tps65217_pmic_get_voltage_sel, + .set_voltage_sel = tps65217_pmic_ldo1_set_voltage_sel, + .list_voltage = tps65217_pmic_list_voltage, }; static struct regulator_desc regulators[] = { - TPS65217_REGULATOR("DCDC1", TPS65217_DCDC_1, - tps65217_pmic_dcdc_ops, 64), - TPS65217_REGULATOR("DCDC2",TPS65217_DCDC_2, - tps65217_pmic_dcdc_ops, 64), - TPS65217_REGULATOR("DCDC3", TPS65217_DCDC_3, - tps65217_pmic_dcdc_ops, 64), - TPS65217_REGULATOR("LDO1", TPS65217_LDO_1, - tps65217_pmic_ldo1_ops, 16), - TPS65217_REGULATOR("LDO2", TPS65217_LDO_2, - tps65217_pmic_ldo234_ops, 64), - TPS65217_REGULATOR("LDO3", TPS65217_LDO_3, - tps65217_pmic_ldo234_ops, 32), - TPS65217_REGULATOR("LDO4", TPS65217_LDO_4, - tps65217_pmic_ldo234_ops, 32), + TPS65217_REGULATOR("DCDC1", TPS65217_DCDC_1, tps65217_pmic_ops, 64), + TPS65217_REGULATOR("DCDC2", TPS65217_DCDC_2, tps65217_pmic_ops, 64), + TPS65217_REGULATOR("DCDC3", TPS65217_DCDC_3, tps65217_pmic_ops, 64), + TPS65217_REGULATOR("LDO1", TPS65217_LDO_1, tps65217_pmic_ldo1_ops, 16), + TPS65217_REGULATOR("LDO2", TPS65217_LDO_2, tps65217_pmic_ops, 64), + TPS65217_REGULATOR("LDO3", TPS65217_LDO_3, tps65217_pmic_ops, 32), + TPS65217_REGULATOR("LDO4", TPS65217_LDO_4, tps65217_pmic_ops, 32), }; static int __devinit tps65217_regulator_probe(struct platform_device *pdev) @@ -486,7 +372,6 @@ static void __exit tps65217_regulator_exit(void) } module_exit(tps65217_regulator_exit); - MODULE_AUTHOR("AnilKumar Ch "); MODULE_DESCRIPTION("TPS65217 voltage regulator driver"); MODULE_ALIAS("platform:tps65217-pmic"); -- cgit v0.10.2 From 585993932ccc44ab6a8c6dc590a2f3d6b2facb41 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Tue, 13 Mar 2012 07:15:27 +0800 Subject: regulator: Fix the logic of tps65910_get_mode We actually clear LDO_ST_ON_BIT for standby mode in tps65910_set_mode. Fix the logic in tps65910_get_mode. Supply state (EEPROM bits): ST[1:0] = 00 : Off ST[1:0] = 01 : On high power (ACTIVE) ST[1:0] = 10 : Off ST[1:0] = 11 : On low power (SLEEP) Signed-off-by: Axel Lin Acked-by: Laxman Dewangan Signed-off-by: Mark Brown diff --git a/drivers/regulator/tps65910-regulator.c b/drivers/regulator/tps65910-regulator.c index 4ac0058..aa11ce8 100644 --- a/drivers/regulator/tps65910-regulator.c +++ b/drivers/regulator/tps65910-regulator.c @@ -520,7 +520,7 @@ static unsigned int tps65910_get_mode(struct regulator_dev *dev) if (value < 0) return value; - if (value & LDO_ST_ON_BIT) + if (!(value & LDO_ST_ON_BIT)) return REGULATOR_MODE_STANDBY; else if (value & LDO_ST_MODE_BIT) return REGULATOR_MODE_IDLE; -- cgit v0.10.2 From 42b5efe4f9aa40b3b0a20149fd7357d9d6c96959 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Tue, 13 Mar 2012 06:40:48 +0800 Subject: regulator: tps65912: Use simple equations to get register address The address of ctrl and sel registers can be calculated by simple equations. This patch simplifies the implementation in tps65912_get_ctrl_register and implements tps65912_get_sel_register to replace tps65912_get_dcdc_sel_register and tps65912_get_ldo_sel_register. Signed-off-by: Axel Lin Signed-off-by: Mark Brown diff --git a/drivers/regulator/tps65912-regulator.c b/drivers/regulator/tps65912-regulator.c index 3ab1722..ede688b 100644 --- a/drivers/regulator/tps65912-regulator.c +++ b/drivers/regulator/tps65912-regulator.c @@ -201,146 +201,30 @@ static unsigned long tps65912_vsel_to_uv_ldo(u8 vsel) static int tps65912_get_ctrl_register(int id) { - switch (id) { - case TPS65912_REG_DCDC1: - return TPS65912_DCDC1_AVS; - case TPS65912_REG_DCDC2: - return TPS65912_DCDC2_AVS; - case TPS65912_REG_DCDC3: - return TPS65912_DCDC3_AVS; - case TPS65912_REG_DCDC4: - return TPS65912_DCDC4_AVS; - case TPS65912_REG_LDO1: - return TPS65912_LDO1_AVS; - case TPS65912_REG_LDO2: - return TPS65912_LDO2_AVS; - case TPS65912_REG_LDO3: - return TPS65912_LDO3_AVS; - case TPS65912_REG_LDO4: - return TPS65912_LDO4_AVS; - case TPS65912_REG_LDO5: - return TPS65912_LDO5; - case TPS65912_REG_LDO6: - return TPS65912_LDO6; - case TPS65912_REG_LDO7: - return TPS65912_LDO7; - case TPS65912_REG_LDO8: - return TPS65912_LDO8; - case TPS65912_REG_LDO9: - return TPS65912_LDO9; - case TPS65912_REG_LDO10: - return TPS65912_LDO10; - default: + if (id >= TPS65912_REG_DCDC1 && id <= TPS65912_REG_LDO4) + return id * 3 + TPS65912_DCDC1_AVS; + else if (id >= TPS65912_REG_LDO5 && id <= TPS65912_REG_LDO10) + return id - TPS65912_REG_LDO5 + TPS65912_LDO5; + else return -EINVAL; - } } -static int tps65912_get_dcdc_sel_register(struct tps65912_reg *pmic, int id) +static int tps65912_get_sel_register(struct tps65912_reg *pmic, int id) { struct tps65912 *mfd = pmic->mfd; - int opvsel = 0, sr = 0; + int opvsel; u8 reg = 0; - if (id < TPS65912_REG_DCDC1 || id > TPS65912_REG_DCDC4) - return -EINVAL; - - switch (id) { - case TPS65912_REG_DCDC1: - opvsel = tps65912_reg_read(mfd, TPS65912_DCDC1_OP); - sr = ((opvsel & OP_SELREG_MASK) >> OP_SELREG_SHIFT); - if (sr) - reg = TPS65912_DCDC1_AVS; + if (id >= TPS65912_REG_DCDC1 && id <= TPS65912_REG_LDO4) { + opvsel = tps65912_reg_read(mfd, id * 3 + TPS65912_DCDC1_OP); + if (opvsel & OP_SELREG_MASK) + reg = id * 3 + TPS65912_DCDC1_AVS; else - reg = TPS65912_DCDC1_OP; - break; - case TPS65912_REG_DCDC2: - opvsel = tps65912_reg_read(mfd, TPS65912_DCDC2_OP); - sr = (opvsel & OP_SELREG_MASK) >> OP_SELREG_SHIFT; - if (sr) - reg = TPS65912_DCDC2_AVS; - else - reg = TPS65912_DCDC2_OP; - break; - case TPS65912_REG_DCDC3: - opvsel = tps65912_reg_read(mfd, TPS65912_DCDC3_OP); - sr = (opvsel & OP_SELREG_MASK) >> OP_SELREG_SHIFT; - if (sr) - reg = TPS65912_DCDC3_AVS; - else - reg = TPS65912_DCDC3_OP; - break; - case TPS65912_REG_DCDC4: - opvsel = tps65912_reg_read(mfd, TPS65912_DCDC4_OP); - sr = (opvsel & OP_SELREG_MASK) >> OP_SELREG_SHIFT; - if (sr) - reg = TPS65912_DCDC4_AVS; - else - reg = TPS65912_DCDC4_OP; - break; - } - return reg; -} - -static int tps65912_get_ldo_sel_register(struct tps65912_reg *pmic, int id) -{ - struct tps65912 *mfd = pmic->mfd; - int opvsel = 0, sr = 0; - u8 reg = 0; - - if (id < TPS65912_REG_LDO1 || id > TPS65912_REG_LDO10) + reg = id * 3 + TPS65912_DCDC1_OP; + } else if (id >= TPS65912_REG_LDO5 && id <= TPS65912_REG_LDO10) { + reg = id - TPS65912_REG_LDO5 + TPS65912_LDO5; + } else { return -EINVAL; - - switch (id) { - case TPS65912_REG_LDO1: - opvsel = tps65912_reg_read(mfd, TPS65912_LDO1_OP); - sr = (opvsel & OP_SELREG_MASK) >> OP_SELREG_SHIFT; - if (sr) - reg = TPS65912_LDO1_AVS; - else - reg = TPS65912_LDO1_OP; - break; - case TPS65912_REG_LDO2: - opvsel = tps65912_reg_read(mfd, TPS65912_LDO2_OP); - sr = (opvsel & OP_SELREG_MASK) >> OP_SELREG_SHIFT; - if (sr) - reg = TPS65912_LDO2_AVS; - else - reg = TPS65912_LDO2_OP; - break; - case TPS65912_REG_LDO3: - opvsel = tps65912_reg_read(mfd, TPS65912_LDO3_OP); - sr = (opvsel & OP_SELREG_MASK) >> OP_SELREG_SHIFT; - if (sr) - reg = TPS65912_LDO3_AVS; - else - reg = TPS65912_LDO3_OP; - break; - case TPS65912_REG_LDO4: - opvsel = tps65912_reg_read(mfd, TPS65912_LDO4_OP); - sr = (opvsel & OP_SELREG_MASK) >> OP_SELREG_SHIFT; - if (sr) - reg = TPS65912_LDO4_AVS; - else - reg = TPS65912_LDO4_OP; - break; - case TPS65912_REG_LDO5: - reg = TPS65912_LDO5; - break; - case TPS65912_REG_LDO6: - reg = TPS65912_LDO6; - break; - case TPS65912_REG_LDO7: - reg = TPS65912_LDO7; - break; - case TPS65912_REG_LDO8: - reg = TPS65912_LDO8; - break; - case TPS65912_REG_LDO9: - reg = TPS65912_LDO9; - break; - case TPS65912_REG_LDO10: - reg = TPS65912_LDO10; - break; } return reg; @@ -567,7 +451,7 @@ static int tps65912_set_voltage_dcdc_sel(struct regulator_dev *dev, int value; u8 reg; - reg = tps65912_get_dcdc_sel_register(pmic, id); + reg = tps65912_get_sel_register(pmic, id); value = tps65912_reg_read(mfd, reg); value &= 0xC0; return tps65912_reg_write(mfd, reg, selector | value); @@ -581,7 +465,7 @@ static int tps65912_get_voltage_ldo(struct regulator_dev *dev) int vsel = 0; u8 reg; - reg = tps65912_get_ldo_sel_register(pmic, id); + reg = tps65912_get_sel_register(pmic, id); vsel = tps65912_reg_read(mfd, reg); vsel &= 0x3F; @@ -595,7 +479,7 @@ static int tps65912_set_voltage_ldo_sel(struct regulator_dev *dev, struct tps65912 *mfd = pmic->mfd; int id = rdev_get_id(dev), reg, value; - reg = tps65912_get_ldo_sel_register(pmic, id); + reg = tps65912_get_sel_register(pmic, id); value = tps65912_reg_read(mfd, reg); value &= 0xC0; return tps65912_reg_write(mfd, reg, selector | value); @@ -718,22 +602,12 @@ static struct platform_driver tps65912_driver = { .remove = __devexit_p(tps65912_remove), }; -/** - * tps65912_init - * - * Module init function - */ static int __init tps65912_init(void) { return platform_driver_register(&tps65912_driver); } subsys_initcall(tps65912_init); -/** - * tps65912_cleanup - * - * Module exit function - */ static void __exit tps65912_cleanup(void) { platform_driver_unregister(&tps65912_driver); -- cgit v0.10.2 From 5db6d09a2b4663735121dfe4222860424788a93f Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Tue, 13 Mar 2012 16:09:28 +0800 Subject: regulator: max8925: Use DIV_ROUND_UP macro Use DIV_ROUND_UP macro for better readability. Signed-off-by: Axel Lin Signed-off-by: Mark Brown diff --git a/drivers/regulator/max8925-regulator.c b/drivers/regulator/max8925-regulator.c index cc290d3..2f242f4 100644 --- a/drivers/regulator/max8925-regulator.c +++ b/drivers/regulator/max8925-regulator.c @@ -73,7 +73,7 @@ static int max8925_set_voltage(struct regulator_dev *rdev, min_uV, max_uV); return -EINVAL; } - data = (min_uV - info->min_uV + info->step_uV - 1) / info->step_uV; + data = DIV_ROUND_UP(min_uV - info->min_uV, info->step_uV); *selector = data; data <<= info->vol_shift; mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; @@ -140,7 +140,7 @@ static int max8925_set_dvm_voltage(struct regulator_dev *rdev, int uV) if (uV < SD1_DVM_VMIN || uV > SD1_DVM_VMAX) return -EINVAL; - data = (uV - SD1_DVM_VMIN + SD1_DVM_STEP - 1) / SD1_DVM_STEP; + data = DIV_ROUND_UP(uV - SD1_DVM_VMIN, SD1_DVM_STEP); data <<= SD1_DVM_SHIFT; mask = 3 << SD1_DVM_SHIFT; -- cgit v0.10.2 From 0651eed5e094a079a0a9fccd80a41cb3e7f2aa99 Mon Sep 17 00:00:00 2001 From: Laxman Dewangan Date: Tue, 13 Mar 2012 11:35:20 +0530 Subject: regulator: tps65910: Provide settling time for enabling rails There is settling time for each rails when it is switched to ON. Implementing enable time for returning proper settling time of regulator rails when it is enabled. Filling the on-time for each rail as per tps65910/tps65911 datasheets. Signed-off-by: Laxman Dewangan Signed-off-by: Mark Brown diff --git a/drivers/regulator/tps65910-regulator.c b/drivers/regulator/tps65910-regulator.c index aa11ce8..f28f41a 100644 --- a/drivers/regulator/tps65910-regulator.c +++ b/drivers/regulator/tps65910-regulator.c @@ -89,11 +89,13 @@ struct tps_info { unsigned max_uV; u8 n_voltages; const u16 *voltage_table; + int enable_time_us; }; static struct tps_info tps65910_regs[] = { { .name = "VRTC", + .enable_time_us = 2200, }, { .name = "VIO", @@ -101,16 +103,19 @@ static struct tps_info tps65910_regs[] = { .max_uV = 3300000, .n_voltages = ARRAY_SIZE(VIO_VSEL_table), .voltage_table = VIO_VSEL_table, + .enable_time_us = 350, }, { .name = "VDD1", .min_uV = 600000, .max_uV = 4500000, + .enable_time_us = 350, }, { .name = "VDD2", .min_uV = 600000, .max_uV = 4500000, + .enable_time_us = 350, }, { .name = "VDD3", @@ -118,6 +123,7 @@ static struct tps_info tps65910_regs[] = { .max_uV = 5000000, .n_voltages = ARRAY_SIZE(VDD3_VSEL_table), .voltage_table = VDD3_VSEL_table, + .enable_time_us = 200, }, { .name = "VDIG1", @@ -125,6 +131,7 @@ static struct tps_info tps65910_regs[] = { .max_uV = 2700000, .n_voltages = ARRAY_SIZE(VDIG1_VSEL_table), .voltage_table = VDIG1_VSEL_table, + .enable_time_us = 100, }, { .name = "VDIG2", @@ -132,6 +139,7 @@ static struct tps_info tps65910_regs[] = { .max_uV = 1800000, .n_voltages = ARRAY_SIZE(VDIG2_VSEL_table), .voltage_table = VDIG2_VSEL_table, + .enable_time_us = 100, }, { .name = "VPLL", @@ -139,6 +147,7 @@ static struct tps_info tps65910_regs[] = { .max_uV = 2500000, .n_voltages = ARRAY_SIZE(VPLL_VSEL_table), .voltage_table = VPLL_VSEL_table, + .enable_time_us = 100, }, { .name = "VDAC", @@ -146,6 +155,7 @@ static struct tps_info tps65910_regs[] = { .max_uV = 2850000, .n_voltages = ARRAY_SIZE(VDAC_VSEL_table), .voltage_table = VDAC_VSEL_table, + .enable_time_us = 100, }, { .name = "VAUX1", @@ -153,6 +163,7 @@ static struct tps_info tps65910_regs[] = { .max_uV = 2850000, .n_voltages = ARRAY_SIZE(VAUX1_VSEL_table), .voltage_table = VAUX1_VSEL_table, + .enable_time_us = 100, }, { .name = "VAUX2", @@ -160,6 +171,7 @@ static struct tps_info tps65910_regs[] = { .max_uV = 3300000, .n_voltages = ARRAY_SIZE(VAUX2_VSEL_table), .voltage_table = VAUX2_VSEL_table, + .enable_time_us = 100, }, { .name = "VAUX33", @@ -167,6 +179,7 @@ static struct tps_info tps65910_regs[] = { .max_uV = 3300000, .n_voltages = ARRAY_SIZE(VAUX33_VSEL_table), .voltage_table = VAUX33_VSEL_table, + .enable_time_us = 100, }, { .name = "VMMC", @@ -174,12 +187,14 @@ static struct tps_info tps65910_regs[] = { .max_uV = 3300000, .n_voltages = ARRAY_SIZE(VMMC_VSEL_table), .voltage_table = VMMC_VSEL_table, + .enable_time_us = 100, }, }; static struct tps_info tps65911_regs[] = { { .name = "VRTC", + .enable_time_us = 2200, }, { .name = "VIO", @@ -187,72 +202,84 @@ static struct tps_info tps65911_regs[] = { .max_uV = 3300000, .n_voltages = ARRAY_SIZE(VIO_VSEL_table), .voltage_table = VIO_VSEL_table, + .enable_time_us = 350, }, { .name = "VDD1", .min_uV = 600000, .max_uV = 4500000, .n_voltages = 73, + .enable_time_us = 350, }, { .name = "VDD2", .min_uV = 600000, .max_uV = 4500000, .n_voltages = 73, + .enable_time_us = 350, }, { .name = "VDDCTRL", .min_uV = 600000, .max_uV = 1400000, .n_voltages = 65, + .enable_time_us = 900, }, { .name = "LDO1", .min_uV = 1000000, .max_uV = 3300000, .n_voltages = 47, + .enable_time_us = 420, }, { .name = "LDO2", .min_uV = 1000000, .max_uV = 3300000, .n_voltages = 47, + .enable_time_us = 420, }, { .name = "LDO3", .min_uV = 1000000, .max_uV = 3300000, .n_voltages = 24, + .enable_time_us = 230, }, { .name = "LDO4", .min_uV = 1000000, .max_uV = 3300000, .n_voltages = 47, + .enable_time_us = 230, }, { .name = "LDO5", .min_uV = 1000000, .max_uV = 3300000, .n_voltages = 24, + .enable_time_us = 230, }, { .name = "LDO6", .min_uV = 1000000, .max_uV = 3300000, .n_voltages = 24, + .enable_time_us = 230, }, { .name = "LDO7", .min_uV = 1000000, .max_uV = 3300000, .n_voltages = 24, + .enable_time_us = 230, }, { .name = "LDO8", .min_uV = 1000000, .max_uV = 3300000, .n_voltages = 24, + .enable_time_us = 230, }, }; @@ -482,6 +509,12 @@ static int tps65910_disable(struct regulator_dev *dev) return tps65910_clear_bits(mfd, reg, TPS65910_SUPPLY_STATE_ENABLED); } +static int tps65910_enable_time(struct regulator_dev *dev) +{ + struct tps65910_reg *pmic = rdev_get_drvdata(dev); + int id = rdev_get_id(dev); + return pmic->info[id]->enable_time_us; +} static int tps65910_set_mode(struct regulator_dev *dev, unsigned int mode) { @@ -866,6 +899,7 @@ static struct regulator_ops tps65910_ops_dcdc = { .is_enabled = tps65910_is_enabled, .enable = tps65910_enable, .disable = tps65910_disable, + .enable_time = tps65910_enable_time, .set_mode = tps65910_set_mode, .get_mode = tps65910_get_mode, .get_voltage = tps65910_get_voltage_dcdc, @@ -877,6 +911,7 @@ static struct regulator_ops tps65910_ops_vdd3 = { .is_enabled = tps65910_is_enabled, .enable = tps65910_enable, .disable = tps65910_disable, + .enable_time = tps65910_enable_time, .set_mode = tps65910_set_mode, .get_mode = tps65910_get_mode, .get_voltage = tps65910_get_voltage_vdd3, @@ -887,6 +922,7 @@ static struct regulator_ops tps65910_ops = { .is_enabled = tps65910_is_enabled, .enable = tps65910_enable, .disable = tps65910_disable, + .enable_time = tps65910_enable_time, .set_mode = tps65910_set_mode, .get_mode = tps65910_get_mode, .get_voltage = tps65910_get_voltage, @@ -898,6 +934,7 @@ static struct regulator_ops tps65911_ops = { .is_enabled = tps65910_is_enabled, .enable = tps65910_enable, .disable = tps65910_disable, + .enable_time = tps65910_enable_time, .set_mode = tps65910_set_mode, .get_mode = tps65910_get_mode, .get_voltage = tps65911_get_voltage, -- cgit v0.10.2 From 831c986f5dfc9f29f5237697029f7faf24521413 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Wed, 14 Mar 2012 10:18:45 +0800 Subject: regulator: Use tps65912_set_voltage_sel for both DCDCx and LDOx commit 42b5ef "regulator: tps65912: Use simple equations to get register address" uses tps65912_get_sel_register to replace tps65912_get_dcdc_sel_register and tps65912_get_ldo_sel_register. Now tps65912_set_voltage_dcdc_sel and tps65912_set_voltage_ldo_sel has exactly the same implementation. Merge them to tps65912_set_voltage_sel function. Signed-off-by: Axel Lin Signed-off-by: Mark Brown diff --git a/drivers/regulator/tps65912-regulator.c b/drivers/regulator/tps65912-regulator.c index ede688b..988d0ec 100644 --- a/drivers/regulator/tps65912-regulator.c +++ b/drivers/regulator/tps65912-regulator.c @@ -442,7 +442,7 @@ static int tps65912_get_voltage_dcdc(struct regulator_dev *dev) return tps65912_list_voltage_dcdc(dev, vsel); } -static int tps65912_set_voltage_dcdc_sel(struct regulator_dev *dev, +static int tps65912_set_voltage_sel(struct regulator_dev *dev, unsigned selector) { struct tps65912_reg *pmic = rdev_get_drvdata(dev); @@ -472,19 +472,6 @@ static int tps65912_get_voltage_ldo(struct regulator_dev *dev) return tps65912_vsel_to_uv_ldo(vsel); } -static int tps65912_set_voltage_ldo_sel(struct regulator_dev *dev, - unsigned selector) -{ - struct tps65912_reg *pmic = rdev_get_drvdata(dev); - struct tps65912 *mfd = pmic->mfd; - int id = rdev_get_id(dev), reg, value; - - reg = tps65912_get_sel_register(pmic, id); - value = tps65912_reg_read(mfd, reg); - value &= 0xC0; - return tps65912_reg_write(mfd, reg, selector | value); -} - static int tps65912_list_voltage_ldo(struct regulator_dev *dev, unsigned selector) { @@ -504,7 +491,7 @@ static struct regulator_ops tps65912_ops_dcdc = { .set_mode = tps65912_set_mode, .get_mode = tps65912_get_mode, .get_voltage = tps65912_get_voltage_dcdc, - .set_voltage_sel = tps65912_set_voltage_dcdc_sel, + .set_voltage_sel = tps65912_set_voltage_sel, .list_voltage = tps65912_list_voltage_dcdc, }; @@ -514,7 +501,7 @@ static struct regulator_ops tps65912_ops_ldo = { .enable = tps65912_reg_enable, .disable = tps65912_reg_disable, .get_voltage = tps65912_get_voltage_ldo, - .set_voltage_sel = tps65912_set_voltage_ldo_sel, + .set_voltage_sel = tps65912_set_voltage_sel, .list_voltage = tps65912_list_voltage_ldo, }; -- cgit v0.10.2 From c567556e75534316f1ae800b0a0fbbc687d0662e Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Wed, 14 Mar 2012 10:20:01 +0800 Subject: regulator: Simplify implementation of tps65912_get_voltage_dcdc Call tps65912_get_sel_register instead of duplicating the same code. Signed-off-by: Axel Lin Signed-off-by: Mark Brown diff --git a/drivers/regulator/tps65912-regulator.c b/drivers/regulator/tps65912-regulator.c index 988d0ec..b36799b 100644 --- a/drivers/regulator/tps65912-regulator.c +++ b/drivers/regulator/tps65912-regulator.c @@ -409,34 +409,13 @@ static int tps65912_get_voltage_dcdc(struct regulator_dev *dev) struct tps65912_reg *pmic = rdev_get_drvdata(dev); struct tps65912 *mfd = pmic->mfd; int id = rdev_get_id(dev); - int opvsel = 0, avsel = 0, sr, vsel; + int reg, vsel; - switch (id) { - case TPS65912_REG_DCDC1: - opvsel = tps65912_reg_read(mfd, TPS65912_DCDC1_OP); - avsel = tps65912_reg_read(mfd, TPS65912_DCDC1_AVS); - break; - case TPS65912_REG_DCDC2: - opvsel = tps65912_reg_read(mfd, TPS65912_DCDC2_OP); - avsel = tps65912_reg_read(mfd, TPS65912_DCDC2_AVS); - break; - case TPS65912_REG_DCDC3: - opvsel = tps65912_reg_read(mfd, TPS65912_DCDC3_OP); - avsel = tps65912_reg_read(mfd, TPS65912_DCDC3_AVS); - break; - case TPS65912_REG_DCDC4: - opvsel = tps65912_reg_read(mfd, TPS65912_DCDC4_OP); - avsel = tps65912_reg_read(mfd, TPS65912_DCDC4_AVS); - break; - default: - return -EINVAL; - } + reg = tps65912_get_sel_register(pmic, id); + if (reg < 0) + return reg; - sr = (opvsel & OP_SELREG_MASK) >> OP_SELREG_SHIFT; - if (sr) - vsel = avsel; - else - vsel = opvsel; + vsel = tps65912_reg_read(mfd, reg); vsel &= 0x3F; return tps65912_list_voltage_dcdc(dev, vsel); -- cgit v0.10.2 From e3e5aff714c0da06201576304f1b41dcdd142ef4 Mon Sep 17 00:00:00 2001 From: "Ying-Chun Liu (PaulLiu)" Date: Wed, 14 Mar 2012 10:29:12 +0800 Subject: regulator: Add Anatop regulator driver Anatop is an integrated regulator inside i.MX6 SoC. There are 3 digital regulators which controls PU, CORE (ARM), and SOC. And 3 analog regulators which controls 1P1, 2P5, 3P0 (USB). This patch adds the Anatop regulator driver. Signed-off-by: Nancy Chen Signed-off-by: Ying-Chun Liu (PaulLiu) Acked-by: Shawn Guo Reviewed-by: Axel Lin Signed-off-by: Mark Brown diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig index c733df5..a229de9 100644 --- a/drivers/regulator/Kconfig +++ b/drivers/regulator/Kconfig @@ -102,6 +102,14 @@ config REGULATOR_DA9052 This driver supports the voltage regulators of DA9052-BC and DA9053-AA/Bx PMIC. +config REGULATOR_ANATOP + tristate "Freescale i.MX on-chip ANATOP LDO regulators" + depends on MFD_ANATOP + help + Say y here to support Freescale i.MX on-chip ANATOP LDOs + regulators. It is recommended that this option be + enabled on i.MX6 platform. + config REGULATOR_MC13XXX_CORE tristate diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile index cf0934b..ab06474e 100644 --- a/drivers/regulator/Makefile +++ b/drivers/regulator/Makefile @@ -15,6 +15,7 @@ obj-$(CONFIG_REGULATOR_AAT2870) += aat2870-regulator.o obj-$(CONFIG_REGULATOR_AB3100) += ab3100.o obj-$(CONFIG_REGULATOR_AB8500) += ab8500.o obj-$(CONFIG_REGULATOR_AD5398) += ad5398.o +obj-$(CONFIG_REGULATOR_ANATOP) += anatop-regulator.o obj-$(CONFIG_REGULATOR_BQ24022) += bq24022.o obj-$(CONFIG_REGULATOR_DA903X) += da903x.o obj-$(CONFIG_REGULATOR_DA9052) += da9052-regulator.o diff --git a/drivers/regulator/anatop-regulator.c b/drivers/regulator/anatop-regulator.c new file mode 100644 index 0000000..17499a5 --- /dev/null +++ b/drivers/regulator/anatop-regulator.c @@ -0,0 +1,241 @@ +/* + * Copyright (C) 2011 Freescale Semiconductor, Inc. All Rights Reserved. + */ + +/* + * 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. + + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct anatop_regulator { + const char *name; + u32 control_reg; + struct anatop *mfd; + int vol_bit_shift; + int vol_bit_width; + int min_bit_val; + int min_voltage; + int max_voltage; + struct regulator_desc rdesc; + struct regulator_init_data *initdata; +}; + +static int anatop_set_voltage(struct regulator_dev *reg, int min_uV, + int max_uV, unsigned *selector) +{ + struct anatop_regulator *anatop_reg = rdev_get_drvdata(reg); + u32 val, sel; + int uv; + + uv = min_uV; + dev_dbg(®->dev, "%s: uv %d, min %d, max %d\n", __func__, + uv, anatop_reg->min_voltage, + anatop_reg->max_voltage); + + if (uv < anatop_reg->min_voltage) { + if (max_uV > anatop_reg->min_voltage) + uv = anatop_reg->min_voltage; + else + return -EINVAL; + } + + if (!anatop_reg->control_reg) + return -ENOTSUPP; + + sel = DIV_ROUND_UP(uv - anatop_reg->min_voltage, 25000); + if (sel * 25000 + anatop_reg->min_voltage > anatop_reg->max_voltage) + return -EINVAL; + val = anatop_reg->min_bit_val + sel; + *selector = sel; + dev_dbg(®->dev, "%s: calculated val %d\n", __func__, val); + anatop_set_bits(anatop_reg->mfd, + anatop_reg->control_reg, + anatop_reg->vol_bit_shift, + anatop_reg->vol_bit_width, + val); + + return 0; +} + +static int anatop_get_voltage_sel(struct regulator_dev *reg) +{ + struct anatop_regulator *anatop_reg = rdev_get_drvdata(reg); + u32 val; + + if (!anatop_reg->control_reg) + return -ENOTSUPP; + + val = anatop_get_bits(anatop_reg->mfd, + anatop_reg->control_reg, + anatop_reg->vol_bit_shift, + anatop_reg->vol_bit_width); + + return val - anatop_reg->min_bit_val; +} + +static int anatop_list_voltage(struct regulator_dev *reg, unsigned selector) +{ + struct anatop_regulator *anatop_reg = rdev_get_drvdata(reg); + int uv; + + uv = anatop_reg->min_voltage + selector * 25000; + dev_dbg(®->dev, "vddio = %d, selector = %u\n", uv, selector); + + return uv; +} + +static struct regulator_ops anatop_rops = { + .set_voltage = anatop_set_voltage, + .get_voltage_sel = anatop_get_voltage_sel, + .list_voltage = anatop_list_voltage, +}; + +static int __devinit anatop_regulator_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct device_node *np = dev->of_node; + struct regulator_desc *rdesc; + struct regulator_dev *rdev; + struct anatop_regulator *sreg; + struct regulator_init_data *initdata; + struct anatop *anatopmfd = dev_get_drvdata(pdev->dev.parent); + int ret = 0; + + initdata = of_get_regulator_init_data(dev, np); + sreg = devm_kzalloc(dev, sizeof(*sreg), GFP_KERNEL); + if (!sreg) + return -ENOMEM; + sreg->initdata = initdata; + sreg->name = kstrdup(of_get_property(np, "regulator-name", NULL), + GFP_KERNEL); + rdesc = &sreg->rdesc; + memset(rdesc, 0, sizeof(*rdesc)); + rdesc->name = sreg->name; + rdesc->ops = &anatop_rops; + rdesc->type = REGULATOR_VOLTAGE; + rdesc->owner = THIS_MODULE; + sreg->mfd = anatopmfd; + ret = of_property_read_u32(np, "reg", &sreg->control_reg); + if (ret) { + dev_err(dev, "no reg property set\n"); + goto anatop_probe_end; + } + 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; + } + 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; + } + 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; + } + 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; + } + 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; + } + + rdesc->n_voltages = (sreg->max_voltage - sreg->min_voltage) + / 25000 + 1; + + /* register regulator */ + rdev = regulator_register(rdesc, dev, + initdata, sreg, pdev->dev.of_node); + if (IS_ERR(rdev)) { + dev_err(dev, "failed to register %s\n", + rdesc->name); + ret = PTR_ERR(rdev); + goto anatop_probe_end; + } + + platform_set_drvdata(pdev, rdev); + +anatop_probe_end: + if (ret) + kfree(sreg->name); + + return ret; +} + +static int __devexit 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; + + regulator_unregister(rdev); + kfree(name); + + return 0; +} + +static struct of_device_id __devinitdata of_anatop_regulator_match_tbl[] = { + { .compatible = "fsl,anatop-regulator", }, + { /* end */ } +}; + +static struct platform_driver anatop_regulator = { + .driver = { + .name = "anatop_regulator", + .owner = THIS_MODULE, + .of_match_table = of_anatop_regulator_match_tbl, + }, + .probe = anatop_regulator_probe, + .remove = anatop_regulator_remove, +}; + +static int __init anatop_regulator_init(void) +{ + return platform_driver_register(&anatop_regulator); +} +postcore_initcall(anatop_regulator_init); + +static void __exit anatop_regulator_exit(void) +{ + platform_driver_unregister(&anatop_regulator); +} +module_exit(anatop_regulator_exit); + +MODULE_AUTHOR("Nancy Chen , " + "Ying-Chun Liu (PaulLiu) "); +MODULE_DESCRIPTION("ANATOP Regulator driver"); +MODULE_LICENSE("GPL v2"); -- cgit v0.10.2 From 18039e0f16d50c8243fe0388a587c25a3b155ece Mon Sep 17 00:00:00 2001 From: Laxman Dewangan Date: Wed, 14 Mar 2012 13:00:58 +0530 Subject: regulator: tps65910: Provide settling time for DCDC voltage change Settling time is require when there is dcdc rail's voltage change. Returning proper delay time for dcdc voltage change to settle down the output voltage to new value. Signed-off-by: Laxman Dewangan Signed-off-by: Mark Brown diff --git a/drivers/regulator/tps65910-regulator.c b/drivers/regulator/tps65910-regulator.c index f28f41a..3d1370f 100644 --- a/drivers/regulator/tps65910-regulator.c +++ b/drivers/regulator/tps65910-regulator.c @@ -561,10 +561,10 @@ static unsigned int tps65910_get_mode(struct regulator_dev *dev) return REGULATOR_MODE_NORMAL; } -static int tps65910_get_voltage_dcdc(struct regulator_dev *dev) +static int tps65910_get_voltage_dcdc_sel(struct regulator_dev *dev) { struct tps65910_reg *pmic = rdev_get_drvdata(dev); - int id = rdev_get_id(dev), voltage = 0; + int id = rdev_get_id(dev); int opvsel = 0, srvsel = 0, vselmax = 0, mult = 0, sr = 0; switch (id) { @@ -608,9 +608,7 @@ static int tps65910_get_voltage_dcdc(struct regulator_dev *dev) srvsel = 3; if (srvsel > vselmax) srvsel = vselmax; - srvsel -= 3; - - voltage = (srvsel * VDD1_2_OFFSET + VDD1_2_MIN_VOLT) * 100; + return srvsel - 3; } else { /* normalise to valid range*/ @@ -618,14 +616,9 @@ static int tps65910_get_voltage_dcdc(struct regulator_dev *dev) opvsel = 3; if (opvsel > vselmax) opvsel = vselmax; - opvsel -= 3; - - voltage = (opvsel * VDD1_2_OFFSET + VDD1_2_MIN_VOLT) * 100; + return opvsel - 3; } - - voltage *= mult; - - return voltage; + return -EINVAL; } static int tps65910_get_voltage(struct regulator_dev *dev) @@ -894,6 +887,31 @@ static int tps65911_list_voltage(struct regulator_dev *dev, unsigned selector) return (LDO_MIN_VOLT + selector * step_mv) * 1000; } +static int tps65910_set_voltage_dcdc_time_sel(struct regulator_dev *dev, + unsigned int old_selector, unsigned int new_selector) +{ + int id = rdev_get_id(dev); + int old_volt, new_volt; + + old_volt = tps65910_list_voltage_dcdc(dev, old_selector); + if (old_volt < 0) + return old_volt; + + new_volt = tps65910_list_voltage_dcdc(dev, new_selector); + if (new_volt < 0) + return new_volt; + + /* VDD1 and VDD2 are 12.5mV/us, VDDCTRL is 100mV/20us */ + switch (id) { + case TPS65910_REG_VDD1: + case TPS65910_REG_VDD2: + return DIV_ROUND_UP(abs(old_volt - new_volt), 12500); + case TPS65911_REG_VDDCTRL: + return DIV_ROUND_UP(abs(old_volt - new_volt), 5000); + } + return -EINVAL; +} + /* Regulator ops (except VRTC) */ static struct regulator_ops tps65910_ops_dcdc = { .is_enabled = tps65910_is_enabled, @@ -902,8 +920,9 @@ static struct regulator_ops tps65910_ops_dcdc = { .enable_time = tps65910_enable_time, .set_mode = tps65910_set_mode, .get_mode = tps65910_get_mode, - .get_voltage = tps65910_get_voltage_dcdc, + .get_voltage_sel = tps65910_get_voltage_dcdc_sel, .set_voltage_sel = tps65910_set_voltage_dcdc_sel, + .set_voltage_time_sel = tps65910_set_voltage_dcdc_time_sel, .list_voltage = tps65910_list_voltage_dcdc, }; -- cgit v0.10.2 From 6c4efe2474d233f439540f1fa364d8a7e48c5cdf Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Sat, 10 Mar 2012 08:43:02 +0800 Subject: regulator: s5m8767: Check pdata->buck[2|3|4]_gpiodvs earlier If we need to ensure only one of the buck[2|3|4]_gpiodvs can be specificed, check them earlier. Signed-off-by: Axel Lin Acked-by: Sangbeom Kim Signed-off-by: Mark Brown diff --git a/drivers/regulator/s5m8767.c b/drivers/regulator/s5m8767.c index 9d5d915..611d02d 100644 --- a/drivers/regulator/s5m8767.c +++ b/drivers/regulator/s5m8767.c @@ -547,6 +547,27 @@ static __devinit int s5m8767_pmic_probe(struct platform_device *pdev) return -ENODEV; } + if (pdata->buck2_gpiodvs) { + if (pdata->buck3_gpiodvs || pdata->buck4_gpiodvs) { + dev_err(&pdev->dev, "S5M8767 GPIO DVS NOT VALID\n"); + return -EINVAL; + } + } + + if (pdata->buck3_gpiodvs) { + if (pdata->buck2_gpiodvs || pdata->buck4_gpiodvs) { + dev_err(&pdev->dev, "S5M8767 GPIO DVS NOT VALID\n"); + return -EINVAL; + } + } + + if (pdata->buck4_gpiodvs) { + if (pdata->buck2_gpiodvs || pdata->buck3_gpiodvs) { + dev_err(&pdev->dev, "S5M8767 GPIO DVS NOT VALID\n"); + return -EINVAL; + } + } + s5m8767 = devm_kzalloc(&pdev->dev, sizeof(struct s5m8767_info), GFP_KERNEL); if (!s5m8767) @@ -640,30 +661,6 @@ static __devinit int s5m8767_pmic_probe(struct platform_device *pdev) } } - if (pdata->buck2_gpiodvs) { - if (pdata->buck3_gpiodvs || pdata->buck4_gpiodvs) { - dev_err(&pdev->dev, "S5M8767 GPIO DVS NOT VALID\n"); - ret = -EINVAL; - return ret; - } - } - - if (pdata->buck3_gpiodvs) { - if (pdata->buck2_gpiodvs || pdata->buck4_gpiodvs) { - dev_err(&pdev->dev, "S5M8767 GPIO DVS NOT VALID\n"); - ret = -EINVAL; - return ret; - } - } - - if (pdata->buck4_gpiodvs) { - if (pdata->buck2_gpiodvs || pdata->buck3_gpiodvs) { - dev_err(&pdev->dev, "S5M8767 GPIO DVS NOT VALID\n"); - ret = -EINVAL; - return ret; - } - } - s5m_reg_update(s5m8767->iodev, S5M8767_REG_BUCK2CTRL, (pdata->buck2_gpiodvs) ? (1 << 1) : (0 << 1), 1 << 1); s5m_reg_update(s5m8767->iodev, S5M8767_REG_BUCK3CTRL, -- cgit v0.10.2 From 0a41685fd58f8a4fe097449063764420ebb7ed93 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Sat, 10 Mar 2012 10:59:43 +0800 Subject: regulator: Make s5m8767_get_voltage_register always return correct register Check s5m8767->buck[2|3|4]_gpiodvs status in s5m8767_get_voltage_register and return correct register accordingly. Signed-off-by: Axel Lin Acked-by: Sangbeom Kim Signed-off-by: Mark Brown diff --git a/drivers/regulator/s5m8767.c b/drivers/regulator/s5m8767.c index 611d02d..58447db 100644 --- a/drivers/regulator/s5m8767.c +++ b/drivers/regulator/s5m8767.c @@ -219,6 +219,7 @@ static int s5m8767_reg_disable(struct regulator_dev *rdev) static int s5m8767_get_voltage_register(struct regulator_dev *rdev, int *_reg) { + struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev); int reg_id = rdev_get_id(rdev); int reg; @@ -234,12 +235,18 @@ static int s5m8767_get_voltage_register(struct regulator_dev *rdev, int *_reg) break; case S5M8767_BUCK2: reg = S5M8767_REG_BUCK2DVS1; + if (s5m8767->buck2_gpiodvs) + reg += s5m8767->buck_gpioindex; break; case S5M8767_BUCK3: reg = S5M8767_REG_BUCK3DVS1; + if (s5m8767->buck3_gpiodvs) + reg += s5m8767->buck_gpioindex; break; case S5M8767_BUCK4: reg = S5M8767_REG_BUCK4DVS1; + if (s5m8767->buck4_gpiodvs) + reg += s5m8767->buck_gpioindex; break; case S5M8767_BUCK5: reg = S5M8767_REG_BUCK5CTRL2; @@ -259,7 +266,7 @@ static int s5m8767_get_voltage_register(struct regulator_dev *rdev, int *_reg) static int s5m8767_get_voltage_sel(struct regulator_dev *rdev) { struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev); - int reg, mask = 0xff, ret; + int reg, mask, ret; int reg_id = rdev_get_id(rdev); u8 val; @@ -267,23 +274,7 @@ static int s5m8767_get_voltage_sel(struct regulator_dev *rdev) if (ret) return ret; - switch (reg_id) { - case S5M8767_LDO1 ... S5M8767_LDO28: - mask = 0x3f; - break; - case S5M8767_BUCK2: - if (s5m8767->buck2_gpiodvs) - reg += s5m8767->buck_gpioindex; - break; - case S5M8767_BUCK3: - if (s5m8767->buck3_gpiodvs) - reg += s5m8767->buck_gpioindex; - break; - case S5M8767_BUCK4: - if (s5m8767->buck4_gpiodvs) - reg += s5m8767->buck_gpioindex; - break; - } + mask = (reg_id < S5M8767_BUCK1) ? 0x3f : 0xff; ret = s5m_reg_read(s5m8767->iodev, reg, &val); if (ret) -- cgit v0.10.2 From f2933d333118bff82e4b46fff605e31f799df5ce Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Mon, 12 Mar 2012 15:57:50 +0800 Subject: regulator: Refactor tps6507x to use one tps6507x_pmic_ops for all LDOs and DCDCs All the callback functions implementation for DCDCx and LDOx are very similar, I think it is ok to use one tps6507x_pmic_ops for all LDOs and DCDCs. This refactor removes a couple of duplicated code. Signed-off-by: Axel Lin Signed-off-by: Mark Brown diff --git a/drivers/regulator/tps6507x-regulator.c b/drivers/regulator/tps6507x-regulator.c index 0b63ef7..e140a15 100644 --- a/drivers/regulator/tps6507x-regulator.c +++ b/drivers/regulator/tps6507x-regulator.c @@ -238,16 +238,16 @@ static int tps6507x_pmic_reg_write(struct tps6507x_pmic *tps, u8 reg, u8 val) return err; } -static int tps6507x_pmic_dcdc_is_enabled(struct regulator_dev *dev) +static int tps6507x_pmic_is_enabled(struct regulator_dev *dev) { struct tps6507x_pmic *tps = rdev_get_drvdata(dev); - int data, dcdc = rdev_get_id(dev); + int data, rid = rdev_get_id(dev); u8 shift; - if (dcdc < TPS6507X_DCDC_1 || dcdc > TPS6507X_DCDC_3) + if (rid < TPS6507X_DCDC_1 || rid > TPS6507X_LDO_2) return -EINVAL; - shift = TPS6507X_MAX_REG_ID - dcdc; + shift = TPS6507X_MAX_REG_ID - rid; data = tps6507x_pmic_reg_read(tps, TPS6507X_REG_CON_CTRL1); if (data < 0) @@ -256,99 +256,65 @@ static int tps6507x_pmic_dcdc_is_enabled(struct regulator_dev *dev) return (data & 1< TPS6507X_LDO_2) + if (rid < TPS6507X_DCDC_1 || rid > TPS6507X_LDO_2) return -EINVAL; - shift = TPS6507X_MAX_REG_ID - ldo; - data = tps6507x_pmic_reg_read(tps, TPS6507X_REG_CON_CTRL1); - - if (data < 0) - return data; - else - return (data & 1< TPS6507X_DCDC_3) - return -EINVAL; - - shift = TPS6507X_MAX_REG_ID - dcdc; - return tps6507x_pmic_set_bits(tps, TPS6507X_REG_CON_CTRL1, 1 << shift); -} - -static int tps6507x_pmic_dcdc_disable(struct regulator_dev *dev) -{ - struct tps6507x_pmic *tps = rdev_get_drvdata(dev); - int dcdc = rdev_get_id(dev); - u8 shift; - - if (dcdc < TPS6507X_DCDC_1 || dcdc > TPS6507X_DCDC_3) - return -EINVAL; - - shift = TPS6507X_MAX_REG_ID - dcdc; - return tps6507x_pmic_clear_bits(tps, TPS6507X_REG_CON_CTRL1, - 1 << shift); -} - -static int tps6507x_pmic_ldo_enable(struct regulator_dev *dev) -{ - struct tps6507x_pmic *tps = rdev_get_drvdata(dev); - int ldo = rdev_get_id(dev); - u8 shift; - - if (ldo < TPS6507X_LDO_1 || ldo > TPS6507X_LDO_2) - return -EINVAL; - - shift = TPS6507X_MAX_REG_ID - ldo; + shift = TPS6507X_MAX_REG_ID - rid; return tps6507x_pmic_set_bits(tps, TPS6507X_REG_CON_CTRL1, 1 << shift); } -static int tps6507x_pmic_ldo_disable(struct regulator_dev *dev) +static int tps6507x_pmic_disable(struct regulator_dev *dev) { struct tps6507x_pmic *tps = rdev_get_drvdata(dev); - int ldo = rdev_get_id(dev); + int rid = rdev_get_id(dev); u8 shift; - if (ldo < TPS6507X_LDO_1 || ldo > TPS6507X_LDO_2) + if (rid < TPS6507X_DCDC_1 || rid > TPS6507X_LDO_2) return -EINVAL; - shift = TPS6507X_MAX_REG_ID - ldo; + shift = TPS6507X_MAX_REG_ID - rid; return tps6507x_pmic_clear_bits(tps, TPS6507X_REG_CON_CTRL1, 1 << shift); } -static int tps6507x_pmic_dcdc_get_voltage(struct regulator_dev *dev) +static int tps6507x_pmic_get_voltage(struct regulator_dev *dev) { struct tps6507x_pmic *tps = rdev_get_drvdata(dev); - int data, dcdc = rdev_get_id(dev); - u8 reg; + int data, rid = rdev_get_id(dev); + u8 reg, mask; - switch (dcdc) { + switch (rid) { case TPS6507X_DCDC_1: reg = TPS6507X_REG_DEFDCDC1; + mask = TPS6507X_DEFDCDCX_DCDC_MASK; break; case TPS6507X_DCDC_2: - if (tps->info[dcdc]->defdcdc_default) + if (tps->info[rid]->defdcdc_default) reg = TPS6507X_REG_DEFDCDC2_HIGH; else reg = TPS6507X_REG_DEFDCDC2_LOW; + mask = TPS6507X_DEFDCDCX_DCDC_MASK; break; case TPS6507X_DCDC_3: - if (tps->info[dcdc]->defdcdc_default) + if (tps->info[rid]->defdcdc_default) reg = TPS6507X_REG_DEFDCDC3_HIGH; else reg = TPS6507X_REG_DEFDCDC3_LOW; + mask = TPS6507X_DEFDCDCX_DCDC_MASK; + break; + case TPS6507X_LDO_1: + reg = TPS6507X_REG_LDO_CTRL1; + mask = TPS6507X_REG_LDO_CTRL1_LDO1_MASK; + break; + case TPS6507X_LDO_2: + reg = TPS6507X_REG_DEFLDO2; + mask = TPS6507X_REG_DEFLDO2_LDO2_MASK; break; default: return -EINVAL; @@ -358,47 +324,56 @@ static int tps6507x_pmic_dcdc_get_voltage(struct regulator_dev *dev) if (data < 0) return data; - data &= TPS6507X_DEFDCDCX_DCDC_MASK; - return tps->info[dcdc]->table[data] * 1000; + data &= mask; + return tps->info[rid]->table[data] * 1000; } -static int tps6507x_pmic_dcdc_set_voltage(struct regulator_dev *dev, +static int tps6507x_pmic_set_voltage(struct regulator_dev *dev, int min_uV, int max_uV, unsigned *selector) { struct tps6507x_pmic *tps = rdev_get_drvdata(dev); - int data, vsel, dcdc = rdev_get_id(dev); - u8 reg; + int data, vsel, rid = rdev_get_id(dev); + u8 reg, mask; - switch (dcdc) { + switch (rid) { case TPS6507X_DCDC_1: reg = TPS6507X_REG_DEFDCDC1; + mask = TPS6507X_DEFDCDCX_DCDC_MASK; break; case TPS6507X_DCDC_2: - if (tps->info[dcdc]->defdcdc_default) + if (tps->info[rid]->defdcdc_default) reg = TPS6507X_REG_DEFDCDC2_HIGH; else reg = TPS6507X_REG_DEFDCDC2_LOW; + mask = TPS6507X_DEFDCDCX_DCDC_MASK; break; case TPS6507X_DCDC_3: - if (tps->info[dcdc]->defdcdc_default) + if (tps->info[rid]->defdcdc_default) reg = TPS6507X_REG_DEFDCDC3_HIGH; else reg = TPS6507X_REG_DEFDCDC3_LOW; + mask = TPS6507X_DEFDCDCX_DCDC_MASK; + break; + case TPS6507X_LDO_1: + reg = TPS6507X_REG_LDO_CTRL1; + mask = TPS6507X_REG_LDO_CTRL1_LDO1_MASK; + break; + case TPS6507X_LDO_2: + reg = TPS6507X_REG_DEFLDO2; + mask = TPS6507X_REG_DEFLDO2_LDO2_MASK; break; default: return -EINVAL; } - if (min_uV < tps->info[dcdc]->min_uV - || min_uV > tps->info[dcdc]->max_uV) + if (min_uV < tps->info[rid]->min_uV || min_uV > tps->info[rid]->max_uV) return -EINVAL; - if (max_uV < tps->info[dcdc]->min_uV - || max_uV > tps->info[dcdc]->max_uV) + if (max_uV < tps->info[rid]->min_uV || max_uV > tps->info[rid]->max_uV) return -EINVAL; - for (vsel = 0; vsel < tps->info[dcdc]->table_len; vsel++) { - int mV = tps->info[dcdc]->table[vsel]; + for (vsel = 0; vsel < tps->info[rid]->table_len; vsel++) { + int mV = tps->info[rid]->table[vsel]; int uV = mV * 1000; /* Break at the first in-range value */ @@ -407,78 +382,7 @@ static int tps6507x_pmic_dcdc_set_voltage(struct regulator_dev *dev, } /* write to the register in case we found a match */ - if (vsel == tps->info[dcdc]->table_len) - return -EINVAL; - - *selector = vsel; - - data = tps6507x_pmic_reg_read(tps, reg); - if (data < 0) - return data; - - data &= ~TPS6507X_DEFDCDCX_DCDC_MASK; - data |= vsel; - - return tps6507x_pmic_reg_write(tps, reg, data); -} - -static int tps6507x_pmic_ldo_get_voltage(struct regulator_dev *dev) -{ - struct tps6507x_pmic *tps = rdev_get_drvdata(dev); - int data, ldo = rdev_get_id(dev); - u8 reg, mask; - - if (ldo < TPS6507X_LDO_1 || ldo > TPS6507X_LDO_2) - return -EINVAL; - else { - reg = (ldo == TPS6507X_LDO_1 ? - TPS6507X_REG_LDO_CTRL1 : TPS6507X_REG_DEFLDO2); - mask = (ldo == TPS6507X_LDO_1 ? - TPS6507X_REG_LDO_CTRL1_LDO1_MASK : - TPS6507X_REG_DEFLDO2_LDO2_MASK); - } - - data = tps6507x_pmic_reg_read(tps, reg); - if (data < 0) - return data; - - data &= mask; - return tps->info[ldo]->table[data] * 1000; -} - -static int tps6507x_pmic_ldo_set_voltage(struct regulator_dev *dev, - int min_uV, int max_uV, - unsigned *selector) -{ - struct tps6507x_pmic *tps = rdev_get_drvdata(dev); - int data, vsel, ldo = rdev_get_id(dev); - u8 reg, mask; - - if (ldo < TPS6507X_LDO_1 || ldo > TPS6507X_LDO_2) - return -EINVAL; - else { - reg = (ldo == TPS6507X_LDO_1 ? - TPS6507X_REG_LDO_CTRL1 : TPS6507X_REG_DEFLDO2); - mask = (ldo == TPS6507X_LDO_1 ? - TPS6507X_REG_LDO_CTRL1_LDO1_MASK : - TPS6507X_REG_DEFLDO2_LDO2_MASK); - } - - if (min_uV < tps->info[ldo]->min_uV || min_uV > tps->info[ldo]->max_uV) - return -EINVAL; - if (max_uV < tps->info[ldo]->min_uV || max_uV > tps->info[ldo]->max_uV) - return -EINVAL; - - for (vsel = 0; vsel < tps->info[ldo]->table_len; vsel++) { - int mV = tps->info[ldo]->table[vsel]; - int uV = mV * 1000; - - /* Break at the first in-range value */ - if (min_uV <= uV && uV <= max_uV) - break; - } - - if (vsel == tps->info[ldo]->table_len) + if (vsel == tps->info[rid]->table_len) return -EINVAL; *selector = vsel; @@ -493,58 +397,31 @@ static int tps6507x_pmic_ldo_set_voltage(struct regulator_dev *dev, return tps6507x_pmic_reg_write(tps, reg, data); } -static int tps6507x_pmic_dcdc_list_voltage(struct regulator_dev *dev, +static int tps6507x_pmic_list_voltage(struct regulator_dev *dev, unsigned selector) { struct tps6507x_pmic *tps = rdev_get_drvdata(dev); - int dcdc = rdev_get_id(dev); + int rid = rdev_get_id(dev); - if (dcdc < TPS6507X_DCDC_1 || dcdc > TPS6507X_DCDC_3) + if (rid < TPS6507X_DCDC_1 || rid > TPS6507X_LDO_2) return -EINVAL; - if (selector >= tps->info[dcdc]->table_len) + if (selector >= tps->info[rid]->table_len) return -EINVAL; else - return tps->info[dcdc]->table[selector] * 1000; + return tps->info[rid]->table[selector] * 1000; } -static int tps6507x_pmic_ldo_list_voltage(struct regulator_dev *dev, - unsigned selector) -{ - struct tps6507x_pmic *tps = rdev_get_drvdata(dev); - int ldo = rdev_get_id(dev); - - if (ldo < TPS6507X_LDO_1 || ldo > TPS6507X_LDO_2) - return -EINVAL; - - if (selector >= tps->info[ldo]->table_len) - return -EINVAL; - else - return tps->info[ldo]->table[selector] * 1000; -} - -/* Operations permitted on VDCDCx */ -static struct regulator_ops tps6507x_pmic_dcdc_ops = { - .is_enabled = tps6507x_pmic_dcdc_is_enabled, - .enable = tps6507x_pmic_dcdc_enable, - .disable = tps6507x_pmic_dcdc_disable, - .get_voltage = tps6507x_pmic_dcdc_get_voltage, - .set_voltage = tps6507x_pmic_dcdc_set_voltage, - .list_voltage = tps6507x_pmic_dcdc_list_voltage, +static struct regulator_ops tps6507x_pmic_ops = { + .is_enabled = tps6507x_pmic_is_enabled, + .enable = tps6507x_pmic_enable, + .disable = tps6507x_pmic_disable, + .get_voltage = tps6507x_pmic_get_voltage, + .set_voltage = tps6507x_pmic_set_voltage, + .list_voltage = tps6507x_pmic_list_voltage, }; -/* Operations permitted on LDOx */ -static struct regulator_ops tps6507x_pmic_ldo_ops = { - .is_enabled = tps6507x_pmic_ldo_is_enabled, - .enable = tps6507x_pmic_ldo_enable, - .disable = tps6507x_pmic_ldo_disable, - .get_voltage = tps6507x_pmic_ldo_get_voltage, - .set_voltage = tps6507x_pmic_ldo_set_voltage, - .list_voltage = tps6507x_pmic_ldo_list_voltage, -}; - -static __devinit -int tps6507x_pmic_probe(struct platform_device *pdev) +static __devinit int tps6507x_pmic_probe(struct platform_device *pdev) { struct tps6507x_dev *tps6507x_dev = dev_get_drvdata(pdev->dev.parent); struct tps_info *info = &tps6507x_pmic_regs[0]; @@ -593,8 +470,7 @@ int tps6507x_pmic_probe(struct platform_device *pdev) tps->desc[i].name = info->name; tps->desc[i].id = i; tps->desc[i].n_voltages = info->table_len; - tps->desc[i].ops = (i > TPS6507X_DCDC_3 ? - &tps6507x_pmic_ldo_ops : &tps6507x_pmic_dcdc_ops); + tps->desc[i].ops = &tps6507x_pmic_ops; tps->desc[i].type = REGULATOR_VOLTAGE; tps->desc[i].owner = THIS_MODULE; @@ -648,22 +524,12 @@ static struct platform_driver tps6507x_pmic_driver = { .remove = __devexit_p(tps6507x_pmic_remove), }; -/** - * tps6507x_pmic_init - * - * Module init function - */ static int __init tps6507x_pmic_init(void) { return platform_driver_register(&tps6507x_pmic_driver); } subsys_initcall(tps6507x_pmic_init); -/** - * tps6507x_pmic_cleanup - * - * Module exit function - */ static void __exit tps6507x_pmic_cleanup(void) { platform_driver_unregister(&tps6507x_pmic_driver); -- cgit v0.10.2 From ca61a7bfcd1c68eba84a58070540684448216506 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Mon, 12 Mar 2012 15:59:54 +0800 Subject: regulator: Convert tps6507x to set_voltage_sel Signed-off-by: Axel Lin Signed-off-by: Mark Brown diff --git a/drivers/regulator/tps6507x-regulator.c b/drivers/regulator/tps6507x-regulator.c index e140a15..832833f 100644 --- a/drivers/regulator/tps6507x-regulator.c +++ b/drivers/regulator/tps6507x-regulator.c @@ -328,12 +328,11 @@ static int tps6507x_pmic_get_voltage(struct regulator_dev *dev) return tps->info[rid]->table[data] * 1000; } -static int tps6507x_pmic_set_voltage(struct regulator_dev *dev, - int min_uV, int max_uV, - unsigned *selector) +static int tps6507x_pmic_set_voltage_sel(struct regulator_dev *dev, + unsigned selector) { struct tps6507x_pmic *tps = rdev_get_drvdata(dev); - int data, vsel, rid = rdev_get_id(dev); + int data, rid = rdev_get_id(dev); u8 reg, mask; switch (rid) { @@ -367,32 +366,12 @@ static int tps6507x_pmic_set_voltage(struct regulator_dev *dev, return -EINVAL; } - if (min_uV < tps->info[rid]->min_uV || min_uV > tps->info[rid]->max_uV) - return -EINVAL; - if (max_uV < tps->info[rid]->min_uV || max_uV > tps->info[rid]->max_uV) - return -EINVAL; - - for (vsel = 0; vsel < tps->info[rid]->table_len; vsel++) { - int mV = tps->info[rid]->table[vsel]; - int uV = mV * 1000; - - /* Break at the first in-range value */ - if (min_uV <= uV && uV <= max_uV) - break; - } - - /* write to the register in case we found a match */ - if (vsel == tps->info[rid]->table_len) - return -EINVAL; - - *selector = vsel; - data = tps6507x_pmic_reg_read(tps, reg); if (data < 0) return data; data &= ~mask; - data |= vsel; + data |= selector; return tps6507x_pmic_reg_write(tps, reg, data); } @@ -417,7 +396,7 @@ static struct regulator_ops tps6507x_pmic_ops = { .enable = tps6507x_pmic_enable, .disable = tps6507x_pmic_disable, .get_voltage = tps6507x_pmic_get_voltage, - .set_voltage = tps6507x_pmic_set_voltage, + .set_voltage_sel = tps6507x_pmic_set_voltage_sel, .list_voltage = tps6507x_pmic_list_voltage, }; -- cgit v0.10.2 From 16fbcc3b1139e90fe560fde5619169db74dc02c2 Mon Sep 17 00:00:00 2001 From: Rajendra Nayak Date: Fri, 16 Mar 2012 15:50:21 +0530 Subject: regulator: Fix up a confusing dev_warn when DT lookup fails of_parse_phandle() returns NULL either if the property name itself does not exist or if it (exists and) does not reference a valid phandle. Giving out a warn like the one below (that the property references an invalid phandle) can be confusing when the property itself does not exist in the node. Fix it with a more sensible message and make it a dev_dbg instead of a dev_warn. Reported-by: Tomi Valkeinen Signed-off-by: Rajendra Nayak Signed-off-by: Mark Brown diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index b97c4a2..fc4ccf8 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -148,7 +148,7 @@ static struct device_node *of_get_regulator(struct device *dev, const char *supp regnode = of_parse_phandle(dev->of_node, prop_name, 0); if (!regnode) { - dev_warn(dev, "%s property in node %s references invalid phandle", + dev_dbg(dev, "Looking up %s property in node %s failed", prop_name, dev->of_node->full_name); return NULL; } -- cgit v0.10.2