at91_ether.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  1. /*
  2. * Ethernet driver for the Atmel AT91RM9200 (Thunder)
  3. *
  4. * Copyright (C) 2003 SAN People (Pty) Ltd
  5. *
  6. * Based on an earlier Atmel EMAC macrocell driver by Atmel and Lineo Inc.
  7. * Initial version by Rick Bronson 01/11/2003
  8. *
  9. * Intel LXT971A PHY support by Christopher Bahns & David Knickerbocker
  10. * (Polaroid Corporation)
  11. *
  12. * Realtek RTL8201(B)L PHY support by Roman Avramenko <roman@imsystems.ru>
  13. *
  14. * This program is free software; you can redistribute it and/or
  15. * modify it under the terms of the GNU General Public License
  16. * as published by the Free Software Foundation; either version
  17. * 2 of the License, or (at your option) any later version.
  18. */
  19. #include <linux/module.h>
  20. #include <linux/init.h>
  21. #include <linux/interrupt.h>
  22. #include <linux/netdevice.h>
  23. #include <linux/etherdevice.h>
  24. #include <linux/skbuff.h>
  25. #include <linux/dma-mapping.h>
  26. #include <linux/ethtool.h>
  27. #include <linux/platform_data/macb.h>
  28. #include <linux/platform_device.h>
  29. #include <linux/clk.h>
  30. #include <linux/gfp.h>
  31. #include <linux/phy.h>
  32. #include <asm/io.h>
  33. #include <asm/uaccess.h>
  34. #include <asm/mach-types.h>
  35. #include "macb.h"
  36. #define DRV_NAME "at91_ether"
  37. #define DRV_VERSION "1.0"
  38. /* 1518 rounded up */
  39. #define MAX_RBUFF_SZ 0x600
  40. /* max number of receive buffers */
  41. #define MAX_RX_DESCR 9
  42. /* ......................... ADDRESS MANAGEMENT ........................ */
  43. /*
  44. * NOTE: Your bootloader must always set the MAC address correctly before
  45. * booting into Linux.
  46. *
  47. * - It must always set the MAC address after reset, even if it doesn't
  48. * happen to access the Ethernet while it's booting. Some versions of
  49. * U-Boot on the AT91RM9200-DK do not do this.
  50. *
  51. * - Likewise it must store the addresses in the correct byte order.
  52. * MicroMonitor (uMon) on the CSB337 does this incorrectly (and
  53. * continues to do so, for bug-compatibility).
  54. */
  55. static short __init unpack_mac_address(struct net_device *dev, unsigned int hi, unsigned int lo)
  56. {
  57. char addr[6];
  58. if (machine_is_csb337()) {
  59. addr[5] = (lo & 0xff); /* The CSB337 bootloader stores the MAC the wrong-way around */
  60. addr[4] = (lo & 0xff00) >> 8;
  61. addr[3] = (lo & 0xff0000) >> 16;
  62. addr[2] = (lo & 0xff000000) >> 24;
  63. addr[1] = (hi & 0xff);
  64. addr[0] = (hi & 0xff00) >> 8;
  65. }
  66. else {
  67. addr[0] = (lo & 0xff);
  68. addr[1] = (lo & 0xff00) >> 8;
  69. addr[2] = (lo & 0xff0000) >> 16;
  70. addr[3] = (lo & 0xff000000) >> 24;
  71. addr[4] = (hi & 0xff);
  72. addr[5] = (hi & 0xff00) >> 8;
  73. }
  74. if (is_valid_ether_addr(addr)) {
  75. memcpy(dev->dev_addr, &addr, 6);
  76. return 1;
  77. }
  78. return 0;
  79. }
  80. /*
  81. * Set the ethernet MAC address in dev->dev_addr
  82. */
  83. static void __init get_mac_address(struct net_device *dev)
  84. {
  85. struct macb *lp = netdev_priv(dev);
  86. /* Check Specific-Address 1 */
  87. if (unpack_mac_address(dev, macb_readl(lp, SA1T), macb_readl(lp, SA1B)))
  88. return;
  89. /* Check Specific-Address 2 */
  90. if (unpack_mac_address(dev, macb_readl(lp, SA2T), macb_readl(lp, SA2B)))
  91. return;
  92. /* Check Specific-Address 3 */
  93. if (unpack_mac_address(dev, macb_readl(lp, SA3T), macb_readl(lp, SA3B)))
  94. return;
  95. /* Check Specific-Address 4 */
  96. if (unpack_mac_address(dev, macb_readl(lp, SA4T), macb_readl(lp, SA4B)))
  97. return;
  98. printk(KERN_ERR "at91_ether: Your bootloader did not configure a MAC address.\n");
  99. }
  100. /*
  101. * Program the hardware MAC address from dev->dev_addr.
  102. */
  103. static void update_mac_address(struct net_device *dev)
  104. {
  105. struct macb *lp = netdev_priv(dev);
  106. macb_writel(lp, SA1B, (dev->dev_addr[3] << 24) | (dev->dev_addr[2] << 16)
  107. | (dev->dev_addr[1] << 8) | (dev->dev_addr[0]));
  108. macb_writel(lp, SA1T, (dev->dev_addr[5] << 8) | (dev->dev_addr[4]));
  109. macb_writel(lp, SA2B, 0);
  110. macb_writel(lp, SA2T, 0);
  111. }
  112. /*
  113. * Store the new hardware address in dev->dev_addr, and update the MAC.
  114. */
  115. static int set_mac_address(struct net_device *dev, void* addr)
  116. {
  117. struct sockaddr *address = addr;
  118. if (!is_valid_ether_addr(address->sa_data))
  119. return -EADDRNOTAVAIL;
  120. memcpy(dev->dev_addr, address->sa_data, dev->addr_len);
  121. update_mac_address(dev);
  122. printk("%s: Setting MAC address to %pM\n", dev->name,
  123. dev->dev_addr);
  124. return 0;
  125. }
  126. /* ................................ MAC ................................ */
  127. /*
  128. * Initialize and start the Receiver and Transmit subsystems
  129. */
  130. static int at91ether_start(struct net_device *dev)
  131. {
  132. struct macb *lp = netdev_priv(dev);
  133. unsigned long ctl;
  134. dma_addr_t addr;
  135. int i;
  136. lp->rx_ring = dma_alloc_coherent(&lp->pdev->dev,
  137. MAX_RX_DESCR * sizeof(struct dma_desc),
  138. &lp->rx_ring_dma, GFP_KERNEL);
  139. if (!lp->rx_ring) {
  140. netdev_err(lp->dev, "unable to alloc rx ring DMA buffer\n");
  141. return -ENOMEM;
  142. }
  143. lp->rx_buffers = dma_alloc_coherent(&lp->pdev->dev,
  144. MAX_RX_DESCR * MAX_RBUFF_SZ,
  145. &lp->rx_buffers_dma, GFP_KERNEL);
  146. if (!lp->rx_buffers) {
  147. netdev_err(lp->dev, "unable to alloc rx data DMA buffer\n");
  148. dma_free_coherent(&lp->pdev->dev,
  149. MAX_RX_DESCR * sizeof(struct dma_desc),
  150. lp->rx_ring, lp->rx_ring_dma);
  151. lp->rx_ring = NULL;
  152. return -ENOMEM;
  153. }
  154. addr = lp->rx_buffers_dma;
  155. for (i = 0; i < MAX_RX_DESCR; i++) {
  156. lp->rx_ring[i].addr = addr;
  157. lp->rx_ring[i].ctrl = 0;
  158. addr += MAX_RBUFF_SZ;
  159. }
  160. /* Set the Wrap bit on the last descriptor */
  161. lp->rx_ring[MAX_RX_DESCR - 1].addr |= MACB_BIT(RX_WRAP);
  162. /* Reset buffer index */
  163. lp->rx_tail = 0;
  164. /* Program address of descriptor list in Rx Buffer Queue register */
  165. macb_writel(lp, RBQP, lp->rx_ring_dma);
  166. /* Enable Receive and Transmit */
  167. ctl = macb_readl(lp, NCR);
  168. macb_writel(lp, NCR, ctl | MACB_BIT(RE) | MACB_BIT(TE));
  169. return 0;
  170. }
  171. /*
  172. * Open the ethernet interface
  173. */
  174. static int at91ether_open(struct net_device *dev)
  175. {
  176. struct macb *lp = netdev_priv(dev);
  177. unsigned long ctl;
  178. int ret;
  179. if (!is_valid_ether_addr(dev->dev_addr))
  180. return -EADDRNOTAVAIL;
  181. /* Clear internal statistics */
  182. ctl = macb_readl(lp, NCR);
  183. macb_writel(lp, NCR, ctl | MACB_BIT(CLRSTAT));
  184. /* Update the MAC address (incase user has changed it) */
  185. update_mac_address(dev);
  186. ret = at91ether_start(dev);
  187. if (ret)
  188. return ret;
  189. /* Enable MAC interrupts */
  190. macb_writel(lp, IER, MACB_BIT(RCOMP) | MACB_BIT(RXUBR)
  191. | MACB_BIT(ISR_TUND) | MACB_BIT(ISR_RLE) | MACB_BIT(TCOMP)
  192. | MACB_BIT(ISR_ROVR) | MACB_BIT(HRESP));
  193. /* schedule a link state check */
  194. phy_start(lp->phy_dev);
  195. netif_start_queue(dev);
  196. return 0;
  197. }
  198. /*
  199. * Close the interface
  200. */
  201. static int at91ether_close(struct net_device *dev)
  202. {
  203. struct macb *lp = netdev_priv(dev);
  204. unsigned long ctl;
  205. /* Disable Receiver and Transmitter */
  206. ctl = macb_readl(lp, NCR);
  207. macb_writel(lp, NCR, ctl & ~(MACB_BIT(TE) | MACB_BIT(RE)));
  208. /* Disable MAC interrupts */
  209. macb_writel(lp, IDR, MACB_BIT(RCOMP) | MACB_BIT(RXUBR)
  210. | MACB_BIT(ISR_TUND) | MACB_BIT(ISR_RLE)
  211. | MACB_BIT(TCOMP) | MACB_BIT(ISR_ROVR)
  212. | MACB_BIT(HRESP));
  213. netif_stop_queue(dev);
  214. dma_free_coherent(&lp->pdev->dev,
  215. MAX_RX_DESCR * sizeof(struct dma_desc),
  216. lp->rx_ring, lp->rx_ring_dma);
  217. lp->rx_ring = NULL;
  218. dma_free_coherent(&lp->pdev->dev,
  219. MAX_RX_DESCR * MAX_RBUFF_SZ,
  220. lp->rx_buffers, lp->rx_buffers_dma);
  221. lp->rx_buffers = NULL;
  222. return 0;
  223. }
  224. /*
  225. * Transmit packet.
  226. */
  227. static int at91ether_start_xmit(struct sk_buff *skb, struct net_device *dev)
  228. {
  229. struct macb *lp = netdev_priv(dev);
  230. if (macb_readl(lp, TSR) & MACB_BIT(RM9200_BNQ)) {
  231. netif_stop_queue(dev);
  232. /* Store packet information (to free when Tx completed) */
  233. lp->skb = skb;
  234. lp->skb_length = skb->len;
  235. lp->skb_physaddr = dma_map_single(NULL, skb->data, skb->len, DMA_TO_DEVICE);
  236. dev->stats.tx_bytes += skb->len;
  237. /* Set address of the data in the Transmit Address register */
  238. macb_writel(lp, TAR, lp->skb_physaddr);
  239. /* Set length of the packet in the Transmit Control register */
  240. macb_writel(lp, TCR, skb->len);
  241. } else {
  242. printk(KERN_ERR "at91_ether.c: at91ether_start_xmit() called, but device is busy!\n");
  243. return NETDEV_TX_BUSY; /* if we return anything but zero, dev.c:1055 calls kfree_skb(skb)
  244. on this skb, he also reports -ENETDOWN and printk's, so either
  245. we free and return(0) or don't free and return 1 */
  246. }
  247. return NETDEV_TX_OK;
  248. }
  249. /*
  250. * Update the current statistics from the internal statistics registers.
  251. */
  252. static struct net_device_stats *at91ether_stats(struct net_device *dev)
  253. {
  254. struct macb *lp = netdev_priv(dev);
  255. int ale, lenerr, seqe, lcol, ecol;
  256. if (netif_running(dev)) {
  257. dev->stats.rx_packets += macb_readl(lp, FRO); /* Good frames received */
  258. ale = macb_readl(lp, ALE);
  259. dev->stats.rx_frame_errors += ale; /* Alignment errors */
  260. lenerr = macb_readl(lp, ELE) + macb_readl(lp, USF);
  261. dev->stats.rx_length_errors += lenerr; /* Excessive Length or Undersize Frame error */
  262. seqe = macb_readl(lp, FCSE);
  263. dev->stats.rx_crc_errors += seqe; /* CRC error */
  264. dev->stats.rx_fifo_errors += macb_readl(lp, RRE);/* Receive buffer not available */
  265. dev->stats.rx_errors += (ale + lenerr + seqe
  266. + macb_readl(lp, RSE) + macb_readl(lp, RJA));
  267. dev->stats.tx_packets += macb_readl(lp, FTO); /* Frames successfully transmitted */
  268. dev->stats.tx_fifo_errors += macb_readl(lp, TUND); /* Transmit FIFO underruns */
  269. dev->stats.tx_carrier_errors += macb_readl(lp, CSE); /* Carrier Sense errors */
  270. dev->stats.tx_heartbeat_errors += macb_readl(lp, STE);/* Heartbeat error */
  271. lcol = macb_readl(lp, LCOL);
  272. ecol = macb_readl(lp, EXCOL);
  273. dev->stats.tx_window_errors += lcol; /* Late collisions */
  274. dev->stats.tx_aborted_errors += ecol; /* 16 collisions */
  275. dev->stats.collisions += (macb_readl(lp, SCF) + macb_readl(lp, MCF) + lcol + ecol);
  276. }
  277. return &dev->stats;
  278. }
  279. /*
  280. * Extract received frame from buffer descriptors and sent to upper layers.
  281. * (Called from interrupt context)
  282. */
  283. static void at91ether_rx(struct net_device *dev)
  284. {
  285. struct macb *lp = netdev_priv(dev);
  286. unsigned char *p_recv;
  287. struct sk_buff *skb;
  288. unsigned int pktlen;
  289. while (lp->rx_ring[lp->rx_tail].addr & MACB_BIT(RX_USED)) {
  290. p_recv = lp->rx_buffers + lp->rx_tail * MAX_RBUFF_SZ;
  291. pktlen = MACB_BF(RX_FRMLEN, lp->rx_ring[lp->rx_tail].ctrl);
  292. skb = netdev_alloc_skb(dev, pktlen + 2);
  293. if (skb) {
  294. skb_reserve(skb, 2);
  295. memcpy(skb_put(skb, pktlen), p_recv, pktlen);
  296. skb->protocol = eth_type_trans(skb, dev);
  297. dev->stats.rx_bytes += pktlen;
  298. netif_rx(skb);
  299. } else {
  300. dev->stats.rx_dropped += 1;
  301. netdev_notice(dev, "Memory squeeze, dropping packet.\n");
  302. }
  303. if (lp->rx_ring[lp->rx_tail].ctrl & MACB_BIT(RX_MHASH_MATCH))
  304. dev->stats.multicast++;
  305. /* reset ownership bit */
  306. lp->rx_ring[lp->rx_tail].addr &= ~MACB_BIT(RX_USED);
  307. /* wrap after last buffer */
  308. if (lp->rx_tail == MAX_RX_DESCR - 1)
  309. lp->rx_tail = 0;
  310. else
  311. lp->rx_tail++;
  312. }
  313. }
  314. /*
  315. * MAC interrupt handler
  316. */
  317. static irqreturn_t at91ether_interrupt(int irq, void *dev_id)
  318. {
  319. struct net_device *dev = (struct net_device *) dev_id;
  320. struct macb *lp = netdev_priv(dev);
  321. unsigned long intstatus, ctl;
  322. /* MAC Interrupt Status register indicates what interrupts are pending.
  323. It is automatically cleared once read. */
  324. intstatus = macb_readl(lp, ISR);
  325. if (intstatus & MACB_BIT(RCOMP)) /* Receive complete */
  326. at91ether_rx(dev);
  327. if (intstatus & MACB_BIT(TCOMP)) { /* Transmit complete */
  328. /* The TCOM bit is set even if the transmission failed. */
  329. if (intstatus & (MACB_BIT(ISR_TUND) | MACB_BIT(ISR_RLE)))
  330. dev->stats.tx_errors += 1;
  331. if (lp->skb) {
  332. dev_kfree_skb_irq(lp->skb);
  333. lp->skb = NULL;
  334. dma_unmap_single(NULL, lp->skb_physaddr, lp->skb_length, DMA_TO_DEVICE);
  335. }
  336. netif_wake_queue(dev);
  337. }
  338. /* Work-around for Errata #11 */
  339. if (intstatus & MACB_BIT(RXUBR)) {
  340. ctl = macb_readl(lp, NCR);
  341. macb_writel(lp, NCR, ctl & ~MACB_BIT(RE));
  342. macb_writel(lp, NCR, ctl | MACB_BIT(RE));
  343. }
  344. if (intstatus & MACB_BIT(ISR_ROVR))
  345. printk("%s: ROVR error\n", dev->name);
  346. return IRQ_HANDLED;
  347. }
  348. #ifdef CONFIG_NET_POLL_CONTROLLER
  349. static void at91ether_poll_controller(struct net_device *dev)
  350. {
  351. unsigned long flags;
  352. local_irq_save(flags);
  353. at91ether_interrupt(dev->irq, dev);
  354. local_irq_restore(flags);
  355. }
  356. #endif
  357. static const struct net_device_ops at91ether_netdev_ops = {
  358. .ndo_open = at91ether_open,
  359. .ndo_stop = at91ether_close,
  360. .ndo_start_xmit = at91ether_start_xmit,
  361. .ndo_get_stats = at91ether_stats,
  362. .ndo_set_rx_mode = macb_set_rx_mode,
  363. .ndo_set_mac_address = set_mac_address,
  364. .ndo_do_ioctl = macb_ioctl,
  365. .ndo_validate_addr = eth_validate_addr,
  366. .ndo_change_mtu = eth_change_mtu,
  367. #ifdef CONFIG_NET_POLL_CONTROLLER
  368. .ndo_poll_controller = at91ether_poll_controller,
  369. #endif
  370. };
  371. /*
  372. * Detect MAC & PHY and perform ethernet interface initialization
  373. */
  374. static int __init at91ether_probe(struct platform_device *pdev)
  375. {
  376. struct macb_platform_data *board_data = pdev->dev.platform_data;
  377. struct resource *regs;
  378. struct net_device *dev;
  379. struct phy_device *phydev;
  380. struct macb *lp;
  381. int res;
  382. regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  383. if (!regs)
  384. return -ENOENT;
  385. dev = alloc_etherdev(sizeof(struct macb));
  386. if (!dev)
  387. return -ENOMEM;
  388. lp = netdev_priv(dev);
  389. lp->pdev = pdev;
  390. lp->dev = dev;
  391. lp->board_data = *board_data;
  392. spin_lock_init(&lp->lock);
  393. dev->base_addr = regs->start; /* physical base address */
  394. lp->regs = ioremap(regs->start, regs->end - regs->start + 1);
  395. if (!lp->regs) {
  396. res = -ENOMEM;
  397. goto err_free_dev;
  398. }
  399. /* Clock */
  400. lp->pclk = clk_get(&pdev->dev, "ether_clk");
  401. if (IS_ERR(lp->pclk)) {
  402. res = PTR_ERR(lp->pclk);
  403. goto err_ioumap;
  404. }
  405. clk_enable(lp->pclk);
  406. /* Install the interrupt handler */
  407. dev->irq = platform_get_irq(pdev, 0);
  408. if (request_irq(dev->irq, at91ether_interrupt, 0, dev->name, dev)) {
  409. res = -EBUSY;
  410. goto err_disable_clock;
  411. }
  412. ether_setup(dev);
  413. dev->netdev_ops = &at91ether_netdev_ops;
  414. dev->ethtool_ops = &macb_ethtool_ops;
  415. platform_set_drvdata(pdev, dev);
  416. SET_NETDEV_DEV(dev, &pdev->dev);
  417. get_mac_address(dev); /* Get ethernet address and store it in dev->dev_addr */
  418. update_mac_address(dev); /* Program ethernet address into MAC */
  419. macb_writel(lp, NCR, 0);
  420. if (board_data->is_rmii) {
  421. macb_writel(lp, NCFGR, MACB_BF(CLK, MACB_CLK_DIV32) | MACB_BIT(BIG) | MACB_BIT(RM9200_RMII));
  422. lp->phy_interface = PHY_INTERFACE_MODE_RMII;
  423. } else {
  424. macb_writel(lp, NCFGR, MACB_BF(CLK, MACB_CLK_DIV32) | MACB_BIT(BIG));
  425. lp->phy_interface = PHY_INTERFACE_MODE_MII;
  426. }
  427. /* Register the network interface */
  428. res = register_netdev(dev);
  429. if (res)
  430. goto err_free_irq;
  431. if (macb_mii_init(lp) != 0)
  432. goto err_out_unregister_netdev;
  433. netif_carrier_off(dev); /* will be enabled in open() */
  434. phydev = lp->phy_dev;
  435. netdev_info(dev, "attached PHY driver [%s] (mii_bus:phy_addr=%s, irq=%d)\n",
  436. phydev->drv->name, dev_name(&phydev->dev), phydev->irq);
  437. /* Display ethernet banner */
  438. printk(KERN_INFO "%s: AT91 ethernet at 0x%08x int=%d %s%s (%pM)\n",
  439. dev->name, (uint) dev->base_addr, dev->irq,
  440. macb_readl(lp, NCFGR) & MACB_BIT(SPD) ? "100-" : "10-",
  441. macb_readl(lp, NCFGR) & MACB_BIT(FD) ? "FullDuplex" : "HalfDuplex",
  442. dev->dev_addr);
  443. return 0;
  444. err_out_unregister_netdev:
  445. unregister_netdev(dev);
  446. err_free_irq:
  447. platform_set_drvdata(pdev, NULL);
  448. free_irq(dev->irq, dev);
  449. err_disable_clock:
  450. clk_disable(lp->pclk);
  451. clk_put(lp->pclk);
  452. err_ioumap:
  453. iounmap(lp->regs);
  454. err_free_dev:
  455. free_netdev(dev);
  456. return res;
  457. }
  458. static int __devexit at91ether_remove(struct platform_device *pdev)
  459. {
  460. struct net_device *dev = platform_get_drvdata(pdev);
  461. struct macb *lp = netdev_priv(dev);
  462. if (lp->phy_dev)
  463. phy_disconnect(lp->phy_dev);
  464. mdiobus_unregister(lp->mii_bus);
  465. kfree(lp->mii_bus->irq);
  466. mdiobus_free(lp->mii_bus);
  467. unregister_netdev(dev);
  468. free_irq(dev->irq, dev);
  469. iounmap(lp->regs);
  470. clk_disable(lp->pclk);
  471. clk_put(lp->pclk);
  472. free_netdev(dev);
  473. platform_set_drvdata(pdev, NULL);
  474. return 0;
  475. }
  476. #ifdef CONFIG_PM
  477. static int at91ether_suspend(struct platform_device *pdev, pm_message_t mesg)
  478. {
  479. struct net_device *net_dev = platform_get_drvdata(pdev);
  480. struct macb *lp = netdev_priv(net_dev);
  481. if (netif_running(net_dev)) {
  482. netif_stop_queue(net_dev);
  483. netif_device_detach(net_dev);
  484. clk_disable(lp->pclk);
  485. }
  486. return 0;
  487. }
  488. static int at91ether_resume(struct platform_device *pdev)
  489. {
  490. struct net_device *net_dev = platform_get_drvdata(pdev);
  491. struct macb *lp = netdev_priv(net_dev);
  492. if (netif_running(net_dev)) {
  493. clk_enable(lp->pclk);
  494. netif_device_attach(net_dev);
  495. netif_start_queue(net_dev);
  496. }
  497. return 0;
  498. }
  499. #else
  500. #define at91ether_suspend NULL
  501. #define at91ether_resume NULL
  502. #endif
  503. static struct platform_driver at91ether_driver = {
  504. .remove = __devexit_p(at91ether_remove),
  505. .suspend = at91ether_suspend,
  506. .resume = at91ether_resume,
  507. .driver = {
  508. .name = DRV_NAME,
  509. .owner = THIS_MODULE,
  510. },
  511. };
  512. static int __init at91ether_init(void)
  513. {
  514. return platform_driver_probe(&at91ether_driver, at91ether_probe);
  515. }
  516. static void __exit at91ether_exit(void)
  517. {
  518. platform_driver_unregister(&at91ether_driver);
  519. }
  520. module_init(at91ether_init)
  521. module_exit(at91ether_exit)
  522. MODULE_LICENSE("GPL");
  523. MODULE_DESCRIPTION("AT91RM9200 EMAC Ethernet driver");
  524. MODULE_AUTHOR("Andrew Victor");
  525. MODULE_ALIAS("platform:" DRV_NAME);