Skip to content

Commit

Permalink
lk2nd: hw: regulator: gpl: Add PM8937 support and improve error logging
Browse files Browse the repository at this point in the history
Add support for the PM8937 SPMI regulator and enhance error logging in the `spmi_regulator_probe` function. Also, improve debugging output in `cmd_oem_debug_spmi_regulators`.
  • Loading branch information
andrewgigena committed Dec 15, 2024
1 parent 2d4c54b commit 123faf8
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 6 deletions.
11 changes: 10 additions & 1 deletion lk2nd/fastboot/debug/regulator.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,16 @@ static void cmd_oem_debug_spmi_regulators(const char *arg, void *data, unsigned

snprintf(response, sizeof(response), "Detected PMIC %#x", target);
fastboot_info(response);
dump_regulators(spmi_regulator_probe(target));

struct regulator_dev *rdev = spmi_regulator_probe(target);
if (!rdev) {
snprintf(response, sizeof(response), "No regulators found");
fastboot_info(response);
} else {
snprintf(response, sizeof(response), "Regulator list:");
fastboot_info(response);
dump_regulators(rdev);
}
}
fastboot_okay("");
}
Expand Down
1 change: 1 addition & 0 deletions lk2nd/hw/regulator/gpl/qcom-spmi-pmic.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#define PM8998_SUBTYPE 0x14
#define PMI8998_SUBTYPE 0x15
#define PM8005_SUBTYPE 0x18
#define PM8937_SUBTYPE 0x19
#define PM660L_SUBTYPE 0x1a
#define PM660_SUBTYPE 0x1b
#define PM8150_SUBTYPE 0x1e
Expand Down
50 changes: 45 additions & 5 deletions lk2nd/hw/regulator/gpl/qcom_spmi-regulator.c
Original file line number Diff line number Diff line change
Expand Up @@ -2269,6 +2269,39 @@ static const struct spmi_regulator_data pm8916_regulators[] = {
{ }
};

static const struct spmi_regulator_data pm8937_regulators[] = {
{ "s1", 0x1400, "vdd_s1", },
{ "s2", 0x1700, "vdd_s2", },
{ "s3", 0x1a00, "vdd_s3", },
{ "s4", 0x1d00, "vdd_s4", },
{ "s5", 0x2000, "vdd_s5", },
{ "s6", 0x2300, "vdd_s6", },
{ "l1", 0x4000, "vdd_l1_l19", },
{ "l2", 0x4100, "vdd_l2_l23", },
{ "l3", 0x4200, "vdd_l3", },
{ "l4", 0x4300, "vdd_l4_l5_l6_l7_l16", },
{ "l5", 0x4400, "vdd_l4_l5_l6_l7_l16", },
{ "l6", 0x4500, "vdd_l4_l5_l6_l7_l16", },
{ "l7", 0x4600, "vdd_l4_l5_l6_l7_l16", },
{ "l8", 0x4700, "vdd_l8_l11_l12_l17_l22", },
{ "l9", 0x4800, "vdd_l9_l10_l13_l14_l15_l18", },
{ "l10", 0x4900, "vdd_l9_l10_l13_l14_l15_l18", },
{ "l11", 0x4a00, "vdd_l8_l11_l12_l17_l22", },
{ "l12", 0x4b00, "vdd_l8_l11_l12_l17_l22", },
{ "l13", 0x4c00, "vdd_l9_l10_l13_l14_l15_l18", },
{ "l14", 0x4d00, "vdd_l9_l10_l13_l14_l15_l18", },
{ "l15", 0x4e00, "vdd_l9_l10_l13_l14_l15_l18", },
{ "l16", 0x4f00, "vdd_l4_l5_l6_l7_l16", },
{ "l17", 0x5000, "vdd_l8_l11_l12_l17_l22", },
{ "l18", 0x5100, "vdd_l9_l10_l13_l14_l15_l18", },
{ "l19", 0x5200, "vdd_l1_l19", },
{ "l20", 0x5300, "vdd_l20_l21", },
{ "l21", 0x5400, "vdd_l21_l21", },
{ "l22", 0x5500, "vdd_l8_l11_l12_l17_l22", },
{ "l23", 0x5600, "vdd_l2_l23", },
{ }
};

static const struct spmi_regulator_data pm8941_regulators[] = {
{ "s1", 0x1400, "vdd_s1", },
{ "s2", 0x1700, "vdd_s2", },
Expand Down Expand Up @@ -2586,6 +2619,7 @@ static const struct spmi_regulator_match qcom_spmi_regulator_match[] = {
{ .subtype = PM8226_SUBTYPE, .sid = 1, .data = pm8226_regulators },
{ .subtype = PM8841_SUBTYPE, .sid = 5, .data = pm8841_regulators },
{ .subtype = PM8916_SUBTYPE, .sid = 1, .data = pm8916_regulators },
{ .subtype = PM8937_SUBTYPE, .sid = 1, .data = pm8937_regulators },
{ .subtype = PM8941_SUBTYPE, .sid = 1, .data = pm8941_regulators },
{ .subtype = PM8950_SUBTYPE, .sid = 1, .data = pm8950_regulators },
{ .subtype = PM8994_SUBTYPE, .sid = 1, .data = pm8994_regulators },
Expand Down Expand Up @@ -2619,15 +2653,19 @@ struct regulator_dev *spmi_regulator_probe(uint8_t subtype)
unsigned int i;
int ret;

if (!match)
if (!match) {
dprintf(CRITICAL, "Failed to find SPMI regulator match for subtype 0x%02X\n", subtype);
return NULL;
}

for (data = match->data; data->name; ++data)
++num;

vreg = calloc(num, sizeof(*vreg));
if (!vreg)
if (!vreg) {
dprintf(CRITICAL, "Failed to allocate memory for SPMI regulator\n");
return NULL;
}

for (i = 0; i < num; ++i) {
const struct spmi_regulator_data *reg = &match->data[i];
Expand All @@ -2637,9 +2675,11 @@ struct regulator_dev *spmi_regulator_probe(uint8_t subtype)
vreg[i].base = (match->sid << 16) | reg->base;

ret = spmi_regulator_match(&vreg[i], reg->force_type);
if (ret)
dprintf(CRITICAL, "Failed to match SPMI regulator %s\n",
reg->name);
if (ret) {
dprintf(CRITICAL, "Failed to match SPMI regulator %s\n", reg->name);
dprintf(CRITICAL, "subtype=%u, force_type=0x%02X, logical_type=%u\n",
subtype, reg->force_type, vreg[i].logical_type);
}

if (vreg[i].set_points)
vreg[i].desc.driver_type = vreg[i].set_points->type;
Expand Down

0 comments on commit 123faf8

Please sign in to comment.