fec.c 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785
  1. /*
  2. * Fast Ethernet Controller (FEC) driver for Motorola MPC8xx.
  3. * Copyright (c) 1997 Dan Malek (dmalek@jlc.net)
  4. *
  5. * Right now, I am very wasteful with the buffers. I allocate memory
  6. * pages and then divide them into 2K frame buffers. This way I know I
  7. * have buffers large enough to hold one frame within one buffer descriptor.
  8. * Once I get this working, I will use 64 or 128 byte CPM buffers, which
  9. * will be much more memory efficient and will easily handle lots of
  10. * small packets.
  11. *
  12. * Much better multiple PHY support by Magnus Damm.
  13. * Copyright (c) 2000 Ericsson Radio Systems AB.
  14. *
  15. * Support for FEC controller of ColdFire processors.
  16. * Copyright (c) 2001-2005 Greg Ungerer (gerg@snapgear.com)
  17. *
  18. * Bug fixes and cleanup by Philippe De Muyter (phdm@macqel.be)
  19. * Copyright (c) 2004-2006 Macq Electronique SA.
  20. *
  21. * Copyright (C) 2010-2011 Freescale Semiconductor, Inc.
  22. */
  23. #include <linux/module.h>
  24. #include <linux/kernel.h>
  25. #include <linux/string.h>
  26. #include <linux/ptrace.h>
  27. #include <linux/errno.h>
  28. #include <linux/ioport.h>
  29. #include <linux/slab.h>
  30. #include <linux/interrupt.h>
  31. #include <linux/pci.h>
  32. #include <linux/init.h>
  33. #include <linux/delay.h>
  34. #include <linux/netdevice.h>
  35. #include <linux/etherdevice.h>
  36. #include <linux/skbuff.h>
  37. #include <linux/spinlock.h>
  38. #include <linux/workqueue.h>
  39. #include <linux/bitops.h>
  40. #include <linux/io.h>
  41. #include <linux/irq.h>
  42. #include <linux/clk.h>
  43. #include <linux/platform_device.h>
  44. #include <linux/phy.h>
  45. #include <linux/fec.h>
  46. #include <linux/of.h>
  47. #include <linux/of_device.h>
  48. #include <linux/of_gpio.h>
  49. #include <linux/of_net.h>
  50. #include <linux/pinctrl/consumer.h>
  51. #include <linux/regulator/consumer.h>
  52. #include <asm/cacheflush.h>
  53. #ifndef CONFIG_ARM
  54. #include <asm/coldfire.h>
  55. #include <asm/mcfsim.h>
  56. #endif
  57. #include "fec.h"
  58. #if defined(CONFIG_ARM)
  59. #define FEC_ALIGNMENT 0xf
  60. #else
  61. #define FEC_ALIGNMENT 0x3
  62. #endif
  63. #define DRIVER_NAME "fec"
  64. /* Controller is ENET-MAC */
  65. #define FEC_QUIRK_ENET_MAC (1 << 0)
  66. /* Controller needs driver to swap frame */
  67. #define FEC_QUIRK_SWAP_FRAME (1 << 1)
  68. /* Controller uses gasket */
  69. #define FEC_QUIRK_USE_GASKET (1 << 2)
  70. /* Controller has GBIT support */
  71. #define FEC_QUIRK_HAS_GBIT (1 << 3)
  72. static struct platform_device_id fec_devtype[] = {
  73. {
  74. /* keep it for coldfire */
  75. .name = DRIVER_NAME,
  76. .driver_data = 0,
  77. }, {
  78. .name = "imx25-fec",
  79. .driver_data = FEC_QUIRK_USE_GASKET,
  80. }, {
  81. .name = "imx27-fec",
  82. .driver_data = 0,
  83. }, {
  84. .name = "imx28-fec",
  85. .driver_data = FEC_QUIRK_ENET_MAC | FEC_QUIRK_SWAP_FRAME,
  86. }, {
  87. .name = "imx6q-fec",
  88. .driver_data = FEC_QUIRK_ENET_MAC | FEC_QUIRK_HAS_GBIT,
  89. }, {
  90. /* sentinel */
  91. }
  92. };
  93. MODULE_DEVICE_TABLE(platform, fec_devtype);
  94. enum imx_fec_type {
  95. IMX25_FEC = 1, /* runs on i.mx25/50/53 */
  96. IMX27_FEC, /* runs on i.mx27/35/51 */
  97. IMX28_FEC,
  98. IMX6Q_FEC,
  99. };
  100. static const struct of_device_id fec_dt_ids[] = {
  101. { .compatible = "fsl,imx25-fec", .data = &fec_devtype[IMX25_FEC], },
  102. { .compatible = "fsl,imx27-fec", .data = &fec_devtype[IMX27_FEC], },
  103. { .compatible = "fsl,imx28-fec", .data = &fec_devtype[IMX28_FEC], },
  104. { .compatible = "fsl,imx6q-fec", .data = &fec_devtype[IMX6Q_FEC], },
  105. { /* sentinel */ }
  106. };
  107. MODULE_DEVICE_TABLE(of, fec_dt_ids);
  108. static unsigned char macaddr[ETH_ALEN];
  109. module_param_array(macaddr, byte, NULL, 0);
  110. MODULE_PARM_DESC(macaddr, "FEC Ethernet MAC address");
  111. #if defined(CONFIG_M5272)
  112. /*
  113. * Some hardware gets it MAC address out of local flash memory.
  114. * if this is non-zero then assume it is the address to get MAC from.
  115. */
  116. #if defined(CONFIG_NETtel)
  117. #define FEC_FLASHMAC 0xf0006006
  118. #elif defined(CONFIG_GILBARCONAP) || defined(CONFIG_SCALES)
  119. #define FEC_FLASHMAC 0xf0006000
  120. #elif defined(CONFIG_CANCam)
  121. #define FEC_FLASHMAC 0xf0020000
  122. #elif defined (CONFIG_M5272C3)
  123. #define FEC_FLASHMAC (0xffe04000 + 4)
  124. #elif defined(CONFIG_MOD5272)
  125. #define FEC_FLASHMAC 0xffc0406b
  126. #else
  127. #define FEC_FLASHMAC 0
  128. #endif
  129. #endif /* CONFIG_M5272 */
  130. /* The number of Tx and Rx buffers. These are allocated from the page
  131. * pool. The code may assume these are power of two, so it it best
  132. * to keep them that size.
  133. * We don't need to allocate pages for the transmitter. We just use
  134. * the skbuffer directly.
  135. */
  136. #define FEC_ENET_RX_PAGES 8
  137. #define FEC_ENET_RX_FRSIZE 2048
  138. #define FEC_ENET_RX_FRPPG (PAGE_SIZE / FEC_ENET_RX_FRSIZE)
  139. #define RX_RING_SIZE (FEC_ENET_RX_FRPPG * FEC_ENET_RX_PAGES)
  140. #define FEC_ENET_TX_FRSIZE 2048
  141. #define FEC_ENET_TX_FRPPG (PAGE_SIZE / FEC_ENET_TX_FRSIZE)
  142. #define TX_RING_SIZE 16 /* Must be power of two */
  143. #define TX_RING_MOD_MASK 15 /* for this to work */
  144. #if (((RX_RING_SIZE + TX_RING_SIZE) * 8) > PAGE_SIZE)
  145. #error "FEC: descriptor ring size constants too large"
  146. #endif
  147. /* Interrupt events/masks. */
  148. #define FEC_ENET_HBERR ((uint)0x80000000) /* Heartbeat error */
  149. #define FEC_ENET_BABR ((uint)0x40000000) /* Babbling receiver */
  150. #define FEC_ENET_BABT ((uint)0x20000000) /* Babbling transmitter */
  151. #define FEC_ENET_GRA ((uint)0x10000000) /* Graceful stop complete */
  152. #define FEC_ENET_TXF ((uint)0x08000000) /* Full frame transmitted */
  153. #define FEC_ENET_TXB ((uint)0x04000000) /* A buffer was transmitted */
  154. #define FEC_ENET_RXF ((uint)0x02000000) /* Full frame received */
  155. #define FEC_ENET_RXB ((uint)0x01000000) /* A buffer was received */
  156. #define FEC_ENET_MII ((uint)0x00800000) /* MII interrupt */
  157. #define FEC_ENET_EBERR ((uint)0x00400000) /* SDMA bus error */
  158. #define FEC_DEFAULT_IMASK (FEC_ENET_TXF | FEC_ENET_RXF | FEC_ENET_MII)
  159. /* The FEC stores dest/src/type, data, and checksum for receive packets.
  160. */
  161. #define PKT_MAXBUF_SIZE 1518
  162. #define PKT_MINBUF_SIZE 64
  163. #define PKT_MAXBLR_SIZE 1520
  164. /* This device has up to three irqs on some platforms */
  165. #define FEC_IRQ_NUM 3
  166. /*
  167. * The 5270/5271/5280/5282/532x RX control register also contains maximum frame
  168. * size bits. Other FEC hardware does not, so we need to take that into
  169. * account when setting it.
  170. */
  171. #if defined(CONFIG_M523x) || defined(CONFIG_M527x) || defined(CONFIG_M528x) || \
  172. defined(CONFIG_M520x) || defined(CONFIG_M532x) || defined(CONFIG_ARM)
  173. #define OPT_FRAME_SIZE (PKT_MAXBUF_SIZE << 16)
  174. #else
  175. #define OPT_FRAME_SIZE 0
  176. #endif
  177. /* The FEC buffer descriptors track the ring buffers. The rx_bd_base and
  178. * tx_bd_base always point to the base of the buffer descriptors. The
  179. * cur_rx and cur_tx point to the currently available buffer.
  180. * The dirty_tx tracks the current buffer that is being sent by the
  181. * controller. The cur_tx and dirty_tx are equal under both completely
  182. * empty and completely full conditions. The empty/ready indicator in
  183. * the buffer descriptor determines the actual condition.
  184. */
  185. struct fec_enet_private {
  186. /* Hardware registers of the FEC device */
  187. void __iomem *hwp;
  188. struct net_device *netdev;
  189. struct clk *clk_ipg;
  190. struct clk *clk_ahb;
  191. /* The saved address of a sent-in-place packet/buffer, for skfree(). */
  192. unsigned char *tx_bounce[TX_RING_SIZE];
  193. struct sk_buff* tx_skbuff[TX_RING_SIZE];
  194. struct sk_buff* rx_skbuff[RX_RING_SIZE];
  195. ushort skb_cur;
  196. ushort skb_dirty;
  197. /* CPM dual port RAM relative addresses */
  198. dma_addr_t bd_dma;
  199. /* Address of Rx and Tx buffers */
  200. struct bufdesc *rx_bd_base;
  201. struct bufdesc *tx_bd_base;
  202. /* The next free ring entry */
  203. struct bufdesc *cur_rx, *cur_tx;
  204. /* The ring entries to be free()ed */
  205. struct bufdesc *dirty_tx;
  206. uint tx_full;
  207. /* hold while accessing the HW like ringbuffer for tx/rx but not MAC */
  208. spinlock_t hw_lock;
  209. struct platform_device *pdev;
  210. int opened;
  211. int dev_id;
  212. /* Phylib and MDIO interface */
  213. struct mii_bus *mii_bus;
  214. struct phy_device *phy_dev;
  215. int mii_timeout;
  216. uint phy_speed;
  217. phy_interface_t phy_interface;
  218. int link;
  219. int full_duplex;
  220. struct completion mdio_done;
  221. int irq[FEC_IRQ_NUM];
  222. };
  223. /* FEC MII MMFR bits definition */
  224. #define FEC_MMFR_ST (1 << 30)
  225. #define FEC_MMFR_OP_READ (2 << 28)
  226. #define FEC_MMFR_OP_WRITE (1 << 28)
  227. #define FEC_MMFR_PA(v) ((v & 0x1f) << 23)
  228. #define FEC_MMFR_RA(v) ((v & 0x1f) << 18)
  229. #define FEC_MMFR_TA (2 << 16)
  230. #define FEC_MMFR_DATA(v) (v & 0xffff)
  231. #define FEC_MII_TIMEOUT 30000 /* us */
  232. /* Transmitter timeout */
  233. #define TX_TIMEOUT (2 * HZ)
  234. static int mii_cnt;
  235. static void *swap_buffer(void *bufaddr, int len)
  236. {
  237. int i;
  238. unsigned int *buf = bufaddr;
  239. for (i = 0; i < (len + 3) / 4; i++, buf++)
  240. *buf = cpu_to_be32(*buf);
  241. return bufaddr;
  242. }
  243. static netdev_tx_t
  244. fec_enet_start_xmit(struct sk_buff *skb, struct net_device *ndev)
  245. {
  246. struct fec_enet_private *fep = netdev_priv(ndev);
  247. const struct platform_device_id *id_entry =
  248. platform_get_device_id(fep->pdev);
  249. struct bufdesc *bdp;
  250. void *bufaddr;
  251. unsigned short status;
  252. unsigned long flags;
  253. if (!fep->link) {
  254. /* Link is down or autonegotiation is in progress. */
  255. return NETDEV_TX_BUSY;
  256. }
  257. spin_lock_irqsave(&fep->hw_lock, flags);
  258. /* Fill in a Tx ring entry */
  259. bdp = fep->cur_tx;
  260. status = bdp->cbd_sc;
  261. if (status & BD_ENET_TX_READY) {
  262. /* Ooops. All transmit buffers are full. Bail out.
  263. * This should not happen, since ndev->tbusy should be set.
  264. */
  265. printk("%s: tx queue full!.\n", ndev->name);
  266. spin_unlock_irqrestore(&fep->hw_lock, flags);
  267. return NETDEV_TX_BUSY;
  268. }
  269. /* Clear all of the status flags */
  270. status &= ~BD_ENET_TX_STATS;
  271. /* Set buffer length and buffer pointer */
  272. bufaddr = skb->data;
  273. bdp->cbd_datlen = skb->len;
  274. /*
  275. * On some FEC implementations data must be aligned on
  276. * 4-byte boundaries. Use bounce buffers to copy data
  277. * and get it aligned. Ugh.
  278. */
  279. if (((unsigned long) bufaddr) & FEC_ALIGNMENT) {
  280. unsigned int index;
  281. index = bdp - fep->tx_bd_base;
  282. memcpy(fep->tx_bounce[index], skb->data, skb->len);
  283. bufaddr = fep->tx_bounce[index];
  284. }
  285. /*
  286. * Some design made an incorrect assumption on endian mode of
  287. * the system that it's running on. As the result, driver has to
  288. * swap every frame going to and coming from the controller.
  289. */
  290. if (id_entry->driver_data & FEC_QUIRK_SWAP_FRAME)
  291. swap_buffer(bufaddr, skb->len);
  292. /* Save skb pointer */
  293. fep->tx_skbuff[fep->skb_cur] = skb;
  294. ndev->stats.tx_bytes += skb->len;
  295. fep->skb_cur = (fep->skb_cur+1) & TX_RING_MOD_MASK;
  296. /* Push the data cache so the CPM does not get stale memory
  297. * data.
  298. */
  299. bdp->cbd_bufaddr = dma_map_single(&fep->pdev->dev, bufaddr,
  300. FEC_ENET_TX_FRSIZE, DMA_TO_DEVICE);
  301. /* Send it on its way. Tell FEC it's ready, interrupt when done,
  302. * it's the last BD of the frame, and to put the CRC on the end.
  303. */
  304. status |= (BD_ENET_TX_READY | BD_ENET_TX_INTR
  305. | BD_ENET_TX_LAST | BD_ENET_TX_TC);
  306. bdp->cbd_sc = status;
  307. /* Trigger transmission start */
  308. writel(0, fep->hwp + FEC_X_DES_ACTIVE);
  309. /* If this was the last BD in the ring, start at the beginning again. */
  310. if (status & BD_ENET_TX_WRAP)
  311. bdp = fep->tx_bd_base;
  312. else
  313. bdp++;
  314. if (bdp == fep->dirty_tx) {
  315. fep->tx_full = 1;
  316. netif_stop_queue(ndev);
  317. }
  318. fep->cur_tx = bdp;
  319. skb_tx_timestamp(skb);
  320. spin_unlock_irqrestore(&fep->hw_lock, flags);
  321. return NETDEV_TX_OK;
  322. }
  323. /* This function is called to start or restart the FEC during a link
  324. * change. This only happens when switching between half and full
  325. * duplex.
  326. */
  327. static void
  328. fec_restart(struct net_device *ndev, int duplex)
  329. {
  330. struct fec_enet_private *fep = netdev_priv(ndev);
  331. const struct platform_device_id *id_entry =
  332. platform_get_device_id(fep->pdev);
  333. int i;
  334. u32 temp_mac[2];
  335. u32 rcntl = OPT_FRAME_SIZE | 0x04;
  336. u32 ecntl = 0x2; /* ETHEREN */
  337. /* Whack a reset. We should wait for this. */
  338. writel(1, fep->hwp + FEC_ECNTRL);
  339. udelay(10);
  340. /*
  341. * enet-mac reset will reset mac address registers too,
  342. * so need to reconfigure it.
  343. */
  344. if (id_entry->driver_data & FEC_QUIRK_ENET_MAC) {
  345. memcpy(&temp_mac, ndev->dev_addr, ETH_ALEN);
  346. writel(cpu_to_be32(temp_mac[0]), fep->hwp + FEC_ADDR_LOW);
  347. writel(cpu_to_be32(temp_mac[1]), fep->hwp + FEC_ADDR_HIGH);
  348. }
  349. /* Clear any outstanding interrupt. */
  350. writel(0xffc00000, fep->hwp + FEC_IEVENT);
  351. /* Reset all multicast. */
  352. writel(0, fep->hwp + FEC_GRP_HASH_TABLE_HIGH);
  353. writel(0, fep->hwp + FEC_GRP_HASH_TABLE_LOW);
  354. #ifndef CONFIG_M5272
  355. writel(0, fep->hwp + FEC_HASH_TABLE_HIGH);
  356. writel(0, fep->hwp + FEC_HASH_TABLE_LOW);
  357. #endif
  358. /* Set maximum receive buffer size. */
  359. writel(PKT_MAXBLR_SIZE, fep->hwp + FEC_R_BUFF_SIZE);
  360. /* Set receive and transmit descriptor base. */
  361. writel(fep->bd_dma, fep->hwp + FEC_R_DES_START);
  362. writel((unsigned long)fep->bd_dma + sizeof(struct bufdesc) * RX_RING_SIZE,
  363. fep->hwp + FEC_X_DES_START);
  364. fep->dirty_tx = fep->cur_tx = fep->tx_bd_base;
  365. fep->cur_rx = fep->rx_bd_base;
  366. /* Reset SKB transmit buffers. */
  367. fep->skb_cur = fep->skb_dirty = 0;
  368. for (i = 0; i <= TX_RING_MOD_MASK; i++) {
  369. if (fep->tx_skbuff[i]) {
  370. dev_kfree_skb_any(fep->tx_skbuff[i]);
  371. fep->tx_skbuff[i] = NULL;
  372. }
  373. }
  374. /* Enable MII mode */
  375. if (duplex) {
  376. /* FD enable */
  377. writel(0x04, fep->hwp + FEC_X_CNTRL);
  378. } else {
  379. /* No Rcv on Xmit */
  380. rcntl |= 0x02;
  381. writel(0x0, fep->hwp + FEC_X_CNTRL);
  382. }
  383. fep->full_duplex = duplex;
  384. /* Set MII speed */
  385. writel(fep->phy_speed, fep->hwp + FEC_MII_SPEED);
  386. /*
  387. * The phy interface and speed need to get configured
  388. * differently on enet-mac.
  389. */
  390. if (id_entry->driver_data & FEC_QUIRK_ENET_MAC) {
  391. /* Enable flow control and length check */
  392. rcntl |= 0x40000000 | 0x00000020;
  393. /* RGMII, RMII or MII */
  394. if (fep->phy_interface == PHY_INTERFACE_MODE_RGMII)
  395. rcntl |= (1 << 6);
  396. else if (fep->phy_interface == PHY_INTERFACE_MODE_RMII)
  397. rcntl |= (1 << 8);
  398. else
  399. rcntl &= ~(1 << 8);
  400. /* 1G, 100M or 10M */
  401. if (fep->phy_dev) {
  402. if (fep->phy_dev->speed == SPEED_1000)
  403. ecntl |= (1 << 5);
  404. else if (fep->phy_dev->speed == SPEED_100)
  405. rcntl &= ~(1 << 9);
  406. else
  407. rcntl |= (1 << 9);
  408. }
  409. } else {
  410. #ifdef FEC_MIIGSK_ENR
  411. if (id_entry->driver_data & FEC_QUIRK_USE_GASKET) {
  412. u32 cfgr;
  413. /* disable the gasket and wait */
  414. writel(0, fep->hwp + FEC_MIIGSK_ENR);
  415. while (readl(fep->hwp + FEC_MIIGSK_ENR) & 4)
  416. udelay(1);
  417. /*
  418. * configure the gasket:
  419. * RMII, 50 MHz, no loopback, no echo
  420. * MII, 25 MHz, no loopback, no echo
  421. */
  422. cfgr = (fep->phy_interface == PHY_INTERFACE_MODE_RMII)
  423. ? BM_MIIGSK_CFGR_RMII : BM_MIIGSK_CFGR_MII;
  424. if (fep->phy_dev && fep->phy_dev->speed == SPEED_10)
  425. cfgr |= BM_MIIGSK_CFGR_FRCONT_10M;
  426. writel(cfgr, fep->hwp + FEC_MIIGSK_CFGR);
  427. /* re-enable the gasket */
  428. writel(2, fep->hwp + FEC_MIIGSK_ENR);
  429. }
  430. #endif
  431. }
  432. writel(rcntl, fep->hwp + FEC_R_CNTRL);
  433. if (id_entry->driver_data & FEC_QUIRK_ENET_MAC) {
  434. /* enable ENET endian swap */
  435. ecntl |= (1 << 8);
  436. /* enable ENET store and forward mode */
  437. writel(1 << 8, fep->hwp + FEC_X_WMRK);
  438. }
  439. /* And last, enable the transmit and receive processing */
  440. writel(ecntl, fep->hwp + FEC_ECNTRL);
  441. writel(0, fep->hwp + FEC_R_DES_ACTIVE);
  442. /* Enable interrupts we wish to service */
  443. writel(FEC_DEFAULT_IMASK, fep->hwp + FEC_IMASK);
  444. }
  445. static void
  446. fec_stop(struct net_device *ndev)
  447. {
  448. struct fec_enet_private *fep = netdev_priv(ndev);
  449. const struct platform_device_id *id_entry =
  450. platform_get_device_id(fep->pdev);
  451. u32 rmii_mode = readl(fep->hwp + FEC_R_CNTRL) & (1 << 8);
  452. /* We cannot expect a graceful transmit stop without link !!! */
  453. if (fep->link) {
  454. writel(1, fep->hwp + FEC_X_CNTRL); /* Graceful transmit stop */
  455. udelay(10);
  456. if (!(readl(fep->hwp + FEC_IEVENT) & FEC_ENET_GRA))
  457. printk("fec_stop : Graceful transmit stop did not complete !\n");
  458. }
  459. /* Whack a reset. We should wait for this. */
  460. writel(1, fep->hwp + FEC_ECNTRL);
  461. udelay(10);
  462. writel(fep->phy_speed, fep->hwp + FEC_MII_SPEED);
  463. writel(FEC_DEFAULT_IMASK, fep->hwp + FEC_IMASK);
  464. /* We have to keep ENET enabled to have MII interrupt stay working */
  465. if (id_entry->driver_data & FEC_QUIRK_ENET_MAC) {
  466. writel(2, fep->hwp + FEC_ECNTRL);
  467. writel(rmii_mode, fep->hwp + FEC_R_CNTRL);
  468. }
  469. }
  470. static void
  471. fec_timeout(struct net_device *ndev)
  472. {
  473. struct fec_enet_private *fep = netdev_priv(ndev);
  474. ndev->stats.tx_errors++;
  475. fec_restart(ndev, fep->full_duplex);
  476. netif_wake_queue(ndev);
  477. }
  478. static void
  479. fec_enet_tx(struct net_device *ndev)
  480. {
  481. struct fec_enet_private *fep;
  482. struct bufdesc *bdp;
  483. unsigned short status;
  484. struct sk_buff *skb;
  485. fep = netdev_priv(ndev);
  486. spin_lock(&fep->hw_lock);
  487. bdp = fep->dirty_tx;
  488. while (((status = bdp->cbd_sc) & BD_ENET_TX_READY) == 0) {
  489. if (bdp == fep->cur_tx && fep->tx_full == 0)
  490. break;
  491. dma_unmap_single(&fep->pdev->dev, bdp->cbd_bufaddr,
  492. FEC_ENET_TX_FRSIZE, DMA_TO_DEVICE);
  493. bdp->cbd_bufaddr = 0;
  494. skb = fep->tx_skbuff[fep->skb_dirty];
  495. /* Check for errors. */
  496. if (status & (BD_ENET_TX_HB | BD_ENET_TX_LC |
  497. BD_ENET_TX_RL | BD_ENET_TX_UN |
  498. BD_ENET_TX_CSL)) {
  499. ndev->stats.tx_errors++;
  500. if (status & BD_ENET_TX_HB) /* No heartbeat */
  501. ndev->stats.tx_heartbeat_errors++;
  502. if (status & BD_ENET_TX_LC) /* Late collision */
  503. ndev->stats.tx_window_errors++;
  504. if (status & BD_ENET_TX_RL) /* Retrans limit */
  505. ndev->stats.tx_aborted_errors++;
  506. if (status & BD_ENET_TX_UN) /* Underrun */
  507. ndev->stats.tx_fifo_errors++;
  508. if (status & BD_ENET_TX_CSL) /* Carrier lost */
  509. ndev->stats.tx_carrier_errors++;
  510. } else {
  511. ndev->stats.tx_packets++;
  512. }
  513. if (status & BD_ENET_TX_READY)
  514. printk("HEY! Enet xmit interrupt and TX_READY.\n");
  515. /* Deferred means some collisions occurred during transmit,
  516. * but we eventually sent the packet OK.
  517. */
  518. if (status & BD_ENET_TX_DEF)
  519. ndev->stats.collisions++;
  520. /* Free the sk buffer associated with this last transmit */
  521. dev_kfree_skb_any(skb);
  522. fep->tx_skbuff[fep->skb_dirty] = NULL;
  523. fep->skb_dirty = (fep->skb_dirty + 1) & TX_RING_MOD_MASK;
  524. /* Update pointer to next buffer descriptor to be transmitted */
  525. if (status & BD_ENET_TX_WRAP)
  526. bdp = fep->tx_bd_base;
  527. else
  528. bdp++;
  529. /* Since we have freed up a buffer, the ring is no longer full
  530. */
  531. if (fep->tx_full) {
  532. fep->tx_full = 0;
  533. if (netif_queue_stopped(ndev))
  534. netif_wake_queue(ndev);
  535. }
  536. }
  537. fep->dirty_tx = bdp;
  538. spin_unlock(&fep->hw_lock);
  539. }
  540. /* During a receive, the cur_rx points to the current incoming buffer.
  541. * When we update through the ring, if the next incoming buffer has
  542. * not been given to the system, we just set the empty indicator,
  543. * effectively tossing the packet.
  544. */
  545. static void
  546. fec_enet_rx(struct net_device *ndev)
  547. {
  548. struct fec_enet_private *fep = netdev_priv(ndev);
  549. const struct platform_device_id *id_entry =
  550. platform_get_device_id(fep->pdev);
  551. struct bufdesc *bdp;
  552. unsigned short status;
  553. struct sk_buff *skb;
  554. ushort pkt_len;
  555. __u8 *data;
  556. #ifdef CONFIG_M532x
  557. flush_cache_all();
  558. #endif
  559. spin_lock(&fep->hw_lock);
  560. /* First, grab all of the stats for the incoming packet.
  561. * These get messed up if we get called due to a busy condition.
  562. */
  563. bdp = fep->cur_rx;
  564. while (!((status = bdp->cbd_sc) & BD_ENET_RX_EMPTY)) {
  565. /* Since we have allocated space to hold a complete frame,
  566. * the last indicator should be set.
  567. */
  568. if ((status & BD_ENET_RX_LAST) == 0)
  569. printk("FEC ENET: rcv is not +last\n");
  570. if (!fep->opened)
  571. goto rx_processing_done;
  572. /* Check for errors. */
  573. if (status & (BD_ENET_RX_LG | BD_ENET_RX_SH | BD_ENET_RX_NO |
  574. BD_ENET_RX_CR | BD_ENET_RX_OV)) {
  575. ndev->stats.rx_errors++;
  576. if (status & (BD_ENET_RX_LG | BD_ENET_RX_SH)) {
  577. /* Frame too long or too short. */
  578. ndev->stats.rx_length_errors++;
  579. }
  580. if (status & BD_ENET_RX_NO) /* Frame alignment */
  581. ndev->stats.rx_frame_errors++;
  582. if (status & BD_ENET_RX_CR) /* CRC Error */
  583. ndev->stats.rx_crc_errors++;
  584. if (status & BD_ENET_RX_OV) /* FIFO overrun */
  585. ndev->stats.rx_fifo_errors++;
  586. }
  587. /* Report late collisions as a frame error.
  588. * On this error, the BD is closed, but we don't know what we
  589. * have in the buffer. So, just drop this frame on the floor.
  590. */
  591. if (status & BD_ENET_RX_CL) {
  592. ndev->stats.rx_errors++;
  593. ndev->stats.rx_frame_errors++;
  594. goto rx_processing_done;
  595. }
  596. /* Process the incoming frame. */
  597. ndev->stats.rx_packets++;
  598. pkt_len = bdp->cbd_datlen;
  599. ndev->stats.rx_bytes += pkt_len;
  600. data = (__u8*)__va(bdp->cbd_bufaddr);
  601. dma_unmap_single(&fep->pdev->dev, bdp->cbd_bufaddr,
  602. FEC_ENET_TX_FRSIZE, DMA_FROM_DEVICE);
  603. if (id_entry->driver_data & FEC_QUIRK_SWAP_FRAME)
  604. swap_buffer(data, pkt_len);
  605. /* This does 16 byte alignment, exactly what we need.
  606. * The packet length includes FCS, but we don't want to
  607. * include that when passing upstream as it messes up
  608. * bridging applications.
  609. */
  610. skb = netdev_alloc_skb(ndev, pkt_len - 4 + NET_IP_ALIGN);
  611. if (unlikely(!skb)) {
  612. printk("%s: Memory squeeze, dropping packet.\n",
  613. ndev->name);
  614. ndev->stats.rx_dropped++;
  615. } else {
  616. skb_reserve(skb, NET_IP_ALIGN);
  617. skb_put(skb, pkt_len - 4); /* Make room */
  618. skb_copy_to_linear_data(skb, data, pkt_len - 4);
  619. skb->protocol = eth_type_trans(skb, ndev);
  620. if (!skb_defer_rx_timestamp(skb))
  621. netif_rx(skb);
  622. }
  623. bdp->cbd_bufaddr = dma_map_single(&fep->pdev->dev, data,
  624. FEC_ENET_TX_FRSIZE, DMA_FROM_DEVICE);
  625. rx_processing_done:
  626. /* Clear the status flags for this buffer */
  627. status &= ~BD_ENET_RX_STATS;
  628. /* Mark the buffer empty */
  629. status |= BD_ENET_RX_EMPTY;
  630. bdp->cbd_sc = status;
  631. /* Update BD pointer to next entry */
  632. if (status & BD_ENET_RX_WRAP)
  633. bdp = fep->rx_bd_base;
  634. else
  635. bdp++;
  636. /* Doing this here will keep the FEC running while we process
  637. * incoming frames. On a heavily loaded network, we should be
  638. * able to keep up at the expense of system resources.
  639. */
  640. writel(0, fep->hwp + FEC_R_DES_ACTIVE);
  641. }
  642. fep->cur_rx = bdp;
  643. spin_unlock(&fep->hw_lock);
  644. }
  645. static irqreturn_t
  646. fec_enet_interrupt(int irq, void *dev_id)
  647. {
  648. struct net_device *ndev = dev_id;
  649. struct fec_enet_private *fep = netdev_priv(ndev);
  650. uint int_events;
  651. irqreturn_t ret = IRQ_NONE;
  652. do {
  653. int_events = readl(fep->hwp + FEC_IEVENT);
  654. writel(int_events, fep->hwp + FEC_IEVENT);
  655. if (int_events & FEC_ENET_RXF) {
  656. ret = IRQ_HANDLED;
  657. fec_enet_rx(ndev);
  658. }
  659. /* Transmit OK, or non-fatal error. Update the buffer
  660. * descriptors. FEC handles all errors, we just discover
  661. * them as part of the transmit process.
  662. */
  663. if (int_events & FEC_ENET_TXF) {
  664. ret = IRQ_HANDLED;
  665. fec_enet_tx(ndev);
  666. }
  667. if (int_events & FEC_ENET_MII) {
  668. ret = IRQ_HANDLED;
  669. complete(&fep->mdio_done);
  670. }
  671. } while (int_events);
  672. return ret;
  673. }
  674. /* ------------------------------------------------------------------------- */
  675. static void __inline__ fec_get_mac(struct net_device *ndev)
  676. {
  677. struct fec_enet_private *fep = netdev_priv(ndev);
  678. struct fec_platform_data *pdata = fep->pdev->dev.platform_data;
  679. unsigned char *iap, tmpaddr[ETH_ALEN];
  680. /*
  681. * try to get mac address in following order:
  682. *
  683. * 1) module parameter via kernel command line in form
  684. * fec.macaddr=0x00,0x04,0x9f,0x01,0x30,0xe0
  685. */
  686. iap = macaddr;
  687. #ifdef CONFIG_OF
  688. /*
  689. * 2) from device tree data
  690. */
  691. if (!is_valid_ether_addr(iap)) {
  692. struct device_node *np = fep->pdev->dev.of_node;
  693. if (np) {
  694. const char *mac = of_get_mac_address(np);
  695. if (mac)
  696. iap = (unsigned char *) mac;
  697. }
  698. }
  699. #endif
  700. /*
  701. * 3) from flash or fuse (via platform data)
  702. */
  703. if (!is_valid_ether_addr(iap)) {
  704. #ifdef CONFIG_M5272
  705. if (FEC_FLASHMAC)
  706. iap = (unsigned char *)FEC_FLASHMAC;
  707. #else
  708. if (pdata)
  709. iap = (unsigned char *)&pdata->mac;
  710. #endif
  711. }
  712. /*
  713. * 4) FEC mac registers set by bootloader
  714. */
  715. if (!is_valid_ether_addr(iap)) {
  716. *((unsigned long *) &tmpaddr[0]) =
  717. be32_to_cpu(readl(fep->hwp + FEC_ADDR_LOW));
  718. *((unsigned short *) &tmpaddr[4]) =
  719. be16_to_cpu(readl(fep->hwp + FEC_ADDR_HIGH) >> 16);
  720. iap = &tmpaddr[0];
  721. }
  722. memcpy(ndev->dev_addr, iap, ETH_ALEN);
  723. /* Adjust MAC if using macaddr */
  724. if (iap == macaddr)
  725. ndev->dev_addr[ETH_ALEN-1] = macaddr[ETH_ALEN-1] + fep->dev_id;
  726. }
  727. /* ------------------------------------------------------------------------- */
  728. /*
  729. * Phy section
  730. */
  731. static void fec_enet_adjust_link(struct net_device *ndev)
  732. {
  733. struct fec_enet_private *fep = netdev_priv(ndev);
  734. struct phy_device *phy_dev = fep->phy_dev;
  735. unsigned long flags;
  736. int status_change = 0;
  737. spin_lock_irqsave(&fep->hw_lock, flags);
  738. /* Prevent a state halted on mii error */
  739. if (fep->mii_timeout && phy_dev->state == PHY_HALTED) {
  740. phy_dev->state = PHY_RESUMING;
  741. goto spin_unlock;
  742. }
  743. /* Duplex link change */
  744. if (phy_dev->link) {
  745. if (fep->full_duplex != phy_dev->duplex) {
  746. fec_restart(ndev, phy_dev->duplex);
  747. /* prevent unnecessary second fec_restart() below */
  748. fep->link = phy_dev->link;
  749. status_change = 1;
  750. }
  751. }
  752. /* Link on or off change */
  753. if (phy_dev->link != fep->link) {
  754. fep->link = phy_dev->link;
  755. if (phy_dev->link)
  756. fec_restart(ndev, phy_dev->duplex);
  757. else
  758. fec_stop(ndev);
  759. status_change = 1;
  760. }
  761. spin_unlock:
  762. spin_unlock_irqrestore(&fep->hw_lock, flags);
  763. if (status_change)
  764. phy_print_status(phy_dev);
  765. }
  766. static int fec_enet_mdio_read(struct mii_bus *bus, int mii_id, int regnum)
  767. {
  768. struct fec_enet_private *fep = bus->priv;
  769. unsigned long time_left;
  770. fep->mii_timeout = 0;
  771. init_completion(&fep->mdio_done);
  772. /* start a read op */
  773. writel(FEC_MMFR_ST | FEC_MMFR_OP_READ |
  774. FEC_MMFR_PA(mii_id) | FEC_MMFR_RA(regnum) |
  775. FEC_MMFR_TA, fep->hwp + FEC_MII_DATA);
  776. /* wait for end of transfer */
  777. time_left = wait_for_completion_timeout(&fep->mdio_done,
  778. usecs_to_jiffies(FEC_MII_TIMEOUT));
  779. if (time_left == 0) {
  780. fep->mii_timeout = 1;
  781. printk(KERN_ERR "FEC: MDIO read timeout\n");
  782. return -ETIMEDOUT;
  783. }
  784. /* return value */
  785. return FEC_MMFR_DATA(readl(fep->hwp + FEC_MII_DATA));
  786. }
  787. static int fec_enet_mdio_write(struct mii_bus *bus, int mii_id, int regnum,
  788. u16 value)
  789. {
  790. struct fec_enet_private *fep = bus->priv;
  791. unsigned long time_left;
  792. fep->mii_timeout = 0;
  793. init_completion(&fep->mdio_done);
  794. /* start a write op */
  795. writel(FEC_MMFR_ST | FEC_MMFR_OP_WRITE |
  796. FEC_MMFR_PA(mii_id) | FEC_MMFR_RA(regnum) |
  797. FEC_MMFR_TA | FEC_MMFR_DATA(value),
  798. fep->hwp + FEC_MII_DATA);
  799. /* wait for end of transfer */
  800. time_left = wait_for_completion_timeout(&fep->mdio_done,
  801. usecs_to_jiffies(FEC_MII_TIMEOUT));
  802. if (time_left == 0) {
  803. fep->mii_timeout = 1;
  804. printk(KERN_ERR "FEC: MDIO write timeout\n");
  805. return -ETIMEDOUT;
  806. }
  807. return 0;
  808. }
  809. static int fec_enet_mdio_reset(struct mii_bus *bus)
  810. {
  811. return 0;
  812. }
  813. static int fec_enet_mii_probe(struct net_device *ndev)
  814. {
  815. struct fec_enet_private *fep = netdev_priv(ndev);
  816. const struct platform_device_id *id_entry =
  817. platform_get_device_id(fep->pdev);
  818. struct phy_device *phy_dev = NULL;
  819. char mdio_bus_id[MII_BUS_ID_SIZE];
  820. char phy_name[MII_BUS_ID_SIZE + 3];
  821. int phy_id;
  822. int dev_id = fep->dev_id;
  823. fep->phy_dev = NULL;
  824. /* check for attached phy */
  825. for (phy_id = 0; (phy_id < PHY_MAX_ADDR); phy_id++) {
  826. if ((fep->mii_bus->phy_mask & (1 << phy_id)))
  827. continue;
  828. if (fep->mii_bus->phy_map[phy_id] == NULL)
  829. continue;
  830. if (fep->mii_bus->phy_map[phy_id]->phy_id == 0)
  831. continue;
  832. if (dev_id--)
  833. continue;
  834. strncpy(mdio_bus_id, fep->mii_bus->id, MII_BUS_ID_SIZE);
  835. break;
  836. }
  837. if (phy_id >= PHY_MAX_ADDR) {
  838. printk(KERN_INFO
  839. "%s: no PHY, assuming direct connection to switch\n",
  840. ndev->name);
  841. strncpy(mdio_bus_id, "fixed-0", MII_BUS_ID_SIZE);
  842. phy_id = 0;
  843. }
  844. snprintf(phy_name, sizeof(phy_name), PHY_ID_FMT, mdio_bus_id, phy_id);
  845. phy_dev = phy_connect(ndev, phy_name, &fec_enet_adjust_link, 0,
  846. fep->phy_interface);
  847. if (IS_ERR(phy_dev)) {
  848. printk(KERN_ERR "%s: could not attach to PHY\n", ndev->name);
  849. return PTR_ERR(phy_dev);
  850. }
  851. /* mask with MAC supported features */
  852. if (id_entry->driver_data & FEC_QUIRK_HAS_GBIT)
  853. phy_dev->supported &= PHY_GBIT_FEATURES;
  854. else
  855. phy_dev->supported &= PHY_BASIC_FEATURES;
  856. phy_dev->advertising = phy_dev->supported;
  857. fep->phy_dev = phy_dev;
  858. fep->link = 0;
  859. fep->full_duplex = 0;
  860. printk(KERN_INFO
  861. "%s: Freescale FEC PHY driver [%s] (mii_bus:phy_addr=%s, irq=%d)\n",
  862. ndev->name,
  863. fep->phy_dev->drv->name, dev_name(&fep->phy_dev->dev),
  864. fep->phy_dev->irq);
  865. return 0;
  866. }
  867. static int fec_enet_mii_init(struct platform_device *pdev)
  868. {
  869. static struct mii_bus *fec0_mii_bus;
  870. struct net_device *ndev = platform_get_drvdata(pdev);
  871. struct fec_enet_private *fep = netdev_priv(ndev);
  872. const struct platform_device_id *id_entry =
  873. platform_get_device_id(fep->pdev);
  874. int err = -ENXIO, i;
  875. /*
  876. * The dual fec interfaces are not equivalent with enet-mac.
  877. * Here are the differences:
  878. *
  879. * - fec0 supports MII & RMII modes while fec1 only supports RMII
  880. * - fec0 acts as the 1588 time master while fec1 is slave
  881. * - external phys can only be configured by fec0
  882. *
  883. * That is to say fec1 can not work independently. It only works
  884. * when fec0 is working. The reason behind this design is that the
  885. * second interface is added primarily for Switch mode.
  886. *
  887. * Because of the last point above, both phys are attached on fec0
  888. * mdio interface in board design, and need to be configured by
  889. * fec0 mii_bus.
  890. */
  891. if ((id_entry->driver_data & FEC_QUIRK_ENET_MAC) && fep->dev_id > 0) {
  892. /* fec1 uses fec0 mii_bus */
  893. if (mii_cnt && fec0_mii_bus) {
  894. fep->mii_bus = fec0_mii_bus;
  895. mii_cnt++;
  896. return 0;
  897. }
  898. return -ENOENT;
  899. }
  900. fep->mii_timeout = 0;
  901. /*
  902. * Set MII speed to 2.5 MHz (= clk_get_rate() / 2 * phy_speed)
  903. *
  904. * The formula for FEC MDC is 'ref_freq / (MII_SPEED x 2)' while
  905. * for ENET-MAC is 'ref_freq / ((MII_SPEED + 1) x 2)'. The i.MX28
  906. * Reference Manual has an error on this, and gets fixed on i.MX6Q
  907. * document.
  908. */
  909. fep->phy_speed = DIV_ROUND_UP(clk_get_rate(fep->clk_ahb), 5000000);
  910. if (id_entry->driver_data & FEC_QUIRK_ENET_MAC)
  911. fep->phy_speed--;
  912. fep->phy_speed <<= 1;
  913. writel(fep->phy_speed, fep->hwp + FEC_MII_SPEED);
  914. fep->mii_bus = mdiobus_alloc();
  915. if (fep->mii_bus == NULL) {
  916. err = -ENOMEM;
  917. goto err_out;
  918. }
  919. fep->mii_bus->name = "fec_enet_mii_bus";
  920. fep->mii_bus->read = fec_enet_mdio_read;
  921. fep->mii_bus->write = fec_enet_mdio_write;
  922. fep->mii_bus->reset = fec_enet_mdio_reset;
  923. snprintf(fep->mii_bus->id, MII_BUS_ID_SIZE, "%s-%x",
  924. pdev->name, fep->dev_id + 1);
  925. fep->mii_bus->priv = fep;
  926. fep->mii_bus->parent = &pdev->dev;
  927. fep->mii_bus->irq = kmalloc(sizeof(int) * PHY_MAX_ADDR, GFP_KERNEL);
  928. if (!fep->mii_bus->irq) {
  929. err = -ENOMEM;
  930. goto err_out_free_mdiobus;
  931. }
  932. for (i = 0; i < PHY_MAX_ADDR; i++)
  933. fep->mii_bus->irq[i] = PHY_POLL;
  934. if (mdiobus_register(fep->mii_bus))
  935. goto err_out_free_mdio_irq;
  936. mii_cnt++;
  937. /* save fec0 mii_bus */
  938. if (id_entry->driver_data & FEC_QUIRK_ENET_MAC)
  939. fec0_mii_bus = fep->mii_bus;
  940. return 0;
  941. err_out_free_mdio_irq:
  942. kfree(fep->mii_bus->irq);
  943. err_out_free_mdiobus:
  944. mdiobus_free(fep->mii_bus);
  945. err_out:
  946. return err;
  947. }
  948. static void fec_enet_mii_remove(struct fec_enet_private *fep)
  949. {
  950. if (--mii_cnt == 0) {
  951. mdiobus_unregister(fep->mii_bus);
  952. kfree(fep->mii_bus->irq);
  953. mdiobus_free(fep->mii_bus);
  954. }
  955. }
  956. static int fec_enet_get_settings(struct net_device *ndev,
  957. struct ethtool_cmd *cmd)
  958. {
  959. struct fec_enet_private *fep = netdev_priv(ndev);
  960. struct phy_device *phydev = fep->phy_dev;
  961. if (!phydev)
  962. return -ENODEV;
  963. return phy_ethtool_gset(phydev, cmd);
  964. }
  965. static int fec_enet_set_settings(struct net_device *ndev,
  966. struct ethtool_cmd *cmd)
  967. {
  968. struct fec_enet_private *fep = netdev_priv(ndev);
  969. struct phy_device *phydev = fep->phy_dev;
  970. if (!phydev)
  971. return -ENODEV;
  972. return phy_ethtool_sset(phydev, cmd);
  973. }
  974. static void fec_enet_get_drvinfo(struct net_device *ndev,
  975. struct ethtool_drvinfo *info)
  976. {
  977. struct fec_enet_private *fep = netdev_priv(ndev);
  978. strcpy(info->driver, fep->pdev->dev.driver->name);
  979. strcpy(info->version, "Revision: 1.0");
  980. strcpy(info->bus_info, dev_name(&ndev->dev));
  981. }
  982. static const struct ethtool_ops fec_enet_ethtool_ops = {
  983. .get_settings = fec_enet_get_settings,
  984. .set_settings = fec_enet_set_settings,
  985. .get_drvinfo = fec_enet_get_drvinfo,
  986. .get_link = ethtool_op_get_link,
  987. .get_ts_info = ethtool_op_get_ts_info,
  988. };
  989. static int fec_enet_ioctl(struct net_device *ndev, struct ifreq *rq, int cmd)
  990. {
  991. struct fec_enet_private *fep = netdev_priv(ndev);
  992. struct phy_device *phydev = fep->phy_dev;
  993. if (!netif_running(ndev))
  994. return -EINVAL;
  995. if (!phydev)
  996. return -ENODEV;
  997. return phy_mii_ioctl(phydev, rq, cmd);
  998. }
  999. static void fec_enet_free_buffers(struct net_device *ndev)
  1000. {
  1001. struct fec_enet_private *fep = netdev_priv(ndev);
  1002. int i;
  1003. struct sk_buff *skb;
  1004. struct bufdesc *bdp;
  1005. bdp = fep->rx_bd_base;
  1006. for (i = 0; i < RX_RING_SIZE; i++) {
  1007. skb = fep->rx_skbuff[i];
  1008. if (bdp->cbd_bufaddr)
  1009. dma_unmap_single(&fep->pdev->dev, bdp->cbd_bufaddr,
  1010. FEC_ENET_RX_FRSIZE, DMA_FROM_DEVICE);
  1011. if (skb)
  1012. dev_kfree_skb(skb);
  1013. bdp++;
  1014. }
  1015. bdp = fep->tx_bd_base;
  1016. for (i = 0; i < TX_RING_SIZE; i++)
  1017. kfree(fep->tx_bounce[i]);
  1018. }
  1019. static int fec_enet_alloc_buffers(struct net_device *ndev)
  1020. {
  1021. struct fec_enet_private *fep = netdev_priv(ndev);
  1022. int i;
  1023. struct sk_buff *skb;
  1024. struct bufdesc *bdp;
  1025. bdp = fep->rx_bd_base;
  1026. for (i = 0; i < RX_RING_SIZE; i++) {
  1027. skb = netdev_alloc_skb(ndev, FEC_ENET_RX_FRSIZE);
  1028. if (!skb) {
  1029. fec_enet_free_buffers(ndev);
  1030. return -ENOMEM;
  1031. }
  1032. fep->rx_skbuff[i] = skb;
  1033. bdp->cbd_bufaddr = dma_map_single(&fep->pdev->dev, skb->data,
  1034. FEC_ENET_RX_FRSIZE, DMA_FROM_DEVICE);
  1035. bdp->cbd_sc = BD_ENET_RX_EMPTY;
  1036. bdp++;
  1037. }
  1038. /* Set the last buffer to wrap. */
  1039. bdp--;
  1040. bdp->cbd_sc |= BD_SC_WRAP;
  1041. bdp = fep->tx_bd_base;
  1042. for (i = 0; i < TX_RING_SIZE; i++) {
  1043. fep->tx_bounce[i] = kmalloc(FEC_ENET_TX_FRSIZE, GFP_KERNEL);
  1044. bdp->cbd_sc = 0;
  1045. bdp->cbd_bufaddr = 0;
  1046. bdp++;
  1047. }
  1048. /* Set the last buffer to wrap. */
  1049. bdp--;
  1050. bdp->cbd_sc |= BD_SC_WRAP;
  1051. return 0;
  1052. }
  1053. static int
  1054. fec_enet_open(struct net_device *ndev)
  1055. {
  1056. struct fec_enet_private *fep = netdev_priv(ndev);
  1057. int ret;
  1058. /* I should reset the ring buffers here, but I don't yet know
  1059. * a simple way to do that.
  1060. */
  1061. ret = fec_enet_alloc_buffers(ndev);
  1062. if (ret)
  1063. return ret;
  1064. /* Probe and connect to PHY when open the interface */
  1065. ret = fec_enet_mii_probe(ndev);
  1066. if (ret) {
  1067. fec_enet_free_buffers(ndev);
  1068. return ret;
  1069. }
  1070. phy_start(fep->phy_dev);
  1071. netif_start_queue(ndev);
  1072. fep->opened = 1;
  1073. return 0;
  1074. }
  1075. static int
  1076. fec_enet_close(struct net_device *ndev)
  1077. {
  1078. struct fec_enet_private *fep = netdev_priv(ndev);
  1079. /* Don't know what to do yet. */
  1080. fep->opened = 0;
  1081. netif_stop_queue(ndev);
  1082. fec_stop(ndev);
  1083. if (fep->phy_dev) {
  1084. phy_stop(fep->phy_dev);
  1085. phy_disconnect(fep->phy_dev);
  1086. }
  1087. fec_enet_free_buffers(ndev);
  1088. return 0;
  1089. }
  1090. /* Set or clear the multicast filter for this adaptor.
  1091. * Skeleton taken from sunlance driver.
  1092. * The CPM Ethernet implementation allows Multicast as well as individual
  1093. * MAC address filtering. Some of the drivers check to make sure it is
  1094. * a group multicast address, and discard those that are not. I guess I
  1095. * will do the same for now, but just remove the test if you want
  1096. * individual filtering as well (do the upper net layers want or support
  1097. * this kind of feature?).
  1098. */
  1099. #define HASH_BITS 6 /* #bits in hash */
  1100. #define CRC32_POLY 0xEDB88320
  1101. static void set_multicast_list(struct net_device *ndev)
  1102. {
  1103. struct fec_enet_private *fep = netdev_priv(ndev);
  1104. struct netdev_hw_addr *ha;
  1105. unsigned int i, bit, data, crc, tmp;
  1106. unsigned char hash;
  1107. if (ndev->flags & IFF_PROMISC) {
  1108. tmp = readl(fep->hwp + FEC_R_CNTRL);
  1109. tmp |= 0x8;
  1110. writel(tmp, fep->hwp + FEC_R_CNTRL);
  1111. return;
  1112. }
  1113. tmp = readl(fep->hwp + FEC_R_CNTRL);
  1114. tmp &= ~0x8;
  1115. writel(tmp, fep->hwp + FEC_R_CNTRL);
  1116. if (ndev->flags & IFF_ALLMULTI) {
  1117. /* Catch all multicast addresses, so set the
  1118. * filter to all 1's
  1119. */
  1120. writel(0xffffffff, fep->hwp + FEC_GRP_HASH_TABLE_HIGH);
  1121. writel(0xffffffff, fep->hwp + FEC_GRP_HASH_TABLE_LOW);
  1122. return;
  1123. }
  1124. /* Clear filter and add the addresses in hash register
  1125. */
  1126. writel(0, fep->hwp + FEC_GRP_HASH_TABLE_HIGH);
  1127. writel(0, fep->hwp + FEC_GRP_HASH_TABLE_LOW);
  1128. netdev_for_each_mc_addr(ha, ndev) {
  1129. /* calculate crc32 value of mac address */
  1130. crc = 0xffffffff;
  1131. for (i = 0; i < ndev->addr_len; i++) {
  1132. data = ha->addr[i];
  1133. for (bit = 0; bit < 8; bit++, data >>= 1) {
  1134. crc = (crc >> 1) ^
  1135. (((crc ^ data) & 1) ? CRC32_POLY : 0);
  1136. }
  1137. }
  1138. /* only upper 6 bits (HASH_BITS) are used
  1139. * which point to specific bit in he hash registers
  1140. */
  1141. hash = (crc >> (32 - HASH_BITS)) & 0x3f;
  1142. if (hash > 31) {
  1143. tmp = readl(fep->hwp + FEC_GRP_HASH_TABLE_HIGH);
  1144. tmp |= 1 << (hash - 32);
  1145. writel(tmp, fep->hwp + FEC_GRP_HASH_TABLE_HIGH);
  1146. } else {
  1147. tmp = readl(fep->hwp + FEC_GRP_HASH_TABLE_LOW);
  1148. tmp |= 1 << hash;
  1149. writel(tmp, fep->hwp + FEC_GRP_HASH_TABLE_LOW);
  1150. }
  1151. }
  1152. }
  1153. /* Set a MAC change in hardware. */
  1154. static int
  1155. fec_set_mac_address(struct net_device *ndev, void *p)
  1156. {
  1157. struct fec_enet_private *fep = netdev_priv(ndev);
  1158. struct sockaddr *addr = p;
  1159. if (!is_valid_ether_addr(addr->sa_data))
  1160. return -EADDRNOTAVAIL;
  1161. memcpy(ndev->dev_addr, addr->sa_data, ndev->addr_len);
  1162. writel(ndev->dev_addr[3] | (ndev->dev_addr[2] << 8) |
  1163. (ndev->dev_addr[1] << 16) | (ndev->dev_addr[0] << 24),
  1164. fep->hwp + FEC_ADDR_LOW);
  1165. writel((ndev->dev_addr[5] << 16) | (ndev->dev_addr[4] << 24),
  1166. fep->hwp + FEC_ADDR_HIGH);
  1167. return 0;
  1168. }
  1169. #ifdef CONFIG_NET_POLL_CONTROLLER
  1170. /**
  1171. * fec_poll_controller - FEC Poll controller function
  1172. * @dev: The FEC network adapter
  1173. *
  1174. * Polled functionality used by netconsole and others in non interrupt mode
  1175. *
  1176. */
  1177. void fec_poll_controller(struct net_device *dev)
  1178. {
  1179. int i;
  1180. struct fec_enet_private *fep = netdev_priv(dev);
  1181. for (i = 0; i < FEC_IRQ_NUM; i++) {
  1182. if (fep->irq[i] > 0) {
  1183. disable_irq(fep->irq[i]);
  1184. fec_enet_interrupt(fep->irq[i], dev);
  1185. enable_irq(fep->irq[i]);
  1186. }
  1187. }
  1188. }
  1189. #endif
  1190. static const struct net_device_ops fec_netdev_ops = {
  1191. .ndo_open = fec_enet_open,
  1192. .ndo_stop = fec_enet_close,
  1193. .ndo_start_xmit = fec_enet_start_xmit,
  1194. .ndo_set_rx_mode = set_multicast_list,
  1195. .ndo_change_mtu = eth_change_mtu,
  1196. .ndo_validate_addr = eth_validate_addr,
  1197. .ndo_tx_timeout = fec_timeout,
  1198. .ndo_set_mac_address = fec_set_mac_address,
  1199. .ndo_do_ioctl = fec_enet_ioctl,
  1200. #ifdef CONFIG_NET_POLL_CONTROLLER
  1201. .ndo_poll_controller = fec_poll_controller,
  1202. #endif
  1203. };
  1204. /*
  1205. * XXX: We need to clean up on failure exits here.
  1206. *
  1207. */
  1208. static int fec_enet_init(struct net_device *ndev)
  1209. {
  1210. struct fec_enet_private *fep = netdev_priv(ndev);
  1211. struct bufdesc *cbd_base;
  1212. struct bufdesc *bdp;
  1213. int i;
  1214. /* Allocate memory for buffer descriptors. */
  1215. cbd_base = dma_alloc_coherent(NULL, PAGE_SIZE, &fep->bd_dma,
  1216. GFP_KERNEL);
  1217. if (!cbd_base) {
  1218. printk("FEC: allocate descriptor memory failed?\n");
  1219. return -ENOMEM;
  1220. }
  1221. spin_lock_init(&fep->hw_lock);
  1222. fep->netdev = ndev;
  1223. /* Get the Ethernet address */
  1224. fec_get_mac(ndev);
  1225. /* Set receive and transmit descriptor base. */
  1226. fep->rx_bd_base = cbd_base;
  1227. fep->tx_bd_base = cbd_base + RX_RING_SIZE;
  1228. /* The FEC Ethernet specific entries in the device structure */
  1229. ndev->watchdog_timeo = TX_TIMEOUT;
  1230. ndev->netdev_ops = &fec_netdev_ops;
  1231. ndev->ethtool_ops = &fec_enet_ethtool_ops;
  1232. /* Initialize the receive buffer descriptors. */
  1233. bdp = fep->rx_bd_base;
  1234. for (i = 0; i < RX_RING_SIZE; i++) {
  1235. /* Initialize the BD for every fragment in the page. */
  1236. bdp->cbd_sc = 0;
  1237. bdp++;
  1238. }
  1239. /* Set the last buffer to wrap */
  1240. bdp--;
  1241. bdp->cbd_sc |= BD_SC_WRAP;
  1242. /* ...and the same for transmit */
  1243. bdp = fep->tx_bd_base;
  1244. for (i = 0; i < TX_RING_SIZE; i++) {
  1245. /* Initialize the BD for every fragment in the page. */
  1246. bdp->cbd_sc = 0;
  1247. bdp->cbd_bufaddr = 0;
  1248. bdp++;
  1249. }
  1250. /* Set the last buffer to wrap */
  1251. bdp--;
  1252. bdp->cbd_sc |= BD_SC_WRAP;
  1253. fec_restart(ndev, 0);
  1254. return 0;
  1255. }
  1256. #ifdef CONFIG_OF
  1257. static int __devinit fec_get_phy_mode_dt(struct platform_device *pdev)
  1258. {
  1259. struct device_node *np = pdev->dev.of_node;
  1260. if (np)
  1261. return of_get_phy_mode(np);
  1262. return -ENODEV;
  1263. }
  1264. static void __devinit fec_reset_phy(struct platform_device *pdev)
  1265. {
  1266. int err, phy_reset;
  1267. int msec = 1;
  1268. struct device_node *np = pdev->dev.of_node;
  1269. if (!np)
  1270. return;
  1271. of_property_read_u32(np, "phy-reset-duration", &msec);
  1272. /* A sane reset duration should not be longer than 1s */
  1273. if (msec > 1000)
  1274. msec = 1;
  1275. phy_reset = of_get_named_gpio(np, "phy-reset-gpios", 0);
  1276. err = devm_gpio_request_one(&pdev->dev, phy_reset,
  1277. GPIOF_OUT_INIT_LOW, "phy-reset");
  1278. if (err) {
  1279. pr_debug("FEC: failed to get gpio phy-reset: %d\n", err);
  1280. return;
  1281. }
  1282. msleep(msec);
  1283. gpio_set_value(phy_reset, 1);
  1284. }
  1285. #else /* CONFIG_OF */
  1286. static inline int fec_get_phy_mode_dt(struct platform_device *pdev)
  1287. {
  1288. return -ENODEV;
  1289. }
  1290. static inline void fec_reset_phy(struct platform_device *pdev)
  1291. {
  1292. /*
  1293. * In case of platform probe, the reset has been done
  1294. * by machine code.
  1295. */
  1296. }
  1297. #endif /* CONFIG_OF */
  1298. static int __devinit
  1299. fec_probe(struct platform_device *pdev)
  1300. {
  1301. struct fec_enet_private *fep;
  1302. struct fec_platform_data *pdata;
  1303. struct net_device *ndev;
  1304. int i, irq, ret = 0;
  1305. struct resource *r;
  1306. const struct of_device_id *of_id;
  1307. static int dev_id;
  1308. struct pinctrl *pinctrl;
  1309. struct regulator *reg_phy;
  1310. of_id = of_match_device(fec_dt_ids, &pdev->dev);
  1311. if (of_id)
  1312. pdev->id_entry = of_id->data;
  1313. r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1314. if (!r)
  1315. return -ENXIO;
  1316. r = request_mem_region(r->start, resource_size(r), pdev->name);
  1317. if (!r)
  1318. return -EBUSY;
  1319. /* Init network device */
  1320. ndev = alloc_etherdev(sizeof(struct fec_enet_private));
  1321. if (!ndev) {
  1322. ret = -ENOMEM;
  1323. goto failed_alloc_etherdev;
  1324. }
  1325. SET_NETDEV_DEV(ndev, &pdev->dev);
  1326. /* setup board info structure */
  1327. fep = netdev_priv(ndev);
  1328. fep->hwp = ioremap(r->start, resource_size(r));
  1329. fep->pdev = pdev;
  1330. fep->dev_id = dev_id++;
  1331. if (!fep->hwp) {
  1332. ret = -ENOMEM;
  1333. goto failed_ioremap;
  1334. }
  1335. platform_set_drvdata(pdev, ndev);
  1336. ret = fec_get_phy_mode_dt(pdev);
  1337. if (ret < 0) {
  1338. pdata = pdev->dev.platform_data;
  1339. if (pdata)
  1340. fep->phy_interface = pdata->phy;
  1341. else
  1342. fep->phy_interface = PHY_INTERFACE_MODE_MII;
  1343. } else {
  1344. fep->phy_interface = ret;
  1345. }
  1346. for (i = 0; i < FEC_IRQ_NUM; i++) {
  1347. irq = platform_get_irq(pdev, i);
  1348. if (irq < 0) {
  1349. if (i)
  1350. break;
  1351. ret = irq;
  1352. goto failed_irq;
  1353. }
  1354. ret = request_irq(irq, fec_enet_interrupt, IRQF_DISABLED, pdev->name, ndev);
  1355. if (ret) {
  1356. while (--i >= 0) {
  1357. irq = platform_get_irq(pdev, i);
  1358. free_irq(irq, ndev);
  1359. }
  1360. goto failed_irq;
  1361. }
  1362. }
  1363. pinctrl = devm_pinctrl_get_select_default(&pdev->dev);
  1364. if (IS_ERR(pinctrl)) {
  1365. ret = PTR_ERR(pinctrl);
  1366. goto failed_pin;
  1367. }
  1368. fep->clk_ipg = devm_clk_get(&pdev->dev, "ipg");
  1369. if (IS_ERR(fep->clk_ipg)) {
  1370. ret = PTR_ERR(fep->clk_ipg);
  1371. goto failed_clk;
  1372. }
  1373. fep->clk_ahb = devm_clk_get(&pdev->dev, "ahb");
  1374. if (IS_ERR(fep->clk_ahb)) {
  1375. ret = PTR_ERR(fep->clk_ahb);
  1376. goto failed_clk;
  1377. }
  1378. clk_prepare_enable(fep->clk_ahb);
  1379. clk_prepare_enable(fep->clk_ipg);
  1380. reg_phy = devm_regulator_get(&pdev->dev, "phy");
  1381. if (!IS_ERR(reg_phy)) {
  1382. ret = regulator_enable(reg_phy);
  1383. if (ret) {
  1384. dev_err(&pdev->dev,
  1385. "Failed to enable phy regulator: %d\n", ret);
  1386. goto failed_regulator;
  1387. }
  1388. }
  1389. fec_reset_phy(pdev);
  1390. ret = fec_enet_init(ndev);
  1391. if (ret)
  1392. goto failed_init;
  1393. ret = fec_enet_mii_init(pdev);
  1394. if (ret)
  1395. goto failed_mii_init;
  1396. /* Carrier starts down, phylib will bring it up */
  1397. netif_carrier_off(ndev);
  1398. ret = register_netdev(ndev);
  1399. if (ret)
  1400. goto failed_register;
  1401. return 0;
  1402. failed_register:
  1403. fec_enet_mii_remove(fep);
  1404. failed_mii_init:
  1405. failed_init:
  1406. failed_regulator:
  1407. clk_disable_unprepare(fep->clk_ahb);
  1408. clk_disable_unprepare(fep->clk_ipg);
  1409. failed_pin:
  1410. failed_clk:
  1411. for (i = 0; i < FEC_IRQ_NUM; i++) {
  1412. irq = platform_get_irq(pdev, i);
  1413. if (irq > 0)
  1414. free_irq(irq, ndev);
  1415. }
  1416. failed_irq:
  1417. iounmap(fep->hwp);
  1418. failed_ioremap:
  1419. free_netdev(ndev);
  1420. failed_alloc_etherdev:
  1421. release_mem_region(r->start, resource_size(r));
  1422. return ret;
  1423. }
  1424. static int __devexit
  1425. fec_drv_remove(struct platform_device *pdev)
  1426. {
  1427. struct net_device *ndev = platform_get_drvdata(pdev);
  1428. struct fec_enet_private *fep = netdev_priv(ndev);
  1429. struct resource *r;
  1430. int i;
  1431. unregister_netdev(ndev);
  1432. fec_enet_mii_remove(fep);
  1433. for (i = 0; i < FEC_IRQ_NUM; i++) {
  1434. int irq = platform_get_irq(pdev, i);
  1435. if (irq > 0)
  1436. free_irq(irq, ndev);
  1437. }
  1438. clk_disable_unprepare(fep->clk_ahb);
  1439. clk_disable_unprepare(fep->clk_ipg);
  1440. iounmap(fep->hwp);
  1441. free_netdev(ndev);
  1442. r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1443. BUG_ON(!r);
  1444. release_mem_region(r->start, resource_size(r));
  1445. platform_set_drvdata(pdev, NULL);
  1446. return 0;
  1447. }
  1448. #ifdef CONFIG_PM
  1449. static int
  1450. fec_suspend(struct device *dev)
  1451. {
  1452. struct net_device *ndev = dev_get_drvdata(dev);
  1453. struct fec_enet_private *fep = netdev_priv(ndev);
  1454. if (netif_running(ndev)) {
  1455. fec_stop(ndev);
  1456. netif_device_detach(ndev);
  1457. }
  1458. clk_disable_unprepare(fep->clk_ahb);
  1459. clk_disable_unprepare(fep->clk_ipg);
  1460. return 0;
  1461. }
  1462. static int
  1463. fec_resume(struct device *dev)
  1464. {
  1465. struct net_device *ndev = dev_get_drvdata(dev);
  1466. struct fec_enet_private *fep = netdev_priv(ndev);
  1467. clk_prepare_enable(fep->clk_ahb);
  1468. clk_prepare_enable(fep->clk_ipg);
  1469. if (netif_running(ndev)) {
  1470. fec_restart(ndev, fep->full_duplex);
  1471. netif_device_attach(ndev);
  1472. }
  1473. return 0;
  1474. }
  1475. static const struct dev_pm_ops fec_pm_ops = {
  1476. .suspend = fec_suspend,
  1477. .resume = fec_resume,
  1478. .freeze = fec_suspend,
  1479. .thaw = fec_resume,
  1480. .poweroff = fec_suspend,
  1481. .restore = fec_resume,
  1482. };
  1483. #endif
  1484. static struct platform_driver fec_driver = {
  1485. .driver = {
  1486. .name = DRIVER_NAME,
  1487. .owner = THIS_MODULE,
  1488. #ifdef CONFIG_PM
  1489. .pm = &fec_pm_ops,
  1490. #endif
  1491. .of_match_table = fec_dt_ids,
  1492. },
  1493. .id_table = fec_devtype,
  1494. .probe = fec_probe,
  1495. .remove = __devexit_p(fec_drv_remove),
  1496. };
  1497. module_platform_driver(fec_driver);
  1498. MODULE_LICENSE("GPL");