blob: f2de039b6b4752266b8af89f392ac35d14137b64 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Marek Vasut400df302016-05-06 20:10:41 +02002/*
3 * Copyright (C) 2016 Marek Vasut <marex@denx.de>
Marek Vasut400df302016-05-06 20:10:41 +02004 */
5
6#include <common.h>
Simon Glass691d7192020-05-10 11:40:02 -06007#include <init.h>
Marek Vasut400df302016-05-06 20:10:41 +02008#include <asm/io.h>
9#include <asm/addrspace.h>
10#include <asm/types.h>
Simon Glasscd93d622020-05-10 11:40:13 -060011#include <linux/bitops.h>
Simon Glassc05ed002020-05-10 11:40:11 -060012#include <linux/delay.h>
Marek Vasut400df302016-05-06 20:10:41 +020013#include <mach/ath79.h>
14#include <mach/ar71xx_regs.h>
15#include <mach/ddr.h>
16#include <debug_uart.h>
17
Tom Rinie8d3eaa2021-07-09 10:11:55 -040018#ifdef CONFIG_USB_HOST
Marek Vasut400df302016-05-06 20:10:41 +020019static void wdr4300_usb_start(void)
20{
21 void __iomem *gpio_regs = map_physmem(AR71XX_GPIO_BASE,
22 AR71XX_GPIO_SIZE, MAP_NOCACHE);
23 if (!gpio_regs)
24 return;
25
26 /* Power up the USB HUB. */
27 clrbits_be32(gpio_regs + AR71XX_GPIO_REG_OE, BIT(21) | BIT(22));
28 writel(BIT(21) | BIT(22), gpio_regs + AR71XX_GPIO_REG_SET);
29 mdelay(1);
30
31 ath79_usb_reset();
32}
33#else
34static inline void wdr4300_usb_start(void) {}
35#endif
36
Álvaro Fernández Rojasfa9aee32017-04-24 19:03:33 +020037void wdr4300_pinmux_config(void)
Marek Vasut400df302016-05-06 20:10:41 +020038{
39 void __iomem *regs;
40
41 regs = map_physmem(AR71XX_GPIO_BASE, AR71XX_GPIO_SIZE,
42 MAP_NOCACHE);
43
44 /* Assure JTAG is not disconnected. */
45 writel(0x40, regs + AR934X_GPIO_REG_FUNC);
46
47 /* Configure default GPIO input/output regs. */
48 writel(0x3031b, regs + AR71XX_GPIO_REG_OE);
49 writel(0x0f804, regs + AR71XX_GPIO_REG_OUT);
50
51 /* Configure pin multiplexing. */
52 writel(0x00000000, regs + AR934X_GPIO_REG_OUT_FUNC0);
53 writel(0x0b0a0980, regs + AR934X_GPIO_REG_OUT_FUNC1);
54 writel(0x00180000, regs + AR934X_GPIO_REG_OUT_FUNC2);
55 writel(0x00000000, regs + AR934X_GPIO_REG_OUT_FUNC3);
56 writel(0x0000004d, regs + AR934X_GPIO_REG_OUT_FUNC4);
57 writel(0x00000000, regs + AR934X_GPIO_REG_OUT_FUNC5);
Álvaro Fernández Rojasfa9aee32017-04-24 19:03:33 +020058}
Marek Vasut400df302016-05-06 20:10:41 +020059
Álvaro Fernández Rojasfa9aee32017-04-24 19:03:33 +020060#ifdef CONFIG_DEBUG_UART_BOARD_INIT
61void board_debug_uart_init(void)
62{
63 wdr4300_pinmux_config();
64}
65#endif
66
67#ifdef CONFIG_BOARD_EARLY_INIT_F
68int board_early_init_f(void)
69{
70#ifndef CONFIG_DEBUG_UART_BOARD_INIT
71 wdr4300_pinmux_config();
Marek Vasut400df302016-05-06 20:10:41 +020072#endif
73
Tom Rinia2ac2b92021-08-27 21:18:30 -040074#if !CONFIG_IS_ENABLED(SKIP_LOWLEVEL_INIT)
Marek Vasut400df302016-05-06 20:10:41 +020075 ar934x_pll_init(560, 480, 240);
76 ar934x_ddr_init(560, 480, 240);
77#endif
78
79 wdr4300_usb_start();
80 ath79_eth_reset();
81
82 return 0;
83}
84#endif