summaryrefslogtreecommitdiff
path: root/drivers/tty/serial/8250/8250_ioc3.c
blob: d5a39e105a76f5bfbd9e3718c91d52ca5a79fbff (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
// SPDX-License-Identifier: GPL-2.0
/*
 * SGI IOC3 8250 UART driver
 *
 * Copyright (C) 2019 Thomas Bogendoerfer <tbogendoerfer@suse.de>
 *
 * based on code Copyright (C) 2005 Stanislaw Skowronek <skylark@unaligned.org>
 *               Copyright (C) 2014 Joshua Kinard <kumba@gentoo.org>
 */

#include <linux/module.h>
#include <linux/errno.h>
#include <linux/io.h>
#include <linux/platform_device.h>

#include "8250.h"

#define IOC3_UARTCLK (22000000 / 3)

struct ioc3_8250_data {
	int line;
};

static unsigned int ioc3_serial_in(struct uart_port *p, int offset)
{
	return readb(p->membase + (offset ^ 3));
}

static void ioc3_serial_out(struct uart_port *p, int offset, int value)
{
	writeb(value, p->membase + (offset ^ 3));
}

static int serial8250_ioc3_probe(struct platform_device *pdev)
{
	struct ioc3_8250_data *data;
	struct uart_8250_port up;
	struct resource *r;
	void __iomem *membase;
	int irq, line;

	r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
	if (!r)
		return -ENODEV;

	data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
	if (!data)
		return -ENOMEM;

	membase = devm_ioremap(&pdev->dev, r->start, resource_size(r));
	if (!membase)
		return -ENOMEM;

	irq = platform_get_irq(pdev, 0);
	if (irq < 0)
		irq = 0; /* no interrupt -> use polling */

	/* Register serial ports with 8250.c */
	memset(&up, 0, sizeof(struct uart_8250_port));
	up.port.iotype = UPIO_MEM;
	up.port.uartclk = IOC3_UARTCLK;
	up.port.type = PORT_16550A;
	up.port.irq = irq;
	up.port.flags = (UPF_BOOT_AUTOCONF | UPF_SHARE_IRQ);
	up.port.dev = &pdev->dev;
	up.port.membase = membase;
	up.port.mapbase = r->start;
	up.port.serial_in = ioc3_serial_in;
	up.port.serial_out = ioc3_serial_out;
	line = serial8250_register_8250_port(&up);
	if (line < 0)
		return line;

	platform_set_drvdata(pdev, data);
	return 0;
}

static int serial8250_ioc3_remove(struct platform_device *pdev)
{
	struct ioc3_8250_data *data = platform_get_drvdata(pdev);

	serial8250_unregister_port(data->line);
	return 0;
}

static struct platform_driver serial8250_ioc3_driver = {
	.probe  = serial8250_ioc3_probe,
	.remove = serial8250_ioc3_remove,
	.driver = {
		.name = "ioc3-serial8250",
	}
};

module_platform_driver(serial8250_ioc3_driver);

MODULE_AUTHOR("Thomas Bogendoerfer <tbogendoerfer@suse.de>");
MODULE_DESCRIPTION("SGI IOC3 8250 UART driver");
MODULE_LICENSE("GPL");