1400df309SMarek Vasut /*
2400df309SMarek Vasut * Copyright (C) 2016 Marek Vasut <marex@denx.de>
3400df309SMarek Vasut *
4400df309SMarek Vasut * SPDX-License-Identifier: GPL-2.0+
5400df309SMarek Vasut */
6400df309SMarek Vasut
7400df309SMarek Vasut #include <common.h>
8400df309SMarek Vasut #include <asm/io.h>
9400df309SMarek Vasut #include <asm/addrspace.h>
10400df309SMarek Vasut #include <asm/types.h>
11400df309SMarek Vasut #include <mach/ath79.h>
12400df309SMarek Vasut #include <mach/ar71xx_regs.h>
13400df309SMarek Vasut #include <mach/ddr.h>
14400df309SMarek Vasut #include <debug_uart.h>
15400df309SMarek Vasut
16400df309SMarek Vasut DECLARE_GLOBAL_DATA_PTR;
17400df309SMarek Vasut
18400df309SMarek Vasut #ifdef CONFIG_USB
wdr4300_usb_start(void)19400df309SMarek Vasut static void wdr4300_usb_start(void)
20400df309SMarek Vasut {
21400df309SMarek Vasut void __iomem *gpio_regs = map_physmem(AR71XX_GPIO_BASE,
22400df309SMarek Vasut AR71XX_GPIO_SIZE, MAP_NOCACHE);
23400df309SMarek Vasut if (!gpio_regs)
24400df309SMarek Vasut return;
25400df309SMarek Vasut
26400df309SMarek Vasut /* Power up the USB HUB. */
27400df309SMarek Vasut clrbits_be32(gpio_regs + AR71XX_GPIO_REG_OE, BIT(21) | BIT(22));
28400df309SMarek Vasut writel(BIT(21) | BIT(22), gpio_regs + AR71XX_GPIO_REG_SET);
29400df309SMarek Vasut mdelay(1);
30400df309SMarek Vasut
31400df309SMarek Vasut ath79_usb_reset();
32400df309SMarek Vasut }
33400df309SMarek Vasut #else
wdr4300_usb_start(void)34400df309SMarek Vasut static inline void wdr4300_usb_start(void) {}
35400df309SMarek Vasut #endif
36400df309SMarek Vasut
wdr4300_pinmux_config(void)37*fa9aee3aSÁlvaro Fernández Rojas void wdr4300_pinmux_config(void)
38400df309SMarek Vasut {
39400df309SMarek Vasut void __iomem *regs;
40400df309SMarek Vasut
41400df309SMarek Vasut regs = map_physmem(AR71XX_GPIO_BASE, AR71XX_GPIO_SIZE,
42400df309SMarek Vasut MAP_NOCACHE);
43400df309SMarek Vasut
44400df309SMarek Vasut /* Assure JTAG is not disconnected. */
45400df309SMarek Vasut writel(0x40, regs + AR934X_GPIO_REG_FUNC);
46400df309SMarek Vasut
47400df309SMarek Vasut /* Configure default GPIO input/output regs. */
48400df309SMarek Vasut writel(0x3031b, regs + AR71XX_GPIO_REG_OE);
49400df309SMarek Vasut writel(0x0f804, regs + AR71XX_GPIO_REG_OUT);
50400df309SMarek Vasut
51400df309SMarek Vasut /* Configure pin multiplexing. */
52400df309SMarek Vasut writel(0x00000000, regs + AR934X_GPIO_REG_OUT_FUNC0);
53400df309SMarek Vasut writel(0x0b0a0980, regs + AR934X_GPIO_REG_OUT_FUNC1);
54400df309SMarek Vasut writel(0x00180000, regs + AR934X_GPIO_REG_OUT_FUNC2);
55400df309SMarek Vasut writel(0x00000000, regs + AR934X_GPIO_REG_OUT_FUNC3);
56400df309SMarek Vasut writel(0x0000004d, regs + AR934X_GPIO_REG_OUT_FUNC4);
57400df309SMarek Vasut writel(0x00000000, regs + AR934X_GPIO_REG_OUT_FUNC5);
58*fa9aee3aSÁlvaro Fernández Rojas }
59400df309SMarek Vasut
60*fa9aee3aSÁlvaro Fernández Rojas #ifdef CONFIG_DEBUG_UART_BOARD_INIT
board_debug_uart_init(void)61*fa9aee3aSÁlvaro Fernández Rojas void board_debug_uart_init(void)
62*fa9aee3aSÁlvaro Fernández Rojas {
63*fa9aee3aSÁlvaro Fernández Rojas wdr4300_pinmux_config();
64*fa9aee3aSÁlvaro Fernández Rojas }
65*fa9aee3aSÁlvaro Fernández Rojas #endif
66*fa9aee3aSÁlvaro Fernández Rojas
67*fa9aee3aSÁlvaro Fernández Rojas #ifdef CONFIG_BOARD_EARLY_INIT_F
board_early_init_f(void)68*fa9aee3aSÁlvaro Fernández Rojas int board_early_init_f(void)
69*fa9aee3aSÁlvaro Fernández Rojas {
70*fa9aee3aSÁlvaro Fernández Rojas #ifndef CONFIG_DEBUG_UART_BOARD_INIT
71*fa9aee3aSÁlvaro Fernández Rojas wdr4300_pinmux_config();
72400df309SMarek Vasut #endif
73400df309SMarek Vasut
74400df309SMarek Vasut #ifndef CONFIG_SKIP_LOWLEVEL_INIT
75400df309SMarek Vasut ar934x_pll_init(560, 480, 240);
76400df309SMarek Vasut ar934x_ddr_init(560, 480, 240);
77400df309SMarek Vasut #endif
78400df309SMarek Vasut
79400df309SMarek Vasut wdr4300_usb_start();
80400df309SMarek Vasut ath79_eth_reset();
81400df309SMarek Vasut
82400df309SMarek Vasut return 0;
83400df309SMarek Vasut }
84400df309SMarek Vasut #endif
85