xref: /openbmc/u-boot/board/renesas/ecovec/ecovec.c (revision 34a31bf5)
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 
59 	udelay(1000);
60 
61 	/* SH-Eth (PLCR, PNCR, PXCR, PSELx )*/
62 	outw(inw(PLCR) & ~0xFFF0, PLCR);
63 	outw(inw(PNCR) & ~0x000F, PNCR);
64 	outw(inw(PXCR) & ~0x0FC0, PXCR);
65 	outw((inw(PSELB) & ~0x030F) | 0x020A, PSELB);
66 	outw((inw(PSELC) & ~0x0307) | 0x0207, PSELC);
67 	outw((inw(PSELE) & ~0x00c0) | 0x0080, PSELE);
68 
69 	debug_led(1 << 3);
70 
71 	outl(inl(MSTPCR2) & ~0x10000000, MSTPCR2);
72 
73 	i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
74 	i2c_set_bus_num(CONFIG_SYS_I2C_MODULE); /* Use I2C 1 */
75 
76 	/* Read MAC address */
77 	i2c_read(0x50, 0x10, 0, mac, 6);
78 
79 	/* Set MAC address */
80 	sprintf(env_mac, "%02X:%02X:%02X:%02X:%02X:%02X",
81 		mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
82 	setenv("ethaddr", env_mac);
83 
84 	debug_led(0x0F);
85 
86 	return 0;
87 }
88 
89 int board_init(void)
90 {
91 
92 	/* LED (PTG) */
93 	outw((inw(PGCR) & ~0xFF) | 0x66, PGCR);
94 	outw((inw(HIZCRA) & ~0x02), HIZCRA);
95 
96 	debug_led(1 << 0);
97 
98 	/* SCIF0 (PTF, PTM) */
99 	outw(inw(PFCR) & ~0x30, PFCR);
100 	outw(inw(PMCR) & ~0x0C, PMCR);
101 	outw((inw(PSELA) & ~0x40) | 0x40, PSELA);
102 
103 	debug_led(1 << 1);
104 
105 	/* RMII (PTA) */
106 	outw((inw(PACR) & ~0x0C) | 0x04, PACR);
107 	outb((inb(PADR) & ~0x02) | 0x02, PADR);
108 
109 	debug_led(1 << 2);
110 
111 	/* USB host */
112 	outw((inw(PBCR) & ~0x300) | 0x100, PBCR);
113 	outb((inb(PBDR) & ~0x10) | 0x10, PBDR);
114 	outl(inl(MSTPCR2) & 0x100000, MSTPCR2);
115 	outw(0x0600, UPONCR0);
116 
117 	debug_led(1 << 3);
118 
119 	/* debug switch */
120 	outw((inw(PVCR) & ~0x03) | 0x02 , PVCR);
121 
122 	return 0;
123 }
124