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) // Exynos Generic power domain support.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) // Copyright (c) 2012 Samsung Electronics Co., Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) //		http://www.samsung.com
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) // Implementation of Exynos specific power domain control which is used in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) // conjunction with runtime-pm. Support for both device-tree and non-device-tree
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) // based power domain support is included.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/pm_domain.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/of_address.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/of_platform.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) struct exynos_pm_domain_config {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	/* Value for LOCAL_PWR_CFG and STATUS fields for each domain */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	u32 local_pwr_cfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) };
^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)  * Exynos specific wrapper around the generic power domain
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) struct exynos_pm_domain {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	void __iomem *base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	bool is_off;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	struct generic_pm_domain pd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	u32 local_pwr_cfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) static int exynos_pd_power(struct generic_pm_domain *domain, bool power_on)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	struct exynos_pm_domain *pd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	void __iomem *base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	u32 timeout, pwr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	char *op;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	pd = container_of(domain, struct exynos_pm_domain, pd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	base = pd->base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	pwr = power_on ? pd->local_pwr_cfg : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	writel_relaxed(pwr, base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	/* Wait max 1ms */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	timeout = 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	while ((readl_relaxed(base + 0x4) & pd->local_pwr_cfg) != pwr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 		if (!timeout) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 			op = (power_on) ? "enable" : "disable";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 			pr_err("Power domain %s %s failed\n", domain->name, op);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 			return -ETIMEDOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		timeout--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		cpu_relax();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		usleep_range(80, 100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) static int exynos_pd_power_on(struct generic_pm_domain *domain)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	return exynos_pd_power(domain, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) static int exynos_pd_power_off(struct generic_pm_domain *domain)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	return exynos_pd_power(domain, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) static const struct exynos_pm_domain_config exynos4210_cfg __initconst = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	.local_pwr_cfg		= 0x7,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) static const struct exynos_pm_domain_config exynos5433_cfg __initconst = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	.local_pwr_cfg		= 0xf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) static const struct of_device_id exynos_pm_domain_of_match[] __initconst = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		.compatible = "samsung,exynos4210-pd",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		.data = &exynos4210_cfg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	}, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		.compatible = "samsung,exynos5433-pd",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		.data = &exynos5433_cfg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	{ },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) static __init const char *exynos_get_domain_name(struct device_node *node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	if (of_property_read_string(node, "label", &name) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		name = kbasename(node->full_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	return kstrdup_const(name, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) static __init int exynos4_pm_init_power_domain(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	struct device_node *np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	const struct of_device_id *match;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	for_each_matching_node_and_match(np, exynos_pm_domain_of_match, &match) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		const struct exynos_pm_domain_config *pm_domain_cfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		struct exynos_pm_domain *pd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		int on;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		pm_domain_cfg = match->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		pd = kzalloc(sizeof(*pd), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 		if (!pd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 			of_node_put(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 			return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		pd->pd.name = exynos_get_domain_name(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		if (!pd->pd.name) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 			kfree(pd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 			of_node_put(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 			return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		pd->base = of_iomap(np, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		if (!pd->base) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 			pr_warn("%s: failed to map memory\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 			kfree_const(pd->pd.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 			kfree(pd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		pd->pd.power_off = exynos_pd_power_off;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		pd->pd.power_on = exynos_pd_power_on;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		pd->local_pwr_cfg = pm_domain_cfg->local_pwr_cfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		on = readl_relaxed(pd->base + 0x4) & pd->local_pwr_cfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		pm_genpd_init(&pd->pd, NULL, !on);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		of_genpd_add_provider_simple(np, &pd->pd);
^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) 	/* Assign the child power domains to their parents */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	for_each_matching_node(np, exynos_pm_domain_of_match) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		struct of_phandle_args child, parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		child.np = np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		child.args_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		if (of_parse_phandle_with_args(np, "power-domains",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 					       "#power-domain-cells", 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 					       &parent) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		if (of_genpd_add_subdomain(&parent, &child))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 			pr_warn("%pOF failed to add subdomain: %pOF\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 				parent.np, child.np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 			pr_info("%pOF has as child subdomain: %pOF.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 				parent.np, child.np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) core_initcall(exynos4_pm_init_power_domain);