]> git.sur5r.net Git - u-boot/commitdiff
nios2: convert altera sysid to driver model
authorThomas Chou <thomas@wytron.com.tw>
Wed, 14 Oct 2015 00:43:31 +0000 (08:43 +0800)
committerThomas Chou <thomas@wytron.com.tw>
Thu, 22 Oct 2015 23:37:03 +0000 (07:37 +0800)
Convert altera sysid to driver model with misc uclass.

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>
Acked-by: Chin Liang See <clsee@altera.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
12 files changed:
arch/nios2/cpu/Makefile
arch/nios2/cpu/cpu.c
arch/nios2/cpu/sysid.c [deleted file]
arch/nios2/dts/3c120_devboard.dts
arch/nios2/include/asm/system.h
board/altera/nios2-generic/nios2-generic.c
configs/nios2-generic_defconfig
doc/device-tree-bindings/misc/altera_sysid.txt [new file with mode: 0644]
drivers/misc/Kconfig
drivers/misc/Makefile
drivers/misc/altera_sysid.c [new file with mode: 0644]
include/configs/nios2-generic.h

index 3fe7847160d5afbcd752415eb3c2657e20312eb9..185ca3cdb76e5cf973e3445c1d8806df392c0a16 100644 (file)
@@ -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
index 34eb7bd68320b53c2d45588d0829181029745601..d7ff290fd7e0945f252d43d6f25dc7b8fc75d4cd 100644 (file)
 
 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 : <unknown>\n");
-#else
-       display_sysid ();
-#endif
-       return (0);
+       printf("CPU:   Nios-II\n");
+       return 0;
 }
 #endif /* CONFIG_DISPLAY_CPUINFO */
 
diff --git a/arch/nios2/cpu/sysid.c b/arch/nios2/cpu/sysid.c
deleted file mode 100644 (file)
index 50819b2..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * (C) Copyright 2004, Psyent Corporation <www.psyent.com>
- * Scott McNutt <smcnutt@psyent.com>
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-#include <common.h>
-
-#if defined (CONFIG_SYS_NIOS_SYSID_BASE)
-
-#include <command.h>
-#include <asm/io.h>
-#include <linux/time.h>
-
-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 */
index 4a34ce56db6604d5284c8effb377d65fe26f6f34..a3cfacb98ab232078c15df3fc24bd08971cc5f7f 100644 (file)
@@ -71,6 +71,7 @@
                                <0x00004cc0 0x08004cc0 0x00000010>,
                                <0x00004ce0 0x08004ce0 0x00000010>,
                                <0x00004d00 0x08004d00 0x00000010>,
+                               <0x00004d40 0x08004d40 0x00000008>,
                                <0x00004d50 0x08004d50 0x00000008>,
                                <0x00008000 0x08008000 0x00000020>,
                                <0x00400000 0x08400000 0x00000020>;
                                clock-frequency = < 125000000 >;
                        };
 
+                       sysid: sysid@0x4d40 {
+                               compatible = "altr,sysid-1.0";
+                               reg = <0x00004d40 0x00000008>;
+                       };
+
                        jtag_uart: serial@0x4d50 {
                                compatible = "altr,juart-1.0";
                                reg = <0x00004d50 0x00000008>;
index 6213a16eda98d1d573394efb5f725a09b909a86d..b15853563e20805912dc440d067fa26c841cee4d 100644 (file)
@@ -45,4 +45,6 @@
        "callr  %0"                                     \
        : : "r" (addr))
 
+void display_sysid(void);
+
 #endif /* __ASM_NIOS2_SYSTEM_H */
index cb98a08895548eeb80b56d833f68ebbaa5ee8dc0..1f108211137630eb6add68bc8f8fcd70242e2e69 100644 (file)
@@ -37,7 +37,10 @@ int board_early_init_f(void)
 
 int checkboard(void)
 {
-       printf("BOARD : %s\n", CONFIG_BOARD_NAME);
+#ifdef CONFIG_ALTERA_SYSID
+       display_sysid();
+#endif
+       printf("BOARD: %s\n", CONFIG_BOARD_NAME);
        return 0;
 }
 
index 505a2cf8be388e7aa5b5fb032cf150013c7ea5cf..3d404b244ebfa828d5d9a85f6ea19d17f554e945 100644 (file)
@@ -16,6 +16,8 @@ CONFIG_CMD_DHCP=y
 CONFIG_CMD_PING=y
 CONFIG_NET_RANDOM_ETHADDR=y
 CONFIG_ALTERA_PIO=y
+CONFIG_MISC=y
+CONFIG_ALTERA_SYSID=y
 CONFIG_ALTERA_JTAG_UART=y
 CONFIG_ALTERA_JTAG_UART_BYPASS=y
 CONFIG_TIMER=y
diff --git a/doc/device-tree-bindings/misc/altera_sysid.txt b/doc/device-tree-bindings/misc/altera_sysid.txt
new file mode 100644 (file)
index 0000000..54462eb
--- /dev/null
@@ -0,0 +1,4 @@
+Altera sysid
+
+Required properties:
+- compatible : should be "altr,sysid-1.0"
index 031b4d8e784a780d0af9fcb9b4aa14cd8627ae3a..101a619558084667ca3dc727315892565b71e409 100644 (file)
@@ -13,6 +13,13 @@ config MISC
          set of generic read, write and ioctl methods may be used to
          access the device.
 
+config ALTERA_SYSID
+       bool "Altera Sysid support"
+       depends on 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
index 7e76b12ccba89d9ab2a9fffe01bf521d9e10eb39..aa137f50ea3bb6db2c2840325802318016fd859e 100644 (file)
@@ -7,6 +7,7 @@
 
 obj-$(CONFIG_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 (file)
index 0000000..249b273
--- /dev/null
@@ -0,0 +1,101 @@
+/*
+ * (C) Copyright 2004, Psyent Corporation <www.psyent.com>
+ * Scott McNutt <smcnutt@psyent.com>
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <command.h>
+#include <dm.h>
+#include <errno.h>
+#include <misc.h>
+#include <linux/time.h>
+#include <asm/io.h>
+
+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;
+       u32 sysid[2];
+       struct tm t;
+       char asc[32];
+       time_t stamp;
+       int ret;
+
+       /* the first misc device will be used */
+       ret = uclass_first_device(UCLASS_MISC, &dev);
+       if (ret)
+               return;
+       if (!dev)
+               return;
+       ret = misc_read(dev, 0, &sysid, sizeof(sysid));
+       if (ret)
+               return;
+
+       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(&regs->id);
+       sysid[1] = readl(&regs->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 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,
+};
index c65b3b3e6d0d09157f2a7bcac7aeeee4a78ff45b..e4b5abb90dcafcb1a4e63c420bedd91dfdef128d 100644 (file)
@@ -16,7 +16,7 @@
 #define CONFIG_BOARD_NAME "nios2-generic" /* custom board name */
 #define CONFIG_BOARD_EARLY_INIT_F      /* enable early board-spec. init */
 #define CONFIG_DISPLAY_CPUINFO
-#define CONFIG_DISPLAY_BOARDINFO
+#define CONFIG_DISPLAY_BOARDINFO_LATE
 #define CONFIG_SYS_NIOS_SYSID_BASE     CONFIG_SYS_SYSID_BASE
 
 /*