2 * Serial Port driver for Open Firmware platform devices
4 * Copyright (C) 2006 Arnd Bergmann <arnd@arndb.de>, IBM Corp.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
12 #include <linux/init.h>
13 #include <linux/module.h>
14 #include <linux/serial_core.h>
15 #include <linux/serial_8250.h>
17 #include <asm/of_platform.h>
20 struct of_serial_info {
26 * Fill a struct uart_port for a given device node
28 static int __devinit of_platform_serial_setup(struct of_device *ofdev,
29 int type, struct uart_port *port)
31 struct resource resource;
32 struct device_node *np = ofdev->node;
33 const unsigned int *clk, *spd;
36 memset(port, 0, sizeof *port);
37 spd = of_get_property(np, "current-speed", NULL);
38 clk = of_get_property(np, "clock-frequency", NULL);
40 dev_warn(&ofdev->dev, "no clock-frequency property set\n");
44 ret = of_address_to_resource(np, 0, &resource);
46 dev_warn(&ofdev->dev, "invalid address\n");
50 spin_lock_init(&port->lock);
51 port->mapbase = resource.start;
52 port->irq = irq_of_parse_and_map(np, 0);
53 port->iotype = UPIO_MEM;
56 port->flags = UPF_SHARE_IRQ | UPF_BOOT_AUTOCONF | UPF_IOREMAP
58 port->dev = &ofdev->dev;
59 port->custom_divisor = *clk / (16 * (*spd));
65 * Try to register a serial port
67 static int __devinit of_platform_serial_probe(struct of_device *ofdev,
68 const struct of_device_id *id)
70 struct of_serial_info *info;
71 struct uart_port port;
75 if (of_find_property(ofdev->node, "used-by-rtas", NULL))
78 info = kmalloc(sizeof(*info), GFP_KERNEL);
82 port_type = (unsigned long)id->data;
83 ret = of_platform_serial_setup(ofdev, port_type, &port);
88 case PORT_8250 ... PORT_MAX_8250:
89 ret = serial8250_register_port(&port);
92 /* need to add code for these */
94 dev_info(&ofdev->dev, "Unknown serial port found, ignored\n");
101 info->type = port_type;
103 ofdev->dev.driver_data = info;
107 irq_dispose_mapping(port.irq);
114 static int of_platform_serial_remove(struct of_device *ofdev)
116 struct of_serial_info *info = ofdev->dev.driver_data;
117 switch (info->type) {
118 case PORT_8250 ... PORT_MAX_8250:
119 serial8250_unregister_port(info->line);
122 /* need to add code for these */
130 * A few common types, add more as needed.
132 static struct of_device_id __devinitdata of_platform_serial_table[] = {
133 { .type = "serial", .compatible = "ns8250", .data = (void *)PORT_8250, },
134 { .type = "serial", .compatible = "ns16450", .data = (void *)PORT_16450, },
135 { .type = "serial", .compatible = "ns16550", .data = (void *)PORT_16550, },
136 { .type = "serial", .compatible = "ns16750", .data = (void *)PORT_16750, },
137 { .type = "serial", .data = (void *)PORT_UNKNOWN, },
138 { /* end of list */ },
141 static struct of_platform_driver __devinitdata of_platform_serial_driver = {
142 .owner = THIS_MODULE,
144 .probe = of_platform_serial_probe,
145 .remove = of_platform_serial_remove,
146 .match_table = of_platform_serial_table,
149 static int __init of_platform_serial_init(void)
151 return of_register_platform_driver(&of_platform_serial_driver);
153 module_init(of_platform_serial_init);
155 static void __exit of_platform_serial_exit(void)
157 return of_unregister_platform_driver(&of_platform_serial_driver);
159 module_exit(of_platform_serial_exit);
161 MODULE_AUTHOR("Arnd Bergmann <arnd@arndb.de>");
162 MODULE_LICENSE("GPL");
163 MODULE_DESCRIPTION("Serial Port driver for Open Firmware platform devices");