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
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) // Copyright (c) 2011-2014 Samsung Electronics Co., Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) //		http://www.samsung.com/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) // Exynos - CPU PMU(Power Management Unit) support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/of_address.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/of_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/mfd/syscon.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/soc/samsung/exynos-regs-pmu.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/soc/samsung/exynos-pmu.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include "exynos-pmu.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) struct exynos_pmu_context {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	struct device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	const struct exynos_pmu_data *pmu_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) void __iomem *pmu_base_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) static struct exynos_pmu_context *pmu_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) void pmu_raw_writel(u32 val, u32 offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	writel_relaxed(val, pmu_base_addr + offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) u32 pmu_raw_readl(u32 offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	return readl_relaxed(pmu_base_addr + offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) void exynos_sys_powerdown_conf(enum sys_powerdown mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	const struct exynos_pmu_data *pmu_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	if (!pmu_context || !pmu_context->pmu_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	pmu_data = pmu_context->pmu_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	if (pmu_data->powerdown_conf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 		pmu_data->powerdown_conf(mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	if (pmu_data->pmu_config) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 		for (i = 0; (pmu_data->pmu_config[i].offset != PMU_TABLE_END); i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 			pmu_raw_writel(pmu_data->pmu_config[i].val[mode],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 					pmu_data->pmu_config[i].offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	if (pmu_data->powerdown_conf_extra)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		pmu_data->powerdown_conf_extra(mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62)  * Split the data between ARM architectures because it is relatively big
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63)  * and useless on other arch.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) #ifdef CONFIG_EXYNOS_PMU_ARM_DRIVERS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) #define exynos_pmu_data_arm_ptr(data)	(&data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) #define exynos_pmu_data_arm_ptr(data)	NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) #endif
^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)  * PMU platform driver and devicetree bindings.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) static const struct of_device_id exynos_pmu_of_device_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		.compatible = "samsung,exynos3250-pmu",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		.data = exynos_pmu_data_arm_ptr(exynos3250_pmu_data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	}, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		.compatible = "samsung,exynos4210-pmu",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		.data = exynos_pmu_data_arm_ptr(exynos4210_pmu_data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	}, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 		.compatible = "samsung,exynos4412-pmu",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		.data = exynos_pmu_data_arm_ptr(exynos4412_pmu_data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	}, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		.compatible = "samsung,exynos5250-pmu",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		.data = exynos_pmu_data_arm_ptr(exynos5250_pmu_data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	}, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		.compatible = "samsung,exynos5410-pmu",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	}, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		.compatible = "samsung,exynos5420-pmu",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		.data = exynos_pmu_data_arm_ptr(exynos5420_pmu_data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	}, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		.compatible = "samsung,exynos5433-pmu",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	}, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		.compatible = "samsung,exynos7-pmu",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	{ /*sentinel*/ },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) struct regmap *exynos_get_pmu_regmap(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	struct device_node *np = of_find_matching_node(NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 						      exynos_pmu_of_device_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	if (np)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		return syscon_node_to_regmap(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	return ERR_PTR(-ENODEV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) EXPORT_SYMBOL_GPL(exynos_get_pmu_regmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) static int exynos_pmu_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	struct device *dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	pmu_base_addr = devm_platform_ioremap_resource(pdev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	if (IS_ERR(pmu_base_addr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		return PTR_ERR(pmu_base_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	pmu_context = devm_kzalloc(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 			sizeof(struct exynos_pmu_context),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 			GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	if (!pmu_context)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	pmu_context->dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	pmu_context->pmu_data = of_device_get_match_data(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	if (pmu_context->pmu_data && pmu_context->pmu_data->pmu_init)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		pmu_context->pmu_data->pmu_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	platform_set_drvdata(pdev, pmu_context);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	if (devm_of_platform_populate(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		dev_err(dev, "Error populating children, reboot and poweroff might not work properly\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	dev_dbg(dev, "Exynos PMU Driver probe done\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) static struct platform_driver exynos_pmu_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	.driver  = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		.name   = "exynos-pmu",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		.of_match_table = exynos_pmu_of_device_ids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	.probe = exynos_pmu_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) static int __init exynos_pmu_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	return platform_driver_register(&exynos_pmu_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) postcore_initcall(exynos_pmu_init);