Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * macsonic.c |
| 3 | * |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 4 | * (C) 2005 Finn Thain |
| 5 | * |
| 6 | * Converted to DMA API, converted to unified driver model, made it work as |
| 7 | * a module again, and from the mac68k project, introduced more 32-bit cards |
| 8 | * and dhd's support for 16-bit cards. |
| 9 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | * (C) 1998 Alan Cox |
| 11 | * |
| 12 | * Debugging Andreas Ehliar, Michael Schmitz |
| 13 | * |
| 14 | * Based on code |
| 15 | * (C) 1996 by Thomas Bogendoerfer (tsbogend@bigbug.franken.de) |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 16 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | * This driver is based on work from Andreas Busse, but most of |
| 18 | * the code is rewritten. |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 19 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | * (C) 1995 by Andreas Busse (andy@waldorf-gmbh.de) |
| 21 | * |
| 22 | * A driver for the Mac onboard Sonic ethernet chip. |
| 23 | * |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 24 | * 98/12/21 MSch: judged from tests on Q800, it's basically working, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | * but eating up both receive and transmit resources |
| 26 | * and duplicating packets. Needs more testing. |
| 27 | * |
| 28 | * 99/01/03 MSch: upgraded to version 0.92 of the core driver, fixed. |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 29 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | * 00/10/31 sammy@oh.verio.com: Updated driver for 2.4 kernels, fixed problems |
| 31 | * on centris. |
| 32 | */ |
| 33 | |
| 34 | #include <linux/kernel.h> |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 35 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #include <linux/types.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | #include <linux/fcntl.h> |
| 38 | #include <linux/interrupt.h> |
| 39 | #include <linux/init.h> |
| 40 | #include <linux/ioport.h> |
| 41 | #include <linux/in.h> |
| 42 | #include <linux/slab.h> |
| 43 | #include <linux/string.h> |
| 44 | #include <linux/delay.h> |
| 45 | #include <linux/nubus.h> |
| 46 | #include <linux/errno.h> |
| 47 | #include <linux/netdevice.h> |
| 48 | #include <linux/etherdevice.h> |
| 49 | #include <linux/skbuff.h> |
Russell King | d052d1b | 2005-10-29 19:07:23 +0100 | [diff] [blame] | 50 | #include <linux/platform_device.h> |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 51 | #include <linux/dma-mapping.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | |
| 53 | #include <asm/bootinfo.h> |
| 54 | #include <asm/system.h> |
| 55 | #include <asm/pgtable.h> |
| 56 | #include <asm/io.h> |
| 57 | #include <asm/hwtest.h> |
| 58 | #include <asm/dma.h> |
| 59 | #include <asm/macintosh.h> |
| 60 | #include <asm/macints.h> |
| 61 | #include <asm/mac_via.h> |
| 62 | |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 63 | static char mac_sonic_string[] = "macsonic"; |
| 64 | static struct platform_device *mac_sonic_device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | |
| 66 | #include "sonic.h" |
| 67 | |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 68 | /* These should basically be bus-size and endian independent (since |
| 69 | the SONIC is at least smart enough that it uses the same endianness |
| 70 | as the host, unlike certain less enlightened Macintosh NICs) */ |
| 71 | #define SONIC_READ(reg) (nubus_readw(dev->base_addr + (reg * 4) \ |
| 72 | + lp->reg_offset)) |
| 73 | #define SONIC_WRITE(reg,val) (nubus_writew(val, dev->base_addr + (reg * 4) \ |
| 74 | + lp->reg_offset)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 76 | /* use 0 for production, 1 for verification, >1 for debug */ |
| 77 | #ifdef SONIC_DEBUG |
| 78 | static unsigned int sonic_debug = SONIC_DEBUG; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 79 | #else |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 80 | static unsigned int sonic_debug = 1; |
| 81 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | static int sonic_version_printed; |
| 84 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | extern int mac_onboard_sonic_probe(struct net_device* dev); |
| 86 | extern int mac_nubus_sonic_probe(struct net_device* dev); |
| 87 | |
| 88 | /* For onboard SONIC */ |
| 89 | #define ONBOARD_SONIC_REGISTERS 0x50F0A000 |
| 90 | #define ONBOARD_SONIC_PROM_BASE 0x50f08000 |
| 91 | |
| 92 | enum macsonic_type { |
| 93 | MACSONIC_DUODOCK, |
| 94 | MACSONIC_APPLE, |
| 95 | MACSONIC_APPLE16, |
| 96 | MACSONIC_DAYNA, |
| 97 | MACSONIC_DAYNALINK |
| 98 | }; |
| 99 | |
| 100 | /* For the built-in SONIC in the Duo Dock */ |
| 101 | #define DUODOCK_SONIC_REGISTERS 0xe10000 |
| 102 | #define DUODOCK_SONIC_PROM_BASE 0xe12000 |
| 103 | |
| 104 | /* For Apple-style NuBus SONIC */ |
| 105 | #define APPLE_SONIC_REGISTERS 0 |
| 106 | #define APPLE_SONIC_PROM_BASE 0x40000 |
| 107 | |
| 108 | /* Daynalink LC SONIC */ |
| 109 | #define DAYNALINK_PROM_BASE 0x400000 |
| 110 | |
| 111 | /* For Dayna-style NuBus SONIC (haven't seen one yet) */ |
| 112 | #define DAYNA_SONIC_REGISTERS 0x180000 |
| 113 | /* This is what OpenBSD says. However, this is definitely in NuBus |
| 114 | ROM space so we should be able to get it by walking the NuBus |
| 115 | resource directories */ |
| 116 | #define DAYNA_SONIC_MAC_ADDR 0xffe004 |
| 117 | |
| 118 | #define SONIC_READ_PROM(addr) nubus_readb(prom_addr+addr) |
| 119 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | /* |
| 121 | * For reversing the PROM address |
| 122 | */ |
| 123 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | static inline void bit_reverse_addr(unsigned char addr[6]) |
| 125 | { |
| 126 | int i; |
| 127 | |
| 128 | for(i = 0; i < 6; i++) |
Akinobu Mita | bc63eb9 | 2006-12-19 13:09:08 -0800 | [diff] [blame] | 129 | addr[i] = bitrev8(addr[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | int __init macsonic_init(struct net_device* dev) |
| 133 | { |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 134 | struct sonic_local* lp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | |
| 136 | /* Allocate the entire chunk of memory for the descriptors. |
| 137 | Note that this cannot cross a 64K boundary. */ |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 138 | if ((lp->descriptors = dma_alloc_coherent(lp->device, |
| 139 | SIZEOF_SONIC_DESC * SONIC_BUS_SCALE(lp->dma_bitmode), |
| 140 | &lp->descriptors_laddr, GFP_KERNEL)) == NULL) { |
| 141 | printk(KERN_ERR "%s: couldn't alloc DMA memory for descriptors.\n", lp->device->bus_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | return -ENOMEM; |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 143 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | |
| 145 | /* Now set up the pointers to point to the appropriate places */ |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 146 | lp->cda = lp->descriptors; |
| 147 | lp->tda = lp->cda + (SIZEOF_SONIC_CDA |
| 148 | * SONIC_BUS_SCALE(lp->dma_bitmode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | lp->rda = lp->tda + (SIZEOF_SONIC_TD * SONIC_NUM_TDS |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 150 | * SONIC_BUS_SCALE(lp->dma_bitmode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | lp->rra = lp->rda + (SIZEOF_SONIC_RD * SONIC_NUM_RDS |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 152 | * SONIC_BUS_SCALE(lp->dma_bitmode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 154 | lp->cda_laddr = lp->descriptors_laddr; |
| 155 | lp->tda_laddr = lp->cda_laddr + (SIZEOF_SONIC_CDA |
| 156 | * SONIC_BUS_SCALE(lp->dma_bitmode)); |
| 157 | lp->rda_laddr = lp->tda_laddr + (SIZEOF_SONIC_TD * SONIC_NUM_TDS |
| 158 | * SONIC_BUS_SCALE(lp->dma_bitmode)); |
| 159 | lp->rra_laddr = lp->rda_laddr + (SIZEOF_SONIC_RD * SONIC_NUM_RDS |
| 160 | * SONIC_BUS_SCALE(lp->dma_bitmode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | |
| 162 | dev->open = sonic_open; |
| 163 | dev->stop = sonic_close; |
| 164 | dev->hard_start_xmit = sonic_send_packet; |
| 165 | dev->get_stats = sonic_get_stats; |
| 166 | dev->set_multicast_list = &sonic_multicast_list; |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 167 | dev->tx_timeout = sonic_tx_timeout; |
| 168 | dev->watchdog_timeo = TX_TIMEOUT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | |
| 170 | /* |
| 171 | * clear tally counter |
| 172 | */ |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 173 | SONIC_WRITE(SONIC_CRCT, 0xffff); |
| 174 | SONIC_WRITE(SONIC_FAET, 0xffff); |
| 175 | SONIC_WRITE(SONIC_MPT, 0xffff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | |
| 177 | return 0; |
| 178 | } |
| 179 | |
| 180 | int __init mac_onboard_sonic_ethernet_addr(struct net_device* dev) |
| 181 | { |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 182 | struct sonic_local *lp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | const int prom_addr = ONBOARD_SONIC_PROM_BASE; |
| 184 | int i; |
| 185 | |
| 186 | /* On NuBus boards we can sometimes look in the ROM resources. |
| 187 | No such luck for comm-slot/onboard. */ |
| 188 | for(i = 0; i < 6; i++) |
| 189 | dev->dev_addr[i] = SONIC_READ_PROM(i); |
| 190 | |
| 191 | /* Most of the time, the address is bit-reversed. The NetBSD |
| 192 | source has a rather long and detailed historical account of |
| 193 | why this is so. */ |
| 194 | if (memcmp(dev->dev_addr, "\x08\x00\x07", 3) && |
| 195 | memcmp(dev->dev_addr, "\x00\xA0\x40", 3) && |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 196 | memcmp(dev->dev_addr, "\x00\x80\x19", 3) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | memcmp(dev->dev_addr, "\x00\x05\x02", 3)) |
| 198 | bit_reverse_addr(dev->dev_addr); |
| 199 | else |
| 200 | return 0; |
| 201 | |
| 202 | /* If we still have what seems to be a bogus address, we'll |
| 203 | look in the CAM. The top entry should be ours. */ |
| 204 | /* Danger! This only works if MacOS has already initialized |
| 205 | the card... */ |
| 206 | if (memcmp(dev->dev_addr, "\x08\x00\x07", 3) && |
| 207 | memcmp(dev->dev_addr, "\x00\xA0\x40", 3) && |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 208 | memcmp(dev->dev_addr, "\x00\x80\x19", 3) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | memcmp(dev->dev_addr, "\x00\x05\x02", 3)) |
| 210 | { |
| 211 | unsigned short val; |
| 212 | |
| 213 | printk(KERN_INFO "macsonic: PROM seems to be wrong, trying CAM entry 15\n"); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 214 | |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 215 | SONIC_WRITE(SONIC_CMD, SONIC_CR_RST); |
| 216 | SONIC_WRITE(SONIC_CEP, 15); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 218 | val = SONIC_READ(SONIC_CAP2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | dev->dev_addr[5] = val >> 8; |
| 220 | dev->dev_addr[4] = val & 0xff; |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 221 | val = SONIC_READ(SONIC_CAP1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | dev->dev_addr[3] = val >> 8; |
| 223 | dev->dev_addr[2] = val & 0xff; |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 224 | val = SONIC_READ(SONIC_CAP0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | dev->dev_addr[1] = val >> 8; |
| 226 | dev->dev_addr[0] = val & 0xff; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 227 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | printk(KERN_INFO "HW Address from CAM 15: "); |
| 229 | for (i = 0; i < 6; i++) { |
| 230 | printk("%2.2x", dev->dev_addr[i]); |
| 231 | if (i < 5) |
| 232 | printk(":"); |
| 233 | } |
| 234 | printk("\n"); |
| 235 | } else return 0; |
| 236 | |
| 237 | if (memcmp(dev->dev_addr, "\x08\x00\x07", 3) && |
| 238 | memcmp(dev->dev_addr, "\x00\xA0\x40", 3) && |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 239 | memcmp(dev->dev_addr, "\x00\x80\x19", 3) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | memcmp(dev->dev_addr, "\x00\x05\x02", 3)) |
| 241 | { |
| 242 | /* |
| 243 | * Still nonsense ... messed up someplace! |
| 244 | */ |
| 245 | printk(KERN_ERR "macsonic: ERROR (INVALID MAC)\n"); |
| 246 | return -EIO; |
| 247 | } else return 0; |
| 248 | } |
| 249 | |
| 250 | int __init mac_onboard_sonic_probe(struct net_device* dev) |
| 251 | { |
| 252 | /* Bwahahaha */ |
| 253 | static int once_is_more_than_enough; |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 254 | struct sonic_local* lp = netdev_priv(dev); |
| 255 | int sr; |
| 256 | int commslot = 0; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 257 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | if (once_is_more_than_enough) |
| 259 | return -ENODEV; |
| 260 | once_is_more_than_enough = 1; |
| 261 | |
| 262 | if (!MACH_IS_MAC) |
| 263 | return -ENODEV; |
| 264 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | if (macintosh_config->ether_type != MAC_ETHER_SONIC) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | return -ENODEV; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 267 | |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 268 | printk(KERN_INFO "Checking for internal Macintosh ethernet (SONIC).. "); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 269 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | /* Bogus probing, on the models which may or may not have |
| 271 | Ethernet (BTW, the Ethernet *is* always at the same |
| 272 | address, and nothing else lives there, at least if Apple's |
| 273 | documentation is to be believed) */ |
| 274 | if (macintosh_config->ident == MAC_MODEL_Q630 || |
| 275 | macintosh_config->ident == MAC_MODEL_P588 || |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 276 | macintosh_config->ident == MAC_MODEL_P575 || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | macintosh_config->ident == MAC_MODEL_C610) { |
| 278 | unsigned long flags; |
| 279 | int card_present; |
| 280 | |
| 281 | local_irq_save(flags); |
| 282 | card_present = hwreg_present((void*)ONBOARD_SONIC_REGISTERS); |
| 283 | local_irq_restore(flags); |
| 284 | |
| 285 | if (!card_present) { |
| 286 | printk("none.\n"); |
| 287 | return -ENODEV; |
| 288 | } |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 289 | commslot = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | } |
| 291 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 292 | printk("yes\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 294 | /* Danger! My arms are flailing wildly! You *must* set lp->reg_offset |
| 295 | * and dev->base_addr before using SONIC_READ() or SONIC_WRITE() */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | dev->base_addr = ONBOARD_SONIC_REGISTERS; |
| 297 | if (via_alt_mapping) |
| 298 | dev->irq = IRQ_AUTO_3; |
| 299 | else |
| 300 | dev->irq = IRQ_NUBUS_9; |
| 301 | |
| 302 | if (!sonic_version_printed) { |
| 303 | printk(KERN_INFO "%s", version); |
| 304 | sonic_version_printed = 1; |
| 305 | } |
| 306 | printk(KERN_INFO "%s: onboard / comm-slot SONIC at 0x%08lx\n", |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 307 | lp->device->bus_id, dev->base_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | |
| 309 | /* The PowerBook's SONIC is 16 bit always. */ |
| 310 | if (macintosh_config->ident == MAC_MODEL_PB520) { |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 311 | lp->reg_offset = 0; |
| 312 | lp->dma_bitmode = SONIC_BITMODE16; |
| 313 | sr = SONIC_READ(SONIC_SR); |
| 314 | } else if (commslot) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | /* Some of the comm-slot cards are 16 bit. But some |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 316 | of them are not. The 32-bit cards use offset 2 and |
| 317 | have known revisions, we try reading the revision |
| 318 | register at offset 2, if we don't get a known revision |
| 319 | we assume 16 bit at offset 0. */ |
| 320 | lp->reg_offset = 2; |
| 321 | lp->dma_bitmode = SONIC_BITMODE16; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 323 | sr = SONIC_READ(SONIC_SR); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 324 | if (sr == 0x0004 || sr == 0x0006 || sr == 0x0100 || sr == 0x0101) |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 325 | /* 83932 is 0x0004 or 0x0006, 83934 is 0x0100 or 0x0101 */ |
| 326 | lp->dma_bitmode = SONIC_BITMODE32; |
| 327 | else { |
| 328 | lp->dma_bitmode = SONIC_BITMODE16; |
| 329 | lp->reg_offset = 0; |
| 330 | sr = SONIC_READ(SONIC_SR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | } |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 332 | } else { |
| 333 | /* All onboard cards are at offset 2 with 32 bit DMA. */ |
| 334 | lp->reg_offset = 2; |
| 335 | lp->dma_bitmode = SONIC_BITMODE32; |
| 336 | sr = SONIC_READ(SONIC_SR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | } |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 338 | printk(KERN_INFO |
| 339 | "%s: revision 0x%04x, using %d bit DMA and register offset %d\n", |
| 340 | lp->device->bus_id, sr, lp->dma_bitmode?32:16, lp->reg_offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 342 | #if 0 /* This is sometimes useful to find out how MacOS configured the card. */ |
| 343 | printk(KERN_INFO "%s: DCR: 0x%04x, DCR2: 0x%04x\n", lp->device->bus_id, |
| 344 | SONIC_READ(SONIC_DCR) & 0xffff, SONIC_READ(SONIC_DCR2) & 0xffff); |
| 345 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | /* Software reset, then initialize control registers. */ |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 348 | SONIC_WRITE(SONIC_CMD, SONIC_CR_RST); |
| 349 | |
| 350 | SONIC_WRITE(SONIC_DCR, SONIC_DCR_EXBUS | SONIC_DCR_BMS | |
| 351 | SONIC_DCR_RFT1 | SONIC_DCR_TFT0 | |
| 352 | (lp->dma_bitmode ? SONIC_DCR_DW : 0)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | |
| 354 | /* This *must* be written back to in order to restore the |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 355 | * extended programmable output bits, as it may not have been |
| 356 | * initialised since the hardware reset. */ |
| 357 | SONIC_WRITE(SONIC_DCR2, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | |
| 359 | /* Clear *and* disable interrupts to be on the safe side */ |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 360 | SONIC_WRITE(SONIC_IMR, 0); |
| 361 | SONIC_WRITE(SONIC_ISR, 0x7fff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | |
| 363 | /* Now look for the MAC address. */ |
| 364 | if (mac_onboard_sonic_ethernet_addr(dev) != 0) |
| 365 | return -ENODEV; |
| 366 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | /* Shared init code */ |
| 368 | return macsonic_init(dev); |
| 369 | } |
| 370 | |
| 371 | int __init mac_nubus_sonic_ethernet_addr(struct net_device* dev, |
| 372 | unsigned long prom_addr, |
| 373 | int id) |
| 374 | { |
| 375 | int i; |
| 376 | for(i = 0; i < 6; i++) |
| 377 | dev->dev_addr[i] = SONIC_READ_PROM(i); |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 378 | |
| 379 | /* Some of the addresses are bit-reversed */ |
| 380 | if (id != MACSONIC_DAYNA) |
| 381 | bit_reverse_addr(dev->dev_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | |
| 383 | return 0; |
| 384 | } |
| 385 | |
| 386 | int __init macsonic_ident(struct nubus_dev* ndev) |
| 387 | { |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 388 | if (ndev->dr_hw == NUBUS_DRHW_ASANTE_LC && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | ndev->dr_sw == NUBUS_DRSW_SONIC_LC) |
| 390 | return MACSONIC_DAYNALINK; |
| 391 | if (ndev->dr_hw == NUBUS_DRHW_SONIC && |
| 392 | ndev->dr_sw == NUBUS_DRSW_APPLE) { |
| 393 | /* There has to be a better way to do this... */ |
| 394 | if (strstr(ndev->board->name, "DuoDock")) |
| 395 | return MACSONIC_DUODOCK; |
| 396 | else |
| 397 | return MACSONIC_APPLE; |
| 398 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 399 | |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 400 | if (ndev->dr_hw == NUBUS_DRHW_SMC9194 && |
| 401 | ndev->dr_sw == NUBUS_DRSW_DAYNA) |
| 402 | return MACSONIC_DAYNA; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 403 | |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 404 | if (ndev->dr_hw == NUBUS_DRHW_SONIC_LC && |
| 405 | ndev->dr_sw == 0) { /* huh? */ |
| 406 | return MACSONIC_APPLE16; |
| 407 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | return -1; |
| 409 | } |
| 410 | |
| 411 | int __init mac_nubus_sonic_probe(struct net_device* dev) |
| 412 | { |
| 413 | static int slots; |
| 414 | struct nubus_dev* ndev = NULL; |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 415 | struct sonic_local* lp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | unsigned long base_addr, prom_addr; |
| 417 | u16 sonic_dcr; |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 418 | int id = -1; |
| 419 | int reg_offset, dma_bitmode; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 420 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | /* Find the first SONIC that hasn't been initialized already */ |
| 422 | while ((ndev = nubus_find_type(NUBUS_CAT_NETWORK, |
| 423 | NUBUS_TYPE_ETHERNET, ndev)) != NULL) |
| 424 | { |
| 425 | /* Have we seen it already? */ |
| 426 | if (slots & (1<<ndev->board->slot)) |
| 427 | continue; |
| 428 | slots |= 1<<ndev->board->slot; |
| 429 | |
| 430 | /* Is it one of ours? */ |
| 431 | if ((id = macsonic_ident(ndev)) != -1) |
| 432 | break; |
| 433 | } |
| 434 | |
| 435 | if (ndev == NULL) |
| 436 | return -ENODEV; |
| 437 | |
| 438 | switch (id) { |
| 439 | case MACSONIC_DUODOCK: |
| 440 | base_addr = ndev->board->slot_addr + DUODOCK_SONIC_REGISTERS; |
| 441 | prom_addr = ndev->board->slot_addr + DUODOCK_SONIC_PROM_BASE; |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 442 | sonic_dcr = SONIC_DCR_EXBUS | SONIC_DCR_RFT0 | SONIC_DCR_RFT1 | |
| 443 | SONIC_DCR_TFT0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | reg_offset = 2; |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 445 | dma_bitmode = SONIC_BITMODE32; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | break; |
| 447 | case MACSONIC_APPLE: |
| 448 | base_addr = ndev->board->slot_addr + APPLE_SONIC_REGISTERS; |
| 449 | prom_addr = ndev->board->slot_addr + APPLE_SONIC_PROM_BASE; |
| 450 | sonic_dcr = SONIC_DCR_BMS | SONIC_DCR_RFT1 | SONIC_DCR_TFT0; |
| 451 | reg_offset = 0; |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 452 | dma_bitmode = SONIC_BITMODE32; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | break; |
| 454 | case MACSONIC_APPLE16: |
| 455 | base_addr = ndev->board->slot_addr + APPLE_SONIC_REGISTERS; |
| 456 | prom_addr = ndev->board->slot_addr + APPLE_SONIC_PROM_BASE; |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 457 | sonic_dcr = SONIC_DCR_EXBUS | SONIC_DCR_RFT1 | SONIC_DCR_TFT0 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 458 | SONIC_DCR_PO1 | SONIC_DCR_BMS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | reg_offset = 0; |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 460 | dma_bitmode = SONIC_BITMODE16; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | break; |
| 462 | case MACSONIC_DAYNALINK: |
| 463 | base_addr = ndev->board->slot_addr + APPLE_SONIC_REGISTERS; |
| 464 | prom_addr = ndev->board->slot_addr + DAYNALINK_PROM_BASE; |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 465 | sonic_dcr = SONIC_DCR_RFT1 | SONIC_DCR_TFT0 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 466 | SONIC_DCR_PO1 | SONIC_DCR_BMS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | reg_offset = 0; |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 468 | dma_bitmode = SONIC_BITMODE16; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | break; |
| 470 | case MACSONIC_DAYNA: |
| 471 | base_addr = ndev->board->slot_addr + DAYNA_SONIC_REGISTERS; |
| 472 | prom_addr = ndev->board->slot_addr + DAYNA_SONIC_MAC_ADDR; |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 473 | sonic_dcr = SONIC_DCR_BMS | |
| 474 | SONIC_DCR_RFT1 | SONIC_DCR_TFT0 | SONIC_DCR_PO1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | reg_offset = 0; |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 476 | dma_bitmode = SONIC_BITMODE16; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | break; |
| 478 | default: |
| 479 | printk(KERN_ERR "macsonic: WTF, id is %d\n", id); |
| 480 | return -ENODEV; |
| 481 | } |
| 482 | |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 483 | /* Danger! My arms are flailing wildly! You *must* set lp->reg_offset |
| 484 | * and dev->base_addr before using SONIC_READ() or SONIC_WRITE() */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | dev->base_addr = base_addr; |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 486 | lp->reg_offset = reg_offset; |
| 487 | lp->dma_bitmode = dma_bitmode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | dev->irq = SLOT2IRQ(ndev->board->slot); |
| 489 | |
| 490 | if (!sonic_version_printed) { |
| 491 | printk(KERN_INFO "%s", version); |
| 492 | sonic_version_printed = 1; |
| 493 | } |
| 494 | printk(KERN_INFO "%s: %s in slot %X\n", |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 495 | lp->device->bus_id, ndev->board->name, ndev->board->slot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | printk(KERN_INFO "%s: revision 0x%04x, using %d bit DMA and register offset %d\n", |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 497 | lp->device->bus_id, SONIC_READ(SONIC_SR), dma_bitmode?32:16, reg_offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 499 | #if 0 /* This is sometimes useful to find out how MacOS configured the card. */ |
| 500 | printk(KERN_INFO "%s: DCR: 0x%04x, DCR2: 0x%04x\n", lp->device->bus_id, |
| 501 | SONIC_READ(SONIC_DCR) & 0xffff, SONIC_READ(SONIC_DCR2) & 0xffff); |
| 502 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | |
| 504 | /* Software reset, then initialize control registers. */ |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 505 | SONIC_WRITE(SONIC_CMD, SONIC_CR_RST); |
| 506 | SONIC_WRITE(SONIC_DCR, sonic_dcr | (dma_bitmode ? SONIC_DCR_DW : 0)); |
| 507 | /* This *must* be written back to in order to restore the |
| 508 | * extended programmable output bits, since it may not have been |
| 509 | * initialised since the hardware reset. */ |
| 510 | SONIC_WRITE(SONIC_DCR2, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | |
| 512 | /* Clear *and* disable interrupts to be on the safe side */ |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 513 | SONIC_WRITE(SONIC_IMR, 0); |
| 514 | SONIC_WRITE(SONIC_ISR, 0x7fff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | |
| 516 | /* Now look for the MAC address. */ |
| 517 | if (mac_nubus_sonic_ethernet_addr(dev, prom_addr, id) != 0) |
| 518 | return -ENODEV; |
| 519 | |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 520 | /* Shared init code */ |
| 521 | return macsonic_init(dev); |
| 522 | } |
| 523 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 524 | static int __init mac_sonic_probe(struct platform_device *device) |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 525 | { |
| 526 | struct net_device *dev; |
| 527 | struct sonic_local *lp; |
| 528 | int err; |
| 529 | int i; |
| 530 | |
| 531 | dev = alloc_etherdev(sizeof(struct sonic_local)); |
| 532 | if (!dev) |
| 533 | return -ENOMEM; |
| 534 | |
| 535 | lp = netdev_priv(dev); |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 536 | lp->device = &device->dev; |
| 537 | SET_NETDEV_DEV(dev, &device->dev); |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 538 | SET_MODULE_OWNER(dev); |
| 539 | |
| 540 | /* This will catch fatal stuff like -ENOMEM as well as success */ |
| 541 | err = mac_onboard_sonic_probe(dev); |
| 542 | if (err == 0) |
| 543 | goto found; |
| 544 | if (err != -ENODEV) |
| 545 | goto out; |
| 546 | err = mac_nubus_sonic_probe(dev); |
| 547 | if (err) |
| 548 | goto out; |
| 549 | found: |
| 550 | err = register_netdev(dev); |
| 551 | if (err) |
| 552 | goto out; |
| 553 | |
| 554 | printk("%s: MAC ", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | for (i = 0; i < 6; i++) { |
| 556 | printk("%2.2x", dev->dev_addr[i]); |
| 557 | if (i < 5) |
| 558 | printk(":"); |
| 559 | } |
| 560 | printk(" IRQ %d\n", dev->irq); |
| 561 | |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 562 | return 0; |
| 563 | |
| 564 | out: |
| 565 | free_netdev(dev); |
| 566 | |
| 567 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | } |
| 569 | |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 570 | MODULE_DESCRIPTION("Macintosh SONIC ethernet driver"); |
| 571 | module_param(sonic_debug, int, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | MODULE_PARM_DESC(sonic_debug, "macsonic debug level (1-4)"); |
| 573 | |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 574 | #define SONIC_IRQ_FLAG IRQ_FLG_FAST |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | |
| 576 | #include "sonic.c" |
| 577 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 578 | static int __devexit mac_sonic_device_remove (struct platform_device *device) |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 579 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 580 | struct net_device *dev = platform_get_drvdata(device); |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 581 | struct sonic_local* lp = netdev_priv(dev); |
| 582 | |
| 583 | unregister_netdev (dev); |
| 584 | dma_free_coherent(lp->device, SIZEOF_SONIC_DESC * SONIC_BUS_SCALE(lp->dma_bitmode), |
| 585 | lp->descriptors, lp->descriptors_laddr); |
| 586 | free_netdev (dev); |
| 587 | |
| 588 | return 0; |
| 589 | } |
| 590 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 591 | static struct platform_driver mac_sonic_driver = { |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 592 | .probe = mac_sonic_probe, |
| 593 | .remove = __devexit_p(mac_sonic_device_remove), |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 594 | .driver = { |
| 595 | .name = mac_sonic_string, |
| 596 | }, |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 597 | }; |
| 598 | |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 599 | static int __init mac_sonic_init_module(void) |
| 600 | { |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 601 | int err; |
| 602 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 603 | if ((err = platform_driver_register(&mac_sonic_driver))) { |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 604 | printk(KERN_ERR "Driver registration failed\n"); |
| 605 | return err; |
| 606 | } |
| 607 | |
Russell King | 09c6518 | 2005-11-05 21:21:10 +0000 | [diff] [blame] | 608 | mac_sonic_device = platform_device_alloc(mac_sonic_string, 0); |
| 609 | if (!mac_sonic_device) { |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 610 | goto out_unregister; |
| 611 | } |
| 612 | |
Russell King | 09c6518 | 2005-11-05 21:21:10 +0000 | [diff] [blame] | 613 | if (platform_device_add(mac_sonic_device)) { |
| 614 | platform_device_put(mac_sonic_device); |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 615 | mac_sonic_device = NULL; |
| 616 | } |
| 617 | |
| 618 | return 0; |
| 619 | |
| 620 | out_unregister: |
Al Viro | ded5ca1 | 2005-12-04 02:28:40 -0500 | [diff] [blame] | 621 | platform_driver_unregister(&mac_sonic_driver); |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 622 | |
| 623 | return -ENOMEM; |
| 624 | } |
| 625 | |
| 626 | static void __exit mac_sonic_cleanup_module(void) |
| 627 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 628 | platform_driver_unregister(&mac_sonic_driver); |
Finn Thain | efcce83 | 2005-08-20 15:53:22 +1000 | [diff] [blame] | 629 | |
| 630 | if (mac_sonic_device) { |
| 631 | platform_device_unregister(mac_sonic_device); |
| 632 | mac_sonic_device = NULL; |
| 633 | } |
| 634 | } |
| 635 | |
| 636 | module_init(mac_sonic_init_module); |
| 637 | module_exit(mac_sonic_cleanup_module); |