at91_ether.c 16 KB

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