initial commit with v2.6.9
[linux-2.6.9-moxart.git] / drivers / serial / 8250_acorn.c
blob2e69f6c536be0664ed9578976c1d7877d1544fea
1 /*
2 * linux/drivers/serial/acorn.c
4 * Copyright (C) 1996-2003 Russell King.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10 #include <linux/module.h>
11 #include <linux/types.h>
12 #include <linux/tty.h>
13 #include <linux/serial_core.h>
14 #include <linux/serial.h>
15 #include <linux/errno.h>
16 #include <linux/ioport.h>
17 #include <linux/slab.h>
18 #include <linux/device.h>
19 #include <linux/init.h>
21 #include <asm/io.h>
22 #include <asm/ecard.h>
23 #include <asm/string.h>
25 #define MAX_PORTS 3
27 struct serial_card_type {
28 unsigned int num_ports;
29 unsigned int baud_base;
30 unsigned int type;
31 unsigned int offset[MAX_PORTS];
34 struct serial_card_info {
35 unsigned int num_ports;
36 int ports[MAX_PORTS];
39 static inline int
40 serial_register_onedev(unsigned long baddr, void *vaddr, int irq, unsigned int baud_base)
42 struct serial_struct req;
44 memset(&req, 0, sizeof(req));
45 req.irq = irq;
46 req.flags = UPF_AUTOPROBE | UPF_SHARE_IRQ;
47 req.baud_base = baud_base;
48 req.io_type = UPIO_MEM;
49 req.iomem_base = vaddr;
50 req.iomem_reg_shift = 2;
51 req.iomap_base = baddr;
53 return register_serial(&req);
56 static int __devinit
57 serial_card_probe(struct expansion_card *ec, const struct ecard_id *id)
59 struct serial_card_info *info;
60 struct serial_card_type *type = id->data;
61 unsigned long bus_addr;
62 unsigned char *virt_addr;
63 unsigned int port;
65 info = kmalloc(sizeof(struct serial_card_info), GFP_KERNEL);
66 if (!info)
67 return -ENOMEM;
69 memset(info, 0, sizeof(struct serial_card_info));
70 info->num_ports = type->num_ports;
72 ecard_set_drvdata(ec, info);
74 bus_addr = ec->resource[type->type].start;
75 virt_addr = ioremap(bus_addr, ec->resource[type->type].end - bus_addr + 1);
76 if (!virt_addr) {
77 kfree(info);
78 return -ENOMEM;
81 for (port = 0; port < info->num_ports; port ++) {
82 unsigned long baddr = bus_addr + type->offset[port];
83 unsigned char *vaddr = virt_addr + type->offset[port];
85 info->ports[port] = serial_register_onedev(baddr, vaddr,
86 ec->irq, type->baud_base);
89 return 0;
92 static void __devexit serial_card_remove(struct expansion_card *ec)
94 struct serial_card_info *info = ecard_get_drvdata(ec);
95 int i;
97 ecard_set_drvdata(ec, NULL);
99 for (i = 0; i < info->num_ports; i++)
100 if (info->ports[i] > 0)
101 unregister_serial(info->ports[i]);
103 kfree(info);
106 static struct serial_card_type atomwide_type = {
107 .num_ports = 3,
108 .baud_base = 7372800 / 16,
109 .type = ECARD_RES_IOCSLOW,
110 .offset = { 0x2800, 0x2400, 0x2000 },
113 static struct serial_card_type serport_type = {
114 .num_ports = 2,
115 .baud_base = 3686400 / 16,
116 .type = ECARD_RES_IOCSLOW,
117 .offset = { 0x2000, 0x2020 },
120 static const struct ecard_id serial_cids[] = {
121 { MANU_ATOMWIDE, PROD_ATOMWIDE_3PSERIAL, &atomwide_type },
122 { MANU_SERPORT, PROD_SERPORT_DSPORT, &serport_type },
123 { 0xffff, 0xffff }
126 static struct ecard_driver serial_card_driver = {
127 .probe = serial_card_probe,
128 .remove = __devexit_p(serial_card_remove),
129 .id_table = serial_cids,
130 .drv = {
131 .name = "8250_acorn",
135 static int __init serial_card_init(void)
137 return ecard_register_driver(&serial_card_driver);
140 static void __exit serial_card_exit(void)
142 ecard_remove_driver(&serial_card_driver);
145 MODULE_AUTHOR("Russell King");
146 MODULE_DESCRIPTION("Acorn 8250-compatible serial port expansion card driver");
147 MODULE_LICENSE("GPL");
149 module_init(serial_card_init);
150 module_exit(serial_card_exit);