1
2
3
4
5
6
7
8
9#define MAXFRM_MASK 0x0000ffff
10
11#include <common.h>
12#include <phy.h>
13#include <asm/types.h>
14#include <asm/io.h>
15#include <fsl_memac.h>
16
17#include "fm.h"
18
19static void memac_init_mac(struct fsl_enet_mac *mac)
20{
21 struct memac *regs = mac->base;
22
23
24 out_be32(®s->imask, IMASK_MASK_ALL);
25
26
27 out_be32(®s->ievent, IEVENT_CLEAR_ALL);
28
29
30 out_be32(®s->maxfrm, mac->max_rx_len & MAXFRM_MASK);
31
32
33 out_be32(®s->hashtable_ctrl, 0);
34}
35
36static void memac_enable_mac(struct fsl_enet_mac *mac)
37{
38 struct memac *regs = mac->base;
39
40 setbits_be32(®s->command_config,
41 MEMAC_CMD_CFG_RXTX_EN | MEMAC_CMD_CFG_NO_LEN_CHK);
42}
43
44static void memac_disable_mac(struct fsl_enet_mac *mac)
45{
46 struct memac *regs = mac->base;
47
48 clrbits_be32(®s->command_config, MEMAC_CMD_CFG_RXTX_EN);
49}
50
51static void memac_set_mac_addr(struct fsl_enet_mac *mac, u8 *mac_addr)
52{
53 struct memac *regs = mac->base;
54 u32 mac_addr0, mac_addr1;
55
56
57
58
59
60 mac_addr0 = (mac_addr[3] << 24) | (mac_addr[2] << 16) | \
61 (mac_addr[1] << 8) | (mac_addr[0]);
62 out_be32(®s->mac_addr_0, mac_addr0);
63
64 mac_addr1 = ((mac_addr[5] << 8) | mac_addr[4]) & 0x0000ffff;
65 out_be32(®s->mac_addr_1, mac_addr1);
66}
67
68static void memac_set_interface_mode(struct fsl_enet_mac *mac,
69 phy_interface_t type, int speed)
70{
71
72
73 struct memac *regs = mac->base;
74 u32 if_mode, if_status;
75
76
77 if_mode = in_be32(®s->if_mode);
78 if_status = in_be32(®s->if_status);
79
80
81 switch (type) {
82 case PHY_INTERFACE_MODE_GMII:
83 if_mode &= ~IF_MODE_MASK;
84 if_mode |= IF_MODE_GMII;
85 break;
86 case PHY_INTERFACE_MODE_RGMII:
87 if_mode |= (IF_MODE_GMII | IF_MODE_RG);
88 break;
89 case PHY_INTERFACE_MODE_RMII:
90 if_mode |= (IF_MODE_GMII | IF_MODE_RM);
91 break;
92 case PHY_INTERFACE_MODE_SGMII:
93 case PHY_INTERFACE_MODE_QSGMII:
94 if_mode &= ~IF_MODE_MASK;
95 if_mode |= (IF_MODE_GMII);
96 break;
97 case PHY_INTERFACE_MODE_XGMII:
98 if_mode &= ~IF_MODE_MASK;
99 if_mode |= IF_MODE_XGMII;
100 break;
101 default:
102 break;
103 }
104
105 if (type != PHY_INTERFACE_MODE_XGMII)
106 if_mode |= IF_MODE_EN_AUTO;
107
108 if (type == PHY_INTERFACE_MODE_RGMII) {
109 if_mode &= ~IF_MODE_EN_AUTO;
110 if_mode &= ~IF_MODE_SETSP_MASK;
111 switch (speed) {
112 case SPEED_1000:
113 if_mode |= IF_MODE_SETSP_1000M;
114 break;
115 case SPEED_100:
116 if_mode |= IF_MODE_SETSP_100M;
117 break;
118 case SPEED_10:
119 if_mode |= IF_MODE_SETSP_10M;
120 default:
121 break;
122 }
123 }
124
125 debug(" %s, if_mode = %x\n", __func__, if_mode);
126 debug(" %s, if_status = %x\n", __func__, if_status);
127 out_be32(®s->if_mode, if_mode);
128 return;
129}
130
131void init_memac(struct fsl_enet_mac *mac, void *base,
132 void *phyregs, int max_rx_len)
133{
134 mac->base = base;
135 mac->phyregs = phyregs;
136 mac->max_rx_len = max_rx_len;
137 mac->init_mac = memac_init_mac;
138 mac->enable_mac = memac_enable_mac;
139 mac->disable_mac = memac_disable_mac;
140 mac->set_mac_addr = memac_set_mac_addr;
141 mac->set_if_mode = memac_set_interface_mode;
142}
143