Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Sealevel Systems 4021 driver. |
| 3 | * |
| 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. |
| 8 | * |
| 9 | * (c) Copyright 1999, 2001 Alan Cox |
| 10 | * (c) Copyright 2001 Red Hat Inc. |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 11 | * Generic HDLC port Copyright (C) 2008 Krzysztof Halasa <khc@pm.waw.pl> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | * |
| 13 | */ |
| 14 | |
Joe Perches | 23efcb7 | 2011-06-26 19:01:35 +0000 | [diff] [blame] | 15 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 16 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <linux/module.h> |
| 18 | #include <linux/kernel.h> |
| 19 | #include <linux/mm.h> |
| 20 | #include <linux/net.h> |
| 21 | #include <linux/skbuff.h> |
| 22 | #include <linux/netdevice.h> |
| 23 | #include <linux/if_arp.h> |
| 24 | #include <linux/delay.h> |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 25 | #include <linux/hdlc.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <linux/ioport.h> |
| 27 | #include <linux/init.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 28 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include <net/arp.h> |
| 30 | |
Al Viro | 8272997 | 2005-12-06 05:53:04 -0500 | [diff] [blame] | 31 | #include <asm/irq.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #include <asm/io.h> |
| 33 | #include <asm/dma.h> |
| 34 | #include <asm/byteorder.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #include "z85230.h" |
| 36 | |
| 37 | |
| 38 | struct slvl_device |
| 39 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | struct z8530_channel *chan; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | int channel; |
| 42 | }; |
| 43 | |
| 44 | |
| 45 | struct slvl_board |
| 46 | { |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 47 | struct slvl_device dev[2]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | struct z8530_dev board; |
| 49 | int iobase; |
| 50 | }; |
| 51 | |
| 52 | /* |
| 53 | * Network driver support routines |
| 54 | */ |
| 55 | |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 56 | static inline struct slvl_device* dev_to_chan(struct net_device *dev) |
| 57 | { |
| 58 | return (struct slvl_device *)dev_to_hdlc(dev)->priv; |
| 59 | } |
| 60 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | /* |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 62 | * Frame receive. Simple for our card as we do HDLC and there |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | * is no funny garbage involved |
| 64 | */ |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 65 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | static void sealevel_input(struct z8530_channel *c, struct sk_buff *skb) |
| 67 | { |
| 68 | /* Drop the CRC - it's not a good idea to try and negotiate it ;) */ |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 69 | skb_trim(skb, skb->len - 2); |
| 70 | skb->protocol = hdlc_type_trans(skb, c->netdevice); |
Arnaldo Carvalho de Melo | 98e399f | 2007-03-19 15:33:04 -0700 | [diff] [blame] | 71 | skb_reset_mac_header(skb); |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 72 | skb->dev = c->netdevice; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | netif_rx(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | } |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 75 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | /* |
| 77 | * We've been placed in the UP state |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 78 | */ |
| 79 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | static int sealevel_open(struct net_device *d) |
| 81 | { |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 82 | struct slvl_device *slvl = dev_to_chan(d); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | int err = -1; |
| 84 | int unit = slvl->channel; |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 85 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | /* |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 87 | * Link layer up. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | */ |
| 89 | |
Rudy Matela | 614c12a | 2009-12-02 01:26:01 -0800 | [diff] [blame] | 90 | switch (unit) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | case 0: |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 92 | err = z8530_sync_dma_open(d, slvl->chan); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | break; |
| 94 | case 1: |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 95 | err = z8530_sync_open(d, slvl->chan); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | break; |
| 97 | } |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 98 | |
| 99 | if (err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | return err; |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 101 | |
| 102 | err = hdlc_open(d); |
| 103 | if (err) { |
| 104 | switch (unit) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | case 0: |
| 106 | z8530_sync_dma_close(d, slvl->chan); |
| 107 | break; |
| 108 | case 1: |
| 109 | z8530_sync_close(d, slvl->chan); |
| 110 | break; |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 111 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | return err; |
| 113 | } |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 114 | |
| 115 | slvl->chan->rx_function = sealevel_input; |
| 116 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | /* |
| 118 | * Go go go |
| 119 | */ |
| 120 | netif_start_queue(d); |
| 121 | return 0; |
| 122 | } |
| 123 | |
| 124 | static int sealevel_close(struct net_device *d) |
| 125 | { |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 126 | struct slvl_device *slvl = dev_to_chan(d); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | int unit = slvl->channel; |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 128 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | /* |
| 130 | * Discard new frames |
| 131 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 133 | slvl->chan->rx_function = z8530_null_rx; |
| 134 | |
| 135 | hdlc_close(d); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | netif_stop_queue(d); |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 137 | |
Rudy Matela | 614c12a | 2009-12-02 01:26:01 -0800 | [diff] [blame] | 138 | switch (unit) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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; |
| 145 | } |
| 146 | return 0; |
| 147 | } |
| 148 | |
| 149 | static int sealevel_ioctl(struct net_device *d, struct ifreq *ifr, int cmd) |
| 150 | { |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 151 | /* struct slvl_device *slvl=dev_to_chan(d); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | z8530_ioctl(d,&slvl->sync.chanA,ifr,cmd) */ |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 153 | return hdlc_ioctl(d, ifr, cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | /* |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 157 | * Passed network frames, fire them downwind. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | */ |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 159 | |
Stephen Hemminger | d71a674 | 2009-08-31 19:50:47 +0000 | [diff] [blame] | 160 | static netdev_tx_t sealevel_queue_xmit(struct sk_buff *skb, |
| 161 | struct net_device *d) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | { |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 163 | return z8530_queue_xmit(dev_to_chan(d)->chan, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | } |
| 165 | |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 166 | static int sealevel_attach(struct net_device *dev, unsigned short encoding, |
| 167 | unsigned short parity) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | { |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 169 | if (encoding == ENCODING_NRZ && parity == PARITY_CRC16_PR1_CCITT) |
| 170 | return 0; |
| 171 | return -EINVAL; |
| 172 | } |
| 173 | |
Krzysztof Hałasa | 991990a | 2009-01-08 22:52:11 +0100 | [diff] [blame] | 174 | static const struct net_device_ops sealevel_ops = { |
| 175 | .ndo_open = sealevel_open, |
| 176 | .ndo_stop = sealevel_close, |
| 177 | .ndo_change_mtu = hdlc_change_mtu, |
| 178 | .ndo_start_xmit = hdlc_start_xmit, |
| 179 | .ndo_do_ioctl = sealevel_ioctl, |
| 180 | }; |
| 181 | |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 182 | static int slvl_setup(struct slvl_device *sv, int iobase, int irq) |
| 183 | { |
| 184 | struct net_device *dev = alloc_hdlcdev(sv); |
| 185 | if (!dev) |
| 186 | return -1; |
| 187 | |
| 188 | dev_to_hdlc(dev)->attach = sealevel_attach; |
| 189 | dev_to_hdlc(dev)->xmit = sealevel_queue_xmit; |
Krzysztof Hałasa | 991990a | 2009-01-08 22:52:11 +0100 | [diff] [blame] | 190 | dev->netdev_ops = &sealevel_ops; |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 191 | dev->base_addr = iobase; |
| 192 | dev->irq = irq; |
| 193 | |
| 194 | if (register_hdlc_device(dev)) { |
Joe Perches | 23efcb7 | 2011-06-26 19:01:35 +0000 | [diff] [blame] | 195 | pr_err("unable to register HDLC device\n"); |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 196 | free_netdev(dev); |
| 197 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | } |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 199 | |
| 200 | sv->chan->netdevice = dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | return 0; |
| 202 | } |
| 203 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | |
| 205 | /* |
| 206 | * Allocate and setup Sealevel board. |
| 207 | */ |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 208 | |
| 209 | static __init struct slvl_board *slvl_init(int iobase, int irq, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | int txdma, int rxdma, int slow) |
| 211 | { |
| 212 | struct z8530_dev *dev; |
| 213 | struct slvl_board *b; |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 214 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | /* |
| 216 | * Get the needed I/O space |
| 217 | */ |
| 218 | |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 219 | if (!request_region(iobase, 8, "Sealevel 4021")) { |
Joe Perches | 23efcb7 | 2011-06-26 19:01:35 +0000 | [diff] [blame] | 220 | pr_warn("I/O 0x%X already in use\n", iobase); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | return NULL; |
| 222 | } |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 223 | |
Yoann Padioleau | dd00cc4 | 2007-07-19 01:49:03 -0700 | [diff] [blame] | 224 | b = kzalloc(sizeof(struct slvl_board), GFP_KERNEL); |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 225 | if (!b) |
| 226 | goto err_kzalloc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 228 | b->dev[0].chan = &b->board.chanA; |
| 229 | b->dev[0].channel = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 231 | b->dev[1].chan = &b->board.chanB; |
| 232 | b->dev[1].channel = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | |
| 234 | dev = &b->board; |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 235 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | /* |
| 237 | * Stuff in the I/O addressing |
| 238 | */ |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 239 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | dev->active = 0; |
| 241 | |
| 242 | b->iobase = iobase; |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 243 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | /* |
| 245 | * Select 8530 delays for the old board |
| 246 | */ |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 247 | |
| 248 | if (slow) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | iobase |= Z8530_PORT_SLEEP; |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 250 | |
| 251 | dev->chanA.ctrlio = iobase + 1; |
| 252 | dev->chanA.dataio = iobase; |
| 253 | dev->chanB.ctrlio = iobase + 3; |
| 254 | dev->chanB.dataio = iobase + 2; |
| 255 | |
| 256 | dev->chanA.irqs = &z8530_nop; |
| 257 | dev->chanB.irqs = &z8530_nop; |
| 258 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | /* |
| 260 | * Assert DTR enable DMA |
| 261 | */ |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 262 | |
| 263 | outb(3 | (1 << 7), b->iobase + 4); |
| 264 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | |
| 266 | /* We want a fast IRQ for this device. Actually we'd like an even faster |
| 267 | IRQ ;) - This is one driver RtLinux is made for */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 269 | if (request_irq(irq, z8530_interrupt, IRQF_DISABLED, |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 270 | "SeaLevel", dev) < 0) { |
Joe Perches | 23efcb7 | 2011-06-26 19:01:35 +0000 | [diff] [blame] | 271 | pr_warn("IRQ %d already in use\n", irq); |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 272 | goto err_request_irq; |
| 273 | } |
| 274 | |
| 275 | dev->irq = irq; |
| 276 | dev->chanA.private = &b->dev[0]; |
| 277 | dev->chanB.private = &b->dev[1]; |
| 278 | dev->chanA.dev = dev; |
| 279 | dev->chanB.dev = dev; |
| 280 | |
| 281 | dev->chanA.txdma = 3; |
| 282 | dev->chanA.rxdma = 1; |
| 283 | if (request_dma(dev->chanA.txdma, "SeaLevel (TX)")) |
| 284 | goto err_dma_tx; |
| 285 | |
| 286 | if (request_dma(dev->chanA.rxdma, "SeaLevel (RX)")) |
| 287 | goto err_dma_rx; |
| 288 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | disable_irq(irq); |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 290 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | /* |
| 292 | * Begin normal initialise |
| 293 | */ |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 294 | |
| 295 | if (z8530_init(dev) != 0) { |
Joe Perches | 23efcb7 | 2011-06-26 19:01:35 +0000 | [diff] [blame] | 296 | pr_err("Z8530 series device not found\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | enable_irq(irq); |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 298 | goto free_hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | } |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 300 | if (dev->type == Z85C30) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | z8530_channel_load(&dev->chanA, z8530_hdlc_kilostream); |
| 302 | z8530_channel_load(&dev->chanB, z8530_hdlc_kilostream); |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 303 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | z8530_channel_load(&dev->chanA, z8530_hdlc_kilostream_85230); |
| 305 | z8530_channel_load(&dev->chanB, z8530_hdlc_kilostream_85230); |
| 306 | } |
| 307 | |
| 308 | /* |
| 309 | * Now we can take the IRQ |
| 310 | */ |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 311 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | enable_irq(irq); |
| 313 | |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 314 | if (slvl_setup(&b->dev[0], iobase, irq)) |
| 315 | goto free_hw; |
| 316 | if (slvl_setup(&b->dev[1], iobase, irq)) |
| 317 | goto free_netdev0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | |
| 319 | z8530_describe(dev, "I/O", iobase); |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 320 | dev->active = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | return b; |
| 322 | |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 323 | free_netdev0: |
| 324 | unregister_hdlc_device(b->dev[0].chan->netdevice); |
| 325 | free_netdev(b->dev[0].chan->netdevice); |
| 326 | free_hw: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | free_dma(dev->chanA.rxdma); |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 328 | err_dma_rx: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | free_dma(dev->chanA.txdma); |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 330 | err_dma_tx: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | free_irq(irq, dev); |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 332 | err_request_irq: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | kfree(b); |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 334 | err_kzalloc: |
| 335 | release_region(iobase, 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | return NULL; |
| 337 | } |
| 338 | |
| 339 | static void __exit slvl_shutdown(struct slvl_board *b) |
| 340 | { |
| 341 | int u; |
| 342 | |
| 343 | z8530_shutdown(&b->board); |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 344 | |
Rudy Matela | 614c12a | 2009-12-02 01:26:01 -0800 | [diff] [blame] | 345 | for (u = 0; u < 2; u++) { |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 346 | struct net_device *d = b->dev[u].chan->netdevice; |
| 347 | unregister_hdlc_device(d); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | free_netdev(d); |
| 349 | } |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 350 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | free_irq(b->board.irq, &b->board); |
| 352 | free_dma(b->board.chanA.rxdma); |
| 353 | free_dma(b->board.chanA.txdma); |
| 354 | /* DMA off on the card, drop DTR */ |
| 355 | outb(0, b->iobase); |
| 356 | release_region(b->iobase, 8); |
| 357 | kfree(b); |
| 358 | } |
| 359 | |
| 360 | |
| 361 | static int io=0x238; |
| 362 | static int txdma=1; |
| 363 | static int rxdma=3; |
| 364 | static int irq=5; |
Rusty Russell | eb93992 | 2011-12-19 14:08:01 +0000 | [diff] [blame^] | 365 | static bool slow=false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | |
| 367 | module_param(io, int, 0); |
| 368 | MODULE_PARM_DESC(io, "The I/O base of the Sealevel card"); |
| 369 | module_param(txdma, int, 0); |
| 370 | MODULE_PARM_DESC(txdma, "Transmit DMA channel"); |
| 371 | module_param(rxdma, int, 0); |
| 372 | MODULE_PARM_DESC(rxdma, "Receive DMA channel"); |
| 373 | module_param(irq, int, 0); |
| 374 | MODULE_PARM_DESC(irq, "The interrupt line setting for the SeaLevel card"); |
| 375 | module_param(slow, bool, 0); |
| 376 | MODULE_PARM_DESC(slow, "Set this for an older Sealevel card such as the 4012"); |
| 377 | |
| 378 | MODULE_AUTHOR("Alan Cox"); |
| 379 | MODULE_LICENSE("GPL"); |
| 380 | MODULE_DESCRIPTION("Modular driver for the SeaLevel 4021"); |
| 381 | |
| 382 | static struct slvl_board *slvl_unit; |
| 383 | |
| 384 | static int __init slvl_init_module(void) |
| 385 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | slvl_unit = slvl_init(io, irq, txdma, rxdma, slow); |
| 387 | |
| 388 | return slvl_unit ? 0 : -ENODEV; |
| 389 | } |
| 390 | |
| 391 | static void __exit slvl_cleanup_module(void) |
| 392 | { |
Rudy Matela | 614c12a | 2009-12-02 01:26:01 -0800 | [diff] [blame] | 393 | if (slvl_unit) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | slvl_shutdown(slvl_unit); |
| 395 | } |
| 396 | |
| 397 | module_init(slvl_init_module); |
| 398 | module_exit(slvl_cleanup_module); |