xref: /openbmc/u-boot/board/renesas/ecovec/ecovec.c (revision d0201692)
1 /*
2  * Copyright (C) 2009, 2011 Renesas Solutions Corp.
3  * Copyright (C) 2009 Kuninori Morimoto <morimoto.kuninori@renesas.com>
4  * Copyright (C) 2011 Nobuhiro Iwamatsu <nobuhiro.iwamatsu.yj@renesas.com>
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as
8  * published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
19  * MA 02111-1307 USA
20  */
21 
22 #include <common.h>
23 #include <command.h>
24 #include <asm/io.h>
25 #include <asm/processor.h>
26 #include <i2c.h>
27 #include <netdev.h>
28 
29 /* USB power management register */
30 #define UPONCR0 0xA40501D4
31 
32 int checkboard(void)
33 {
34 	puts("BOARD: ecovec\n");
35 	return 0;
36 }
37 
38 int dram_init(void)
39 {
40 	DECLARE_GLOBAL_DATA_PTR;
41 
42 	gd->bd->bi_memstart = CONFIG_SYS_SDRAM_BASE;
43 	gd->bd->bi_memsize = CONFIG_SYS_SDRAM_SIZE;
44 	printf("DRAM: %dMB\n", CONFIG_SYS_SDRAM_SIZE / (1024 * 1024));
45 	return 0;
46 }
47 
48 static void debug_led(u8 led)
49 {
50 	/* PDGR[0-4] is debug LED */
51 	outb((inb(PGDR) & ~0x0F) | (led & 0x0F), PGDR);
52 }
53 
54 int board_late_init(void)
55 {
56 	u8 mac[6];
57 	char env_mac[17];
58 	int i;
59 
60 	udelay(1000);
61 
62 	/* SH-Eth (PLCR, PNCR, PXCR, PSELx )*/
63 	outw(inw(PLCR) & ~0xFFF0, PLCR);
64 	outw(inw(PNCR) & ~0x000F, PNCR);
65 	outw(inw(PXCR) & ~0x0FC0, PXCR);
66 	outw((inw(PSELB) & ~0x030F) | 0x020A, PSELB);
67 	outw((inw(PSELC) & ~0x0307) | 0x0207, PSELC);
68 	outw((inw(PSELE) & ~0x00c0) | 0x0080, PSELE);
69 
70 	debug_led(1 << 3);
71 
72 	outl(inl(MSTPCR2) & ~0x10000000, MSTPCR2);
73 
74 	i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
75 	i2c_set_bus_num(CONFIG_SYS_I2C_MODULE); /* Use I2C 1 */
76 
77 	/* Read MAC address */
78 	i2c_read(0x50, 0x10, 0, mac, 6);
79 
80 	/* Set MAC address */
81 	sprintf(env_mac, "%02X:%02X:%02X:%02X:%02X:%02X",
82 		mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
83 	setenv("ethaddr", env_mac);
84 
85 	debug_led(0x0F);
86 
87 	return 0;
88 }
89 
90 int board_init(void)
91 {
92 
93 	/* LED (PTG) */
94 	outw((inw(PGCR) & ~0xFF) | 0x66, PGCR);
95 	outw((inw(HIZCRA) & ~0x02), HIZCRA);
96 
97 	debug_led(1 << 0);
98 
99 	/* SCIF0 (PTF, PTM) */
100 	outw(inw(PFCR) & ~0x30, PFCR);
101 	outw(inw(PMCR) & ~0x0C, PMCR);
102 	outw((inw(PSELA) & ~0x40) | 0x40, PSELA);
103 
104 	debug_led(1 << 1);
105 
106 	/* RMII (PTA) */
107 	outw((inw(PACR) & ~0x0C) | 0x04, PACR);
108 	outb((inb(PADR) & ~0x02) | 0x02, PADR);
109 
110 	debug_led(1 << 2);
111 
112 	/* USB host */
113 	outw((inw(PBCR) & ~0x300) | 0x100, PBCR);
114 	outb((inb(PBDR) & ~0x10) | 0x10, PBDR);
115 	outl(inl(MSTPCR2) & 0x100000, MSTPCR2);
116 	outw(0x0600, UPONCR0);
117 
118 	debug_led(1 << 3);
119 
120 	/* debug switch */
121 	outw((inw(PVCR) & ~0x03) | 0x02 , PVCR);
122 
123 	return 0;
124 }
125