blob: 4766446f0fa0914a651661728f9e3a263ef82266 [file] [log] [blame]
Thomas Gleixner25763b32019-05-28 10:10:09 -07001// SPDX-License-Identifier: GPL-2.0-only
Krzysztof Halasa7517c1b2007-01-30 16:10:24 +01002/*
3 * Cyclades PC300 synchronous serial card driver for Linux
4 *
Krzysztof Hałasa61e0a6a2008-07-09 23:13:49 +02005 * Copyright (C) 2000-2008 Krzysztof Halasa <khc@pm.waw.pl>
Krzysztof Halasa7517c1b2007-01-30 16:10:24 +01006 *
Alexander A. Klimovab274952020-07-13 11:33:23 +02007 * For information see <https://www.kernel.org/pub/linux/utils/net/hdlc/>.
Krzysztof Halasa7517c1b2007-01-30 16:10:24 +01008 *
9 * Sources of information:
10 * Hitachi HD64572 SCA-II User's Manual
Krzysztof Hałasa61e0a6a2008-07-09 23:13:49 +020011 * Original Cyclades PC300 Linux driver
Krzysztof Halasa7517c1b2007-01-30 16:10:24 +010012 *
13 * This driver currently supports only PC300/RSV (V.24/V.35) and
14 * PC300/X21 cards.
15 */
16
Joe Perches12a3bfe2011-06-26 19:01:28 +000017#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
18
Krzysztof Halasa7517c1b2007-01-30 16:10:24 +010019#include <linux/module.h>
20#include <linux/kernel.h>
21#include <linux/slab.h>
22#include <linux/sched.h>
23#include <linux/types.h>
24#include <linux/fcntl.h>
25#include <linux/in.h>
26#include <linux/string.h>
27#include <linux/errno.h>
28#include <linux/init.h>
29#include <linux/ioport.h>
30#include <linux/moduleparam.h>
31#include <linux/netdevice.h>
32#include <linux/hdlc.h>
33#include <linux/pci.h>
34#include <linux/delay.h>
35#include <asm/io.h>
36
37#include "hd64572.h"
38
Krzysztof Halasa7517c1b2007-01-30 16:10:24 +010039#undef DEBUG_PKT
40#define DEBUG_RINGS
41
42#define PC300_PLX_SIZE 0x80 /* PLX control window size (128 B) */
43#define PC300_SCA_SIZE 0x400 /* SCA window size (1 KB) */
Krzysztof Halasa7517c1b2007-01-30 16:10:24 +010044#define MAX_TX_BUFFERS 10
45
46static int pci_clock_freq = 33000000;
Peng Liae644042021-06-11 11:36:19 +080047static int use_crystal_clock;
Krzysztof Halasa7517c1b2007-01-30 16:10:24 +010048static unsigned int CLOCK_BASE;
49
50/* Masks to access the init_ctrl PLX register */
51#define PC300_CLKSEL_MASK (0x00000004UL)
52#define PC300_CHMEDIA_MASK(port) (0x00000020UL << ((port) * 3))
53#define PC300_CTYPE_MASK (0x00000800UL)
54
Krzysztof Halasa7517c1b2007-01-30 16:10:24 +010055enum { PC300_RSV = 1, PC300_X21, PC300_TE }; /* card types */
56
Peng Lief1806a2021-06-11 11:36:22 +080057/* PLX PCI9050-1 local configuration and shared runtime registers.
Krzysztof Halasa7517c1b2007-01-30 16:10:24 +010058 * This structure can be used to access 9050 registers (memory mapped).
59 */
60typedef struct {
61 u32 loc_addr_range[4]; /* 00-0Ch : Local Address Ranges */
62 u32 loc_rom_range; /* 10h : Local ROM Range */
63 u32 loc_addr_base[4]; /* 14-20h : Local Address Base Addrs */
64 u32 loc_rom_base; /* 24h : Local ROM Base */
65 u32 loc_bus_descr[4]; /* 28-34h : Local Bus Descriptors */
66 u32 rom_bus_descr; /* 38h : ROM Bus Descriptor */
67 u32 cs_base[4]; /* 3C-48h : Chip Select Base Addrs */
68 u32 intr_ctrl_stat; /* 4Ch : Interrupt Control/Status */
69 u32 init_ctrl; /* 50h : EEPROM ctrl, Init Ctrl, etc */
Peng Lieed00312021-06-11 11:36:21 +080070} plx9050;
Krzysztof Halasa7517c1b2007-01-30 16:10:24 +010071
Krzysztof Halasa7517c1b2007-01-30 16:10:24 +010072typedef struct port_s {
Krzysztof Hałasaabc9d912008-07-09 16:49:37 +020073 struct napi_struct napi;
Krzysztof Hałasa61e0a6a2008-07-09 23:13:49 +020074 struct net_device *netdev;
Krzysztof Halasa7517c1b2007-01-30 16:10:24 +010075 struct card_s *card;
76 spinlock_t lock; /* TX lock */
77 sync_serial_settings settings;
78 int rxpart; /* partial frame received, next frame invalid*/
79 unsigned short encoding;
80 unsigned short parity;
81 unsigned int iface;
82 u16 rxin; /* rx ring buffer 'in' pointer */
83 u16 txin; /* tx ring buffer 'in' and 'last' pointers */
84 u16 txlast;
85 u8 rxs, txs, tmc; /* SCA registers */
Krzysztof Hałasa61e0a6a2008-07-09 23:13:49 +020086 u8 chan; /* physical port # - 0 or 1 */
Peng Lieed00312021-06-11 11:36:21 +080087} port_t;
Krzysztof Halasa7517c1b2007-01-30 16:10:24 +010088
Krzysztof Halasa7517c1b2007-01-30 16:10:24 +010089typedef struct card_s {
90 int type; /* RSV, X21, etc. */
91 int n_ports; /* 1 or 2 ports */
Al Viro184123d2007-02-09 16:40:05 +000092 u8 __iomem *rambase; /* buffer memory base (virtual) */
93 u8 __iomem *scabase; /* SCA memory base (virtual) */
Krzysztof Halasa7517c1b2007-01-30 16:10:24 +010094 plx9050 __iomem *plxbase; /* PLX registers memory base (virtual) */
95 u32 init_ctrl_value; /* Saved value - 9050 bug workaround */
96 u16 rx_ring_buffers; /* number of buffers in a ring */
97 u16 tx_ring_buffers;
98 u16 buff_offset; /* offset of first buffer of first channel */
99 u8 irq; /* interrupt request level */
100
101 port_t ports[2];
Peng Lieed00312021-06-11 11:36:21 +0800102} card_t;
Krzysztof Halasa7517c1b2007-01-30 16:10:24 +0100103
Krzysztof Halasa7517c1b2007-01-30 16:10:24 +0100104#define get_port(card, port) ((port) < (card)->n_ports ? \
105 (&(card)->ports[port]) : (NULL))
106
Krzysztof Hałasa6b40aba2008-03-24 16:39:02 +0100107#include "hd64572.c"
Krzysztof Halasa7517c1b2007-01-30 16:10:24 +0100108
Krzysztof Halasa7517c1b2007-01-30 16:10:24 +0100109static void pc300_set_iface(port_t *port)
110{
111 card_t *card = port->card;
Peng Lif8864e22021-06-11 11:36:17 +0800112 u32 __iomem *init_ctrl = &card->plxbase->init_ctrl;
Krzysztof Halasa7517c1b2007-01-30 16:10:24 +0100113 u16 msci = get_msci(port);
114 u8 rxs = port->rxs & CLK_BRG_MASK;
115 u8 txs = port->txs & CLK_BRG_MASK;
116
Krzysztof Hałasa61e0a6a2008-07-09 23:13:49 +0200117 sca_out(EXS_TES1, (port->chan ? MSCI1_OFFSET : MSCI0_OFFSET) + EXS,
118 port->card);
Peng Lieed00312021-06-11 11:36:21 +0800119 switch (port->settings.clock_type) {
Krzysztof Halasa7517c1b2007-01-30 16:10:24 +0100120 case CLOCK_INT:
121 rxs |= CLK_BRG; /* BRG output */
122 txs |= CLK_PIN_OUT | CLK_TX_RXCLK; /* RX clock */
123 break;
124
125 case CLOCK_TXINT:
126 rxs |= CLK_LINE; /* RXC input */
127 txs |= CLK_PIN_OUT | CLK_BRG; /* BRG output */
128 break;
129
130 case CLOCK_TXFROMRX:
131 rxs |= CLK_LINE; /* RXC input */
132 txs |= CLK_PIN_OUT | CLK_TX_RXCLK; /* RX clock */
133 break;
134
135 default: /* EXTernal clock */
136 rxs |= CLK_LINE; /* RXC input */
137 txs |= CLK_PIN_OUT | CLK_LINE; /* TXC input */
138 break;
139 }
140
141 port->rxs = rxs;
142 port->txs = txs;
143 sca_out(rxs, msci + RXS, card);
144 sca_out(txs, msci + TXS, card);
145 sca_set_port(port);
146
147 if (port->card->type == PC300_RSV) {
148 if (port->iface == IF_IFACE_V35)
149 writel(card->init_ctrl_value |
Krzysztof Hałasa61e0a6a2008-07-09 23:13:49 +0200150 PC300_CHMEDIA_MASK(port->chan), init_ctrl);
Krzysztof Halasa7517c1b2007-01-30 16:10:24 +0100151 else
152 writel(card->init_ctrl_value &
Krzysztof Hałasa61e0a6a2008-07-09 23:13:49 +0200153 ~PC300_CHMEDIA_MASK(port->chan), init_ctrl);
Krzysztof Halasa7517c1b2007-01-30 16:10:24 +0100154 }
155}
156
Krzysztof Halasa7517c1b2007-01-30 16:10:24 +0100157static int pc300_open(struct net_device *dev)
158{
159 port_t *port = dev_to_port(dev);
Krzysztof Halasa7517c1b2007-01-30 16:10:24 +0100160 int result = hdlc_open(dev);
Peng Lia657c8b2021-06-11 11:36:16 +0800161
Krzysztof Halasa7517c1b2007-01-30 16:10:24 +0100162 if (result)
163 return result;
164
165 sca_open(dev);
166 pc300_set_iface(port);
167 return 0;
168}
169
Krzysztof Halasa7517c1b2007-01-30 16:10:24 +0100170static int pc300_close(struct net_device *dev)
171{
172 sca_close(dev);
173 hdlc_close(dev);
174 return 0;
175}
176
Arnd Bergmann73d74f62021-07-27 15:45:10 +0200177static int pc300_siocdevprivate(struct net_device *dev, struct ifreq *ifr,
178 void __user *data, int cmd)
179{
180#ifdef DEBUG_RINGS
181 if (cmd == SIOCDEVPRIVATE) {
182 sca_dump_rings(dev);
183 return 0;
184 }
185#endif
186 return -EOPNOTSUPP;
187}
188
Arnd Bergmannad7eab2a2021-07-27 15:45:14 +0200189static int pc300_ioctl(struct net_device *dev, struct if_settings *ifs)
Krzysztof Halasa7517c1b2007-01-30 16:10:24 +0100190{
191 const size_t size = sizeof(sync_serial_settings);
192 sync_serial_settings new_line;
Arnd Bergmannad7eab2a2021-07-27 15:45:14 +0200193 sync_serial_settings __user *line = ifs->ifs_ifsu.sync;
Krzysztof Halasa7517c1b2007-01-30 16:10:24 +0100194 int new_type;
195 port_t *port = dev_to_port(dev);
196
Arnd Bergmannad7eab2a2021-07-27 15:45:14 +0200197 if (ifs->type == IF_GET_IFACE) {
198 ifs->type = port->iface;
199 if (ifs->size < size) {
200 ifs->size = size; /* data size wanted */
Krzysztof Halasa7517c1b2007-01-30 16:10:24 +0100201 return -ENOBUFS;
202 }
203 if (copy_to_user(line, &port->settings, size))
204 return -EFAULT;
205 return 0;
Krzysztof Halasa7517c1b2007-01-30 16:10:24 +0100206 }
207
208 if (port->card->type == PC300_X21 &&
Arnd Bergmannad7eab2a2021-07-27 15:45:14 +0200209 (ifs->type == IF_IFACE_SYNC_SERIAL ||
210 ifs->type == IF_IFACE_X21))
Krzysztof Halasa7517c1b2007-01-30 16:10:24 +0100211 new_type = IF_IFACE_X21;
212
213 else if (port->card->type == PC300_RSV &&
Arnd Bergmannad7eab2a2021-07-27 15:45:14 +0200214 (ifs->type == IF_IFACE_SYNC_SERIAL ||
215 ifs->type == IF_IFACE_V35))
Krzysztof Halasa7517c1b2007-01-30 16:10:24 +0100216 new_type = IF_IFACE_V35;
217
218 else if (port->card->type == PC300_RSV &&
Arnd Bergmannad7eab2a2021-07-27 15:45:14 +0200219 ifs->type == IF_IFACE_V24)
Krzysztof Halasa7517c1b2007-01-30 16:10:24 +0100220 new_type = IF_IFACE_V24;
221
222 else
Arnd Bergmannad7eab2a2021-07-27 15:45:14 +0200223 return hdlc_ioctl(dev, ifs);
Krzysztof Halasa7517c1b2007-01-30 16:10:24 +0100224
225 if (!capable(CAP_NET_ADMIN))
226 return -EPERM;
227
228 if (copy_from_user(&new_line, line, size))
229 return -EFAULT;
230
231 if (new_line.clock_type != CLOCK_EXT &&
232 new_line.clock_type != CLOCK_TXFROMRX &&
233 new_line.clock_type != CLOCK_INT &&
234 new_line.clock_type != CLOCK_TXINT)
235 return -EINVAL; /* No such clock setting */
236
237 if (new_line.loopback != 0 && new_line.loopback != 1)
238 return -EINVAL;
239
240 memcpy(&port->settings, &new_line, size); /* Update settings */
241 port->iface = new_type;
242 pc300_set_iface(port);
243 return 0;
244}
245
Krzysztof Halasa7517c1b2007-01-30 16:10:24 +0100246static void pc300_pci_remove_one(struct pci_dev *pdev)
247{
248 int i;
249 card_t *card = pci_get_drvdata(pdev);
250
251 for (i = 0; i < 2; i++)
Krzysztof Hałasa61e0a6a2008-07-09 23:13:49 +0200252 if (card->ports[i].card)
253 unregister_hdlc_device(card->ports[i].netdev);
Krzysztof Halasa7517c1b2007-01-30 16:10:24 +0100254
255 if (card->irq)
256 free_irq(card->irq, card);
257
258 if (card->rambase)
259 iounmap(card->rambase);
260 if (card->scabase)
261 iounmap(card->scabase);
262 if (card->plxbase)
263 iounmap(card->plxbase);
264
265 pci_release_regions(pdev);
266 pci_disable_device(pdev);
Krzysztof Hałasa61e0a6a2008-07-09 23:13:49 +0200267 if (card->ports[0].netdev)
268 free_netdev(card->ports[0].netdev);
269 if (card->ports[1].netdev)
270 free_netdev(card->ports[1].netdev);
Krzysztof Halasa7517c1b2007-01-30 16:10:24 +0100271 kfree(card);
272}
273
Krzysztof Hałasa991990a2009-01-08 22:52:11 +0100274static const struct net_device_ops pc300_ops = {
275 .ndo_open = pc300_open,
276 .ndo_stop = pc300_close,
Krzysztof Hałasa991990a2009-01-08 22:52:11 +0100277 .ndo_start_xmit = hdlc_start_xmit,
Arnd Bergmannad7eab2a2021-07-27 15:45:14 +0200278 .ndo_siocwandev = pc300_ioctl,
Arnd Bergmann73d74f62021-07-27 15:45:10 +0200279 .ndo_siocdevprivate = pc300_siocdevprivate,
Krzysztof Hałasa991990a2009-01-08 22:52:11 +0100280};
Krzysztof Halasa7517c1b2007-01-30 16:10:24 +0100281
Bill Pembertonaeea6bb2012-12-03 09:24:19 -0500282static int pc300_pci_init_one(struct pci_dev *pdev,
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +0000283 const struct pci_device_id *ent)
Krzysztof Halasa7517c1b2007-01-30 16:10:24 +0100284{
285 card_t *card;
Krzysztof Halasa7517c1b2007-01-30 16:10:24 +0100286 u32 __iomem *p;
287 int i;
288 u32 ramsize;
289 u32 ramphys; /* buffer memory base */
290 u32 scaphys; /* SCA memory base */
291 u32 plxphys; /* PLX registers memory base */
292
Krzysztof Halasa7517c1b2007-01-30 16:10:24 +0100293 i = pci_enable_device(pdev);
294 if (i)
295 return i;
296
297 i = pci_request_regions(pdev, "PC300");
298 if (i) {
299 pci_disable_device(pdev);
300 return i;
301 }
302
Yoann Padioleaudd00cc42007-07-19 01:49:03 -0700303 card = kzalloc(sizeof(card_t), GFP_KERNEL);
Peng Li0cd21352021-06-11 11:36:20 +0800304 if (!card) {
Krzysztof Halasa7517c1b2007-01-30 16:10:24 +0100305 pci_release_regions(pdev);
306 pci_disable_device(pdev);
307 return -ENOBUFS;
308 }
Krzysztof Halasa7517c1b2007-01-30 16:10:24 +0100309 pci_set_drvdata(pdev, card);
310
Krzysztof Hałasa6476a902008-11-20 15:51:05 +0100311 if (pci_resource_len(pdev, 0) != PC300_PLX_SIZE ||
312 pci_resource_len(pdev, 2) != PC300_SCA_SIZE ||
313 pci_resource_len(pdev, 3) < 16384) {
Joe Perches12a3bfe2011-06-26 19:01:28 +0000314 pr_err("invalid card EEPROM parameters\n");
Krzysztof Hałasa6476a902008-11-20 15:51:05 +0100315 pc300_pci_remove_one(pdev);
316 return -EFAULT;
317 }
318
319 plxphys = pci_resource_start(pdev, 0) & PCI_BASE_ADDRESS_MEM_MASK;
320 card->plxbase = ioremap(plxphys, PC300_PLX_SIZE);
321
322 scaphys = pci_resource_start(pdev, 2) & PCI_BASE_ADDRESS_MEM_MASK;
323 card->scabase = ioremap(scaphys, PC300_SCA_SIZE);
324
325 ramphys = pci_resource_start(pdev, 3) & PCI_BASE_ADDRESS_MEM_MASK;
326 card->rambase = pci_ioremap_bar(pdev, 3);
327
Peng Li0cd21352021-06-11 11:36:20 +0800328 if (!card->plxbase || !card->scabase || !card->rambase) {
Joe Perches12a3bfe2011-06-26 19:01:28 +0000329 pr_err("ioremap() failed\n");
Krzysztof Hałasa6476a902008-11-20 15:51:05 +0100330 pc300_pci_remove_one(pdev);
Pan Bian2a39e7a2017-04-23 17:38:35 +0800331 return -ENOMEM;
Krzysztof Hałasa6476a902008-11-20 15:51:05 +0100332 }
333
334 /* PLX PCI 9050 workaround for local configuration register read bug */
335 pci_write_config_dword(pdev, PCI_BASE_ADDRESS_0, scaphys);
336 card->init_ctrl_value = readl(&((plx9050 __iomem *)card->scabase)->init_ctrl);
337 pci_write_config_dword(pdev, PCI_BASE_ADDRESS_0, plxphys);
338
Krzysztof Halasa7517c1b2007-01-30 16:10:24 +0100339 if (pdev->device == PCI_DEVICE_ID_PC300_TE_1 ||
340 pdev->device == PCI_DEVICE_ID_PC300_TE_2)
341 card->type = PC300_TE; /* not fully supported */
342 else if (card->init_ctrl_value & PC300_CTYPE_MASK)
343 card->type = PC300_X21;
344 else
345 card->type = PC300_RSV;
346
347 if (pdev->device == PCI_DEVICE_ID_PC300_RX_1 ||
348 pdev->device == PCI_DEVICE_ID_PC300_TE_1)
349 card->n_ports = 1;
350 else
351 card->n_ports = 2;
352
Peng Lid72f78d2021-06-11 11:36:18 +0800353 for (i = 0; i < card->n_ports; i++) {
354 card->ports[i].netdev = alloc_hdlcdev(&card->ports[i]);
355 if (!card->ports[i].netdev) {
Joe Perches12a3bfe2011-06-26 19:01:28 +0000356 pr_err("unable to allocate memory\n");
Krzysztof Halasa7517c1b2007-01-30 16:10:24 +0100357 pc300_pci_remove_one(pdev);
358 return -ENOMEM;
359 }
Peng Lid72f78d2021-06-11 11:36:18 +0800360 }
Krzysztof Halasa7517c1b2007-01-30 16:10:24 +0100361
Krzysztof Halasa7517c1b2007-01-30 16:10:24 +0100362 /* Reset PLX */
363 p = &card->plxbase->init_ctrl;
364 writel(card->init_ctrl_value | 0x40000000, p);
365 readl(p); /* Flush the write - do not use sca_flush */
366 udelay(1);
367
368 writel(card->init_ctrl_value, p);
369 readl(p); /* Flush the write - do not use sca_flush */
370 udelay(1);
371
372 /* Reload Config. Registers from EEPROM */
373 writel(card->init_ctrl_value | 0x20000000, p);
374 readl(p); /* Flush the write - do not use sca_flush */
375 udelay(1);
376
377 writel(card->init_ctrl_value, p);
378 readl(p); /* Flush the write - do not use sca_flush */
379 udelay(1);
380
381 ramsize = sca_detect_ram(card, card->rambase,
382 pci_resource_len(pdev, 3));
383
384 if (use_crystal_clock)
385 card->init_ctrl_value &= ~PC300_CLKSEL_MASK;
386 else
387 card->init_ctrl_value |= PC300_CLKSEL_MASK;
388
389 writel(card->init_ctrl_value, &card->plxbase->init_ctrl);
390 /* number of TX + RX buffers for one port */
391 i = ramsize / (card->n_ports * (sizeof(pkt_desc) + HDLC_MAX_MRU));
392 card->tx_ring_buffers = min(i / 2, MAX_TX_BUFFERS);
393 card->rx_ring_buffers = i - card->tx_ring_buffers;
394
395 card->buff_offset = card->n_ports * sizeof(pkt_desc) *
396 (card->tx_ring_buffers + card->rx_ring_buffers);
397
Joe Perches12a3bfe2011-06-26 19:01:28 +0000398 pr_info("PC300/%s, %u KB RAM at 0x%x, IRQ%u, using %u TX + %u RX packets rings\n",
399 card->type == PC300_X21 ? "X21" :
400 card->type == PC300_TE ? "TE" : "RSV",
401 ramsize / 1024, ramphys, pdev->irq,
402 card->tx_ring_buffers, card->rx_ring_buffers);
Krzysztof Halasa7517c1b2007-01-30 16:10:24 +0100403
404 if (card->tx_ring_buffers < 1) {
Joe Perches12a3bfe2011-06-26 19:01:28 +0000405 pr_err("RAM test failed\n");
Krzysztof Halasa7517c1b2007-01-30 16:10:24 +0100406 pc300_pci_remove_one(pdev);
407 return -EFAULT;
408 }
409
410 /* Enable interrupts on the PCI bridge, LINTi1 active low */
411 writew(0x0041, &card->plxbase->intr_ctrl_stat);
412
413 /* Allocate IRQ */
Krzysztof Hałasa96783432008-07-09 21:30:17 +0200414 if (request_irq(pdev->irq, sca_intr, IRQF_SHARED, "pc300", card)) {
Joe Perches12a3bfe2011-06-26 19:01:28 +0000415 pr_warn("could not allocate IRQ%d\n", pdev->irq);
Krzysztof Halasa7517c1b2007-01-30 16:10:24 +0100416 pc300_pci_remove_one(pdev);
417 return -EBUSY;
418 }
419 card->irq = pdev->irq;
420
421 sca_init(card, 0);
422
423 // COTE not set - allows better TX DMA settings
424 // sca_out(sca_in(PCR, card) | PCR_COTE, PCR, card);
425
426 sca_out(0x10, BTCR, card);
427
428 for (i = 0; i < card->n_ports; i++) {
429 port_t *port = &card->ports[i];
Krzysztof Hałasa61e0a6a2008-07-09 23:13:49 +0200430 struct net_device *dev = port->netdev;
Krzysztof Halasa7517c1b2007-01-30 16:10:24 +0100431 hdlc_device *hdlc = dev_to_hdlc(dev);
Peng Lia657c8b2021-06-11 11:36:16 +0800432
Krzysztof Hałasa61e0a6a2008-07-09 23:13:49 +0200433 port->chan = i;
Krzysztof Halasa7517c1b2007-01-30 16:10:24 +0100434
435 spin_lock_init(&port->lock);
Krzysztof Halasa7517c1b2007-01-30 16:10:24 +0100436 dev->irq = card->irq;
437 dev->mem_start = ramphys;
438 dev->mem_end = ramphys + ramsize - 1;
439 dev->tx_queue_len = 50;
Krzysztof Hałasa991990a2009-01-08 22:52:11 +0100440 dev->netdev_ops = &pc300_ops;
Krzysztof Halasa7517c1b2007-01-30 16:10:24 +0100441 hdlc->attach = sca_attach;
442 hdlc->xmit = sca_xmit;
443 port->settings.clock_type = CLOCK_EXT;
444 port->card = card;
445 if (card->type == PC300_X21)
446 port->iface = IF_IFACE_X21;
447 else
448 port->iface = IF_IFACE_V35;
449
Krzysztof Hałasaabc9d912008-07-09 16:49:37 +0200450 sca_init_port(port);
Krzysztof Halasa7517c1b2007-01-30 16:10:24 +0100451 if (register_hdlc_device(dev)) {
Joe Perches12a3bfe2011-06-26 19:01:28 +0000452 pr_err("unable to register hdlc device\n");
Krzysztof Halasa7517c1b2007-01-30 16:10:24 +0100453 port->card = NULL;
454 pc300_pci_remove_one(pdev);
455 return -ENOBUFS;
456 }
Krzysztof Halasa7517c1b2007-01-30 16:10:24 +0100457
Joe Perches12a3bfe2011-06-26 19:01:28 +0000458 netdev_info(dev, "PC300 channel %d\n", port->chan);
Krzysztof Halasa7517c1b2007-01-30 16:10:24 +0100459 }
460 return 0;
461}
462
Benoit Taine9baa3c32014-08-08 15:56:03 +0200463static const struct pci_device_id pc300_pci_tbl[] = {
Krzysztof Halasa7517c1b2007-01-30 16:10:24 +0100464 { PCI_VENDOR_ID_CYCLADES, PCI_DEVICE_ID_PC300_RX_1, PCI_ANY_ID,
465 PCI_ANY_ID, 0, 0, 0 },
466 { PCI_VENDOR_ID_CYCLADES, PCI_DEVICE_ID_PC300_RX_2, PCI_ANY_ID,
467 PCI_ANY_ID, 0, 0, 0 },
468 { PCI_VENDOR_ID_CYCLADES, PCI_DEVICE_ID_PC300_TE_1, PCI_ANY_ID,
469 PCI_ANY_ID, 0, 0, 0 },
470 { PCI_VENDOR_ID_CYCLADES, PCI_DEVICE_ID_PC300_TE_2, PCI_ANY_ID,
471 PCI_ANY_ID, 0, 0, 0 },
472 { 0, }
473};
474
Krzysztof Halasa7517c1b2007-01-30 16:10:24 +0100475static struct pci_driver pc300_pci_driver = {
Al Viro184123d2007-02-09 16:40:05 +0000476 .name = "PC300",
477 .id_table = pc300_pci_tbl,
478 .probe = pc300_pci_init_one,
479 .remove = pc300_pci_remove_one,
Krzysztof Halasa7517c1b2007-01-30 16:10:24 +0100480};
481
Krzysztof Halasa7517c1b2007-01-30 16:10:24 +0100482static int __init pc300_init_module(void)
483{
Krzysztof Halasa7517c1b2007-01-30 16:10:24 +0100484 if (pci_clock_freq < 1000000 || pci_clock_freq > 80000000) {
Joe Perches12a3bfe2011-06-26 19:01:28 +0000485 pr_err("Invalid PCI clock frequency\n");
Krzysztof Halasa7517c1b2007-01-30 16:10:24 +0100486 return -EINVAL;
487 }
488 if (use_crystal_clock != 0 && use_crystal_clock != 1) {
Joe Perches12a3bfe2011-06-26 19:01:28 +0000489 pr_err("Invalid 'use_crystal_clock' value\n");
Krzysztof Halasa7517c1b2007-01-30 16:10:24 +0100490 return -EINVAL;
491 }
492
493 CLOCK_BASE = use_crystal_clock ? 24576000 : pci_clock_freq;
494
Richard Knutsson11cc3bb2007-02-14 01:40:21 +0100495 return pci_register_driver(&pc300_pci_driver);
Krzysztof Halasa7517c1b2007-01-30 16:10:24 +0100496}
497
Krzysztof Halasa7517c1b2007-01-30 16:10:24 +0100498static void __exit pc300_cleanup_module(void)
499{
500 pci_unregister_driver(&pc300_pci_driver);
501}
502
503MODULE_AUTHOR("Krzysztof Halasa <khc@pm.waw.pl>");
504MODULE_DESCRIPTION("Cyclades PC300 serial port driver");
505MODULE_LICENSE("GPL v2");
506MODULE_DEVICE_TABLE(pci, pc300_pci_tbl);
507module_param(pci_clock_freq, int, 0444);
508MODULE_PARM_DESC(pci_clock_freq, "System PCI clock frequency in Hz");
509module_param(use_crystal_clock, int, 0444);
510MODULE_PARM_DESC(use_crystal_clock,
511 "Use 24.576 MHz clock instead of PCI clock");
512module_init(pc300_init_module);
513module_exit(pc300_cleanup_module);