From patchwork Mon Jul 29 12:42:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sagar Shrikant Kadam X-Patchwork-Id: 1138346 X-Patchwork-Delegate: uboot@andestech.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=sifive.com header.i=@sifive.com header.b="mQanFwGV"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 45xzr53Q9Nz9s7T for ; Mon, 29 Jul 2019 22:43:17 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 2B64DC21E1B; Mon, 29 Jul 2019 12:43:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id EB6CDC21E50; Mon, 29 Jul 2019 12:43:08 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 92F02C21DA2; Mon, 29 Jul 2019 12:42:58 +0000 (UTC) Received: from mail-pf1-f196.google.com (mail-pf1-f196.google.com [209.85.210.196]) by lists.denx.de (Postfix) with ESMTPS id 6C4A9C21E02 for ; Mon, 29 Jul 2019 12:42:54 +0000 (UTC) Received: by mail-pf1-f196.google.com with SMTP id b13so27986849pfo.1 for ; Mon, 29 Jul 2019 05:42:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=WgEG4zYyyI2yiVcpLBctSnH4D8mwh00WeEcMizOvObw=; b=mQanFwGVE8gAP5wbQOjo68OaXXJQ9HbKK9WtnLzGsRAPa1ES5oUqnAX1Hnodv/Jgbg H0V3ouqPH71G/kFUr4dt/rI/eWa8Ybk6/tgvkARkHNNhQgSpddL+9GjS8gl5hTZiiQXn KwVGMEcsr1Tl8NG2GVleWcxmpeMZwosP0TSw3sA8B9pF76w0Bs5U42l+uppT67wmrmd6 O3huYlcY7EWOe1DPUqYpjlRXErkTpvx+iYByc/J5fl9FUU340fhtaQL0ViB4tj1Vlq9x Lm5NqrWEQOUkATqZDX4MFy0Ypyg/zQZKqSGTMNMirFnAJoyNaNLh+ahewCo+lSWPCo/b /qgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=WgEG4zYyyI2yiVcpLBctSnH4D8mwh00WeEcMizOvObw=; b=VkkDWS0gTNOqMJd0Fhbtx6Kom/I8BulCDDMddTjFk5mYvQv7WlrYUxfZqYb1cvgKof 2lv5Z6gqslaCkQwmfq7KCHJNKWXolQXb3Q9614AkYtliHuZDAB5ZrCwdtM5JPtVPhK50 M3DBjHn+fQMMTURwSabZswAtT9fNadIDwkaUr/+2H09sCZN/717q2C+HyShbjcjeJsDY pWixb9A7pVBTqx7sK7hz10eEwFITvgvFdr5lwEfkgYvZx3qWLXOjlni00W56rOh6xqq0 2Vbb2iDw69utb8cxL4CFlJIcjnXQ07IxfTSOCIvI2/w/TVyeozfRjWHxdE8I2DhlqU1Z mSMw== X-Gm-Message-State: APjAAAVbCEZbWx5RKtF+CxODPFb4fxgOKkDz+U9dMZZpC9wsdKXXMSWT 3lN7GJHcj+A1WdwvC7uEDh9xvtOnJO0= X-Google-Smtp-Source: APXvYqx2uhUzHlVqX3KQy/3kQIpzC4uOcdF0BY2D4iK/KAwO+mtuNAfUTvxVEOmxjpBnsmmtVXEJxw== X-Received: by 2002:a62:28b:: with SMTP id 133mr36218066pfc.251.1564404172438; Mon, 29 Jul 2019 05:42:52 -0700 (PDT) Received: from gamma07.internal.sifive.com ([64.62.193.194]) by smtp.googlemail.com with ESMTPSA id z12sm43044282pfn.29.2019.07.29.05.42.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 29 Jul 2019 05:42:52 -0700 (PDT) From: Sagar Shrikant Kadam To: u-boot@lists.denx.de, rick@andestech.com, paul.walmsley@sifive.com, palmer@sifive.com, anup.patel@wdc.com, atish.patra@wdc.com Date: Mon, 29 Jul 2019 05:42:25 -0700 Message-Id: <1564404146-8903-2-git-send-email-sagar.kadam@sifive.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1564404146-8903-1-git-send-email-sagar.kadam@sifive.com> References: <1564404146-8903-1-git-send-email-sagar.kadam@sifive.com> Subject: [U-Boot] [PATCH] sifive: riscv: update Hifive Unleashed configuration infrastructure X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" This patch aligns the current implementation of HiFive Unleashed board configuration framework with the one described in doc/README.kconfig. Signed-off-by: Sagar Shrikant Kadam --- arch/riscv/Kconfig | 6 +- arch/riscv/cpu/generic/Kconfig | 12 --- arch/riscv/cpu/generic/Makefile | 6 -- arch/riscv/cpu/generic/cpu.c | 35 ------- arch/riscv/cpu/generic/dram.c | 37 ------- arch/riscv/cpu/u54-mc/Kconfig | 12 +++ arch/riscv/cpu/u54-mc/Makefile | 6 ++ arch/riscv/cpu/u54-mc/cpu.c | 35 +++++++ arch/riscv/cpu/u54-mc/dram.c | 37 +++++++ arch/riscv/include/asm/arch-fu540-c000/clk.h | 14 +++ arch/riscv/include/asm/arch-generic/clk.h | 14 --- board/sifive/fu540/Kconfig | 49 ---------- board/sifive/fu540/MAINTAINERS | 9 -- board/sifive/fu540/Makefile | 5 - board/sifive/fu540/fu540.c | 139 --------------------------- board/sifive/hifive_unleashed/Kconfig | 52 ++++++++++ board/sifive/hifive_unleashed/MAINTAINERS | 9 ++ board/sifive/hifive_unleashed/Makefile | 5 + board/sifive/hifive_unleashed/fu540.c | 139 +++++++++++++++++++++++++++ configs/hifive_unleashed_defconfig | 11 +++ configs/sifive_fu540_defconfig | 11 --- include/configs/hifive_unleashed.h | 47 +++++++++ include/configs/sifive-fu540.h | 47 --------- 23 files changed, 370 insertions(+), 367 deletions(-) delete mode 100644 arch/riscv/cpu/generic/Kconfig delete mode 100644 arch/riscv/cpu/generic/Makefile delete mode 100644 arch/riscv/cpu/generic/cpu.c delete mode 100644 arch/riscv/cpu/generic/dram.c create mode 100644 arch/riscv/cpu/u54-mc/Kconfig create mode 100644 arch/riscv/cpu/u54-mc/Makefile create mode 100644 arch/riscv/cpu/u54-mc/cpu.c create mode 100644 arch/riscv/cpu/u54-mc/dram.c create mode 100644 arch/riscv/include/asm/arch-fu540-c000/clk.h delete mode 100644 arch/riscv/include/asm/arch-generic/clk.h delete mode 100644 board/sifive/fu540/Kconfig delete mode 100644 board/sifive/fu540/MAINTAINERS delete mode 100644 board/sifive/fu540/Makefile delete mode 100644 board/sifive/fu540/fu540.c create mode 100644 board/sifive/hifive_unleashed/Kconfig create mode 100644 board/sifive/hifive_unleashed/MAINTAINERS create mode 100644 board/sifive/hifive_unleashed/Makefile create mode 100644 board/sifive/hifive_unleashed/fu540.c create mode 100644 configs/hifive_unleashed_defconfig delete mode 100644 configs/sifive_fu540_defconfig create mode 100644 include/configs/hifive_unleashed.h delete mode 100644 include/configs/sifive-fu540.h diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 8cfc7d0..82891fd 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -17,7 +17,7 @@ config TARGET_MICROCHIP_ICICLE config TARGET_QEMU_VIRT bool "Support QEMU Virt Board" -config TARGET_SIFIVE_FU540 +config TARGET_SIFIVE_HIFIVE_UNLEASHED bool "Support SiFive FU540 Board" endchoice @@ -52,11 +52,11 @@ config SPL_SYS_DCACHE_OFF source "board/AndesTech/ax25-ae350/Kconfig" source "board/emulation/qemu-riscv/Kconfig" source "board/microchip/mpfs_icicle/Kconfig" -source "board/sifive/fu540/Kconfig" +source "board/sifive/hifive_unleashed/Kconfig" # platform-specific options below source "arch/riscv/cpu/ax25/Kconfig" -source "arch/riscv/cpu/generic/Kconfig" +source "arch/riscv/cpu/u54-mc/Kconfig" # architecture-specific options below diff --git a/arch/riscv/cpu/generic/Kconfig b/arch/riscv/cpu/generic/Kconfig deleted file mode 100644 index 1d6ab50..0000000 --- a/arch/riscv/cpu/generic/Kconfig +++ /dev/null @@ -1,12 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0+ -# -# Copyright (C) 2018, Bin Meng - -config GENERIC_RISCV - bool - select ARCH_EARLY_INIT_R - imply CPU - imply CPU_RISCV - imply RISCV_TIMER - imply SIFIVE_CLINT if RISCV_MMODE - imply CMD_CPU diff --git a/arch/riscv/cpu/generic/Makefile b/arch/riscv/cpu/generic/Makefile deleted file mode 100644 index 258e462..0000000 --- a/arch/riscv/cpu/generic/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0+ -# -# Copyright (C) 2018, Bin Meng - -obj-y += dram.o -obj-y += cpu.o diff --git a/arch/riscv/cpu/generic/cpu.c b/arch/riscv/cpu/generic/cpu.c deleted file mode 100644 index ad2950c..0000000 --- a/arch/riscv/cpu/generic/cpu.c +++ /dev/null @@ -1,35 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * Copyright (C) 2018, Bin Meng - */ - -#include -#include - -/* - * cleanup_before_linux() is called just before we call linux - * it prepares the processor for linux - * - * we disable interrupt and caches. - */ -int cleanup_before_linux(void) -{ - disable_interrupts(); - - cache_flush(); - - return 0; -} - -/* To enumerate devices on the /soc/ node, create a "simple-bus" driver */ -static const struct udevice_id riscv_virtio_soc_ids[] = { - { .compatible = "riscv-virtio-soc" }, - { } -}; - -U_BOOT_DRIVER(riscv_virtio_soc) = { - .name = "riscv_virtio_soc", - .id = UCLASS_SIMPLE_BUS, - .of_match = riscv_virtio_soc_ids, - .flags = DM_FLAG_PRE_RELOC, -}; diff --git a/arch/riscv/cpu/generic/dram.c b/arch/riscv/cpu/generic/dram.c deleted file mode 100644 index b7b1207..0000000 --- a/arch/riscv/cpu/generic/dram.c +++ /dev/null @@ -1,37 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * Copyright (C) 2018, Bin Meng - */ - -#include -#include -#include - -DECLARE_GLOBAL_DATA_PTR; - -int dram_init(void) -{ - return fdtdec_setup_mem_size_base(); -} - -int dram_init_banksize(void) -{ - return fdtdec_setup_memory_banksize(); -} - -ulong board_get_usable_ram_top(ulong total_size) -{ -#ifdef CONFIG_64BIT - /* - * Ensure that we run from first 4GB so that all - * addresses used by U-Boot are 32bit addresses. - * - * This in-turn ensures that 32bit DMA capable - * devices work fine because DMA mapping APIs will - * provide 32bit DMA addresses only. - */ - if (gd->ram_top > SZ_4G) - return SZ_4G; -#endif - return gd->ram_top; -} diff --git a/arch/riscv/cpu/u54-mc/Kconfig b/arch/riscv/cpu/u54-mc/Kconfig new file mode 100644 index 0000000..60189a7 --- /dev/null +++ b/arch/riscv/cpu/u54-mc/Kconfig @@ -0,0 +1,12 @@ +# SPDX-License-Identifier: GPL-2.0+ +# +# Copyright (C) 2018, Bin Meng + +config U54_MC_RISCV + bool + select ARCH_EARLY_INIT_R + imply CPU + imply CPU_RISCV + imply RISCV_TIMER + imply SIFIVE_CLINT if RISCV_MMODE + imply CMD_CPU diff --git a/arch/riscv/cpu/u54-mc/Makefile b/arch/riscv/cpu/u54-mc/Makefile new file mode 100644 index 0000000..258e462 --- /dev/null +++ b/arch/riscv/cpu/u54-mc/Makefile @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0+ +# +# Copyright (C) 2018, Bin Meng + +obj-y += dram.o +obj-y += cpu.o diff --git a/arch/riscv/cpu/u54-mc/cpu.c b/arch/riscv/cpu/u54-mc/cpu.c new file mode 100644 index 0000000..ad2950c --- /dev/null +++ b/arch/riscv/cpu/u54-mc/cpu.c @@ -0,0 +1,35 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2018, Bin Meng + */ + +#include +#include + +/* + * cleanup_before_linux() is called just before we call linux + * it prepares the processor for linux + * + * we disable interrupt and caches. + */ +int cleanup_before_linux(void) +{ + disable_interrupts(); + + cache_flush(); + + return 0; +} + +/* To enumerate devices on the /soc/ node, create a "simple-bus" driver */ +static const struct udevice_id riscv_virtio_soc_ids[] = { + { .compatible = "riscv-virtio-soc" }, + { } +}; + +U_BOOT_DRIVER(riscv_virtio_soc) = { + .name = "riscv_virtio_soc", + .id = UCLASS_SIMPLE_BUS, + .of_match = riscv_virtio_soc_ids, + .flags = DM_FLAG_PRE_RELOC, +}; diff --git a/arch/riscv/cpu/u54-mc/dram.c b/arch/riscv/cpu/u54-mc/dram.c new file mode 100644 index 0000000..b7b1207 --- /dev/null +++ b/arch/riscv/cpu/u54-mc/dram.c @@ -0,0 +1,37 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2018, Bin Meng + */ + +#include +#include +#include + +DECLARE_GLOBAL_DATA_PTR; + +int dram_init(void) +{ + return fdtdec_setup_mem_size_base(); +} + +int dram_init_banksize(void) +{ + return fdtdec_setup_memory_banksize(); +} + +ulong board_get_usable_ram_top(ulong total_size) +{ +#ifdef CONFIG_64BIT + /* + * Ensure that we run from first 4GB so that all + * addresses used by U-Boot are 32bit addresses. + * + * This in-turn ensures that 32bit DMA capable + * devices work fine because DMA mapping APIs will + * provide 32bit DMA addresses only. + */ + if (gd->ram_top > SZ_4G) + return SZ_4G; +#endif + return gd->ram_top; +} diff --git a/arch/riscv/include/asm/arch-fu540-c000/clk.h b/arch/riscv/include/asm/arch-fu540-c000/clk.h new file mode 100644 index 0000000..1631f5f --- /dev/null +++ b/arch/riscv/include/asm/arch-fu540-c000/clk.h @@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright (c) 2019 Western Digital Corporation or its affiliates. + * + * Authors: + * Anup Patel + */ + +#ifndef __ASM_RISCV_ARCH_CLK_H +#define __ASM_RISCV_ARCH_CLK_H + +/* Note: This is a placeholder header for driver compilation. */ + +#endif diff --git a/arch/riscv/include/asm/arch-generic/clk.h b/arch/riscv/include/asm/arch-generic/clk.h deleted file mode 100644 index 1631f5f..0000000 --- a/arch/riscv/include/asm/arch-generic/clk.h +++ /dev/null @@ -1,14 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0+ */ -/* - * Copyright (c) 2019 Western Digital Corporation or its affiliates. - * - * Authors: - * Anup Patel - */ - -#ifndef __ASM_RISCV_ARCH_CLK_H -#define __ASM_RISCV_ARCH_CLK_H - -/* Note: This is a placeholder header for driver compilation. */ - -#endif diff --git a/board/sifive/fu540/Kconfig b/board/sifive/fu540/Kconfig deleted file mode 100644 index 5d65080..0000000 --- a/board/sifive/fu540/Kconfig +++ /dev/null @@ -1,49 +0,0 @@ -if TARGET_SIFIVE_FU540 - -config SYS_BOARD - default "fu540" - -config SYS_VENDOR - default "sifive" - -config SYS_CPU - default "generic" - -config SYS_CONFIG_NAME - default "sifive-fu540" - -config SYS_TEXT_BASE - default 0x80000000 if !RISCV_SMODE - default 0x80200000 if RISCV_SMODE - -config BOARD_SPECIFIC_OPTIONS # dummy - def_bool y - select GENERIC_RISCV - imply CMD_DHCP - imply CMD_EXT2 - imply CMD_EXT4 - imply CMD_FAT - imply CMD_FS_GENERIC - imply CMD_NET - imply CMD_PING - imply CLK_SIFIVE - imply CLK_SIFIVE_FU540_PRCI - imply DOS_PARTITION - imply EFI_PARTITION - imply IP_DYN - imply ISO_PARTITION - imply MACB - imply MII - imply NET_RANDOM_ETHADDR - imply PHY_LIB - imply PHY_MSCC - imply SIFIVE_SERIAL - imply SPI - imply SPI_SIFIVE - imply MMC - imply MMC_SPI - imply MMC_BROKEN_CD - imply CMD_MMC - imply SMP - -endif diff --git a/board/sifive/fu540/MAINTAINERS b/board/sifive/fu540/MAINTAINERS deleted file mode 100644 index 702d803..0000000 --- a/board/sifive/fu540/MAINTAINERS +++ /dev/null @@ -1,9 +0,0 @@ -SiFive FU540 BOARD -M: Paul Walmsley -M: Palmer Dabbelt -M: Anup Patel -M: Atish Patra -S: Maintained -F: board/sifive/fu540/ -F: include/configs/sifive-fu540.h -F: configs/sifive_fu540_defconfig diff --git a/board/sifive/fu540/Makefile b/board/sifive/fu540/Makefile deleted file mode 100644 index 6e1862c..0000000 --- a/board/sifive/fu540/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0+ -# -# Copyright (c) 2019 Western Digital Corporation or its affiliates. - -obj-y += fu540.o diff --git a/board/sifive/fu540/fu540.c b/board/sifive/fu540/fu540.c deleted file mode 100644 index 11daf1a..0000000 --- a/board/sifive/fu540/fu540.c +++ /dev/null @@ -1,139 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * Copyright (c) 2019 Western Digital Corporation or its affiliates. - * - * Authors: - * Anup Patel - */ - -#include -#include -#include -#include - -#ifdef CONFIG_MISC_INIT_R - -#define FU540_OTP_BASE_ADDR 0x10070000 - -struct fu540_otp_regs { - u32 pa; /* Address input */ - u32 paio; /* Program address input */ - u32 pas; /* Program redundancy cell selection input */ - u32 pce; /* OTP Macro enable input */ - u32 pclk; /* Clock input */ - u32 pdin; /* Write data input */ - u32 pdout; /* Read data output */ - u32 pdstb; /* Deep standby mode enable input (active low) */ - u32 pprog; /* Program mode enable input */ - u32 ptc; /* Test column enable input */ - u32 ptm; /* Test mode enable input */ - u32 ptm_rep;/* Repair function test mode enable input */ - u32 ptr; /* Test row enable input */ - u32 ptrim; /* Repair function enable input */ - u32 pwe; /* Write enable input (defines program cycle) */ -} __packed; - -#define BYTES_PER_FUSE 4 -#define NUM_FUSES 0x1000 - -static int fu540_otp_read(int offset, void *buf, int size) -{ - struct fu540_otp_regs *regs = (void __iomem *)FU540_OTP_BASE_ADDR; - unsigned int i; - int fuseidx = offset / BYTES_PER_FUSE; - int fusecount = size / BYTES_PER_FUSE; - u32 fusebuf[fusecount]; - - /* check bounds */ - if (offset < 0 || size < 0) - return -EINVAL; - if (fuseidx >= NUM_FUSES) - return -EINVAL; - if ((fuseidx + fusecount) > NUM_FUSES) - return -EINVAL; - - /* init OTP */ - writel(0x01, ®s->pdstb); /* wake up from stand-by */ - writel(0x01, ®s->ptrim); /* enable repair function */ - writel(0x01, ®s->pce); /* enable input */ - - /* read all requested fuses */ - for (i = 0; i < fusecount; i++, fuseidx++) { - writel(fuseidx, ®s->pa); - - /* cycle clock to read */ - writel(0x01, ®s->pclk); - mdelay(1); - writel(0x00, ®s->pclk); - mdelay(1); - - /* read the value */ - fusebuf[i] = readl(®s->pdout); - } - - /* shut down */ - writel(0, ®s->pce); - writel(0, ®s->ptrim); - writel(0, ®s->pdstb); - - /* copy out */ - memcpy(buf, fusebuf, size); - - return 0; -} - -static u32 fu540_read_serialnum(void) -{ - int ret; - u32 serial[2] = {0}; - - for (int i = 0xfe * 4; i > 0; i -= 8) { - ret = fu540_otp_read(i, serial, sizeof(serial)); - if (ret) { - printf("%s: error reading from OTP\n", __func__); - break; - } - if (serial[0] == ~serial[1]) - return serial[0]; - } - - return 0; -} - -static void fu540_setup_macaddr(u32 serialnum) -{ - /* Default MAC address */ - unsigned char mac[6] = { 0x70, 0xb3, 0xd5, 0x92, 0xf0, 0x00 }; - - /* - * We derive our board MAC address by ORing last three bytes - * of board serial number to above default MAC address. - * - * This logic of deriving board MAC address is taken from - * SiFive FSBL and is kept unchanged. - */ - mac[5] |= (serialnum >> 0) & 0xff; - mac[4] |= (serialnum >> 8) & 0xff; - mac[3] |= (serialnum >> 16) & 0xff; - - /* Update environment variable */ - eth_env_set_enetaddr("ethaddr", mac); -} - -int misc_init_r(void) -{ - /* Set ethaddr environment variable if not set */ - if (!env_get("ethaddr")) - fu540_setup_macaddr(fu540_read_serialnum()); - - return 0; -} - -#endif - -int board_init(void) -{ - /* For now nothing to do here. */ - - return 0; -} diff --git a/board/sifive/hifive_unleashed/Kconfig b/board/sifive/hifive_unleashed/Kconfig new file mode 100644 index 0000000..484b262 --- /dev/null +++ b/board/sifive/hifive_unleashed/Kconfig @@ -0,0 +1,52 @@ +if TARGET_SIFIVE_HIFIVE_UNLEASHED + +config SYS_BOARD + default "hifive_unleashed" + +config SYS_VENDOR + default "sifive" + +config SYS_SOC + default "fu540-c000" + +config SYS_CPU + default "u54-mc" + +config SYS_CONFIG_NAME + default "hifive_unleashed" + +config SYS_TEXT_BASE + default 0x80000000 if !RISCV_SMODE + default 0x80200000 if RISCV_SMODE + +config BOARD_SPECIFIC_OPTIONS # dummy + def_bool y + select U54_MC_RISCV + imply CMD_DHCP + imply CMD_EXT2 + imply CMD_EXT4 + imply CMD_FAT + imply CMD_FS_GENERIC + imply CMD_NET + imply CMD_PING + imply CLK_SIFIVE + imply CLK_SIFIVE_FU540_PRCI + imply DOS_PARTITION + imply EFI_PARTITION + imply IP_DYN + imply ISO_PARTITION + imply MACB + imply MII + imply NET_RANDOM_ETHADDR + imply PHY_LIB + imply PHY_MSCC + imply SIFIVE_SERIAL + imply SPI + imply SPI_SIFIVE + imply MMC + imply MMC_SPI + imply MMC_BROKEN_CD + imply CMD_MMC + imply SMP + +endif diff --git a/board/sifive/hifive_unleashed/MAINTAINERS b/board/sifive/hifive_unleashed/MAINTAINERS new file mode 100644 index 0000000..94539dd --- /dev/null +++ b/board/sifive/hifive_unleashed/MAINTAINERS @@ -0,0 +1,9 @@ +SiFive HIFIVE UNLEASHED BOARD +M: Paul Walmsley +M: Palmer Dabbelt +M: Anup Patel +M: Atish Patra +S: Maintained +F: board/sifive/hifive_unleashed/ +F: include/configs/hifive_unleashed.h +F: configs/hifive_unleashed_defconfig diff --git a/board/sifive/hifive_unleashed/Makefile b/board/sifive/hifive_unleashed/Makefile new file mode 100644 index 0000000..6e1862c --- /dev/null +++ b/board/sifive/hifive_unleashed/Makefile @@ -0,0 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0+ +# +# Copyright (c) 2019 Western Digital Corporation or its affiliates. + +obj-y += fu540.o diff --git a/board/sifive/hifive_unleashed/fu540.c b/board/sifive/hifive_unleashed/fu540.c new file mode 100644 index 0000000..11daf1a --- /dev/null +++ b/board/sifive/hifive_unleashed/fu540.c @@ -0,0 +1,139 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (c) 2019 Western Digital Corporation or its affiliates. + * + * Authors: + * Anup Patel + */ + +#include +#include +#include +#include + +#ifdef CONFIG_MISC_INIT_R + +#define FU540_OTP_BASE_ADDR 0x10070000 + +struct fu540_otp_regs { + u32 pa; /* Address input */ + u32 paio; /* Program address input */ + u32 pas; /* Program redundancy cell selection input */ + u32 pce; /* OTP Macro enable input */ + u32 pclk; /* Clock input */ + u32 pdin; /* Write data input */ + u32 pdout; /* Read data output */ + u32 pdstb; /* Deep standby mode enable input (active low) */ + u32 pprog; /* Program mode enable input */ + u32 ptc; /* Test column enable input */ + u32 ptm; /* Test mode enable input */ + u32 ptm_rep;/* Repair function test mode enable input */ + u32 ptr; /* Test row enable input */ + u32 ptrim; /* Repair function enable input */ + u32 pwe; /* Write enable input (defines program cycle) */ +} __packed; + +#define BYTES_PER_FUSE 4 +#define NUM_FUSES 0x1000 + +static int fu540_otp_read(int offset, void *buf, int size) +{ + struct fu540_otp_regs *regs = (void __iomem *)FU540_OTP_BASE_ADDR; + unsigned int i; + int fuseidx = offset / BYTES_PER_FUSE; + int fusecount = size / BYTES_PER_FUSE; + u32 fusebuf[fusecount]; + + /* check bounds */ + if (offset < 0 || size < 0) + return -EINVAL; + if (fuseidx >= NUM_FUSES) + return -EINVAL; + if ((fuseidx + fusecount) > NUM_FUSES) + return -EINVAL; + + /* init OTP */ + writel(0x01, ®s->pdstb); /* wake up from stand-by */ + writel(0x01, ®s->ptrim); /* enable repair function */ + writel(0x01, ®s->pce); /* enable input */ + + /* read all requested fuses */ + for (i = 0; i < fusecount; i++, fuseidx++) { + writel(fuseidx, ®s->pa); + + /* cycle clock to read */ + writel(0x01, ®s->pclk); + mdelay(1); + writel(0x00, ®s->pclk); + mdelay(1); + + /* read the value */ + fusebuf[i] = readl(®s->pdout); + } + + /* shut down */ + writel(0, ®s->pce); + writel(0, ®s->ptrim); + writel(0, ®s->pdstb); + + /* copy out */ + memcpy(buf, fusebuf, size); + + return 0; +} + +static u32 fu540_read_serialnum(void) +{ + int ret; + u32 serial[2] = {0}; + + for (int i = 0xfe * 4; i > 0; i -= 8) { + ret = fu540_otp_read(i, serial, sizeof(serial)); + if (ret) { + printf("%s: error reading from OTP\n", __func__); + break; + } + if (serial[0] == ~serial[1]) + return serial[0]; + } + + return 0; +} + +static void fu540_setup_macaddr(u32 serialnum) +{ + /* Default MAC address */ + unsigned char mac[6] = { 0x70, 0xb3, 0xd5, 0x92, 0xf0, 0x00 }; + + /* + * We derive our board MAC address by ORing last three bytes + * of board serial number to above default MAC address. + * + * This logic of deriving board MAC address is taken from + * SiFive FSBL and is kept unchanged. + */ + mac[5] |= (serialnum >> 0) & 0xff; + mac[4] |= (serialnum >> 8) & 0xff; + mac[3] |= (serialnum >> 16) & 0xff; + + /* Update environment variable */ + eth_env_set_enetaddr("ethaddr", mac); +} + +int misc_init_r(void) +{ + /* Set ethaddr environment variable if not set */ + if (!env_get("ethaddr")) + fu540_setup_macaddr(fu540_read_serialnum()); + + return 0; +} + +#endif + +int board_init(void) +{ + /* For now nothing to do here. */ + + return 0; +} diff --git a/configs/hifive_unleashed_defconfig b/configs/hifive_unleashed_defconfig new file mode 100644 index 0000000..5a3b421 --- /dev/null +++ b/configs/hifive_unleashed_defconfig @@ -0,0 +1,11 @@ +CONFIG_RISCV=y +CONFIG_NR_DRAM_BANKS=1 +CONFIG_TARGET_SIFIVE_HIFIVE_UNLEASHED=y +CONFIG_ARCH_RV64I=y +CONFIG_RISCV_SMODE=y +CONFIG_DISTRO_DEFAULTS=y +CONFIG_FIT=y +CONFIG_DISPLAY_CPUINFO=y +CONFIG_DISPLAY_BOARDINFO=y +CONFIG_MISC_INIT_R=y +CONFIG_OF_PRIOR_STAGE=y diff --git a/configs/sifive_fu540_defconfig b/configs/sifive_fu540_defconfig deleted file mode 100644 index f192037..0000000 --- a/configs/sifive_fu540_defconfig +++ /dev/null @@ -1,11 +0,0 @@ -CONFIG_RISCV=y -CONFIG_NR_DRAM_BANKS=1 -CONFIG_TARGET_SIFIVE_FU540=y -CONFIG_ARCH_RV64I=y -CONFIG_RISCV_SMODE=y -CONFIG_DISTRO_DEFAULTS=y -CONFIG_FIT=y -CONFIG_DISPLAY_CPUINFO=y -CONFIG_DISPLAY_BOARDINFO=y -CONFIG_MISC_INIT_R=y -CONFIG_OF_PRIOR_STAGE=y diff --git a/include/configs/hifive_unleashed.h b/include/configs/hifive_unleashed.h new file mode 100644 index 0000000..858b7a7 --- /dev/null +++ b/include/configs/hifive_unleashed.h @@ -0,0 +1,47 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright (c) 2019 Western Digital Corporation or its affiliates. + * + * Authors: + * Anup Patel + */ + +#ifndef __CONFIG_H +#define __CONFIG_H + +#include + +#define CONFIG_SYS_SDRAM_BASE 0x80000000 +#define CONFIG_SYS_INIT_SP_ADDR (CONFIG_SYS_SDRAM_BASE + SZ_2M) + +#define CONFIG_SYS_LOAD_ADDR (CONFIG_SYS_SDRAM_BASE + SZ_2M) + +#define CONFIG_SYS_MALLOC_LEN SZ_8M + +#define CONFIG_SYS_BOOTM_LEN SZ_64M + +#define CONFIG_STANDALONE_LOAD_ADDR 0x80200000 + +/* Environment options */ +#define CONFIG_ENV_SIZE SZ_128K + +#define BOOT_TARGET_DEVICES(func) \ + func(DHCP, dhcp, na) + +#include + +#define CONFIG_EXTRA_ENV_SETTINGS \ + "fdt_high=0xffffffffffffffff\0" \ + "initrd_high=0xffffffffffffffff\0" \ + "kernel_addr_r=0x84000000\0" \ + "fdt_addr_r=0x88000000\0" \ + "scriptaddr=0x88100000\0" \ + "pxefile_addr_r=0x88200000\0" \ + "ramdisk_addr_r=0x88300000\0" \ + BOOTENV + +#define CONFIG_PREBOOT \ + "setenv fdt_addr ${fdtcontroladdr};" \ + "fdt addr ${fdtcontroladdr};" + +#endif /* __CONFIG_H */ diff --git a/include/configs/sifive-fu540.h b/include/configs/sifive-fu540.h deleted file mode 100644 index 858b7a7..0000000 --- a/include/configs/sifive-fu540.h +++ /dev/null @@ -1,47 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0+ */ -/* - * Copyright (c) 2019 Western Digital Corporation or its affiliates. - * - * Authors: - * Anup Patel - */ - -#ifndef __CONFIG_H -#define __CONFIG_H - -#include - -#define CONFIG_SYS_SDRAM_BASE 0x80000000 -#define CONFIG_SYS_INIT_SP_ADDR (CONFIG_SYS_SDRAM_BASE + SZ_2M) - -#define CONFIG_SYS_LOAD_ADDR (CONFIG_SYS_SDRAM_BASE + SZ_2M) - -#define CONFIG_SYS_MALLOC_LEN SZ_8M - -#define CONFIG_SYS_BOOTM_LEN SZ_64M - -#define CONFIG_STANDALONE_LOAD_ADDR 0x80200000 - -/* Environment options */ -#define CONFIG_ENV_SIZE SZ_128K - -#define BOOT_TARGET_DEVICES(func) \ - func(DHCP, dhcp, na) - -#include - -#define CONFIG_EXTRA_ENV_SETTINGS \ - "fdt_high=0xffffffffffffffff\0" \ - "initrd_high=0xffffffffffffffff\0" \ - "kernel_addr_r=0x84000000\0" \ - "fdt_addr_r=0x88000000\0" \ - "scriptaddr=0x88100000\0" \ - "pxefile_addr_r=0x88200000\0" \ - "ramdisk_addr_r=0x88300000\0" \ - BOOTENV - -#define CONFIG_PREBOOT \ - "setenv fdt_addr ${fdtcontroladdr};" \ - "fdt addr ${fdtcontroladdr};" - -#endif /* __CONFIG_H */