]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - arch/arm/cpu/armv7/am33xx/board.c
ot1200: add sata support
[karo-tx-uboot.git] / arch / arm / cpu / armv7 / am33xx / board.c
1 /*
2  * board.c
3  *
4  * Common board functions for AM33XX based boards
5  *
6  * Copyright (C) 2011, Texas Instruments, Incorporated - http://www.ti.com/
7  *
8  * SPDX-License-Identifier:     GPL-2.0+
9  */
10
11 #include <common.h>
12 #include <errno.h>
13 #include <spl.h>
14 #include <asm/arch/cpu.h>
15 #include <asm/arch/hardware.h>
16 #include <asm/arch/omap.h>
17 #include <asm/arch/ddr_defs.h>
18 #include <asm/arch/clock.h>
19 #include <asm/arch/gpio.h>
20 #include <asm/arch/mem.h>
21 #include <asm/arch/mmc_host_def.h>
22 #include <asm/arch/sys_proto.h>
23 #include <asm/io.h>
24 #include <asm/emif.h>
25 #include <asm/gpio.h>
26 #include <i2c.h>
27 #include <miiphy.h>
28 #include <cpsw.h>
29 #include <asm/errno.h>
30 #include <linux/compiler.h>
31 #include <linux/usb/ch9.h>
32 #include <linux/usb/gadget.h>
33 #include <linux/usb/musb.h>
34 #include <asm/omap_musb.h>
35 #include <asm/davinci_rtc.h>
36
37 DECLARE_GLOBAL_DATA_PTR;
38
39 static const struct gpio_bank gpio_bank_am33xx[] = {
40         { (void *)AM33XX_GPIO0_BASE, METHOD_GPIO_24XX },
41         { (void *)AM33XX_GPIO1_BASE, METHOD_GPIO_24XX },
42         { (void *)AM33XX_GPIO2_BASE, METHOD_GPIO_24XX },
43         { (void *)AM33XX_GPIO3_BASE, METHOD_GPIO_24XX },
44 #ifdef CONFIG_AM43XX
45         { (void *)AM33XX_GPIO4_BASE, METHOD_GPIO_24XX },
46         { (void *)AM33XX_GPIO5_BASE, METHOD_GPIO_24XX },
47 #endif
48 };
49
50 const struct gpio_bank *const omap_gpio_bank = gpio_bank_am33xx;
51
52 #if defined(CONFIG_OMAP_HSMMC) && !defined(CONFIG_SPL_BUILD)
53 int cpu_mmc_init(bd_t *bis)
54 {
55         int ret;
56
57         ret = omap_mmc_init(0, 0, 0, -1, -1);
58         if (ret)
59                 return ret;
60
61         return omap_mmc_init(1, 0, 0, -1, -1);
62 }
63 #endif
64
65 /* AM33XX has two MUSB controllers which can be host or gadget */
66 #if (defined(CONFIG_MUSB_GADGET) || defined(CONFIG_MUSB_HOST)) && \
67         (defined(CONFIG_AM335X_USB0) || defined(CONFIG_AM335X_USB1))
68 static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
69
70 /* USB 2.0 PHY Control */
71 #define CM_PHY_PWRDN                    (1 << 0)
72 #define CM_PHY_OTG_PWRDN                (1 << 1)
73 #define OTGVDET_EN                      (1 << 19)
74 #define OTGSESSENDEN                    (1 << 20)
75
76 static void am33xx_usb_set_phy_power(u8 on, u32 *reg_addr)
77 {
78         if (on) {
79                 clrsetbits_le32(reg_addr, CM_PHY_PWRDN | CM_PHY_OTG_PWRDN,
80                                 OTGVDET_EN | OTGSESSENDEN);
81         } else {
82                 clrsetbits_le32(reg_addr, 0, CM_PHY_PWRDN | CM_PHY_OTG_PWRDN);
83         }
84 }
85
86 static struct musb_hdrc_config musb_config = {
87         .multipoint     = 1,
88         .dyn_fifo       = 1,
89         .num_eps        = 16,
90         .ram_bits       = 12,
91 };
92
93 #ifdef CONFIG_AM335X_USB0
94 static void am33xx_otg0_set_phy_power(u8 on)
95 {
96         am33xx_usb_set_phy_power(on, &cdev->usb_ctrl0);
97 }
98
99 struct omap_musb_board_data otg0_board_data = {
100         .set_phy_power = am33xx_otg0_set_phy_power,
101 };
102
103 static struct musb_hdrc_platform_data otg0_plat = {
104         .mode           = CONFIG_AM335X_USB0_MODE,
105         .config         = &musb_config,
106         .power          = 50,
107         .platform_ops   = &musb_dsps_ops,
108         .board_data     = &otg0_board_data,
109 };
110 #endif
111
112 #ifdef CONFIG_AM335X_USB1
113 static void am33xx_otg1_set_phy_power(u8 on)
114 {
115         am33xx_usb_set_phy_power(on, &cdev->usb_ctrl1);
116 }
117
118 struct omap_musb_board_data otg1_board_data = {
119         .set_phy_power = am33xx_otg1_set_phy_power,
120 };
121
122 static struct musb_hdrc_platform_data otg1_plat = {
123         .mode           = CONFIG_AM335X_USB1_MODE,
124         .config         = &musb_config,
125         .power          = 50,
126         .platform_ops   = &musb_dsps_ops,
127         .board_data     = &otg1_board_data,
128 };
129 #endif
130 #endif
131
132 int arch_misc_init(void)
133 {
134 #ifdef CONFIG_AM335X_USB0
135         musb_register(&otg0_plat, &otg0_board_data,
136                 (void *)USB0_OTG_BASE);
137 #endif
138 #ifdef CONFIG_AM335X_USB1
139         musb_register(&otg1_plat, &otg1_board_data,
140                 (void *)USB1_OTG_BASE);
141 #endif
142         return 0;
143 }
144
145 #ifndef CONFIG_SKIP_LOWLEVEL_INIT
146 /*
147  * In the case of non-SPL based booting we'll want to call these
148  * functions a tiny bit later as it will require gd to be set and cleared
149  * and that's not true in s_init in this case so we cannot do it there.
150  */
151 int board_early_init_f(void)
152 {
153         prcm_init();
154         set_mux_conf_regs();
155
156         return 0;
157 }
158
159 /*
160  * This function is the place to do per-board things such as ramp up the
161  * MPU clock frequency.
162  */
163 __weak void am33xx_spl_board_init(void)
164 {
165         do_setup_dpll(&dpll_core_regs, &dpll_core_opp100);
166         do_setup_dpll(&dpll_mpu_regs, &dpll_mpu_opp100);
167 }
168
169 #if defined(CONFIG_SPL_AM33XX_ENABLE_RTC32K_OSC)
170 static void rtc32k_enable(void)
171 {
172         struct davinci_rtc *rtc = (struct davinci_rtc *)RTC_BASE;
173
174         /*
175          * Unlock the RTC's registers.  For more details please see the
176          * RTC_SS section of the TRM.  In order to unlock we need to
177          * write these specific values (keys) in this order.
178          */
179         writel(RTC_KICK0R_WE, &rtc->kick0r);
180         writel(RTC_KICK1R_WE, &rtc->kick1r);
181
182         /* Enable the RTC 32K OSC by setting bits 3 and 6. */
183         writel((1 << 3) | (1 << 6), &rtc->osc);
184 }
185 #endif
186
187 static void uart_soft_reset(void)
188 {
189         struct uart_sys *uart_base = (struct uart_sys *)DEFAULT_UART_BASE;
190         u32 regval;
191
192         regval = readl(&uart_base->uartsyscfg);
193         regval |= UART_RESET;
194         writel(regval, &uart_base->uartsyscfg);
195         while ((readl(&uart_base->uartsyssts) &
196                 UART_CLK_RUNNING_MASK) != UART_CLK_RUNNING_MASK)
197                 ;
198
199         /* Disable smart idle */
200         regval = readl(&uart_base->uartsyscfg);
201         regval |= UART_SMART_IDLE_EN;
202         writel(regval, &uart_base->uartsyscfg);
203 }
204
205 static void watchdog_disable(void)
206 {
207         struct wd_timer *wdtimer = (struct wd_timer *)WDT_BASE;
208
209         writel(0xAAAA, &wdtimer->wdtwspr);
210         while (readl(&wdtimer->wdtwwps) != 0x0)
211                 ;
212         writel(0x5555, &wdtimer->wdtwspr);
213         while (readl(&wdtimer->wdtwwps) != 0x0)
214                 ;
215 }
216
217 void s_init(void)
218 {
219         /*
220          * The ROM will only have set up sufficient pinmux to allow for the
221          * first 4KiB NOR to be read, we must finish doing what we know of
222          * the NOR mux in this space in order to continue.
223          */
224 #ifdef CONFIG_NOR_BOOT
225         enable_norboot_pin_mux();
226 #endif
227         /*
228          * Save the boot parameters passed from romcode.
229          * We cannot delay the saving further than this,
230          * to prevent overwrites.
231          */
232 #ifdef CONFIG_SPL_BUILD
233         save_omap_boot_params();
234 #endif
235         watchdog_disable();
236         timer_init();
237         set_uart_mux_conf();
238         setup_clocks_for_console();
239         uart_soft_reset();
240 #if defined(CONFIG_NOR_BOOT) || defined(CONFIG_QSPI_BOOT)
241         gd->baudrate = CONFIG_BAUDRATE;
242         serial_init();
243         gd->have_console = 1;
244 #elif defined(CONFIG_SPL_BUILD)
245         gd = &gdata;
246         preloader_console_init();
247 #endif
248 #if defined(CONFIG_SPL_AM33XX_ENABLE_RTC32K_OSC)
249         /* Enable RTC32K clock */
250         rtc32k_enable();
251 #endif
252 #ifdef CONFIG_SPL_BUILD
253         board_early_init_f();
254         sdram_init();
255 #endif
256 }
257 #endif