Vikas Manocha | e66c49f | 2016-02-11 15:47:20 -0800 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2016 |
| 3 | * Vikas Manocha, <vikas.manocha@st.com> |
| 4 | * |
| 5 | * SPDX-License-Identifier: GPL-2.0+ |
| 6 | */ |
| 7 | |
| 8 | #include <common.h> |
Vikas Manocha | 2d9c33c | 2017-04-10 15:02:54 -0700 | [diff] [blame] | 9 | #include <dm.h> |
| 10 | #include <ram.h> |
Vikas Manocha | e66c49f | 2016-02-11 15:47:20 -0800 | [diff] [blame] | 11 | #include <asm/io.h> |
| 12 | #include <asm/armv7m.h> |
| 13 | #include <asm/arch/stm32.h> |
| 14 | #include <asm/arch/gpio.h> |
| 15 | #include <dm/platdata.h> |
| 16 | #include <dm/platform_data/serial_stm32x7.h> |
| 17 | #include <asm/arch/stm32_periph.h> |
| 18 | #include <asm/arch/stm32_defs.h> |
Michael Kurz | b20b70f | 2017-01-22 16:04:27 +0100 | [diff] [blame] | 19 | #include <asm/arch/syscfg.h> |
Vikas Manocha | 2f80a9f | 2017-04-10 15:03:00 -0700 | [diff] [blame^] | 20 | #include <asm/gpio.h> |
Vikas Manocha | e66c49f | 2016-02-11 15:47:20 -0800 | [diff] [blame] | 21 | |
| 22 | DECLARE_GLOBAL_DATA_PTR; |
| 23 | |
Toshifumi NISHINAGA | 25c1b13 | 2016-07-08 01:02:25 +0900 | [diff] [blame] | 24 | int dram_init(void) |
| 25 | { |
Vikas Manocha | 2d9c33c | 2017-04-10 15:02:54 -0700 | [diff] [blame] | 26 | struct udevice *dev; |
| 27 | struct ram_info ram; |
Toshifumi NISHINAGA | 25c1b13 | 2016-07-08 01:02:25 +0900 | [diff] [blame] | 28 | int rv; |
| 29 | |
Vikas Manocha | 2d9c33c | 2017-04-10 15:02:54 -0700 | [diff] [blame] | 30 | rv = uclass_get_device(UCLASS_RAM, 0, &dev); |
| 31 | if (rv) { |
| 32 | debug("DRAM init failed: %d\n", rv); |
| 33 | return rv; |
| 34 | } |
| 35 | rv = ram_get_info(dev, &ram); |
| 36 | if (rv) { |
| 37 | debug("Cannot get DRAM size: %d\n", rv); |
| 38 | return rv; |
| 39 | } |
| 40 | debug("SDRAM base=%lx, size=%x\n", ram.base, ram.size); |
| 41 | gd->ram_size = ram.size; |
Toshifumi NISHINAGA | 25c1b13 | 2016-07-08 01:02:25 +0900 | [diff] [blame] | 42 | |
| 43 | /* |
| 44 | * Fill in global info with description of SRAM configuration |
| 45 | */ |
| 46 | gd->bd->bi_dram[0].start = CONFIG_SYS_RAM_BASE; |
Vikas Manocha | 2d9c33c | 2017-04-10 15:02:54 -0700 | [diff] [blame] | 47 | gd->bd->bi_dram[0].size = ram.size; |
Toshifumi NISHINAGA | 25c1b13 | 2016-07-08 01:02:25 +0900 | [diff] [blame] | 48 | |
Toshifumi NISHINAGA | 25c1b13 | 2016-07-08 01:02:25 +0900 | [diff] [blame] | 49 | return rv; |
| 50 | } |
| 51 | |
Michael Kurz | b20b70f | 2017-01-22 16:04:27 +0100 | [diff] [blame] | 52 | #ifdef CONFIG_ETH_DESIGNWARE |
Michael Kurz | b20b70f | 2017-01-22 16:04:27 +0100 | [diff] [blame] | 53 | static int stmmac_setup(void) |
| 54 | { |
Michael Kurz | b20b70f | 2017-01-22 16:04:27 +0100 | [diff] [blame] | 55 | clock_setup(SYSCFG_CLOCK_CFG); |
Michael Kurz | b20b70f | 2017-01-22 16:04:27 +0100 | [diff] [blame] | 56 | /* Set >RMII mode */ |
| 57 | STM32_SYSCFG->pmc |= SYSCFG_PMC_MII_RMII_SEL; |
Michael Kurz | b20b70f | 2017-01-22 16:04:27 +0100 | [diff] [blame] | 58 | clock_setup(STMMAC_CLOCK_CFG); |
| 59 | |
| 60 | return 0; |
| 61 | } |
Michael Kurz | b20b70f | 2017-01-22 16:04:27 +0100 | [diff] [blame] | 62 | |
Vikas Manocha | 280057b | 2017-04-10 15:02:59 -0700 | [diff] [blame] | 63 | int board_early_init_f(void) |
Michael Kurz | d4363ba | 2017-01-22 16:04:30 +0100 | [diff] [blame] | 64 | { |
Vikas Manocha | 280057b | 2017-04-10 15:02:59 -0700 | [diff] [blame] | 65 | stmmac_setup(); |
| 66 | |
Michael Kurz | d4363ba | 2017-01-22 16:04:30 +0100 | [diff] [blame] | 67 | return 0; |
| 68 | } |
| 69 | #endif |
| 70 | |
Vikas Manocha | e66c49f | 2016-02-11 15:47:20 -0800 | [diff] [blame] | 71 | u32 get_board_rev(void) |
| 72 | { |
| 73 | return 0; |
| 74 | } |
| 75 | |
Vikas Manocha | 2f80a9f | 2017-04-10 15:03:00 -0700 | [diff] [blame^] | 76 | int board_late_init(void) |
| 77 | { |
| 78 | struct gpio_desc gpio = {}; |
| 79 | int node; |
| 80 | |
| 81 | node = fdt_node_offset_by_compatible(gd->fdt_blob, 0, "st,led1"); |
| 82 | if (node < 0) |
| 83 | return -1; |
| 84 | |
| 85 | gpio_request_by_name_nodev(gd->fdt_blob, node, "led-gpio", 0, &gpio, |
| 86 | GPIOD_IS_OUT); |
| 87 | |
| 88 | if (dm_gpio_is_valid(&gpio)) { |
| 89 | dm_gpio_set_value(&gpio, 0); |
| 90 | mdelay(10); |
| 91 | dm_gpio_set_value(&gpio, 1); |
| 92 | } |
| 93 | |
| 94 | /* read button 1*/ |
| 95 | node = fdt_node_offset_by_compatible(gd->fdt_blob, 0, "st,button1"); |
| 96 | if (node < 0) |
| 97 | return -1; |
| 98 | |
| 99 | gpio_request_by_name_nodev(gd->fdt_blob, node, "button-gpio", 0, &gpio, |
| 100 | GPIOD_IS_IN); |
| 101 | |
| 102 | if (dm_gpio_is_valid(&gpio)) { |
| 103 | if (dm_gpio_get_value(&gpio)) |
| 104 | puts("usr button is at HIGH LEVEL\n"); |
| 105 | else |
| 106 | puts("usr button is at LOW LEVEL\n"); |
| 107 | } |
| 108 | |
| 109 | return 0; |
| 110 | } |
| 111 | |
Vikas Manocha | e66c49f | 2016-02-11 15:47:20 -0800 | [diff] [blame] | 112 | int board_init(void) |
| 113 | { |
| 114 | gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100; |
| 115 | |
| 116 | return 0; |
| 117 | } |