0001
0002
0003
0004
0005
0006
0007 #include <linux/module.h>
0008 #include <linux/types.h>
0009 #include <linux/tty.h>
0010 #include <linux/serial_core.h>
0011 #include <linux/errno.h>
0012 #include <linux/ioport.h>
0013 #include <linux/slab.h>
0014 #include <linux/device.h>
0015 #include <linux/init.h>
0016
0017 #include <asm/io.h>
0018 #include <asm/ecard.h>
0019 #include <asm/string.h>
0020
0021 #include "8250.h"
0022
0023 #define MAX_PORTS 3
0024
0025 struct serial_card_type {
0026 unsigned int num_ports;
0027 unsigned int uartclk;
0028 unsigned int type;
0029 unsigned int offset[MAX_PORTS];
0030 };
0031
0032 struct serial_card_info {
0033 unsigned int num_ports;
0034 int ports[MAX_PORTS];
0035 void __iomem *vaddr;
0036 };
0037
0038 static int
0039 serial_card_probe(struct expansion_card *ec, const struct ecard_id *id)
0040 {
0041 struct serial_card_info *info;
0042 struct serial_card_type *type = id->data;
0043 struct uart_8250_port uart;
0044 unsigned long bus_addr;
0045 unsigned int i;
0046
0047 info = kzalloc(sizeof(struct serial_card_info), GFP_KERNEL);
0048 if (!info)
0049 return -ENOMEM;
0050
0051 info->num_ports = type->num_ports;
0052
0053 bus_addr = ecard_resource_start(ec, type->type);
0054 info->vaddr = ecardm_iomap(ec, type->type, 0, 0);
0055 if (!info->vaddr) {
0056 kfree(info);
0057 return -ENOMEM;
0058 }
0059
0060 ecard_set_drvdata(ec, info);
0061
0062 memset(&uart, 0, sizeof(struct uart_8250_port));
0063 uart.port.irq = ec->irq;
0064 uart.port.flags = UPF_BOOT_AUTOCONF | UPF_SHARE_IRQ;
0065 uart.port.uartclk = type->uartclk;
0066 uart.port.iotype = UPIO_MEM;
0067 uart.port.regshift = 2;
0068 uart.port.dev = &ec->dev;
0069
0070 for (i = 0; i < info->num_ports; i++) {
0071 uart.port.membase = info->vaddr + type->offset[i];
0072 uart.port.mapbase = bus_addr + type->offset[i];
0073
0074 info->ports[i] = serial8250_register_8250_port(&uart);
0075 }
0076
0077 return 0;
0078 }
0079
0080 static void serial_card_remove(struct expansion_card *ec)
0081 {
0082 struct serial_card_info *info = ecard_get_drvdata(ec);
0083 int i;
0084
0085 ecard_set_drvdata(ec, NULL);
0086
0087 for (i = 0; i < info->num_ports; i++)
0088 if (info->ports[i] > 0)
0089 serial8250_unregister_port(info->ports[i]);
0090
0091 kfree(info);
0092 }
0093
0094 static struct serial_card_type atomwide_type = {
0095 .num_ports = 3,
0096 .uartclk = 7372800,
0097 .type = ECARD_RES_IOCSLOW,
0098 .offset = { 0x2800, 0x2400, 0x2000 },
0099 };
0100
0101 static struct serial_card_type serport_type = {
0102 .num_ports = 2,
0103 .uartclk = 3686400,
0104 .type = ECARD_RES_IOCSLOW,
0105 .offset = { 0x2000, 0x2020 },
0106 };
0107
0108 static const struct ecard_id serial_cids[] = {
0109 { MANU_ATOMWIDE, PROD_ATOMWIDE_3PSERIAL, &atomwide_type },
0110 { MANU_SERPORT, PROD_SERPORT_DSPORT, &serport_type },
0111 { 0xffff, 0xffff }
0112 };
0113
0114 static struct ecard_driver serial_card_driver = {
0115 .probe = serial_card_probe,
0116 .remove = serial_card_remove,
0117 .id_table = serial_cids,
0118 .drv = {
0119 .name = "8250_acorn",
0120 },
0121 };
0122
0123 static int __init serial_card_init(void)
0124 {
0125 return ecard_register_driver(&serial_card_driver);
0126 }
0127
0128 static void __exit serial_card_exit(void)
0129 {
0130 ecard_remove_driver(&serial_card_driver);
0131 }
0132
0133 MODULE_AUTHOR("Russell King");
0134 MODULE_DESCRIPTION("Acorn 8250-compatible serial port expansion card driver");
0135 MODULE_LICENSE("GPL");
0136
0137 module_init(serial_card_init);
0138 module_exit(serial_card_exit);