1 /*
2 * arch/h8300/kernel/early_printk.c
3 *
4 * Copyright (C) 2009 Yoshinori Sato <ysato@users.sourceforge.jp>
5 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file "COPYING" in the main directory of this archive
8 * for more details.
9 */
10 #include <linux/console.h>
11 #include <linux/tty.h>
12 #include <linux/init.h>
13 #include <linux/io.h>
14 #include <linux/platform_device.h>
15
sim_write(struct console * co,const char * ptr,unsigned len)16 static void sim_write(struct console *co, const char *ptr,
17 unsigned len)
18 {
19 register const int fd __asm__("er0") = 1; /* stdout */
20 register const char *_ptr __asm__("er1") = ptr;
21 register const unsigned _len __asm__("er2") = len;
22
23 __asm__(".byte 0x5e,0x00,0x00,0xc7\n\t" /* jsr @0xc7 (sys_write) */
24 : : "g"(fd), "g"(_ptr), "g"(_len));
25 }
26
27 static struct console sim_console = {
28 .name = "sim_console",
29 .write = sim_write,
30 .setup = NULL,
31 .flags = CON_PRINTBUFFER,
32 .index = -1,
33 };
34
35 static char sim_console_buf[32];
36
sim_probe(struct platform_device * pdev)37 static int sim_probe(struct platform_device *pdev)
38 {
39 if (sim_console.data)
40 return -EEXIST;
41
42 if (!strstr(sim_console_buf, "keep"))
43 sim_console.flags |= CON_BOOT;
44
45 register_console(&sim_console);
46 return 0;
47 }
48
sim_remove(struct platform_device * pdev)49 static int sim_remove(struct platform_device *pdev)
50 {
51 return 0;
52 }
53
54 static struct platform_driver sim_driver = {
55 .probe = sim_probe,
56 .remove = sim_remove,
57 .driver = {
58 .name = "h8300-sim",
59 .owner = THIS_MODULE,
60 },
61 };
62
63 early_platform_init_buffer("earlyprintk", &sim_driver,
64 sim_console_buf, ARRAY_SIZE(sim_console_buf));
65
66 static struct platform_device sim_console_device = {
67 .name = "h8300-sim",
68 .id = 0,
69 };
70
71 static struct platform_device *devices[] __initdata = {
72 &sim_console_device,
73 };
74
sim_console_register(void)75 void __init sim_console_register(void)
76 {
77 early_platform_add_devices(devices,
78 ARRAY_SIZE(devices));
79 }
80