Skip to content

Commit

Permalink
Merge tag 'regulator-fix-v5.13-rc4' of git://git.kernel.org/pub/scm/l…
Browse files Browse the repository at this point in the history
…inux/kernel/git/broonie/regulator

Pull regulator fixes from Mark Brown:
 "A collection of fixes for the regulator API that have come up since
  the merge window, including a big batch of fixes from Axel Lin's usual
  careful and detailed review.

  The one stand out fix here is Dmitry Baryshkov's fix for an issue
  where we fail to power on the parents of always on regulators during
  system startup if they weren't already powered on"

* tag 'regulator-fix-v5.13-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator: (21 commits)
  regulator: rt4801: Fix NULL pointer dereference if priv->enable_gpios is NULL
  regulator: hi6421v600: Fix .vsel_mask setting
  regulator: bd718x7: Fix the BUCK7 voltage setting on BD71837
  regulator: atc260x: Fix n_voltages and min_sel for pickable linear ranges
  regulator: rtmv20: Fix to make regcache value first reading back from HW
  regulator: mt6315: Fix function prototype for mt6315_map_mode
  regulator: rtmv20: Add Richtek to Kconfig text
  regulator: rtmv20: Fix .set_current_limit/.get_current_limit callbacks
  regulator: hisilicon: use the correct HiSilicon copyright
  regulator: bd71828: Fix .n_voltages settings
  regulator: bd70528: Fix off-by-one for buck123 .n_voltages setting
  regulator: max77620: Silence deferred probe error
  regulator: max77620: Use device_set_of_node_from_dev()
  regulator: scmi: Fix off-by-one for linear regulators .n_voltages setting
  regulator: core: resolve supply for boot-on/always-on regulators
  regulator: fixed: Ensure enable_counter is correct if reg_domain_disable fails
  regulator: Check ramp_delay_table for regulator_set_ramp_delay_regmap
  regulator: fan53880: Fix missing n_voltages setting
  regulator: da9121: Return REGULATOR_MODE_INVALID for invalid mode
  regulator: fan53555: fix TCS4525 voltage calulation
  ...
  • Loading branch information
Linus Torvalds committed Jun 8, 2021
2 parents dc25573 + cb2381c commit 9b1111f
Show file tree
Hide file tree
Showing 19 changed files with 104 additions and 42 deletions.
2 changes: 1 addition & 1 deletion drivers/regulator/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -1031,7 +1031,7 @@ config REGULATOR_RT5033
current source, LDO and Buck.

config REGULATOR_RTMV20
tristate "RTMV20 Laser Diode Regulator"
tristate "Richtek RTMV20 Laser Diode Regulator"
depends on I2C
select REGMAP_I2C
help
Expand Down
19 changes: 10 additions & 9 deletions drivers/regulator/atc260x-regulator.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ static const struct linear_range atc2609a_dcdc_voltage_ranges[] = {

static const struct linear_range atc2609a_ldo_voltage_ranges0[] = {
REGULATOR_LINEAR_RANGE(700000, 0, 15, 100000),
REGULATOR_LINEAR_RANGE(2100000, 16, 28, 100000),
REGULATOR_LINEAR_RANGE(2100000, 0, 12, 100000),
};

static const struct linear_range atc2609a_ldo_voltage_ranges1[] = {
REGULATOR_LINEAR_RANGE(850000, 0, 15, 100000),
REGULATOR_LINEAR_RANGE(2100000, 16, 27, 100000),
REGULATOR_LINEAR_RANGE(2100000, 0, 11, 100000),
};

static const unsigned int atc260x_ldo_voltage_range_sel[] = {
0x0, 0x1,
0x0, 0x20,
};

static int atc260x_dcdc_set_voltage_time_sel(struct regulator_dev *rdev,
Expand Down Expand Up @@ -411,7 +411,7 @@ enum atc2609a_reg_ids {
.owner = THIS_MODULE, \
}

#define atc2609a_reg_desc_ldo_range_pick(num, n_range) { \
#define atc2609a_reg_desc_ldo_range_pick(num, n_range, n_volt) { \
.name = "LDO"#num, \
.supply_name = "ldo"#num, \
.of_match = of_match_ptr("ldo"#num), \
Expand All @@ -421,6 +421,7 @@ enum atc2609a_reg_ids {
.type = REGULATOR_VOLTAGE, \
.linear_ranges = atc2609a_ldo_voltage_ranges##n_range, \
.n_linear_ranges = ARRAY_SIZE(atc2609a_ldo_voltage_ranges##n_range), \
.n_voltages = n_volt, \
.vsel_reg = ATC2609A_PMU_LDO##num##_CTL0, \
.vsel_mask = GENMASK(4, 1), \
.vsel_range_reg = ATC2609A_PMU_LDO##num##_CTL0, \
Expand Down Expand Up @@ -458,12 +459,12 @@ static const struct regulator_desc atc2609a_reg[] = {
atc2609a_reg_desc_ldo_bypass(0),
atc2609a_reg_desc_ldo_bypass(1),
atc2609a_reg_desc_ldo_bypass(2),
atc2609a_reg_desc_ldo_range_pick(3, 0),
atc2609a_reg_desc_ldo_range_pick(4, 0),
atc2609a_reg_desc_ldo_range_pick(3, 0, 29),
atc2609a_reg_desc_ldo_range_pick(4, 0, 29),
atc2609a_reg_desc_ldo(5),
atc2609a_reg_desc_ldo_range_pick(6, 1),
atc2609a_reg_desc_ldo_range_pick(7, 0),
atc2609a_reg_desc_ldo_range_pick(8, 0),
atc2609a_reg_desc_ldo_range_pick(6, 1, 28),
atc2609a_reg_desc_ldo_range_pick(7, 0, 29),
atc2609a_reg_desc_ldo_range_pick(8, 0, 29),
atc2609a_reg_desc_ldo_fixed(9),
};

Expand Down
2 changes: 1 addition & 1 deletion drivers/regulator/bd718x7-regulator.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ BD718XX_OPS(bd71837_buck_regulator_ops, regulator_list_voltage_linear_range,
NULL);

BD718XX_OPS(bd71837_buck_regulator_nolinear_ops, regulator_list_voltage_table,
regulator_map_voltage_ascend, bd718xx_set_voltage_sel_restricted,
regulator_map_voltage_ascend, bd71837_set_voltage_sel_restricted,
regulator_get_voltage_sel_regmap, regulator_set_voltage_time_sel,
NULL);
/*
Expand Down
6 changes: 6 additions & 0 deletions drivers/regulator/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1425,6 +1425,12 @@ static int set_machine_constraints(struct regulator_dev *rdev)
* and we have control then make sure it is enabled.
*/
if (rdev->constraints->always_on || rdev->constraints->boot_on) {
/* If we want to enable this regulator, make sure that we know
* the supplying regulator.
*/
if (rdev->supply_name && !rdev->supply)
return -EPROBE_DEFER;

if (rdev->supply) {
ret = regulator_enable(rdev->supply);
if (ret < 0) {
Expand Down
3 changes: 2 additions & 1 deletion drivers/regulator/cros-ec-regulator.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,9 @@ static int cros_ec_regulator_probe(struct platform_device *pdev)

drvdata->dev = devm_regulator_register(dev, &drvdata->desc, &cfg);
if (IS_ERR(drvdata->dev)) {
ret = PTR_ERR(drvdata->dev);
dev_err(&pdev->dev, "Failed to register regulator: %d\n", ret);
return PTR_ERR(drvdata->dev);
return ret;
}

platform_set_drvdata(pdev, drvdata);
Expand Down
10 changes: 7 additions & 3 deletions drivers/regulator/da9121-regulator.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ static unsigned int da9121_map_mode(unsigned int mode)
case DA9121_BUCK_MODE_FORCE_PFM:
return REGULATOR_MODE_STANDBY;
default:
return -EINVAL;
return REGULATOR_MODE_INVALID;
}
}

Expand Down Expand Up @@ -317,7 +317,7 @@ static unsigned int da9121_buck_get_mode(struct regulator_dev *rdev)
{
struct da9121 *chip = rdev_get_drvdata(rdev);
int id = rdev_get_id(rdev);
unsigned int val;
unsigned int val, mode;
int ret = 0;

ret = regmap_read(chip->regmap, da9121_mode_field[id].reg, &val);
Expand All @@ -326,7 +326,11 @@ static unsigned int da9121_buck_get_mode(struct regulator_dev *rdev)
return -EINVAL;
}

return da9121_map_mode(val & da9121_mode_field[id].msk);
mode = da9121_map_mode(val & da9121_mode_field[id].msk);
if (mode == REGULATOR_MODE_INVALID)
return -EINVAL;

return mode;
}

static const struct regulator_ops da9121_buck_ops = {
Expand Down
3 changes: 1 addition & 2 deletions drivers/regulator/fan53555.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@

#define FAN53555_NVOLTAGES 64 /* Numbers of voltages */
#define FAN53526_NVOLTAGES 128
#define TCS4525_NVOLTAGES 127 /* Numbers of voltages */

#define TCS_VSEL_NSEL_MASK 0x7f
#define TCS_VSEL0_MODE (1 << 7)
Expand Down Expand Up @@ -376,7 +375,7 @@ static int fan53555_voltages_setup_tcs(struct fan53555_device_info *di)
/* Init voltage range and step */
di->vsel_min = 600000;
di->vsel_step = 6250;
di->vsel_count = TCS4525_NVOLTAGES;
di->vsel_count = FAN53526_NVOLTAGES;

return 0;
}
Expand Down
3 changes: 3 additions & 0 deletions drivers/regulator/fan53880.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ static const struct regulator_ops fan53880_ops = {
REGULATOR_LINEAR_RANGE(800000, 0xf, 0x73, 25000), \
}, \
.n_linear_ranges = 2, \
.n_voltages = 0x74, \
.vsel_reg = FAN53880_LDO ## _num ## VOUT, \
.vsel_mask = 0x7f, \
.enable_reg = FAN53880_ENABLE, \
Expand All @@ -76,6 +77,7 @@ static const struct regulator_desc fan53880_regulators[] = {
REGULATOR_LINEAR_RANGE(600000, 0x1f, 0xf7, 12500),
},
.n_linear_ranges = 2,
.n_voltages = 0xf8,
.vsel_reg = FAN53880_BUCKVOUT,
.vsel_mask = 0x7f,
.enable_reg = FAN53880_ENABLE,
Expand All @@ -95,6 +97,7 @@ static const struct regulator_desc fan53880_regulators[] = {
REGULATOR_LINEAR_RANGE(3000000, 0x4, 0x70, 25000),
},
.n_linear_ranges = 2,
.n_voltages = 0x71,
.vsel_reg = FAN53880_BOOSTVOUT,
.vsel_mask = 0x7f,
.enable_reg = FAN53880_ENABLE_BOOST,
Expand Down
7 changes: 6 additions & 1 deletion drivers/regulator/fixed.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,15 @@ static int reg_domain_disable(struct regulator_dev *rdev)
{
struct fixed_voltage_data *priv = rdev_get_drvdata(rdev);
struct device *dev = rdev->dev.parent;
int ret;

ret = dev_pm_genpd_set_performance_state(dev, 0);
if (ret)
return ret;

priv->enable_counter--;

return dev_pm_genpd_set_performance_state(dev, 0);
return 0;
}

static int reg_is_enabled(struct regulator_dev *rdev)
Expand Down
2 changes: 1 addition & 1 deletion drivers/regulator/helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,7 @@ int regulator_set_ramp_delay_regmap(struct regulator_dev *rdev, int ramp_delay)
int ret;
unsigned int sel;

if (!rdev->desc->n_ramp_values)
if (WARN_ON(!rdev->desc->n_ramp_values || !rdev->desc->ramp_delay_table))
return -EINVAL;

ret = find_closest_bigger(ramp_delay, rdev->desc->ramp_delay_table,
Expand Down
4 changes: 2 additions & 2 deletions drivers/regulator/hi6421v600-regulator.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Device driver for regulators in Hisi IC
//
// Copyright (c) 2013 Linaro Ltd.
// Copyright (c) 2011 Hisilicon.
// Copyright (c) 2011 HiSilicon Ltd.
// Copyright (c) 2020-2021 Huawei Technologies Co., Ltd
//
// Guodong Xu <guodong.xu@linaro.org>
Expand Down Expand Up @@ -83,7 +83,7 @@ static const unsigned int ldo34_voltages[] = {
.owner = THIS_MODULE, \
.volt_table = vtable, \
.n_voltages = ARRAY_SIZE(vtable), \
.vsel_mask = (1 << (ARRAY_SIZE(vtable) - 1)) - 1, \
.vsel_mask = ARRAY_SIZE(vtable) - 1, \
.vsel_reg = vreg, \
.enable_reg = ereg, \
.enable_mask = emask, \
Expand Down
2 changes: 1 addition & 1 deletion drivers/regulator/hi655x-regulator.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// Device driver for regulators in Hi655x IC
//
// Copyright (c) 2016 Hisilicon.
// Copyright (c) 2016 HiSilicon Ltd.
//
// Authors:
// Chen Feng <puck.chen@hisilicon.com>
Expand Down
17 changes: 11 additions & 6 deletions drivers/regulator/max77620-regulator.c
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,13 @@ static int max77620_regulator_probe(struct platform_device *pdev)
config.dev = dev;
config.driver_data = pmic;

/*
* Set of_node_reuse flag to prevent driver core from attempting to
* claim any pinmux resources already claimed by the parent device.
* Otherwise PMIC driver will fail to re-probe.
*/
device_set_of_node_from_dev(&pdev->dev, pdev->dev.parent);

for (id = 0; id < MAX77620_NUM_REGS; id++) {
struct regulator_dev *rdev;
struct regulator_desc *rdesc;
Expand All @@ -839,12 +846,10 @@ static int max77620_regulator_probe(struct platform_device *pdev)
return ret;

rdev = devm_regulator_register(dev, rdesc, &config);
if (IS_ERR(rdev)) {
ret = PTR_ERR(rdev);
dev_err(dev, "Regulator registration %s failed: %d\n",
rdesc->name, ret);
return ret;
}
if (IS_ERR(rdev))
return dev_err_probe(dev, PTR_ERR(rdev),
"Regulator registration %s failed\n",
rdesc->name);
}

return 0;
Expand Down
2 changes: 1 addition & 1 deletion drivers/regulator/mt6315-regulator.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ static const struct linear_range mt_volt_range1[] = {
REGULATOR_LINEAR_RANGE(0, 0, 0xbf, 6250),
};

static unsigned int mt6315_map_mode(u32 mode)
static unsigned int mt6315_map_mode(unsigned int mode)
{
switch (mode) {
case MT6315_BUCK_MODE_AUTO:
Expand Down
4 changes: 2 additions & 2 deletions drivers/regulator/rt4801-regulator.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ static int rt4801_enable(struct regulator_dev *rdev)
struct gpio_descs *gpios = priv->enable_gpios;
int id = rdev_get_id(rdev), ret;

if (gpios->ndescs <= id) {
if (!gpios || gpios->ndescs <= id) {
dev_warn(&rdev->dev, "no dedicated gpio can control\n");
goto bypass_gpio;
}
Expand All @@ -88,7 +88,7 @@ static int rt4801_disable(struct regulator_dev *rdev)
struct gpio_descs *gpios = priv->enable_gpios;
int id = rdev_get_id(rdev);

if (gpios->ndescs <= id) {
if (!gpios || gpios->ndescs <= id) {
dev_warn(&rdev->dev, "no dedicated gpio can control\n");
goto bypass_gpio;
}
Expand Down
44 changes: 42 additions & 2 deletions drivers/regulator/rtmv20-regulator.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#define RTMV20_REG_LDIRQ 0x30
#define RTMV20_REG_LDSTAT 0x40
#define RTMV20_REG_LDMASK 0x50
#define RTMV20_MAX_REGS (RTMV20_REG_LDMASK + 1)

#define RTMV20_VID_MASK GENMASK(7, 4)
#define RICHTEK_VID 0x80
Expand Down Expand Up @@ -103,9 +104,47 @@ static int rtmv20_lsw_disable(struct regulator_dev *rdev)
return 0;
}

static int rtmv20_lsw_set_current_limit(struct regulator_dev *rdev, int min_uA,
int max_uA)
{
int sel;

if (min_uA > RTMV20_LSW_MAXUA || max_uA < RTMV20_LSW_MINUA)
return -EINVAL;

if (max_uA > RTMV20_LSW_MAXUA)
max_uA = RTMV20_LSW_MAXUA;

sel = (max_uA - RTMV20_LSW_MINUA) / RTMV20_LSW_STEPUA;

/* Ensure the selected setting is still in range */
if ((sel * RTMV20_LSW_STEPUA + RTMV20_LSW_MINUA) < min_uA)
return -EINVAL;

sel <<= ffs(rdev->desc->csel_mask) - 1;

return regmap_update_bits(rdev->regmap, rdev->desc->csel_reg,
rdev->desc->csel_mask, sel);
}

static int rtmv20_lsw_get_current_limit(struct regulator_dev *rdev)
{
unsigned int val;
int ret;

ret = regmap_read(rdev->regmap, rdev->desc->csel_reg, &val);
if (ret)
return ret;

val &= rdev->desc->csel_mask;
val >>= ffs(rdev->desc->csel_mask) - 1;

return val * RTMV20_LSW_STEPUA + RTMV20_LSW_MINUA;
}

static const struct regulator_ops rtmv20_regulator_ops = {
.set_current_limit = regulator_set_current_limit_regmap,
.get_current_limit = regulator_get_current_limit_regmap,
.set_current_limit = rtmv20_lsw_set_current_limit,
.get_current_limit = rtmv20_lsw_get_current_limit,
.enable = rtmv20_lsw_enable,
.disable = rtmv20_lsw_disable,
.is_enabled = regulator_is_enabled_regmap,
Expand Down Expand Up @@ -275,6 +314,7 @@ static const struct regmap_config rtmv20_regmap_config = {
.val_bits = 8,
.cache_type = REGCACHE_RBTREE,
.max_register = RTMV20_REG_LDMASK,
.num_reg_defaults_raw = RTMV20_MAX_REGS,

.writeable_reg = rtmv20_is_accessible_reg,
.readable_reg = rtmv20_is_accessible_reg,
Expand Down
2 changes: 1 addition & 1 deletion drivers/regulator/scmi-regulator.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ scmi_config_linear_regulator_mappings(struct scmi_regulator *sreg,
sreg->desc.uV_step =
vinfo->levels_uv[SCMI_VOLTAGE_SEGMENT_STEP];
sreg->desc.linear_min_sel = 0;
sreg->desc.n_voltages = delta_uV / sreg->desc.uV_step;
sreg->desc.n_voltages = (delta_uV / sreg->desc.uV_step) + 1;
sreg->desc.ops = &scmi_reg_linear_ops;
}

Expand Down
4 changes: 1 addition & 3 deletions include/linux/mfd/rohm-bd70528.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ struct bd70528_data {
struct mutex rtc_timer_lock;
};

#define BD70528_BUCK_VOLTS 17
#define BD70528_BUCK_VOLTS 17
#define BD70528_BUCK_VOLTS 17
#define BD70528_BUCK_VOLTS 0x10
#define BD70528_LDO_VOLTS 0x20

#define BD70528_REG_BUCK1_EN 0x0F
Expand Down
10 changes: 5 additions & 5 deletions include/linux/mfd/rohm-bd71828.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ enum {
BD71828_REGULATOR_AMOUNT,
};

#define BD71828_BUCK1267_VOLTS 0xEF
#define BD71828_BUCK3_VOLTS 0x10
#define BD71828_BUCK4_VOLTS 0x20
#define BD71828_BUCK5_VOLTS 0x10
#define BD71828_LDO_VOLTS 0x32
#define BD71828_BUCK1267_VOLTS 0x100
#define BD71828_BUCK3_VOLTS 0x20
#define BD71828_BUCK4_VOLTS 0x40
#define BD71828_BUCK5_VOLTS 0x20
#define BD71828_LDO_VOLTS 0x40
/* LDO6 is fixed 1.8V voltage */
#define BD71828_LDO_6_VOLTAGE 1800000

Expand Down

0 comments on commit 9b1111f

Please sign in to comment.