1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2014 Linaro Ltd.
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";
42 static ssize_t realview_get_manf(struct device *dev,
43 struct device_attribute *attr,
46 return sprintf(buf, "%02x\n", realview_coreid >> 24);
49 static struct device_attribute realview_manf_attr =
50 __ATTR(manufacturer, S_IRUGO, realview_get_manf, NULL);
52 static ssize_t realview_get_board(struct device *dev,
53 struct device_attribute *attr,
56 return sprintf(buf, "HBI-%03x\n", ((realview_coreid >> 16) & 0xfff));
59 static struct device_attribute realview_board_attr =
60 __ATTR(board, S_IRUGO, realview_get_board, NULL);
62 static ssize_t realview_get_arch(struct device *dev,
63 struct device_attribute *attr,
66 return sprintf(buf, "%s\n", realview_arch_str(realview_coreid));
69 static struct device_attribute realview_arch_attr =
70 __ATTR(fpga, S_IRUGO, realview_get_arch, NULL);
72 static ssize_t realview_get_build(struct device *dev,
73 struct device_attribute *attr,
76 return sprintf(buf, "%02x\n", (realview_coreid & 0xFF));
79 static struct device_attribute realview_build_attr =
80 __ATTR(build, S_IRUGO, realview_get_build, NULL);
82 static int realview_soc_probe(struct platform_device *pdev)
84 struct regmap *syscon_regmap;
85 struct soc_device *soc_dev;
86 struct soc_device_attribute *soc_dev_attr;
87 struct device_node *np = pdev->dev.of_node;
90 syscon_regmap = syscon_regmap_lookup_by_phandle(np, "regmap");
91 if (IS_ERR(syscon_regmap))
92 return PTR_ERR(syscon_regmap);
94 soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
98 ret = of_property_read_string(np, "compatible",
99 &soc_dev_attr->soc_id);
103 soc_dev_attr->machine = "RealView";
104 soc_dev_attr->family = "Versatile";
105 soc_dev = soc_device_register(soc_dev_attr);
106 if (IS_ERR(soc_dev)) {
110 ret = regmap_read(syscon_regmap, REALVIEW_SYS_ID_OFFSET,
115 device_create_file(soc_device_to_device(soc_dev), &realview_manf_attr);
116 device_create_file(soc_device_to_device(soc_dev), &realview_board_attr);
117 device_create_file(soc_device_to_device(soc_dev), &realview_arch_attr);
118 device_create_file(soc_device_to_device(soc_dev), &realview_build_attr);
120 dev_info(&pdev->dev, "RealView Syscon Core ID: 0x%08x, HBI-%03x\n",
122 ((realview_coreid >> 16) & 0xfff));
123 /* FIXME: add attributes for SoC to sysfs */
127 static struct platform_driver realview_soc_driver = {
128 .probe = realview_soc_probe,
130 .name = "realview-soc",
131 .of_match_table = realview_soc_of_match,
134 builtin_platform_driver(realview_soc_driver);