Ian Campbell | cba69ee | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2012 Henrik Nordstrom <henrik@henriknordstrom.net> |
| 3 | * |
| 4 | * (C) Copyright 2007-2011 |
| 5 | * Allwinner Technology Co., Ltd. <www.allwinnertech.com> |
| 6 | * Tom Cubie <tangliang@allwinnertech.com> |
| 7 | * |
| 8 | * Some init for sunxi platform. |
| 9 | * |
| 10 | * SPDX-License-Identifier: GPL-2.0+ |
| 11 | */ |
| 12 | |
| 13 | #include <common.h> |
Hans de Goede | 6620377 | 2014-06-13 22:55:49 +0200 | [diff] [blame] | 14 | #include <i2c.h> |
Ian Campbell | 5835823 | 2014-05-05 11:52:28 +0100 | [diff] [blame] | 15 | #include <netdev.h> |
| 16 | #include <miiphy.h> |
Ian Campbell | cba69ee | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 17 | #include <serial.h> |
| 18 | #ifdef CONFIG_SPL_BUILD |
| 19 | #include <spl.h> |
| 20 | #endif |
| 21 | #include <asm/gpio.h> |
| 22 | #include <asm/io.h> |
| 23 | #include <asm/arch/clock.h> |
| 24 | #include <asm/arch/gpio.h> |
| 25 | #include <asm/arch/sys_proto.h> |
| 26 | #include <asm/arch/timer.h> |
| 27 | |
Ian Campbell | 799aff3 | 2014-07-06 20:03:20 +0100 | [diff] [blame] | 28 | #include <linux/compiler.h> |
| 29 | |
Ian Campbell | cba69ee | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 30 | #ifdef CONFIG_SPL_BUILD |
| 31 | /* Pointer to the global data structure for SPL */ |
| 32 | DECLARE_GLOBAL_DATA_PTR; |
| 33 | |
| 34 | /* The sunxi internal brom will try to loader external bootloader |
| 35 | * from mmc0, nand flash, mmc2. |
| 36 | * Unfortunately we can't check how SPL was loaded so assume |
| 37 | * it's always the first SD/MMC controller |
| 38 | */ |
| 39 | u32 spl_boot_device(void) |
| 40 | { |
| 41 | return BOOT_DEVICE_MMC1; |
| 42 | } |
| 43 | |
| 44 | /* No confirmation data available in SPL yet. Hardcode bootmode */ |
| 45 | u32 spl_boot_mode(void) |
| 46 | { |
| 47 | return MMCSD_MODE_RAW; |
| 48 | } |
| 49 | #endif |
| 50 | |
| 51 | int gpio_init(void) |
| 52 | { |
Hans de Goede | f84269c | 2014-06-09 11:36:58 +0200 | [diff] [blame] | 53 | #if CONFIG_CONS_INDEX == 1 && (defined(CONFIG_SUN4I) || defined(CONFIG_SUN7I)) |
Ian Campbell | cba69ee | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 54 | sunxi_gpio_set_cfgpin(SUNXI_GPB(22), SUN4I_GPB22_UART0_TX); |
| 55 | sunxi_gpio_set_cfgpin(SUNXI_GPB(23), SUN4I_GPB23_UART0_RX); |
| 56 | sunxi_gpio_set_pull(SUNXI_GPB(23), 1); |
Hans de Goede | f84269c | 2014-06-09 11:36:58 +0200 | [diff] [blame] | 57 | #elif CONFIG_CONS_INDEX == 1 && defined(CONFIG_SUN5I) |
| 58 | sunxi_gpio_set_cfgpin(SUNXI_GPB(19), SUN5I_GPB19_UART0_TX); |
| 59 | sunxi_gpio_set_cfgpin(SUNXI_GPB(20), SUN5I_GPB20_UART0_RX); |
| 60 | sunxi_gpio_set_pull(SUNXI_GPB(20), 1); |
| 61 | #elif CONFIG_CONS_INDEX == 2 && defined(CONFIG_SUN5I) |
| 62 | sunxi_gpio_set_cfgpin(SUNXI_GPG(3), SUN5I_GPG3_UART1_TX); |
| 63 | sunxi_gpio_set_cfgpin(SUNXI_GPG(4), SUN5I_GPG4_UART1_RX); |
| 64 | sunxi_gpio_set_pull(SUNXI_GPG(4), 1); |
| 65 | #else |
| 66 | #error Unsupported console port number. Please fix pin mux settings in board.c |
| 67 | #endif |
Ian Campbell | cba69ee | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 68 | |
| 69 | return 0; |
| 70 | } |
| 71 | |
| 72 | void reset_cpu(ulong addr) |
| 73 | { |
Hans de Goede | c7e79de | 2014-06-09 11:36:56 +0200 | [diff] [blame] | 74 | static const struct sunxi_wdog *wdog = |
| 75 | &((struct sunxi_timer_reg *)SUNXI_TIMER_BASE)->wdog; |
| 76 | |
| 77 | /* Set the watchdog for its shortest interval (.5s) and wait */ |
| 78 | writel(WDT_MODE_RESET_EN | WDT_MODE_EN, &wdog->mode); |
| 79 | writel(WDT_CTRL_KEY | WDT_CTRL_RESTART, &wdog->ctl); |
Hans de Goede | ae5de5a | 2014-06-13 22:55:52 +0200 | [diff] [blame] | 80 | |
| 81 | while (1) { |
| 82 | /* sun5i sometimes gets stuck without this */ |
| 83 | writel(WDT_MODE_RESET_EN | WDT_MODE_EN, &wdog->mode); |
| 84 | } |
Ian Campbell | cba69ee | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | /* do some early init */ |
| 88 | void s_init(void) |
| 89 | { |
| 90 | #if !defined CONFIG_SPL_BUILD && (defined CONFIG_SUN7I || defined CONFIG_SUN6I) |
| 91 | /* Enable SMP mode for CPU0, by setting bit 6 of Auxiliary Ctl reg */ |
| 92 | asm volatile( |
| 93 | "mrc p15, 0, r0, c1, c0, 1\n" |
| 94 | "orr r0, r0, #1 << 6\n" |
| 95 | "mcr p15, 0, r0, c1, c0, 1\n"); |
| 96 | #endif |
| 97 | |
| 98 | clock_init(); |
| 99 | timer_init(); |
| 100 | gpio_init(); |
Hans de Goede | 6620377 | 2014-06-13 22:55:49 +0200 | [diff] [blame] | 101 | i2c_init_board(); |
Ian Campbell | cba69ee | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 102 | |
| 103 | #ifdef CONFIG_SPL_BUILD |
| 104 | gd = &gdata; |
| 105 | preloader_console_init(); |
| 106 | |
Hans de Goede | 6620377 | 2014-06-13 22:55:49 +0200 | [diff] [blame] | 107 | #ifdef CONFIG_SPL_I2C_SUPPORT |
| 108 | /* Needed early by sunxi_board_init if PMU is enabled */ |
| 109 | i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE); |
| 110 | #endif |
Ian Campbell | cba69ee | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 111 | sunxi_board_init(); |
| 112 | #endif |
| 113 | } |
| 114 | |
| 115 | #ifndef CONFIG_SYS_DCACHE_OFF |
| 116 | void enable_caches(void) |
| 117 | { |
| 118 | /* Enable D-cache. I-cache is already enabled in start.S */ |
| 119 | dcache_enable(); |
| 120 | } |
| 121 | #endif |
Ian Campbell | 5835823 | 2014-05-05 11:52:28 +0100 | [diff] [blame] | 122 | |
| 123 | #ifdef CONFIG_CMD_NET |
| 124 | /* |
| 125 | * Initializes on-chip ethernet controllers. |
| 126 | * to override, implement board_eth_init() |
| 127 | */ |
| 128 | int cpu_eth_init(bd_t *bis) |
| 129 | { |
Ian Campbell | 799aff3 | 2014-07-06 20:03:20 +0100 | [diff] [blame] | 130 | __maybe_unused int rc; |
Ian Campbell | 5835823 | 2014-05-05 11:52:28 +0100 | [diff] [blame] | 131 | |
Hans de Goede | fc70300 | 2014-07-26 17:09:13 +0200 | [diff] [blame] | 132 | #ifdef CONFIG_MACPWR |
| 133 | gpio_direction_output(CONFIG_MACPWR, 1); |
| 134 | mdelay(200); |
| 135 | #endif |
| 136 | |
Hans de Goede | c26fb9d | 2014-06-09 11:37:00 +0200 | [diff] [blame] | 137 | #ifdef CONFIG_SUNXI_EMAC |
| 138 | rc = sunxi_emac_initialize(bis); |
| 139 | if (rc < 0) { |
| 140 | printf("sunxi: failed to initialize emac\n"); |
| 141 | return rc; |
| 142 | } |
| 143 | #endif |
| 144 | |
Ian Campbell | 5835823 | 2014-05-05 11:52:28 +0100 | [diff] [blame] | 145 | #ifdef CONFIG_SUNXI_GMAC |
| 146 | rc = sunxi_gmac_initialize(bis); |
| 147 | if (rc < 0) { |
| 148 | printf("sunxi: failed to initialize gmac\n"); |
| 149 | return rc; |
| 150 | } |
| 151 | #endif |
| 152 | |
| 153 | return 0; |
| 154 | } |
| 155 | #endif |