2 * (C) Copyright 2004, Psyent Corporation <www.psyent.com>
3 * Scott McNutt <smcnutt@psyent.com>
5 * SPDX-License-Identifier: GPL-2.0+
13 #include <linux/time.h>
16 struct altera_sysid_regs {
17 u32 id; /* The system build id */
18 u32 timestamp; /* Timestamp */
21 struct altera_sysid_platdata {
22 struct altera_sysid_regs *regs;
25 void display_sysid(void)
34 /* the first misc device will be used */
35 ret = uclass_first_device_err(UCLASS_MISC, &dev);
38 ret = misc_read(dev, 0, &sysid, sizeof(sysid));
43 localtime_r(&stamp, &t);
45 printf("SYSID: %08x, %s", sysid[0], asc);
48 int do_sysid(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
55 sysid, 1, 1, do_sysid,
56 "display Nios-II system id",
60 static int altera_sysid_read(struct udevice *dev,
61 int offset, void *buf, int size)
63 struct altera_sysid_platdata *plat = dev->platdata;
64 struct altera_sysid_regs *const regs = plat->regs;
67 sysid[0] = readl(®s->id);
68 sysid[1] = readl(®s->timestamp);
73 static int altera_sysid_ofdata_to_platdata(struct udevice *dev)
75 struct altera_sysid_platdata *plat = dev_get_platdata(dev);
77 plat->regs = map_physmem(dev_get_addr(dev),
78 sizeof(struct altera_sysid_regs),
84 static const struct misc_ops altera_sysid_ops = {
85 .read = altera_sysid_read,
88 static const struct udevice_id altera_sysid_ids[] = {
89 { .compatible = "altr,sysid-1.0" },
93 U_BOOT_DRIVER(altera_sysid) = {
94 .name = "altera_sysid",
96 .of_match = altera_sysid_ids,
97 .ofdata_to_platdata = altera_sysid_ofdata_to_platdata,
98 .platdata_auto_alloc_size = sizeof(struct altera_sysid_platdata),
99 .ops = &altera_sysid_ops,