Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 // Copyright (C) 2019 ROHM Semiconductors
0003 // bd71828-regulator.c ROHM BD71828GW-DS1 regulator driver
0004 //
0005 
0006 #include <linux/delay.h>
0007 #include <linux/err.h>
0008 #include <linux/gpio.h>
0009 #include <linux/interrupt.h>
0010 #include <linux/kernel.h>
0011 #include <linux/mfd/rohm-bd71828.h>
0012 #include <linux/module.h>
0013 #include <linux/of.h>
0014 #include <linux/platform_device.h>
0015 #include <linux/regmap.h>
0016 #include <linux/regulator/driver.h>
0017 #include <linux/regulator/machine.h>
0018 #include <linux/regulator/of_regulator.h>
0019 
0020 struct reg_init {
0021     unsigned int reg;
0022     unsigned int mask;
0023     unsigned int val;
0024 };
0025 struct bd71828_regulator_data {
0026     struct regulator_desc desc;
0027     const struct rohm_dvs_config dvs;
0028     const struct reg_init *reg_inits;
0029     int reg_init_amnt;
0030 };
0031 
0032 static const struct reg_init buck1_inits[] = {
0033     /*
0034      * DVS Buck voltages can be changed by register values or via GPIO.
0035      * Use register accesses by default.
0036      */
0037     {
0038         .reg = BD71828_REG_PS_CTRL_1,
0039         .mask = BD71828_MASK_DVS_BUCK1_CTRL,
0040         .val = BD71828_DVS_BUCK1_CTRL_I2C,
0041     },
0042 };
0043 
0044 static const struct reg_init buck2_inits[] = {
0045     {
0046         .reg = BD71828_REG_PS_CTRL_1,
0047         .mask = BD71828_MASK_DVS_BUCK2_CTRL,
0048         .val = BD71828_DVS_BUCK2_CTRL_I2C,
0049     },
0050 };
0051 
0052 static const struct reg_init buck6_inits[] = {
0053     {
0054         .reg = BD71828_REG_PS_CTRL_1,
0055         .mask = BD71828_MASK_DVS_BUCK6_CTRL,
0056         .val = BD71828_DVS_BUCK6_CTRL_I2C,
0057     },
0058 };
0059 
0060 static const struct reg_init buck7_inits[] = {
0061     {
0062         .reg = BD71828_REG_PS_CTRL_1,
0063         .mask = BD71828_MASK_DVS_BUCK7_CTRL,
0064         .val = BD71828_DVS_BUCK7_CTRL_I2C,
0065     },
0066 };
0067 
0068 static const struct linear_range bd71828_buck1267_volts[] = {
0069     REGULATOR_LINEAR_RANGE(500000, 0x00, 0xef, 6250),
0070     REGULATOR_LINEAR_RANGE(2000000, 0xf0, 0xff, 0),
0071 };
0072 
0073 static const struct linear_range bd71828_buck3_volts[] = {
0074     REGULATOR_LINEAR_RANGE(1200000, 0x00, 0x0f, 50000),
0075     REGULATOR_LINEAR_RANGE(2000000, 0x10, 0x1f, 0),
0076 };
0077 
0078 static const struct linear_range bd71828_buck4_volts[] = {
0079     REGULATOR_LINEAR_RANGE(1000000, 0x00, 0x1f, 25000),
0080     REGULATOR_LINEAR_RANGE(1800000, 0x20, 0x3f, 0),
0081 };
0082 
0083 static const struct linear_range bd71828_buck5_volts[] = {
0084     REGULATOR_LINEAR_RANGE(2500000, 0x00, 0x0f, 50000),
0085     REGULATOR_LINEAR_RANGE(3300000, 0x10, 0x1f, 0),
0086 };
0087 
0088 static const struct linear_range bd71828_ldo_volts[] = {
0089     REGULATOR_LINEAR_RANGE(800000, 0x00, 0x31, 50000),
0090     REGULATOR_LINEAR_RANGE(3300000, 0x32, 0x3f, 0),
0091 };
0092 
0093 static const unsigned int bd71828_ramp_delay[] = { 2500, 5000, 10000, 20000 };
0094 
0095 static int buck_set_hw_dvs_levels(struct device_node *np,
0096                   const struct regulator_desc *desc,
0097                   struct regulator_config *cfg)
0098 {
0099     struct bd71828_regulator_data *data;
0100 
0101     data = container_of(desc, struct bd71828_regulator_data, desc);
0102 
0103     return rohm_regulator_set_dvs_levels(&data->dvs, np, desc, cfg->regmap);
0104 }
0105 
0106 static int ldo6_parse_dt(struct device_node *np,
0107              const struct regulator_desc *desc,
0108              struct regulator_config *cfg)
0109 {
0110     int ret, i;
0111     uint32_t uv = 0;
0112     unsigned int en;
0113     struct regmap *regmap = cfg->regmap;
0114     static const char * const props[] = { "rohm,dvs-run-voltage",
0115                           "rohm,dvs-idle-voltage",
0116                           "rohm,dvs-suspend-voltage",
0117                           "rohm,dvs-lpsr-voltage" };
0118     unsigned int mask[] = { BD71828_MASK_RUN_EN, BD71828_MASK_IDLE_EN,
0119                    BD71828_MASK_SUSP_EN, BD71828_MASK_LPSR_EN };
0120 
0121     for (i = 0; i < ARRAY_SIZE(props); i++) {
0122         ret = of_property_read_u32(np, props[i], &uv);
0123         if (ret) {
0124             if (ret != -EINVAL)
0125                 return ret;
0126             continue;
0127         }
0128         if (uv)
0129             en = 0xffffffff;
0130         else
0131             en = 0;
0132 
0133         ret = regmap_update_bits(regmap, desc->enable_reg, mask[i], en);
0134         if (ret)
0135             return ret;
0136     }
0137     return 0;
0138 }
0139 
0140 static const struct regulator_ops bd71828_buck_ops = {
0141     .enable = regulator_enable_regmap,
0142     .disable = regulator_disable_regmap,
0143     .is_enabled = regulator_is_enabled_regmap,
0144     .list_voltage = regulator_list_voltage_linear_range,
0145     .set_voltage_sel = regulator_set_voltage_sel_regmap,
0146     .get_voltage_sel = regulator_get_voltage_sel_regmap,
0147 };
0148 
0149 static const struct regulator_ops bd71828_dvs_buck_ops = {
0150     .enable = regulator_enable_regmap,
0151     .disable = regulator_disable_regmap,
0152     .is_enabled = regulator_is_enabled_regmap,
0153     .list_voltage = regulator_list_voltage_linear_range,
0154     .set_voltage_sel = regulator_set_voltage_sel_regmap,
0155     .get_voltage_sel = regulator_get_voltage_sel_regmap,
0156     .set_voltage_time_sel = regulator_set_voltage_time_sel,
0157     .set_ramp_delay = regulator_set_ramp_delay_regmap,
0158 };
0159 
0160 static const struct regulator_ops bd71828_ldo_ops = {
0161     .enable = regulator_enable_regmap,
0162     .disable = regulator_disable_regmap,
0163     .is_enabled = regulator_is_enabled_regmap,
0164     .list_voltage = regulator_list_voltage_linear_range,
0165     .set_voltage_sel = regulator_set_voltage_sel_regmap,
0166     .get_voltage_sel = regulator_get_voltage_sel_regmap,
0167 };
0168 
0169 static const struct regulator_ops bd71828_ldo6_ops = {
0170     .enable = regulator_enable_regmap,
0171     .disable = regulator_disable_regmap,
0172     .is_enabled = regulator_is_enabled_regmap,
0173 };
0174 
0175 static const struct bd71828_regulator_data bd71828_rdata[] = {
0176     {
0177         .desc = {
0178             .name = "buck1",
0179             .of_match = of_match_ptr("BUCK1"),
0180             .regulators_node = of_match_ptr("regulators"),
0181             .id = BD71828_BUCK1,
0182             .ops = &bd71828_dvs_buck_ops,
0183             .type = REGULATOR_VOLTAGE,
0184             .linear_ranges = bd71828_buck1267_volts,
0185             .n_linear_ranges = ARRAY_SIZE(bd71828_buck1267_volts),
0186             .n_voltages = BD71828_BUCK1267_VOLTS,
0187             .enable_reg = BD71828_REG_BUCK1_EN,
0188             .enable_mask = BD71828_MASK_RUN_EN,
0189             .vsel_reg = BD71828_REG_BUCK1_VOLT,
0190             .vsel_mask = BD71828_MASK_BUCK1267_VOLT,
0191             .ramp_delay_table = bd71828_ramp_delay,
0192             .n_ramp_values = ARRAY_SIZE(bd71828_ramp_delay),
0193             .ramp_reg = BD71828_REG_BUCK1_MODE,
0194             .ramp_mask = BD71828_MASK_RAMP_DELAY,
0195             .owner = THIS_MODULE,
0196             .of_parse_cb = buck_set_hw_dvs_levels,
0197         },
0198         .dvs = {
0199             .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
0200                      ROHM_DVS_LEVEL_SUSPEND |
0201                      ROHM_DVS_LEVEL_LPSR,
0202             .run_reg = BD71828_REG_BUCK1_VOLT,
0203             .run_mask = BD71828_MASK_BUCK1267_VOLT,
0204             .idle_reg = BD71828_REG_BUCK1_IDLE_VOLT,
0205             .idle_mask = BD71828_MASK_BUCK1267_VOLT,
0206             .idle_on_mask = BD71828_MASK_IDLE_EN,
0207             .suspend_reg = BD71828_REG_BUCK1_SUSP_VOLT,
0208             .suspend_mask = BD71828_MASK_BUCK1267_VOLT,
0209             .suspend_on_mask = BD71828_MASK_SUSP_EN,
0210             .lpsr_on_mask = BD71828_MASK_LPSR_EN,
0211             /*
0212              * LPSR voltage is same as SUSPEND voltage. Allow
0213              * setting it so that regulator can be set enabled at
0214              * LPSR state
0215              */
0216             .lpsr_reg = BD71828_REG_BUCK1_SUSP_VOLT,
0217             .lpsr_mask = BD71828_MASK_BUCK1267_VOLT,
0218         },
0219         .reg_inits = buck1_inits,
0220         .reg_init_amnt = ARRAY_SIZE(buck1_inits),
0221     },
0222     {
0223         .desc = {
0224             .name = "buck2",
0225             .of_match = of_match_ptr("BUCK2"),
0226             .regulators_node = of_match_ptr("regulators"),
0227             .id = BD71828_BUCK2,
0228             .ops = &bd71828_dvs_buck_ops,
0229             .type = REGULATOR_VOLTAGE,
0230             .linear_ranges = bd71828_buck1267_volts,
0231             .n_linear_ranges = ARRAY_SIZE(bd71828_buck1267_volts),
0232             .n_voltages = BD71828_BUCK1267_VOLTS,
0233             .enable_reg = BD71828_REG_BUCK2_EN,
0234             .enable_mask = BD71828_MASK_RUN_EN,
0235             .vsel_reg = BD71828_REG_BUCK2_VOLT,
0236             .vsel_mask = BD71828_MASK_BUCK1267_VOLT,
0237             .ramp_delay_table = bd71828_ramp_delay,
0238             .n_ramp_values = ARRAY_SIZE(bd71828_ramp_delay),
0239             .ramp_reg = BD71828_REG_BUCK2_MODE,
0240             .ramp_mask = BD71828_MASK_RAMP_DELAY,
0241             .owner = THIS_MODULE,
0242             .of_parse_cb = buck_set_hw_dvs_levels,
0243         },
0244         .dvs = {
0245             .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
0246                      ROHM_DVS_LEVEL_SUSPEND |
0247                      ROHM_DVS_LEVEL_LPSR,
0248             .run_reg = BD71828_REG_BUCK2_VOLT,
0249             .run_mask = BD71828_MASK_BUCK1267_VOLT,
0250             .idle_reg = BD71828_REG_BUCK2_IDLE_VOLT,
0251             .idle_mask = BD71828_MASK_BUCK1267_VOLT,
0252             .idle_on_mask = BD71828_MASK_IDLE_EN,
0253             .suspend_reg = BD71828_REG_BUCK2_SUSP_VOLT,
0254             .suspend_mask = BD71828_MASK_BUCK1267_VOLT,
0255             .suspend_on_mask = BD71828_MASK_SUSP_EN,
0256             .lpsr_on_mask = BD71828_MASK_LPSR_EN,
0257             .lpsr_reg = BD71828_REG_BUCK2_SUSP_VOLT,
0258             .lpsr_mask = BD71828_MASK_BUCK1267_VOLT,
0259         },
0260         .reg_inits = buck2_inits,
0261         .reg_init_amnt = ARRAY_SIZE(buck2_inits),
0262     },
0263     {
0264         .desc = {
0265             .name = "buck3",
0266             .of_match = of_match_ptr("BUCK3"),
0267             .regulators_node = of_match_ptr("regulators"),
0268             .id = BD71828_BUCK3,
0269             .ops = &bd71828_buck_ops,
0270             .type = REGULATOR_VOLTAGE,
0271             .linear_ranges = bd71828_buck3_volts,
0272             .n_linear_ranges = ARRAY_SIZE(bd71828_buck3_volts),
0273             .n_voltages = BD71828_BUCK3_VOLTS,
0274             .enable_reg = BD71828_REG_BUCK3_EN,
0275             .enable_mask = BD71828_MASK_RUN_EN,
0276             .vsel_reg = BD71828_REG_BUCK3_VOLT,
0277             .vsel_mask = BD71828_MASK_BUCK3_VOLT,
0278             .owner = THIS_MODULE,
0279             .of_parse_cb = buck_set_hw_dvs_levels,
0280         },
0281         .dvs = {
0282             /*
0283              * BUCK3 only supports single voltage for all states.
0284              * voltage can be individually enabled for each state
0285              * though => allow setting all states to support
0286              * enabling power rail on different states.
0287              */
0288             .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
0289                      ROHM_DVS_LEVEL_SUSPEND |
0290                      ROHM_DVS_LEVEL_LPSR,
0291             .run_reg = BD71828_REG_BUCK3_VOLT,
0292             .idle_reg = BD71828_REG_BUCK3_VOLT,
0293             .suspend_reg = BD71828_REG_BUCK3_VOLT,
0294             .lpsr_reg = BD71828_REG_BUCK3_VOLT,
0295             .run_mask = BD71828_MASK_BUCK3_VOLT,
0296             .idle_mask = BD71828_MASK_BUCK3_VOLT,
0297             .suspend_mask = BD71828_MASK_BUCK3_VOLT,
0298             .lpsr_mask = BD71828_MASK_BUCK3_VOLT,
0299             .idle_on_mask = BD71828_MASK_IDLE_EN,
0300             .suspend_on_mask = BD71828_MASK_SUSP_EN,
0301             .lpsr_on_mask = BD71828_MASK_LPSR_EN,
0302         },
0303     },
0304     {
0305         .desc = {
0306             .name = "buck4",
0307             .of_match = of_match_ptr("BUCK4"),
0308             .regulators_node = of_match_ptr("regulators"),
0309             .id = BD71828_BUCK4,
0310             .ops = &bd71828_buck_ops,
0311             .type = REGULATOR_VOLTAGE,
0312             .linear_ranges = bd71828_buck4_volts,
0313             .n_linear_ranges = ARRAY_SIZE(bd71828_buck4_volts),
0314             .n_voltages = BD71828_BUCK4_VOLTS,
0315             .enable_reg = BD71828_REG_BUCK4_EN,
0316             .enable_mask = BD71828_MASK_RUN_EN,
0317             .vsel_reg = BD71828_REG_BUCK4_VOLT,
0318             .vsel_mask = BD71828_MASK_BUCK4_VOLT,
0319             .owner = THIS_MODULE,
0320             .of_parse_cb = buck_set_hw_dvs_levels,
0321         },
0322         .dvs = {
0323             /*
0324              * BUCK4 only supports single voltage for all states.
0325              * voltage can be individually enabled for each state
0326              * though => allow setting all states to support
0327              * enabling power rail on different states.
0328              */
0329             .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
0330                      ROHM_DVS_LEVEL_SUSPEND |
0331                      ROHM_DVS_LEVEL_LPSR,
0332             .run_reg = BD71828_REG_BUCK4_VOLT,
0333             .idle_reg = BD71828_REG_BUCK4_VOLT,
0334             .suspend_reg = BD71828_REG_BUCK4_VOLT,
0335             .lpsr_reg = BD71828_REG_BUCK4_VOLT,
0336             .run_mask = BD71828_MASK_BUCK4_VOLT,
0337             .idle_mask = BD71828_MASK_BUCK4_VOLT,
0338             .suspend_mask = BD71828_MASK_BUCK4_VOLT,
0339             .lpsr_mask = BD71828_MASK_BUCK4_VOLT,
0340             .idle_on_mask = BD71828_MASK_IDLE_EN,
0341             .suspend_on_mask = BD71828_MASK_SUSP_EN,
0342             .lpsr_on_mask = BD71828_MASK_LPSR_EN,
0343         },
0344     },
0345     {
0346         .desc = {
0347             .name = "buck5",
0348             .of_match = of_match_ptr("BUCK5"),
0349             .regulators_node = of_match_ptr("regulators"),
0350             .id = BD71828_BUCK5,
0351             .ops = &bd71828_buck_ops,
0352             .type = REGULATOR_VOLTAGE,
0353             .linear_ranges = bd71828_buck5_volts,
0354             .n_linear_ranges = ARRAY_SIZE(bd71828_buck5_volts),
0355             .n_voltages = BD71828_BUCK5_VOLTS,
0356             .enable_reg = BD71828_REG_BUCK5_EN,
0357             .enable_mask = BD71828_MASK_RUN_EN,
0358             .vsel_reg = BD71828_REG_BUCK5_VOLT,
0359             .vsel_mask = BD71828_MASK_BUCK5_VOLT,
0360             .owner = THIS_MODULE,
0361             .of_parse_cb = buck_set_hw_dvs_levels,
0362         },
0363         .dvs = {
0364             /*
0365              * BUCK5 only supports single voltage for all states.
0366              * voltage can be individually enabled for each state
0367              * though => allow setting all states to support
0368              * enabling power rail on different states.
0369              */
0370             .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
0371                      ROHM_DVS_LEVEL_SUSPEND |
0372                      ROHM_DVS_LEVEL_LPSR,
0373             .run_reg = BD71828_REG_BUCK5_VOLT,
0374             .idle_reg = BD71828_REG_BUCK5_VOLT,
0375             .suspend_reg = BD71828_REG_BUCK5_VOLT,
0376             .lpsr_reg = BD71828_REG_BUCK5_VOLT,
0377             .run_mask = BD71828_MASK_BUCK5_VOLT,
0378             .idle_mask = BD71828_MASK_BUCK5_VOLT,
0379             .suspend_mask = BD71828_MASK_BUCK5_VOLT,
0380             .lpsr_mask = BD71828_MASK_BUCK5_VOLT,
0381             .idle_on_mask = BD71828_MASK_IDLE_EN,
0382             .suspend_on_mask = BD71828_MASK_SUSP_EN,
0383             .lpsr_on_mask = BD71828_MASK_LPSR_EN,
0384         },
0385     },
0386     {
0387         .desc = {
0388             .name = "buck6",
0389             .of_match = of_match_ptr("BUCK6"),
0390             .regulators_node = of_match_ptr("regulators"),
0391             .id = BD71828_BUCK6,
0392             .ops = &bd71828_dvs_buck_ops,
0393             .type = REGULATOR_VOLTAGE,
0394             .linear_ranges = bd71828_buck1267_volts,
0395             .n_linear_ranges = ARRAY_SIZE(bd71828_buck1267_volts),
0396             .n_voltages = BD71828_BUCK1267_VOLTS,
0397             .enable_reg = BD71828_REG_BUCK6_EN,
0398             .enable_mask = BD71828_MASK_RUN_EN,
0399             .vsel_reg = BD71828_REG_BUCK6_VOLT,
0400             .vsel_mask = BD71828_MASK_BUCK1267_VOLT,
0401             .ramp_delay_table = bd71828_ramp_delay,
0402             .n_ramp_values = ARRAY_SIZE(bd71828_ramp_delay),
0403             .ramp_reg = BD71828_REG_BUCK6_MODE,
0404             .ramp_mask = BD71828_MASK_RAMP_DELAY,
0405             .owner = THIS_MODULE,
0406             .of_parse_cb = buck_set_hw_dvs_levels,
0407         },
0408         .dvs = {
0409             .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
0410                      ROHM_DVS_LEVEL_SUSPEND |
0411                      ROHM_DVS_LEVEL_LPSR,
0412             .run_reg = BD71828_REG_BUCK6_VOLT,
0413             .run_mask = BD71828_MASK_BUCK1267_VOLT,
0414             .idle_reg = BD71828_REG_BUCK6_IDLE_VOLT,
0415             .idle_mask = BD71828_MASK_BUCK1267_VOLT,
0416             .idle_on_mask = BD71828_MASK_IDLE_EN,
0417             .suspend_reg = BD71828_REG_BUCK6_SUSP_VOLT,
0418             .suspend_mask = BD71828_MASK_BUCK1267_VOLT,
0419             .suspend_on_mask = BD71828_MASK_SUSP_EN,
0420             .lpsr_on_mask = BD71828_MASK_LPSR_EN,
0421             .lpsr_reg = BD71828_REG_BUCK6_SUSP_VOLT,
0422             .lpsr_mask = BD71828_MASK_BUCK1267_VOLT,
0423         },
0424         .reg_inits = buck6_inits,
0425         .reg_init_amnt = ARRAY_SIZE(buck6_inits),
0426     },
0427     {
0428         .desc = {
0429             .name = "buck7",
0430             .of_match = of_match_ptr("BUCK7"),
0431             .regulators_node = of_match_ptr("regulators"),
0432             .id = BD71828_BUCK7,
0433             .ops = &bd71828_dvs_buck_ops,
0434             .type = REGULATOR_VOLTAGE,
0435             .linear_ranges = bd71828_buck1267_volts,
0436             .n_linear_ranges = ARRAY_SIZE(bd71828_buck1267_volts),
0437             .n_voltages = BD71828_BUCK1267_VOLTS,
0438             .enable_reg = BD71828_REG_BUCK7_EN,
0439             .enable_mask = BD71828_MASK_RUN_EN,
0440             .vsel_reg = BD71828_REG_BUCK7_VOLT,
0441             .vsel_mask = BD71828_MASK_BUCK1267_VOLT,
0442             .ramp_delay_table = bd71828_ramp_delay,
0443             .n_ramp_values = ARRAY_SIZE(bd71828_ramp_delay),
0444             .ramp_reg = BD71828_REG_BUCK7_MODE,
0445             .ramp_mask = BD71828_MASK_RAMP_DELAY,
0446             .owner = THIS_MODULE,
0447             .of_parse_cb = buck_set_hw_dvs_levels,
0448         },
0449         .dvs = {
0450             .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
0451                      ROHM_DVS_LEVEL_SUSPEND |
0452                      ROHM_DVS_LEVEL_LPSR,
0453             .run_reg = BD71828_REG_BUCK7_VOLT,
0454             .run_mask = BD71828_MASK_BUCK1267_VOLT,
0455             .idle_reg = BD71828_REG_BUCK7_IDLE_VOLT,
0456             .idle_mask = BD71828_MASK_BUCK1267_VOLT,
0457             .idle_on_mask = BD71828_MASK_IDLE_EN,
0458             .suspend_reg = BD71828_REG_BUCK7_SUSP_VOLT,
0459             .suspend_mask = BD71828_MASK_BUCK1267_VOLT,
0460             .suspend_on_mask = BD71828_MASK_SUSP_EN,
0461             .lpsr_on_mask = BD71828_MASK_LPSR_EN,
0462             .lpsr_reg = BD71828_REG_BUCK7_SUSP_VOLT,
0463             .lpsr_mask = BD71828_MASK_BUCK1267_VOLT,
0464         },
0465         .reg_inits = buck7_inits,
0466         .reg_init_amnt = ARRAY_SIZE(buck7_inits),
0467     },
0468     {
0469         .desc = {
0470             .name = "ldo1",
0471             .of_match = of_match_ptr("LDO1"),
0472             .regulators_node = of_match_ptr("regulators"),
0473             .id = BD71828_LDO1,
0474             .ops = &bd71828_ldo_ops,
0475             .type = REGULATOR_VOLTAGE,
0476             .linear_ranges = bd71828_ldo_volts,
0477             .n_linear_ranges = ARRAY_SIZE(bd71828_ldo_volts),
0478             .n_voltages = BD71828_LDO_VOLTS,
0479             .enable_reg = BD71828_REG_LDO1_EN,
0480             .enable_mask = BD71828_MASK_RUN_EN,
0481             .vsel_reg = BD71828_REG_LDO1_VOLT,
0482             .vsel_mask = BD71828_MASK_LDO_VOLT,
0483             .owner = THIS_MODULE,
0484             .of_parse_cb = buck_set_hw_dvs_levels,
0485         },
0486         .dvs = {
0487             /*
0488              * LDO1 only supports single voltage for all states.
0489              * voltage can be individually enabled for each state
0490              * though => allow setting all states to support
0491              * enabling power rail on different states.
0492              */
0493             .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
0494                      ROHM_DVS_LEVEL_SUSPEND |
0495                      ROHM_DVS_LEVEL_LPSR,
0496             .run_reg = BD71828_REG_LDO1_VOLT,
0497             .idle_reg = BD71828_REG_LDO1_VOLT,
0498             .suspend_reg = BD71828_REG_LDO1_VOLT,
0499             .lpsr_reg = BD71828_REG_LDO1_VOLT,
0500             .run_mask = BD71828_MASK_LDO_VOLT,
0501             .idle_mask = BD71828_MASK_LDO_VOLT,
0502             .suspend_mask = BD71828_MASK_LDO_VOLT,
0503             .lpsr_mask = BD71828_MASK_LDO_VOLT,
0504             .idle_on_mask = BD71828_MASK_IDLE_EN,
0505             .suspend_on_mask = BD71828_MASK_SUSP_EN,
0506             .lpsr_on_mask = BD71828_MASK_LPSR_EN,
0507         },
0508     }, {
0509         .desc = {
0510             .name = "ldo2",
0511             .of_match = of_match_ptr("LDO2"),
0512             .regulators_node = of_match_ptr("regulators"),
0513             .id = BD71828_LDO2,
0514             .ops = &bd71828_ldo_ops,
0515             .type = REGULATOR_VOLTAGE,
0516             .linear_ranges = bd71828_ldo_volts,
0517             .n_linear_ranges = ARRAY_SIZE(bd71828_ldo_volts),
0518             .n_voltages = BD71828_LDO_VOLTS,
0519             .enable_reg = BD71828_REG_LDO2_EN,
0520             .enable_mask = BD71828_MASK_RUN_EN,
0521             .vsel_reg = BD71828_REG_LDO2_VOLT,
0522             .vsel_mask = BD71828_MASK_LDO_VOLT,
0523             .owner = THIS_MODULE,
0524             .of_parse_cb = buck_set_hw_dvs_levels,
0525         },
0526         .dvs = {
0527             /*
0528              * LDO2 only supports single voltage for all states.
0529              * voltage can be individually enabled for each state
0530              * though => allow setting all states to support
0531              * enabling power rail on different states.
0532              */
0533             .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
0534                      ROHM_DVS_LEVEL_SUSPEND |
0535                      ROHM_DVS_LEVEL_LPSR,
0536             .run_reg = BD71828_REG_LDO2_VOLT,
0537             .idle_reg = BD71828_REG_LDO2_VOLT,
0538             .suspend_reg = BD71828_REG_LDO2_VOLT,
0539             .lpsr_reg = BD71828_REG_LDO2_VOLT,
0540             .run_mask = BD71828_MASK_LDO_VOLT,
0541             .idle_mask = BD71828_MASK_LDO_VOLT,
0542             .suspend_mask = BD71828_MASK_LDO_VOLT,
0543             .lpsr_mask = BD71828_MASK_LDO_VOLT,
0544             .idle_on_mask = BD71828_MASK_IDLE_EN,
0545             .suspend_on_mask = BD71828_MASK_SUSP_EN,
0546             .lpsr_on_mask = BD71828_MASK_LPSR_EN,
0547         },
0548     }, {
0549         .desc = {
0550             .name = "ldo3",
0551             .of_match = of_match_ptr("LDO3"),
0552             .regulators_node = of_match_ptr("regulators"),
0553             .id = BD71828_LDO3,
0554             .ops = &bd71828_ldo_ops,
0555             .type = REGULATOR_VOLTAGE,
0556             .linear_ranges = bd71828_ldo_volts,
0557             .n_linear_ranges = ARRAY_SIZE(bd71828_ldo_volts),
0558             .n_voltages = BD71828_LDO_VOLTS,
0559             .enable_reg = BD71828_REG_LDO3_EN,
0560             .enable_mask = BD71828_MASK_RUN_EN,
0561             .vsel_reg = BD71828_REG_LDO3_VOLT,
0562             .vsel_mask = BD71828_MASK_LDO_VOLT,
0563             .owner = THIS_MODULE,
0564             .of_parse_cb = buck_set_hw_dvs_levels,
0565         },
0566         .dvs = {
0567             /*
0568              * LDO3 only supports single voltage for all states.
0569              * voltage can be individually enabled for each state
0570              * though => allow setting all states to support
0571              * enabling power rail on different states.
0572              */
0573             .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
0574                      ROHM_DVS_LEVEL_SUSPEND |
0575                      ROHM_DVS_LEVEL_LPSR,
0576             .run_reg = BD71828_REG_LDO3_VOLT,
0577             .idle_reg = BD71828_REG_LDO3_VOLT,
0578             .suspend_reg = BD71828_REG_LDO3_VOLT,
0579             .lpsr_reg = BD71828_REG_LDO3_VOLT,
0580             .run_mask = BD71828_MASK_LDO_VOLT,
0581             .idle_mask = BD71828_MASK_LDO_VOLT,
0582             .suspend_mask = BD71828_MASK_LDO_VOLT,
0583             .lpsr_mask = BD71828_MASK_LDO_VOLT,
0584             .idle_on_mask = BD71828_MASK_IDLE_EN,
0585             .suspend_on_mask = BD71828_MASK_SUSP_EN,
0586             .lpsr_on_mask = BD71828_MASK_LPSR_EN,
0587         },
0588 
0589     }, {
0590         .desc = {
0591             .name = "ldo4",
0592             .of_match = of_match_ptr("LDO4"),
0593             .regulators_node = of_match_ptr("regulators"),
0594             .id = BD71828_LDO4,
0595             .ops = &bd71828_ldo_ops,
0596             .type = REGULATOR_VOLTAGE,
0597             .linear_ranges = bd71828_ldo_volts,
0598             .n_linear_ranges = ARRAY_SIZE(bd71828_ldo_volts),
0599             .n_voltages = BD71828_LDO_VOLTS,
0600             .enable_reg = BD71828_REG_LDO4_EN,
0601             .enable_mask = BD71828_MASK_RUN_EN,
0602             .vsel_reg = BD71828_REG_LDO4_VOLT,
0603             .vsel_mask = BD71828_MASK_LDO_VOLT,
0604             .owner = THIS_MODULE,
0605             .of_parse_cb = buck_set_hw_dvs_levels,
0606         },
0607         .dvs = {
0608             /*
0609              * LDO1 only supports single voltage for all states.
0610              * voltage can be individually enabled for each state
0611              * though => allow setting all states to support
0612              * enabling power rail on different states.
0613              */
0614             .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
0615                      ROHM_DVS_LEVEL_SUSPEND |
0616                      ROHM_DVS_LEVEL_LPSR,
0617             .run_reg = BD71828_REG_LDO4_VOLT,
0618             .idle_reg = BD71828_REG_LDO4_VOLT,
0619             .suspend_reg = BD71828_REG_LDO4_VOLT,
0620             .lpsr_reg = BD71828_REG_LDO4_VOLT,
0621             .run_mask = BD71828_MASK_LDO_VOLT,
0622             .idle_mask = BD71828_MASK_LDO_VOLT,
0623             .suspend_mask = BD71828_MASK_LDO_VOLT,
0624             .lpsr_mask = BD71828_MASK_LDO_VOLT,
0625             .idle_on_mask = BD71828_MASK_IDLE_EN,
0626             .suspend_on_mask = BD71828_MASK_SUSP_EN,
0627             .lpsr_on_mask = BD71828_MASK_LPSR_EN,
0628         },
0629     }, {
0630         .desc = {
0631             .name = "ldo5",
0632             .of_match = of_match_ptr("LDO5"),
0633             .regulators_node = of_match_ptr("regulators"),
0634             .id = BD71828_LDO5,
0635             .ops = &bd71828_ldo_ops,
0636             .type = REGULATOR_VOLTAGE,
0637             .linear_ranges = bd71828_ldo_volts,
0638             .n_linear_ranges = ARRAY_SIZE(bd71828_ldo_volts),
0639             .n_voltages = BD71828_LDO_VOLTS,
0640             .enable_reg = BD71828_REG_LDO5_EN,
0641             .enable_mask = BD71828_MASK_RUN_EN,
0642             .vsel_reg = BD71828_REG_LDO5_VOLT,
0643             .vsel_mask = BD71828_MASK_LDO_VOLT,
0644             .of_parse_cb = buck_set_hw_dvs_levels,
0645             .owner = THIS_MODULE,
0646         },
0647         /*
0648          * LDO5 is special. It can choose vsel settings to be configured
0649          * from 2 different registers (by GPIO).
0650          *
0651          * This driver supports only configuration where
0652          * BD71828_REG_LDO5_VOLT_L is used.
0653          */
0654         .dvs = {
0655             .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
0656                      ROHM_DVS_LEVEL_SUSPEND |
0657                      ROHM_DVS_LEVEL_LPSR,
0658             .run_reg = BD71828_REG_LDO5_VOLT,
0659             .idle_reg = BD71828_REG_LDO5_VOLT,
0660             .suspend_reg = BD71828_REG_LDO5_VOLT,
0661             .lpsr_reg = BD71828_REG_LDO5_VOLT,
0662             .run_mask = BD71828_MASK_LDO_VOLT,
0663             .idle_mask = BD71828_MASK_LDO_VOLT,
0664             .suspend_mask = BD71828_MASK_LDO_VOLT,
0665             .lpsr_mask = BD71828_MASK_LDO_VOLT,
0666             .idle_on_mask = BD71828_MASK_IDLE_EN,
0667             .suspend_on_mask = BD71828_MASK_SUSP_EN,
0668             .lpsr_on_mask = BD71828_MASK_LPSR_EN,
0669         },
0670 
0671     }, {
0672         .desc = {
0673             .name = "ldo6",
0674             .of_match = of_match_ptr("LDO6"),
0675             .regulators_node = of_match_ptr("regulators"),
0676             .id = BD71828_LDO6,
0677             .ops = &bd71828_ldo6_ops,
0678             .type = REGULATOR_VOLTAGE,
0679             .fixed_uV = BD71828_LDO_6_VOLTAGE,
0680             .n_voltages = 1,
0681             .enable_reg = BD71828_REG_LDO6_EN,
0682             .enable_mask = BD71828_MASK_RUN_EN,
0683             .owner = THIS_MODULE,
0684             /*
0685              * LDO6 only supports enable/disable for all states.
0686              * Voltage for LDO6 is fixed.
0687              */
0688             .of_parse_cb = ldo6_parse_dt,
0689         },
0690     }, {
0691         .desc = {
0692             /* SNVS LDO in data-sheet */
0693             .name = "ldo7",
0694             .of_match = of_match_ptr("LDO7"),
0695             .regulators_node = of_match_ptr("regulators"),
0696             .id = BD71828_LDO_SNVS,
0697             .ops = &bd71828_ldo_ops,
0698             .type = REGULATOR_VOLTAGE,
0699             .linear_ranges = bd71828_ldo_volts,
0700             .n_linear_ranges = ARRAY_SIZE(bd71828_ldo_volts),
0701             .n_voltages = BD71828_LDO_VOLTS,
0702             .enable_reg = BD71828_REG_LDO7_EN,
0703             .enable_mask = BD71828_MASK_RUN_EN,
0704             .vsel_reg = BD71828_REG_LDO7_VOLT,
0705             .vsel_mask = BD71828_MASK_LDO_VOLT,
0706             .owner = THIS_MODULE,
0707             .of_parse_cb = buck_set_hw_dvs_levels,
0708         },
0709         .dvs = {
0710             /*
0711              * LDO7 only supports single voltage for all states.
0712              * voltage can be individually enabled for each state
0713              * though => allow setting all states to support
0714              * enabling power rail on different states.
0715              */
0716             .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
0717                      ROHM_DVS_LEVEL_SUSPEND |
0718                      ROHM_DVS_LEVEL_LPSR,
0719             .run_reg = BD71828_REG_LDO7_VOLT,
0720             .idle_reg = BD71828_REG_LDO7_VOLT,
0721             .suspend_reg = BD71828_REG_LDO7_VOLT,
0722             .lpsr_reg = BD71828_REG_LDO7_VOLT,
0723             .run_mask = BD71828_MASK_LDO_VOLT,
0724             .idle_mask = BD71828_MASK_LDO_VOLT,
0725             .suspend_mask = BD71828_MASK_LDO_VOLT,
0726             .lpsr_mask = BD71828_MASK_LDO_VOLT,
0727             .idle_on_mask = BD71828_MASK_IDLE_EN,
0728             .suspend_on_mask = BD71828_MASK_SUSP_EN,
0729             .lpsr_on_mask = BD71828_MASK_LPSR_EN,
0730         },
0731 
0732     },
0733 };
0734 
0735 static int bd71828_probe(struct platform_device *pdev)
0736 {
0737     int i, j, ret;
0738     struct regulator_config config = {
0739         .dev = pdev->dev.parent,
0740     };
0741 
0742     config.regmap = dev_get_regmap(pdev->dev.parent, NULL);
0743     if (!config.regmap)
0744         return -ENODEV;
0745 
0746     for (i = 0; i < ARRAY_SIZE(bd71828_rdata); i++) {
0747         struct regulator_dev *rdev;
0748         const struct bd71828_regulator_data *rd;
0749 
0750         rd = &bd71828_rdata[i];
0751         rdev = devm_regulator_register(&pdev->dev,
0752                            &rd->desc, &config);
0753         if (IS_ERR(rdev)) {
0754             dev_err(&pdev->dev,
0755                 "failed to register %s regulator\n",
0756                 rd->desc.name);
0757             return PTR_ERR(rdev);
0758         }
0759         for (j = 0; j < rd->reg_init_amnt; j++) {
0760             ret = regmap_update_bits(config.regmap,
0761                          rd->reg_inits[j].reg,
0762                          rd->reg_inits[j].mask,
0763                          rd->reg_inits[j].val);
0764             if (ret) {
0765                 dev_err(&pdev->dev,
0766                     "regulator %s init failed\n",
0767                     rd->desc.name);
0768                 return ret;
0769             }
0770         }
0771     }
0772     return 0;
0773 }
0774 
0775 static struct platform_driver bd71828_regulator = {
0776     .driver = {
0777         .name = "bd71828-pmic"
0778     },
0779     .probe = bd71828_probe,
0780 };
0781 
0782 module_platform_driver(bd71828_regulator);
0783 
0784 MODULE_AUTHOR("Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>");
0785 MODULE_DESCRIPTION("BD71828 voltage regulator driver");
0786 MODULE_LICENSE("GPL");
0787 MODULE_ALIAS("platform:bd71828-pmic");