blob: a120b75afe3d686001f53c36571b1fb1e093a6e8 [file] [log] [blame]
Iliyan Malchevc1db50b2010-06-05 17:36:24 -07001/*
2 * arch/arm/common/fiq_debugger.c
3 *
4 * Serial Debugger Interface accessed through an FIQ interrupt.
5 *
6 * Copyright (C) 2008 Google, Inc.
7 *
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.
11 *
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.
16 */
17
18#include <stdarg.h>
19#include <linux/module.h>
20#include <linux/io.h>
Colin Cross4df8d7b2010-08-16 14:51:51 -070021#include <linux/console.h>
Iliyan Malchevc1db50b2010-06-05 17:36:24 -070022#include <linux/interrupt.h>
23#include <linux/clk.h>
24#include <linux/platform_device.h>
25#include <linux/kernel_debugger.h>
26#include <linux/kernel_stat.h>
27#include <linux/irq.h>
28#include <linux/delay.h>
29#include <linux/sched.h>
30#include <linux/slab.h>
Dima Zavin83b72702011-10-02 20:35:47 -070031#include <linux/smp.h>
Iliyan Malchevc1db50b2010-06-05 17:36:24 -070032#include <linux/timer.h>
Colin Cross4df8d7b2010-08-16 14:51:51 -070033#include <linux/tty.h>
34#include <linux/tty_flip.h>
Iliyan Malchevc1db50b2010-06-05 17:36:24 -070035#include <linux/wakelock.h>
36
37#include <asm/fiq_debugger.h>
38#include <asm/fiq_glue.h>
39#include <asm/stacktrace.h>
40
41#include <mach/system.h>
42
43#include <linux/uaccess.h>
44
Colin Cross4df8d7b2010-08-16 14:51:51 -070045#include "fiq_debugger_ringbuf.h"
46
Iliyan Malchevc1db50b2010-06-05 17:36:24 -070047#define DEBUG_MAX 64
Colin Cross24b3bd42010-10-01 23:41:38 -070048#define MAX_UNHANDLED_FIQ_COUNT 1000000
49
50#define THREAD_INFO(sp) ((struct thread_info *) \
51 ((unsigned long)(sp) & ~(THREAD_SIZE - 1)))
Iliyan Malchevc1db50b2010-06-05 17:36:24 -070052
53struct fiq_debugger_state {
54 struct fiq_glue_handler handler;
55
56 int fiq;
Dima Zavin83b72702011-10-02 20:35:47 -070057 int uart_irq;
Iliyan Malchevc1db50b2010-06-05 17:36:24 -070058 int signal_irq;
59 int wakeup_irq;
60 bool wakeup_irq_no_set_wake;
61 struct clk *clk;
62 struct fiq_debugger_pdata *pdata;
63 struct platform_device *pdev;
64
65 char debug_cmd[DEBUG_MAX];
66 int debug_busy;
67 int debug_abort;
68
69 char debug_buf[DEBUG_MAX];
70 int debug_count;
71
72 bool no_sleep;
73 bool debug_enable;
74 bool ignore_next_wakeup_irq;
75 struct timer_list sleep_timer;
Dima Zavin932de6c2011-10-13 22:38:45 -070076 spinlock_t sleep_timer_lock;
Dima Zavinefde6552011-10-05 14:08:20 -070077 bool uart_enabled;
Iliyan Malchevc1db50b2010-06-05 17:36:24 -070078 struct wake_lock debugger_wake_lock;
Colin Cross4df8d7b2010-08-16 14:51:51 -070079 bool console_enable;
Colin Cross24b3bd42010-10-01 23:41:38 -070080 int current_cpu;
81 atomic_t unhandled_fiq_count;
82 bool in_fiq;
Colin Cross4df8d7b2010-08-16 14:51:51 -070083
84#ifdef CONFIG_FIQ_DEBUGGER_CONSOLE
85 struct console console;
86 struct tty_driver *tty_driver;
87 struct tty_struct *tty;
88 int tty_open_count;
89 struct fiq_debugger_ringbuf *tty_rbuf;
90#endif
Iliyan Malchevc1db50b2010-06-05 17:36:24 -070091
92 unsigned int last_irqs[NR_IRQS];
Rebecca Schultz Zavinb824eef2010-10-22 15:55:17 -070093 unsigned int last_local_timer_irqs[NR_CPUS];
Iliyan Malchevc1db50b2010-06-05 17:36:24 -070094};
95
96#ifdef CONFIG_FIQ_DEBUGGER_NO_SLEEP
97static bool initial_no_sleep = true;
98#else
99static bool initial_no_sleep;
100#endif
Dima Zavinc6fba162010-11-10 15:39:07 -0800101
102#ifdef CONFIG_FIQ_DEBUGGER_CONSOLE_DEFAULT_ENABLE
103static bool initial_debug_enable = true;
104static bool initial_console_enable = true;
105#else
Iliyan Malchevc1db50b2010-06-05 17:36:24 -0700106static bool initial_debug_enable;
Colin Cross4df8d7b2010-08-16 14:51:51 -0700107static bool initial_console_enable;
Dima Zavinc6fba162010-11-10 15:39:07 -0800108#endif
Iliyan Malchevc1db50b2010-06-05 17:36:24 -0700109
110module_param_named(no_sleep, initial_no_sleep, bool, 0644);
111module_param_named(debug_enable, initial_debug_enable, bool, 0644);
Colin Cross4df8d7b2010-08-16 14:51:51 -0700112module_param_named(console_enable, initial_console_enable, bool, 0644);
Iliyan Malchevc1db50b2010-06-05 17:36:24 -0700113
114#ifdef CONFIG_FIQ_DEBUGGER_WAKEUP_IRQ_ALWAYS_ON
115static inline void enable_wakeup_irq(struct fiq_debugger_state *state) {}
116static inline void disable_wakeup_irq(struct fiq_debugger_state *state) {}
117#else
118static inline void enable_wakeup_irq(struct fiq_debugger_state *state)
119{
120 if (state->wakeup_irq < 0)
121 return;
122 enable_irq(state->wakeup_irq);
123 if (!state->wakeup_irq_no_set_wake)
124 enable_irq_wake(state->wakeup_irq);
125}
126static inline void disable_wakeup_irq(struct fiq_debugger_state *state)
127{
128 if (state->wakeup_irq < 0)
129 return;
130 disable_irq_nosync(state->wakeup_irq);
131 if (!state->wakeup_irq_no_set_wake)
132 disable_irq_wake(state->wakeup_irq);
133}
134#endif
135
Dima Zavin83b72702011-10-02 20:35:47 -0700136static bool inline debug_have_fiq(struct fiq_debugger_state *state)
137{
138 return (state->fiq >= 0);
139}
140
Iliyan Malchevc1db50b2010-06-05 17:36:24 -0700141static void debug_force_irq(struct fiq_debugger_state *state)
142{
143 unsigned int irq = state->signal_irq;
Dima Zavin83b72702011-10-02 20:35:47 -0700144
145 if (WARN_ON(!debug_have_fiq(state)))
146 return;
147 if (state->pdata->force_irq) {
Iliyan Malchevc1db50b2010-06-05 17:36:24 -0700148 state->pdata->force_irq(state->pdev, irq);
Dima Zavin83b72702011-10-02 20:35:47 -0700149 } else {
Colin Cross999853b2011-04-08 17:26:06 -0700150 struct irq_chip *chip = irq_get_chip(irq);
151 if (chip && chip->irq_retrigger)
152 chip->irq_retrigger(irq_get_irq_data(irq));
Iliyan Malchevc1db50b2010-06-05 17:36:24 -0700153 }
154}
155
Dima Zavinefde6552011-10-05 14:08:20 -0700156static void debug_uart_enable(struct fiq_debugger_state *state)
157{
158 if (state->clk)
159 clk_enable(state->clk);
160 if (state->pdata->uart_enable)
161 state->pdata->uart_enable(state->pdev);
162}
163
164static void debug_uart_disable(struct fiq_debugger_state *state)
165{
166 if (state->pdata->uart_disable)
167 state->pdata->uart_disable(state->pdev);
168 if (state->clk)
169 clk_disable(state->clk);
170}
171
Iliyan Malchevc1db50b2010-06-05 17:36:24 -0700172static void debug_uart_flush(struct fiq_debugger_state *state)
173{
174 if (state->pdata->uart_flush)
175 state->pdata->uart_flush(state->pdev);
176}
177
178static void debug_puts(struct fiq_debugger_state *state, char *s)
179{
180 unsigned c;
181 while ((c = *s++)) {
182 if (c == '\n')
183 state->pdata->uart_putc(state->pdev, '\r');
184 state->pdata->uart_putc(state->pdev, c);
185 }
186}
187
188static void debug_prompt(struct fiq_debugger_state *state)
189{
190 debug_puts(state, "debug> ");
191}
192
193int log_buf_copy(char *dest, int idx, int len);
194static void dump_kernel_log(struct fiq_debugger_state *state)
195{
196 char buf[1024];
197 int idx = 0;
198 int ret;
199 int saved_oip;
200
201 /* setting oops_in_progress prevents log_buf_copy()
202 * from trying to take a spinlock which will make it
203 * very unhappy in some cases...
204 */
205 saved_oip = oops_in_progress;
206 oops_in_progress = 1;
207 for (;;) {
208 ret = log_buf_copy(buf, idx, 1023);
209 if (ret <= 0)
210 break;
211 buf[ret] = 0;
212 debug_puts(state, buf);
213 idx += ret;
214 }
215 oops_in_progress = saved_oip;
216}
217
218static char *mode_name(unsigned cpsr)
219{
220 switch (cpsr & MODE_MASK) {
221 case USR_MODE: return "USR";
222 case FIQ_MODE: return "FIQ";
223 case IRQ_MODE: return "IRQ";
224 case SVC_MODE: return "SVC";
225 case ABT_MODE: return "ABT";
226 case UND_MODE: return "UND";
227 case SYSTEM_MODE: return "SYS";
228 default: return "???";
229 }
230}
231
232static int debug_printf(void *cookie, const char *fmt, ...)
233{
234 struct fiq_debugger_state *state = cookie;
235 char buf[256];
236 va_list ap;
237
238 va_start(ap, fmt);
239 vsnprintf(buf, sizeof(buf), fmt, ap);
240 va_end(ap);
241
242 debug_puts(state, buf);
243 return state->debug_abort;
244}
245
246/* Safe outside fiq context */
247static int debug_printf_nfiq(void *cookie, const char *fmt, ...)
248{
249 struct fiq_debugger_state *state = cookie;
250 char buf[256];
251 va_list ap;
252 unsigned long irq_flags;
253
254 va_start(ap, fmt);
255 vsnprintf(buf, 128, fmt, ap);
256 va_end(ap);
257
258 local_irq_save(irq_flags);
259 debug_puts(state, buf);
260 debug_uart_flush(state);
261 local_irq_restore(irq_flags);
262 return state->debug_abort;
263}
264
265static void dump_regs(struct fiq_debugger_state *state, unsigned *regs)
266{
267 debug_printf(state, " r0 %08x r1 %08x r2 %08x r3 %08x\n",
268 regs[0], regs[1], regs[2], regs[3]);
269 debug_printf(state, " r4 %08x r5 %08x r6 %08x r7 %08x\n",
270 regs[4], regs[5], regs[6], regs[7]);
271 debug_printf(state, " r8 %08x r9 %08x r10 %08x r11 %08x mode %s\n",
272 regs[8], regs[9], regs[10], regs[11],
273 mode_name(regs[16]));
274 if ((regs[16] & MODE_MASK) == USR_MODE)
275 debug_printf(state, " ip %08x sp %08x lr %08x pc %08x "
276 "cpsr %08x\n", regs[12], regs[13], regs[14],
277 regs[15], regs[16]);
278 else
279 debug_printf(state, " ip %08x sp %08x lr %08x pc %08x "
280 "cpsr %08x spsr %08x\n", regs[12], regs[13],
281 regs[14], regs[15], regs[16], regs[17]);
282}
283
284struct mode_regs {
285 unsigned long sp_svc;
286 unsigned long lr_svc;
287 unsigned long spsr_svc;
288
289 unsigned long sp_abt;
290 unsigned long lr_abt;
291 unsigned long spsr_abt;
292
293 unsigned long sp_und;
294 unsigned long lr_und;
295 unsigned long spsr_und;
296
297 unsigned long sp_irq;
298 unsigned long lr_irq;
299 unsigned long spsr_irq;
300
301 unsigned long r8_fiq;
302 unsigned long r9_fiq;
303 unsigned long r10_fiq;
304 unsigned long r11_fiq;
305 unsigned long r12_fiq;
306 unsigned long sp_fiq;
307 unsigned long lr_fiq;
308 unsigned long spsr_fiq;
309};
310
311void __naked get_mode_regs(struct mode_regs *regs)
312{
313 asm volatile (
314 "mrs r1, cpsr\n"
315 "msr cpsr_c, #0xd3 @(SVC_MODE | PSR_I_BIT | PSR_F_BIT)\n"
316 "stmia r0!, {r13 - r14}\n"
317 "mrs r2, spsr\n"
318 "msr cpsr_c, #0xd7 @(ABT_MODE | PSR_I_BIT | PSR_F_BIT)\n"
319 "stmia r0!, {r2, r13 - r14}\n"
320 "mrs r2, spsr\n"
321 "msr cpsr_c, #0xdb @(UND_MODE | PSR_I_BIT | PSR_F_BIT)\n"
322 "stmia r0!, {r2, r13 - r14}\n"
323 "mrs r2, spsr\n"
324 "msr cpsr_c, #0xd2 @(IRQ_MODE | PSR_I_BIT | PSR_F_BIT)\n"
325 "stmia r0!, {r2, r13 - r14}\n"
326 "mrs r2, spsr\n"
327 "msr cpsr_c, #0xd1 @(FIQ_MODE | PSR_I_BIT | PSR_F_BIT)\n"
328 "stmia r0!, {r2, r8 - r14}\n"
329 "mrs r2, spsr\n"
330 "stmia r0!, {r2}\n"
331 "msr cpsr_c, r1\n"
332 "bx lr\n");
333}
334
335
336static void dump_allregs(struct fiq_debugger_state *state, unsigned *regs)
337{
338 struct mode_regs mode_regs;
339 dump_regs(state, regs);
340 get_mode_regs(&mode_regs);
341 debug_printf(state, " svc: sp %08x lr %08x spsr %08x\n",
342 mode_regs.sp_svc, mode_regs.lr_svc, mode_regs.spsr_svc);
343 debug_printf(state, " abt: sp %08x lr %08x spsr %08x\n",
344 mode_regs.sp_abt, mode_regs.lr_abt, mode_regs.spsr_abt);
345 debug_printf(state, " und: sp %08x lr %08x spsr %08x\n",
346 mode_regs.sp_und, mode_regs.lr_und, mode_regs.spsr_und);
347 debug_printf(state, " irq: sp %08x lr %08x spsr %08x\n",
348 mode_regs.sp_irq, mode_regs.lr_irq, mode_regs.spsr_irq);
349 debug_printf(state, " fiq: r8 %08x r9 %08x r10 %08x r11 %08x "
350 "r12 %08x\n",
351 mode_regs.r8_fiq, mode_regs.r9_fiq, mode_regs.r10_fiq,
352 mode_regs.r11_fiq, mode_regs.r12_fiq);
353 debug_printf(state, " fiq: sp %08x lr %08x spsr %08x\n",
354 mode_regs.sp_fiq, mode_regs.lr_fiq, mode_regs.spsr_fiq);
355}
356
357static void dump_irqs(struct fiq_debugger_state *state)
358{
359 int n;
Rebecca Schultz Zavinb824eef2010-10-22 15:55:17 -0700360 unsigned int cpu;
361
Iliyan Malchevc1db50b2010-06-05 17:36:24 -0700362 debug_printf(state, "irqnr total since-last status name\n");
363 for (n = 0; n < NR_IRQS; n++) {
364 struct irqaction *act = irq_desc[n].action;
365 if (!act && !kstat_irqs(n))
366 continue;
367 debug_printf(state, "%5d: %10u %11u %8x %s\n", n,
368 kstat_irqs(n),
369 kstat_irqs(n) - state->last_irqs[n],
Colin Cross999853b2011-04-08 17:26:06 -0700370 irq_desc[n].status_use_accessors,
Iliyan Malchevc1db50b2010-06-05 17:36:24 -0700371 (act && act->name) ? act->name : "???");
372 state->last_irqs[n] = kstat_irqs(n);
373 }
Rebecca Schultz Zavinb824eef2010-10-22 15:55:17 -0700374
375 for (cpu = 0; cpu < NR_CPUS; cpu++) {
376
377 debug_printf(state, "LOC %d: %10u %11u\n", cpu,
378 __IRQ_STAT(cpu, local_timer_irqs),
379 __IRQ_STAT(cpu, local_timer_irqs) -
380 state->last_local_timer_irqs[cpu]);
381 state->last_local_timer_irqs[cpu] =
382 __IRQ_STAT(cpu, local_timer_irqs);
383 }
Iliyan Malchevc1db50b2010-06-05 17:36:24 -0700384}
385
386struct stacktrace_state {
387 struct fiq_debugger_state *state;
388 unsigned int depth;
389};
390
391static int report_trace(struct stackframe *frame, void *d)
392{
393 struct stacktrace_state *sts = d;
394
395 if (sts->depth) {
396 debug_printf(sts->state,
397 " pc: %p (%pF), lr %p (%pF), sp %p, fp %p\n",
398 frame->pc, frame->pc, frame->lr, frame->lr,
399 frame->sp, frame->fp);
400 sts->depth--;
401 return 0;
402 }
403 debug_printf(sts->state, " ...\n");
404
405 return sts->depth == 0;
406}
407
408struct frame_tail {
409 struct frame_tail *fp;
410 unsigned long sp;
411 unsigned long lr;
412} __attribute__((packed));
413
414static struct frame_tail *user_backtrace(struct fiq_debugger_state *state,
415 struct frame_tail *tail)
416{
417 struct frame_tail buftail[2];
418
419 /* Also check accessibility of one struct frame_tail beyond */
420 if (!access_ok(VERIFY_READ, tail, sizeof(buftail))) {
421 debug_printf(state, " invalid frame pointer %p\n", tail);
422 return NULL;
423 }
424 if (__copy_from_user_inatomic(buftail, tail, sizeof(buftail))) {
425 debug_printf(state,
426 " failed to copy frame pointer %p\n", tail);
427 return NULL;
428 }
429
430 debug_printf(state, " %p\n", buftail[0].lr);
431
432 /* frame pointers should strictly progress back up the stack
433 * (towards higher addresses) */
434 if (tail >= buftail[0].fp)
435 return NULL;
436
437 return buftail[0].fp-1;
438}
439
440void dump_stacktrace(struct fiq_debugger_state *state,
441 struct pt_regs * const regs, unsigned int depth, void *ssp)
442{
443 struct frame_tail *tail;
Colin Cross24b3bd42010-10-01 23:41:38 -0700444 struct thread_info *real_thread_info = THREAD_INFO(ssp);
Iliyan Malchevc1db50b2010-06-05 17:36:24 -0700445 struct stacktrace_state sts;
446
447 sts.depth = depth;
448 sts.state = state;
449 *current_thread_info() = *real_thread_info;
450
451 if (!current)
452 debug_printf(state, "current NULL\n");
453 else
454 debug_printf(state, "pid: %d comm: %s\n",
455 current->pid, current->comm);
456 dump_regs(state, (unsigned *)regs);
457
458 if (!user_mode(regs)) {
459 struct stackframe frame;
460 frame.fp = regs->ARM_fp;
461 frame.sp = regs->ARM_sp;
462 frame.lr = regs->ARM_lr;
463 frame.pc = regs->ARM_pc;
464 debug_printf(state,
465 " pc: %p (%pF), lr %p (%pF), sp %p, fp %p\n",
466 regs->ARM_pc, regs->ARM_pc, regs->ARM_lr, regs->ARM_lr,
467 regs->ARM_sp, regs->ARM_fp);
468 walk_stackframe(&frame, report_trace, &sts);
469 return;
470 }
471
472 tail = ((struct frame_tail *) regs->ARM_fp) - 1;
473 while (depth-- && tail && !((unsigned long) tail & 3))
474 tail = user_backtrace(state, tail);
475}
476
Dima Zavin83b72702011-10-02 20:35:47 -0700477static bool debug_help(struct fiq_debugger_state *state)
Dmitry Shmidt5eed1db2010-11-16 15:40:13 -0800478{
479 debug_printf(state, "FIQ Debugger commands:\n"
480 " pc PC status\n"
481 " regs Register dump\n"
482 " allregs Extended Register dump\n"
483 " bt Stack trace\n"
484 " reboot Reboot\n"
485 " irqs Interupt status\n"
486 " kmsg Kernel log\n"
487 " version Kernel version\n");
488 debug_printf(state, " sleep Allow sleep while in FIQ\n"
489 " nosleep Disable sleep while in FIQ\n"
490 " console Switch terminal to console\n"
491 " cpu Current CPU\n"
492 " cpu <number> Switch to CPU<number>\n");
493 if (!state->debug_busy) {
494 strcpy(state->debug_cmd, "help");
495 state->debug_busy = 1;
Dima Zavin83b72702011-10-02 20:35:47 -0700496 return true;
Dmitry Shmidt5eed1db2010-11-16 15:40:13 -0800497 }
Dima Zavin83b72702011-10-02 20:35:47 -0700498
499 return false;
Dmitry Shmidt5eed1db2010-11-16 15:40:13 -0800500}
501
Dima Zavin83b72702011-10-02 20:35:47 -0700502static void take_affinity(void *info)
503{
504 struct fiq_debugger_state *state = info;
505 struct cpumask cpumask;
506
507 cpumask_clear(&cpumask);
508 cpumask_set_cpu(get_cpu(), &cpumask);
509
510 irq_set_affinity(state->uart_irq, &cpumask);
511}
512
513static void switch_cpu(struct fiq_debugger_state *state, int cpu)
514{
515 if (!debug_have_fiq(state))
516 smp_call_function_single(cpu, take_affinity, state, false);
517 state->current_cpu = cpu;
518}
519
520static bool debug_exec(struct fiq_debugger_state *state,
Iliyan Malchevc1db50b2010-06-05 17:36:24 -0700521 const char *cmd, unsigned *regs, void *svc_sp)
522{
Dima Zavin83b72702011-10-02 20:35:47 -0700523 bool signal_helper = false;
524
Dmitry Shmidt5eed1db2010-11-16 15:40:13 -0800525 if (!strcmp(cmd, "help") || !strcmp(cmd, "?")) {
Dima Zavin83b72702011-10-02 20:35:47 -0700526 signal_helper |= debug_help(state);
Dmitry Shmidt5eed1db2010-11-16 15:40:13 -0800527 } else if (!strcmp(cmd, "pc")) {
Iliyan Malchevc1db50b2010-06-05 17:36:24 -0700528 debug_printf(state, " pc %08x cpsr %08x mode %s\n",
529 regs[15], regs[16], mode_name(regs[16]));
530 } else if (!strcmp(cmd, "regs")) {
531 dump_regs(state, regs);
532 } else if (!strcmp(cmd, "allregs")) {
533 dump_allregs(state, regs);
534 } else if (!strcmp(cmd, "bt")) {
535 dump_stacktrace(state, (struct pt_regs *)regs, 100, svc_sp);
536 } else if (!strcmp(cmd, "reboot")) {
537 arch_reset(0, 0);
538 } else if (!strcmp(cmd, "irqs")) {
539 dump_irqs(state);
540 } else if (!strcmp(cmd, "kmsg")) {
541 dump_kernel_log(state);
542 } else if (!strcmp(cmd, "version")) {
543 debug_printf(state, "%s\n", linux_banner);
544 } else if (!strcmp(cmd, "sleep")) {
545 state->no_sleep = false;
Dima Zavin83b72702011-10-02 20:35:47 -0700546 debug_printf(state, "enabling sleep\n");
Iliyan Malchevc1db50b2010-06-05 17:36:24 -0700547 } else if (!strcmp(cmd, "nosleep")) {
548 state->no_sleep = true;
Dima Zavin83b72702011-10-02 20:35:47 -0700549 debug_printf(state, "disabling sleep\n");
Colin Cross4df8d7b2010-08-16 14:51:51 -0700550 } else if (!strcmp(cmd, "console")) {
551 state->console_enable = true;
552 debug_printf(state, "console mode\n");
Colin Cross24b3bd42010-10-01 23:41:38 -0700553 } else if (!strcmp(cmd, "cpu")) {
554 debug_printf(state, "cpu %d\n", state->current_cpu);
555 } else if (!strncmp(cmd, "cpu ", 4)) {
556 unsigned long cpu = 0;
557 if (strict_strtoul(cmd + 4, 10, &cpu) == 0)
Dima Zavin83b72702011-10-02 20:35:47 -0700558 switch_cpu(state, cpu);
Colin Cross24b3bd42010-10-01 23:41:38 -0700559 else
560 debug_printf(state, "invalid cpu\n");
561 debug_printf(state, "cpu %d\n", state->current_cpu);
Iliyan Malchevc1db50b2010-06-05 17:36:24 -0700562 } else {
563 if (state->debug_busy) {
564 debug_printf(state,
565 "command processor busy. trying to abort.\n");
566 state->debug_abort = -1;
567 } else {
568 strcpy(state->debug_cmd, cmd);
569 state->debug_busy = 1;
570 }
571
Dima Zavin83b72702011-10-02 20:35:47 -0700572 return true;
Iliyan Malchevc1db50b2010-06-05 17:36:24 -0700573 }
Colin Cross4df8d7b2010-08-16 14:51:51 -0700574 if (!state->console_enable)
575 debug_prompt(state);
Dima Zavin83b72702011-10-02 20:35:47 -0700576
577 return signal_helper;
Iliyan Malchevc1db50b2010-06-05 17:36:24 -0700578}
579
580static void sleep_timer_expired(unsigned long data)
581{
582 struct fiq_debugger_state *state = (struct fiq_debugger_state *)data;
Dima Zavin932de6c2011-10-13 22:38:45 -0700583 unsigned long flags;
Iliyan Malchevc1db50b2010-06-05 17:36:24 -0700584
Dima Zavin932de6c2011-10-13 22:38:45 -0700585 spin_lock_irqsave(&state->sleep_timer_lock, flags);
Dima Zavinefde6552011-10-05 14:08:20 -0700586 if (state->uart_enabled && !state->no_sleep) {
Dima Zavin48ef31a2011-10-09 11:47:35 -0700587 if (state->debug_enable && !state->console_enable) {
Iliyan Malchevc1db50b2010-06-05 17:36:24 -0700588 state->debug_enable = false;
589 debug_printf_nfiq(state, "suspending fiq debugger\n");
590 }
591 state->ignore_next_wakeup_irq = true;
Dima Zavinefde6552011-10-05 14:08:20 -0700592 debug_uart_disable(state);
593 state->uart_enabled = false;
Iliyan Malchevc1db50b2010-06-05 17:36:24 -0700594 enable_wakeup_irq(state);
595 }
596 wake_unlock(&state->debugger_wake_lock);
Dima Zavin932de6c2011-10-13 22:38:45 -0700597 spin_unlock_irqrestore(&state->sleep_timer_lock, flags);
Iliyan Malchevc1db50b2010-06-05 17:36:24 -0700598}
599
Dima Zavin83b72702011-10-02 20:35:47 -0700600static void handle_wakeup(struct fiq_debugger_state *state)
Iliyan Malchevc1db50b2010-06-05 17:36:24 -0700601{
Dima Zavin932de6c2011-10-13 22:38:45 -0700602 unsigned long flags;
603
604 spin_lock_irqsave(&state->sleep_timer_lock, flags);
Dima Zavin83b72702011-10-02 20:35:47 -0700605 if (state->wakeup_irq >= 0 && state->ignore_next_wakeup_irq) {
Iliyan Malchevc1db50b2010-06-05 17:36:24 -0700606 state->ignore_next_wakeup_irq = false;
Dima Zavinefde6552011-10-05 14:08:20 -0700607 } else if (!state->uart_enabled) {
Iliyan Malchevc1db50b2010-06-05 17:36:24 -0700608 wake_lock(&state->debugger_wake_lock);
Dima Zavinefde6552011-10-05 14:08:20 -0700609 debug_uart_enable(state);
610 state->uart_enabled = true;
Iliyan Malchevc1db50b2010-06-05 17:36:24 -0700611 disable_wakeup_irq(state);
612 mod_timer(&state->sleep_timer, jiffies + HZ / 2);
613 }
Dima Zavin932de6c2011-10-13 22:38:45 -0700614 spin_unlock_irqrestore(&state->sleep_timer_lock, flags);
Dima Zavin83b72702011-10-02 20:35:47 -0700615}
616
617static irqreturn_t wakeup_irq_handler(int irq, void *dev)
618{
619 struct fiq_debugger_state *state = dev;
620
621 if (!state->no_sleep)
622 debug_puts(state, "WAKEUP\n");
623 handle_wakeup(state);
624
Iliyan Malchevc1db50b2010-06-05 17:36:24 -0700625 return IRQ_HANDLED;
626}
627
Iliyan Malchevc1db50b2010-06-05 17:36:24 -0700628
Dima Zavin83b72702011-10-02 20:35:47 -0700629static void debug_handle_irq_context(struct fiq_debugger_state *state)
630{
Iliyan Malchevc1db50b2010-06-05 17:36:24 -0700631 if (!state->no_sleep) {
Dima Zavin932de6c2011-10-13 22:38:45 -0700632 unsigned long flags;
633
634 spin_lock_irqsave(&state->sleep_timer_lock, flags);
Iliyan Malchevc1db50b2010-06-05 17:36:24 -0700635 wake_lock(&state->debugger_wake_lock);
636 mod_timer(&state->sleep_timer, jiffies + HZ * 5);
Dima Zavin932de6c2011-10-13 22:38:45 -0700637 spin_unlock_irqrestore(&state->sleep_timer_lock, flags);
Iliyan Malchevc1db50b2010-06-05 17:36:24 -0700638 }
Colin Cross4df8d7b2010-08-16 14:51:51 -0700639#if defined(CONFIG_FIQ_DEBUGGER_CONSOLE)
640 if (state->tty) {
641 int i;
642 int count = fiq_debugger_ringbuf_level(state->tty_rbuf);
643 for (i = 0; i < count; i++) {
Dima Zavinb0092752011-10-25 21:24:10 -0700644 int c = fiq_debugger_ringbuf_peek(state->tty_rbuf, 0);
Colin Cross4df8d7b2010-08-16 14:51:51 -0700645 tty_insert_flip_char(state->tty, c, TTY_NORMAL);
646 if (!fiq_debugger_ringbuf_consume(state->tty_rbuf, 1))
647 pr_warn("fiq tty failed to consume byte\n");
648 }
649 tty_flip_buffer_push(state->tty);
650 }
651#endif
Iliyan Malchevc1db50b2010-06-05 17:36:24 -0700652 if (state->debug_busy) {
653 struct kdbg_ctxt ctxt;
654
655 ctxt.printf = debug_printf_nfiq;
656 ctxt.cookie = state;
657 kernel_debugger(&ctxt, state->debug_cmd);
658 debug_prompt(state);
659
660 state->debug_busy = 0;
661 }
Iliyan Malchevc1db50b2010-06-05 17:36:24 -0700662}
663
664static int debug_getc(struct fiq_debugger_state *state)
665{
666 return state->pdata->uart_getc(state->pdev);
667}
668
Dima Zavin83b72702011-10-02 20:35:47 -0700669static bool debug_handle_uart_interrupt(struct fiq_debugger_state *state,
670 int this_cpu, void *regs, void *svc_sp)
Iliyan Malchevc1db50b2010-06-05 17:36:24 -0700671{
Iliyan Malchevc1db50b2010-06-05 17:36:24 -0700672 int c;
673 static int last_c;
674 int count = 0;
Dima Zavin83b72702011-10-02 20:35:47 -0700675 bool signal_helper = false;
Colin Cross24b3bd42010-10-01 23:41:38 -0700676
677 if (this_cpu != state->current_cpu) {
678 if (state->in_fiq)
Dima Zavin83b72702011-10-02 20:35:47 -0700679 return false;
Colin Cross24b3bd42010-10-01 23:41:38 -0700680
681 if (atomic_inc_return(&state->unhandled_fiq_count) !=
682 MAX_UNHANDLED_FIQ_COUNT)
Dima Zavin83b72702011-10-02 20:35:47 -0700683 return false;
Colin Cross24b3bd42010-10-01 23:41:38 -0700684
685 debug_printf(state, "fiq_debugger: cpu %d not responding, "
686 "reverting to cpu %d\n", state->current_cpu,
687 this_cpu);
688
689 atomic_set(&state->unhandled_fiq_count, 0);
Dima Zavin83b72702011-10-02 20:35:47 -0700690 switch_cpu(state, this_cpu);
691 return false;
Colin Cross24b3bd42010-10-01 23:41:38 -0700692 }
693
694 state->in_fiq = true;
Iliyan Malchevc1db50b2010-06-05 17:36:24 -0700695
696 while ((c = debug_getc(state)) != FIQ_DEBUGGER_NO_CHAR) {
697 count++;
698 if (!state->debug_enable) {
699 if ((c == 13) || (c == 10)) {
700 state->debug_enable = true;
701 state->debug_count = 0;
702 debug_prompt(state);
703 }
Colin Cross4df8d7b2010-08-16 14:51:51 -0700704 } else if (c == FIQ_DEBUGGER_BREAK) {
705 state->console_enable = false;
706 debug_puts(state, "fiq debugger mode\n");
707 state->debug_count = 0;
708 debug_prompt(state);
709#ifdef CONFIG_FIQ_DEBUGGER_CONSOLE
710 } else if (state->console_enable && state->tty_rbuf) {
711 fiq_debugger_ringbuf_push(state->tty_rbuf, c);
Dima Zavin83b72702011-10-02 20:35:47 -0700712 signal_helper = true;
Colin Cross4df8d7b2010-08-16 14:51:51 -0700713#endif
Iliyan Malchevc1db50b2010-06-05 17:36:24 -0700714 } else if ((c >= ' ') && (c < 127)) {
715 if (state->debug_count < (DEBUG_MAX - 1)) {
716 state->debug_buf[state->debug_count++] = c;
717 state->pdata->uart_putc(state->pdev, c);
718 }
719 } else if ((c == 8) || (c == 127)) {
720 if (state->debug_count > 0) {
721 state->debug_count--;
722 state->pdata->uart_putc(state->pdev, 8);
723 state->pdata->uart_putc(state->pdev, ' ');
724 state->pdata->uart_putc(state->pdev, 8);
725 }
726 } else if ((c == 13) || (c == 10)) {
727 if (c == '\r' || (c == '\n' && last_c != '\r')) {
728 state->pdata->uart_putc(state->pdev, '\r');
729 state->pdata->uart_putc(state->pdev, '\n');
730 }
731 if (state->debug_count) {
732 state->debug_buf[state->debug_count] = 0;
733 state->debug_count = 0;
Dima Zavin83b72702011-10-02 20:35:47 -0700734 signal_helper |=
735 debug_exec(state, state->debug_buf,
736 regs, svc_sp);
Iliyan Malchevc1db50b2010-06-05 17:36:24 -0700737 } else {
738 debug_prompt(state);
739 }
740 }
741 last_c = c;
742 }
743 debug_uart_flush(state);
744 if (state->pdata->fiq_ack)
745 state->pdata->fiq_ack(state->pdev, state->fiq);
746
747 /* poke sleep timer if necessary */
748 if (state->debug_enable && !state->no_sleep)
Dima Zavin83b72702011-10-02 20:35:47 -0700749 signal_helper = true;
Colin Cross24b3bd42010-10-01 23:41:38 -0700750
751 atomic_set(&state->unhandled_fiq_count, 0);
752 state->in_fiq = false;
Dima Zavin83b72702011-10-02 20:35:47 -0700753
754 return signal_helper;
755}
756
757static void debug_fiq(struct fiq_glue_handler *h, void *regs, void *svc_sp)
758{
759 struct fiq_debugger_state *state =
760 container_of(h, struct fiq_debugger_state, handler);
761 unsigned int this_cpu = THREAD_INFO(svc_sp)->cpu;
762 bool need_irq;
763
764 need_irq = debug_handle_uart_interrupt(state, this_cpu, regs, svc_sp);
765 if (need_irq)
766 debug_force_irq(state);
767}
768
769/*
770 * When not using FIQs, we only use this single interrupt as an entry point.
771 * This just effectively takes over the UART interrupt and does all the work
772 * in this context.
773 */
774static irqreturn_t debug_uart_irq(int irq, void *dev)
775{
776 struct fiq_debugger_state *state = dev;
777 bool not_done;
778
779 handle_wakeup(state);
780
781 /* handle the debugger irq in regular context */
782 not_done = debug_handle_uart_interrupt(state, smp_processor_id(),
783 get_irq_regs(),
784 current_thread_info());
785 if (not_done)
786 debug_handle_irq_context(state);
787
788 return IRQ_HANDLED;
789}
790
791/*
792 * If FIQs are used, not everything can happen in fiq context.
793 * FIQ handler does what it can and then signals this interrupt to finish the
794 * job in irq context.
795 */
796static irqreturn_t debug_signal_irq(int irq, void *dev)
797{
798 struct fiq_debugger_state *state = dev;
799
800 if (state->pdata->force_irq_ack)
801 state->pdata->force_irq_ack(state->pdev, state->signal_irq);
802
803 debug_handle_irq_context(state);
804
805 return IRQ_HANDLED;
Iliyan Malchevc1db50b2010-06-05 17:36:24 -0700806}
807
808static void debug_resume(struct fiq_glue_handler *h)
809{
810 struct fiq_debugger_state *state =
811 container_of(h, struct fiq_debugger_state, handler);
812 if (state->pdata->uart_resume)
813 state->pdata->uart_resume(state->pdev);
814}
815
Colin Cross4df8d7b2010-08-16 14:51:51 -0700816#if defined(CONFIG_FIQ_DEBUGGER_CONSOLE)
817struct tty_driver *debug_console_device(struct console *co, int *index)
818{
819 struct fiq_debugger_state *state;
820 state = container_of(co, struct fiq_debugger_state, console);
821 *index = 0;
822 return state->tty_driver;
823}
824
825static void debug_console_write(struct console *co,
826 const char *s, unsigned int count)
827{
828 struct fiq_debugger_state *state;
829
830 state = container_of(co, struct fiq_debugger_state, console);
831
832 if (!state->console_enable)
833 return;
834
Dima Zavinefde6552011-10-05 14:08:20 -0700835 debug_uart_enable(state);
Colin Cross4df8d7b2010-08-16 14:51:51 -0700836 while (count--) {
837 if (*s == '\n')
838 state->pdata->uart_putc(state->pdev, '\r');
839 state->pdata->uart_putc(state->pdev, *s++);
840 }
841 debug_uart_flush(state);
Dima Zavinefde6552011-10-05 14:08:20 -0700842 debug_uart_disable(state);
Colin Cross4df8d7b2010-08-16 14:51:51 -0700843}
844
845static struct console fiq_debugger_console = {
846 .name = "ttyFIQ",
847 .device = debug_console_device,
848 .write = debug_console_write,
849 .flags = CON_PRINTBUFFER | CON_ANYTIME | CON_ENABLED,
850};
851
852int fiq_tty_open(struct tty_struct *tty, struct file *filp)
853{
854 struct fiq_debugger_state *state = tty->driver->driver_state;
855 if (state->tty_open_count++)
856 return 0;
857
858 tty->driver_data = state;
859 state->tty = tty;
860 return 0;
861}
862
863void fiq_tty_close(struct tty_struct *tty, struct file *filp)
864{
865 struct fiq_debugger_state *state = tty->driver_data;
866 if (--state->tty_open_count)
867 return;
868 state->tty = NULL;
869}
870
871int fiq_tty_write(struct tty_struct *tty, const unsigned char *buf, int count)
872{
873 int i;
874 struct fiq_debugger_state *state = tty->driver_data;
875
876 if (!state->console_enable)
877 return count;
878
Dima Zavinefde6552011-10-05 14:08:20 -0700879 debug_uart_enable(state);
Colin Cross4df8d7b2010-08-16 14:51:51 -0700880 for (i = 0; i < count; i++)
881 state->pdata->uart_putc(state->pdev, *buf++);
Dima Zavinefde6552011-10-05 14:08:20 -0700882 debug_uart_disable(state);
Colin Cross4df8d7b2010-08-16 14:51:51 -0700883
884 return count;
885}
886
887int fiq_tty_write_room(struct tty_struct *tty)
888{
889 return 1024;
890}
891
892static const struct tty_operations fiq_tty_driver_ops = {
893 .write = fiq_tty_write,
894 .write_room = fiq_tty_write_room,
895 .open = fiq_tty_open,
896 .close = fiq_tty_close,
897};
898
899static int fiq_debugger_tty_init(struct fiq_debugger_state *state)
900{
901 int ret = -EINVAL;
902
903 state->tty_driver = alloc_tty_driver(1);
904 if (!state->tty_driver) {
905 pr_err("Failed to allocate fiq debugger tty\n");
906 return -ENOMEM;
907 }
908
909 state->tty_driver->owner = THIS_MODULE;
910 state->tty_driver->driver_name = "fiq-debugger";
911 state->tty_driver->name = "ttyFIQ";
912 state->tty_driver->type = TTY_DRIVER_TYPE_SERIAL;
913 state->tty_driver->subtype = SERIAL_TYPE_NORMAL;
914 state->tty_driver->init_termios = tty_std_termios;
915 state->tty_driver->init_termios.c_cflag =
916 B115200 | CS8 | CREAD | HUPCL | CLOCAL;
917 state->tty_driver->init_termios.c_ispeed =
918 state->tty_driver->init_termios.c_ospeed = 115200;
919 state->tty_driver->flags = TTY_DRIVER_REAL_RAW;
920 tty_set_operations(state->tty_driver, &fiq_tty_driver_ops);
921 state->tty_driver->driver_state = state;
922
923 ret = tty_register_driver(state->tty_driver);
924 if (ret) {
925 pr_err("Failed to register fiq tty: %d\n", ret);
926 goto err;
927 }
928
929 state->tty_rbuf = fiq_debugger_ringbuf_alloc(1024);
930 if (!state->tty_rbuf) {
931 pr_err("Failed to allocate fiq debugger ringbuf\n");
932 ret = -ENOMEM;
933 goto err;
934 }
935
936 pr_info("Registered FIQ tty driver %p\n", state->tty_driver);
937 return 0;
938
939err:
940 fiq_debugger_ringbuf_free(state->tty_rbuf);
941 state->tty_rbuf = NULL;
942 put_tty_driver(state->tty_driver);
943 return ret;
944}
945#endif
946
Dima Zavinf4aea212011-10-10 15:24:34 -0700947static int fiq_debugger_dev_suspend(struct device *dev)
948{
949 struct platform_device *pdev = to_platform_device(dev);
950 struct fiq_debugger_state *state = platform_get_drvdata(pdev);
951
952 if (state->pdata->uart_dev_suspend)
953 return state->pdata->uart_dev_suspend(pdev);
954 return 0;
955}
956
957static int fiq_debugger_dev_resume(struct device *dev)
958{
959 struct platform_device *pdev = to_platform_device(dev);
960 struct fiq_debugger_state *state = platform_get_drvdata(pdev);
961
962 if (state->pdata->uart_dev_resume)
963 return state->pdata->uart_dev_resume(pdev);
964 return 0;
965}
966
Iliyan Malchevc1db50b2010-06-05 17:36:24 -0700967static int fiq_debugger_probe(struct platform_device *pdev)
968{
969 int ret;
970 struct fiq_debugger_pdata *pdata = dev_get_platdata(&pdev->dev);
971 struct fiq_debugger_state *state;
Dima Zavin83b72702011-10-02 20:35:47 -0700972 int fiq;
973 int uart_irq;
Iliyan Malchevc1db50b2010-06-05 17:36:24 -0700974
Dima Zavin83b72702011-10-02 20:35:47 -0700975 if (!pdata->uart_getc || !pdata->uart_putc)
976 return -EINVAL;
Dima Zavinefde6552011-10-05 14:08:20 -0700977 if ((pdata->uart_enable && !pdata->uart_disable) ||
978 (!pdata->uart_enable && pdata->uart_disable))
979 return -EINVAL;
Dima Zavin83b72702011-10-02 20:35:47 -0700980
981 fiq = platform_get_irq_byname(pdev, "fiq");
982 uart_irq = platform_get_irq_byname(pdev, "uart_irq");
983
984 /* uart_irq mode and fiq mode are mutually exclusive, but one of them
985 * is required */
986 if ((uart_irq < 0 && fiq < 0) || (uart_irq >= 0 && fiq >= 0))
987 return -EINVAL;
988 if (fiq >= 0 && !pdata->fiq_enable)
Iliyan Malchevc1db50b2010-06-05 17:36:24 -0700989 return -EINVAL;
990
991 state = kzalloc(sizeof(*state), GFP_KERNEL);
Iliyan Malchevc1db50b2010-06-05 17:36:24 -0700992 setup_timer(&state->sleep_timer, sleep_timer_expired,
993 (unsigned long)state);
994 state->pdata = pdata;
995 state->pdev = pdev;
996 state->no_sleep = initial_no_sleep;
997 state->debug_enable = initial_debug_enable;
Colin Cross4df8d7b2010-08-16 14:51:51 -0700998 state->console_enable = initial_console_enable;
Iliyan Malchevc1db50b2010-06-05 17:36:24 -0700999
Dima Zavin83b72702011-10-02 20:35:47 -07001000 state->fiq = fiq;
1001 state->uart_irq = uart_irq;
Iliyan Malchevc1db50b2010-06-05 17:36:24 -07001002 state->signal_irq = platform_get_irq_byname(pdev, "signal");
1003 state->wakeup_irq = platform_get_irq_byname(pdev, "wakeup");
1004
Dima Zavinf4aea212011-10-10 15:24:34 -07001005 platform_set_drvdata(pdev, state);
1006
Dima Zavin932de6c2011-10-13 22:38:45 -07001007 spin_lock_init(&state->sleep_timer_lock);
1008
Dima Zavin83b72702011-10-02 20:35:47 -07001009 if (state->wakeup_irq < 0 && debug_have_fiq(state))
Iliyan Malchevc1db50b2010-06-05 17:36:24 -07001010 state->no_sleep = true;
1011 state->ignore_next_wakeup_irq = !state->no_sleep;
1012
1013 wake_lock_init(&state->debugger_wake_lock,
1014 WAKE_LOCK_SUSPEND, "serial-debug");
1015
1016 state->clk = clk_get(&pdev->dev, NULL);
1017 if (IS_ERR(state->clk))
1018 state->clk = NULL;
1019
Dima Zavinefde6552011-10-05 14:08:20 -07001020 /* do not call pdata->uart_enable here since uart_init may still
1021 * need to do some initialization before uart_enable can work.
1022 * So, only try to manage the clock during init.
1023 */
Iliyan Malchevc1db50b2010-06-05 17:36:24 -07001024 if (state->clk)
1025 clk_enable(state->clk);
1026
1027 if (pdata->uart_init) {
1028 ret = pdata->uart_init(pdev);
1029 if (ret)
1030 goto err_uart_init;
1031 }
1032
1033 debug_printf_nfiq(state, "<hit enter %sto activate fiq debugger>\n",
1034 state->no_sleep ? "" : "twice ");
1035
Dima Zavin83b72702011-10-02 20:35:47 -07001036 if (debug_have_fiq(state)) {
1037 state->handler.fiq = debug_fiq;
1038 state->handler.resume = debug_resume;
1039 ret = fiq_glue_register_handler(&state->handler);
1040 if (ret) {
1041 pr_err("%s: could not install fiq handler\n", __func__);
1042 goto err_register_fiq;
1043 }
Iliyan Malchevc1db50b2010-06-05 17:36:24 -07001044
Dima Zavin83b72702011-10-02 20:35:47 -07001045 pdata->fiq_enable(pdev, state->fiq, 1);
1046 } else {
1047 ret = request_irq(state->uart_irq, debug_uart_irq,
1048 0, "debug", state);
1049 if (ret) {
1050 pr_err("%s: could not install irq handler\n", __func__);
1051 goto err_register_irq;
1052 }
1053
1054 /* for irq-only mode, we want this irq to wake us up, if it
1055 * can.
1056 */
1057 enable_irq_wake(state->uart_irq);
1058 }
Iliyan Malchevc1db50b2010-06-05 17:36:24 -07001059
1060 if (state->clk)
1061 clk_disable(state->clk);
1062
Dima Zavin83b72702011-10-02 20:35:47 -07001063 if (state->signal_irq >= 0) {
1064 ret = request_irq(state->signal_irq, debug_signal_irq,
1065 IRQF_TRIGGER_RISING, "debug-signal", state);
1066 if (ret)
1067 pr_err("serial_debugger: could not install signal_irq");
1068 }
Iliyan Malchevc1db50b2010-06-05 17:36:24 -07001069
1070 if (state->wakeup_irq >= 0) {
1071 ret = request_irq(state->wakeup_irq, wakeup_irq_handler,
1072 IRQF_TRIGGER_FALLING | IRQF_DISABLED,
1073 "debug-wakeup", state);
1074 if (ret) {
1075 pr_err("serial_debugger: "
1076 "could not install wakeup irq\n");
1077 state->wakeup_irq = -1;
1078 } else {
1079 ret = enable_irq_wake(state->wakeup_irq);
1080 if (ret) {
1081 pr_err("serial_debugger: "
1082 "could not enable wakeup\n");
1083 state->wakeup_irq_no_set_wake = true;
1084 }
1085 }
1086 }
1087 if (state->no_sleep)
Dima Zavin83b72702011-10-02 20:35:47 -07001088 handle_wakeup(state);
Iliyan Malchevc1db50b2010-06-05 17:36:24 -07001089
Colin Cross4df8d7b2010-08-16 14:51:51 -07001090#if defined(CONFIG_FIQ_DEBUGGER_CONSOLE)
1091 state->console = fiq_debugger_console;
1092 register_console(&state->console);
1093 fiq_debugger_tty_init(state);
1094#endif
Iliyan Malchevc1db50b2010-06-05 17:36:24 -07001095 return 0;
1096
Dima Zavin83b72702011-10-02 20:35:47 -07001097err_register_irq:
Iliyan Malchevc1db50b2010-06-05 17:36:24 -07001098err_register_fiq:
1099 if (pdata->uart_free)
1100 pdata->uart_free(pdev);
1101err_uart_init:
Dima Zavin0d5d8ec2011-10-20 14:48:37 -07001102 if (state->clk)
1103 clk_disable(state->clk);
Iliyan Malchevc1db50b2010-06-05 17:36:24 -07001104 if (state->clk)
1105 clk_put(state->clk);
Dima Zavin0d5d8ec2011-10-20 14:48:37 -07001106 wake_lock_destroy(&state->debugger_wake_lock);
Dima Zavinf4aea212011-10-10 15:24:34 -07001107 platform_set_drvdata(pdev, NULL);
Dima Zavin0d5d8ec2011-10-20 14:48:37 -07001108 kfree(state);
Iliyan Malchevc1db50b2010-06-05 17:36:24 -07001109 return ret;
1110}
1111
Dima Zavinf4aea212011-10-10 15:24:34 -07001112static const struct dev_pm_ops fiq_debugger_dev_pm_ops = {
1113 .suspend = fiq_debugger_dev_suspend,
1114 .resume = fiq_debugger_dev_resume,
1115};
1116
Iliyan Malchevc1db50b2010-06-05 17:36:24 -07001117static struct platform_driver fiq_debugger_driver = {
Dima Zavinf4aea212011-10-10 15:24:34 -07001118 .probe = fiq_debugger_probe,
1119 .driver = {
1120 .name = "fiq_debugger",
1121 .pm = &fiq_debugger_dev_pm_ops,
1122 },
Iliyan Malchevc1db50b2010-06-05 17:36:24 -07001123};
1124
1125static int __init fiq_debugger_init(void)
1126{
1127 return platform_driver_register(&fiq_debugger_driver);
1128}
1129
1130postcore_initcall(fiq_debugger_init);