Merge tag 'regulator-fix-v7.4-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator

Pull regulator fixes from Mark Brown:
 "A small collection of mostly fairly standard driver specific fixes.

  The mt6363 changes are a little large but are the result of two
  independent users running into the same issues and testing each
  other's changes so given that it's only -rc1 it seemed sensible to
  take the changes as fixes"

* tag 'regulator-fix-v7.4-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator:
  regulator: mt6363: Fix VEMC voltage selection
  regulator: mt6363: Use 8-bit register values
  regulator: mt6363: Fix the registers of the VSRAM CPU and APU LDOs
  regulator: qcom_spmi: don't take a sleeping lock in the SAW IPI
This commit is contained in:
Linus Torvalds
2026-11-07 11:51:34 -08:00
4 changed files with 81 additions and 112 deletions
+1
View File
@@ -1210,6 +1210,7 @@ config REGULATOR_QCOM_SMD_RPM
config REGULATOR_QCOM_SPMI
tristate "Qualcomm SPMI regulator driver"
depends on SPMI || COMPILE_TEST
select REGMAP_MMIO
help
If you say yes to this option, support will be included for the
regulators found in Qualcomm SPMI PMICs.
+52 -104
View File
@@ -4,7 +4,6 @@
// Copyright (c) 2025 Collabora Ltd
// AngeloGioacchino Del Regno <[email protected]>
#include <linux/bitfield.h>
#include <linux/delay.h>
#include <linux/devm-helpers.h>
#include <linux/err.h>
@@ -147,7 +146,7 @@ struct mt6363_regulator_info {
}
#define MT6363_LDO_LINEAR_OPS(match, vreg, in_sup, vops, min, max, \
step, buck_reg, ocp_intn) \
step, en_reg, lp_reg, ocp_intn) \
[MT6363_ID_##vreg] = { \
.desc = { \
.name = match, \
@@ -160,13 +159,13 @@ struct mt6363_regulator_info {
.n_voltages = (max - min) / step + 1, \
.min_uV = min, \
.uV_step = step, \
.enable_reg = MT6363_RG_##buck_reg##_EN_ADDR, \
.enable_reg = en_reg, \
.enable_mask = BIT(MT6363_RG_LDO_##vreg##_EN_BIT), \
.vsel_reg = MT6363_RG_LDO_##vreg##_VOSEL_ADDR, \
.vsel_mask = MT6363_RG_LDO_##vreg##_VOSEL_MASK, \
.of_map_mode = mt6363_map_mode, \
}, \
.lp_mode_reg = MT6363_RG_##buck_reg##_LP_ADDR, \
.lp_mode_reg = lp_reg, \
.lp_mode_mask = BIT(MT6363_RG_LDO_##vreg##_LP_BIT), \
.hw_lp_mode_reg = MT6363_LDO_##vreg##_HW_LP_MODE, \
.hw_lp_mode_mask = 0x4, \
@@ -176,12 +175,15 @@ struct mt6363_regulator_info {
#define MT6363_LDO_L_SC(match, vreg, inp, min, max, step, buck_reg, \
ocp_intn) \
MT6363_LDO_LINEAR_OPS(match, vreg, inp, mt6363_vreg_setclr_ops, \
min, max, step, buck_reg, ocp_intn)
min, max, step, \
MT6363_RG_##buck_reg##_EN_ADDR, \
MT6363_RG_##buck_reg##_LP_ADDR, ocp_intn)
#define MT6363_LDO_L(match, vreg, inp, min, max, step, buck_reg, \
ocp_intn) \
#define MT6363_LDO_L(match, vreg, inp, min, max, step, ocp_intn) \
MT6363_LDO_LINEAR_OPS(match, vreg, inp, mt6363_ldo_linear_ops, \
min, max, step, buck_reg, ocp_intn)
min, max, step, \
MT6363_RG_LDO_##vreg##_ADDR, \
MT6363_RG_LDO_##vreg##_ADDR, ocp_intn)
#define MT6363_LDO_LINEAR_CAL_OPS(match, vreg, in_sup, vops, vrnum, \
ocp_intn) \
@@ -381,7 +383,7 @@ static unsigned int mt6363_regulator_get_mode(struct regulator_dev *rdev)
static int mt6363_buck_unlock(struct regmap *map, bool unlock)
{
u16 buf = unlock ? MT6363_BUCK_TOP_UNLOCK_VALUE : 0;
__le16 buf = cpu_to_le16(unlock ? MT6363_BUCK_TOP_UNLOCK_VALUE : 0);
return regmap_bulk_write(map, MT6363_BUCK_TOP_KEY_PROT_LO, &buf, sizeof(buf));
}
@@ -482,31 +484,9 @@ static int mt6363_regulator_set_load(struct regulator_dev *rdev, int load_uA)
static int mt6363_vemc_set_voltage_sel(struct regulator_dev *rdev, unsigned int sel)
{
const u16 tma_unlock_key = MT6363_TMA_UNLOCK_VALUE;
const struct regulator_desc *rdesc = rdev->desc;
struct regmap *regmap = rdev->regmap;
unsigned int range, val;
int i, ret;
u16 mask;
for (i = 0; i < rdesc->n_linear_ranges; i++) {
const struct linear_range *r = &rdesc->linear_ranges[i];
unsigned int voltages_in_range = linear_range_values_in_range(r);
if (sel < voltages_in_range)
break;
sel -= voltages_in_range;
}
if (i == rdesc->n_linear_ranges)
return -EINVAL;
ret = regmap_read(rdev->regmap, MT6363_TOP_TRAP, &val);
if (ret)
return ret;
if (val > 1)
return -EINVAL;
const __le16 tma_unlock_key = cpu_to_le16(MT6363_TMA_UNLOCK_VALUE);
const __le16 tma_lock_key = cpu_to_le16(0);
int ret;
/* Unlock TMA for writing */
ret = regmap_bulk_write(rdev->regmap, MT6363_TOP_TMA_KEY_L,
@@ -514,76 +494,15 @@ static int mt6363_vemc_set_voltage_sel(struct regulator_dev *rdev, unsigned int
if (ret)
return ret;
/* If HW trapping value is 1, use VEMC_VOSEL_1 instead of VEMC_VOSEL_0 */
if (val == 1) {
mask = MT6363_RG_VEMC_VOSEL_1_MASK;
sel = FIELD_PREP(MT6363_RG_VEMC_VOSEL_1_MASK, sel);
} else {
mask = rdesc->vsel_mask;
}
ret = regulator_set_voltage_sel_pickable_regmap(rdev, sel);
sel <<= ffs(rdesc->vsel_mask) - 1;
sel += rdesc->linear_ranges[i].min_sel;
range = rdesc->linear_range_selectors_bitfield[i];
range <<= ffs(rdesc->vsel_range_mask) - 1;
/* Write to the vreg calibration register for voltage finetuning */
ret = regmap_update_bits(regmap, rdesc->vsel_range_reg,
rdesc->vsel_range_mask, range);
if (ret)
goto lock_tma;
/* Function must return the result of this write operation */
ret = regmap_update_bits(regmap, rdesc->vsel_reg, mask, sel);
lock_tma:
/* Unconditionally re-lock TMA */
val = 0;
regmap_bulk_write(rdev->regmap, MT6363_TOP_TMA_KEY_L, &val, 2);
regmap_bulk_write(rdev->regmap, MT6363_TOP_TMA_KEY_L,
&tma_lock_key, sizeof(tma_lock_key));
return ret;
}
static int mt6363_vemc_get_voltage_sel(struct regulator_dev *rdev)
{
const struct regulator_desc *rdesc = rdev->desc;
unsigned int vosel, trap, calsel;
int vcal, vsel, range, ret;
ret = regmap_read(rdev->regmap, rdesc->vsel_reg, &vosel);
if (ret)
return ret;
ret = regmap_read(rdev->regmap, rdesc->vsel_range_reg, &calsel);
if (ret)
return ret;
calsel &= rdesc->vsel_range_mask;
for (range = 0; range < rdesc->n_linear_ranges; range++)
if (rdesc->linear_range_selectors_bitfield[range] != calsel)
break;
if (range == rdesc->n_linear_ranges)
return -EINVAL;
ret = regmap_read(rdev->regmap, MT6363_TOP_TRAP, &trap);
if (ret)
return ret;
/* If HW trapping value is 1, use VEMC_VOSEL_1 instead of VEMC_VOSEL_0 */
if (trap > 1)
return -EINVAL;
else if (trap == 1)
vsel = FIELD_GET(MT6363_RG_VEMC_VOSEL_1_MASK, vosel);
else
vsel = vosel & rdesc->vsel_mask;
vcal = linear_range_values_in_range_array(rdesc->linear_ranges, range);
return vsel + vcal;
}
static int mt6363_va15_set_voltage_sel(struct regulator_dev *rdev, unsigned int sel)
{
struct regmap *regmap = rdev->regmap;
@@ -696,7 +615,7 @@ static const struct regulator_ops mt6363_ldo_vemc_ops = {
.list_voltage = regulator_list_voltage_pickable_linear_range,
.map_voltage = regulator_map_voltage_pickable_linear_range,
.set_voltage_sel = mt6363_vemc_set_voltage_sel,
.get_voltage_sel = mt6363_vemc_get_voltage_sel,
.get_voltage_sel = regulator_get_voltage_sel_pickable_regmap,
.set_voltage_time_sel = regulator_set_voltage_time_sel,
.enable = regulator_enable_regmap,
.disable = regulator_disable_regmap,
@@ -754,10 +673,10 @@ static struct mt6363_regulator_info mt6363_regulators[] = {
MT6363_LDO_VT("vio0p75", VIO075, "vs1-ldo1", 5, 36),
MT6363_LDO_VT("vio18", VIO18, "vs1-ldo2", 3, 35),
MT6363_LDO_VT("vm18", VM18, "vs1-ldo1", 4, 40),
MT6363_LDO_L("vsram-apu", VSRAM_APU, "vs3-ldo1", 400000, 1193750, 6250, BUCK1, 30),
MT6363_LDO_L("vsram-cpub", VSRAM_CPUB, "vs2-ldo1", 400000, 1193750, 6250, BUCK1, 27),
MT6363_LDO_L("vsram-cpum", VSRAM_CPUM, "vs2-ldo1", 400000, 1193750, 6250, BUCK1, 28),
MT6363_LDO_L("vsram-cpul", VSRAM_CPUL, "vs2-ldo2", 400000, 1193750, 6250, BUCK1, 29),
MT6363_LDO_L("vsram-apu", VSRAM_APU, "vs3-ldo1", 400000, 1193750, 6250, 30),
MT6363_LDO_L("vsram-cpub", VSRAM_CPUB, "vs2-ldo1", 400000, 1193750, 6250, 27),
MT6363_LDO_L("vsram-cpum", VSRAM_CPUM, "vs2-ldo1", 400000, 1193750, 6250, 28),
MT6363_LDO_L("vsram-cpul", VSRAM_CPUL, "vs2-ldo2", 400000, 1193750, 6250, 29),
MT6363_LDO_L_SC("vsram-digrf", VSRAM_DIGRF, "vs3-ldo1", 400000, 1193750, 6250, BUCK1, 23),
MT6363_LDO_L_SC("vsram-mdfe", VSRAM_MDFE, "vs3-ldo1", 400000, 1193750, 6250, BUCK1, 24),
MT6363_LDO_L_SC("vsram-modem", VSRAM_MODEM, "vs3-ldo2", 400000, 1193750, 6250, BUCK1, 25),
@@ -793,6 +712,30 @@ static int mt6363_backup_op_setting(struct regmap *map, struct mt6363_regulator_
return 0;
}
static int mt6363_vemc_select_bank(struct regmap *map, struct regulator_desc *desc)
{
unsigned int trap;
int ret;
ret = regmap_read(map, MT6363_TOP_TRAP, &trap);
if (ret)
return ret;
/* The hardware trap value selects which VEMC voltage controls are used */
switch (trap) {
case 0:
desc->vsel_reg = MT6363_RG_VEMC_VOCAL_ADDR;
desc->vsel_range_mask = MT6363_RG_VEMC_VOSEL_MASK;
return 0;
case 1:
desc->vsel_reg = MT6363_RG_VEMC_VOCAL_1_ADDR;
desc->vsel_range_mask = MT6363_RG_VEMC_VOSEL_1_MASK;
return 0;
default:
return -EINVAL;
}
}
static void mt6363_irq_remove(void *data)
{
int *virq = data;
@@ -811,7 +754,7 @@ static struct regmap *mt6363_spmi_register_regmap(struct device *dev)
{
struct regmap_config mt6363_regmap_config = {
.reg_bits = 16,
.val_bits = 16,
.val_bits = 8,
.max_register = 0x1f90,
.fast_io = true,
};
@@ -877,6 +820,11 @@ static int mt6363_regulator_probe(struct platform_device *pdev)
*/
regmap_read(config.regmap, MT6363_TOP_TRAP, &val);
ret = mt6363_vemc_select_bank(config.regmap,
&mt6363_regulators[MT6363_ID_VEMC].desc);
if (ret)
return dev_err_probe(dev, ret, "Failed to select VEMC bank\n");
interrupt_parent = of_irq_find_parent(dev->of_node);
if (!interrupt_parent)
return dev_err_probe(dev, -EINVAL, "Cannot find IRQ parent\n");
+27 -8
View File
@@ -12,13 +12,13 @@
#include <linux/bitops.h>
#include <linux/slab.h>
#include <linux/of.h>
#include <linux/of_address.h>
#include <linux/of_device.h>
#include <linux/platform_device.h>
#include <linux/ktime.h>
#include <linux/regulator/driver.h>
#include <linux/regmap.h>
#include <linux/list.h>
#include <linux/mfd/syscon.h>
#include <linux/io.h>
/* Pin control enable input pins. */
@@ -1335,6 +1335,14 @@ static irqreturn_t spmi_regulator_vs_ocp_isr(int irq, void *data)
static struct regmap *saw_regmap;
static const struct regmap_config saw_regmap_config = {
.name = "saw",
.reg_bits = 32,
.val_bits = 32,
.reg_stride = 4,
.use_raw_spinlock = true,
};
static void spmi_saw_set_vdd(void *data)
{
u32 vctl, data3, avs_ctl, pmic_sts;
@@ -2504,7 +2512,8 @@ static int qcom_spmi_regulator_probe(struct platform_device *pdev)
const char *name;
struct device *dev = &pdev->dev;
struct device_node *node = pdev->dev.of_node;
struct device_node *syscon, *reg_node;
struct device_node *saw, *reg_node;
void __iomem *saw_base;
struct property *reg_prop;
int ret, lenp;
struct list_head *vreg_list;
@@ -2523,12 +2532,22 @@ static int qcom_spmi_regulator_probe(struct platform_device *pdev)
if (!reg)
return -ENODEV;
syscon = of_parse_phandle(node, "qcom,saw-reg", 0);
if (syscon) {
saw_regmap = syscon_node_to_regmap(syscon);
of_node_put(syscon);
if (IS_ERR(saw_regmap))
dev_err(dev, "ERROR reading SAW regmap\n");
saw = of_parse_phandle(node, "qcom,saw-reg", 0);
if (saw) {
saw_base = devm_of_iomap(dev, saw, 0, NULL);
of_node_put(saw);
if (IS_ERR(saw_base))
return dev_err_probe(dev, PTR_ERR(saw_base),
"failed to map the SAW\n");
saw_regmap = devm_regmap_init_mmio(dev, saw_base,
&saw_regmap_config);
if (IS_ERR(saw_regmap)) {
ret = PTR_ERR(saw_regmap);
saw_regmap = NULL;
return dev_err_probe(dev, ret,
"failed to set the SAW regmap up\n");
}
}
for (; reg->name; reg++) {
@@ -138,6 +138,7 @@
#define MT6363_RG_LDO_VSRAM_APU_VOSEL_ADDR 0x1b17
#define MT6363_RG_LDO_VSRAM_APU_VOSEL_MASK GENMASK(6, 0)
#define MT6363_RG_VEMC_VOCAL_ADDR 0x1b1b
#define MT6363_RG_VEMC_VOCAL_1_ADDR 0x1b1c
#define MT6363_RG_VEMC_VOCAL_MASK GENMASK(3, 0)
#define MT6363_RG_LDO_VCN15_ADDR 0x1b57
#define MT6363_RG_LDO_VCN15_EN_BIT 0