summaryrefslogtreecommitdiffstats
path: root/drivers/serial/linux_console.c
blob: df826284ccf5fec8a1191115066d128f0e9f8a66 (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
#include <common.h>
#include <driver.h>
#include <init.h>
#include <asm/arch/linux.h>
#include <malloc.h>
#include <console.h>
#include <xfuncs.h>

static void linux_console_putc(struct console_device *cdev, char c)
{
	struct device_d *dev = cdev->dev;
	struct linux_console_data *d = dev->platform_data;

	linux_write(d->stdoutfd, &c, 1);
}

static int linux_console_tstc(struct console_device *cdev)
{
	struct device_d *dev = cdev->dev;
	struct linux_console_data *d = dev->platform_data;

	return linux_tstc(d->stdinfd);
}

static int linux_console_getc(struct console_device *cdev)
{
	struct device_d *dev = cdev->dev;
	struct linux_console_data *d = dev->platform_data;
	char c;

	linux_read(d->stdinfd, &c, 1);

	return c;
}

static int linux_console_probe(struct device_d *dev)
{
	struct console_device *cdev;
	struct linux_console_data *data = dev->platform_data;

	cdev = xzalloc(sizeof(struct console_device));
	dev->type_data = cdev;
	cdev->dev = dev;
	cdev->f_caps = data->flags;
	cdev->tstc = linux_console_tstc;
	cdev->putc = linux_console_putc;
	cdev->getc = linux_console_getc;

	console_register(cdev);

	return 0;
}

static struct driver_d linux_console_driver = {
        .name  = "console",
        .probe = linux_console_probe,
        .type  = DEVICE_TYPE_CONSOLE,
};

static int console_init(void)
{
	return register_driver(&linux_console_driver);
}

console_initcall(console_init);