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)  * rmobile power management support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2012  Renesas Solutions Corp.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Copyright (C) 2012  Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Copyright (C) 2014  Glider bvba
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * based on pm-sh7372.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *  Copyright (C) 2011 Magnus Damm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/clk/renesas.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/console.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/of_address.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/of_platform.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/pm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/pm_clock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/pm_domain.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <asm/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) /* SYSC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #define SPDCR		0x08	/* SYS Power Down Control Register */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #define SWUCR		0x14	/* SYS Wakeup Control Register */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #define PSTR		0x80	/* Power Status Register */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #define PSTR_RETRIES	100
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #define PSTR_DELAY_US	10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) struct rmobile_pm_domain {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	struct generic_pm_domain genpd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	struct dev_power_governor *gov;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	int (*suspend)(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	void __iomem *base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	unsigned int bit_shift;
^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 inline
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) struct rmobile_pm_domain *to_rmobile_pd(struct generic_pm_domain *d)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	return container_of(d, struct rmobile_pm_domain, genpd);
^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 int rmobile_pd_power_down(struct generic_pm_domain *genpd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	struct rmobile_pm_domain *rmobile_pd = to_rmobile_pd(genpd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	unsigned int mask = BIT(rmobile_pd->bit_shift);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	if (rmobile_pd->suspend) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 		int ret = rmobile_pd->suspend();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	if (__raw_readl(rmobile_pd->base + PSTR) & mask) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		unsigned int retry_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 		__raw_writel(mask, rmobile_pd->base + SPDCR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 		for (retry_count = PSTR_RETRIES; retry_count; retry_count--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 			if (!(__raw_readl(rmobile_pd->base + SPDCR) & mask))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 			cpu_relax();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		}
^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) 	pr_debug("%s: Power off, 0x%08x -> PSTR = 0x%08x\n", genpd->name, mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		 __raw_readl(rmobile_pd->base + PSTR));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) static int __rmobile_pd_power_up(struct rmobile_pm_domain *rmobile_pd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	unsigned int mask = BIT(rmobile_pd->bit_shift);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	unsigned int retry_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	if (__raw_readl(rmobile_pd->base + PSTR) & mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	__raw_writel(mask, rmobile_pd->base + SWUCR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	for (retry_count = 2 * PSTR_RETRIES; retry_count; retry_count--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		if (!(__raw_readl(rmobile_pd->base + SWUCR) & mask))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		if (retry_count > PSTR_RETRIES)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 			udelay(PSTR_DELAY_US);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 			cpu_relax();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	if (!retry_count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	pr_debug("%s: Power on, 0x%08x -> PSTR = 0x%08x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		 rmobile_pd->genpd.name, mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		 __raw_readl(rmobile_pd->base + PSTR));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) static int rmobile_pd_power_up(struct generic_pm_domain *genpd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	return __rmobile_pd_power_up(to_rmobile_pd(genpd));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) static void rmobile_init_pm_domain(struct rmobile_pm_domain *rmobile_pd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	struct generic_pm_domain *genpd = &rmobile_pd->genpd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	struct dev_power_governor *gov = rmobile_pd->gov;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	genpd->flags |= GENPD_FLAG_PM_CLK | GENPD_FLAG_ACTIVE_WAKEUP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	genpd->attach_dev = cpg_mstp_attach_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	genpd->detach_dev = cpg_mstp_detach_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	if (!(genpd->flags & GENPD_FLAG_ALWAYS_ON)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		genpd->power_off = rmobile_pd_power_down;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		genpd->power_on = rmobile_pd_power_up;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		__rmobile_pd_power_up(rmobile_pd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	pm_genpd_init(genpd, gov ? : &simple_qos_governor, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) static int rmobile_pd_suspend_console(void)
^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) 	 * Serial consoles make use of SCIF hardware located in this domain,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	 * hence keep the power domain on if "no_console_suspend" is set.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	return console_suspend_enabled ? 0 : -EBUSY;
^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) enum pd_types {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	PD_NORMAL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	PD_CPU,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	PD_CONSOLE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	PD_DEBUG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	PD_MEMCTL,
^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) #define MAX_NUM_SPECIAL_PDS	16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) static struct special_pd {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	struct device_node *pd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	enum pd_types type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) } special_pds[MAX_NUM_SPECIAL_PDS] __initdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) static unsigned int num_special_pds __initdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) static const struct of_device_id special_ids[] __initconst = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	{ .compatible = "arm,coresight-etm3x", .data = (void *)PD_DEBUG },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	{ .compatible = "renesas,dbsc-r8a73a4", .data = (void *)PD_MEMCTL, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	{ .compatible = "renesas,dbsc3-r8a7740", .data = (void *)PD_MEMCTL, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	{ .compatible = "renesas,sbsc-sh73a0", .data = (void *)PD_MEMCTL, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	{ /* sentinel */ },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) static void __init add_special_pd(struct device_node *np, enum pd_types type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	struct device_node *pd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	pd = of_parse_phandle(np, "power-domains", 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	if (!pd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	for (i = 0; i < num_special_pds; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 		if (pd == special_pds[i].pd && type == special_pds[i].type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 			of_node_put(pd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	if (num_special_pds == ARRAY_SIZE(special_pds)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 		pr_warn("Too many special PM domains\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 		of_node_put(pd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	pr_debug("Special PM domain %pOFn type %d for %pOF\n", pd, type, np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	special_pds[num_special_pds].pd = pd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	special_pds[num_special_pds].type = type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	num_special_pds++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) static void __init get_special_pds(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	struct device_node *np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	const struct of_device_id *id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	/* PM domains containing CPUs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	for_each_of_cpu_node(np)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		add_special_pd(np, PD_CPU);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	/* PM domain containing console */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	if (of_stdout)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		add_special_pd(of_stdout, PD_CONSOLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	/* PM domains containing other special devices */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	for_each_matching_node_and_match(np, special_ids, &id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		add_special_pd(np, (enum pd_types)id->data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) static void __init put_special_pds(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	for (i = 0; i < num_special_pds; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		of_node_put(special_pds[i].pd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) static enum pd_types __init pd_type(const struct device_node *pd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	for (i = 0; i < num_special_pds; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		if (pd == special_pds[i].pd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 			return special_pds[i].type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	return PD_NORMAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) static void __init rmobile_setup_pm_domain(struct device_node *np,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 					   struct rmobile_pm_domain *pd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	const char *name = pd->genpd.name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	switch (pd_type(np)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	case PD_CPU:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		 * This domain contains the CPU core and therefore it should
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 		 * only be turned off if the CPU is not in use.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		pr_debug("PM domain %s contains CPU\n", name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 		pd->genpd.flags |= GENPD_FLAG_ALWAYS_ON;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	case PD_CONSOLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 		pr_debug("PM domain %s contains serial console\n", name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 		pd->gov = &pm_domain_always_on_gov;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 		pd->suspend = rmobile_pd_suspend_console;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	case PD_DEBUG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 		 * This domain contains the Coresight-ETM hardware block and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 		 * therefore it should only be turned off if the debug module
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 		 * is not in use.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 		pr_debug("PM domain %s contains Coresight-ETM\n", name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		pd->genpd.flags |= GENPD_FLAG_ALWAYS_ON;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	case PD_MEMCTL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 		 * This domain contains a memory-controller and therefore it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 		 * should only be turned off if memory is not in use.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 		pr_debug("PM domain %s contains MEMCTL\n", name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 		pd->genpd.flags |= GENPD_FLAG_ALWAYS_ON;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	case PD_NORMAL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		if (pd->bit_shift == ~0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 			/* Top-level always-on domain */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 			pr_debug("PM domain %s is always-on domain\n", name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 			pd->genpd.flags |= GENPD_FLAG_ALWAYS_ON;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	rmobile_init_pm_domain(pd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) static int __init rmobile_add_pm_domains(void __iomem *base,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 					 struct device_node *parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 					 struct generic_pm_domain *genpd_parent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	struct device_node *np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	for_each_child_of_node(parent, np) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 		struct rmobile_pm_domain *pd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 		u32 idx = ~0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		if (of_property_read_u32(np, "reg", &idx)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 			/* always-on domain */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 		pd = kzalloc(sizeof(*pd), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 		if (!pd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 			of_node_put(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 			return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 		pd->genpd.name = np->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 		pd->base = base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 		pd->bit_shift = idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 		rmobile_setup_pm_domain(np, pd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 		if (genpd_parent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 			pm_genpd_add_subdomain(genpd_parent, &pd->genpd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 		of_genpd_add_provider_simple(np, &pd->genpd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 		rmobile_add_pm_domains(base, np, &pd->genpd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) static int __init rmobile_init_pm_domains(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	struct device_node *np, *pmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	bool scanned = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	void __iomem *base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	for_each_compatible_node(np, NULL, "renesas,sysc-rmobile") {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 		base = of_iomap(np, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 		if (!base) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 			pr_warn("%pOF cannot map reg 0\n", np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 		pmd = of_get_child_by_name(np, "pm-domains");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 		if (!pmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 			iounmap(base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 			pr_warn("%pOF lacks pm-domains node\n", np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 		if (!scanned) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 			/* Find PM domains containing special blocks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 			get_special_pds();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 			scanned = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 		ret = rmobile_add_pm_domains(base, pmd, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 		of_node_put(pmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 		if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 			of_node_put(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	put_special_pds();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) core_initcall(rmobile_init_pm_domains);