]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - arch/arm/cpu/armv7/am33xx/board.c
am33xx: Add am33xx_spl_board_init function, call
[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
36 DECLARE_GLOBAL_DATA_PTR;
37
38 static const struct gpio_bank gpio_bank_am33xx[4] = {
39         { (void *)AM33XX_GPIO0_BASE, METHOD_GPIO_24XX },
40         { (void *)AM33XX_GPIO1_BASE, METHOD_GPIO_24XX },
41         { (void *)AM33XX_GPIO2_BASE, METHOD_GPIO_24XX },
42         { (void *)AM33XX_GPIO3_BASE, METHOD_GPIO_24XX },
43 };
44
45 const struct gpio_bank *const omap_gpio_bank = gpio_bank_am33xx;
46
47 #if defined(CONFIG_OMAP_HSMMC) && !defined(CONFIG_SPL_BUILD)
48 int cpu_mmc_init(bd_t *bis)
49 {
50         int ret;
51
52         ret = omap_mmc_init(0, 0, 0, -1, -1);
53         if (ret)
54                 return ret;
55
56         return omap_mmc_init(1, 0, 0, -1, -1);
57 }
58 #endif
59
60 /* AM33XX has two MUSB controllers which can be host or gadget */
61 #if (defined(CONFIG_MUSB_GADGET) || defined(CONFIG_MUSB_HOST)) && \
62         (defined(CONFIG_AM335X_USB0) || defined(CONFIG_AM335X_USB1))
63 static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
64
65 /* USB 2.0 PHY Control */
66 #define CM_PHY_PWRDN                    (1 << 0)
67 #define CM_PHY_OTG_PWRDN                (1 << 1)
68 #define OTGVDET_EN                      (1 << 19)
69 #define OTGSESSENDEN                    (1 << 20)
70
71 static void am33xx_usb_set_phy_power(u8 on, u32 *reg_addr)
72 {
73         if (on) {
74                 clrsetbits_le32(reg_addr, CM_PHY_PWRDN | CM_PHY_OTG_PWRDN,
75                                 OTGVDET_EN | OTGSESSENDEN);
76         } else {
77                 clrsetbits_le32(reg_addr, 0, CM_PHY_PWRDN | CM_PHY_OTG_PWRDN);
78         }
79 }
80
81 static struct musb_hdrc_config musb_config = {
82         .multipoint     = 1,
83         .dyn_fifo       = 1,
84         .num_eps        = 16,
85         .ram_bits       = 12,
86 };
87
88 #ifdef CONFIG_AM335X_USB0
89 static void am33xx_otg0_set_phy_power(u8 on)
90 {
91         am33xx_usb_set_phy_power(on, &cdev->usb_ctrl0);
92 }
93
94 struct omap_musb_board_data otg0_board_data = {
95         .set_phy_power = am33xx_otg0_set_phy_power,
96 };
97
98 static struct musb_hdrc_platform_data otg0_plat = {
99         .mode           = CONFIG_AM335X_USB0_MODE,
100         .config         = &musb_config,
101         .power          = 50,
102         .platform_ops   = &musb_dsps_ops,
103         .board_data     = &otg0_board_data,
104 };
105 #endif
106
107 #ifdef CONFIG_AM335X_USB1
108 static void am33xx_otg1_set_phy_power(u8 on)
109 {
110         am33xx_usb_set_phy_power(on, &cdev->usb_ctrl1);
111 }
112
113 struct omap_musb_board_data otg1_board_data = {
114         .set_phy_power = am33xx_otg1_set_phy_power,
115 };
116
117 static struct musb_hdrc_platform_data otg1_plat = {
118         .mode           = CONFIG_AM335X_USB1_MODE,
119         .config         = &musb_config,
120         .power          = 50,
121         .platform_ops   = &musb_dsps_ops,
122         .board_data     = &otg1_board_data,
123 };
124 #endif
125 #endif
126
127 int arch_misc_init(void)
128 {
129 #ifdef CONFIG_AM335X_USB0
130         musb_register(&otg0_plat, &otg0_board_data,
131                 (void *)USB0_OTG_BASE);
132 #endif
133 #ifdef CONFIG_AM335X_USB1
134         musb_register(&otg1_plat, &otg1_board_data,
135                 (void *)USB1_OTG_BASE);
136 #endif
137         return 0;
138 }
139
140 #if defined(CONFIG_SPL_BUILD) || defined(CONFIG_NOR_BOOT)
141 /*
142  * This function is the place to do per-board things such as ramp up the
143  * MPU clock frequency.
144  */
145 __weak void am33xx_spl_board_init(void)
146 {
147 }
148
149 static void rtc32k_enable(void)
150 {
151         struct rtc_regs *rtc = (struct rtc_regs *)RTC_BASE;
152
153         /*
154          * Unlock the RTC's registers.  For more details please see the
155          * RTC_SS section of the TRM.  In order to unlock we need to
156          * write these specific values (keys) in this order.
157          */
158         writel(0x83e70b13, &rtc->kick0r);
159         writel(0x95a4f1e0, &rtc->kick1r);
160
161         /* Enable the RTC 32K OSC by setting bits 3 and 6. */
162         writel((1 << 3) | (1 << 6), &rtc->osc);
163 }
164
165 static void uart_soft_reset(void)
166 {
167         struct uart_sys *uart_base = (struct uart_sys *)DEFAULT_UART_BASE;
168         u32 regval;
169
170         regval = readl(&uart_base->uartsyscfg);
171         regval |= UART_RESET;
172         writel(regval, &uart_base->uartsyscfg);
173         while ((readl(&uart_base->uartsyssts) &
174                 UART_CLK_RUNNING_MASK) != UART_CLK_RUNNING_MASK)
175                 ;
176
177         /* Disable smart idle */
178         regval = readl(&uart_base->uartsyscfg);
179         regval |= UART_SMART_IDLE_EN;
180         writel(regval, &uart_base->uartsyscfg);
181 }
182
183 static void watchdog_disable(void)
184 {
185         struct wd_timer *wdtimer = (struct wd_timer *)WDT_BASE;
186
187         writel(0xAAAA, &wdtimer->wdtwspr);
188         while (readl(&wdtimer->wdtwwps) != 0x0)
189                 ;
190         writel(0x5555, &wdtimer->wdtwspr);
191         while (readl(&wdtimer->wdtwwps) != 0x0)
192                 ;
193 }
194 #endif
195
196 void s_init(void)
197 {
198         /*
199          * The ROM will only have set up sufficient pinmux to allow for the
200          * first 4KiB NOR to be read, we must finish doing what we know of
201          * the NOR mux in this space in order to continue.
202          */
203 #ifdef CONFIG_NOR_BOOT
204         enable_norboot_pin_mux();
205 #endif
206         /*
207          * Save the boot parameters passed from romcode.
208          * We cannot delay the saving further than this,
209          * to prevent overwrites.
210          */
211 #ifdef CONFIG_SPL_BUILD
212         save_omap_boot_params();
213 #endif
214 #if defined(CONFIG_SPL_BUILD) || defined(CONFIG_NOR_BOOT)
215         watchdog_disable();
216         timer_init();
217         set_uart_mux_conf();
218         setup_clocks_for_console();
219         uart_soft_reset();
220 #endif
221 #ifdef CONFIG_NOR_BOOT
222         gd->baudrate = CONFIG_BAUDRATE;
223         serial_init();
224         gd->have_console = 1;
225 #else
226         gd = &gdata;
227         preloader_console_init();
228 #endif
229 #if defined(CONFIG_SPL_BUILD) || defined(CONFIG_NOR_BOOT)
230         prcm_init();
231         set_mux_conf_regs();
232         /* Enable RTC32K clock */
233         rtc32k_enable();
234         sdram_init();
235 #endif
236 }