summaryrefslogtreecommitdiffstats
path: root/drivers/serial/serial_omap4_usbboot.c
blob: 2ef026c24d1c42735633dd35b25f31b07effbec9 (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
/*
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

#include <common.h>
#include <init.h>
#include <malloc.h>
#include <errno.h>
#include <mach/omap4_rom_usb.h>

struct serial_omap4_usbboot_priv {
	struct console_device cdev;
	u32 val;
};

static void serial_omap4_usbboot_putc(struct console_device *cdev, char c)
{
	unsigned b = c;
	omap4_usbboot_write(&b, 4);
}

static int serial_omap4_usbboot_tstc(struct console_device *cdev)
{
	struct serial_omap4_usbboot_priv *priv =
		container_of(cdev, struct serial_omap4_usbboot_priv, cdev);
	if (omap4_usbboot_is_read_waiting())
		return 0;
	else if (omap4_usbboot_is_read_ok())
		return 1;
	omap4_usbboot_queue_read(&priv->val, 4);
	udelay(100);
	if (omap4_usbboot_is_read_waiting())
		return 0;
	else if (omap4_usbboot_is_read_ok())
		return 1;
	return 0;
}

static int serial_omap4_usbboot_getc(struct console_device *cdev)
{
	struct serial_omap4_usbboot_priv *priv =
		container_of(cdev, struct serial_omap4_usbboot_priv, cdev);
	if (omap4_usbboot_is_read_waiting() || omap4_usbboot_is_read_ok()) {
		omap4_usbboot_wait_read();
		return priv->val;
	}
	omap4_usbboot_read(&priv->val, 4);
	return priv->val;
}

static int serial_omap4_usbboot_probe(struct device_d *dev)
{
	struct serial_omap4_usbboot_priv *priv;
	priv = xzalloc(sizeof(*priv));

	priv->cdev.dev = dev;
	priv->cdev.tstc = serial_omap4_usbboot_tstc;
	priv->cdev.putc = serial_omap4_usbboot_putc;
	priv->cdev.getc = serial_omap4_usbboot_getc;
	priv->cdev.setbrg = NULL;

	return console_register(&priv->cdev);
}

static struct driver_d serial_omap4_usbboot_driver = {
	.name = "serial_omap4_usbboot",
	.probe = serial_omap4_usbboot_probe,
};
console_platform_driver(serial_omap4_usbboot_driver);