summaryrefslogtreecommitdiffstats
path: root/drivers/serial/serial_omap4_usbboot.c
blob: d0d01d585f9f0e3bf974fbe5981ab33a4600dc18 (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
// SPDX-License-Identifier: GPL-2.0-or-later

#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);