1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Davicom DM9000 Fast Ethernet driver for Linux.
4 * Copyright (C) 1997 Sten Wang
6 * (C) Copyright 1997-1998 DAVICOM Semiconductor,Inc. All Rights Reserved.
8 * Additional updates, Copyright:
13 #include <linux/module.h>
14 #include <linux/ioport.h>
15 #include <linux/netdevice.h>
16 #include <linux/etherdevice.h>
17 #include <linux/interrupt.h>
18 #include <linux/skbuff.h>
19 #include <linux/spinlock.h>
20 #include <linux/crc32.h>
21 #include <linux/mii.h>
23 #include <linux/of_net.h>
24 #include <linux/ethtool.h>
25 #include <linux/dm9000.h>
26 #include <linux/delay.h>
27 #include <linux/platform_device.h>
28 #include <linux/irq.h>
29 #include <linux/slab.h>
30 #include <linux/regulator/consumer.h>
31 #include <linux/gpio/consumer.h>
33 #include <asm/delay.h>
39 /* Board/System/Debug information/definition ---------------- */
41 #define DM9000_PHY 0x40 /* PHY address 0x01 */
43 #define CARDNAME "dm9000"
46 * Transmit timeout, default 5 seconds.
48 static int watchdog = 5000;
49 module_param(watchdog, int, 0400);
50 MODULE_PARM_DESC(watchdog, "transmit timeout in milliseconds");
53 * Debug messages level
56 module_param(debug, int, 0644);
57 MODULE_PARM_DESC(debug, "dm9000 debug level (0-6)");
59 /* DM9000 register address locking.
61 * The DM9000 uses an address register to control where data written
62 * to the data register goes. This means that the address register
63 * must be preserved over interrupts or similar calls.
65 * During interrupt and other critical calls, a spinlock is used to
66 * protect the system, but the calls themselves save the address
67 * in the address register in case they are interrupting another
68 * access to the device.
70 * For general accesses a lock is provided so that calls which are
71 * allowed to sleep are serialised so that the address register does
72 * not need to be saved. This lock also serves to serialise access
73 * to the EEPROM and PHY access registers which are shared between
77 /* The driver supports the original DM9000E, and now the two newer
78 * devices, DM9000A and DM9000B.
82 TYPE_DM9000E, /* original DM9000 */
87 /* Structure/enum declaration ------------------------------- */
90 void __iomem *io_addr; /* Register I/O base address */
91 void __iomem *io_data; /* Data I/O address */
99 u8 io_mode; /* 0:word, 2:byte */
104 unsigned int in_timeout:1;
105 unsigned int in_suspend:1;
106 unsigned int wake_supported:1;
108 enum dm9000_type type;
110 void (*inblk)(void __iomem *port, void *data, int length);
111 void (*outblk)(void __iomem *port, void *data, int length);
112 void (*dumpblk)(void __iomem *port, int length);
114 struct device *dev; /* parent device */
116 struct resource *addr_res; /* resources found */
117 struct resource *data_res;
118 struct resource *addr_req; /* resources requested */
119 struct resource *data_req;
123 struct mutex addr_lock; /* phy and eeprom access lock */
125 struct delayed_work phy_poll;
126 struct net_device *ndev;
130 struct mii_if_info mii;
136 struct regulator *power_supply;
141 #define dm9000_dbg(db, lev, msg...) do { \
142 if ((lev) < debug) { \
143 dev_dbg(db->dev, msg); \
147 static inline struct board_info *to_dm9000_board(struct net_device *dev)
149 return netdev_priv(dev);
152 /* DM9000 network board routine ---------------------------- */
155 * Read a byte from I/O port
158 ior(struct board_info *db, int reg)
160 writeb(reg, db->io_addr);
161 return readb(db->io_data);
165 * Write a byte to I/O port
169 iow(struct board_info *db, int reg, int value)
171 writeb(reg, db->io_addr);
172 writeb(value, db->io_data);
176 dm9000_reset(struct board_info *db)
178 dev_dbg(db->dev, "resetting device\n");
180 /* Reset DM9000, see DM9000 Application Notes V1.22 Jun 11, 2004 page 29
181 * The essential point is that we have to do a double reset, and the
182 * instruction is to set LBK into MAC internal loopback mode.
184 iow(db, DM9000_NCR, NCR_RST | NCR_MAC_LBK);
185 udelay(100); /* Application note says at least 20 us */
186 if (ior(db, DM9000_NCR) & 1)
187 dev_err(db->dev, "dm9000 did not respond to first reset\n");
189 iow(db, DM9000_NCR, 0);
190 iow(db, DM9000_NCR, NCR_RST | NCR_MAC_LBK);
192 if (ior(db, DM9000_NCR) & 1)
193 dev_err(db->dev, "dm9000 did not respond to second reset\n");
196 /* routines for sending block to chip */
198 static void dm9000_outblk_8bit(void __iomem *reg, void *data, int count)
200 iowrite8_rep(reg, data, count);
203 static void dm9000_outblk_16bit(void __iomem *reg, void *data, int count)
205 iowrite16_rep(reg, data, (count+1) >> 1);
208 static void dm9000_outblk_32bit(void __iomem *reg, void *data, int count)
210 iowrite32_rep(reg, data, (count+3) >> 2);
213 /* input block from chip to memory */
215 static void dm9000_inblk_8bit(void __iomem *reg, void *data, int count)
217 ioread8_rep(reg, data, count);
221 static void dm9000_inblk_16bit(void __iomem *reg, void *data, int count)
223 ioread16_rep(reg, data, (count+1) >> 1);
226 static void dm9000_inblk_32bit(void __iomem *reg, void *data, int count)
228 ioread32_rep(reg, data, (count+3) >> 2);
231 /* dump block from chip to null */
233 static void dm9000_dumpblk_8bit(void __iomem *reg, int count)
237 for (i = 0; i < count; i++)
241 static void dm9000_dumpblk_16bit(void __iomem *reg, int count)
245 count = (count + 1) >> 1;
247 for (i = 0; i < count; i++)
251 static void dm9000_dumpblk_32bit(void __iomem *reg, int count)
255 count = (count + 3) >> 2;
257 for (i = 0; i < count; i++)
262 * Sleep, either by using msleep() or if we are suspending, then
263 * use mdelay() to sleep.
265 static void dm9000_msleep(struct board_info *db, unsigned int ms)
267 if (db->in_suspend || db->in_timeout)
273 /* Read a word from phyxcer */
275 dm9000_phy_read(struct net_device *dev, int phy_reg_unused, int reg)
277 struct board_info *db = netdev_priv(dev);
279 unsigned int reg_save;
282 mutex_lock(&db->addr_lock);
284 spin_lock_irqsave(&db->lock, flags);
286 /* Save previous register address */
287 reg_save = readb(db->io_addr);
289 /* Fill the phyxcer register into REG_0C */
290 iow(db, DM9000_EPAR, DM9000_PHY | reg);
292 /* Issue phyxcer read command */
293 iow(db, DM9000_EPCR, EPCR_ERPRR | EPCR_EPOS);
295 writeb(reg_save, db->io_addr);
296 spin_unlock_irqrestore(&db->lock, flags);
298 dm9000_msleep(db, 1); /* Wait read complete */
300 spin_lock_irqsave(&db->lock, flags);
301 reg_save = readb(db->io_addr);
303 iow(db, DM9000_EPCR, 0x0); /* Clear phyxcer read command */
305 /* The read data keeps on REG_0D & REG_0E */
306 ret = (ior(db, DM9000_EPDRH) << 8) | ior(db, DM9000_EPDRL);
308 /* restore the previous address */
309 writeb(reg_save, db->io_addr);
310 spin_unlock_irqrestore(&db->lock, flags);
312 mutex_unlock(&db->addr_lock);
314 dm9000_dbg(db, 5, "phy_read[%02x] -> %04x\n", reg, ret);
318 /* Write a word to phyxcer */
320 dm9000_phy_write(struct net_device *dev,
321 int phyaddr_unused, int reg, int value)
323 struct board_info *db = netdev_priv(dev);
325 unsigned long reg_save;
327 dm9000_dbg(db, 5, "phy_write[%02x] = %04x\n", reg, value);
329 mutex_lock(&db->addr_lock);
331 spin_lock_irqsave(&db->lock, flags);
333 /* Save previous register address */
334 reg_save = readb(db->io_addr);
336 /* Fill the phyxcer register into REG_0C */
337 iow(db, DM9000_EPAR, DM9000_PHY | reg);
339 /* Fill the written data into REG_0D & REG_0E */
340 iow(db, DM9000_EPDRL, value);
341 iow(db, DM9000_EPDRH, value >> 8);
343 /* Issue phyxcer write command */
344 iow(db, DM9000_EPCR, EPCR_EPOS | EPCR_ERPRW);
346 writeb(reg_save, db->io_addr);
347 spin_unlock_irqrestore(&db->lock, flags);
349 dm9000_msleep(db, 1); /* Wait write complete */
351 spin_lock_irqsave(&db->lock, flags);
352 reg_save = readb(db->io_addr);
354 iow(db, DM9000_EPCR, 0x0); /* Clear phyxcer write command */
356 /* restore the previous address */
357 writeb(reg_save, db->io_addr);
359 spin_unlock_irqrestore(&db->lock, flags);
361 mutex_unlock(&db->addr_lock);
366 * select the specified set of io routines to use with the
370 static void dm9000_set_io(struct board_info *db, int byte_width)
372 /* use the size of the data resource to work out what IO
373 * routines we want to use
376 switch (byte_width) {
378 db->dumpblk = dm9000_dumpblk_8bit;
379 db->outblk = dm9000_outblk_8bit;
380 db->inblk = dm9000_inblk_8bit;
385 dev_dbg(db->dev, ": 3 byte IO, falling back to 16bit\n");
388 db->dumpblk = dm9000_dumpblk_16bit;
389 db->outblk = dm9000_outblk_16bit;
390 db->inblk = dm9000_inblk_16bit;
395 db->dumpblk = dm9000_dumpblk_32bit;
396 db->outblk = dm9000_outblk_32bit;
397 db->inblk = dm9000_inblk_32bit;
402 static void dm9000_schedule_poll(struct board_info *db)
404 if (db->type == TYPE_DM9000E)
405 schedule_delayed_work(&db->phy_poll, HZ * 2);
408 static int dm9000_ioctl(struct net_device *dev, struct ifreq *req, int cmd)
410 struct board_info *dm = to_dm9000_board(dev);
412 if (!netif_running(dev))
415 return generic_mii_ioctl(&dm->mii, if_mii(req), cmd, NULL);
419 dm9000_read_locked(struct board_info *db, int reg)
424 spin_lock_irqsave(&db->lock, flags);
426 spin_unlock_irqrestore(&db->lock, flags);
431 static int dm9000_wait_eeprom(struct board_info *db)
434 int timeout = 8; /* wait max 8msec */
436 /* The DM9000 data sheets say we should be able to
437 * poll the ERRE bit in EPCR to wait for the EEPROM
438 * operation. From testing several chips, this bit
439 * does not seem to work.
441 * We attempt to use the bit, but fall back to the
442 * timeout (which is why we do not return an error
443 * on expiry) to say that the EEPROM operation has
448 status = dm9000_read_locked(db, DM9000_EPCR);
450 if ((status & EPCR_ERRE) == 0)
456 dev_dbg(db->dev, "timeout waiting EEPROM\n");
465 * Read a word data from EEPROM
468 dm9000_read_eeprom(struct board_info *db, int offset, u8 *to)
472 if (db->flags & DM9000_PLATF_NO_EEPROM) {
478 mutex_lock(&db->addr_lock);
480 spin_lock_irqsave(&db->lock, flags);
482 iow(db, DM9000_EPAR, offset);
483 iow(db, DM9000_EPCR, EPCR_ERPRR);
485 spin_unlock_irqrestore(&db->lock, flags);
487 dm9000_wait_eeprom(db);
489 /* delay for at-least 150uS */
492 spin_lock_irqsave(&db->lock, flags);
494 iow(db, DM9000_EPCR, 0x0);
496 to[0] = ior(db, DM9000_EPDRL);
497 to[1] = ior(db, DM9000_EPDRH);
499 spin_unlock_irqrestore(&db->lock, flags);
501 mutex_unlock(&db->addr_lock);
505 * Write a word data to SROM
508 dm9000_write_eeprom(struct board_info *db, int offset, u8 *data)
512 if (db->flags & DM9000_PLATF_NO_EEPROM)
515 mutex_lock(&db->addr_lock);
517 spin_lock_irqsave(&db->lock, flags);
518 iow(db, DM9000_EPAR, offset);
519 iow(db, DM9000_EPDRH, data[1]);
520 iow(db, DM9000_EPDRL, data[0]);
521 iow(db, DM9000_EPCR, EPCR_WEP | EPCR_ERPRW);
522 spin_unlock_irqrestore(&db->lock, flags);
524 dm9000_wait_eeprom(db);
526 mdelay(1); /* wait at least 150uS to clear */
528 spin_lock_irqsave(&db->lock, flags);
529 iow(db, DM9000_EPCR, 0);
530 spin_unlock_irqrestore(&db->lock, flags);
532 mutex_unlock(&db->addr_lock);
537 static void dm9000_get_drvinfo(struct net_device *dev,
538 struct ethtool_drvinfo *info)
540 struct board_info *dm = to_dm9000_board(dev);
542 strscpy(info->driver, CARDNAME, sizeof(info->driver));
543 strscpy(info->bus_info, to_platform_device(dm->dev)->name,
544 sizeof(info->bus_info));
547 static u32 dm9000_get_msglevel(struct net_device *dev)
549 struct board_info *dm = to_dm9000_board(dev);
551 return dm->msg_enable;
554 static void dm9000_set_msglevel(struct net_device *dev, u32 value)
556 struct board_info *dm = to_dm9000_board(dev);
558 dm->msg_enable = value;
561 static int dm9000_get_link_ksettings(struct net_device *dev,
562 struct ethtool_link_ksettings *cmd)
564 struct board_info *dm = to_dm9000_board(dev);
566 mii_ethtool_get_link_ksettings(&dm->mii, cmd);
570 static int dm9000_set_link_ksettings(struct net_device *dev,
571 const struct ethtool_link_ksettings *cmd)
573 struct board_info *dm = to_dm9000_board(dev);
575 return mii_ethtool_set_link_ksettings(&dm->mii, cmd);
578 static int dm9000_nway_reset(struct net_device *dev)
580 struct board_info *dm = to_dm9000_board(dev);
581 return mii_nway_restart(&dm->mii);
584 static int dm9000_set_features(struct net_device *dev,
585 netdev_features_t features)
587 struct board_info *dm = to_dm9000_board(dev);
588 netdev_features_t changed = dev->features ^ features;
591 if (!(changed & NETIF_F_RXCSUM))
594 spin_lock_irqsave(&dm->lock, flags);
595 iow(dm, DM9000_RCSR, (features & NETIF_F_RXCSUM) ? RCSR_CSUM : 0);
596 spin_unlock_irqrestore(&dm->lock, flags);
601 static u32 dm9000_get_link(struct net_device *dev)
603 struct board_info *dm = to_dm9000_board(dev);
606 if (dm->flags & DM9000_PLATF_EXT_PHY)
607 ret = mii_link_ok(&dm->mii);
609 ret = dm9000_read_locked(dm, DM9000_NSR) & NSR_LINKST ? 1 : 0;
614 #define DM_EEPROM_MAGIC (0x444D394B)
616 static int dm9000_get_eeprom_len(struct net_device *dev)
621 static int dm9000_get_eeprom(struct net_device *dev,
622 struct ethtool_eeprom *ee, u8 *data)
624 struct board_info *dm = to_dm9000_board(dev);
625 int offset = ee->offset;
629 /* EEPROM access is aligned to two bytes */
631 if ((len & 1) != 0 || (offset & 1) != 0)
634 if (dm->flags & DM9000_PLATF_NO_EEPROM)
637 ee->magic = DM_EEPROM_MAGIC;
639 for (i = 0; i < len; i += 2)
640 dm9000_read_eeprom(dm, (offset + i) / 2, data + i);
645 static int dm9000_set_eeprom(struct net_device *dev,
646 struct ethtool_eeprom *ee, u8 *data)
648 struct board_info *dm = to_dm9000_board(dev);
649 int offset = ee->offset;
653 /* EEPROM access is aligned to two bytes */
655 if (dm->flags & DM9000_PLATF_NO_EEPROM)
658 if (ee->magic != DM_EEPROM_MAGIC)
662 if (len & 1 || offset & 1) {
663 int which = offset & 1;
666 dm9000_read_eeprom(dm, offset / 2, tmp);
668 dm9000_write_eeprom(dm, offset / 2, tmp);
672 dm9000_write_eeprom(dm, offset / 2, data);
684 static void dm9000_get_wol(struct net_device *dev, struct ethtool_wolinfo *w)
686 struct board_info *dm = to_dm9000_board(dev);
688 memset(w, 0, sizeof(struct ethtool_wolinfo));
690 /* note, we could probably support wake-phy too */
691 w->supported = dm->wake_supported ? WAKE_MAGIC : 0;
692 w->wolopts = dm->wake_state;
695 static int dm9000_set_wol(struct net_device *dev, struct ethtool_wolinfo *w)
697 struct board_info *dm = to_dm9000_board(dev);
699 u32 opts = w->wolopts;
702 if (!dm->wake_supported)
705 if (opts & ~WAKE_MAGIC)
708 if (opts & WAKE_MAGIC)
711 mutex_lock(&dm->addr_lock);
713 spin_lock_irqsave(&dm->lock, flags);
714 iow(dm, DM9000_WCR, wcr);
715 spin_unlock_irqrestore(&dm->lock, flags);
717 mutex_unlock(&dm->addr_lock);
719 if (dm->wake_state != opts) {
720 /* change in wol state, update IRQ state */
723 irq_set_irq_wake(dm->irq_wake, 1);
724 else if (dm->wake_state && !opts)
725 irq_set_irq_wake(dm->irq_wake, 0);
728 dm->wake_state = opts;
732 static const struct ethtool_ops dm9000_ethtool_ops = {
733 .get_drvinfo = dm9000_get_drvinfo,
734 .get_msglevel = dm9000_get_msglevel,
735 .set_msglevel = dm9000_set_msglevel,
736 .nway_reset = dm9000_nway_reset,
737 .get_link = dm9000_get_link,
738 .get_wol = dm9000_get_wol,
739 .set_wol = dm9000_set_wol,
740 .get_eeprom_len = dm9000_get_eeprom_len,
741 .get_eeprom = dm9000_get_eeprom,
742 .set_eeprom = dm9000_set_eeprom,
743 .get_link_ksettings = dm9000_get_link_ksettings,
744 .set_link_ksettings = dm9000_set_link_ksettings,
747 static void dm9000_show_carrier(struct board_info *db,
748 unsigned carrier, unsigned nsr)
751 struct net_device *ndev = db->ndev;
752 struct mii_if_info *mii = &db->mii;
753 unsigned ncr = dm9000_read_locked(db, DM9000_NCR);
756 lpa = mii->mdio_read(mii->dev, mii->phy_id, MII_LPA);
758 "%s: link up, %dMbps, %s-duplex, lpa 0x%04X\n",
759 ndev->name, (nsr & NSR_SPEED) ? 10 : 100,
760 (ncr & NCR_FDX) ? "full" : "half", lpa);
762 dev_info(db->dev, "%s: link down\n", ndev->name);
767 dm9000_poll_work(struct work_struct *w)
769 struct delayed_work *dw = to_delayed_work(w);
770 struct board_info *db = container_of(dw, struct board_info, phy_poll);
771 struct net_device *ndev = db->ndev;
773 if (db->flags & DM9000_PLATF_SIMPLE_PHY &&
774 !(db->flags & DM9000_PLATF_EXT_PHY)) {
775 unsigned nsr = dm9000_read_locked(db, DM9000_NSR);
776 unsigned old_carrier = netif_carrier_ok(ndev) ? 1 : 0;
777 unsigned new_carrier;
779 new_carrier = (nsr & NSR_LINKST) ? 1 : 0;
781 if (old_carrier != new_carrier) {
782 if (netif_msg_link(db))
783 dm9000_show_carrier(db, new_carrier, nsr);
786 netif_carrier_off(ndev);
788 netif_carrier_on(ndev);
791 mii_check_media(&db->mii, netif_msg_link(db), 0);
793 if (netif_running(ndev))
794 dm9000_schedule_poll(db);
797 /* dm9000_release_board
799 * release a board, and any mapped resources
803 dm9000_release_board(struct platform_device *pdev, struct board_info *db)
805 /* unmap our resources */
807 iounmap(db->io_addr);
808 iounmap(db->io_data);
810 /* release the resources */
813 release_resource(db->data_req);
817 release_resource(db->addr_req);
821 static unsigned char dm9000_type_to_char(enum dm9000_type type)
824 case TYPE_DM9000E: return 'e';
825 case TYPE_DM9000A: return 'a';
826 case TYPE_DM9000B: return 'b';
833 * Set DM9000 multicast address
836 dm9000_hash_table_unlocked(struct net_device *dev)
838 struct board_info *db = netdev_priv(dev);
839 struct netdev_hw_addr *ha;
842 u16 hash_table[4] = { 0, 0, 0, 0x8000 }; /* broadcast address */
843 u8 rcr = RCR_DIS_LONG | RCR_DIS_CRC | RCR_RXEN;
845 dm9000_dbg(db, 1, "entering %s\n", __func__);
847 for (i = 0, oft = DM9000_PAR; i < 6; i++, oft++)
848 iow(db, oft, dev->dev_addr[i]);
850 if (dev->flags & IFF_PROMISC)
853 if (dev->flags & IFF_ALLMULTI)
856 /* the multicast address in Hash Table : 64 bits */
857 netdev_for_each_mc_addr(ha, dev) {
858 hash_val = ether_crc_le(6, ha->addr) & 0x3f;
859 hash_table[hash_val / 16] |= (u16) 1 << (hash_val % 16);
862 /* Write the hash table to MAC MD table */
863 for (i = 0, oft = DM9000_MAR; i < 4; i++) {
864 iow(db, oft++, hash_table[i]);
865 iow(db, oft++, hash_table[i] >> 8);
868 iow(db, DM9000_RCR, rcr);
872 dm9000_hash_table(struct net_device *dev)
874 struct board_info *db = netdev_priv(dev);
877 spin_lock_irqsave(&db->lock, flags);
878 dm9000_hash_table_unlocked(dev);
879 spin_unlock_irqrestore(&db->lock, flags);
883 dm9000_mask_interrupts(struct board_info *db)
885 iow(db, DM9000_IMR, IMR_PAR);
889 dm9000_unmask_interrupts(struct board_info *db)
891 iow(db, DM9000_IMR, db->imr_all);
895 * Initialize dm9000 board
898 dm9000_init_dm9000(struct net_device *dev)
900 struct board_info *db = netdev_priv(dev);
904 dm9000_dbg(db, 1, "entering %s\n", __func__);
907 dm9000_mask_interrupts(db);
910 db->io_mode = ior(db, DM9000_ISR) >> 6; /* ISR bit7:6 keeps I/O mode */
913 if (dev->hw_features & NETIF_F_RXCSUM)
915 (dev->features & NETIF_F_RXCSUM) ? RCSR_CSUM : 0);
917 iow(db, DM9000_GPCR, GPCR_GEP_CNTL); /* Let GPIO0 output */
918 iow(db, DM9000_GPR, 0);
920 /* If we are dealing with DM9000B, some extra steps are required: a
921 * manual phy reset, and setting init params.
923 if (db->type == TYPE_DM9000B) {
924 dm9000_phy_write(dev, 0, MII_BMCR, BMCR_RESET);
925 dm9000_phy_write(dev, 0, MII_DM_DSPCR, DSPCR_INIT_PARAM);
928 ncr = (db->flags & DM9000_PLATF_EXT_PHY) ? NCR_EXT_PHY : 0;
930 /* if wol is needed, then always set NCR_WAKEEN otherwise we end
931 * up dumping the wake events if we disable this. There is already
932 * a wake-mask in DM9000_WCR */
933 if (db->wake_supported)
936 iow(db, DM9000_NCR, ncr);
938 /* Program operating register */
939 iow(db, DM9000_TCR, 0); /* TX Polling clear */
940 iow(db, DM9000_BPTR, 0x3f); /* Less 3Kb, 200us */
941 iow(db, DM9000_FCR, 0xff); /* Flow Control */
942 iow(db, DM9000_SMCR, 0); /* Special Mode */
943 /* clear TX status */
944 iow(db, DM9000_NSR, NSR_WAKEST | NSR_TX2END | NSR_TX1END);
945 iow(db, DM9000_ISR, ISR_CLR_STATUS); /* Clear interrupt status */
947 /* Set address filter table */
948 dm9000_hash_table_unlocked(dev);
950 imr = IMR_PAR | IMR_PTM | IMR_PRM;
951 if (db->type != TYPE_DM9000E)
956 /* Init Driver variable */
958 db->queue_pkt_len = 0;
959 netif_trans_update(dev);
962 /* Our watchdog timed out. Called by the networking layer */
963 static void dm9000_timeout(struct net_device *dev, unsigned int txqueue)
965 struct board_info *db = netdev_priv(dev);
969 /* Save previous register address */
970 spin_lock_irqsave(&db->lock, flags);
972 reg_save = readb(db->io_addr);
974 netif_stop_queue(dev);
975 dm9000_init_dm9000(dev);
976 dm9000_unmask_interrupts(db);
977 /* We can accept TX packets again */
978 netif_trans_update(dev); /* prevent tx timeout */
979 netif_wake_queue(dev);
981 /* Restore previous register address */
982 writeb(reg_save, db->io_addr);
984 spin_unlock_irqrestore(&db->lock, flags);
987 static void dm9000_send_packet(struct net_device *dev,
991 struct board_info *dm = to_dm9000_board(dev);
993 /* The DM9000 is not smart enough to leave fragmented packets alone. */
994 if (dm->ip_summed != ip_summed) {
995 if (ip_summed == CHECKSUM_NONE)
996 iow(dm, DM9000_TCCR, 0);
998 iow(dm, DM9000_TCCR, TCCR_IP | TCCR_UDP | TCCR_TCP);
999 dm->ip_summed = ip_summed;
1002 /* Set TX length to DM9000 */
1003 iow(dm, DM9000_TXPLL, pkt_len);
1004 iow(dm, DM9000_TXPLH, pkt_len >> 8);
1006 /* Issue TX polling command */
1007 iow(dm, DM9000_TCR, TCR_TXREQ); /* Cleared after TX complete */
1011 * Hardware start transmission.
1012 * Send a packet to media from the upper layer.
1015 dm9000_start_xmit(struct sk_buff *skb, struct net_device *dev)
1017 unsigned long flags;
1018 struct board_info *db = netdev_priv(dev);
1020 dm9000_dbg(db, 3, "%s:\n", __func__);
1022 if (db->tx_pkt_cnt > 1)
1023 return NETDEV_TX_BUSY;
1025 spin_lock_irqsave(&db->lock, flags);
1027 /* Move data to DM9000 TX RAM */
1028 writeb(DM9000_MWCMD, db->io_addr);
1030 (db->outblk)(db->io_data, skb->data, skb->len);
1031 dev->stats.tx_bytes += skb->len;
1034 /* TX control: First packet immediately send, second packet queue */
1035 if (db->tx_pkt_cnt == 1) {
1036 dm9000_send_packet(dev, skb->ip_summed, skb->len);
1039 db->queue_pkt_len = skb->len;
1040 db->queue_ip_summed = skb->ip_summed;
1041 netif_stop_queue(dev);
1044 spin_unlock_irqrestore(&db->lock, flags);
1047 dev_consume_skb_any(skb);
1049 return NETDEV_TX_OK;
1053 * DM9000 interrupt handler
1054 * receive the packet to upper layer, free the transmitted packet
1057 static void dm9000_tx_done(struct net_device *dev, struct board_info *db)
1059 int tx_status = ior(db, DM9000_NSR); /* Got TX status */
1061 if (tx_status & (NSR_TX2END | NSR_TX1END)) {
1062 /* One packet sent complete */
1064 dev->stats.tx_packets++;
1066 if (netif_msg_tx_done(db))
1067 dev_dbg(db->dev, "tx done, NSR %02x\n", tx_status);
1069 /* Queue packet check & send */
1070 if (db->tx_pkt_cnt > 0)
1071 dm9000_send_packet(dev, db->queue_ip_summed,
1073 netif_wake_queue(dev);
1077 struct dm9000_rxhdr {
1084 * Received a packet and pass to upper layer
1087 dm9000_rx(struct net_device *dev)
1089 struct board_info *db = netdev_priv(dev);
1090 struct dm9000_rxhdr rxhdr;
1091 struct sk_buff *skb;
1096 /* Check packet ready or not */
1098 ior(db, DM9000_MRCMDX); /* Dummy read */
1100 /* Get most updated data */
1101 rxbyte = readb(db->io_data);
1103 /* Status check: this byte must be 0 or 1 */
1104 if (rxbyte & DM9000_PKT_ERR) {
1105 dev_warn(db->dev, "status check fail: %d\n", rxbyte);
1106 iow(db, DM9000_RCR, 0x00); /* Stop Device */
1110 if (!(rxbyte & DM9000_PKT_RDY))
1113 /* A packet ready now & Get status/length */
1115 writeb(DM9000_MRCMD, db->io_addr);
1117 (db->inblk)(db->io_data, &rxhdr, sizeof(rxhdr));
1119 RxLen = le16_to_cpu(rxhdr.RxLen);
1121 if (netif_msg_rx_status(db))
1122 dev_dbg(db->dev, "RX: status %02x, length %04x\n",
1123 rxhdr.RxStatus, RxLen);
1125 /* Packet Status check */
1128 if (netif_msg_rx_err(db))
1129 dev_dbg(db->dev, "RX: Bad Packet (runt)\n");
1132 if (RxLen > DM9000_PKT_MAX) {
1133 dev_dbg(db->dev, "RST: RX Len:%x\n", RxLen);
1136 /* rxhdr.RxStatus is identical to RSR register. */
1137 if (rxhdr.RxStatus & (RSR_FOE | RSR_CE | RSR_AE |
1138 RSR_PLE | RSR_RWTO |
1139 RSR_LCS | RSR_RF)) {
1141 if (rxhdr.RxStatus & RSR_FOE) {
1142 if (netif_msg_rx_err(db))
1143 dev_dbg(db->dev, "fifo error\n");
1144 dev->stats.rx_fifo_errors++;
1146 if (rxhdr.RxStatus & RSR_CE) {
1147 if (netif_msg_rx_err(db))
1148 dev_dbg(db->dev, "crc error\n");
1149 dev->stats.rx_crc_errors++;
1151 if (rxhdr.RxStatus & RSR_RF) {
1152 if (netif_msg_rx_err(db))
1153 dev_dbg(db->dev, "length error\n");
1154 dev->stats.rx_length_errors++;
1158 /* Move data from DM9000 */
1160 ((skb = netdev_alloc_skb(dev, RxLen + 4)) != NULL)) {
1161 skb_reserve(skb, 2);
1162 rdptr = skb_put(skb, RxLen - 4);
1164 /* Read received packet from RX SRAM */
1166 (db->inblk)(db->io_data, rdptr, RxLen);
1167 dev->stats.rx_bytes += RxLen;
1169 /* Pass to upper layer */
1170 skb->protocol = eth_type_trans(skb, dev);
1171 if (dev->features & NETIF_F_RXCSUM) {
1172 if ((((rxbyte & 0x1c) << 3) & rxbyte) == 0)
1173 skb->ip_summed = CHECKSUM_UNNECESSARY;
1175 skb_checksum_none_assert(skb);
1178 dev->stats.rx_packets++;
1181 /* need to dump the packet's data */
1183 (db->dumpblk)(db->io_data, RxLen);
1185 } while (rxbyte & DM9000_PKT_RDY);
1188 static irqreturn_t dm9000_interrupt(int irq, void *dev_id)
1190 struct net_device *dev = dev_id;
1191 struct board_info *db = netdev_priv(dev);
1193 unsigned long flags;
1196 dm9000_dbg(db, 3, "entering %s\n", __func__);
1198 /* A real interrupt coming */
1200 /* holders of db->lock must always block IRQs */
1201 spin_lock_irqsave(&db->lock, flags);
1203 /* Save previous register address */
1204 reg_save = readb(db->io_addr);
1206 dm9000_mask_interrupts(db);
1207 /* Got DM9000 interrupt status */
1208 int_status = ior(db, DM9000_ISR); /* Got ISR */
1209 iow(db, DM9000_ISR, int_status); /* Clear ISR status */
1211 if (netif_msg_intr(db))
1212 dev_dbg(db->dev, "interrupt status %02x\n", int_status);
1214 /* Received the coming packet */
1215 if (int_status & ISR_PRS)
1218 /* Transmit Interrupt check */
1219 if (int_status & ISR_PTS)
1220 dm9000_tx_done(dev, db);
1222 if (db->type != TYPE_DM9000E) {
1223 if (int_status & ISR_LNKCHNG) {
1224 /* fire a link-change request */
1225 schedule_delayed_work(&db->phy_poll, 1);
1229 dm9000_unmask_interrupts(db);
1230 /* Restore previous register address */
1231 writeb(reg_save, db->io_addr);
1233 spin_unlock_irqrestore(&db->lock, flags);
1238 static irqreturn_t dm9000_wol_interrupt(int irq, void *dev_id)
1240 struct net_device *dev = dev_id;
1241 struct board_info *db = netdev_priv(dev);
1242 unsigned long flags;
1245 spin_lock_irqsave(&db->lock, flags);
1247 nsr = ior(db, DM9000_NSR);
1248 wcr = ior(db, DM9000_WCR);
1250 dev_dbg(db->dev, "%s: NSR=0x%02x, WCR=0x%02x\n", __func__, nsr, wcr);
1252 if (nsr & NSR_WAKEST) {
1253 /* clear, so we can avoid */
1254 iow(db, DM9000_NSR, NSR_WAKEST);
1256 if (wcr & WCR_LINKST)
1257 dev_info(db->dev, "wake by link status change\n");
1258 if (wcr & WCR_SAMPLEST)
1259 dev_info(db->dev, "wake by sample packet\n");
1260 if (wcr & WCR_MAGICST)
1261 dev_info(db->dev, "wake by magic packet\n");
1262 if (!(wcr & (WCR_LINKST | WCR_SAMPLEST | WCR_MAGICST)))
1263 dev_err(db->dev, "wake signalled with no reason? "
1264 "NSR=0x%02x, WSR=0x%02x\n", nsr, wcr);
1267 spin_unlock_irqrestore(&db->lock, flags);
1269 return (nsr & NSR_WAKEST) ? IRQ_HANDLED : IRQ_NONE;
1272 #ifdef CONFIG_NET_POLL_CONTROLLER
1276 static void dm9000_poll_controller(struct net_device *dev)
1278 disable_irq(dev->irq);
1279 dm9000_interrupt(dev->irq, dev);
1280 enable_irq(dev->irq);
1285 * Open the interface.
1286 * The interface is opened whenever "ifconfig" actives it.
1289 dm9000_open(struct net_device *dev)
1291 struct board_info *db = netdev_priv(dev);
1292 unsigned int irq_flags = irq_get_trigger_type(dev->irq);
1294 if (netif_msg_ifup(db))
1295 dev_dbg(db->dev, "enabling %s\n", dev->name);
1297 /* If there is no IRQ type specified, tell the user that this is a
1300 if (irq_flags == IRQF_TRIGGER_NONE)
1301 dev_warn(db->dev, "WARNING: no IRQ resource flags set.\n");
1303 irq_flags |= IRQF_SHARED;
1305 /* GPIO0 on pre-activate PHY, Reg 1F is not set by reset */
1306 iow(db, DM9000_GPR, 0); /* REG_1F bit0 activate phyxcer */
1307 mdelay(1); /* delay needs by DM9000B */
1309 /* Initialize DM9000 board */
1310 dm9000_init_dm9000(dev);
1312 if (request_irq(dev->irq, dm9000_interrupt, irq_flags, dev->name, dev))
1314 /* Now that we have an interrupt handler hooked up we can unmask
1317 dm9000_unmask_interrupts(db);
1319 /* Init driver variable */
1322 mii_check_media(&db->mii, netif_msg_link(db), 1);
1323 netif_start_queue(dev);
1325 /* Poll initial link status */
1326 schedule_delayed_work(&db->phy_poll, 1);
1332 dm9000_shutdown(struct net_device *dev)
1334 struct board_info *db = netdev_priv(dev);
1337 dm9000_phy_write(dev, 0, MII_BMCR, BMCR_RESET); /* PHY RESET */
1338 iow(db, DM9000_GPR, 0x01); /* Power-Down PHY */
1339 dm9000_mask_interrupts(db);
1340 iow(db, DM9000_RCR, 0x00); /* Disable RX */
1344 * Stop the interface.
1345 * The interface is stopped when it is brought.
1348 dm9000_stop(struct net_device *ndev)
1350 struct board_info *db = netdev_priv(ndev);
1352 if (netif_msg_ifdown(db))
1353 dev_dbg(db->dev, "shutting down %s\n", ndev->name);
1355 cancel_delayed_work_sync(&db->phy_poll);
1357 netif_stop_queue(ndev);
1358 netif_carrier_off(ndev);
1360 /* free interrupt */
1361 free_irq(ndev->irq, ndev);
1363 dm9000_shutdown(ndev);
1368 static const struct net_device_ops dm9000_netdev_ops = {
1369 .ndo_open = dm9000_open,
1370 .ndo_stop = dm9000_stop,
1371 .ndo_start_xmit = dm9000_start_xmit,
1372 .ndo_tx_timeout = dm9000_timeout,
1373 .ndo_set_rx_mode = dm9000_hash_table,
1374 .ndo_eth_ioctl = dm9000_ioctl,
1375 .ndo_set_features = dm9000_set_features,
1376 .ndo_validate_addr = eth_validate_addr,
1377 .ndo_set_mac_address = eth_mac_addr,
1378 #ifdef CONFIG_NET_POLL_CONTROLLER
1379 .ndo_poll_controller = dm9000_poll_controller,
1383 static struct dm9000_plat_data *dm9000_parse_dt(struct device *dev)
1385 struct dm9000_plat_data *pdata;
1386 struct device_node *np = dev->of_node;
1389 if (!IS_ENABLED(CONFIG_OF) || !np)
1390 return ERR_PTR(-ENXIO);
1392 pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
1394 return ERR_PTR(-ENOMEM);
1396 if (of_property_read_bool(np, "davicom,ext-phy"))
1397 pdata->flags |= DM9000_PLATF_EXT_PHY;
1398 if (of_property_read_bool(np, "davicom,no-eeprom"))
1399 pdata->flags |= DM9000_PLATF_NO_EEPROM;
1401 ret = of_get_mac_address(np, pdata->dev_addr);
1402 if (ret == -EPROBE_DEFER)
1403 return ERR_PTR(ret);
1409 * Search DM9000 board, allocate space and register it
1412 dm9000_probe(struct platform_device *pdev)
1414 struct dm9000_plat_data *pdata = dev_get_platdata(&pdev->dev);
1415 struct board_info *db; /* Point a board information structure */
1416 struct net_device *ndev;
1417 struct device *dev = &pdev->dev;
1418 const unsigned char *mac_src;
1423 struct gpio_desc *reset_gpio;
1424 struct regulator *power;
1425 bool inv_mac_addr = false;
1428 power = devm_regulator_get(dev, "vcc");
1429 if (IS_ERR(power)) {
1430 if (PTR_ERR(power) == -EPROBE_DEFER)
1431 return -EPROBE_DEFER;
1432 dev_dbg(dev, "no regulator provided\n");
1434 ret = regulator_enable(power);
1437 "Failed to enable power regulator: %d\n", ret);
1440 dev_dbg(dev, "regulator enabled\n");
1443 reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
1444 ret = PTR_ERR_OR_ZERO(reset_gpio);
1446 dev_err(dev, "failed to request reset gpio: %d\n", ret);
1447 goto out_regulator_disable;
1451 ret = gpiod_set_consumer_name(reset_gpio, "dm9000_reset");
1453 dev_err(dev, "failed to set reset gpio name: %d\n",
1455 goto out_regulator_disable;
1458 /* According to manual PWRST# Low Period Min 1ms */
1460 gpiod_set_value_cansleep(reset_gpio, 0);
1461 /* Needs 3ms to read eeprom when PWRST is deasserted */
1466 pdata = dm9000_parse_dt(&pdev->dev);
1467 if (IS_ERR(pdata)) {
1468 ret = PTR_ERR(pdata);
1469 goto out_regulator_disable;
1473 /* Init network device */
1474 ndev = alloc_etherdev(sizeof(struct board_info));
1477 goto out_regulator_disable;
1480 SET_NETDEV_DEV(ndev, &pdev->dev);
1482 dev_dbg(&pdev->dev, "dm9000_probe()\n");
1484 /* setup board info structure */
1485 db = netdev_priv(ndev);
1487 db->dev = &pdev->dev;
1490 db->power_supply = power;
1492 spin_lock_init(&db->lock);
1493 mutex_init(&db->addr_lock);
1495 INIT_DELAYED_WORK(&db->phy_poll, dm9000_poll_work);
1497 db->addr_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1498 db->data_res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
1500 if (!db->addr_res || !db->data_res) {
1501 dev_err(db->dev, "insufficient resources addr=%p data=%p\n",
1502 db->addr_res, db->data_res);
1507 ndev->irq = platform_get_irq(pdev, 0);
1508 if (ndev->irq < 0) {
1513 db->irq_wake = platform_get_irq_optional(pdev, 1);
1514 if (db->irq_wake >= 0) {
1515 dev_dbg(db->dev, "wakeup irq %d\n", db->irq_wake);
1517 ret = request_irq(db->irq_wake, dm9000_wol_interrupt,
1518 IRQF_SHARED, dev_name(db->dev), ndev);
1520 dev_err(db->dev, "cannot get wakeup irq (%d)\n", ret);
1523 /* test to see if irq is really wakeup capable */
1524 ret = irq_set_irq_wake(db->irq_wake, 1);
1526 dev_err(db->dev, "irq %d cannot set wakeup (%d)\n",
1529 irq_set_irq_wake(db->irq_wake, 0);
1530 db->wake_supported = 1;
1535 iosize = resource_size(db->addr_res);
1536 db->addr_req = request_mem_region(db->addr_res->start, iosize,
1539 if (db->addr_req == NULL) {
1540 dev_err(db->dev, "cannot claim address reg area\n");
1545 db->io_addr = ioremap(db->addr_res->start, iosize);
1547 if (db->io_addr == NULL) {
1548 dev_err(db->dev, "failed to ioremap address reg\n");
1553 iosize = resource_size(db->data_res);
1554 db->data_req = request_mem_region(db->data_res->start, iosize,
1557 if (db->data_req == NULL) {
1558 dev_err(db->dev, "cannot claim data reg area\n");
1563 db->io_data = ioremap(db->data_res->start, iosize);
1565 if (db->io_data == NULL) {
1566 dev_err(db->dev, "failed to ioremap data reg\n");
1571 /* fill in parameters for net-dev structure */
1572 ndev->base_addr = (unsigned long)db->io_addr;
1574 /* ensure at least we have a default set of IO routines */
1575 dm9000_set_io(db, iosize);
1577 /* check to see if anything is being over-ridden */
1578 if (pdata != NULL) {
1579 /* check to see if the driver wants to over-ride the
1580 * default IO width */
1582 if (pdata->flags & DM9000_PLATF_8BITONLY)
1583 dm9000_set_io(db, 1);
1585 if (pdata->flags & DM9000_PLATF_16BITONLY)
1586 dm9000_set_io(db, 2);
1588 if (pdata->flags & DM9000_PLATF_32BITONLY)
1589 dm9000_set_io(db, 4);
1591 /* check to see if there are any IO routine
1594 if (pdata->inblk != NULL)
1595 db->inblk = pdata->inblk;
1597 if (pdata->outblk != NULL)
1598 db->outblk = pdata->outblk;
1600 if (pdata->dumpblk != NULL)
1601 db->dumpblk = pdata->dumpblk;
1603 db->flags = pdata->flags;
1606 #ifdef CONFIG_DM9000_FORCE_SIMPLE_PHY_POLL
1607 db->flags |= DM9000_PLATF_SIMPLE_PHY;
1612 /* try multiple times, DM9000 sometimes gets the read wrong */
1613 for (i = 0; i < 8; i++) {
1614 id_val = ior(db, DM9000_VIDL);
1615 id_val |= (u32)ior(db, DM9000_VIDH) << 8;
1616 id_val |= (u32)ior(db, DM9000_PIDL) << 16;
1617 id_val |= (u32)ior(db, DM9000_PIDH) << 24;
1619 if (id_val == DM9000_ID)
1621 dev_err(db->dev, "read wrong id 0x%08x\n", id_val);
1624 if (id_val != DM9000_ID) {
1625 dev_err(db->dev, "wrong id: 0x%08x\n", id_val);
1630 /* Identify what type of DM9000 we are working on */
1632 id_val = ior(db, DM9000_CHIPR);
1633 dev_dbg(db->dev, "dm9000 revision 0x%02x\n", id_val);
1637 db->type = TYPE_DM9000A;
1640 db->type = TYPE_DM9000B;
1643 dev_dbg(db->dev, "ID %02x => defaulting to DM9000E\n", id_val);
1644 db->type = TYPE_DM9000E;
1647 /* dm9000a/b are capable of hardware checksum offload */
1648 if (db->type == TYPE_DM9000A || db->type == TYPE_DM9000B) {
1649 ndev->hw_features = NETIF_F_RXCSUM | NETIF_F_IP_CSUM;
1650 ndev->features |= ndev->hw_features;
1653 /* from this point we assume that we have found a DM9000 */
1655 ndev->netdev_ops = &dm9000_netdev_ops;
1656 ndev->watchdog_timeo = msecs_to_jiffies(watchdog);
1657 ndev->ethtool_ops = &dm9000_ethtool_ops;
1659 db->msg_enable = NETIF_MSG_LINK;
1660 db->mii.phy_id_mask = 0x1f;
1661 db->mii.reg_num_mask = 0x1f;
1662 db->mii.force_media = 0;
1663 db->mii.full_duplex = 0;
1665 db->mii.mdio_read = dm9000_phy_read;
1666 db->mii.mdio_write = dm9000_phy_write;
1670 /* try reading the node address from the attached EEPROM */
1671 for (i = 0; i < 6; i += 2)
1672 dm9000_read_eeprom(db, i / 2, addr + i);
1673 eth_hw_addr_set(ndev, addr);
1675 if (!is_valid_ether_addr(ndev->dev_addr) && pdata != NULL) {
1676 mac_src = "platform data";
1677 eth_hw_addr_set(ndev, pdata->dev_addr);
1680 if (!is_valid_ether_addr(ndev->dev_addr)) {
1681 /* try reading from mac */
1684 for (i = 0; i < 6; i++)
1685 addr[i] = ior(db, i + DM9000_PAR);
1686 eth_hw_addr_set(ndev, pdata->dev_addr);
1689 if (!is_valid_ether_addr(ndev->dev_addr)) {
1690 inv_mac_addr = true;
1691 eth_hw_addr_random(ndev);
1696 platform_set_drvdata(pdev, ndev);
1697 ret = register_netdev(ndev);
1701 dev_warn(db->dev, "%s: Invalid ethernet MAC address. Please set using ip\n",
1703 printk(KERN_INFO "%s: dm9000%c at %p,%p IRQ %d MAC: %pM (%s)\n",
1704 ndev->name, dm9000_type_to_char(db->type),
1705 db->io_addr, db->io_data, ndev->irq,
1706 ndev->dev_addr, mac_src);
1711 dev_err(db->dev, "not found (%d).\n", ret);
1713 dm9000_release_board(pdev, db);
1716 out_regulator_disable:
1718 regulator_disable(power);
1724 dm9000_drv_suspend(struct device *dev)
1726 struct net_device *ndev = dev_get_drvdata(dev);
1727 struct board_info *db;
1730 db = netdev_priv(ndev);
1733 if (!netif_running(ndev))
1736 netif_device_detach(ndev);
1738 /* only shutdown if not using WoL */
1739 if (!db->wake_state)
1740 dm9000_shutdown(ndev);
1746 dm9000_drv_resume(struct device *dev)
1748 struct net_device *ndev = dev_get_drvdata(dev);
1749 struct board_info *db = netdev_priv(ndev);
1752 if (netif_running(ndev)) {
1753 /* reset if we were not in wake mode to ensure if
1754 * the device was powered off it is in a known state */
1755 if (!db->wake_state) {
1756 dm9000_init_dm9000(ndev);
1757 dm9000_unmask_interrupts(db);
1760 netif_device_attach(ndev);
1768 static const struct dev_pm_ops dm9000_drv_pm_ops = {
1769 .suspend = dm9000_drv_suspend,
1770 .resume = dm9000_drv_resume,
1773 static void dm9000_drv_remove(struct platform_device *pdev)
1775 struct net_device *ndev = platform_get_drvdata(pdev);
1776 struct board_info *dm = to_dm9000_board(ndev);
1778 unregister_netdev(ndev);
1779 dm9000_release_board(pdev, dm);
1780 if (dm->power_supply)
1781 regulator_disable(dm->power_supply);
1783 free_netdev(ndev); /* free device structure */
1785 dev_dbg(&pdev->dev, "released and freed device\n");
1789 static const struct of_device_id dm9000_of_matches[] = {
1790 { .compatible = "davicom,dm9000", },
1793 MODULE_DEVICE_TABLE(of, dm9000_of_matches);
1796 static struct platform_driver dm9000_driver = {
1799 .pm = &dm9000_drv_pm_ops,
1800 .of_match_table = of_match_ptr(dm9000_of_matches),
1802 .probe = dm9000_probe,
1803 .remove = dm9000_drv_remove,
1806 module_platform_driver(dm9000_driver);
1808 MODULE_AUTHOR("Sascha Hauer, Ben Dooks");
1809 MODULE_DESCRIPTION("Davicom DM9000 network driver");
1810 MODULE_LICENSE("GPL");
1811 MODULE_ALIAS("platform:dm9000");