Xenomai 3.3.2
Loading...
Searching...
No Matches
16550A_pci.h
1/*
2 * Copyright (C) 2006-2007 Jan Kiszka <jan.kiszka@web.de>.
3 * Copyright (C) 2011 Stefan Kisdaroczi <kisda@hispeed.ch>.
4 *
5 * Xenomai is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * Xenomai is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with Xenomai; if not, write to the Free Software Foundation,
17 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
19
20#if defined(CONFIG_XENO_DRIVERS_16550A_PCI)
21
22#include <linux/pci.h>
23
24struct rt_16550_pci_board {
25 char *name;
26 resource_size_t resource_base_addr;
27 unsigned int nports;
28 unsigned int port_ofs;
29 unsigned long irqtype;
30 unsigned int baud_base;
31 int tx_fifo;
32};
33
34#if defined(CONFIG_XENO_DRIVERS_16550A_PCI_MOXA)
35
36#define PCI_DEVICE_ID_CP112UL 0x1120
37#define PCI_DEVICE_ID_CP114UL 0x1143
38#define PCI_DEVICE_ID_CP138U 0x1380
39#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,17,0)
40#define PCI_DEVICE_ID_MOXA_CP102UL 0x1021
41#define PCI_DEVICE_ID_MOXA_CP102U 0x1022
42#define PCI_DEVICE_ID_MOXA_C104 0x1040
43#define PCI_DEVICE_ID_MOXA_CP104U 0x1041
44#define PCI_DEVICE_ID_MOXA_CP114 0x1141
45#define PCI_DEVICE_ID_MOXA_CP118U 0x1180
46#define PCI_DEVICE_ID_MOXA_CP132 0x1320
47#define PCI_DEVICE_ID_MOXA_CP132U 0x1321
48#define PCI_DEVICE_ID_MOXA_CP134U 0x1340
49#define PCI_DEVICE_ID_MOXA_C168 0x1680
50#define PCI_DEVICE_ID_MOXA_CP168U 0x1681
51#endif
52
53static const struct rt_16550_pci_board rt_16550_moxa_c104 = {
54 .name = "Moxa C104H/PCI",
55 .resource_base_addr = 2,
56 .nports = 4,
57 .port_ofs = 8,
58 .baud_base = 921600,
59 .tx_fifo = 16,
60 .irqtype = RTDM_IRQTYPE_SHARED,
61};
62
63static const struct rt_16550_pci_board rt_16550_moxa_c168 = {
64 .name = "Moxa C168H/PCI",
65 .resource_base_addr = 2,
66 .nports = 8,
67 .port_ofs = 8,
68 .baud_base = 921600,
69 .tx_fifo = 16,
70 .irqtype = RTDM_IRQTYPE_SHARED,
71};
72
73static const struct rt_16550_pci_board rt_16550_moxa_cp114 = {
74 .name = "Moxa CP-114",
75 .resource_base_addr = 2,
76 .nports = 4,
77 .port_ofs = 8,
78 .baud_base = 921600,
79 .tx_fifo = 16,
80 .irqtype = RTDM_IRQTYPE_SHARED,
81};
82
83static const struct rt_16550_pci_board rt_16550_moxa_cp132 = {
84 .name = "Moxa CP-132",
85 .resource_base_addr = 2,
86 .nports = 2,
87 .port_ofs = 8,
88 .baud_base = 921600,
89 .tx_fifo = 16,
90 .irqtype = RTDM_IRQTYPE_SHARED,
91};
92
93static const struct rt_16550_pci_board rt_16550_moxa_cp102u = {
94 .name = "Moxa CP-102U",
95 .resource_base_addr = 2,
96 .nports = 2,
97 .port_ofs = 8,
98 .baud_base = 921600,
99 .tx_fifo = 16,
100 .irqtype = RTDM_IRQTYPE_SHARED,
101};
102
103static const struct rt_16550_pci_board rt_16550_moxa_cp102ul = {
104 .name = "Moxa CP-102UL",
105 .resource_base_addr = 2,
106 .nports = 2,
107 .port_ofs = 8,
108 .baud_base = 921600,
109 .tx_fifo = 16,
110 .irqtype = RTDM_IRQTYPE_SHARED,
111};
112
113static const struct rt_16550_pci_board rt_16550_moxa_cp104u = {
114 .name = "Moxa CP-104U",
115 .resource_base_addr = 2,
116 .nports = 4,
117 .port_ofs = 8,
118 .baud_base = 921600,
119 .tx_fifo = 16,
120 .irqtype = RTDM_IRQTYPE_SHARED,
121};
122
123static const struct rt_16550_pci_board rt_16550_moxa_cp112ul = {
124 .name = "Moxa CP-112UL",
125 .resource_base_addr = 2,
126 .nports = 2,
127 .port_ofs = 8,
128 .baud_base = 921600,
129 .tx_fifo = 16,
130 .irqtype = RTDM_IRQTYPE_SHARED,
131};
132
133static const struct rt_16550_pci_board rt_16550_moxa_cp114ul = {
134 .name = "Moxa CP-114UL",
135 .resource_base_addr = 2,
136 .nports = 4,
137 .port_ofs = 8,
138 .baud_base = 921600,
139 .tx_fifo = 16,
140 .irqtype = RTDM_IRQTYPE_SHARED,
141};
142
143static const struct rt_16550_pci_board rt_16550_moxa_cp118u = {
144 .name = "Moxa CP-118U",
145 .resource_base_addr = 2,
146 .nports = 8,
147 .port_ofs = 8,
148 .baud_base = 921600,
149 .tx_fifo = 16,
150 .irqtype = RTDM_IRQTYPE_SHARED,
151};
152
153static const struct rt_16550_pci_board rt_16550_moxa_cp132u = {
154 .name = "Moxa CP-132U",
155 .resource_base_addr = 2,
156 .nports = 2,
157 .port_ofs = 8,
158 .baud_base = 921600,
159 .tx_fifo = 16,
160 .irqtype = RTDM_IRQTYPE_SHARED,
161};
162
163static const struct rt_16550_pci_board rt_16550_moxa_cp134u = {
164 .name = "Moxa CP-134U",
165 .resource_base_addr = 2,
166 .nports = 4,
167 .port_ofs = 8,
168 .baud_base = 921600,
169 .tx_fifo = 16,
170 .irqtype = RTDM_IRQTYPE_SHARED,
171};
172
173static const struct rt_16550_pci_board rt_16550_moxa_cp138u = {
174 .name = "Moxa CP-138U",
175 .resource_base_addr = 2,
176 .nports = 8,
177 .port_ofs = 8,
178 .baud_base = 921600,
179 .tx_fifo = 16,
180 .irqtype = RTDM_IRQTYPE_SHARED,
181};
182
183static const struct rt_16550_pci_board rt_16550_moxa_cp168u = {
184 .name = "Moxa CP-168U",
185 .resource_base_addr = 2,
186 .nports = 8,
187 .port_ofs = 8,
188 .baud_base = 921600,
189 .tx_fifo = 16,
190 .irqtype = RTDM_IRQTYPE_SHARED,
191};
192#endif
193
194const struct pci_device_id rt_16550_pci_table[] = {
195#if defined(CONFIG_XENO_DRIVERS_16550A_PCI_MOXA)
196 {PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_C104),
197 .driver_data = (unsigned long)&rt_16550_moxa_c104},
198 {PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_C168),
199 .driver_data = (unsigned long)&rt_16550_moxa_c168},
200 {PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP114),
201 .driver_data = (unsigned long)&rt_16550_moxa_cp114},
202 {PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP132),
203 .driver_data = (unsigned long)&rt_16550_moxa_cp132},
204 {PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP102U),
205 .driver_data = (unsigned long)&rt_16550_moxa_cp102u},
206 {PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP102UL),
207 .driver_data = (unsigned long)&rt_16550_moxa_cp102ul},
208 {PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP104U),
209 .driver_data = (unsigned long)&rt_16550_moxa_cp104u},
210 {PCI_VDEVICE(MOXA, PCI_DEVICE_ID_CP112UL),
211 .driver_data = (unsigned long)&rt_16550_moxa_cp112ul},
212 {PCI_VDEVICE(MOXA, PCI_DEVICE_ID_CP114UL),
213 .driver_data = (unsigned long)&rt_16550_moxa_cp114ul},
214 {PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP118U),
215 .driver_data = (unsigned long)&rt_16550_moxa_cp118u},
216 {PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP132U),
217 .driver_data = (unsigned long)&rt_16550_moxa_cp132u},
218 {PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP134U),
219 .driver_data = (unsigned long)&rt_16550_moxa_cp134u},
220 {PCI_VDEVICE(MOXA, PCI_DEVICE_ID_CP138U),
221 .driver_data = (unsigned long)&rt_16550_moxa_cp138u},
222 {PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP168U),
223 .driver_data = (unsigned long)&rt_16550_moxa_cp168u},
224#endif
225 { }
226};
227
228static int rt_16550_pci_probe(struct pci_dev *pdev,
229 const struct pci_device_id *ent)
230{
231 struct rt_16550_pci_board *board;
232 int err;
233 int i;
234 int port = 0;
235 int base_addr;
236 int max_devices = 0;
237
238 if (!ent->driver_data)
239 return -ENODEV;
240
241 board = (struct rt_16550_pci_board *)ent->driver_data;
242
243 for (i = 0; i < MAX_DEVICES; i++)
244 if (!rt_16550_addr_param(i))
245 max_devices++;
246
247 if (board->nports > max_devices)
248 return -ENODEV;
249
250 if ((err = pci_enable_device(pdev)))
251 return err;
252
253 base_addr = pci_resource_start(pdev, board->resource_base_addr);
254
255 for (i = 0; i < MAX_DEVICES; i++) {
256 if ((port < board->nports) && (!rt_16550_addr_param(i))) {
257 io[i] = base_addr + port * board->port_ofs;
258 irq[i] = pdev->irq;
259 irqtype[i] = board->irqtype;
260 baud_base[i] = board->baud_base;
261 tx_fifo[i] = board->tx_fifo;
262 port++;
263 }
264 }
265
266 return 0;
267}
268
269static void rt_16550_pci_remove(struct pci_dev *pdev) {
270 pci_disable_device( pdev );
271};
272
273static struct pci_driver rt_16550_pci_driver = {
274 .name = RT_16550_DRIVER_NAME,
275 .id_table = rt_16550_pci_table,
276 .probe = rt_16550_pci_probe,
277 .remove = rt_16550_pci_remove
278};
279
280static int pci_registered;
281
282static inline void rt_16550_pci_init(void)
283{
284 if (pci_register_driver(&rt_16550_pci_driver) == 0)
285 pci_registered = 1;
286}
287
288static inline void rt_16550_pci_cleanup(void)
289{
290 if (pci_registered)
291 pci_unregister_driver(&rt_16550_pci_driver);
292}
293
294#else /* Linux < 2.6.0 || !CONFIG_PCI || !(..._16550A_PCI */
295
296#define rt_16550_pci_init() do { } while (0)
297#define rt_16550_pci_cleanup() do { } while (0)
298
299#endif /* Linux < 2.6.0 || !CONFIG_PCI || !(..._16550A_PCI */
#define RTDM_IRQTYPE_SHARED
Enable IRQ-sharing with other real-time drivers.
Definition driver.h:812