fiq debugger: support dummy console

Maybe you need to use uart2 as normal ttyS2, firstly disable the
uart2 debug function. Set "rockchip,serial-id" as -1, it means
fiq debugger still have a /dev/ttyFIQ0, but it doesn't have any uart
hardware.

&fiq_debugger {
	rockchip,serial-id = <0xffffffff>;
	status = "okay";
};

Change-Id: I80065eed852eb50139520c5c1fdceb882773d79d
Signed-off-by: Huibin Hong <huibin.hong@rock-chips.com>
This commit is contained in:
Huibin Hong 2019-03-04 15:17:26 +08:00 committed by Tao Huang
parent 199f9ec5ea
commit 3c04924a04
2 changed files with 80 additions and 19 deletions

View File

@ -189,6 +189,15 @@ static void debug_putc(struct platform_device *pdev, unsigned int c)
rk_fiq_write(t, c, UART_TX);
}
static int debug_getc_dummy(struct platform_device *pdev)
{
return FIQ_DEBUGGER_NO_CHAR;
}
static void debug_putc_dummy(struct platform_device *pdev, unsigned int c)
{
}
static void debug_flush(struct platform_device *pdev)
{
struct rk_fiq_debugger *t;
@ -598,6 +607,41 @@ void rk_serial_debug_init(void __iomem *base, phys_addr_t phy_base,
kfree(t);
}
void rk_serial_debug_init_dummy(void)
{
struct rk_fiq_debugger *t = NULL;
struct platform_device *pdev = NULL;
t = kzalloc(sizeof(*t), GFP_KERNEL);
if (!t) {
pr_err("Failed to allocate for fiq debugger\n");
return;
}
t->pdata.uart_getc = debug_getc_dummy;
t->pdata.uart_putc = debug_putc_dummy;
pdev = kzalloc(sizeof(*pdev), GFP_KERNEL);
if (!pdev) {
pr_err("Failed to alloc fiq debugger platform device\n");
goto out2;
}
pdev->name = "fiq_debugger";
pdev->id = rk_fiq_debugger_id++;
pdev->dev.platform_data = &t->pdata;
if (platform_device_register(pdev)) {
pr_err("Failed to register fiq debugger\n");
goto out3;
}
return;
out3:
kfree(pdev);
out2:
kfree(t);
}
#if defined(CONFIG_OF)
static const struct of_device_id rk_fiqdbg_of_match[] = {
{ .compatible = "rockchip,fiq-debugger", },
@ -628,6 +672,11 @@ static int __init rk_fiqdbg_probe(struct platform_device *pdev)
if (of_property_read_u32(np, "rockchip,serial-id", &serial_id))
return -EINVAL;
if (serial_id == -1) {
rk_serial_debug_init_dummy();
return 0;
}
if (of_property_read_u32(np, "rockchip,irq-mode-enable", &irq_mode))
irq_mode = -1;

View File

@ -232,7 +232,8 @@ static void fiq_debugger_uart_flush(struct fiq_debugger_state *state)
static void fiq_debugger_putc(struct fiq_debugger_state *state, char c)
{
state->pdata->uart_putc(state->pdev, c);
if (state->pdata->uart_putc)
state->pdata->uart_putc(state->pdev, c);
}
static void fiq_debugger_puts(struct fiq_debugger_state *state, char *s)
@ -756,7 +757,10 @@ static void fiq_debugger_handle_irq_context(struct fiq_debugger_state *state)
static int fiq_debugger_getc(struct fiq_debugger_state *state)
{
return state->pdata->uart_getc(state->pdev);
if (state->pdata->uart_getc)
return state->pdata->uart_getc(state->pdev);
else
return FIQ_DEBUGGER_NO_CHAR;
}
static int fiq_debugger_cmd_check_back(struct fiq_debugger_state *state, char c)
@ -770,9 +774,9 @@ static int fiq_debugger_cmd_check_back(struct fiq_debugger_state *state, char c)
s = state->cmd_buf[state->back_pointer];
if (*s != 0) {
for (i = 0; i < strlen(state->debug_buf) - 1; i++) {
state->pdata->uart_putc(state->pdev, 8);
state->pdata->uart_putc(state->pdev, ' ');
state->pdata->uart_putc(state->pdev, 8);
fiq_debugger_putc(state, 8);
fiq_debugger_putc(state, ' ');
fiq_debugger_putc(state, 8);
}
memset(state->debug_buf, 0, DEBUG_MAX);
strcpy(state->debug_buf, s);
@ -794,9 +798,9 @@ static int fiq_debugger_cmd_check_back(struct fiq_debugger_state *state, char c)
s = state->cmd_buf[state->back_pointer];
if (*s != 0) {
for (i = 0; i < strlen(state->debug_buf) - 1; i++) {
state->pdata->uart_putc(state->pdev, 8);
state->pdata->uart_putc(state->pdev, ' ');
state->pdata->uart_putc(state->pdev, 8);
fiq_debugger_putc(state, 8);
fiq_debugger_putc(state, ' ');
fiq_debugger_putc(state, 8);
}
memset(state->debug_buf, 0, DEBUG_MAX);
strcpy(state->debug_buf, s);
@ -807,9 +811,9 @@ static int fiq_debugger_cmd_check_back(struct fiq_debugger_state *state, char c)
} else {
cmd_clear:
for (i = 0; i < strlen(state->debug_buf) - 1; i++) {
state->pdata->uart_putc(state->pdev, 8);
state->pdata->uart_putc(state->pdev, ' ');
state->pdata->uart_putc(state->pdev, 8);
fiq_debugger_putc(state, 8);
fiq_debugger_putc(state, ' ');
fiq_debugger_putc(state, 8);
}
memset(state->debug_buf, 0, DEBUG_MAX);
state->debug_count = 0;
@ -847,9 +851,9 @@ static void fiq_debugger_cmd_tab(struct fiq_debugger_state *state)
}
for (j = 0; j < strlen(state->debug_buf); j++) {
state->pdata->uart_putc(state->pdev, 8);
state->pdata->uart_putc(state->pdev, ' ');
state->pdata->uart_putc(state->pdev, 8);
fiq_debugger_putc(state, 8);
fiq_debugger_putc(state, ' ');
fiq_debugger_putc(state, 8);
}
memset(state->debug_buf, 0, DEBUG_MAX);
strcpy(state->debug_buf, cmd_buf[i]);
@ -932,9 +936,9 @@ static bool fiq_debugger_handle_uart_interrupt(struct fiq_debugger_state *state,
} else if (last_c == '[' && (c == 'A' || c == 'B' || c == 'C' || c == 'D')) {
if (state->debug_count > 0) {
state->debug_count--;
state->pdata->uart_putc(state->pdev, 8);
state->pdata->uart_putc(state->pdev, ' ');
state->pdata->uart_putc(state->pdev, 8);
fiq_debugger_putc(state, 8);
fiq_debugger_putc(state, ' ');
fiq_debugger_putc(state, 8);
}
fiq_debugger_cmd_check_back(state, c);
} else if (c == 9) {
@ -1375,13 +1379,14 @@ static int fiq_debugger_probe(struct platform_device *pdev)
fiq = platform_get_irq_byname(pdev, "fiq");
uart_irq = platform_get_irq_byname(pdev, "uart_irq");
#ifndef CONFIG_ARCH_ROCKCHIP
/* uart_irq mode and fiq mode are mutually exclusive, but one of them
* is required */
if ((uart_irq < 0 && fiq < 0) || (uart_irq >= 0 && fiq >= 0))
return -EINVAL;
if (fiq >= 0 && !pdata->fiq_enable)
return -EINVAL;
#endif
state = kzalloc(sizeof(*state), GFP_KERNEL);
state->output.printf = fiq_debugger_printf;
timer_setup(&state->sleep_timer, fiq_debugger_sleep_timer_expired, 0);
@ -1409,6 +1414,11 @@ static int fiq_debugger_probe(struct platform_device *pdev)
wakeup_source_init(&state->debugger_wake_src, "serial-debug");
#ifdef CONFIG_ARCH_ROCKCHIP
if (uart_irq < 0 && fiq < 0)
goto console_out;
#endif
state->clk = clk_get(&pdev->dev, NULL);
if (IS_ERR(state->clk))
state->clk = NULL;
@ -1500,7 +1510,9 @@ static int fiq_debugger_probe(struct platform_device *pdev)
if (state->clk)
clk_disable(state->clk);
#ifdef CONFIG_ARCH_ROCKCHIP
console_out:
#endif
#if defined(CONFIG_FIQ_DEBUGGER_CONSOLE)
spin_lock_init(&state->console_lock);
state->console = fiq_debugger_console;