yuezonghe | 824eb0c | 2024-06-27 02:32:26 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/arch/arm/mach-zx297520v2/debug.c |
| 3 | * |
| 4 | * Copyright (C) 2015 ZTE-TSP |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | */ |
| 16 | |
| 17 | #include <linux/kernel.h> |
| 18 | #include <linux/interrupt.h> |
| 19 | #include <linux/irq.h> |
| 20 | #include <linux/clockchips.h> |
| 21 | #include <linux/clk.h> |
| 22 | #include <linux/module.h> |
| 23 | #include <linux/err.h> |
| 24 | #include <linux/syscore_ops.h> |
| 25 | #include <linux/gpio.h> |
| 26 | |
| 27 | #include <asm/mach/time.h> |
| 28 | |
| 29 | #include <mach/timex.h> |
| 30 | #include <mach/iomap.h> |
| 31 | #include <mach/debug.h> |
| 32 | #include <mach/irqs.h> |
| 33 | #include <mach/gpio.h> |
| 34 | |
| 35 | #include <linux/ramdump/ramdump.h> |
| 36 | |
| 37 | #define CONFIG_USE_DEBUG_LED 0 |
| 38 | /* |
| 39 | * we use sysfs to test&debug some system funcs |
| 40 | * |
| 41 | */ |
| 42 | struct kobject *zx_root_kobj; |
| 43 | struct kobject *zx_test_kobj; |
| 44 | |
| 45 | extern int __init zx_clk_test_init(void); |
| 46 | extern int __init zx_dma_test_init(void); |
| 47 | extern int __init zx_icp_test_init(void); |
| 48 | |
| 49 | /* |
| 50 | * test led helper interface |
| 51 | * |
| 52 | */ |
| 53 | #if CONFIG_USE_DEBUG_LED |
| 54 | static void test_led_init(void) |
| 55 | { |
| 56 | int ret; |
| 57 | |
| 58 | ret = gpio_request(ZX29_GPIO_16, "gpio16_led"); |
| 59 | if (ret) |
| 60 | { |
| 61 | pr_info("gpio16_led gpio request error.\n"); |
| 62 | return ; |
| 63 | } |
| 64 | |
| 65 | zx29_gpio_config(ZX29_GPIO_16, 0); /*GPIO*/ |
| 66 | gpio_direction_output(ZX29_GPIO_16, GPIO_LOW); |
| 67 | } |
| 68 | static void test_led_on(void) |
| 69 | { |
| 70 | gpio_direction_output(ZX29_GPIO_16, GPIO_HIGH); |
| 71 | } |
| 72 | static void test_led_off(void) |
| 73 | { |
| 74 | gpio_direction_output(ZX29_GPIO_16, GPIO_LOW); |
| 75 | } |
| 76 | #else |
| 77 | static void test_led_init(void){} |
| 78 | static void test_led_on(void){} |
| 79 | static void test_led_off(void){} |
| 80 | #endif |
| 81 | |
| 82 | |
| 83 | /*============================================================================= |
| 84 | *======== /sys/zte/test/timer ============================================== |
| 85 | *============================================================================= |
| 86 | */ |
| 87 | static ssize_t timer_show(struct kobject *kobj, struct kobj_attribute *attr, |
| 88 | char *buf) |
| 89 | { |
| 90 | char *s = buf; |
| 91 | |
| 92 | s += sprintf(s, "%s\n", "[TEST]Test will light on/off led every 5s~"); |
| 93 | |
| 94 | return (s - buf); |
| 95 | } |
| 96 | |
| 97 | /*echo 1 > /sys/zte/test/timer*/ |
| 98 | static struct timer_list test_timer; |
| 99 | static unsigned long test_timer_count = 0; |
| 100 | static void test_timer_expired(unsigned long data) |
| 101 | { |
| 102 | mod_timer(&test_timer, jiffies + msecs_to_jiffies(5*1000)); |
| 103 | |
| 104 | pr_info("[TEST]Test timer arrived:%lu \n", ++test_timer_count); |
| 105 | |
| 106 | if(test_timer_count&1) |
| 107 | test_led_on(); |
| 108 | else |
| 109 | test_led_off(); |
| 110 | } |
| 111 | |
| 112 | static ssize_t timer_store(struct kobject *kobj, struct kobj_attribute *attr, |
| 113 | const char *buf, size_t n) |
| 114 | { |
| 115 | int error = 0; |
| 116 | long temp; |
| 117 | // BUG(); |
| 118 | if(strict_strtol(buf, 0, &temp)) |
| 119 | error = -EINVAL; |
| 120 | |
| 121 | if(temp == 1) |
| 122 | { |
| 123 | mod_timer(&test_timer, jiffies + msecs_to_jiffies(5*1000)); |
| 124 | } |
| 125 | else |
| 126 | { |
| 127 | del_timer(&test_timer); |
| 128 | test_timer_count = 0; |
| 129 | } |
| 130 | |
| 131 | return error ? error : n; |
| 132 | } |
| 133 | |
| 134 | zte_attr(timer); |
| 135 | |
| 136 | /*============================================================================= |
| 137 | *======== /sys/zte/test/timer ============================================== |
| 138 | *============================================================================= |
| 139 | */ |
| 140 | /*echo 0xXXXXXXXX > /sys/zte/test/reg_read*/ |
| 141 | static ssize_t reg_read_show(struct kobject *kobj, struct kobj_attribute *attr, |
| 142 | char *buf) |
| 143 | { |
| 144 | char *s = buf; |
| 145 | |
| 146 | // s += sprintf(s, "%s\n", "[TEST]Read register[0xXXXXXXXX] value~"); |
| 147 | s += sprintf(s, "reg[0xf8b0002c]=%x, reg[0xf8801010]=%x, reg[0xf880100c]=%x \n", \ |
| 148 | ioread32((void __iomem *)0xf8b0002c), ioread32((void __iomem *)0xf8801010), \ |
| 149 | ioread32((void __iomem *)0xf880100c)); |
| 150 | |
| 151 | return (s - buf); |
| 152 | } |
| 153 | |
| 154 | static ssize_t reg_read_store(struct kobject *kobj, struct kobj_attribute *attr, |
| 155 | const char *buf, size_t n) |
| 156 | { |
| 157 | int error = 0; |
| 158 | unsigned long temp; |
| 159 | |
| 160 | if(strict_strtol(buf, 16, (long *)&temp)) |
| 161 | error = -EINVAL; |
| 162 | |
| 163 | pr_info("reg[%x]=%x", temp, ioread32((void __iomem *)temp)); |
| 164 | |
| 165 | return error ? error : n; |
| 166 | } |
| 167 | |
| 168 | zte_attr(reg_read); |
| 169 | |
| 170 | /*test group*/ |
| 171 | static struct attribute * g[] = |
| 172 | { |
| 173 | &timer_attr.attr, |
| 174 | ®_read_attr.attr, |
| 175 | NULL, |
| 176 | }; |
| 177 | |
| 178 | |
| 179 | static struct attribute_group zte_test_attr_group = |
| 180 | { |
| 181 | .attrs = g, |
| 182 | }; |
| 183 | |
| 184 | /** |
| 185 | * 1¡¢create sysfs "/sys/zte/test" |
| 186 | * 2¡¢call other debug modules |
| 187 | */ |
| 188 | static int __init zx_test_init(void) |
| 189 | { |
| 190 | int ret; |
| 191 | |
| 192 | zx_test_kobj = kobject_create_and_add("test", zx_root_kobj); |
| 193 | if (!zx_test_kobj) |
| 194 | return -ENOMEM; |
| 195 | |
| 196 | ret = sysfs_create_group(zx_test_kobj, &zte_test_attr_group); |
| 197 | if (ret) |
| 198 | { |
| 199 | pr_info("[DEBUG] sysfs_create_group ret %d\n", ret); |
| 200 | return ret; |
| 201 | } |
| 202 | |
| 203 | setup_timer(&test_timer, test_timer_expired, 0); |
| 204 | |
| 205 | test_led_init(); |
| 206 | |
| 207 | pr_info("[DEBUG] create test sysfs interface OK.\n"); |
| 208 | return 0; |
| 209 | } |
| 210 | |
| 211 | static void sys_ramdump_config(void) |
| 212 | { |
| 213 | ramdump_ram_conf_table_add("pcu_reg",0x13a000,0x7e0,ZX_PCU_BASE,0,0); |
| 214 | ramdump_ram_conf_table_add("soc_sys_reg",0x140000,0x620,ZX_SOC_SYS_BASE,0,0); |
| 215 | ramdump_ram_conf_table_add("std_crm_reg",0x1306000,0x4a0,ZX_MATRIX_CRM_BASE,0,0); |
| 216 | ramdump_ram_conf_table_add("lsp_crm_reg",0x1400000,0x150,ZX_LSP_CRPM_BASE,0,0); |
| 217 | ramdump_ram_conf_table_add("top_crm_reg",0x13b000,0x4b0,ZX_TOP_CRM_BASE,0,0); |
| 218 | ramdump_ram_conf_table_add("ICP_reg",0x1302000,0x920,ZX_ICP_BASE,0,0); |
| 219 | ramdump_ram_conf_table_add("IRAM1_reg",0x100000,0x10000,ZX_IRAM1_BASE,0,0); |
| 220 | ramdump_ram_conf_table_add("DMA_reg",0x1301000,0x1000,ZX_DMA_PS_BASE,0,0); |
| 221 | |
| 222 | ramdump_ram_conf_table_add("RM_TIMER0_reg",0x142000,0x20,ZX_RM_TIMER0_BASE,0,0); |
| 223 | ramdump_ram_conf_table_add("AP_TIMER1_reg",0x143000,0x20,ZX_AP_TIMER1_BASE,0,0); |
| 224 | ramdump_ram_conf_table_add("AP_TIMER2_reg",0x144000,0x20,ZX_AP_TIMER2_BASE,0,0); |
| 225 | ramdump_ram_conf_table_add("RM_TIMER1_reg",0x145000,0x20,ZX_RM_TIMER1_BASE,0,0); |
| 226 | ramdump_ram_conf_table_add("AP_TIMER3_reg",0x146000,0x20,ZX_AP_TIMER3_BASE,0,0); |
| 227 | ramdump_ram_conf_table_add("PS_TIMER1_reg",0x138000,0x20,ZX_PS_TIMER1_BASE,0,0); |
| 228 | ramdump_ram_conf_table_add("PS_TIMER2_reg",0x139000,0x20,ZX_PS_TIMER2_BASE,0,0); |
| 229 | ramdump_ram_conf_table_add("PS_TIMER0_reg",0x1401000,0x20,ZX_PS_TIMER0_BASE,0,0); |
| 230 | ramdump_ram_conf_table_add("PS_RM_TIMER_reg",0x140B000,0x20,ZX_PS_RM_TIMER_BASE,0,0); |
| 231 | ramdump_ram_conf_table_add("AP_TIMER0_reg",0x140F000,0x20,ZX_AP_TIMER0_BASE,0,0); |
| 232 | ramdump_ram_conf_table_add("AP_TIMER4_reg",0x1411000,0x20,ZX_AP_TIMER4_BASE,0,0); |
| 233 | ramdump_ram_conf_table_add("AP_reg",0x800000,0x2000,0XF8000000,0,0); |
| 234 | |
| 235 | } |
| 236 | |
| 237 | /** |
| 238 | * 1¡¢create sysfs "/sys/zte" |
| 239 | * 2¡¢call other debug modules |
| 240 | */ |
| 241 | static int __init zx_debug_init(void) |
| 242 | { |
| 243 | pr_info("[DEBUG] create zte sysfs interface OK.\n"); |
| 244 | zx_root_kobj = kobject_create_and_add("zte", NULL); |
| 245 | if (!zx_root_kobj) |
| 246 | return -ENOMEM; |
| 247 | |
| 248 | |
| 249 | zx_test_init(); |
| 250 | |
| 251 | zx_clk_test_init(); |
| 252 | |
| 253 | #ifdef CONFIG_ZX29_DMA |
| 254 | zx_dma_test_init(); |
| 255 | #endif |
| 256 | |
| 257 | #ifdef CONFIG_RPM_ZX29 |
| 258 | zx_icp_test_init(); |
| 259 | #endif |
| 260 | sys_ramdump_config( ); |
| 261 | |
| 262 | return 0; |
| 263 | } |
| 264 | |
| 265 | late_initcall(zx_debug_init); |
| 266 | |