Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1 | /* |
Ben Dooks | 41c340f | 2008-02-05 00:02:15 +0000 | [diff] [blame] | 2 | * Davicom DM9000 Fast Ethernet driver for Linux. |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 3 | * Copyright (C) 1997 Sten Wang |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License |
| 7 | * as published by the Free Software Foundation; either version 2 |
| 8 | * of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
Ben Dooks | 41c340f | 2008-02-05 00:02:15 +0000 | [diff] [blame] | 15 | * (C) Copyright 1997-1998 DAVICOM Semiconductor,Inc. All Rights Reserved. |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 16 | * |
Ben Dooks | 41c340f | 2008-02-05 00:02:15 +0000 | [diff] [blame] | 17 | * Additional updates, Copyright: |
| 18 | * Ben Dooks <ben@simtec.co.uk> |
| 19 | * Sascha Hauer <s.hauer@pengutronix.de> |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 20 | */ |
| 21 | |
| 22 | #include <linux/module.h> |
| 23 | #include <linux/ioport.h> |
| 24 | #include <linux/netdevice.h> |
| 25 | #include <linux/etherdevice.h> |
| 26 | #include <linux/init.h> |
| 27 | #include <linux/skbuff.h> |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 28 | #include <linux/spinlock.h> |
| 29 | #include <linux/crc32.h> |
| 30 | #include <linux/mii.h> |
Ben Dooks | 7da9985 | 2008-02-05 00:02:06 +0000 | [diff] [blame] | 31 | #include <linux/ethtool.h> |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 32 | #include <linux/dm9000.h> |
| 33 | #include <linux/delay.h> |
Russell King | d052d1b | 2005-10-29 19:07:23 +0100 | [diff] [blame] | 34 | #include <linux/platform_device.h> |
Daniel Mack | 4e4fc05 | 2008-01-23 14:54:50 +0100 | [diff] [blame] | 35 | #include <linux/irq.h> |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 36 | |
| 37 | #include <asm/delay.h> |
| 38 | #include <asm/irq.h> |
| 39 | #include <asm/io.h> |
| 40 | |
| 41 | #include "dm9000.h" |
| 42 | |
| 43 | /* Board/System/Debug information/definition ---------------- */ |
| 44 | |
| 45 | #define DM9000_PHY 0x40 /* PHY address 0x01 */ |
| 46 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 47 | #define CARDNAME "dm9000" |
| 48 | #define PFX CARDNAME ": " |
Ben Dooks | 7da9985 | 2008-02-05 00:02:06 +0000 | [diff] [blame] | 49 | #define DRV_VERSION "1.30" |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 50 | |
Alex Landau | f40d24d | 2007-07-12 12:11:48 +0800 | [diff] [blame] | 51 | #ifdef CONFIG_BLACKFIN |
| 52 | #define readsb insb |
| 53 | #define readsw insw |
| 54 | #define readsl insl |
| 55 | #define writesb outsb |
| 56 | #define writesw outsw |
| 57 | #define writesl outsl |
Ben Dooks | 1a5f1c4 | 2008-02-05 00:02:04 +0000 | [diff] [blame] | 58 | #define DEFAULT_TRIGGER IRQF_TRIGGER_HIGH |
Alex Landau | f40d24d | 2007-07-12 12:11:48 +0800 | [diff] [blame] | 59 | #else |
Ben Dooks | 1a5f1c4 | 2008-02-05 00:02:04 +0000 | [diff] [blame] | 60 | #define DEFAULT_TRIGGER (0) |
Alex Landau | f40d24d | 2007-07-12 12:11:48 +0800 | [diff] [blame] | 61 | #endif |
| 62 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 63 | /* |
| 64 | * Transmit timeout, default 5 seconds. |
| 65 | */ |
| 66 | static int watchdog = 5000; |
| 67 | module_param(watchdog, int, 0400); |
| 68 | MODULE_PARM_DESC(watchdog, "transmit timeout in milliseconds"); |
| 69 | |
Ben Dooks | 9a2f037 | 2008-02-05 00:02:10 +0000 | [diff] [blame] | 70 | /* DM9000 register address locking. |
| 71 | * |
| 72 | * The DM9000 uses an address register to control where data written |
| 73 | * to the data register goes. This means that the address register |
| 74 | * must be preserved over interrupts or similar calls. |
| 75 | * |
| 76 | * During interrupt and other critical calls, a spinlock is used to |
| 77 | * protect the system, but the calls themselves save the address |
| 78 | * in the address register in case they are interrupting another |
| 79 | * access to the device. |
| 80 | * |
| 81 | * For general accesses a lock is provided so that calls which are |
| 82 | * allowed to sleep are serialised so that the address register does |
| 83 | * not need to be saved. This lock also serves to serialise access |
| 84 | * to the EEPROM and PHY access registers which are shared between |
| 85 | * these two devices. |
| 86 | */ |
| 87 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 88 | /* Structure/enum declaration ------------------------------- */ |
| 89 | typedef struct board_info { |
| 90 | |
| 91 | void __iomem *io_addr; /* Register I/O base address */ |
| 92 | void __iomem *io_data; /* Data I/O address */ |
| 93 | u16 irq; /* IRQ */ |
| 94 | |
| 95 | u16 tx_pkt_cnt; |
| 96 | u16 queue_pkt_len; |
| 97 | u16 queue_start_addr; |
| 98 | u16 dbug_cnt; |
| 99 | u8 io_mode; /* 0:word, 2:byte */ |
| 100 | u8 phy_addr; |
Ben Dooks | 33ba509 | 2008-02-05 00:02:01 +0000 | [diff] [blame] | 101 | unsigned int flags; |
Ben Dooks | 321f69a | 2008-02-05 00:02:08 +0000 | [diff] [blame] | 102 | unsigned int in_suspend :1; |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 103 | |
Ben Dooks | 5b2b4ff | 2008-02-05 00:02:03 +0000 | [diff] [blame] | 104 | int debug_level; |
| 105 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 106 | void (*inblk)(void __iomem *port, void *data, int length); |
| 107 | void (*outblk)(void __iomem *port, void *data, int length); |
| 108 | void (*dumpblk)(void __iomem *port, int length); |
| 109 | |
Ben Dooks | a76836f | 2008-02-05 00:02:02 +0000 | [diff] [blame] | 110 | struct device *dev; /* parent device */ |
| 111 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 112 | struct resource *addr_res; /* resources found */ |
| 113 | struct resource *data_res; |
| 114 | struct resource *addr_req; /* resources requested */ |
| 115 | struct resource *data_req; |
| 116 | struct resource *irq_res; |
| 117 | |
Ben Dooks | 9a2f037 | 2008-02-05 00:02:10 +0000 | [diff] [blame] | 118 | struct mutex addr_lock; /* phy and eeprom access lock */ |
| 119 | |
Ben Dooks | 8f5bf5f2 | 2008-05-08 11:36:42 +0100 | [diff] [blame] | 120 | struct delayed_work phy_poll; |
| 121 | struct net_device *ndev; |
| 122 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 123 | spinlock_t lock; |
| 124 | |
| 125 | struct mii_if_info mii; |
| 126 | u32 msg_enable; |
| 127 | } board_info_t; |
| 128 | |
Ben Dooks | 5b2b4ff | 2008-02-05 00:02:03 +0000 | [diff] [blame] | 129 | /* debug code */ |
| 130 | |
| 131 | #define dm9000_dbg(db, lev, msg...) do { \ |
| 132 | if ((lev) < CONFIG_DM9000_DEBUGLEVEL && \ |
| 133 | (lev) < db->debug_level) { \ |
| 134 | dev_dbg(db->dev, msg); \ |
| 135 | } \ |
| 136 | } while (0) |
| 137 | |
Ben Dooks | 7da9985 | 2008-02-05 00:02:06 +0000 | [diff] [blame] | 138 | static inline board_info_t *to_dm9000_board(struct net_device *dev) |
| 139 | { |
| 140 | return dev->priv; |
| 141 | } |
| 142 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 143 | /* function declaration ------------------------------------- */ |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 144 | static int dm9000_probe(struct platform_device *); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 145 | static int dm9000_open(struct net_device *); |
| 146 | static int dm9000_start_xmit(struct sk_buff *, struct net_device *); |
| 147 | static int dm9000_stop(struct net_device *); |
Ben Dooks | f42d8ae | 2008-02-05 00:02:21 +0000 | [diff] [blame] | 148 | static int dm9000_ioctl(struct net_device *dev, struct ifreq *req, int cmd); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 149 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 150 | static void dm9000_init_dm9000(struct net_device *); |
| 151 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 152 | static irqreturn_t dm9000_interrupt(int, void *); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 153 | |
| 154 | static int dm9000_phy_read(struct net_device *dev, int phyaddr_unsused, int reg); |
| 155 | static void dm9000_phy_write(struct net_device *dev, int phyaddr_unused, int reg, |
| 156 | int value); |
Ben Dooks | 86c62fa | 2008-02-05 00:02:09 +0000 | [diff] [blame] | 157 | |
Ben Dooks | 29d52e5 | 2008-02-05 00:02:11 +0000 | [diff] [blame] | 158 | static void dm9000_read_eeprom(board_info_t *, int addr, u8 *to); |
| 159 | static void dm9000_write_eeprom(board_info_t *, int addr, u8 *dp); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 160 | static void dm9000_rx(struct net_device *); |
| 161 | static void dm9000_hash_table(struct net_device *); |
| 162 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 163 | /* DM9000 network board routine ---------------------------- */ |
| 164 | |
| 165 | static void |
| 166 | dm9000_reset(board_info_t * db) |
| 167 | { |
Ben Dooks | a76836f | 2008-02-05 00:02:02 +0000 | [diff] [blame] | 168 | dev_dbg(db->dev, "resetting device\n"); |
| 169 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 170 | /* RESET device */ |
| 171 | writeb(DM9000_NCR, db->io_addr); |
| 172 | udelay(200); |
| 173 | writeb(NCR_RST, db->io_data); |
| 174 | udelay(200); |
| 175 | } |
| 176 | |
| 177 | /* |
| 178 | * Read a byte from I/O port |
| 179 | */ |
| 180 | static u8 |
| 181 | ior(board_info_t * db, int reg) |
| 182 | { |
| 183 | writeb(reg, db->io_addr); |
| 184 | return readb(db->io_data); |
| 185 | } |
| 186 | |
| 187 | /* |
| 188 | * Write a byte to I/O port |
| 189 | */ |
| 190 | |
| 191 | static void |
| 192 | iow(board_info_t * db, int reg, int value) |
| 193 | { |
| 194 | writeb(reg, db->io_addr); |
| 195 | writeb(value, db->io_data); |
| 196 | } |
| 197 | |
| 198 | /* routines for sending block to chip */ |
| 199 | |
| 200 | static void dm9000_outblk_8bit(void __iomem *reg, void *data, int count) |
| 201 | { |
| 202 | writesb(reg, data, count); |
| 203 | } |
| 204 | |
| 205 | static void dm9000_outblk_16bit(void __iomem *reg, void *data, int count) |
| 206 | { |
| 207 | writesw(reg, data, (count+1) >> 1); |
| 208 | } |
| 209 | |
| 210 | static void dm9000_outblk_32bit(void __iomem *reg, void *data, int count) |
| 211 | { |
| 212 | writesl(reg, data, (count+3) >> 2); |
| 213 | } |
| 214 | |
| 215 | /* input block from chip to memory */ |
| 216 | |
| 217 | static void dm9000_inblk_8bit(void __iomem *reg, void *data, int count) |
| 218 | { |
Sascha Hauer | 5f6b551 | 2005-06-20 15:32:51 -0700 | [diff] [blame] | 219 | readsb(reg, data, count); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | |
| 223 | static void dm9000_inblk_16bit(void __iomem *reg, void *data, int count) |
| 224 | { |
| 225 | readsw(reg, data, (count+1) >> 1); |
| 226 | } |
| 227 | |
| 228 | static void dm9000_inblk_32bit(void __iomem *reg, void *data, int count) |
| 229 | { |
| 230 | readsl(reg, data, (count+3) >> 2); |
| 231 | } |
| 232 | |
| 233 | /* dump block from chip to null */ |
| 234 | |
| 235 | static void dm9000_dumpblk_8bit(void __iomem *reg, int count) |
| 236 | { |
| 237 | int i; |
| 238 | int tmp; |
| 239 | |
| 240 | for (i = 0; i < count; i++) |
| 241 | tmp = readb(reg); |
| 242 | } |
| 243 | |
| 244 | static void dm9000_dumpblk_16bit(void __iomem *reg, int count) |
| 245 | { |
| 246 | int i; |
| 247 | int tmp; |
| 248 | |
| 249 | count = (count + 1) >> 1; |
| 250 | |
| 251 | for (i = 0; i < count; i++) |
| 252 | tmp = readw(reg); |
| 253 | } |
| 254 | |
| 255 | static void dm9000_dumpblk_32bit(void __iomem *reg, int count) |
| 256 | { |
| 257 | int i; |
| 258 | int tmp; |
| 259 | |
| 260 | count = (count + 3) >> 2; |
| 261 | |
| 262 | for (i = 0; i < count; i++) |
| 263 | tmp = readl(reg); |
| 264 | } |
| 265 | |
| 266 | /* dm9000_set_io |
| 267 | * |
| 268 | * select the specified set of io routines to use with the |
| 269 | * device |
| 270 | */ |
| 271 | |
| 272 | static void dm9000_set_io(struct board_info *db, int byte_width) |
| 273 | { |
| 274 | /* use the size of the data resource to work out what IO |
| 275 | * routines we want to use |
| 276 | */ |
| 277 | |
| 278 | switch (byte_width) { |
| 279 | case 1: |
| 280 | db->dumpblk = dm9000_dumpblk_8bit; |
| 281 | db->outblk = dm9000_outblk_8bit; |
| 282 | db->inblk = dm9000_inblk_8bit; |
| 283 | break; |
| 284 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 285 | |
| 286 | case 3: |
Ben Dooks | a76836f | 2008-02-05 00:02:02 +0000 | [diff] [blame] | 287 | dev_dbg(db->dev, ": 3 byte IO, falling back to 16bit\n"); |
| 288 | case 2: |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 289 | db->dumpblk = dm9000_dumpblk_16bit; |
| 290 | db->outblk = dm9000_outblk_16bit; |
| 291 | db->inblk = dm9000_inblk_16bit; |
| 292 | break; |
| 293 | |
| 294 | case 4: |
| 295 | default: |
| 296 | db->dumpblk = dm9000_dumpblk_32bit; |
| 297 | db->outblk = dm9000_outblk_32bit; |
| 298 | db->inblk = dm9000_inblk_32bit; |
| 299 | break; |
| 300 | } |
| 301 | } |
| 302 | |
Ben Dooks | 8f5bf5f2 | 2008-05-08 11:36:42 +0100 | [diff] [blame] | 303 | static void dm9000_schedule_poll(board_info_t *db) |
| 304 | { |
| 305 | schedule_delayed_work(&db->phy_poll, HZ * 2); |
| 306 | } |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 307 | |
| 308 | /* Our watchdog timed out. Called by the networking layer */ |
| 309 | static void dm9000_timeout(struct net_device *dev) |
| 310 | { |
| 311 | board_info_t *db = (board_info_t *) dev->priv; |
| 312 | u8 reg_save; |
| 313 | unsigned long flags; |
| 314 | |
| 315 | /* Save previous register address */ |
| 316 | reg_save = readb(db->io_addr); |
Ben Dooks | 9ef9ac5 | 2005-07-23 17:25:18 +0100 | [diff] [blame] | 317 | spin_lock_irqsave(&db->lock,flags); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 318 | |
| 319 | netif_stop_queue(dev); |
| 320 | dm9000_reset(db); |
| 321 | dm9000_init_dm9000(dev); |
| 322 | /* We can accept TX packets again */ |
| 323 | dev->trans_start = jiffies; |
| 324 | netif_wake_queue(dev); |
| 325 | |
| 326 | /* Restore previous register address */ |
| 327 | writeb(reg_save, db->io_addr); |
Ben Dooks | 9ef9ac5 | 2005-07-23 17:25:18 +0100 | [diff] [blame] | 328 | spin_unlock_irqrestore(&db->lock,flags); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 329 | } |
| 330 | |
Kevin Hao | 2fd0e33 | 2006-08-14 23:00:15 -0700 | [diff] [blame] | 331 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 332 | /* |
| 333 | *Used by netconsole |
| 334 | */ |
| 335 | static void dm9000_poll_controller(struct net_device *dev) |
| 336 | { |
| 337 | disable_irq(dev->irq); |
Al Viro | 2843114 | 2006-10-08 15:00:12 +0100 | [diff] [blame] | 338 | dm9000_interrupt(dev->irq,dev); |
Kevin Hao | 2fd0e33 | 2006-08-14 23:00:15 -0700 | [diff] [blame] | 339 | enable_irq(dev->irq); |
| 340 | } |
| 341 | #endif |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 342 | |
Ben Dooks | f42d8ae | 2008-02-05 00:02:21 +0000 | [diff] [blame] | 343 | static int dm9000_ioctl(struct net_device *dev, struct ifreq *req, int cmd) |
| 344 | { |
| 345 | board_info_t *dm = to_dm9000_board(dev); |
| 346 | |
| 347 | if (!netif_running(dev)) |
| 348 | return -EINVAL; |
| 349 | |
| 350 | return generic_mii_ioctl(&dm->mii, if_mii(req), cmd, NULL); |
| 351 | } |
| 352 | |
Ben Dooks | 7da9985 | 2008-02-05 00:02:06 +0000 | [diff] [blame] | 353 | /* ethtool ops */ |
| 354 | |
| 355 | static void dm9000_get_drvinfo(struct net_device *dev, |
| 356 | struct ethtool_drvinfo *info) |
| 357 | { |
| 358 | board_info_t *dm = to_dm9000_board(dev); |
| 359 | |
| 360 | strcpy(info->driver, CARDNAME); |
| 361 | strcpy(info->version, DRV_VERSION); |
| 362 | strcpy(info->bus_info, to_platform_device(dm->dev)->name); |
| 363 | } |
| 364 | |
Ben Dooks | e662ee0 | 2008-02-05 00:02:12 +0000 | [diff] [blame] | 365 | static u32 dm9000_get_msglevel(struct net_device *dev) |
| 366 | { |
| 367 | board_info_t *dm = to_dm9000_board(dev); |
| 368 | |
| 369 | return dm->msg_enable; |
| 370 | } |
| 371 | |
| 372 | static void dm9000_set_msglevel(struct net_device *dev, u32 value) |
| 373 | { |
| 374 | board_info_t *dm = to_dm9000_board(dev); |
| 375 | |
| 376 | dm->msg_enable = value; |
| 377 | } |
| 378 | |
Ben Dooks | 7da9985 | 2008-02-05 00:02:06 +0000 | [diff] [blame] | 379 | static int dm9000_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
| 380 | { |
| 381 | board_info_t *dm = to_dm9000_board(dev); |
Ben Dooks | 7da9985 | 2008-02-05 00:02:06 +0000 | [diff] [blame] | 382 | |
Ben Dooks | 7da9985 | 2008-02-05 00:02:06 +0000 | [diff] [blame] | 383 | mii_ethtool_gset(&dm->mii, cmd); |
Ben Dooks | 7da9985 | 2008-02-05 00:02:06 +0000 | [diff] [blame] | 384 | return 0; |
| 385 | } |
| 386 | |
| 387 | static int dm9000_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
| 388 | { |
| 389 | board_info_t *dm = to_dm9000_board(dev); |
Ben Dooks | 7da9985 | 2008-02-05 00:02:06 +0000 | [diff] [blame] | 390 | |
Ben Dooks | 9a2f037 | 2008-02-05 00:02:10 +0000 | [diff] [blame] | 391 | return mii_ethtool_sset(&dm->mii, cmd); |
Ben Dooks | 7da9985 | 2008-02-05 00:02:06 +0000 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | static int dm9000_nway_reset(struct net_device *dev) |
| 395 | { |
| 396 | board_info_t *dm = to_dm9000_board(dev); |
| 397 | return mii_nway_restart(&dm->mii); |
| 398 | } |
| 399 | |
| 400 | static u32 dm9000_get_link(struct net_device *dev) |
| 401 | { |
| 402 | board_info_t *dm = to_dm9000_board(dev); |
| 403 | return mii_link_ok(&dm->mii); |
| 404 | } |
| 405 | |
Ben Dooks | 29d52e5 | 2008-02-05 00:02:11 +0000 | [diff] [blame] | 406 | #define DM_EEPROM_MAGIC (0x444D394B) |
| 407 | |
| 408 | static int dm9000_get_eeprom_len(struct net_device *dev) |
| 409 | { |
| 410 | return 128; |
| 411 | } |
| 412 | |
| 413 | static int dm9000_get_eeprom(struct net_device *dev, |
| 414 | struct ethtool_eeprom *ee, u8 *data) |
| 415 | { |
| 416 | board_info_t *dm = to_dm9000_board(dev); |
| 417 | int offset = ee->offset; |
| 418 | int len = ee->len; |
| 419 | int i; |
| 420 | |
| 421 | /* EEPROM access is aligned to two bytes */ |
| 422 | |
| 423 | if ((len & 1) != 0 || (offset & 1) != 0) |
| 424 | return -EINVAL; |
| 425 | |
Ben Dooks | bb44fb70 | 2008-02-05 00:02:20 +0000 | [diff] [blame] | 426 | if (dm->flags & DM9000_PLATF_NO_EEPROM) |
| 427 | return -ENOENT; |
| 428 | |
Ben Dooks | 29d52e5 | 2008-02-05 00:02:11 +0000 | [diff] [blame] | 429 | ee->magic = DM_EEPROM_MAGIC; |
| 430 | |
| 431 | for (i = 0; i < len; i += 2) |
| 432 | dm9000_read_eeprom(dm, (offset + i) / 2, data + i); |
| 433 | |
| 434 | return 0; |
| 435 | } |
| 436 | |
| 437 | static int dm9000_set_eeprom(struct net_device *dev, |
| 438 | struct ethtool_eeprom *ee, u8 *data) |
| 439 | { |
| 440 | board_info_t *dm = to_dm9000_board(dev); |
| 441 | int offset = ee->offset; |
| 442 | int len = ee->len; |
| 443 | int i; |
| 444 | |
| 445 | /* EEPROM access is aligned to two bytes */ |
| 446 | |
| 447 | if ((len & 1) != 0 || (offset & 1) != 0) |
| 448 | return -EINVAL; |
| 449 | |
Ben Dooks | bb44fb70 | 2008-02-05 00:02:20 +0000 | [diff] [blame] | 450 | if (dm->flags & DM9000_PLATF_NO_EEPROM) |
| 451 | return -ENOENT; |
| 452 | |
Ben Dooks | 29d52e5 | 2008-02-05 00:02:11 +0000 | [diff] [blame] | 453 | if (ee->magic != DM_EEPROM_MAGIC) |
| 454 | return -EINVAL; |
| 455 | |
| 456 | for (i = 0; i < len; i += 2) |
| 457 | dm9000_write_eeprom(dm, (offset + i) / 2, data + i); |
| 458 | |
| 459 | return 0; |
| 460 | } |
| 461 | |
Ben Dooks | 7da9985 | 2008-02-05 00:02:06 +0000 | [diff] [blame] | 462 | static const struct ethtool_ops dm9000_ethtool_ops = { |
| 463 | .get_drvinfo = dm9000_get_drvinfo, |
| 464 | .get_settings = dm9000_get_settings, |
| 465 | .set_settings = dm9000_set_settings, |
Ben Dooks | e662ee0 | 2008-02-05 00:02:12 +0000 | [diff] [blame] | 466 | .get_msglevel = dm9000_get_msglevel, |
| 467 | .set_msglevel = dm9000_set_msglevel, |
Ben Dooks | 7da9985 | 2008-02-05 00:02:06 +0000 | [diff] [blame] | 468 | .nway_reset = dm9000_nway_reset, |
| 469 | .get_link = dm9000_get_link, |
Ben Dooks | 29d52e5 | 2008-02-05 00:02:11 +0000 | [diff] [blame] | 470 | .get_eeprom_len = dm9000_get_eeprom_len, |
| 471 | .get_eeprom = dm9000_get_eeprom, |
| 472 | .set_eeprom = dm9000_set_eeprom, |
Ben Dooks | 7da9985 | 2008-02-05 00:02:06 +0000 | [diff] [blame] | 473 | }; |
| 474 | |
Ben Dooks | 8f5bf5f2 | 2008-05-08 11:36:42 +0100 | [diff] [blame] | 475 | static void |
| 476 | dm9000_poll_work(struct work_struct *w) |
| 477 | { |
| 478 | struct delayed_work *dw = container_of(w, struct delayed_work, work); |
| 479 | board_info_t *db = container_of(dw, board_info_t, phy_poll); |
| 480 | |
| 481 | mii_check_media(&db->mii, netif_msg_link(db), 0); |
| 482 | |
| 483 | if (netif_running(db->ndev)) |
| 484 | dm9000_schedule_poll(db); |
| 485 | } |
Ben Dooks | 7da9985 | 2008-02-05 00:02:06 +0000 | [diff] [blame] | 486 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 487 | /* dm9000_release_board |
| 488 | * |
| 489 | * release a board, and any mapped resources |
| 490 | */ |
| 491 | |
| 492 | static void |
| 493 | dm9000_release_board(struct platform_device *pdev, struct board_info *db) |
| 494 | { |
| 495 | if (db->data_res == NULL) { |
| 496 | if (db->addr_res != NULL) |
| 497 | release_mem_region((unsigned long)db->io_addr, 4); |
| 498 | return; |
| 499 | } |
| 500 | |
| 501 | /* unmap our resources */ |
| 502 | |
| 503 | iounmap(db->io_addr); |
| 504 | iounmap(db->io_data); |
| 505 | |
| 506 | /* release the resources */ |
| 507 | |
| 508 | if (db->data_req != NULL) { |
| 509 | release_resource(db->data_req); |
| 510 | kfree(db->data_req); |
| 511 | } |
| 512 | |
Dirk Opfer | 5198548 | 2006-09-06 19:53:32 +0200 | [diff] [blame] | 513 | if (db->addr_req != NULL) { |
| 514 | release_resource(db->addr_req); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 515 | kfree(db->addr_req); |
| 516 | } |
| 517 | } |
| 518 | |
| 519 | #define res_size(_r) (((_r)->end - (_r)->start) + 1) |
| 520 | |
| 521 | /* |
| 522 | * Search DM9000 board, allocate space and register it |
| 523 | */ |
Enrico Scholz | e21fd4f | 2008-05-08 11:33:03 +0100 | [diff] [blame] | 524 | static int __devinit |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 525 | dm9000_probe(struct platform_device *pdev) |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 526 | { |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 527 | struct dm9000_plat_data *pdata = pdev->dev.platform_data; |
| 528 | struct board_info *db; /* Point a board information structure */ |
| 529 | struct net_device *ndev; |
Ben Dooks | 179c743 | 2008-02-05 00:02:23 +0000 | [diff] [blame] | 530 | const unsigned char *mac_src; |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 531 | int ret = 0; |
| 532 | int iosize; |
| 533 | int i; |
| 534 | u32 id_val; |
| 535 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 536 | /* Init network device */ |
| 537 | ndev = alloc_etherdev(sizeof (struct board_info)); |
| 538 | if (!ndev) { |
Ben Dooks | a76836f | 2008-02-05 00:02:02 +0000 | [diff] [blame] | 539 | dev_err(&pdev->dev, "could not allocate device.\n"); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 540 | return -ENOMEM; |
| 541 | } |
| 542 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 543 | SET_NETDEV_DEV(ndev, &pdev->dev); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 544 | |
Enrico Scholz | 37d5dca | 2008-05-08 11:35:13 +0100 | [diff] [blame] | 545 | dev_dbg(&pdev->dev, "dm9000_probe()\n"); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 546 | |
| 547 | /* setup board info structure */ |
| 548 | db = (struct board_info *) ndev->priv; |
| 549 | memset(db, 0, sizeof (*db)); |
| 550 | |
Ben Dooks | a76836f | 2008-02-05 00:02:02 +0000 | [diff] [blame] | 551 | db->dev = &pdev->dev; |
Ben Dooks | 8f5bf5f2 | 2008-05-08 11:36:42 +0100 | [diff] [blame] | 552 | db->ndev = ndev; |
Ben Dooks | a76836f | 2008-02-05 00:02:02 +0000 | [diff] [blame] | 553 | |
Ben Dooks | 9ef9ac5 | 2005-07-23 17:25:18 +0100 | [diff] [blame] | 554 | spin_lock_init(&db->lock); |
Ben Dooks | 9a2f037 | 2008-02-05 00:02:10 +0000 | [diff] [blame] | 555 | mutex_init(&db->addr_lock); |
Ben Dooks | 9ef9ac5 | 2005-07-23 17:25:18 +0100 | [diff] [blame] | 556 | |
Ben Dooks | 8f5bf5f2 | 2008-05-08 11:36:42 +0100 | [diff] [blame] | 557 | INIT_DELAYED_WORK(&db->phy_poll, dm9000_poll_work); |
| 558 | |
| 559 | |
Laurent Pinchart | 08c3f57 | 2008-06-24 22:15:57 +0100 | [diff] [blame^] | 560 | if (pdev->num_resources < 3) { |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 561 | ret = -ENODEV; |
| 562 | goto out; |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 563 | } |
| 564 | |
Laurent Pinchart | 08c3f57 | 2008-06-24 22:15:57 +0100 | [diff] [blame^] | 565 | db->addr_res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 566 | db->data_res = platform_get_resource(pdev, IORESOURCE_MEM, 1); |
| 567 | db->irq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); |
| 568 | |
| 569 | if (db->addr_res == NULL || db->data_res == NULL || |
| 570 | db->irq_res == NULL) { |
| 571 | dev_err(db->dev, "insufficient resources\n"); |
| 572 | ret = -ENOENT; |
| 573 | goto out; |
| 574 | } |
| 575 | |
| 576 | iosize = res_size(db->addr_res); |
| 577 | db->addr_req = request_mem_region(db->addr_res->start, iosize, |
| 578 | pdev->name); |
| 579 | |
| 580 | if (db->addr_req == NULL) { |
| 581 | dev_err(db->dev, "cannot claim address reg area\n"); |
| 582 | ret = -EIO; |
| 583 | goto out; |
| 584 | } |
| 585 | |
| 586 | db->io_addr = ioremap(db->addr_res->start, iosize); |
| 587 | |
| 588 | if (db->io_addr == NULL) { |
| 589 | dev_err(db->dev, "failed to ioremap address reg\n"); |
| 590 | ret = -EINVAL; |
| 591 | goto out; |
| 592 | } |
| 593 | |
| 594 | iosize = res_size(db->data_res); |
| 595 | db->data_req = request_mem_region(db->data_res->start, iosize, |
| 596 | pdev->name); |
| 597 | |
| 598 | if (db->data_req == NULL) { |
| 599 | dev_err(db->dev, "cannot claim data reg area\n"); |
| 600 | ret = -EIO; |
| 601 | goto out; |
| 602 | } |
| 603 | |
| 604 | db->io_data = ioremap(db->data_res->start, iosize); |
| 605 | |
| 606 | if (db->io_data == NULL) { |
| 607 | dev_err(db->dev, "failed to ioremap data reg\n"); |
| 608 | ret = -EINVAL; |
| 609 | goto out; |
| 610 | } |
| 611 | |
| 612 | /* fill in parameters for net-dev structure */ |
| 613 | ndev->base_addr = (unsigned long)db->io_addr; |
| 614 | ndev->irq = db->irq_res->start; |
| 615 | |
| 616 | /* ensure at least we have a default set of IO routines */ |
| 617 | dm9000_set_io(db, iosize); |
| 618 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 619 | /* check to see if anything is being over-ridden */ |
| 620 | if (pdata != NULL) { |
| 621 | /* check to see if the driver wants to over-ride the |
| 622 | * default IO width */ |
| 623 | |
| 624 | if (pdata->flags & DM9000_PLATF_8BITONLY) |
| 625 | dm9000_set_io(db, 1); |
| 626 | |
| 627 | if (pdata->flags & DM9000_PLATF_16BITONLY) |
| 628 | dm9000_set_io(db, 2); |
| 629 | |
| 630 | if (pdata->flags & DM9000_PLATF_32BITONLY) |
| 631 | dm9000_set_io(db, 4); |
| 632 | |
| 633 | /* check to see if there are any IO routine |
| 634 | * over-rides */ |
| 635 | |
| 636 | if (pdata->inblk != NULL) |
| 637 | db->inblk = pdata->inblk; |
| 638 | |
| 639 | if (pdata->outblk != NULL) |
| 640 | db->outblk = pdata->outblk; |
| 641 | |
| 642 | if (pdata->dumpblk != NULL) |
| 643 | db->dumpblk = pdata->dumpblk; |
Ben Dooks | 33ba509 | 2008-02-05 00:02:01 +0000 | [diff] [blame] | 644 | |
| 645 | db->flags = pdata->flags; |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | dm9000_reset(db); |
| 649 | |
| 650 | /* try two times, DM9000 sometimes gets the first read wrong */ |
Ben Dooks | 513b6be | 2008-02-05 00:02:22 +0000 | [diff] [blame] | 651 | for (i = 0; i < 8; i++) { |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 652 | id_val = ior(db, DM9000_VIDL); |
| 653 | id_val |= (u32)ior(db, DM9000_VIDH) << 8; |
| 654 | id_val |= (u32)ior(db, DM9000_PIDL) << 16; |
| 655 | id_val |= (u32)ior(db, DM9000_PIDH) << 24; |
| 656 | |
| 657 | if (id_val == DM9000_ID) |
| 658 | break; |
Ben Dooks | a76836f | 2008-02-05 00:02:02 +0000 | [diff] [blame] | 659 | dev_err(db->dev, "read wrong id 0x%08x\n", id_val); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 660 | } |
| 661 | |
| 662 | if (id_val != DM9000_ID) { |
Ben Dooks | a76836f | 2008-02-05 00:02:02 +0000 | [diff] [blame] | 663 | dev_err(db->dev, "wrong id: 0x%08x\n", id_val); |
Mike Rapoport | 418d6f8 | 2007-10-18 09:23:11 +0200 | [diff] [blame] | 664 | ret = -ENODEV; |
| 665 | goto out; |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 666 | } |
| 667 | |
| 668 | /* from this point we assume that we have found a DM9000 */ |
| 669 | |
| 670 | /* driver system function */ |
| 671 | ether_setup(ndev); |
| 672 | |
| 673 | ndev->open = &dm9000_open; |
| 674 | ndev->hard_start_xmit = &dm9000_start_xmit; |
| 675 | ndev->tx_timeout = &dm9000_timeout; |
| 676 | ndev->watchdog_timeo = msecs_to_jiffies(watchdog); |
| 677 | ndev->stop = &dm9000_stop; |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 678 | ndev->set_multicast_list = &dm9000_hash_table; |
Ben Dooks | 7da9985 | 2008-02-05 00:02:06 +0000 | [diff] [blame] | 679 | ndev->ethtool_ops = &dm9000_ethtool_ops; |
Ben Dooks | f42d8ae | 2008-02-05 00:02:21 +0000 | [diff] [blame] | 680 | ndev->do_ioctl = &dm9000_ioctl; |
Ben Dooks | 7da9985 | 2008-02-05 00:02:06 +0000 | [diff] [blame] | 681 | |
Kevin Hao | 2fd0e33 | 2006-08-14 23:00:15 -0700 | [diff] [blame] | 682 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 683 | ndev->poll_controller = &dm9000_poll_controller; |
| 684 | #endif |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 685 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 686 | db->msg_enable = NETIF_MSG_LINK; |
| 687 | db->mii.phy_id_mask = 0x1f; |
| 688 | db->mii.reg_num_mask = 0x1f; |
| 689 | db->mii.force_media = 0; |
| 690 | db->mii.full_duplex = 0; |
| 691 | db->mii.dev = ndev; |
| 692 | db->mii.mdio_read = dm9000_phy_read; |
| 693 | db->mii.mdio_write = dm9000_phy_write; |
| 694 | |
Ben Dooks | 179c743 | 2008-02-05 00:02:23 +0000 | [diff] [blame] | 695 | mac_src = "eeprom"; |
| 696 | |
Ben Dooks | 86c62fa | 2008-02-05 00:02:09 +0000 | [diff] [blame] | 697 | /* try reading the node address from the attached EEPROM */ |
| 698 | for (i = 0; i < 6; i += 2) |
| 699 | dm9000_read_eeprom(db, i / 2, ndev->dev_addr+i); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 700 | |
Ben Dooks | 5b55dda | 2006-06-13 23:50:15 +0100 | [diff] [blame] | 701 | if (!is_valid_ether_addr(ndev->dev_addr)) { |
| 702 | /* try reading from mac */ |
Jeff Garzik | 7d2e3cb | 2008-05-13 01:41:58 -0400 | [diff] [blame] | 703 | |
Ben Dooks | 179c743 | 2008-02-05 00:02:23 +0000 | [diff] [blame] | 704 | mac_src = "chip"; |
Ben Dooks | 5b55dda | 2006-06-13 23:50:15 +0100 | [diff] [blame] | 705 | for (i = 0; i < 6; i++) |
| 706 | ndev->dev_addr[i] = ior(db, i+DM9000_PAR); |
| 707 | } |
| 708 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 709 | if (!is_valid_ether_addr(ndev->dev_addr)) |
Ben Dooks | a76836f | 2008-02-05 00:02:02 +0000 | [diff] [blame] | 710 | dev_warn(db->dev, "%s: Invalid ethernet MAC address. Please " |
| 711 | "set using ifconfig\n", ndev->name); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 712 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 713 | platform_set_drvdata(pdev, ndev); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 714 | ret = register_netdev(ndev); |
| 715 | |
| 716 | if (ret == 0) { |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 717 | DECLARE_MAC_BUF(mac); |
Ben Dooks | 179c743 | 2008-02-05 00:02:23 +0000 | [diff] [blame] | 718 | printk("%s: dm9000 at %p,%p IRQ %d MAC: %s (%s)\n", |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 719 | ndev->name, db->io_addr, db->io_data, ndev->irq, |
Ben Dooks | 179c743 | 2008-02-05 00:02:23 +0000 | [diff] [blame] | 720 | print_mac(mac, ndev->dev_addr), mac_src); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 721 | } |
| 722 | return 0; |
| 723 | |
Mike Rapoport | 418d6f8 | 2007-10-18 09:23:11 +0200 | [diff] [blame] | 724 | out: |
Ben Dooks | a76836f | 2008-02-05 00:02:02 +0000 | [diff] [blame] | 725 | dev_err(db->dev, "not found (%d).\n", ret); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 726 | |
| 727 | dm9000_release_board(pdev, db); |
Ben Dooks | 9fd9f9b | 2007-05-07 11:13:25 +0000 | [diff] [blame] | 728 | free_netdev(ndev); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 729 | |
| 730 | return ret; |
| 731 | } |
| 732 | |
| 733 | /* |
| 734 | * Open the interface. |
| 735 | * The interface is opened whenever "ifconfig" actives it. |
| 736 | */ |
| 737 | static int |
| 738 | dm9000_open(struct net_device *dev) |
| 739 | { |
| 740 | board_info_t *db = (board_info_t *) dev->priv; |
Ben Dooks | 1a5f1c4 | 2008-02-05 00:02:04 +0000 | [diff] [blame] | 741 | unsigned long irqflags = db->irq_res->flags & IRQF_TRIGGER_MASK; |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 742 | |
Ben Dooks | c991d16 | 2008-02-05 00:02:16 +0000 | [diff] [blame] | 743 | if (netif_msg_ifup(db)) |
| 744 | dev_dbg(db->dev, "enabling %s\n", dev->name); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 745 | |
Ben Dooks | 1a5f1c4 | 2008-02-05 00:02:04 +0000 | [diff] [blame] | 746 | /* If there is no IRQ type specified, default to something that |
| 747 | * may work, and tell the user that this is a problem */ |
| 748 | |
| 749 | if (irqflags == IRQF_TRIGGER_NONE) { |
| 750 | dev_warn(db->dev, "WARNING: no IRQ resource flags set.\n"); |
| 751 | irqflags = DEFAULT_TRIGGER; |
| 752 | } |
Jeff Garzik | 7d2e3cb | 2008-05-13 01:41:58 -0400 | [diff] [blame] | 753 | |
Ben Dooks | 1a5f1c4 | 2008-02-05 00:02:04 +0000 | [diff] [blame] | 754 | irqflags |= IRQF_SHARED; |
| 755 | |
| 756 | if (request_irq(dev->irq, &dm9000_interrupt, irqflags, dev->name, dev)) |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 757 | return -EAGAIN; |
| 758 | |
| 759 | /* Initialize DM9000 board */ |
| 760 | dm9000_reset(db); |
| 761 | dm9000_init_dm9000(dev); |
| 762 | |
| 763 | /* Init driver variable */ |
| 764 | db->dbug_cnt = 0; |
| 765 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 766 | mii_check_media(&db->mii, netif_msg_link(db), 1); |
| 767 | netif_start_queue(dev); |
Ben Dooks | 8f5bf5f2 | 2008-05-08 11:36:42 +0100 | [diff] [blame] | 768 | |
| 769 | dm9000_schedule_poll(db); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 770 | |
| 771 | return 0; |
| 772 | } |
| 773 | |
| 774 | /* |
| 775 | * Initilize dm9000 board |
| 776 | */ |
| 777 | static void |
| 778 | dm9000_init_dm9000(struct net_device *dev) |
| 779 | { |
| 780 | board_info_t *db = (board_info_t *) dev->priv; |
| 781 | |
Ben Dooks | 5b2b4ff | 2008-02-05 00:02:03 +0000 | [diff] [blame] | 782 | dm9000_dbg(db, 1, "entering %s\n", __func__); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 783 | |
| 784 | /* I/O mode */ |
| 785 | db->io_mode = ior(db, DM9000_ISR) >> 6; /* ISR bit7:6 keeps I/O mode */ |
| 786 | |
| 787 | /* GPIO0 on pre-activate PHY */ |
| 788 | iow(db, DM9000_GPR, 0); /* REG_1F bit0 activate phyxcer */ |
| 789 | iow(db, DM9000_GPCR, GPCR_GEP_CNTL); /* Let GPIO0 output */ |
| 790 | iow(db, DM9000_GPR, 0); /* Enable PHY */ |
| 791 | |
Ben Dooks | 33ba509 | 2008-02-05 00:02:01 +0000 | [diff] [blame] | 792 | if (db->flags & DM9000_PLATF_EXT_PHY) |
| 793 | iow(db, DM9000_NCR, NCR_EXT_PHY); |
| 794 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 795 | /* Program operating register */ |
| 796 | iow(db, DM9000_TCR, 0); /* TX Polling clear */ |
| 797 | iow(db, DM9000_BPTR, 0x3f); /* Less 3Kb, 200us */ |
| 798 | iow(db, DM9000_FCR, 0xff); /* Flow Control */ |
| 799 | iow(db, DM9000_SMCR, 0); /* Special Mode */ |
| 800 | /* clear TX status */ |
| 801 | iow(db, DM9000_NSR, NSR_WAKEST | NSR_TX2END | NSR_TX1END); |
| 802 | iow(db, DM9000_ISR, ISR_CLR_STATUS); /* Clear interrupt status */ |
| 803 | |
| 804 | /* Set address filter table */ |
| 805 | dm9000_hash_table(dev); |
| 806 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 807 | /* Enable TX/RX interrupt mask */ |
| 808 | iow(db, DM9000_IMR, IMR_PAR | IMR_PTM | IMR_PRM); |
| 809 | |
| 810 | /* Init Driver variable */ |
| 811 | db->tx_pkt_cnt = 0; |
| 812 | db->queue_pkt_len = 0; |
| 813 | dev->trans_start = 0; |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 814 | } |
| 815 | |
| 816 | /* |
| 817 | * Hardware start transmission. |
| 818 | * Send a packet to media from the upper layer. |
| 819 | */ |
| 820 | static int |
| 821 | dm9000_start_xmit(struct sk_buff *skb, struct net_device *dev) |
| 822 | { |
Florian Westphal | c46ac94 | 2007-08-21 01:33:42 +0200 | [diff] [blame] | 823 | unsigned long flags; |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 824 | board_info_t *db = (board_info_t *) dev->priv; |
| 825 | |
Ben Dooks | 5b2b4ff | 2008-02-05 00:02:03 +0000 | [diff] [blame] | 826 | dm9000_dbg(db, 3, "%s:\n", __func__); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 827 | |
| 828 | if (db->tx_pkt_cnt > 1) |
| 829 | return 1; |
| 830 | |
Florian Westphal | c46ac94 | 2007-08-21 01:33:42 +0200 | [diff] [blame] | 831 | spin_lock_irqsave(&db->lock, flags); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 832 | |
| 833 | /* Move data to DM9000 TX RAM */ |
| 834 | writeb(DM9000_MWCMD, db->io_addr); |
| 835 | |
| 836 | (db->outblk)(db->io_data, skb->data, skb->len); |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 837 | dev->stats.tx_bytes += skb->len; |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 838 | |
Florian Westphal | c46ac94 | 2007-08-21 01:33:42 +0200 | [diff] [blame] | 839 | db->tx_pkt_cnt++; |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 840 | /* TX control: First packet immediately send, second packet queue */ |
Florian Westphal | c46ac94 | 2007-08-21 01:33:42 +0200 | [diff] [blame] | 841 | if (db->tx_pkt_cnt == 1) { |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 842 | /* Set TX length to DM9000 */ |
Ben Dooks | 073d3f4 | 2008-02-05 00:02:19 +0000 | [diff] [blame] | 843 | iow(db, DM9000_TXPLL, skb->len); |
| 844 | iow(db, DM9000_TXPLH, skb->len >> 8); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 845 | |
| 846 | /* Issue TX polling command */ |
| 847 | iow(db, DM9000_TCR, TCR_TXREQ); /* Cleared after TX complete */ |
| 848 | |
| 849 | dev->trans_start = jiffies; /* save the time stamp */ |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 850 | } else { |
| 851 | /* Second packet */ |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 852 | db->queue_pkt_len = skb->len; |
Florian Westphal | c46ac94 | 2007-08-21 01:33:42 +0200 | [diff] [blame] | 853 | netif_stop_queue(dev); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 854 | } |
| 855 | |
Florian Westphal | c46ac94 | 2007-08-21 01:33:42 +0200 | [diff] [blame] | 856 | spin_unlock_irqrestore(&db->lock, flags); |
| 857 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 858 | /* free this SKB */ |
| 859 | dev_kfree_skb(skb); |
| 860 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 861 | return 0; |
| 862 | } |
| 863 | |
| 864 | static void |
| 865 | dm9000_shutdown(struct net_device *dev) |
| 866 | { |
| 867 | board_info_t *db = (board_info_t *) dev->priv; |
| 868 | |
| 869 | /* RESET device */ |
| 870 | dm9000_phy_write(dev, 0, MII_BMCR, BMCR_RESET); /* PHY RESET */ |
| 871 | iow(db, DM9000_GPR, 0x01); /* Power-Down PHY */ |
| 872 | iow(db, DM9000_IMR, IMR_PAR); /* Disable all interrupt */ |
| 873 | iow(db, DM9000_RCR, 0x00); /* Disable RX */ |
| 874 | } |
| 875 | |
| 876 | /* |
| 877 | * Stop the interface. |
| 878 | * The interface is stopped when it is brought. |
| 879 | */ |
| 880 | static int |
| 881 | dm9000_stop(struct net_device *ndev) |
| 882 | { |
| 883 | board_info_t *db = (board_info_t *) ndev->priv; |
| 884 | |
Ben Dooks | c991d16 | 2008-02-05 00:02:16 +0000 | [diff] [blame] | 885 | if (netif_msg_ifdown(db)) |
| 886 | dev_dbg(db->dev, "shutting down %s\n", ndev->name); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 887 | |
Andrew Morton | 5bceeda | 2008-05-14 16:20:12 -0700 | [diff] [blame] | 888 | cancel_delayed_work_sync(&db->phy_poll); |
Ben Dooks | 8f5bf5f2 | 2008-05-08 11:36:42 +0100 | [diff] [blame] | 889 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 890 | netif_stop_queue(ndev); |
| 891 | netif_carrier_off(ndev); |
| 892 | |
| 893 | /* free interrupt */ |
| 894 | free_irq(ndev->irq, ndev); |
| 895 | |
| 896 | dm9000_shutdown(ndev); |
| 897 | |
| 898 | return 0; |
| 899 | } |
| 900 | |
| 901 | /* |
| 902 | * DM9000 interrupt handler |
| 903 | * receive the packet to upper layer, free the transmitted packet |
| 904 | */ |
| 905 | |
Ben Dooks | 5d22a31 | 2006-06-14 00:09:17 +0100 | [diff] [blame] | 906 | static void |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 907 | dm9000_tx_done(struct net_device *dev, board_info_t * db) |
| 908 | { |
| 909 | int tx_status = ior(db, DM9000_NSR); /* Got TX status */ |
| 910 | |
| 911 | if (tx_status & (NSR_TX2END | NSR_TX1END)) { |
| 912 | /* One packet sent complete */ |
| 913 | db->tx_pkt_cnt--; |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 914 | dev->stats.tx_packets++; |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 915 | |
Ben Dooks | c991d16 | 2008-02-05 00:02:16 +0000 | [diff] [blame] | 916 | if (netif_msg_tx_done(db)) |
| 917 | dev_dbg(db->dev, "tx done, NSR %02x\n", tx_status); |
| 918 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 919 | /* Queue packet check & send */ |
| 920 | if (db->tx_pkt_cnt > 0) { |
Ben Dooks | 073d3f4 | 2008-02-05 00:02:19 +0000 | [diff] [blame] | 921 | iow(db, DM9000_TXPLL, db->queue_pkt_len); |
| 922 | iow(db, DM9000_TXPLH, db->queue_pkt_len >> 8); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 923 | iow(db, DM9000_TCR, TCR_TXREQ); |
| 924 | dev->trans_start = jiffies; |
| 925 | } |
| 926 | netif_wake_queue(dev); |
| 927 | } |
| 928 | } |
| 929 | |
| 930 | static irqreturn_t |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 931 | dm9000_interrupt(int irq, void *dev_id) |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 932 | { |
| 933 | struct net_device *dev = dev_id; |
Ben Dooks | 5b2b4ff | 2008-02-05 00:02:03 +0000 | [diff] [blame] | 934 | board_info_t *db = (board_info_t *) dev->priv; |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 935 | int int_status; |
| 936 | u8 reg_save; |
| 937 | |
Ben Dooks | 5b2b4ff | 2008-02-05 00:02:03 +0000 | [diff] [blame] | 938 | dm9000_dbg(db, 3, "entering %s\n", __func__); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 939 | |
| 940 | /* A real interrupt coming */ |
Ben Dooks | 5b2b4ff | 2008-02-05 00:02:03 +0000 | [diff] [blame] | 941 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 942 | spin_lock(&db->lock); |
| 943 | |
| 944 | /* Save previous register address */ |
| 945 | reg_save = readb(db->io_addr); |
| 946 | |
| 947 | /* Disable all interrupts */ |
| 948 | iow(db, DM9000_IMR, IMR_PAR); |
| 949 | |
| 950 | /* Got DM9000 interrupt status */ |
| 951 | int_status = ior(db, DM9000_ISR); /* Got ISR */ |
| 952 | iow(db, DM9000_ISR, int_status); /* Clear ISR status */ |
| 953 | |
Ben Dooks | c991d16 | 2008-02-05 00:02:16 +0000 | [diff] [blame] | 954 | if (netif_msg_intr(db)) |
| 955 | dev_dbg(db->dev, "interrupt status %02x\n", int_status); |
| 956 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 957 | /* Received the coming packet */ |
| 958 | if (int_status & ISR_PRS) |
| 959 | dm9000_rx(dev); |
| 960 | |
| 961 | /* Trnasmit Interrupt check */ |
| 962 | if (int_status & ISR_PTS) |
| 963 | dm9000_tx_done(dev, db); |
| 964 | |
| 965 | /* Re-enable interrupt mask */ |
| 966 | iow(db, DM9000_IMR, IMR_PAR | IMR_PTM | IMR_PRM); |
| 967 | |
| 968 | /* Restore previous register address */ |
| 969 | writeb(reg_save, db->io_addr); |
| 970 | |
| 971 | spin_unlock(&db->lock); |
| 972 | |
| 973 | return IRQ_HANDLED; |
| 974 | } |
| 975 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 976 | struct dm9000_rxhdr { |
Ben Dooks | 9311657 | 2008-02-05 00:02:00 +0000 | [diff] [blame] | 977 | u8 RxPktReady; |
| 978 | u8 RxStatus; |
Al Viro | 8b9fc8a | 2008-03-29 03:11:08 +0000 | [diff] [blame] | 979 | __le16 RxLen; |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 980 | } __attribute__((__packed__)); |
| 981 | |
| 982 | /* |
| 983 | * Received a packet and pass to upper layer |
| 984 | */ |
| 985 | static void |
| 986 | dm9000_rx(struct net_device *dev) |
| 987 | { |
| 988 | board_info_t *db = (board_info_t *) dev->priv; |
| 989 | struct dm9000_rxhdr rxhdr; |
| 990 | struct sk_buff *skb; |
| 991 | u8 rxbyte, *rdptr; |
Richard Knutsson | 6478fac | 2007-05-01 18:43:27 +0200 | [diff] [blame] | 992 | bool GoodPacket; |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 993 | int RxLen; |
| 994 | |
| 995 | /* Check packet ready or not */ |
| 996 | do { |
| 997 | ior(db, DM9000_MRCMDX); /* Dummy read */ |
| 998 | |
| 999 | /* Get most updated data */ |
| 1000 | rxbyte = readb(db->io_data); |
| 1001 | |
| 1002 | /* Status check: this byte must be 0 or 1 */ |
| 1003 | if (rxbyte > DM9000_PKT_RDY) { |
Ben Dooks | a76836f | 2008-02-05 00:02:02 +0000 | [diff] [blame] | 1004 | dev_warn(db->dev, "status check fail: %d\n", rxbyte); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1005 | iow(db, DM9000_RCR, 0x00); /* Stop Device */ |
| 1006 | iow(db, DM9000_ISR, IMR_PAR); /* Stop INT request */ |
| 1007 | return; |
| 1008 | } |
| 1009 | |
| 1010 | if (rxbyte != DM9000_PKT_RDY) |
| 1011 | return; |
| 1012 | |
| 1013 | /* A packet ready now & Get status/length */ |
Richard Knutsson | 6478fac | 2007-05-01 18:43:27 +0200 | [diff] [blame] | 1014 | GoodPacket = true; |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1015 | writeb(DM9000_MRCMD, db->io_addr); |
| 1016 | |
| 1017 | (db->inblk)(db->io_data, &rxhdr, sizeof(rxhdr)); |
| 1018 | |
Ben Dooks | 9311657 | 2008-02-05 00:02:00 +0000 | [diff] [blame] | 1019 | RxLen = le16_to_cpu(rxhdr.RxLen); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1020 | |
Ben Dooks | c991d16 | 2008-02-05 00:02:16 +0000 | [diff] [blame] | 1021 | if (netif_msg_rx_status(db)) |
| 1022 | dev_dbg(db->dev, "RX: status %02x, length %04x\n", |
| 1023 | rxhdr.RxStatus, RxLen); |
| 1024 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1025 | /* Packet Status check */ |
| 1026 | if (RxLen < 0x40) { |
Richard Knutsson | 6478fac | 2007-05-01 18:43:27 +0200 | [diff] [blame] | 1027 | GoodPacket = false; |
Ben Dooks | c991d16 | 2008-02-05 00:02:16 +0000 | [diff] [blame] | 1028 | if (netif_msg_rx_err(db)) |
| 1029 | dev_dbg(db->dev, "RX: Bad Packet (runt)\n"); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1030 | } |
| 1031 | |
| 1032 | if (RxLen > DM9000_PKT_MAX) { |
Ben Dooks | a76836f | 2008-02-05 00:02:02 +0000 | [diff] [blame] | 1033 | dev_dbg(db->dev, "RST: RX Len:%x\n", RxLen); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1034 | } |
| 1035 | |
Ben Dooks | 9311657 | 2008-02-05 00:02:00 +0000 | [diff] [blame] | 1036 | if (rxhdr.RxStatus & 0xbf) { |
Richard Knutsson | 6478fac | 2007-05-01 18:43:27 +0200 | [diff] [blame] | 1037 | GoodPacket = false; |
Ben Dooks | 9311657 | 2008-02-05 00:02:00 +0000 | [diff] [blame] | 1038 | if (rxhdr.RxStatus & 0x01) { |
Ben Dooks | c991d16 | 2008-02-05 00:02:16 +0000 | [diff] [blame] | 1039 | if (netif_msg_rx_err(db)) |
| 1040 | dev_dbg(db->dev, "fifo error\n"); |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 1041 | dev->stats.rx_fifo_errors++; |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1042 | } |
Ben Dooks | 9311657 | 2008-02-05 00:02:00 +0000 | [diff] [blame] | 1043 | if (rxhdr.RxStatus & 0x02) { |
Ben Dooks | c991d16 | 2008-02-05 00:02:16 +0000 | [diff] [blame] | 1044 | if (netif_msg_rx_err(db)) |
| 1045 | dev_dbg(db->dev, "crc error\n"); |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 1046 | dev->stats.rx_crc_errors++; |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1047 | } |
Ben Dooks | 9311657 | 2008-02-05 00:02:00 +0000 | [diff] [blame] | 1048 | if (rxhdr.RxStatus & 0x80) { |
Ben Dooks | c991d16 | 2008-02-05 00:02:16 +0000 | [diff] [blame] | 1049 | if (netif_msg_rx_err(db)) |
| 1050 | dev_dbg(db->dev, "length error\n"); |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 1051 | dev->stats.rx_length_errors++; |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1052 | } |
| 1053 | } |
| 1054 | |
| 1055 | /* Move data from DM9000 */ |
| 1056 | if (GoodPacket |
| 1057 | && ((skb = dev_alloc_skb(RxLen + 4)) != NULL)) { |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1058 | skb_reserve(skb, 2); |
| 1059 | rdptr = (u8 *) skb_put(skb, RxLen - 4); |
| 1060 | |
| 1061 | /* Read received packet from RX SRAM */ |
| 1062 | |
| 1063 | (db->inblk)(db->io_data, rdptr, RxLen); |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 1064 | dev->stats.rx_bytes += RxLen; |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1065 | |
| 1066 | /* Pass to upper layer */ |
| 1067 | skb->protocol = eth_type_trans(skb, dev); |
| 1068 | netif_rx(skb); |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 1069 | dev->stats.rx_packets++; |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1070 | |
| 1071 | } else { |
| 1072 | /* need to dump the packet's data */ |
| 1073 | |
| 1074 | (db->dumpblk)(db->io_data, RxLen); |
| 1075 | } |
| 1076 | } while (rxbyte == DM9000_PKT_RDY); |
| 1077 | } |
| 1078 | |
Ben Dooks | 39c341a | 2008-02-05 00:02:17 +0000 | [diff] [blame] | 1079 | static unsigned int |
| 1080 | dm9000_read_locked(board_info_t *db, int reg) |
| 1081 | { |
| 1082 | unsigned long flags; |
| 1083 | unsigned int ret; |
| 1084 | |
| 1085 | spin_lock_irqsave(&db->lock, flags); |
| 1086 | ret = ior(db, reg); |
| 1087 | spin_unlock_irqrestore(&db->lock, flags); |
| 1088 | |
| 1089 | return ret; |
| 1090 | } |
| 1091 | |
| 1092 | static int dm9000_wait_eeprom(board_info_t *db) |
| 1093 | { |
| 1094 | unsigned int status; |
| 1095 | int timeout = 8; /* wait max 8msec */ |
| 1096 | |
| 1097 | /* The DM9000 data sheets say we should be able to |
| 1098 | * poll the ERRE bit in EPCR to wait for the EEPROM |
| 1099 | * operation. From testing several chips, this bit |
Jeff Garzik | 7d2e3cb | 2008-05-13 01:41:58 -0400 | [diff] [blame] | 1100 | * does not seem to work. |
Ben Dooks | 39c341a | 2008-02-05 00:02:17 +0000 | [diff] [blame] | 1101 | * |
| 1102 | * We attempt to use the bit, but fall back to the |
| 1103 | * timeout (which is why we do not return an error |
| 1104 | * on expiry) to say that the EEPROM operation has |
| 1105 | * completed. |
| 1106 | */ |
| 1107 | |
| 1108 | while (1) { |
| 1109 | status = dm9000_read_locked(db, DM9000_EPCR); |
| 1110 | |
| 1111 | if ((status & EPCR_ERRE) == 0) |
| 1112 | break; |
| 1113 | |
| 1114 | if (timeout-- < 0) { |
| 1115 | dev_dbg(db->dev, "timeout waiting EEPROM\n"); |
| 1116 | break; |
| 1117 | } |
| 1118 | } |
| 1119 | |
| 1120 | return 0; |
| 1121 | } |
| 1122 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1123 | /* |
Ben Dooks | 86c62fa | 2008-02-05 00:02:09 +0000 | [diff] [blame] | 1124 | * Read a word data from EEPROM |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1125 | */ |
Ben Dooks | 86c62fa | 2008-02-05 00:02:09 +0000 | [diff] [blame] | 1126 | static void |
Ben Dooks | 29d52e5 | 2008-02-05 00:02:11 +0000 | [diff] [blame] | 1127 | dm9000_read_eeprom(board_info_t *db, int offset, u8 *to) |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1128 | { |
Ben Dooks | 621ddcb | 2008-02-05 00:02:14 +0000 | [diff] [blame] | 1129 | unsigned long flags; |
| 1130 | |
Ben Dooks | bb44fb70 | 2008-02-05 00:02:20 +0000 | [diff] [blame] | 1131 | if (db->flags & DM9000_PLATF_NO_EEPROM) { |
| 1132 | to[0] = 0xff; |
| 1133 | to[1] = 0xff; |
| 1134 | return; |
| 1135 | } |
| 1136 | |
Ben Dooks | 9a2f037 | 2008-02-05 00:02:10 +0000 | [diff] [blame] | 1137 | mutex_lock(&db->addr_lock); |
| 1138 | |
Ben Dooks | 621ddcb | 2008-02-05 00:02:14 +0000 | [diff] [blame] | 1139 | spin_lock_irqsave(&db->lock, flags); |
| 1140 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1141 | iow(db, DM9000_EPAR, offset); |
| 1142 | iow(db, DM9000_EPCR, EPCR_ERPRR); |
Ben Dooks | 621ddcb | 2008-02-05 00:02:14 +0000 | [diff] [blame] | 1143 | |
| 1144 | spin_unlock_irqrestore(&db->lock, flags); |
| 1145 | |
Ben Dooks | 39c341a | 2008-02-05 00:02:17 +0000 | [diff] [blame] | 1146 | dm9000_wait_eeprom(db); |
| 1147 | |
| 1148 | /* delay for at-least 150uS */ |
| 1149 | msleep(1); |
Ben Dooks | 621ddcb | 2008-02-05 00:02:14 +0000 | [diff] [blame] | 1150 | |
| 1151 | spin_lock_irqsave(&db->lock, flags); |
| 1152 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1153 | iow(db, DM9000_EPCR, 0x0); |
Ben Dooks | 86c62fa | 2008-02-05 00:02:09 +0000 | [diff] [blame] | 1154 | |
| 1155 | to[0] = ior(db, DM9000_EPDRL); |
| 1156 | to[1] = ior(db, DM9000_EPDRH); |
Ben Dooks | 9a2f037 | 2008-02-05 00:02:10 +0000 | [diff] [blame] | 1157 | |
Ben Dooks | 621ddcb | 2008-02-05 00:02:14 +0000 | [diff] [blame] | 1158 | spin_unlock_irqrestore(&db->lock, flags); |
| 1159 | |
Ben Dooks | 9a2f037 | 2008-02-05 00:02:10 +0000 | [diff] [blame] | 1160 | mutex_unlock(&db->addr_lock); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1161 | } |
| 1162 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1163 | /* |
| 1164 | * Write a word data to SROM |
| 1165 | */ |
| 1166 | static void |
Ben Dooks | 29d52e5 | 2008-02-05 00:02:11 +0000 | [diff] [blame] | 1167 | dm9000_write_eeprom(board_info_t *db, int offset, u8 *data) |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1168 | { |
Ben Dooks | 621ddcb | 2008-02-05 00:02:14 +0000 | [diff] [blame] | 1169 | unsigned long flags; |
| 1170 | |
Ben Dooks | bb44fb70 | 2008-02-05 00:02:20 +0000 | [diff] [blame] | 1171 | if (db->flags & DM9000_PLATF_NO_EEPROM) |
| 1172 | return; |
| 1173 | |
Ben Dooks | 9a2f037 | 2008-02-05 00:02:10 +0000 | [diff] [blame] | 1174 | mutex_lock(&db->addr_lock); |
| 1175 | |
Ben Dooks | 621ddcb | 2008-02-05 00:02:14 +0000 | [diff] [blame] | 1176 | spin_lock_irqsave(&db->lock, flags); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1177 | iow(db, DM9000_EPAR, offset); |
Ben Dooks | 29d52e5 | 2008-02-05 00:02:11 +0000 | [diff] [blame] | 1178 | iow(db, DM9000_EPDRH, data[1]); |
| 1179 | iow(db, DM9000_EPDRL, data[0]); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1180 | iow(db, DM9000_EPCR, EPCR_WEP | EPCR_ERPRW); |
Ben Dooks | 621ddcb | 2008-02-05 00:02:14 +0000 | [diff] [blame] | 1181 | spin_unlock_irqrestore(&db->lock, flags); |
| 1182 | |
Ben Dooks | 39c341a | 2008-02-05 00:02:17 +0000 | [diff] [blame] | 1183 | dm9000_wait_eeprom(db); |
| 1184 | |
| 1185 | mdelay(1); /* wait at least 150uS to clear */ |
Ben Dooks | 621ddcb | 2008-02-05 00:02:14 +0000 | [diff] [blame] | 1186 | |
| 1187 | spin_lock_irqsave(&db->lock, flags); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1188 | iow(db, DM9000_EPCR, 0); |
Ben Dooks | 621ddcb | 2008-02-05 00:02:14 +0000 | [diff] [blame] | 1189 | spin_unlock_irqrestore(&db->lock, flags); |
Ben Dooks | 9a2f037 | 2008-02-05 00:02:10 +0000 | [diff] [blame] | 1190 | |
| 1191 | mutex_unlock(&db->addr_lock); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1192 | } |
| 1193 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1194 | /* |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1195 | * Set DM9000 multicast address |
| 1196 | */ |
| 1197 | static void |
| 1198 | dm9000_hash_table(struct net_device *dev) |
| 1199 | { |
| 1200 | board_info_t *db = (board_info_t *) dev->priv; |
| 1201 | struct dev_mc_list *mcptr = dev->mc_list; |
| 1202 | int mc_cnt = dev->mc_count; |
Ben Dooks | d39cb786 | 2008-02-05 00:02:18 +0000 | [diff] [blame] | 1203 | int i, oft; |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1204 | u32 hash_val; |
Ben Dooks | d39cb786 | 2008-02-05 00:02:18 +0000 | [diff] [blame] | 1205 | u16 hash_table[4]; |
Peter Korsgaard | 23d245b | 2008-03-18 23:17:16 +0100 | [diff] [blame] | 1206 | u8 rcr = RCR_DIS_LONG | RCR_DIS_CRC | RCR_RXEN; |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1207 | unsigned long flags; |
| 1208 | |
Ben Dooks | 5b2b4ff | 2008-02-05 00:02:03 +0000 | [diff] [blame] | 1209 | dm9000_dbg(db, 1, "entering %s\n", __func__); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1210 | |
Ben Dooks | d39cb786 | 2008-02-05 00:02:18 +0000 | [diff] [blame] | 1211 | spin_lock_irqsave(&db->lock, flags); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1212 | |
Ben Dooks | d39cb786 | 2008-02-05 00:02:18 +0000 | [diff] [blame] | 1213 | for (i = 0, oft = DM9000_PAR; i < 6; i++, oft++) |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1214 | iow(db, oft, dev->dev_addr[i]); |
| 1215 | |
| 1216 | /* Clear Hash Table */ |
| 1217 | for (i = 0; i < 4; i++) |
| 1218 | hash_table[i] = 0x0; |
| 1219 | |
| 1220 | /* broadcast address */ |
| 1221 | hash_table[3] = 0x8000; |
| 1222 | |
Peter Korsgaard | 23d245b | 2008-03-18 23:17:16 +0100 | [diff] [blame] | 1223 | if (dev->flags & IFF_PROMISC) |
| 1224 | rcr |= RCR_PRMSC; |
| 1225 | |
| 1226 | if (dev->flags & IFF_ALLMULTI) |
| 1227 | rcr |= RCR_ALL; |
| 1228 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1229 | /* the multicast address in Hash Table : 64 bits */ |
| 1230 | for (i = 0; i < mc_cnt; i++, mcptr = mcptr->next) { |
Ben Dooks | d39cb786 | 2008-02-05 00:02:18 +0000 | [diff] [blame] | 1231 | hash_val = ether_crc_le(6, mcptr->dmi_addr) & 0x3f; |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1232 | hash_table[hash_val / 16] |= (u16) 1 << (hash_val % 16); |
| 1233 | } |
| 1234 | |
| 1235 | /* Write the hash table to MAC MD table */ |
Ben Dooks | d39cb786 | 2008-02-05 00:02:18 +0000 | [diff] [blame] | 1236 | for (i = 0, oft = DM9000_MAR; i < 4; i++) { |
| 1237 | iow(db, oft++, hash_table[i]); |
| 1238 | iow(db, oft++, hash_table[i] >> 8); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1239 | } |
| 1240 | |
Peter Korsgaard | 23d245b | 2008-03-18 23:17:16 +0100 | [diff] [blame] | 1241 | iow(db, DM9000_RCR, rcr); |
Ben Dooks | d39cb786 | 2008-02-05 00:02:18 +0000 | [diff] [blame] | 1242 | spin_unlock_irqrestore(&db->lock, flags); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1243 | } |
| 1244 | |
| 1245 | |
| 1246 | /* |
Ben Dooks | 321f69a | 2008-02-05 00:02:08 +0000 | [diff] [blame] | 1247 | * Sleep, either by using msleep() or if we are suspending, then |
| 1248 | * use mdelay() to sleep. |
| 1249 | */ |
| 1250 | static void dm9000_msleep(board_info_t *db, unsigned int ms) |
| 1251 | { |
| 1252 | if (db->in_suspend) |
| 1253 | mdelay(ms); |
| 1254 | else |
| 1255 | msleep(ms); |
| 1256 | } |
| 1257 | |
| 1258 | /* |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1259 | * Read a word from phyxcer |
| 1260 | */ |
| 1261 | static int |
| 1262 | dm9000_phy_read(struct net_device *dev, int phy_reg_unused, int reg) |
| 1263 | { |
| 1264 | board_info_t *db = (board_info_t *) dev->priv; |
| 1265 | unsigned long flags; |
Ben Dooks | 9ef9ac5 | 2005-07-23 17:25:18 +0100 | [diff] [blame] | 1266 | unsigned int reg_save; |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1267 | int ret; |
| 1268 | |
Ben Dooks | 9a2f037 | 2008-02-05 00:02:10 +0000 | [diff] [blame] | 1269 | mutex_lock(&db->addr_lock); |
| 1270 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1271 | spin_lock_irqsave(&db->lock,flags); |
Ben Dooks | 9ef9ac5 | 2005-07-23 17:25:18 +0100 | [diff] [blame] | 1272 | |
| 1273 | /* Save previous register address */ |
| 1274 | reg_save = readb(db->io_addr); |
| 1275 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1276 | /* Fill the phyxcer register into REG_0C */ |
| 1277 | iow(db, DM9000_EPAR, DM9000_PHY | reg); |
| 1278 | |
| 1279 | iow(db, DM9000_EPCR, 0xc); /* Issue phyxcer read command */ |
Ben Dooks | 89c8b0e | 2008-02-05 00:02:07 +0000 | [diff] [blame] | 1280 | |
| 1281 | writeb(reg_save, db->io_addr); |
| 1282 | spin_unlock_irqrestore(&db->lock,flags); |
| 1283 | |
Ben Dooks | 321f69a | 2008-02-05 00:02:08 +0000 | [diff] [blame] | 1284 | dm9000_msleep(db, 1); /* Wait read complete */ |
Ben Dooks | 89c8b0e | 2008-02-05 00:02:07 +0000 | [diff] [blame] | 1285 | |
| 1286 | spin_lock_irqsave(&db->lock,flags); |
| 1287 | reg_save = readb(db->io_addr); |
| 1288 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1289 | iow(db, DM9000_EPCR, 0x0); /* Clear phyxcer read command */ |
| 1290 | |
| 1291 | /* The read data keeps on REG_0D & REG_0E */ |
| 1292 | ret = (ior(db, DM9000_EPDRH) << 8) | ior(db, DM9000_EPDRL); |
| 1293 | |
Ben Dooks | 9ef9ac5 | 2005-07-23 17:25:18 +0100 | [diff] [blame] | 1294 | /* restore the previous address */ |
| 1295 | writeb(reg_save, db->io_addr); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1296 | spin_unlock_irqrestore(&db->lock,flags); |
| 1297 | |
Ben Dooks | 9a2f037 | 2008-02-05 00:02:10 +0000 | [diff] [blame] | 1298 | mutex_unlock(&db->addr_lock); |
Enrico Scholz | 37d5dca | 2008-05-08 11:35:13 +0100 | [diff] [blame] | 1299 | |
| 1300 | dm9000_dbg(db, 5, "phy_read[%02x] -> %04x\n", reg, ret); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1301 | return ret; |
| 1302 | } |
| 1303 | |
| 1304 | /* |
| 1305 | * Write a word to phyxcer |
| 1306 | */ |
| 1307 | static void |
| 1308 | dm9000_phy_write(struct net_device *dev, int phyaddr_unused, int reg, int value) |
| 1309 | { |
| 1310 | board_info_t *db = (board_info_t *) dev->priv; |
| 1311 | unsigned long flags; |
Ben Dooks | 9ef9ac5 | 2005-07-23 17:25:18 +0100 | [diff] [blame] | 1312 | unsigned long reg_save; |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1313 | |
Enrico Scholz | 37d5dca | 2008-05-08 11:35:13 +0100 | [diff] [blame] | 1314 | dm9000_dbg(db, 5, "phy_write[%02x] = %04x\n", reg, value); |
Ben Dooks | 9a2f037 | 2008-02-05 00:02:10 +0000 | [diff] [blame] | 1315 | mutex_lock(&db->addr_lock); |
| 1316 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1317 | spin_lock_irqsave(&db->lock,flags); |
| 1318 | |
Ben Dooks | 9ef9ac5 | 2005-07-23 17:25:18 +0100 | [diff] [blame] | 1319 | /* Save previous register address */ |
| 1320 | reg_save = readb(db->io_addr); |
| 1321 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1322 | /* Fill the phyxcer register into REG_0C */ |
| 1323 | iow(db, DM9000_EPAR, DM9000_PHY | reg); |
| 1324 | |
| 1325 | /* Fill the written data into REG_0D & REG_0E */ |
Ben Dooks | 073d3f4 | 2008-02-05 00:02:19 +0000 | [diff] [blame] | 1326 | iow(db, DM9000_EPDRL, value); |
| 1327 | iow(db, DM9000_EPDRH, value >> 8); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1328 | |
| 1329 | iow(db, DM9000_EPCR, 0xa); /* Issue phyxcer write command */ |
Ben Dooks | 89c8b0e | 2008-02-05 00:02:07 +0000 | [diff] [blame] | 1330 | |
| 1331 | writeb(reg_save, db->io_addr); |
Ben Dooks | 9a2f037 | 2008-02-05 00:02:10 +0000 | [diff] [blame] | 1332 | spin_unlock_irqrestore(&db->lock, flags); |
Ben Dooks | 89c8b0e | 2008-02-05 00:02:07 +0000 | [diff] [blame] | 1333 | |
Ben Dooks | 321f69a | 2008-02-05 00:02:08 +0000 | [diff] [blame] | 1334 | dm9000_msleep(db, 1); /* Wait write complete */ |
Ben Dooks | 89c8b0e | 2008-02-05 00:02:07 +0000 | [diff] [blame] | 1335 | |
| 1336 | spin_lock_irqsave(&db->lock,flags); |
| 1337 | reg_save = readb(db->io_addr); |
| 1338 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1339 | iow(db, DM9000_EPCR, 0x0); /* Clear phyxcer write command */ |
| 1340 | |
Ben Dooks | 9ef9ac5 | 2005-07-23 17:25:18 +0100 | [diff] [blame] | 1341 | /* restore the previous address */ |
| 1342 | writeb(reg_save, db->io_addr); |
| 1343 | |
Ben Dooks | 9a2f037 | 2008-02-05 00:02:10 +0000 | [diff] [blame] | 1344 | spin_unlock_irqrestore(&db->lock, flags); |
| 1345 | mutex_unlock(&db->addr_lock); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1346 | } |
| 1347 | |
| 1348 | static int |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1349 | dm9000_drv_suspend(struct platform_device *dev, pm_message_t state) |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1350 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1351 | struct net_device *ndev = platform_get_drvdata(dev); |
Ben Dooks | 321f69a | 2008-02-05 00:02:08 +0000 | [diff] [blame] | 1352 | board_info_t *db; |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1353 | |
Russell King | 9480e30 | 2005-10-28 09:52:56 -0700 | [diff] [blame] | 1354 | if (ndev) { |
Ben Dooks | 321f69a | 2008-02-05 00:02:08 +0000 | [diff] [blame] | 1355 | db = (board_info_t *) ndev->priv; |
| 1356 | db->in_suspend = 1; |
| 1357 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1358 | if (netif_running(ndev)) { |
| 1359 | netif_device_detach(ndev); |
| 1360 | dm9000_shutdown(ndev); |
| 1361 | } |
| 1362 | } |
| 1363 | return 0; |
| 1364 | } |
| 1365 | |
| 1366 | static int |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1367 | dm9000_drv_resume(struct platform_device *dev) |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1368 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1369 | struct net_device *ndev = platform_get_drvdata(dev); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1370 | board_info_t *db = (board_info_t *) ndev->priv; |
| 1371 | |
Russell King | 9480e30 | 2005-10-28 09:52:56 -0700 | [diff] [blame] | 1372 | if (ndev) { |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1373 | |
| 1374 | if (netif_running(ndev)) { |
| 1375 | dm9000_reset(db); |
| 1376 | dm9000_init_dm9000(ndev); |
| 1377 | |
| 1378 | netif_device_attach(ndev); |
| 1379 | } |
Ben Dooks | 321f69a | 2008-02-05 00:02:08 +0000 | [diff] [blame] | 1380 | |
| 1381 | db->in_suspend = 0; |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1382 | } |
| 1383 | return 0; |
| 1384 | } |
| 1385 | |
Enrico Scholz | e21fd4f | 2008-05-08 11:33:03 +0100 | [diff] [blame] | 1386 | static int __devexit |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1387 | dm9000_drv_remove(struct platform_device *pdev) |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1388 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1389 | struct net_device *ndev = platform_get_drvdata(pdev); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1390 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1391 | platform_set_drvdata(pdev, NULL); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1392 | |
| 1393 | unregister_netdev(ndev); |
| 1394 | dm9000_release_board(pdev, (board_info_t *) ndev->priv); |
Ben Dooks | 9fd9f9b | 2007-05-07 11:13:25 +0000 | [diff] [blame] | 1395 | free_netdev(ndev); /* free device structure */ |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1396 | |
Ben Dooks | a76836f | 2008-02-05 00:02:02 +0000 | [diff] [blame] | 1397 | dev_dbg(&pdev->dev, "released and freed device\n"); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1398 | return 0; |
| 1399 | } |
| 1400 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1401 | static struct platform_driver dm9000_driver = { |
Ben Dooks | 5d22a31 | 2006-06-14 00:09:17 +0100 | [diff] [blame] | 1402 | .driver = { |
| 1403 | .name = "dm9000", |
| 1404 | .owner = THIS_MODULE, |
| 1405 | }, |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1406 | .probe = dm9000_probe, |
Enrico Scholz | e21fd4f | 2008-05-08 11:33:03 +0100 | [diff] [blame] | 1407 | .remove = __devexit_p(dm9000_drv_remove), |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1408 | .suspend = dm9000_drv_suspend, |
| 1409 | .resume = dm9000_drv_resume, |
| 1410 | }; |
| 1411 | |
| 1412 | static int __init |
| 1413 | dm9000_init(void) |
| 1414 | { |
Ben Dooks | 7da9985 | 2008-02-05 00:02:06 +0000 | [diff] [blame] | 1415 | printk(KERN_INFO "%s Ethernet Driver, V%s\n", CARDNAME, DRV_VERSION); |
Ben Dooks | 2ae2d77 | 2005-07-23 17:29:38 +0100 | [diff] [blame] | 1416 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1417 | return platform_driver_register(&dm9000_driver); /* search board and register */ |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1418 | } |
| 1419 | |
| 1420 | static void __exit |
| 1421 | dm9000_cleanup(void) |
| 1422 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1423 | platform_driver_unregister(&dm9000_driver); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1424 | } |
| 1425 | |
| 1426 | module_init(dm9000_init); |
| 1427 | module_exit(dm9000_cleanup); |
| 1428 | |
| 1429 | MODULE_AUTHOR("Sascha Hauer, Ben Dooks"); |
| 1430 | MODULE_DESCRIPTION("Davicom DM9000 network driver"); |
| 1431 | MODULE_LICENSE("GPL"); |
Kay Sievers | 72abb46 | 2008-04-18 13:50:44 -0700 | [diff] [blame] | 1432 | MODULE_ALIAS("platform:dm9000"); |