1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2004, Psyent Corporation <www.psyent.com>
4 * Scott McNutt <smcnutt@psyent.com>
12 #include <linux/time.h>
15 struct altera_sysid_regs {
16 u32 id; /* The system build id */
17 u32 timestamp; /* Timestamp */
20 struct altera_sysid_platdata {
21 struct altera_sysid_regs *regs;
24 void display_sysid(void)
33 /* the first misc device will be used */
34 ret = uclass_first_device_err(UCLASS_MISC, &dev);
37 ret = misc_read(dev, 0, &sysid, sizeof(sysid));
42 localtime_r(&stamp, &t);
44 printf("SYSID: %08x, %s", sysid[0], asc);
47 int do_sysid(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
54 sysid, 1, 1, do_sysid,
55 "display Nios-II system id",
59 static int altera_sysid_read(struct udevice *dev,
60 int offset, void *buf, int size)
62 struct altera_sysid_platdata *plat = dev->plat;
63 struct altera_sysid_regs *const regs = plat->regs;
66 sysid[0] = readl(®s->id);
67 sysid[1] = readl(®s->timestamp);
72 static int altera_sysid_ofdata_to_platdata(struct udevice *dev)
74 struct altera_sysid_platdata *plat = dev_get_plat(dev);
76 plat->regs = map_physmem(dev_read_addr(dev),
77 sizeof(struct altera_sysid_regs),
83 static const struct misc_ops altera_sysid_ops = {
84 .read = altera_sysid_read,
87 static const struct udevice_id altera_sysid_ids[] = {
88 { .compatible = "altr,sysid-1.0" },
92 U_BOOT_DRIVER(altera_sysid) = {
93 .name = "altera_sysid",
95 .of_match = altera_sysid_ids,
96 .ofdata_to_platdata = altera_sysid_ofdata_to_platdata,
97 .plat_auto = sizeof(struct altera_sysid_platdata),
98 .ops = &altera_sysid_ops,