blob: 562ba745a044ae7f30d46ace434d6ba4af72b3d6 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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/errno.h>
15#include <linux/ioport.h>
16#include <linux/slab.h>
17#include <linux/device.h>
18#include <linux/init.h>
19
20#include <asm/io.h>
21#include <asm/ecard.h>
22#include <asm/string.h>
23
24#include "8250.h"
25
26#define MAX_PORTS 3
27
28struct serial_card_type {
29 unsigned int num_ports;
30 unsigned int uartclk;
31 unsigned int type;
32 unsigned int offset[MAX_PORTS];
33};
34
35struct serial_card_info {
36 unsigned int num_ports;
37 int ports[MAX_PORTS];
Amol Ladf12ad7d2006-09-30 23:29:20 -070038 void __iomem *vaddr;
Linus Torvalds1da177e2005-04-16 15:20:36 -070039};
40
41static int __devinit
42serial_card_probe(struct expansion_card *ec, const struct ecard_id *id)
43{
44 struct serial_card_info *info;
45 struct serial_card_type *type = id->data;
46 struct uart_port port;
47 unsigned long bus_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 unsigned int i;
49
Burman Yan8f31bb32007-02-14 00:33:07 -080050 info = kzalloc(sizeof(struct serial_card_info), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 if (!info)
52 return -ENOMEM;
53
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 info->num_ports = type->num_ports;
55
56 bus_addr = ecard_resource_start(ec, type->type);
Amol Ladf12ad7d2006-09-30 23:29:20 -070057 info->vaddr = ioremap(bus_addr, ecard_resource_len(ec, type->type));
58 if (!info->vaddr) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 kfree(info);
60 return -ENOMEM;
61 }
62
63 ecard_set_drvdata(ec, info);
64
65 memset(&port, 0, sizeof(struct uart_port));
66 port.irq = ec->irq;
67 port.flags = UPF_BOOT_AUTOCONF | UPF_SHARE_IRQ;
68 port.uartclk = type->uartclk;
69 port.iotype = UPIO_MEM;
70 port.regshift = 2;
71 port.dev = &ec->dev;
72
73 for (i = 0; i < info->num_ports; i ++) {
Amol Ladf12ad7d2006-09-30 23:29:20 -070074 port.membase = info->vaddr + type->offset[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 port.mapbase = bus_addr + type->offset[i];
76
77 info->ports[i] = serial8250_register_port(&port);
78 }
79
80 return 0;
81}
82
83static void __devexit serial_card_remove(struct expansion_card *ec)
84{
85 struct serial_card_info *info = ecard_get_drvdata(ec);
86 int i;
87
88 ecard_set_drvdata(ec, NULL);
89
90 for (i = 0; i < info->num_ports; i++)
91 if (info->ports[i] > 0)
92 serial8250_unregister_port(info->ports[i]);
93
Amol Ladf12ad7d2006-09-30 23:29:20 -070094 iounmap(info->vaddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 kfree(info);
96}
97
98static struct serial_card_type atomwide_type = {
99 .num_ports = 3,
100 .uartclk = 7372800,
101 .type = ECARD_RES_IOCSLOW,
102 .offset = { 0x2800, 0x2400, 0x2000 },
103};
104
105static struct serial_card_type serport_type = {
106 .num_ports = 2,
107 .uartclk = 3686400,
108 .type = ECARD_RES_IOCSLOW,
109 .offset = { 0x2000, 0x2020 },
110};
111
112static const struct ecard_id serial_cids[] = {
113 { MANU_ATOMWIDE, PROD_ATOMWIDE_3PSERIAL, &atomwide_type },
114 { MANU_SERPORT, PROD_SERPORT_DSPORT, &serport_type },
115 { 0xffff, 0xffff }
116};
117
118static struct ecard_driver serial_card_driver = {
119 .probe = serial_card_probe,
120 .remove = __devexit_p(serial_card_remove),
121 .id_table = serial_cids,
122 .drv = {
123 .name = "8250_acorn",
124 },
125};
126
127static int __init serial_card_init(void)
128{
129 return ecard_register_driver(&serial_card_driver);
130}
131
132static void __exit serial_card_exit(void)
133{
134 ecard_remove_driver(&serial_card_driver);
135}
136
137MODULE_AUTHOR("Russell King");
138MODULE_DESCRIPTION("Acorn 8250-compatible serial port expansion card driver");
139MODULE_LICENSE("GPL");
140
141module_init(serial_card_init);
142module_exit(serial_card_exit);