2 * Copyright (C) 2014 Linaro Ltd.
4 * Author: Linus Walleij <linus.walleij@linaro.org>
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.
11 #include <linux/init.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>
20 #define INTEGRATOR_HDR_ID_OFFSET 0x00
22 static u32 integrator_coreid;
24 static const struct of_device_id integrator_cm_match[] = {
25 { .compatible = "arm,core-module-integrator", },
29 static const char *integrator_arch_str(u32 id)
31 switch ((id >> 16) & 0xff) {
33 return "ASB little-endian";
35 return "AHB little-endian";
37 return "AHB-Lite system bus, bi-endian";
41 return "AHB system bus, ASB processor bus";
47 static const char *integrator_fpga_str(u32 id)
49 switch ((id >> 12) & 0xf) {
57 return "EPM7256AE (Altera PLD)";
63 static ssize_t integrator_get_manf(struct device *dev,
64 struct device_attribute *attr,
67 return sprintf(buf, "%02x\n", integrator_coreid >> 24);
70 static struct device_attribute integrator_manf_attr =
71 __ATTR(manufacturer, S_IRUGO, integrator_get_manf, NULL);
73 static ssize_t integrator_get_arch(struct device *dev,
74 struct device_attribute *attr,
77 return sprintf(buf, "%s\n", integrator_arch_str(integrator_coreid));
80 static struct device_attribute integrator_arch_attr =
81 __ATTR(arch, S_IRUGO, integrator_get_arch, NULL);
83 static ssize_t integrator_get_fpga(struct device *dev,
84 struct device_attribute *attr,
87 return sprintf(buf, "%s\n", integrator_fpga_str(integrator_coreid));
90 static struct device_attribute integrator_fpga_attr =
91 __ATTR(fpga, S_IRUGO, integrator_get_fpga, NULL);
93 static ssize_t integrator_get_build(struct device *dev,
94 struct device_attribute *attr,
97 return sprintf(buf, "%02x\n", (integrator_coreid >> 4) & 0xFF);
100 static struct device_attribute integrator_build_attr =
101 __ATTR(build, S_IRUGO, integrator_get_build, NULL);
103 static int __init integrator_soc_init(void)
105 static struct regmap *syscon_regmap;
106 struct soc_device *soc_dev;
107 struct soc_device_attribute *soc_dev_attr;
108 struct device_node *np;
113 np = of_find_matching_node(NULL, integrator_cm_match);
117 syscon_regmap = syscon_node_to_regmap(np);
118 if (IS_ERR(syscon_regmap))
119 return PTR_ERR(syscon_regmap);
121 ret = regmap_read(syscon_regmap, INTEGRATOR_HDR_ID_OFFSET,
125 integrator_coreid = val;
127 soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
131 soc_dev_attr->soc_id = "Integrator";
132 soc_dev_attr->machine = "Integrator";
133 soc_dev_attr->family = "Versatile";
134 soc_dev = soc_device_register(soc_dev_attr);
135 if (IS_ERR(soc_dev)) {
139 dev = soc_device_to_device(soc_dev);
141 device_create_file(dev, &integrator_manf_attr);
142 device_create_file(dev, &integrator_arch_attr);
143 device_create_file(dev, &integrator_fpga_attr);
144 device_create_file(dev, &integrator_build_attr);
146 dev_info(dev, "Detected ARM core module:\n");
147 dev_info(dev, " Manufacturer: %02x\n", (val >> 24));
148 dev_info(dev, " Architecture: %s\n", integrator_arch_str(val));
149 dev_info(dev, " FPGA: %s\n", integrator_fpga_str(val));
150 dev_info(dev, " Build: %02x\n", (val >> 4) & 0xFF);
151 dev_info(dev, " Rev: %c\n", ('A' + (val & 0x03)));
155 device_initcall(integrator_soc_init);