2 * arch/arm/common/fiq_debugger.c
4 * Serial Debugger Interface accessed through an FIQ interrupt.
6 * Copyright (C) 2008 Google, Inc.
8 * This software is licensed under the terms of the GNU General Public
9 * License version 2, as published by the Free Software Foundation, and
10 * may be copied, distributed, and modified under those terms.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
19 #include <linux/module.h>
21 #include <linux/console.h>
22 #include <linux/interrupt.h>
23 #include <linux/clk.h>
24 #include <linux/platform_device.h>
25 #include <linux/kernel_stat.h>
26 #include <linux/kmsg_dump.h>
27 #include <linux/irq.h>
28 #include <linux/delay.h>
29 #include <linux/reboot.h>
30 #include <linux/sched.h>
31 #include <linux/slab.h>
32 #include <linux/smp.h>
33 #include <linux/timer.h>
34 #include <linux/tty.h>
35 #include <linux/tty_flip.h>
36 #include <linux/wakelock.h>
38 #include <asm/fiq_debugger.h>
39 #include <asm/fiq_glue.h>
40 #include <asm/stacktrace.h>
42 #include <linux/uaccess.h>
43 #include <linux/rockchip/grf.h>
44 #include <linux/rockchip/iomap.h>
45 #include <linux/rockchip/cpu.h>
47 #include "fiq_debugger_ringbuf.h"
49 #ifdef CONFIG_RK29_WATCHDOG
50 extern void rk29_wdt_keepalive(void);
51 #define wdt_keepalive() rk29_wdt_keepalive()
53 #define wdt_keepalive() do {} while (0)
56 #define CMD_COUNT 0x0f
57 #define MAX_UNHANDLED_FIQ_COUNT 1000000
59 #ifdef CONFIG_ARCH_ROCKCHIP
60 #define MAX_FIQ_DEBUGGER_PORTS 1
62 #define MAX_FIQ_DEBUGGER_PORTS 4
65 #define THREAD_INFO(sp) ((struct thread_info *) \
66 ((unsigned long)(sp) & ~(THREAD_SIZE - 1)))
68 struct fiq_debugger_state {
69 struct fiq_glue_handler handler;
75 bool wakeup_irq_no_set_wake;
77 struct fiq_debugger_pdata *pdata;
78 struct platform_device *pdev;
80 char debug_cmd[DEBUG_MAX];
84 char debug_buf[DEBUG_MAX];
87 #ifdef CONFIG_ARCH_ROCKCHIP
88 char cmd_buf[CMD_COUNT+1][DEBUG_MAX];
94 bool ignore_next_wakeup_irq;
95 struct timer_list sleep_timer;
96 spinlock_t sleep_timer_lock;
98 struct wake_lock debugger_wake_lock;
101 atomic_t unhandled_fiq_count;
104 struct work_struct work;
105 spinlock_t work_lock;
106 char work_cmd[DEBUG_MAX];
108 #ifdef CONFIG_FIQ_DEBUGGER_CONSOLE
109 spinlock_t console_lock;
110 struct console console;
111 struct tty_port tty_port;
112 struct fiq_debugger_ringbuf *tty_rbuf;
116 #ifdef CONFIG_ARCH_ROCKCHIP
117 unsigned int last_irqs[1024];
118 unsigned int last_local_irqs[NR_CPUS][32];
120 unsigned int last_irqs[NR_IRQS];
121 unsigned int last_local_timer_irqs[NR_CPUS];
125 #ifdef CONFIG_FIQ_DEBUGGER_CONSOLE
126 struct tty_driver *fiq_tty_driver;
129 #ifdef CONFIG_FIQ_DEBUGGER_NO_SLEEP
130 static bool initial_no_sleep = true;
132 static bool initial_no_sleep;
135 #ifdef CONFIG_FIQ_DEBUGGER_CONSOLE_DEFAULT_ENABLE
136 static bool initial_debug_enable = true;
137 static bool initial_console_enable = true;
139 static bool initial_debug_enable;
140 static bool initial_console_enable;
143 static bool fiq_kgdb_enable;
145 module_param_named(no_sleep, initial_no_sleep, bool, 0644);
146 module_param_named(debug_enable, initial_debug_enable, bool, 0644);
147 module_param_named(console_enable, initial_console_enable, bool, 0644);
148 module_param_named(kgdb_enable, fiq_kgdb_enable, bool, 0644);
150 void gic_set_irq_secure(struct irq_data *d);
151 void gic_set_irq_priority(struct irq_data *d, u8 pri);
153 #ifdef CONFIG_FIQ_DEBUGGER_WAKEUP_IRQ_ALWAYS_ON
154 static inline void enable_wakeup_irq(struct fiq_debugger_state *state) {}
155 static inline void disable_wakeup_irq(struct fiq_debugger_state *state) {}
157 static inline void enable_wakeup_irq(struct fiq_debugger_state *state)
159 if (state->wakeup_irq < 0)
161 enable_irq(state->wakeup_irq);
162 if (!state->wakeup_irq_no_set_wake)
163 enable_irq_wake(state->wakeup_irq);
165 static inline void disable_wakeup_irq(struct fiq_debugger_state *state)
167 if (state->wakeup_irq < 0)
169 disable_irq_nosync(state->wakeup_irq);
170 if (!state->wakeup_irq_no_set_wake)
171 disable_irq_wake(state->wakeup_irq);
175 static bool inline debug_have_fiq(struct fiq_debugger_state *state)
177 return (state->fiq >= 0);
180 static void debug_force_irq(struct fiq_debugger_state *state)
182 unsigned int irq = state->signal_irq;
184 if (WARN_ON(!debug_have_fiq(state)))
186 if (state->pdata->force_irq) {
187 state->pdata->force_irq(state->pdev, irq);
189 struct irq_chip *chip = irq_get_chip(irq);
190 if (chip && chip->irq_retrigger)
191 chip->irq_retrigger(irq_get_irq_data(irq));
195 static void debug_uart_enable(struct fiq_debugger_state *state)
198 clk_enable(state->clk);
199 if (state->pdata->uart_enable)
200 state->pdata->uart_enable(state->pdev);
203 static void debug_uart_disable(struct fiq_debugger_state *state)
205 if (state->pdata->uart_disable)
206 state->pdata->uart_disable(state->pdev);
208 clk_disable(state->clk);
211 static void debug_uart_flush(struct fiq_debugger_state *state)
213 if (state->pdata->uart_flush)
214 state->pdata->uart_flush(state->pdev);
217 static void debug_putc(struct fiq_debugger_state *state, char c)
219 state->pdata->uart_putc(state->pdev, c);
222 static void debug_puts(struct fiq_debugger_state *state, char *s)
227 debug_putc(state, '\r');
228 debug_putc(state, c);
232 static void debug_prompt(struct fiq_debugger_state *state)
234 debug_puts(state, "debug> ");
237 static void dump_kernel_log(struct fiq_debugger_state *state)
241 struct kmsg_dumper dumper = { .active = true };
244 kmsg_dump_rewind_nolock(&dumper);
245 while (kmsg_dump_get_line_nolock(&dumper, true, buf,
246 sizeof(buf) - 1, &len)) {
248 debug_puts(state, buf);
253 #ifdef CONFIG_RK_LAST_LOG
254 #include <linux/ctype.h>
255 extern char *rk_last_log_get(unsigned *size);
256 static void dump_last_kernel_log(struct fiq_debugger_state *state)
259 char *s = rk_last_log_get(&size);
261 for (i = 0; i < size; i++) {
266 state->pdata->uart_putc(state->pdev, '\r');
267 state->pdata->uart_putc(state->pdev, c);
268 } else if (isascii(c) && isprint(c)) {
269 state->pdata->uart_putc(state->pdev, c);
275 static char *mode_name(unsigned cpsr)
277 switch (cpsr & MODE_MASK) {
278 case USR_MODE: return "USR";
279 case FIQ_MODE: return "FIQ";
280 case IRQ_MODE: return "IRQ";
281 case SVC_MODE: return "SVC";
282 case ABT_MODE: return "ABT";
283 case UND_MODE: return "UND";
284 case SYSTEM_MODE: return "SYS";
285 default: return "???";
289 static int debug_printf(void *cookie, const char *fmt, ...)
291 struct fiq_debugger_state *state = cookie;
296 vsnprintf(buf, sizeof(buf), fmt, ap);
299 debug_puts(state, buf);
300 return state->debug_abort;
303 /* Safe outside fiq context */
304 static int debug_printf_nfiq(void *cookie, const char *fmt, ...)
306 struct fiq_debugger_state *state = cookie;
309 unsigned long irq_flags;
312 vsnprintf(buf, 128, fmt, ap);
315 local_irq_save(irq_flags);
316 debug_puts(state, buf);
317 debug_uart_flush(state);
318 local_irq_restore(irq_flags);
319 return state->debug_abort;
322 static void dump_regs(struct fiq_debugger_state *state, unsigned *regs)
324 debug_printf(state, " r0 %08x r1 %08x r2 %08x r3 %08x\n",
325 regs[0], regs[1], regs[2], regs[3]);
326 debug_printf(state, " r4 %08x r5 %08x r6 %08x r7 %08x\n",
327 regs[4], regs[5], regs[6], regs[7]);
328 debug_printf(state, " r8 %08x r9 %08x r10 %08x r11 %08x mode %s\n",
329 regs[8], regs[9], regs[10], regs[11],
330 mode_name(regs[16]));
331 if ((regs[16] & MODE_MASK) == USR_MODE)
332 debug_printf(state, " ip %08x sp %08x lr %08x pc %08x "
333 "cpsr %08x\n", regs[12], regs[13], regs[14],
336 debug_printf(state, " ip %08x sp %08x lr %08x pc %08x "
337 "cpsr %08x spsr %08x\n", regs[12], regs[13],
338 regs[14], regs[15], regs[16], regs[17]);
342 unsigned long sp_svc;
343 unsigned long lr_svc;
344 unsigned long spsr_svc;
346 unsigned long sp_abt;
347 unsigned long lr_abt;
348 unsigned long spsr_abt;
350 unsigned long sp_und;
351 unsigned long lr_und;
352 unsigned long spsr_und;
354 unsigned long sp_irq;
355 unsigned long lr_irq;
356 unsigned long spsr_irq;
358 unsigned long r8_fiq;
359 unsigned long r9_fiq;
360 unsigned long r10_fiq;
361 unsigned long r11_fiq;
362 unsigned long r12_fiq;
363 unsigned long sp_fiq;
364 unsigned long lr_fiq;
365 unsigned long spsr_fiq;
368 void __naked get_mode_regs(struct mode_regs *regs)
372 "msr cpsr_c, #0xd3 @(SVC_MODE | PSR_I_BIT | PSR_F_BIT)\n"
373 "stmia r0!, {r13 - r14}\n"
375 "msr cpsr_c, #0xd7 @(ABT_MODE | PSR_I_BIT | PSR_F_BIT)\n"
376 "stmia r0!, {r2, r13 - r14}\n"
378 "msr cpsr_c, #0xdb @(UND_MODE | PSR_I_BIT | PSR_F_BIT)\n"
379 "stmia r0!, {r2, r13 - r14}\n"
381 "msr cpsr_c, #0xd2 @(IRQ_MODE | PSR_I_BIT | PSR_F_BIT)\n"
382 "stmia r0!, {r2, r13 - r14}\n"
384 "msr cpsr_c, #0xd1 @(FIQ_MODE | PSR_I_BIT | PSR_F_BIT)\n"
385 "stmia r0!, {r2, r8 - r14}\n"
393 static void dump_allregs(struct fiq_debugger_state *state, unsigned *regs)
395 struct mode_regs mode_regs;
396 dump_regs(state, regs);
397 get_mode_regs(&mode_regs);
398 debug_printf(state, " svc: sp %08x lr %08x spsr %08x\n",
399 mode_regs.sp_svc, mode_regs.lr_svc, mode_regs.spsr_svc);
400 debug_printf(state, " abt: sp %08x lr %08x spsr %08x\n",
401 mode_regs.sp_abt, mode_regs.lr_abt, mode_regs.spsr_abt);
402 debug_printf(state, " und: sp %08x lr %08x spsr %08x\n",
403 mode_regs.sp_und, mode_regs.lr_und, mode_regs.spsr_und);
404 debug_printf(state, " irq: sp %08x lr %08x spsr %08x\n",
405 mode_regs.sp_irq, mode_regs.lr_irq, mode_regs.spsr_irq);
406 debug_printf(state, " fiq: r8 %08x r9 %08x r10 %08x r11 %08x "
408 mode_regs.r8_fiq, mode_regs.r9_fiq, mode_regs.r10_fiq,
409 mode_regs.r11_fiq, mode_regs.r12_fiq);
410 debug_printf(state, " fiq: sp %08x lr %08x spsr %08x\n",
411 mode_regs.sp_fiq, mode_regs.lr_fiq, mode_regs.spsr_fiq);
414 static void dump_irqs(struct fiq_debugger_state *state)
418 struct irq_desc *desc;
420 debug_printf(state, "irqnr total since-last status name\n");
421 for_each_irq_desc(n, desc) {
422 struct irqaction *act = desc->action;
423 if (!act && !kstat_irqs(n))
425 debug_printf(state, "%5d: %10u %11u %8x %s\n", n,
427 kstat_irqs(n) - state->last_irqs[n],
428 desc->status_use_accessors,
429 (act && act->name) ? act->name : "???");
430 state->last_irqs[n] = kstat_irqs(n);
433 #ifdef CONFIG_ARCH_ROCKCHIP
434 for (n = 16; n < 32; n++) {
435 desc = irq_to_desc(n);
438 for (cpu = 0; cpu < NR_CPUS; cpu++) {
439 unsigned int irqs = kstat_irqs_cpu(n, cpu);
440 struct irqaction *act = desc->action;
441 const char *name = (act && act->name) ? act->name : "???";
445 "%5d: %10u %11u %s (CPU%d)\n", n,
446 irqs, irqs - state->last_local_irqs[cpu][n],
448 state->last_local_irqs[cpu][n] = irqs;
451 for (n = 0; n < NR_IPI; n++) {
457 IPI_CALL_FUNC_SINGLE,
462 static const char *ipi_types[NR_IPI] = {
463 #define S(x,s) [x] = s
464 S(IPI_WAKEUP, "CPU wakeup"),
465 S(IPI_TIMER, "Timer broadcast"),
466 S(IPI_RESCHEDULE, "Rescheduling"),
467 S(IPI_CALL_FUNC, "Function call"),
468 S(IPI_CALL_FUNC_SINGLE, "Single function call"),
469 S(IPI_CPU_STOP, "CPU stop"),
470 S(IPI_COMPLETION, "Completion"),
471 S(IPI_CPU_BACKTRACE, "CPU backtrace"),
474 for (cpu = 0; cpu < NR_CPUS; cpu++) {
475 unsigned int irqs = __get_irq_stat(cpu, ipi_irqs[n]);
479 "%5d: %10u %11u %s (CPU%d)\n",
480 n, irqs, irqs - state->last_local_irqs[cpu][n],
482 state->last_local_irqs[cpu][n] = irqs;
488 struct stacktrace_state {
489 struct fiq_debugger_state *state;
493 static int report_trace(struct stackframe *frame, void *d)
495 struct stacktrace_state *sts = d;
498 debug_printf(sts->state,
499 " pc: %p (%pF), lr %p (%pF), sp %p, fp %p\n",
500 frame->pc, frame->pc, frame->lr, frame->lr,
501 frame->sp, frame->fp);
505 debug_printf(sts->state, " ...\n");
507 return sts->depth == 0;
511 struct frame_tail *fp;
514 } __attribute__((packed));
516 static struct frame_tail *user_backtrace(struct fiq_debugger_state *state,
517 struct frame_tail *tail)
519 struct frame_tail buftail[2];
521 /* Also check accessibility of one struct frame_tail beyond */
522 if (!access_ok(VERIFY_READ, tail, sizeof(buftail))) {
523 debug_printf(state, " invalid frame pointer %p\n", tail);
526 if (__copy_from_user_inatomic(buftail, tail, sizeof(buftail))) {
528 " failed to copy frame pointer %p\n", tail);
532 debug_printf(state, " %p\n", buftail[0].lr);
534 /* frame pointers should strictly progress back up the stack
535 * (towards higher addresses) */
536 if (tail >= buftail[0].fp)
539 return buftail[0].fp-1;
542 void dump_stacktrace(struct fiq_debugger_state *state,
543 struct pt_regs * const regs, unsigned int depth, void *ssp)
545 struct frame_tail *tail;
546 struct thread_info *real_thread_info = THREAD_INFO(ssp);
547 struct stacktrace_state sts;
551 *current_thread_info() = *real_thread_info;
554 debug_printf(state, "current NULL\n");
556 debug_printf(state, "pid: %d comm: %s\n",
557 current->pid, current->comm);
558 dump_regs(state, (unsigned *)regs);
560 if (!user_mode(regs)) {
561 struct stackframe frame;
562 frame.fp = regs->ARM_fp;
563 frame.sp = regs->ARM_sp;
564 frame.lr = regs->ARM_lr;
565 frame.pc = regs->ARM_pc;
567 " pc: %p (%pF), lr %p (%pF), sp %p, fp %p\n",
568 regs->ARM_pc, regs->ARM_pc, regs->ARM_lr, regs->ARM_lr,
569 regs->ARM_sp, regs->ARM_fp);
570 walk_stackframe(&frame, report_trace, &sts);
574 tail = ((struct frame_tail *) regs->ARM_fp) - 1;
575 while (depth-- && tail && !((unsigned long) tail & 3))
576 tail = user_backtrace(state, tail);
579 static void do_ps(struct fiq_debugger_state *state)
581 struct task_struct *g;
582 struct task_struct *p;
584 static const char stat_nam[] = "RSDTtZX";
586 debug_printf(state, "pid ppid prio task pc\n");
587 read_lock(&tasklist_lock);
588 do_each_thread(g, p) {
589 task_state = p->state ? __ffs(p->state) + 1 : 0;
591 "%5d %5d %4d ", p->pid, p->parent->pid, p->prio);
592 debug_printf(state, "%-13.13s %c", p->comm,
593 task_state >= sizeof(stat_nam) ? '?' : stat_nam[task_state]);
594 if (task_state == TASK_RUNNING)
595 debug_printf(state, " running\n");
597 debug_printf(state, " %08lx\n", thread_saved_pc(p));
598 } while_each_thread(g, p);
599 read_unlock(&tasklist_lock);
602 #ifdef CONFIG_FIQ_DEBUGGER_CONSOLE
603 static void begin_syslog_dump(struct fiq_debugger_state *state)
605 state->syslog_dumping = true;
608 static void end_syslog_dump(struct fiq_debugger_state *state)
610 state->syslog_dumping = false;
613 extern int do_syslog(int type, char __user *bug, int count);
614 static void begin_syslog_dump(struct fiq_debugger_state *state)
616 do_syslog(5 /* clear */, NULL, 0);
619 static void end_syslog_dump(struct fiq_debugger_state *state)
621 dump_kernel_log(state);
625 static void do_sysrq(struct fiq_debugger_state *state, char rq)
627 if ((rq == 'g' || rq == 'G') && !fiq_kgdb_enable) {
628 debug_printf(state, "sysrq-g blocked\n");
631 begin_syslog_dump(state);
633 end_syslog_dump(state);
637 static void do_kgdb(struct fiq_debugger_state *state)
639 if (!fiq_kgdb_enable) {
640 debug_printf(state, "kgdb through fiq debugger not enabled\n");
644 debug_printf(state, "enabling console and triggering kgdb\n");
645 state->console_enable = true;
650 static void debug_schedule_work(struct fiq_debugger_state *state, char *cmd)
654 spin_lock_irqsave(&state->work_lock, flags);
655 if (state->work_cmd[0] != '\0') {
656 debug_printf(state, "work command processor busy\n");
657 spin_unlock_irqrestore(&state->work_lock, flags);
661 strlcpy(state->work_cmd, cmd, sizeof(state->work_cmd));
662 spin_unlock_irqrestore(&state->work_lock, flags);
664 schedule_work(&state->work);
667 static void debug_work(struct work_struct *work)
669 struct fiq_debugger_state *state;
670 char work_cmd[DEBUG_MAX];
674 state = container_of(work, struct fiq_debugger_state, work);
676 spin_lock_irqsave(&state->work_lock, flags);
678 strlcpy(work_cmd, state->work_cmd, sizeof(work_cmd));
679 state->work_cmd[0] = '\0';
681 spin_unlock_irqrestore(&state->work_lock, flags);
684 if (!strncmp(cmd, "reboot", 6)) {
691 kernel_restart(NULL);
693 debug_printf(state, "unknown work command '%s'\n", work_cmd);
697 /* This function CANNOT be called in FIQ context */
698 static void debug_irq_exec(struct fiq_debugger_state *state, char *cmd)
701 if (!strcmp(cmd, "ps"))
703 else if (!strcmp(cmd, "sysrq"))
704 do_sysrq(state, 'h');
705 else if (!strncmp(cmd, "sysrq ", 6))
706 do_sysrq(state, cmd[6]);
708 else if (!strcmp(cmd, "kgdb"))
711 else if (!strncmp(cmd, "reboot", 6))
712 debug_schedule_work(state, cmd);
713 #ifdef CONFIG_ARCH_ROCKCHIP
716 memset(state->debug_buf, 0, DEBUG_MAX);
719 if (invalid_cmd == 0) {
720 state->current_pointer = (state->current_pointer-1) & CMD_COUNT;
721 if (strcmp(state->cmd_buf[state->current_pointer], state->debug_buf)) {
722 state->current_pointer = (state->current_pointer+1) & CMD_COUNT;
723 memset(state->cmd_buf[state->current_pointer], 0, DEBUG_MAX);
724 strcpy(state->cmd_buf[state->current_pointer], state->debug_buf);
726 memset(state->debug_buf, 0, DEBUG_MAX);
727 state->current_pointer = (state->current_pointer+1) & CMD_COUNT;
728 state->back_pointer = state->current_pointer;
733 #ifdef CONFIG_ARCH_ROCKCHIP
734 static char cmd_buf[][16] = {
742 #ifdef CONFIG_RK_LAST_LOG
759 static void debug_help(struct fiq_debugger_state *state)
761 debug_printf(state, "FIQ Debugger commands:\n"
763 " regs Register dump\n"
764 " allregs Extended Register dump\n"
766 " reboot [<c>] Reboot with command <c>\n"
767 " reset [<c>] Hard reset with command <c>\n"
768 " irqs Interupt status\n"
770 " version Kernel version\n");
771 #ifdef CONFIG_RK_LAST_LOG
772 debug_printf(state, " last_kmsg Last kernel log\n");
774 debug_printf(state, " sleep Allow sleep while in FIQ\n"
775 " nosleep Disable sleep while in FIQ\n"
776 " console Switch terminal to console\n"
778 " cpu <number> Switch to CPU<number>\n");
779 debug_printf(state, " ps Process list\n"
780 " sysrq sysrq options\n"
781 " sysrq <param> Execute sysrq with <param>\n");
783 debug_printf(state, " kgdb Enter kernel debugger\n");
787 static void take_affinity(void *info)
789 struct fiq_debugger_state *state = info;
790 struct cpumask cpumask;
792 cpumask_clear(&cpumask);
793 cpumask_set_cpu(get_cpu(), &cpumask);
795 irq_set_affinity(state->uart_irq, &cpumask);
798 static void switch_cpu(struct fiq_debugger_state *state, int cpu)
800 if (!debug_have_fiq(state))
801 smp_call_function_single(cpu, take_affinity, state, false);
802 #ifdef CONFIG_ARCH_ROCKCHIP
804 struct cpumask cpumask;
806 if (!cpu_online(cpu)) {
807 debug_printf(state, "cpu %d offline\n", cpu);
811 cpumask_clear(&cpumask);
812 cpumask_set_cpu(cpu, &cpumask);
814 irq_set_affinity(state->fiq, &cpumask);
815 irq_set_affinity(state->uart_irq, &cpumask);
818 state->current_cpu = cpu;
821 static bool debug_fiq_exec(struct fiq_debugger_state *state,
822 const char *cmd, unsigned *regs, void *svc_sp)
824 bool signal_helper = false;
826 if (!strcmp(cmd, "help") || !strcmp(cmd, "?")) {
828 } else if (!strcmp(cmd, "pc")) {
829 debug_printf(state, " pc %08x cpsr %08x mode %s\n",
830 regs[15], regs[16], mode_name(regs[16]));
831 } else if (!strcmp(cmd, "regs")) {
832 dump_regs(state, regs);
833 } else if (!strcmp(cmd, "allregs")) {
834 dump_allregs(state, regs);
835 } else if (!strcmp(cmd, "bt")) {
836 dump_stacktrace(state, (struct pt_regs *)regs, 100, svc_sp);
837 } else if (!strncmp(cmd, "reset", 5)) {
843 strlcpy(tmp_cmd, cmd, sizeof(tmp_cmd));
844 machine_restart(tmp_cmd);
846 machine_restart(NULL);
848 } else if (!strcmp(cmd, "irqs")) {
850 } else if (!strcmp(cmd, "kmsg")) {
851 dump_kernel_log(state);
852 #ifdef CONFIG_RK_LAST_LOG
853 } else if (!strcmp(cmd, "last_kmsg")) {
854 dump_last_kernel_log(state);
856 } else if (!strcmp(cmd, "version")) {
857 debug_printf(state, "%s\n", linux_banner);
858 } else if (!strcmp(cmd, "sleep")) {
859 state->no_sleep = false;
860 debug_printf(state, "enabling sleep\n");
861 } else if (!strcmp(cmd, "nosleep")) {
862 state->no_sleep = true;
863 debug_printf(state, "disabling sleep\n");
864 } else if (!strcmp(cmd, "console")) {
865 debug_printf(state, "console mode\n");
866 debug_uart_flush(state);
867 state->console_enable = true;
868 } else if (!strcmp(cmd, "cpu")) {
869 debug_printf(state, "cpu %d\n", state->current_cpu);
870 } else if (!strncmp(cmd, "cpu ", 4)) {
871 unsigned long cpu = 0;
872 if (strict_strtoul(cmd + 4, 10, &cpu) == 0)
873 switch_cpu(state, cpu);
875 debug_printf(state, "invalid cpu\n");
876 debug_printf(state, "cpu %d\n", state->current_cpu);
878 if (state->debug_busy) {
880 "command processor busy. trying to abort.\n");
881 state->debug_abort = -1;
883 strcpy(state->debug_cmd, cmd);
884 state->debug_busy = 1;
889 if (!state->console_enable)
892 return signal_helper;
895 static void sleep_timer_expired(unsigned long data)
897 struct fiq_debugger_state *state = (struct fiq_debugger_state *)data;
900 spin_lock_irqsave(&state->sleep_timer_lock, flags);
901 if (state->uart_enabled && !state->no_sleep) {
902 if (state->debug_enable && !state->console_enable) {
903 state->debug_enable = false;
904 debug_printf_nfiq(state, "suspending fiq debugger\n");
906 state->ignore_next_wakeup_irq = true;
907 debug_uart_disable(state);
908 state->uart_enabled = false;
909 enable_wakeup_irq(state);
911 wake_unlock(&state->debugger_wake_lock);
912 spin_unlock_irqrestore(&state->sleep_timer_lock, flags);
915 static void handle_wakeup(struct fiq_debugger_state *state)
919 spin_lock_irqsave(&state->sleep_timer_lock, flags);
920 if (state->wakeup_irq >= 0 && state->ignore_next_wakeup_irq) {
921 state->ignore_next_wakeup_irq = false;
922 } else if (!state->uart_enabled) {
923 wake_lock(&state->debugger_wake_lock);
924 debug_uart_enable(state);
925 state->uart_enabled = true;
926 disable_wakeup_irq(state);
927 mod_timer(&state->sleep_timer, jiffies + HZ / 2);
929 spin_unlock_irqrestore(&state->sleep_timer_lock, flags);
932 static irqreturn_t wakeup_irq_handler(int irq, void *dev)
934 struct fiq_debugger_state *state = dev;
936 if (!state->no_sleep)
937 debug_puts(state, "WAKEUP\n");
938 handle_wakeup(state);
943 static void debug_handle_console_irq_context(struct fiq_debugger_state *state)
945 #if defined(CONFIG_FIQ_DEBUGGER_CONSOLE)
946 if (state->tty_port.ops) {
948 int count = fiq_debugger_ringbuf_level(state->tty_rbuf);
949 for (i = 0; i < count; i++) {
950 int c = fiq_debugger_ringbuf_peek(state->tty_rbuf, 0);
951 tty_insert_flip_char(&state->tty_port, c, TTY_NORMAL);
952 if (!fiq_debugger_ringbuf_consume(state->tty_rbuf, 1))
953 pr_warn("fiq tty failed to consume byte\n");
955 tty_flip_buffer_push(&state->tty_port);
960 static void debug_handle_irq_context(struct fiq_debugger_state *state)
962 if (!state->no_sleep) {
965 spin_lock_irqsave(&state->sleep_timer_lock, flags);
966 wake_lock(&state->debugger_wake_lock);
967 mod_timer(&state->sleep_timer, jiffies + HZ * 5);
968 spin_unlock_irqrestore(&state->sleep_timer_lock, flags);
970 debug_handle_console_irq_context(state);
971 if (state->debug_busy) {
972 debug_irq_exec(state, state->debug_cmd);
973 if (!state->console_enable)
975 state->debug_busy = 0;
979 static int debug_getc(struct fiq_debugger_state *state)
981 return state->pdata->uart_getc(state->pdev);
985 static int debug_cmd_check_back(struct fiq_debugger_state *state, char c)
990 state->back_pointer = (state->back_pointer-1) & CMD_COUNT;
991 if (state->back_pointer != state->current_pointer) {
992 s = state->cmd_buf[state->back_pointer];
994 for(i = 0; i < strlen(state->debug_buf)-1; i++) {
995 state->pdata->uart_putc(state->pdev, 8);
996 state->pdata->uart_putc(state->pdev, ' ');
997 state->pdata->uart_putc(state->pdev, 8);
999 memset(state->debug_buf, 0, DEBUG_MAX);
1000 strcpy(state->debug_buf, s);
1001 state->debug_count = strlen(state->debug_buf);
1002 debug_printf(state, state->debug_buf);
1004 state->back_pointer = (state->back_pointer+1) & CMD_COUNT;
1008 state->back_pointer = (state->back_pointer+1) & CMD_COUNT;
1010 } else if (c == 'B') {
1012 if (state->back_pointer != state->current_pointer) {
1013 state->back_pointer = (state->back_pointer+1) & CMD_COUNT;
1014 if(state->back_pointer == state->current_pointer){
1017 s = state->cmd_buf[state->back_pointer];
1019 for(i = 0; i < strlen(state->debug_buf)-1; i++) {
1020 state->pdata->uart_putc(state->pdev, 8);
1021 state->pdata->uart_putc(state->pdev, ' ');
1022 state->pdata->uart_putc(state->pdev, 8);
1024 memset(state->debug_buf, 0, DEBUG_MAX);
1025 strcpy(state->debug_buf, s);
1026 state->debug_count = strlen(state->debug_buf);
1027 debug_printf(state, state->debug_buf);
1032 for(i = 0; i < strlen(state->debug_buf)-1; i++) {
1033 state->pdata->uart_putc(state->pdev, 8);
1034 state->pdata->uart_putc(state->pdev, ' ');
1035 state->pdata->uart_putc(state->pdev, 8);
1037 memset(state->debug_buf, 0, DEBUG_MAX);
1038 state->debug_count = 0;
1044 static void debug_cmd_tab(struct fiq_debugger_state *state)
1049 for (i = 0; i < ARRAY_SIZE(cmd_buf); i++) {
1053 for (j = 1; j <= strlen(state->debug_buf); j++) {
1055 for (i = 0; i < ARRAY_SIZE(cmd_buf); i++) {
1056 if (cmd_buf[i][15] == 1) {
1057 if (strncmp(state->debug_buf, cmd_buf[i], j)) {
1069 for (i = 0; i < ARRAY_SIZE(cmd_buf); i++) {
1070 if (cmd_buf[i][15] == 1)
1074 for(j = 0; j < strlen(state->debug_buf); j++) {
1075 state->pdata->uart_putc(state->pdev, 8);
1076 state->pdata->uart_putc(state->pdev, ' ');
1077 state->pdata->uart_putc(state->pdev, 8);
1079 memset(state->debug_buf, 0, DEBUG_MAX);
1080 strcpy(state->debug_buf, cmd_buf[i]);
1081 state->debug_count = strlen(state->debug_buf);
1082 debug_printf(state, state->debug_buf);
1087 static bool debug_handle_uart_interrupt(struct fiq_debugger_state *state,
1088 int this_cpu, void *regs, void *svc_sp)
1093 bool signal_helper = false;
1095 if (this_cpu != state->current_cpu) {
1099 if (atomic_inc_return(&state->unhandled_fiq_count) !=
1100 MAX_UNHANDLED_FIQ_COUNT)
1103 debug_printf(state, "fiq_debugger: cpu %d not responding, "
1104 "reverting to cpu %d\n", state->current_cpu,
1107 atomic_set(&state->unhandled_fiq_count, 0);
1108 switch_cpu(state, this_cpu);
1112 state->in_fiq = true;
1114 while ((c = debug_getc(state)) != FIQ_DEBUGGER_NO_CHAR) {
1116 if (!state->debug_enable) {
1117 if ((c == 13) || (c == 10)) {
1118 state->debug_enable = true;
1119 state->debug_count = 0;
1120 debug_prompt(state);
1122 } else if (c == FIQ_DEBUGGER_BREAK) {
1123 state->console_enable = false;
1124 #ifdef CONFIG_ARCH_ROCKCHIP
1125 debug_puts(state, "\nWelcome to ");
1127 debug_puts(state, "fiq debugger mode\n");
1128 state->debug_count = 0;
1129 #ifdef CONFIG_ARCH_ROCKCHIP
1130 debug_puts(state, "Enter ? to get command help\n");
1131 state->back_pointer = CMD_COUNT;
1132 state->current_pointer = CMD_COUNT;
1133 memset(state->cmd_buf, 0, (CMD_COUNT+1)*DEBUG_MAX);
1135 debug_prompt(state);
1136 #ifdef CONFIG_FIQ_DEBUGGER_CONSOLE
1137 } else if (state->console_enable && state->tty_rbuf) {
1138 fiq_debugger_ringbuf_push(state->tty_rbuf, c);
1139 signal_helper = true;
1141 #ifdef CONFIG_ARCH_ROCKCHIP
1142 } else if (last_c == '[' && (c == 'A' || c == 'B' || c == 'C' || c == 'D')) {
1143 if (state->debug_count > 0) {
1144 state->debug_count--;
1145 state->pdata->uart_putc(state->pdev, 8);
1146 state->pdata->uart_putc(state->pdev, ' ');
1147 state->pdata->uart_putc(state->pdev, 8);
1149 debug_cmd_check_back(state, c);
1151 } else if (c == 9) {
1152 debug_cmd_tab(state);
1154 } else if ((c >= ' ') && (c < 127)) {
1155 if (state->debug_count < (DEBUG_MAX - 1)) {
1156 state->debug_buf[state->debug_count++] = c;
1157 debug_putc(state, c);
1159 } else if ((c == 8) || (c == 127)) {
1160 if (state->debug_count > 0) {
1161 state->debug_count--;
1162 debug_putc(state, 8);
1163 debug_putc(state, ' ');
1164 debug_putc(state, 8);
1166 } else if ((c == 13) || (c == 10)) {
1167 if (c == '\r' || (c == '\n' && last_c != '\r')) {
1168 debug_putc(state, '\r');
1169 debug_putc(state, '\n');
1171 if (state->debug_count) {
1172 state->debug_buf[state->debug_count] = 0;
1173 state->debug_count = 0;
1174 #ifdef CONFIG_ARCH_ROCKCHIP
1176 debug_fiq_exec(state, state->debug_buf,
1178 if (signal_helper == false) {
1179 state->current_pointer = (state->current_pointer-1) & CMD_COUNT;
1180 if (strcmp(state->cmd_buf[state->current_pointer], state->debug_buf)) {
1181 state->current_pointer = (state->current_pointer+1) & CMD_COUNT;
1182 memset(state->cmd_buf[state->current_pointer], 0, DEBUG_MAX);
1183 strcpy(state->cmd_buf[state->current_pointer], state->debug_buf);
1185 memset(state->debug_buf, 0, DEBUG_MAX);
1186 state->current_pointer = (state->current_pointer+1) & CMD_COUNT;
1187 state->back_pointer = state->current_pointer;
1191 debug_prompt(state);
1196 if (!state->console_enable)
1197 debug_uart_flush(state);
1198 if (state->pdata->fiq_ack)
1199 state->pdata->fiq_ack(state->pdev, state->fiq);
1201 /* poke sleep timer if necessary */
1202 if (state->debug_enable && !state->no_sleep)
1203 signal_helper = true;
1205 atomic_set(&state->unhandled_fiq_count, 0);
1206 state->in_fiq = false;
1208 return signal_helper;
1211 static void debug_fiq(struct fiq_glue_handler *h, void *regs, void *svc_sp)
1213 struct fiq_debugger_state *state =
1214 container_of(h, struct fiq_debugger_state, handler);
1215 unsigned int this_cpu = THREAD_INFO(svc_sp)->cpu;
1218 /* RK2928 USB-UART function, otg dp/dm default in uart status;
1219 * connect with otg cable&usb device, dp/dm will be hi-z status
1220 * and make uart controller enter infinite fiq loop
1222 #ifdef CONFIG_RK_USB_UART
1223 if(cpu_is_rk3188()){
1224 if(!(readl_relaxed(RK_GRF_VIRT + RK3188_GRF_SOC_STATUS0) & (1 << 13))){//id low
1225 writel_relaxed((0x0300 << 16), RK_GRF_VIRT + RK3188_GRF_UOC0_CON0); //enter usb phy
1227 }else if(cpu_is_rk3288()){
1228 if(!(readl_relaxed(RK_GRF_VIRT + RK3288_GRF_SOC_STATUS2) & (1 << 17))){//id low
1229 writel_relaxed((0x00c0 << 16), RK_GRF_VIRT + RK3288_GRF_UOC0_CON3);//enter usb phy
1233 need_irq = debug_handle_uart_interrupt(state, this_cpu, regs, svc_sp);
1235 debug_force_irq(state);
1239 * When not using FIQs, we only use this single interrupt as an entry point.
1240 * This just effectively takes over the UART interrupt and does all the work
1243 static irqreturn_t debug_uart_irq(int irq, void *dev)
1245 struct fiq_debugger_state *state = dev;
1248 handle_wakeup(state);
1250 /* handle the debugger irq in regular context */
1251 not_done = debug_handle_uart_interrupt(state, smp_processor_id(),
1253 current_thread_info());
1255 debug_handle_irq_context(state);
1261 * If FIQs are used, not everything can happen in fiq context.
1262 * FIQ handler does what it can and then signals this interrupt to finish the
1263 * job in irq context.
1265 static irqreturn_t debug_signal_irq(int irq, void *dev)
1267 struct fiq_debugger_state *state = dev;
1269 if (state->pdata->force_irq_ack)
1270 state->pdata->force_irq_ack(state->pdev, state->signal_irq);
1272 debug_handle_irq_context(state);
1277 static void debug_resume(struct fiq_glue_handler *h)
1279 struct fiq_debugger_state *state =
1280 container_of(h, struct fiq_debugger_state, handler);
1281 if (state->pdata->uart_resume)
1282 state->pdata->uart_resume(state->pdev);
1285 #if defined(CONFIG_FIQ_DEBUGGER_CONSOLE)
1286 struct tty_driver *debug_console_device(struct console *co, int *index)
1289 return fiq_tty_driver;
1292 static void debug_console_write(struct console *co,
1293 const char *s, unsigned int count)
1295 struct fiq_debugger_state *state;
1296 unsigned long flags;
1298 state = container_of(co, struct fiq_debugger_state, console);
1300 if (!state->console_enable && !state->syslog_dumping)
1303 #ifdef CONFIG_RK_CONSOLE_THREAD
1304 if (state->pdata->console_write) {
1305 state->pdata->console_write(state->pdev, s, count);
1310 debug_uart_enable(state);
1311 spin_lock_irqsave(&state->console_lock, flags);
1314 debug_putc(state, '\r');
1315 debug_putc(state, *s++);
1317 debug_uart_flush(state);
1318 spin_unlock_irqrestore(&state->console_lock, flags);
1319 debug_uart_disable(state);
1322 static struct console fiq_debugger_console = {
1324 .device = debug_console_device,
1325 .write = debug_console_write,
1326 .flags = CON_PRINTBUFFER | CON_ANYTIME | CON_ENABLED,
1329 int fiq_tty_open(struct tty_struct *tty, struct file *filp)
1331 int line = tty->index;
1332 struct fiq_debugger_state **states = tty->driver->driver_state;
1333 struct fiq_debugger_state *state = states[line];
1335 return tty_port_open(&state->tty_port, tty, filp);
1338 void fiq_tty_close(struct tty_struct *tty, struct file *filp)
1340 tty_port_close(tty->port, tty, filp);
1343 int fiq_tty_write(struct tty_struct *tty, const unsigned char *buf, int count)
1346 int line = tty->index;
1347 struct fiq_debugger_state **states = tty->driver->driver_state;
1348 struct fiq_debugger_state *state = states[line];
1350 if (!state->console_enable)
1353 debug_uart_enable(state);
1354 spin_lock_irq(&state->console_lock);
1355 for (i = 0; i < count; i++)
1356 debug_putc(state, *buf++);
1357 spin_unlock_irq(&state->console_lock);
1358 debug_uart_disable(state);
1363 int fiq_tty_write_room(struct tty_struct *tty)
1368 #ifdef CONFIG_CONSOLE_POLL
1369 static int fiq_tty_poll_init(struct tty_driver *driver, int line, char *options)
1374 static int fiq_tty_poll_get_char(struct tty_driver *driver, int line)
1376 struct fiq_debugger_state **states = driver->driver_state;
1377 struct fiq_debugger_state *state = states[line];
1378 int c = NO_POLL_CHAR;
1380 debug_uart_enable(state);
1381 if (debug_have_fiq(state)) {
1382 int count = fiq_debugger_ringbuf_level(state->tty_rbuf);
1384 c = fiq_debugger_ringbuf_peek(state->tty_rbuf, 0);
1385 fiq_debugger_ringbuf_consume(state->tty_rbuf, 1);
1388 c = debug_getc(state);
1389 if (c == FIQ_DEBUGGER_NO_CHAR)
1392 debug_uart_disable(state);
1397 static void fiq_tty_poll_put_char(struct tty_driver *driver, int line, char ch)
1399 struct fiq_debugger_state **states = driver->driver_state;
1400 struct fiq_debugger_state *state = states[line];
1401 debug_uart_enable(state);
1402 debug_putc(state, ch);
1403 debug_uart_disable(state);
1407 static const struct tty_port_operations fiq_tty_port_ops;
1409 static const struct tty_operations fiq_tty_driver_ops = {
1410 .write = fiq_tty_write,
1411 .write_room = fiq_tty_write_room,
1412 .open = fiq_tty_open,
1413 .close = fiq_tty_close,
1414 #ifdef CONFIG_CONSOLE_POLL
1415 .poll_init = fiq_tty_poll_init,
1416 .poll_get_char = fiq_tty_poll_get_char,
1417 .poll_put_char = fiq_tty_poll_put_char,
1421 static int fiq_debugger_tty_init(void)
1424 struct fiq_debugger_state **states = NULL;
1426 states = kzalloc(sizeof(*states) * MAX_FIQ_DEBUGGER_PORTS, GFP_KERNEL);
1428 pr_err("Failed to allocate fiq debugger state structres\n");
1432 fiq_tty_driver = alloc_tty_driver(MAX_FIQ_DEBUGGER_PORTS);
1433 if (!fiq_tty_driver) {
1434 pr_err("Failed to allocate fiq debugger tty\n");
1436 goto err_free_state;
1439 fiq_tty_driver->owner = THIS_MODULE;
1440 fiq_tty_driver->driver_name = "fiq-debugger";
1441 fiq_tty_driver->name = "ttyFIQ";
1442 fiq_tty_driver->type = TTY_DRIVER_TYPE_SERIAL;
1443 fiq_tty_driver->subtype = SERIAL_TYPE_NORMAL;
1444 fiq_tty_driver->init_termios = tty_std_termios;
1445 fiq_tty_driver->flags = TTY_DRIVER_REAL_RAW |
1446 TTY_DRIVER_DYNAMIC_DEV;
1447 fiq_tty_driver->driver_state = states;
1449 fiq_tty_driver->init_termios.c_cflag =
1450 B115200 | CS8 | CREAD | HUPCL | CLOCAL;
1451 fiq_tty_driver->init_termios.c_ispeed = 115200;
1452 fiq_tty_driver->init_termios.c_ospeed = 115200;
1454 tty_set_operations(fiq_tty_driver, &fiq_tty_driver_ops);
1456 ret = tty_register_driver(fiq_tty_driver);
1458 pr_err("Failed to register fiq tty: %d\n", ret);
1462 pr_info("Registered FIQ tty driver\n");
1466 put_tty_driver(fiq_tty_driver);
1467 fiq_tty_driver = NULL;
1473 static int fiq_debugger_tty_init_one(struct fiq_debugger_state *state)
1476 struct device *tty_dev;
1477 struct fiq_debugger_state **states = fiq_tty_driver->driver_state;
1479 states[state->pdev->id] = state;
1481 state->tty_rbuf = fiq_debugger_ringbuf_alloc(1024);
1482 if (!state->tty_rbuf) {
1483 pr_err("Failed to allocate fiq debugger ringbuf\n");
1488 tty_port_init(&state->tty_port);
1489 state->tty_port.ops = &fiq_tty_port_ops;
1491 tty_dev = tty_port_register_device(&state->tty_port, fiq_tty_driver,
1492 state->pdev->id, &state->pdev->dev);
1493 if (IS_ERR(tty_dev)) {
1494 pr_err("Failed to register fiq debugger tty device\n");
1495 ret = PTR_ERR(tty_dev);
1499 device_set_wakeup_capable(tty_dev, 1);
1501 pr_info("Registered fiq debugger ttyFIQ%d\n", state->pdev->id);
1506 fiq_debugger_ringbuf_free(state->tty_rbuf);
1507 state->tty_rbuf = NULL;
1512 static int fiq_debugger_dev_suspend(struct device *dev)
1514 struct platform_device *pdev = to_platform_device(dev);
1515 struct fiq_debugger_state *state = platform_get_drvdata(pdev);
1517 if (state->pdata->uart_dev_suspend)
1518 return state->pdata->uart_dev_suspend(pdev);
1522 static int fiq_debugger_dev_resume(struct device *dev)
1524 struct platform_device *pdev = to_platform_device(dev);
1525 struct fiq_debugger_state *state = platform_get_drvdata(pdev);
1527 if (state->pdata->uart_dev_resume)
1528 return state->pdata->uart_dev_resume(pdev);
1532 static int fiq_debugger_probe(struct platform_device *pdev)
1535 struct fiq_debugger_pdata *pdata = dev_get_platdata(&pdev->dev);
1536 struct fiq_debugger_state *state;
1540 if (pdev->id >= MAX_FIQ_DEBUGGER_PORTS)
1543 if (!pdata->uart_getc || !pdata->uart_putc)
1545 if ((pdata->uart_enable && !pdata->uart_disable) ||
1546 (!pdata->uart_enable && pdata->uart_disable))
1549 fiq = platform_get_irq_byname(pdev, "fiq");
1550 uart_irq = platform_get_irq_byname(pdev, "uart_irq");
1552 /* uart_irq mode and fiq mode are mutually exclusive, but one of them
1554 if ((uart_irq < 0 && fiq < 0) || (uart_irq >= 0 && fiq >= 0))
1556 if (fiq >= 0 && !pdata->fiq_enable)
1559 state = kzalloc(sizeof(*state), GFP_KERNEL);
1560 setup_timer(&state->sleep_timer, sleep_timer_expired,
1561 (unsigned long)state);
1562 state->pdata = pdata;
1564 state->no_sleep = initial_no_sleep;
1565 state->debug_enable = initial_debug_enable;
1566 state->console_enable = initial_console_enable;
1569 state->uart_irq = uart_irq;
1570 state->signal_irq = platform_get_irq_byname(pdev, "signal");
1571 state->wakeup_irq = platform_get_irq_byname(pdev, "wakeup");
1573 INIT_WORK(&state->work, debug_work);
1574 spin_lock_init(&state->work_lock);
1576 platform_set_drvdata(pdev, state);
1578 spin_lock_init(&state->sleep_timer_lock);
1580 if (state->wakeup_irq < 0 && debug_have_fiq(state))
1581 state->no_sleep = true;
1582 state->ignore_next_wakeup_irq = !state->no_sleep;
1584 wake_lock_init(&state->debugger_wake_lock,
1585 WAKE_LOCK_SUSPEND, "serial-debug");
1587 state->clk = clk_get(&pdev->dev, NULL);
1588 if (IS_ERR(state->clk))
1591 /* do not call pdata->uart_enable here since uart_init may still
1592 * need to do some initialization before uart_enable can work.
1593 * So, only try to manage the clock during init.
1596 clk_enable(state->clk);
1598 if (pdata->uart_init) {
1599 ret = pdata->uart_init(pdev);
1604 debug_printf_nfiq(state, "<hit enter %sto activate fiq debugger>\n",
1605 state->no_sleep ? "" : "twice ");
1607 if (debug_have_fiq(state)) {
1608 state->handler.fiq = debug_fiq;
1609 state->handler.resume = debug_resume;
1610 ret = fiq_glue_register_handler(&state->handler);
1612 pr_err("%s: could not install fiq handler\n", __func__);
1613 goto err_register_fiq;
1615 #ifdef CONFIG_ARCH_ROCKCHIP
1616 //set state->fiq to secure state, so fiq is avalable
1617 gic_set_irq_secure(irq_get_irq_data(state->fiq));
1618 //set state->fiq priority a little higher than other interrupts (normal is 0xa0)
1619 gic_set_irq_priority(irq_get_irq_data(state->fiq), 0x90);
1621 pdata->fiq_enable(pdev, state->fiq, 1);
1623 ret = request_irq(state->uart_irq, debug_uart_irq,
1624 IRQF_NO_SUSPEND, "debug", state);
1626 pr_err("%s: could not install irq handler\n", __func__);
1627 goto err_register_irq;
1630 /* for irq-only mode, we want this irq to wake us up, if it
1633 enable_irq_wake(state->uart_irq);
1637 clk_disable(state->clk);
1639 if (state->signal_irq >= 0) {
1640 ret = request_irq(state->signal_irq, debug_signal_irq,
1641 IRQF_TRIGGER_RISING, "debug-signal", state);
1643 pr_err("serial_debugger: could not install signal_irq");
1646 if (state->wakeup_irq >= 0) {
1647 ret = request_irq(state->wakeup_irq, wakeup_irq_handler,
1648 IRQF_TRIGGER_FALLING | IRQF_DISABLED,
1649 "debug-wakeup", state);
1651 pr_err("serial_debugger: "
1652 "could not install wakeup irq\n");
1653 state->wakeup_irq = -1;
1655 ret = enable_irq_wake(state->wakeup_irq);
1657 pr_err("serial_debugger: "
1658 "could not enable wakeup\n");
1659 state->wakeup_irq_no_set_wake = true;
1663 if (state->no_sleep)
1664 handle_wakeup(state);
1666 #if defined(CONFIG_FIQ_DEBUGGER_CONSOLE)
1667 spin_lock_init(&state->console_lock);
1668 state->console = fiq_debugger_console;
1669 state->console.index = pdev->id;
1670 if (!console_set_on_cmdline)
1671 add_preferred_console(state->console.name,
1672 state->console.index, NULL);
1673 register_console(&state->console);
1674 fiq_debugger_tty_init_one(state);
1680 if (pdata->uart_free)
1681 pdata->uart_free(pdev);
1684 clk_disable(state->clk);
1686 clk_put(state->clk);
1687 wake_lock_destroy(&state->debugger_wake_lock);
1688 platform_set_drvdata(pdev, NULL);
1693 static const struct dev_pm_ops fiq_debugger_dev_pm_ops = {
1694 .suspend = fiq_debugger_dev_suspend,
1695 .resume = fiq_debugger_dev_resume,
1698 static struct platform_driver fiq_debugger_driver = {
1699 .probe = fiq_debugger_probe,
1701 .name = "fiq_debugger",
1702 .pm = &fiq_debugger_dev_pm_ops,
1706 static int __init fiq_debugger_init(void)
1708 #if defined(CONFIG_FIQ_DEBUGGER_CONSOLE)
1709 fiq_debugger_tty_init();
1711 return platform_driver_register(&fiq_debugger_driver);
1714 postcore_initcall(fiq_debugger_init);