2 * File: drivers/net/bfin_mac.c
5 * Bryan Wu <bryan.wu@analog.com>
8 * Luke Yang <luke.yang@analog.com>
14 * Copyright 2004-2006 Analog Devices Inc.
16 * Bugs: Enter bugs at http://blackfin.uclinux.org/
18 * This program is free software ; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation ; either version 2, or (at your option)
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY ; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
28 * You should have received a copy of the GNU General Public License
29 * along with this program ; see the file COPYING.
30 * If not, write to the Free Software Foundation,
31 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
34 #include <linux/init.h>
35 #include <linux/module.h>
36 #include <linux/kernel.h>
37 #include <linux/sched.h>
38 #include <linux/slab.h>
39 #include <linux/delay.h>
40 #include <linux/timer.h>
41 #include <linux/errno.h>
42 #include <linux/irq.h>
44 #include <linux/ioport.h>
45 #include <linux/crc32.h>
46 #include <linux/device.h>
47 #include <linux/spinlock.h>
48 #include <linux/ethtool.h>
49 #include <linux/mii.h>
51 #include <linux/netdevice.h>
52 #include <linux/etherdevice.h>
53 #include <linux/skbuff.h>
55 #include <linux/platform_device.h>
56 #include <linux/netdevice.h>
57 #include <linux/etherdevice.h>
58 #include <linux/skbuff.h>
61 #include <linux/dma-mapping.h>
63 #include <asm/blackfin.h>
64 #include <asm/cacheflush.h>
65 #include <asm/portmux.h>
69 #define DRV_NAME "bfin_mac"
70 #define DRV_VERSION "1.1"
71 #define DRV_AUTHOR "Bryan Wu, Luke Yang"
72 #define DRV_DESC "Blackfin BF53[67] on-chip Ethernet MAC driver"
74 MODULE_AUTHOR(DRV_AUTHOR);
75 MODULE_LICENSE("GPL");
76 MODULE_DESCRIPTION(DRV_DESC);
78 #if defined(CONFIG_BFIN_MAC_USE_L1)
79 # define bfin_mac_alloc(dma_handle, size) l1_data_sram_zalloc(size)
80 # define bfin_mac_free(dma_handle, ptr) l1_data_sram_free(ptr)
82 # define bfin_mac_alloc(dma_handle, size) \
83 dma_alloc_coherent(NULL, size, dma_handle, GFP_KERNEL)
84 # define bfin_mac_free(dma_handle, ptr) \
85 dma_free_coherent(NULL, sizeof(*ptr), ptr, dma_handle)
88 #define PKT_BUF_SZ 1580
90 #define MAX_TIMEOUT_CNT 500
92 /* pointers to maintain transmit list */
93 static struct net_dma_desc_tx *tx_list_head;
94 static struct net_dma_desc_tx *tx_list_tail;
95 static struct net_dma_desc_rx *rx_list_head;
96 static struct net_dma_desc_rx *rx_list_tail;
97 static struct net_dma_desc_rx *current_rx_ptr;
98 static struct net_dma_desc_tx *current_tx_ptr;
99 static struct net_dma_desc_tx *tx_desc;
100 static struct net_dma_desc_rx *rx_desc;
102 static void desc_list_free(void)
104 struct net_dma_desc_rx *r;
105 struct net_dma_desc_tx *t;
107 #if !defined(CONFIG_BFIN_MAC_USE_L1)
108 dma_addr_t dma_handle = 0;
113 for (i = 0; i < CONFIG_BFIN_TX_DESC_NUM; i++) {
116 dev_kfree_skb(t->skb);
122 bfin_mac_free(dma_handle, tx_desc);
127 for (i = 0; i < CONFIG_BFIN_RX_DESC_NUM; i++) {
130 dev_kfree_skb(r->skb);
136 bfin_mac_free(dma_handle, rx_desc);
140 static int desc_list_init(void)
143 struct sk_buff *new_skb;
144 #if !defined(CONFIG_BFIN_MAC_USE_L1)
146 * This dma_handle is useless in Blackfin dma_alloc_coherent().
147 * The real dma handler is the return value of dma_alloc_coherent().
149 dma_addr_t dma_handle;
152 tx_desc = bfin_mac_alloc(&dma_handle,
153 sizeof(struct net_dma_desc_tx) *
154 CONFIG_BFIN_TX_DESC_NUM);
158 rx_desc = bfin_mac_alloc(&dma_handle,
159 sizeof(struct net_dma_desc_rx) *
160 CONFIG_BFIN_RX_DESC_NUM);
165 tx_list_head = tx_list_tail = tx_desc;
167 for (i = 0; i < CONFIG_BFIN_TX_DESC_NUM; i++) {
168 struct net_dma_desc_tx *t = tx_desc + i;
169 struct dma_descriptor *a = &(t->desc_a);
170 struct dma_descriptor *b = &(t->desc_b);
174 * read from memory WNR = 0
175 * wordsize is 32 bits
176 * 6 half words is desc size
179 a->config = WDSIZE_32 | NDSIZE_6 | DMAFLOW_LARGE;
180 a->start_addr = (unsigned long)t->packet;
182 a->next_dma_desc = b;
186 * write to memory WNR = 1
187 * wordsize is 32 bits
189 * 6 half words is desc size
192 b->config = DMAEN | WNR | WDSIZE_32 | NDSIZE_6 | DMAFLOW_LARGE;
193 b->start_addr = (unsigned long)(&(t->status));
197 tx_list_tail->desc_b.next_dma_desc = a;
198 tx_list_tail->next = t;
201 tx_list_tail->next = tx_list_head; /* tx_list is a circle */
202 tx_list_tail->desc_b.next_dma_desc = &(tx_list_head->desc_a);
203 current_tx_ptr = tx_list_head;
206 rx_list_head = rx_list_tail = rx_desc;
208 for (i = 0; i < CONFIG_BFIN_RX_DESC_NUM; i++) {
209 struct net_dma_desc_rx *r = rx_desc + i;
210 struct dma_descriptor *a = &(r->desc_a);
211 struct dma_descriptor *b = &(r->desc_b);
213 /* allocate a new skb for next time receive */
214 new_skb = dev_alloc_skb(PKT_BUF_SZ + 2);
216 printk(KERN_NOTICE DRV_NAME
217 ": init: low on mem - packet dropped\n");
220 skb_reserve(new_skb, 2);
225 * write to memory WNR = 1
226 * wordsize is 32 bits
228 * 6 half words is desc size
231 a->config = DMAEN | WNR | WDSIZE_32 | NDSIZE_6 | DMAFLOW_LARGE;
232 /* since RXDWA is enabled */
233 a->start_addr = (unsigned long)new_skb->data - 2;
235 a->next_dma_desc = b;
239 * write to memory WNR = 1
240 * wordsize is 32 bits
242 * 6 half words is desc size
245 b->config = DMAEN | WNR | WDSIZE_32 | DI_EN |
246 NDSIZE_6 | DMAFLOW_LARGE;
247 b->start_addr = (unsigned long)(&(r->status));
250 rx_list_tail->desc_b.next_dma_desc = a;
251 rx_list_tail->next = r;
254 rx_list_tail->next = rx_list_head; /* rx_list is a circle */
255 rx_list_tail->desc_b.next_dma_desc = &(rx_list_head->desc_a);
256 current_rx_ptr = rx_list_head;
262 printk(KERN_ERR DRV_NAME ": kmalloc failed\n");
267 /*---PHY CONTROL AND CONFIGURATION-----------------------------------------*/
269 /* Set FER regs to MUX in Ethernet pins */
270 static int setup_pin_mux(int action)
272 #if defined(CONFIG_BFIN_MAC_RMII)
273 u16 pin_req[] = P_RMII0;
275 u16 pin_req[] = P_MII0;
279 if (peripheral_request_list(pin_req, DRV_NAME)) {
280 printk(KERN_ERR DRV_NAME
281 ": Requesting Peripherals failed\n");
285 peripheral_free_list(pin_req);
290 /* Wait until the previous MDC/MDIO transaction has completed */
291 static void poll_mdc_done(void)
293 int timeout_cnt = MAX_TIMEOUT_CNT;
295 /* poll the STABUSY bit */
296 while ((bfin_read_EMAC_STAADD()) & STABUSY) {
298 if (timeout_cnt-- < 0) {
299 printk(KERN_ERR DRV_NAME
300 ": wait MDC/MDIO transaction to complete timeout\n");
306 /* Read an off-chip register in a PHY through the MDC/MDIO port */
307 static u16 read_phy_reg(u16 PHYAddr, u16 RegAddr)
311 bfin_write_EMAC_STAADD(SET_PHYAD(PHYAddr) |
316 return (u16) bfin_read_EMAC_STADAT();
319 /* Write an off-chip register in a PHY through the MDC/MDIO port */
320 static void raw_write_phy_reg(u16 PHYAddr, u16 RegAddr, u32 Data)
322 bfin_write_EMAC_STADAT(Data);
325 bfin_write_EMAC_STAADD(SET_PHYAD(PHYAddr) |
333 static void write_phy_reg(u16 PHYAddr, u16 RegAddr, u32 Data)
336 raw_write_phy_reg(PHYAddr, RegAddr, Data);
340 static void bf537mac_setphy(struct net_device *dev)
343 struct bf537mac_local *lp = netdev_priv(dev);
345 /* Program PHY registers */
346 pr_debug("start setting up phy\n");
349 raw_write_phy_reg(lp->PhyAddr, PHYREG_MODECTL, 0x8000);
351 /* wait half a second */
354 phydat = read_phy_reg(lp->PhyAddr, PHYREG_MODECTL);
356 /* advertise flow control supported */
357 phydat = read_phy_reg(lp->PhyAddr, PHYREG_ANAR);
359 write_phy_reg(lp->PhyAddr, PHYREG_ANAR, phydat);
363 phydat |= 0x1000; /* enable auto negotiation */
366 phydat |= (1 << 8); /* full duplex */
368 phydat &= (~(1 << 8)); /* half duplex */
371 phydat |= (1 << 13); /* 100 Mbps */
373 phydat &= (~(1 << 13)); /* 10 Mbps */
377 phydat |= (1 << 14); /* enable TX->RX loopback */
379 write_phy_reg(lp->PhyAddr, PHYREG_MODECTL, phydat);
382 phydat = read_phy_reg(lp->PhyAddr, PHYREG_MODECTL);
383 /* check for SMSC PHY */
384 if ((read_phy_reg(lp->PhyAddr, PHYREG_PHYID1) == 0x7) &&
385 ((read_phy_reg(lp->PhyAddr, PHYREG_PHYID2) & 0xfff0) == 0xC0A0)) {
387 * we have SMSC PHY so reqest interrupt
388 * on link down condition
391 /* enable interrupts */
392 write_phy_reg(lp->PhyAddr, 30, 0x0ff);
396 /**************************************************************************/
397 void setup_system_regs(struct net_device *dev)
400 unsigned short sysctl, phydat;
402 struct bf537mac_local *lp = netdev_priv(dev);
405 phyaddr = lp->PhyAddr;
407 /* Enable PHY output */
408 if (!(bfin_read_VR_CTL() & PHYCLKOE))
409 bfin_write_VR_CTL(bfin_read_VR_CTL() | PHYCLKOE);
412 sysctl = SET_MDCDIV(24);
413 /* Odd word alignment for Receive Frame DMA word */
414 /* Configure checksum support and rcve frame word alignment */
415 #if defined(BFIN_MAC_CSUM_OFFLOAD)
416 sysctl |= RXDWA | RXCKS;
420 bfin_write_EMAC_SYSCTL(sysctl);
421 /* auto negotiation on */
424 phydat = PHY_ANEG_EN | PHY_DUPLEX | PHY_SPD_SET;
425 write_phy_reg(phyaddr, PHYREG_MODECTL, phydat);
427 /* test if full duplex supported */
430 phydat = read_phy_reg(phyaddr, PHYREG_MODESTAT);
432 printk(KERN_NOTICE DRV_NAME ": Link is down\n");
433 printk(KERN_NOTICE DRV_NAME
434 "please check your network connection\n");
438 } while (!(phydat & 0x0004));
440 phydat = read_phy_reg(phyaddr, PHYREG_ANLPAR);
442 if ((phydat & 0x0100) || (phydat & 0x0040)) {
446 printk(KERN_INFO DRV_NAME
447 ": Network is set to half duplex\n");
450 #if defined(CONFIG_BFIN_MAC_RMII)
451 opmode |= RMII; /* For Now only 100MBit are supported */
454 bfin_write_EMAC_OPMODE(opmode);
456 bfin_write_EMAC_MMC_CTL(RSTC | CROLL);
458 /* Initialize the TX DMA channel registers */
459 bfin_write_DMA2_X_COUNT(0);
460 bfin_write_DMA2_X_MODIFY(4);
461 bfin_write_DMA2_Y_COUNT(0);
462 bfin_write_DMA2_Y_MODIFY(0);
464 /* Initialize the RX DMA channel registers */
465 bfin_write_DMA1_X_COUNT(0);
466 bfin_write_DMA1_X_MODIFY(4);
467 bfin_write_DMA1_Y_COUNT(0);
468 bfin_write_DMA1_Y_MODIFY(0);
471 void setup_mac_addr(u8 * mac_addr)
473 u32 addr_low = le32_to_cpu(*(__le32 *) & mac_addr[0]);
474 u16 addr_hi = le16_to_cpu(*(__le16 *) & mac_addr[4]);
476 /* this depends on a little-endian machine */
477 bfin_write_EMAC_ADDRLO(addr_low);
478 bfin_write_EMAC_ADDRHI(addr_hi);
481 static void adjust_tx_list(void)
483 int timeout_cnt = MAX_TIMEOUT_CNT;
485 if (tx_list_head->status.status_word != 0
486 && current_tx_ptr != tx_list_head) {
487 goto adjust_head; /* released something, just return; */
491 * if nothing released, check wait condition
492 * current's next can not be the head,
493 * otherwise the dma will not stop as we want
495 if (current_tx_ptr->next->next == tx_list_head) {
496 while (tx_list_head->status.status_word == 0) {
498 if (tx_list_head->status.status_word != 0
499 || !(bfin_read_DMA2_IRQ_STATUS() & 0x08)) {
502 if (timeout_cnt-- < 0) {
503 printk(KERN_ERR DRV_NAME
504 ": wait for adjust tx list head timeout\n");
508 if (tx_list_head->status.status_word != 0) {
517 tx_list_head->desc_a.config &= ~DMAEN;
518 tx_list_head->status.status_word = 0;
519 if (tx_list_head->skb) {
520 dev_kfree_skb(tx_list_head->skb);
521 tx_list_head->skb = NULL;
523 printk(KERN_ERR DRV_NAME
524 ": no sk_buff in a transmitted frame!\n");
526 tx_list_head = tx_list_head->next;
527 } while (tx_list_head->status.status_word != 0
528 && current_tx_ptr != tx_list_head);
533 static int bf537mac_hard_start_xmit(struct sk_buff *skb,
534 struct net_device *dev)
536 struct bf537mac_local *lp = netdev_priv(dev);
539 current_tx_ptr->skb = skb;
542 * Is skb->data always 16-bit aligned?
543 * Do we need to memcpy((char *)(tail->packet + 2), skb->data, len)?
545 if ((((unsigned int)(skb->data)) & 0x02) == 2) {
546 /* move skb->data to current_tx_ptr payload */
547 data = (unsigned int)(skb->data) - 2;
548 *((unsigned short *)data) = (unsigned short)(skb->len);
549 current_tx_ptr->desc_a.start_addr = (unsigned long)data;
550 /* this is important! */
551 blackfin_dcache_flush_range(data, (data + (skb->len)) + 2);
554 *((unsigned short *)(current_tx_ptr->packet)) =
555 (unsigned short)(skb->len);
556 memcpy((char *)(current_tx_ptr->packet + 2), skb->data,
558 current_tx_ptr->desc_a.start_addr =
559 (unsigned long)current_tx_ptr->packet;
560 if (current_tx_ptr->status.status_word != 0)
561 current_tx_ptr->status.status_word = 0;
562 blackfin_dcache_flush_range((unsigned int)current_tx_ptr->
564 (unsigned int)(current_tx_ptr->
569 /* enable this packet's dma */
570 current_tx_ptr->desc_a.config |= DMAEN;
572 /* tx dma is running, just return */
573 if (bfin_read_DMA2_IRQ_STATUS() & 0x08)
576 /* tx dma is not running */
577 bfin_write_DMA2_NEXT_DESC_PTR(&(current_tx_ptr->desc_a));
578 /* dma enabled, read from memory, size is 6 */
579 bfin_write_DMA2_CONFIG(current_tx_ptr->desc_a.config);
580 /* Turn on the EMAC tx */
581 bfin_write_EMAC_OPMODE(bfin_read_EMAC_OPMODE() | TE);
585 current_tx_ptr = current_tx_ptr->next;
586 dev->trans_start = jiffies;
587 lp->stats.tx_packets++;
588 lp->stats.tx_bytes += (skb->len);
592 static void bf537mac_rx(struct net_device *dev)
594 struct sk_buff *skb, *new_skb;
595 struct bf537mac_local *lp = netdev_priv(dev);
598 /* allocate a new skb for next time receive */
599 skb = current_rx_ptr->skb;
600 new_skb = dev_alloc_skb(PKT_BUF_SZ + 2);
602 printk(KERN_NOTICE DRV_NAME
603 ": rx: low on mem - packet dropped\n");
604 lp->stats.rx_dropped++;
607 /* reserve 2 bytes for RXDWA padding */
608 skb_reserve(new_skb, 2);
609 current_rx_ptr->skb = new_skb;
610 current_rx_ptr->desc_a.start_addr = (unsigned long)new_skb->data - 2;
612 len = (unsigned short)((current_rx_ptr->status.status_word) & RX_FRLEN);
614 blackfin_dcache_invalidate_range((unsigned long)skb->head,
615 (unsigned long)skb->tail);
617 dev->last_rx = jiffies;
619 skb->protocol = eth_type_trans(skb, dev);
620 #if defined(BFIN_MAC_CSUM_OFFLOAD)
621 skb->csum = current_rx_ptr->status.ip_payload_csum;
622 skb->ip_summed = CHECKSUM_PARTIAL;
626 lp->stats.rx_packets++;
627 lp->stats.rx_bytes += len;
628 current_rx_ptr->status.status_word = 0x00000000;
629 current_rx_ptr = current_rx_ptr->next;
635 /* interrupt routine to handle rx and error signal */
636 static irqreturn_t bf537mac_interrupt(int irq, void *dev_id)
638 struct net_device *dev = dev_id;
642 if (current_rx_ptr->status.status_word == 0) {
643 /* no more new packet received */
645 if (current_rx_ptr->next->status.status_word != 0) {
646 current_rx_ptr = current_rx_ptr->next;
650 bfin_write_DMA1_IRQ_STATUS(bfin_read_DMA1_IRQ_STATUS() |
661 #ifdef CONFIG_NET_POLL_CONTROLLER
662 static void bf537mac_poll(struct net_device *dev)
664 disable_irq(IRQ_MAC_RX);
665 bf537mac_interrupt(IRQ_MAC_RX, dev);
666 enable_irq(IRQ_MAC_RX);
668 #endif /* CONFIG_NET_POLL_CONTROLLER */
670 static void bf537mac_reset(void)
674 opmode = bfin_read_EMAC_OPMODE();
677 /* Turn off the EMAC */
678 bfin_write_EMAC_OPMODE(opmode);
682 * Enable Interrupts, Receive, and Transmit
684 static int bf537mac_enable(struct net_device *dev)
688 pr_debug("%s: %s\n", dev->name, __FUNCTION__);
691 bfin_write_DMA1_NEXT_DESC_PTR(&(rx_list_head->desc_a));
692 bfin_write_DMA1_CONFIG(rx_list_head->desc_a.config);
697 /* We enable only RX here */
698 /* ASTP : Enable Automatic Pad Stripping
699 PR : Promiscuous Mode for test
700 PSF : Receive frames with total length less than 64 bytes.
701 FDMODE : Full Duplex Mode
702 LB : Internal Loopback for test
703 RE : Receiver Enable */
704 opmode = bfin_read_EMAC_OPMODE();
708 opmode |= DRO | DC | PSF;
711 #if defined(CONFIG_BFIN_MAC_RMII)
712 opmode |= RMII; /* For Now only 100MBit are supported */
713 #ifdef CONFIG_BF_REV_0_2
717 /* Turn on the EMAC rx */
718 bfin_write_EMAC_OPMODE(opmode);
723 /* Our watchdog timed out. Called by the networking layer */
724 static void bf537mac_timeout(struct net_device *dev)
726 pr_debug("%s: %s\n", dev->name, __FUNCTION__);
731 tx_list_tail = tx_list_head->next;
733 bf537mac_enable(dev);
735 /* We can accept TX packets again */
736 dev->trans_start = jiffies;
737 netif_wake_queue(dev);
741 * Get the current statistics.
742 * This may be called with the card open or closed.
744 static struct net_device_stats *bf537mac_query_statistics(struct net_device
747 struct bf537mac_local *lp = netdev_priv(dev);
749 pr_debug("%s: %s\n", dev->name, __FUNCTION__);
755 * This routine will, depending on the values passed to it,
756 * either make it accept multicast packets, go into
757 * promiscuous mode (for TCPDUMP and cousins) or accept
758 * a select set of multicast packets
760 static void bf537mac_set_multicast_list(struct net_device *dev)
764 if (dev->flags & IFF_PROMISC) {
765 printk(KERN_INFO "%s: set to promisc mode\n", dev->name);
766 sysctl = bfin_read_EMAC_OPMODE();
768 bfin_write_EMAC_OPMODE(sysctl);
769 } else if (dev->flags & IFF_ALLMULTI || dev->mc_count) {
770 /* accept all multicast */
771 sysctl = bfin_read_EMAC_OPMODE();
773 bfin_write_EMAC_OPMODE(sysctl);
775 /* clear promisc or multicast mode */
776 sysctl = bfin_read_EMAC_OPMODE();
777 sysctl &= ~(RAF | PAM);
778 bfin_write_EMAC_OPMODE(sysctl);
783 * this puts the device in an inactive state
785 static void bf537mac_shutdown(struct net_device *dev)
787 /* Turn off the EMAC */
788 bfin_write_EMAC_OPMODE(0x00000000);
789 /* Turn off the EMAC RX DMA */
790 bfin_write_DMA1_CONFIG(0x0000);
791 bfin_write_DMA2_CONFIG(0x0000);
795 * Open and Initialize the interface
797 * Set up everything, reset the card, etc..
799 static int bf537mac_open(struct net_device *dev)
801 pr_debug("%s: %s\n", dev->name, __FUNCTION__);
804 * Check that the address is valid. If its not, refuse
805 * to bring the device up. The user must specify an
806 * address using ifconfig eth0 hw ether xx:xx:xx:xx:xx:xx
808 if (!is_valid_ether_addr(dev->dev_addr)) {
809 printk(KERN_WARNING DRV_NAME ": no valid ethernet hw addr\n");
813 /* initial rx and tx list */
816 bf537mac_setphy(dev);
817 setup_system_regs(dev);
819 bf537mac_enable(dev);
821 pr_debug("hardware init finished\n");
822 netif_start_queue(dev);
823 netif_carrier_on(dev);
830 * this makes the board clean up everything that it can
831 * and not talk to the outside world. Caused by
832 * an 'ifconfig ethX down'
834 static int bf537mac_close(struct net_device *dev)
836 pr_debug("%s: %s\n", dev->name, __FUNCTION__);
838 netif_stop_queue(dev);
839 netif_carrier_off(dev);
841 /* clear everything */
842 bf537mac_shutdown(dev);
844 /* free the rx/tx buffers */
850 static int __init bf537mac_probe(struct net_device *dev)
852 struct bf537mac_local *lp = netdev_priv(dev);
855 /* Grab the MAC address in the MAC */
856 *(__le32 *) (&(dev->dev_addr[0])) = cpu_to_le32(bfin_read_EMAC_ADDRLO());
857 *(__le16 *) (&(dev->dev_addr[4])) = cpu_to_le16((u16) bfin_read_EMAC_ADDRHI());
860 /*todo: how to proble? which is revision_register */
861 bfin_write_EMAC_ADDRLO(0x12345678);
862 if (bfin_read_EMAC_ADDRLO() != 0x12345678) {
863 pr_debug("can't detect bf537 mac!\n");
868 /* set the GPIO pins to Ethernet mode */
869 retval = setup_pin_mux(1);
874 /*Is it valid? (Did bootloader initialize it?) */
875 if (!is_valid_ether_addr(dev->dev_addr)) {
876 /* Grab the MAC from the board somehow - this is done in the
877 arch/blackfin/mach-bf537/boards/eth_mac.c */
878 get_bf537_ether_addr(dev->dev_addr);
881 /* If still not valid, get a random one */
882 if (!is_valid_ether_addr(dev->dev_addr)) {
883 random_ether_addr(dev->dev_addr);
886 setup_mac_addr(dev->dev_addr);
888 /* Fill in the fields of the device structure with ethernet values. */
891 dev->open = bf537mac_open;
892 dev->stop = bf537mac_close;
893 dev->hard_start_xmit = bf537mac_hard_start_xmit;
894 dev->tx_timeout = bf537mac_timeout;
895 dev->get_stats = bf537mac_query_statistics;
896 dev->set_multicast_list = bf537mac_set_multicast_list;
897 #ifdef CONFIG_NET_POLL_CONTROLLER
898 dev->poll_controller = bf537mac_poll;
901 /* fill in some of the fields */
908 spin_lock_init(&lp->lock);
910 /* now, enable interrupts */
911 /* register irq handler */
913 (IRQ_MAC_RX, bf537mac_interrupt, IRQF_DISABLED | IRQF_SHARED,
914 "BFIN537_MAC_RX", dev)) {
915 printk(KERN_WARNING DRV_NAME
916 ": Unable to attach BlackFin MAC RX interrupt\n");
920 /* Enable PHY output early */
921 if (!(bfin_read_VR_CTL() & PHYCLKOE))
922 bfin_write_VR_CTL(bfin_read_VR_CTL() | PHYCLKOE);
924 retval = register_netdev(dev);
926 /* now, print out the card info, in a short format.. */
927 printk(KERN_INFO "%s: Version %s, %s\n",
928 DRV_NAME, DRV_VERSION, DRV_DESC);
935 static int bfin_mac_probe(struct platform_device *pdev)
937 struct net_device *ndev;
939 ndev = alloc_etherdev(sizeof(struct bf537mac_local));
941 printk(KERN_WARNING DRV_NAME ": could not allocate device\n");
945 SET_MODULE_OWNER(ndev);
946 SET_NETDEV_DEV(ndev, &pdev->dev);
948 platform_set_drvdata(pdev, ndev);
950 if (bf537mac_probe(ndev) != 0) {
951 platform_set_drvdata(pdev, NULL);
953 printk(KERN_WARNING DRV_NAME ": not found\n");
960 static int bfin_mac_remove(struct platform_device *pdev)
962 struct net_device *ndev = platform_get_drvdata(pdev);
964 platform_set_drvdata(pdev, NULL);
966 unregister_netdev(ndev);
968 free_irq(IRQ_MAC_RX, ndev);
977 static int bfin_mac_suspend(struct platform_device *pdev, pm_message_t state)
982 static int bfin_mac_resume(struct platform_device *pdev)
987 static struct platform_driver bfin_mac_driver = {
988 .probe = bfin_mac_probe,
989 .remove = bfin_mac_remove,
990 .resume = bfin_mac_resume,
991 .suspend = bfin_mac_suspend,
997 static int __init bfin_mac_init(void)
999 return platform_driver_register(&bfin_mac_driver);
1002 module_init(bfin_mac_init);
1004 static void __exit bfin_mac_cleanup(void)
1006 platform_driver_unregister(&bfin_mac_driver);
1009 module_exit(bfin_mac_cleanup);