From ef1ce4231a6e2ba6f70ab311b0886598b1dc37b0 Mon Sep 17 00:00:00 2001 From: ontim52 Date: Wed, 16 Aug 2023 10:40:29 +0800 Subject: [PATCH] kernel: add debug-config for debug use 1. gpio status printed before cpu sleep, for debug use. 2. enable dump clk/regulator on suspend for userdebug SW. Change-Id: Icb45c5bd9300650bba4ab6c8795b492bedaa25de Signed-off-by: ontim52 Reviewed-on: https://gerrit.mot.com/2710381 SLTApproved: Slta Waiver SME-Granted: SME Approvals Granted Tested-by: Jira Key Reviewed-by: Huosheng Liao Submit-Approved: Jira Key --- arch/arm64/configs/vendor/holi_debug.config | 3 + drivers/clk/clk.c | 2 +- drivers/cpuidle/lpm-levels.c | 3 + drivers/gpio/gpiolib.c | 99 +++++++++++++++++++++ drivers/regulator/core.c | 2 +- init/Kconfig | 9 ++ 6 files changed, 116 insertions(+), 2 deletions(-) diff --git a/arch/arm64/configs/vendor/holi_debug.config b/arch/arm64/configs/vendor/holi_debug.config index 8cf2926d45f4..fe2e00c5079e 100644 --- a/arch/arm64/configs/vendor/holi_debug.config +++ b/arch/arm64/configs/vendor/holi_debug.config @@ -140,3 +140,6 @@ CONFIG_MMC_IPC_LOGGING=y CONFIG_CRYPTO_SHA1_ARM64_CE=y CONFIG_DEBUG_PAGEALLOC=y CONFIG_DEBUG_PAGEALLOC_ENABLE_DEFAULT=y +CONFIG_DUMP_GPIO_ON_SUSPEND=y +CONFIG_DUMP_CLK_ON_SUSPEND=y +CONFIG_DUMP_REGULATOR_ON_SUSPEND=y diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index f385e141577c..c076e6a7460f 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -3481,7 +3481,7 @@ static const struct file_operations clk_enabled_list_fops = { .release = seq_release, }; -static u32 debug_suspend; +static u32 debug_suspend = IS_ENABLED(CONFIG_DUMP_CLK_ON_SUSPEND); /* * Print the names of all enabled clocks and their parents if diff --git a/drivers/cpuidle/lpm-levels.c b/drivers/cpuidle/lpm-levels.c index 50564ec5ef3f..6ac5669c0403 100644 --- a/drivers/cpuidle/lpm-levels.c +++ b/drivers/cpuidle/lpm-levels.c @@ -123,6 +123,8 @@ static void cluster_prepare(struct lpm_cluster *cluster, static bool sleep_disabled; module_param_named(sleep_disabled, sleep_disabled, bool, 0664); +extern void gpio_debug_print_enabled(void); + #ifdef CONFIG_SMP static int lpm_cpu_qos_notify(struct notifier_block *nb, unsigned long val, void *ptr); @@ -1119,6 +1121,7 @@ static int cluster_configure(struct lpm_cluster *cluster, int idx, if (!from_idle) { clock_debug_print_enabled(); regulator_debug_print_enabled(); + gpio_debug_print_enabled(); } cpu = get_next_online_cpu(from_idle); diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index abdf448b11a3..bbdcce68a206 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -5063,6 +5063,104 @@ static int gpiolib_seq_show(struct seq_file *s, void *v) return 0; } +static u32 debug_gpio = IS_ENABLED(CONFIG_DUMP_GPIO_ON_SUSPEND); +void gpio_debug_print_enabled(void) +{ + unsigned long flags; + struct gpio_device *gdev = NULL; + struct seq_file *s; + int back; + + if (likely(!debug_gpio)) + { + return; + } + + printk("======================= Dump GPIO status begin ======================="); + spin_lock_irqsave(&gpio_lock, flags); + s = kzalloc(sizeof(struct seq_file), GFP_KERNEL); + if(s == NULL) + { + printk("hxy struct seq file failed to alloc memory"); + return; + } + s->index = 0; + s->version = 0; + s->count = s->from = 0; + s->read_pos= 0; + s->private = NULL; + s->file = NULL; + s->op = NULL; + s->private = ""; + + s->buf = kzalloc(s->size = PAGE_SIZE,GFP_KERNEL_ACCOUNT); + if (!s->buf) + { + printk("hxy seq file buffer failed to alloc memory %d bytes",s->size); + kfree(s ); + return ; + } + + list_for_each_entry(gdev, &gpio_devices, list) + { + try_again: + s->count = 0; + back=s->count; + + gpiolib_seq_show(s,gdev); + + if(s->count >= s->size) + { + kfree(s->buf ); + s->buf = kzalloc(s->size = (s->size*2),GFP_KERNEL_ACCOUNT); + if (!s->buf) + { + printk("hxy seq file buffer failed to alloc memory %d bytes",s->size); + kfree(s ); + return ; + } + goto try_again; + } + s->buf[s->count] = '\0'; + { + char tt[256]; + char *ptr; + char *ptr1; + int n; + int loop; + + ptr1=s->buf+back; + ptr=strstr(ptr1,"\x0a"); + loop=0; + while(ptr != NULL && (loop++ < 500) && (ptr < (s->buf+ s->size))) + { + n=ptr-ptr1; + strncpy(tt,ptr1,n); + tt[n]='\0'; + printk(" %s",tt); + ptr1 = ptr+strlen("\x0a"); + ptr=strstr(ptr1,"\x0a"); + } + } + } + + if(s->buf != NULL) + { + kfree(s->buf ); + s->buf = NULL; + } + if(s != NULL) + { + kfree(s ); + s = NULL; + } + spin_unlock_irqrestore(&gpio_lock, flags); + printk("======================= Dump GPIO status end ======================="); + +} + +EXPORT_SYMBOL(gpio_debug_print_enabled); + static const struct seq_operations gpiolib_seq_ops = { .start = gpiolib_seq_start, .next = gpiolib_seq_next, @@ -5088,6 +5186,7 @@ static int __init gpiolib_debugfs_init(void) /* /sys/kernel/debug/gpio */ debugfs_create_file("gpio", S_IFREG | S_IRUGO, NULL, NULL, &gpiolib_operations); + debugfs_create_u32("debug_gpio", 0644, NULL, &debug_gpio); return 0; } subsys_initcall(gpiolib_debugfs_init); diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 018534248353..40ef341f879b 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -55,7 +55,7 @@ static LIST_HEAD(regulator_supply_alias_list); static LIST_HEAD(regulator_coupler_list); static bool has_full_constraints; #ifdef CONFIG_DEBUG_FS -static bool debug_suspend; +static bool debug_suspend = IS_ENABLED(CONFIG_DUMP_REGULATOR_ON_SUSPEND); #endif static struct dentry *debugfs_root; diff --git a/init/Kconfig b/init/Kconfig index 10e37d91b9de..0c7ec0ac0951 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -639,6 +639,15 @@ config IKHEADERS or similar programs. If you build the headers as a module, a module called kheaders.ko is built which can be loaded on-demand to get access to headers. +config DUMP_GPIO_ON_SUSPEND + bool "dump gpio on suspend" + +config DUMP_CLK_ON_SUSPEND + bool "dump clk on suspend" + +config DUMP_REGULATOR_ON_SUSPEND + bool "dump regulator on suspend" + config LOG_BUF_SHIFT int "Kernel log buffer size (16 => 64KB, 17 => 128KB)" range 12 25 if !H8300