1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2014 Linaro Ltd.
5 * Author: Linus Walleij <linus.walleij@linaro.org>
7 #include <linux/init.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>
16 #define INTEGRATOR_HDR_ID_OFFSET 0x00
18 static u32 integrator_coreid
;
20 static const struct of_device_id integrator_cm_match
[] = {
21 { .compatible
= "arm,core-module-integrator", },
25 static const char *integrator_arch_str(u32 id
)
27 switch ((id
>> 16) & 0xff) {
29 return "ASB little-endian";
31 return "AHB little-endian";
33 return "AHB-Lite system bus, bi-endian";
37 return "AHB system bus, ASB processor bus";
43 static const char *integrator_fpga_str(u32 id
)
45 switch ((id
>> 12) & 0xf) {
53 return "EPM7256AE (Altera PLD)";
59 static ssize_t
integrator_get_manf(struct device
*dev
,
60 struct device_attribute
*attr
,
63 return sprintf(buf
, "%02x\n", integrator_coreid
>> 24);
66 static struct device_attribute integrator_manf_attr
=
67 __ATTR(manufacturer
, S_IRUGO
, integrator_get_manf
, NULL
);
69 static ssize_t
integrator_get_arch(struct device
*dev
,
70 struct device_attribute
*attr
,
73 return sprintf(buf
, "%s\n", integrator_arch_str(integrator_coreid
));
76 static struct device_attribute integrator_arch_attr
=
77 __ATTR(arch
, S_IRUGO
, integrator_get_arch
, NULL
);
79 static ssize_t
integrator_get_fpga(struct device
*dev
,
80 struct device_attribute
*attr
,
83 return sprintf(buf
, "%s\n", integrator_fpga_str(integrator_coreid
));
86 static struct device_attribute integrator_fpga_attr
=
87 __ATTR(fpga
, S_IRUGO
, integrator_get_fpga
, NULL
);
89 static ssize_t
integrator_get_build(struct device
*dev
,
90 struct device_attribute
*attr
,
93 return sprintf(buf
, "%02x\n", (integrator_coreid
>> 4) & 0xFF);
96 static struct device_attribute integrator_build_attr
=
97 __ATTR(build
, S_IRUGO
, integrator_get_build
, NULL
);
99 static int __init
integrator_soc_init(void)
101 static struct regmap
*syscon_regmap
;
102 struct soc_device
*soc_dev
;
103 struct soc_device_attribute
*soc_dev_attr
;
104 struct device_node
*np
;
109 np
= of_find_matching_node(NULL
, integrator_cm_match
);
113 syscon_regmap
= syscon_node_to_regmap(np
);
114 if (IS_ERR(syscon_regmap
))
115 return PTR_ERR(syscon_regmap
);
117 ret
= regmap_read(syscon_regmap
, INTEGRATOR_HDR_ID_OFFSET
,
121 integrator_coreid
= val
;
123 soc_dev_attr
= kzalloc(sizeof(*soc_dev_attr
), GFP_KERNEL
);
127 soc_dev_attr
->soc_id
= "Integrator";
128 soc_dev_attr
->machine
= "Integrator";
129 soc_dev_attr
->family
= "Versatile";
130 soc_dev
= soc_device_register(soc_dev_attr
);
131 if (IS_ERR(soc_dev
)) {
135 dev
= soc_device_to_device(soc_dev
);
137 device_create_file(dev
, &integrator_manf_attr
);
138 device_create_file(dev
, &integrator_arch_attr
);
139 device_create_file(dev
, &integrator_fpga_attr
);
140 device_create_file(dev
, &integrator_build_attr
);
142 dev_info(dev
, "Detected ARM core module:\n");
143 dev_info(dev
, " Manufacturer: %02x\n", (val
>> 24));
144 dev_info(dev
, " Architecture: %s\n", integrator_arch_str(val
));
145 dev_info(dev
, " FPGA: %s\n", integrator_fpga_str(val
));
146 dev_info(dev
, " Build: %02x\n", (val
>> 4) & 0xFF);
147 dev_info(dev
, " Rev: %c\n", ('A' + (val
& 0x03)));
151 device_initcall(integrator_soc_init
);