at91_ether.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135
  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/config.h>
  22. #include <linux/mii.h>
  23. #include <linux/netdevice.h>
  24. #include <linux/etherdevice.h>
  25. #include <linux/skbuff.h>
  26. #include <linux/dma-mapping.h>
  27. #include <linux/ethtool.h>
  28. #include <linux/platform_device.h>
  29. #include <linux/clk.h>
  30. #include <asm/io.h>
  31. #include <asm/uaccess.h>
  32. #include <asm/mach-types.h>
  33. #include <asm/arch/at91rm9200_emac.h>
  34. #include <asm/arch/gpio.h>
  35. #include <asm/arch/board.h>
  36. #include "at91_ether.h"
  37. #define DRV_NAME "at91_ether"
  38. #define DRV_VERSION "1.0"
  39. static struct net_device *at91_dev;
  40. static struct clk *ether_clk;
  41. static struct timer_list check_timer;
  42. #define LINK_POLL_INTERVAL (HZ)
  43. /* ..................................................................... */
  44. /*
  45. * Read from a EMAC register.
  46. */
  47. static inline unsigned long at91_emac_read(unsigned int reg)
  48. {
  49. void __iomem *emac_base = (void __iomem *)AT91_VA_BASE_EMAC;
  50. return __raw_readl(emac_base + reg);
  51. }
  52. /*
  53. * Write to a EMAC register.
  54. */
  55. static inline void at91_emac_write(unsigned int reg, unsigned long value)
  56. {
  57. void __iomem *emac_base = (void __iomem *)AT91_VA_BASE_EMAC;
  58. __raw_writel(value, emac_base + reg);
  59. }
  60. /* ........................... PHY INTERFACE ........................... */
  61. /*
  62. * Enable the MDIO bit in MAC control register
  63. * When not called from an interrupt-handler, access to the PHY must be
  64. * protected by a spinlock.
  65. */
  66. static void enable_mdi(void)
  67. {
  68. unsigned long ctl;
  69. ctl = at91_emac_read(AT91_EMAC_CTL);
  70. at91_emac_write(AT91_EMAC_CTL, ctl | AT91_EMAC_MPE); /* enable management port */
  71. }
  72. /*
  73. * Disable the MDIO bit in the MAC control register
  74. */
  75. static void disable_mdi(void)
  76. {
  77. unsigned long ctl;
  78. ctl = at91_emac_read(AT91_EMAC_CTL);
  79. at91_emac_write(AT91_EMAC_CTL, ctl & ~AT91_EMAC_MPE); /* disable management port */
  80. }
  81. /*
  82. * Wait until the PHY operation is complete.
  83. */
  84. static inline void at91_phy_wait(void) {
  85. unsigned long timeout = jiffies + 2;
  86. while (!(at91_emac_read(AT91_EMAC_SR) & AT91_EMAC_SR_IDLE)) {
  87. if (time_after(jiffies, timeout)) {
  88. printk("at91_ether: MIO timeout\n");
  89. break;
  90. }
  91. cpu_relax();
  92. }
  93. }
  94. /*
  95. * Write value to the a PHY register
  96. * Note: MDI interface is assumed to already have been enabled.
  97. */
  98. static void write_phy(unsigned char phy_addr, unsigned char address, unsigned int value)
  99. {
  100. at91_emac_write(AT91_EMAC_MAN, AT91_EMAC_MAN_802_3 | AT91_EMAC_RW_W
  101. | ((phy_addr & 0x1f) << 23) | (address << 18) | (value & AT91_EMAC_DATA));
  102. /* Wait until IDLE bit in Network Status register is cleared */
  103. at91_phy_wait();
  104. }
  105. /*
  106. * Read value stored in a PHY register.
  107. * Note: MDI interface is assumed to already have been enabled.
  108. */
  109. static void read_phy(unsigned char phy_addr, unsigned char address, unsigned int *value)
  110. {
  111. at91_emac_write(AT91_EMAC_MAN, AT91_EMAC_MAN_802_3 | AT91_EMAC_RW_R
  112. | ((phy_addr & 0x1f) << 23) | (address << 18));
  113. /* Wait until IDLE bit in Network Status register is cleared */
  114. at91_phy_wait();
  115. *value = at91_emac_read(AT91_EMAC_MAN) & AT91_EMAC_DATA;
  116. }
  117. /* ........................... PHY MANAGEMENT .......................... */
  118. /*
  119. * Access the PHY to determine the current link speed and mode, and update the
  120. * MAC accordingly.
  121. * If no link or auto-negotiation is busy, then no changes are made.
  122. */
  123. static void update_linkspeed(struct net_device *dev, int silent)
  124. {
  125. struct at91_private *lp = (struct at91_private *) dev->priv;
  126. unsigned int bmsr, bmcr, lpa, mac_cfg;
  127. unsigned int speed, duplex;
  128. if (!mii_link_ok(&lp->mii)) { /* no link */
  129. netif_carrier_off(dev);
  130. if (!silent)
  131. printk(KERN_INFO "%s: Link down.\n", dev->name);
  132. return;
  133. }
  134. /* Link up, or auto-negotiation still in progress */
  135. read_phy(lp->phy_address, MII_BMSR, &bmsr);
  136. read_phy(lp->phy_address, MII_BMCR, &bmcr);
  137. if (bmcr & BMCR_ANENABLE) { /* AutoNegotiation is enabled */
  138. if (!(bmsr & BMSR_ANEGCOMPLETE))
  139. return; /* Do nothing - another interrupt generated when negotiation complete */
  140. read_phy(lp->phy_address, MII_LPA, &lpa);
  141. if ((lpa & LPA_100FULL) || (lpa & LPA_100HALF)) speed = SPEED_100;
  142. else speed = SPEED_10;
  143. if ((lpa & LPA_100FULL) || (lpa & LPA_10FULL)) duplex = DUPLEX_FULL;
  144. else duplex = DUPLEX_HALF;
  145. } else {
  146. speed = (bmcr & BMCR_SPEED100) ? SPEED_100 : SPEED_10;
  147. duplex = (bmcr & BMCR_FULLDPLX) ? DUPLEX_FULL : DUPLEX_HALF;
  148. }
  149. /* Update the MAC */
  150. mac_cfg = at91_emac_read(AT91_EMAC_CFG) & ~(AT91_EMAC_SPD | AT91_EMAC_FD);
  151. if (speed == SPEED_100) {
  152. if (duplex == DUPLEX_FULL) /* 100 Full Duplex */
  153. mac_cfg |= AT91_EMAC_SPD | AT91_EMAC_FD;
  154. else /* 100 Half Duplex */
  155. mac_cfg |= AT91_EMAC_SPD;
  156. } else {
  157. if (duplex == DUPLEX_FULL) /* 10 Full Duplex */
  158. mac_cfg |= AT91_EMAC_FD;
  159. else {} /* 10 Half Duplex */
  160. }
  161. at91_emac_write(AT91_EMAC_CFG, mac_cfg);
  162. if (!silent)
  163. printk(KERN_INFO "%s: Link now %i-%s\n", dev->name, speed, (duplex == DUPLEX_FULL) ? "FullDuplex" : "HalfDuplex");
  164. netif_carrier_on(dev);
  165. }
  166. /*
  167. * Handle interrupts from the PHY
  168. */
  169. static irqreturn_t at91ether_phy_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  170. {
  171. struct net_device *dev = (struct net_device *) dev_id;
  172. struct at91_private *lp = (struct at91_private *) dev->priv;
  173. unsigned int phy;
  174. /*
  175. * This hander is triggered on both edges, but the PHY chips expect
  176. * level-triggering. We therefore have to check if the PHY actually has
  177. * an IRQ pending.
  178. */
  179. enable_mdi();
  180. if ((lp->phy_type == MII_DM9161_ID) || (lp->phy_type == MII_DM9161A_ID)) {
  181. read_phy(lp->phy_address, MII_DSINTR_REG, &phy); /* ack interrupt in Davicom PHY */
  182. if (!(phy & (1 << 0)))
  183. goto done;
  184. }
  185. else if (lp->phy_type == MII_LXT971A_ID) {
  186. read_phy(lp->phy_address, MII_ISINTS_REG, &phy); /* ack interrupt in Intel PHY */
  187. if (!(phy & (1 << 2)))
  188. goto done;
  189. }
  190. else if (lp->phy_type == MII_BCM5221_ID) {
  191. read_phy(lp->phy_address, MII_BCMINTR_REG, &phy); /* ack interrupt in Broadcom PHY */
  192. if (!(phy & (1 << 0)))
  193. goto done;
  194. }
  195. else if (lp->phy_type == MII_KS8721_ID) {
  196. read_phy(lp->phy_address, MII_TPISTATUS, &phy); /* ack interrupt in Micrel PHY */
  197. if (!(phy & ((1 << 2) | 1)))
  198. goto done;
  199. }
  200. update_linkspeed(dev, 0);
  201. done:
  202. disable_mdi();
  203. return IRQ_HANDLED;
  204. }
  205. /*
  206. * Initialize and enable the PHY interrupt for link-state changes
  207. */
  208. static void enable_phyirq(struct net_device *dev)
  209. {
  210. struct at91_private *lp = (struct at91_private *) dev->priv;
  211. unsigned int dsintr, irq_number;
  212. int status;
  213. irq_number = lp->board_data.phy_irq_pin;
  214. if (!irq_number) {
  215. /*
  216. * PHY doesn't have an IRQ pin (RTL8201, DP83847, AC101L),
  217. * or board does not have it connected.
  218. */
  219. check_timer.expires = jiffies + LINK_POLL_INTERVAL;
  220. add_timer(&check_timer);
  221. return;
  222. }
  223. status = request_irq(irq_number, at91ether_phy_interrupt, 0, dev->name, dev);
  224. if (status) {
  225. printk(KERN_ERR "at91_ether: PHY IRQ %d request failed - status %d!\n", irq_number, status);
  226. return;
  227. }
  228. spin_lock_irq(&lp->lock);
  229. enable_mdi();
  230. if ((lp->phy_type == MII_DM9161_ID) || (lp->phy_type == MII_DM9161A_ID)) { /* for Davicom PHY */
  231. read_phy(lp->phy_address, MII_DSINTR_REG, &dsintr);
  232. dsintr = dsintr & ~0xf00; /* clear bits 8..11 */
  233. write_phy(lp->phy_address, MII_DSINTR_REG, dsintr);
  234. }
  235. else if (lp->phy_type == MII_LXT971A_ID) { /* for Intel PHY */
  236. read_phy(lp->phy_address, MII_ISINTE_REG, &dsintr);
  237. dsintr = dsintr | 0xf2; /* set bits 1, 4..7 */
  238. write_phy(lp->phy_address, MII_ISINTE_REG, dsintr);
  239. }
  240. else if (lp->phy_type == MII_BCM5221_ID) { /* for Broadcom PHY */
  241. dsintr = (1 << 15) | ( 1 << 14);
  242. write_phy(lp->phy_address, MII_BCMINTR_REG, dsintr);
  243. }
  244. else if (lp->phy_type == MII_KS8721_ID) { /* for Micrel PHY */
  245. dsintr = (1 << 10) | ( 1 << 8);
  246. write_phy(lp->phy_address, MII_TPISTATUS, dsintr);
  247. }
  248. disable_mdi();
  249. spin_unlock_irq(&lp->lock);
  250. }
  251. /*
  252. * Disable the PHY interrupt
  253. */
  254. static void disable_phyirq(struct net_device *dev)
  255. {
  256. struct at91_private *lp = (struct at91_private *) dev->priv;
  257. unsigned int dsintr;
  258. unsigned int irq_number;
  259. irq_number = lp->board_data.phy_irq_pin;
  260. if (!irq_number) {
  261. del_timer_sync(&check_timer);
  262. return;
  263. }
  264. spin_lock_irq(&lp->lock);
  265. enable_mdi();
  266. if ((lp->phy_type == MII_DM9161_ID) || (lp->phy_type == MII_DM9161A_ID)) { /* for Davicom PHY */
  267. read_phy(lp->phy_address, MII_DSINTR_REG, &dsintr);
  268. dsintr = dsintr | 0xf00; /* set bits 8..11 */
  269. write_phy(lp->phy_address, MII_DSINTR_REG, dsintr);
  270. }
  271. else if (lp->phy_type == MII_LXT971A_ID) { /* for Intel PHY */
  272. read_phy(lp->phy_address, MII_ISINTE_REG, &dsintr);
  273. dsintr = dsintr & ~0xf2; /* clear bits 1, 4..7 */
  274. write_phy(lp->phy_address, MII_ISINTE_REG, dsintr);
  275. }
  276. else if (lp->phy_type == MII_BCM5221_ID) { /* for Broadcom PHY */
  277. read_phy(lp->phy_address, MII_BCMINTR_REG, &dsintr);
  278. dsintr = ~(1 << 14);
  279. write_phy(lp->phy_address, MII_BCMINTR_REG, dsintr);
  280. }
  281. else if (lp->phy_type == MII_KS8721_ID) { /* for Micrel PHY */
  282. read_phy(lp->phy_address, MII_TPISTATUS, &dsintr);
  283. dsintr = ~((1 << 10) | (1 << 8));
  284. write_phy(lp->phy_address, MII_TPISTATUS, dsintr);
  285. }
  286. disable_mdi();
  287. spin_unlock_irq(&lp->lock);
  288. free_irq(irq_number, dev); /* Free interrupt handler */
  289. }
  290. /*
  291. * Perform a software reset of the PHY.
  292. */
  293. #if 0
  294. static void reset_phy(struct net_device *dev)
  295. {
  296. struct at91_private *lp = (struct at91_private *) dev->priv;
  297. unsigned int bmcr;
  298. spin_lock_irq(&lp->lock);
  299. enable_mdi();
  300. /* Perform PHY reset */
  301. write_phy(lp->phy_address, MII_BMCR, BMCR_RESET);
  302. /* Wait until PHY reset is complete */
  303. do {
  304. read_phy(lp->phy_address, MII_BMCR, &bmcr);
  305. } while (!(bmcr && BMCR_RESET));
  306. disable_mdi();
  307. spin_unlock_irq(&lp->lock);
  308. }
  309. #endif
  310. static void at91ether_check_link(unsigned long dev_id)
  311. {
  312. struct net_device *dev = (struct net_device *) dev_id;
  313. enable_mdi();
  314. update_linkspeed(dev, 1);
  315. disable_mdi();
  316. check_timer.expires = jiffies + LINK_POLL_INTERVAL;
  317. add_timer(&check_timer);
  318. }
  319. /* ......................... ADDRESS MANAGEMENT ........................ */
  320. /*
  321. * NOTE: Your bootloader must always set the MAC address correctly before
  322. * booting into Linux.
  323. *
  324. * - It must always set the MAC address after reset, even if it doesn't
  325. * happen to access the Ethernet while it's booting. Some versions of
  326. * U-Boot on the AT91RM9200-DK do not do this.
  327. *
  328. * - Likewise it must store the addresses in the correct byte order.
  329. * MicroMonitor (uMon) on the CSB337 does this incorrectly (and
  330. * continues to do so, for bug-compatibility).
  331. */
  332. static short __init unpack_mac_address(struct net_device *dev, unsigned int hi, unsigned int lo)
  333. {
  334. char addr[6];
  335. if (machine_is_csb337()) {
  336. addr[5] = (lo & 0xff); /* The CSB337 bootloader stores the MAC the wrong-way around */
  337. addr[4] = (lo & 0xff00) >> 8;
  338. addr[3] = (lo & 0xff0000) >> 16;
  339. addr[2] = (lo & 0xff000000) >> 24;
  340. addr[1] = (hi & 0xff);
  341. addr[0] = (hi & 0xff00) >> 8;
  342. }
  343. else {
  344. addr[0] = (lo & 0xff);
  345. addr[1] = (lo & 0xff00) >> 8;
  346. addr[2] = (lo & 0xff0000) >> 16;
  347. addr[3] = (lo & 0xff000000) >> 24;
  348. addr[4] = (hi & 0xff);
  349. addr[5] = (hi & 0xff00) >> 8;
  350. }
  351. if (is_valid_ether_addr(addr)) {
  352. memcpy(dev->dev_addr, &addr, 6);
  353. return 1;
  354. }
  355. return 0;
  356. }
  357. /*
  358. * Set the ethernet MAC address in dev->dev_addr
  359. */
  360. static void __init get_mac_address(struct net_device *dev)
  361. {
  362. /* Check Specific-Address 1 */
  363. if (unpack_mac_address(dev, at91_emac_read(AT91_EMAC_SA1H), at91_emac_read(AT91_EMAC_SA1L)))
  364. return;
  365. /* Check Specific-Address 2 */
  366. if (unpack_mac_address(dev, at91_emac_read(AT91_EMAC_SA2H), at91_emac_read(AT91_EMAC_SA2L)))
  367. return;
  368. /* Check Specific-Address 3 */
  369. if (unpack_mac_address(dev, at91_emac_read(AT91_EMAC_SA3H), at91_emac_read(AT91_EMAC_SA3L)))
  370. return;
  371. /* Check Specific-Address 4 */
  372. if (unpack_mac_address(dev, at91_emac_read(AT91_EMAC_SA4H), at91_emac_read(AT91_EMAC_SA4L)))
  373. return;
  374. printk(KERN_ERR "at91_ether: Your bootloader did not configure a MAC address.\n");
  375. }
  376. /*
  377. * Program the hardware MAC address from dev->dev_addr.
  378. */
  379. static void update_mac_address(struct net_device *dev)
  380. {
  381. at91_emac_write(AT91_EMAC_SA1L, (dev->dev_addr[3] << 24) | (dev->dev_addr[2] << 16) | (dev->dev_addr[1] << 8) | (dev->dev_addr[0]));
  382. at91_emac_write(AT91_EMAC_SA1H, (dev->dev_addr[5] << 8) | (dev->dev_addr[4]));
  383. at91_emac_write(AT91_EMAC_SA2L, 0);
  384. at91_emac_write(AT91_EMAC_SA2H, 0);
  385. }
  386. /*
  387. * Store the new hardware address in dev->dev_addr, and update the MAC.
  388. */
  389. static int set_mac_address(struct net_device *dev, void* addr)
  390. {
  391. struct sockaddr *address = addr;
  392. if (!is_valid_ether_addr(address->sa_data))
  393. return -EADDRNOTAVAIL;
  394. memcpy(dev->dev_addr, address->sa_data, dev->addr_len);
  395. update_mac_address(dev);
  396. printk("%s: Setting MAC address to %02x:%02x:%02x:%02x:%02x:%02x\n", dev->name,
  397. dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
  398. dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
  399. return 0;
  400. }
  401. static int inline hash_bit_value(int bitnr, __u8 *addr)
  402. {
  403. if (addr[bitnr / 8] & (1 << (bitnr % 8)))
  404. return 1;
  405. return 0;
  406. }
  407. /*
  408. * The hash address register is 64 bits long and takes up two locations in the memory map.
  409. * The least significant bits are stored in EMAC_HSL and the most significant
  410. * bits in EMAC_HSH.
  411. *
  412. * The unicast hash enable and the multicast hash enable bits in the network configuration
  413. * register enable the reception of hash matched frames. The destination address is
  414. * reduced to a 6 bit index into the 64 bit hash register using the following hash function.
  415. * The hash function is an exclusive or of every sixth bit of the destination address.
  416. * hash_index[5] = da[5] ^ da[11] ^ da[17] ^ da[23] ^ da[29] ^ da[35] ^ da[41] ^ da[47]
  417. * hash_index[4] = da[4] ^ da[10] ^ da[16] ^ da[22] ^ da[28] ^ da[34] ^ da[40] ^ da[46]
  418. * hash_index[3] = da[3] ^ da[09] ^ da[15] ^ da[21] ^ da[27] ^ da[33] ^ da[39] ^ da[45]
  419. * hash_index[2] = da[2] ^ da[08] ^ da[14] ^ da[20] ^ da[26] ^ da[32] ^ da[38] ^ da[44]
  420. * hash_index[1] = da[1] ^ da[07] ^ da[13] ^ da[19] ^ da[25] ^ da[31] ^ da[37] ^ da[43]
  421. * hash_index[0] = da[0] ^ da[06] ^ da[12] ^ da[18] ^ da[24] ^ da[30] ^ da[36] ^ da[42]
  422. * da[0] represents the least significant bit of the first byte received, that is, the multicast/
  423. * unicast indicator, and da[47] represents the most significant bit of the last byte
  424. * received.
  425. * If the hash index points to a bit that is set in the hash register then the frame will be
  426. * matched according to whether the frame is multicast or unicast.
  427. * A multicast match will be signalled if the multicast hash enable bit is set, da[0] is 1 and
  428. * the hash index points to a bit set in the hash register.
  429. * A unicast match will be signalled if the unicast hash enable bit is set, da[0] is 0 and the
  430. * hash index points to a bit set in the hash register.
  431. * To receive all multicast frames, the hash register should be set with all ones and the
  432. * multicast hash enable bit should be set in the network configuration register.
  433. */
  434. /*
  435. * Return the hash index value for the specified address.
  436. */
  437. static int hash_get_index(__u8 *addr)
  438. {
  439. int i, j, bitval;
  440. int hash_index = 0;
  441. for (j = 0; j < 6; j++) {
  442. for (i = 0, bitval = 0; i < 8; i++)
  443. bitval ^= hash_bit_value(i*6 + j, addr);
  444. hash_index |= (bitval << j);
  445. }
  446. return hash_index;
  447. }
  448. /*
  449. * Add multicast addresses to the internal multicast-hash table.
  450. */
  451. static void at91ether_sethashtable(struct net_device *dev)
  452. {
  453. struct dev_mc_list *curr;
  454. unsigned long mc_filter[2];
  455. unsigned int i, bitnr;
  456. mc_filter[0] = mc_filter[1] = 0;
  457. curr = dev->mc_list;
  458. for (i = 0; i < dev->mc_count; i++, curr = curr->next) {
  459. if (!curr) break; /* unexpected end of list */
  460. bitnr = hash_get_index(curr->dmi_addr);
  461. mc_filter[bitnr >> 5] |= 1 << (bitnr & 31);
  462. }
  463. at91_emac_write(AT91_EMAC_HSH, mc_filter[0]);
  464. at91_emac_write(AT91_EMAC_HSL, mc_filter[1]);
  465. }
  466. /*
  467. * Enable/Disable promiscuous and multicast modes.
  468. */
  469. static void at91ether_set_rx_mode(struct net_device *dev)
  470. {
  471. unsigned long cfg;
  472. cfg = at91_emac_read(AT91_EMAC_CFG);
  473. if (dev->flags & IFF_PROMISC) /* Enable promiscuous mode */
  474. cfg |= AT91_EMAC_CAF;
  475. else if (dev->flags & (~IFF_PROMISC)) /* Disable promiscuous mode */
  476. cfg &= ~AT91_EMAC_CAF;
  477. if (dev->flags & IFF_ALLMULTI) { /* Enable all multicast mode */
  478. at91_emac_write(AT91_EMAC_HSH, -1);
  479. at91_emac_write(AT91_EMAC_HSL, -1);
  480. cfg |= AT91_EMAC_MTI;
  481. } else if (dev->mc_count > 0) { /* Enable specific multicasts */
  482. at91ether_sethashtable(dev);
  483. cfg |= AT91_EMAC_MTI;
  484. } else if (dev->flags & (~IFF_ALLMULTI)) { /* Disable all multicast mode */
  485. at91_emac_write(AT91_EMAC_HSH, 0);
  486. at91_emac_write(AT91_EMAC_HSL, 0);
  487. cfg &= ~AT91_EMAC_MTI;
  488. }
  489. at91_emac_write(AT91_EMAC_CFG, cfg);
  490. }
  491. /* ......................... ETHTOOL SUPPORT ........................... */
  492. static int mdio_read(struct net_device *dev, int phy_id, int location)
  493. {
  494. unsigned int value;
  495. read_phy(phy_id, location, &value);
  496. return value;
  497. }
  498. static void mdio_write(struct net_device *dev, int phy_id, int location, int value)
  499. {
  500. write_phy(phy_id, location, value);
  501. }
  502. static int at91ether_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  503. {
  504. struct at91_private *lp = (struct at91_private *) dev->priv;
  505. int ret;
  506. spin_lock_irq(&lp->lock);
  507. enable_mdi();
  508. ret = mii_ethtool_gset(&lp->mii, cmd);
  509. disable_mdi();
  510. spin_unlock_irq(&lp->lock);
  511. if (lp->phy_media == PORT_FIBRE) { /* override media type since mii.c doesn't know */
  512. cmd->supported = SUPPORTED_FIBRE;
  513. cmd->port = PORT_FIBRE;
  514. }
  515. return ret;
  516. }
  517. static int at91ether_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  518. {
  519. struct at91_private *lp = (struct at91_private *) dev->priv;
  520. int ret;
  521. spin_lock_irq(&lp->lock);
  522. enable_mdi();
  523. ret = mii_ethtool_sset(&lp->mii, cmd);
  524. disable_mdi();
  525. spin_unlock_irq(&lp->lock);
  526. return ret;
  527. }
  528. static int at91ether_nwayreset(struct net_device *dev)
  529. {
  530. struct at91_private *lp = (struct at91_private *) dev->priv;
  531. int ret;
  532. spin_lock_irq(&lp->lock);
  533. enable_mdi();
  534. ret = mii_nway_restart(&lp->mii);
  535. disable_mdi();
  536. spin_unlock_irq(&lp->lock);
  537. return ret;
  538. }
  539. static void at91ether_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
  540. {
  541. strlcpy(info->driver, DRV_NAME, sizeof(info->driver));
  542. strlcpy(info->version, DRV_VERSION, sizeof(info->version));
  543. strlcpy(info->bus_info, dev->class_dev.dev->bus_id, sizeof(info->bus_info));
  544. }
  545. static struct ethtool_ops at91ether_ethtool_ops = {
  546. .get_settings = at91ether_get_settings,
  547. .set_settings = at91ether_set_settings,
  548. .get_drvinfo = at91ether_get_drvinfo,
  549. .nway_reset = at91ether_nwayreset,
  550. .get_link = ethtool_op_get_link,
  551. };
  552. /* ................................ MAC ................................ */
  553. /*
  554. * Initialize and start the Receiver and Transmit subsystems
  555. */
  556. static void at91ether_start(struct net_device *dev)
  557. {
  558. struct at91_private *lp = (struct at91_private *) dev->priv;
  559. struct recv_desc_bufs *dlist, *dlist_phys;
  560. int i;
  561. unsigned long ctl;
  562. dlist = lp->dlist;
  563. dlist_phys = lp->dlist_phys;
  564. for (i = 0; i < MAX_RX_DESCR; i++) {
  565. dlist->descriptors[i].addr = (unsigned int) &dlist_phys->recv_buf[i][0];
  566. dlist->descriptors[i].size = 0;
  567. }
  568. /* Set the Wrap bit on the last descriptor */
  569. dlist->descriptors[i-1].addr |= EMAC_DESC_WRAP;
  570. /* Reset buffer index */
  571. lp->rxBuffIndex = 0;
  572. /* Program address of descriptor list in Rx Buffer Queue register */
  573. at91_emac_write(AT91_EMAC_RBQP, (unsigned long) dlist_phys);
  574. /* Enable Receive and Transmit */
  575. ctl = at91_emac_read(AT91_EMAC_CTL);
  576. at91_emac_write(AT91_EMAC_CTL, ctl | AT91_EMAC_RE | AT91_EMAC_TE);
  577. }
  578. /*
  579. * Open the ethernet interface
  580. */
  581. static int at91ether_open(struct net_device *dev)
  582. {
  583. struct at91_private *lp = (struct at91_private *) dev->priv;
  584. unsigned long ctl;
  585. if (!is_valid_ether_addr(dev->dev_addr))
  586. return -EADDRNOTAVAIL;
  587. clk_enable(ether_clk); /* Re-enable Peripheral clock */
  588. /* Clear internal statistics */
  589. ctl = at91_emac_read(AT91_EMAC_CTL);
  590. at91_emac_write(AT91_EMAC_CTL, ctl | AT91_EMAC_CSR);
  591. /* Update the MAC address (incase user has changed it) */
  592. update_mac_address(dev);
  593. /* Enable PHY interrupt */
  594. enable_phyirq(dev);
  595. /* Enable MAC interrupts */
  596. at91_emac_write(AT91_EMAC_IER, AT91_EMAC_RCOM | AT91_EMAC_RBNA
  597. | AT91_EMAC_TUND | AT91_EMAC_RTRY | AT91_EMAC_TCOM
  598. | AT91_EMAC_ROVR | AT91_EMAC_ABT);
  599. /* Determine current link speed */
  600. spin_lock_irq(&lp->lock);
  601. enable_mdi();
  602. update_linkspeed(dev, 0);
  603. disable_mdi();
  604. spin_unlock_irq(&lp->lock);
  605. at91ether_start(dev);
  606. netif_start_queue(dev);
  607. return 0;
  608. }
  609. /*
  610. * Close the interface
  611. */
  612. static int at91ether_close(struct net_device *dev)
  613. {
  614. unsigned long ctl;
  615. /* Disable Receiver and Transmitter */
  616. ctl = at91_emac_read(AT91_EMAC_CTL);
  617. at91_emac_write(AT91_EMAC_CTL, ctl & ~(AT91_EMAC_TE | AT91_EMAC_RE));
  618. /* Disable PHY interrupt */
  619. disable_phyirq(dev);
  620. /* Disable MAC interrupts */
  621. at91_emac_write(AT91_EMAC_IDR, AT91_EMAC_RCOM | AT91_EMAC_RBNA
  622. | AT91_EMAC_TUND | AT91_EMAC_RTRY | AT91_EMAC_TCOM
  623. | AT91_EMAC_ROVR | AT91_EMAC_ABT);
  624. netif_stop_queue(dev);
  625. clk_disable(ether_clk); /* Disable Peripheral clock */
  626. return 0;
  627. }
  628. /*
  629. * Transmit packet.
  630. */
  631. static int at91ether_tx(struct sk_buff *skb, struct net_device *dev)
  632. {
  633. struct at91_private *lp = (struct at91_private *) dev->priv;
  634. if (at91_emac_read(AT91_EMAC_TSR) & AT91_EMAC_TSR_BNQ) {
  635. netif_stop_queue(dev);
  636. /* Store packet information (to free when Tx completed) */
  637. lp->skb = skb;
  638. lp->skb_length = skb->len;
  639. lp->skb_physaddr = dma_map_single(NULL, skb->data, skb->len, DMA_TO_DEVICE);
  640. lp->stats.tx_bytes += skb->len;
  641. /* Set address of the data in the Transmit Address register */
  642. at91_emac_write(AT91_EMAC_TAR, lp->skb_physaddr);
  643. /* Set length of the packet in the Transmit Control register */
  644. at91_emac_write(AT91_EMAC_TCR, skb->len);
  645. dev->trans_start = jiffies;
  646. } else {
  647. printk(KERN_ERR "at91_ether.c: at91ether_tx() called, but device is busy!\n");
  648. return 1; /* if we return anything but zero, dev.c:1055 calls kfree_skb(skb)
  649. on this skb, he also reports -ENETDOWN and printk's, so either
  650. we free and return(0) or don't free and return 1 */
  651. }
  652. return 0;
  653. }
  654. /*
  655. * Update the current statistics from the internal statistics registers.
  656. */
  657. static struct net_device_stats *at91ether_stats(struct net_device *dev)
  658. {
  659. struct at91_private *lp = (struct at91_private *) dev->priv;
  660. int ale, lenerr, seqe, lcol, ecol;
  661. if (netif_running(dev)) {
  662. lp->stats.rx_packets += at91_emac_read(AT91_EMAC_OK); /* Good frames received */
  663. ale = at91_emac_read(AT91_EMAC_ALE);
  664. lp->stats.rx_frame_errors += ale; /* Alignment errors */
  665. lenerr = at91_emac_read(AT91_EMAC_ELR) + at91_emac_read(AT91_EMAC_USF);
  666. lp->stats.rx_length_errors += lenerr; /* Excessive Length or Undersize Frame error */
  667. seqe = at91_emac_read(AT91_EMAC_SEQE);
  668. lp->stats.rx_crc_errors += seqe; /* CRC error */
  669. lp->stats.rx_fifo_errors += at91_emac_read(AT91_EMAC_DRFC); /* Receive buffer not available */
  670. lp->stats.rx_errors += (ale + lenerr + seqe
  671. + at91_emac_read(AT91_EMAC_CDE) + at91_emac_read(AT91_EMAC_RJB));
  672. lp->stats.tx_packets += at91_emac_read(AT91_EMAC_FRA); /* Frames successfully transmitted */
  673. lp->stats.tx_fifo_errors += at91_emac_read(AT91_EMAC_TUE); /* Transmit FIFO underruns */
  674. lp->stats.tx_carrier_errors += at91_emac_read(AT91_EMAC_CSE); /* Carrier Sense errors */
  675. lp->stats.tx_heartbeat_errors += at91_emac_read(AT91_EMAC_SQEE);/* Heartbeat error */
  676. lcol = at91_emac_read(AT91_EMAC_LCOL);
  677. ecol = at91_emac_read(AT91_EMAC_ECOL);
  678. lp->stats.tx_window_errors += lcol; /* Late collisions */
  679. lp->stats.tx_aborted_errors += ecol; /* 16 collisions */
  680. lp->stats.collisions += (at91_emac_read(AT91_EMAC_SCOL) + at91_emac_read(AT91_EMAC_MCOL) + lcol + ecol);
  681. }
  682. return &lp->stats;
  683. }
  684. /*
  685. * Extract received frame from buffer descriptors and sent to upper layers.
  686. * (Called from interrupt context)
  687. */
  688. static void at91ether_rx(struct net_device *dev)
  689. {
  690. struct at91_private *lp = (struct at91_private *) dev->priv;
  691. struct recv_desc_bufs *dlist;
  692. unsigned char *p_recv;
  693. struct sk_buff *skb;
  694. unsigned int pktlen;
  695. dlist = lp->dlist;
  696. while (dlist->descriptors[lp->rxBuffIndex].addr & EMAC_DESC_DONE) {
  697. p_recv = dlist->recv_buf[lp->rxBuffIndex];
  698. pktlen = dlist->descriptors[lp->rxBuffIndex].size & 0x7ff; /* Length of frame including FCS */
  699. skb = alloc_skb(pktlen + 2, GFP_ATOMIC);
  700. if (skb != NULL) {
  701. skb_reserve(skb, 2);
  702. memcpy(skb_put(skb, pktlen), p_recv, pktlen);
  703. skb->dev = dev;
  704. skb->protocol = eth_type_trans(skb, dev);
  705. skb->len = pktlen;
  706. dev->last_rx = jiffies;
  707. lp->stats.rx_bytes += pktlen;
  708. netif_rx(skb);
  709. }
  710. else {
  711. lp->stats.rx_dropped += 1;
  712. printk(KERN_NOTICE "%s: Memory squeeze, dropping packet.\n", dev->name);
  713. }
  714. if (dlist->descriptors[lp->rxBuffIndex].size & EMAC_MULTICAST)
  715. lp->stats.multicast++;
  716. dlist->descriptors[lp->rxBuffIndex].addr &= ~EMAC_DESC_DONE; /* reset ownership bit */
  717. if (lp->rxBuffIndex == MAX_RX_DESCR-1) /* wrap after last buffer */
  718. lp->rxBuffIndex = 0;
  719. else
  720. lp->rxBuffIndex++;
  721. }
  722. }
  723. /*
  724. * MAC interrupt handler
  725. */
  726. static irqreturn_t at91ether_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  727. {
  728. struct net_device *dev = (struct net_device *) dev_id;
  729. struct at91_private *lp = (struct at91_private *) dev->priv;
  730. unsigned long intstatus, ctl;
  731. /* MAC Interrupt Status register indicates what interrupts are pending.
  732. It is automatically cleared once read. */
  733. intstatus = at91_emac_read(AT91_EMAC_ISR);
  734. if (intstatus & AT91_EMAC_RCOM) /* Receive complete */
  735. at91ether_rx(dev);
  736. if (intstatus & AT91_EMAC_TCOM) { /* Transmit complete */
  737. /* The TCOM bit is set even if the transmission failed. */
  738. if (intstatus & (AT91_EMAC_TUND | AT91_EMAC_RTRY))
  739. lp->stats.tx_errors += 1;
  740. if (lp->skb) {
  741. dev_kfree_skb_irq(lp->skb);
  742. lp->skb = NULL;
  743. dma_unmap_single(NULL, lp->skb_physaddr, lp->skb_length, DMA_TO_DEVICE);
  744. }
  745. netif_wake_queue(dev);
  746. }
  747. /* Work-around for Errata #11 */
  748. if (intstatus & AT91_EMAC_RBNA) {
  749. ctl = at91_emac_read(AT91_EMAC_CTL);
  750. at91_emac_write(AT91_EMAC_CTL, ctl & ~AT91_EMAC_RE);
  751. at91_emac_write(AT91_EMAC_CTL, ctl | AT91_EMAC_RE);
  752. }
  753. if (intstatus & AT91_EMAC_ROVR)
  754. printk("%s: ROVR error\n", dev->name);
  755. return IRQ_HANDLED;
  756. }
  757. /*
  758. * Initialize the ethernet interface
  759. */
  760. static int __init at91ether_setup(unsigned long phy_type, unsigned short phy_address, struct platform_device *pdev)
  761. {
  762. struct at91_eth_data *board_data = pdev->dev.platform_data;
  763. struct net_device *dev;
  764. struct at91_private *lp;
  765. unsigned int val;
  766. int res;
  767. if (at91_dev) /* already initialized */
  768. return 0;
  769. dev = alloc_etherdev(sizeof(struct at91_private));
  770. if (!dev)
  771. return -ENOMEM;
  772. dev->base_addr = AT91_VA_BASE_EMAC;
  773. dev->irq = AT91_ID_EMAC;
  774. SET_MODULE_OWNER(dev);
  775. /* Install the interrupt handler */
  776. if (request_irq(dev->irq, at91ether_interrupt, 0, dev->name, dev)) {
  777. free_netdev(dev);
  778. return -EBUSY;
  779. }
  780. /* Allocate memory for DMA Receive descriptors */
  781. lp = (struct at91_private *)dev->priv;
  782. lp->dlist = (struct recv_desc_bufs *) dma_alloc_coherent(NULL, sizeof(struct recv_desc_bufs), (dma_addr_t *) &lp->dlist_phys, GFP_KERNEL);
  783. if (lp->dlist == NULL) {
  784. free_irq(dev->irq, dev);
  785. free_netdev(dev);
  786. return -ENOMEM;
  787. }
  788. lp->board_data = *board_data;
  789. platform_set_drvdata(pdev, dev);
  790. spin_lock_init(&lp->lock);
  791. ether_setup(dev);
  792. dev->open = at91ether_open;
  793. dev->stop = at91ether_close;
  794. dev->hard_start_xmit = at91ether_tx;
  795. dev->get_stats = at91ether_stats;
  796. dev->set_multicast_list = at91ether_set_rx_mode;
  797. dev->set_mac_address = set_mac_address;
  798. dev->ethtool_ops = &at91ether_ethtool_ops;
  799. SET_NETDEV_DEV(dev, &pdev->dev);
  800. get_mac_address(dev); /* Get ethernet address and store it in dev->dev_addr */
  801. update_mac_address(dev); /* Program ethernet address into MAC */
  802. at91_emac_write(AT91_EMAC_CTL, 0);
  803. if (lp->board_data.is_rmii)
  804. at91_emac_write(AT91_EMAC_CFG, AT91_EMAC_CLK_DIV32 | AT91_EMAC_BIG | AT91_EMAC_RMII);
  805. else
  806. at91_emac_write(AT91_EMAC_CFG, AT91_EMAC_CLK_DIV32 | AT91_EMAC_BIG);
  807. /* Perform PHY-specific initialization */
  808. spin_lock_irq(&lp->lock);
  809. enable_mdi();
  810. if ((phy_type == MII_DM9161_ID) || (lp->phy_type == MII_DM9161A_ID)) {
  811. read_phy(phy_address, MII_DSCR_REG, &val);
  812. if ((val & (1 << 10)) == 0) /* DSCR bit 10 is 0 -- fiber mode */
  813. lp->phy_media = PORT_FIBRE;
  814. } else if (machine_is_csb337()) {
  815. /* mix link activity status into LED2 link state */
  816. write_phy(phy_address, MII_LEDCTRL_REG, 0x0d22);
  817. }
  818. disable_mdi();
  819. spin_unlock_irq(&lp->lock);
  820. lp->mii.dev = dev; /* Support for ethtool */
  821. lp->mii.mdio_read = mdio_read;
  822. lp->mii.mdio_write = mdio_write;
  823. lp->phy_type = phy_type; /* Type of PHY connected */
  824. lp->phy_address = phy_address; /* MDI address of PHY */
  825. /* Register the network interface */
  826. res = register_netdev(dev);
  827. if (res) {
  828. free_irq(dev->irq, dev);
  829. free_netdev(dev);
  830. dma_free_coherent(NULL, sizeof(struct recv_desc_bufs), lp->dlist, (dma_addr_t)lp->dlist_phys);
  831. return res;
  832. }
  833. at91_dev = dev;
  834. /* Determine current link speed */
  835. spin_lock_irq(&lp->lock);
  836. enable_mdi();
  837. update_linkspeed(dev, 0);
  838. disable_mdi();
  839. spin_unlock_irq(&lp->lock);
  840. netif_carrier_off(dev); /* will be enabled in open() */
  841. /* If board has no PHY IRQ, use a timer to poll the PHY */
  842. if (!lp->board_data.phy_irq_pin) {
  843. init_timer(&check_timer);
  844. check_timer.data = (unsigned long)dev;
  845. check_timer.function = at91ether_check_link;
  846. }
  847. /* Display ethernet banner */
  848. printk(KERN_INFO "%s: AT91 ethernet at 0x%08x int=%d %s%s (%02x:%02x:%02x:%02x:%02x:%02x)\n",
  849. dev->name, (uint) dev->base_addr, dev->irq,
  850. at91_emac_read(AT91_EMAC_CFG) & AT91_EMAC_SPD ? "100-" : "10-",
  851. at91_emac_read(AT91_EMAC_CFG) & AT91_EMAC_FD ? "FullDuplex" : "HalfDuplex",
  852. dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
  853. dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
  854. if ((phy_type == MII_DM9161_ID) || (lp->phy_type == MII_DM9161A_ID))
  855. printk(KERN_INFO "%s: Davicom 9196 PHY %s\n", dev->name, (lp->phy_media == PORT_FIBRE) ? "(Fiber)" : "(Copper)");
  856. else if (phy_type == MII_LXT971A_ID)
  857. printk(KERN_INFO "%s: Intel LXT971A PHY\n", dev->name);
  858. else if (phy_type == MII_RTL8201_ID)
  859. printk(KERN_INFO "%s: Realtek RTL8201(B)L PHY\n", dev->name);
  860. else if (phy_type == MII_BCM5221_ID)
  861. printk(KERN_INFO "%s: Broadcom BCM5221 PHY\n", dev->name);
  862. else if (phy_type == MII_DP83847_ID)
  863. printk(KERN_INFO "%s: National Semiconductor DP83847 PHY\n", dev->name);
  864. else if (phy_type == MII_AC101L_ID)
  865. printk(KERN_INFO "%s: Altima AC101L PHY\n", dev->name);
  866. else if (phy_type == MII_KS8721_ID)
  867. printk(KERN_INFO "%s: Micrel KS8721 PHY\n", dev->name);
  868. return 0;
  869. }
  870. /*
  871. * Detect MAC and PHY and perform initialization
  872. */
  873. static int __init at91ether_probe(struct platform_device *pdev)
  874. {
  875. unsigned int phyid1, phyid2;
  876. int detected = -1;
  877. unsigned long phy_id;
  878. unsigned short phy_address = 0;
  879. ether_clk = clk_get(&pdev->dev, "ether_clk");
  880. if (!ether_clk) {
  881. printk(KERN_ERR "at91_ether: no clock defined\n");
  882. return -ENODEV;
  883. }
  884. clk_enable(ether_clk); /* Enable Peripheral clock */
  885. while ((detected != 0) && (phy_address < 32)) {
  886. /* Read the PHY ID registers */
  887. enable_mdi();
  888. read_phy(phy_address, MII_PHYSID1, &phyid1);
  889. read_phy(phy_address, MII_PHYSID2, &phyid2);
  890. disable_mdi();
  891. phy_id = (phyid1 << 16) | (phyid2 & 0xfff0);
  892. switch (phy_id) {
  893. case MII_DM9161_ID: /* Davicom 9161: PHY_ID1 = 0x181, PHY_ID2 = B881 */
  894. case MII_DM9161A_ID: /* Davicom 9161A: PHY_ID1 = 0x181, PHY_ID2 = B8A0 */
  895. case MII_LXT971A_ID: /* Intel LXT971A: PHY_ID1 = 0x13, PHY_ID2 = 78E0 */
  896. case MII_RTL8201_ID: /* Realtek RTL8201: PHY_ID1 = 0, PHY_ID2 = 0x8201 */
  897. case MII_BCM5221_ID: /* Broadcom BCM5221: PHY_ID1 = 0x40, PHY_ID2 = 0x61e0 */
  898. case MII_DP83847_ID: /* National Semiconductor DP83847: */
  899. case MII_AC101L_ID: /* Altima AC101L: PHY_ID1 = 0x22, PHY_ID2 = 0x5520 */
  900. case MII_KS8721_ID: /* Micrel KS8721: PHY_ID1 = 0x22, PHY_ID2 = 0x1610 */
  901. detected = at91ether_setup(phy_id, phy_address, pdev);
  902. break;
  903. }
  904. phy_address++;
  905. }
  906. clk_disable(ether_clk); /* Disable Peripheral clock */
  907. return detected;
  908. }
  909. static int __devexit at91ether_remove(struct platform_device *pdev)
  910. {
  911. struct at91_private *lp = (struct at91_private *) at91_dev->priv;
  912. unregister_netdev(at91_dev);
  913. free_irq(at91_dev->irq, at91_dev);
  914. dma_free_coherent(NULL, sizeof(struct recv_desc_bufs), lp->dlist, (dma_addr_t)lp->dlist_phys);
  915. clk_put(ether_clk);
  916. free_netdev(at91_dev);
  917. at91_dev = NULL;
  918. return 0;
  919. }
  920. static struct platform_driver at91ether_driver = {
  921. .probe = at91ether_probe,
  922. .remove = __devexit_p(at91ether_remove),
  923. /* FIXME: support suspend and resume */
  924. .driver = {
  925. .name = DRV_NAME,
  926. .owner = THIS_MODULE,
  927. },
  928. };
  929. static int __init at91ether_init(void)
  930. {
  931. return platform_driver_register(&at91ether_driver);
  932. }
  933. static void __exit at91ether_exit(void)
  934. {
  935. platform_driver_unregister(&at91ether_driver);
  936. }
  937. module_init(at91ether_init)
  938. module_exit(at91ether_exit)
  939. MODULE_LICENSE("GPL");
  940. MODULE_DESCRIPTION("AT91RM9200 EMAC Ethernet driver");
  941. MODULE_AUTHOR("Andrew Victor");