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/device.h>
8 #include <linux/init.h>
10 #include <linux/slab.h>
11 #include <linux/sys_soc.h>
12 #include <linux/platform_device.h>
13 #include <linux/mfd/syscon.h>
14 #include <linux/regmap.h>
17 /* System ID in syscon */
18 #define REALVIEW_SYS_ID_OFFSET 0x00
20 static const struct of_device_id realview_soc_of_match
[] = {
21 { .compatible
= "arm,realview-eb-soc", },
22 { .compatible
= "arm,realview-pb1176-soc", },
23 { .compatible
= "arm,realview-pb11mp-soc", },
24 { .compatible
= "arm,realview-pba8-soc", },
25 { .compatible
= "arm,realview-pbx-soc", },
29 static u32 realview_coreid
;
31 static const char *realview_arch_str(u32 id
)
33 switch ((id
>> 8) & 0xf) {
37 return "Multi-layer AXI";
44 manufacturer_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
46 return sprintf(buf
, "%02x\n", realview_coreid
>> 24);
49 static DEVICE_ATTR_RO(manufacturer
);
52 board_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
54 return sprintf(buf
, "HBI-%03x\n", ((realview_coreid
>> 16) & 0xfff));
57 static DEVICE_ATTR_RO(board
);
60 fpga_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
62 return sprintf(buf
, "%s\n", realview_arch_str(realview_coreid
));
65 static DEVICE_ATTR_RO(fpga
);
68 build_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
70 return sprintf(buf
, "%02x\n", (realview_coreid
& 0xFF));
73 static DEVICE_ATTR_RO(build
);
75 static struct attribute
*realview_attrs
[] = {
76 &dev_attr_manufacturer
.attr
,
83 ATTRIBUTE_GROUPS(realview
);
85 static void realview_soc_socdev_release(void *data
)
87 struct soc_device
*soc_dev
= data
;
89 soc_device_unregister(soc_dev
);
92 static int realview_soc_probe(struct platform_device
*pdev
)
94 struct regmap
*syscon_regmap
;
95 struct soc_device
*soc_dev
;
96 struct soc_device_attribute
*soc_dev_attr
;
97 struct device_node
*np
= pdev
->dev
.of_node
;
100 syscon_regmap
= syscon_regmap_lookup_by_phandle(np
, "regmap");
101 if (IS_ERR(syscon_regmap
))
102 return PTR_ERR(syscon_regmap
);
104 soc_dev_attr
= devm_kzalloc(&pdev
->dev
, sizeof(*soc_dev_attr
), GFP_KERNEL
);
108 ret
= of_property_read_string(np
, "compatible",
109 &soc_dev_attr
->soc_id
);
113 soc_dev_attr
->machine
= "RealView";
114 soc_dev_attr
->family
= "Versatile";
115 soc_dev_attr
->custom_attr_group
= realview_groups
[0];
116 soc_dev
= soc_device_register(soc_dev_attr
);
120 ret
= devm_add_action_or_reset(&pdev
->dev
, realview_soc_socdev_release
,
125 ret
= regmap_read(syscon_regmap
, REALVIEW_SYS_ID_OFFSET
,
130 dev_info(&pdev
->dev
, "RealView Syscon Core ID: 0x%08x, HBI-%03x\n",
132 ((realview_coreid
>> 16) & 0xfff));
133 /* FIXME: add attributes for SoC to sysfs */
137 static struct platform_driver realview_soc_driver
= {
138 .probe
= realview_soc_probe
,
140 .name
= "realview-soc",
141 .of_match_table
= realview_soc_of_match
,
144 builtin_platform_driver(realview_soc_driver
);