Skip to content

Commit

Permalink
lk2nd: fastboot: debug: Add command to dump SPMI regulator state
Browse files Browse the repository at this point in the history
This allows reading which PMIC/SPMI regulators are enabled and which
voltage they are configured with during boot.

Example output for PM8916 on MSM8916:

$ fastboot oem debug spmi-regulators
(bootloader) Detected PMIC 0x2000b
(bootloader)   s1: 1012500 mV,  enabled, normal  (ult_lo_smps)
(bootloader)   s2: 1150000 mV,  enabled, normal  (ult_lo_smps)
(bootloader)   s3: 1250000 mV,  enabled, normal  (ult_lo_smps)
(bootloader)   s4: 2050000 mV,  enabled, normal  (ult_ho_smps)
(bootloader)   l1: 1287500 mV, disabled, normal  (ult_nldo)
(bootloader)   l2: 1200000 mV,  enabled,   idle  (ult_nldo)
(bootloader)   l3: 1150000 mV,  enabled,   idle  (ult_nldo)
(bootloader)   l4: 2050000 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,   idle  (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)
  • Loading branch information
stephan-gh committed Sep 9, 2023
1 parent f3cbd7e commit ee60a2b
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
58 changes: 58 additions & 0 deletions lk2nd/fastboot/debug/regulator.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// SPDX-License-Identifier: BSD-3-Clause
/* Copyright (c) 2023, Stephan Gerhold <[email protected]> */

#include <board.h>
#include <fastboot.h>
#include <printf.h>
#include <stdint.h>

#include <lk2nd/hw/regulator.h>
#include <lk2nd/util/minmax.h>

static const char * const regulator_state[] = {
"unknown", "disabled", "enabled",
};

static const char * const regulator_modes[] = {
"", ", fast", ", normal", ", idle"
};

static void dump_regulator(struct regulator_dev *rdev)
{
char response[MAX_RSP_SIZE];

snprintf(response, sizeof(response),
"%4s: %7d mV, %8s%s%s (%s)",
rdev->name,
regulator_get_voltage(rdev),
regulator_state[clamp(regulator_is_enabled(rdev), -1, 1) + 1],
regulator_modes[regulator_get_mode(rdev)],
regulator_is_bypassed(rdev) == 1 ? ", bypassed" : "",
rdev->driver_type);
fastboot_info(response);
}

static void dump_regulators(struct regulator_dev *rdev)
{
for (; rdev; rdev = rdev->next)
dump_regulator(rdev);
}

static void cmd_oem_debug_spmi_regulators(const char *arg, void *data, unsigned sz)
{
char response[MAX_RSP_SIZE];
uint32_t target;
int i;

for (i = 0; i < MAX_PMIC_DEVICES; ++i) {
target = board_pmic_target(i);
if (!target)
break;

snprintf(response, sizeof(response), "Detected PMIC %#x", target);
fastboot_info(response);
dump_regulators(spmi_regulator_probe(target));
}
fastboot_okay("");
}
FASTBOOT_REGISTER("oem debug spmi-regulators", cmd_oem_debug_spmi_regulators);
8 changes: 8 additions & 0 deletions lk2nd/fastboot/debug/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,11 @@ LOCAL_DIR := $(GET_LOCAL_DIR)
OBJS += \
$(LOCAL_DIR)/cpuid.o \
$(LOCAL_DIR)/register.o \

# Currently the regulator fastboot debug code is only used for SPMI regulators
ifneq ($(filter dev/pmic/pm8x41, $(ALLMODULES)),)
ifneq ($(BUILD_GPL),)
MODULES += lk2nd/hw/regulator
OBJS += $(LOCAL_DIR)/regulator.o
endif
endif

0 comments on commit ee60a2b

Please sign in to comment.