Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Marek Vasut | aee8312 | 2016-05-06 20:10:41 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2016 Marek Vasut <marex@denx.de> |
Marek Vasut | aee8312 | 2016-05-06 20:10:41 +0200 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 7 | #include <init.h> |
Marek Vasut | aee8312 | 2016-05-06 20:10:41 +0200 | [diff] [blame] | 8 | #include <asm/io.h> |
| 9 | #include <asm/addrspace.h> |
| 10 | #include <asm/types.h> |
| 11 | #include <mach/ath79.h> |
| 12 | #include <mach/ar71xx_regs.h> |
| 13 | #include <mach/ddr.h> |
| 14 | #include <debug_uart.h> |
| 15 | |
Marek Vasut | aee8312 | 2016-05-06 20:10:41 +0200 | [diff] [blame] | 16 | #ifdef CONFIG_USB |
| 17 | static void wdr4300_usb_start(void) |
| 18 | { |
| 19 | void __iomem *gpio_regs = map_physmem(AR71XX_GPIO_BASE, |
| 20 | AR71XX_GPIO_SIZE, MAP_NOCACHE); |
| 21 | if (!gpio_regs) |
| 22 | return; |
| 23 | |
| 24 | /* Power up the USB HUB. */ |
| 25 | clrbits_be32(gpio_regs + AR71XX_GPIO_REG_OE, BIT(21) | BIT(22)); |
| 26 | writel(BIT(21) | BIT(22), gpio_regs + AR71XX_GPIO_REG_SET); |
| 27 | mdelay(1); |
| 28 | |
| 29 | ath79_usb_reset(); |
| 30 | } |
| 31 | #else |
| 32 | static inline void wdr4300_usb_start(void) {} |
| 33 | #endif |
| 34 | |
Álvaro Fernández Rojas | 96d2779 | 2017-04-24 19:03:33 +0200 | [diff] [blame] | 35 | void wdr4300_pinmux_config(void) |
Marek Vasut | aee8312 | 2016-05-06 20:10:41 +0200 | [diff] [blame] | 36 | { |
| 37 | void __iomem *regs; |
| 38 | |
| 39 | regs = map_physmem(AR71XX_GPIO_BASE, AR71XX_GPIO_SIZE, |
| 40 | MAP_NOCACHE); |
| 41 | |
| 42 | /* Assure JTAG is not disconnected. */ |
| 43 | writel(0x40, regs + AR934X_GPIO_REG_FUNC); |
| 44 | |
| 45 | /* Configure default GPIO input/output regs. */ |
| 46 | writel(0x3031b, regs + AR71XX_GPIO_REG_OE); |
| 47 | writel(0x0f804, regs + AR71XX_GPIO_REG_OUT); |
| 48 | |
| 49 | /* Configure pin multiplexing. */ |
| 50 | writel(0x00000000, regs + AR934X_GPIO_REG_OUT_FUNC0); |
| 51 | writel(0x0b0a0980, regs + AR934X_GPIO_REG_OUT_FUNC1); |
| 52 | writel(0x00180000, regs + AR934X_GPIO_REG_OUT_FUNC2); |
| 53 | writel(0x00000000, regs + AR934X_GPIO_REG_OUT_FUNC3); |
| 54 | writel(0x0000004d, regs + AR934X_GPIO_REG_OUT_FUNC4); |
| 55 | writel(0x00000000, regs + AR934X_GPIO_REG_OUT_FUNC5); |
Álvaro Fernández Rojas | 96d2779 | 2017-04-24 19:03:33 +0200 | [diff] [blame] | 56 | } |
Marek Vasut | aee8312 | 2016-05-06 20:10:41 +0200 | [diff] [blame] | 57 | |
Álvaro Fernández Rojas | 96d2779 | 2017-04-24 19:03:33 +0200 | [diff] [blame] | 58 | #ifdef CONFIG_DEBUG_UART_BOARD_INIT |
| 59 | void board_debug_uart_init(void) |
| 60 | { |
| 61 | wdr4300_pinmux_config(); |
| 62 | } |
| 63 | #endif |
| 64 | |
| 65 | #ifdef CONFIG_BOARD_EARLY_INIT_F |
| 66 | int board_early_init_f(void) |
| 67 | { |
| 68 | #ifndef CONFIG_DEBUG_UART_BOARD_INIT |
| 69 | wdr4300_pinmux_config(); |
Marek Vasut | aee8312 | 2016-05-06 20:10:41 +0200 | [diff] [blame] | 70 | #endif |
| 71 | |
| 72 | #ifndef CONFIG_SKIP_LOWLEVEL_INIT |
| 73 | ar934x_pll_init(560, 480, 240); |
| 74 | ar934x_ddr_init(560, 480, 240); |
| 75 | #endif |
| 76 | |
| 77 | wdr4300_usb_start(); |
| 78 | ath79_eth_reset(); |
| 79 | |
| 80 | return 0; |
| 81 | } |
| 82 | #endif |