Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Comtrol SV11 card driver |
| 3 | * |
| 4 | * This is a slightly odd Z85230 synchronous driver. All you need to |
| 5 | * know basically is |
| 6 | * |
| 7 | * Its a genuine Z85230 |
| 8 | * |
| 9 | * It supports DMA using two DMA channels in SYNC mode. The driver doesn't |
| 10 | * use these facilities |
| 11 | * |
| 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 |
| 14 | * |
| 15 | * The hardware does the bus handling to avoid the need for delays between |
| 16 | * touching control registers. |
| 17 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 18 | * Port B isn't wired (why - beats me) |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 19 | * |
| 20 | * Generic HDLC port Copyright (C) 2008 Krzysztof Halasa <khc@pm.waw.pl> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | */ |
| 22 | |
Joe Perches | 23efcb7 | 2011-06-26 19:01:35 +0000 | [diff] [blame] | 23 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 24 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include <linux/module.h> |
| 26 | #include <linux/kernel.h> |
| 27 | #include <linux/mm.h> |
| 28 | #include <linux/net.h> |
| 29 | #include <linux/skbuff.h> |
| 30 | #include <linux/netdevice.h> |
| 31 | #include <linux/if_arp.h> |
| 32 | #include <linux/delay.h> |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 33 | #include <linux/hdlc.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #include <linux/ioport.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 35 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #include <net/arp.h> |
| 37 | |
Al Viro | 8272997 | 2005-12-06 05:53:04 -0500 | [diff] [blame] | 38 | #include <asm/irq.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include <asm/io.h> |
| 40 | #include <asm/dma.h> |
| 41 | #include <asm/byteorder.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #include "z85230.h" |
| 43 | |
| 44 | static int dma; |
| 45 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | /* |
| 47 | * Network driver support routines |
| 48 | */ |
| 49 | |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 50 | static inline struct z8530_dev* dev_to_sv(struct net_device *dev) |
| 51 | { |
| 52 | return (struct z8530_dev *)dev_to_hdlc(dev)->priv; |
| 53 | } |
| 54 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | /* |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 56 | * Frame receive. Simple for our card as we do HDLC and there |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | * is no funny garbage involved |
| 58 | */ |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 59 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | static void hostess_input(struct z8530_channel *c, struct sk_buff *skb) |
| 61 | { |
| 62 | /* 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] | 63 | skb_trim(skb, skb->len - 2); |
| 64 | skb->protocol = hdlc_type_trans(skb, c->netdevice); |
Arnaldo Carvalho de Melo | 98e399f | 2007-03-19 15:33:04 -0700 | [diff] [blame] | 65 | skb_reset_mac_header(skb); |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 66 | skb->dev = c->netdevice; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | /* |
| 68 | * Send it to the PPP layer. We don't have time to process |
| 69 | * it right now. |
| 70 | */ |
| 71 | netif_rx(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | } |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 73 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | /* |
| 75 | * We've been placed in the UP state |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 76 | */ |
| 77 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | static int hostess_open(struct net_device *d) |
| 79 | { |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 80 | struct z8530_dev *sv11 = dev_to_sv(d); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | int err = -1; |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 82 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | /* |
| 84 | * Link layer up |
| 85 | */ |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 86 | switch (dma) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | case 0: |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 88 | err = z8530_sync_open(d, &sv11->chanA); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | break; |
| 90 | case 1: |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 91 | err = z8530_sync_dma_open(d, &sv11->chanA); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | break; |
| 93 | case 2: |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 94 | err = z8530_sync_txdma_open(d, &sv11->chanA); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | break; |
| 96 | } |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 97 | |
| 98 | if (err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | return err; |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 100 | |
| 101 | err = hdlc_open(d); |
| 102 | if (err) { |
| 103 | switch (dma) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | case 0: |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 105 | z8530_sync_close(d, &sv11->chanA); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | break; |
| 107 | case 1: |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 108 | z8530_sync_dma_close(d, &sv11->chanA); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | break; |
| 110 | case 2: |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 111 | z8530_sync_txdma_close(d, &sv11->chanA); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | break; |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 113 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | return err; |
| 115 | } |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 116 | sv11->chanA.rx_function = hostess_input; |
| 117 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | /* |
| 119 | * Go go go |
| 120 | */ |
| 121 | |
| 122 | netif_start_queue(d); |
| 123 | return 0; |
| 124 | } |
| 125 | |
| 126 | static int hostess_close(struct net_device *d) |
| 127 | { |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 128 | struct z8530_dev *sv11 = dev_to_sv(d); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | /* |
| 130 | * Discard new frames |
| 131 | */ |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 132 | sv11->chanA.rx_function = z8530_null_rx; |
| 133 | |
| 134 | hdlc_close(d); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | netif_stop_queue(d); |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 136 | |
| 137 | switch (dma) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | case 0: |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 139 | z8530_sync_close(d, &sv11->chanA); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | break; |
| 141 | case 1: |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 142 | z8530_sync_dma_close(d, &sv11->chanA); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | break; |
| 144 | case 2: |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 145 | z8530_sync_txdma_close(d, &sv11->chanA); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | break; |
| 147 | } |
| 148 | return 0; |
| 149 | } |
| 150 | |
| 151 | static int hostess_ioctl(struct net_device *d, struct ifreq *ifr, int cmd) |
| 152 | { |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 153 | /* struct z8530_dev *sv11=dev_to_sv(d); |
| 154 | z8530_ioctl(d,&sv11->chanA,ifr,cmd) */ |
| 155 | return hdlc_ioctl(d, ifr, cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | /* |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 159 | * Passed network frames, fire them downwind. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | */ |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 161 | |
Stephen Hemminger | d71a674 | 2009-08-31 19:50:47 +0000 | [diff] [blame] | 162 | static netdev_tx_t hostess_queue_xmit(struct sk_buff *skb, |
| 163 | struct net_device *d) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | { |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 165 | return z8530_queue_xmit(&dev_to_sv(d)->chanA, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | } |
| 167 | |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 168 | static int hostess_attach(struct net_device *dev, unsigned short encoding, |
| 169 | unsigned short parity) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | { |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 171 | if (encoding == ENCODING_NRZ && parity == PARITY_CRC16_PR1_CCITT) |
| 172 | return 0; |
| 173 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | /* |
| 177 | * Description block for a Comtrol Hostess SV11 card |
| 178 | */ |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 179 | |
Krzysztof Hałasa | 991990a | 2009-01-08 22:52:11 +0100 | [diff] [blame] | 180 | static const struct net_device_ops hostess_ops = { |
| 181 | .ndo_open = hostess_open, |
| 182 | .ndo_stop = hostess_close, |
| 183 | .ndo_change_mtu = hdlc_change_mtu, |
| 184 | .ndo_start_xmit = hdlc_start_xmit, |
| 185 | .ndo_do_ioctl = hostess_ioctl, |
| 186 | }; |
| 187 | |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 188 | static struct z8530_dev *sv11_init(int iobase, int irq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | { |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 190 | struct z8530_dev *sv; |
| 191 | struct net_device *netdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | /* |
| 193 | * Get the needed I/O space |
| 194 | */ |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 195 | |
| 196 | if (!request_region(iobase, 8, "Comtrol SV11")) { |
Joe Perches | 23efcb7 | 2011-06-26 19:01:35 +0000 | [diff] [blame] | 197 | pr_warn("I/O 0x%X already in use\n", iobase); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | return NULL; |
| 199 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 201 | sv = kzalloc(sizeof(struct z8530_dev), GFP_KERNEL); |
| 202 | if (!sv) |
| 203 | goto err_kzalloc; |
| 204 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | /* |
| 206 | * Stuff in the I/O addressing |
| 207 | */ |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 208 | |
| 209 | sv->active = 0; |
| 210 | |
| 211 | sv->chanA.ctrlio = iobase + 1; |
| 212 | sv->chanA.dataio = iobase + 3; |
| 213 | sv->chanB.ctrlio = -1; |
| 214 | sv->chanB.dataio = -1; |
| 215 | sv->chanA.irqs = &z8530_nop; |
| 216 | sv->chanB.irqs = &z8530_nop; |
| 217 | |
| 218 | outb(0, iobase + 4); /* DMA off */ |
| 219 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | /* We want a fast IRQ for this device. Actually we'd like an even faster |
| 221 | IRQ ;) - This is one driver RtLinux is made for */ |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 222 | |
Michael Opdenacker | 0ca4520 | 2013-10-05 06:45:30 +0200 | [diff] [blame] | 223 | if (request_irq(irq, z8530_interrupt, 0, |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 224 | "Hostess SV11", sv) < 0) { |
Joe Perches | 23efcb7 | 2011-06-26 19:01:35 +0000 | [diff] [blame] | 225 | pr_warn("IRQ %d already in use\n", irq); |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 226 | goto err_irq; |
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 | |
| 229 | sv->irq = irq; |
| 230 | sv->chanA.private = sv; |
| 231 | sv->chanA.dev = sv; |
| 232 | sv->chanB.dev = sv; |
| 233 | |
| 234 | if (dma) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | /* |
| 236 | * You can have DMA off or 1 and 3 thats the lot |
| 237 | * on the Comtrol. |
| 238 | */ |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 239 | sv->chanA.txdma = 3; |
| 240 | sv->chanA.rxdma = 1; |
| 241 | outb(0x03 | 0x08, iobase + 4); /* DMA on */ |
| 242 | if (request_dma(sv->chanA.txdma, "Hostess SV/11 (TX)")) |
| 243 | goto err_txdma; |
| 244 | |
| 245 | if (dma == 1) |
| 246 | if (request_dma(sv->chanA.rxdma, "Hostess SV/11 (RX)")) |
| 247 | goto err_rxdma; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | /* Kill our private IRQ line the hostess can end up chattering |
| 251 | until the configuration is set */ |
| 252 | disable_irq(irq); |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 253 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | /* |
| 255 | * Begin normal initialise |
| 256 | */ |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 257 | |
| 258 | if (z8530_init(sv)) { |
Joe Perches | 23efcb7 | 2011-06-26 19:01:35 +0000 | [diff] [blame] | 259 | pr_err("Z8530 series device not found\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | enable_irq(irq); |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 261 | goto free_dma; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | } |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 263 | z8530_channel_load(&sv->chanB, z8530_dead_port); |
| 264 | if (sv->type == Z85C30) |
| 265 | z8530_channel_load(&sv->chanA, z8530_hdlc_kilostream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | else |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 267 | z8530_channel_load(&sv->chanA, z8530_hdlc_kilostream_85230); |
| 268 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | enable_irq(irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | |
| 271 | /* |
| 272 | * Now we can take the IRQ |
| 273 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 275 | sv->chanA.netdevice = netdev = alloc_hdlcdev(sv); |
| 276 | if (!netdev) |
| 277 | goto free_dma; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 279 | dev_to_hdlc(netdev)->attach = hostess_attach; |
| 280 | dev_to_hdlc(netdev)->xmit = hostess_queue_xmit; |
Krzysztof Hałasa | 991990a | 2009-01-08 22:52:11 +0100 | [diff] [blame] | 281 | netdev->netdev_ops = &hostess_ops; |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 282 | netdev->base_addr = iobase; |
| 283 | netdev->irq = irq; |
| 284 | |
| 285 | if (register_hdlc_device(netdev)) { |
Joe Perches | 23efcb7 | 2011-06-26 19:01:35 +0000 | [diff] [blame] | 286 | pr_err("unable to register HDLC device\n"); |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 287 | free_netdev(netdev); |
| 288 | goto free_dma; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | } |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 290 | |
| 291 | z8530_describe(sv, "I/O", iobase); |
| 292 | sv->active = 1; |
| 293 | return sv; |
| 294 | |
| 295 | free_dma: |
| 296 | if (dma == 1) |
| 297 | free_dma(sv->chanA.rxdma); |
| 298 | err_rxdma: |
| 299 | if (dma) |
| 300 | free_dma(sv->chanA.txdma); |
| 301 | err_txdma: |
| 302 | free_irq(irq, sv); |
| 303 | err_irq: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | kfree(sv); |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 305 | err_kzalloc: |
| 306 | release_region(iobase, 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | return NULL; |
| 308 | } |
| 309 | |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 310 | static void sv11_shutdown(struct z8530_dev *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | { |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 312 | unregister_hdlc_device(dev->chanA.netdevice); |
| 313 | z8530_shutdown(dev); |
| 314 | free_irq(dev->irq, dev); |
| 315 | if (dma) { |
| 316 | if (dma == 1) |
| 317 | free_dma(dev->chanA.rxdma); |
| 318 | free_dma(dev->chanA.txdma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | } |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 320 | release_region(dev->chanA.ctrlio - 1, 8); |
| 321 | free_netdev(dev->chanA.netdevice); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | kfree(dev); |
| 323 | } |
| 324 | |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 325 | static int io = 0x200; |
| 326 | static int irq = 9; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | |
| 328 | module_param(io, int, 0); |
| 329 | MODULE_PARM_DESC(io, "The I/O base of the Comtrol Hostess SV11 card"); |
| 330 | module_param(dma, int, 0); |
| 331 | MODULE_PARM_DESC(dma, "Set this to 1 to use DMA1/DMA3 for TX/RX"); |
| 332 | module_param(irq, int, 0); |
| 333 | MODULE_PARM_DESC(irq, "The interrupt line setting for the Comtrol Hostess SV11 card"); |
| 334 | |
| 335 | MODULE_AUTHOR("Alan Cox"); |
| 336 | MODULE_LICENSE("GPL"); |
| 337 | MODULE_DESCRIPTION("Modular driver for the Comtrol Hostess SV11"); |
| 338 | |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 339 | static struct z8530_dev *sv11_unit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | |
| 341 | int init_module(void) |
| 342 | { |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 343 | if ((sv11_unit = sv11_init(io, irq)) == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | return -ENODEV; |
| 345 | return 0; |
| 346 | } |
| 347 | |
| 348 | void cleanup_module(void) |
| 349 | { |
Krzysztof Hałasa | 52e8a6a | 2008-07-02 17:47:52 +0200 | [diff] [blame] | 350 | if (sv11_unit) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | sv11_shutdown(sv11_unit); |
| 352 | } |