From 71f2700b92ab6e419741dc81c27d77cddfaab45f Mon Sep 17 00:00:00 2001 From: Ley Foon Tan Date: Thu, 16 Aug 2018 13:46:30 +0800 Subject: [PATCH 1/7] gpio: dwapb_gpio: Enable get_function support Enabled get_function support for dwapb where the function will return the state of GPIO port. Signed-off-by: Chin Liang See Signed-off-by: Ley Foon Tan --- drivers/gpio/dwapb_gpio.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/gpio/dwapb_gpio.c b/drivers/gpio/dwapb_gpio.c index a118f58..e7e9b1e 100644 --- a/drivers/gpio/dwapb_gpio.c +++ b/drivers/gpio/dwapb_gpio.c @@ -78,11 +78,25 @@ static int dwapb_gpio_set_value(struct udevice *dev, unsigned pin, int val) return 0; } +static int dwapb_gpio_get_function(struct udevice *dev, unsigned offset) +{ + struct gpio_dwapb_platdata *plat = dev_get_platdata(dev); + u32 gpio; + + gpio = readl(plat->base + GPIO_SWPORT_DDR(plat->bank)); + + if (gpio & BIT(offset)) + return GPIOF_OUTPUT; + else + return GPIOF_INPUT; +} + static const struct dm_gpio_ops gpio_dwapb_ops = { .direction_input = dwapb_gpio_direction_input, .direction_output = dwapb_gpio_direction_output, .get_value = dwapb_gpio_get_value, .set_value = dwapb_gpio_set_value, + .get_function = dwapb_gpio_get_function, }; static int gpio_dwapb_probe(struct udevice *dev) From db6a158bc3fbf44fa71d18bf92f48961a500b4cc Mon Sep 17 00:00:00 2001 From: Ley Foon Tan Date: Tue, 4 Sep 2018 14:04:58 +0800 Subject: [PATCH 2/7] gpio: dwapb_gpio: Add reset ctrl to driver Add code to reset all reset signals as in gpio DT node. A reset property is an optional feature, so only print out a warning and do not fail if a reset property is not present. If a reset property is discovered, then use it to deassert, thus bringing the IP out of reset. Signed-off-by: Ley Foon Tan --- drivers/gpio/dwapb_gpio.c | 51 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/drivers/gpio/dwapb_gpio.c b/drivers/gpio/dwapb_gpio.c index e7e9b1e..3f6f2e8 100644 --- a/drivers/gpio/dwapb_gpio.c +++ b/drivers/gpio/dwapb_gpio.c @@ -15,6 +15,7 @@ #include #include #include +#include DECLARE_GLOBAL_DATA_PTR; @@ -29,6 +30,10 @@ DECLARE_GLOBAL_DATA_PTR; #define GPIO_PORTA_EOI 0x4c #define GPIO_EXT_PORT(p) (0x50 + (p) * 4) +struct gpio_dwapb_priv { + struct reset_ctl_bulk resets; +}; + struct gpio_dwapb_platdata { const char *name; int bank; @@ -99,13 +104,42 @@ static const struct dm_gpio_ops gpio_dwapb_ops = { .get_function = dwapb_gpio_get_function, }; +static int gpio_dwapb_reset(struct udevice *dev) +{ + int ret; + struct gpio_dwapb_priv *priv = dev_get_priv(dev); + + ret = reset_get_bulk(dev, &priv->resets); + if (ret) { + /* Return 0 if error due to !CONFIG_DM_RESET and reset + * DT property is not present. + */ + if (ret == -ENOENT || ret == -ENOTSUPP) + return 0; + + dev_warn(dev, "Can't get reset: %d\n", ret); + return ret; + } + + ret = reset_deassert_bulk(&priv->resets); + if (ret) { + reset_release_bulk(&priv->resets); + dev_err(dev, "Failed to reset: %d\n", ret); + return ret; + } + + return 0; +} + static int gpio_dwapb_probe(struct udevice *dev) { struct gpio_dev_priv *priv = dev_get_uclass_priv(dev); struct gpio_dwapb_platdata *plat = dev->platdata; - if (!plat) - return 0; + if (!plat) { + /* Reset on parent device only */ + return gpio_dwapb_reset(dev); + } priv->gpio_count = plat->pins; priv->bank_name = plat->name; @@ -166,6 +200,17 @@ err: return ret; } +static int gpio_dwapb_remove(struct udevice *dev) +{ + struct gpio_dwapb_platdata *plat = dev_get_platdata(dev); + struct gpio_dwapb_priv *priv = dev_get_priv(dev); + + if (!plat && priv) + return reset_release_bulk(&priv->resets); + + return 0; +} + static const struct udevice_id gpio_dwapb_ids[] = { { .compatible = "snps,dw-apb-gpio" }, { } @@ -178,4 +223,6 @@ U_BOOT_DRIVER(gpio_dwapb) = { .ops = &gpio_dwapb_ops, .bind = gpio_dwapb_bind, .probe = gpio_dwapb_probe, + .remove = gpio_dwapb_remove, + .priv_auto_alloc_size = sizeof(struct gpio_dwapb_priv), }; From 9ea354444d156b1f7c1d1990a32215c257b38e16 Mon Sep 17 00:00:00 2001 From: Ley Foon Tan Date: Thu, 16 Aug 2018 02:05:54 +0800 Subject: [PATCH 3/7] gpio: dwapb_gpio: Change to use dev_read_addr() This changes the driver to use dev_read_addr() which is safe both for flat trees and live trees. Signed-off-by: Ley Foon Tan --- drivers/gpio/dwapb_gpio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpio/dwapb_gpio.c b/drivers/gpio/dwapb_gpio.c index 3f6f2e8..0f6574d 100644 --- a/drivers/gpio/dwapb_gpio.c +++ b/drivers/gpio/dwapb_gpio.c @@ -159,7 +159,7 @@ static int gpio_dwapb_bind(struct udevice *dev) if (plat) return 0; - base = fdtdec_get_addr(blob, dev_of_offset(dev), "reg"); + base = dev_read_addr(dev); if (base == FDT_ADDR_T_NONE) { debug("Can't get the GPIO register base address\n"); return -ENXIO; From 2ff60af605d64218374dbaf71cf47be865f84192 Mon Sep 17 00:00:00 2001 From: Dalon Westergreen Date: Mon, 10 Sep 2018 10:28:47 -0700 Subject: [PATCH 4/7] common: add spl/u-boot-spl.hex target Some devices, namely Intel's stratix10 SoC, require u-boot-spl in a hex format. This patch adds spl/u-boot-spl.hex as a possible target. Signed-off-by: Dalon Westergreen --- Makefile | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Makefile b/Makefile index 1891c3a..e38966e 100644 --- a/Makefile +++ b/Makefile @@ -985,6 +985,11 @@ spl/u-boot-spl.srec: spl/u-boot-spl FORCE OBJCOPYFLAGS_u-boot-nodtb.bin := -O binary \ $(if $(CONFIG_X86_16BIT_INIT),-R .start16 -R .resetvec) +OBJCOPYFLAGS_u-boot-spl.hex = $(OBJCOPYFLAGS_u-boot.hex) + +spl/u-boot-spl.hex: spl/u-boot-spl FORCE + $(call if_changed,objcopy) + binary_size_check: u-boot-nodtb.bin FORCE @file_size=$(shell wc -c u-boot-nodtb.bin | awk '{print $$1}') ; \ map_size=$(shell cat u-boot.map | \ From 3570469742aec30fed0b423708df346176fa9438 Mon Sep 17 00:00:00 2001 From: Dalon Westergreen Date: Mon, 10 Sep 2018 10:28:48 -0700 Subject: [PATCH 5/7] arm: socfpga: stratix10: add CONFIG_SPL_TARGET Stratix10 combines the u-boot-spl image into the fpga configuration bitstream so that the SDM can load the processors memory. This process requires a hex format of the u-boot-spl image. CONFIG_SPL_TARGET is set to "spl/u-boot-spl.hex" Signed-off-by: Dalon Westergreen --- include/configs/socfpga_stratix10_socdk.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/configs/socfpga_stratix10_socdk.h b/include/configs/socfpga_stratix10_socdk.h index b58f478..91315a0 100644 --- a/include/configs/socfpga_stratix10_socdk.h +++ b/include/configs/socfpga_stratix10_socdk.h @@ -202,6 +202,7 @@ unsigned int cm_get_l4_sys_free_clk_hz(void); * 0x8000_0000 ...... End of SDRAM_1 (assume 2GB) * */ +#define CONFIG_SPL_TARGET "spl/u-boot-spl.hex" #define CONFIG_SPL_TEXT_BASE CONFIG_SYS_INIT_RAM_ADDR #define CONFIG_SPL_MAX_SIZE CONFIG_SYS_INIT_RAM_SIZE #define CONFIG_SPL_STACK CONFIG_SYS_INIT_SP_ADDR From 02d8d3259133ea7af6031e4a780bdac1462ae057 Mon Sep 17 00:00:00 2001 From: Dalon Westergreen Date: Tue, 11 Sep 2018 10:06:14 -0700 Subject: [PATCH 6/7] socfpga: stratix10: fix sdram_calculate_size Incorrect type of size variable results in 0 being returned for sdram sizes greater than or equal to 4GB. Signed-off-by: Dalon Westergreen --- arch/arm/mach-socfpga/include/mach/sdram_s10.h | 2 +- drivers/ddr/altera/sdram_s10.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/arm/mach-socfpga/include/mach/sdram_s10.h b/arch/arm/mach-socfpga/include/mach/sdram_s10.h index 91bfc0e..ca68594 100644 --- a/arch/arm/mach-socfpga/include/mach/sdram_s10.h +++ b/arch/arm/mach-socfpga/include/mach/sdram_s10.h @@ -7,7 +7,7 @@ #ifndef _SDRAM_S10_H_ #define _SDRAM_S10_H_ -unsigned long sdram_calculate_size(void); +phys_size_t sdram_calculate_size(void); int sdram_mmr_init_full(unsigned int sdr_phy_reg); int sdram_calibration_full(void); diff --git a/drivers/ddr/altera/sdram_s10.c b/drivers/ddr/altera/sdram_s10.c index 48f4f47..a48567c 100644 --- a/drivers/ddr/altera/sdram_s10.c +++ b/drivers/ddr/altera/sdram_s10.c @@ -371,11 +371,11 @@ int sdram_mmr_init_full(unsigned int unused) * Calculate SDRAM device size based on SDRAM controller parameters. * Size is specified in bytes. */ -unsigned long sdram_calculate_size(void) +phys_size_t sdram_calculate_size(void) { u32 dramaddrw = hmc_readl(DRAMADDRW); - u32 size = 1 << (DRAMADDRW_CFG_CS_ADDR_WIDTH(dramaddrw) + + phys_size_t size = 1 << (DRAMADDRW_CFG_CS_ADDR_WIDTH(dramaddrw) + DRAMADDRW_CFG_BANK_GRP_ADDR_WIDTH(dramaddrw) + DRAMADDRW_CFG_BANK_ADDR_WIDTH(dramaddrw) + DRAMADDRW_CFG_ROW_ADDR_WIDTH(dramaddrw) + From f6d600b39bfc9a9402bcb393e706407b109d00e7 Mon Sep 17 00:00:00 2001 From: Dalon Westergreen Date: Tue, 11 Sep 2018 17:25:00 -0700 Subject: [PATCH 7/7] arm: socfpga: stratix10: Add CONFIG_OF_EMBED The dtb should be embedded in the u-boot-spl image so that the CONFIG_SPL_TARGET of spl/u-boot-spl.hex includes it. This also affects the main u-boot image, so adjust CONFIG_SPL_FS_LOAD_PAYLOAD_NAME to u-boot.img which now also includes the dtb. Signed-off-by: Dalon Westergreen --- configs/socfpga_stratix10_defconfig | 1 + include/configs/socfpga_stratix10_socdk.h | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/configs/socfpga_stratix10_defconfig b/configs/socfpga_stratix10_defconfig index c27985a..5f3d733 100644 --- a/configs/socfpga_stratix10_defconfig +++ b/configs/socfpga_stratix10_defconfig @@ -26,6 +26,7 @@ CONFIG_CMD_CACHE=y CONFIG_CMD_EXT4=y CONFIG_CMD_FAT=y CONFIG_CMD_FS_GENERIC=y +CONFIG_OF_EMBED=y CONFIG_DEFAULT_DEVICE_TREE="socfpga_stratix10_socdk" CONFIG_ENV_IS_IN_MMC=y CONFIG_NET_RANDOM_ETHADDR=y diff --git a/include/configs/socfpga_stratix10_socdk.h b/include/configs/socfpga_stratix10_socdk.h index 91315a0..e190b3d 100644 --- a/include/configs/socfpga_stratix10_socdk.h +++ b/include/configs/socfpga_stratix10_socdk.h @@ -216,6 +216,6 @@ unsigned int cm_get_l4_sys_free_clk_hz(void); /* SPL SDMMC boot support */ #define CONFIG_SYS_MMCSD_FS_BOOT_PARTITION 1 -#define CONFIG_SPL_FS_LOAD_PAYLOAD_NAME "u-boot-dtb.img" +#define CONFIG_SPL_FS_LOAD_PAYLOAD_NAME "u-boot.img" #endif /* __CONFIG_H */