cpufreq/amd-pstate: Fix per-policy boost flag incorrect when fail
[pf-kernel.git] / drivers / soc / versatile / soc-realview.c
blobcf91abe07d38d006aea72c66b51d669208845f71
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Copyright (C) 2014 Linaro Ltd.
5 * Author: Linus Walleij <linus.walleij@linaro.org>
6 */
7 #include <linux/device.h>
8 #include <linux/init.h>
9 #include <linux/io.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>
15 #include <linux/of.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", },
26 { }
29 static u32 realview_coreid;
31 static const char *realview_arch_str(u32 id)
33 switch ((id >> 8) & 0xf) {
34 case 0x04:
35 return "AHB";
36 case 0x05:
37 return "Multi-layer AXI";
38 default:
39 return "Unknown";
43 static ssize_t
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);
51 static ssize_t
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);
59 static ssize_t
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);
67 static ssize_t
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,
77 &dev_attr_board.attr,
78 &dev_attr_fpga.attr,
79 &dev_attr_build.attr,
80 NULL
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;
98 int ret;
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);
105 if (!soc_dev_attr)
106 return -ENOMEM;
108 ret = of_property_read_string(np, "compatible",
109 &soc_dev_attr->soc_id);
110 if (ret)
111 return -EINVAL;
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);
117 if (IS_ERR(soc_dev))
118 return -ENODEV;
120 ret = devm_add_action_or_reset(&pdev->dev, realview_soc_socdev_release,
121 soc_dev);
122 if (ret)
123 return ret;
125 ret = regmap_read(syscon_regmap, REALVIEW_SYS_ID_OFFSET,
126 &realview_coreid);
127 if (ret)
128 return -ENODEV;
130 dev_info(&pdev->dev, "RealView Syscon Core ID: 0x%08x, HBI-%03x\n",
131 realview_coreid,
132 ((realview_coreid >> 16) & 0xfff));
133 /* FIXME: add attributes for SoC to sysfs */
134 return 0;
137 static struct platform_driver realview_soc_driver = {
138 .probe = realview_soc_probe,
139 .driver = {
140 .name = "realview-soc",
141 .of_match_table = realview_soc_of_match,
144 builtin_platform_driver(realview_soc_driver);