1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2004, Psyent Corporation <www.psyent.com>
4 * Scott McNutt <smcnutt@psyent.com>
11 #include <linux/time.h>
14 struct altera_sysid_regs {
15 u32 id; /* The system build id */
16 u32 timestamp; /* Timestamp */
19 struct altera_sysid_plat {
20 struct altera_sysid_regs *regs;
23 void display_sysid(void)
32 /* the first misc device will be used */
33 ret = uclass_first_device_err(UCLASS_MISC, &dev);
36 ret = misc_read(dev, 0, &sysid, sizeof(sysid));
41 localtime_r(&stamp, &t);
43 printf("SYSID: %08x, %s", sysid[0], asc);
46 int do_sysid(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
53 sysid, 1, 1, do_sysid,
54 "display Nios-II system id",
58 static int altera_sysid_read(struct udevice *dev,
59 int offset, void *buf, int size)
61 struct altera_sysid_plat *plat = dev_get_plat(dev);
62 struct altera_sysid_regs *const regs = plat->regs;
65 sysid[0] = readl(®s->id);
66 sysid[1] = readl(®s->timestamp);
71 static int altera_sysid_of_to_plat(struct udevice *dev)
73 struct altera_sysid_plat *plat = dev_get_plat(dev);
75 plat->regs = map_physmem(dev_read_addr(dev),
76 sizeof(struct altera_sysid_regs),
82 static const struct misc_ops altera_sysid_ops = {
83 .read = altera_sysid_read,
86 static const struct udevice_id altera_sysid_ids[] = {
87 { .compatible = "altr,sysid-1.0" },
91 U_BOOT_DRIVER(altera_sysid) = {
92 .name = "altera_sysid",
94 .of_match = altera_sysid_ids,
95 .of_to_plat = altera_sysid_of_to_plat,
96 .plat_auto = sizeof(struct altera_sysid_plat),
97 .ops = &altera_sysid_ops,