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:
9 * Ben Dooks <ben@simtec.co.uk>
10 * Sascha Hauer <s.hauer@pengutronix.de>
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.h>
32 #include <linux/of_gpio.h>
34 #include <asm/delay.h>
40 /* Board/System/Debug information/definition ---------------- */
42 #define DM9000_PHY 0x40 /* PHY address 0x01 */
44 #define CARDNAME "dm9000"
47 * Transmit timeout, default 5 seconds.
49 static int watchdog = 5000;
50 module_param(watchdog, int, 0400);
51 MODULE_PARM_DESC(watchdog, "transmit timeout in milliseconds");
54 * Debug messages level
57 module_param(debug, int, 0644);
58 MODULE_PARM_DESC(debug, "dm9000 debug level (0-6)");
60 /* DM9000 register address locking.
62 * The DM9000 uses an address register to control where data written
63 * to the data register goes. This means that the address register
64 * must be preserved over interrupts or similar calls.
66 * During interrupt and other critical calls, a spinlock is used to
67 * protect the system, but the calls themselves save the address
68 * in the address register in case they are interrupting another
69 * access to the device.
71 * For general accesses a lock is provided so that calls which are
72 * allowed to sleep are serialised so that the address register does
73 * not need to be saved. This lock also serves to serialise access
74 * to the EEPROM and PHY access registers which are shared between
78 /* The driver supports the original DM9000E, and now the two newer
79 * devices, DM9000A and DM9000B.
83 TYPE_DM9000E, /* original DM9000 */
88 /* Structure/enum declaration ------------------------------- */
91 void __iomem *io_addr; /* Register I/O base address */
92 void __iomem *io_data; /* Data I/O address */
100 u8 io_mode; /* 0:word, 2:byte */
105 unsigned int in_timeout:1;
106 unsigned int in_suspend:1;
107 unsigned int wake_supported:1;
109 enum dm9000_type type;
111 void (*inblk)(void __iomem *port, void *data, int length);
112 void (*outblk)(void __iomem *port, void *data, int length);
113 void (*dumpblk)(void __iomem *port, int length);
115 struct device *dev; /* parent device */
117 struct resource *addr_res; /* resources found */
118 struct resource *data_res;
119 struct resource *addr_req; /* resources requested */
120 struct resource *data_req;
124 struct mutex addr_lock; /* phy and eeprom access lock */
126 struct delayed_work phy_poll;
127 struct net_device *ndev;
131 struct mii_if_info mii;
137 struct regulator *power_supply;
142 #define dm9000_dbg(db, lev, msg...) do { \
143 if ((lev) < debug) { \
144 dev_dbg(db->dev, msg); \
148 static inline struct board_info *to_dm9000_board(struct net_device *dev)
150 return netdev_priv(dev);
153 /* DM9000 network board routine ---------------------------- */
156 * Read a byte from I/O port
159 ior(struct board_info *db, int reg)
161 writeb(reg, db->io_addr);
162 return readb(db->io_data);
166 * Write a byte to I/O port
170 iow(struct board_info *db, int reg, int value)
172 writeb(reg, db->io_addr);
173 writeb(value, db->io_data);
177 dm9000_reset(struct board_info *db)
179 dev_dbg(db->dev, "resetting device\n");
181 /* Reset DM9000, see DM9000 Application Notes V1.22 Jun 11, 2004 page 29
182 * The essential point is that we have to do a double reset, and the
183 * instruction is to set LBK into MAC internal loopback mode.
185 iow(db, DM9000_NCR, NCR_RST | NCR_MAC_LBK);
186 udelay(100); /* Application note says at least 20 us */
187 if (ior(db, DM9000_NCR) & 1)
188 dev_err(db->dev, "dm9000 did not respond to first reset\n");
190 iow(db, DM9000_NCR, 0);
191 iow(db, DM9000_NCR, NCR_RST | NCR_MAC_LBK);
193 if (ior(db, DM9000_NCR) & 1)
194 dev_err(db->dev, "dm9000 did not respond to second reset\n");
197 /* routines for sending block to chip */
199 static void dm9000_outblk_8bit(void __iomem *reg, void *data, int count)
201 iowrite8_rep(reg, data, count);
204 static void dm9000_outblk_16bit(void __iomem *reg, void *data, int count)
206 iowrite16_rep(reg, data, (count+1) >> 1);
209 static void dm9000_outblk_32bit(void __iomem *reg, void *data, int count)
211 iowrite32_rep(reg, data, (count+3) >> 2);
214 /* input block from chip to memory */
216 static void dm9000_inblk_8bit(void __iomem *reg, void *data, int count)
218 ioread8_rep(reg, data, count);
222 static void dm9000_inblk_16bit(void __iomem *reg, void *data, int count)
224 ioread16_rep(reg, data, (count+1) >> 1);
227 static void dm9000_inblk_32bit(void __iomem *reg, void *data, int count)
229 ioread32_rep(reg, data, (count+3) >> 2);
232 /* dump block from chip to null */
234 static void dm9000_dumpblk_8bit(void __iomem *reg, int count)
238 for (i = 0; i < count; i++)
242 static void dm9000_dumpblk_16bit(void __iomem *reg, int count)
246 count = (count + 1) >> 1;
248 for (i = 0; i < count; i++)
252 static void dm9000_dumpblk_32bit(void __iomem *reg, int count)
256 count = (count + 3) >> 2;
258 for (i = 0; i < count; i++)
263 * Sleep, either by using msleep() or if we are suspending, then
264 * use mdelay() to sleep.
266 static void dm9000_msleep(struct board_info *db, unsigned int ms)
268 if (db->in_suspend || db->in_timeout)
274 /* Read a word from phyxcer */
276 dm9000_phy_read(struct net_device *dev, int phy_reg_unused, int reg)
278 struct board_info *db = netdev_priv(dev);
280 unsigned int reg_save;
283 mutex_lock(&db->addr_lock);
285 spin_lock_irqsave(&db->lock, flags);
287 /* Save previous register address */
288 reg_save = readb(db->io_addr);
290 /* Fill the phyxcer register into REG_0C */
291 iow(db, DM9000_EPAR, DM9000_PHY | reg);
293 /* Issue phyxcer read command */
294 iow(db, DM9000_EPCR, EPCR_ERPRR | EPCR_EPOS);
296 writeb(reg_save, db->io_addr);
297 spin_unlock_irqrestore(&db->lock, flags);
299 dm9000_msleep(db, 1); /* Wait read complete */
301 spin_lock_irqsave(&db->lock, flags);
302 reg_save = readb(db->io_addr);
304 iow(db, DM9000_EPCR, 0x0); /* Clear phyxcer read command */
306 /* The read data keeps on REG_0D & REG_0E */
307 ret = (ior(db, DM9000_EPDRH) << 8) | ior(db, DM9000_EPDRL);
309 /* restore the previous address */
310 writeb(reg_save, db->io_addr);
311 spin_unlock_irqrestore(&db->lock, flags);
313 mutex_unlock(&db->addr_lock);
315 dm9000_dbg(db, 5, "phy_read[%02x] -> %04x\n", reg, ret);
319 /* Write a word to phyxcer */
321 dm9000_phy_write(struct net_device *dev,
322 int phyaddr_unused, int reg, int value)
324 struct board_info *db = netdev_priv(dev);
326 unsigned long reg_save;
328 dm9000_dbg(db, 5, "phy_write[%02x] = %04x\n", reg, value);
330 mutex_lock(&db->addr_lock);
332 spin_lock_irqsave(&db->lock, flags);
334 /* Save previous register address */
335 reg_save = readb(db->io_addr);
337 /* Fill the phyxcer register into REG_0C */
338 iow(db, DM9000_EPAR, DM9000_PHY | reg);
340 /* Fill the written data into REG_0D & REG_0E */
341 iow(db, DM9000_EPDRL, value);
342 iow(db, DM9000_EPDRH, value >> 8);
344 /* Issue phyxcer write command */
345 iow(db, DM9000_EPCR, EPCR_EPOS | EPCR_ERPRW);
347 writeb(reg_save, db->io_addr);
348 spin_unlock_irqrestore(&db->lock, flags);
350 dm9000_msleep(db, 1); /* Wait write complete */
352 spin_lock_irqsave(&db->lock, flags);
353 reg_save = readb(db->io_addr);
355 iow(db, DM9000_EPCR, 0x0); /* Clear phyxcer write command */
357 /* restore the previous address */
358 writeb(reg_save, db->io_addr);
360 spin_unlock_irqrestore(&db->lock, flags);
362 mutex_unlock(&db->addr_lock);
367 * select the specified set of io routines to use with the
371 static void dm9000_set_io(struct board_info *db, int byte_width)
373 /* use the size of the data resource to work out what IO
374 * routines we want to use
377 switch (byte_width) {
379 db->dumpblk = dm9000_dumpblk_8bit;
380 db->outblk = dm9000_outblk_8bit;
381 db->inblk = dm9000_inblk_8bit;
386 dev_dbg(db->dev, ": 3 byte IO, falling back to 16bit\n");
389 db->dumpblk = dm9000_dumpblk_16bit;
390 db->outblk = dm9000_outblk_16bit;
391 db->inblk = dm9000_inblk_16bit;
396 db->dumpblk = dm9000_dumpblk_32bit;
397 db->outblk = dm9000_outblk_32bit;
398 db->inblk = dm9000_inblk_32bit;
403 static void dm9000_schedule_poll(struct board_info *db)
405 if (db->type == TYPE_DM9000E)
406 schedule_delayed_work(&db->phy_poll, HZ * 2);
409 static int dm9000_ioctl(struct net_device *dev, struct ifreq *req, int cmd)
411 struct board_info *dm = to_dm9000_board(dev);
413 if (!netif_running(dev))
416 return generic_mii_ioctl(&dm->mii, if_mii(req), cmd, NULL);
420 dm9000_read_locked(struct board_info *db, int reg)
425 spin_lock_irqsave(&db->lock, flags);
427 spin_unlock_irqrestore(&db->lock, flags);
432 static int dm9000_wait_eeprom(struct board_info *db)
435 int timeout = 8; /* wait max 8msec */
437 /* The DM9000 data sheets say we should be able to
438 * poll the ERRE bit in EPCR to wait for the EEPROM
439 * operation. From testing several chips, this bit
440 * does not seem to work.
442 * We attempt to use the bit, but fall back to the
443 * timeout (which is why we do not return an error
444 * on expiry) to say that the EEPROM operation has
449 status = dm9000_read_locked(db, DM9000_EPCR);
451 if ((status & EPCR_ERRE) == 0)
457 dev_dbg(db->dev, "timeout waiting EEPROM\n");
466 * Read a word data from EEPROM
469 dm9000_read_eeprom(struct board_info *db, int offset, u8 *to)
473 if (db->flags & DM9000_PLATF_NO_EEPROM) {
479 mutex_lock(&db->addr_lock);
481 spin_lock_irqsave(&db->lock, flags);
483 iow(db, DM9000_EPAR, offset);
484 iow(db, DM9000_EPCR, EPCR_ERPRR);
486 spin_unlock_irqrestore(&db->lock, flags);
488 dm9000_wait_eeprom(db);
490 /* delay for at-least 150uS */
493 spin_lock_irqsave(&db->lock, flags);
495 iow(db, DM9000_EPCR, 0x0);
497 to[0] = ior(db, DM9000_EPDRL);
498 to[1] = ior(db, DM9000_EPDRH);
500 spin_unlock_irqrestore(&db->lock, flags);
502 mutex_unlock(&db->addr_lock);
506 * Write a word data to SROM
509 dm9000_write_eeprom(struct board_info *db, int offset, u8 *data)
513 if (db->flags & DM9000_PLATF_NO_EEPROM)
516 mutex_lock(&db->addr_lock);
518 spin_lock_irqsave(&db->lock, flags);
519 iow(db, DM9000_EPAR, offset);
520 iow(db, DM9000_EPDRH, data[1]);
521 iow(db, DM9000_EPDRL, data[0]);
522 iow(db, DM9000_EPCR, EPCR_WEP | EPCR_ERPRW);
523 spin_unlock_irqrestore(&db->lock, flags);
525 dm9000_wait_eeprom(db);
527 mdelay(1); /* wait at least 150uS to clear */
529 spin_lock_irqsave(&db->lock, flags);
530 iow(db, DM9000_EPCR, 0);
531 spin_unlock_irqrestore(&db->lock, flags);
533 mutex_unlock(&db->addr_lock);
538 static void dm9000_get_drvinfo(struct net_device *dev,
539 struct ethtool_drvinfo *info)
541 struct board_info *dm = to_dm9000_board(dev);
543 strlcpy(info->driver, CARDNAME, sizeof(info->driver));
544 strlcpy(info->bus_info, to_platform_device(dm->dev)->name,
545 sizeof(info->bus_info));
548 static u32 dm9000_get_msglevel(struct net_device *dev)
550 struct board_info *dm = to_dm9000_board(dev);
552 return dm->msg_enable;
555 static void dm9000_set_msglevel(struct net_device *dev, u32 value)
557 struct board_info *dm = to_dm9000_board(dev);
559 dm->msg_enable = value;
562 static int dm9000_get_link_ksettings(struct net_device *dev,
563 struct ethtool_link_ksettings *cmd)
565 struct board_info *dm = to_dm9000_board(dev);
567 mii_ethtool_get_link_ksettings(&dm->mii, cmd);
571 static int dm9000_set_link_ksettings(struct net_device *dev,
572 const struct ethtool_link_ksettings *cmd)
574 struct board_info *dm = to_dm9000_board(dev);
576 return mii_ethtool_set_link_ksettings(&dm->mii, cmd);
579 static int dm9000_nway_reset(struct net_device *dev)
581 struct board_info *dm = to_dm9000_board(dev);
582 return mii_nway_restart(&dm->mii);
585 static int dm9000_set_features(struct net_device *dev,
586 netdev_features_t features)
588 struct board_info *dm = to_dm9000_board(dev);
589 netdev_features_t changed = dev->features ^ features;
592 if (!(changed & NETIF_F_RXCSUM))
595 spin_lock_irqsave(&dm->lock, flags);
596 iow(dm, DM9000_RCSR, (features & NETIF_F_RXCSUM) ? RCSR_CSUM : 0);
597 spin_unlock_irqrestore(&dm->lock, flags);
602 static u32 dm9000_get_link(struct net_device *dev)
604 struct board_info *dm = to_dm9000_board(dev);
607 if (dm->flags & DM9000_PLATF_EXT_PHY)
608 ret = mii_link_ok(&dm->mii);
610 ret = dm9000_read_locked(dm, DM9000_NSR) & NSR_LINKST ? 1 : 0;
615 #define DM_EEPROM_MAGIC (0x444D394B)
617 static int dm9000_get_eeprom_len(struct net_device *dev)
622 static int dm9000_get_eeprom(struct net_device *dev,
623 struct ethtool_eeprom *ee, u8 *data)
625 struct board_info *dm = to_dm9000_board(dev);
626 int offset = ee->offset;
630 /* EEPROM access is aligned to two bytes */
632 if ((len & 1) != 0 || (offset & 1) != 0)
635 if (dm->flags & DM9000_PLATF_NO_EEPROM)
638 ee->magic = DM_EEPROM_MAGIC;
640 for (i = 0; i < len; i += 2)
641 dm9000_read_eeprom(dm, (offset + i) / 2, data + i);
646 static int dm9000_set_eeprom(struct net_device *dev,
647 struct ethtool_eeprom *ee, u8 *data)
649 struct board_info *dm = to_dm9000_board(dev);
650 int offset = ee->offset;
654 /* EEPROM access is aligned to two bytes */
656 if (dm->flags & DM9000_PLATF_NO_EEPROM)
659 if (ee->magic != DM_EEPROM_MAGIC)
663 if (len & 1 || offset & 1) {
664 int which = offset & 1;
667 dm9000_read_eeprom(dm, offset / 2, tmp);
669 dm9000_write_eeprom(dm, offset / 2, tmp);
673 dm9000_write_eeprom(dm, offset / 2, data);
685 static void dm9000_get_wol(struct net_device *dev, struct ethtool_wolinfo *w)
687 struct board_info *dm = to_dm9000_board(dev);
689 memset(w, 0, sizeof(struct ethtool_wolinfo));
691 /* note, we could probably support wake-phy too */
692 w->supported = dm->wake_supported ? WAKE_MAGIC : 0;
693 w->wolopts = dm->wake_state;
696 static int dm9000_set_wol(struct net_device *dev, struct ethtool_wolinfo *w)
698 struct board_info *dm = to_dm9000_board(dev);
700 u32 opts = w->wolopts;
703 if (!dm->wake_supported)
706 if (opts & ~WAKE_MAGIC)
709 if (opts & WAKE_MAGIC)
712 mutex_lock(&dm->addr_lock);
714 spin_lock_irqsave(&dm->lock, flags);
715 iow(dm, DM9000_WCR, wcr);
716 spin_unlock_irqrestore(&dm->lock, flags);
718 mutex_unlock(&dm->addr_lock);
720 if (dm->wake_state != opts) {
721 /* change in wol state, update IRQ state */
724 irq_set_irq_wake(dm->irq_wake, 1);
725 else if (dm->wake_state && !opts)
726 irq_set_irq_wake(dm->irq_wake, 0);
729 dm->wake_state = opts;
733 static const struct ethtool_ops dm9000_ethtool_ops = {
734 .get_drvinfo = dm9000_get_drvinfo,
735 .get_msglevel = dm9000_get_msglevel,
736 .set_msglevel = dm9000_set_msglevel,
737 .nway_reset = dm9000_nway_reset,
738 .get_link = dm9000_get_link,
739 .get_wol = dm9000_get_wol,
740 .set_wol = dm9000_set_wol,
741 .get_eeprom_len = dm9000_get_eeprom_len,
742 .get_eeprom = dm9000_get_eeprom,
743 .set_eeprom = dm9000_set_eeprom,
744 .get_link_ksettings = dm9000_get_link_ksettings,
745 .set_link_ksettings = dm9000_set_link_ksettings,
748 static void dm9000_show_carrier(struct board_info *db,
749 unsigned carrier, unsigned nsr)
752 struct net_device *ndev = db->ndev;
753 struct mii_if_info *mii = &db->mii;
754 unsigned ncr = dm9000_read_locked(db, DM9000_NCR);
757 lpa = mii->mdio_read(mii->dev, mii->phy_id, MII_LPA);
759 "%s: link up, %dMbps, %s-duplex, lpa 0x%04X\n",
760 ndev->name, (nsr & NSR_SPEED) ? 10 : 100,
761 (ncr & NCR_FDX) ? "full" : "half", lpa);
763 dev_info(db->dev, "%s: link down\n", ndev->name);
768 dm9000_poll_work(struct work_struct *w)
770 struct delayed_work *dw = to_delayed_work(w);
771 struct board_info *db = container_of(dw, struct board_info, phy_poll);
772 struct net_device *ndev = db->ndev;
774 if (db->flags & DM9000_PLATF_SIMPLE_PHY &&
775 !(db->flags & DM9000_PLATF_EXT_PHY)) {
776 unsigned nsr = dm9000_read_locked(db, DM9000_NSR);
777 unsigned old_carrier = netif_carrier_ok(ndev) ? 1 : 0;
778 unsigned new_carrier;
780 new_carrier = (nsr & NSR_LINKST) ? 1 : 0;
782 if (old_carrier != new_carrier) {
783 if (netif_msg_link(db))
784 dm9000_show_carrier(db, new_carrier, nsr);
787 netif_carrier_off(ndev);
789 netif_carrier_on(ndev);
792 mii_check_media(&db->mii, netif_msg_link(db), 0);
794 if (netif_running(ndev))
795 dm9000_schedule_poll(db);
798 /* dm9000_release_board
800 * release a board, and any mapped resources
804 dm9000_release_board(struct platform_device *pdev, struct board_info *db)
806 /* unmap our resources */
808 iounmap(db->io_addr);
809 iounmap(db->io_data);
811 /* release the resources */
814 release_resource(db->data_req);
818 release_resource(db->addr_req);
822 static unsigned char dm9000_type_to_char(enum dm9000_type type)
825 case TYPE_DM9000E: return 'e';
826 case TYPE_DM9000A: return 'a';
827 case TYPE_DM9000B: return 'b';
834 * Set DM9000 multicast address
837 dm9000_hash_table_unlocked(struct net_device *dev)
839 struct board_info *db = netdev_priv(dev);
840 struct netdev_hw_addr *ha;
843 u16 hash_table[4] = { 0, 0, 0, 0x8000 }; /* broadcast address */
844 u8 rcr = RCR_DIS_LONG | RCR_DIS_CRC | RCR_RXEN;
846 dm9000_dbg(db, 1, "entering %s\n", __func__);
848 for (i = 0, oft = DM9000_PAR; i < 6; i++, oft++)
849 iow(db, oft, dev->dev_addr[i]);
851 if (dev->flags & IFF_PROMISC)
854 if (dev->flags & IFF_ALLMULTI)
857 /* the multicast address in Hash Table : 64 bits */
858 netdev_for_each_mc_addr(ha, dev) {
859 hash_val = ether_crc_le(6, ha->addr) & 0x3f;
860 hash_table[hash_val / 16] |= (u16) 1 << (hash_val % 16);
863 /* Write the hash table to MAC MD table */
864 for (i = 0, oft = DM9000_MAR; i < 4; i++) {
865 iow(db, oft++, hash_table[i]);
866 iow(db, oft++, hash_table[i] >> 8);
869 iow(db, DM9000_RCR, rcr);
873 dm9000_hash_table(struct net_device *dev)
875 struct board_info *db = netdev_priv(dev);
878 spin_lock_irqsave(&db->lock, flags);
879 dm9000_hash_table_unlocked(dev);
880 spin_unlock_irqrestore(&db->lock, flags);
884 dm9000_mask_interrupts(struct board_info *db)
886 iow(db, DM9000_IMR, IMR_PAR);
890 dm9000_unmask_interrupts(struct board_info *db)
892 iow(db, DM9000_IMR, db->imr_all);
896 * Initialize dm9000 board
899 dm9000_init_dm9000(struct net_device *dev)
901 struct board_info *db = netdev_priv(dev);
905 dm9000_dbg(db, 1, "entering %s\n", __func__);
908 dm9000_mask_interrupts(db);
911 db->io_mode = ior(db, DM9000_ISR) >> 6; /* ISR bit7:6 keeps I/O mode */
914 if (dev->hw_features & NETIF_F_RXCSUM)
916 (dev->features & NETIF_F_RXCSUM) ? RCSR_CSUM : 0);
918 iow(db, DM9000_GPCR, GPCR_GEP_CNTL); /* Let GPIO0 output */
919 iow(db, DM9000_GPR, 0);
921 /* If we are dealing with DM9000B, some extra steps are required: a
922 * manual phy reset, and setting init params.
924 if (db->type == TYPE_DM9000B) {
925 dm9000_phy_write(dev, 0, MII_BMCR, BMCR_RESET);
926 dm9000_phy_write(dev, 0, MII_DM_DSPCR, DSPCR_INIT_PARAM);
929 ncr = (db->flags & DM9000_PLATF_EXT_PHY) ? NCR_EXT_PHY : 0;
931 /* if wol is needed, then always set NCR_WAKEEN otherwise we end
932 * up dumping the wake events if we disable this. There is already
933 * a wake-mask in DM9000_WCR */
934 if (db->wake_supported)
937 iow(db, DM9000_NCR, ncr);
939 /* Program operating register */
940 iow(db, DM9000_TCR, 0); /* TX Polling clear */
941 iow(db, DM9000_BPTR, 0x3f); /* Less 3Kb, 200us */
942 iow(db, DM9000_FCR, 0xff); /* Flow Control */
943 iow(db, DM9000_SMCR, 0); /* Special Mode */
944 /* clear TX status */
945 iow(db, DM9000_NSR, NSR_WAKEST | NSR_TX2END | NSR_TX1END);
946 iow(db, DM9000_ISR, ISR_CLR_STATUS); /* Clear interrupt status */
948 /* Set address filter table */
949 dm9000_hash_table_unlocked(dev);
951 imr = IMR_PAR | IMR_PTM | IMR_PRM;
952 if (db->type != TYPE_DM9000E)
957 /* Init Driver variable */
959 db->queue_pkt_len = 0;
960 netif_trans_update(dev);
963 /* Our watchdog timed out. Called by the networking layer */
964 static void dm9000_timeout(struct net_device *dev, unsigned int txqueue)
966 struct board_info *db = netdev_priv(dev);
970 /* Save previous register address */
971 spin_lock_irqsave(&db->lock, flags);
973 reg_save = readb(db->io_addr);
975 netif_stop_queue(dev);
976 dm9000_init_dm9000(dev);
977 dm9000_unmask_interrupts(db);
978 /* We can accept TX packets again */
979 netif_trans_update(dev); /* prevent tx timeout */
980 netif_wake_queue(dev);
982 /* Restore previous register address */
983 writeb(reg_save, db->io_addr);
985 spin_unlock_irqrestore(&db->lock, flags);
988 static void dm9000_send_packet(struct net_device *dev,
992 struct board_info *dm = to_dm9000_board(dev);
994 /* The DM9000 is not smart enough to leave fragmented packets alone. */
995 if (dm->ip_summed != ip_summed) {
996 if (ip_summed == CHECKSUM_NONE)
997 iow(dm, DM9000_TCCR, 0);
999 iow(dm, DM9000_TCCR, TCCR_IP | TCCR_UDP | TCCR_TCP);
1000 dm->ip_summed = ip_summed;
1003 /* Set TX length to DM9000 */
1004 iow(dm, DM9000_TXPLL, pkt_len);
1005 iow(dm, DM9000_TXPLH, pkt_len >> 8);
1007 /* Issue TX polling command */
1008 iow(dm, DM9000_TCR, TCR_TXREQ); /* Cleared after TX complete */
1012 * Hardware start transmission.
1013 * Send a packet to media from the upper layer.
1016 dm9000_start_xmit(struct sk_buff *skb, struct net_device *dev)
1018 unsigned long flags;
1019 struct board_info *db = netdev_priv(dev);
1021 dm9000_dbg(db, 3, "%s:\n", __func__);
1023 if (db->tx_pkt_cnt > 1)
1024 return NETDEV_TX_BUSY;
1026 spin_lock_irqsave(&db->lock, flags);
1028 /* Move data to DM9000 TX RAM */
1029 writeb(DM9000_MWCMD, db->io_addr);
1031 (db->outblk)(db->io_data, skb->data, skb->len);
1032 dev->stats.tx_bytes += skb->len;
1035 /* TX control: First packet immediately send, second packet queue */
1036 if (db->tx_pkt_cnt == 1) {
1037 dm9000_send_packet(dev, skb->ip_summed, skb->len);
1040 db->queue_pkt_len = skb->len;
1041 db->queue_ip_summed = skb->ip_summed;
1042 netif_stop_queue(dev);
1045 spin_unlock_irqrestore(&db->lock, flags);
1048 dev_consume_skb_any(skb);
1050 return NETDEV_TX_OK;
1054 * DM9000 interrupt handler
1055 * receive the packet to upper layer, free the transmitted packet
1058 static void dm9000_tx_done(struct net_device *dev, struct board_info *db)
1060 int tx_status = ior(db, DM9000_NSR); /* Got TX status */
1062 if (tx_status & (NSR_TX2END | NSR_TX1END)) {
1063 /* One packet sent complete */
1065 dev->stats.tx_packets++;
1067 if (netif_msg_tx_done(db))
1068 dev_dbg(db->dev, "tx done, NSR %02x\n", tx_status);
1070 /* Queue packet check & send */
1071 if (db->tx_pkt_cnt > 0)
1072 dm9000_send_packet(dev, db->queue_ip_summed,
1074 netif_wake_queue(dev);
1078 struct dm9000_rxhdr {
1085 * Received a packet and pass to upper layer
1088 dm9000_rx(struct net_device *dev)
1090 struct board_info *db = netdev_priv(dev);
1091 struct dm9000_rxhdr rxhdr;
1092 struct sk_buff *skb;
1097 /* Check packet ready or not */
1099 ior(db, DM9000_MRCMDX); /* Dummy read */
1101 /* Get most updated data */
1102 rxbyte = readb(db->io_data);
1104 /* Status check: this byte must be 0 or 1 */
1105 if (rxbyte & DM9000_PKT_ERR) {
1106 dev_warn(db->dev, "status check fail: %d\n", rxbyte);
1107 iow(db, DM9000_RCR, 0x00); /* Stop Device */
1111 if (!(rxbyte & DM9000_PKT_RDY))
1114 /* A packet ready now & Get status/length */
1116 writeb(DM9000_MRCMD, db->io_addr);
1118 (db->inblk)(db->io_data, &rxhdr, sizeof(rxhdr));
1120 RxLen = le16_to_cpu(rxhdr.RxLen);
1122 if (netif_msg_rx_status(db))
1123 dev_dbg(db->dev, "RX: status %02x, length %04x\n",
1124 rxhdr.RxStatus, RxLen);
1126 /* Packet Status check */
1129 if (netif_msg_rx_err(db))
1130 dev_dbg(db->dev, "RX: Bad Packet (runt)\n");
1133 if (RxLen > DM9000_PKT_MAX) {
1134 dev_dbg(db->dev, "RST: RX Len:%x\n", RxLen);
1137 /* rxhdr.RxStatus is identical to RSR register. */
1138 if (rxhdr.RxStatus & (RSR_FOE | RSR_CE | RSR_AE |
1139 RSR_PLE | RSR_RWTO |
1140 RSR_LCS | RSR_RF)) {
1142 if (rxhdr.RxStatus & RSR_FOE) {
1143 if (netif_msg_rx_err(db))
1144 dev_dbg(db->dev, "fifo error\n");
1145 dev->stats.rx_fifo_errors++;
1147 if (rxhdr.RxStatus & RSR_CE) {
1148 if (netif_msg_rx_err(db))
1149 dev_dbg(db->dev, "crc error\n");
1150 dev->stats.rx_crc_errors++;
1152 if (rxhdr.RxStatus & RSR_RF) {
1153 if (netif_msg_rx_err(db))
1154 dev_dbg(db->dev, "length error\n");
1155 dev->stats.rx_length_errors++;
1159 /* Move data from DM9000 */
1161 ((skb = netdev_alloc_skb(dev, RxLen + 4)) != NULL)) {
1162 skb_reserve(skb, 2);
1163 rdptr = skb_put(skb, RxLen - 4);
1165 /* Read received packet from RX SRAM */
1167 (db->inblk)(db->io_data, rdptr, RxLen);
1168 dev->stats.rx_bytes += RxLen;
1170 /* Pass to upper layer */
1171 skb->protocol = eth_type_trans(skb, dev);
1172 if (dev->features & NETIF_F_RXCSUM) {
1173 if ((((rxbyte & 0x1c) << 3) & rxbyte) == 0)
1174 skb->ip_summed = CHECKSUM_UNNECESSARY;
1176 skb_checksum_none_assert(skb);
1179 dev->stats.rx_packets++;
1182 /* need to dump the packet's data */
1184 (db->dumpblk)(db->io_data, RxLen);
1186 } while (rxbyte & DM9000_PKT_RDY);
1189 static irqreturn_t dm9000_interrupt(int irq, void *dev_id)
1191 struct net_device *dev = dev_id;
1192 struct board_info *db = netdev_priv(dev);
1194 unsigned long flags;
1197 dm9000_dbg(db, 3, "entering %s\n", __func__);
1199 /* A real interrupt coming */
1201 /* holders of db->lock must always block IRQs */
1202 spin_lock_irqsave(&db->lock, flags);
1204 /* Save previous register address */
1205 reg_save = readb(db->io_addr);
1207 dm9000_mask_interrupts(db);
1208 /* Got DM9000 interrupt status */
1209 int_status = ior(db, DM9000_ISR); /* Got ISR */
1210 iow(db, DM9000_ISR, int_status); /* Clear ISR status */
1212 if (netif_msg_intr(db))
1213 dev_dbg(db->dev, "interrupt status %02x\n", int_status);
1215 /* Received the coming packet */
1216 if (int_status & ISR_PRS)
1219 /* Transmit Interrupt check */
1220 if (int_status & ISR_PTS)
1221 dm9000_tx_done(dev, db);
1223 if (db->type != TYPE_DM9000E) {
1224 if (int_status & ISR_LNKCHNG) {
1225 /* fire a link-change request */
1226 schedule_delayed_work(&db->phy_poll, 1);
1230 dm9000_unmask_interrupts(db);
1231 /* Restore previous register address */
1232 writeb(reg_save, db->io_addr);
1234 spin_unlock_irqrestore(&db->lock, flags);
1239 static irqreturn_t dm9000_wol_interrupt(int irq, void *dev_id)
1241 struct net_device *dev = dev_id;
1242 struct board_info *db = netdev_priv(dev);
1243 unsigned long flags;
1246 spin_lock_irqsave(&db->lock, flags);
1248 nsr = ior(db, DM9000_NSR);
1249 wcr = ior(db, DM9000_WCR);
1251 dev_dbg(db->dev, "%s: NSR=0x%02x, WCR=0x%02x\n", __func__, nsr, wcr);
1253 if (nsr & NSR_WAKEST) {
1254 /* clear, so we can avoid */
1255 iow(db, DM9000_NSR, NSR_WAKEST);
1257 if (wcr & WCR_LINKST)
1258 dev_info(db->dev, "wake by link status change\n");
1259 if (wcr & WCR_SAMPLEST)
1260 dev_info(db->dev, "wake by sample packet\n");
1261 if (wcr & WCR_MAGICST)
1262 dev_info(db->dev, "wake by magic packet\n");
1263 if (!(wcr & (WCR_LINKST | WCR_SAMPLEST | WCR_MAGICST)))
1264 dev_err(db->dev, "wake signalled with no reason? "
1265 "NSR=0x%02x, WSR=0x%02x\n", nsr, wcr);
1268 spin_unlock_irqrestore(&db->lock, flags);
1270 return (nsr & NSR_WAKEST) ? IRQ_HANDLED : IRQ_NONE;
1273 #ifdef CONFIG_NET_POLL_CONTROLLER
1277 static void dm9000_poll_controller(struct net_device *dev)
1279 disable_irq(dev->irq);
1280 dm9000_interrupt(dev->irq, dev);
1281 enable_irq(dev->irq);
1286 * Open the interface.
1287 * The interface is opened whenever "ifconfig" actives it.
1290 dm9000_open(struct net_device *dev)
1292 struct board_info *db = netdev_priv(dev);
1293 unsigned int irq_flags = irq_get_trigger_type(dev->irq);
1295 if (netif_msg_ifup(db))
1296 dev_dbg(db->dev, "enabling %s\n", dev->name);
1298 /* If there is no IRQ type specified, tell the user that this is a
1301 if (irq_flags == IRQF_TRIGGER_NONE)
1302 dev_warn(db->dev, "WARNING: no IRQ resource flags set.\n");
1304 irq_flags |= IRQF_SHARED;
1306 /* GPIO0 on pre-activate PHY, Reg 1F is not set by reset */
1307 iow(db, DM9000_GPR, 0); /* REG_1F bit0 activate phyxcer */
1308 mdelay(1); /* delay needs by DM9000B */
1310 /* Initialize DM9000 board */
1311 dm9000_init_dm9000(dev);
1313 if (request_irq(dev->irq, dm9000_interrupt, irq_flags, dev->name, dev))
1315 /* Now that we have an interrupt handler hooked up we can unmask
1318 dm9000_unmask_interrupts(db);
1320 /* Init driver variable */
1323 mii_check_media(&db->mii, netif_msg_link(db), 1);
1324 netif_start_queue(dev);
1326 /* Poll initial link status */
1327 schedule_delayed_work(&db->phy_poll, 1);
1333 dm9000_shutdown(struct net_device *dev)
1335 struct board_info *db = netdev_priv(dev);
1338 dm9000_phy_write(dev, 0, MII_BMCR, BMCR_RESET); /* PHY RESET */
1339 iow(db, DM9000_GPR, 0x01); /* Power-Down PHY */
1340 dm9000_mask_interrupts(db);
1341 iow(db, DM9000_RCR, 0x00); /* Disable RX */
1345 * Stop the interface.
1346 * The interface is stopped when it is brought.
1349 dm9000_stop(struct net_device *ndev)
1351 struct board_info *db = netdev_priv(ndev);
1353 if (netif_msg_ifdown(db))
1354 dev_dbg(db->dev, "shutting down %s\n", ndev->name);
1356 cancel_delayed_work_sync(&db->phy_poll);
1358 netif_stop_queue(ndev);
1359 netif_carrier_off(ndev);
1361 /* free interrupt */
1362 free_irq(ndev->irq, ndev);
1364 dm9000_shutdown(ndev);
1369 static const struct net_device_ops dm9000_netdev_ops = {
1370 .ndo_open = dm9000_open,
1371 .ndo_stop = dm9000_stop,
1372 .ndo_start_xmit = dm9000_start_xmit,
1373 .ndo_tx_timeout = dm9000_timeout,
1374 .ndo_set_rx_mode = dm9000_hash_table,
1375 .ndo_do_ioctl = dm9000_ioctl,
1376 .ndo_set_features = dm9000_set_features,
1377 .ndo_validate_addr = eth_validate_addr,
1378 .ndo_set_mac_address = eth_mac_addr,
1379 #ifdef CONFIG_NET_POLL_CONTROLLER
1380 .ndo_poll_controller = dm9000_poll_controller,
1384 static struct dm9000_plat_data *dm9000_parse_dt(struct device *dev)
1386 struct dm9000_plat_data *pdata;
1387 struct device_node *np = dev->of_node;
1390 if (!IS_ENABLED(CONFIG_OF) || !np)
1391 return ERR_PTR(-ENXIO);
1393 pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
1395 return ERR_PTR(-ENOMEM);
1397 if (of_find_property(np, "davicom,ext-phy", NULL))
1398 pdata->flags |= DM9000_PLATF_EXT_PHY;
1399 if (of_find_property(np, "davicom,no-eeprom", NULL))
1400 pdata->flags |= DM9000_PLATF_NO_EEPROM;
1402 ret = of_get_mac_address(np, pdata->dev_addr);
1403 if (ret == -EPROBE_DEFER)
1404 return ERR_PTR(ret);
1410 * Search DM9000 board, allocate space and register it
1413 dm9000_probe(struct platform_device *pdev)
1415 struct dm9000_plat_data *pdata = dev_get_platdata(&pdev->dev);
1416 struct board_info *db; /* Point a board information structure */
1417 struct net_device *ndev;
1418 struct device *dev = &pdev->dev;
1419 const unsigned char *mac_src;
1425 enum of_gpio_flags flags;
1426 struct regulator *power;
1427 bool inv_mac_addr = false;
1429 power = devm_regulator_get(dev, "vcc");
1430 if (IS_ERR(power)) {
1431 if (PTR_ERR(power) == -EPROBE_DEFER)
1432 return -EPROBE_DEFER;
1433 dev_dbg(dev, "no regulator provided\n");
1435 ret = regulator_enable(power);
1438 "Failed to enable power regulator: %d\n", ret);
1441 dev_dbg(dev, "regulator enabled\n");
1444 reset_gpios = of_get_named_gpio_flags(dev->of_node, "reset-gpios", 0,
1446 if (gpio_is_valid(reset_gpios)) {
1447 ret = devm_gpio_request_one(dev, reset_gpios, flags,
1450 dev_err(dev, "failed to request reset gpio %d: %d\n",
1452 goto out_regulator_disable;
1455 /* According to manual PWRST# Low Period Min 1ms */
1457 gpio_set_value(reset_gpios, 1);
1458 /* Needs 3ms to read eeprom when PWRST is deasserted */
1463 pdata = dm9000_parse_dt(&pdev->dev);
1464 if (IS_ERR(pdata)) {
1465 ret = PTR_ERR(pdata);
1466 goto out_regulator_disable;
1470 /* Init network device */
1471 ndev = alloc_etherdev(sizeof(struct board_info));
1474 goto out_regulator_disable;
1477 SET_NETDEV_DEV(ndev, &pdev->dev);
1479 dev_dbg(&pdev->dev, "dm9000_probe()\n");
1481 /* setup board info structure */
1482 db = netdev_priv(ndev);
1484 db->dev = &pdev->dev;
1487 db->power_supply = power;
1489 spin_lock_init(&db->lock);
1490 mutex_init(&db->addr_lock);
1492 INIT_DELAYED_WORK(&db->phy_poll, dm9000_poll_work);
1494 db->addr_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1495 db->data_res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
1497 if (!db->addr_res || !db->data_res) {
1498 dev_err(db->dev, "insufficient resources addr=%p data=%p\n",
1499 db->addr_res, db->data_res);
1504 ndev->irq = platform_get_irq(pdev, 0);
1505 if (ndev->irq < 0) {
1510 db->irq_wake = platform_get_irq_optional(pdev, 1);
1511 if (db->irq_wake >= 0) {
1512 dev_dbg(db->dev, "wakeup irq %d\n", db->irq_wake);
1514 ret = request_irq(db->irq_wake, dm9000_wol_interrupt,
1515 IRQF_SHARED, dev_name(db->dev), ndev);
1517 dev_err(db->dev, "cannot get wakeup irq (%d)\n", ret);
1520 /* test to see if irq is really wakeup capable */
1521 ret = irq_set_irq_wake(db->irq_wake, 1);
1523 dev_err(db->dev, "irq %d cannot set wakeup (%d)\n",
1527 irq_set_irq_wake(db->irq_wake, 0);
1528 db->wake_supported = 1;
1533 iosize = resource_size(db->addr_res);
1534 db->addr_req = request_mem_region(db->addr_res->start, iosize,
1537 if (db->addr_req == NULL) {
1538 dev_err(db->dev, "cannot claim address reg area\n");
1543 db->io_addr = ioremap(db->addr_res->start, iosize);
1545 if (db->io_addr == NULL) {
1546 dev_err(db->dev, "failed to ioremap address reg\n");
1551 iosize = resource_size(db->data_res);
1552 db->data_req = request_mem_region(db->data_res->start, iosize,
1555 if (db->data_req == NULL) {
1556 dev_err(db->dev, "cannot claim data reg area\n");
1561 db->io_data = ioremap(db->data_res->start, iosize);
1563 if (db->io_data == NULL) {
1564 dev_err(db->dev, "failed to ioremap data reg\n");
1569 /* fill in parameters for net-dev structure */
1570 ndev->base_addr = (unsigned long)db->io_addr;
1572 /* ensure at least we have a default set of IO routines */
1573 dm9000_set_io(db, iosize);
1575 /* check to see if anything is being over-ridden */
1576 if (pdata != NULL) {
1577 /* check to see if the driver wants to over-ride the
1578 * default IO width */
1580 if (pdata->flags & DM9000_PLATF_8BITONLY)
1581 dm9000_set_io(db, 1);
1583 if (pdata->flags & DM9000_PLATF_16BITONLY)
1584 dm9000_set_io(db, 2);
1586 if (pdata->flags & DM9000_PLATF_32BITONLY)
1587 dm9000_set_io(db, 4);
1589 /* check to see if there are any IO routine
1592 if (pdata->inblk != NULL)
1593 db->inblk = pdata->inblk;
1595 if (pdata->outblk != NULL)
1596 db->outblk = pdata->outblk;
1598 if (pdata->dumpblk != NULL)
1599 db->dumpblk = pdata->dumpblk;
1601 db->flags = pdata->flags;
1604 #ifdef CONFIG_DM9000_FORCE_SIMPLE_PHY_POLL
1605 db->flags |= DM9000_PLATF_SIMPLE_PHY;
1610 /* try multiple times, DM9000 sometimes gets the read wrong */
1611 for (i = 0; i < 8; i++) {
1612 id_val = ior(db, DM9000_VIDL);
1613 id_val |= (u32)ior(db, DM9000_VIDH) << 8;
1614 id_val |= (u32)ior(db, DM9000_PIDL) << 16;
1615 id_val |= (u32)ior(db, DM9000_PIDH) << 24;
1617 if (id_val == DM9000_ID)
1619 dev_err(db->dev, "read wrong id 0x%08x\n", id_val);
1622 if (id_val != DM9000_ID) {
1623 dev_err(db->dev, "wrong id: 0x%08x\n", id_val);
1628 /* Identify what type of DM9000 we are working on */
1630 id_val = ior(db, DM9000_CHIPR);
1631 dev_dbg(db->dev, "dm9000 revision 0x%02x\n", id_val);
1635 db->type = TYPE_DM9000A;
1638 db->type = TYPE_DM9000B;
1641 dev_dbg(db->dev, "ID %02x => defaulting to DM9000E\n", id_val);
1642 db->type = TYPE_DM9000E;
1645 /* dm9000a/b are capable of hardware checksum offload */
1646 if (db->type == TYPE_DM9000A || db->type == TYPE_DM9000B) {
1647 ndev->hw_features = NETIF_F_RXCSUM | NETIF_F_IP_CSUM;
1648 ndev->features |= ndev->hw_features;
1651 /* from this point we assume that we have found a DM9000 */
1653 ndev->netdev_ops = &dm9000_netdev_ops;
1654 ndev->watchdog_timeo = msecs_to_jiffies(watchdog);
1655 ndev->ethtool_ops = &dm9000_ethtool_ops;
1657 db->msg_enable = NETIF_MSG_LINK;
1658 db->mii.phy_id_mask = 0x1f;
1659 db->mii.reg_num_mask = 0x1f;
1660 db->mii.force_media = 0;
1661 db->mii.full_duplex = 0;
1663 db->mii.mdio_read = dm9000_phy_read;
1664 db->mii.mdio_write = dm9000_phy_write;
1668 /* try reading the node address from the attached EEPROM */
1669 for (i = 0; i < 6; i += 2)
1670 dm9000_read_eeprom(db, i / 2, ndev->dev_addr+i);
1672 if (!is_valid_ether_addr(ndev->dev_addr) && pdata != NULL) {
1673 mac_src = "platform data";
1674 memcpy(ndev->dev_addr, pdata->dev_addr, ETH_ALEN);
1677 if (!is_valid_ether_addr(ndev->dev_addr)) {
1678 /* try reading from mac */
1681 for (i = 0; i < 6; i++)
1682 ndev->dev_addr[i] = ior(db, i+DM9000_PAR);
1685 if (!is_valid_ether_addr(ndev->dev_addr)) {
1686 inv_mac_addr = true;
1687 eth_hw_addr_random(ndev);
1692 platform_set_drvdata(pdev, ndev);
1693 ret = register_netdev(ndev);
1697 dev_warn(db->dev, "%s: Invalid ethernet MAC address. Please set using ip\n",
1699 printk(KERN_INFO "%s: dm9000%c at %p,%p IRQ %d MAC: %pM (%s)\n",
1700 ndev->name, dm9000_type_to_char(db->type),
1701 db->io_addr, db->io_data, ndev->irq,
1702 ndev->dev_addr, mac_src);
1707 dev_err(db->dev, "not found (%d).\n", ret);
1709 dm9000_release_board(pdev, db);
1712 out_regulator_disable:
1714 regulator_disable(power);
1720 dm9000_drv_suspend(struct device *dev)
1722 struct net_device *ndev = dev_get_drvdata(dev);
1723 struct board_info *db;
1726 db = netdev_priv(ndev);
1729 if (!netif_running(ndev))
1732 netif_device_detach(ndev);
1734 /* only shutdown if not using WoL */
1735 if (!db->wake_state)
1736 dm9000_shutdown(ndev);
1742 dm9000_drv_resume(struct device *dev)
1744 struct net_device *ndev = dev_get_drvdata(dev);
1745 struct board_info *db = netdev_priv(ndev);
1748 if (netif_running(ndev)) {
1749 /* reset if we were not in wake mode to ensure if
1750 * the device was powered off it is in a known state */
1751 if (!db->wake_state) {
1752 dm9000_init_dm9000(ndev);
1753 dm9000_unmask_interrupts(db);
1756 netif_device_attach(ndev);
1764 static const struct dev_pm_ops dm9000_drv_pm_ops = {
1765 .suspend = dm9000_drv_suspend,
1766 .resume = dm9000_drv_resume,
1770 dm9000_drv_remove(struct platform_device *pdev)
1772 struct net_device *ndev = platform_get_drvdata(pdev);
1773 struct board_info *dm = to_dm9000_board(ndev);
1775 unregister_netdev(ndev);
1776 dm9000_release_board(pdev, dm);
1777 free_netdev(ndev); /* free device structure */
1778 if (dm->power_supply)
1779 regulator_disable(dm->power_supply);
1781 dev_dbg(&pdev->dev, "released and freed device\n");
1786 static const struct of_device_id dm9000_of_matches[] = {
1787 { .compatible = "davicom,dm9000", },
1790 MODULE_DEVICE_TABLE(of, dm9000_of_matches);
1793 static struct platform_driver dm9000_driver = {
1796 .pm = &dm9000_drv_pm_ops,
1797 .of_match_table = of_match_ptr(dm9000_of_matches),
1799 .probe = dm9000_probe,
1800 .remove = dm9000_drv_remove,
1803 module_platform_driver(dm9000_driver);
1805 MODULE_AUTHOR("Sascha Hauer, Ben Dooks");
1806 MODULE_DESCRIPTION("Davicom DM9000 network driver");
1807 MODULE_LICENSE("GPL");
1808 MODULE_ALIAS("platform:dm9000");