xref: /rk3399_rockchip-uboot/board/overo/overo.c (revision c2d5b341206f44c13f4de3c4bb80916d085dfdea)
1127f9ae5SJean-Christophe PLAGNIOL-VILLARD /*
2127f9ae5SJean-Christophe PLAGNIOL-VILLARD  * Maintainer : Steve Sakoman <steve@sakoman.com>
3127f9ae5SJean-Christophe PLAGNIOL-VILLARD  *
4127f9ae5SJean-Christophe PLAGNIOL-VILLARD  * Derived from Beagle Board, 3430 SDP, and OMAP3EVM code by
5127f9ae5SJean-Christophe PLAGNIOL-VILLARD  *	Richard Woodruff <r-woodruff2@ti.com>
6127f9ae5SJean-Christophe PLAGNIOL-VILLARD  *	Syed Mohammed Khasim <khasim@ti.com>
7127f9ae5SJean-Christophe PLAGNIOL-VILLARD  *	Sunil Kumar <sunilsaini05@gmail.com>
8127f9ae5SJean-Christophe PLAGNIOL-VILLARD  *	Shashi Ranjan <shashiranjanmca05@gmail.com>
9127f9ae5SJean-Christophe PLAGNIOL-VILLARD  *
10127f9ae5SJean-Christophe PLAGNIOL-VILLARD  * (C) Copyright 2004-2008
11127f9ae5SJean-Christophe PLAGNIOL-VILLARD  * Texas Instruments, <www.ti.com>
12127f9ae5SJean-Christophe PLAGNIOL-VILLARD  *
13127f9ae5SJean-Christophe PLAGNIOL-VILLARD  * See file CREDITS for list of people who contributed to this
14127f9ae5SJean-Christophe PLAGNIOL-VILLARD  * project.
15127f9ae5SJean-Christophe PLAGNIOL-VILLARD  *
16127f9ae5SJean-Christophe PLAGNIOL-VILLARD  * This program is free software; you can redistribute it and/or
17127f9ae5SJean-Christophe PLAGNIOL-VILLARD  * modify it under the terms of the GNU General Public License as
18127f9ae5SJean-Christophe PLAGNIOL-VILLARD  * published by the Free Software Foundation; either version 2 of
19127f9ae5SJean-Christophe PLAGNIOL-VILLARD  * the License, or (at your option) any later version.
20127f9ae5SJean-Christophe PLAGNIOL-VILLARD  *
21127f9ae5SJean-Christophe PLAGNIOL-VILLARD  * This program is distributed in the hope that it will be useful,
22127f9ae5SJean-Christophe PLAGNIOL-VILLARD  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23127f9ae5SJean-Christophe PLAGNIOL-VILLARD  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24127f9ae5SJean-Christophe PLAGNIOL-VILLARD  * GNU General Public License for more details.
25127f9ae5SJean-Christophe PLAGNIOL-VILLARD  *
26127f9ae5SJean-Christophe PLAGNIOL-VILLARD  * You should have received a copy of the GNU General Public License
27127f9ae5SJean-Christophe PLAGNIOL-VILLARD  * along with this program; if not, write to the Free Software
28127f9ae5SJean-Christophe PLAGNIOL-VILLARD  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
29127f9ae5SJean-Christophe PLAGNIOL-VILLARD  * MA 02111-1307 USA
30127f9ae5SJean-Christophe PLAGNIOL-VILLARD  */
31127f9ae5SJean-Christophe PLAGNIOL-VILLARD #include <common.h>
32df382626SOlof Johansson #include <netdev.h>
33127f9ae5SJean-Christophe PLAGNIOL-VILLARD #include <twl4030.h>
34127f9ae5SJean-Christophe PLAGNIOL-VILLARD #include <asm/io.h>
35127f9ae5SJean-Christophe PLAGNIOL-VILLARD #include <asm/arch/mux.h>
36df382626SOlof Johansson #include <asm/arch/mem.h>
37127f9ae5SJean-Christophe PLAGNIOL-VILLARD #include <asm/arch/sys_proto.h>
38df382626SOlof Johansson #include <asm/arch/gpio.h>
39127f9ae5SJean-Christophe PLAGNIOL-VILLARD #include <asm/mach-types.h>
40127f9ae5SJean-Christophe PLAGNIOL-VILLARD #include "overo.h"
41127f9ae5SJean-Christophe PLAGNIOL-VILLARD 
42df382626SOlof Johansson #if defined(CONFIG_CMD_NET)
43df382626SOlof Johansson static void setup_net_chip(void);
44df382626SOlof Johansson #endif
45df382626SOlof Johansson 
46127f9ae5SJean-Christophe PLAGNIOL-VILLARD /*
47127f9ae5SJean-Christophe PLAGNIOL-VILLARD  * Routine: board_init
48127f9ae5SJean-Christophe PLAGNIOL-VILLARD  * Description: Early hardware init.
49127f9ae5SJean-Christophe PLAGNIOL-VILLARD  */
50127f9ae5SJean-Christophe PLAGNIOL-VILLARD int board_init(void)
51127f9ae5SJean-Christophe PLAGNIOL-VILLARD {
52127f9ae5SJean-Christophe PLAGNIOL-VILLARD 	DECLARE_GLOBAL_DATA_PTR;
53127f9ae5SJean-Christophe PLAGNIOL-VILLARD 
54127f9ae5SJean-Christophe PLAGNIOL-VILLARD 	gpmc_init(); /* in SRAM or SDRAM, finish GPMC */
55127f9ae5SJean-Christophe PLAGNIOL-VILLARD 	/* board id for Linux */
56127f9ae5SJean-Christophe PLAGNIOL-VILLARD 	gd->bd->bi_arch_number = MACH_TYPE_OVERO;
57127f9ae5SJean-Christophe PLAGNIOL-VILLARD 	/* boot param addr */
58127f9ae5SJean-Christophe PLAGNIOL-VILLARD 	gd->bd->bi_boot_params = (OMAP34XX_SDRC_CS0 + 0x100);
59127f9ae5SJean-Christophe PLAGNIOL-VILLARD 
60127f9ae5SJean-Christophe PLAGNIOL-VILLARD 	return 0;
61127f9ae5SJean-Christophe PLAGNIOL-VILLARD }
62127f9ae5SJean-Christophe PLAGNIOL-VILLARD 
63127f9ae5SJean-Christophe PLAGNIOL-VILLARD /*
64*c2d5b341SSteve Sakoman  * Routine: get_board_revision
65*c2d5b341SSteve Sakoman  * Description: Returns the board revision
66*c2d5b341SSteve Sakoman  */
67*c2d5b341SSteve Sakoman int get_board_revision(void)
68*c2d5b341SSteve Sakoman {
69*c2d5b341SSteve Sakoman 	int revision;
70*c2d5b341SSteve Sakoman 
71*c2d5b341SSteve Sakoman 	if (!omap_request_gpio(112) &&
72*c2d5b341SSteve Sakoman 	    !omap_request_gpio(113) &&
73*c2d5b341SSteve Sakoman 	    !omap_request_gpio(115)) {
74*c2d5b341SSteve Sakoman 
75*c2d5b341SSteve Sakoman 		omap_set_gpio_direction(112, 1);
76*c2d5b341SSteve Sakoman 		omap_set_gpio_direction(113, 1);
77*c2d5b341SSteve Sakoman 		omap_set_gpio_direction(115, 1);
78*c2d5b341SSteve Sakoman 
79*c2d5b341SSteve Sakoman 		revision = omap_get_gpio_datain(115) << 2 |
80*c2d5b341SSteve Sakoman 			   omap_get_gpio_datain(113) << 1 |
81*c2d5b341SSteve Sakoman 			   omap_get_gpio_datain(112);
82*c2d5b341SSteve Sakoman 
83*c2d5b341SSteve Sakoman 		omap_free_gpio(112);
84*c2d5b341SSteve Sakoman 		omap_free_gpio(113);
85*c2d5b341SSteve Sakoman 		omap_free_gpio(115);
86*c2d5b341SSteve Sakoman 	} else {
87*c2d5b341SSteve Sakoman 		printf("Error: unable to acquire board revision GPIOs\n");
88*c2d5b341SSteve Sakoman 		revision = -1;
89*c2d5b341SSteve Sakoman 	}
90*c2d5b341SSteve Sakoman 
91*c2d5b341SSteve Sakoman 	return revision;
92*c2d5b341SSteve Sakoman }
93*c2d5b341SSteve Sakoman 
94*c2d5b341SSteve Sakoman /*
95127f9ae5SJean-Christophe PLAGNIOL-VILLARD  * Routine: misc_init_r
96127f9ae5SJean-Christophe PLAGNIOL-VILLARD  * Description: Configure board specific parts
97127f9ae5SJean-Christophe PLAGNIOL-VILLARD  */
98127f9ae5SJean-Christophe PLAGNIOL-VILLARD int misc_init_r(void)
99127f9ae5SJean-Christophe PLAGNIOL-VILLARD {
100127f9ae5SJean-Christophe PLAGNIOL-VILLARD 	twl4030_power_init();
101ead39d7aSGrazvydas Ignotas 	twl4030_led_init(TWL4030_LED_LEDEN_LEDAON | TWL4030_LED_LEDEN_LEDBON);
102127f9ae5SJean-Christophe PLAGNIOL-VILLARD 
103df382626SOlof Johansson #if defined(CONFIG_CMD_NET)
104df382626SOlof Johansson 	setup_net_chip();
105df382626SOlof Johansson #endif
106df382626SOlof Johansson 
107*c2d5b341SSteve Sakoman 	printf("Board revision: %d\n", get_board_revision());
108127f9ae5SJean-Christophe PLAGNIOL-VILLARD 	dieid_num_r();
109127f9ae5SJean-Christophe PLAGNIOL-VILLARD 
110127f9ae5SJean-Christophe PLAGNIOL-VILLARD 	return 0;
111127f9ae5SJean-Christophe PLAGNIOL-VILLARD }
112127f9ae5SJean-Christophe PLAGNIOL-VILLARD 
113127f9ae5SJean-Christophe PLAGNIOL-VILLARD /*
114127f9ae5SJean-Christophe PLAGNIOL-VILLARD  * Routine: set_muxconf_regs
115127f9ae5SJean-Christophe PLAGNIOL-VILLARD  * Description: Setting up the configuration Mux registers specific to the
116127f9ae5SJean-Christophe PLAGNIOL-VILLARD  *		hardware. Many pins need to be moved from protect to primary
117127f9ae5SJean-Christophe PLAGNIOL-VILLARD  *		mode.
118127f9ae5SJean-Christophe PLAGNIOL-VILLARD  */
119127f9ae5SJean-Christophe PLAGNIOL-VILLARD void set_muxconf_regs(void)
120127f9ae5SJean-Christophe PLAGNIOL-VILLARD {
121127f9ae5SJean-Christophe PLAGNIOL-VILLARD 	MUX_OVERO();
122127f9ae5SJean-Christophe PLAGNIOL-VILLARD }
123df382626SOlof Johansson 
124df382626SOlof Johansson #if defined(CONFIG_CMD_NET)
125df382626SOlof Johansson /*
126df382626SOlof Johansson  * Routine: setup_net_chip
127df382626SOlof Johansson  * Description: Setting up the configuration GPMC registers specific to the
128df382626SOlof Johansson  *	      Ethernet hardware.
129df382626SOlof Johansson  */
130df382626SOlof Johansson static void setup_net_chip(void)
131df382626SOlof Johansson {
132df382626SOlof Johansson 	struct ctrl *ctrl_base = (struct ctrl *)OMAP34XX_CTRL_BASE;
133df382626SOlof Johansson 
134df382626SOlof Johansson 	/* Configure GPMC registers */
135093d6018SScott Ellis 	writel(NET_LAN9221_GPMC_CONFIG1, &gpmc_cfg->cs[5].config1);
136093d6018SScott Ellis 	writel(NET_LAN9221_GPMC_CONFIG2, &gpmc_cfg->cs[5].config2);
137093d6018SScott Ellis 	writel(NET_LAN9221_GPMC_CONFIG3, &gpmc_cfg->cs[5].config3);
138093d6018SScott Ellis 	writel(NET_LAN9221_GPMC_CONFIG4, &gpmc_cfg->cs[5].config4);
139093d6018SScott Ellis 	writel(NET_LAN9221_GPMC_CONFIG5, &gpmc_cfg->cs[5].config5);
140093d6018SScott Ellis 	writel(NET_LAN9221_GPMC_CONFIG6, &gpmc_cfg->cs[5].config6);
141093d6018SScott Ellis 	writel(NET_LAN9221_GPMC_CONFIG7, &gpmc_cfg->cs[5].config7);
142df382626SOlof Johansson 
143df382626SOlof Johansson 	/* Enable off mode for NWE in PADCONF_GPMC_NWE register */
144df382626SOlof Johansson 	writew(readw(&ctrl_base ->gpmc_nwe) | 0x0E00, &ctrl_base->gpmc_nwe);
145df382626SOlof Johansson 	/* Enable off mode for NOE in PADCONF_GPMC_NADV_ALE register */
146df382626SOlof Johansson 	writew(readw(&ctrl_base->gpmc_noe) | 0x0E00, &ctrl_base->gpmc_noe);
147df382626SOlof Johansson 	/* Enable off mode for ALE in PADCONF_GPMC_NADV_ALE register */
148df382626SOlof Johansson 	writew(readw(&ctrl_base->gpmc_nadv_ale) | 0x0E00,
149df382626SOlof Johansson 		&ctrl_base->gpmc_nadv_ale);
150df382626SOlof Johansson 
151df382626SOlof Johansson 	/* Make GPIO 64 as output pin and send a magic pulse through it */
152df382626SOlof Johansson 	if (!omap_request_gpio(64)) {
153df382626SOlof Johansson 		omap_set_gpio_direction(64, 0);
154df382626SOlof Johansson 		omap_set_gpio_dataout(64, 1);
155df382626SOlof Johansson 		udelay(1);
156df382626SOlof Johansson 		omap_set_gpio_dataout(64, 0);
157df382626SOlof Johansson 		udelay(1);
158df382626SOlof Johansson 		omap_set_gpio_dataout(64, 1);
159df382626SOlof Johansson 	}
160df382626SOlof Johansson }
161df382626SOlof Johansson #endif
162df382626SOlof Johansson 
163df382626SOlof Johansson int board_eth_init(bd_t *bis)
164df382626SOlof Johansson {
165df382626SOlof Johansson 	int rc = 0;
166df382626SOlof Johansson #ifdef CONFIG_SMC911X
167df382626SOlof Johansson 	rc = smc911x_initialize(0, CONFIG_SMC911X_BASE);
168df382626SOlof Johansson #endif
169df382626SOlof Johansson 	return rc;
170df382626SOlof Johansson }
171