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.
11 #include <linux/module.h>
12 #include <linux/pci.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;
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;
55 resource_size_t baseaddr;
56 unsigned int i, nr_ports;
60 brd = &moxa8250_boards[id->driver_data];
61 nr_ports = brd->num_ports;
63 ret = pcim_enable_device(pdev);
67 brd = devm_kzalloc(&pdev->dev, sizeof(struct moxa8250_board) +
68 sizeof(unsigned int) * nr_ports, GFP_KERNEL);
71 brd->num_ports = nr_ports;
73 memset(&uart, 0, sizeof(struct uart_8250_port));
75 uart.port.dev = &pdev->dev;
76 uart.port.irq = pdev->irq;
77 uart.port.uartclk = MOXA_BASE_BAUD * 16;
78 uart.port.flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF | UPF_SHARE_IRQ;
80 baseaddr = pci_resource_start(pdev, MOXA_BASE_BAR);
81 ioaddr = pcim_iomap(pdev, MOXA_BASE_BAR, 0);
85 for (i = 0; i < nr_ports; i++) {
88 * MOXA Smartio MUE boards with 4 ports have
89 * a different offset for port #3
91 if (nr_ports == 4 && i == 3)
92 offset = 7 * MOXA_UART_OFFSET;
94 offset = i * MOXA_UART_OFFSET;
96 uart.port.iotype = UPIO_MEM;
98 uart.port.mapbase = baseaddr + offset;
99 uart.port.membase = ioaddr + offset;
100 uart.port.regshift = 0;
102 dev_dbg(&pdev->dev, "Setup PCI port: port %lx, irq %d, type %d\n",
103 uart.port.iobase, uart.port.irq, uart.port.iotype);
105 brd->line[i] = serial8250_register_8250_port(&uart);
106 if (brd->line[i] < 0) {
108 "Couldn't register serial port %lx, irq %d, type %d, error %d\n",
109 uart.port.iobase, uart.port.irq,
110 uart.port.iotype, brd->line[i]);
115 pci_set_drvdata(pdev, brd);
119 static void moxa8250_remove(struct pci_dev *pdev)
121 struct moxa8250_board *brd = pci_get_drvdata(pdev);
124 for (i = 0; i < brd->num_ports; i++)
125 serial8250_unregister_port(brd->line[i]);
128 #define MOXA_DEVICE(id, data) { PCI_VDEVICE(MOXA, id), (kernel_ulong_t)data }
130 static const struct pci_device_id pci_ids[] = {
131 MOXA_DEVICE(PCI_DEVICE_ID_MOXA_CP102E, moxa8250_2p),
132 MOXA_DEVICE(PCI_DEVICE_ID_MOXA_CP102EL, moxa8250_2p),
133 MOXA_DEVICE(PCI_DEVICE_ID_MOXA_CP104EL_A, moxa8250_4p),
134 MOXA_DEVICE(PCI_DEVICE_ID_MOXA_CP114EL, moxa8250_4p),
135 MOXA_DEVICE(PCI_DEVICE_ID_MOXA_CP116E_A_A, moxa8250_8p),
136 MOXA_DEVICE(PCI_DEVICE_ID_MOXA_CP116E_A_B, moxa8250_8p),
137 MOXA_DEVICE(PCI_DEVICE_ID_MOXA_CP118EL_A, moxa8250_8p),
138 MOXA_DEVICE(PCI_DEVICE_ID_MOXA_CP118E_A_I, moxa8250_8p),
139 MOXA_DEVICE(PCI_DEVICE_ID_MOXA_CP132EL, moxa8250_2p),
140 MOXA_DEVICE(PCI_DEVICE_ID_MOXA_CP134EL_A, moxa8250_4p),
141 MOXA_DEVICE(PCI_DEVICE_ID_MOXA_CP138E_A, moxa8250_8p),
142 MOXA_DEVICE(PCI_DEVICE_ID_MOXA_CP168EL_A, moxa8250_8p),
145 MODULE_DEVICE_TABLE(pci, pci_ids);
147 static struct pci_driver moxa8250_pci_driver = {
150 .probe = moxa8250_probe,
151 .remove = moxa8250_remove,
154 module_pci_driver(moxa8250_pci_driver);
156 MODULE_AUTHOR("Mathieu OTHACEHE");
157 MODULE_DESCRIPTION("MOXA SmartIO MUE driver");
158 MODULE_LICENSE("GPL v2");