2 * Comtrol SV11 card driver
4 * This is a slightly odd Z85230 synchronous driver. All you need to
9 * It supports DMA using two DMA channels in SYNC mode. The driver doesn't
10 * use these facilities
12 * The control port is at io+1, the data at io+3 and turning off the DMA
13 * is done by writing 0 to io+4
15 * The hardware does the bus handling to avoid the need for delays between
16 * touching control registers.
18 * Port B isnt wired (why - beats me)
20 * Generic HDLC port Copyright (C) 2008 Krzysztof Halasa <khc@pm.waw.pl>
23 #include <linux/module.h>
24 #include <linux/kernel.h>
26 #include <linux/net.h>
27 #include <linux/skbuff.h>
28 #include <linux/netdevice.h>
29 #include <linux/if_arp.h>
30 #include <linux/delay.h>
31 #include <linux/hdlc.h>
32 #include <linux/ioport.h>
38 #include <asm/byteorder.h>
44 * Network driver support routines
47 static inline struct z8530_dev* dev_to_sv(struct net_device *dev)
49 return (struct z8530_dev *)dev_to_hdlc(dev)->priv;
53 * Frame receive. Simple for our card as we do HDLC and there
54 * is no funny garbage involved
57 static void hostess_input(struct z8530_channel *c, struct sk_buff *skb)
59 /* Drop the CRC - it's not a good idea to try and negotiate it ;) */
60 skb_trim(skb, skb->len - 2);
61 skb->protocol = hdlc_type_trans(skb, c->netdevice);
62 skb_reset_mac_header(skb);
63 skb->dev = c->netdevice;
65 * Send it to the PPP layer. We don't have time to process
72 * We've been placed in the UP state
75 static int hostess_open(struct net_device *d)
77 struct z8530_dev *sv11 = dev_to_sv(d);
85 err = z8530_sync_open(d, &sv11->chanA);
88 err = z8530_sync_dma_open(d, &sv11->chanA);
91 err = z8530_sync_txdma_open(d, &sv11->chanA);
102 z8530_sync_close(d, &sv11->chanA);
105 z8530_sync_dma_close(d, &sv11->chanA);
108 z8530_sync_txdma_close(d, &sv11->chanA);
113 sv11->chanA.rx_function = hostess_input;
119 netif_start_queue(d);
123 static int hostess_close(struct net_device *d)
125 struct z8530_dev *sv11 = dev_to_sv(d);
129 sv11->chanA.rx_function = z8530_null_rx;
136 z8530_sync_close(d, &sv11->chanA);
139 z8530_sync_dma_close(d, &sv11->chanA);
142 z8530_sync_txdma_close(d, &sv11->chanA);
148 static int hostess_ioctl(struct net_device *d, struct ifreq *ifr, int cmd)
150 /* struct z8530_dev *sv11=dev_to_sv(d);
151 z8530_ioctl(d,&sv11->chanA,ifr,cmd) */
152 return hdlc_ioctl(d, ifr, cmd);
156 * Passed network frames, fire them downwind.
159 static int hostess_queue_xmit(struct sk_buff *skb, struct net_device *d)
161 return z8530_queue_xmit(&dev_to_sv(d)->chanA, skb);
164 static int hostess_attach(struct net_device *dev, unsigned short encoding,
165 unsigned short parity)
167 if (encoding == ENCODING_NRZ && parity == PARITY_CRC16_PR1_CCITT)
173 * Description block for a Comtrol Hostess SV11 card
176 static const struct net_device_ops hostess_ops = {
177 .ndo_open = hostess_open,
178 .ndo_stop = hostess_close,
179 .ndo_change_mtu = hdlc_change_mtu,
180 .ndo_start_xmit = hdlc_start_xmit,
181 .ndo_do_ioctl = hostess_ioctl,
184 static struct z8530_dev *sv11_init(int iobase, int irq)
186 struct z8530_dev *sv;
187 struct net_device *netdev;
189 * Get the needed I/O space
192 if (!request_region(iobase, 8, "Comtrol SV11")) {
193 printk(KERN_WARNING "hostess: I/O 0x%X already in use.\n",
198 sv = kzalloc(sizeof(struct z8530_dev), GFP_KERNEL);
203 * Stuff in the I/O addressing
208 sv->chanA.ctrlio = iobase + 1;
209 sv->chanA.dataio = iobase + 3;
210 sv->chanB.ctrlio = -1;
211 sv->chanB.dataio = -1;
212 sv->chanA.irqs = &z8530_nop;
213 sv->chanB.irqs = &z8530_nop;
215 outb(0, iobase + 4); /* DMA off */
217 /* We want a fast IRQ for this device. Actually we'd like an even faster
218 IRQ ;) - This is one driver RtLinux is made for */
220 if (request_irq(irq, &z8530_interrupt, IRQF_DISABLED,
221 "Hostess SV11", sv) < 0) {
222 printk(KERN_WARNING "hostess: IRQ %d already in use.\n", irq);
227 sv->chanA.private = sv;
233 * You can have DMA off or 1 and 3 thats the lot
238 outb(0x03 | 0x08, iobase + 4); /* DMA on */
239 if (request_dma(sv->chanA.txdma, "Hostess SV/11 (TX)"))
243 if (request_dma(sv->chanA.rxdma, "Hostess SV/11 (RX)"))
247 /* Kill our private IRQ line the hostess can end up chattering
248 until the configuration is set */
252 * Begin normal initialise
255 if (z8530_init(sv)) {
256 printk(KERN_ERR "Z8530 series device not found.\n");
260 z8530_channel_load(&sv->chanB, z8530_dead_port);
261 if (sv->type == Z85C30)
262 z8530_channel_load(&sv->chanA, z8530_hdlc_kilostream);
264 z8530_channel_load(&sv->chanA, z8530_hdlc_kilostream_85230);
269 * Now we can take the IRQ
272 sv->chanA.netdevice = netdev = alloc_hdlcdev(sv);
276 dev_to_hdlc(netdev)->attach = hostess_attach;
277 dev_to_hdlc(netdev)->xmit = hostess_queue_xmit;
278 netdev->netdev_ops = &hostess_ops;
279 netdev->base_addr = iobase;
282 if (register_hdlc_device(netdev)) {
283 printk(KERN_ERR "hostess: unable to register HDLC device.\n");
288 z8530_describe(sv, "I/O", iobase);
294 free_dma(sv->chanA.rxdma);
297 free_dma(sv->chanA.txdma);
303 release_region(iobase, 8);
307 static void sv11_shutdown(struct z8530_dev *dev)
309 unregister_hdlc_device(dev->chanA.netdevice);
311 free_irq(dev->irq, dev);
314 free_dma(dev->chanA.rxdma);
315 free_dma(dev->chanA.txdma);
317 release_region(dev->chanA.ctrlio - 1, 8);
318 free_netdev(dev->chanA.netdevice);
322 static int io = 0x200;
325 module_param(io, int, 0);
326 MODULE_PARM_DESC(io, "The I/O base of the Comtrol Hostess SV11 card");
327 module_param(dma, int, 0);
328 MODULE_PARM_DESC(dma, "Set this to 1 to use DMA1/DMA3 for TX/RX");
329 module_param(irq, int, 0);
330 MODULE_PARM_DESC(irq, "The interrupt line setting for the Comtrol Hostess SV11 card");
332 MODULE_AUTHOR("Alan Cox");
333 MODULE_LICENSE("GPL");
334 MODULE_DESCRIPTION("Modular driver for the Comtrol Hostess SV11");
336 static struct z8530_dev *sv11_unit;
338 int init_module(void)
340 if ((sv11_unit = sv11_init(io, irq)) == NULL)
345 void cleanup_module(void)
348 sv11_shutdown(sv11_unit);