summaryrefslogtreecommitdiff
path: root/drivers/regulator/max8907c-regulator.c
diff options
context:
space:
mode:
authorJin Park <jinyoungp@nvidia.com>2010-10-28 18:04:04 +0900
committerDan Willemsen <dwillemsen@nvidia.com>2011-11-30 21:43:09 -0800
commitb1ca0d16bd9fe99d993a04e7ccf4fbbb1e192f99 (patch)
treef1210ac591d2172db6961643dd9c8dce1ef6c0e1 /drivers/regulator/max8907c-regulator.c
parent0e5eec3307ce47cb03f9405b1c227b400611b24b (diff)
Regulators: Add max8907c and max8952
Add max8907c regulator and mfd driver. Add max8952 regulator driver. Original-Change-Id: If63b724647d887a8088da0f2deb8af91e4fe3cfa Signed-off-by: Jin Park <jinyoungp@nvidia.com> Reviewed-on: http://git-master/r/9902 Reviewed-by: Thomas Cherry <tcherry@nvidia.com> Reviewed-by: Bharat Nihalani <bnihalani@nvidia.com> Tested-by: Bharat Nihalani <bnihalani@nvidia.com> Rebase-Id: R34a5dc549ba3f6781e5b7371e8e182c3cf6368db
Diffstat (limited to 'drivers/regulator/max8907c-regulator.c')
-rw-r--r--drivers/regulator/max8907c-regulator.c416
1 files changed, 416 insertions, 0 deletions
diff --git a/drivers/regulator/max8907c-regulator.c b/drivers/regulator/max8907c-regulator.c
new file mode 100644
index 000000000000..fc3087670164
--- /dev/null
+++ b/drivers/regulator/max8907c-regulator.c
@@ -0,0 +1,416 @@
+/*
+ * max8907c-regulator.c -- support regulators in max8907c
+ *
+ * Copyright (C) 2010 Gyungoh Yoo <jack.yoo@maxim-ic.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <linux/err.h>
+#include <linux/platform_device.h>
+#include <linux/regulator/driver.h>
+#include <linux/mfd/max8907c.h>
+#include <linux/regulator/max8907c-regulator.h>
+
+#define MAX8907C_REGULATOR_CNT (ARRAY_SIZE(max8907c_regulators))
+
+struct max8907c_regulator_info {
+ u32 min_uV;
+ u32 max_uV;
+ u32 step_uV;
+ u8 reg_base;
+ struct regulator_desc desc;
+};
+
+#define REG_LDO(ids, base, min, max, step) \
+ { \
+ .min_uV = (min), \
+ .max_uV = (max), \
+ .step_uV = (step), \
+ .reg_base = (base), \
+ .desc = { \
+ .name = #ids, \
+ .id = MAX8907C_##ids, \
+ .n_voltages = ((max) - (min)) / (step) + 1, \
+ .ops = &max8907c_ldo_ops, \
+ .type = REGULATOR_VOLTAGE, \
+ .owner = THIS_MODULE, \
+ }, \
+ }
+
+#define REG_FIXED(ids, voltage) \
+ { \
+ .min_uV = (voltage), \
+ .max_uV = (voltage), \
+ .desc = { \
+ .name = #ids, \
+ .id = MAX8907C_##ids, \
+ .n_voltages = 1, \
+ .ops = &max8907c_fixed_ops, \
+ .type = REGULATOR_VOLTAGE, \
+ .owner = THIS_MODULE, \
+ }, \
+ }
+
+#define REG_OUT5V(ids, base, voltage) \
+ { \
+ .min_uV = (voltage), \
+ .max_uV = (voltage), \
+ .reg_base = (base), \
+ .desc = { \
+ .name = #ids, \
+ .id = MAX8907C_##ids, \
+ .n_voltages = 1, \
+ .ops = &max8907c_out5v_ops, \
+ .type = REGULATOR_VOLTAGE, \
+ .owner = THIS_MODULE, \
+ }, \
+ }
+
+#define REG_BBAT(ids, base, min, max, step) \
+ { \
+ .min_uV = (min), \
+ .max_uV = (max), \
+ .step_uV = (step), \
+ .reg_base = (base), \
+ .desc = { \
+ .name = #ids, \
+ .id = MAX8907C_##ids, \
+ .n_voltages = ((max) - (min)) / (step) + 1, \
+ .ops = &max8907c_bbat_ops, \
+ .type = REGULATOR_VOLTAGE, \
+ .owner = THIS_MODULE, \
+ }, \
+ }
+
+#define REG_WLED(ids, base, voltage) \
+ { \
+ .min_uV = (voltage), \
+ .max_uV = (voltage), \
+ .reg_base = (base), \
+ .desc = { \
+ .name = #ids, \
+ .id = MAX8907C_##ids, \
+ .n_voltages = 1, \
+ .ops = &max8907c_wled_ops, \
+ .type = REGULATOR_CURRENT, \
+ .owner = THIS_MODULE, \
+ }, \
+ }
+
+#define LDO_750_50(id, base) REG_LDO(id, (base), 750000, 3900000, 50000)
+#define LDO_650_25(id, base) REG_LDO(id, (base), 650000, 2225000, 25000)
+
+static int max8907c_regulator_list_voltage(struct regulator_dev *dev,
+ unsigned index);
+static int max8907c_regulator_ldo_set_voltage(struct regulator_dev *dev,
+ int min_uV, int max_uV);
+static int max8907c_regulator_bbat_set_voltage(struct regulator_dev *dev,
+ int min_uV, int max_uV);
+static int max8907c_regulator_ldo_get_voltage(struct regulator_dev *dev);
+static int max8907c_regulator_fixed_get_voltage(struct regulator_dev *dev);
+static int max8907c_regulator_bbat_get_voltage(struct regulator_dev *dev);
+static int max8907c_regulator_wled_set_current_limit(struct regulator_dev *dev,
+ int min_uA, int max_uA);
+static int max8907c_regulator_wled_get_current_limit(struct regulator_dev *dev);
+static int max8907c_regulator_ldo_enable(struct regulator_dev *dev);
+static int max8907c_regulator_out5v_enable(struct regulator_dev *dev);
+static int max8907c_regulator_ldo_disable(struct regulator_dev *dev);
+static int max8907c_regulator_out5v_disable(struct regulator_dev *dev);
+static int max8907c_regulator_ldo_is_enabled(struct regulator_dev *dev);
+static int max8907c_regulator_out5v_is_enabled(struct regulator_dev *dev);
+
+static struct regulator_ops max8907c_ldo_ops = {
+ .list_voltage = max8907c_regulator_list_voltage,
+ .set_voltage = max8907c_regulator_ldo_set_voltage,
+ .get_voltage = max8907c_regulator_ldo_get_voltage,
+ .enable = max8907c_regulator_ldo_enable,
+ .disable = max8907c_regulator_ldo_disable,
+ .is_enabled = max8907c_regulator_ldo_is_enabled,
+};
+
+static struct regulator_ops max8907c_fixed_ops = {
+ .list_voltage = max8907c_regulator_list_voltage,
+ .get_voltage = max8907c_regulator_fixed_get_voltage,
+};
+
+static struct regulator_ops max8907c_out5v_ops = {
+ .list_voltage = max8907c_regulator_list_voltage,
+ .get_voltage = max8907c_regulator_fixed_get_voltage,
+ .enable = max8907c_regulator_out5v_enable,
+ .disable = max8907c_regulator_out5v_disable,
+ .is_enabled = max8907c_regulator_out5v_is_enabled,
+};
+
+static struct regulator_ops max8907c_bbat_ops = {
+ .list_voltage = max8907c_regulator_list_voltage,
+ .set_voltage = max8907c_regulator_bbat_set_voltage,
+ .get_voltage = max8907c_regulator_bbat_get_voltage,
+};
+
+static struct regulator_ops max8907c_wled_ops = {
+ .list_voltage = max8907c_regulator_list_voltage,
+ .set_current_limit = max8907c_regulator_wled_set_current_limit,
+ .get_current_limit = max8907c_regulator_wled_get_current_limit,
+ .get_voltage = max8907c_regulator_fixed_get_voltage,
+};
+
+static struct max8907c_regulator_info max8907c_regulators[] = {
+ REG_LDO(SD1, MAX8907C_REG_SDCTL1, 650000, 2225000, 25000),
+ REG_LDO(SD2, MAX8907C_REG_SDCTL2, 637500, 1425000, 12500),
+ REG_LDO(SD3, MAX8907C_REG_SDCTL3, 750000, 3900000, 50000),
+ LDO_750_50(LDO1, MAX8907C_REG_LDOCTL1),
+ LDO_650_25(LDO2, MAX8907C_REG_LDOCTL2),
+ LDO_650_25(LDO3, MAX8907C_REG_LDOCTL3),
+ LDO_750_50(LDO4, MAX8907C_REG_LDOCTL4),
+ LDO_750_50(LDO5, MAX8907C_REG_LDOCTL5),
+ LDO_750_50(LDO6, MAX8907C_REG_LDOCTL6),
+ LDO_750_50(LDO7, MAX8907C_REG_LDOCTL7),
+ LDO_750_50(LDO8, MAX8907C_REG_LDOCTL8),
+ LDO_750_50(LDO9, MAX8907C_REG_LDOCTL9),
+ LDO_750_50(LDO10, MAX8907C_REG_LDOCTL10),
+ LDO_750_50(LDO11, MAX8907C_REG_LDOCTL11),
+ LDO_750_50(LDO12, MAX8907C_REG_LDOCTL12),
+ LDO_750_50(LDO13, MAX8907C_REG_LDOCTL13),
+ LDO_750_50(LDO14, MAX8907C_REG_LDOCTL14),
+ LDO_750_50(LDO15, MAX8907C_REG_LDOCTL15),
+ LDO_750_50(LDO16, MAX8907C_REG_LDOCTL16),
+ LDO_650_25(LDO17, MAX8907C_REG_LDOCTL17),
+ LDO_650_25(LDO18, MAX8907C_REG_LDOCTL18),
+ LDO_750_50(LDO19, MAX8907C_REG_LDOCTL19),
+ LDO_750_50(LDO20, MAX8907C_REG_LDOCTL20),
+ REG_OUT5V(OUT5V, MAX8907C_REG_OUT5VEN, 5000000),
+ REG_OUT5V(OUT33V, MAX8907C_REG_OUT33VEN, 3300000),
+ REG_BBAT(BBAT, MAX8907C_REG_BBAT_CNFG, 2400000, 3000000, 200000),
+ REG_FIXED(SDBY, 1200000),
+ REG_FIXED(VRTC, 3300000),
+ REG_WLED(WLED, MAX8907C_REG_ILED_CNTL, 0),
+};
+
+static int max8907c_regulator_list_voltage(struct regulator_dev *rdev,
+ unsigned index)
+{
+ const struct max8907c_regulator_info *info = rdev_get_drvdata(rdev);
+
+ return info->min_uV + info->step_uV * index;
+}
+
+static int max8907c_regulator_ldo_set_voltage(struct regulator_dev *rdev,
+ int min_uV, int max_uV)
+{
+ const struct max8907c_regulator_info *info = rdev_get_drvdata(rdev);
+ struct device *parent = rdev_get_dev(rdev)->parent->parent;
+ int val;
+
+ if (min_uV < info->min_uV || max_uV > info->max_uV)
+ return -EDOM;
+
+ val = (min_uV - info->min_uV) / info->step_uV;
+
+ return max8907c_reg_write(parent, info->reg_base + MAX8907C_VOUT, val);
+}
+
+static int max8907c_regulator_bbat_set_voltage(struct regulator_dev *rdev,
+ int min_uV, int max_uV)
+{
+ const struct max8907c_regulator_info *info = rdev_get_drvdata(rdev);
+ struct device *parent = rdev_get_dev(rdev)->parent->parent;
+ int val;
+
+ if (min_uV < info->min_uV || max_uV > info->max_uV)
+ return -EDOM;
+
+ val = (min_uV - info->min_uV) / info->step_uV;
+
+ return max8907c_set_bits(parent, info->reg_base, MAX8907C_MASK_VBBATTCV,
+ val);
+}
+
+static int max8907c_regulator_ldo_get_voltage(struct regulator_dev *rdev)
+{
+ const struct max8907c_regulator_info *info = rdev_get_drvdata(rdev);
+ struct device *parent = rdev_get_dev(rdev)->parent->parent;
+ int val;
+
+ val = max8907c_reg_read(parent, info->reg_base + MAX8907C_VOUT);
+ return val * info->step_uV + info->min_uV;
+}
+
+static int max8907c_regulator_fixed_get_voltage(struct regulator_dev *rdev)
+{
+ const struct max8907c_regulator_info *info = rdev_get_drvdata(rdev);
+
+ return info->min_uV;
+}
+
+static int max8907c_regulator_bbat_get_voltage(struct regulator_dev *rdev)
+{
+ const struct max8907c_regulator_info *info = rdev_get_drvdata(rdev);
+ struct device *parent = rdev_get_dev(rdev)->parent->parent;
+ int val;
+
+ val =
+ max8907c_reg_read(parent, info->reg_base) & MAX8907C_MASK_VBBATTCV;
+ return val * info->step_uV + info->min_uV;
+}
+
+static int max8907c_regulator_wled_set_current_limit(struct regulator_dev *rdev,
+ int min_uA, int max_uA)
+{
+ const struct max8907c_regulator_info *info = rdev_get_drvdata(rdev);
+ struct device *parent = rdev_get_dev(rdev)->parent->parent;
+
+ if (min_uA > 25500)
+ return -EDOM;
+
+ return max8907c_reg_write(parent, info->reg_base, min_uA / 100);
+}
+
+static int max8907c_regulator_wled_get_current_limit(struct regulator_dev *rdev)
+{
+ const struct max8907c_regulator_info *info = rdev_get_drvdata(rdev);
+ struct device *parent = rdev_get_dev(rdev)->parent->parent;
+ int val;
+
+ val = max8907c_reg_read(parent, info->reg_base);
+ return val * 100;
+}
+
+static int max8907c_regulator_ldo_enable(struct regulator_dev *rdev)
+{
+ const struct max8907c_regulator_info *info = rdev_get_drvdata(rdev);
+ struct device *parent = rdev_get_dev(rdev)->parent->parent;
+
+ return max8907c_set_bits(parent, info->reg_base + MAX8907C_CTL,
+ MAX8907C_MASK_LDO_EN | MAX8907C_MASK_LDO_SEQ,
+ MAX8907C_MASK_LDO_EN | MAX8907C_MASK_LDO_SEQ);
+}
+
+static int max8907c_regulator_out5v_enable(struct regulator_dev *rdev)
+{
+ const struct max8907c_regulator_info *info = rdev_get_drvdata(rdev);
+ struct device *parent = rdev_get_dev(rdev)->parent->parent;
+
+ return max8907c_set_bits(parent, info->reg_base,
+ MAX8907C_MASK_OUT5V_VINEN |
+ MAX8907C_MASK_OUT5V_ENSRC |
+ MAX8907C_MASK_OUT5V_EN,
+ MAX8907C_MASK_OUT5V_ENSRC |
+ MAX8907C_MASK_OUT5V_EN);
+}
+
+static int max8907c_regulator_ldo_disable(struct regulator_dev *rdev)
+{
+ const struct max8907c_regulator_info *info = rdev_get_drvdata(rdev);
+ struct device *parent = rdev_get_dev(rdev)->parent->parent;
+
+ return max8907c_set_bits(parent, info->reg_base + MAX8907C_CTL,
+ MAX8907C_MASK_LDO_EN | MAX8907C_MASK_LDO_SEQ,
+ MAX8907C_MASK_LDO_SEQ);
+}
+
+static int max8907c_regulator_out5v_disable(struct regulator_dev *rdev)
+{
+ const struct max8907c_regulator_info *info = rdev_get_drvdata(rdev);
+ struct device *parent = rdev_get_dev(rdev)->parent->parent;
+
+ return max8907c_set_bits(parent, info->reg_base,
+ MAX8907C_MASK_OUT5V_VINEN |
+ MAX8907C_MASK_OUT5V_ENSRC |
+ MAX8907C_MASK_OUT5V_EN,
+ MAX8907C_MASK_OUT5V_ENSRC);
+}
+
+static int max8907c_regulator_ldo_is_enabled(struct regulator_dev *rdev)
+{
+ const struct max8907c_regulator_info *info = rdev_get_drvdata(rdev);
+ struct device *parent = rdev_get_dev(rdev)->parent->parent;
+ int val;
+
+ val = max8907c_reg_read(parent, info->reg_base + MAX8907C_CTL);
+ if (val < 0)
+ return -EDOM;
+
+ return (val & MAX8907C_MASK_LDO_EN) || !(val & MAX8907C_MASK_LDO_SEQ);
+}
+
+static int max8907c_regulator_out5v_is_enabled(struct regulator_dev *rdev)
+{
+ const struct max8907c_regulator_info *info = rdev_get_drvdata(rdev);
+ struct device *parent = rdev_get_dev(rdev)->parent->parent;
+ int val;
+
+ val = max8907c_reg_read(parent, info->reg_base);
+ if (val < 0)
+ return -EDOM;
+
+ if ((val &
+ (MAX8907C_MASK_OUT5V_VINEN | MAX8907C_MASK_OUT5V_ENSRC |
+ MAX8907C_MASK_OUT5V_EN))
+ == MAX8907C_MASK_OUT5V_ENSRC)
+ return 1;
+
+ return 0;
+}
+
+static int max8907c_regulator_probe(struct platform_device *pdev)
+{
+ struct max8907c_regulator_info *info;
+ struct regulator_dev *rdev;
+
+ info = &max8907c_regulators[pdev->id];
+
+ rdev = regulator_register(&info->desc,
+ &pdev->dev, pdev->dev.platform_data, info);
+ if (IS_ERR(rdev)) {
+ dev_err(&pdev->dev, "Cannot register regulator \"%s\", %ld\n",
+ info->desc.name, PTR_ERR(rdev));
+ goto error;
+ }
+
+ platform_set_drvdata(pdev, rdev);
+ return 0;
+
+error:
+ return PTR_ERR(rdev);
+}
+
+static int max8907c_regulator_remove(struct platform_device *pdev)
+{
+ struct regulator_dev *rdev = platform_get_drvdata(pdev);
+
+ regulator_unregister(rdev);
+ return 0;
+}
+
+static struct platform_driver max8907c_regulator_driver = {
+ .driver = {
+ .name = "max8907c-regulator",
+ .owner = THIS_MODULE,
+ },
+ .probe = max8907c_regulator_probe,
+ .remove = __devexit_p(max8907c_regulator_remove),
+};
+
+static int __init max8907c_regulator_init(void)
+{
+ return platform_driver_register(&max8907c_regulator_driver);
+}
+
+subsys_initcall(max8907c_regulator_init);
+
+static void __exit max8907c_reg_exit(void)
+{
+ platform_driver_unregister(&max8907c_regulator_driver);
+}
+
+module_exit(max8907c_reg_exit);
+
+MODULE_DESCRIPTION("MAX8907C regulator driver");
+MODULE_AUTHOR("Gyungoh Yoo <jack.yoo@maxim-ic.com>");
+MODULE_LICENSE("GPL");