xref: /linux/drivers/soc/versatile/soc-integrator.c (revision 4eca459bc10d8400407d0fc04e90dac45b571c87)
1 /*
2  * Copyright (C) 2014 Linaro Ltd.
3  *
4  * Author: Linus Walleij <linus.walleij@linaro.org>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2, as
8  * published by the Free Software Foundation.
9  *
10  */
11 #include <linux/init.h>
12 #include <linux/io.h>
13 #include <linux/slab.h>
14 #include <linux/sys_soc.h>
15 #include <linux/platform_device.h>
16 #include <linux/mfd/syscon.h>
17 #include <linux/regmap.h>
18 #include <linux/of.h>
19 
20 #define INTEGRATOR_HDR_ID_OFFSET	0x00
21 
22 static u32 integrator_coreid;
23 
24 static const struct of_device_id integrator_cm_match[] = {
25 	{ .compatible = "arm,core-module-integrator", },
26 };
27 
28 static const char *integrator_arch_str(u32 id)
29 {
30 	switch ((id >> 16) & 0xff) {
31 	case 0x00:
32 		return "ASB little-endian";
33 	case 0x01:
34 		return "AHB little-endian";
35 	case 0x03:
36 		return "AHB-Lite system bus, bi-endian";
37 	case 0x04:
38 		return "AHB";
39 	case 0x08:
40 		return "AHB system bus, ASB processor bus";
41 	default:
42 		return "Unknown";
43 	}
44 }
45 
46 static const char *integrator_fpga_str(u32 id)
47 {
48 	switch ((id >> 12) & 0xf) {
49 	case 0x01:
50 		return "XC4062";
51 	case 0x02:
52 		return "XC4085";
53 	case 0x03:
54 		return "XVC600";
55 	case 0x04:
56 		return "EPM7256AE (Altera PLD)";
57 	default:
58 		return "Unknown";
59 	}
60 }
61 
62 static ssize_t integrator_get_manf(struct device *dev,
63 			      struct device_attribute *attr,
64 			      char *buf)
65 {
66 	return sprintf(buf, "%02x\n", integrator_coreid >> 24);
67 }
68 
69 static struct device_attribute integrator_manf_attr =
70 	__ATTR(manufacturer,  S_IRUGO, integrator_get_manf,  NULL);
71 
72 static ssize_t integrator_get_arch(struct device *dev,
73 			      struct device_attribute *attr,
74 			      char *buf)
75 {
76 	return sprintf(buf, "%s\n", integrator_arch_str(integrator_coreid));
77 }
78 
79 static struct device_attribute integrator_arch_attr =
80 	__ATTR(arch,  S_IRUGO, integrator_get_arch,  NULL);
81 
82 static ssize_t integrator_get_fpga(struct device *dev,
83 			      struct device_attribute *attr,
84 			      char *buf)
85 {
86 	return sprintf(buf, "%s\n", integrator_fpga_str(integrator_coreid));
87 }
88 
89 static struct device_attribute integrator_fpga_attr =
90 	__ATTR(fpga,  S_IRUGO, integrator_get_fpga,  NULL);
91 
92 static ssize_t integrator_get_build(struct device *dev,
93 			       struct device_attribute *attr,
94 			       char *buf)
95 {
96 	return sprintf(buf, "%02x\n", (integrator_coreid >> 4) & 0xFF);
97 }
98 
99 static struct device_attribute integrator_build_attr =
100 	__ATTR(build,  S_IRUGO, integrator_get_build,  NULL);
101 
102 static int __init integrator_soc_init(void)
103 {
104 	static struct regmap *syscon_regmap;
105 	struct soc_device *soc_dev;
106 	struct soc_device_attribute *soc_dev_attr;
107 	struct device_node *np;
108 	struct device *dev;
109 	u32 val;
110 	int ret;
111 
112 	np = of_find_matching_node(NULL, integrator_cm_match);
113 	if (!np)
114 		return -ENODEV;
115 
116 	syscon_regmap = syscon_node_to_regmap(np);
117 	if (IS_ERR(syscon_regmap))
118 		return PTR_ERR(syscon_regmap);
119 
120 	ret = regmap_read(syscon_regmap, INTEGRATOR_HDR_ID_OFFSET,
121 			  &val);
122 	if (ret)
123 		return -ENODEV;
124 	integrator_coreid = val;
125 
126 	soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
127 	if (!soc_dev_attr)
128 		return -ENOMEM;
129 
130 	soc_dev_attr->soc_id = "Integrator";
131 	soc_dev_attr->machine = "Integrator";
132 	soc_dev_attr->family = "Versatile";
133 	soc_dev = soc_device_register(soc_dev_attr);
134 	if (IS_ERR(soc_dev)) {
135 		kfree(soc_dev_attr);
136 		return -ENODEV;
137 	}
138 	dev = soc_device_to_device(soc_dev);
139 
140 	device_create_file(dev, &integrator_manf_attr);
141 	device_create_file(dev, &integrator_arch_attr);
142 	device_create_file(dev, &integrator_fpga_attr);
143 	device_create_file(dev, &integrator_build_attr);
144 
145 	dev_info(dev, "Detected ARM core module:\n");
146 	dev_info(dev, "    Manufacturer: %02x\n", (val >> 24));
147 	dev_info(dev, "    Architecture: %s\n", integrator_arch_str(val));
148 	dev_info(dev, "    FPGA: %s\n", integrator_fpga_str(val));
149 	dev_info(dev, "    Build: %02x\n", (val >> 4) & 0xFF);
150 	dev_info(dev, "    Rev: %c\n", ('A' + (val & 0x03)));
151 
152 	return 0;
153 }
154 device_initcall(integrator_soc_init);
155