Commit b92803f6 authored by Philippe Gerum's avatar Philippe Gerum
Browse files

ipipe: amba-pl011: implement serial debug helper

parent d463af45
......@@ -563,38 +563,6 @@ unsigned long long __ipipe_mach_get_tsc(void) {
}
#endif
#if defined(CONFIG_IPIPE_DEBUG) && defined(CONFIG_DEBUG_LL)
void printascii(const char *s);
static IPIPE_DEFINE_SPINLOCK(serial_debug_lock);
void __ipipe_serial_debug(const char *fmt, ...)
{
unsigned long flags;
char buf[128];
va_list ap;
int n;
va_start(ap, fmt);
n = vsnprintf(buf, sizeof(buf) - 2, fmt, ap);
va_end(ap);
if (n > 0 && buf[n - 1] == '\n') {
buf[n] = '\r';
buf[n+1] = '\0';
}
spin_lock_irqsave(&serial_debug_lock, flags);
printascii(buf);
spin_unlock_irqrestore(&serial_debug_lock, flags);
}
#ifndef CONFIG_SERIAL_8250_CONSOLE
EXPORT_SYMBOL_GPL(__ipipe_serial_debug);
#endif
#endif
EXPORT_SYMBOL_GPL(do_munmap);
EXPORT_SYMBOL_GPL(show_stack);
EXPORT_SYMBOL_GPL(init_mm);
......
......@@ -1980,6 +1980,20 @@ static struct uart_amba_port *amba_ports[UART_NR];
#ifdef CONFIG_SERIAL_AMBA_PL011_CONSOLE
#ifdef CONFIG_IPIPE_DEBUG
#define ipipe_clk_setup(clk) clk_prepare_enable(clk)
#define ipipe_clk_enable(clk) do { } while (0)
#define ipipe_clk_disable(clk) do { } while (0)
#else /* !CONFIG_IPIPE_DEBUG */
#define ipipe_clk_setup(clk) clk_prepare(clk)
#define ipipe_clk_enable(clk) clk_enable(clk)
#define ipipe_clk_disable(clk) clk_disable(clk)
#endif /* !CONFIG_IPIPE_DEBUG */
static void pl011_console_putchar(struct uart_port *port, int ch)
{
struct uart_amba_port *uap =
......@@ -1998,7 +2012,7 @@ pl011_console_write(struct console *co, const char *s, unsigned int count)
unsigned long flags;
int locked = 1;
clk_enable(uap->clk);
ipipe_clk_enable(uap->clk);
local_irq_save(flags);
if (uap->port.sysrq)
......@@ -2031,7 +2045,7 @@ pl011_console_write(struct console *co, const char *s, unsigned int count)
spin_unlock(&uap->port.lock);
local_irq_restore(flags);
clk_disable(uap->clk);
ipipe_clk_disable(uap->clk);
}
static void __init
......@@ -2092,7 +2106,7 @@ static int __init pl011_console_setup(struct console *co, char *options)
/* Allow pins to be muxed in and configured */
pinctrl_pm_select_default_state(uap->port.dev);
ret = clk_prepare(uap->clk);
ret = ipipe_clk_setup(uap->clk);
if (ret)
return ret;
......@@ -2155,6 +2169,57 @@ static int __init pl011_early_console_setup(struct earlycon_device *device,
EARLYCON_DECLARE(pl011, pl011_early_console_setup);
OF_EARLYCON_DECLARE(pl011, "arm,pl011", pl011_early_console_setup);
static IPIPE_DEFINE_SPINLOCK(ipipe_amba_lock);
#include <linux/nmi.h>
#include <stdarg.h>
static struct console amba_console;
static void __ipipe_putchar(struct uart_port *port, int c)
{
writeb(c, port->membase + UART01x_DR);
}
void __ipipe_serial_debug(const char *fmt, ...)
{
unsigned int old_cr, new_cr, count;
struct uart_amba_port *uap;
unsigned long flags;
char buf[128];
va_list ap;
if (amba_console.index < 0)
return;
uap = amba_ports[amba_console.index];
if (uap == NULL || uap->port.membase == NULL)
return;
va_start(ap, fmt);
vsnprintf(buf, sizeof(buf), fmt, ap);
va_end(ap);
count = strlen(buf);
touch_nmi_watchdog();
spin_lock_irqsave(&ipipe_amba_lock, flags);
old_cr = readw(uap->port.membase + UART011_CR);
new_cr = old_cr & ~UART011_CR_CTSEN;
new_cr |= UART01x_CR_UARTEN | UART011_CR_TXE;
writew(new_cr, uap->port.membase + UART011_CR);
/*
* Absolutely no congestion control, debug output is supposed
* to be terse enough to cope with low latency at the selected
* serial speed.
*/
uart_console_write(&uap->port, buf, count, __ipipe_putchar);
writew(old_cr, uap->port.membase + UART011_CR);
spin_unlock_irqrestore(&ipipe_amba_lock, flags);
}
#else
#define AMBA_CONSOLE NULL
#endif
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment