]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/isee/igep0033/board.c
Merge branch 'master' of git://git.denx.de/u-boot-nand-flash
[karo-tx-uboot.git] / board / isee / igep0033 / board.c
1 /*
2  * Board functions for IGEP COM AQUILA/CYGNUS based boards
3  *
4  * Copyright (C) 2013, ISEE 2007 SL - http://www.isee.biz/
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
17 #include <common.h>
18 #include <errno.h>
19 #include <spl.h>
20 #include <asm/arch/cpu.h>
21 #include <asm/arch/hardware.h>
22 #include <asm/arch/omap.h>
23 #include <asm/arch/ddr_defs.h>
24 #include <asm/arch/clock.h>
25 #include <asm/arch/gpio.h>
26 #include <asm/arch/mmc_host_def.h>
27 #include <asm/arch/sys_proto.h>
28 #include <asm/io.h>
29 #include <asm/emif.h>
30 #include <asm/gpio.h>
31 #include <i2c.h>
32 #include <miiphy.h>
33 #include <cpsw.h>
34 #include "board.h"
35
36 DECLARE_GLOBAL_DATA_PTR;
37
38 static struct wd_timer *wdtimer = (struct wd_timer *)WDT_BASE;
39 #ifdef CONFIG_SPL_BUILD
40 static struct uart_sys *uart_base = (struct uart_sys *)DEFAULT_UART_BASE;
41 #endif
42
43 /* MII mode defines */
44 #define RMII_MODE_ENABLE        0x4D
45
46 static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
47
48 /* UART Defines */
49 #ifdef CONFIG_SPL_BUILD
50 #define UART_RESET              (0x1 << 1)
51 #define UART_CLK_RUNNING_MASK   0x1
52 #define UART_SMART_IDLE_EN      (0x1 << 0x3)
53
54 static void rtc32k_enable(void)
55 {
56         struct rtc_regs *rtc = (struct rtc_regs *)RTC_BASE;
57
58         /*
59          * Unlock the RTC's registers.  For more details please see the
60          * RTC_SS section of the TRM.  In order to unlock we need to
61          * write these specific values (keys) in this order.
62          */
63         writel(0x83e70b13, &rtc->kick0r);
64         writel(0x95a4f1e0, &rtc->kick1r);
65
66         /* Enable the RTC 32K OSC by setting bits 3 and 6. */
67         writel((1 << 3) | (1 << 6), &rtc->osc);
68 }
69
70 static const struct ddr_data ddr3_data = {
71         .datardsratio0 = K4B2G1646EBIH9_RD_DQS,
72         .datawdsratio0 = K4B2G1646EBIH9_WR_DQS,
73         .datafwsratio0 = K4B2G1646EBIH9_PHY_FIFO_WE,
74         .datawrsratio0 = K4B2G1646EBIH9_PHY_WR_DATA,
75         .datadldiff0 = PHY_DLL_LOCK_DIFF,
76 };
77
78 static const struct cmd_control ddr3_cmd_ctrl_data = {
79         .cmd0csratio = K4B2G1646EBIH9_RATIO,
80         .cmd0dldiff = K4B2G1646EBIH9_DLL_LOCK_DIFF,
81         .cmd0iclkout = K4B2G1646EBIH9_INVERT_CLKOUT,
82
83         .cmd1csratio = K4B2G1646EBIH9_RATIO,
84         .cmd1dldiff = K4B2G1646EBIH9_DLL_LOCK_DIFF,
85         .cmd1iclkout = K4B2G1646EBIH9_INVERT_CLKOUT,
86
87         .cmd2csratio = K4B2G1646EBIH9_RATIO,
88         .cmd2dldiff = K4B2G1646EBIH9_DLL_LOCK_DIFF,
89         .cmd2iclkout = K4B2G1646EBIH9_INVERT_CLKOUT,
90 };
91
92 static struct emif_regs ddr3_emif_reg_data = {
93         .sdram_config = K4B2G1646EBIH9_EMIF_SDCFG,
94         .ref_ctrl = K4B2G1646EBIH9_EMIF_SDREF,
95         .sdram_tim1 = K4B2G1646EBIH9_EMIF_TIM1,
96         .sdram_tim2 = K4B2G1646EBIH9_EMIF_TIM2,
97         .sdram_tim3 = K4B2G1646EBIH9_EMIF_TIM3,
98         .zq_config = K4B2G1646EBIH9_ZQ_CFG,
99         .emif_ddr_phy_ctlr_1 = K4B2G1646EBIH9_EMIF_READ_LATENCY,
100 };
101 #endif
102
103 /*
104  * Early system init of muxing and clocks.
105  */
106 void s_init(void)
107 {
108         /* WDT1 is already running when the bootloader gets control
109          * Disable it to avoid "random" resets
110          */
111         writel(0xAAAA, &wdtimer->wdtwspr);
112         while (readl(&wdtimer->wdtwwps) != 0x0)
113                 ;
114         writel(0x5555, &wdtimer->wdtwspr);
115         while (readl(&wdtimer->wdtwwps) != 0x0)
116                 ;
117
118 #ifdef CONFIG_SPL_BUILD
119         /* Setup the PLLs and the clocks for the peripherals */
120         pll_init();
121
122         /* Enable RTC32K clock */
123         rtc32k_enable();
124
125         /* UART softreset */
126         u32 regval;
127
128         enable_uart0_pin_mux();
129
130         regval = readl(&uart_base->uartsyscfg);
131         regval |= UART_RESET;
132         writel(regval, &uart_base->uartsyscfg);
133         while ((readl(&uart_base->uartsyssts) &
134                 UART_CLK_RUNNING_MASK) != UART_CLK_RUNNING_MASK)
135                 ;
136
137         /* Disable smart idle */
138         regval = readl(&uart_base->uartsyscfg);
139         regval |= UART_SMART_IDLE_EN;
140         writel(regval, &uart_base->uartsyscfg);
141
142         gd = &gdata;
143
144         preloader_console_init();
145
146         /* Configure board pin mux */
147         enable_board_pin_mux();
148
149         config_ddr(303, K4B2G1646EBIH9_IOCTRL_VALUE, &ddr3_data,
150                    &ddr3_cmd_ctrl_data, &ddr3_emif_reg_data, 0);
151 #endif
152 }
153
154 /*
155  * Basic board specific setup.  Pinmux has been handled already.
156  */
157 int board_init(void)
158 {
159         gd->bd->bi_boot_params = PHYS_DRAM_1 + 0x100;
160
161         gpmc_init();
162
163         return 0;
164 }
165
166 #if defined(CONFIG_DRIVER_TI_CPSW)
167 static void cpsw_control(int enabled)
168 {
169         /* VTP can be added here */
170
171         return;
172 }
173
174 static struct cpsw_slave_data cpsw_slaves[] = {
175         {
176                 .slave_reg_ofs  = 0x208,
177                 .sliver_reg_ofs = 0xd80,
178                 .phy_id         = 0,
179                 .phy_if         = PHY_INTERFACE_MODE_RMII,
180         },
181 };
182
183 static struct cpsw_platform_data cpsw_data = {
184         .mdio_base              = CPSW_MDIO_BASE,
185         .cpsw_base              = CPSW_BASE,
186         .mdio_div               = 0xff,
187         .channels               = 8,
188         .cpdma_reg_ofs          = 0x800,
189         .slaves                 = 1,
190         .slave_data             = cpsw_slaves,
191         .ale_reg_ofs            = 0xd00,
192         .ale_entries            = 1024,
193         .host_port_reg_ofs      = 0x108,
194         .hw_stats_reg_ofs       = 0x900,
195         .mac_control            = (1 << 5),
196         .control                = cpsw_control,
197         .host_port_num          = 0,
198         .version                = CPSW_CTRL_VERSION_2,
199 };
200
201 int board_eth_init(bd_t *bis)
202 {
203         int rv, ret = 0;
204         uint8_t mac_addr[6];
205         uint32_t mac_hi, mac_lo;
206
207         if (!eth_getenv_enetaddr("ethaddr", mac_addr)) {
208                 /* try reading mac address from efuse */
209                 mac_lo = readl(&cdev->macid0l);
210                 mac_hi = readl(&cdev->macid0h);
211                 mac_addr[0] = mac_hi & 0xFF;
212                 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
213                 mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
214                 mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
215                 mac_addr[4] = mac_lo & 0xFF;
216                 mac_addr[5] = (mac_lo & 0xFF00) >> 8;
217                 if (is_valid_ether_addr(mac_addr))
218                         eth_setenv_enetaddr("ethaddr", mac_addr);
219         }
220
221         writel(RMII_MODE_ENABLE, &cdev->miisel);
222
223         rv = cpsw_register(&cpsw_data);
224         if (rv < 0)
225                 printf("Error %d registering CPSW switch\n", rv);
226         else
227                 ret += rv;
228
229         return ret;
230 }
231 #endif
232