2007-02-14 04:35:38 +08:00
|
|
|
/*
|
|
|
|
* Serial Port driver for Open Firmware platform devices
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 Arnd Bergmann <arnd@arndb.de>, IBM Corp.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include <linux/module.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2012-04-11 05:10:53 +08:00
|
|
|
#include <linux/delay.h>
|
2007-02-14 04:35:38 +08:00
|
|
|
#include <linux/serial_core.h>
|
2012-04-11 05:10:53 +08:00
|
|
|
#include <linux/serial_reg.h>
|
2010-08-17 13:44:49 +08:00
|
|
|
#include <linux/of_address.h>
|
2010-11-18 07:50:23 +08:00
|
|
|
#include <linux/of_irq.h>
|
2008-05-23 14:32:54 +08:00
|
|
|
#include <linux/of_platform.h>
|
2009-01-07 17:32:38 +08:00
|
|
|
#include <linux/nwpserial.h>
|
2012-10-22 23:58:01 +08:00
|
|
|
#include <linux/clk.h>
|
2007-02-14 04:35:38 +08:00
|
|
|
|
2013-03-25 21:51:15 +08:00
|
|
|
#include "8250/8250.h"
|
|
|
|
|
2007-05-31 17:33:04 +08:00
|
|
|
struct of_serial_info {
|
2012-10-22 23:58:01 +08:00
|
|
|
struct clk *clk;
|
2007-05-31 17:33:04 +08:00
|
|
|
int type;
|
|
|
|
int line;
|
|
|
|
};
|
|
|
|
|
2012-04-11 05:10:53 +08:00
|
|
|
#ifdef CONFIG_ARCH_TEGRA
|
|
|
|
void tegra_serial_handle_break(struct uart_port *p)
|
|
|
|
{
|
|
|
|
unsigned int status, tmout = 10000;
|
|
|
|
|
|
|
|
do {
|
|
|
|
status = p->serial_in(p, UART_LSR);
|
|
|
|
if (status & (UART_LSR_FIFOE | UART_LSR_BRK_ERROR_BITS))
|
|
|
|
status = p->serial_in(p, UART_RX);
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
if (--tmout == 0)
|
|
|
|
break;
|
|
|
|
udelay(1);
|
|
|
|
} while (1);
|
|
|
|
}
|
2013-02-01 03:01:53 +08:00
|
|
|
#else
|
|
|
|
static inline void tegra_serial_handle_break(struct uart_port *port)
|
|
|
|
{
|
|
|
|
}
|
2012-04-11 05:10:53 +08:00
|
|
|
#endif
|
|
|
|
|
2007-02-14 04:35:38 +08:00
|
|
|
/*
|
|
|
|
* Fill a struct uart_port for a given device node
|
|
|
|
*/
|
2012-11-20 02:21:50 +08:00
|
|
|
static int of_platform_serial_setup(struct platform_device *ofdev,
|
2012-10-22 23:58:01 +08:00
|
|
|
int type, struct uart_port *port,
|
|
|
|
struct of_serial_info *info)
|
2007-02-14 04:35:38 +08:00
|
|
|
{
|
|
|
|
struct resource resource;
|
2010-04-14 07:12:29 +08:00
|
|
|
struct device_node *np = ofdev->dev.of_node;
|
2011-07-01 02:39:12 +08:00
|
|
|
u32 clk, spd, prop;
|
|
|
|
int ret;
|
2007-02-14 04:35:38 +08:00
|
|
|
|
|
|
|
memset(port, 0, sizeof *port);
|
2011-07-01 02:39:12 +08:00
|
|
|
if (of_property_read_u32(np, "clock-frequency", &clk)) {
|
2012-10-22 23:58:01 +08:00
|
|
|
|
|
|
|
/* Get clk rate through clk driver if present */
|
|
|
|
info->clk = clk_get(&ofdev->dev, NULL);
|
2012-11-01 13:27:34 +08:00
|
|
|
if (IS_ERR(info->clk)) {
|
2012-10-22 23:58:01 +08:00
|
|
|
dev_warn(&ofdev->dev,
|
|
|
|
"clk or clock-frequency not defined\n");
|
2012-11-01 13:27:34 +08:00
|
|
|
return PTR_ERR(info->clk);
|
2012-10-22 23:58:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
clk_prepare_enable(info->clk);
|
|
|
|
clk = clk_get_rate(info->clk);
|
2007-02-14 04:35:38 +08:00
|
|
|
}
|
2011-07-01 02:39:12 +08:00
|
|
|
/* If current-speed was set, then try not to change it. */
|
|
|
|
if (of_property_read_u32(np, "current-speed", &spd) == 0)
|
|
|
|
port->custom_divisor = clk / (16 * spd);
|
2007-02-14 04:35:38 +08:00
|
|
|
|
|
|
|
ret = of_address_to_resource(np, 0, &resource);
|
|
|
|
if (ret) {
|
|
|
|
dev_warn(&ofdev->dev, "invalid address\n");
|
2012-10-22 23:58:01 +08:00
|
|
|
goto out;
|
2007-02-14 04:35:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
spin_lock_init(&port->lock);
|
|
|
|
port->mapbase = resource.start;
|
2008-04-03 07:22:19 +08:00
|
|
|
|
|
|
|
/* Check for shifted address mapping */
|
2011-07-01 02:39:12 +08:00
|
|
|
if (of_property_read_u32(np, "reg-offset", &prop) == 0)
|
|
|
|
port->mapbase += prop;
|
2008-04-03 07:22:19 +08:00
|
|
|
|
|
|
|
/* Check for registers offset within the devices address range */
|
2011-07-01 02:39:12 +08:00
|
|
|
if (of_property_read_u32(np, "reg-shift", &prop) == 0)
|
|
|
|
port->regshift = prop;
|
2008-04-03 07:22:19 +08:00
|
|
|
|
2013-03-25 19:34:45 +08:00
|
|
|
/* Check for fifo size */
|
|
|
|
if (of_property_read_u32(np, "fifo-size", &prop) == 0)
|
|
|
|
port->fifosize = prop;
|
|
|
|
|
2007-02-14 04:35:38 +08:00
|
|
|
port->irq = irq_of_parse_and_map(np, 0);
|
|
|
|
port->iotype = UPIO_MEM;
|
2011-07-01 02:39:12 +08:00
|
|
|
if (of_property_read_u32(np, "reg-io-width", &prop) == 0) {
|
|
|
|
switch (prop) {
|
2011-06-27 20:32:34 +08:00
|
|
|
case 1:
|
|
|
|
port->iotype = UPIO_MEM;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
port->iotype = UPIO_MEM32;
|
|
|
|
break;
|
|
|
|
default:
|
2011-07-01 02:39:12 +08:00
|
|
|
dev_warn(&ofdev->dev, "unsupported reg-io-width (%d)\n",
|
|
|
|
prop);
|
2012-10-22 23:58:01 +08:00
|
|
|
ret = -EINVAL;
|
|
|
|
goto out;
|
2011-06-27 20:32:34 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-02-14 04:35:38 +08:00
|
|
|
port->type = type;
|
2011-07-01 02:39:12 +08:00
|
|
|
port->uartclk = clk;
|
serial: define FIXED_PORT flag for serial_core
At present, the serial core always allows setserial in userspace to change the
port address, irq and base clock of any serial port. That makes sense for
legacy ISA ports, but not for (say) embedded ns16550 compatible serial ports
at peculiar addresses. In these cases, the kernel code configuring the ports
must know exactly where they are, and their clocking arrangements (which can
be unusual on embedded boards). It doesn't make sense for userspace to change
these settings.
Therefore, this patch defines a UPF_FIXED_PORT flag for the uart_port
structure. If this flag is set when the serial port is configured, any
attempts to alter the port's type, io address, irq or base clock with
setserial are ignored.
In addition this patch uses the new flag for on-chip serial ports probed in
arch/powerpc/kernel/legacy_serial.c, and for other hard-wired serial ports
probed by drivers/serial/of_serial.c.
Signed-off-by: David Gibson <dwg@au1.ibm.com>
Cc: Russell King <rmk@arm.linux.org.uk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-05-07 05:48:49 +08:00
|
|
|
port->flags = UPF_SHARE_IRQ | UPF_BOOT_AUTOCONF | UPF_IOREMAP
|
2009-06-09 21:39:47 +08:00
|
|
|
| UPF_FIXED_PORT | UPF_FIXED_TYPE;
|
2012-07-18 00:08:31 +08:00
|
|
|
|
|
|
|
if (of_find_property(np, "no-loopback-test", NULL))
|
|
|
|
port->flags |= UPF_SKIP_TEST;
|
|
|
|
|
2007-02-14 04:35:38 +08:00
|
|
|
port->dev = &ofdev->dev;
|
|
|
|
|
2012-04-11 05:10:53 +08:00
|
|
|
if (type == PORT_TEGRA)
|
|
|
|
port->handle_break = tegra_serial_handle_break;
|
|
|
|
|
2007-02-14 04:35:38 +08:00
|
|
|
return 0;
|
2012-10-22 23:58:01 +08:00
|
|
|
out:
|
|
|
|
if (info->clk)
|
|
|
|
clk_disable_unprepare(info->clk);
|
|
|
|
return ret;
|
2007-02-14 04:35:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Try to register a serial port
|
|
|
|
*/
|
2011-05-19 01:19:24 +08:00
|
|
|
static struct of_device_id of_platform_serial_table[];
|
2012-11-20 02:21:50 +08:00
|
|
|
static int of_platform_serial_probe(struct platform_device *ofdev)
|
2007-02-14 04:35:38 +08:00
|
|
|
{
|
2011-05-19 01:19:24 +08:00
|
|
|
const struct of_device_id *match;
|
2007-05-31 17:33:04 +08:00
|
|
|
struct of_serial_info *info;
|
2007-02-14 04:35:38 +08:00
|
|
|
struct uart_port port;
|
|
|
|
int port_type;
|
|
|
|
int ret;
|
|
|
|
|
2011-05-19 01:19:24 +08:00
|
|
|
match = of_match_device(of_platform_serial_table, &ofdev->dev);
|
|
|
|
if (!match)
|
2011-02-23 12:10:26 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
2010-04-14 07:12:29 +08:00
|
|
|
if (of_find_property(ofdev->dev.of_node, "used-by-rtas", NULL))
|
2007-02-14 04:35:38 +08:00
|
|
|
return -EBUSY;
|
|
|
|
|
2007-05-31 17:33:04 +08:00
|
|
|
info = kmalloc(sizeof(*info), GFP_KERNEL);
|
|
|
|
if (info == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2011-05-19 01:19:24 +08:00
|
|
|
port_type = (unsigned long)match->data;
|
2012-10-22 23:58:01 +08:00
|
|
|
ret = of_platform_serial_setup(ofdev, port_type, &port, info);
|
2007-02-14 04:35:38 +08:00
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
switch (port_type) {
|
2009-01-07 17:32:38 +08:00
|
|
|
#ifdef CONFIG_SERIAL_8250
|
2007-02-14 04:35:38 +08:00
|
|
|
case PORT_8250 ... PORT_MAX_8250:
|
2012-07-18 00:06:20 +08:00
|
|
|
{
|
|
|
|
struct uart_8250_port port8250;
|
|
|
|
memset(&port8250, 0, sizeof(port8250));
|
2014-05-14 06:04:39 +08:00
|
|
|
port.type = port_type;
|
2012-07-18 00:06:20 +08:00
|
|
|
port8250.port = port;
|
2013-03-25 21:51:15 +08:00
|
|
|
|
|
|
|
if (port.fifosize)
|
|
|
|
port8250.capabilities = UART_CAP_FIFO;
|
|
|
|
|
|
|
|
if (of_property_read_bool(ofdev->dev.of_node,
|
|
|
|
"auto-flow-control"))
|
|
|
|
port8250.capabilities |= UART_CAP_AFE;
|
|
|
|
|
2012-07-18 00:06:20 +08:00
|
|
|
ret = serial8250_register_8250_port(&port8250);
|
2007-02-14 04:35:38 +08:00
|
|
|
break;
|
2012-07-18 00:06:20 +08:00
|
|
|
}
|
2009-01-07 17:32:38 +08:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_SERIAL_OF_PLATFORM_NWPSERIAL
|
|
|
|
case PORT_NWPSERIAL:
|
|
|
|
ret = nwpserial_register_port(&port);
|
|
|
|
break;
|
|
|
|
#endif
|
2007-02-14 04:35:38 +08:00
|
|
|
default:
|
|
|
|
/* need to add code for these */
|
2007-05-31 17:30:33 +08:00
|
|
|
case PORT_UNKNOWN:
|
|
|
|
dev_info(&ofdev->dev, "Unknown serial port found, ignored\n");
|
2007-02-14 04:35:38 +08:00
|
|
|
ret = -ENODEV;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
|
|
|
|
2007-05-31 17:33:04 +08:00
|
|
|
info->type = port_type;
|
|
|
|
info->line = ret;
|
2013-05-23 18:39:36 +08:00
|
|
|
platform_set_drvdata(ofdev, info);
|
2007-02-14 04:35:38 +08:00
|
|
|
return 0;
|
|
|
|
out:
|
2007-05-31 17:33:04 +08:00
|
|
|
kfree(info);
|
2007-02-14 04:35:38 +08:00
|
|
|
irq_dispose_mapping(port.irq);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Release a line
|
|
|
|
*/
|
2010-08-06 23:25:50 +08:00
|
|
|
static int of_platform_serial_remove(struct platform_device *ofdev)
|
2007-02-14 04:35:38 +08:00
|
|
|
{
|
2013-05-23 18:39:36 +08:00
|
|
|
struct of_serial_info *info = platform_get_drvdata(ofdev);
|
2007-05-31 17:33:04 +08:00
|
|
|
switch (info->type) {
|
2009-01-07 17:32:38 +08:00
|
|
|
#ifdef CONFIG_SERIAL_8250
|
2007-05-31 17:33:04 +08:00
|
|
|
case PORT_8250 ... PORT_MAX_8250:
|
|
|
|
serial8250_unregister_port(info->line);
|
|
|
|
break;
|
2009-01-07 17:32:38 +08:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_SERIAL_OF_PLATFORM_NWPSERIAL
|
|
|
|
case PORT_NWPSERIAL:
|
|
|
|
nwpserial_unregister_port(info->line);
|
|
|
|
break;
|
|
|
|
#endif
|
2007-05-31 17:33:04 +08:00
|
|
|
default:
|
|
|
|
/* need to add code for these */
|
|
|
|
break;
|
|
|
|
}
|
2012-10-22 23:58:01 +08:00
|
|
|
|
|
|
|
if (info->clk)
|
|
|
|
clk_disable_unprepare(info->clk);
|
2007-05-31 17:33:04 +08:00
|
|
|
kfree(info);
|
2007-02-14 04:35:38 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-09-23 16:34:12 +08:00
|
|
|
#ifdef CONFIG_PM_SLEEP
|
|
|
|
static int of_serial_suspend(struct device *dev)
|
|
|
|
{
|
|
|
|
struct of_serial_info *info = dev_get_drvdata(dev);
|
|
|
|
|
|
|
|
serial8250_suspend_port(info->line);
|
|
|
|
if (info->clk)
|
|
|
|
clk_disable_unprepare(info->clk);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int of_serial_resume(struct device *dev)
|
|
|
|
{
|
|
|
|
struct of_serial_info *info = dev_get_drvdata(dev);
|
|
|
|
|
|
|
|
if (info->clk)
|
|
|
|
clk_prepare_enable(info->clk);
|
|
|
|
|
|
|
|
serial8250_resume_port(info->line);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
static SIMPLE_DEV_PM_OPS(of_serial_pm_ops, of_serial_suspend, of_serial_resume);
|
|
|
|
|
2007-02-14 04:35:38 +08:00
|
|
|
/*
|
|
|
|
* A few common types, add more as needed.
|
|
|
|
*/
|
2012-11-20 02:24:32 +08:00
|
|
|
static struct of_device_id of_platform_serial_table[] = {
|
2011-02-23 10:12:21 +08:00
|
|
|
{ .compatible = "ns8250", .data = (void *)PORT_8250, },
|
|
|
|
{ .compatible = "ns16450", .data = (void *)PORT_16450, },
|
|
|
|
{ .compatible = "ns16550a", .data = (void *)PORT_16550A, },
|
|
|
|
{ .compatible = "ns16550", .data = (void *)PORT_16550, },
|
|
|
|
{ .compatible = "ns16750", .data = (void *)PORT_16750, },
|
|
|
|
{ .compatible = "ns16850", .data = (void *)PORT_16850, },
|
2011-07-06 13:42:36 +08:00
|
|
|
{ .compatible = "nvidia,tegra20-uart", .data = (void *)PORT_TEGRA, },
|
2012-06-12 03:57:14 +08:00
|
|
|
{ .compatible = "nxp,lpc3220-uart", .data = (void *)PORT_LPC3220, },
|
2013-03-07 10:28:37 +08:00
|
|
|
{ .compatible = "altr,16550-FIFO32",
|
|
|
|
.data = (void *)PORT_ALTR_16550_F32, },
|
|
|
|
{ .compatible = "altr,16550-FIFO64",
|
|
|
|
.data = (void *)PORT_ALTR_16550_F64, },
|
|
|
|
{ .compatible = "altr,16550-FIFO128",
|
|
|
|
.data = (void *)PORT_ALTR_16550_F128, },
|
2009-01-07 17:32:38 +08:00
|
|
|
#ifdef CONFIG_SERIAL_OF_PLATFORM_NWPSERIAL
|
2011-02-23 10:12:21 +08:00
|
|
|
{ .compatible = "ibm,qpace-nwp-serial",
|
|
|
|
.data = (void *)PORT_NWPSERIAL, },
|
2009-01-07 17:32:38 +08:00
|
|
|
#endif
|
2011-02-23 10:12:21 +08:00
|
|
|
{ .type = "serial", .data = (void *)PORT_UNKNOWN, },
|
2007-02-14 04:35:38 +08:00
|
|
|
{ /* end of list */ },
|
|
|
|
};
|
|
|
|
|
2011-02-23 12:10:26 +08:00
|
|
|
static struct platform_driver of_platform_serial_driver = {
|
2010-04-14 07:13:02 +08:00
|
|
|
.driver = {
|
|
|
|
.name = "of_serial",
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.of_match_table = of_platform_serial_table,
|
2014-09-23 16:34:12 +08:00
|
|
|
.pm = &of_serial_pm_ops,
|
2010-04-14 07:13:02 +08:00
|
|
|
},
|
2007-02-14 04:35:38 +08:00
|
|
|
.probe = of_platform_serial_probe,
|
|
|
|
.remove = of_platform_serial_remove,
|
|
|
|
};
|
|
|
|
|
2011-10-06 01:29:49 +08:00
|
|
|
module_platform_driver(of_platform_serial_driver);
|
2007-02-14 04:35:38 +08:00
|
|
|
|
|
|
|
MODULE_AUTHOR("Arnd Bergmann <arnd@arndb.de>");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_DESCRIPTION("Serial Port driver for Open Firmware platform devices");
|