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