1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2014 Linaro Ltd.
5 * Author: Linus Walleij <linus.walleij@linaro.org>
7 #include <linux/init.h>
9 #include <linux/slab.h>
10 #include <linux/sys_soc.h>
11 #include <linux/platform_device.h>
12 #include <linux/mfd/syscon.h>
13 #include <linux/regmap.h>
16 /* System ID in syscon */
17 #define REALVIEW_SYS_ID_OFFSET 0x00
19 static const struct of_device_id realview_soc_of_match
[] = {
20 { .compatible
= "arm,realview-eb-soc", },
21 { .compatible
= "arm,realview-pb1176-soc", },
22 { .compatible
= "arm,realview-pb11mp-soc", },
23 { .compatible
= "arm,realview-pba8-soc", },
24 { .compatible
= "arm,realview-pbx-soc", },
28 static u32 realview_coreid
;
30 static const char *realview_arch_str(u32 id
)
32 switch ((id
>> 8) & 0xf) {
36 return "Multi-layer AXI";
43 manufacturer_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
45 return sprintf(buf
, "%02x\n", realview_coreid
>> 24);
48 static DEVICE_ATTR_RO(manufacturer
);
51 board_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
53 return sprintf(buf
, "HBI-%03x\n", ((realview_coreid
>> 16) & 0xfff));
56 static DEVICE_ATTR_RO(board
);
59 fpga_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
61 return sprintf(buf
, "%s\n", realview_arch_str(realview_coreid
));
64 static DEVICE_ATTR_RO(fpga
);
67 build_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
69 return sprintf(buf
, "%02x\n", (realview_coreid
& 0xFF));
72 static DEVICE_ATTR_RO(build
);
74 static struct attribute
*realview_attrs
[] = {
75 &dev_attr_manufacturer
.attr
,
82 ATTRIBUTE_GROUPS(realview
);
84 static int realview_soc_probe(struct platform_device
*pdev
)
86 struct regmap
*syscon_regmap
;
87 struct soc_device
*soc_dev
;
88 struct soc_device_attribute
*soc_dev_attr
;
89 struct device_node
*np
= pdev
->dev
.of_node
;
92 syscon_regmap
= syscon_regmap_lookup_by_phandle(np
, "regmap");
93 if (IS_ERR(syscon_regmap
))
94 return PTR_ERR(syscon_regmap
);
96 soc_dev_attr
= kzalloc(sizeof(*soc_dev_attr
), GFP_KERNEL
);
100 ret
= of_property_read_string(np
, "compatible",
101 &soc_dev_attr
->soc_id
);
105 soc_dev_attr
->machine
= "RealView";
106 soc_dev_attr
->family
= "Versatile";
107 soc_dev_attr
->custom_attr_group
= realview_groups
[0];
108 soc_dev
= soc_device_register(soc_dev_attr
);
109 if (IS_ERR(soc_dev
)) {
113 ret
= regmap_read(syscon_regmap
, REALVIEW_SYS_ID_OFFSET
,
118 dev_info(&pdev
->dev
, "RealView Syscon Core ID: 0x%08x, HBI-%03x\n",
120 ((realview_coreid
>> 16) & 0xfff));
121 /* FIXME: add attributes for SoC to sysfs */
125 static struct platform_driver realview_soc_driver
= {
126 .probe
= realview_soc_probe
,
128 .name
= "realview-soc",
129 .of_match_table
= realview_soc_of_match
,
132 builtin_platform_driver(realview_soc_driver
);