VServer 1.9.2 (patch-2.6.8.1-vs1.9.2.diff)
[linux-2.6.git] / drivers / serial / 8250_acorn.c
1 /*
2  *  linux/drivers/serial/acorn.c
3  *
4  *  Copyright (C) 1996-2003 Russell King.
5  *
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>
20
21 #include <asm/io.h>
22 #include <asm/ecard.h>
23 #include <asm/string.h>
24
25 #define MAX_PORTS       3
26
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];
32 };
33
34 struct serial_card_info {
35         unsigned int    num_ports;
36         int             ports[MAX_PORTS];
37 };
38
39 static inline int
40 serial_register_onedev(unsigned long baddr, void *vaddr, int irq, unsigned int baud_base)
41 {
42         struct serial_struct req;
43
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;
52
53         return register_serial(&req);
54 }
55
56 static int __devinit
57 serial_card_probe(struct expansion_card *ec, const struct ecard_id *id)
58 {
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;
64
65         info = kmalloc(sizeof(struct serial_card_info), GFP_KERNEL);
66         if (!info)
67                 return -ENOMEM;
68
69         memset(info, 0, sizeof(struct serial_card_info));
70         info->num_ports = type->num_ports;
71
72         ecard_set_drvdata(ec, info);
73
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;
79         }
80
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];
84
85                 info->ports[port] = serial_register_onedev(baddr, vaddr,
86                                                 ec->irq, type->baud_base);
87         }
88
89         return 0;
90 }
91
92 static void __devexit serial_card_remove(struct expansion_card *ec)
93 {
94         struct serial_card_info *info = ecard_get_drvdata(ec);
95         int i;
96
97         ecard_set_drvdata(ec, NULL);
98
99         for (i = 0; i < info->num_ports; i++)
100                 if (info->ports[i] > 0)
101                         unregister_serial(info->ports[i]);
102
103         kfree(info);
104 }
105
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 },
111 };
112
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 },
118 };
119
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 }
124 };
125
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",
132         },
133 };
134
135 static int __init serial_card_init(void)
136 {
137         return ecard_register_driver(&serial_card_driver);
138 }
139
140 static void __exit serial_card_exit(void)
141 {
142         ecard_remove_driver(&serial_card_driver);
143 }
144
145 MODULE_AUTHOR("Russell King");
146 MODULE_DESCRIPTION("Acorn 8250-compatible serial port expansion card driver");
147 MODULE_LICENSE("GPL");
148
149 module_init(serial_card_init);
150 module_exit(serial_card_exit);