]>
git.ipfire.org Git - people/ms/u-boot.git/blob - drivers/net/fm/memac.c
2 * Copyright 2012 Freescale Semiconductor, Inc.
3 * Roy Zang <tie-fei.zang@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_memac.h>
33 static void memac_init_mac(struct fsl_enet_mac
*mac
)
35 struct memac
*regs
= mac
->base
;
37 /* mask all interrupt */
38 out_be32(®s
->imask
, IMASK_MASK_ALL
);
40 /* clear all events */
41 out_be32(®s
->ievent
, IEVENT_CLEAR_ALL
);
43 /* set the max receive length */
44 out_be32(®s
->maxfrm
, mac
->max_rx_len
& MAXFRM_MASK
);
46 /* multicast frame reception for the hash entry disable */
47 out_be32(®s
->hashtable_ctrl
, 0);
50 static void memac_enable_mac(struct fsl_enet_mac
*mac
)
52 struct memac
*regs
= mac
->base
;
54 setbits_be32(®s
->command_config
, MEMAC_CMD_CFG_RXTX_EN
);
57 static void memac_disable_mac(struct fsl_enet_mac
*mac
)
59 struct memac
*regs
= mac
->base
;
61 clrbits_be32(®s
->command_config
, MEMAC_CMD_CFG_RXTX_EN
);
64 static void memac_set_mac_addr(struct fsl_enet_mac
*mac
, u8
*mac_addr
)
66 struct memac
*regs
= mac
->base
;
67 u32 mac_addr0
, mac_addr1
;
70 * if a station address of 0x12345678ABCD, perform a write to
71 * MAC_ADDR0 of 0x78563412, MAC_ADDR1 of 0x0000CDAB
73 mac_addr0
= (mac_addr
[3] << 24) | (mac_addr
[2] << 16) | \
74 (mac_addr
[1] << 8) | (mac_addr
[0]);
75 out_be32(®s
->mac_addr_0
, mac_addr0
);
77 mac_addr1
= ((mac_addr
[5] << 8) | mac_addr
[4]) & 0x0000ffff;
78 out_be32(®s
->mac_addr_1
, mac_addr1
);
81 static void memac_set_interface_mode(struct fsl_enet_mac
*mac
,
82 phy_interface_t type
, int speed
)
84 /* Roy need more work here */
86 struct memac
*regs
= mac
->base
;
87 u32 if_mode
, if_status
;
89 /* clear all bits relative with interface mode */
90 if_mode
= in_be32(®s
->if_mode
);
91 if_status
= in_be32(®s
->if_status
);
93 /* set interface mode */
95 case PHY_INTERFACE_MODE_GMII
:
96 if_mode
&= ~IF_MODE_MASK
;
97 if_mode
|= IF_MODE_GMII
;
99 case PHY_INTERFACE_MODE_RGMII
:
100 if_mode
|= (IF_MODE_GMII
| IF_MODE_RG
);
102 case PHY_INTERFACE_MODE_RMII
:
103 if_mode
|= (IF_MODE_GMII
| IF_MODE_RM
);
105 case PHY_INTERFACE_MODE_SGMII
:
106 if_mode
&= ~IF_MODE_MASK
;
107 if_mode
|= (IF_MODE_GMII
);
112 /* Enable automatic speed selection */
113 if_mode
|= IF_MODE_EN_AUTO
;
115 if (type
== PHY_INTERFACE_MODE_RGMII
) {
116 if_mode
&= ~IF_MODE_EN_AUTO
;
117 if_mode
&= ~IF_MODE_SETSP_MASK
;
120 if_mode
|= IF_MODE_SETSP_1000M
;
123 if_mode
|= IF_MODE_SETSP_100M
;
126 if_mode
|= IF_MODE_SETSP_10M
;
132 debug(" %s, if_mode = %x\n", __func__
, if_mode
);
133 debug(" %s, if_status = %x\n", __func__
, if_status
);
134 out_be32(®s
->if_mode
, if_mode
);
138 void init_memac(struct fsl_enet_mac
*mac
, void *base
,
139 void *phyregs
, int max_rx_len
)
142 mac
->phyregs
= phyregs
;
143 mac
->max_rx_len
= max_rx_len
;
144 mac
->init_mac
= memac_init_mac
;
145 mac
->enable_mac
= memac_enable_mac
;
146 mac
->disable_mac
= memac_disable_mac
;
147 mac
->set_mac_addr
= memac_set_mac_addr
;
148 mac
->set_if_mode
= memac_set_interface_mode
;