Loading...
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * Copyright (C) 2014 Linaro Ltd.
4 *
5 * Author: Linus Walleij <linus.walleij@linaro.org>
6 */
7#include <linux/init.h>
8#include <linux/io.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>
14#include <linux/of.h>
15
16/* System ID in syscon */
17#define REALVIEW_SYS_ID_OFFSET 0x00
18
19static 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", },
25 { }
26};
27
28static u32 realview_coreid;
29
30static const char *realview_arch_str(u32 id)
31{
32 switch ((id >> 8) & 0xf) {
33 case 0x04:
34 return "AHB";
35 case 0x05:
36 return "Multi-layer AXI";
37 default:
38 return "Unknown";
39 }
40}
41
42static ssize_t
43manufacturer_show(struct device *dev, struct device_attribute *attr, char *buf)
44{
45 return sprintf(buf, "%02x\n", realview_coreid >> 24);
46}
47
48static DEVICE_ATTR_RO(manufacturer);
49
50static ssize_t
51board_show(struct device *dev, struct device_attribute *attr, char *buf)
52{
53 return sprintf(buf, "HBI-%03x\n", ((realview_coreid >> 16) & 0xfff));
54}
55
56static DEVICE_ATTR_RO(board);
57
58static ssize_t
59fpga_show(struct device *dev, struct device_attribute *attr, char *buf)
60{
61 return sprintf(buf, "%s\n", realview_arch_str(realview_coreid));
62}
63
64static DEVICE_ATTR_RO(fpga);
65
66static ssize_t
67build_show(struct device *dev, struct device_attribute *attr, char *buf)
68{
69 return sprintf(buf, "%02x\n", (realview_coreid & 0xFF));
70}
71
72static DEVICE_ATTR_RO(build);
73
74static struct attribute *realview_attrs[] = {
75 &dev_attr_manufacturer.attr,
76 &dev_attr_board.attr,
77 &dev_attr_fpga.attr,
78 &dev_attr_build.attr,
79 NULL
80};
81
82ATTRIBUTE_GROUPS(realview);
83
84static int realview_soc_probe(struct platform_device *pdev)
85{
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;
90 int ret;
91
92 syscon_regmap = syscon_regmap_lookup_by_phandle(np, "regmap");
93 if (IS_ERR(syscon_regmap))
94 return PTR_ERR(syscon_regmap);
95
96 soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
97 if (!soc_dev_attr)
98 return -ENOMEM;
99
100 ret = of_property_read_string(np, "compatible",
101 &soc_dev_attr->soc_id);
102 if (ret)
103 return -EINVAL;
104
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)) {
110 kfree(soc_dev_attr);
111 return -ENODEV;
112 }
113 ret = regmap_read(syscon_regmap, REALVIEW_SYS_ID_OFFSET,
114 &realview_coreid);
115 if (ret)
116 return -ENODEV;
117
118 dev_info(&pdev->dev, "RealView Syscon Core ID: 0x%08x, HBI-%03x\n",
119 realview_coreid,
120 ((realview_coreid >> 16) & 0xfff));
121 /* FIXME: add attributes for SoC to sysfs */
122 return 0;
123}
124
125static struct platform_driver realview_soc_driver = {
126 .probe = realview_soc_probe,
127 .driver = {
128 .name = "realview-soc",
129 .of_match_table = realview_soc_of_match,
130 },
131};
132builtin_platform_driver(realview_soc_driver);
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * Copyright (C) 2014 Linaro Ltd.
4 *
5 * Author: Linus Walleij <linus.walleij@linaro.org>
6 */
7#include <linux/init.h>
8#include <linux/io.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>
14#include <linux/of.h>
15
16/* System ID in syscon */
17#define REALVIEW_SYS_ID_OFFSET 0x00
18
19static 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", },
25 { }
26};
27
28static u32 realview_coreid;
29
30static const char *realview_arch_str(u32 id)
31{
32 switch ((id >> 8) & 0xf) {
33 case 0x04:
34 return "AHB";
35 case 0x05:
36 return "Multi-layer AXI";
37 default:
38 return "Unknown";
39 }
40}
41
42static ssize_t realview_get_manf(struct device *dev,
43 struct device_attribute *attr,
44 char *buf)
45{
46 return sprintf(buf, "%02x\n", realview_coreid >> 24);
47}
48
49static struct device_attribute realview_manf_attr =
50 __ATTR(manufacturer, S_IRUGO, realview_get_manf, NULL);
51
52static ssize_t realview_get_board(struct device *dev,
53 struct device_attribute *attr,
54 char *buf)
55{
56 return sprintf(buf, "HBI-%03x\n", ((realview_coreid >> 16) & 0xfff));
57}
58
59static struct device_attribute realview_board_attr =
60 __ATTR(board, S_IRUGO, realview_get_board, NULL);
61
62static ssize_t realview_get_arch(struct device *dev,
63 struct device_attribute *attr,
64 char *buf)
65{
66 return sprintf(buf, "%s\n", realview_arch_str(realview_coreid));
67}
68
69static struct device_attribute realview_arch_attr =
70 __ATTR(fpga, S_IRUGO, realview_get_arch, NULL);
71
72static ssize_t realview_get_build(struct device *dev,
73 struct device_attribute *attr,
74 char *buf)
75{
76 return sprintf(buf, "%02x\n", (realview_coreid & 0xFF));
77}
78
79static struct device_attribute realview_build_attr =
80 __ATTR(build, S_IRUGO, realview_get_build, NULL);
81
82static int realview_soc_probe(struct platform_device *pdev)
83{
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;
88 int ret;
89
90 syscon_regmap = syscon_regmap_lookup_by_phandle(np, "regmap");
91 if (IS_ERR(syscon_regmap))
92 return PTR_ERR(syscon_regmap);
93
94 soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
95 if (!soc_dev_attr)
96 return -ENOMEM;
97
98 ret = of_property_read_string(np, "compatible",
99 &soc_dev_attr->soc_id);
100 if (ret)
101 return -EINVAL;
102
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)) {
107 kfree(soc_dev_attr);
108 return -ENODEV;
109 }
110 ret = regmap_read(syscon_regmap, REALVIEW_SYS_ID_OFFSET,
111 &realview_coreid);
112 if (ret)
113 return -ENODEV;
114
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);
119
120 dev_info(&pdev->dev, "RealView Syscon Core ID: 0x%08x, HBI-%03x\n",
121 realview_coreid,
122 ((realview_coreid >> 16) & 0xfff));
123 /* FIXME: add attributes for SoC to sysfs */
124 return 0;
125}
126
127static struct platform_driver realview_soc_driver = {
128 .probe = realview_soc_probe,
129 .driver = {
130 .name = "realview-soc",
131 .of_match_table = realview_soc_of_match,
132 },
133};
134builtin_platform_driver(realview_soc_driver);