Merge branch 'linux-linaro-lsk-v4.4-android' of git://git.linaro.org/kernel/linux...
[firefly-linux-kernel-4.4.55.git] / drivers / staging / android / fiq_debugger / fiq_debugger.c
index 4c392729fc680a7d557311b3eb215e724ac6368e..c9a38705f3ad402c1ea576273ade1570205ca292 100644 (file)
 #ifdef CONFIG_FIQ_GLUE
 #include <asm/fiq_glue.h>
 #endif
-#include <asm/stacktrace.h>
+
+#ifdef CONFIG_FIQ_DEBUGGER_UART_OVERLAY
+#include <linux/of.h>
+#endif
 
 #include <linux/uaccess.h>
 
 #include "fiq_debugger.h"
+#include "fiq_debugger_priv.h"
 #include "fiq_debugger_ringbuf.h"
 
 #define DEBUG_MAX 64
 
 #define MAX_FIQ_DEBUGGER_PORTS 4
 
-#define THREAD_INFO(sp) ((struct thread_info *) \
-               ((unsigned long)(sp) & ~(THREAD_SIZE - 1)))
-
 struct fiq_debugger_state {
 #ifdef CONFIG_FIQ_GLUE
        struct fiq_glue_handler handler;
 #endif
+       struct fiq_debugger_output output;
 
        int fiq;
        int uart_irq;
@@ -121,11 +123,13 @@ static bool initial_console_enable;
 #endif
 
 static bool fiq_kgdb_enable;
+static bool fiq_debugger_disable;
 
 module_param_named(no_sleep, initial_no_sleep, bool, 0644);
 module_param_named(debug_enable, initial_debug_enable, bool, 0644);
 module_param_named(console_enable, initial_console_enable, bool, 0644);
 module_param_named(kgdb_enable, fiq_kgdb_enable, bool, 0644);
+module_param_named(disable, fiq_debugger_disable, bool, 0644);
 
 #ifdef CONFIG_FIQ_DEBUGGER_WAKEUP_IRQ_ALWAYS_ON
 static inline
@@ -232,32 +236,19 @@ static void fiq_debugger_dump_kernel_log(struct fiq_debugger_state *state)
        }
 }
 
-static char *mode_name(unsigned cpsr)
-{
-       switch (cpsr & MODE_MASK) {
-       case USR_MODE: return "USR";
-       case FIQ_MODE: return "FIQ";
-       case IRQ_MODE: return "IRQ";
-       case SVC_MODE: return "SVC";
-       case ABT_MODE: return "ABT";
-       case UND_MODE: return "UND";
-       case SYSTEM_MODE: return "SYS";
-       default: return "???";
-       }
-}
-
-static int fiq_debugger_printf(void *cookie, const char *fmt, ...)
+static void fiq_debugger_printf(struct fiq_debugger_output *output,
+                              const char *fmt, ...)
 {
-       struct fiq_debugger_state *state = cookie;
+       struct fiq_debugger_state *state;
        char buf[256];
        va_list ap;
 
+       state = container_of(output, struct fiq_debugger_state, output);
        va_start(ap, fmt);
        vsnprintf(buf, sizeof(buf), fmt, ap);
        va_end(ap);
 
        fiq_debugger_puts(state, buf);
-       return state->debug_abort;
 }
 
 /* Safe outside fiq context */
@@ -279,122 +270,18 @@ static int fiq_debugger_printf_nfiq(void *cookie, const char *fmt, ...)
        return state->debug_abort;
 }
 
-static void fiq_debugger_dump_regs(struct fiq_debugger_state *state,
-               unsigned *regs)
-{
-       fiq_debugger_printf(state,
-                       " r0 %08x  r1 %08x  r2 %08x  r3 %08x\n",
-                       regs[0], regs[1], regs[2], regs[3]);
-       fiq_debugger_printf(state,
-                       " r4 %08x  r5 %08x  r6 %08x  r7 %08x\n",
-                       regs[4], regs[5], regs[6], regs[7]);
-       fiq_debugger_printf(state,
-                       " r8 %08x  r9 %08x r10 %08x r11 %08x  mode %s\n",
-                       regs[8], regs[9], regs[10], regs[11],
-                       mode_name(regs[16]));
-       if ((regs[16] & MODE_MASK) == USR_MODE)
-               fiq_debugger_printf(state,
-                               " ip %08x  sp %08x  lr %08x  pc %08x  cpsr %08x\n",
-                               regs[12], regs[13], regs[14], regs[15],
-                               regs[16]);
-       else
-               fiq_debugger_printf(state,
-                               " ip %08x  sp %08x  lr %08x  pc %08x  cpsr %08x  spsr %08x\n",
-                               regs[12], regs[13], regs[14], regs[15],
-                               regs[16], regs[17]);
-}
-
-struct mode_regs {
-       unsigned long sp_svc;
-       unsigned long lr_svc;
-       unsigned long spsr_svc;
-
-       unsigned long sp_abt;
-       unsigned long lr_abt;
-       unsigned long spsr_abt;
-
-       unsigned long sp_und;
-       unsigned long lr_und;
-       unsigned long spsr_und;
-
-       unsigned long sp_irq;
-       unsigned long lr_irq;
-       unsigned long spsr_irq;
-
-       unsigned long r8_fiq;
-       unsigned long r9_fiq;
-       unsigned long r10_fiq;
-       unsigned long r11_fiq;
-       unsigned long r12_fiq;
-       unsigned long sp_fiq;
-       unsigned long lr_fiq;
-       unsigned long spsr_fiq;
-};
-
-void __naked get_mode_regs(struct mode_regs *regs)
-{
-       asm volatile (
-       "mrs    r1, cpsr\n"
-       "msr    cpsr_c, #0xd3 @(SVC_MODE | PSR_I_BIT | PSR_F_BIT)\n"
-       "stmia  r0!, {r13 - r14}\n"
-       "mrs    r2, spsr\n"
-       "msr    cpsr_c, #0xd7 @(ABT_MODE | PSR_I_BIT | PSR_F_BIT)\n"
-       "stmia  r0!, {r2, r13 - r14}\n"
-       "mrs    r2, spsr\n"
-       "msr    cpsr_c, #0xdb @(UND_MODE | PSR_I_BIT | PSR_F_BIT)\n"
-       "stmia  r0!, {r2, r13 - r14}\n"
-       "mrs    r2, spsr\n"
-       "msr    cpsr_c, #0xd2 @(IRQ_MODE | PSR_I_BIT | PSR_F_BIT)\n"
-       "stmia  r0!, {r2, r13 - r14}\n"
-       "mrs    r2, spsr\n"
-       "msr    cpsr_c, #0xd1 @(FIQ_MODE | PSR_I_BIT | PSR_F_BIT)\n"
-       "stmia  r0!, {r2, r8 - r14}\n"
-       "mrs    r2, spsr\n"
-       "stmia  r0!, {r2}\n"
-       "msr    cpsr_c, r1\n"
-       "bx     lr\n");
-}
-
-
-static void fiq_debugger_dump_allregs(struct fiq_debugger_state *state,
-               unsigned *regs)
-{
-       struct mode_regs mode_regs;
-       fiq_debugger_dump_regs(state, regs);
-       get_mode_regs(&mode_regs);
-       fiq_debugger_printf(state,
-                       " svc: sp %08x  lr %08x  spsr %08x\n",
-                       mode_regs.sp_svc, mode_regs.lr_svc, mode_regs.spsr_svc);
-       fiq_debugger_printf(state,
-                       " abt: sp %08x  lr %08x  spsr %08x\n",
-                       mode_regs.sp_abt, mode_regs.lr_abt, mode_regs.spsr_abt);
-       fiq_debugger_printf(state,
-                       " und: sp %08x  lr %08x  spsr %08x\n",
-                       mode_regs.sp_und, mode_regs.lr_und, mode_regs.spsr_und);
-       fiq_debugger_printf(state,
-                       " irq: sp %08x  lr %08x  spsr %08x\n",
-                       mode_regs.sp_irq, mode_regs.lr_irq, mode_regs.spsr_irq);
-       fiq_debugger_printf(state,
-                       " fiq: r8 %08x  r9 %08x  r10 %08x  r11 %08x  r12 %08x\n",
-                       mode_regs.r8_fiq, mode_regs.r9_fiq, mode_regs.r10_fiq,
-                       mode_regs.r11_fiq, mode_regs.r12_fiq);
-       fiq_debugger_printf(state,
-                       " fiq: sp %08x  lr %08x  spsr %08x\n",
-                       mode_regs.sp_fiq, mode_regs.lr_fiq, mode_regs.spsr_fiq);
-}
-
 static void fiq_debugger_dump_irqs(struct fiq_debugger_state *state)
 {
        int n;
        struct irq_desc *desc;
 
-       fiq_debugger_printf(state,
+       fiq_debugger_printf(&state->output,
                        "irqnr       total  since-last   status  name\n");
        for_each_irq_desc(n, desc) {
                struct irqaction *act = desc->action;
                if (!act && !kstat_irqs(n))
                        continue;
-               fiq_debugger_printf(state, "%5d: %10u %11u %8x  %s\n", n,
+               fiq_debugger_printf(&state->output, "%5d: %10u %11u %8x  %s\n", n,
                        kstat_irqs(n),
                        kstat_irqs(n) - state->last_irqs[n],
                        desc->status_use_accessors,
@@ -403,98 +290,6 @@ static void fiq_debugger_dump_irqs(struct fiq_debugger_state *state)
        }
 }
 
-struct stacktrace_state {
-       struct fiq_debugger_state *state;
-       unsigned int depth;
-};
-
-static int report_trace(struct stackframe *frame, void *d)
-{
-       struct stacktrace_state *sts = d;
-
-       if (sts->depth) {
-               fiq_debugger_printf(sts->state,
-                       "  pc: %p (%pF), lr %p (%pF), sp %p, fp %p\n",
-                       frame->pc, frame->pc, frame->lr, frame->lr,
-                       frame->sp, frame->fp);
-               sts->depth--;
-               return 0;
-       }
-       fiq_debugger_printf(sts->state, "  ...\n");
-
-       return sts->depth == 0;
-}
-
-struct frame_tail {
-       struct frame_tail *fp;
-       unsigned long sp;
-       unsigned long lr;
-} __attribute__((packed));
-
-static struct frame_tail *user_backtrace(struct fiq_debugger_state *state,
-                                       struct frame_tail *tail)
-{
-       struct frame_tail buftail[2];
-
-       /* Also check accessibility of one struct frame_tail beyond */
-       if (!access_ok(VERIFY_READ, tail, sizeof(buftail))) {
-               fiq_debugger_printf(state, "  invalid frame pointer %p\n",
-                               tail);
-               return NULL;
-       }
-       if (__copy_from_user_inatomic(buftail, tail, sizeof(buftail))) {
-               fiq_debugger_printf(state,
-                       "  failed to copy frame pointer %p\n", tail);
-               return NULL;
-       }
-
-       fiq_debugger_printf(state, "  %p\n", buftail[0].lr);
-
-       /* frame pointers should strictly progress back up the stack
-        * (towards higher addresses) */
-       if (tail >= buftail[0].fp)
-               return NULL;
-
-       return buftail[0].fp-1;
-}
-
-void fiq_debugger_dump_stacktrace(struct fiq_debugger_state *state,
-               struct pt_regs * const regs, unsigned int depth, void *ssp)
-{
-       struct frame_tail *tail;
-       struct thread_info *real_thread_info = THREAD_INFO(ssp);
-       struct stacktrace_state sts;
-
-       sts.depth = depth;
-       sts.state = state;
-       *current_thread_info() = *real_thread_info;
-
-       if (!current)
-               fiq_debugger_printf(state, "current NULL\n");
-       else
-               fiq_debugger_printf(state, "pid: %d  comm: %s\n",
-                       current->pid, current->comm);
-       fiq_debugger_dump_regs(state, (unsigned *)regs);
-
-       if (!user_mode(regs)) {
-               struct stackframe frame;
-               frame.fp = regs->ARM_fp;
-               frame.sp = regs->ARM_sp;
-               frame.lr = regs->ARM_lr;
-               frame.pc = regs->ARM_pc;
-               fiq_debugger_printf(state,
-                       "  pc: %p (%pF), lr %p (%pF), sp %p, fp %p\n",
-                       regs->ARM_pc, regs->ARM_pc, regs->ARM_lr, regs->ARM_lr,
-                       regs->ARM_sp, regs->ARM_fp);
-               walk_stackframe(&frame, report_trace, &sts);
-               return;
-       }
-
-       tail = ((struct frame_tail *) regs->ARM_fp) - 1;
-       while (depth-- && tail && !((unsigned long) tail & 3))
-               tail = user_backtrace(state, tail);
-}
-
 static void fiq_debugger_do_ps(struct fiq_debugger_state *state)
 {
        struct task_struct *g;
@@ -502,18 +297,18 @@ static void fiq_debugger_do_ps(struct fiq_debugger_state *state)
        unsigned task_state;
        static const char stat_nam[] = "RSDTtZX";
 
-       fiq_debugger_printf(state, "pid   ppid  prio task            pc\n");
+       fiq_debugger_printf(&state->output, "pid   ppid  prio task            pc\n");
        read_lock(&tasklist_lock);
        do_each_thread(g, p) {
                task_state = p->state ? __ffs(p->state) + 1 : 0;
-               fiq_debugger_printf(state,
+               fiq_debugger_printf(&state->output,
                             "%5d %5d %4d ", p->pid, p->parent->pid, p->prio);
-               fiq_debugger_printf(state, "%-13.13s %c", p->comm,
+               fiq_debugger_printf(&state->output, "%-13.13s %c", p->comm,
                             task_state >= sizeof(stat_nam) ? '?' : stat_nam[task_state]);
                if (task_state == TASK_RUNNING)
-                       fiq_debugger_printf(state, " running\n");
+                       fiq_debugger_printf(&state->output, " running\n");
                else
-                       fiq_debugger_printf(state, " %08lx\n",
+                       fiq_debugger_printf(&state->output, " %08lx\n",
                                        thread_saved_pc(p));
        } while_each_thread(g, p);
        read_unlock(&tasklist_lock);
@@ -545,7 +340,7 @@ static void fiq_debugger_end_syslog_dump(struct fiq_debugger_state *state)
 static void fiq_debugger_do_sysrq(struct fiq_debugger_state *state, char rq)
 {
        if ((rq == 'g' || rq == 'G') && !fiq_kgdb_enable) {
-               fiq_debugger_printf(state, "sysrq-g blocked\n");
+               fiq_debugger_printf(&state->output, "sysrq-g blocked\n");
                return;
        }
        fiq_debugger_begin_syslog_dump(state);
@@ -557,11 +352,11 @@ static void fiq_debugger_do_sysrq(struct fiq_debugger_state *state, char rq)
 static void fiq_debugger_do_kgdb(struct fiq_debugger_state *state)
 {
        if (!fiq_kgdb_enable) {
-               fiq_debugger_printf(state, "kgdb through fiq debugger not enabled\n");
+               fiq_debugger_printf(&state->output, "kgdb through fiq debugger not enabled\n");
                return;
        }
 
-       fiq_debugger_printf(state, "enabling console and triggering kgdb\n");
+       fiq_debugger_printf(&state->output, "enabling console and triggering kgdb\n");
        state->console_enable = true;
        handle_sysrq('g');
 }
@@ -574,7 +369,7 @@ static void fiq_debugger_schedule_work(struct fiq_debugger_state *state,
 
        spin_lock_irqsave(&state->work_lock, flags);
        if (state->work_cmd[0] != '\0') {
-               fiq_debugger_printf(state, "work command processor busy\n");
+               fiq_debugger_printf(&state->output, "work command processor busy\n");
                spin_unlock_irqrestore(&state->work_lock, flags);
                return;
        }
@@ -611,7 +406,7 @@ static void fiq_debugger_work(struct work_struct *work)
                else
                        kernel_restart(NULL);
        } else {
-               fiq_debugger_printf(state, "unknown work command '%s'\n",
+               fiq_debugger_printf(&state->output, "unknown work command '%s'\n",
                                work_cmd);
        }
 }
@@ -635,7 +430,7 @@ static void fiq_debugger_irq_exec(struct fiq_debugger_state *state, char *cmd)
 
 static void fiq_debugger_help(struct fiq_debugger_state *state)
 {
-       fiq_debugger_printf(state,
+       fiq_debugger_printf(&state->output,
                                "FIQ Debugger commands:\n"
                                " pc            PC status\n"
                                " regs          Register dump\n"
@@ -646,18 +441,18 @@ static void fiq_debugger_help(struct fiq_debugger_state *state)
                                " irqs          Interupt status\n"
                                " kmsg          Kernel log\n"
                                " version       Kernel version\n");
-       fiq_debugger_printf(state,
+       fiq_debugger_printf(&state->output,
                                " sleep         Allow sleep while in FIQ\n"
                                " nosleep       Disable sleep while in FIQ\n"
                                " console       Switch terminal to console\n"
                                " cpu           Current CPU\n"
                                " cpu <number>  Switch to CPU<number>\n");
-       fiq_debugger_printf(state,
+       fiq_debugger_printf(&state->output,
                                " ps            Process list\n"
                                " sysrq         sysrq options\n"
                                " sysrq <param> Execute sysrq with <param>\n");
 #ifdef CONFIG_KGDB
-       fiq_debugger_printf(state,
+       fiq_debugger_printf(&state->output,
                                " kgdb          Enter kernel debugger\n");
 #endif
 }
@@ -682,22 +477,21 @@ static void fiq_debugger_switch_cpu(struct fiq_debugger_state *state, int cpu)
 }
 
 static bool fiq_debugger_fiq_exec(struct fiq_debugger_state *state,
-                       const char *cmd, unsigned *regs, void *svc_sp)
+                       const char *cmd, const struct pt_regs *regs,
+                       void *svc_sp)
 {
        bool signal_helper = false;
 
        if (!strcmp(cmd, "help") || !strcmp(cmd, "?")) {
                fiq_debugger_help(state);
        } else if (!strcmp(cmd, "pc")) {
-               fiq_debugger_printf(state, " pc %08x cpsr %08x mode %s\n",
-                       regs[15], regs[16], mode_name(regs[16]));
+               fiq_debugger_dump_pc(&state->output, regs);
        } else if (!strcmp(cmd, "regs")) {
-               fiq_debugger_dump_regs(state, regs);
+               fiq_debugger_dump_regs(&state->output, regs);
        } else if (!strcmp(cmd, "allregs")) {
-               fiq_debugger_dump_allregs(state, regs);
+               fiq_debugger_dump_allregs(&state->output, regs);
        } else if (!strcmp(cmd, "bt")) {
-               fiq_debugger_dump_stacktrace(state, (struct pt_regs *)regs, 100,
-                               svc_sp);
+               fiq_debugger_dump_stacktrace(&state->output, regs, 100, svc_sp);
        } else if (!strncmp(cmd, "reset", 5)) {
                cmd += 5;
                while (*cmd == ' ')
@@ -705,6 +499,8 @@ static bool fiq_debugger_fiq_exec(struct fiq_debugger_state *state,
                if (*cmd) {
                        char tmp_cmd[32];
                        strlcpy(tmp_cmd, cmd, sizeof(tmp_cmd));
+                       blocking_notifier_call_chain(&reboot_notifier_list,
+                                               SYS_RESTART, (char *)cmd);
                        machine_restart(tmp_cmd);
                } else {
                        machine_restart(NULL);
@@ -714,29 +510,29 @@ static bool fiq_debugger_fiq_exec(struct fiq_debugger_state *state,
        } else if (!strcmp(cmd, "kmsg")) {
                fiq_debugger_dump_kernel_log(state);
        } else if (!strcmp(cmd, "version")) {
-               fiq_debugger_printf(state, "%s\n", linux_banner);
+               fiq_debugger_printf(&state->output, "%s\n", linux_banner);
        } else if (!strcmp(cmd, "sleep")) {
                state->no_sleep = false;
-               fiq_debugger_printf(state, "enabling sleep\n");
+               fiq_debugger_printf(&state->output, "enabling sleep\n");
        } else if (!strcmp(cmd, "nosleep")) {
                state->no_sleep = true;
-               fiq_debugger_printf(state, "disabling sleep\n");
+               fiq_debugger_printf(&state->output, "disabling sleep\n");
        } else if (!strcmp(cmd, "console")) {
-               fiq_debugger_printf(state, "console mode\n");
+               fiq_debugger_printf(&state->output, "console mode\n");
                fiq_debugger_uart_flush(state);
                state->console_enable = true;
        } else if (!strcmp(cmd, "cpu")) {
-               fiq_debugger_printf(state, "cpu %d\n", state->current_cpu);
+               fiq_debugger_printf(&state->output, "cpu %d\n", state->current_cpu);
        } else if (!strncmp(cmd, "cpu ", 4)) {
                unsigned long cpu = 0;
-               if (strict_strtoul(cmd + 4, 10, &cpu) == 0)
+               if (kstrtoul(cmd + 4, 10, &cpu) == 0)
                        fiq_debugger_switch_cpu(state, cpu);
                else
-                       fiq_debugger_printf(state, "invalid cpu\n");
-               fiq_debugger_printf(state, "cpu %d\n", state->current_cpu);
+                       fiq_debugger_printf(&state->output, "invalid cpu\n");
+               fiq_debugger_printf(&state->output, "cpu %d\n", state->current_cpu);
        } else {
                if (state->debug_busy) {
-                       fiq_debugger_printf(state,
+                       fiq_debugger_printf(&state->output,
                                "command processor busy. trying to abort.\n");
                        state->debug_abort = -1;
                } else {
@@ -844,14 +640,14 @@ static int fiq_debugger_getc(struct fiq_debugger_state *state)
 }
 
 static bool fiq_debugger_handle_uart_interrupt(struct fiq_debugger_state *state,
-                       int this_cpu, struct pt_regs *regs, void *svc_sp)
+                       int this_cpu, const struct pt_regs *regs, void *svc_sp)
 {
        int c;
        static int last_c;
        int count = 0;
        bool signal_helper = false;
 
-       if (this_cpu != state->current_cpu) {
+       if ((this_cpu != state->current_cpu) && (cpu_online(state->current_cpu))) {
                if (state->in_fiq)
                        return false;
 
@@ -859,7 +655,7 @@ static bool fiq_debugger_handle_uart_interrupt(struct fiq_debugger_state *state,
                                        MAX_UNHANDLED_FIQ_COUNT)
                        return false;
 
-               fiq_debugger_printf(state,
+               fiq_debugger_printf(&state->output,
                        "fiq_debugger: cpu %d not responding, "
                        "reverting to cpu %d\n", state->current_cpu,
                        this_cpu);
@@ -869,6 +665,9 @@ static bool fiq_debugger_handle_uart_interrupt(struct fiq_debugger_state *state,
                return false;
        }
 
+       if (this_cpu != state->current_cpu)
+               state->current_cpu = this_cpu;
+
        state->in_fiq = true;
 
        while ((c = fiq_debugger_getc(state)) != FIQ_DEBUGGER_NO_CHAR) {
@@ -935,8 +734,8 @@ static bool fiq_debugger_handle_uart_interrupt(struct fiq_debugger_state *state,
 }
 
 #ifdef CONFIG_FIQ_GLUE
-static void fiq_debugger_fiq(struct fiq_glue_handler *h, void *regs,
-               void *svc_sp)
+static void fiq_debugger_fiq(struct fiq_glue_handler *h,
+               const struct pt_regs *regs, void *svc_sp)
 {
        struct fiq_debugger_state *state =
                container_of(h, struct fiq_debugger_state, handler);
@@ -1017,6 +816,13 @@ static void fiq_debugger_console_write(struct console *co,
        if (!state->console_enable && !state->syslog_dumping)
                return;
 
+#ifdef CONFIG_RK_CONSOLE_THREAD
+       if (state->pdata->console_write) {
+               state->pdata->console_write(state->pdev, s, count);
+               return;
+       }
+#endif
+
        fiq_debugger_uart_enable(state);
        spin_lock_irqsave(&state->console_lock, flags);
        while (count--) {
@@ -1267,6 +1073,7 @@ static int fiq_debugger_probe(struct platform_device *pdev)
                return -EINVAL;
 
        state = kzalloc(sizeof(*state), GFP_KERNEL);
+       state->output.printf = fiq_debugger_printf;
        setup_timer(&state->sleep_timer, fiq_debugger_sleep_timer_expired,
                    (unsigned long)state);
        state->pdata = pdata;
@@ -1355,7 +1162,7 @@ static int fiq_debugger_probe(struct platform_device *pdev)
        if (state->wakeup_irq >= 0) {
                ret = request_irq(state->wakeup_irq,
                                  fiq_debugger_wakeup_irq_handler,
-                                 IRQF_TRIGGER_FALLING | IRQF_DISABLED,
+                                 IRQF_TRIGGER_FALLING,
                                  "debug-wakeup", state);
                if (ret) {
                        pr_err("serial_debugger: "
@@ -1412,10 +1219,40 @@ static struct platform_driver fiq_debugger_driver = {
        },
 };
 
+#if defined(CONFIG_FIQ_DEBUGGER_UART_OVERLAY)
+int fiq_debugger_uart_overlay(void)
+{
+       struct device_node *onp = of_find_node_by_path("/uart_overlay@0");
+       int ret;
+
+       if (!onp) {
+               pr_err("serial_debugger: uart overlay not found\n");
+               return -ENODEV;
+       }
+
+       ret = of_overlay_create(onp);
+       if (ret < 0) {
+               pr_err("serial_debugger: fail to create overlay: %d\n", ret);
+               of_node_put(onp);
+               return ret;
+       }
+
+       pr_info("serial_debugger: uart overlay applied\n");
+       return 0;
+}
+#endif
+
 static int __init fiq_debugger_init(void)
 {
+       if (fiq_debugger_disable) {
+               pr_err("serial_debugger: disabled\n");
+               return -ENODEV;
+       }
 #if defined(CONFIG_FIQ_DEBUGGER_CONSOLE)
        fiq_debugger_tty_init();
+#endif
+#if defined(CONFIG_FIQ_DEBUGGER_UART_OVERLAY)
+       fiq_debugger_uart_overlay();
 #endif
        return platform_driver_register(&fiq_debugger_driver);
 }