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