Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Copyright (C) 2014 Linaro Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Author: Linus Walleij <linus.walleij@linaro.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/sys_soc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/mfd/syscon.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/regmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) /* System ID in syscon */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #define REALVIEW_SYS_ID_OFFSET 0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) static const struct of_device_id realview_soc_of_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 	{ .compatible = "arm,realview-eb-soc",	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	{ .compatible = "arm,realview-pb1176-soc", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	{ .compatible = "arm,realview-pb11mp-soc", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	{ .compatible = "arm,realview-pba8-soc", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	{ .compatible = "arm,realview-pbx-soc", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	{ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) static u32 realview_coreid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) static const char *realview_arch_str(u32 id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	switch ((id >> 8) & 0xf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	case 0x04:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 		return "AHB";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	case 0x05:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 		return "Multi-layer AXI";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 		return "Unknown";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) manufacturer_show(struct device *dev, struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	return sprintf(buf, "%02x\n", realview_coreid >> 24);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) static DEVICE_ATTR_RO(manufacturer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) board_show(struct device *dev, struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	return sprintf(buf, "HBI-%03x\n", ((realview_coreid >> 16) & 0xfff));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) static DEVICE_ATTR_RO(board);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) fpga_show(struct device *dev, struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	return sprintf(buf, "%s\n", realview_arch_str(realview_coreid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) static DEVICE_ATTR_RO(fpga);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) build_show(struct device *dev, struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	return sprintf(buf, "%02x\n", (realview_coreid & 0xFF));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) static DEVICE_ATTR_RO(build);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) static struct attribute *realview_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	&dev_attr_manufacturer.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	&dev_attr_board.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	&dev_attr_fpga.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	&dev_attr_build.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) ATTRIBUTE_GROUPS(realview);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) static int realview_soc_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	struct regmap *syscon_regmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	struct soc_device *soc_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	struct soc_device_attribute *soc_dev_attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	struct device_node *np = pdev->dev.of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	syscon_regmap = syscon_regmap_lookup_by_phandle(np, "regmap");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	if (IS_ERR(syscon_regmap))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		return PTR_ERR(syscon_regmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	if (!soc_dev_attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	ret = of_property_read_string(np, "compatible",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 				      &soc_dev_attr->soc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	soc_dev_attr->machine = "RealView";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	soc_dev_attr->family = "Versatile";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	soc_dev_attr->custom_attr_group = realview_groups[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	soc_dev = soc_device_register(soc_dev_attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	if (IS_ERR(soc_dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		kfree(soc_dev_attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	ret = regmap_read(syscon_regmap, REALVIEW_SYS_ID_OFFSET,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 			  &realview_coreid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	dev_info(&pdev->dev, "RealView Syscon Core ID: 0x%08x, HBI-%03x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		 realview_coreid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		 ((realview_coreid >> 16) & 0xfff));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	/* FIXME: add attributes for SoC to sysfs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) static struct platform_driver realview_soc_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	.probe = realview_soc_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		.name = "realview-soc",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		.of_match_table = realview_soc_of_match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) builtin_platform_driver(realview_soc_driver);