Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Vikas Manocha | e66c49f | 2016-02-11 15:47:20 -0800 | [diff] [blame] | 2 | /* |
Patrice Chotard | 3bc599c | 2017-10-23 09:53:58 +0200 | [diff] [blame] | 3 | * Copyright (C) 2016, STMicroelectronics - All Rights Reserved |
| 4 | * Author(s): Vikas Manocha, <vikas.manocha@st.com> for STMicroelectronics. |
Vikas Manocha | e66c49f | 2016-02-11 15:47:20 -0800 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Vikas Manocha | 2d9c33c | 2017-04-10 15:02:54 -0700 | [diff] [blame] | 8 | #include <dm.h> |
Simon Glass | 5255932 | 2019-11-14 12:57:46 -0700 | [diff] [blame] | 9 | #include <init.h> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 10 | #include <log.h> |
Patrice Chotard | 77594d7 | 2019-02-22 15:04:44 +0100 | [diff] [blame] | 11 | #include <miiphy.h> |
| 12 | #include <phy_interface.h> |
Vikas Manocha | 2d9c33c | 2017-04-10 15:02:54 -0700 | [diff] [blame] | 13 | #include <ram.h> |
Simon Glass | b03e051 | 2019-11-14 12:57:24 -0700 | [diff] [blame] | 14 | #include <serial.h> |
Vikas Manocha | b974769 | 2017-05-28 12:55:10 -0700 | [diff] [blame] | 15 | #include <spl.h> |
yannick fertre | 92eac58 | 2018-03-02 15:59:28 +0100 | [diff] [blame] | 16 | #include <splash.h> |
yannick fertre | 92eac58 | 2018-03-02 15:59:28 +0100 | [diff] [blame] | 17 | #include <video.h> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 18 | #include <asm/global_data.h> |
Vikas Manocha | e66c49f | 2016-02-11 15:47:20 -0800 | [diff] [blame] | 19 | #include <asm/io.h> |
| 20 | #include <asm/armv7m.h> |
| 21 | #include <asm/arch/stm32.h> |
Michael Kurz | b20b70f | 2017-01-22 16:04:27 +0100 | [diff] [blame] | 22 | #include <asm/arch/syscfg.h> |
Vikas Manocha | 2f80a9f | 2017-04-10 15:03:00 -0700 | [diff] [blame] | 23 | #include <asm/gpio.h> |
Simon Glass | c05ed00 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 24 | #include <linux/delay.h> |
Vikas Manocha | e66c49f | 2016-02-11 15:47:20 -0800 | [diff] [blame] | 25 | |
| 26 | DECLARE_GLOBAL_DATA_PTR; |
| 27 | |
Toshifumi NISHINAGA | 25c1b13 | 2016-07-08 01:02:25 +0900 | [diff] [blame] | 28 | int dram_init(void) |
| 29 | { |
Patrice Chotard | 16613ed | 2022-04-27 13:53:57 +0200 | [diff] [blame] | 30 | #ifndef CONFIG_SPL_BUILD |
Patrice Chotard | 8ff21d6 | 2018-08-03 13:09:55 +0200 | [diff] [blame] | 31 | int rv; |
Vikas Manocha | b974769 | 2017-05-28 12:55:10 -0700 | [diff] [blame] | 32 | struct udevice *dev; |
Vikas Manocha | 2d9c33c | 2017-04-10 15:02:54 -0700 | [diff] [blame] | 33 | rv = uclass_get_device(UCLASS_RAM, 0, &dev); |
| 34 | if (rv) { |
| 35 | debug("DRAM init failed: %d\n", rv); |
| 36 | return rv; |
| 37 | } |
Toshifumi NISHINAGA | 25c1b13 | 2016-07-08 01:02:25 +0900 | [diff] [blame] | 38 | |
Vikas Manocha | b974769 | 2017-05-28 12:55:10 -0700 | [diff] [blame] | 39 | #endif |
Patrice Chotard | 8ff21d6 | 2018-08-03 13:09:55 +0200 | [diff] [blame] | 40 | return fdtdec_setup_mem_size_base(); |
Vikas Manocha | 57af3cc | 2017-04-10 15:03:01 -0700 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | int dram_init_banksize(void) |
| 44 | { |
Patrice Chotard | 8ff21d6 | 2018-08-03 13:09:55 +0200 | [diff] [blame] | 45 | return fdtdec_setup_memory_banksize(); |
Toshifumi NISHINAGA | 25c1b13 | 2016-07-08 01:02:25 +0900 | [diff] [blame] | 46 | } |
| 47 | |
Vikas Manocha | b974769 | 2017-05-28 12:55:10 -0700 | [diff] [blame] | 48 | #ifdef CONFIG_SPL_BUILD |
Vikas Manocha | 55a3ef7 | 2017-05-28 12:55:13 -0700 | [diff] [blame] | 49 | #ifdef CONFIG_SPL_OS_BOOT |
| 50 | int spl_start_uboot(void) |
| 51 | { |
| 52 | debug("SPL: booting kernel\n"); |
| 53 | /* break into full u-boot on 'c' */ |
| 54 | return serial_tstc() && serial_getc() == 'c'; |
| 55 | } |
| 56 | #endif |
| 57 | |
Vikas Manocha | b974769 | 2017-05-28 12:55:10 -0700 | [diff] [blame] | 58 | int spl_dram_init(void) |
| 59 | { |
| 60 | struct udevice *dev; |
| 61 | int rv; |
| 62 | rv = uclass_get_device(UCLASS_RAM, 0, &dev); |
| 63 | if (rv) |
| 64 | debug("DRAM init failed: %d\n", rv); |
| 65 | return rv; |
| 66 | } |
| 67 | void spl_board_init(void) |
| 68 | { |
Vikas Manocha | b974769 | 2017-05-28 12:55:10 -0700 | [diff] [blame] | 69 | preloader_console_init(); |
Giulio Benetti | 6bd8845 | 2021-04-04 20:21:35 +0200 | [diff] [blame] | 70 | spl_dram_init(); |
Vikas Manocha | b974769 | 2017-05-28 12:55:10 -0700 | [diff] [blame] | 71 | arch_cpu_init(); /* to configure mpu for sdram rw permissions */ |
| 72 | } |
| 73 | u32 spl_boot_device(void) |
| 74 | { |
Vikas Manocha | 1a73bd8 | 2017-05-28 12:55:14 -0700 | [diff] [blame] | 75 | return BOOT_DEVICE_XIP; |
Vikas Manocha | b974769 | 2017-05-28 12:55:10 -0700 | [diff] [blame] | 76 | } |
Vikas Manocha | b974769 | 2017-05-28 12:55:10 -0700 | [diff] [blame] | 77 | #endif |
Vikas Manocha | e66c49f | 2016-02-11 15:47:20 -0800 | [diff] [blame] | 78 | |
Vikas Manocha | 2f80a9f | 2017-04-10 15:03:00 -0700 | [diff] [blame] | 79 | int board_late_init(void) |
| 80 | { |
| 81 | struct gpio_desc gpio = {}; |
| 82 | int node; |
| 83 | |
| 84 | node = fdt_node_offset_by_compatible(gd->fdt_blob, 0, "st,led1"); |
| 85 | if (node < 0) |
| 86 | return -1; |
| 87 | |
Simon Glass | 150c5af | 2017-05-30 21:47:09 -0600 | [diff] [blame] | 88 | gpio_request_by_name_nodev(offset_to_ofnode(node), "led-gpio", 0, &gpio, |
Vikas Manocha | 2f80a9f | 2017-04-10 15:03:00 -0700 | [diff] [blame] | 89 | GPIOD_IS_OUT); |
| 90 | |
| 91 | if (dm_gpio_is_valid(&gpio)) { |
| 92 | dm_gpio_set_value(&gpio, 0); |
| 93 | mdelay(10); |
| 94 | dm_gpio_set_value(&gpio, 1); |
| 95 | } |
| 96 | |
| 97 | /* read button 1*/ |
| 98 | node = fdt_node_offset_by_compatible(gd->fdt_blob, 0, "st,button1"); |
| 99 | if (node < 0) |
| 100 | return -1; |
| 101 | |
Simon Glass | 150c5af | 2017-05-30 21:47:09 -0600 | [diff] [blame] | 102 | gpio_request_by_name_nodev(offset_to_ofnode(node), "button-gpio", 0, |
| 103 | &gpio, GPIOD_IS_IN); |
Vikas Manocha | 2f80a9f | 2017-04-10 15:03:00 -0700 | [diff] [blame] | 104 | |
| 105 | if (dm_gpio_is_valid(&gpio)) { |
| 106 | if (dm_gpio_get_value(&gpio)) |
| 107 | puts("usr button is at HIGH LEVEL\n"); |
| 108 | else |
| 109 | puts("usr button is at LOW LEVEL\n"); |
| 110 | } |
| 111 | |
| 112 | return 0; |
| 113 | } |
| 114 | |
Vikas Manocha | e66c49f | 2016-02-11 15:47:20 -0800 | [diff] [blame] | 115 | int board_init(void) |
| 116 | { |
Patrice Chotard | 20fe38e | 2018-01-18 14:10:05 +0100 | [diff] [blame] | 117 | #ifdef CONFIG_ETH_DESIGNWARE |
Marek Behún | 123ca11 | 2022-04-07 00:33:01 +0200 | [diff] [blame] | 118 | ofnode node; |
Patrice Chotard | 77594d7 | 2019-02-22 15:04:44 +0100 | [diff] [blame] | 119 | |
Marek Behún | 123ca11 | 2022-04-07 00:33:01 +0200 | [diff] [blame] | 120 | node = ofnode_by_compatible(ofnode_null(), "st,stm32-dwmac"); |
| 121 | if (!ofnode_valid(node)) |
Patrice Chotard | 77594d7 | 2019-02-22 15:04:44 +0100 | [diff] [blame] | 122 | return -1; |
| 123 | |
Marek Behún | 123ca11 | 2022-04-07 00:33:01 +0200 | [diff] [blame] | 124 | switch (ofnode_read_phy_mode(node)) { |
Patrice Chotard | 77594d7 | 2019-02-22 15:04:44 +0100 | [diff] [blame] | 125 | case PHY_INTERFACE_MODE_RMII: |
| 126 | STM32_SYSCFG->pmc |= SYSCFG_PMC_MII_RMII_SEL; |
| 127 | break; |
| 128 | case PHY_INTERFACE_MODE_MII: |
| 129 | STM32_SYSCFG->pmc &= ~SYSCFG_PMC_MII_RMII_SEL; |
| 130 | break; |
| 131 | default: |
Marek Behún | 123ca11 | 2022-04-07 00:33:01 +0200 | [diff] [blame] | 132 | printf("Unsupported PHY interface!\n"); |
Patrice Chotard | 77594d7 | 2019-02-22 15:04:44 +0100 | [diff] [blame] | 133 | } |
Patrice Chotard | 20fe38e | 2018-01-18 14:10:05 +0100 | [diff] [blame] | 134 | #endif |
| 135 | |
Vikas Manocha | e66c49f | 2016-02-11 15:47:20 -0800 | [diff] [blame] | 136 | return 0; |
| 137 | } |