2 * Copyright 2009-2011 Freescale Semiconductor, Inc.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of
7 * the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 #include <asm/types.h>
23 #include <asm/fsl_enet.h>
24 #include <asm/fsl_dtsec.h>
30 #define RCTRL_INIT (RCTRL_GRS | RCTRL_UPROM)
31 #define TCTRL_INIT TCTRL_GTS
32 #define MACCFG1_INIT MACCFG1_SOFT_RST
34 #define MACCFG2_INIT (MACCFG2_PRE_LEN(0x7) | MACCFG2_LEN_CHECK | \
35 MACCFG2_PAD_CRC | MACCFG2_FULL_DUPLEX | \
36 MACCFG2_IF_MODE_NIBBLE)
38 /* MAXFRM - maximum frame length register */
39 #define MAXFRM_MASK 0x00003fff
41 static void dtsec_init_mac(struct fsl_enet_mac *mac)
43 struct dtsec *regs = mac->base;
46 out_be32(®s->maccfg1, MACCFG1_SOFT_RST);
49 /* clear soft reset, Rx/Tx MAC disable */
50 out_be32(®s->maccfg1, 0);
52 /* graceful stop rx */
53 out_be32(®s->rctrl, RCTRL_INIT);
56 /* graceful stop tx */
57 out_be32(®s->tctrl, TCTRL_INIT);
60 /* disable all interrupts */
61 out_be32(®s->imask, IMASK_MASK_ALL);
63 /* clear all events */
64 out_be32(®s->ievent, IEVENT_CLEAR_ALL);
66 /* set the max Rx length */
67 out_be32(®s->maxfrm, mac->max_rx_len & MAXFRM_MASK);
69 /* set the ecntrl to reset value */
70 out_be32(®s->ecntrl, ECNTRL_DEFAULT);
73 * Rx length check, no strip CRC for Rx, pad and append CRC for Tx,
76 out_be32(®s->maccfg2, MACCFG2_INIT);
79 static void dtsec_enable_mac(struct fsl_enet_mac *mac)
81 struct dtsec *regs = mac->base;
83 /* enable Rx/Tx MAC */
84 setbits_be32(®s->maccfg1, MACCFG1_RXTX_EN);
86 /* clear the graceful Rx stop */
87 clrbits_be32(®s->rctrl, RCTRL_GRS);
89 /* clear the graceful Tx stop */
90 clrbits_be32(®s->tctrl, TCTRL_GTS);
93 static void dtsec_disable_mac(struct fsl_enet_mac *mac)
95 struct dtsec *regs = mac->base;
97 /* graceful Rx stop */
98 setbits_be32(®s->rctrl, RCTRL_GRS);
100 /* graceful Tx stop */
101 setbits_be32(®s->tctrl, TCTRL_GTS);
103 /* disable Rx/Tx MAC */
104 clrbits_be32(®s->maccfg1, MACCFG1_RXTX_EN);
107 static void dtsec_set_mac_addr(struct fsl_enet_mac *mac, u8 *mac_addr)
109 struct dtsec *regs = mac->base;
110 u32 mac_addr1, mac_addr2;
113 * if a station address of 0x12345678ABCD, perform a write to
114 * MACSTNADDR1 of 0xCDAB7856, MACSTNADDR2 of 0x34120000
116 mac_addr1 = (mac_addr[5] << 24) | (mac_addr[4] << 16) | \
117 (mac_addr[3] << 8) | (mac_addr[2]);
118 out_be32(®s->macstnaddr1, mac_addr1);
120 mac_addr2 = ((mac_addr[1] << 24) | (mac_addr[0] << 16)) & 0xffff0000;
121 out_be32(®s->macstnaddr2, mac_addr2);
124 static void dtsec_set_interface_mode(struct fsl_enet_mac *mac,
125 phy_interface_t type, int speed)
127 struct dtsec *regs = mac->base;
130 /* clear all bits relative with interface mode */
131 ecntrl = in_be32(®s->ecntrl);
132 ecntrl &= ~(ECNTRL_TBIM | ECNTRL_GMIIM | ECNTRL_RPM |
133 ECNTRL_R100M | ECNTRL_SGMIIM);
135 maccfg2 = in_be32(®s->maccfg2);
136 maccfg2 &= ~MACCFG2_IF_MODE_MASK;
138 if (speed == SPEED_1000)
139 maccfg2 |= MACCFG2_IF_MODE_BYTE;
141 maccfg2 |= MACCFG2_IF_MODE_NIBBLE;
143 /* set interface mode */
145 case PHY_INTERFACE_MODE_GMII:
146 ecntrl |= ECNTRL_GMIIM;
148 case PHY_INTERFACE_MODE_RGMII:
149 ecntrl |= (ECNTRL_GMIIM | ECNTRL_RPM);
150 if (speed == SPEED_100)
151 ecntrl |= ECNTRL_R100M;
153 case PHY_INTERFACE_MODE_RMII:
154 if (speed == SPEED_100)
155 ecntrl |= ECNTRL_R100M;
157 case PHY_INTERFACE_MODE_SGMII:
158 ecntrl |= (ECNTRL_SGMIIM | ECNTRL_TBIM);
159 if (speed == SPEED_100)
160 ecntrl |= ECNTRL_R100M;
166 out_be32(®s->ecntrl, ecntrl);
167 out_be32(®s->maccfg2, maccfg2);
170 void init_dtsec(struct fsl_enet_mac *mac, void *base,
171 void *phyregs, int max_rx_len)
174 mac->phyregs = phyregs;
175 mac->max_rx_len = max_rx_len;
176 mac->init_mac = dtsec_init_mac;
177 mac->enable_mac = dtsec_enable_mac;
178 mac->disable_mac = dtsec_disable_mac;
179 mac->set_mac_addr = dtsec_set_mac_addr;
180 mac->set_if_mode = dtsec_set_interface_mode;