From patchwork Tue Sep 29 01:28:01 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Chou X-Patchwork-Id: 523682 X-Patchwork-Delegate: thomas@wytron.com.tw Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 4E3B914016A for ; Tue, 29 Sep 2015 11:28:21 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id DA24A4B78D; Tue, 29 Sep 2015 03:28:17 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 4pe4Tq8FmPpF; Tue, 29 Sep 2015 03:28:17 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 2657F4B7AF; Tue, 29 Sep 2015 03:28:17 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id E7DDD4B7AF for ; Tue, 29 Sep 2015 03:28:10 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id KbZ3IwrI4Iiy for ; Tue, 29 Sep 2015 03:28:10 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from www.wytron.com.tw (220-134-43-68.HINET-IP.hinet.net [220.134.43.68]) by theia.denx.de (Postfix) with ESMTP id 214B94B78D for ; Tue, 29 Sep 2015 03:28:06 +0200 (CEST) Received: from localhost.localdomain (unknown [192.168.1.250]) by www.wytron.com.tw (Postfix) with ESMTP id 516E0D002F9; Tue, 29 Sep 2015 09:28:03 +0800 (CST) From: Thomas Chou To: u-boot@lists.denx.de Date: Tue, 29 Sep 2015 09:28:01 +0800 Message-Id: <1443490081-19526-1-git-send-email-thomas@wytron.com.tw> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1443400318-19151-1-git-send-email-thomas@wytron.com.tw> References: <1443400318-19151-1-git-send-email-thomas@wytron.com.tw> Cc: Marek Vasut , clsee@altera.com, lftan@altera.com Subject: [U-Boot] [PATCH v2] nios2: convert nios2 cpu to driver model X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 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" Convert nios2 cpu to driver model. The cpu parameters are extracted from device tree and saved to global data structure. We will use them to replace the custom_fpga.h . Signed-off-by: Thomas Chou --- v2 move cpu param setup to arch_cpu_init_dm, remove probe. arch/Kconfig | 3 ++ arch/nios2/cpu/cpu.c | 76 ++++++++++++++++++++++++++++++++++-- arch/nios2/dts/3c120_devboard.dts | 1 + arch/nios2/include/asm/global_data.h | 8 ++++ configs/nios2-generic_defconfig | 2 - 5 files changed, 85 insertions(+), 5 deletions(-) diff --git a/arch/Kconfig b/arch/Kconfig index 207c778..9be1538 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -64,6 +64,9 @@ config NIOS2 select HAVE_GENERIC_BOARD select SYS_GENERIC_BOARD select SUPPORT_OF_CONTROL + select OF_CONTROL + select DM + select CPU config OPENRISC bool "OpenRISC architecture" diff --git a/arch/nios2/cpu/cpu.c b/arch/nios2/cpu/cpu.c index 39ae972..88984e2 100644 --- a/arch/nios2/cpu/cpu.c +++ b/arch/nios2/cpu/cpu.c @@ -6,7 +6,9 @@ */ #include -#include +#include +#include +#include #include DECLARE_GLOBAL_DATA_PTR; @@ -51,10 +53,78 @@ void dcache_disable(void) flush_dcache(CONFIG_SYS_DCACHE_SIZE, CONFIG_SYS_DCACHELINE_SIZE); } -int arch_cpu_init(void) +int arch_cpu_init_dm(void) { - gd->cpu_clk = CONFIG_SYS_CLK_FREQ; + struct udevice *dev; + + uclass_first_device(UCLASS_CPU, &dev); + if (!dev) + return -ENODEV; + + gd->cpu_clk = fdtdec_get_int(gd->fdt_blob, dev->of_offset, + "clock-frequency", 0); + gd->arch.dcache_line_size = fdtdec_get_int(gd->fdt_blob, dev->of_offset, + "dcache-line-size", 0); + gd->arch.icache_line_size = fdtdec_get_int(gd->fdt_blob, dev->of_offset, + "icache-line-size", 0); + gd->arch.dcache_size = fdtdec_get_int(gd->fdt_blob, dev->of_offset, + "dcache-size", 0); + gd->arch.icache_size = fdtdec_get_int(gd->fdt_blob, dev->of_offset, + "icache-size", 0); + gd->arch.reset_addr = fdtdec_get_int(gd->fdt_blob, dev->of_offset, + "altr,reset-addr", 0); + gd->arch.exception_addr = fdtdec_get_int(gd->fdt_blob, dev->of_offset, + "altr,exception-addr", 0); + gd->arch.has_mmu = fdtdec_get_int(gd->fdt_blob, dev->of_offset, + "altr,has-mmu", 0); + gd->arch.io_region_base = gd->arch.has_mmu ? 0xe0000000 : 0x8000000; gd->ram_size = CONFIG_SYS_SDRAM_SIZE; return 0; } + +static int altera_nios2_get_desc(struct udevice *dev, char *buf, int size) +{ + const char *cpu_name = "Nios-II"; + + if (size < strlen(cpu_name)) + return -ENOSPC; + strcpy(buf, cpu_name); + + return 0; +} + +static int altera_nios2_get_info(struct udevice *dev, struct cpu_info *info) +{ + + info->cpu_freq = gd->cpu_clk; + info->features = 1 << CPU_FEAT_L1_CACHE + | (gd->arch.has_mmu ? 1 << CPU_FEAT_MMU : 0); + + return 0; +} + +static int altera_nios2_get_count(struct udevice *dev) +{ + return 1; +} + +static const struct cpu_ops altera_nios2_ops = { + .get_desc = altera_nios2_get_desc, + .get_info = altera_nios2_get_info, + .get_count = altera_nios2_get_count, +}; + +static const struct udevice_id altera_nios2_ids[] = { + { .compatible = "altr,nios2-1.0" }, + { .compatible = "altr,nios2-1.1" }, + { } +}; + +U_BOOT_DRIVER(altera_nios2) = { + .name = "altera_nios2", + .id = UCLASS_CPU, + .of_match = altera_nios2_ids, + .ops = &altera_nios2_ops, + .flags = DM_FLAG_PRE_RELOC, +}; diff --git a/arch/nios2/dts/3c120_devboard.dts b/arch/nios2/dts/3c120_devboard.dts index 781a652..2e2956f 100644 --- a/arch/nios2/dts/3c120_devboard.dts +++ b/arch/nios2/dts/3c120_devboard.dts @@ -41,6 +41,7 @@ altr,exception-addr = <0xd0000020>; altr,has-initda = <1>; altr,has-mmu = <1>; + u-boot,dm-pre-reloc; }; }; diff --git a/arch/nios2/include/asm/global_data.h b/arch/nios2/include/asm/global_data.h index 580b019..ee5180b 100644 --- a/arch/nios2/include/asm/global_data.h +++ b/arch/nios2/include/asm/global_data.h @@ -9,6 +9,14 @@ /* Architecture-specific global data */ struct arch_global_data { + u32 dcache_line_size; + u32 icache_line_size; + u32 dcache_size; + u32 icache_size; + u32 reset_addr; + u32 exception_addr; + int has_mmu; + u32 io_region_base; }; #include diff --git a/configs/nios2-generic_defconfig b/configs/nios2-generic_defconfig index ad72272..63d99d8 100644 --- a/configs/nios2-generic_defconfig +++ b/configs/nios2-generic_defconfig @@ -13,9 +13,7 @@ CONFIG_HUSH_PARSER=y CONFIG_CMD_DHCP=y # CONFIG_CMD_NFS is not set CONFIG_CMD_PING=y -CONFIG_OF_CONTROL=y CONFIG_NET_RANDOM_ETHADDR=y -CONFIG_DM=y CONFIG_ALTERA_PIO=y CONFIG_ALTERA_JTAG_UART=y CONFIG_ALTERA_JTAG_UART_BYPASS=y