diff options
-rw-r--r-- | Documentation/devicetree/bindings/regulator/nxp,pf8x00-regulator.yaml | 17 | ||||
-rw-r--r-- | drivers/regulator/Kconfig | 4 | ||||
-rw-r--r-- | drivers/regulator/pf8x00-regulator.c | 203 |
3 files changed, 136 insertions, 88 deletions
diff --git a/Documentation/devicetree/bindings/regulator/nxp,pf8x00-regulator.yaml b/Documentation/devicetree/bindings/regulator/nxp,pf8x00-regulator.yaml index 956156fe52a3..8761437ed8ad 100644 --- a/Documentation/devicetree/bindings/regulator/nxp,pf8x00-regulator.yaml +++ b/Documentation/devicetree/bindings/regulator/nxp,pf8x00-regulator.yaml @@ -62,8 +62,11 @@ properties: $ref: "/schemas/types.yaml#/definitions/uint32" minimum: 2100 maximum: 4500 + deprecated: true description: BUCK regulators current limit in mA. + This property is deprecated, please use + "regulator-max-microamp" instead. Listed current limits in mA are, 2100 (default) @@ -73,21 +76,11 @@ properties: nxp,phase-shift: $ref: "/schemas/types.yaml#/definitions/uint32" - minimum: 45 - maximum: 0 + default: 0 + enum: [ 0, 45, 90, 135, 180, 225, 270, 315 ] description: BUCK regulators phase shift control in degrees. - Listed phase shift control values in degrees are, - 45 - 90 - 135 - 180 - 225 - 270 - 315 - 0 (default) - unevaluatedProperties: false "^vsnvs$": diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig index eafa13be6e3e..ba8c09d90701 100644 --- a/drivers/regulator/Kconfig +++ b/drivers/regulator/Kconfig @@ -846,6 +846,10 @@ config REGULATOR_PF8X00 Say y here to support the regulators found on the NXP PF8100/PF8121A/PF8200 PMIC. + Say M here if you want to support for the regulators found + on the NXP PF8100/PF8121A/PF8200 PMIC. The module will be named + "pf8x00-regulator". + config REGULATOR_PFUZE100 tristate "Freescale PFUZE100/200/3000/3001 regulator driver" depends on I2C && OF diff --git a/drivers/regulator/pf8x00-regulator.c b/drivers/regulator/pf8x00-regulator.c index af9918cd27aa..1e5582d73405 100644 --- a/drivers/regulator/pf8x00-regulator.c +++ b/drivers/regulator/pf8x00-regulator.c @@ -114,7 +114,6 @@ enum swxilim_bits { #define PF8X00_SWXILIM_SHIFT 3 #define PF8X00_SWXILIM_MASK GENMASK(4, 3) #define PF8X00_SWXPHASE_MASK GENMASK(2, 0) -#define PF8X00_SWXPHASE_DEFAULT 0 #define PF8X00_SWXPHASE_SHIFT 7 enum pf8x00_devid { @@ -128,8 +127,6 @@ enum pf8x00_devid { struct pf8x00_regulator { struct regulator_desc desc; - u8 ilim; - u8 phase_shift; }; struct pf8x00_chip { @@ -150,35 +147,16 @@ static const int pf8x00_ldo_voltages[] = { 3100000, 3150000, 3200000, 3300000, 3350000, 1650000, 1700000, 5000000, }; -#define SWV(i) (6250 * i + 400000) -#define SWV_LINE(i) SWV(i*8+0), SWV(i*8+1), SWV(i*8+2), SWV(i*8+3), \ - SWV(i*8+4), SWV(i*8+5), SWV(i*8+6), SWV(i*8+7) +/* Output: 2.1A to 4.5A */ +static const unsigned int pf8x00_sw_current_table[] = { + 2100000, 2600000, 3000000, 4500000, +}; /* Output: 0.4V to 1.8V */ -static const int pf8x00_sw1_to_6_voltages[] = { - SWV_LINE(0), - SWV_LINE(1), - SWV_LINE(2), - SWV_LINE(3), - SWV_LINE(4), - SWV_LINE(5), - SWV_LINE(6), - SWV_LINE(7), - SWV_LINE(8), - SWV_LINE(9), - SWV_LINE(10), - SWV_LINE(11), - SWV_LINE(12), - SWV_LINE(13), - SWV_LINE(14), - SWV_LINE(15), - SWV_LINE(16), - SWV_LINE(17), - SWV_LINE(18), - SWV_LINE(19), - SWV_LINE(20), - SWV_LINE(21), - 1500000, 1800000, +#define PF8XOO_SW1_6_VOLTAGE_NUM 0xB2 +static const struct linear_range pf8x00_sw1_to_6_voltages[] = { + REGULATOR_LINEAR_RANGE(400000, 0x00, 0xB0, 6250), + REGULATOR_LINEAR_RANGE(1800000, 0xB1, 0xB1, 0), }; /* Output: 1.0V to 4.1V */ @@ -194,15 +172,10 @@ static const int pf8x00_vsnvs_voltages[] = { 0, 1800000, 3000000, 3300000, }; -static struct pf8x00_regulator *desc_to_regulator(const struct regulator_desc *desc) -{ - return container_of(desc, struct pf8x00_regulator, desc); -} - -static void swxilim_select(const struct regulator_desc *desc, int ilim) +static void swxilim_select(struct pf8x00_chip *chip, int id, int ilim) { - struct pf8x00_regulator *data = desc_to_regulator(desc); u8 ilim_sel; + u8 reg = PF8X00_SW_BASE(id) + SW_CONFIG2; switch (ilim) { case 2100: @@ -222,43 +195,83 @@ static void swxilim_select(const struct regulator_desc *desc, int ilim) break; } - data->ilim = ilim_sel; + regmap_update_bits(chip->regmap, reg, + PF8X00_SWXILIM_MASK, + ilim_sel << PF8X00_SWXILIM_SHIFT); } -static int pf8x00_of_parse_cb(struct device_node *np, +static void handle_ilim_property(struct device_node *np, + const struct regulator_desc *desc, + struct regulator_config *config) +{ + struct pf8x00_chip *chip = config->driver_data; + int ret; + int val; + + if ((desc->id >= PF8X00_BUCK1) && (desc->id <= PF8X00_BUCK7)) { + ret = of_property_read_u32(np, "nxp,ilim-ma", &val); + if (ret) { + dev_dbg(chip->dev, "unspecified ilim for BUCK%d, use value stored in OTP\n", + desc->id - PF8X00_LDO4); + return; + } + + dev_warn(chip->dev, "nxp,ilim-ma is deprecated, please use regulator-max-microamp\n"); + swxilim_select(chip, desc->id, val); + + } else + dev_warn(chip->dev, "nxp,ilim-ma used with incorrect regulator (%d)\n", desc->id); +} + +static void handle_shift_property(struct device_node *np, const struct regulator_desc *desc, struct regulator_config *config) { - struct pf8x00_regulator *data = desc_to_regulator(desc); + unsigned char id = desc->id - PF8X00_LDO4; + unsigned char reg = PF8X00_SW_BASE(id) + SW_CONFIG2; struct pf8x00_chip *chip = config->driver_data; + int phase; int val; int ret; + if ((desc->id >= PF8X00_BUCK1) && (desc->id <= PF8X00_BUCK7)) { + ret = of_property_read_u32(np, "nxp,phase-shift", &val); + if (ret) { + dev_dbg(chip->dev, + "unspecified phase-shift for BUCK%d, using OTP configuration\n", + id); + return; + } - ret = of_property_read_u32(np, "nxp,ilim-ma", &val); - if (ret) - dev_dbg(chip->dev, "unspecified ilim for BUCK%d, use 2100 mA\n", - desc->id - PF8X00_LDO4); + if (val < 0 || val > 315 || val % 45 != 0) { + dev_warn(config->dev, + "invalid phase_shift %d for BUCK%d, using OTP configuration\n", + val, id); + return; + } - swxilim_select(desc, val); + phase = val / 45; - ret = of_property_read_u32(np, "nxp,phase-shift", &val); - if (ret) { - dev_dbg(chip->dev, - "unspecified phase-shift for BUCK%d, use 0 degrees\n", - desc->id - PF8X00_LDO4); - val = PF8X00_SWXPHASE_DEFAULT; - } + if (phase >= 1) + phase -= 1; + else + phase = PF8X00_SWXPHASE_SHIFT; - phase = val / 45; - if ((phase * 45) != val) { - dev_warn(config->dev, - "invalid phase_shift %d for BUCK%d, use 0 degrees\n", - (phase * 45), desc->id - PF8X00_LDO4); - phase = PF8X00_SWXPHASE_SHIFT; - } + regmap_update_bits(chip->regmap, reg, + PF8X00_SWXPHASE_MASK, + phase); + } else + dev_warn(chip->dev, "nxp,phase-shift used with incorrect regulator (%d)\n", id); - data->phase_shift = (phase >= 1) ? phase - 1 : PF8X00_SWXPHASE_SHIFT; +} + +static int pf8x00_of_parse_cb(struct device_node *np, + const struct regulator_desc *desc, + struct regulator_config *config) +{ + + handle_ilim_property(np, desc, config); + handle_shift_property(np, desc, config); return 0; } @@ -272,13 +285,27 @@ static const struct regulator_ops pf8x00_ldo_ops = { .get_voltage_sel = regulator_get_voltage_sel_regmap, }; -static const struct regulator_ops pf8x00_buck_ops = { + +static const struct regulator_ops pf8x00_buck1_6_ops = { + .enable = regulator_enable_regmap, + .disable = regulator_disable_regmap, + .is_enabled = regulator_is_enabled_regmap, + .list_voltage = regulator_list_voltage_linear_range, + .set_voltage_sel = regulator_set_voltage_sel_regmap, + .get_voltage_sel = regulator_get_voltage_sel_regmap, + .get_current_limit = regulator_get_current_limit_regmap, + .set_current_limit = regulator_set_current_limit_regmap, +}; + +static const struct regulator_ops pf8x00_buck7_ops = { .enable = regulator_enable_regmap, .disable = regulator_disable_regmap, .is_enabled = regulator_is_enabled_regmap, .list_voltage = regulator_list_voltage_table, .set_voltage_sel = regulator_set_voltage_sel_regmap, .get_voltage_sel = regulator_get_voltage_sel_regmap, + .get_current_limit = regulator_get_current_limit_regmap, + .set_current_limit = regulator_set_current_limit_regmap, }; static const struct regulator_ops pf8x00_vsnvs_ops = { @@ -319,14 +346,49 @@ static const struct regulator_ops pf8x00_vsnvs_ops = { .of_match = _name, \ .regulators_node = "regulators", \ .of_parse_cb = pf8x00_of_parse_cb, \ - .n_voltages = ARRAY_SIZE(voltages), \ - .ops = &pf8x00_buck_ops, \ + .n_voltages = PF8XOO_SW1_6_VOLTAGE_NUM, \ + .ops = &pf8x00_buck1_6_ops, \ .type = REGULATOR_VOLTAGE, \ .id = PF8X00_BUCK ## _id, \ .owner = THIS_MODULE, \ + .linear_ranges = pf8x00_sw1_to_6_voltages, \ + .n_linear_ranges = \ + ARRAY_SIZE(pf8x00_sw1_to_6_voltages), \ + .vsel_reg = (base) + SW_RUN_VOLT, \ + .vsel_mask = 0xff, \ + .curr_table = pf8x00_sw_current_table, \ + .n_current_limits = \ + ARRAY_SIZE(pf8x00_sw_current_table), \ + .csel_reg = (base) + SW_CONFIG2, \ + .csel_mask = PF8X00_SWXILIM_MASK, \ + .enable_reg = (base) + SW_MODE1, \ + .enable_val = 0x3, \ + .disable_val = 0x0, \ + .enable_mask = 0x3, \ + .enable_time = 500, \ + }, \ + } + +#define PF8X00BUCK7(_name, base, voltages) \ + [PF8X00_BUCK7] = { \ + .desc = { \ + .name = _name, \ + .of_match = _name, \ + .regulators_node = "regulators", \ + .of_parse_cb = pf8x00_of_parse_cb, \ + .n_voltages = ARRAY_SIZE(voltages), \ + .ops = &pf8x00_buck7_ops, \ + .type = REGULATOR_VOLTAGE, \ + .id = PF8X00_BUCK7, \ + .owner = THIS_MODULE, \ .volt_table = voltages, \ .vsel_reg = (base) + SW_RUN_VOLT, \ .vsel_mask = 0xff, \ + .curr_table = pf8x00_sw_current_table, \ + .n_current_limits = \ + ARRAY_SIZE(pf8x00_sw_current_table), \ + .csel_reg = (base) + SW_CONFIG2, \ + .csel_mask = PF8X00_SWXILIM_MASK, \ .enable_reg = (base) + SW_MODE1, \ .enable_val = 0x3, \ .disable_val = 0x0, \ @@ -335,6 +397,7 @@ static const struct regulator_ops pf8x00_vsnvs_ops = { }, \ } + #define PF8X00VSNVS(_name, base, voltages) \ [PF8X00_VSNVS] = { \ .desc = { \ @@ -363,7 +426,7 @@ static struct pf8x00_regulator pf8x00_regulators_data[PF8X00_MAX_REGULATORS] = { PF8X00BUCK(4, "buck4", PF8X00_SW_BASE(PF8X00_BUCK4), pf8x00_sw1_to_6_voltages), PF8X00BUCK(5, "buck5", PF8X00_SW_BASE(PF8X00_BUCK5), pf8x00_sw1_to_6_voltages), PF8X00BUCK(6, "buck6", PF8X00_SW_BASE(PF8X00_BUCK6), pf8x00_sw1_to_6_voltages), - PF8X00BUCK(7, "buck7", PF8X00_SW_BASE(PF8X00_BUCK7), pf8x00_sw7_voltages), + PF8X00BUCK7("buck7", PF8X00_SW_BASE(PF8X00_BUCK7), pf8x00_sw7_voltages), PF8X00VSNVS("vsnvs", PF8X00_VSNVS_CONFIG1, pf8x00_vsnvs_voltages), }; @@ -451,18 +514,6 @@ static int pf8x00_i2c_probe(struct i2c_client *client) "failed to register %s regulator\n", data->desc.name); return PTR_ERR(rdev); } - - if ((id >= PF8X00_BUCK1) && (id <= PF8X00_BUCK7)) { - u8 reg = PF8X00_SW_BASE(id) + SW_CONFIG2; - - regmap_update_bits(chip->regmap, reg, - PF8X00_SWXPHASE_MASK, - data->phase_shift); - - regmap_update_bits(chip->regmap, reg, - PF8X00_SWXILIM_MASK, - data->ilim << PF8X00_SWXILIM_SHIFT); - } } return 0; |