2007-02-13 23:35:38 +03: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>
|
|
|
|
|
|
|
|
#include <asm/of_platform.h>
|
|
|
|
#include <asm/prom.h>
|
|
|
|
|
2007-05-31 13:33:04 +04:00
|
|
|
struct of_serial_info {
|
|
|
|
int type;
|
|
|
|
int line;
|
|
|
|
};
|
|
|
|
|
2007-02-13 23:35:38 +03: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 03:22:19 +04:00
|
|
|
const u32 *prop;
|
|
|
|
int ret, prop_size;
|
2007-02-13 23:35:38 +03:00
|
|
|
|
|
|
|
memset(port, 0, sizeof *port);
|
2007-05-01 07:54:02 +04:00
|
|
|
spd = of_get_property(np, "current-speed", NULL);
|
|
|
|
clk = of_get_property(np, "clock-frequency", NULL);
|
2007-02-13 23:35:38 +03: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 03:22:19 +04: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-13 23:35:38 +03: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 01:48:49 +04:00
|
|
|
port->flags = UPF_SHARE_IRQ | UPF_BOOT_AUTOCONF | UPF_IOREMAP
|
|
|
|
| UPF_FIXED_PORT;
|
2007-02-13 23:35:38 +03:00
|
|
|
port->dev = &ofdev->dev;
|
2008-04-02 20:52:13 +04:00
|
|
|
/* If current-speed was set, then try not to change it. */
|
|
|
|
if (spd)
|
|
|
|
port->custom_divisor = *clk / (16 * (*spd));
|
2007-02-13 23:35:38 +03: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 13:33:04 +04:00
|
|
|
struct of_serial_info *info;
|
2007-02-13 23:35:38 +03: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 13:33:04 +04:00
|
|
|
info = kmalloc(sizeof(*info), GFP_KERNEL);
|
|
|
|
if (info == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2007-02-13 23:35:38 +03:00
|
|
|
port_type = (unsigned long)id->data;
|
|
|
|
ret = of_platform_serial_setup(ofdev, port_type, &port);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
switch (port_type) {
|
|
|
|
case PORT_8250 ... PORT_MAX_8250:
|
|
|
|
ret = serial8250_register_port(&port);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* need to add code for these */
|
2007-05-31 13:30:33 +04:00
|
|
|
case PORT_UNKNOWN:
|
|
|
|
dev_info(&ofdev->dev, "Unknown serial port found, ignored\n");
|
2007-02-13 23:35:38 +03:00
|
|
|
ret = -ENODEV;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
|
|
|
|
2007-05-31 13:33:04 +04:00
|
|
|
info->type = port_type;
|
|
|
|
info->line = ret;
|
|
|
|
ofdev->dev.driver_data = info;
|
2007-02-13 23:35:38 +03:00
|
|
|
return 0;
|
|
|
|
out:
|
2007-05-31 13:33:04 +04:00
|
|
|
kfree(info);
|
2007-02-13 23:35:38 +03:00
|
|
|
irq_dispose_mapping(port.irq);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Release a line
|
|
|
|
*/
|
|
|
|
static int of_platform_serial_remove(struct of_device *ofdev)
|
|
|
|
{
|
2007-05-31 13:33:04 +04:00
|
|
|
struct of_serial_info *info = ofdev->dev.driver_data;
|
|
|
|
switch (info->type) {
|
|
|
|
case PORT_8250 ... PORT_MAX_8250:
|
|
|
|
serial8250_unregister_port(info->line);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* need to add code for these */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
kfree(info);
|
2007-02-13 23:35:38 +03: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, },
|
|
|
|
{ .type = "serial", .compatible = "ns16550", .data = (void *)PORT_16550, },
|
|
|
|
{ .type = "serial", .compatible = "ns16750", .data = (void *)PORT_16750, },
|
|
|
|
{ .type = "serial", .data = (void *)PORT_UNKNOWN, },
|
|
|
|
{ /* end of list */ },
|
|
|
|
};
|
|
|
|
|
2008-03-10 21:43:35 +03:00
|
|
|
static struct of_platform_driver of_platform_serial_driver = {
|
2007-02-13 23:35:38 +03: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");
|