tty: add SPDX identifiers to all remaining files in drivers/tty/
[linux-2.6-block.git] / drivers / tty / serial / 8250 / 8250_acorn.c
CommitLineData
e3b3d0f5 1// SPDX-License-Identifier: GPL-2.0
1da177e4
LT
2/*
3 * linux/drivers/serial/acorn.c
4 *
5 * Copyright (C) 1996-2003 Russell King.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11#include <linux/module.h>
12#include <linux/types.h>
13#include <linux/tty.h>
14#include <linux/serial_core.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#include "8250.h"
26
27#define MAX_PORTS 3
28
29struct serial_card_type {
30 unsigned int num_ports;
31 unsigned int uartclk;
32 unsigned int type;
33 unsigned int offset[MAX_PORTS];
34};
35
36struct serial_card_info {
37 unsigned int num_ports;
38 int ports[MAX_PORTS];
f12ad7d5 39 void __iomem *vaddr;
1da177e4
LT
40};
41
9671f099 42static int
1da177e4
LT
43serial_card_probe(struct expansion_card *ec, const struct ecard_id *id)
44{
45 struct serial_card_info *info;
46 struct serial_card_type *type = id->data;
2655a2c7 47 struct uart_8250_port uart;
1da177e4 48 unsigned long bus_addr;
1da177e4
LT
49 unsigned int i;
50
8f31bb39 51 info = kzalloc(sizeof(struct serial_card_info), GFP_KERNEL);
1da177e4
LT
52 if (!info)
53 return -ENOMEM;
54
1da177e4
LT
55 info->num_ports = type->num_ports;
56
57 bus_addr = ecard_resource_start(ec, type->type);
10bdaaa0 58 info->vaddr = ecardm_iomap(ec, type->type, 0, 0);
f12ad7d5 59 if (!info->vaddr) {
1da177e4
LT
60 kfree(info);
61 return -ENOMEM;
62 }
63
64 ecard_set_drvdata(ec, info);
65
2655a2c7
AC
66 memset(&uart, 0, sizeof(struct uart_8250_port));
67 uart.port.irq = ec->irq;
68 uart.port.flags = UPF_BOOT_AUTOCONF | UPF_SHARE_IRQ;
69 uart.port.uartclk = type->uartclk;
70 uart.port.iotype = UPIO_MEM;
71 uart.port.regshift = 2;
72 uart.port.dev = &ec->dev;
1da177e4 73
1a33e342 74 for (i = 0; i < info->num_ports; i++) {
2655a2c7
AC
75 uart.port.membase = info->vaddr + type->offset[i];
76 uart.port.mapbase = bus_addr + type->offset[i];
1da177e4 77
2655a2c7 78 info->ports[i] = serial8250_register_8250_port(&uart);
1da177e4
LT
79 }
80
81 return 0;
82}
83
ae8d8a14 84static void serial_card_remove(struct expansion_card *ec)
1da177e4
LT
85{
86 struct serial_card_info *info = ecard_get_drvdata(ec);
87 int i;
88
89 ecard_set_drvdata(ec, NULL);
90
91 for (i = 0; i < info->num_ports; i++)
92 if (info->ports[i] > 0)
93 serial8250_unregister_port(info->ports[i]);
94
95 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,
2d47b716 120 .remove = serial_card_remove,
1da177e4
LT
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);