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