Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lk2nd: hw: regulator: gpl: Add PM8937 support and improve error logging #463

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

andrewgigena
Copy link
Contributor

@andrewgigena andrewgigena commented Dec 15, 2024

This PR is part of my research to enable support for sdcard on Nokia 5. I added 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. Code extracted from this patch by danct12

Tested on Nokia 5 (nokia-nd1):

$ fastboot oem debug spmi-regulators
(bootloader) Detected PMIC 0x10019
(bootloader) Regulator list:
(bootloader)   s1: 1225000 mV, disabled,   fast  (smps)
(bootloader)   s2: 1125000 mV,  enabled,   fast  (smps)
(bootloader)   s3: 1350000 mV,  enabled,   fast  (smps)
(bootloader)   s4: 2050000 mV,  enabled,   fast  (smps)
(bootloader)   s5: 1225000 mV,  enabled,   fast  (ftsmps2p5)
(bootloader)   s6: 1225000 mV,  enabled,   fast  (ftsmps2p5)
(bootloader)   l1: 1000000 mV, disabled, normal  (ult_nldo)
(bootloader)   l2: 1200000 mV,  enabled, normal  (ult_nldo)
(bootloader)   l3: 1287500 mV,  enabled,   idle  (ult_nldo)
(bootloader)   l4: 1800000 mV, disabled, normal  (ult_pldo)
(bootloader)   l5: 1800000 mV,  enabled,   idle  (ult_pldo)
(bootloader)   l6: 1800000 mV,  enabled, normal  (ult_pldo)
(bootloader)   l7: 1800000 mV,  enabled, normal  (ult_pldo)
(bootloader)   l8: 2900000 mV,  enabled, normal  (ult_pldo)
(bootloader)   l9: 3300000 mV, disabled, normal  (ult_pldo)
(bootloader)  l10: 2800000 mV,  enabled, normal  (ult_pldo)
(bootloader)  l11: 2950000 mV, disabled, normal  (ult_pldo)
(bootloader)  l12: 2950000 mV,  enabled, normal  (ult_pldo)
(bootloader)  l13: 3075000 mV,  enabled, normal  (ult_pldo)
(bootloader)  l14: 1800000 mV, disabled, normal  (ult_pldo)
(bootloader)  l15: 1800000 mV, disabled, normal  (ult_pldo)
(bootloader)  l16: 1800000 mV, disabled, normal  (ult_pldo)
(bootloader)  l17: 2850000 mV,  enabled, normal  (ult_pldo)
(bootloader)  l18: 2700000 mV, disabled, normal  (ult_pldo)
(bootloader)  l19: 1300000 mV, disabled, normal  (ult_nldo)
(bootloader)  l20: 1740000 mV, disabled  (ln_ldo)
(bootloader)  l21: 1740000 mV, disabled  (ln_ldo)
(bootloader)  l22: 2800000 mV, disabled, normal  (ult_pldo)
(bootloader)  l23: 1300000 mV, disabled, normal  (nldo1)
(bootloader) Detected PMIC 0x20011
(bootloader) No regulators found
OKAY [  0.038s]
Finished. Total time: 0.038s

Tested on Xiaomi Redmi 4 (xiaomi-santoni):

$ fastboot oem debug spmi-regulators
(bootloader) Detected PMIC 0x10019
(bootloader) Regulator list:
(bootloader)   s1: 1225000 mV, disabled,   fast  (smps)
(bootloader)   s2: 1175000 mV,  enabled,   fast  (smps)
(bootloader)   s3: 1412500 mV,  enabled,   fast  (smps)
(bootloader)   s4: 2050000 mV,  enabled,   fast  (smps)
(bootloader)   s5: 1225000 mV,  enabled,   fast  (ftsmps2p5)
(bootloader)   s6: 1225000 mV,  enabled,   fast  (ftsmps2p5)
(bootloader)   l1: 1000000 mV, disabled, normal  (ult_nldo)
(bootloader)   l2: 1250000 mV,  enabled, normal  (ult_nldo)
(bootloader)   l3: 1350000 mV,  enabled,   idle  (ult_nldo)
(bootloader)   l4: 1800000 mV, disabled, normal  (ult_pldo)
(bootloader)   l5: 1800000 mV,  enabled,   idle  (ult_pldo)
(bootloader)   l6: 1800000 mV,  enabled, normal  (ult_pldo)
(bootloader)   l7: 1800000 mV,  enabled, normal  (ult_pldo)
(bootloader)   l8: 2900000 mV,  enabled, normal  (ult_pldo)
(bootloader)   l9: 3300000 mV, disabled, normal  (ult_pldo)
(bootloader)  l10: 2800000 mV, disabled, normal  (ult_pldo)
(bootloader)  l11: 2950000 mV,  enabled, normal  (ult_pldo)
(bootloader)  l12: 2950000 mV,  enabled, normal  (ult_pldo)
(bootloader)  l13: 3075000 mV,  enabled, normal  (ult_pldo)
(bootloader)  l14: 1800000 mV, disabled, normal  (ult_pldo)
(bootloader)  l15: 1800000 mV, disabled, normal  (ult_pldo)
(bootloader)  l16: 1800000 mV, disabled, normal  (ult_pldo)
(bootloader)  l17: 2850000 mV,  enabled, normal  (ult_pldo)
(bootloader)  l18: 2700000 mV, disabled, normal  (ult_pldo)
(bootloader)  l19: 1300000 mV, disabled, normal  (ult_nldo)
(bootloader)  l20: 1740000 mV, disabled  (ln_ldo)
(bootloader)  l21: 1740000 mV, disabled  (ln_ldo)
(bootloader)  l22: 2800000 mV, disabled, normal  (ult_pldo)
(bootloader)  l23: 1300000 mV, disabled, normal  (nldo1)
(bootloader) Detected PMIC 0x20011
(bootloader) No regulators found
OKAY [  0.038s]
Finished. Total time: 0.038s

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`.
@andrewgigena andrewgigena force-pushed the pm8937-spmi-regulators branch from 123faf8 to ef8d1d5 Compare December 15, 2024 04:56
struct regulator_dev *rdev = spmi_regulator_probe(target);
if (!rdev) {
snprintf(response, sizeof(response), "No regulators found");
fastboot_info(response);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fastboot_info("No regulators found") should work I think, same below

@@ -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 },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is meant to be synced completely with upstream to add all the new entries. I just did that and pushed to main, can you rebase to drop these changes?

@andrewgigena
Copy link
Contributor Author

@stephan-gh Hi, I did the rebase locally, here you have the code with the changes after the rebase. Should we modify this PR to add only this logs?

diff --git a/lk2nd/fastboot/debug/regulator.c b/lk2nd/fastboot/debug/regulator.c
index 5fe25e52..3e7b52c5 100644
--- a/lk2nd/fastboot/debug/regulator.c
+++ b/lk2nd/fastboot/debug/regulator.c
@@ -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("");
 }
diff --git a/lk2nd/hw/regulator/gpl/qcom_spmi-regulator.c b/lk2nd/hw/regulator/gpl/qcom_spmi-regulator.c
index c84e1220..aae17f23 100644
--- a/lk2nd/hw/regulator/gpl/qcom_spmi-regulator.c
+++ b/lk2nd/hw/regulator/gpl/qcom_spmi-regulator.c
@@ -2750,15 +2750,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];
@@ -2768,9 +2772,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;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants