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/init.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/serial_core.h>
|
|
|
|
#include <linux/serial_8250.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>
|
2007-02-14 04:35:38 +08:00
|
|
|
|
|
|
|
#include <asm/prom.h>
|
|
|
|
|
2007-05-31 17:33:04 +08:00
|
|
|
struct of_serial_info {
|
|
|
|
int type;
|
|
|
|
int line;
|
|
|
|
};
|
|
|
|
|
2007-02-14 04:35:38 +08:00
|
|
|
/*
|
|
|
|
* Fill a struct uart_port for a given device node
|
|
|
|
*/
|
|
|
|
static int __devinit of_platform_serial_setup(struct of_device *ofdev,
|
|
|
|
int type, struct uart_port *port)
|
|
|
|
{
|
|
|
|
struct resource resource;
|
|
|
|
struct device_node *np = ofdev->node;
|
|
|
|
const unsigned int *clk, *spd;
|
2008-04-03 07:22:19 +08:00
|
|
|
const u32 *prop;
|
|
|
|
int ret, prop_size;
|
2007-02-14 04:35:38 +08:00
|
|
|
|
|
|
|
memset(port, 0, sizeof *port);
|
2007-05-01 11:54:02 +08:00
|
|
|
spd = of_get_property(np, "current-speed", NULL);
|
|
|
|
clk = of_get_property(np, "clock-frequency", NULL);
|
2007-02-14 04:35:38 +08:00
|
|
|
if (!clk) {
|
|
|
|
dev_warn(&ofdev->dev, "no clock-frequency property set\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = of_address_to_resource(np, 0, &resource);
|
|
|
|
if (ret) {
|
|
|
|
dev_warn(&ofdev->dev, "invalid address\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_lock_init(&port->lock);
|
|
|
|
port->mapbase = resource.start;
|
2008-04-03 07:22:19 +08:00
|
|
|
|
|
|
|
/* Check for shifted address mapping */
|
|
|
|
prop = of_get_property(np, "reg-offset", &prop_size);
|
|
|
|
if (prop && (prop_size == sizeof(u32)))
|
|
|
|
port->mapbase += *prop;
|
|
|
|
|
|
|
|
/* Check for registers offset within the devices address range */
|
|
|
|
prop = of_get_property(np, "reg-shift", &prop_size);
|
|
|
|
if (prop && (prop_size == sizeof(u32)))
|
|
|
|
port->regshift = *prop;
|
|
|
|
|
2007-02-14 04:35:38 +08:00
|
|
|
port->irq = irq_of_parse_and_map(np, 0);
|
|
|
|
port->iotype = UPIO_MEM;
|
|
|
|
port->type = type;
|
|
|
|
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;
|
2007-02-14 04:35:38 +08:00
|
|
|
port->dev = &ofdev->dev;
|
2008-04-03 00:52:13 +08:00
|
|
|
/* If current-speed was set, then try not to change it. */
|
|
|
|
if (spd)
|
|
|
|
port->custom_divisor = *clk / (16 * (*spd));
|
2007-02-14 04:35:38 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Try to register a serial port
|
|
|
|
*/
|
|
|
|
static int __devinit of_platform_serial_probe(struct of_device *ofdev,
|
|
|
|
const struct of_device_id *id)
|
|
|
|
{
|
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;
|
|
|
|
|
|
|
|
if (of_find_property(ofdev->node, "used-by-rtas", NULL))
|
|
|
|
return -EBUSY;
|
|
|
|
|
2007-05-31 17:33:04 +08:00
|
|
|
info = kmalloc(sizeof(*info), GFP_KERNEL);
|
|
|
|
if (info == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2007-02-14 04:35:38 +08:00
|
|
|
port_type = (unsigned long)id->data;
|
|
|
|
ret = of_platform_serial_setup(ofdev, port_type, &port);
|
|
|
|
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:
|
|
|
|
ret = serial8250_register_port(&port);
|
|
|
|
break;
|
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;
|
2009-05-05 03:40:54 +08:00
|
|
|
dev_set_drvdata(&ofdev->dev, 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
|
|
|
|
*/
|
|
|
|
static int of_platform_serial_remove(struct of_device *ofdev)
|
|
|
|
{
|
2009-05-05 03:40:54 +08:00
|
|
|
struct of_serial_info *info = dev_get_drvdata(&ofdev->dev);
|
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;
|
|
|
|
}
|
|
|
|
kfree(info);
|
2007-02-14 04:35:38 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A few common types, add more as needed.
|
|
|
|
*/
|
|
|
|
static struct of_device_id __devinitdata of_platform_serial_table[] = {
|
|
|
|
{ .type = "serial", .compatible = "ns8250", .data = (void *)PORT_8250, },
|
|
|
|
{ .type = "serial", .compatible = "ns16450", .data = (void *)PORT_16450, },
|
2009-11-24 18:22:41 +08:00
|
|
|
{ .type = "serial", .compatible = "ns16550a", .data = (void *)PORT_16550A, },
|
2007-02-14 04:35:38 +08:00
|
|
|
{ .type = "serial", .compatible = "ns16550", .data = (void *)PORT_16550, },
|
|
|
|
{ .type = "serial", .compatible = "ns16750", .data = (void *)PORT_16750, },
|
2009-01-15 17:43:35 +08:00
|
|
|
{ .type = "serial", .compatible = "ns16850", .data = (void *)PORT_16850, },
|
2009-01-07 17:32:38 +08:00
|
|
|
#ifdef CONFIG_SERIAL_OF_PLATFORM_NWPSERIAL
|
|
|
|
{ .type = "serial", .compatible = "ibm,qpace-nwp-serial",
|
|
|
|
.data = (void *)PORT_NWPSERIAL, },
|
|
|
|
#endif
|
2007-02-14 04:35:38 +08:00
|
|
|
{ .type = "serial", .data = (void *)PORT_UNKNOWN, },
|
|
|
|
{ /* end of list */ },
|
|
|
|
};
|
|
|
|
|
2008-03-11 02:43:35 +08:00
|
|
|
static struct of_platform_driver of_platform_serial_driver = {
|
2007-02-14 04:35:38 +08:00
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.name = "of_serial",
|
|
|
|
.probe = of_platform_serial_probe,
|
|
|
|
.remove = of_platform_serial_remove,
|
|
|
|
.match_table = of_platform_serial_table,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init of_platform_serial_init(void)
|
|
|
|
{
|
|
|
|
return of_register_platform_driver(&of_platform_serial_driver);
|
|
|
|
}
|
|
|
|
module_init(of_platform_serial_init);
|
|
|
|
|
|
|
|
static void __exit of_platform_serial_exit(void)
|
|
|
|
{
|
|
|
|
return of_unregister_platform_driver(&of_platform_serial_driver);
|
|
|
|
};
|
|
|
|
module_exit(of_platform_serial_exit);
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Arnd Bergmann <arnd@arndb.de>");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_DESCRIPTION("Serial Port driver for Open Firmware platform devices");
|