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>
21 * Fill a struct uart_port for a given device node
23 static int __devinit
of_platform_serial_setup(struct of_device
*ofdev
,
24 int type
, struct uart_port
*port
)
26 struct resource resource
;
27 struct device_node
*np
= ofdev
->node
;
28 const unsigned int *clk
, *spd
;
31 memset(port
, 0, sizeof *port
);
32 spd
= get_property(np
, "current-speed", NULL
);
33 clk
= get_property(np
, "clock-frequency", NULL
);
35 dev_warn(&ofdev
->dev
, "no clock-frequency property set\n");
39 ret
= of_address_to_resource(np
, 0, &resource
);
41 dev_warn(&ofdev
->dev
, "invalid address\n");
45 spin_lock_init(&port
->lock
);
46 port
->mapbase
= resource
.start
;
47 port
->irq
= irq_of_parse_and_map(np
, 0);
48 port
->iotype
= UPIO_MEM
;
51 port
->flags
= UPF_SHARE_IRQ
| UPF_BOOT_AUTOCONF
| UPF_IOREMAP
;
52 port
->dev
= &ofdev
->dev
;
53 port
->custom_divisor
= *clk
/ (16 * (*spd
));
59 * Try to register a serial port
61 static int __devinit
of_platform_serial_probe(struct of_device
*ofdev
,
62 const struct of_device_id
*id
)
64 struct uart_port port
;
68 if (of_find_property(ofdev
->node
, "used-by-rtas", NULL
))
71 port_type
= (unsigned long)id
->data
;
72 ret
= of_platform_serial_setup(ofdev
, port_type
, &port
);
78 dev_info(&ofdev
->dev
, "Unknown serial port found, "
79 "attempting to use 8250 driver\n");
81 case PORT_8250
... PORT_MAX_8250
:
82 ret
= serial8250_register_port(&port
);
85 /* need to add code for these */
92 ofdev
->dev
.driver_data
= (void *)(unsigned long)ret
;
95 irq_dispose_mapping(port
.irq
);
102 static int of_platform_serial_remove(struct of_device
*ofdev
)
104 int line
= (unsigned long)ofdev
->dev
.driver_data
;
105 serial8250_unregister_port(line
);
110 * A few common types, add more as needed.
112 static struct of_device_id __devinitdata of_platform_serial_table
[] = {
113 { .type
= "serial", .compatible
= "ns8250", .data
= (void *)PORT_8250
, },
114 { .type
= "serial", .compatible
= "ns16450", .data
= (void *)PORT_16450
, },
115 { .type
= "serial", .compatible
= "ns16550", .data
= (void *)PORT_16550
, },
116 { .type
= "serial", .compatible
= "ns16750", .data
= (void *)PORT_16750
, },
117 { .type
= "serial", .data
= (void *)PORT_UNKNOWN
, },
118 { /* end of list */ },
121 static struct of_platform_driver __devinitdata of_platform_serial_driver
= {
122 .owner
= THIS_MODULE
,
124 .probe
= of_platform_serial_probe
,
125 .remove
= of_platform_serial_remove
,
126 .match_table
= of_platform_serial_table
,
129 static int __init
of_platform_serial_init(void)
131 return of_register_platform_driver(&of_platform_serial_driver
);
133 module_init(of_platform_serial_init
);
135 static void __exit
of_platform_serial_exit(void)
137 return of_unregister_platform_driver(&of_platform_serial_driver
);
139 module_exit(of_platform_serial_exit
);
141 MODULE_AUTHOR("Arnd Bergmann <arnd@arndb.de>");
142 MODULE_LICENSE("GPL");
143 MODULE_DESCRIPTION("Serial Port driver for Open Firmware platform devices");