39b5c706a95a045ff6a9cea0da5207be253ac923
[platform/kernel/u-boot.git] / board / ti / evm / evm.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * (C) Copyright 2004-2011
4  * Texas Instruments, <www.ti.com>
5  *
6  * Author :
7  *      Manikandan Pillai <mani.pillai@ti.com>
8  *
9  * Derived from Beagle Board and 3430 SDP code by
10  *      Richard Woodruff <r-woodruff2@ti.com>
11  *      Syed Mohammed Khasim <khasim@ti.com>
12  */
13 #include <common.h>
14 #include <dm.h>
15 #include <env.h>
16 #include <init.h>
17 #include <net.h>
18 #include <ns16550.h>
19 #include <serial.h>
20 #include <asm/global_data.h>
21 #include <asm/io.h>
22 #include <asm/arch/mem.h>
23 #include <asm/arch/mux.h>
24 #include <asm/arch/sys_proto.h>
25 #include <asm/arch/mmc_host_def.h>
26 #include <asm/gpio.h>
27 #include <twl4030.h>
28 #include <asm/mach-types.h>
29 #include <linux/delay.h>
30 #include <linux/mtd/rawnand.h>
31 #include "evm.h"
32
33 #define OMAP3EVM_GPIO_ETH_RST_GEN1 64
34 #define OMAP3EVM_GPIO_ETH_RST_GEN2 7
35
36 #define CONFIG_SMC911X_BASE 0x2C000000
37
38 DECLARE_GLOBAL_DATA_PTR;
39
40 static u32 omap3_evm_version;
41
42 u32 get_omap3_evm_rev(void)
43 {
44         return omap3_evm_version;
45 }
46
47 static void omap3_evm_get_revision(void)
48 {
49 #if defined(CONFIG_SMC911X)
50         /*
51          * Board revision can be ascertained only by identifying
52          * the Ethernet chipset.
53          */
54         unsigned int smsc_id;
55
56         /* Ethernet PHY ID is stored at ID_REV register */
57         smsc_id = readl(CONFIG_SMC911X_BASE + 0x50) & 0xFFFF0000;
58         printf("Read back SMSC id 0x%x\n", smsc_id);
59
60         switch (smsc_id) {
61         /* SMSC9115 chipset */
62         case 0x01150000:
63                 omap3_evm_version = OMAP3EVM_BOARD_GEN_1;
64                 break;
65         /* SMSC 9220 chipset */
66         case 0x92200000:
67         default:
68                 omap3_evm_version = OMAP3EVM_BOARD_GEN_2;
69        }
70 #else /* !CONFIG_SMC911X */
71 #if defined(CONFIG_STATIC_BOARD_REV)
72         /* Look for static defintion of the board revision */
73         omap3_evm_version = CONFIG_STATIC_BOARD_REV;
74 #else
75         /* Fallback to the default above */
76         omap3_evm_version = OMAP3EVM_BOARD_GEN_2;
77 #endif /* CONFIG_STATIC_BOARD_REV */
78 #endif /* CONFIG_SMC911X */
79 }
80
81 #if defined(CONFIG_USB_MUSB_GADGET) || defined(CONFIG_USB_MUSB_HOST)
82 /* MUSB port on OMAP3EVM Rev >= E requires extvbus programming. */
83 u8 omap3_evm_need_extvbus(void)
84 {
85         u8 retval = 0;
86
87         if (get_omap3_evm_rev() >= OMAP3EVM_BOARD_GEN_2)
88                 retval = 1;
89
90         return retval;
91 }
92 #endif /* CONFIG_USB_MUSB_{GADGET,HOST} */
93
94 /*
95  * Routine: board_init
96  * Description: Early hardware init.
97  */
98 int board_init(void)
99 {
100         gpmc_init(); /* in SRAM or SDRAM, finish GPMC */
101         /* board id for Linux */
102         gd->bd->bi_arch_number = MACH_TYPE_OMAP3EVM;
103         /* boot param addr */
104         gd->bd->bi_boot_params = (OMAP34XX_SDRC_CS0 + 0x100);
105
106         return 0;
107 }
108
109 #if defined(CONFIG_SPL_OS_BOOT)
110 int spl_start_uboot(void)
111 {
112         /* break into full u-boot on 'c' */
113         if (serial_tstc() && serial_getc() == 'c')
114                 return 1;
115
116         return 0;
117 }
118 #endif /* CONFIG_SPL_OS_BOOT */
119
120 #if defined(CONFIG_SPL_BUILD)
121 /*
122  * Routine: get_board_mem_timings
123  * Description: If we use SPL then there is no x-loader nor config header
124  * so we have to setup the DDR timings ourself on the first bank.  This
125  * provides the timing values back to the function that configures
126  * the memory.
127  */
128 void get_board_mem_timings(struct board_sdrc_timings *timings)
129 {
130         int pop_mfr, pop_id;
131
132         /*
133          * We need to identify what PoP memory is on the board so that
134          * we know what timings to use.  To map the ID values please see
135          * nand_ids.c
136          */
137         identify_nand_chip(&pop_mfr, &pop_id);
138
139         if (pop_mfr == NAND_MFR_HYNIX && pop_id == 0xbc) {
140                 /* 256MB DDR */
141                 timings->mcfg = HYNIX_V_MCFG_200(256 << 20);
142                 timings->ctrla = HYNIX_V_ACTIMA_200;
143                 timings->ctrlb = HYNIX_V_ACTIMB_200;
144         } else {
145                 /* 128MB DDR */
146                 timings->mcfg = MICRON_V_MCFG_165(128 << 20);
147                 timings->ctrla = MICRON_V_ACTIMA_165;
148                 timings->ctrlb = MICRON_V_ACTIMB_165;
149         }
150         timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
151         timings->mr = MICRON_V_MR_165;
152 }
153 #endif /* CONFIG_SPL_BUILD */
154
155 /*
156  * Routine: misc_init_r
157  * Description: Init ethernet (done here so udelay works)
158  */
159 int misc_init_r(void)
160 {
161         twl4030_power_init();
162         twl4030_power_mmc_init(0);
163
164 #if defined(CONFIG_SMC911X)
165         setup_net_chip();
166 #endif
167         omap3_evm_get_revision();
168
169 #if defined(CONFIG_SMC911X)
170         reset_net_chip();
171 #endif
172         omap_die_id_display();
173
174 #if defined(CONFIG_USB_ETHER) && defined(CONFIG_USB_MUSB_GADGET) && \
175                                                 !defined(CONFIG_SMC911X)
176         omap_die_id_usbethaddr();
177 #endif
178         return 0;
179 }
180
181 /*
182  * Routine: set_muxconf_regs
183  * Description: Setting up the configuration Mux registers specific to the
184  *              hardware. Many pins need to be moved from protect to primary
185  *              mode.
186  */
187 void set_muxconf_regs(void)
188 {
189         MUX_EVM();
190 }
191
192 #if defined(CONFIG_SMC911X)
193 /*
194  * Routine: setup_net_chip
195  * Description: Setting up the configuration GPMC registers specific to the
196  *              Ethernet hardware.
197  */
198 static void setup_net_chip(void)
199 {
200         struct ctrl *ctrl_base = (struct ctrl *)OMAP34XX_CTRL_BASE;
201
202         /* Configure GPMC registers */
203         writel(NET_GPMC_CONFIG1, &gpmc_cfg->cs[5].config1);
204         writel(NET_GPMC_CONFIG2, &gpmc_cfg->cs[5].config2);
205         writel(NET_GPMC_CONFIG3, &gpmc_cfg->cs[5].config3);
206         writel(NET_GPMC_CONFIG4, &gpmc_cfg->cs[5].config4);
207         writel(NET_GPMC_CONFIG5, &gpmc_cfg->cs[5].config5);
208         writel(NET_GPMC_CONFIG6, &gpmc_cfg->cs[5].config6);
209         writel(NET_GPMC_CONFIG7, &gpmc_cfg->cs[5].config7);
210
211         /* Enable off mode for NWE in PADCONF_GPMC_NWE register */
212         writew(readw(&ctrl_base ->gpmc_nwe) | 0x0E00, &ctrl_base->gpmc_nwe);
213         /* Enable off mode for NOE in PADCONF_GPMC_NADV_ALE register */
214         writew(readw(&ctrl_base->gpmc_noe) | 0x0E00, &ctrl_base->gpmc_noe);
215         /* Enable off mode for ALE in PADCONF_GPMC_NADV_ALE register */
216         writew(readw(&ctrl_base->gpmc_nadv_ale) | 0x0E00,
217                 &ctrl_base->gpmc_nadv_ale);
218 }
219
220 /**
221  * Reset the ethernet chip.
222  */
223 static void reset_net_chip(void)
224 {
225         int ret;
226         int rst_gpio;
227
228         if (get_omap3_evm_rev() == OMAP3EVM_BOARD_GEN_1) {
229                 rst_gpio = OMAP3EVM_GPIO_ETH_RST_GEN1;
230         } else {
231                 rst_gpio = OMAP3EVM_GPIO_ETH_RST_GEN2;
232         }
233
234         ret = gpio_request(rst_gpio, "");
235         if (ret < 0) {
236                 printf("Unable to get GPIO %d\n", rst_gpio);
237                 return ;
238         }
239
240         /* Configure as output */
241         gpio_direction_output(rst_gpio, 0);
242
243         /* Send a pulse on the GPIO pin */
244         gpio_set_value(rst_gpio, 1);
245         udelay(1);
246         gpio_set_value(rst_gpio, 0);
247         udelay(1);
248         gpio_set_value(rst_gpio, 1);
249 }
250 #endif /* CONFIG_SMC911X */