From patchwork Tue Sep 29 09:04:34 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Chou X-Patchwork-Id: 523757 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 EBFEE140180 for ; Tue, 29 Sep 2015 19:05:06 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 8BBDD4B8C6; Tue, 29 Sep 2015 11:05:02 +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 Tg27ZOGPlmTL; Tue, 29 Sep 2015 11:05:02 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id E11804B8C8; Tue, 29 Sep 2015 11:04:54 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id D2BB04B7F9 for ; Tue, 29 Sep 2015 11:04:46 +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 BQhXcQpDPlR8 for ; Tue, 29 Sep 2015 11:04:46 +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 18BF84B825 for ; Tue, 29 Sep 2015 11:04:41 +0200 (CEST) Received: from localhost.localdomain (unknown [192.168.1.250]) by www.wytron.com.tw (Postfix) with ESMTP id 86471D002FA; Tue, 29 Sep 2015 17:04:38 +0800 (CST) From: Thomas Chou To: u-boot@lists.denx.de Date: Tue, 29 Sep 2015 17:04:34 +0800 Message-Id: <1443517474-9838-2-git-send-email-thomas@wytron.com.tw> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1443517474-9838-1-git-send-email-thomas@wytron.com.tw> References: <1443511438-18625-1-git-send-email-thomas@wytron.com.tw> <1443517474-9838-1-git-send-email-thomas@wytron.com.tw> Cc: Marek Vasut , clsee@altera.com, lftan@altera.com Subject: [U-Boot] [PATCH v2 2/2] nios2: convert altera sysid 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 altera sysid to driver model with misc uclass. Signed-off-by: Thomas Chou --- v2 remove trailing whitespace in altera_sysid.c. arch/nios2/cpu/Makefile | 2 +- arch/nios2/cpu/cpu.c | 15 +---- arch/nios2/cpu/sysid.c | 46 -------------- arch/nios2/dts/3c120_devboard.dts | 8 +++ board/altera/nios2-generic/nios2-generic.c | 6 +- configs/nios2-generic_defconfig | 2 + drivers/misc/Kconfig | 7 +++ drivers/misc/Makefile | 1 + drivers/misc/altera_sysid.c | 99 ++++++++++++++++++++++++++++++ include/configs/nios2-generic.h | 3 +- 10 files changed, 126 insertions(+), 63 deletions(-) delete mode 100644 arch/nios2/cpu/sysid.c create mode 100644 drivers/misc/altera_sysid.c diff --git a/arch/nios2/cpu/Makefile b/arch/nios2/cpu/Makefile index 3fe7847..185ca3c 100644 --- a/arch/nios2/cpu/Makefile +++ b/arch/nios2/cpu/Makefile @@ -7,5 +7,5 @@ extra-y = start.o obj-y = exceptions.o -obj-y += cpu.o interrupts.o sysid.o traps.o +obj-y += cpu.o interrupts.o traps.o obj-y += fdt.o diff --git a/arch/nios2/cpu/cpu.c b/arch/nios2/cpu/cpu.c index 88984e2..7b1717c 100644 --- a/arch/nios2/cpu/cpu.c +++ b/arch/nios2/cpu/cpu.c @@ -13,22 +13,11 @@ DECLARE_GLOBAL_DATA_PTR; -#if defined (CONFIG_SYS_NIOS_SYSID_BASE) -extern void display_sysid (void); -#endif /* CONFIG_SYS_NIOS_SYSID_BASE */ - -#ifdef CONFIG_DISPLAY_CPUINFO int print_cpuinfo(void) { - printf ("CPU : Nios-II\n"); -#if !defined(CONFIG_SYS_NIOS_SYSID_BASE) - printf ("SYSID : \n"); -#else - display_sysid (); -#endif - return (0); + printf("CPU: Nios-II\n"); + return 0; } -#endif /* CONFIG_DISPLAY_CPUINFO */ int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { diff --git a/arch/nios2/cpu/sysid.c b/arch/nios2/cpu/sysid.c deleted file mode 100644 index 50819b2..0000000 --- a/arch/nios2/cpu/sysid.c +++ /dev/null @@ -1,46 +0,0 @@ -/* - * (C) Copyright 2004, Psyent Corporation - * Scott McNutt - * - * SPDX-License-Identifier: GPL-2.0+ - */ - -#include - -#if defined (CONFIG_SYS_NIOS_SYSID_BASE) - -#include -#include -#include - -typedef volatile struct { - unsigned id; /* The system build id */ - unsigned timestamp; /* Timestamp */ -} nios_sysid_t; - -void display_sysid (void) -{ - nios_sysid_t *sysid = (nios_sysid_t *)CONFIG_SYS_NIOS_SYSID_BASE; - struct tm t; - char asc[32]; - time_t stamp; - - stamp = readl (&sysid->timestamp); - localtime_r (&stamp, &t); - asctime_r (&t, asc); - printf ("SYSID : %08lx, %s", readl (&sysid->id), asc); - -} - -int do_sysid (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) -{ - display_sysid (); - return (0); -} - -U_BOOT_CMD( - sysid, 1, 1, do_sysid, - "display Nios-II system id", - "" -); -#endif /* CONFIG_SYS_NIOS_SYSID_BASE */ diff --git a/arch/nios2/dts/3c120_devboard.dts b/arch/nios2/dts/3c120_devboard.dts index 2e2956f..2eb339c 100644 --- a/arch/nios2/dts/3c120_devboard.dts +++ b/arch/nios2/dts/3c120_devboard.dts @@ -72,6 +72,7 @@ <0x00004cc0 0x08004cc0 0x00000010>, <0x00004ce0 0x08004ce0 0x00000010>, <0x00004d00 0x08004d00 0x00000010>, + <0x00004d40 0x08004d40 0x00000008>, <0x00004d50 0x08004d50 0x00000008>, <0x00008000 0x08008000 0x00000020>, <0x00400000 0x08400000 0x00000020>; @@ -92,6 +93,13 @@ clock-frequency = < 125000000 >; }; + sysid: sysid@0x4d40 { + compatible = "altr,sysid-1.0"; + reg = <0x00004d40 0x00000008>; + id = <0>; + timestamp = <1440939556>; + }; + jtag_uart: serial@0x4d50 { compatible = "altr,juart-1.0"; reg = <0x00004d50 0x00000008>; diff --git a/board/altera/nios2-generic/nios2-generic.c b/board/altera/nios2-generic/nios2-generic.c index 61d32c7..e08b8f7 100644 --- a/board/altera/nios2-generic/nios2-generic.c +++ b/board/altera/nios2-generic/nios2-generic.c @@ -42,7 +42,11 @@ int board_early_init_r(void) int checkboard(void) { - printf("BOARD : %s\n", CONFIG_BOARD_NAME); +#ifdef CONFIG_ALTERA_SYSID + extern void display_sysid(void); + display_sysid(); +#endif + printf("BOARD: %s\n", CONFIG_BOARD_NAME); return 0; } diff --git a/configs/nios2-generic_defconfig b/configs/nios2-generic_defconfig index 1aa2d9e..d8d26e5 100644 --- a/configs/nios2-generic_defconfig +++ b/configs/nios2-generic_defconfig @@ -15,6 +15,8 @@ CONFIG_CMD_DHCP=y CONFIG_CMD_PING=y CONFIG_NET_RANDOM_ETHADDR=y CONFIG_ALTERA_PIO=y +CONFIG_DM_MISC=y +CONFIG_ALTERA_SYSID=y CONFIG_ALTERA_JTAG_UART=y CONFIG_ALTERA_JTAG_UART_BYPASS=y CONFIG_DM_TIMER=y diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig index 51c2a08..06a10d4 100644 --- a/drivers/misc/Kconfig +++ b/drivers/misc/Kconfig @@ -10,6 +10,13 @@ config DM_MISC help Enable driver model for miscellaneous devices. +config ALTERA_SYSID + bool "Altera Sysid support" + depends on DM_MISC + help + Select this to enable a sysid for Altera devices. Please find + details on the "Embedded Peripherals IP User Guide" of Altera. + config CMD_CROS_EC bool "Enable crosec command" depends on CROS_EC diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile index b285946..449425e 100644 --- a/drivers/misc/Makefile +++ b/drivers/misc/Makefile @@ -7,6 +7,7 @@ obj-$(CONFIG_DM_MISC) += misc-uclass.o obj-$(CONFIG_ALI152X) += ali512x.o +obj-$(CONFIG_ALTERA_SYSID) += altera_sysid.o obj-$(CONFIG_DS4510) += ds4510.o obj-$(CONFIG_CBMEM_CONSOLE) += cbmem_console.o obj-$(CONFIG_CROS_EC) += cros_ec.o diff --git a/drivers/misc/altera_sysid.c b/drivers/misc/altera_sysid.c new file mode 100644 index 0000000..e200bf7 --- /dev/null +++ b/drivers/misc/altera_sysid.c @@ -0,0 +1,99 @@ +/* + * (C) Copyright 2004, Psyent Corporation + * Scott McNutt + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include +#include +#include +#include +#include +#include +#include + +struct altera_sysid_regs { + u32 id; /* The system build id */ + u32 timestamp; /* Timestamp */ +}; + +struct altera_sysid_platdata { + struct altera_sysid_regs *regs; +}; + +void display_sysid (void) +{ + struct udevice *dev; + const struct dm_misc_ops *ops; + u32 sysid[2]; + struct tm t; + char asc[32]; + time_t stamp; + + uclass_first_device(UCLASS_MISC, &dev); + if (!dev) + return; + ops = device_get_ops(dev); + if (!ops->read) + return; + ops->read(dev, 0, &sysid, sizeof(sysid)); + + stamp = sysid[1]; + localtime_r(&stamp, &t); + asctime_r(&t, asc); + printf("SYSID: %08x, %s", sysid[0], asc); +} + +int do_sysid (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +{ + display_sysid(); + return 0; +} + +U_BOOT_CMD( + sysid, 1, 1, do_sysid, + "display Nios-II system id", + "" +); + +static int altera_sysid_read(struct udevice *dev, + int offset, void *buf, int size) +{ + struct altera_sysid_platdata *plat = dev->platdata; + struct altera_sysid_regs *const regs = plat->regs; + u32 *sysid = buf; + + sysid[0] = readl(®s->id); + sysid[1] = readl(®s->timestamp); + + return 0; +} + +static int altera_sysid_ofdata_to_platdata(struct udevice *dev) +{ + struct altera_sysid_platdata *plat = dev_get_platdata(dev); + + plat->regs = ioremap(dev_get_addr(dev), + sizeof(struct altera_sysid_regs)); + + return 0; +} + +static const struct dm_misc_ops altera_sysid_ops = { + .read = altera_sysid_read, +}; + +static const struct udevice_id altera_sysid_ids[] = { + { .compatible = "altr,sysid-1.0", }, + { } +}; + +U_BOOT_DRIVER(altera_sysid) = { + .name = "altera_sysid", + .id = UCLASS_MISC, + .of_match = altera_sysid_ids, + .ofdata_to_platdata = altera_sysid_ofdata_to_platdata, + .platdata_auto_alloc_size = sizeof(struct altera_sysid_platdata), + .ops = &altera_sysid_ops, +}; diff --git a/include/configs/nios2-generic.h b/include/configs/nios2-generic.h index ae19676..bd219e3 100644 --- a/include/configs/nios2-generic.h +++ b/include/configs/nios2-generic.h @@ -16,8 +16,7 @@ #define CONFIG_BOARD_NAME "nios2-generic" /* custom board name */ #define CONFIG_BOARD_EARLY_INIT_F /* enable early board-spec. init */ #define CONFIG_BOARD_EARLY_INIT_R -#define CONFIG_DISPLAY_CPUINFO -#define CONFIG_DISPLAY_BOARDINFO +#define CONFIG_DISPLAY_BOARDINFO_LATE #define CONFIG_SYS_NIOS_SYSID_BASE CONFIG_SYS_SYSID_BASE /*