common: Drop net.h from common header
[oweals/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 <net.h>
17 #include <ns16550.h>
18 #include <netdev.h>
19 #include <serial.h>
20 #include <asm/io.h>
21 #include <asm/arch/mem.h>
22 #include <asm/arch/mux.h>
23 #include <asm/arch/sys_proto.h>
24 #include <asm/arch/mmc_host_def.h>
25 #include <asm/gpio.h>
26 #include <i2c.h>
27 #include <twl4030.h>
28 #include <asm/mach-types.h>
29 #include <asm/omap_musb.h>
30 #include <linux/mtd/rawnand.h>
31 #include <linux/usb/ch9.h>
32 #include <linux/usb/gadget.h>
33 #include <linux/usb/musb.h>
34 #include "evm.h"
35
36 #define OMAP3EVM_GPIO_ETH_RST_GEN1 64
37 #define OMAP3EVM_GPIO_ETH_RST_GEN2 7
38
39 DECLARE_GLOBAL_DATA_PTR;
40
41 static u32 omap3_evm_version;
42
43 u32 get_omap3_evm_rev(void)
44 {
45         return omap3_evm_version;
46 }
47
48 static void omap3_evm_get_revision(void)
49 {
50 #if defined(CONFIG_CMD_NET)
51         /*
52          * Board revision can be ascertained only by identifying
53          * the Ethernet chipset.
54          */
55         unsigned int smsc_id;
56
57         /* Ethernet PHY ID is stored at ID_REV register */
58         smsc_id = readl(CONFIG_SMC911X_BASE + 0x50) & 0xFFFF0000;
59         printf("Read back SMSC id 0x%x\n", smsc_id);
60
61         switch (smsc_id) {
62         /* SMSC9115 chipset */
63         case 0x01150000:
64                 omap3_evm_version = OMAP3EVM_BOARD_GEN_1;
65                 break;
66         /* SMSC 9220 chipset */
67         case 0x92200000:
68         default:
69                 omap3_evm_version = OMAP3EVM_BOARD_GEN_2;
70        }
71 #else /* !CONFIG_CMD_NET */
72 #if defined(CONFIG_STATIC_BOARD_REV)
73         /* Look for static defintion of the board revision */
74         omap3_evm_version = CONFIG_STATIC_BOARD_REV;
75 #else
76         /* Fallback to the default above */
77         omap3_evm_version = OMAP3EVM_BOARD_GEN_2;
78 #endif /* CONFIG_STATIC_BOARD_REV */
79 #endif /* CONFIG_CMD_NET */
80 }
81
82 #if defined(CONFIG_USB_MUSB_GADGET) || defined(CONFIG_USB_MUSB_HOST)
83 /* MUSB port on OMAP3EVM Rev >= E requires extvbus programming. */
84 u8 omap3_evm_need_extvbus(void)
85 {
86         u8 retval = 0;
87
88         if (get_omap3_evm_rev() >= OMAP3EVM_BOARD_GEN_2)
89                 retval = 1;
90
91         return retval;
92 }
93 #endif /* CONFIG_USB_MUSB_{GADGET,HOST} */
94
95 /*
96  * Routine: board_init
97  * Description: Early hardware init.
98  */
99 int board_init(void)
100 {
101         gpmc_init(); /* in SRAM or SDRAM, finish GPMC */
102         /* board id for Linux */
103         gd->bd->bi_arch_number = MACH_TYPE_OMAP3EVM;
104         /* boot param addr */
105         gd->bd->bi_boot_params = (OMAP34XX_SDRC_CS0 + 0x100);
106
107         return 0;
108 }
109
110 #if defined(CONFIG_SPL_OS_BOOT)
111 int spl_start_uboot(void)
112 {
113         /* break into full u-boot on 'c' */
114         if (serial_tstc() && serial_getc() == 'c')
115                 return 1;
116
117         return 0;
118 }
119 #endif /* CONFIG_SPL_OS_BOOT */
120
121 #if defined(CONFIG_SPL_BUILD)
122 /*
123  * Routine: get_board_mem_timings
124  * Description: If we use SPL then there is no x-loader nor config header
125  * so we have to setup the DDR timings ourself on the first bank.  This
126  * provides the timing values back to the function that configures
127  * the memory.
128  */
129 void get_board_mem_timings(struct board_sdrc_timings *timings)
130 {
131         int pop_mfr, pop_id;
132
133         /*
134          * We need to identify what PoP memory is on the board so that
135          * we know what timings to use.  To map the ID values please see
136          * nand_ids.c
137          */
138         identify_nand_chip(&pop_mfr, &pop_id);
139
140         if (pop_mfr == NAND_MFR_HYNIX && pop_id == 0xbc) {
141                 /* 256MB DDR */
142                 timings->mcfg = HYNIX_V_MCFG_200(256 << 20);
143                 timings->ctrla = HYNIX_V_ACTIMA_200;
144                 timings->ctrlb = HYNIX_V_ACTIMB_200;
145         } else {
146                 /* 128MB DDR */
147                 timings->mcfg = MICRON_V_MCFG_165(128 << 20);
148                 timings->ctrla = MICRON_V_ACTIMA_165;
149                 timings->ctrlb = MICRON_V_ACTIMB_165;
150         }
151         timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
152         timings->mr = MICRON_V_MR_165;
153 }
154 #endif /* CONFIG_SPL_BUILD */
155
156 #if defined(CONFIG_USB_MUSB_OMAP2PLUS)
157 static struct musb_hdrc_config musb_config = {
158         .multipoint     = 1,
159         .dyn_fifo       = 1,
160         .num_eps        = 16,
161         .ram_bits       = 12,
162 };
163
164 static struct omap_musb_board_data musb_board_data = {
165         .interface_type = MUSB_INTERFACE_ULPI,
166 };
167
168 static struct musb_hdrc_platform_data musb_plat = {
169 #if defined(CONFIG_USB_MUSB_HOST)
170         .mode           = MUSB_HOST,
171 #elif defined(CONFIG_USB_MUSB_GADGET)
172         .mode           = MUSB_PERIPHERAL,
173 #else
174 #error "Please define either CONFIG_USB_MUSB_HOST or CONFIG_USB_MUSB_GADGET"
175 #endif /* CONFIG_USB_MUSB_{GADGET,HOST} */
176         .config         = &musb_config,
177         .power          = 100,
178         .platform_ops   = &omap2430_ops,
179         .board_data     = &musb_board_data,
180 };
181 #endif /* CONFIG_USB_MUSB_OMAP2PLUS */
182
183 /*
184  * Routine: misc_init_r
185  * Description: Init ethernet (done here so udelay works)
186  */
187 int misc_init_r(void)
188 {
189         twl4030_power_init();
190
191 #ifdef CONFIG_SYS_I2C_OMAP24XX
192         i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED, CONFIG_SYS_OMAP24_I2C_SLAVE);
193 #endif
194
195 #if defined(CONFIG_CMD_NET)
196         setup_net_chip();
197 #endif
198         omap3_evm_get_revision();
199
200 #if defined(CONFIG_CMD_NET)
201         reset_net_chip();
202 #endif
203         omap_die_id_display();
204
205 #if defined(CONFIG_USB_MUSB_OMAP2PLUS)
206         musb_register(&musb_plat, &musb_board_data, (void *)MUSB_BASE);
207 #endif
208
209 #if defined(CONFIG_USB_ETHER) && defined(CONFIG_USB_MUSB_GADGET)
210         omap_die_id_usbethaddr();
211 #endif
212         return 0;
213 }
214
215 /*
216  * Routine: set_muxconf_regs
217  * Description: Setting up the configuration Mux registers specific to the
218  *              hardware. Many pins need to be moved from protect to primary
219  *              mode.
220  */
221 void set_muxconf_regs(void)
222 {
223         MUX_EVM();
224 }
225
226 #if defined(CONFIG_CMD_NET)
227 /*
228  * Routine: setup_net_chip
229  * Description: Setting up the configuration GPMC registers specific to the
230  *              Ethernet hardware.
231  */
232 static void setup_net_chip(void)
233 {
234         struct ctrl *ctrl_base = (struct ctrl *)OMAP34XX_CTRL_BASE;
235
236         /* Configure GPMC registers */
237         writel(NET_GPMC_CONFIG1, &gpmc_cfg->cs[5].config1);
238         writel(NET_GPMC_CONFIG2, &gpmc_cfg->cs[5].config2);
239         writel(NET_GPMC_CONFIG3, &gpmc_cfg->cs[5].config3);
240         writel(NET_GPMC_CONFIG4, &gpmc_cfg->cs[5].config4);
241         writel(NET_GPMC_CONFIG5, &gpmc_cfg->cs[5].config5);
242         writel(NET_GPMC_CONFIG6, &gpmc_cfg->cs[5].config6);
243         writel(NET_GPMC_CONFIG7, &gpmc_cfg->cs[5].config7);
244
245         /* Enable off mode for NWE in PADCONF_GPMC_NWE register */
246         writew(readw(&ctrl_base ->gpmc_nwe) | 0x0E00, &ctrl_base->gpmc_nwe);
247         /* Enable off mode for NOE in PADCONF_GPMC_NADV_ALE register */
248         writew(readw(&ctrl_base->gpmc_noe) | 0x0E00, &ctrl_base->gpmc_noe);
249         /* Enable off mode for ALE in PADCONF_GPMC_NADV_ALE register */
250         writew(readw(&ctrl_base->gpmc_nadv_ale) | 0x0E00,
251                 &ctrl_base->gpmc_nadv_ale);
252 }
253
254 /**
255  * Reset the ethernet chip.
256  */
257 static void reset_net_chip(void)
258 {
259         int ret;
260         int rst_gpio;
261
262         if (get_omap3_evm_rev() == OMAP3EVM_BOARD_GEN_1) {
263                 rst_gpio = OMAP3EVM_GPIO_ETH_RST_GEN1;
264         } else {
265                 rst_gpio = OMAP3EVM_GPIO_ETH_RST_GEN2;
266         }
267
268         ret = gpio_request(rst_gpio, "");
269         if (ret < 0) {
270                 printf("Unable to get GPIO %d\n", rst_gpio);
271                 return ;
272         }
273
274         /* Configure as output */
275         gpio_direction_output(rst_gpio, 0);
276
277         /* Send a pulse on the GPIO pin */
278         gpio_set_value(rst_gpio, 1);
279         udelay(1);
280         gpio_set_value(rst_gpio, 0);
281         udelay(1);
282         gpio_set_value(rst_gpio, 1);
283 }
284
285 int board_eth_init(bd_t *bis)
286 {
287 #if defined(CONFIG_SMC911X)
288         env_set("ethaddr", NULL);
289         return smc911x_initialize(0, CONFIG_SMC911X_BASE);
290 #else
291         return 0;
292 #endif
293 }
294 #endif /* CONFIG_CMD_NET */
295
296 #if defined(CONFIG_MMC)
297 int board_mmc_init(bd_t *bis)
298 {
299         return omap_mmc_init(0, 0, 0, -1, -1);
300 }
301
302 void board_mmc_power_init(void)
303 {
304         twl4030_power_mmc_init(0);
305 }
306 #endif /* CONFIG_MMC */
307
308 #if defined(CONFIG_USB_ETHER) && defined(CONFIG_USB_MUSB_GADGET) && !defined(CONFIG_CMD_NET)
309 int board_eth_init(bd_t *bis)
310 {
311         return usb_eth_initialize(bis);
312 }
313 #endif /* CONFIG_USB_ETHER */