summaryrefslogtreecommitdiff
path: root/board/scalys/simc-t10xx/eth.c
blob: 2f5c4015d00ddc0a0934339420ece4dac7e8c8b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/*
 * Copyright 2016 Scalys B.V.
 * opensource@scalys.com
 *
 * SPDX-License-Identifier:	GPL-2.0+
 */

#include <common.h>
#include <netdev.h>
#include <asm/immap_85xx.h>
#include <fm_eth.h>
#include <fsl_mdio.h>
#include <malloc.h>
#include <i2c.h>




#include <common.h>
#include <netdev.h>
#include <asm/fsl_serdes.h>
#include <asm/immap_85xx.h>
#include <fm_eth.h>
#include <fsl_mdio.h>
#include <malloc.h>
#include <fsl_dtsec.h>
#include <vsc9953.h>

//#include "../common/fman.h"
//#include "../common/qixis.h"




#include "../../freescale/common/fman.h"

uint8_t sfp_phy_config[][2] = {
	{ 0x1b, 0x90 },
	{ 0x1b, 0x84 },
	{ 0x09, 0x0F },
	{ 0x09, 0x00 },
	{ 0x00, 0x81 },
	{ 0x00, 0x40 },
};

int board_eth_init(bd_t *bis)
{
#ifdef CONFIG_FMAN_ENET
	struct memac_mdio_info memac_mdio_info;
	unsigned int i;
	uint8_t i2c_data;
	int ret;
	int phy_addr = 0;
	
#ifdef CONFIG_VSC9953
	int lane;
	phy_interface_t phy_int;
	struct mii_dev *bus;
	struct ccsr_scfg *scfg;
#endif
	
	uint32_t *gpio2_gpdir = (uint32_t *) 0xffe131000;
	uint32_t *gpio2_gpdat = (uint32_t *) 0xffe131008;
	uint32_t regval;
	
	printf("Initializing Fman\n");

	memac_mdio_info.regs =
		(struct memac_mdio_controller *)CONFIG_SYS_FM1_DTSEC_MDIO_ADDR;
	memac_mdio_info.name = DEFAULT_FM_MDIO_NAME;

	/* Register the real 1G MDIO bus */
	fm_memac_mdio_init(bis, &memac_mdio_info);

	/* Remove reset from Ethernet PHY's 
	 * IFC_PERR_B : GPIO2_15 : eth1_reset
	 * IFC_CS_N2  : GPIO2_11 : eth2_reset */
//	gpio_set_value(2, 0);

	/* Clear outputs to activate reset */
	regval = in_be32(gpio2_gpdat);
	regval &= ~((0x80000000 >> 11 ) | (0x80000000 >> 15));
	out_be32(gpio2_gpdat, regval);
	
	/* Set outputs to output mode */
	regval = in_be32(gpio2_gpdir);
	regval |= ((0x80000000 >> 11 ) | (0x80000000 >> 15));
	out_be32(gpio2_gpdir, regval);
	
	/* Wait for 10 ms to to meet reset timing */
	mdelay(10);
	
	/* Set outputs to de-activate reset */
	regval = in_be32(gpio2_gpdat);
	regval |= ((0x80000000 >> 11 ) | (0x80000000 >> 15));
	out_be32(gpio2_gpdat, regval);


	/* Remove SFP TX_disable */
	i2c_set_bus_num(0);
	i2c_data = 0x3b;
	ret = i2c_write(0x22, 0x0E, 1, &i2c_data, 1);

	mdelay(100);
	
	i2c_set_bus_num(3);
	
	for (phy_addr=0; phy_addr<4; phy_addr++) {
		i2c_data = (1 << phy_addr);
		ret = i2c_write(0x70, 0, 1, &i2c_data, 1);
		if (ret) {
			printf("Error Setting SFP i2c MUX\n");
			break;
		}
		
		for ( i = 0; i < 6; i++) {
			ret = i2c_write(0x56, sfp_phy_config[i][0], 1, &(sfp_phy_config[i][1]), 1);
			if (ret) {
				printf("Error sfp phy(%i:%i):%02x to address %02x\n", phy_addr, i, sfp_phy_config[i][1],sfp_phy_config[i][0]);
				break;
			}
		}
	}
	
	/* Two external pin interfaces
	 * MAC1|MAC2|MAC3 SGMII interface
	 * MAC4|MAC5 EC1|EC2 RGMII interface
	 */
	
	/*
	 * Program on board RGMII, SGMII PHY addresses.
	 */
	for (i = FM1_DTSEC1; i < FM1_DTSEC1 + CONFIG_SYS_NUM_FM1_DTSEC; i++) {
		int idx = i - FM1_DTSEC1;
		switch (fm_info_get_enet_if(i)) {
		case PHY_INTERFACE_MODE_RGMII:
			if (FM1_DTSEC4 == i)
				phy_addr = CONFIG_SYS_RGMII1_PHY_ADDR;
			if (FM1_DTSEC5 == i)
				phy_addr = CONFIG_SYS_RGMII2_PHY_ADDR;
			fm_info_set_phy_address(i, phy_addr);
			break;
		case PHY_INTERFACE_MODE_QSGMII:
			/* TODO, get fixed phy here */
			fm_info_set_phy_address(i, i+2); 
			break;
		case PHY_INTERFACE_MODE_NONE:
			fm_info_set_phy_address(i, 0);
			break;
		case PHY_INTERFACE_MODE_SGMII:
			printf("TODO, add phy interface to SGMII\n");
			fm_info_set_phy_address(i, PHY_INTERFACE_MODE_NONE);
			break;
		default:
			printf("Fman1: DTSEC%u set to unknown interface %i\n",
			       idx + 1, fm_info_get_enet_if(i));
			//fm_info_set_phy_address(i, 0);
			break;
		}
		fm_info_set_mdio(i,
				 miiphy_get_dev_by_name(DEFAULT_FM_MDIO_NAME));
	}
	
#ifdef CONFIG_VSC9953
	for (i = 0; i < VSC9953_MAX_PORTS; i++) {
		int lane = -1;
		int phy_addr = 0;
		int phy_int = PHY_INTERFACE_MODE_NONE;
		switch (i) {
		case 0:
		case 1:
		case 2:
			vsc9953_port_enable(i);
			vsc9953_port_info_set_phy_int(i, PHY_INTERFACE_MODE_SGMII);
			break;
		case 3:
		case 4:
		case 5:
		case 6:
		case 7:
			continue;
		case 8:
			/* FM1@DTSEC1 is connected to SW1@PORT8 */
			vsc9953_port_enable(i);
			break;
		case 9:
			/* Enable L2 On MAC2 using SCFG */
			scfg = (struct ccsr_scfg *) CONFIG_SYS_MPC85xx_SCFG;

			out_be32(&scfg->esgmiiselcr,
				 in_be32(&scfg->esgmiiselcr) |
				 (0x80000000));
			vsc9953_port_enable(i);
			break;
		}
		bus = lane;

	}
#endif
	
	cpu_eth_init(bis);
#endif
	return pci_eth_init(bis);
}