ALSA: ASoC: Permit simultaneous compilation of both PXA AC97 drivers
[linux-2.6/libata-dev.git] / drivers / net / wan / sealevel.c
blobc0235844a4d594e5cee2b243d4105b54c0f47eb9
1 /*
2 * Sealevel Systems 4021 driver.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
9 * (c) Copyright 1999, 2001 Alan Cox
10 * (c) Copyright 2001 Red Hat Inc.
11 * Generic HDLC port Copyright (C) 2008 Krzysztof Halasa <khc@pm.waw.pl>
15 #include <linux/module.h>
16 #include <linux/kernel.h>
17 #include <linux/mm.h>
18 #include <linux/net.h>
19 #include <linux/skbuff.h>
20 #include <linux/netdevice.h>
21 #include <linux/if_arp.h>
22 #include <linux/delay.h>
23 #include <linux/hdlc.h>
24 #include <linux/ioport.h>
25 #include <linux/init.h>
26 #include <net/arp.h>
28 #include <asm/irq.h>
29 #include <asm/io.h>
30 #include <asm/dma.h>
31 #include <asm/byteorder.h>
32 #include "z85230.h"
35 struct slvl_device
37 struct z8530_channel *chan;
38 int channel;
42 struct slvl_board
44 struct slvl_device dev[2];
45 struct z8530_dev board;
46 int iobase;
50 * Network driver support routines
53 static inline struct slvl_device* dev_to_chan(struct net_device *dev)
55 return (struct slvl_device *)dev_to_hdlc(dev)->priv;
59 * Frame receive. Simple for our card as we do HDLC and there
60 * is no funny garbage involved
63 static void sealevel_input(struct z8530_channel *c, struct sk_buff *skb)
65 /* Drop the CRC - it's not a good idea to try and negotiate it ;) */
66 skb_trim(skb, skb->len - 2);
67 skb->protocol = hdlc_type_trans(skb, c->netdevice);
68 skb_reset_mac_header(skb);
69 skb->dev = c->netdevice;
70 netif_rx(skb);
71 c->netdevice->last_rx = jiffies;
75 * We've been placed in the UP state
78 static int sealevel_open(struct net_device *d)
80 struct slvl_device *slvl = dev_to_chan(d);
81 int err = -1;
82 int unit = slvl->channel;
85 * Link layer up.
88 switch (unit)
90 case 0:
91 err = z8530_sync_dma_open(d, slvl->chan);
92 break;
93 case 1:
94 err = z8530_sync_open(d, slvl->chan);
95 break;
98 if (err)
99 return err;
101 err = hdlc_open(d);
102 if (err) {
103 switch (unit) {
104 case 0:
105 z8530_sync_dma_close(d, slvl->chan);
106 break;
107 case 1:
108 z8530_sync_close(d, slvl->chan);
109 break;
111 return err;
114 slvl->chan->rx_function = sealevel_input;
117 * Go go go
119 netif_start_queue(d);
120 return 0;
123 static int sealevel_close(struct net_device *d)
125 struct slvl_device *slvl = dev_to_chan(d);
126 int unit = slvl->channel;
129 * Discard new frames
132 slvl->chan->rx_function = z8530_null_rx;
134 hdlc_close(d);
135 netif_stop_queue(d);
137 switch (unit)
139 case 0:
140 z8530_sync_dma_close(d, slvl->chan);
141 break;
142 case 1:
143 z8530_sync_close(d, slvl->chan);
144 break;
146 return 0;
149 static int sealevel_ioctl(struct net_device *d, struct ifreq *ifr, int cmd)
151 /* struct slvl_device *slvl=dev_to_chan(d);
152 z8530_ioctl(d,&slvl->sync.chanA,ifr,cmd) */
153 return hdlc_ioctl(d, ifr, cmd);
157 * Passed network frames, fire them downwind.
160 static int sealevel_queue_xmit(struct sk_buff *skb, struct net_device *d)
162 return z8530_queue_xmit(dev_to_chan(d)->chan, skb);
165 static int sealevel_attach(struct net_device *dev, unsigned short encoding,
166 unsigned short parity)
168 if (encoding == ENCODING_NRZ && parity == PARITY_CRC16_PR1_CCITT)
169 return 0;
170 return -EINVAL;
173 static int slvl_setup(struct slvl_device *sv, int iobase, int irq)
175 struct net_device *dev = alloc_hdlcdev(sv);
176 if (!dev)
177 return -1;
179 dev_to_hdlc(dev)->attach = sealevel_attach;
180 dev_to_hdlc(dev)->xmit = sealevel_queue_xmit;
181 dev->open = sealevel_open;
182 dev->stop = sealevel_close;
183 dev->do_ioctl = sealevel_ioctl;
184 dev->base_addr = iobase;
185 dev->irq = irq;
187 if (register_hdlc_device(dev)) {
188 printk(KERN_ERR "sealevel: unable to register HDLC device\n");
189 free_netdev(dev);
190 return -1;
193 sv->chan->netdevice = dev;
194 return 0;
199 * Allocate and setup Sealevel board.
202 static __init struct slvl_board *slvl_init(int iobase, int irq,
203 int txdma, int rxdma, int slow)
205 struct z8530_dev *dev;
206 struct slvl_board *b;
209 * Get the needed I/O space
212 if (!request_region(iobase, 8, "Sealevel 4021")) {
213 printk(KERN_WARNING "sealevel: I/O 0x%X already in use.\n",
214 iobase);
215 return NULL;
218 b = kzalloc(sizeof(struct slvl_board), GFP_KERNEL);
219 if (!b)
220 goto err_kzalloc;
222 b->dev[0].chan = &b->board.chanA;
223 b->dev[0].channel = 0;
225 b->dev[1].chan = &b->board.chanB;
226 b->dev[1].channel = 1;
228 dev = &b->board;
231 * Stuff in the I/O addressing
234 dev->active = 0;
236 b->iobase = iobase;
239 * Select 8530 delays for the old board
242 if (slow)
243 iobase |= Z8530_PORT_SLEEP;
245 dev->chanA.ctrlio = iobase + 1;
246 dev->chanA.dataio = iobase;
247 dev->chanB.ctrlio = iobase + 3;
248 dev->chanB.dataio = iobase + 2;
250 dev->chanA.irqs = &z8530_nop;
251 dev->chanB.irqs = &z8530_nop;
254 * Assert DTR enable DMA
257 outb(3 | (1 << 7), b->iobase + 4);
260 /* We want a fast IRQ for this device. Actually we'd like an even faster
261 IRQ ;) - This is one driver RtLinux is made for */
263 if (request_irq(irq, &z8530_interrupt, IRQF_DISABLED,
264 "SeaLevel", dev) < 0) {
265 printk(KERN_WARNING "sealevel: IRQ %d already in use.\n", irq);
266 goto err_request_irq;
269 dev->irq = irq;
270 dev->chanA.private = &b->dev[0];
271 dev->chanB.private = &b->dev[1];
272 dev->chanA.dev = dev;
273 dev->chanB.dev = dev;
275 dev->chanA.txdma = 3;
276 dev->chanA.rxdma = 1;
277 if (request_dma(dev->chanA.txdma, "SeaLevel (TX)"))
278 goto err_dma_tx;
280 if (request_dma(dev->chanA.rxdma, "SeaLevel (RX)"))
281 goto err_dma_rx;
283 disable_irq(irq);
286 * Begin normal initialise
289 if (z8530_init(dev) != 0) {
290 printk(KERN_ERR "Z8530 series device not found.\n");
291 enable_irq(irq);
292 goto free_hw;
294 if (dev->type == Z85C30) {
295 z8530_channel_load(&dev->chanA, z8530_hdlc_kilostream);
296 z8530_channel_load(&dev->chanB, z8530_hdlc_kilostream);
297 } else {
298 z8530_channel_load(&dev->chanA, z8530_hdlc_kilostream_85230);
299 z8530_channel_load(&dev->chanB, z8530_hdlc_kilostream_85230);
303 * Now we can take the IRQ
306 enable_irq(irq);
308 if (slvl_setup(&b->dev[0], iobase, irq))
309 goto free_hw;
310 if (slvl_setup(&b->dev[1], iobase, irq))
311 goto free_netdev0;
313 z8530_describe(dev, "I/O", iobase);
314 dev->active = 1;
315 return b;
317 free_netdev0:
318 unregister_hdlc_device(b->dev[0].chan->netdevice);
319 free_netdev(b->dev[0].chan->netdevice);
320 free_hw:
321 free_dma(dev->chanA.rxdma);
322 err_dma_rx:
323 free_dma(dev->chanA.txdma);
324 err_dma_tx:
325 free_irq(irq, dev);
326 err_request_irq:
327 kfree(b);
328 err_kzalloc:
329 release_region(iobase, 8);
330 return NULL;
333 static void __exit slvl_shutdown(struct slvl_board *b)
335 int u;
337 z8530_shutdown(&b->board);
339 for (u = 0; u < 2; u++)
341 struct net_device *d = b->dev[u].chan->netdevice;
342 unregister_hdlc_device(d);
343 free_netdev(d);
346 free_irq(b->board.irq, &b->board);
347 free_dma(b->board.chanA.rxdma);
348 free_dma(b->board.chanA.txdma);
349 /* DMA off on the card, drop DTR */
350 outb(0, b->iobase);
351 release_region(b->iobase, 8);
352 kfree(b);
356 static int io=0x238;
357 static int txdma=1;
358 static int rxdma=3;
359 static int irq=5;
360 static int slow=0;
362 module_param(io, int, 0);
363 MODULE_PARM_DESC(io, "The I/O base of the Sealevel card");
364 module_param(txdma, int, 0);
365 MODULE_PARM_DESC(txdma, "Transmit DMA channel");
366 module_param(rxdma, int, 0);
367 MODULE_PARM_DESC(rxdma, "Receive DMA channel");
368 module_param(irq, int, 0);
369 MODULE_PARM_DESC(irq, "The interrupt line setting for the SeaLevel card");
370 module_param(slow, bool, 0);
371 MODULE_PARM_DESC(slow, "Set this for an older Sealevel card such as the 4012");
373 MODULE_AUTHOR("Alan Cox");
374 MODULE_LICENSE("GPL");
375 MODULE_DESCRIPTION("Modular driver for the SeaLevel 4021");
377 static struct slvl_board *slvl_unit;
379 static int __init slvl_init_module(void)
381 slvl_unit = slvl_init(io, irq, txdma, rxdma, slow);
383 return slvl_unit ? 0 : -ENODEV;
386 static void __exit slvl_cleanup_module(void)
388 if(slvl_unit)
389 slvl_shutdown(slvl_unit);
392 module_init(slvl_init_module);
393 module_exit(slvl_cleanup_module);