sh_eth: fix EESIPR values for SH77{34|63}
[linux/fpc-iii.git] / drivers / tty / serial / 8250 / 8250_moxa.c
blob26eb5393a2630c39549362d8c077256cb3fa2b0c
1 /*
2 * 8250_moxa.c - MOXA Smartio/Industio MUE multiport serial driver.
4 * Author: Mathieu OTHACEHE <m.othacehe@gmail.com>
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 */
11 #include <linux/module.h>
12 #include <linux/pci.h>
14 #include "8250.h"
16 #define PCI_DEVICE_ID_MOXA_CP102E 0x1024
17 #define PCI_DEVICE_ID_MOXA_CP102EL 0x1025
18 #define PCI_DEVICE_ID_MOXA_CP104EL_A 0x1045
19 #define PCI_DEVICE_ID_MOXA_CP114EL 0x1144
20 #define PCI_DEVICE_ID_MOXA_CP116E_A_A 0x1160
21 #define PCI_DEVICE_ID_MOXA_CP116E_A_B 0x1161
22 #define PCI_DEVICE_ID_MOXA_CP118EL_A 0x1182
23 #define PCI_DEVICE_ID_MOXA_CP118E_A_I 0x1183
24 #define PCI_DEVICE_ID_MOXA_CP132EL 0x1322
25 #define PCI_DEVICE_ID_MOXA_CP134EL_A 0x1342
26 #define PCI_DEVICE_ID_MOXA_CP138E_A 0x1381
27 #define PCI_DEVICE_ID_MOXA_CP168EL_A 0x1683
29 #define MOXA_BASE_BAUD 921600
30 #define MOXA_UART_OFFSET 0x200
31 #define MOXA_BASE_BAR 1
33 struct moxa8250_board {
34 unsigned int num_ports;
35 int line[0];
38 enum {
39 moxa8250_2p = 0,
40 moxa8250_4p,
41 moxa8250_8p
44 static struct moxa8250_board moxa8250_boards[] = {
45 [moxa8250_2p] = { .num_ports = 2},
46 [moxa8250_4p] = { .num_ports = 4},
47 [moxa8250_8p] = { .num_ports = 8},
50 static int moxa8250_probe(struct pci_dev *pdev, const struct pci_device_id *id)
52 struct uart_8250_port uart;
53 struct moxa8250_board *brd;
54 void __iomem *ioaddr;
55 resource_size_t baseaddr;
56 unsigned int i, nr_ports;
57 unsigned int offset;
58 int ret;
60 brd = &moxa8250_boards[id->driver_data];
61 nr_ports = brd->num_ports;
63 ret = pcim_enable_device(pdev);
64 if (ret)
65 return ret;
67 brd = devm_kzalloc(&pdev->dev, sizeof(struct moxa8250_board) +
68 sizeof(unsigned int) * nr_ports, GFP_KERNEL);
69 if (!brd)
70 return -ENOMEM;
72 memset(&uart, 0, sizeof(struct uart_8250_port));
74 uart.port.dev = &pdev->dev;
75 uart.port.irq = pdev->irq;
76 uart.port.uartclk = MOXA_BASE_BAUD * 16;
77 uart.port.flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF | UPF_SHARE_IRQ;
79 baseaddr = pci_resource_start(pdev, MOXA_BASE_BAR);
80 ioaddr = pcim_iomap(pdev, MOXA_BASE_BAR, 0);
81 if (!ioaddr)
82 return -ENOMEM;
84 for (i = 0; i < nr_ports; i++) {
87 * MOXA Smartio MUE boards with 4 ports have
88 * a different offset for port #3
90 if (nr_ports == 4 && i == 3)
91 offset = 7 * MOXA_UART_OFFSET;
92 else
93 offset = i * MOXA_UART_OFFSET;
95 uart.port.iotype = UPIO_MEM;
96 uart.port.iobase = 0;
97 uart.port.mapbase = baseaddr + offset;
98 uart.port.membase = ioaddr + offset;
99 uart.port.regshift = 0;
101 dev_dbg(&pdev->dev, "Setup PCI port: port %lx, irq %d, type %d\n",
102 uart.port.iobase, uart.port.irq, uart.port.iotype);
104 brd->line[i] = serial8250_register_8250_port(&uart);
105 if (brd->line[i] < 0) {
106 dev_err(&pdev->dev,
107 "Couldn't register serial port %lx, irq %d, type %d, error %d\n",
108 uart.port.iobase, uart.port.irq,
109 uart.port.iotype, brd->line[i]);
110 break;
114 pci_set_drvdata(pdev, brd);
115 return 0;
118 static void moxa8250_remove(struct pci_dev *pdev)
120 struct moxa8250_board *brd = pci_get_drvdata(pdev);
121 unsigned int i;
123 for (i = 0; i < brd->num_ports; i++)
124 serial8250_unregister_port(brd->line[i]);
127 #define MOXA_DEVICE(id, data) { PCI_VDEVICE(MOXA, id), (kernel_ulong_t)data }
129 static const struct pci_device_id pci_ids[] = {
130 MOXA_DEVICE(PCI_DEVICE_ID_MOXA_CP102E, moxa8250_2p),
131 MOXA_DEVICE(PCI_DEVICE_ID_MOXA_CP102EL, moxa8250_2p),
132 MOXA_DEVICE(PCI_DEVICE_ID_MOXA_CP104EL_A, moxa8250_4p),
133 MOXA_DEVICE(PCI_DEVICE_ID_MOXA_CP114EL, moxa8250_4p),
134 MOXA_DEVICE(PCI_DEVICE_ID_MOXA_CP116E_A_A, moxa8250_8p),
135 MOXA_DEVICE(PCI_DEVICE_ID_MOXA_CP116E_A_B, moxa8250_8p),
136 MOXA_DEVICE(PCI_DEVICE_ID_MOXA_CP118EL_A, moxa8250_8p),
137 MOXA_DEVICE(PCI_DEVICE_ID_MOXA_CP118E_A_I, moxa8250_8p),
138 MOXA_DEVICE(PCI_DEVICE_ID_MOXA_CP132EL, moxa8250_2p),
139 MOXA_DEVICE(PCI_DEVICE_ID_MOXA_CP134EL_A, moxa8250_4p),
140 MOXA_DEVICE(PCI_DEVICE_ID_MOXA_CP138E_A, moxa8250_8p),
141 MOXA_DEVICE(PCI_DEVICE_ID_MOXA_CP168EL_A, moxa8250_8p),
144 MODULE_DEVICE_TABLE(pci, pci_ids);
146 static struct pci_driver moxa8250_pci_driver = {
147 .name = "8250_moxa",
148 .id_table = pci_ids,
149 .probe = moxa8250_probe,
150 .remove = moxa8250_remove,
153 module_pci_driver(moxa8250_pci_driver);
155 MODULE_AUTHOR("Mathieu OTHACEHE");
156 MODULE_DESCRIPTION("MOXA SmartIO MUE driver");
157 MODULE_LICENSE("GPL v2");