* [U-Boot] [PATCH 2/2] nios2: convert altera sysid to driver model
2015-09-29 7:23 [U-Boot] [PATCH 1/2] dm: implement a Miscellaneous uclass Thomas Chou
@ 2015-09-29 7:23 ` Thomas Chou
2015-09-30 0:54 ` Chin Liang See
2015-09-29 9:04 ` [U-Boot] [PATCH v2 1/2] dm: implement a Miscellaneous uclass Thomas Chou
` (4 subsequent siblings)
5 siblings, 1 reply; 22+ messages in thread
From: Thomas Chou @ 2015-09-29 7:23 UTC (permalink / raw)
To: u-boot
Convert altera sysid to driver model with misc uclass.
Signed-off-by: Thomas Chou <thomas@wytron.com.tw>
---
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 : <unknown>\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 <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 */
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 at 0x4d40 {
+ compatible = "altr,sysid-1.0";
+ reg = <0x00004d40 0x00000008>;
+ id = <0>;
+ timestamp = <1440939556>;
+ };
+
jtag_uart: serial at 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..648fdb1
--- /dev/null
+++ b/drivers/misc/altera_sysid.c
@@ -0,0 +1,99 @@
+/*
+ * (C) Copyright 2004, Psyent Corporation <www.psyent.com>
+ * Scott McNutt <smcnutt@psyent.com>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <misc.h>
+#include <errno.h>
+#include <command.h>
+#include <asm/io.h>
+#include <linux/time.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;
+ 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
/*
--
2.1.4
^ permalink raw reply related [flat|nested] 22+ messages in thread* [U-Boot] [PATCH 2/2] nios2: convert altera sysid to driver model
2015-09-29 7:23 ` [U-Boot] [PATCH 2/2] nios2: convert altera sysid to driver model Thomas Chou
@ 2015-09-30 0:54 ` Chin Liang See
0 siblings, 0 replies; 22+ messages in thread
From: Chin Liang See @ 2015-09-30 0:54 UTC (permalink / raw)
To: u-boot
Hi Thomas,
On Tue, 2015-09-29 at 15:23 +0800, thomas at wytron.com.tw wrote:
> Convert altera sysid to driver model with misc uclass.
>
> Signed-off-by: Thomas Chou <thomas@wytron.com.tw>
Thanks for the patch.
> ---
> 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 : <unknown>\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 <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 */
> 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 at 0x4d40 {
> + compatible = "altr,sysid-1.0";
> + reg = <0x00004d40 0x00000008>;
> + id = <0>;
> + timestamp = <1440939556>;
I believe we won't need the id and timestamp as these will be read from
sysid register.
Thanks
Chin Liang
p/s: Oh ya, let me know if you need my help to send new revision of
those patches commented by me. I can share the load :)
> + };
> +
> jtag_uart: serial at 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..648fdb1
> --- /dev/null
> +++ b/drivers/misc/altera_sysid.c
> @@ -0,0 +1,99 @@
> +/*
> + * (C) Copyright 2004, Psyent Corporation <www.psyent.com>
> + * Scott McNutt <smcnutt@psyent.com>
> + *
> + * SPDX-License-Identifier: GPL-2.0+
> + */
> +
> +#include <common.h>
> +#include <dm.h>
> +#include <misc.h>
> +#include <errno.h>
> +#include <command.h>
> +#include <asm/io.h>
> +#include <linux/time.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;
> + 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
>
> /*
^ permalink raw reply [flat|nested] 22+ messages in thread
* [U-Boot] [PATCH v2 1/2] dm: implement a Miscellaneous uclass
2015-09-29 7:23 [U-Boot] [PATCH 1/2] dm: implement a Miscellaneous uclass Thomas Chou
2015-09-29 7:23 ` [U-Boot] [PATCH 2/2] nios2: convert altera sysid to driver model Thomas Chou
@ 2015-09-29 9:04 ` Thomas Chou
2015-09-29 9:04 ` [U-Boot] [PATCH v2 2/2] nios2: convert altera sysid to driver model Thomas Chou
2015-09-29 11:59 ` [U-Boot] [PATCH v3 1/2] dm: implement a Miscellaneous uclass Thomas Chou
` (3 subsequent siblings)
5 siblings, 1 reply; 22+ messages in thread
From: Thomas Chou @ 2015-09-29 9:04 UTC (permalink / raw)
To: u-boot
Implement a Miscellaneous uclass with generic read or
write operations. This class is used only for those
do not fit other more general classes.
Signed-off-by: Thomas Chou <thomas@wytron.com.tw>
---
v2
add missing misc.h.
drivers/misc/Kconfig | 6 ++++++
drivers/misc/Makefile | 1 +
drivers/misc/misc-uclass.c | 14 ++++++++++++++
include/dm/uclass-id.h | 1 +
include/misc.h | 22 ++++++++++++++++++++++
5 files changed, 44 insertions(+)
create mode 100644 drivers/misc/misc-uclass.c
create mode 100644 include/misc.h
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index 8b38a84..51c2a08 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -4,6 +4,12 @@
menu "Multifunction device drivers"
+config DM_MISC
+ bool "Enable Driver Model for Misc drivers"
+ depends on DM
+ help
+ Enable driver model for miscellaneous devices.
+
config CMD_CROS_EC
bool "Enable crosec command"
depends on CROS_EC
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index 8d0fc3c..b285946 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -5,6 +5,7 @@
# SPDX-License-Identifier: GPL-2.0+
#
+obj-$(CONFIG_DM_MISC) += misc-uclass.o
obj-$(CONFIG_ALI152X) += ali512x.o
obj-$(CONFIG_DS4510) += ds4510.o
obj-$(CONFIG_CBMEM_CONSOLE) += cbmem_console.o
diff --git a/drivers/misc/misc-uclass.c b/drivers/misc/misc-uclass.c
new file mode 100644
index 0000000..40fe947
--- /dev/null
+++ b/drivers/misc/misc-uclass.c
@@ -0,0 +1,14 @@
+/*
+ * Copyright (C) 2010 Thomas Chou <thomas@wytron.com.tw>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <misc.h>
+
+UCLASS_DRIVER(misc) = {
+ .id = UCLASS_MISC,
+ .name = "misc",
+};
diff --git a/include/dm/uclass-id.h b/include/dm/uclass-id.h
index aff34a4..a6982ab 100644
--- a/include/dm/uclass-id.h
+++ b/include/dm/uclass-id.h
@@ -39,6 +39,7 @@ enum uclass_id {
UCLASS_LED, /* Light-emitting diode (LED) */
UCLASS_LPC, /* x86 'low pin count' interface */
UCLASS_MASS_STORAGE, /* Mass storage device */
+ UCLASS_MISC, /* Miscellaneous device */
UCLASS_MMC, /* SD / MMC card or chip */
UCLASS_MOD_EXP, /* RSA Mod Exp device */
UCLASS_PCH, /* x86 platform controller hub */
diff --git a/include/misc.h b/include/misc.h
new file mode 100644
index 0000000..dfca41f
--- /dev/null
+++ b/include/misc.h
@@ -0,0 +1,22 @@
+/*
+ * Copyright (C) 2015 Thomas Chou <thomas@wytron.com.tw>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#ifndef _DM_MISC_H_
+#define _DM_MISC_H_
+
+/*
+ * struct dm_misc_ops - Driver model Misc operations
+ *
+ * The uclass interface is implemented by all miscellaneous devices which
+ * use driver model.
+ */
+struct dm_misc_ops {
+ int (*read)(struct udevice *dev, int offset, void *buf, int size);
+ int (*write)(struct udevice *dev, int offset, const void *buf,
+ int size);
+};
+
+#endif /* _DM_MISC_H_ */
--
2.1.4
^ permalink raw reply related [flat|nested] 22+ messages in thread* [U-Boot] [PATCH v2 2/2] nios2: convert altera sysid to driver model
2015-09-29 9:04 ` [U-Boot] [PATCH v2 1/2] dm: implement a Miscellaneous uclass Thomas Chou
@ 2015-09-29 9:04 ` Thomas Chou
2015-09-29 9:30 ` Stefan Roese
0 siblings, 1 reply; 22+ messages in thread
From: Thomas Chou @ 2015-09-29 9:04 UTC (permalink / raw)
To: u-boot
Convert altera sysid to driver model with misc uclass.
Signed-off-by: Thomas Chou <thomas@wytron.com.tw>
---
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 : <unknown>\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 <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 */
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 at 0x4d40 {
+ compatible = "altr,sysid-1.0";
+ reg = <0x00004d40 0x00000008>;
+ id = <0>;
+ timestamp = <1440939556>;
+ };
+
jtag_uart: serial at 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 <www.psyent.com>
+ * Scott McNutt <smcnutt@psyent.com>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <misc.h>
+#include <errno.h>
+#include <command.h>
+#include <asm/io.h>
+#include <linux/time.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;
+ 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
/*
--
2.1.4
^ permalink raw reply related [flat|nested] 22+ messages in thread* [U-Boot] [PATCH v2 2/2] nios2: convert altera sysid to driver model
2015-09-29 9:04 ` [U-Boot] [PATCH v2 2/2] nios2: convert altera sysid to driver model Thomas Chou
@ 2015-09-29 9:30 ` Stefan Roese
2015-09-29 11:55 ` Thomas Chou
0 siblings, 1 reply; 22+ messages in thread
From: Stefan Roese @ 2015-09-29 9:30 UTC (permalink / raw)
To: u-boot
Hi Thomas,
On 29.09.2015 11:04, Thomas Chou wrote:
> Convert altera sysid to driver model with misc uclass.
>
> Signed-off-by: Thomas Chou <thomas@wytron.com.tw>
> ---
> 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 : <unknown>\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 <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 */
> 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 at 0x4d40 {
> + compatible = "altr,sysid-1.0";
> + reg = <0x00004d40 0x00000008>;
> + id = <0>;
> + timestamp = <1440939556>;
> + };
> +
> jtag_uart: serial at 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 <www.psyent.com>
> + * Scott McNutt <smcnutt@psyent.com>
> + *
> + * SPDX-License-Identifier: GPL-2.0+
> + */
> +
> +#include <common.h>
> +#include <dm.h>
> +#include <misc.h>
> +#include <errno.h>
> +#include <command.h>
> +#include <asm/io.h>
> +#include <linux/time.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)
> +{
Even though you have copied this code, please fix the coding style
above (space before "("). For all occurrences in this patch, so
that it is checkpatch clean.
Thank,
Stefan
^ permalink raw reply [flat|nested] 22+ messages in thread* [U-Boot] [PATCH v2 2/2] nios2: convert altera sysid to driver model
2015-09-29 9:30 ` Stefan Roese
@ 2015-09-29 11:55 ` Thomas Chou
0 siblings, 0 replies; 22+ messages in thread
From: Thomas Chou @ 2015-09-29 11:55 UTC (permalink / raw)
To: u-boot
Hi Stefan,
On 09/29/2015 05:30 PM, Stefan Roese wrote:
>> +void display_sysid (void)
>> +{
>
> Even though you have copied this code, please fix the coding style
> above (space before "("). For all occurrences in this patch, so
> that it is checkpatch clean.
Thanks a lot for reminding.
Best regards,
Thomas Chou
^ permalink raw reply [flat|nested] 22+ messages in thread
* [U-Boot] [PATCH v3 1/2] dm: implement a Miscellaneous uclass
2015-09-29 7:23 [U-Boot] [PATCH 1/2] dm: implement a Miscellaneous uclass Thomas Chou
2015-09-29 7:23 ` [U-Boot] [PATCH 2/2] nios2: convert altera sysid to driver model Thomas Chou
2015-09-29 9:04 ` [U-Boot] [PATCH v2 1/2] dm: implement a Miscellaneous uclass Thomas Chou
@ 2015-09-29 11:59 ` Thomas Chou
2015-09-29 11:59 ` [U-Boot] [PATCH v3 2/2] nios2: convert altera sysid to driver model Thomas Chou
2015-10-03 14:29 ` [U-Boot] [PATCH v3 1/2] dm: implement a Miscellaneous uclass Simon Glass
2015-10-05 2:18 ` [U-Boot] [PATCH v4 " Thomas Chou
` (2 subsequent siblings)
5 siblings, 2 replies; 22+ messages in thread
From: Thomas Chou @ 2015-09-29 11:59 UTC (permalink / raw)
To: u-boot
Implement a Miscellaneous uclass with generic read or
write operations. This class is used only for those
do not fit other more general classes.
Signed-off-by: Thomas Chou <thomas@wytron.com.tw>
---
v2
add missing misc.h.
v3
no change.
drivers/misc/Kconfig | 6 ++++++
drivers/misc/Makefile | 1 +
drivers/misc/misc-uclass.c | 14 ++++++++++++++
include/dm/uclass-id.h | 1 +
include/misc.h | 22 ++++++++++++++++++++++
5 files changed, 44 insertions(+)
create mode 100644 drivers/misc/misc-uclass.c
create mode 100644 include/misc.h
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index 8b38a84..51c2a08 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -4,6 +4,12 @@
menu "Multifunction device drivers"
+config DM_MISC
+ bool "Enable Driver Model for Misc drivers"
+ depends on DM
+ help
+ Enable driver model for miscellaneous devices.
+
config CMD_CROS_EC
bool "Enable crosec command"
depends on CROS_EC
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index 8d0fc3c..b285946 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -5,6 +5,7 @@
# SPDX-License-Identifier: GPL-2.0+
#
+obj-$(CONFIG_DM_MISC) += misc-uclass.o
obj-$(CONFIG_ALI152X) += ali512x.o
obj-$(CONFIG_DS4510) += ds4510.o
obj-$(CONFIG_CBMEM_CONSOLE) += cbmem_console.o
diff --git a/drivers/misc/misc-uclass.c b/drivers/misc/misc-uclass.c
new file mode 100644
index 0000000..40fe947
--- /dev/null
+++ b/drivers/misc/misc-uclass.c
@@ -0,0 +1,14 @@
+/*
+ * Copyright (C) 2010 Thomas Chou <thomas@wytron.com.tw>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <misc.h>
+
+UCLASS_DRIVER(misc) = {
+ .id = UCLASS_MISC,
+ .name = "misc",
+};
diff --git a/include/dm/uclass-id.h b/include/dm/uclass-id.h
index aff34a4..a6982ab 100644
--- a/include/dm/uclass-id.h
+++ b/include/dm/uclass-id.h
@@ -39,6 +39,7 @@ enum uclass_id {
UCLASS_LED, /* Light-emitting diode (LED) */
UCLASS_LPC, /* x86 'low pin count' interface */
UCLASS_MASS_STORAGE, /* Mass storage device */
+ UCLASS_MISC, /* Miscellaneous device */
UCLASS_MMC, /* SD / MMC card or chip */
UCLASS_MOD_EXP, /* RSA Mod Exp device */
UCLASS_PCH, /* x86 platform controller hub */
diff --git a/include/misc.h b/include/misc.h
new file mode 100644
index 0000000..dfca41f
--- /dev/null
+++ b/include/misc.h
@@ -0,0 +1,22 @@
+/*
+ * Copyright (C) 2015 Thomas Chou <thomas@wytron.com.tw>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#ifndef _DM_MISC_H_
+#define _DM_MISC_H_
+
+/*
+ * struct dm_misc_ops - Driver model Misc operations
+ *
+ * The uclass interface is implemented by all miscellaneous devices which
+ * use driver model.
+ */
+struct dm_misc_ops {
+ int (*read)(struct udevice *dev, int offset, void *buf, int size);
+ int (*write)(struct udevice *dev, int offset, const void *buf,
+ int size);
+};
+
+#endif /* _DM_MISC_H_ */
--
2.1.4
^ permalink raw reply related [flat|nested] 22+ messages in thread* [U-Boot] [PATCH v3 2/2] nios2: convert altera sysid to driver model
2015-09-29 11:59 ` [U-Boot] [PATCH v3 1/2] dm: implement a Miscellaneous uclass Thomas Chou
@ 2015-09-29 11:59 ` Thomas Chou
2015-10-03 14:29 ` [U-Boot] [PATCH v3 1/2] dm: implement a Miscellaneous uclass Simon Glass
1 sibling, 0 replies; 22+ messages in thread
From: Thomas Chou @ 2015-09-29 11:59 UTC (permalink / raw)
To: u-boot
Convert altera sysid to driver model with misc uclass.
Signed-off-by: Thomas Chou <thomas@wytron.com.tw>
---
v2
remove trailing whitespace in altera_sysid.c.
v3
fix coding style as suggested by Stefan.
arch/nios2/cpu/Makefile | 2 +-
arch/nios2/cpu/cpu.c | 13 +---
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 | 2 +-
10 files changed, 126 insertions(+), 60 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..1d497ab 100644
--- a/arch/nios2/cpu/cpu.c
+++ b/arch/nios2/cpu/cpu.c
@@ -13,20 +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 : <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
index 50819b2..0000000
--- a/arch/nios2/cpu/sysid.c
+++ /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 */
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 at 0x4d40 {
+ compatible = "altr,sysid-1.0";
+ reg = <0x00004d40 0x00000008>;
+ id = <0>;
+ timestamp = <1440939556>;
+ };
+
jtag_uart: serial at 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..968f59c
--- /dev/null
+++ b/drivers/misc/altera_sysid.c
@@ -0,0 +1,99 @@
+/*
+ * (C) Copyright 2004, Psyent Corporation <www.psyent.com>
+ * Scott McNutt <smcnutt@psyent.com>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <misc.h>
+#include <errno.h>
+#include <command.h>
+#include <asm/io.h>
+#include <linux/time.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;
+ 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..16a16f3 100644
--- a/include/configs/nios2-generic.h
+++ b/include/configs/nios2-generic.h
@@ -17,7 +17,7 @@
#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
/*
--
2.1.4
^ permalink raw reply related [flat|nested] 22+ messages in thread* [U-Boot] [PATCH v3 1/2] dm: implement a Miscellaneous uclass
2015-09-29 11:59 ` [U-Boot] [PATCH v3 1/2] dm: implement a Miscellaneous uclass Thomas Chou
2015-09-29 11:59 ` [U-Boot] [PATCH v3 2/2] nios2: convert altera sysid to driver model Thomas Chou
@ 2015-10-03 14:29 ` Simon Glass
1 sibling, 0 replies; 22+ messages in thread
From: Simon Glass @ 2015-10-03 14:29 UTC (permalink / raw)
To: u-boot
Hi Thomas,
On 29 September 2015 at 12:59, Thomas Chou <thomas@wytron.com.tw> wrote:
> Implement a Miscellaneous uclass with generic read or
> write operations. This class is used only for those
> do not fit other more general classes.
>
> Signed-off-by: Thomas Chou <thomas@wytron.com.tw>
> ---
> v2
> add missing misc.h.
> v3
> no change.
>
> drivers/misc/Kconfig | 6 ++++++
> drivers/misc/Makefile | 1 +
> drivers/misc/misc-uclass.c | 14 ++++++++++++++
> include/dm/uclass-id.h | 1 +
> include/misc.h | 22 ++++++++++++++++++++++
> 5 files changed, 44 insertions(+)
> create mode 100644 drivers/misc/misc-uclass.c
> create mode 100644 include/misc.h
>
> diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
> index 8b38a84..51c2a08 100644
> --- a/drivers/misc/Kconfig
> +++ b/drivers/misc/Kconfig
> @@ -4,6 +4,12 @@
>
> menu "Multifunction device drivers"
>
> +config DM_MISC
> + bool "Enable Driver Model for Misc drivers"
> + depends on DM
> + help
> + Enable driver model for miscellaneous devices.
Need to explain this a bit more! When do I use it, mention that it has
read and write.
I'm not sure about the name 'misc' but I suppose it makes sense. I
wonder if you should add 'ioctl' also?
> +
> config CMD_CROS_EC
> bool "Enable crosec command"
> depends on CROS_EC
> diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
> index 8d0fc3c..b285946 100644
> --- a/drivers/misc/Makefile
> +++ b/drivers/misc/Makefile
> @@ -5,6 +5,7 @@
> # SPDX-License-Identifier: GPL-2.0+
> #
>
> +obj-$(CONFIG_DM_MISC) += misc-uclass.o
> obj-$(CONFIG_ALI152X) += ali512x.o
> obj-$(CONFIG_DS4510) += ds4510.o
> obj-$(CONFIG_CBMEM_CONSOLE) += cbmem_console.o
> diff --git a/drivers/misc/misc-uclass.c b/drivers/misc/misc-uclass.c
> new file mode 100644
> index 0000000..40fe947
> --- /dev/null
> +++ b/drivers/misc/misc-uclass.c
> @@ -0,0 +1,14 @@
> +/*
> + * Copyright (C) 2010 Thomas Chou <thomas@wytron.com.tw>
> + *
> + * SPDX-License-Identifier: GPL-2.0+
> + */
> +
> +#include <common.h>
> +#include <dm.h>
> +#include <misc.h>
> +
> +UCLASS_DRIVER(misc) = {
> + .id = UCLASS_MISC,
> + .name = "misc",
> +};
> diff --git a/include/dm/uclass-id.h b/include/dm/uclass-id.h
> index aff34a4..a6982ab 100644
> --- a/include/dm/uclass-id.h
> +++ b/include/dm/uclass-id.h
> @@ -39,6 +39,7 @@ enum uclass_id {
> UCLASS_LED, /* Light-emitting diode (LED) */
> UCLASS_LPC, /* x86 'low pin count' interface */
> UCLASS_MASS_STORAGE, /* Mass storage device */
> + UCLASS_MISC, /* Miscellaneous device */
> UCLASS_MMC, /* SD / MMC card or chip */
> UCLASS_MOD_EXP, /* RSA Mod Exp device */
> UCLASS_PCH, /* x86 platform controller hub */
> diff --git a/include/misc.h b/include/misc.h
> new file mode 100644
> index 0000000..dfca41f
> --- /dev/null
> +++ b/include/misc.h
> @@ -0,0 +1,22 @@
> +/*
> + * Copyright (C) 2015 Thomas Chou <thomas@wytron.com.tw>
> + *
> + * SPDX-License-Identifier: GPL-2.0+
> + */
> +
> +#ifndef _DM_MISC_H_
> +#define _DM_MISC_H_
> +
> +/*
> + * struct dm_misc_ops - Driver model Misc operations
> + *
> + * The uclass interface is implemented by all miscellaneous devices which
> + * use driver model.
> + */
> +struct dm_misc_ops {
> + int (*read)(struct udevice *dev, int offset, void *buf, int size);
> + int (*write)(struct udevice *dev, int offset, const void *buf,
> + int size);
Method comments
> +};
Also don't you need to create misc_read() and misc_write() functions
so people can use it?
> +
> +#endif /* _DM_MISC_H_ */
> --
> 2.1.4
>
Regards,
Simon
^ permalink raw reply [flat|nested] 22+ messages in thread
* [U-Boot] [PATCH v4 1/2] dm: implement a Miscellaneous uclass
2015-09-29 7:23 [U-Boot] [PATCH 1/2] dm: implement a Miscellaneous uclass Thomas Chou
` (2 preceding siblings ...)
2015-09-29 11:59 ` [U-Boot] [PATCH v3 1/2] dm: implement a Miscellaneous uclass Thomas Chou
@ 2015-10-05 2:18 ` Thomas Chou
2015-10-05 2:18 ` [U-Boot] [PATCH v4 2/2] nios2: convert altera sysid to driver model Thomas Chou
2015-10-06 22:49 ` [U-Boot] [PATCH v4 1/2] dm: implement a Miscellaneous uclass Simon Glass
2015-10-07 12:29 ` [U-Boot] [PATCH v5 " Thomas Chou
2015-10-10 9:07 ` [U-Boot] [PATCH v6 1/2] dm: implement a Miscellaneous uclass Thomas Chou
5 siblings, 2 replies; 22+ messages in thread
From: Thomas Chou @ 2015-10-05 2:18 UTC (permalink / raw)
To: u-boot
Implement a Miscellaneous uclass with generic read or
write operations. This class is used only for those
do not fit other more general classes.
Signed-off-by: Thomas Chou <thomas@wytron.com.tw>
---
v2
add missing misc.h.
v3
no change.
v4
add ioctl and comments as Simon suggested.
drivers/misc/Kconfig | 9 ++++++
drivers/misc/Makefile | 1 +
drivers/misc/misc-uclass.c | 52 ++++++++++++++++++++++++++++++
include/dm/uclass-id.h | 1 +
include/misc.h | 79 ++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 142 insertions(+)
create mode 100644 drivers/misc/misc-uclass.c
create mode 100644 include/misc.h
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index 8b38a84..2699329 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -4,6 +4,15 @@
menu "Multifunction device drivers"
+config DM_MISC
+ bool "Enable Driver Model for Misc drivers"
+ depends on DM
+ help
+ Enable driver model for miscellaneous devices. This class is
+ used only for those do not fit other more general classes. A
+ set of generic read, write and ioctl methods may be used to
+ access the device.
+
config CMD_CROS_EC
bool "Enable crosec command"
depends on CROS_EC
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index 8d0fc3c..b285946 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -5,6 +5,7 @@
# SPDX-License-Identifier: GPL-2.0+
#
+obj-$(CONFIG_DM_MISC) += misc-uclass.o
obj-$(CONFIG_ALI152X) += ali512x.o
obj-$(CONFIG_DS4510) += ds4510.o
obj-$(CONFIG_CBMEM_CONSOLE) += cbmem_console.o
diff --git a/drivers/misc/misc-uclass.c b/drivers/misc/misc-uclass.c
new file mode 100644
index 0000000..7cfcd4c
--- /dev/null
+++ b/drivers/misc/misc-uclass.c
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2010 Thomas Chou <thomas@wytron.com.tw>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <errno.h>
+#include <misc.h>
+
+/*
+ * Implement a miscellaneous uclass for those do not fit other more
+ * general classes. A set of generic read, write and ioctl methods may
+ * be used to access the device.
+ */
+
+int misc_read(struct udevice *dev, int offset, void *buf, int size)
+{
+ const struct dm_misc_ops *ops = device_get_ops(dev);
+
+ if (!ops->read)
+ return -ENOSYS;
+
+ return ops->read(dev, offset, buf, size);
+}
+
+int misc_write(struct udevice *dev, int offset, void *buf, int size)
+{
+ const struct dm_misc_ops *ops = device_get_ops(dev);
+
+ if (!ops->write)
+ return -ENOSYS;
+
+ return ops->write(dev, offset, buf, size);
+}
+
+int misc_ioctl(struct udevice *dev, unsigned long request, void *buf)
+{
+ const struct dm_misc_ops *ops = device_get_ops(dev);
+
+ if (!ops->ioctl)
+ return -ENOSYS;
+
+ return ops->ioctl(dev, request, buf);
+}
+
+
+UCLASS_DRIVER(misc) = {
+ .id = UCLASS_MISC,
+ .name = "misc",
+};
diff --git a/include/dm/uclass-id.h b/include/dm/uclass-id.h
index aff34a4..a6982ab 100644
--- a/include/dm/uclass-id.h
+++ b/include/dm/uclass-id.h
@@ -39,6 +39,7 @@ enum uclass_id {
UCLASS_LED, /* Light-emitting diode (LED) */
UCLASS_LPC, /* x86 'low pin count' interface */
UCLASS_MASS_STORAGE, /* Mass storage device */
+ UCLASS_MISC, /* Miscellaneous device */
UCLASS_MMC, /* SD / MMC card or chip */
UCLASS_MOD_EXP, /* RSA Mod Exp device */
UCLASS_PCH, /* x86 platform controller hub */
diff --git a/include/misc.h b/include/misc.h
new file mode 100644
index 0000000..73de11b
--- /dev/null
+++ b/include/misc.h
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2015 Thomas Chou <thomas@wytron.com.tw>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#ifndef _DM_MISC_H_
+#define _DM_MISC_H_
+
+/*
+ * Read the device to buffer, optional.
+ *
+ * @dev: the device
+ * @offset: offset to read the device
+ * @buf: pointer to data buffer
+ * @size: data size in bytes to read the device
+ * @return: 0 if OK, -ve on error
+ */
+int misc_read(struct udevice *dev, int offset, void *buf, int size);
+/*
+ * Write buffer to the device, optional.
+ *
+ * @dev: the device
+ * @offset: offset to write the device
+ * @buf: pointer to data buffer
+ * @size: data size in bytes to write the device
+ * @return: 0 if OK, -ve on error
+ */
+int misc_write(struct udevice *dev, int offset, void *buf, int size);
+/*
+ * Assert command to the device, optional.
+ *
+ * @dev: the device
+ * @request: command to be sent to the device
+ * @buf: pointer to buffer related to the requset
+ * @return: 0 if OK, -ve on error
+ */
+int misc_ioctl(struct udevice *dev, unsigned long request, void *buf);
+
+/*
+ * struct dm_misc_ops - Driver model Misc operations
+ *
+ * The uclass interface is implemented by all miscellaneous devices which
+ * use driver model.
+ */
+struct dm_misc_ops {
+ /*
+ * Read the device to buffer, optional.
+ *
+ * @dev: the device
+ * @offset: offset to read the device
+ * @buf: pointer to data buffer
+ * @size: data size in bytes to read the device
+ * @return: 0 if OK, -ve on error
+ */
+ int (*read)(struct udevice *dev, int offset, void *buf, int size);
+ /*
+ * Write buffer to the device, optional.
+ *
+ * @dev: the device
+ * @offset: offset to write the device
+ * @buf: pointer to data buffer
+ * @size: data size in bytes to write the device
+ * @return: 0 if OK, -ve on error
+ */
+ int (*write)(struct udevice *dev, int offset, const void *buf,
+ int size);
+ /*
+ * Assert command to the device, optional.
+ *
+ * @dev: the device
+ * @request: command to be sent to the device
+ * @buf: pointer to buffer related to the requset
+ * @return: 0 if OK, -ve on error
+ */
+ int (*ioctl)(struct udevice *dev, unsigned long request, void *buf);
+};
+
+#endif /* _DM_MISC_H_ */
--
2.1.4
^ permalink raw reply related [flat|nested] 22+ messages in thread* [U-Boot] [PATCH v4 2/2] nios2: convert altera sysid to driver model
2015-10-05 2:18 ` [U-Boot] [PATCH v4 " Thomas Chou
@ 2015-10-05 2:18 ` Thomas Chou
2015-10-06 22:49 ` Simon Glass
2015-10-07 2:20 ` Chin Liang See
2015-10-06 22:49 ` [U-Boot] [PATCH v4 1/2] dm: implement a Miscellaneous uclass Simon Glass
1 sibling, 2 replies; 22+ messages in thread
From: Thomas Chou @ 2015-10-05 2:18 UTC (permalink / raw)
To: u-boot
Convert altera sysid to driver model with misc uclass.
Signed-off-by: Thomas Chou <thomas@wytron.com.tw>
---
v2
remove trailing whitespace in altera_sysid.c.
v3
fix coding style as suggested by Stefan.
v4
clean up sysid and timestamp in dts as Chin Liang suggested.
arch/nios2/cpu/Makefile | 2 +-
arch/nios2/cpu/cpu.c | 13 +---
arch/nios2/cpu/sysid.c | 46 -------------
arch/nios2/dts/3c120_devboard.dts | 6 ++
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 | 101 +++++++++++++++++++++++++++++
include/configs/nios2-generic.h | 2 +-
10 files changed, 126 insertions(+), 60 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 bd11abc..106f0bf 100644
--- a/arch/nios2/cpu/cpu.c
+++ b/arch/nios2/cpu/cpu.c
@@ -13,20 +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 : <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
index 50819b2..0000000
--- a/arch/nios2/cpu/sysid.c
+++ /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 */
diff --git a/arch/nios2/dts/3c120_devboard.dts b/arch/nios2/dts/3c120_devboard.dts
index 2e2956f..2455fff 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,11 @@
clock-frequency = < 125000000 >;
};
+ sysid: sysid at 0x4d40 {
+ compatible = "altr,sysid-1.0";
+ reg = <0x00004d40 0x00000008>;
+ };
+
jtag_uart: serial at 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 dac0b62..5576413 100644
--- a/configs/nios2-generic_defconfig
+++ b/configs/nios2-generic_defconfig
@@ -16,6 +16,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 2699329..a292289 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -13,6 +13,13 @@ config DM_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 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..980f3b6
--- /dev/null
+++ b/drivers/misc/altera_sysid.c
@@ -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 <dm.h>
+#include <misc.h>
+#include <errno.h>
+#include <command.h>
+#include <asm/io.h>
+#include <linux/time.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(®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..16a16f3 100644
--- a/include/configs/nios2-generic.h
+++ b/include/configs/nios2-generic.h
@@ -17,7 +17,7 @@
#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
/*
--
2.1.4
^ permalink raw reply related [flat|nested] 22+ messages in thread* [U-Boot] [PATCH v4 2/2] nios2: convert altera sysid to driver model
2015-10-05 2:18 ` [U-Boot] [PATCH v4 2/2] nios2: convert altera sysid to driver model Thomas Chou
@ 2015-10-06 22:49 ` Simon Glass
2015-10-07 2:20 ` Chin Liang See
1 sibling, 0 replies; 22+ messages in thread
From: Simon Glass @ 2015-10-06 22:49 UTC (permalink / raw)
To: u-boot
Hi Thomas,
On 5 October 2015 at 03:18, Thomas Chou <thomas@wytron.com.tw> wrote:
> Convert altera sysid to driver model with misc uclass.
>
> Signed-off-by: Thomas Chou <thomas@wytron.com.tw>
> ---
> v2
> remove trailing whitespace in altera_sysid.c.
> v3
> fix coding style as suggested by Stefan.
> v4
> clean up sysid and timestamp in dts as Chin Liang suggested.
>
> arch/nios2/cpu/Makefile | 2 +-
> arch/nios2/cpu/cpu.c | 13 +---
> arch/nios2/cpu/sysid.c | 46 -------------
> arch/nios2/dts/3c120_devboard.dts | 6 ++
> 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 | 101 +++++++++++++++++++++++++++++
> include/configs/nios2-generic.h | 2 +-
> 10 files changed, 126 insertions(+), 60 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 bd11abc..106f0bf 100644
> --- a/arch/nios2/cpu/cpu.c
> +++ b/arch/nios2/cpu/cpu.c
> @@ -13,20 +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 : <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
> index 50819b2..0000000
> --- a/arch/nios2/cpu/sysid.c
> +++ /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 */
> diff --git a/arch/nios2/dts/3c120_devboard.dts b/arch/nios2/dts/3c120_devboard.dts
> index 2e2956f..2455fff 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,11 @@
> clock-frequency = < 125000000 >;
> };
>
> + sysid: sysid at 0x4d40 {
> + compatible = "altr,sysid-1.0";
> + reg = <0x00004d40 0x00000008>;
> + };
> +
> jtag_uart: serial at 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);
Should that go in a system header file asm/system.h or similar?
> + 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 dac0b62..5576413 100644
> --- a/configs/nios2-generic_defconfig
> +++ b/configs/nios2-generic_defconfig
> @@ -16,6 +16,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 2699329..a292289 100644
> --- a/drivers/misc/Kconfig
> +++ b/drivers/misc/Kconfig
> @@ -13,6 +13,13 @@ config DM_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 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..980f3b6
> --- /dev/null
> +++ b/drivers/misc/altera_sysid.c
> @@ -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 <dm.h>
> +#include <misc.h>
> +#include <errno.h>
nit: Should sort these
common.h
command.h
dm.h
errno.h
misc.h
> +#include <command.h>
> +#include <asm/io.h>
> +#include <linux/time.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(®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..16a16f3 100644
> --- a/include/configs/nios2-generic.h
> +++ b/include/configs/nios2-generic.h
> @@ -17,7 +17,7 @@
> #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
>
> /*
> --
> 2.1.4
>
Regards,
Simon
^ permalink raw reply [flat|nested] 22+ messages in thread* [U-Boot] [PATCH v4 2/2] nios2: convert altera sysid to driver model
2015-10-05 2:18 ` [U-Boot] [PATCH v4 2/2] nios2: convert altera sysid to driver model Thomas Chou
2015-10-06 22:49 ` Simon Glass
@ 2015-10-07 2:20 ` Chin Liang See
1 sibling, 0 replies; 22+ messages in thread
From: Chin Liang See @ 2015-10-07 2:20 UTC (permalink / raw)
To: u-boot
Hi Thomas,
On Mon, 2015-10-05 at 10:18 +0800, thomas at wytron.com.tw wrote:
> Convert altera sysid to driver model with misc uclass.
>
> Signed-off-by: Thomas Chou <thomas@wytron.com.tw>
> ---
> v2
> remove trailing whitespace in altera_sysid.c.
> v3
> fix coding style as suggested by Stefan.
> v4
> clean up sysid and timestamp in dts as Chin Liang suggested.
>
Acked-by: Chin Liang See <clsee@altera.com>
Thanks
Chin Liang
^ permalink raw reply [flat|nested] 22+ messages in thread
* [U-Boot] [PATCH v4 1/2] dm: implement a Miscellaneous uclass
2015-10-05 2:18 ` [U-Boot] [PATCH v4 " Thomas Chou
2015-10-05 2:18 ` [U-Boot] [PATCH v4 2/2] nios2: convert altera sysid to driver model Thomas Chou
@ 2015-10-06 22:49 ` Simon Glass
1 sibling, 0 replies; 22+ messages in thread
From: Simon Glass @ 2015-10-06 22:49 UTC (permalink / raw)
To: u-boot
On 5 October 2015 at 03:18, Thomas Chou <thomas@wytron.com.tw> wrote:
> Implement a Miscellaneous uclass with generic read or
> write operations. This class is used only for those
> do not fit other more general classes.
>
> Signed-off-by: Thomas Chou <thomas@wytron.com.tw>
> ---
> v2
> add missing misc.h.
> v3
> no change.
> v4
> add ioctl and comments as Simon suggested.
>
> drivers/misc/Kconfig | 9 ++++++
> drivers/misc/Makefile | 1 +
> drivers/misc/misc-uclass.c | 52 ++++++++++++++++++++++++++++++
> include/dm/uclass-id.h | 1 +
> include/misc.h | 79 ++++++++++++++++++++++++++++++++++++++++++++++
> 5 files changed, 142 insertions(+)
> create mode 100644 drivers/misc/misc-uclass.c
> create mode 100644 include/misc.h
Acked-by: Simon Glass <sjg@chromium.org>
^ permalink raw reply [flat|nested] 22+ messages in thread
* [U-Boot] [PATCH v5 1/2] dm: implement a Miscellaneous uclass
2015-09-29 7:23 [U-Boot] [PATCH 1/2] dm: implement a Miscellaneous uclass Thomas Chou
` (3 preceding siblings ...)
2015-10-05 2:18 ` [U-Boot] [PATCH v4 " Thomas Chou
@ 2015-10-07 12:29 ` Thomas Chou
2015-10-07 12:29 ` [U-Boot] [PATCH v5 2/2] nios2: convert altera sysid to driver model Thomas Chou
2015-10-10 9:07 ` [U-Boot] [PATCH v6 1/2] dm: implement a Miscellaneous uclass Thomas Chou
5 siblings, 1 reply; 22+ messages in thread
From: Thomas Chou @ 2015-10-07 12:29 UTC (permalink / raw)
To: u-boot
Implement a Miscellaneous uclass with generic read or
write operations. This class is used only for those
do not fit other more general classes.
Signed-off-by: Thomas Chou <thomas@wytron.com.tw>
Acked-by: Simon Glass <sjg@chromium.org>
---
v2
add missing misc.h.
v3
no change.
v4
add ioctl and comments as Simon suggested.
v5
no change.
drivers/misc/Kconfig | 9 ++++++
drivers/misc/Makefile | 1 +
drivers/misc/misc-uclass.c | 51 ++++++++++++++++++++++++++++++
include/dm/uclass-id.h | 1 +
include/misc.h | 79 ++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 141 insertions(+)
create mode 100644 drivers/misc/misc-uclass.c
create mode 100644 include/misc.h
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index 8b38a84..2699329 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -4,6 +4,15 @@
menu "Multifunction device drivers"
+config DM_MISC
+ bool "Enable Driver Model for Misc drivers"
+ depends on DM
+ help
+ Enable driver model for miscellaneous devices. This class is
+ used only for those do not fit other more general classes. A
+ set of generic read, write and ioctl methods may be used to
+ access the device.
+
config CMD_CROS_EC
bool "Enable crosec command"
depends on CROS_EC
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index 8d0fc3c..b285946 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -5,6 +5,7 @@
# SPDX-License-Identifier: GPL-2.0+
#
+obj-$(CONFIG_DM_MISC) += misc-uclass.o
obj-$(CONFIG_ALI152X) += ali512x.o
obj-$(CONFIG_DS4510) += ds4510.o
obj-$(CONFIG_CBMEM_CONSOLE) += cbmem_console.o
diff --git a/drivers/misc/misc-uclass.c b/drivers/misc/misc-uclass.c
new file mode 100644
index 0000000..a436ff5
--- /dev/null
+++ b/drivers/misc/misc-uclass.c
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2010 Thomas Chou <thomas@wytron.com.tw>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <errno.h>
+#include <misc.h>
+
+/*
+ * Implement a miscellaneous uclass for those do not fit other more
+ * general classes. A set of generic read, write and ioctl methods may
+ * be used to access the device.
+ */
+
+int misc_read(struct udevice *dev, int offset, void *buf, int size)
+{
+ const struct dm_misc_ops *ops = device_get_ops(dev);
+
+ if (!ops->read)
+ return -ENOSYS;
+
+ return ops->read(dev, offset, buf, size);
+}
+
+int misc_write(struct udevice *dev, int offset, void *buf, int size)
+{
+ const struct dm_misc_ops *ops = device_get_ops(dev);
+
+ if (!ops->write)
+ return -ENOSYS;
+
+ return ops->write(dev, offset, buf, size);
+}
+
+int misc_ioctl(struct udevice *dev, unsigned long request, void *buf)
+{
+ const struct dm_misc_ops *ops = device_get_ops(dev);
+
+ if (!ops->ioctl)
+ return -ENOSYS;
+
+ return ops->ioctl(dev, request, buf);
+}
+
+UCLASS_DRIVER(misc) = {
+ .id = UCLASS_MISC,
+ .name = "misc",
+};
diff --git a/include/dm/uclass-id.h b/include/dm/uclass-id.h
index aff34a4..a6982ab 100644
--- a/include/dm/uclass-id.h
+++ b/include/dm/uclass-id.h
@@ -39,6 +39,7 @@ enum uclass_id {
UCLASS_LED, /* Light-emitting diode (LED) */
UCLASS_LPC, /* x86 'low pin count' interface */
UCLASS_MASS_STORAGE, /* Mass storage device */
+ UCLASS_MISC, /* Miscellaneous device */
UCLASS_MMC, /* SD / MMC card or chip */
UCLASS_MOD_EXP, /* RSA Mod Exp device */
UCLASS_PCH, /* x86 platform controller hub */
diff --git a/include/misc.h b/include/misc.h
new file mode 100644
index 0000000..73de11b
--- /dev/null
+++ b/include/misc.h
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2015 Thomas Chou <thomas@wytron.com.tw>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#ifndef _DM_MISC_H_
+#define _DM_MISC_H_
+
+/*
+ * Read the device to buffer, optional.
+ *
+ * @dev: the device
+ * @offset: offset to read the device
+ * @buf: pointer to data buffer
+ * @size: data size in bytes to read the device
+ * @return: 0 if OK, -ve on error
+ */
+int misc_read(struct udevice *dev, int offset, void *buf, int size);
+/*
+ * Write buffer to the device, optional.
+ *
+ * @dev: the device
+ * @offset: offset to write the device
+ * @buf: pointer to data buffer
+ * @size: data size in bytes to write the device
+ * @return: 0 if OK, -ve on error
+ */
+int misc_write(struct udevice *dev, int offset, void *buf, int size);
+/*
+ * Assert command to the device, optional.
+ *
+ * @dev: the device
+ * @request: command to be sent to the device
+ * @buf: pointer to buffer related to the requset
+ * @return: 0 if OK, -ve on error
+ */
+int misc_ioctl(struct udevice *dev, unsigned long request, void *buf);
+
+/*
+ * struct dm_misc_ops - Driver model Misc operations
+ *
+ * The uclass interface is implemented by all miscellaneous devices which
+ * use driver model.
+ */
+struct dm_misc_ops {
+ /*
+ * Read the device to buffer, optional.
+ *
+ * @dev: the device
+ * @offset: offset to read the device
+ * @buf: pointer to data buffer
+ * @size: data size in bytes to read the device
+ * @return: 0 if OK, -ve on error
+ */
+ int (*read)(struct udevice *dev, int offset, void *buf, int size);
+ /*
+ * Write buffer to the device, optional.
+ *
+ * @dev: the device
+ * @offset: offset to write the device
+ * @buf: pointer to data buffer
+ * @size: data size in bytes to write the device
+ * @return: 0 if OK, -ve on error
+ */
+ int (*write)(struct udevice *dev, int offset, const void *buf,
+ int size);
+ /*
+ * Assert command to the device, optional.
+ *
+ * @dev: the device
+ * @request: command to be sent to the device
+ * @buf: pointer to buffer related to the requset
+ * @return: 0 if OK, -ve on error
+ */
+ int (*ioctl)(struct udevice *dev, unsigned long request, void *buf);
+};
+
+#endif /* _DM_MISC_H_ */
--
2.1.4
^ permalink raw reply related [flat|nested] 22+ messages in thread* [U-Boot] [PATCH v5 2/2] nios2: convert altera sysid to driver model
2015-10-07 12:29 ` [U-Boot] [PATCH v5 " Thomas Chou
@ 2015-10-07 12:29 ` Thomas Chou
2015-10-07 22:47 ` Simon Glass
0 siblings, 1 reply; 22+ messages in thread
From: Thomas Chou @ 2015-10-07 12:29 UTC (permalink / raw)
To: u-boot
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>
---
v2
fix coding style.
v3
doc dts binding.
v4
no change.
v5
sort headers inclusion as Simon suggested.
add display_sysid() to asm/system.h.
arch/nios2/cpu/Makefile | 2 +-
arch/nios2/cpu/cpu.c | 13 +---
arch/nios2/cpu/sysid.c | 46 -------------
arch/nios2/dts/3c120_devboard.dts | 6 ++
arch/nios2/include/asm/system.h | 2 +
board/altera/nios2-generic/nios2-generic.c | 5 +-
configs/nios2-generic_defconfig | 2 +
drivers/misc/Kconfig | 7 ++
drivers/misc/Makefile | 1 +
drivers/misc/altera_sysid.c | 101 +++++++++++++++++++++++++++++
include/configs/nios2-generic.h | 2 +-
11 files changed, 127 insertions(+), 60 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 bd11abc..106f0bf 100644
--- a/arch/nios2/cpu/cpu.c
+++ b/arch/nios2/cpu/cpu.c
@@ -13,20 +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 : <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
index 50819b2..0000000
--- a/arch/nios2/cpu/sysid.c
+++ /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 */
diff --git a/arch/nios2/dts/3c120_devboard.dts b/arch/nios2/dts/3c120_devboard.dts
index 2e2956f..2455fff 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,11 @@
clock-frequency = < 125000000 >;
};
+ sysid: sysid at 0x4d40 {
+ compatible = "altr,sysid-1.0";
+ reg = <0x00004d40 0x00000008>;
+ };
+
jtag_uart: serial at 0x4d50 {
compatible = "altr,juart-1.0";
reg = <0x00004d50 0x00000008>;
diff --git a/arch/nios2/include/asm/system.h b/arch/nios2/include/asm/system.h
index 6213a16..b158535 100644
--- a/arch/nios2/include/asm/system.h
+++ b/arch/nios2/include/asm/system.h
@@ -45,4 +45,6 @@
"callr %0" \
: : "r" (addr))
+void display_sysid(void);
+
#endif /* __ASM_NIOS2_SYSTEM_H */
diff --git a/board/altera/nios2-generic/nios2-generic.c b/board/altera/nios2-generic/nios2-generic.c
index 61d32c7..be5c350 100644
--- a/board/altera/nios2-generic/nios2-generic.c
+++ b/board/altera/nios2-generic/nios2-generic.c
@@ -42,7 +42,10 @@ int board_early_init_r(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;
}
diff --git a/configs/nios2-generic_defconfig b/configs/nios2-generic_defconfig
index dac0b62..5576413 100644
--- a/configs/nios2-generic_defconfig
+++ b/configs/nios2-generic_defconfig
@@ -16,6 +16,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 2699329..a292289 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -13,6 +13,13 @@ config DM_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 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..177e434
--- /dev/null
+++ b/drivers/misc/altera_sysid.c
@@ -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(®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..16a16f3 100644
--- a/include/configs/nios2-generic.h
+++ b/include/configs/nios2-generic.h
@@ -17,7 +17,7 @@
#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
/*
--
2.1.4
^ permalink raw reply related [flat|nested] 22+ messages in thread* [U-Boot] [PATCH v5 2/2] nios2: convert altera sysid to driver model
2015-10-07 12:29 ` [U-Boot] [PATCH v5 2/2] nios2: convert altera sysid to driver model Thomas Chou
@ 2015-10-07 22:47 ` Simon Glass
0 siblings, 0 replies; 22+ messages in thread
From: Simon Glass @ 2015-10-07 22:47 UTC (permalink / raw)
To: u-boot
On 7 October 2015 at 13:29, Thomas Chou <thomas@wytron.com.tw> wrote:
> 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>
> ---
> v2
> fix coding style.
> v3
> doc dts binding.
> v4
> no change.
> v5
> sort headers inclusion as Simon suggested.
> add display_sysid() to asm/system.h.
>
> arch/nios2/cpu/Makefile | 2 +-
> arch/nios2/cpu/cpu.c | 13 +---
> arch/nios2/cpu/sysid.c | 46 -------------
> arch/nios2/dts/3c120_devboard.dts | 6 ++
> arch/nios2/include/asm/system.h | 2 +
> board/altera/nios2-generic/nios2-generic.c | 5 +-
> configs/nios2-generic_defconfig | 2 +
> drivers/misc/Kconfig | 7 ++
> drivers/misc/Makefile | 1 +
> drivers/misc/altera_sysid.c | 101 +++++++++++++++++++++++++++++
> include/configs/nios2-generic.h | 2 +-
> 11 files changed, 127 insertions(+), 60 deletions(-)
> delete mode 100644 arch/nios2/cpu/sysid.c
> create mode 100644 drivers/misc/altera_sysid.c
Reviewed-by: Simon Glass <sjg@chromium.org>
^ permalink raw reply [flat|nested] 22+ messages in thread
* [U-Boot] [PATCH v6 1/2] dm: implement a Miscellaneous uclass
2015-09-29 7:23 [U-Boot] [PATCH 1/2] dm: implement a Miscellaneous uclass Thomas Chou
` (4 preceding siblings ...)
2015-10-07 12:29 ` [U-Boot] [PATCH v5 " Thomas Chou
@ 2015-10-10 9:07 ` Thomas Chou
2015-10-10 9:07 ` [U-Boot] [PATCH v6 2/2] nios2: convert altera sysid to driver model Thomas Chou
2015-10-13 13:18 ` [U-Boot] [PATCH v6 1/2] dm: implement a Miscellaneous uclass Thomas Chou
5 siblings, 2 replies; 22+ messages in thread
From: Thomas Chou @ 2015-10-10 9:07 UTC (permalink / raw)
To: u-boot
Implement a Miscellaneous uclass with generic read or
write operations. This class is used only for those
do not fit other more general classes.
Signed-off-by: Thomas Chou <thomas@wytron.com.tw>
Acked-by: Simon Glass <sjg@chromium.org>
---
v2
add missing misc.h.
v3
no change.
v4
add ioctl and comments as Simon suggested.
v5
no change.
v6
replace DM_MISC to MISC.
drivers/misc/Kconfig | 9 ++++++
drivers/misc/Makefile | 1 +
drivers/misc/misc-uclass.c | 51 ++++++++++++++++++++++++++++++
include/dm/uclass-id.h | 1 +
include/misc.h | 79 ++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 141 insertions(+)
create mode 100644 drivers/misc/misc-uclass.c
create mode 100644 include/misc.h
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index 8b38a84..2699329 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -4,6 +4,15 @@
menu "Multifunction device drivers"
+config MISC
+ bool "Enable Driver Model for Misc drivers"
+ depends on DM
+ help
+ Enable driver model for miscellaneous devices. This class is
+ used only for those do not fit other more general classes. A
+ set of generic read, write and ioctl methods may be used to
+ access the device.
+
config CMD_CROS_EC
bool "Enable crosec command"
depends on CROS_EC
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index 8d0fc3c..b285946 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -5,6 +5,7 @@
# SPDX-License-Identifier: GPL-2.0+
#
+obj-$(CONFIG_MISC) += misc-uclass.o
obj-$(CONFIG_ALI152X) += ali512x.o
obj-$(CONFIG_DS4510) += ds4510.o
obj-$(CONFIG_CBMEM_CONSOLE) += cbmem_console.o
diff --git a/drivers/misc/misc-uclass.c b/drivers/misc/misc-uclass.c
new file mode 100644
index 0000000..a436ff5
--- /dev/null
+++ b/drivers/misc/misc-uclass.c
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2010 Thomas Chou <thomas@wytron.com.tw>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <errno.h>
+#include <misc.h>
+
+/*
+ * Implement a miscellaneous uclass for those do not fit other more
+ * general classes. A set of generic read, write and ioctl methods may
+ * be used to access the device.
+ */
+
+int misc_read(struct udevice *dev, int offset, void *buf, int size)
+{
+ const struct misc_ops *ops = device_get_ops(dev);
+
+ if (!ops->read)
+ return -ENOSYS;
+
+ return ops->read(dev, offset, buf, size);
+}
+
+int misc_write(struct udevice *dev, int offset, void *buf, int size)
+{
+ const struct misc_ops *ops = device_get_ops(dev);
+
+ if (!ops->write)
+ return -ENOSYS;
+
+ return ops->write(dev, offset, buf, size);
+}
+
+int misc_ioctl(struct udevice *dev, unsigned long request, void *buf)
+{
+ const struct misc_ops *ops = device_get_ops(dev);
+
+ if (!ops->ioctl)
+ return -ENOSYS;
+
+ return ops->ioctl(dev, request, buf);
+}
+
+UCLASS_DRIVER(misc) = {
+ .id = UCLASS_MISC,
+ .name = "misc",
+};
diff --git a/include/dm/uclass-id.h b/include/dm/uclass-id.h
index aff34a4..a6982ab 100644
--- a/include/dm/uclass-id.h
+++ b/include/dm/uclass-id.h
@@ -39,6 +39,7 @@ enum uclass_id {
UCLASS_LED, /* Light-emitting diode (LED) */
UCLASS_LPC, /* x86 'low pin count' interface */
UCLASS_MASS_STORAGE, /* Mass storage device */
+ UCLASS_MISC, /* Miscellaneous device */
UCLASS_MMC, /* SD / MMC card or chip */
UCLASS_MOD_EXP, /* RSA Mod Exp device */
UCLASS_PCH, /* x86 platform controller hub */
diff --git a/include/misc.h b/include/misc.h
new file mode 100644
index 0000000..73de11b
--- /dev/null
+++ b/include/misc.h
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2015 Thomas Chou <thomas@wytron.com.tw>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#ifndef _MISC_H_
+#define _MISC_H_
+
+/*
+ * Read the device to buffer, optional.
+ *
+ * @dev: the device
+ * @offset: offset to read the device
+ * @buf: pointer to data buffer
+ * @size: data size in bytes to read the device
+ * @return: 0 if OK, -ve on error
+ */
+int misc_read(struct udevice *dev, int offset, void *buf, int size);
+/*
+ * Write buffer to the device, optional.
+ *
+ * @dev: the device
+ * @offset: offset to write the device
+ * @buf: pointer to data buffer
+ * @size: data size in bytes to write the device
+ * @return: 0 if OK, -ve on error
+ */
+int misc_write(struct udevice *dev, int offset, void *buf, int size);
+/*
+ * Assert command to the device, optional.
+ *
+ * @dev: the device
+ * @request: command to be sent to the device
+ * @buf: pointer to buffer related to the requset
+ * @return: 0 if OK, -ve on error
+ */
+int misc_ioctl(struct udevice *dev, unsigned long request, void *buf);
+
+/*
+ * struct misc_ops - Driver model Misc operations
+ *
+ * The uclass interface is implemented by all miscellaneous devices which
+ * use driver model.
+ */
+struct misc_ops {
+ /*
+ * Read the device to buffer, optional.
+ *
+ * @dev: the device
+ * @offset: offset to read the device
+ * @buf: pointer to data buffer
+ * @size: data size in bytes to read the device
+ * @return: 0 if OK, -ve on error
+ */
+ int (*read)(struct udevice *dev, int offset, void *buf, int size);
+ /*
+ * Write buffer to the device, optional.
+ *
+ * @dev: the device
+ * @offset: offset to write the device
+ * @buf: pointer to data buffer
+ * @size: data size in bytes to write the device
+ * @return: 0 if OK, -ve on error
+ */
+ int (*write)(struct udevice *dev, int offset, const void *buf,
+ int size);
+ /*
+ * Assert command to the device, optional.
+ *
+ * @dev: the device
+ * @request: command to be sent to the device
+ * @buf: pointer to buffer related to the requset
+ * @return: 0 if OK, -ve on error
+ */
+ int (*ioctl)(struct udevice *dev, unsigned long request, void *buf);
+};
+
+#endif /* _MISC_H_ */
--
2.1.4
^ permalink raw reply related [flat|nested] 22+ messages in thread* [U-Boot] [PATCH v6 2/2] nios2: convert altera sysid to driver model
2015-10-10 9:07 ` [U-Boot] [PATCH v6 1/2] dm: implement a Miscellaneous uclass Thomas Chou
@ 2015-10-10 9:07 ` Thomas Chou
2015-10-13 13:18 ` Thomas Chou
2015-10-13 13:18 ` [U-Boot] [PATCH v6 1/2] dm: implement a Miscellaneous uclass Thomas Chou
1 sibling, 1 reply; 22+ messages in thread
From: Thomas Chou @ 2015-10-10 9:07 UTC (permalink / raw)
To: u-boot
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>
---
v2
fix coding style.
v3
doc dts binding.
v4
no change.
v5
sort headers inclusion as Simon suggested.
add display_sysid() to asm/system.h.
v6
replace DM_MISC to MISC.
arch/nios2/cpu/Makefile | 2 +-
arch/nios2/cpu/cpu.c | 13 +---
arch/nios2/cpu/sysid.c | 46 -------------
arch/nios2/dts/3c120_devboard.dts | 6 ++
arch/nios2/include/asm/system.h | 2 +
board/altera/nios2-generic/nios2-generic.c | 5 +-
configs/nios2-generic_defconfig | 2 +
drivers/misc/Kconfig | 7 ++
drivers/misc/Makefile | 1 +
drivers/misc/altera_sysid.c | 101 +++++++++++++++++++++++++++++
include/configs/nios2-generic.h | 2 +-
11 files changed, 127 insertions(+), 60 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 bd11abc..106f0bf 100644
--- a/arch/nios2/cpu/cpu.c
+++ b/arch/nios2/cpu/cpu.c
@@ -13,20 +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 : <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
index 50819b2..0000000
--- a/arch/nios2/cpu/sysid.c
+++ /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 */
diff --git a/arch/nios2/dts/3c120_devboard.dts b/arch/nios2/dts/3c120_devboard.dts
index 2e2956f..2455fff 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,11 @@
clock-frequency = < 125000000 >;
};
+ sysid: sysid at 0x4d40 {
+ compatible = "altr,sysid-1.0";
+ reg = <0x00004d40 0x00000008>;
+ };
+
jtag_uart: serial at 0x4d50 {
compatible = "altr,juart-1.0";
reg = <0x00004d50 0x00000008>;
diff --git a/arch/nios2/include/asm/system.h b/arch/nios2/include/asm/system.h
index 6213a16..b158535 100644
--- a/arch/nios2/include/asm/system.h
+++ b/arch/nios2/include/asm/system.h
@@ -45,4 +45,6 @@
"callr %0" \
: : "r" (addr))
+void display_sysid(void);
+
#endif /* __ASM_NIOS2_SYSTEM_H */
diff --git a/board/altera/nios2-generic/nios2-generic.c b/board/altera/nios2-generic/nios2-generic.c
index cb98a08..1f10821 100644
--- a/board/altera/nios2-generic/nios2-generic.c
+++ b/board/altera/nios2-generic/nios2-generic.c
@@ -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;
}
diff --git a/configs/nios2-generic_defconfig b/configs/nios2-generic_defconfig
index 505a2cf..a9020ff 100644
--- a/configs/nios2-generic_defconfig
+++ b/configs/nios2-generic_defconfig
@@ -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/drivers/misc/Kconfig b/drivers/misc/Kconfig
index 2699329..a292289 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -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
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_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..177e434
--- /dev/null
+++ b/drivers/misc/altera_sysid.c
@@ -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(®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 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 c65b3b3..e4b5abb 100644
--- a/include/configs/nios2-generic.h
+++ b/include/configs/nios2-generic.h
@@ -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
/*
--
2.1.4
^ permalink raw reply related [flat|nested] 22+ messages in thread* [U-Boot] [PATCH v6 2/2] nios2: convert altera sysid to driver model
2015-10-10 9:07 ` [U-Boot] [PATCH v6 2/2] nios2: convert altera sysid to driver model Thomas Chou
@ 2015-10-13 13:18 ` Thomas Chou
0 siblings, 0 replies; 22+ messages in thread
From: Thomas Chou @ 2015-10-13 13:18 UTC (permalink / raw)
To: u-boot
On 10/10/2015 05:07 PM, Thomas Chou wrote:
> 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>
> ---
> v2
> fix coding style.
> v3
> doc dts binding.
> v4
> no change.
> v5
> sort headers inclusion as Simon suggested.
> add display_sysid() to asm/system.h.
> v6
> replace DM_MISC to MISC.
>
> arch/nios2/cpu/Makefile | 2 +-
> arch/nios2/cpu/cpu.c | 13 +---
> arch/nios2/cpu/sysid.c | 46 -------------
> arch/nios2/dts/3c120_devboard.dts | 6 ++
> arch/nios2/include/asm/system.h | 2 +
> board/altera/nios2-generic/nios2-generic.c | 5 +-
> configs/nios2-generic_defconfig | 2 +
> drivers/misc/Kconfig | 7 ++
> drivers/misc/Makefile | 1 +
> drivers/misc/altera_sysid.c | 101 +++++++++++++++++++++++++++++
> include/configs/nios2-generic.h | 2 +-
> 11 files changed, 127 insertions(+), 60 deletions(-)
> delete mode 100644 arch/nios2/cpu/sysid.c
> create mode 100644 drivers/misc/altera_sysid.c
>
Applied to u-boot-nios.
^ permalink raw reply [flat|nested] 22+ messages in thread
* [U-Boot] [PATCH v6 1/2] dm: implement a Miscellaneous uclass
2015-10-10 9:07 ` [U-Boot] [PATCH v6 1/2] dm: implement a Miscellaneous uclass Thomas Chou
2015-10-10 9:07 ` [U-Boot] [PATCH v6 2/2] nios2: convert altera sysid to driver model Thomas Chou
@ 2015-10-13 13:18 ` Thomas Chou
1 sibling, 0 replies; 22+ messages in thread
From: Thomas Chou @ 2015-10-13 13:18 UTC (permalink / raw)
To: u-boot
On 10/10/2015 05:07 PM, Thomas Chou wrote:
> Implement a Miscellaneous uclass with generic read or
> write operations. This class is used only for those
> do not fit other more general classes.
>
> Signed-off-by: Thomas Chou <thomas@wytron.com.tw>
> Acked-by: Simon Glass <sjg@chromium.org>
> ---
> v2
> add missing misc.h.
> v3
> no change.
> v4
> add ioctl and comments as Simon suggested.
> v5
> no change.
> v6
> replace DM_MISC to MISC.
>
> drivers/misc/Kconfig | 9 ++++++
> drivers/misc/Makefile | 1 +
> drivers/misc/misc-uclass.c | 51 ++++++++++++++++++++++++++++++
> include/dm/uclass-id.h | 1 +
> include/misc.h | 79 ++++++++++++++++++++++++++++++++++++++++++++++
> 5 files changed, 141 insertions(+)
> create mode 100644 drivers/misc/misc-uclass.c
> create mode 100644 include/misc.h
>
Applied to u-boot-nios.
^ permalink raw reply [flat|nested] 22+ messages in thread