xref: /linux/drivers/soc/versatile/soc-realview.c (revision d2912cb15bdda8ba4a5dd73396ad62641af2f520)
1*d2912cb1SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2a2974c9cSLinus Walleij /*
3a2974c9cSLinus Walleij  * Copyright (C) 2014 Linaro Ltd.
4a2974c9cSLinus Walleij  *
5a2974c9cSLinus Walleij  * Author: Linus Walleij <linus.walleij@linaro.org>
6a2974c9cSLinus Walleij  */
7a2974c9cSLinus Walleij #include <linux/init.h>
8a2974c9cSLinus Walleij #include <linux/io.h>
9a2974c9cSLinus Walleij #include <linux/slab.h>
10a2974c9cSLinus Walleij #include <linux/sys_soc.h>
11a2974c9cSLinus Walleij #include <linux/platform_device.h>
12a2974c9cSLinus Walleij #include <linux/mfd/syscon.h>
13a2974c9cSLinus Walleij #include <linux/regmap.h>
14a2974c9cSLinus Walleij #include <linux/of.h>
15a2974c9cSLinus Walleij 
16a2974c9cSLinus Walleij /* System ID in syscon */
17a2974c9cSLinus Walleij #define REALVIEW_SYS_ID_OFFSET 0x00
18a2974c9cSLinus Walleij 
19a2974c9cSLinus Walleij static const struct of_device_id realview_soc_of_match[] = {
20a2974c9cSLinus Walleij 	{ .compatible = "arm,realview-eb-soc",	},
21a2974c9cSLinus Walleij 	{ .compatible = "arm,realview-pb1176-soc", },
22a2974c9cSLinus Walleij 	{ .compatible = "arm,realview-pb11mp-soc", },
23a2974c9cSLinus Walleij 	{ .compatible = "arm,realview-pba8-soc", },
24a2974c9cSLinus Walleij 	{ .compatible = "arm,realview-pbx-soc", },
25157a1b17SAxel Lin 	{ }
26a2974c9cSLinus Walleij };
27a2974c9cSLinus Walleij 
28a2974c9cSLinus Walleij static u32 realview_coreid;
29a2974c9cSLinus Walleij 
30a2974c9cSLinus Walleij static const char *realview_arch_str(u32 id)
31a2974c9cSLinus Walleij {
32a2974c9cSLinus Walleij 	switch ((id >> 8) & 0xf) {
335d87f7a3SLinus Walleij 	case 0x04:
345d87f7a3SLinus Walleij 		return "AHB";
35a2974c9cSLinus Walleij 	case 0x05:
36a2974c9cSLinus Walleij 		return "Multi-layer AXI";
37a2974c9cSLinus Walleij 	default:
38a2974c9cSLinus Walleij 		return "Unknown";
39a2974c9cSLinus Walleij 	}
40a2974c9cSLinus Walleij }
41a2974c9cSLinus Walleij 
42a2974c9cSLinus Walleij static ssize_t realview_get_manf(struct device *dev,
43a2974c9cSLinus Walleij 			      struct device_attribute *attr,
44a2974c9cSLinus Walleij 			      char *buf)
45a2974c9cSLinus Walleij {
46a2974c9cSLinus Walleij 	return sprintf(buf, "%02x\n", realview_coreid >> 24);
47a2974c9cSLinus Walleij }
48a2974c9cSLinus Walleij 
49a2974c9cSLinus Walleij static struct device_attribute realview_manf_attr =
50a2974c9cSLinus Walleij 	__ATTR(manufacturer,  S_IRUGO, realview_get_manf,  NULL);
51a2974c9cSLinus Walleij 
52a2974c9cSLinus Walleij static ssize_t realview_get_board(struct device *dev,
53a2974c9cSLinus Walleij 			      struct device_attribute *attr,
54a2974c9cSLinus Walleij 			      char *buf)
55a2974c9cSLinus Walleij {
56fccc2b36SLinus Walleij 	return sprintf(buf, "HBI-%03x\n", ((realview_coreid >> 16) & 0xfff));
57a2974c9cSLinus Walleij }
58a2974c9cSLinus Walleij 
59a2974c9cSLinus Walleij static struct device_attribute realview_board_attr =
60a2974c9cSLinus Walleij 	__ATTR(board,  S_IRUGO, realview_get_board,  NULL);
61a2974c9cSLinus Walleij 
62a2974c9cSLinus Walleij static ssize_t realview_get_arch(struct device *dev,
63a2974c9cSLinus Walleij 			      struct device_attribute *attr,
64a2974c9cSLinus Walleij 			      char *buf)
65a2974c9cSLinus Walleij {
66a2974c9cSLinus Walleij 	return sprintf(buf, "%s\n", realview_arch_str(realview_coreid));
67a2974c9cSLinus Walleij }
68a2974c9cSLinus Walleij 
69a2974c9cSLinus Walleij static struct device_attribute realview_arch_attr =
70a2974c9cSLinus Walleij 	__ATTR(fpga,  S_IRUGO, realview_get_arch,  NULL);
71a2974c9cSLinus Walleij 
72a2974c9cSLinus Walleij static ssize_t realview_get_build(struct device *dev,
73a2974c9cSLinus Walleij 			       struct device_attribute *attr,
74a2974c9cSLinus Walleij 			       char *buf)
75a2974c9cSLinus Walleij {
76a2974c9cSLinus Walleij 	return sprintf(buf, "%02x\n", (realview_coreid & 0xFF));
77a2974c9cSLinus Walleij }
78a2974c9cSLinus Walleij 
79a2974c9cSLinus Walleij static struct device_attribute realview_build_attr =
80a2974c9cSLinus Walleij 	__ATTR(build,  S_IRUGO, realview_get_build,  NULL);
81a2974c9cSLinus Walleij 
82a2974c9cSLinus Walleij static int realview_soc_probe(struct platform_device *pdev)
83a2974c9cSLinus Walleij {
84db86ab06SGustavo A. R. Silva 	struct regmap *syscon_regmap;
85a2974c9cSLinus Walleij 	struct soc_device *soc_dev;
86a2974c9cSLinus Walleij 	struct soc_device_attribute *soc_dev_attr;
87a2974c9cSLinus Walleij 	struct device_node *np = pdev->dev.of_node;
88a2974c9cSLinus Walleij 	int ret;
89a2974c9cSLinus Walleij 
90a2974c9cSLinus Walleij 	syscon_regmap = syscon_regmap_lookup_by_phandle(np, "regmap");
91a2974c9cSLinus Walleij 	if (IS_ERR(syscon_regmap))
92a2974c9cSLinus Walleij 		return PTR_ERR(syscon_regmap);
93a2974c9cSLinus Walleij 
94a2974c9cSLinus Walleij 	soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
95a2974c9cSLinus Walleij 	if (!soc_dev_attr)
96a2974c9cSLinus Walleij 		return -ENOMEM;
97a2974c9cSLinus Walleij 
98a2974c9cSLinus Walleij 	ret = of_property_read_string(np, "compatible",
99a2974c9cSLinus Walleij 				      &soc_dev_attr->soc_id);
100a2974c9cSLinus Walleij 	if (ret)
101a2974c9cSLinus Walleij 		return -EINVAL;
102a2974c9cSLinus Walleij 
103a2974c9cSLinus Walleij 	soc_dev_attr->machine = "RealView";
104a2974c9cSLinus Walleij 	soc_dev_attr->family = "Versatile";
105a2974c9cSLinus Walleij 	soc_dev = soc_device_register(soc_dev_attr);
106a2974c9cSLinus Walleij 	if (IS_ERR(soc_dev)) {
107a2974c9cSLinus Walleij 		kfree(soc_dev_attr);
108a2974c9cSLinus Walleij 		return -ENODEV;
109a2974c9cSLinus Walleij 	}
110a2974c9cSLinus Walleij 	ret = regmap_read(syscon_regmap, REALVIEW_SYS_ID_OFFSET,
111a2974c9cSLinus Walleij 			  &realview_coreid);
112a2974c9cSLinus Walleij 	if (ret)
113a2974c9cSLinus Walleij 		return -ENODEV;
114a2974c9cSLinus Walleij 
115a2974c9cSLinus Walleij 	device_create_file(soc_device_to_device(soc_dev), &realview_manf_attr);
116a2974c9cSLinus Walleij 	device_create_file(soc_device_to_device(soc_dev), &realview_board_attr);
117a2974c9cSLinus Walleij 	device_create_file(soc_device_to_device(soc_dev), &realview_arch_attr);
118a2974c9cSLinus Walleij 	device_create_file(soc_device_to_device(soc_dev), &realview_build_attr);
119a2974c9cSLinus Walleij 
120fccc2b36SLinus Walleij 	dev_info(&pdev->dev, "RealView Syscon Core ID: 0x%08x, HBI-%03x\n",
121fccc2b36SLinus Walleij 		 realview_coreid,
122fccc2b36SLinus Walleij 		 ((realview_coreid >> 16) & 0xfff));
123a2974c9cSLinus Walleij 	/* FIXME: add attributes for SoC to sysfs */
124a2974c9cSLinus Walleij 	return 0;
125a2974c9cSLinus Walleij }
126a2974c9cSLinus Walleij 
127a2974c9cSLinus Walleij static struct platform_driver realview_soc_driver = {
128a2974c9cSLinus Walleij 	.probe = realview_soc_probe,
129a2974c9cSLinus Walleij 	.driver = {
130a2974c9cSLinus Walleij 		.name = "realview-soc",
131a2974c9cSLinus Walleij 		.of_match_table = realview_soc_of_match,
132a2974c9cSLinus Walleij 	},
133a2974c9cSLinus Walleij };
1340159ae95SPaul Gortmaker builtin_platform_driver(realview_soc_driver);
135