summaryrefslogtreecommitdiff
path: root/multitech/recipes/u-boot/u-boot-2012.10/mtocgd2/u-boot-2012.10-mtocgd2.patch
blob: cfd1225685a05507e679c1bf86605cfdc364ac9e (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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
Index: git/board/atmel/at91sam9x5ek/at91sam9x5ek.c
===================================================================
--- git.orig/board/atmel/at91sam9x5ek/at91sam9x5ek.c	2013-02-11 10:22:37.000000000 -0600
+++ git/board/atmel/at91sam9x5ek/at91sam9x5ek.c	2013-02-11 13:52:43.930054966 -0600
@@ -60,8 +60,6 @@
 	/* Enable CS3 */
 	csa = readl(&matrix->ebicsa);
 	csa |= AT91_MATRIX_EBI_CS3A_SMC_SMARTMEDIA;
-	/* NAND flash on D16 */
-	csa |= AT91_MATRIX_NFD0_ON_D16;
 
 	/* Configure IO drive */
 	csa &= ~AT91_MATRIX_EBI_EBI_IOSR_NORMAL;
@@ -115,8 +113,9 @@
 
 #ifdef CONFIG_MACB
 	if (has_emac0())
+		/* MTOCGD2: use phy addr 5 for ethernet switch */
 		rc = macb_eth_initialize(0,
-			(void *)ATMEL_BASE_EMAC0, 0x00);
+			(void *)ATMEL_BASE_EMAC0, 0x05);
 	if (has_emac1())
 		rc = macb_eth_initialize(1,
 			(void *)ATMEL_BASE_EMAC1, 0x00);
Index: git/include/configs/at91sam9x5ek.h
===================================================================
--- git.orig/include/configs/at91sam9x5ek.h	2013-02-11 10:22:38.000000000 -0600
+++ git/include/configs/at91sam9x5ek.h	2013-02-11 13:56:13.890363608 -0600
@@ -54,6 +54,7 @@
 #define CONFIG_USART_ID		ATMEL_ID_SYS
 
 /* LCD */
+/* MTOCGD2 has no LCD
 #define CONFIG_LCD
 #define LCD_BPP			LCD_COLOR16
 #define LCD_OUTPUT_BPP		24
@@ -65,6 +66,7 @@
 #define CONFIG_ATMEL_HLCD
 #define CONFIG_ATMEL_LCD_RGB565
 #define CONFIG_SYS_CONSOLE_IS_IN_ENV
+*/
 
 #define CONFIG_BOOTDELAY	3
 
@@ -120,12 +122,14 @@
 /* our CLE is AD22 */
 #define CONFIG_SYS_NAND_MASK_CLE	(1 << 22)
 #define CONFIG_SYS_NAND_ENABLE_PIN	AT91_PIN_PD4
-#define CONFIG_SYS_NAND_READY_PIN	AT91_PIN_PD5
+/* MTOCGD2: nand ready is on PC31 */
+#define CONFIG_SYS_NAND_READY_PIN	AT91_PIN_PC31
 
 /* PMECC & PMERRLOC */
 #define CONFIG_ATMEL_NAND_HWECC		1
 #define CONFIG_ATMEL_NAND_HW_PMECC	1
-#define CONFIG_PMECC_CAP		2
+/* MTOCGD2: 4-bit PMECC */
+#define CONFIG_PMECC_CAP		4
 #define CONFIG_PMECC_SECTOR_SIZE	512
 #define CONFIG_PMECC_INDEX_TABLE_OFFSET	0x8000
 
@@ -140,9 +144,14 @@
 
 /* Ethernet */
 #define CONFIG_MACB
-#define CONFIG_RMII
+/* MTOCGD2 is MII */
+#undef CONFIG_RMII
 #define CONFIG_NET_RETRY_COUNT		20
-#define CONFIG_MACB_SEARCH_PHY
+/* MTOCGD2: MAC is connected to fixed-speed PHY on ethernet switch */
+#undef CONFIG_MACB_SEARCH_PHY
+#define CONFIG_FIXED_PHY   1
+/* enable MII command */
+#define CONFIG_CMD_MII 1
 
 #define CONFIG_SYS_LOAD_ADDR		0x22000000	/* load address */
 
@@ -155,9 +164,8 @@
 #define CONFIG_ENV_OFFSET		0xc0000
 #define CONFIG_ENV_OFFSET_REDUND	0x100000
 #define CONFIG_ENV_SIZE		0x20000		/* 1 sector = 128 kB */
-#define CONFIG_BOOTCOMMAND	"nand read " \
-				"0x22000000 0x200000 0x300000; " \
-				"bootm 0x22000000"
+/* MTOCGD2: read from env variables for boot */
+#define CONFIG_BOOTCOMMAND "nboot.jffs2 ${loadaddr} 0 ${kernel_addr}; bootm ${loadaddr}"
 #else
 #ifdef CONFIG_SYS_USE_SPIFLASH
 /* bootstrap + u-boot + env + linux in spi flash */
@@ -172,11 +180,8 @@
 #endif
 #endif
 
-#define CONFIG_BOOTARGS		"mem=128M console=ttyS0,115200 " \
-				"mtdparts=atmel_nand:" \
-				"8M(bootstrap/uboot/kernel)ro,-(rootfs) " \
-				"root=/dev/mtdblock1 rw " \
-				"rootfstype=ubifs ubi.mtd=1 root=ubi0:rootfs"
+/* MTOCGD2: rootfs is jffs2 */
+#define CONFIG_BOOTARGS	"mem=128M console=ttyS0,115200 root=/dev/mtdblock8 ro rootfstype=jffs2"
 
 #define CONFIG_BAUDRATE		115200
 
@@ -199,4 +204,22 @@
 #error CONFIG_USE_IRQ not supported
 #endif
 
+// MTOCGD2 defaults
+#define CONFIG_ENV_OVERWRITE   1 /* Allow Overwrite of serial# & ethaddr */
+#define CONFIG_ETHADDR     00:08:00:87:00:02
+#define CONFIG_IPADDR      192.168.2.1
+#define CONFIG_NETMASK     255.255.255.0
+#define CONFIG_SERVERIP    192.168.2.2
+#define CONFIG_HOSTNAME    AT91SAM9G25
+#define CONFIG_LOADADDR    0x22000000
+
+// MTOCGD2 - enable watchdog
+#define CONFIG_AT91SAM9_WATCHDOG 1
+#define CONFIG_HW_WATCHDOG 1
+
+#define CONFIG_EXTRA_ENV_SETTINGS          \
+   "kernel_addr=0x200000\0"          \
+   ""
+
+
 #endif
Index: git/drivers/net/macb.c
===================================================================
--- git.orig/drivers/net/macb.c	2013-02-11 13:52:43.930054966 -0600
+++ git/drivers/net/macb.c	2013-02-11 13:52:43.930054966 -0600
@@ -86,6 +86,18 @@
 #define TXBUF_WRAP		0x40000000
 #define TXBUF_USED		0x80000000
 
+#define BIT0  (1<<0)
+#define BIT1  (1<<1)
+#define BIT2  (1<<2)
+#define BIT3  (1<<3)
+#define BIT4  (1<<4)
+#define BIT5  (1<<5)
+#define BIT6  (1<<6)
+#define BIT7  (1<<7)
+#define BIT8  (1<<8)
+#define BIT9  (1<<9)
+#define BIT10 (1<<10)
+
 struct macb_device {
 	void			*regs;
 
@@ -105,6 +117,7 @@
 	const struct device	*dev;
 	struct eth_device	netdev;
 	unsigned short		phy_addr;
+	unsigned short		ext_phy_addr;
 };
 #define to_macb(_nd) container_of(_nd, struct macb_device, netdev)
 
@@ -113,6 +126,13 @@
 	unsigned long netctl;
 	unsigned long netstat;
 	unsigned long frame;
+	unsigned short phya;
+
+	// use extended phy addr if set, else use fixed phy addr
+	if (macb->ext_phy_addr != 0)
+		phya = macb->ext_phy_addr;
+	else
+		phya = macb->phy_addr;
 
 	netctl = macb_readl(macb, NCR);
 	netctl |= MACB_BIT(MPE);
@@ -120,7 +140,7 @@
 
 	frame = (MACB_BF(SOF, 1)
 		 | MACB_BF(RW, 1)
-		 | MACB_BF(PHYA, macb->phy_addr)
+		 | MACB_BF(PHYA, phya)
 		 | MACB_BF(REGA, reg)
 		 | MACB_BF(CODE, 2)
 		 | MACB_BF(DATA, value));
@@ -140,6 +160,14 @@
 	unsigned long netctl;
 	unsigned long netstat;
 	unsigned long frame;
+	unsigned short phya;
+
+	// use extended phy addr if set, else use fixed phy addr
+	if (macb->ext_phy_addr != 0)
+		phya = macb->ext_phy_addr;
+	else
+		phya = macb->phy_addr;
+
 
 	netctl = macb_readl(macb, NCR);
 	netctl |= MACB_BIT(MPE);
@@ -147,7 +175,7 @@
 
 	frame = (MACB_BF(SOF, 1)
 		 | MACB_BF(RW, 2)
-		 | MACB_BF(PHYA, macb->phy_addr)
+		 | MACB_BF(PHYA, phya)
 		 | MACB_BF(REGA, reg)
 		 | MACB_BF(CODE, 2));
 	macb_writel(macb, MAN, frame);
@@ -167,15 +195,59 @@
 
 #if defined(CONFIG_CMD_MII)
 
+// Micrel switch support -- converts SMI register address to split reg and phy address fields
+void convert_smi_reg(u8 smi_reg, u8 *reg, u8 *phy_adr)
+{
+	u8 new_phy_adr = 0;
+
+	// lower 5 bits go in reg
+	if (reg)
+		*reg = smi_reg & 0x1f;
+
+	// upper 3 bits go in phy_adr bits 4,3,0
+	if (smi_reg & BIT5)
+		new_phy_adr |= BIT0;
+	if (smi_reg & BIT6)
+		new_phy_adr |= BIT3;
+	if (smi_reg & BIT7)
+		new_phy_adr |= BIT4;
+
+	// bits 1 and 2 are always 1
+	new_phy_adr |= BIT1;
+	new_phy_adr |= BIT2;
+
+	if (phy_adr)
+		*phy_adr = new_phy_adr;
+}
+
 int macb_miiphy_read(const char *devname, u8 phy_adr, u8 reg, u16 *value)
 {
 	struct eth_device *dev = eth_get_dev_by_name(devname);
 	struct macb_device *macb = to_macb(dev);
+	u8 smi_reg = reg;
+	u8 phy_arg = phy_adr;
+	u8 reg_arg = reg;
+
+	if (phy_adr == 0 || phy_adr > 6)
+	    return -1;
+
+	// ---micrel switch support---
+	// use phy_adr 0x06 to designate that reg is an SMI command and we should
+	// construct phy_adr and reg values for accessing the control registers
+	if (phy_adr == 0x06) {
+		convert_smi_reg(smi_reg, &reg_arg, &phy_arg);
+		//debug("reading SMI reg %x, phy_adr %x, reg %x\n",
+		//	smi_reg, phy_arg, reg_arg);
+		debug("reading SMI reg %x\n", smi_reg);
+	}
 
-	if ( macb->phy_addr != phy_adr )
-		return -1;
+	// allow reading any phy addr value (ethernet switch)
+	macb->ext_phy_addr = phy_arg;
+
+	*value = macb_mdio_read(macb, reg_arg);
 
-	*value = macb_mdio_read(macb, reg);
+	// reset to use fixed phy for later calls
+	macb->ext_phy_addr = 0;
 
 	return 0;
 }
@@ -184,11 +256,30 @@
 {
 	struct eth_device *dev = eth_get_dev_by_name(devname);
 	struct macb_device *macb = to_macb(dev);
+	u8 smi_reg = reg;
+	u8 phy_arg = phy_adr;
+	u8 reg_arg = reg;
+
+	if (phy_adr == 0 || phy_adr > 6)
+	    return -1;
+
+	// ---micrel switch support---
+	// use phy_adr 0x06 to designate that reg is an SMI command and we should
+	// construct phy_adr and reg values for accessing the control registers
+	if (phy_adr == 0x06) {
+		convert_smi_reg(smi_reg, &reg_arg, &phy_arg);
+		//debug("writing value %x to SMI reg %x, phy_adr %x, reg %x\n",
+		//	value, smi_reg, phy_arg, reg_arg);
+		debug("writing value %x to SMI reg %x\n", value, smi_reg);
+	}
 
-	if ( macb->phy_addr != phy_adr )
-		return -1;
+	// allow using any phy addr value (ethernet switch)
+	macb->ext_phy_addr = phy_arg;
 
-	macb_mdio_write(macb, reg, value);
+	macb_mdio_write(macb, reg_arg, value);
+
+	// reset to use fixed phy for later calls
+	macb->ext_phy_addr = 0;
 
 	return 0;
 }
@@ -396,6 +487,14 @@
 		return 0;
 	}
 
+#ifdef CONFIG_FIXED_PHY
+	ncfgr = macb_readl(macb, NCFGR);
+	// MTOCGD2: force link to 100, full duplex
+	ncfgr |= MACB_BIT(SPD);
+	ncfgr |= MACB_BIT(FD);
+	macb_writel(macb, NCFGR, ncfgr);
+	return 1;
+#else
 	status = macb_mdio_read(macb, MII_BMSR);
 	if (!(status & BMSR_LSTATUS)) {
 		/* Try to re-negotiate if we don't have link already. */
@@ -428,6 +527,7 @@
 		macb_writel(macb, NCFGR, ncfgr);
 		return 1;
 	}
+#endif /* CONFIG_FIXED_PHY */
 }
 
 static int macb_init(struct eth_device *netdev, bd_t *bd)
@@ -554,6 +654,7 @@
 
 	macb->regs = regs;
 	macb->phy_addr = phy_addr;
+	macb->ext_phy_addr = 0;
 
 	sprintf(netdev->name, "macb%d", id);
 	netdev->init = macb_init;
@@ -583,6 +684,10 @@
 #if defined(CONFIG_CMD_MII)
 	miiphy_register(netdev->name, macb_miiphy_read, macb_miiphy_write);
 #endif
+
+	// MTOCGD2: enable micrel switch
+	macb_miiphy_write("macb0", 6, 1, 0x41);
+
 	return 0;
 }