regulator: Rename files for max77686 and max77802 drivers
authorJavier Martinez Canillas <javier@osg.samsung.com>
Fri, 12 Feb 2016 04:14:23 +0000 (01:14 -0300)
committerMark Brown <broonie@kernel.org>
Fri, 12 Feb 2016 12:15:51 +0000 (12:15 +0000)
The max77686 and max77802 regulator drivers are for sub-devices of a MFD
driver for some PMIC blocks. But the same object file name (max77686.o)
was used for both the common MFD driver and the max77686 regulator one.

This confuses kbuild if both drivers are built as module causing the MFD
driver to not be copied when installing the modules.

Also, max77{686,802} are a quite generic name for MFD subdevices drivers
so it is better to rename them to max77{686,802}-regulator like it's the
case for most regulator drivers.

Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
MAINTAINERS
drivers/regulator/Makefile
drivers/regulator/max77686-regulator.c [new file with mode: 0644]
drivers/regulator/max77686.c [deleted file]
drivers/regulator/max77802-regulator.c [new file with mode: 0644]
drivers/regulator/max77802.c [deleted file]

index 30aca4aa5467b53d6a171a27b57a4357fa09127b..1d88035630cca9af98fa90b65324f553b8c3473b 100644 (file)
@@ -6903,7 +6903,7 @@ MAXIM MAX77802 MULTIFUNCTION PMIC DEVICE DRIVERS
 M:     Javier Martinez Canillas <javier@osg.samsung.com>
 L:     linux-kernel@vger.kernel.org
 S:     Supported
-F:     drivers/*/*max77802.c
+F:     drivers/*/*max77802*.c
 F:     Documentation/devicetree/bindings/*/*max77802.txt
 F:     include/dt-bindings/*/*max77802.h
 
index 980b1943fa8153dd0c7cb1d286c5f5a23aacdbf4..a8c07a079996c4135b68b6f802bb83797475a26e 100644 (file)
@@ -54,9 +54,9 @@ obj-$(CONFIG_REGULATOR_MAX8952) += max8952.o
 obj-$(CONFIG_REGULATOR_MAX8973) += max8973-regulator.o
 obj-$(CONFIG_REGULATOR_MAX8997) += max8997.o
 obj-$(CONFIG_REGULATOR_MAX8998) += max8998.o
-obj-$(CONFIG_REGULATOR_MAX77686) += max77686.o
+obj-$(CONFIG_REGULATOR_MAX77686) += max77686-regulator.o
 obj-$(CONFIG_REGULATOR_MAX77693) += max77693.o
-obj-$(CONFIG_REGULATOR_MAX77802) += max77802.o
+obj-$(CONFIG_REGULATOR_MAX77802) += max77802-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
diff --git a/drivers/regulator/max77686-regulator.c b/drivers/regulator/max77686-regulator.c
new file mode 100644 (file)
index 0000000..17ccf36
--- /dev/null
@@ -0,0 +1,570 @@
+/*
+ * max77686.c - Regulator driver for the Maxim 77686
+ *
+ * Copyright (C) 2012 Samsung Electronics
+ * Chiwoong Byun <woong.byun@samsung.com>
+ * Jonghwa Lee <jonghwa3.lee@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.
+ *
+ * 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
+ *
+ * This driver is based on max8997.c
+ */
+
+#include <linux/kernel.h>
+#include <linux/bug.h>
+#include <linux/err.h>
+#include <linux/gpio.h>
+#include <linux/of_gpio.h>
+#include <linux/slab.h>
+#include <linux/platform_device.h>
+#include <linux/regulator/driver.h>
+#include <linux/regulator/machine.h>
+#include <linux/regulator/of_regulator.h>
+#include <linux/mfd/max77686.h>
+#include <linux/mfd/max77686-private.h>
+
+#define MAX77686_LDO_MINUV     800000
+#define MAX77686_LDO_UVSTEP    50000
+#define MAX77686_LDO_LOW_MINUV 800000
+#define MAX77686_LDO_LOW_UVSTEP        25000
+#define MAX77686_BUCK_MINUV    750000
+#define MAX77686_BUCK_UVSTEP   50000
+#define MAX77686_RAMP_DELAY    100000                  /* uV/us */
+#define MAX77686_DVS_RAMP_DELAY        27500                   /* uV/us */
+#define MAX77686_DVS_MINUV     600000
+#define MAX77686_DVS_UVSTEP    12500
+
+/*
+ * Value for configuring buck[89] and LDO{20,21,22} as GPIO control.
+ * It is the same as 'off' for other regulators.
+ */
+#define MAX77686_GPIO_CONTROL          0x0
+/*
+ * Values used for configuring LDOs and bucks.
+ * Forcing low power mode: LDO1, 3-5, 9, 13, 17-26
+ */
+#define MAX77686_LDO_LOWPOWER          0x1
+/*
+ * On/off controlled by PWRREQ:
+ *  - LDO2, 6-8, 10-12, 14-16
+ *  - buck[1234]
+ */
+#define MAX77686_OFF_PWRREQ            0x1
+/* Low power mode controlled by PWRREQ: All LDOs */
+#define MAX77686_LDO_LOWPOWER_PWRREQ   0x2
+/* Forcing low power mode: buck[234] */
+#define MAX77686_BUCK_LOWPOWER         0x2
+#define MAX77686_NORMAL                        0x3
+
+#define MAX77686_OPMODE_SHIFT  6
+#define MAX77686_OPMODE_BUCK234_SHIFT  4
+#define MAX77686_OPMODE_MASK   0x3
+
+#define MAX77686_VSEL_MASK     0x3F
+#define MAX77686_DVS_VSEL_MASK 0xFF
+
+#define MAX77686_RAMP_RATE_MASK        0xC0
+
+#define MAX77686_REGULATORS    MAX77686_REG_MAX
+#define MAX77686_LDOS          26
+
+enum max77686_ramp_rate {
+       RAMP_RATE_13P75MV,
+       RAMP_RATE_27P5MV,
+       RAMP_RATE_55MV,
+       RAMP_RATE_NO_CTRL,      /* 100mV/us */
+};
+
+struct max77686_data {
+       DECLARE_BITMAP(gpio_enabled, MAX77686_REGULATORS);
+
+       /* Array indexed by regulator id */
+       unsigned int opmode[MAX77686_REGULATORS];
+};
+
+static unsigned int max77686_get_opmode_shift(int id)
+{
+       switch (id) {
+       case MAX77686_BUCK1:
+       case MAX77686_BUCK5 ... MAX77686_BUCK9:
+               return 0;
+       case MAX77686_BUCK2 ... MAX77686_BUCK4:
+               return MAX77686_OPMODE_BUCK234_SHIFT;
+       default:
+               /* all LDOs */
+               return MAX77686_OPMODE_SHIFT;
+       }
+}
+
+/*
+ * When regulator is configured for GPIO control then it
+ * replaces "normal" mode. Any change from low power mode to normal
+ * should actually change to GPIO control.
+ * Map normal mode to proper value for such regulators.
+ */
+static unsigned int max77686_map_normal_mode(struct max77686_data *max77686,
+                                            int id)
+{
+       switch (id) {
+       case MAX77686_BUCK8:
+       case MAX77686_BUCK9:
+       case MAX77686_LDO20 ... MAX77686_LDO22:
+               if (test_bit(id, max77686->gpio_enabled))
+                       return MAX77686_GPIO_CONTROL;
+       }
+
+       return MAX77686_NORMAL;
+}
+
+/* Some BUCKs and LDOs supports Normal[ON/OFF] mode during suspend */
+static int max77686_set_suspend_disable(struct regulator_dev *rdev)
+{
+       unsigned int val, shift;
+       struct max77686_data *max77686 = rdev_get_drvdata(rdev);
+       int ret, id = rdev_get_id(rdev);
+
+       shift = max77686_get_opmode_shift(id);
+       val = MAX77686_OFF_PWRREQ;
+
+       ret = regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
+                                rdev->desc->enable_mask, val << shift);
+       if (ret)
+               return ret;
+
+       max77686->opmode[id] = val;
+       return 0;
+}
+
+/* Some LDOs supports [LPM/Normal]ON mode during suspend state */
+static int max77686_set_suspend_mode(struct regulator_dev *rdev,
+                                    unsigned int mode)
+{
+       struct max77686_data *max77686 = rdev_get_drvdata(rdev);
+       unsigned int val;
+       int ret, id = rdev_get_id(rdev);
+
+       /* BUCK[5-9] doesn't support this feature */
+       if (id >= MAX77686_BUCK5)
+               return 0;
+
+       switch (mode) {
+       case REGULATOR_MODE_IDLE:                       /* ON in LP Mode */
+               val = MAX77686_LDO_LOWPOWER_PWRREQ;
+               break;
+       case REGULATOR_MODE_NORMAL:                     /* ON in Normal Mode */
+               val = max77686_map_normal_mode(max77686, id);
+               break;
+       default:
+               pr_warn("%s: regulator_suspend_mode : 0x%x not supported\n",
+                       rdev->desc->name, mode);
+               return -EINVAL;
+       }
+
+       ret = regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
+                                 rdev->desc->enable_mask,
+                                 val << MAX77686_OPMODE_SHIFT);
+       if (ret)
+               return ret;
+
+       max77686->opmode[id] = val;
+       return 0;
+}
+
+/* Some LDOs supports LPM-ON/OFF/Normal-ON mode during suspend state */
+static int max77686_ldo_set_suspend_mode(struct regulator_dev *rdev,
+                                    unsigned int mode)
+{
+       unsigned int val;
+       struct max77686_data *max77686 = rdev_get_drvdata(rdev);
+       int ret, id = rdev_get_id(rdev);
+
+       switch (mode) {
+       case REGULATOR_MODE_STANDBY:                    /* switch off */
+               val = MAX77686_OFF_PWRREQ;
+               break;
+       case REGULATOR_MODE_IDLE:                       /* ON in LP Mode */
+               val = MAX77686_LDO_LOWPOWER_PWRREQ;
+               break;
+       case REGULATOR_MODE_NORMAL:                     /* ON in Normal Mode */
+               val = max77686_map_normal_mode(max77686, id);
+               break;
+       default:
+               pr_warn("%s: regulator_suspend_mode : 0x%x not supported\n",
+                       rdev->desc->name, mode);
+               return -EINVAL;
+       }
+
+       ret = regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
+                                rdev->desc->enable_mask,
+                                val << MAX77686_OPMODE_SHIFT);
+       if (ret)
+               return ret;
+
+       max77686->opmode[id] = val;
+       return 0;
+}
+
+static int max77686_enable(struct regulator_dev *rdev)
+{
+       struct max77686_data *max77686 = rdev_get_drvdata(rdev);
+       unsigned int shift;
+       int id = rdev_get_id(rdev);
+
+       shift = max77686_get_opmode_shift(id);
+
+       if (max77686->opmode[id] == MAX77686_OFF_PWRREQ)
+               max77686->opmode[id] = max77686_map_normal_mode(max77686, id);
+
+       return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
+                                 rdev->desc->enable_mask,
+                                 max77686->opmode[id] << shift);
+}
+
+static int max77686_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay)
+{
+       unsigned int ramp_value = RAMP_RATE_NO_CTRL;
+
+       switch (ramp_delay) {
+       case 1 ... 13750:
+               ramp_value = RAMP_RATE_13P75MV;
+               break;
+       case 13751 ... 27500:
+               ramp_value = RAMP_RATE_27P5MV;
+               break;
+       case 27501 ... 55000:
+               ramp_value = RAMP_RATE_55MV;
+               break;
+       case 55001 ... 100000:
+               break;
+       default:
+               pr_warn("%s: ramp_delay: %d not supported, setting 100000\n",
+                       rdev->desc->name, ramp_delay);
+       }
+
+       return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
+                                 MAX77686_RAMP_RATE_MASK, ramp_value << 6);
+}
+
+static int max77686_of_parse_cb(struct device_node *np,
+               const struct regulator_desc *desc,
+               struct regulator_config *config)
+{
+       struct max77686_data *max77686 = config->driver_data;
+
+       switch (desc->id) {
+       case MAX77686_BUCK8:
+       case MAX77686_BUCK9:
+       case MAX77686_LDO20 ... MAX77686_LDO22:
+               config->ena_gpio = of_get_named_gpio(np,
+                                       "maxim,ena-gpios", 0);
+               config->ena_gpio_flags = GPIOF_OUT_INIT_HIGH;
+               config->ena_gpio_initialized = true;
+               break;
+       default:
+               return 0;
+       }
+
+       if (gpio_is_valid(config->ena_gpio)) {
+               set_bit(desc->id, max77686->gpio_enabled);
+
+               return regmap_update_bits(config->regmap, desc->enable_reg,
+                                         desc->enable_mask,
+                                         MAX77686_GPIO_CONTROL);
+       }
+
+       return 0;
+}
+
+static struct regulator_ops max77686_ops = {
+       .list_voltage           = regulator_list_voltage_linear,
+       .map_voltage            = regulator_map_voltage_linear,
+       .is_enabled             = regulator_is_enabled_regmap,
+       .enable                 = max77686_enable,
+       .disable                = regulator_disable_regmap,
+       .get_voltage_sel        = regulator_get_voltage_sel_regmap,
+       .set_voltage_sel        = regulator_set_voltage_sel_regmap,
+       .set_voltage_time_sel   = regulator_set_voltage_time_sel,
+       .set_suspend_mode       = max77686_set_suspend_mode,
+};
+
+static struct regulator_ops max77686_ldo_ops = {
+       .list_voltage           = regulator_list_voltage_linear,
+       .map_voltage            = regulator_map_voltage_linear,
+       .is_enabled             = regulator_is_enabled_regmap,
+       .enable                 = max77686_enable,
+       .disable                = regulator_disable_regmap,
+       .get_voltage_sel        = regulator_get_voltage_sel_regmap,
+       .set_voltage_sel        = regulator_set_voltage_sel_regmap,
+       .set_voltage_time_sel   = regulator_set_voltage_time_sel,
+       .set_suspend_mode       = max77686_ldo_set_suspend_mode,
+       .set_suspend_disable    = max77686_set_suspend_disable,
+};
+
+static struct regulator_ops max77686_buck1_ops = {
+       .list_voltage           = regulator_list_voltage_linear,
+       .map_voltage            = regulator_map_voltage_linear,
+       .is_enabled             = regulator_is_enabled_regmap,
+       .enable                 = max77686_enable,
+       .disable                = regulator_disable_regmap,
+       .get_voltage_sel        = regulator_get_voltage_sel_regmap,
+       .set_voltage_sel        = regulator_set_voltage_sel_regmap,
+       .set_voltage_time_sel   = regulator_set_voltage_time_sel,
+       .set_suspend_disable    = max77686_set_suspend_disable,
+};
+
+static struct regulator_ops max77686_buck_dvs_ops = {
+       .list_voltage           = regulator_list_voltage_linear,
+       .map_voltage            = regulator_map_voltage_linear,
+       .is_enabled             = regulator_is_enabled_regmap,
+       .enable                 = max77686_enable,
+       .disable                = regulator_disable_regmap,
+       .get_voltage_sel        = regulator_get_voltage_sel_regmap,
+       .set_voltage_sel        = regulator_set_voltage_sel_regmap,
+       .set_voltage_time_sel   = regulator_set_voltage_time_sel,
+       .set_ramp_delay         = max77686_set_ramp_delay,
+       .set_suspend_disable    = max77686_set_suspend_disable,
+};
+
+#define regulator_desc_ldo(num)                {                               \
+       .name           = "LDO"#num,                                    \
+       .of_match       = of_match_ptr("LDO"#num),                      \
+       .regulators_node        = of_match_ptr("voltage-regulators"),   \
+       .of_parse_cb    = max77686_of_parse_cb,                         \
+       .id             = MAX77686_LDO##num,                            \
+       .ops            = &max77686_ops,                                \
+       .type           = REGULATOR_VOLTAGE,                            \
+       .owner          = THIS_MODULE,                                  \
+       .min_uV         = MAX77686_LDO_MINUV,                           \
+       .uV_step        = MAX77686_LDO_UVSTEP,                          \
+       .ramp_delay     = MAX77686_RAMP_DELAY,                          \
+       .n_voltages     = MAX77686_VSEL_MASK + 1,                       \
+       .vsel_reg       = MAX77686_REG_LDO1CTRL1 + num - 1,             \
+       .vsel_mask      = MAX77686_VSEL_MASK,                           \
+       .enable_reg     = MAX77686_REG_LDO1CTRL1 + num - 1,             \
+       .enable_mask    = MAX77686_OPMODE_MASK                          \
+                       << MAX77686_OPMODE_SHIFT,                       \
+}
+#define regulator_desc_lpm_ldo(num)    {                               \
+       .name           = "LDO"#num,                                    \
+       .of_match       = of_match_ptr("LDO"#num),                      \
+       .regulators_node        = of_match_ptr("voltage-regulators"),   \
+       .id             = MAX77686_LDO##num,                            \
+       .ops            = &max77686_ldo_ops,                            \
+       .type           = REGULATOR_VOLTAGE,                            \
+       .owner          = THIS_MODULE,                                  \
+       .min_uV         = MAX77686_LDO_MINUV,                           \
+       .uV_step        = MAX77686_LDO_UVSTEP,                          \
+       .ramp_delay     = MAX77686_RAMP_DELAY,                          \
+       .n_voltages     = MAX77686_VSEL_MASK + 1,                       \
+       .vsel_reg       = MAX77686_REG_LDO1CTRL1 + num - 1,             \
+       .vsel_mask      = MAX77686_VSEL_MASK,                           \
+       .enable_reg     = MAX77686_REG_LDO1CTRL1 + num - 1,             \
+       .enable_mask    = MAX77686_OPMODE_MASK                          \
+                       << MAX77686_OPMODE_SHIFT,                       \
+}
+#define regulator_desc_ldo_low(num)            {                       \
+       .name           = "LDO"#num,                                    \
+       .of_match       = of_match_ptr("LDO"#num),                      \
+       .regulators_node        = of_match_ptr("voltage-regulators"),   \
+       .id             = MAX77686_LDO##num,                            \
+       .ops            = &max77686_ldo_ops,                            \
+       .type           = REGULATOR_VOLTAGE,                            \
+       .owner          = THIS_MODULE,                                  \
+       .min_uV         = MAX77686_LDO_LOW_MINUV,                       \
+       .uV_step        = MAX77686_LDO_LOW_UVSTEP,                      \
+       .ramp_delay     = MAX77686_RAMP_DELAY,                          \
+       .n_voltages     = MAX77686_VSEL_MASK + 1,                       \
+       .vsel_reg       = MAX77686_REG_LDO1CTRL1 + num - 1,             \
+       .vsel_mask      = MAX77686_VSEL_MASK,                           \
+       .enable_reg     = MAX77686_REG_LDO1CTRL1 + num - 1,             \
+       .enable_mask    = MAX77686_OPMODE_MASK                          \
+                       << MAX77686_OPMODE_SHIFT,                       \
+}
+#define regulator_desc_ldo1_low(num)           {                       \
+       .name           = "LDO"#num,                                    \
+       .of_match       = of_match_ptr("LDO"#num),                      \
+       .regulators_node        = of_match_ptr("voltage-regulators"),   \
+       .id             = MAX77686_LDO##num,                            \
+       .ops            = &max77686_ops,                                \
+       .type           = REGULATOR_VOLTAGE,                            \
+       .owner          = THIS_MODULE,                                  \
+       .min_uV         = MAX77686_LDO_LOW_MINUV,                       \
+       .uV_step        = MAX77686_LDO_LOW_UVSTEP,                      \
+       .ramp_delay     = MAX77686_RAMP_DELAY,                          \
+       .n_voltages     = MAX77686_VSEL_MASK + 1,                       \
+       .vsel_reg       = MAX77686_REG_LDO1CTRL1 + num - 1,             \
+       .vsel_mask      = MAX77686_VSEL_MASK,                           \
+       .enable_reg     = MAX77686_REG_LDO1CTRL1 + num - 1,             \
+       .enable_mask    = MAX77686_OPMODE_MASK                          \
+                       << MAX77686_OPMODE_SHIFT,                       \
+}
+#define regulator_desc_buck(num)               {                       \
+       .name           = "BUCK"#num,                                   \
+       .of_match       = of_match_ptr("BUCK"#num),                     \
+       .regulators_node        = of_match_ptr("voltage-regulators"),   \
+       .of_parse_cb    = max77686_of_parse_cb,                         \
+       .id             = MAX77686_BUCK##num,                           \
+       .ops            = &max77686_ops,                                \
+       .type           = REGULATOR_VOLTAGE,                            \
+       .owner          = THIS_MODULE,                                  \
+       .min_uV         = MAX77686_BUCK_MINUV,                          \
+       .uV_step        = MAX77686_BUCK_UVSTEP,                         \
+       .ramp_delay     = MAX77686_RAMP_DELAY,                          \
+       .n_voltages     = MAX77686_VSEL_MASK + 1,                       \
+       .vsel_reg       = MAX77686_REG_BUCK5OUT + (num - 5) * 2,        \
+       .vsel_mask      = MAX77686_VSEL_MASK,                           \
+       .enable_reg     = MAX77686_REG_BUCK5CTRL + (num - 5) * 2,       \
+       .enable_mask    = MAX77686_OPMODE_MASK,                         \
+}
+#define regulator_desc_buck1(num)              {                       \
+       .name           = "BUCK"#num,                                   \
+       .of_match       = of_match_ptr("BUCK"#num),                     \
+       .regulators_node        = of_match_ptr("voltage-regulators"),   \
+       .id             = MAX77686_BUCK##num,                           \
+       .ops            = &max77686_buck1_ops,                          \
+       .type           = REGULATOR_VOLTAGE,                            \
+       .owner          = THIS_MODULE,                                  \
+       .min_uV         = MAX77686_BUCK_MINUV,                          \
+       .uV_step        = MAX77686_BUCK_UVSTEP,                         \
+       .ramp_delay     = MAX77686_RAMP_DELAY,                          \
+       .n_voltages     = MAX77686_VSEL_MASK + 1,                       \
+       .vsel_reg       = MAX77686_REG_BUCK1OUT,                        \
+       .vsel_mask      = MAX77686_VSEL_MASK,                           \
+       .enable_reg     = MAX77686_REG_BUCK1CTRL,                       \
+       .enable_mask    = MAX77686_OPMODE_MASK,                         \
+}
+#define regulator_desc_buck_dvs(num)           {                       \
+       .name           = "BUCK"#num,                                   \
+       .of_match       = of_match_ptr("BUCK"#num),                     \
+       .regulators_node        = of_match_ptr("voltage-regulators"),   \
+       .id             = MAX77686_BUCK##num,                           \
+       .ops            = &max77686_buck_dvs_ops,                       \
+       .type           = REGULATOR_VOLTAGE,                            \
+       .owner          = THIS_MODULE,                                  \
+       .min_uV         = MAX77686_DVS_MINUV,                           \
+       .uV_step        = MAX77686_DVS_UVSTEP,                          \
+       .ramp_delay     = MAX77686_DVS_RAMP_DELAY,                      \
+       .n_voltages     = MAX77686_DVS_VSEL_MASK + 1,                   \
+       .vsel_reg       = MAX77686_REG_BUCK2DVS1 + (num - 2) * 10,      \
+       .vsel_mask      = MAX77686_DVS_VSEL_MASK,                       \
+       .enable_reg     = MAX77686_REG_BUCK2CTRL1 + (num - 2) * 10,     \
+       .enable_mask    = MAX77686_OPMODE_MASK                          \
+                       << MAX77686_OPMODE_BUCK234_SHIFT,               \
+}
+
+static const struct regulator_desc regulators[] = {
+       regulator_desc_ldo1_low(1),
+       regulator_desc_ldo_low(2),
+       regulator_desc_ldo(3),
+       regulator_desc_ldo(4),
+       regulator_desc_ldo(5),
+       regulator_desc_ldo_low(6),
+       regulator_desc_ldo_low(7),
+       regulator_desc_ldo_low(8),
+       regulator_desc_ldo(9),
+       regulator_desc_lpm_ldo(10),
+       regulator_desc_lpm_ldo(11),
+       regulator_desc_lpm_ldo(12),
+       regulator_desc_ldo(13),
+       regulator_desc_lpm_ldo(14),
+       regulator_desc_ldo_low(15),
+       regulator_desc_lpm_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_buck1(1),
+       regulator_desc_buck_dvs(2),
+       regulator_desc_buck_dvs(3),
+       regulator_desc_buck_dvs(4),
+       regulator_desc_buck(5),
+       regulator_desc_buck(6),
+       regulator_desc_buck(7),
+       regulator_desc_buck(8),
+       regulator_desc_buck(9),
+};
+
+static int max77686_pmic_probe(struct platform_device *pdev)
+{
+       struct max77686_dev *iodev = dev_get_drvdata(pdev->dev.parent);
+       struct max77686_data *max77686;
+       int i;
+       struct regulator_config config = { };
+
+       dev_dbg(&pdev->dev, "%s\n", __func__);
+
+       max77686 = devm_kzalloc(&pdev->dev, sizeof(struct max77686_data),
+                               GFP_KERNEL);
+       if (!max77686)
+               return -ENOMEM;
+
+       config.dev = iodev->dev;
+       config.regmap = iodev->regmap;
+       config.driver_data = max77686;
+       platform_set_drvdata(pdev, max77686);
+
+       for (i = 0; i < MAX77686_REGULATORS; i++) {
+               struct regulator_dev *rdev;
+               int id = regulators[i].id;
+
+               max77686->opmode[id] = MAX77686_NORMAL;
+               rdev = devm_regulator_register(&pdev->dev,
+                                               &regulators[i], &config);
+               if (IS_ERR(rdev)) {
+                       int ret = PTR_ERR(rdev);
+                       dev_err(&pdev->dev,
+                               "regulator init failed for %d: %d\n", i, ret);
+                       return ret;
+               }
+       }
+
+       return 0;
+}
+
+static const struct platform_device_id max77686_pmic_id[] = {
+       {"max77686-pmic", 0},
+       { },
+};
+MODULE_DEVICE_TABLE(platform, max77686_pmic_id);
+
+static struct platform_driver max77686_pmic_driver = {
+       .driver = {
+               .name = "max77686-pmic",
+       },
+       .probe = max77686_pmic_probe,
+       .id_table = max77686_pmic_id,
+};
+
+static int __init max77686_pmic_init(void)
+{
+       return platform_driver_register(&max77686_pmic_driver);
+}
+subsys_initcall(max77686_pmic_init);
+
+static void __exit max77686_pmic_cleanup(void)
+{
+       platform_driver_unregister(&max77686_pmic_driver);
+}
+module_exit(max77686_pmic_cleanup);
+
+MODULE_DESCRIPTION("MAXIM 77686 Regulator Driver");
+MODULE_AUTHOR("Chiwoong Byun <woong.byun@samsung.com>");
+MODULE_LICENSE("GPL");
diff --git a/drivers/regulator/max77686.c b/drivers/regulator/max77686.c
deleted file mode 100644 (file)
index 17ccf36..0000000
+++ /dev/null
@@ -1,570 +0,0 @@
-/*
- * max77686.c - Regulator driver for the Maxim 77686
- *
- * Copyright (C) 2012 Samsung Electronics
- * Chiwoong Byun <woong.byun@samsung.com>
- * Jonghwa Lee <jonghwa3.lee@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.
- *
- * 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
- *
- * This driver is based on max8997.c
- */
-
-#include <linux/kernel.h>
-#include <linux/bug.h>
-#include <linux/err.h>
-#include <linux/gpio.h>
-#include <linux/of_gpio.h>
-#include <linux/slab.h>
-#include <linux/platform_device.h>
-#include <linux/regulator/driver.h>
-#include <linux/regulator/machine.h>
-#include <linux/regulator/of_regulator.h>
-#include <linux/mfd/max77686.h>
-#include <linux/mfd/max77686-private.h>
-
-#define MAX77686_LDO_MINUV     800000
-#define MAX77686_LDO_UVSTEP    50000
-#define MAX77686_LDO_LOW_MINUV 800000
-#define MAX77686_LDO_LOW_UVSTEP        25000
-#define MAX77686_BUCK_MINUV    750000
-#define MAX77686_BUCK_UVSTEP   50000
-#define MAX77686_RAMP_DELAY    100000                  /* uV/us */
-#define MAX77686_DVS_RAMP_DELAY        27500                   /* uV/us */
-#define MAX77686_DVS_MINUV     600000
-#define MAX77686_DVS_UVSTEP    12500
-
-/*
- * Value for configuring buck[89] and LDO{20,21,22} as GPIO control.
- * It is the same as 'off' for other regulators.
- */
-#define MAX77686_GPIO_CONTROL          0x0
-/*
- * Values used for configuring LDOs and bucks.
- * Forcing low power mode: LDO1, 3-5, 9, 13, 17-26
- */
-#define MAX77686_LDO_LOWPOWER          0x1
-/*
- * On/off controlled by PWRREQ:
- *  - LDO2, 6-8, 10-12, 14-16
- *  - buck[1234]
- */
-#define MAX77686_OFF_PWRREQ            0x1
-/* Low power mode controlled by PWRREQ: All LDOs */
-#define MAX77686_LDO_LOWPOWER_PWRREQ   0x2
-/* Forcing low power mode: buck[234] */
-#define MAX77686_BUCK_LOWPOWER         0x2
-#define MAX77686_NORMAL                        0x3
-
-#define MAX77686_OPMODE_SHIFT  6
-#define MAX77686_OPMODE_BUCK234_SHIFT  4
-#define MAX77686_OPMODE_MASK   0x3
-
-#define MAX77686_VSEL_MASK     0x3F
-#define MAX77686_DVS_VSEL_MASK 0xFF
-
-#define MAX77686_RAMP_RATE_MASK        0xC0
-
-#define MAX77686_REGULATORS    MAX77686_REG_MAX
-#define MAX77686_LDOS          26
-
-enum max77686_ramp_rate {
-       RAMP_RATE_13P75MV,
-       RAMP_RATE_27P5MV,
-       RAMP_RATE_55MV,
-       RAMP_RATE_NO_CTRL,      /* 100mV/us */
-};
-
-struct max77686_data {
-       DECLARE_BITMAP(gpio_enabled, MAX77686_REGULATORS);
-
-       /* Array indexed by regulator id */
-       unsigned int opmode[MAX77686_REGULATORS];
-};
-
-static unsigned int max77686_get_opmode_shift(int id)
-{
-       switch (id) {
-       case MAX77686_BUCK1:
-       case MAX77686_BUCK5 ... MAX77686_BUCK9:
-               return 0;
-       case MAX77686_BUCK2 ... MAX77686_BUCK4:
-               return MAX77686_OPMODE_BUCK234_SHIFT;
-       default:
-               /* all LDOs */
-               return MAX77686_OPMODE_SHIFT;
-       }
-}
-
-/*
- * When regulator is configured for GPIO control then it
- * replaces "normal" mode. Any change from low power mode to normal
- * should actually change to GPIO control.
- * Map normal mode to proper value for such regulators.
- */
-static unsigned int max77686_map_normal_mode(struct max77686_data *max77686,
-                                            int id)
-{
-       switch (id) {
-       case MAX77686_BUCK8:
-       case MAX77686_BUCK9:
-       case MAX77686_LDO20 ... MAX77686_LDO22:
-               if (test_bit(id, max77686->gpio_enabled))
-                       return MAX77686_GPIO_CONTROL;
-       }
-
-       return MAX77686_NORMAL;
-}
-
-/* Some BUCKs and LDOs supports Normal[ON/OFF] mode during suspend */
-static int max77686_set_suspend_disable(struct regulator_dev *rdev)
-{
-       unsigned int val, shift;
-       struct max77686_data *max77686 = rdev_get_drvdata(rdev);
-       int ret, id = rdev_get_id(rdev);
-
-       shift = max77686_get_opmode_shift(id);
-       val = MAX77686_OFF_PWRREQ;
-
-       ret = regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
-                                rdev->desc->enable_mask, val << shift);
-       if (ret)
-               return ret;
-
-       max77686->opmode[id] = val;
-       return 0;
-}
-
-/* Some LDOs supports [LPM/Normal]ON mode during suspend state */
-static int max77686_set_suspend_mode(struct regulator_dev *rdev,
-                                    unsigned int mode)
-{
-       struct max77686_data *max77686 = rdev_get_drvdata(rdev);
-       unsigned int val;
-       int ret, id = rdev_get_id(rdev);
-
-       /* BUCK[5-9] doesn't support this feature */
-       if (id >= MAX77686_BUCK5)
-               return 0;
-
-       switch (mode) {
-       case REGULATOR_MODE_IDLE:                       /* ON in LP Mode */
-               val = MAX77686_LDO_LOWPOWER_PWRREQ;
-               break;
-       case REGULATOR_MODE_NORMAL:                     /* ON in Normal Mode */
-               val = max77686_map_normal_mode(max77686, id);
-               break;
-       default:
-               pr_warn("%s: regulator_suspend_mode : 0x%x not supported\n",
-                       rdev->desc->name, mode);
-               return -EINVAL;
-       }
-
-       ret = regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
-                                 rdev->desc->enable_mask,
-                                 val << MAX77686_OPMODE_SHIFT);
-       if (ret)
-               return ret;
-
-       max77686->opmode[id] = val;
-       return 0;
-}
-
-/* Some LDOs supports LPM-ON/OFF/Normal-ON mode during suspend state */
-static int max77686_ldo_set_suspend_mode(struct regulator_dev *rdev,
-                                    unsigned int mode)
-{
-       unsigned int val;
-       struct max77686_data *max77686 = rdev_get_drvdata(rdev);
-       int ret, id = rdev_get_id(rdev);
-
-       switch (mode) {
-       case REGULATOR_MODE_STANDBY:                    /* switch off */
-               val = MAX77686_OFF_PWRREQ;
-               break;
-       case REGULATOR_MODE_IDLE:                       /* ON in LP Mode */
-               val = MAX77686_LDO_LOWPOWER_PWRREQ;
-               break;
-       case REGULATOR_MODE_NORMAL:                     /* ON in Normal Mode */
-               val = max77686_map_normal_mode(max77686, id);
-               break;
-       default:
-               pr_warn("%s: regulator_suspend_mode : 0x%x not supported\n",
-                       rdev->desc->name, mode);
-               return -EINVAL;
-       }
-
-       ret = regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
-                                rdev->desc->enable_mask,
-                                val << MAX77686_OPMODE_SHIFT);
-       if (ret)
-               return ret;
-
-       max77686->opmode[id] = val;
-       return 0;
-}
-
-static int max77686_enable(struct regulator_dev *rdev)
-{
-       struct max77686_data *max77686 = rdev_get_drvdata(rdev);
-       unsigned int shift;
-       int id = rdev_get_id(rdev);
-
-       shift = max77686_get_opmode_shift(id);
-
-       if (max77686->opmode[id] == MAX77686_OFF_PWRREQ)
-               max77686->opmode[id] = max77686_map_normal_mode(max77686, id);
-
-       return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
-                                 rdev->desc->enable_mask,
-                                 max77686->opmode[id] << shift);
-}
-
-static int max77686_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay)
-{
-       unsigned int ramp_value = RAMP_RATE_NO_CTRL;
-
-       switch (ramp_delay) {
-       case 1 ... 13750:
-               ramp_value = RAMP_RATE_13P75MV;
-               break;
-       case 13751 ... 27500:
-               ramp_value = RAMP_RATE_27P5MV;
-               break;
-       case 27501 ... 55000:
-               ramp_value = RAMP_RATE_55MV;
-               break;
-       case 55001 ... 100000:
-               break;
-       default:
-               pr_warn("%s: ramp_delay: %d not supported, setting 100000\n",
-                       rdev->desc->name, ramp_delay);
-       }
-
-       return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
-                                 MAX77686_RAMP_RATE_MASK, ramp_value << 6);
-}
-
-static int max77686_of_parse_cb(struct device_node *np,
-               const struct regulator_desc *desc,
-               struct regulator_config *config)
-{
-       struct max77686_data *max77686 = config->driver_data;
-
-       switch (desc->id) {
-       case MAX77686_BUCK8:
-       case MAX77686_BUCK9:
-       case MAX77686_LDO20 ... MAX77686_LDO22:
-               config->ena_gpio = of_get_named_gpio(np,
-                                       "maxim,ena-gpios", 0);
-               config->ena_gpio_flags = GPIOF_OUT_INIT_HIGH;
-               config->ena_gpio_initialized = true;
-               break;
-       default:
-               return 0;
-       }
-
-       if (gpio_is_valid(config->ena_gpio)) {
-               set_bit(desc->id, max77686->gpio_enabled);
-
-               return regmap_update_bits(config->regmap, desc->enable_reg,
-                                         desc->enable_mask,
-                                         MAX77686_GPIO_CONTROL);
-       }
-
-       return 0;
-}
-
-static struct regulator_ops max77686_ops = {
-       .list_voltage           = regulator_list_voltage_linear,
-       .map_voltage            = regulator_map_voltage_linear,
-       .is_enabled             = regulator_is_enabled_regmap,
-       .enable                 = max77686_enable,
-       .disable                = regulator_disable_regmap,
-       .get_voltage_sel        = regulator_get_voltage_sel_regmap,
-       .set_voltage_sel        = regulator_set_voltage_sel_regmap,
-       .set_voltage_time_sel   = regulator_set_voltage_time_sel,
-       .set_suspend_mode       = max77686_set_suspend_mode,
-};
-
-static struct regulator_ops max77686_ldo_ops = {
-       .list_voltage           = regulator_list_voltage_linear,
-       .map_voltage            = regulator_map_voltage_linear,
-       .is_enabled             = regulator_is_enabled_regmap,
-       .enable                 = max77686_enable,
-       .disable                = regulator_disable_regmap,
-       .get_voltage_sel        = regulator_get_voltage_sel_regmap,
-       .set_voltage_sel        = regulator_set_voltage_sel_regmap,
-       .set_voltage_time_sel   = regulator_set_voltage_time_sel,
-       .set_suspend_mode       = max77686_ldo_set_suspend_mode,
-       .set_suspend_disable    = max77686_set_suspend_disable,
-};
-
-static struct regulator_ops max77686_buck1_ops = {
-       .list_voltage           = regulator_list_voltage_linear,
-       .map_voltage            = regulator_map_voltage_linear,
-       .is_enabled             = regulator_is_enabled_regmap,
-       .enable                 = max77686_enable,
-       .disable                = regulator_disable_regmap,
-       .get_voltage_sel        = regulator_get_voltage_sel_regmap,
-       .set_voltage_sel        = regulator_set_voltage_sel_regmap,
-       .set_voltage_time_sel   = regulator_set_voltage_time_sel,
-       .set_suspend_disable    = max77686_set_suspend_disable,
-};
-
-static struct regulator_ops max77686_buck_dvs_ops = {
-       .list_voltage           = regulator_list_voltage_linear,
-       .map_voltage            = regulator_map_voltage_linear,
-       .is_enabled             = regulator_is_enabled_regmap,
-       .enable                 = max77686_enable,
-       .disable                = regulator_disable_regmap,
-       .get_voltage_sel        = regulator_get_voltage_sel_regmap,
-       .set_voltage_sel        = regulator_set_voltage_sel_regmap,
-       .set_voltage_time_sel   = regulator_set_voltage_time_sel,
-       .set_ramp_delay         = max77686_set_ramp_delay,
-       .set_suspend_disable    = max77686_set_suspend_disable,
-};
-
-#define regulator_desc_ldo(num)                {                               \
-       .name           = "LDO"#num,                                    \
-       .of_match       = of_match_ptr("LDO"#num),                      \
-       .regulators_node        = of_match_ptr("voltage-regulators"),   \
-       .of_parse_cb    = max77686_of_parse_cb,                         \
-       .id             = MAX77686_LDO##num,                            \
-       .ops            = &max77686_ops,                                \
-       .type           = REGULATOR_VOLTAGE,                            \
-       .owner          = THIS_MODULE,                                  \
-       .min_uV         = MAX77686_LDO_MINUV,                           \
-       .uV_step        = MAX77686_LDO_UVSTEP,                          \
-       .ramp_delay     = MAX77686_RAMP_DELAY,                          \
-       .n_voltages     = MAX77686_VSEL_MASK + 1,                       \
-       .vsel_reg       = MAX77686_REG_LDO1CTRL1 + num - 1,             \
-       .vsel_mask      = MAX77686_VSEL_MASK,                           \
-       .enable_reg     = MAX77686_REG_LDO1CTRL1 + num - 1,             \
-       .enable_mask    = MAX77686_OPMODE_MASK                          \
-                       << MAX77686_OPMODE_SHIFT,                       \
-}
-#define regulator_desc_lpm_ldo(num)    {                               \
-       .name           = "LDO"#num,                                    \
-       .of_match       = of_match_ptr("LDO"#num),                      \
-       .regulators_node        = of_match_ptr("voltage-regulators"),   \
-       .id             = MAX77686_LDO##num,                            \
-       .ops            = &max77686_ldo_ops,                            \
-       .type           = REGULATOR_VOLTAGE,                            \
-       .owner          = THIS_MODULE,                                  \
-       .min_uV         = MAX77686_LDO_MINUV,                           \
-       .uV_step        = MAX77686_LDO_UVSTEP,                          \
-       .ramp_delay     = MAX77686_RAMP_DELAY,                          \
-       .n_voltages     = MAX77686_VSEL_MASK + 1,                       \
-       .vsel_reg       = MAX77686_REG_LDO1CTRL1 + num - 1,             \
-       .vsel_mask      = MAX77686_VSEL_MASK,                           \
-       .enable_reg     = MAX77686_REG_LDO1CTRL1 + num - 1,             \
-       .enable_mask    = MAX77686_OPMODE_MASK                          \
-                       << MAX77686_OPMODE_SHIFT,                       \
-}
-#define regulator_desc_ldo_low(num)            {                       \
-       .name           = "LDO"#num,                                    \
-       .of_match       = of_match_ptr("LDO"#num),                      \
-       .regulators_node        = of_match_ptr("voltage-regulators"),   \
-       .id             = MAX77686_LDO##num,                            \
-       .ops            = &max77686_ldo_ops,                            \
-       .type           = REGULATOR_VOLTAGE,                            \
-       .owner          = THIS_MODULE,                                  \
-       .min_uV         = MAX77686_LDO_LOW_MINUV,                       \
-       .uV_step        = MAX77686_LDO_LOW_UVSTEP,                      \
-       .ramp_delay     = MAX77686_RAMP_DELAY,                          \
-       .n_voltages     = MAX77686_VSEL_MASK + 1,                       \
-       .vsel_reg       = MAX77686_REG_LDO1CTRL1 + num - 1,             \
-       .vsel_mask      = MAX77686_VSEL_MASK,                           \
-       .enable_reg     = MAX77686_REG_LDO1CTRL1 + num - 1,             \
-       .enable_mask    = MAX77686_OPMODE_MASK                          \
-                       << MAX77686_OPMODE_SHIFT,                       \
-}
-#define regulator_desc_ldo1_low(num)           {                       \
-       .name           = "LDO"#num,                                    \
-       .of_match       = of_match_ptr("LDO"#num),                      \
-       .regulators_node        = of_match_ptr("voltage-regulators"),   \
-       .id             = MAX77686_LDO##num,                            \
-       .ops            = &max77686_ops,                                \
-       .type           = REGULATOR_VOLTAGE,                            \
-       .owner          = THIS_MODULE,                                  \
-       .min_uV         = MAX77686_LDO_LOW_MINUV,                       \
-       .uV_step        = MAX77686_LDO_LOW_UVSTEP,                      \
-       .ramp_delay     = MAX77686_RAMP_DELAY,                          \
-       .n_voltages     = MAX77686_VSEL_MASK + 1,                       \
-       .vsel_reg       = MAX77686_REG_LDO1CTRL1 + num - 1,             \
-       .vsel_mask      = MAX77686_VSEL_MASK,                           \
-       .enable_reg     = MAX77686_REG_LDO1CTRL1 + num - 1,             \
-       .enable_mask    = MAX77686_OPMODE_MASK                          \
-                       << MAX77686_OPMODE_SHIFT,                       \
-}
-#define regulator_desc_buck(num)               {                       \
-       .name           = "BUCK"#num,                                   \
-       .of_match       = of_match_ptr("BUCK"#num),                     \
-       .regulators_node        = of_match_ptr("voltage-regulators"),   \
-       .of_parse_cb    = max77686_of_parse_cb,                         \
-       .id             = MAX77686_BUCK##num,                           \
-       .ops            = &max77686_ops,                                \
-       .type           = REGULATOR_VOLTAGE,                            \
-       .owner          = THIS_MODULE,                                  \
-       .min_uV         = MAX77686_BUCK_MINUV,                          \
-       .uV_step        = MAX77686_BUCK_UVSTEP,                         \
-       .ramp_delay     = MAX77686_RAMP_DELAY,                          \
-       .n_voltages     = MAX77686_VSEL_MASK + 1,                       \
-       .vsel_reg       = MAX77686_REG_BUCK5OUT + (num - 5) * 2,        \
-       .vsel_mask      = MAX77686_VSEL_MASK,                           \
-       .enable_reg     = MAX77686_REG_BUCK5CTRL + (num - 5) * 2,       \
-       .enable_mask    = MAX77686_OPMODE_MASK,                         \
-}
-#define regulator_desc_buck1(num)              {                       \
-       .name           = "BUCK"#num,                                   \
-       .of_match       = of_match_ptr("BUCK"#num),                     \
-       .regulators_node        = of_match_ptr("voltage-regulators"),   \
-       .id             = MAX77686_BUCK##num,                           \
-       .ops            = &max77686_buck1_ops,                          \
-       .type           = REGULATOR_VOLTAGE,                            \
-       .owner          = THIS_MODULE,                                  \
-       .min_uV         = MAX77686_BUCK_MINUV,                          \
-       .uV_step        = MAX77686_BUCK_UVSTEP,                         \
-       .ramp_delay     = MAX77686_RAMP_DELAY,                          \
-       .n_voltages     = MAX77686_VSEL_MASK + 1,                       \
-       .vsel_reg       = MAX77686_REG_BUCK1OUT,                        \
-       .vsel_mask      = MAX77686_VSEL_MASK,                           \
-       .enable_reg     = MAX77686_REG_BUCK1CTRL,                       \
-       .enable_mask    = MAX77686_OPMODE_MASK,                         \
-}
-#define regulator_desc_buck_dvs(num)           {                       \
-       .name           = "BUCK"#num,                                   \
-       .of_match       = of_match_ptr("BUCK"#num),                     \
-       .regulators_node        = of_match_ptr("voltage-regulators"),   \
-       .id             = MAX77686_BUCK##num,                           \
-       .ops            = &max77686_buck_dvs_ops,                       \
-       .type           = REGULATOR_VOLTAGE,                            \
-       .owner          = THIS_MODULE,                                  \
-       .min_uV         = MAX77686_DVS_MINUV,                           \
-       .uV_step        = MAX77686_DVS_UVSTEP,                          \
-       .ramp_delay     = MAX77686_DVS_RAMP_DELAY,                      \
-       .n_voltages     = MAX77686_DVS_VSEL_MASK + 1,                   \
-       .vsel_reg       = MAX77686_REG_BUCK2DVS1 + (num - 2) * 10,      \
-       .vsel_mask      = MAX77686_DVS_VSEL_MASK,                       \
-       .enable_reg     = MAX77686_REG_BUCK2CTRL1 + (num - 2) * 10,     \
-       .enable_mask    = MAX77686_OPMODE_MASK                          \
-                       << MAX77686_OPMODE_BUCK234_SHIFT,               \
-}
-
-static const struct regulator_desc regulators[] = {
-       regulator_desc_ldo1_low(1),
-       regulator_desc_ldo_low(2),
-       regulator_desc_ldo(3),
-       regulator_desc_ldo(4),
-       regulator_desc_ldo(5),
-       regulator_desc_ldo_low(6),
-       regulator_desc_ldo_low(7),
-       regulator_desc_ldo_low(8),
-       regulator_desc_ldo(9),
-       regulator_desc_lpm_ldo(10),
-       regulator_desc_lpm_ldo(11),
-       regulator_desc_lpm_ldo(12),
-       regulator_desc_ldo(13),
-       regulator_desc_lpm_ldo(14),
-       regulator_desc_ldo_low(15),
-       regulator_desc_lpm_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_buck1(1),
-       regulator_desc_buck_dvs(2),
-       regulator_desc_buck_dvs(3),
-       regulator_desc_buck_dvs(4),
-       regulator_desc_buck(5),
-       regulator_desc_buck(6),
-       regulator_desc_buck(7),
-       regulator_desc_buck(8),
-       regulator_desc_buck(9),
-};
-
-static int max77686_pmic_probe(struct platform_device *pdev)
-{
-       struct max77686_dev *iodev = dev_get_drvdata(pdev->dev.parent);
-       struct max77686_data *max77686;
-       int i;
-       struct regulator_config config = { };
-
-       dev_dbg(&pdev->dev, "%s\n", __func__);
-
-       max77686 = devm_kzalloc(&pdev->dev, sizeof(struct max77686_data),
-                               GFP_KERNEL);
-       if (!max77686)
-               return -ENOMEM;
-
-       config.dev = iodev->dev;
-       config.regmap = iodev->regmap;
-       config.driver_data = max77686;
-       platform_set_drvdata(pdev, max77686);
-
-       for (i = 0; i < MAX77686_REGULATORS; i++) {
-               struct regulator_dev *rdev;
-               int id = regulators[i].id;
-
-               max77686->opmode[id] = MAX77686_NORMAL;
-               rdev = devm_regulator_register(&pdev->dev,
-                                               &regulators[i], &config);
-               if (IS_ERR(rdev)) {
-                       int ret = PTR_ERR(rdev);
-                       dev_err(&pdev->dev,
-                               "regulator init failed for %d: %d\n", i, ret);
-                       return ret;
-               }
-       }
-
-       return 0;
-}
-
-static const struct platform_device_id max77686_pmic_id[] = {
-       {"max77686-pmic", 0},
-       { },
-};
-MODULE_DEVICE_TABLE(platform, max77686_pmic_id);
-
-static struct platform_driver max77686_pmic_driver = {
-       .driver = {
-               .name = "max77686-pmic",
-       },
-       .probe = max77686_pmic_probe,
-       .id_table = max77686_pmic_id,
-};
-
-static int __init max77686_pmic_init(void)
-{
-       return platform_driver_register(&max77686_pmic_driver);
-}
-subsys_initcall(max77686_pmic_init);
-
-static void __exit max77686_pmic_cleanup(void)
-{
-       platform_driver_unregister(&max77686_pmic_driver);
-}
-module_exit(max77686_pmic_cleanup);
-
-MODULE_DESCRIPTION("MAXIM 77686 Regulator Driver");
-MODULE_AUTHOR("Chiwoong Byun <woong.byun@samsung.com>");
-MODULE_LICENSE("GPL");
diff --git a/drivers/regulator/max77802-regulator.c b/drivers/regulator/max77802-regulator.c
new file mode 100644 (file)
index 0000000..c07ee13
--- /dev/null
@@ -0,0 +1,610 @@
+/*
+ * max77802.c - Regulator driver for the Maxim 77802
+ *
+ * Copyright (C) 2013-2014 Google, Inc
+ * Simon Glass <sjg@chromium.org>
+ *
+ * Copyright (C) 2012 Samsung Electronics
+ * Chiwoong Byun <woong.byun@smasung.com>
+ * Jonghwa Lee <jonghwa3.lee@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.
+ *
+ * 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.
+ *
+ * This driver is based on max8997.c
+ */
+
+#include <linux/kernel.h>
+#include <linux/bug.h>
+#include <linux/err.h>
+#include <linux/gpio.h>
+#include <linux/slab.h>
+#include <linux/gpio/consumer.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/regulator/driver.h>
+#include <linux/regulator/machine.h>
+#include <linux/regulator/of_regulator.h>
+#include <linux/mfd/max77686.h>
+#include <linux/mfd/max77686-private.h>
+#include <dt-bindings/regulator/maxim,max77802.h>
+
+/* Default ramp delay in case it is not manually set */
+#define MAX77802_RAMP_DELAY            100000          /* uV/us */
+
+#define MAX77802_OPMODE_SHIFT_LDO      6
+#define MAX77802_OPMODE_BUCK234_SHIFT  4
+#define MAX77802_OPMODE_MASK           0x3
+
+#define MAX77802_VSEL_MASK             0x3F
+#define MAX77802_DVS_VSEL_MASK         0xFF
+
+#define MAX77802_RAMP_RATE_MASK_2BIT   0xC0
+#define MAX77802_RAMP_RATE_SHIFT_2BIT  6
+#define MAX77802_RAMP_RATE_MASK_4BIT   0xF0
+#define MAX77802_RAMP_RATE_SHIFT_4BIT  4
+
+#define MAX77802_STATUS_OFF            0x0
+#define MAX77802_OFF_PWRREQ            0x1
+#define MAX77802_LP_PWRREQ             0x2
+
+/* MAX77802 has two register formats: 2-bit and 4-bit */
+static const unsigned int ramp_table_77802_2bit[] = {
+       12500,
+       25000,
+       50000,
+       100000,
+};
+
+static unsigned int ramp_table_77802_4bit[] = {
+       1000,   2000,   3030,   4000,
+       5000,   5880,   7140,   8330,
+       9090,   10000,  11110,  12500,
+       16670,  25000,  50000,  100000,
+};
+
+struct max77802_regulator_prv {
+       /* Array indexed by regulator id */
+       unsigned int opmode[MAX77802_REG_MAX];
+};
+
+static inline unsigned int max77802_map_mode(unsigned int mode)
+{
+       return mode == MAX77802_OPMODE_NORMAL ?
+               REGULATOR_MODE_NORMAL : REGULATOR_MODE_STANDBY;
+}
+
+static int max77802_get_opmode_shift(int id)
+{
+       if (id == MAX77802_BUCK1 || (id >= MAX77802_BUCK5 &&
+                                    id <= MAX77802_BUCK10))
+               return 0;
+
+       if (id >= MAX77802_BUCK2 && id <= MAX77802_BUCK4)
+               return MAX77802_OPMODE_BUCK234_SHIFT;
+
+       if (id >= MAX77802_LDO1 && id <= MAX77802_LDO35)
+               return MAX77802_OPMODE_SHIFT_LDO;
+
+       return -EINVAL;
+}
+
+/**
+ * max77802_set_suspend_disable - Disable the regulator during system suspend
+ * @rdev: regulator to mark as disabled
+ *
+ * All regulators expect LDO 1, 3, 20 and 21 support OFF by PWRREQ.
+ * Configure the regulator so the PMIC will turn it OFF during system suspend.
+ */
+static int max77802_set_suspend_disable(struct regulator_dev *rdev)
+{
+       unsigned int val = MAX77802_OFF_PWRREQ;
+       struct max77802_regulator_prv *max77802 = rdev_get_drvdata(rdev);
+       int id = rdev_get_id(rdev);
+       int shift = max77802_get_opmode_shift(id);
+
+       max77802->opmode[id] = val;
+       return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
+                                 rdev->desc->enable_mask, val << shift);
+}
+
+/*
+ * Some LDOs support Low Power Mode while the system is running.
+ *
+ * LDOs 1, 3, 20, 21.
+ */
+static int max77802_set_mode(struct regulator_dev *rdev, unsigned int mode)
+{
+       struct max77802_regulator_prv *max77802 = rdev_get_drvdata(rdev);
+       int id = rdev_get_id(rdev);
+       unsigned int val;
+       int shift = max77802_get_opmode_shift(id);
+
+       switch (mode) {
+       case REGULATOR_MODE_STANDBY:
+               val = MAX77802_OPMODE_LP;       /* ON in Low Power Mode */
+               break;
+       case REGULATOR_MODE_NORMAL:
+               val = MAX77802_OPMODE_NORMAL;   /* ON in Normal Mode */
+               break;
+       default:
+               dev_warn(&rdev->dev, "%s: regulator mode: 0x%x not supported\n",
+                        rdev->desc->name, mode);
+               return -EINVAL;
+       }
+
+       max77802->opmode[id] = val;
+       return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
+                                 rdev->desc->enable_mask, val << shift);
+}
+
+static unsigned max77802_get_mode(struct regulator_dev *rdev)
+{
+       struct max77802_regulator_prv *max77802 = rdev_get_drvdata(rdev);
+       int id = rdev_get_id(rdev);
+
+       return max77802_map_mode(max77802->opmode[id]);
+}
+
+/**
+ * max77802_set_suspend_mode - set regulator opmode when the system is suspended
+ * @rdev: regulator to change mode
+ * @mode: operating mode to be set
+ *
+ * Will set the operating mode for the regulators during system suspend.
+ * This function is valid for the three different enable control logics:
+ *
+ * Enable Control Logic1 by PWRREQ (BUCK 2-4 and LDOs 2, 4-19, 22-35)
+ * Enable Control Logic2 by PWRREQ (LDOs 1, 20, 21)
+ * Enable Control Logic3 by PWRREQ (LDO 3)
+ *
+ * If setting the regulator mode fails, the function only warns but does
+ * not return an error code to avoid the regulator core to stop setting
+ * the operating mode for the remaining regulators.
+ */
+static int max77802_set_suspend_mode(struct regulator_dev *rdev,
+                                    unsigned int mode)
+{
+       struct max77802_regulator_prv *max77802 = rdev_get_drvdata(rdev);
+       int id = rdev_get_id(rdev);
+       unsigned int val;
+       int shift = max77802_get_opmode_shift(id);
+
+       /*
+        * If the regulator has been disabled for suspend
+        * then is invalid to try setting a suspend mode.
+        */
+       if (max77802->opmode[id] == MAX77802_OFF_PWRREQ) {
+               dev_warn(&rdev->dev, "%s: is disabled, mode: 0x%x not set\n",
+                        rdev->desc->name, mode);
+               return 0;
+       }
+
+       switch (mode) {
+       case REGULATOR_MODE_STANDBY:
+               /*
+                * If the regulator opmode is normal then enable
+                * ON in Low Power Mode by PWRREQ. If the mode is
+                * already Low Power then no action is required.
+                */
+               if (max77802->opmode[id] == MAX77802_OPMODE_NORMAL)
+                       val = MAX77802_LP_PWRREQ;
+               else
+                       return 0;
+               break;
+       case REGULATOR_MODE_NORMAL:
+               /*
+                * If the regulator operating mode is Low Power then
+                * normal is not a valid opmode in suspend. If the
+                * mode is already normal then no action is required.
+                */
+               if (max77802->opmode[id] == MAX77802_OPMODE_LP)
+                       dev_warn(&rdev->dev, "%s: in Low Power: 0x%x invalid\n",
+                                rdev->desc->name, mode);
+               return 0;
+       default:
+               dev_warn(&rdev->dev, "%s: regulator mode: 0x%x not supported\n",
+                        rdev->desc->name, mode);
+               return -EINVAL;
+       }
+
+       return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
+                                 rdev->desc->enable_mask, val << shift);
+}
+
+static int max77802_enable(struct regulator_dev *rdev)
+{
+       struct max77802_regulator_prv *max77802 = rdev_get_drvdata(rdev);
+       int id = rdev_get_id(rdev);
+       int shift = max77802_get_opmode_shift(id);
+
+       if (max77802->opmode[id] == MAX77802_OFF_PWRREQ)
+               max77802->opmode[id] = MAX77802_OPMODE_NORMAL;
+
+       return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
+                                 rdev->desc->enable_mask,
+                                 max77802->opmode[id] << shift);
+}
+
+static int max77802_find_ramp_value(struct regulator_dev *rdev,
+                                   const unsigned int limits[], int size,
+                                   unsigned int ramp_delay)
+{
+       int i;
+
+       for (i = 0; i < size; i++) {
+               if (ramp_delay <= limits[i])
+                       return i;
+       }
+
+       /* Use maximum value for no ramp control */
+       dev_warn(&rdev->dev, "%s: ramp_delay: %d not supported, setting 100000\n",
+                rdev->desc->name, ramp_delay);
+       return size - 1;
+}
+
+/* Used for BUCKs 2-4 */
+static int max77802_set_ramp_delay_2bit(struct regulator_dev *rdev,
+                                       int ramp_delay)
+{
+       int id = rdev_get_id(rdev);
+       unsigned int ramp_value;
+
+       if (id > MAX77802_BUCK4) {
+                       dev_warn(&rdev->dev,
+                                "%s: regulator: ramp delay not supported\n",
+                                rdev->desc->name);
+               return -EINVAL;
+       }
+       ramp_value = max77802_find_ramp_value(rdev, ramp_table_77802_2bit,
+                               ARRAY_SIZE(ramp_table_77802_2bit), ramp_delay);
+
+       return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
+                                 MAX77802_RAMP_RATE_MASK_2BIT,
+                                 ramp_value << MAX77802_RAMP_RATE_SHIFT_2BIT);
+}
+
+/* For BUCK1, 6 */
+static int max77802_set_ramp_delay_4bit(struct regulator_dev *rdev,
+                                           int ramp_delay)
+{
+       unsigned int ramp_value;
+
+       ramp_value = max77802_find_ramp_value(rdev, ramp_table_77802_4bit,
+                               ARRAY_SIZE(ramp_table_77802_4bit), ramp_delay);
+
+       return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
+                                 MAX77802_RAMP_RATE_MASK_4BIT,
+                                 ramp_value << MAX77802_RAMP_RATE_SHIFT_4BIT);
+}
+
+/*
+ * LDOs 2, 4-19, 22-35
+ */
+static struct regulator_ops max77802_ldo_ops_logic1 = {
+       .list_voltage           = regulator_list_voltage_linear,
+       .map_voltage            = regulator_map_voltage_linear,
+       .is_enabled             = regulator_is_enabled_regmap,
+       .enable                 = max77802_enable,
+       .disable                = regulator_disable_regmap,
+       .get_voltage_sel        = regulator_get_voltage_sel_regmap,
+       .set_voltage_sel        = regulator_set_voltage_sel_regmap,
+       .set_voltage_time_sel   = regulator_set_voltage_time_sel,
+       .set_suspend_disable    = max77802_set_suspend_disable,
+       .set_suspend_mode       = max77802_set_suspend_mode,
+};
+
+/*
+ * LDOs 1, 20, 21, 3
+ */
+static struct regulator_ops max77802_ldo_ops_logic2 = {
+       .list_voltage           = regulator_list_voltage_linear,
+       .map_voltage            = regulator_map_voltage_linear,
+       .is_enabled             = regulator_is_enabled_regmap,
+       .enable                 = max77802_enable,
+       .disable                = regulator_disable_regmap,
+       .get_voltage_sel        = regulator_get_voltage_sel_regmap,
+       .set_voltage_sel        = regulator_set_voltage_sel_regmap,
+       .set_voltage_time_sel   = regulator_set_voltage_time_sel,
+       .set_mode               = max77802_set_mode,
+       .get_mode               = max77802_get_mode,
+       .set_suspend_mode       = max77802_set_suspend_mode,
+};
+
+/* BUCKS 1, 6 */
+static struct regulator_ops max77802_buck_16_dvs_ops = {
+       .list_voltage           = regulator_list_voltage_linear,
+       .map_voltage            = regulator_map_voltage_linear,
+       .is_enabled             = regulator_is_enabled_regmap,
+       .enable                 = max77802_enable,
+       .disable                = regulator_disable_regmap,
+       .get_voltage_sel        = regulator_get_voltage_sel_regmap,
+       .set_voltage_sel        = regulator_set_voltage_sel_regmap,
+       .set_voltage_time_sel   = regulator_set_voltage_time_sel,
+       .set_ramp_delay         = max77802_set_ramp_delay_4bit,
+       .set_suspend_disable    = max77802_set_suspend_disable,
+};
+
+/* BUCKs 2-4 */
+static struct regulator_ops max77802_buck_234_ops = {
+       .list_voltage           = regulator_list_voltage_linear,
+       .map_voltage            = regulator_map_voltage_linear,
+       .is_enabled             = regulator_is_enabled_regmap,
+       .enable                 = max77802_enable,
+       .disable                = regulator_disable_regmap,
+       .get_voltage_sel        = regulator_get_voltage_sel_regmap,
+       .set_voltage_sel        = regulator_set_voltage_sel_regmap,
+       .set_voltage_time_sel   = regulator_set_voltage_time_sel,
+       .set_ramp_delay         = max77802_set_ramp_delay_2bit,
+       .set_suspend_disable    = max77802_set_suspend_disable,
+       .set_suspend_mode       = max77802_set_suspend_mode,
+};
+
+/* BUCKs 5, 7-10 */
+static struct regulator_ops max77802_buck_dvs_ops = {
+       .list_voltage           = regulator_list_voltage_linear,
+       .map_voltage            = regulator_map_voltage_linear,
+       .is_enabled             = regulator_is_enabled_regmap,
+       .enable                 = max77802_enable,
+       .disable                = regulator_disable_regmap,
+       .get_voltage_sel        = regulator_get_voltage_sel_regmap,
+       .set_voltage_sel        = regulator_set_voltage_sel_regmap,
+       .set_voltage_time_sel   = regulator_set_voltage_time_sel,
+       .set_ramp_delay         = max77802_set_ramp_delay_2bit,
+       .set_suspend_disable    = max77802_set_suspend_disable,
+};
+
+/* LDOs 3-7, 9-14, 18-26, 28, 29, 32-34 */
+#define regulator_77802_desc_p_ldo(num, supply, log)   {               \
+       .name           = "LDO"#num,                                    \
+       .of_match       = of_match_ptr("LDO"#num),                      \
+       .regulators_node        = of_match_ptr("regulators"),           \
+       .id             = MAX77802_LDO##num,                            \
+       .supply_name    = "inl"#supply,                                 \
+       .ops            = &max77802_ldo_ops_logic##log,                 \
+       .type           = REGULATOR_VOLTAGE,                            \
+       .owner          = THIS_MODULE,                                  \
+       .min_uV         = 800000,                                       \
+       .uV_step        = 50000,                                        \
+       .ramp_delay     = MAX77802_RAMP_DELAY,                          \
+       .n_voltages     = 1 << 6,                                       \
+       .vsel_reg       = MAX77802_REG_LDO1CTRL1 + num - 1,             \
+       .vsel_mask      = MAX77802_VSEL_MASK,                           \
+       .enable_reg     = MAX77802_REG_LDO1CTRL1 + num - 1,             \
+       .enable_mask    = MAX77802_OPMODE_MASK << MAX77802_OPMODE_SHIFT_LDO, \
+       .of_map_mode    = max77802_map_mode,                            \
+}
+
+/* LDOs 1, 2, 8, 15, 17, 27, 30, 35 */
+#define regulator_77802_desc_n_ldo(num, supply, log)   {               \
+       .name           = "LDO"#num,                                    \
+       .of_match       = of_match_ptr("LDO"#num),                      \
+       .regulators_node        = of_match_ptr("regulators"),           \
+       .id             = MAX77802_LDO##num,                            \
+       .supply_name    = "inl"#supply,                                 \
+       .ops            = &max77802_ldo_ops_logic##log,                 \
+       .type           = REGULATOR_VOLTAGE,                            \
+       .owner          = THIS_MODULE,                                  \
+       .min_uV         = 800000,                                       \
+       .uV_step        = 25000,                                        \
+       .ramp_delay     = MAX77802_RAMP_DELAY,                          \
+       .n_voltages     = 1 << 6,                                       \
+       .vsel_reg       = MAX77802_REG_LDO1CTRL1 + num - 1,             \
+       .vsel_mask      = MAX77802_VSEL_MASK,                           \
+       .enable_reg     = MAX77802_REG_LDO1CTRL1 + num - 1,             \
+       .enable_mask    = MAX77802_OPMODE_MASK << MAX77802_OPMODE_SHIFT_LDO, \
+       .of_map_mode    = max77802_map_mode,                            \
+}
+
+/* BUCKs 1, 6 */
+#define regulator_77802_desc_16_buck(num)      {               \
+       .name           = "BUCK"#num,                                   \
+       .of_match       = of_match_ptr("BUCK"#num),                     \
+       .regulators_node        = of_match_ptr("regulators"),           \
+       .id             = MAX77802_BUCK##num,                           \
+       .supply_name    = "inb"#num,                                    \
+       .ops            = &max77802_buck_16_dvs_ops,                    \
+       .type           = REGULATOR_VOLTAGE,                            \
+       .owner          = THIS_MODULE,                                  \
+       .min_uV         = 612500,                                       \
+       .uV_step        = 6250,                                         \
+       .ramp_delay     = MAX77802_RAMP_DELAY,                          \
+       .n_voltages     = 1 << 8,                                       \
+       .vsel_reg       = MAX77802_REG_BUCK ## num ## DVS1,             \
+       .vsel_mask      = MAX77802_DVS_VSEL_MASK,                       \
+       .enable_reg     = MAX77802_REG_BUCK ## num ## CTRL,             \
+       .enable_mask    = MAX77802_OPMODE_MASK,                         \
+       .of_map_mode    = max77802_map_mode,                            \
+}
+
+/* BUCKS 2-4 */
+#define regulator_77802_desc_234_buck(num)     {               \
+       .name           = "BUCK"#num,                                   \
+       .of_match       = of_match_ptr("BUCK"#num),                     \
+       .regulators_node        = of_match_ptr("regulators"),           \
+       .id             = MAX77802_BUCK##num,                           \
+       .supply_name    = "inb"#num,                                    \
+       .ops            = &max77802_buck_234_ops,                       \
+       .type           = REGULATOR_VOLTAGE,                            \
+       .owner          = THIS_MODULE,                                  \
+       .min_uV         = 600000,                                       \
+       .uV_step        = 6250,                                         \
+       .ramp_delay     = MAX77802_RAMP_DELAY,                          \
+       .n_voltages     = 0x91,                                         \
+       .vsel_reg       = MAX77802_REG_BUCK ## num ## DVS1,             \
+       .vsel_mask      = MAX77802_DVS_VSEL_MASK,                       \
+       .enable_reg     = MAX77802_REG_BUCK ## num ## CTRL1,            \
+       .enable_mask    = MAX77802_OPMODE_MASK <<                       \
+                               MAX77802_OPMODE_BUCK234_SHIFT,          \
+       .of_map_mode    = max77802_map_mode,                            \
+}
+
+/* BUCK 5 */
+#define regulator_77802_desc_buck5(num)                {               \
+       .name           = "BUCK"#num,                                   \
+       .of_match       = of_match_ptr("BUCK"#num),                     \
+       .regulators_node        = of_match_ptr("regulators"),           \
+       .id             = MAX77802_BUCK##num,                           \
+       .supply_name    = "inb"#num,                                    \
+       .ops            = &max77802_buck_dvs_ops,                       \
+       .type           = REGULATOR_VOLTAGE,                            \
+       .owner          = THIS_MODULE,                                  \
+       .min_uV         = 750000,                                       \
+       .uV_step        = 50000,                                        \
+       .ramp_delay     = MAX77802_RAMP_DELAY,                          \
+       .n_voltages     = 1 << 6,                                       \
+       .vsel_reg       = MAX77802_REG_BUCK5OUT,                        \
+       .vsel_mask      = MAX77802_VSEL_MASK,                           \
+       .enable_reg     = MAX77802_REG_BUCK5CTRL,                       \
+       .enable_mask    = MAX77802_OPMODE_MASK,                         \
+       .of_map_mode    = max77802_map_mode,                            \
+}
+
+/* BUCKs 7-10 */
+#define regulator_77802_desc_buck7_10(num)     {               \
+       .name           = "BUCK"#num,                                   \
+       .of_match       = of_match_ptr("BUCK"#num),                     \
+       .regulators_node        = of_match_ptr("regulators"),           \
+       .id             = MAX77802_BUCK##num,                           \
+       .supply_name    = "inb"#num,                                    \
+       .ops            = &max77802_buck_dvs_ops,                       \
+       .type           = REGULATOR_VOLTAGE,                            \
+       .owner          = THIS_MODULE,                                  \
+       .min_uV         = 750000,                                       \
+       .uV_step        = 50000,                                        \
+       .ramp_delay     = MAX77802_RAMP_DELAY,                          \
+       .n_voltages     = 1 << 6,                                       \
+       .vsel_reg       = MAX77802_REG_BUCK7OUT + (num - 7) * 3,        \
+       .vsel_mask      = MAX77802_VSEL_MASK,                           \
+       .enable_reg     = MAX77802_REG_BUCK7CTRL + (num - 7) * 3,       \
+       .enable_mask    = MAX77802_OPMODE_MASK,                         \
+       .of_map_mode    = max77802_map_mode,                            \
+}
+
+static const struct regulator_desc regulators[] = {
+       regulator_77802_desc_16_buck(1),
+       regulator_77802_desc_234_buck(2),
+       regulator_77802_desc_234_buck(3),
+       regulator_77802_desc_234_buck(4),
+       regulator_77802_desc_buck5(5),
+       regulator_77802_desc_16_buck(6),
+       regulator_77802_desc_buck7_10(7),
+       regulator_77802_desc_buck7_10(8),
+       regulator_77802_desc_buck7_10(9),
+       regulator_77802_desc_buck7_10(10),
+       regulator_77802_desc_n_ldo(1, 10, 2),
+       regulator_77802_desc_n_ldo(2, 10, 1),
+       regulator_77802_desc_p_ldo(3, 3, 2),
+       regulator_77802_desc_p_ldo(4, 6, 1),
+       regulator_77802_desc_p_ldo(5, 3, 1),
+       regulator_77802_desc_p_ldo(6, 3, 1),
+       regulator_77802_desc_p_ldo(7, 3, 1),
+       regulator_77802_desc_n_ldo(8, 1, 1),
+       regulator_77802_desc_p_ldo(9, 5, 1),
+       regulator_77802_desc_p_ldo(10, 4, 1),
+       regulator_77802_desc_p_ldo(11, 4, 1),
+       regulator_77802_desc_p_ldo(12, 9, 1),
+       regulator_77802_desc_p_ldo(13, 4, 1),
+       regulator_77802_desc_p_ldo(14, 4, 1),
+       regulator_77802_desc_n_ldo(15, 1, 1),
+       regulator_77802_desc_n_ldo(17, 2, 1),
+       regulator_77802_desc_p_ldo(18, 7, 1),
+       regulator_77802_desc_p_ldo(19, 5, 1),
+       regulator_77802_desc_p_ldo(20, 7, 2),
+       regulator_77802_desc_p_ldo(21, 6, 2),
+       regulator_77802_desc_p_ldo(23, 9, 1),
+       regulator_77802_desc_p_ldo(24, 6, 1),
+       regulator_77802_desc_p_ldo(25, 9, 1),
+       regulator_77802_desc_p_ldo(26, 9, 1),
+       regulator_77802_desc_n_ldo(27, 2, 1),
+       regulator_77802_desc_p_ldo(28, 7, 1),
+       regulator_77802_desc_p_ldo(29, 7, 1),
+       regulator_77802_desc_n_ldo(30, 2, 1),
+       regulator_77802_desc_p_ldo(32, 9, 1),
+       regulator_77802_desc_p_ldo(33, 6, 1),
+       regulator_77802_desc_p_ldo(34, 9, 1),
+       regulator_77802_desc_n_ldo(35, 2, 1),
+};
+
+static int max77802_pmic_probe(struct platform_device *pdev)
+{
+       struct max77686_dev *iodev = dev_get_drvdata(pdev->dev.parent);
+       struct max77802_regulator_prv *max77802;
+       int i, val;
+       struct regulator_config config = { };
+
+       max77802 = devm_kzalloc(&pdev->dev,
+                               sizeof(struct max77802_regulator_prv),
+                               GFP_KERNEL);
+       if (!max77802)
+               return -ENOMEM;
+
+       config.dev = iodev->dev;
+       config.regmap = iodev->regmap;
+       config.driver_data = max77802;
+       platform_set_drvdata(pdev, max77802);
+
+       for (i = 0; i < MAX77802_REG_MAX; i++) {
+               struct regulator_dev *rdev;
+               int id = regulators[i].id;
+               int shift = max77802_get_opmode_shift(id);
+               int ret;
+
+               ret = regmap_read(iodev->regmap, regulators[i].enable_reg, &val);
+               if (ret < 0) {
+                       dev_warn(&pdev->dev,
+                               "cannot read current mode for %d\n", i);
+                       val = MAX77802_OPMODE_NORMAL;
+               } else {
+                       val = val >> shift & MAX77802_OPMODE_MASK;
+               }
+
+               /*
+                * If the regulator is disabled and the system warm rebooted,
+                * the hardware reports OFF as the regulator operating mode.
+                * Default to operating mode NORMAL in that case.
+                */
+               if (val == MAX77802_STATUS_OFF)
+                       max77802->opmode[id] = MAX77802_OPMODE_NORMAL;
+               else
+                       max77802->opmode[id] = val;
+
+               rdev = devm_regulator_register(&pdev->dev,
+                                              &regulators[i], &config);
+               if (IS_ERR(rdev)) {
+                       ret = PTR_ERR(rdev);
+                       dev_err(&pdev->dev,
+                               "regulator init failed for %d: %d\n", i, ret);
+                       return ret;
+               }
+       }
+
+       return 0;
+}
+
+static const struct platform_device_id max77802_pmic_id[] = {
+       {"max77802-pmic", 0},
+       { },
+};
+MODULE_DEVICE_TABLE(platform, max77802_pmic_id);
+
+static struct platform_driver max77802_pmic_driver = {
+       .driver = {
+               .name = "max77802-pmic",
+       },
+       .probe = max77802_pmic_probe,
+       .id_table = max77802_pmic_id,
+};
+
+module_platform_driver(max77802_pmic_driver);
+
+MODULE_DESCRIPTION("MAXIM 77802 Regulator Driver");
+MODULE_AUTHOR("Simon Glass <sjg@chromium.org>");
+MODULE_LICENSE("GPL");
diff --git a/drivers/regulator/max77802.c b/drivers/regulator/max77802.c
deleted file mode 100644 (file)
index c07ee13..0000000
+++ /dev/null
@@ -1,610 +0,0 @@
-/*
- * max77802.c - Regulator driver for the Maxim 77802
- *
- * Copyright (C) 2013-2014 Google, Inc
- * Simon Glass <sjg@chromium.org>
- *
- * Copyright (C) 2012 Samsung Electronics
- * Chiwoong Byun <woong.byun@smasung.com>
- * Jonghwa Lee <jonghwa3.lee@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.
- *
- * 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.
- *
- * This driver is based on max8997.c
- */
-
-#include <linux/kernel.h>
-#include <linux/bug.h>
-#include <linux/err.h>
-#include <linux/gpio.h>
-#include <linux/slab.h>
-#include <linux/gpio/consumer.h>
-#include <linux/module.h>
-#include <linux/platform_device.h>
-#include <linux/regulator/driver.h>
-#include <linux/regulator/machine.h>
-#include <linux/regulator/of_regulator.h>
-#include <linux/mfd/max77686.h>
-#include <linux/mfd/max77686-private.h>
-#include <dt-bindings/regulator/maxim,max77802.h>
-
-/* Default ramp delay in case it is not manually set */
-#define MAX77802_RAMP_DELAY            100000          /* uV/us */
-
-#define MAX77802_OPMODE_SHIFT_LDO      6
-#define MAX77802_OPMODE_BUCK234_SHIFT  4
-#define MAX77802_OPMODE_MASK           0x3
-
-#define MAX77802_VSEL_MASK             0x3F
-#define MAX77802_DVS_VSEL_MASK         0xFF
-
-#define MAX77802_RAMP_RATE_MASK_2BIT   0xC0
-#define MAX77802_RAMP_RATE_SHIFT_2BIT  6
-#define MAX77802_RAMP_RATE_MASK_4BIT   0xF0
-#define MAX77802_RAMP_RATE_SHIFT_4BIT  4
-
-#define MAX77802_STATUS_OFF            0x0
-#define MAX77802_OFF_PWRREQ            0x1
-#define MAX77802_LP_PWRREQ             0x2
-
-/* MAX77802 has two register formats: 2-bit and 4-bit */
-static const unsigned int ramp_table_77802_2bit[] = {
-       12500,
-       25000,
-       50000,
-       100000,
-};
-
-static unsigned int ramp_table_77802_4bit[] = {
-       1000,   2000,   3030,   4000,
-       5000,   5880,   7140,   8330,
-       9090,   10000,  11110,  12500,
-       16670,  25000,  50000,  100000,
-};
-
-struct max77802_regulator_prv {
-       /* Array indexed by regulator id */
-       unsigned int opmode[MAX77802_REG_MAX];
-};
-
-static inline unsigned int max77802_map_mode(unsigned int mode)
-{
-       return mode == MAX77802_OPMODE_NORMAL ?
-               REGULATOR_MODE_NORMAL : REGULATOR_MODE_STANDBY;
-}
-
-static int max77802_get_opmode_shift(int id)
-{
-       if (id == MAX77802_BUCK1 || (id >= MAX77802_BUCK5 &&
-                                    id <= MAX77802_BUCK10))
-               return 0;
-
-       if (id >= MAX77802_BUCK2 && id <= MAX77802_BUCK4)
-               return MAX77802_OPMODE_BUCK234_SHIFT;
-
-       if (id >= MAX77802_LDO1 && id <= MAX77802_LDO35)
-               return MAX77802_OPMODE_SHIFT_LDO;
-
-       return -EINVAL;
-}
-
-/**
- * max77802_set_suspend_disable - Disable the regulator during system suspend
- * @rdev: regulator to mark as disabled
- *
- * All regulators expect LDO 1, 3, 20 and 21 support OFF by PWRREQ.
- * Configure the regulator so the PMIC will turn it OFF during system suspend.
- */
-static int max77802_set_suspend_disable(struct regulator_dev *rdev)
-{
-       unsigned int val = MAX77802_OFF_PWRREQ;
-       struct max77802_regulator_prv *max77802 = rdev_get_drvdata(rdev);
-       int id = rdev_get_id(rdev);
-       int shift = max77802_get_opmode_shift(id);
-
-       max77802->opmode[id] = val;
-       return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
-                                 rdev->desc->enable_mask, val << shift);
-}
-
-/*
- * Some LDOs support Low Power Mode while the system is running.
- *
- * LDOs 1, 3, 20, 21.
- */
-static int max77802_set_mode(struct regulator_dev *rdev, unsigned int mode)
-{
-       struct max77802_regulator_prv *max77802 = rdev_get_drvdata(rdev);
-       int id = rdev_get_id(rdev);
-       unsigned int val;
-       int shift = max77802_get_opmode_shift(id);
-
-       switch (mode) {
-       case REGULATOR_MODE_STANDBY:
-               val = MAX77802_OPMODE_LP;       /* ON in Low Power Mode */
-               break;
-       case REGULATOR_MODE_NORMAL:
-               val = MAX77802_OPMODE_NORMAL;   /* ON in Normal Mode */
-               break;
-       default:
-               dev_warn(&rdev->dev, "%s: regulator mode: 0x%x not supported\n",
-                        rdev->desc->name, mode);
-               return -EINVAL;
-       }
-
-       max77802->opmode[id] = val;
-       return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
-                                 rdev->desc->enable_mask, val << shift);
-}
-
-static unsigned max77802_get_mode(struct regulator_dev *rdev)
-{
-       struct max77802_regulator_prv *max77802 = rdev_get_drvdata(rdev);
-       int id = rdev_get_id(rdev);
-
-       return max77802_map_mode(max77802->opmode[id]);
-}
-
-/**
- * max77802_set_suspend_mode - set regulator opmode when the system is suspended
- * @rdev: regulator to change mode
- * @mode: operating mode to be set
- *
- * Will set the operating mode for the regulators during system suspend.
- * This function is valid for the three different enable control logics:
- *
- * Enable Control Logic1 by PWRREQ (BUCK 2-4 and LDOs 2, 4-19, 22-35)
- * Enable Control Logic2 by PWRREQ (LDOs 1, 20, 21)
- * Enable Control Logic3 by PWRREQ (LDO 3)
- *
- * If setting the regulator mode fails, the function only warns but does
- * not return an error code to avoid the regulator core to stop setting
- * the operating mode for the remaining regulators.
- */
-static int max77802_set_suspend_mode(struct regulator_dev *rdev,
-                                    unsigned int mode)
-{
-       struct max77802_regulator_prv *max77802 = rdev_get_drvdata(rdev);
-       int id = rdev_get_id(rdev);
-       unsigned int val;
-       int shift = max77802_get_opmode_shift(id);
-
-       /*
-        * If the regulator has been disabled for suspend
-        * then is invalid to try setting a suspend mode.
-        */
-       if (max77802->opmode[id] == MAX77802_OFF_PWRREQ) {
-               dev_warn(&rdev->dev, "%s: is disabled, mode: 0x%x not set\n",
-                        rdev->desc->name, mode);
-               return 0;
-       }
-
-       switch (mode) {
-       case REGULATOR_MODE_STANDBY:
-               /*
-                * If the regulator opmode is normal then enable
-                * ON in Low Power Mode by PWRREQ. If the mode is
-                * already Low Power then no action is required.
-                */
-               if (max77802->opmode[id] == MAX77802_OPMODE_NORMAL)
-                       val = MAX77802_LP_PWRREQ;
-               else
-                       return 0;
-               break;
-       case REGULATOR_MODE_NORMAL:
-               /*
-                * If the regulator operating mode is Low Power then
-                * normal is not a valid opmode in suspend. If the
-                * mode is already normal then no action is required.
-                */
-               if (max77802->opmode[id] == MAX77802_OPMODE_LP)
-                       dev_warn(&rdev->dev, "%s: in Low Power: 0x%x invalid\n",
-                                rdev->desc->name, mode);
-               return 0;
-       default:
-               dev_warn(&rdev->dev, "%s: regulator mode: 0x%x not supported\n",
-                        rdev->desc->name, mode);
-               return -EINVAL;
-       }
-
-       return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
-                                 rdev->desc->enable_mask, val << shift);
-}
-
-static int max77802_enable(struct regulator_dev *rdev)
-{
-       struct max77802_regulator_prv *max77802 = rdev_get_drvdata(rdev);
-       int id = rdev_get_id(rdev);
-       int shift = max77802_get_opmode_shift(id);
-
-       if (max77802->opmode[id] == MAX77802_OFF_PWRREQ)
-               max77802->opmode[id] = MAX77802_OPMODE_NORMAL;
-
-       return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
-                                 rdev->desc->enable_mask,
-                                 max77802->opmode[id] << shift);
-}
-
-static int max77802_find_ramp_value(struct regulator_dev *rdev,
-                                   const unsigned int limits[], int size,
-                                   unsigned int ramp_delay)
-{
-       int i;
-
-       for (i = 0; i < size; i++) {
-               if (ramp_delay <= limits[i])
-                       return i;
-       }
-
-       /* Use maximum value for no ramp control */
-       dev_warn(&rdev->dev, "%s: ramp_delay: %d not supported, setting 100000\n",
-                rdev->desc->name, ramp_delay);
-       return size - 1;
-}
-
-/* Used for BUCKs 2-4 */
-static int max77802_set_ramp_delay_2bit(struct regulator_dev *rdev,
-                                       int ramp_delay)
-{
-       int id = rdev_get_id(rdev);
-       unsigned int ramp_value;
-
-       if (id > MAX77802_BUCK4) {
-                       dev_warn(&rdev->dev,
-                                "%s: regulator: ramp delay not supported\n",
-                                rdev->desc->name);
-               return -EINVAL;
-       }
-       ramp_value = max77802_find_ramp_value(rdev, ramp_table_77802_2bit,
-                               ARRAY_SIZE(ramp_table_77802_2bit), ramp_delay);
-
-       return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
-                                 MAX77802_RAMP_RATE_MASK_2BIT,
-                                 ramp_value << MAX77802_RAMP_RATE_SHIFT_2BIT);
-}
-
-/* For BUCK1, 6 */
-static int max77802_set_ramp_delay_4bit(struct regulator_dev *rdev,
-                                           int ramp_delay)
-{
-       unsigned int ramp_value;
-
-       ramp_value = max77802_find_ramp_value(rdev, ramp_table_77802_4bit,
-                               ARRAY_SIZE(ramp_table_77802_4bit), ramp_delay);
-
-       return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
-                                 MAX77802_RAMP_RATE_MASK_4BIT,
-                                 ramp_value << MAX77802_RAMP_RATE_SHIFT_4BIT);
-}
-
-/*
- * LDOs 2, 4-19, 22-35
- */
-static struct regulator_ops max77802_ldo_ops_logic1 = {
-       .list_voltage           = regulator_list_voltage_linear,
-       .map_voltage            = regulator_map_voltage_linear,
-       .is_enabled             = regulator_is_enabled_regmap,
-       .enable                 = max77802_enable,
-       .disable                = regulator_disable_regmap,
-       .get_voltage_sel        = regulator_get_voltage_sel_regmap,
-       .set_voltage_sel        = regulator_set_voltage_sel_regmap,
-       .set_voltage_time_sel   = regulator_set_voltage_time_sel,
-       .set_suspend_disable    = max77802_set_suspend_disable,
-       .set_suspend_mode       = max77802_set_suspend_mode,
-};
-
-/*
- * LDOs 1, 20, 21, 3
- */
-static struct regulator_ops max77802_ldo_ops_logic2 = {
-       .list_voltage           = regulator_list_voltage_linear,
-       .map_voltage            = regulator_map_voltage_linear,
-       .is_enabled             = regulator_is_enabled_regmap,
-       .enable                 = max77802_enable,
-       .disable                = regulator_disable_regmap,
-       .get_voltage_sel        = regulator_get_voltage_sel_regmap,
-       .set_voltage_sel        = regulator_set_voltage_sel_regmap,
-       .set_voltage_time_sel   = regulator_set_voltage_time_sel,
-       .set_mode               = max77802_set_mode,
-       .get_mode               = max77802_get_mode,
-       .set_suspend_mode       = max77802_set_suspend_mode,
-};
-
-/* BUCKS 1, 6 */
-static struct regulator_ops max77802_buck_16_dvs_ops = {
-       .list_voltage           = regulator_list_voltage_linear,
-       .map_voltage            = regulator_map_voltage_linear,
-       .is_enabled             = regulator_is_enabled_regmap,
-       .enable                 = max77802_enable,
-       .disable                = regulator_disable_regmap,
-       .get_voltage_sel        = regulator_get_voltage_sel_regmap,
-       .set_voltage_sel        = regulator_set_voltage_sel_regmap,
-       .set_voltage_time_sel   = regulator_set_voltage_time_sel,
-       .set_ramp_delay         = max77802_set_ramp_delay_4bit,
-       .set_suspend_disable    = max77802_set_suspend_disable,
-};
-
-/* BUCKs 2-4 */
-static struct regulator_ops max77802_buck_234_ops = {
-       .list_voltage           = regulator_list_voltage_linear,
-       .map_voltage            = regulator_map_voltage_linear,
-       .is_enabled             = regulator_is_enabled_regmap,
-       .enable                 = max77802_enable,
-       .disable                = regulator_disable_regmap,
-       .get_voltage_sel        = regulator_get_voltage_sel_regmap,
-       .set_voltage_sel        = regulator_set_voltage_sel_regmap,
-       .set_voltage_time_sel   = regulator_set_voltage_time_sel,
-       .set_ramp_delay         = max77802_set_ramp_delay_2bit,
-       .set_suspend_disable    = max77802_set_suspend_disable,
-       .set_suspend_mode       = max77802_set_suspend_mode,
-};
-
-/* BUCKs 5, 7-10 */
-static struct regulator_ops max77802_buck_dvs_ops = {
-       .list_voltage           = regulator_list_voltage_linear,
-       .map_voltage            = regulator_map_voltage_linear,
-       .is_enabled             = regulator_is_enabled_regmap,
-       .enable                 = max77802_enable,
-       .disable                = regulator_disable_regmap,
-       .get_voltage_sel        = regulator_get_voltage_sel_regmap,
-       .set_voltage_sel        = regulator_set_voltage_sel_regmap,
-       .set_voltage_time_sel   = regulator_set_voltage_time_sel,
-       .set_ramp_delay         = max77802_set_ramp_delay_2bit,
-       .set_suspend_disable    = max77802_set_suspend_disable,
-};
-
-/* LDOs 3-7, 9-14, 18-26, 28, 29, 32-34 */
-#define regulator_77802_desc_p_ldo(num, supply, log)   {               \
-       .name           = "LDO"#num,                                    \
-       .of_match       = of_match_ptr("LDO"#num),                      \
-       .regulators_node        = of_match_ptr("regulators"),           \
-       .id             = MAX77802_LDO##num,                            \
-       .supply_name    = "inl"#supply,                                 \
-       .ops            = &max77802_ldo_ops_logic##log,                 \
-       .type           = REGULATOR_VOLTAGE,                            \
-       .owner          = THIS_MODULE,                                  \
-       .min_uV         = 800000,                                       \
-       .uV_step        = 50000,                                        \
-       .ramp_delay     = MAX77802_RAMP_DELAY,                          \
-       .n_voltages     = 1 << 6,                                       \
-       .vsel_reg       = MAX77802_REG_LDO1CTRL1 + num - 1,             \
-       .vsel_mask      = MAX77802_VSEL_MASK,                           \
-       .enable_reg     = MAX77802_REG_LDO1CTRL1 + num - 1,             \
-       .enable_mask    = MAX77802_OPMODE_MASK << MAX77802_OPMODE_SHIFT_LDO, \
-       .of_map_mode    = max77802_map_mode,                            \
-}
-
-/* LDOs 1, 2, 8, 15, 17, 27, 30, 35 */
-#define regulator_77802_desc_n_ldo(num, supply, log)   {               \
-       .name           = "LDO"#num,                                    \
-       .of_match       = of_match_ptr("LDO"#num),                      \
-       .regulators_node        = of_match_ptr("regulators"),           \
-       .id             = MAX77802_LDO##num,                            \
-       .supply_name    = "inl"#supply,                                 \
-       .ops            = &max77802_ldo_ops_logic##log,                 \
-       .type           = REGULATOR_VOLTAGE,                            \
-       .owner          = THIS_MODULE,                                  \
-       .min_uV         = 800000,                                       \
-       .uV_step        = 25000,                                        \
-       .ramp_delay     = MAX77802_RAMP_DELAY,                          \
-       .n_voltages     = 1 << 6,                                       \
-       .vsel_reg       = MAX77802_REG_LDO1CTRL1 + num - 1,             \
-       .vsel_mask      = MAX77802_VSEL_MASK,                           \
-       .enable_reg     = MAX77802_REG_LDO1CTRL1 + num - 1,             \
-       .enable_mask    = MAX77802_OPMODE_MASK << MAX77802_OPMODE_SHIFT_LDO, \
-       .of_map_mode    = max77802_map_mode,                            \
-}
-
-/* BUCKs 1, 6 */
-#define regulator_77802_desc_16_buck(num)      {               \
-       .name           = "BUCK"#num,                                   \
-       .of_match       = of_match_ptr("BUCK"#num),                     \
-       .regulators_node        = of_match_ptr("regulators"),           \
-       .id             = MAX77802_BUCK##num,                           \
-       .supply_name    = "inb"#num,                                    \
-       .ops            = &max77802_buck_16_dvs_ops,                    \
-       .type           = REGULATOR_VOLTAGE,                            \
-       .owner          = THIS_MODULE,                                  \
-       .min_uV         = 612500,                                       \
-       .uV_step        = 6250,                                         \
-       .ramp_delay     = MAX77802_RAMP_DELAY,                          \
-       .n_voltages     = 1 << 8,                                       \
-       .vsel_reg       = MAX77802_REG_BUCK ## num ## DVS1,             \
-       .vsel_mask      = MAX77802_DVS_VSEL_MASK,                       \
-       .enable_reg     = MAX77802_REG_BUCK ## num ## CTRL,             \
-       .enable_mask    = MAX77802_OPMODE_MASK,                         \
-       .of_map_mode    = max77802_map_mode,                            \
-}
-
-/* BUCKS 2-4 */
-#define regulator_77802_desc_234_buck(num)     {               \
-       .name           = "BUCK"#num,                                   \
-       .of_match       = of_match_ptr("BUCK"#num),                     \
-       .regulators_node        = of_match_ptr("regulators"),           \
-       .id             = MAX77802_BUCK##num,                           \
-       .supply_name    = "inb"#num,                                    \
-       .ops            = &max77802_buck_234_ops,                       \
-       .type           = REGULATOR_VOLTAGE,                            \
-       .owner          = THIS_MODULE,                                  \
-       .min_uV         = 600000,                                       \
-       .uV_step        = 6250,                                         \
-       .ramp_delay     = MAX77802_RAMP_DELAY,                          \
-       .n_voltages     = 0x91,                                         \
-       .vsel_reg       = MAX77802_REG_BUCK ## num ## DVS1,             \
-       .vsel_mask      = MAX77802_DVS_VSEL_MASK,                       \
-       .enable_reg     = MAX77802_REG_BUCK ## num ## CTRL1,            \
-       .enable_mask    = MAX77802_OPMODE_MASK <<                       \
-                               MAX77802_OPMODE_BUCK234_SHIFT,          \
-       .of_map_mode    = max77802_map_mode,                            \
-}
-
-/* BUCK 5 */
-#define regulator_77802_desc_buck5(num)                {               \
-       .name           = "BUCK"#num,                                   \
-       .of_match       = of_match_ptr("BUCK"#num),                     \
-       .regulators_node        = of_match_ptr("regulators"),           \
-       .id             = MAX77802_BUCK##num,                           \
-       .supply_name    = "inb"#num,                                    \
-       .ops            = &max77802_buck_dvs_ops,                       \
-       .type           = REGULATOR_VOLTAGE,                            \
-       .owner          = THIS_MODULE,                                  \
-       .min_uV         = 750000,                                       \
-       .uV_step        = 50000,                                        \
-       .ramp_delay     = MAX77802_RAMP_DELAY,                          \
-       .n_voltages     = 1 << 6,                                       \
-       .vsel_reg       = MAX77802_REG_BUCK5OUT,                        \
-       .vsel_mask      = MAX77802_VSEL_MASK,                           \
-       .enable_reg     = MAX77802_REG_BUCK5CTRL,                       \
-       .enable_mask    = MAX77802_OPMODE_MASK,                         \
-       .of_map_mode    = max77802_map_mode,                            \
-}
-
-/* BUCKs 7-10 */
-#define regulator_77802_desc_buck7_10(num)     {               \
-       .name           = "BUCK"#num,                                   \
-       .of_match       = of_match_ptr("BUCK"#num),                     \
-       .regulators_node        = of_match_ptr("regulators"),           \
-       .id             = MAX77802_BUCK##num,                           \
-       .supply_name    = "inb"#num,                                    \
-       .ops            = &max77802_buck_dvs_ops,                       \
-       .type           = REGULATOR_VOLTAGE,                            \
-       .owner          = THIS_MODULE,                                  \
-       .min_uV         = 750000,                                       \
-       .uV_step        = 50000,                                        \
-       .ramp_delay     = MAX77802_RAMP_DELAY,                          \
-       .n_voltages     = 1 << 6,                                       \
-       .vsel_reg       = MAX77802_REG_BUCK7OUT + (num - 7) * 3,        \
-       .vsel_mask      = MAX77802_VSEL_MASK,                           \
-       .enable_reg     = MAX77802_REG_BUCK7CTRL + (num - 7) * 3,       \
-       .enable_mask    = MAX77802_OPMODE_MASK,                         \
-       .of_map_mode    = max77802_map_mode,                            \
-}
-
-static const struct regulator_desc regulators[] = {
-       regulator_77802_desc_16_buck(1),
-       regulator_77802_desc_234_buck(2),
-       regulator_77802_desc_234_buck(3),
-       regulator_77802_desc_234_buck(4),
-       regulator_77802_desc_buck5(5),
-       regulator_77802_desc_16_buck(6),
-       regulator_77802_desc_buck7_10(7),
-       regulator_77802_desc_buck7_10(8),
-       regulator_77802_desc_buck7_10(9),
-       regulator_77802_desc_buck7_10(10),
-       regulator_77802_desc_n_ldo(1, 10, 2),
-       regulator_77802_desc_n_ldo(2, 10, 1),
-       regulator_77802_desc_p_ldo(3, 3, 2),
-       regulator_77802_desc_p_ldo(4, 6, 1),
-       regulator_77802_desc_p_ldo(5, 3, 1),
-       regulator_77802_desc_p_ldo(6, 3, 1),
-       regulator_77802_desc_p_ldo(7, 3, 1),
-       regulator_77802_desc_n_ldo(8, 1, 1),
-       regulator_77802_desc_p_ldo(9, 5, 1),
-       regulator_77802_desc_p_ldo(10, 4, 1),
-       regulator_77802_desc_p_ldo(11, 4, 1),
-       regulator_77802_desc_p_ldo(12, 9, 1),
-       regulator_77802_desc_p_ldo(13, 4, 1),
-       regulator_77802_desc_p_ldo(14, 4, 1),
-       regulator_77802_desc_n_ldo(15, 1, 1),
-       regulator_77802_desc_n_ldo(17, 2, 1),
-       regulator_77802_desc_p_ldo(18, 7, 1),
-       regulator_77802_desc_p_ldo(19, 5, 1),
-       regulator_77802_desc_p_ldo(20, 7, 2),
-       regulator_77802_desc_p_ldo(21, 6, 2),
-       regulator_77802_desc_p_ldo(23, 9, 1),
-       regulator_77802_desc_p_ldo(24, 6, 1),
-       regulator_77802_desc_p_ldo(25, 9, 1),
-       regulator_77802_desc_p_ldo(26, 9, 1),
-       regulator_77802_desc_n_ldo(27, 2, 1),
-       regulator_77802_desc_p_ldo(28, 7, 1),
-       regulator_77802_desc_p_ldo(29, 7, 1),
-       regulator_77802_desc_n_ldo(30, 2, 1),
-       regulator_77802_desc_p_ldo(32, 9, 1),
-       regulator_77802_desc_p_ldo(33, 6, 1),
-       regulator_77802_desc_p_ldo(34, 9, 1),
-       regulator_77802_desc_n_ldo(35, 2, 1),
-};
-
-static int max77802_pmic_probe(struct platform_device *pdev)
-{
-       struct max77686_dev *iodev = dev_get_drvdata(pdev->dev.parent);
-       struct max77802_regulator_prv *max77802;
-       int i, val;
-       struct regulator_config config = { };
-
-       max77802 = devm_kzalloc(&pdev->dev,
-                               sizeof(struct max77802_regulator_prv),
-                               GFP_KERNEL);
-       if (!max77802)
-               return -ENOMEM;
-
-       config.dev = iodev->dev;
-       config.regmap = iodev->regmap;
-       config.driver_data = max77802;
-       platform_set_drvdata(pdev, max77802);
-
-       for (i = 0; i < MAX77802_REG_MAX; i++) {
-               struct regulator_dev *rdev;
-               int id = regulators[i].id;
-               int shift = max77802_get_opmode_shift(id);
-               int ret;
-
-               ret = regmap_read(iodev->regmap, regulators[i].enable_reg, &val);
-               if (ret < 0) {
-                       dev_warn(&pdev->dev,
-                               "cannot read current mode for %d\n", i);
-                       val = MAX77802_OPMODE_NORMAL;
-               } else {
-                       val = val >> shift & MAX77802_OPMODE_MASK;
-               }
-
-               /*
-                * If the regulator is disabled and the system warm rebooted,
-                * the hardware reports OFF as the regulator operating mode.
-                * Default to operating mode NORMAL in that case.
-                */
-               if (val == MAX77802_STATUS_OFF)
-                       max77802->opmode[id] = MAX77802_OPMODE_NORMAL;
-               else
-                       max77802->opmode[id] = val;
-
-               rdev = devm_regulator_register(&pdev->dev,
-                                              &regulators[i], &config);
-               if (IS_ERR(rdev)) {
-                       ret = PTR_ERR(rdev);
-                       dev_err(&pdev->dev,
-                               "regulator init failed for %d: %d\n", i, ret);
-                       return ret;
-               }
-       }
-
-       return 0;
-}
-
-static const struct platform_device_id max77802_pmic_id[] = {
-       {"max77802-pmic", 0},
-       { },
-};
-MODULE_DEVICE_TABLE(platform, max77802_pmic_id);
-
-static struct platform_driver max77802_pmic_driver = {
-       .driver = {
-               .name = "max77802-pmic",
-       },
-       .probe = max77802_pmic_probe,
-       .id_table = max77802_pmic_id,
-};
-
-module_platform_driver(max77802_pmic_driver);
-
-MODULE_DESCRIPTION("MAXIM 77802 Regulator Driver");
-MODULE_AUTHOR("Simon Glass <sjg@chromium.org>");
-MODULE_LICENSE("GPL");