1d2912cb1SThomas 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 42*5feebc65SSudeep Holla static ssize_t 43*5feebc65SSudeep Holla manufacturer_show(struct device *dev, struct device_attribute *attr, char *buf) 44a2974c9cSLinus Walleij { 45a2974c9cSLinus Walleij return sprintf(buf, "%02x\n", realview_coreid >> 24); 46a2974c9cSLinus Walleij } 47a2974c9cSLinus Walleij 48*5feebc65SSudeep Holla static DEVICE_ATTR_RO(manufacturer); 49a2974c9cSLinus Walleij 50*5feebc65SSudeep Holla static ssize_t 51*5feebc65SSudeep Holla board_show(struct device *dev, struct device_attribute *attr, char *buf) 52a2974c9cSLinus Walleij { 53fccc2b36SLinus Walleij return sprintf(buf, "HBI-%03x\n", ((realview_coreid >> 16) & 0xfff)); 54a2974c9cSLinus Walleij } 55a2974c9cSLinus Walleij 56*5feebc65SSudeep Holla static DEVICE_ATTR_RO(board); 57a2974c9cSLinus Walleij 58*5feebc65SSudeep Holla static ssize_t 59*5feebc65SSudeep Holla fpga_show(struct device *dev, struct device_attribute *attr, char *buf) 60a2974c9cSLinus Walleij { 61a2974c9cSLinus Walleij return sprintf(buf, "%s\n", realview_arch_str(realview_coreid)); 62a2974c9cSLinus Walleij } 63a2974c9cSLinus Walleij 64*5feebc65SSudeep Holla static DEVICE_ATTR_RO(fpga); 65a2974c9cSLinus Walleij 66*5feebc65SSudeep Holla static ssize_t 67*5feebc65SSudeep Holla build_show(struct device *dev, struct device_attribute *attr, char *buf) 68a2974c9cSLinus Walleij { 69a2974c9cSLinus Walleij return sprintf(buf, "%02x\n", (realview_coreid & 0xFF)); 70a2974c9cSLinus Walleij } 71a2974c9cSLinus Walleij 72*5feebc65SSudeep Holla static DEVICE_ATTR_RO(build); 73a2974c9cSLinus Walleij 74a2974c9cSLinus Walleij static int realview_soc_probe(struct platform_device *pdev) 75a2974c9cSLinus Walleij { 76db86ab06SGustavo A. R. Silva struct regmap *syscon_regmap; 77a2974c9cSLinus Walleij struct soc_device *soc_dev; 78a2974c9cSLinus Walleij struct soc_device_attribute *soc_dev_attr; 79a2974c9cSLinus Walleij struct device_node *np = pdev->dev.of_node; 80a2974c9cSLinus Walleij int ret; 81a2974c9cSLinus Walleij 82a2974c9cSLinus Walleij syscon_regmap = syscon_regmap_lookup_by_phandle(np, "regmap"); 83a2974c9cSLinus Walleij if (IS_ERR(syscon_regmap)) 84a2974c9cSLinus Walleij return PTR_ERR(syscon_regmap); 85a2974c9cSLinus Walleij 86a2974c9cSLinus Walleij soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL); 87a2974c9cSLinus Walleij if (!soc_dev_attr) 88a2974c9cSLinus Walleij return -ENOMEM; 89a2974c9cSLinus Walleij 90a2974c9cSLinus Walleij ret = of_property_read_string(np, "compatible", 91a2974c9cSLinus Walleij &soc_dev_attr->soc_id); 92a2974c9cSLinus Walleij if (ret) 93a2974c9cSLinus Walleij return -EINVAL; 94a2974c9cSLinus Walleij 95a2974c9cSLinus Walleij soc_dev_attr->machine = "RealView"; 96a2974c9cSLinus Walleij soc_dev_attr->family = "Versatile"; 97a2974c9cSLinus Walleij soc_dev = soc_device_register(soc_dev_attr); 98a2974c9cSLinus Walleij if (IS_ERR(soc_dev)) { 99a2974c9cSLinus Walleij kfree(soc_dev_attr); 100a2974c9cSLinus Walleij return -ENODEV; 101a2974c9cSLinus Walleij } 102a2974c9cSLinus Walleij ret = regmap_read(syscon_regmap, REALVIEW_SYS_ID_OFFSET, 103a2974c9cSLinus Walleij &realview_coreid); 104a2974c9cSLinus Walleij if (ret) 105a2974c9cSLinus Walleij return -ENODEV; 106a2974c9cSLinus Walleij 107*5feebc65SSudeep Holla device_create_file(soc_device_to_device(soc_dev), &dev_attr_manufacturer); 108*5feebc65SSudeep Holla device_create_file(soc_device_to_device(soc_dev), &dev_attr_board); 109*5feebc65SSudeep Holla device_create_file(soc_device_to_device(soc_dev), &dev_attr_fpga); 110*5feebc65SSudeep Holla device_create_file(soc_device_to_device(soc_dev), &dev_attr_build); 111a2974c9cSLinus Walleij 112fccc2b36SLinus Walleij dev_info(&pdev->dev, "RealView Syscon Core ID: 0x%08x, HBI-%03x\n", 113fccc2b36SLinus Walleij realview_coreid, 114fccc2b36SLinus Walleij ((realview_coreid >> 16) & 0xfff)); 115a2974c9cSLinus Walleij /* FIXME: add attributes for SoC to sysfs */ 116a2974c9cSLinus Walleij return 0; 117a2974c9cSLinus Walleij } 118a2974c9cSLinus Walleij 119a2974c9cSLinus Walleij static struct platform_driver realview_soc_driver = { 120a2974c9cSLinus Walleij .probe = realview_soc_probe, 121a2974c9cSLinus Walleij .driver = { 122a2974c9cSLinus Walleij .name = "realview-soc", 123a2974c9cSLinus Walleij .of_match_table = realview_soc_of_match, 124a2974c9cSLinus Walleij }, 125a2974c9cSLinus Walleij }; 1260159ae95SPaul Gortmaker builtin_platform_driver(realview_soc_driver); 127