From 156f252857dfd81f03d77d09e33b5f7d2b113e2b Mon Sep 17 00:00:00 2001 From: Kyungmin Park Date: Wed, 16 Jun 2010 09:04:16 +0200 Subject: drivers: regulator: add Maxim 8998 driver Acked-by: Mark Brown This patch adds voltage regulator driver for Maxim 8998 chip. This chip is used on Samsung Aquila and GONI boards and provides following functionalities: - 4 BUCK voltage converters, 17 LDO power regulators and 5 other power controllers - battery charger This patch adds basic driver for voltage regulators and MAX 8998 MFD core. Signed-off-by: Kyungmin Park Signed-off-by: Marek Szyprowski Acked-by: Samuel Ortiz Acked-by: Mark Brown Signed-off-by: Liam Girdwood --- drivers/regulator/Kconfig | 9 + drivers/regulator/Makefile | 1 + drivers/regulator/max8998.c | 610 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 620 insertions(+) create mode 100644 drivers/regulator/max8998.c (limited to 'drivers/regulator') diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig index 6bf56c9..671b81a 100644 --- a/drivers/regulator/Kconfig +++ b/drivers/regulator/Kconfig @@ -100,6 +100,15 @@ config REGULATOR_MAX8925 help Say y here to support the voltage regulaltor of Maxim MAX8925 PMIC. +config REGULATOR_MAX8998 + tristate "Maxim 8998 voltage regulator" + depends on I2C + default n + help + This driver controls a Maxim 8998 voltage output regulator + via I2C bus. The provided regulator is suitable for S3C6410 + and S5PC1XX chips to control VCC_CORE and VCC_USIM voltages. + config REGULATOR_TWL4030 bool "TI TWL4030/TWL5030/TWL6030/TPS695x0 PMIC" depends on TWL4030_CORE diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile index 451a14a..74a4638 100644 --- a/drivers/regulator/Makefile +++ b/drivers/regulator/Makefile @@ -17,6 +17,7 @@ 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_MAX8998) += max8998.o obj-$(CONFIG_REGULATOR_WM831X) += wm831x-dcdc.o obj-$(CONFIG_REGULATOR_WM831X) += wm831x-isink.o obj-$(CONFIG_REGULATOR_WM831X) += wm831x-ldo.o diff --git a/drivers/regulator/max8998.c b/drivers/regulator/max8998.c new file mode 100644 index 0000000..174fd19 --- /dev/null +++ b/drivers/regulator/max8998.c @@ -0,0 +1,610 @@ +/* + * max8998.c - Voltage regulator driver for the Maxim 8998 + * + * Copyright (C) 2009-2010 Samsung Electronics + * Kyungmin Park + * Marek Szyprowski + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct max8998_data { + struct device *dev; + struct max8998_dev *iodev; + int num_regulators; + struct regulator_dev **rdev; +}; + +struct voltage_map_desc { + int min; + int max; + int step; +}; + +/* Voltage maps */ +static const struct voltage_map_desc ldo23_voltage_map_desc = { + .min = 800, .step = 50, .max = 1300, +}; +static const struct voltage_map_desc ldo456711_voltage_map_desc = { + .min = 1600, .step = 100, .max = 3600, +}; +static const struct voltage_map_desc ldo8_voltage_map_desc = { + .min = 3000, .step = 100, .max = 3600, +}; +static const struct voltage_map_desc ldo9_voltage_map_desc = { + .min = 2800, .step = 100, .max = 3100, +}; +static const struct voltage_map_desc ldo10_voltage_map_desc = { + .min = 950, .step = 50, .max = 1300, +}; +static const struct voltage_map_desc ldo1213_voltage_map_desc = { + .min = 800, .step = 100, .max = 3300, +}; +static const struct voltage_map_desc ldo1415_voltage_map_desc = { + .min = 1200, .step = 100, .max = 3300, +}; +static const struct voltage_map_desc ldo1617_voltage_map_desc = { + .min = 1600, .step = 100, .max = 3600, +}; +static const struct voltage_map_desc buck12_voltage_map_desc = { + .min = 750, .step = 25, .max = 1525, +}; +static const struct voltage_map_desc buck3_voltage_map_desc = { + .min = 1600, .step = 100, .max = 3600, +}; +static const struct voltage_map_desc buck4_voltage_map_desc = { + .min = 800, .step = 100, .max = 2300, +}; + +static const struct voltage_map_desc *ldo_voltage_map[] = { + NULL, + NULL, + &ldo23_voltage_map_desc, /* LDO2 */ + &ldo23_voltage_map_desc, /* LDO3 */ + &ldo456711_voltage_map_desc, /* LDO4 */ + &ldo456711_voltage_map_desc, /* LDO5 */ + &ldo456711_voltage_map_desc, /* LDO6 */ + &ldo456711_voltage_map_desc, /* LDO7 */ + &ldo8_voltage_map_desc, /* LDO8 */ + &ldo9_voltage_map_desc, /* LDO9 */ + &ldo10_voltage_map_desc, /* LDO10 */ + &ldo456711_voltage_map_desc, /* LDO11 */ + &ldo1213_voltage_map_desc, /* LDO12 */ + &ldo1213_voltage_map_desc, /* LDO13 */ + &ldo1415_voltage_map_desc, /* LDO14 */ + &ldo1415_voltage_map_desc, /* LDO15 */ + &ldo1617_voltage_map_desc, /* LDO16 */ + &ldo1617_voltage_map_desc, /* LDO17 */ + &buck12_voltage_map_desc, /* BUCK1 */ + &buck12_voltage_map_desc, /* BUCK2 */ + &buck3_voltage_map_desc, /* BUCK3 */ + &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 val; + + if (ldo > ARRAY_SIZE(ldo_voltage_map)) + return -EINVAL; + + desc = ldo_voltage_map[ldo]; + if (desc == NULL) + return -EINVAL; + + val = desc->min + desc->step * selector; + if (val > desc->max) + return -EINVAL; + + return val * 1000; +} + +static int max8998_get_enable_register(struct regulator_dev *rdev, + int *reg, int *shift) +{ + int ldo = max8998_get_ldo(rdev); + + switch (ldo) { + case MAX8998_LDO2 ... MAX8998_LDO5: + *reg = MAX8998_REG_ONOFF1; + *shift = 3 - (ldo - MAX8998_LDO2); + break; + case MAX8998_LDO6 ... MAX8998_LDO13: + *reg = MAX8998_REG_ONOFF2; + *shift = 7 - (ldo - MAX8998_LDO6); + break; + case MAX8998_LDO14 ... MAX8998_LDO17: + *reg = MAX8998_REG_ONOFF3; + *shift = 7 - (ldo - MAX8998_LDO14); + break; + case MAX8998_BUCK1 ... MAX8998_BUCK4: + *reg = MAX8998_REG_ONOFF1; + *shift = 7 - (ldo - MAX8998_BUCK1); + break; + case MAX8998_EN32KHZ_AP ... MAX8998_ENVICHG: + *reg = MAX8998_REG_ONOFF4; + *shift = 7 - (ldo - MAX8998_EN32KHZ_AP); + break; + case MAX8998_ESAFEOUT1 ... MAX8998_ESAFEOUT2: + *reg = MAX8998_REG_CHGR2; + *shift = 7 - (ldo - MAX8998_ESAFEOUT1); + break; + default: + return -EINVAL; + } + + return 0; +} + +static int max8998_ldo_is_enabled(struct regulator_dev *rdev) +{ + struct max8998_data *max8998 = rdev_get_drvdata(rdev); + int ret, reg, shift = 8; + u8 val; + + ret = max8998_get_enable_register(rdev, ®, &shift); + if (ret) + return ret; + + ret = max8998_read_reg(max8998->iodev, reg, &val); + if (ret) + return ret; + + return val & (1 << shift); +} + +static int max8998_ldo_enable(struct regulator_dev *rdev) +{ + struct max8998_data *max8998 = rdev_get_drvdata(rdev); + int reg, shift = 8, ret; + + ret = max8998_get_enable_register(rdev, ®, &shift); + if (ret) + return ret; + + return max8998_update_reg(max8998->iodev, reg, 1<iodev, reg, 0, 1<iodev, reg, &val); + if (ret) + return ret; + + val >>= shift; + val &= mask; + + return max8998_list_voltage(rdev, val); +} + +static int max8998_set_voltage(struct regulator_dev *rdev, + int min_uV, int max_uV) +{ + struct max8998_data *max8998 = rdev_get_drvdata(rdev); + int min_vol = min_uV / 1000, max_vol = max_uV / 1000; + const struct voltage_map_desc *desc; + int ldo = max8998_get_ldo(rdev); + int reg, shift = 0, mask, ret; + int i = 0; + + if (ldo > ARRAY_SIZE(ldo_voltage_map)) + return -EINVAL; + + desc = ldo_voltage_map[ldo]; + if (desc == NULL) + return -EINVAL; + + if (max_vol < desc->min || min_vol > desc->max) + return -EINVAL; + + while (desc->min + desc->step*i < max_vol && + desc->min + desc->step*i < desc->max) + i++; + + ret = max8998_get_voltage_register(rdev, ®, &shift, &mask); + if (ret) + return ret; + + return max8998_update_reg(max8998->iodev, reg, i<dev.parent); + struct max8998_platform_data *pdata = dev_get_platdata(iodev->dev); + struct regulator_dev **rdev; + struct max8998_data *max8998; + int i, ret, size; + + if (!pdata) { + dev_err(pdev->dev.parent, "No platform init data supplied\n"); + return -ENODEV; + } + + max8998 = kzalloc(sizeof(struct max8998_data), GFP_KERNEL); + if (!max8998) + return -ENOMEM; + + size = sizeof(struct regulator_dev *) * (pdata->num_regulators + 1); + max8998->rdev = kzalloc(size, GFP_KERNEL); + if (!max8998->rdev) { + kfree(max8998); + return -ENOMEM; + } + + rdev = max8998->rdev; + max8998->iodev = iodev; + platform_set_drvdata(pdev, max8998); + + for (i = 0; i < pdata->num_regulators; i++) { + const struct voltage_map_desc *desc; + int id = pdata->regulators[i].id; + int index = id - MAX8998_LDO2; + + desc = ldo_voltage_map[id]; + if (desc && regulators[index].ops != &max8998_others_ops) { + int count = (desc->max - desc->min) / desc->step + 1; + regulators[index].n_voltages = count; + } + rdev[i] = regulator_register(®ulators[index], max8998->dev, + pdata->regulators[i].initdata, max8998); + if (IS_ERR(rdev[i])) { + ret = PTR_ERR(rdev[i]); + dev_err(max8998->dev, "regulator init failed\n"); + rdev[i] = NULL; + goto err; + } + } + + + return 0; +err: + for (i = 0; i <= max8998->num_regulators; i++) + if (rdev[i]) + regulator_unregister(rdev[i]); + + kfree(max8998->rdev); + kfree(max8998); + + return ret; +} + +static int __devexit max8998_pmic_remove(struct platform_device *pdev) +{ + struct max8998_data *max8998 = platform_get_drvdata(pdev); + struct regulator_dev **rdev = max8998->rdev; + int i; + + for (i = 0; i <= max8998->num_regulators; i++) + if (rdev[i]) + regulator_unregister(rdev[i]); + + kfree(max8998->rdev); + kfree(max8998); + + return 0; +} + +static struct platform_driver max8998_pmic_driver = { + .driver = { + .name = "max8998-pmic", + .owner = THIS_MODULE, + }, + .probe = max8998_pmic_probe, + .remove = __devexit_p(max8998_pmic_remove), +}; + +static int __init max8998_pmic_init(void) +{ + return platform_driver_register(&max8998_pmic_driver); +} +subsys_initcall(max8998_pmic_init); + +static void __exit max8998_pmic_cleanup(void) +{ + platform_driver_unregister(&max8998_pmic_driver); +} +module_exit(max8998_pmic_cleanup); + +MODULE_DESCRIPTION("MAXIM 8998 voltage regulator driver"); +MODULE_AUTHOR("Kyungmin Park "); +MODULE_LICENSE("GPL"); -- cgit v1.1