FILE
exynos-pm-domains.c
File preview with syntax highlighting.
linux-6.19.14/drivers/pmdomain/samsung/exynos-pm-domains.c
1// SPDX-License-Identifier: GPL-2.0 2// 3// Exynos Generic power domain support. 4// 5// Copyright (c) 2012 Samsung Electronics Co., Ltd. 6// http://www.samsung.com 7// 8// Implementation of Exynos specific power domain control which is used in 9// conjunction with runtime-pm. Support for both device-tree and non-device-tree 10// based power domain support is included. 11 12#include <linux/io.h> 13#include <linux/err.h> 14#include <linux/platform_device.h> 15#include <linux/slab.h> 16#include <linux/pm_domain.h> 17#include <linux/delay.h> 18#include <linux/of.h> 19#include <linux/of_address.h> 20#include <linux/pm_runtime.h> 21 22struct exynos_pm_domain_config { 23 /* Value for LOCAL_PWR_CFG and STATUS fields for each domain */ 24 u32 local_pwr_cfg; 25}; 26 27/* 28 * Exynos specific wrapper around the generic power domain 29 */ 30struct exynos_pm_domain { 31 void __iomem *base; 32 struct generic_pm_domain pd; 33 u32 local_pwr_cfg; 34}; 35 36static int exynos_pd_power(struct generic_pm_domain *domain, bool power_on) 37{ 38 struct exynos_pm_domain *pd; 39 void __iomem *base; 40 u32 timeout, pwr; 41 char *op; 42 43 pd = container_of(domain, struct exynos_pm_domain, pd); 44 base = pd->base; 45 46 pwr = power_on ? pd->local_pwr_cfg : 0; 47 writel_relaxed(pwr, base); 48 49 /* Wait max 1ms */ 50 timeout = 10; 51 52 while ((readl_relaxed(base + 0x4) & pd->local_pwr_cfg) != pwr) { 53 if (!timeout) { 54 op = (power_on) ? "enable" : "disable"; 55 pr_err("Power domain %s %s failed\n", domain->name, op); 56 return -ETIMEDOUT; 57 } 58 timeout--; 59 cpu_relax(); 60 usleep_range(80, 100); 61 } 62 63 return 0; 64} 65 66static int exynos_pd_power_on(struct generic_pm_domain *domain) 67{ 68 return exynos_pd_power(domain, true); 69} 70 71static int exynos_pd_power_off(struct generic_pm_domain *domain) 72{ 73 return exynos_pd_power(domain, false); 74} 75 76static const struct exynos_pm_domain_config exynos4210_cfg = { 77 .local_pwr_cfg = 0x7, 78}; 79 80static const struct exynos_pm_domain_config exynos5433_cfg = { 81 .local_pwr_cfg = 0xf, 82}; 83 84static const struct of_device_id exynos_pm_domain_of_match[] = { 85 { 86 .compatible = "samsung,exynos4210-pd", 87 .data = &exynos4210_cfg, 88 }, { 89 .compatible = "samsung,exynos5433-pd", 90 .data = &exynos5433_cfg, 91 }, 92 { }, 93}; 94 95static const char *exynos_get_domain_name(struct device *dev, 96 struct device_node *node) 97{ 98 const char *name; 99 100 if (of_property_read_string(node, "label", &name) < 0) 101 name = kbasename(node->full_name); 102 return devm_kstrdup_const(dev, name, GFP_KERNEL); 103} 104 105static int exynos_pd_probe(struct platform_device *pdev) 106{ 107 const struct exynos_pm_domain_config *pm_domain_cfg; 108 struct device *dev = &pdev->dev; 109 struct device_node *np = dev->of_node; 110 struct of_phandle_args child, parent; 111 struct exynos_pm_domain *pd; 112 int on, ret; 113 114 pm_domain_cfg = of_device_get_match_data(dev); 115 pd = devm_kzalloc(dev, sizeof(*pd), GFP_KERNEL); 116 if (!pd) 117 return -ENOMEM; 118 119 pd->pd.name = exynos_get_domain_name(dev, np); 120 if (!pd->pd.name) 121 return -ENOMEM; 122 123 pd->base = of_iomap(np, 0); 124 if (!pd->base) 125 return -ENODEV; 126 127 pd->pd.power_off = exynos_pd_power_off; 128 pd->pd.power_on = exynos_pd_power_on; 129 pd->local_pwr_cfg = pm_domain_cfg->local_pwr_cfg; 130 131 /* 132 * Some Samsung platforms with bootloaders turning on the splash-screen 133 * and handing it over to the kernel, requires the power-domains to be 134 * reset during boot. 135 */ 136 if (IS_ENABLED(CONFIG_ARM) && 137 of_device_is_compatible(np, "samsung,exynos4210-pd")) 138 exynos_pd_power_off(&pd->pd); 139 140 on = readl_relaxed(pd->base + 0x4) & pd->local_pwr_cfg; 141 142 pm_genpd_init(&pd->pd, NULL, !on); 143 ret = of_genpd_add_provider_simple(np, &pd->pd); 144 145 if (ret == 0 && of_parse_phandle_with_args(np, "power-domains", 146 "#power-domain-cells", 0, &parent) == 0) { 147 child.np = np; 148 child.args_count = 0; 149 150 if (of_genpd_add_subdomain(&parent, &child)) 151 pr_warn("%pOF failed to add subdomain: %pOF\n", 152 parent.np, child.np); 153 else 154 pr_info("%pOF has as child subdomain: %pOF.\n", 155 parent.np, child.np); 156 } 157 158 pm_runtime_enable(dev); 159 return ret; 160} 161 162static struct platform_driver exynos_pd_driver = { 163 .probe = exynos_pd_probe, 164 .driver = { 165 .name = "exynos-pd", 166 .of_match_table = exynos_pm_domain_of_match, 167 .suppress_bind_attrs = true, 168 } 169}; 170 171static __init int exynos4_pm_init_power_domain(void) 172{ 173 return platform_driver_register(&exynos_pd_driver); 174} 175core_initcall(exynos4_pm_init_power_domain);
~/
Read-only file preview.