19bef3d41SPaul Gortmaker /*
29bef3d41SPaul Gortmaker  *  linux/drivers/serial/acorn.c
39bef3d41SPaul Gortmaker  *
49bef3d41SPaul Gortmaker  *  Copyright (C) 1996-2003 Russell King.
59bef3d41SPaul Gortmaker  *
69bef3d41SPaul Gortmaker  * This program is free software; you can redistribute it and/or modify
79bef3d41SPaul Gortmaker  * it under the terms of the GNU General Public License version 2 as
89bef3d41SPaul Gortmaker  * published by the Free Software Foundation.
99bef3d41SPaul Gortmaker  */
109bef3d41SPaul Gortmaker #include <linux/module.h>
119bef3d41SPaul Gortmaker #include <linux/types.h>
129bef3d41SPaul Gortmaker #include <linux/tty.h>
139bef3d41SPaul Gortmaker #include <linux/serial_core.h>
149bef3d41SPaul Gortmaker #include <linux/errno.h>
159bef3d41SPaul Gortmaker #include <linux/ioport.h>
169bef3d41SPaul Gortmaker #include <linux/slab.h>
179bef3d41SPaul Gortmaker #include <linux/device.h>
189bef3d41SPaul Gortmaker #include <linux/init.h>
199bef3d41SPaul Gortmaker 
209bef3d41SPaul Gortmaker #include <asm/io.h>
219bef3d41SPaul Gortmaker #include <asm/ecard.h>
229bef3d41SPaul Gortmaker #include <asm/string.h>
239bef3d41SPaul Gortmaker 
249bef3d41SPaul Gortmaker #include "8250.h"
259bef3d41SPaul Gortmaker 
269bef3d41SPaul Gortmaker #define MAX_PORTS	3
279bef3d41SPaul Gortmaker 
289bef3d41SPaul Gortmaker struct serial_card_type {
299bef3d41SPaul Gortmaker 	unsigned int	num_ports;
309bef3d41SPaul Gortmaker 	unsigned int	uartclk;
319bef3d41SPaul Gortmaker 	unsigned int	type;
329bef3d41SPaul Gortmaker 	unsigned int	offset[MAX_PORTS];
339bef3d41SPaul Gortmaker };
349bef3d41SPaul Gortmaker 
359bef3d41SPaul Gortmaker struct serial_card_info {
369bef3d41SPaul Gortmaker 	unsigned int	num_ports;
379bef3d41SPaul Gortmaker 	int		ports[MAX_PORTS];
389bef3d41SPaul Gortmaker 	void __iomem *vaddr;
399bef3d41SPaul Gortmaker };
409bef3d41SPaul Gortmaker 
419671f099SBill Pemberton static int
429bef3d41SPaul Gortmaker serial_card_probe(struct expansion_card *ec, const struct ecard_id *id)
439bef3d41SPaul Gortmaker {
449bef3d41SPaul Gortmaker 	struct serial_card_info *info;
459bef3d41SPaul Gortmaker 	struct serial_card_type *type = id->data;
462655a2c7SAlan Cox 	struct uart_8250_port uart;
479bef3d41SPaul Gortmaker 	unsigned long bus_addr;
489bef3d41SPaul Gortmaker 	unsigned int i;
499bef3d41SPaul Gortmaker 
509bef3d41SPaul Gortmaker 	info = kzalloc(sizeof(struct serial_card_info), GFP_KERNEL);
519bef3d41SPaul Gortmaker 	if (!info)
529bef3d41SPaul Gortmaker 		return -ENOMEM;
539bef3d41SPaul Gortmaker 
549bef3d41SPaul Gortmaker 	info->num_ports = type->num_ports;
559bef3d41SPaul Gortmaker 
569bef3d41SPaul Gortmaker 	bus_addr = ecard_resource_start(ec, type->type);
579bef3d41SPaul Gortmaker 	info->vaddr = ecardm_iomap(ec, type->type, 0, 0);
589bef3d41SPaul Gortmaker 	if (!info->vaddr) {
599bef3d41SPaul Gortmaker 		kfree(info);
609bef3d41SPaul Gortmaker 		return -ENOMEM;
619bef3d41SPaul Gortmaker 	}
629bef3d41SPaul Gortmaker 
639bef3d41SPaul Gortmaker 	ecard_set_drvdata(ec, info);
649bef3d41SPaul Gortmaker 
652655a2c7SAlan Cox 	memset(&uart, 0, sizeof(struct uart_8250_port));
662655a2c7SAlan Cox 	uart.port.irq	= ec->irq;
672655a2c7SAlan Cox 	uart.port.flags	= UPF_BOOT_AUTOCONF | UPF_SHARE_IRQ;
682655a2c7SAlan Cox 	uart.port.uartclk	= type->uartclk;
692655a2c7SAlan Cox 	uart.port.iotype	= UPIO_MEM;
702655a2c7SAlan Cox 	uart.port.regshift	= 2;
712655a2c7SAlan Cox 	uart.port.dev	= &ec->dev;
729bef3d41SPaul Gortmaker 
739bef3d41SPaul Gortmaker 	for (i = 0; i < info->num_ports; i ++) {
742655a2c7SAlan Cox 		uart.port.membase = info->vaddr + type->offset[i];
752655a2c7SAlan Cox 		uart.port.mapbase = bus_addr + type->offset[i];
769bef3d41SPaul Gortmaker 
772655a2c7SAlan Cox 		info->ports[i] = serial8250_register_8250_port(&uart);
789bef3d41SPaul Gortmaker 	}
799bef3d41SPaul Gortmaker 
809bef3d41SPaul Gortmaker 	return 0;
819bef3d41SPaul Gortmaker }
829bef3d41SPaul Gortmaker 
83ae8d8a14SBill Pemberton static void serial_card_remove(struct expansion_card *ec)
849bef3d41SPaul Gortmaker {
859bef3d41SPaul Gortmaker 	struct serial_card_info *info = ecard_get_drvdata(ec);
869bef3d41SPaul Gortmaker 	int i;
879bef3d41SPaul Gortmaker 
889bef3d41SPaul Gortmaker 	ecard_set_drvdata(ec, NULL);
899bef3d41SPaul Gortmaker 
909bef3d41SPaul Gortmaker 	for (i = 0; i < info->num_ports; i++)
919bef3d41SPaul Gortmaker 		if (info->ports[i] > 0)
929bef3d41SPaul Gortmaker 			serial8250_unregister_port(info->ports[i]);
939bef3d41SPaul Gortmaker 
949bef3d41SPaul Gortmaker 	kfree(info);
959bef3d41SPaul Gortmaker }
969bef3d41SPaul Gortmaker 
979bef3d41SPaul Gortmaker static struct serial_card_type atomwide_type = {
989bef3d41SPaul Gortmaker 	.num_ports	= 3,
999bef3d41SPaul Gortmaker 	.uartclk	= 7372800,
1009bef3d41SPaul Gortmaker 	.type		= ECARD_RES_IOCSLOW,
1019bef3d41SPaul Gortmaker 	.offset		= { 0x2800, 0x2400, 0x2000 },
1029bef3d41SPaul Gortmaker };
1039bef3d41SPaul Gortmaker 
1049bef3d41SPaul Gortmaker static struct serial_card_type serport_type = {
1059bef3d41SPaul Gortmaker 	.num_ports	= 2,
1069bef3d41SPaul Gortmaker 	.uartclk	= 3686400,
1079bef3d41SPaul Gortmaker 	.type		= ECARD_RES_IOCSLOW,
1089bef3d41SPaul Gortmaker 	.offset		= { 0x2000, 0x2020 },
1099bef3d41SPaul Gortmaker };
1109bef3d41SPaul Gortmaker 
1119bef3d41SPaul Gortmaker static const struct ecard_id serial_cids[] = {
1129bef3d41SPaul Gortmaker 	{ MANU_ATOMWIDE,	PROD_ATOMWIDE_3PSERIAL,	&atomwide_type	},
1139bef3d41SPaul Gortmaker 	{ MANU_SERPORT,		PROD_SERPORT_DSPORT,	&serport_type	},
1149bef3d41SPaul Gortmaker 	{ 0xffff, 0xffff }
1159bef3d41SPaul Gortmaker };
1169bef3d41SPaul Gortmaker 
1179bef3d41SPaul Gortmaker static struct ecard_driver serial_card_driver = {
1189bef3d41SPaul Gortmaker 	.probe		= serial_card_probe,
1192d47b716SBill Pemberton 	.remove		= serial_card_remove,
1209bef3d41SPaul Gortmaker 	.id_table	= serial_cids,
1219bef3d41SPaul Gortmaker 	.drv = {
1229bef3d41SPaul Gortmaker 		.name	= "8250_acorn",
1239bef3d41SPaul Gortmaker 	},
1249bef3d41SPaul Gortmaker };
1259bef3d41SPaul Gortmaker 
1269bef3d41SPaul Gortmaker static int __init serial_card_init(void)
1279bef3d41SPaul Gortmaker {
1289bef3d41SPaul Gortmaker 	return ecard_register_driver(&serial_card_driver);
1299bef3d41SPaul Gortmaker }
1309bef3d41SPaul Gortmaker 
1319bef3d41SPaul Gortmaker static void __exit serial_card_exit(void)
1329bef3d41SPaul Gortmaker {
1339bef3d41SPaul Gortmaker 	ecard_remove_driver(&serial_card_driver);
1349bef3d41SPaul Gortmaker }
1359bef3d41SPaul Gortmaker 
1369bef3d41SPaul Gortmaker MODULE_AUTHOR("Russell King");
1379bef3d41SPaul Gortmaker MODULE_DESCRIPTION("Acorn 8250-compatible serial port expansion card driver");
1389bef3d41SPaul Gortmaker MODULE_LICENSE("GPL");
1399bef3d41SPaul Gortmaker 
1409bef3d41SPaul Gortmaker module_init(serial_card_init);
1419bef3d41SPaul Gortmaker module_exit(serial_card_exit);
142