summaryrefslogtreecommitdiffstats
path: root/arch/sh64/kernel/early_printk.c
blob: 8c8a76e180aabca423167cf247056590ded9fdce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
 * arch/sh64/kernel/early_printk.c
 *
 * SH-5 Early SCIF console (cloned and hacked from sh implementation)
 *
 * Copyright (C) 2003, 2004  Paul Mundt <lethal@linux-sh.org>
 * Copyright (C) 2002  M. R. Brown <mrbrown@0xd6.org>
 *
 * This file is subject to the terms and conditions of the GNU General Public
 * License.  See the file "COPYING" in the main directory of this archive
 * for more details.
 */
#include <linux/console.h>
#include <linux/tty.h>
#include <linux/init.h>
#include <asm/io.h>
#include <asm/hardware.h>

#define SCIF_BASE_ADDR	0x01030000
#define SCIF_ADDR_SH5	PHYS_PERIPHERAL_BLOCK+SCIF_BASE_ADDR

/*
 * Fixed virtual address where SCIF is mapped (should already be done
 * in arch/sh64/kernel/head.S!).
 */
#define SCIF_REG	0xfa030000

enum {
	SCIF_SCSMR2	= SCIF_REG + 0x00,
	SCIF_SCBRR2	= SCIF_REG + 0x04,
	SCIF_SCSCR2	= SCIF_REG + 0x08,
	SCIF_SCFTDR2	= SCIF_REG + 0x0c,
	SCIF_SCFSR2	= SCIF_REG + 0x10,
	SCIF_SCFRDR2	= SCIF_REG + 0x14,
	SCIF_SCFCR2	= SCIF_REG + 0x18,
	SCIF_SCFDR2	= SCIF_REG + 0x1c,
	SCIF_SCSPTR2	= SCIF_REG + 0x20,
	SCIF_SCLSR2	= SCIF_REG + 0x24,
};

static void sh_console_putc(int c)
{
	while (!(ctrl_inw(SCIF_SCFSR2) & 0x20))
		cpu_relax();

	ctrl_outb(c, SCIF_SCFTDR2);
	ctrl_outw((ctrl_inw(SCIF_SCFSR2) & 0x9f), SCIF_SCFSR2);

	if (c == '\n')
		sh_console_putc('\r');
}

static void sh_console_flush(void)
{
	ctrl_outw((ctrl_inw(SCIF_SCFSR2) & 0xbf), SCIF_SCFSR2);

	while (!(ctrl_inw(SCIF_SCFSR2) & 0x40))
		cpu_relax();

	ctrl_outw((ctrl_inw(SCIF_SCFSR2) & 0xbf), SCIF_SCFSR2);
}

static void sh_console_write(struct console *con, const char *s, unsigned count)
{
	while (count-- > 0)
		sh_console_putc(*s++);

	sh_console_flush();
}

static int __init sh_console_setup(struct console *con, char *options)
{
	con->cflag = CREAD | HUPCL | CLOCAL | B19200 | CS8;

	return 0;
}

static struct console sh_console = {
	.name		= "scifcon",
	.write		= sh_console_write,
	.setup		= sh_console_setup,
	.flags		= CON_PRINTBUFFER,
	.index		= -1,
};

void __init enable_early_printk(void)
{
	ctrl_outb(0x2a, SCIF_SCBRR2);	/* 19200bps */

	ctrl_outw(0x04, SCIF_SCFCR2);	/* Reset TFRST */
	ctrl_outw(0x10, SCIF_SCFCR2);	/* TTRG0=1 */

	ctrl_outw(0, SCIF_SCSPTR2);
	ctrl_outw(0x60, SCIF_SCFSR2);
	ctrl_outw(0, SCIF_SCLSR2);
	ctrl_outw(0x30, SCIF_SCSCR2);

	register_console(&sh_console);
}

void disable_early_printk(void)
{
	unregister_console(&sh_console);
}

OpenPOWER on IntegriCloud