2 * Copyright 2009-2011 Freescale Semiconductor, Inc.
3 * Dave Liu <daveliu@freescale.com>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of
8 * the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 /* MAXFRM - maximum frame length */
22 #define MAXFRM_MASK 0x0000ffff
26 #include <asm/types.h>
28 #include <asm/fsl_enet.h>
29 #include <asm/fsl_tgec.h>
33 #define TGEC_CMD_CFG_INIT (TGEC_CMD_CFG_NO_LEN_CHK | \
34 TGEC_CMD_CFG_RX_ER_DISC | \
35 TGEC_CMD_CFG_STAT_CLR | \
36 TGEC_CMD_CFG_PAUSE_IGNORE | \
38 #define TGEC_CMD_CFG_FINAL (TGEC_CMD_CFG_NO_LEN_CHK | \
39 TGEC_CMD_CFG_RX_ER_DISC | \
40 TGEC_CMD_CFG_PAUSE_IGNORE | \
43 static void tgec_init_mac(struct fsl_enet_mac *mac)
45 struct tgec *regs = mac->base;
47 /* mask all interrupt */
48 out_be32(®s->imask, IMASK_MASK_ALL);
50 /* clear all events */
51 out_be32(®s->ievent, IEVENT_CLEAR_ALL);
53 /* set the max receive length */
54 out_be32(®s->maxfrm, mac->max_rx_len & MAXFRM_MASK);
57 * 1588 disable, insert second mac disable payload length check
58 * disable, normal operation, any rx error frame is discarded, clear
59 * counters, pause frame ignore, no promiscuous, LAN mode Rx CRC no
60 * strip, Tx CRC append, Rx disable and Tx disable
62 out_be32(®s->command_config, TGEC_CMD_CFG_INIT);
64 out_be32(®s->command_config, TGEC_CMD_CFG_FINAL);
66 /* multicast frame reception for the hash entry disable */
67 out_be32(®s->hashtable_ctrl, 0);
70 static void tgec_enable_mac(struct fsl_enet_mac *mac)
72 struct tgec *regs = mac->base;
74 setbits_be32(®s->command_config, TGEC_CMD_CFG_RXTX_EN);
77 static void tgec_disable_mac(struct fsl_enet_mac *mac)
79 struct tgec *regs = mac->base;
81 clrbits_be32(®s->command_config, TGEC_CMD_CFG_RXTX_EN);
84 static void tgec_set_mac_addr(struct fsl_enet_mac *mac, u8 *mac_addr)
86 struct tgec *regs = mac->base;
87 u32 mac_addr0, mac_addr1;
90 * if a station address of 0x12345678ABCD, perform a write to
91 * MAC_ADDR0 of 0x78563412, MAC_ADDR1 of 0x0000CDAB
93 mac_addr0 = (mac_addr[3] << 24) | (mac_addr[2] << 16) | \
94 (mac_addr[1] << 8) | (mac_addr[0]);
95 out_be32(®s->mac_addr_0, mac_addr0);
97 mac_addr1 = ((mac_addr[5] << 8) | mac_addr[4]) & 0x0000ffff;
98 out_be32(®s->mac_addr_1, mac_addr1);
101 static void tgec_set_interface_mode(struct fsl_enet_mac *mac,
102 phy_interface_t type, int speed)
104 /* nothing right now */
108 void init_tgec(struct fsl_enet_mac *mac, void *base,
109 void *phyregs, int max_rx_len)
112 mac->phyregs = phyregs;
113 mac->max_rx_len = max_rx_len;
114 mac->init_mac = tgec_init_mac;
115 mac->enable_mac = tgec_enable_mac;
116 mac->disable_mac = tgec_disable_mac;
117 mac->set_mac_addr = tgec_set_mac_addr;
118 mac->set_if_mode = tgec_set_interface_mode;