1a2974c9cSLinus Walleij /* 2a2974c9cSLinus Walleij * Copyright (C) 2014 Linaro Ltd. 3a2974c9cSLinus Walleij * 4a2974c9cSLinus Walleij * Author: Linus Walleij <linus.walleij@linaro.org> 5a2974c9cSLinus Walleij * 6a2974c9cSLinus Walleij * This program is free software; you can redistribute it and/or modify 7a2974c9cSLinus Walleij * it under the terms of the GNU General Public License version 2, as 8a2974c9cSLinus Walleij * published by the Free Software Foundation. 9a2974c9cSLinus Walleij * 10a2974c9cSLinus Walleij */ 11a2974c9cSLinus Walleij #include <linux/init.h> 12a2974c9cSLinus Walleij #include <linux/io.h> 13a2974c9cSLinus Walleij #include <linux/slab.h> 14a2974c9cSLinus Walleij #include <linux/sys_soc.h> 15a2974c9cSLinus Walleij #include <linux/platform_device.h> 16a2974c9cSLinus Walleij #include <linux/mfd/syscon.h> 17a2974c9cSLinus Walleij #include <linux/regmap.h> 18a2974c9cSLinus Walleij #include <linux/of.h> 19a2974c9cSLinus Walleij 20a2974c9cSLinus Walleij /* System ID in syscon */ 21a2974c9cSLinus Walleij #define REALVIEW_SYS_ID_OFFSET 0x00 22a2974c9cSLinus Walleij 23a2974c9cSLinus Walleij static const struct of_device_id realview_soc_of_match[] = { 24a2974c9cSLinus Walleij { .compatible = "arm,realview-eb-soc", }, 25a2974c9cSLinus Walleij { .compatible = "arm,realview-pb1176-soc", }, 26a2974c9cSLinus Walleij { .compatible = "arm,realview-pb11mp-soc", }, 27a2974c9cSLinus Walleij { .compatible = "arm,realview-pba8-soc", }, 28a2974c9cSLinus Walleij { .compatible = "arm,realview-pbx-soc", }, 29157a1b17SAxel Lin { } 30a2974c9cSLinus Walleij }; 31a2974c9cSLinus Walleij 32a2974c9cSLinus Walleij static u32 realview_coreid; 33a2974c9cSLinus Walleij 34a2974c9cSLinus Walleij static const char *realview_board_str(u32 id) 35a2974c9cSLinus Walleij { 36a2974c9cSLinus Walleij switch ((id >> 16) & 0xfff) { 37a2974c9cSLinus Walleij case 0x0147: 38a2974c9cSLinus Walleij return "HBI-0147"; 39a2974c9cSLinus Walleij default: 40a2974c9cSLinus Walleij return "Unknown"; 41a2974c9cSLinus Walleij } 42a2974c9cSLinus Walleij } 43a2974c9cSLinus Walleij 44a2974c9cSLinus Walleij static const char *realview_arch_str(u32 id) 45a2974c9cSLinus Walleij { 46a2974c9cSLinus Walleij switch ((id >> 8) & 0xf) { 47a2974c9cSLinus Walleij case 0x05: 48a2974c9cSLinus Walleij return "Multi-layer AXI"; 49a2974c9cSLinus Walleij default: 50a2974c9cSLinus Walleij return "Unknown"; 51a2974c9cSLinus Walleij } 52a2974c9cSLinus Walleij } 53a2974c9cSLinus Walleij 54a2974c9cSLinus Walleij static ssize_t realview_get_manf(struct device *dev, 55a2974c9cSLinus Walleij struct device_attribute *attr, 56a2974c9cSLinus Walleij char *buf) 57a2974c9cSLinus Walleij { 58a2974c9cSLinus Walleij return sprintf(buf, "%02x\n", realview_coreid >> 24); 59a2974c9cSLinus Walleij } 60a2974c9cSLinus Walleij 61a2974c9cSLinus Walleij static struct device_attribute realview_manf_attr = 62a2974c9cSLinus Walleij __ATTR(manufacturer, S_IRUGO, realview_get_manf, NULL); 63a2974c9cSLinus Walleij 64a2974c9cSLinus Walleij static ssize_t realview_get_board(struct device *dev, 65a2974c9cSLinus Walleij struct device_attribute *attr, 66a2974c9cSLinus Walleij char *buf) 67a2974c9cSLinus Walleij { 68a2974c9cSLinus Walleij return sprintf(buf, "%s\n", realview_board_str(realview_coreid)); 69a2974c9cSLinus Walleij } 70a2974c9cSLinus Walleij 71a2974c9cSLinus Walleij static struct device_attribute realview_board_attr = 72a2974c9cSLinus Walleij __ATTR(board, S_IRUGO, realview_get_board, NULL); 73a2974c9cSLinus Walleij 74a2974c9cSLinus Walleij static ssize_t realview_get_arch(struct device *dev, 75a2974c9cSLinus Walleij struct device_attribute *attr, 76a2974c9cSLinus Walleij char *buf) 77a2974c9cSLinus Walleij { 78a2974c9cSLinus Walleij return sprintf(buf, "%s\n", realview_arch_str(realview_coreid)); 79a2974c9cSLinus Walleij } 80a2974c9cSLinus Walleij 81a2974c9cSLinus Walleij static struct device_attribute realview_arch_attr = 82a2974c9cSLinus Walleij __ATTR(fpga, S_IRUGO, realview_get_arch, NULL); 83a2974c9cSLinus Walleij 84a2974c9cSLinus Walleij static ssize_t realview_get_build(struct device *dev, 85a2974c9cSLinus Walleij struct device_attribute *attr, 86a2974c9cSLinus Walleij char *buf) 87a2974c9cSLinus Walleij { 88a2974c9cSLinus Walleij return sprintf(buf, "%02x\n", (realview_coreid & 0xFF)); 89a2974c9cSLinus Walleij } 90a2974c9cSLinus Walleij 91a2974c9cSLinus Walleij static struct device_attribute realview_build_attr = 92a2974c9cSLinus Walleij __ATTR(build, S_IRUGO, realview_get_build, NULL); 93a2974c9cSLinus Walleij 94a2974c9cSLinus Walleij static int realview_soc_probe(struct platform_device *pdev) 95a2974c9cSLinus Walleij { 96a2974c9cSLinus Walleij static struct regmap *syscon_regmap; 97a2974c9cSLinus Walleij struct soc_device *soc_dev; 98a2974c9cSLinus Walleij struct soc_device_attribute *soc_dev_attr; 99a2974c9cSLinus Walleij struct device_node *np = pdev->dev.of_node; 100a2974c9cSLinus Walleij int ret; 101a2974c9cSLinus Walleij 102a2974c9cSLinus Walleij syscon_regmap = syscon_regmap_lookup_by_phandle(np, "regmap"); 103a2974c9cSLinus Walleij if (IS_ERR(syscon_regmap)) 104a2974c9cSLinus Walleij return PTR_ERR(syscon_regmap); 105a2974c9cSLinus Walleij 106a2974c9cSLinus Walleij soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL); 107a2974c9cSLinus Walleij if (!soc_dev_attr) 108a2974c9cSLinus Walleij return -ENOMEM; 109a2974c9cSLinus Walleij 110a2974c9cSLinus Walleij ret = of_property_read_string(np, "compatible", 111a2974c9cSLinus Walleij &soc_dev_attr->soc_id); 112a2974c9cSLinus Walleij if (ret) 113a2974c9cSLinus Walleij return -EINVAL; 114a2974c9cSLinus Walleij 115a2974c9cSLinus Walleij soc_dev_attr->machine = "RealView"; 116a2974c9cSLinus Walleij soc_dev_attr->family = "Versatile"; 117a2974c9cSLinus Walleij soc_dev = soc_device_register(soc_dev_attr); 118a2974c9cSLinus Walleij if (IS_ERR(soc_dev)) { 119a2974c9cSLinus Walleij kfree(soc_dev_attr); 120a2974c9cSLinus Walleij return -ENODEV; 121a2974c9cSLinus Walleij } 122a2974c9cSLinus Walleij ret = regmap_read(syscon_regmap, REALVIEW_SYS_ID_OFFSET, 123a2974c9cSLinus Walleij &realview_coreid); 124a2974c9cSLinus Walleij if (ret) 125a2974c9cSLinus Walleij return -ENODEV; 126a2974c9cSLinus Walleij 127a2974c9cSLinus Walleij device_create_file(soc_device_to_device(soc_dev), &realview_manf_attr); 128a2974c9cSLinus Walleij device_create_file(soc_device_to_device(soc_dev), &realview_board_attr); 129a2974c9cSLinus Walleij device_create_file(soc_device_to_device(soc_dev), &realview_arch_attr); 130a2974c9cSLinus Walleij device_create_file(soc_device_to_device(soc_dev), &realview_build_attr); 131a2974c9cSLinus Walleij 132a2974c9cSLinus Walleij dev_info(&pdev->dev, "RealView Syscon Core ID: 0x%08x\n", 133a2974c9cSLinus Walleij realview_coreid); 134a2974c9cSLinus Walleij /* FIXME: add attributes for SoC to sysfs */ 135a2974c9cSLinus Walleij return 0; 136a2974c9cSLinus Walleij } 137a2974c9cSLinus Walleij 138a2974c9cSLinus Walleij static struct platform_driver realview_soc_driver = { 139a2974c9cSLinus Walleij .probe = realview_soc_probe, 140a2974c9cSLinus Walleij .driver = { 141a2974c9cSLinus Walleij .name = "realview-soc", 142a2974c9cSLinus Walleij .of_match_table = realview_soc_of_match, 143a2974c9cSLinus Walleij }, 144a2974c9cSLinus Walleij }; 145*0159ae95SPaul Gortmaker builtin_platform_driver(realview_soc_driver); 146