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)  * OMAP2/3/4 clockdomain framework functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  * Copyright (C) 2008-2011 Texas Instruments, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)  * Copyright (C) 2008-2011 Nokia Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8)  * Written by Paul Walmsley and Jouni Högander
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9)  * Added OMAP4 specific support by Abhijit Pagare <abhijitpagare@ti.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11) #undef DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19) #include <linux/clk.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20) #include <linux/limits.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22) #include <linux/clk-provider.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23) #include <linux/cpu_pm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27) #include <linux/bitops.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29) #include "soc.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30) #include "clock.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) #include "clockdomain.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) #include "pm.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) /* clkdm_list contains all registered struct clockdomains */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) static LIST_HEAD(clkdm_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) /* array of clockdomain deps to be added/removed when clkdm in hwsup mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) static struct clkdm_autodep *autodeps;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) static struct clkdm_ops *arch_clkdm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) void clkdm_save_context(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) void clkdm_restore_context(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) /* Private functions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) static struct clockdomain *_clkdm_lookup(const char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) 	struct clockdomain *clkdm, *temp_clkdm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) 	if (!name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) 	clkdm = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) 	list_for_each_entry(temp_clkdm, &clkdm_list, node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) 		if (!strcmp(name, temp_clkdm->name)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) 			clkdm = temp_clkdm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) 			break;
^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) 	return clkdm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) }
^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)  * _clkdm_register - register a clockdomain
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67)  * @clkdm: struct clockdomain * to register
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69)  * Adds a clockdomain to the internal clockdomain list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70)  * Returns -EINVAL if given a null pointer, -EEXIST if a clockdomain is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71)  * already registered by the provided name, or 0 upon success.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) static int _clkdm_register(struct clockdomain *clkdm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) 	struct powerdomain *pwrdm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) 	if (!clkdm || !clkdm->name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) 	pwrdm = pwrdm_lookup(clkdm->pwrdm.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) 	if (!pwrdm) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) 		pr_err("clockdomain: %s: powerdomain %s does not exist\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) 			clkdm->name, clkdm->pwrdm.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) 	clkdm->pwrdm.ptr = pwrdm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) 	/* Verify that the clockdomain is not already registered */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) 	if (_clkdm_lookup(clkdm->name))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) 		return -EEXIST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) 	list_add(&clkdm->node, &clkdm_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) 	pwrdm_add_clkdm(pwrdm, clkdm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) 	pr_debug("clockdomain: registered %s\n", clkdm->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) /* _clkdm_deps_lookup - look up the specified clockdomain in a clkdm list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) static struct clkdm_dep *_clkdm_deps_lookup(struct clockdomain *clkdm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) 					    struct clkdm_dep *deps)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) 	struct clkdm_dep *cd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) 	if (!clkdm || !deps)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) 		return ERR_PTR(-EINVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) 	for (cd = deps; cd->clkdm_name; cd++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) 		if (!cd->clkdm && cd->clkdm_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) 			cd->clkdm = _clkdm_lookup(cd->clkdm_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) 		if (cd->clkdm == clkdm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) 	if (!cd->clkdm_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) 		return ERR_PTR(-ENOENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) 	return cd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) }
^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)  * _autodep_lookup - resolve autodep clkdm names to clkdm pointers; store
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126)  * @autodep: struct clkdm_autodep * to resolve
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128)  * Resolve autodep clockdomain names to clockdomain pointers via
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129)  * clkdm_lookup() and store the pointers in the autodep structure.  An
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130)  * "autodep" is a clockdomain sleep/wakeup dependency that is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131)  * automatically added and removed whenever clocks in the associated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132)  * clockdomain are enabled or disabled (respectively) when the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133)  * clockdomain is in hardware-supervised mode.	Meant to be called
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134)  * once at clockdomain layer initialization, since these should remain
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135)  * fixed for a particular architecture.  No return value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137)  * XXX autodeps are deprecated and should be removed at the earliest
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138)  * opportunity
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) static void _autodep_lookup(struct clkdm_autodep *autodep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) 	struct clockdomain *clkdm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) 	if (!autodep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) 	clkdm = clkdm_lookup(autodep->clkdm.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) 	if (!clkdm) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 		pr_err("clockdomain: autodeps: clockdomain %s does not exist\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) 			 autodep->clkdm.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) 		clkdm = ERR_PTR(-ENOENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) 	autodep->clkdm.ptr = clkdm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157)  * _resolve_clkdm_deps() - resolve clkdm_names in @clkdm_deps to clkdms
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158)  * @clkdm: clockdomain that we are resolving dependencies for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159)  * @clkdm_deps: ptr to array of struct clkdm_deps to resolve
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161)  * Iterates through @clkdm_deps, looking up the struct clockdomain named by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162)  * clkdm_name and storing the clockdomain pointer in the struct clkdm_dep.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163)  * No return value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) static void _resolve_clkdm_deps(struct clockdomain *clkdm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) 				struct clkdm_dep *clkdm_deps)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) 	struct clkdm_dep *cd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) 	for (cd = clkdm_deps; cd && cd->clkdm_name; cd++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) 		if (cd->clkdm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) 		cd->clkdm = _clkdm_lookup(cd->clkdm_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) 		WARN(!cd->clkdm, "clockdomain: %s: could not find clkdm %s while resolving dependencies - should never happen",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) 		     clkdm->name, cd->clkdm_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181)  * _clkdm_add_wkdep - add a wakeup dependency from clkdm2 to clkdm1 (lockless)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182)  * @clkdm1: wake this struct clockdomain * up (dependent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183)  * @clkdm2: when this struct clockdomain * wakes up (source)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185)  * When the clockdomain represented by @clkdm2 wakes up, wake up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186)  * @clkdm1. Implemented in hardware on the OMAP, this feature is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187)  * designed to reduce wakeup latency of the dependent clockdomain @clkdm1.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188)  * Returns -EINVAL if presented with invalid clockdomain pointers,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189)  * -ENOENT if @clkdm2 cannot wake up clkdm1 in hardware, or 0 upon
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190)  * success.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) static int _clkdm_add_wkdep(struct clockdomain *clkdm1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) 			    struct clockdomain *clkdm2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) 	struct clkdm_dep *cd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) 	if (!clkdm1 || !clkdm2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) 	cd = _clkdm_deps_lookup(clkdm2, clkdm1->wkdep_srcs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 	if (IS_ERR(cd))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) 		ret = PTR_ERR(cd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) 	if (!arch_clkdm || !arch_clkdm->clkdm_add_wkdep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) 		ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) 		pr_debug("clockdomain: hardware cannot set/clear wake up of %s when %s wakes up\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) 			 clkdm1->name, clkdm2->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 	cd->wkdep_usecount++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 	if (cd->wkdep_usecount == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) 		pr_debug("clockdomain: hardware will wake up %s when %s wakes up\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) 			 clkdm1->name, clkdm2->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) 		ret = arch_clkdm->clkdm_add_wkdep(clkdm1, clkdm2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226)  * _clkdm_del_wkdep - remove a wakeup dep from clkdm2 to clkdm1 (lockless)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227)  * @clkdm1: wake this struct clockdomain * up (dependent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228)  * @clkdm2: when this struct clockdomain * wakes up (source)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230)  * Remove a wakeup dependency causing @clkdm1 to wake up when @clkdm2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231)  * wakes up.  Returns -EINVAL if presented with invalid clockdomain
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232)  * pointers, -ENOENT if @clkdm2 cannot wake up clkdm1 in hardware, or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233)  * 0 upon success.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) static int _clkdm_del_wkdep(struct clockdomain *clkdm1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 			    struct clockdomain *clkdm2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 	struct clkdm_dep *cd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) 	if (!clkdm1 || !clkdm2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 	cd = _clkdm_deps_lookup(clkdm2, clkdm1->wkdep_srcs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 	if (IS_ERR(cd))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) 		ret = PTR_ERR(cd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 	if (!arch_clkdm || !arch_clkdm->clkdm_del_wkdep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) 		ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) 		pr_debug("clockdomain: hardware cannot set/clear wake up of %s when %s wakes up\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) 			 clkdm1->name, clkdm2->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) 	cd->wkdep_usecount--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 	if (cd->wkdep_usecount == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) 		pr_debug("clockdomain: hardware will no longer wake up %s after %s wakes up\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) 			 clkdm1->name, clkdm2->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) 		ret = arch_clkdm->clkdm_del_wkdep(clkdm1, clkdm2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269)  * _clkdm_add_sleepdep - add a sleep dependency from clkdm2 to clkdm1 (lockless)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270)  * @clkdm1: prevent this struct clockdomain * from sleeping (dependent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271)  * @clkdm2: when this struct clockdomain * is active (source)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273)  * Prevent @clkdm1 from automatically going inactive (and then to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274)  * retention or off) if @clkdm2 is active.  Returns -EINVAL if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275)  * presented with invalid clockdomain pointers or called on a machine
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276)  * that does not support software-configurable hardware sleep
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277)  * dependencies, -ENOENT if the specified dependency cannot be set in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278)  * hardware, or 0 upon success.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) static int _clkdm_add_sleepdep(struct clockdomain *clkdm1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 			       struct clockdomain *clkdm2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 	struct clkdm_dep *cd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) 	if (!clkdm1 || !clkdm2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) 	cd = _clkdm_deps_lookup(clkdm2, clkdm1->sleepdep_srcs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 	if (IS_ERR(cd))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 		ret = PTR_ERR(cd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) 	if (!arch_clkdm || !arch_clkdm->clkdm_add_sleepdep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 		ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) 		pr_debug("clockdomain: hardware cannot set/clear sleep dependency affecting %s from %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) 			 clkdm1->name, clkdm2->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 	cd->sleepdep_usecount++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 	if (cd->sleepdep_usecount == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 		pr_debug("clockdomain: will prevent %s from sleeping if %s is active\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 			 clkdm1->name, clkdm2->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 		ret = arch_clkdm->clkdm_add_sleepdep(clkdm1, clkdm2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) }
^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)  * _clkdm_del_sleepdep - remove a sleep dep from clkdm2 to clkdm1 (lockless)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315)  * @clkdm1: prevent this struct clockdomain * from sleeping (dependent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316)  * @clkdm2: when this struct clockdomain * is active (source)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318)  * Allow @clkdm1 to automatically go inactive (and then to retention or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319)  * off), independent of the activity state of @clkdm2.  Returns -EINVAL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320)  * if presented with invalid clockdomain pointers or called on a machine
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321)  * that does not support software-configurable hardware sleep dependencies,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322)  * -ENOENT if the specified dependency cannot be cleared in hardware, or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323)  * 0 upon success.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) static int _clkdm_del_sleepdep(struct clockdomain *clkdm1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 			       struct clockdomain *clkdm2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 	struct clkdm_dep *cd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 	if (!clkdm1 || !clkdm2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) 	cd = _clkdm_deps_lookup(clkdm2, clkdm1->sleepdep_srcs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) 	if (IS_ERR(cd))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 		ret = PTR_ERR(cd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 	if (!arch_clkdm || !arch_clkdm->clkdm_del_sleepdep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 		ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 		pr_debug("clockdomain: hardware cannot set/clear sleep dependency affecting %s from %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 			 clkdm1->name, clkdm2->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 	cd->sleepdep_usecount--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 	if (cd->sleepdep_usecount == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 		pr_debug("clockdomain: will no longer prevent %s from sleeping if %s is active\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 			 clkdm1->name, clkdm2->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 		ret = arch_clkdm->clkdm_del_sleepdep(clkdm1, clkdm2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) /* Public functions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361)  * clkdm_register_platform_funcs - register clockdomain implementation fns
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362)  * @co: func pointers for arch specific implementations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364)  * Register the list of function pointers used to implement the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365)  * clockdomain functions on different OMAP SoCs.  Should be called
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366)  * before any other clkdm_register*() function.  Returns -EINVAL if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367)  * @co is null, -EEXIST if platform functions have already been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368)  * registered, or 0 upon success.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) int clkdm_register_platform_funcs(struct clkdm_ops *co)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 	if (!co)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 	if (arch_clkdm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 		return -EEXIST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 	arch_clkdm = co;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384)  * clkdm_register_clkdms - register SoC clockdomains
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385)  * @cs: pointer to an array of struct clockdomain to register
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387)  * Register the clockdomains available on a particular OMAP SoC.  Must
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388)  * be called after clkdm_register_platform_funcs().  May be called
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389)  * multiple times.  Returns -EACCES if called before
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390)  * clkdm_register_platform_funcs(); -EINVAL if the argument @cs is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391)  * null; or 0 upon success.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) int clkdm_register_clkdms(struct clockdomain **cs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 	struct clockdomain **c = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 	if (!arch_clkdm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 		return -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 	if (!cs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 	for (c = cs; *c; c++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 		_clkdm_register(*c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410)  * clkdm_register_autodeps - register autodeps (if required)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411)  * @ia: pointer to a static array of struct clkdm_autodep to register
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413)  * Register clockdomain "automatic dependencies."  These are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414)  * clockdomain wakeup and sleep dependencies that are automatically
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415)  * added whenever the first clock inside a clockdomain is enabled, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416)  * removed whenever the last clock inside a clockdomain is disabled.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417)  * These are currently only used on OMAP3 devices, and are deprecated,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418)  * since they waste energy.  However, until the OMAP2/3 IP block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419)  * enable/disable sequence can be converted to match the OMAP4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420)  * sequence, they are needed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422)  * Must be called only after all of the SoC clockdomains are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423)  * registered, since the function will resolve autodep clockdomain
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424)  * names into clockdomain pointers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426)  * The struct clkdm_autodep @ia array must be static, as this function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427)  * does not copy the array elements.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429)  * Returns -EACCES if called before any clockdomains have been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430)  * registered, -EINVAL if called with a null @ia argument, -EEXIST if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431)  * autodeps have already been registered, or 0 upon success.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) int clkdm_register_autodeps(struct clkdm_autodep *ia)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 	struct clkdm_autodep *a = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 	if (list_empty(&clkdm_list))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 		return -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 	if (!ia)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 	if (autodeps)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 		return -EEXIST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 	autodeps = ia;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 	for (a = autodeps; a->clkdm.ptr; a++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 		_autodep_lookup(a);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) static int cpu_notifier(struct notifier_block *nb, unsigned long cmd, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 	switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 	case CPU_CLUSTER_PM_ENTER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 		if (enable_off_mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 			clkdm_save_context();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 	case CPU_CLUSTER_PM_EXIT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 		if (enable_off_mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 			clkdm_restore_context();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 	return NOTIFY_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470)  * clkdm_complete_init - set up the clockdomain layer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472)  * Put all clockdomains into software-supervised mode; PM code should
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473)  * later enable hardware-supervised mode as appropriate.  Must be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474)  * called after clkdm_register_clkdms().  Returns -EACCES if called
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475)  * before clkdm_register_clkdms(), or 0 upon success.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) int clkdm_complete_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 	struct clockdomain *clkdm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 	static struct notifier_block nb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 	if (list_empty(&clkdm_list))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 		return -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 	list_for_each_entry(clkdm, &clkdm_list, node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 		clkdm_deny_idle(clkdm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 		_resolve_clkdm_deps(clkdm, clkdm->wkdep_srcs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 		clkdm_clear_all_wkdeps(clkdm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 		_resolve_clkdm_deps(clkdm, clkdm->sleepdep_srcs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 		clkdm_clear_all_sleepdeps(clkdm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 	/* Only AM43XX can lose clkdm context during rtc-ddr suspend */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 	if (soc_is_am43xx()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 		nb.notifier_call = cpu_notifier;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 		cpu_pm_register_notifier(&nb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505)  * clkdm_lookup - look up a clockdomain by name, return a pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506)  * @name: name of clockdomain
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508)  * Find a registered clockdomain by its name @name.  Returns a pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509)  * to the struct clockdomain if found, or NULL otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) struct clockdomain *clkdm_lookup(const char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 	struct clockdomain *clkdm, *temp_clkdm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 	if (!name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) 	clkdm = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) 	list_for_each_entry(temp_clkdm, &clkdm_list, node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 		if (!strcmp(name, temp_clkdm->name)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 			clkdm = temp_clkdm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 	return clkdm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531)  * clkdm_for_each - call function on each registered clockdomain
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532)  * @fn: callback function *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534)  * Call the supplied function @fn for each registered clockdomain.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535)  * The callback function @fn can return anything but 0 to bail
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536)  * out early from the iterator.  The callback function is called with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537)  * the clkdm_mutex held, so no clockdomain structure manipulation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538)  * functions should be called from the callback, although hardware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539)  * clockdomain control functions are fine.  Returns the last return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540)  * value of the callback function, which should be 0 for success or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541)  * anything else to indicate failure; or -EINVAL if the function pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542)  * is null.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) int clkdm_for_each(int (*fn)(struct clockdomain *clkdm, void *user),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 			void *user)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 	struct clockdomain *clkdm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 	if (!fn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 	list_for_each_entry(clkdm, &clkdm_list, node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 		ret = (*fn)(clkdm, user);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564)  * clkdm_get_pwrdm - return a ptr to the pwrdm that this clkdm resides in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565)  * @clkdm: struct clockdomain *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567)  * Return a pointer to the struct powerdomain that the specified clockdomain
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568)  * @clkdm exists in, or returns NULL if @clkdm is NULL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) struct powerdomain *clkdm_get_pwrdm(struct clockdomain *clkdm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 	if (!clkdm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 	return clkdm->pwrdm.ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) /* Hardware clockdomain control */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582)  * clkdm_add_wkdep - add a wakeup dependency from clkdm2 to clkdm1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583)  * @clkdm1: wake this struct clockdomain * up (dependent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584)  * @clkdm2: when this struct clockdomain * wakes up (source)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586)  * When the clockdomain represented by @clkdm2 wakes up, wake up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587)  * @clkdm1. Implemented in hardware on the OMAP, this feature is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588)  * designed to reduce wakeup latency of the dependent clockdomain @clkdm1.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589)  * Returns -EINVAL if presented with invalid clockdomain pointers,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590)  * -ENOENT if @clkdm2 cannot wake up clkdm1 in hardware, or 0 upon
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591)  * success.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) int clkdm_add_wkdep(struct clockdomain *clkdm1, struct clockdomain *clkdm2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 	struct clkdm_dep *cd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 	if (!clkdm1 || !clkdm2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 	cd = _clkdm_deps_lookup(clkdm2, clkdm1->wkdep_srcs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 	if (IS_ERR(cd))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 		return PTR_ERR(cd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 	pwrdm_lock(cd->clkdm->pwrdm.ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 	ret = _clkdm_add_wkdep(clkdm1, clkdm2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 	pwrdm_unlock(cd->clkdm->pwrdm.ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613)  * clkdm_del_wkdep - remove a wakeup dependency from clkdm2 to clkdm1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614)  * @clkdm1: wake this struct clockdomain * up (dependent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615)  * @clkdm2: when this struct clockdomain * wakes up (source)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617)  * Remove a wakeup dependency causing @clkdm1 to wake up when @clkdm2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618)  * wakes up.  Returns -EINVAL if presented with invalid clockdomain
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619)  * pointers, -ENOENT if @clkdm2 cannot wake up clkdm1 in hardware, or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620)  * 0 upon success.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) int clkdm_del_wkdep(struct clockdomain *clkdm1, struct clockdomain *clkdm2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 	struct clkdm_dep *cd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 	if (!clkdm1 || !clkdm2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 	cd = _clkdm_deps_lookup(clkdm2, clkdm1->wkdep_srcs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 	if (IS_ERR(cd))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 		return PTR_ERR(cd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 	pwrdm_lock(cd->clkdm->pwrdm.ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 	ret = _clkdm_del_wkdep(clkdm1, clkdm2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 	pwrdm_unlock(cd->clkdm->pwrdm.ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642)  * clkdm_read_wkdep - read wakeup dependency state from clkdm2 to clkdm1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643)  * @clkdm1: wake this struct clockdomain * up (dependent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644)  * @clkdm2: when this struct clockdomain * wakes up (source)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646)  * Return 1 if a hardware wakeup dependency exists wherein @clkdm1 will be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647)  * awoken when @clkdm2 wakes up; 0 if dependency is not set; -EINVAL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648)  * if either clockdomain pointer is invalid; or -ENOENT if the hardware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649)  * is incapable.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651)  * REVISIT: Currently this function only represents software-controllable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652)  * wakeup dependencies.  Wakeup dependencies fixed in hardware are not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653)  * yet handled here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) int clkdm_read_wkdep(struct clockdomain *clkdm1, struct clockdomain *clkdm2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 	struct clkdm_dep *cd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 	if (!clkdm1 || !clkdm2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 	cd = _clkdm_deps_lookup(clkdm2, clkdm1->wkdep_srcs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 	if (IS_ERR(cd))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 		ret = PTR_ERR(cd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) 	if (!arch_clkdm || !arch_clkdm->clkdm_read_wkdep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 		ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 		pr_debug("clockdomain: hardware cannot set/clear wake up of %s when %s wakes up\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 			 clkdm1->name, clkdm2->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 	/* XXX It's faster to return the wkdep_usecount */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 	return arch_clkdm->clkdm_read_wkdep(clkdm1, clkdm2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681)  * clkdm_clear_all_wkdeps - remove all wakeup dependencies from target clkdm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682)  * @clkdm: struct clockdomain * to remove all wakeup dependencies from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684)  * Remove all inter-clockdomain wakeup dependencies that could cause
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685)  * @clkdm to wake.  Intended to be used during boot to initialize the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686)  * PRCM to a known state, after all clockdomains are put into swsup idle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687)  * and woken up.  Returns -EINVAL if @clkdm pointer is invalid, or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688)  * 0 upon success.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) int clkdm_clear_all_wkdeps(struct clockdomain *clkdm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 	if (!clkdm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 	if (!arch_clkdm || !arch_clkdm->clkdm_clear_all_wkdeps)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 	return arch_clkdm->clkdm_clear_all_wkdeps(clkdm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702)  * clkdm_add_sleepdep - add a sleep dependency from clkdm2 to clkdm1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703)  * @clkdm1: prevent this struct clockdomain * from sleeping (dependent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704)  * @clkdm2: when this struct clockdomain * is active (source)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706)  * Prevent @clkdm1 from automatically going inactive (and then to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707)  * retention or off) if @clkdm2 is active.  Returns -EINVAL if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708)  * presented with invalid clockdomain pointers or called on a machine
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709)  * that does not support software-configurable hardware sleep
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710)  * dependencies, -ENOENT if the specified dependency cannot be set in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711)  * hardware, or 0 upon success.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) int clkdm_add_sleepdep(struct clockdomain *clkdm1, struct clockdomain *clkdm2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 	struct clkdm_dep *cd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 	if (!clkdm1 || !clkdm2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 	cd = _clkdm_deps_lookup(clkdm2, clkdm1->wkdep_srcs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 	if (IS_ERR(cd))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 		return PTR_ERR(cd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 	pwrdm_lock(cd->clkdm->pwrdm.ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 	ret = _clkdm_add_sleepdep(clkdm1, clkdm2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 	pwrdm_unlock(cd->clkdm->pwrdm.ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733)  * clkdm_del_sleepdep - remove a sleep dependency from clkdm2 to clkdm1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734)  * @clkdm1: prevent this struct clockdomain * from sleeping (dependent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735)  * @clkdm2: when this struct clockdomain * is active (source)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737)  * Allow @clkdm1 to automatically go inactive (and then to retention or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738)  * off), independent of the activity state of @clkdm2.  Returns -EINVAL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739)  * if presented with invalid clockdomain pointers or called on a machine
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740)  * that does not support software-configurable hardware sleep dependencies,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741)  * -ENOENT if the specified dependency cannot be cleared in hardware, or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742)  * 0 upon success.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) int clkdm_del_sleepdep(struct clockdomain *clkdm1, struct clockdomain *clkdm2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 	struct clkdm_dep *cd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 	if (!clkdm1 || !clkdm2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 	cd = _clkdm_deps_lookup(clkdm2, clkdm1->wkdep_srcs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 	if (IS_ERR(cd))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 		return PTR_ERR(cd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 	pwrdm_lock(cd->clkdm->pwrdm.ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 	ret = _clkdm_del_sleepdep(clkdm1, clkdm2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 	pwrdm_unlock(cd->clkdm->pwrdm.ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764)  * clkdm_read_sleepdep - read sleep dependency state from clkdm2 to clkdm1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765)  * @clkdm1: prevent this struct clockdomain * from sleeping (dependent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766)  * @clkdm2: when this struct clockdomain * is active (source)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768)  * Return 1 if a hardware sleep dependency exists wherein @clkdm1 will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769)  * not be allowed to automatically go inactive if @clkdm2 is active;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770)  * 0 if @clkdm1's automatic power state inactivity transition is independent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771)  * of @clkdm2's; -EINVAL if either clockdomain pointer is invalid or called
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772)  * on a machine that does not support software-configurable hardware sleep
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773)  * dependencies; or -ENOENT if the hardware is incapable.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775)  * REVISIT: Currently this function only represents software-controllable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776)  * sleep dependencies.	Sleep dependencies fixed in hardware are not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777)  * yet handled here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) int clkdm_read_sleepdep(struct clockdomain *clkdm1, struct clockdomain *clkdm2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 	struct clkdm_dep *cd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 	if (!clkdm1 || !clkdm2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 	cd = _clkdm_deps_lookup(clkdm2, clkdm1->sleepdep_srcs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 	if (IS_ERR(cd))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 		ret = PTR_ERR(cd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 	if (!arch_clkdm || !arch_clkdm->clkdm_read_sleepdep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 		ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 		pr_debug("clockdomain: hardware cannot set/clear sleep dependency affecting %s from %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 			 clkdm1->name, clkdm2->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 	/* XXX It's faster to return the sleepdep_usecount */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 	return arch_clkdm->clkdm_read_sleepdep(clkdm1, clkdm2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805)  * clkdm_clear_all_sleepdeps - remove all sleep dependencies from target clkdm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806)  * @clkdm: struct clockdomain * to remove all sleep dependencies from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808)  * Remove all inter-clockdomain sleep dependencies that could prevent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809)  * @clkdm from idling.  Intended to be used during boot to initialize the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810)  * PRCM to a known state, after all clockdomains are put into swsup idle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811)  * and woken up.  Returns -EINVAL if @clkdm pointer is invalid, or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812)  * 0 upon success.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) int clkdm_clear_all_sleepdeps(struct clockdomain *clkdm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 	if (!clkdm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 	if (!arch_clkdm || !arch_clkdm->clkdm_clear_all_sleepdeps)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 	return arch_clkdm->clkdm_clear_all_sleepdeps(clkdm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826)  * clkdm_sleep_nolock - force clockdomain sleep transition (lockless)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827)  * @clkdm: struct clockdomain *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829)  * Instruct the CM to force a sleep transition on the specified
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830)  * clockdomain @clkdm.  Only for use by the powerdomain code.  Returns
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831)  * -EINVAL if @clkdm is NULL or if clockdomain does not support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832)  * software-initiated sleep; 0 upon success.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) int clkdm_sleep_nolock(struct clockdomain *clkdm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 	if (!clkdm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 	if (!(clkdm->flags & CLKDM_CAN_FORCE_SLEEP)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 		pr_debug("clockdomain: %s does not support forcing sleep via software\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) 			 clkdm->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 	if (!arch_clkdm || !arch_clkdm->clkdm_sleep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 	pr_debug("clockdomain: forcing sleep on %s\n", clkdm->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 	clkdm->_flags &= ~_CLKDM_FLAG_HWSUP_ENABLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 	ret = arch_clkdm->clkdm_sleep(clkdm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 	ret |= pwrdm_state_switch_nolock(clkdm->pwrdm.ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860)  * clkdm_sleep - force clockdomain sleep transition
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861)  * @clkdm: struct clockdomain *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863)  * Instruct the CM to force a sleep transition on the specified
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864)  * clockdomain @clkdm.  Returns -EINVAL if @clkdm is NULL or if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865)  * clockdomain does not support software-initiated sleep; 0 upon
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866)  * success.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) int clkdm_sleep(struct clockdomain *clkdm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 	pwrdm_lock(clkdm->pwrdm.ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 	ret = clkdm_sleep_nolock(clkdm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 	pwrdm_unlock(clkdm->pwrdm.ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880)  * clkdm_wakeup_nolock - force clockdomain wakeup transition (lockless)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881)  * @clkdm: struct clockdomain *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883)  * Instruct the CM to force a wakeup transition on the specified
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884)  * clockdomain @clkdm.  Only for use by the powerdomain code.  Returns
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885)  * -EINVAL if @clkdm is NULL or if the clockdomain does not support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886)  * software-controlled wakeup; 0 upon success.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) int clkdm_wakeup_nolock(struct clockdomain *clkdm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 	if (!clkdm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 	if (!(clkdm->flags & CLKDM_CAN_FORCE_WAKEUP)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 		pr_debug("clockdomain: %s does not support forcing wakeup via software\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 			 clkdm->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 	if (!arch_clkdm || !arch_clkdm->clkdm_wakeup)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 	pr_debug("clockdomain: forcing wakeup on %s\n", clkdm->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 	clkdm->_flags &= ~_CLKDM_FLAG_HWSUP_ENABLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 	ret = arch_clkdm->clkdm_wakeup(clkdm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 	ret |= pwrdm_state_switch_nolock(clkdm->pwrdm.ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914)  * clkdm_wakeup - force clockdomain wakeup transition
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915)  * @clkdm: struct clockdomain *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917)  * Instruct the CM to force a wakeup transition on the specified
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918)  * clockdomain @clkdm.  Returns -EINVAL if @clkdm is NULL or if the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919)  * clockdomain does not support software-controlled wakeup; 0 upon
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920)  * success.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) int clkdm_wakeup(struct clockdomain *clkdm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 	pwrdm_lock(clkdm->pwrdm.ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 	ret = clkdm_wakeup_nolock(clkdm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 	pwrdm_unlock(clkdm->pwrdm.ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934)  * clkdm_allow_idle_nolock - enable hwsup idle transitions for clkdm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935)  * @clkdm: struct clockdomain *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937)  * Allow the hardware to automatically switch the clockdomain @clkdm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938)  * into active or idle states, as needed by downstream clocks.  If the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939)  * clockdomain has any downstream clocks enabled in the clock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940)  * framework, wkdep/sleepdep autodependencies are added; this is so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941)  * device drivers can read and write to the device.  Only for use by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942)  * the powerdomain code.  No return value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) void clkdm_allow_idle_nolock(struct clockdomain *clkdm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 	if (!clkdm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 	if (!WARN_ON(!clkdm->forcewake_count))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 		clkdm->forcewake_count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 	if (clkdm->forcewake_count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 	if (!clkdm->usecount && (clkdm->flags & CLKDM_CAN_FORCE_SLEEP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 		clkdm_sleep_nolock(clkdm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 	if (!(clkdm->flags & CLKDM_CAN_ENABLE_AUTO))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 	if (clkdm->flags & CLKDM_MISSING_IDLE_REPORTING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 	if (!arch_clkdm || !arch_clkdm->clkdm_allow_idle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 	pr_debug("clockdomain: enabling automatic idle transitions for %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 		 clkdm->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 	clkdm->_flags |= _CLKDM_FLAG_HWSUP_ENABLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 	arch_clkdm->clkdm_allow_idle(clkdm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 	pwrdm_state_switch_nolock(clkdm->pwrdm.ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976)  * clkdm_allow_idle - enable hwsup idle transitions for clkdm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977)  * @clkdm: struct clockdomain *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979)  * Allow the hardware to automatically switch the clockdomain @clkdm into
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980)  * active or idle states, as needed by downstream clocks.  If the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981)  * clockdomain has any downstream clocks enabled in the clock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982)  * framework, wkdep/sleepdep autodependencies are added; this is so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983)  * device drivers can read and write to the device.  No return value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) void clkdm_allow_idle(struct clockdomain *clkdm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 	pwrdm_lock(clkdm->pwrdm.ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 	clkdm_allow_idle_nolock(clkdm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 	pwrdm_unlock(clkdm->pwrdm.ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993)  * clkdm_deny_idle - disable hwsup idle transitions for clkdm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994)  * @clkdm: struct clockdomain *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996)  * Prevent the hardware from automatically switching the clockdomain
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997)  * @clkdm into inactive or idle states.  If the clockdomain has
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998)  * downstream clocks enabled in the clock framework, wkdep/sleepdep
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999)  * autodependencies are removed.  Only for use by the powerdomain
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000)  * code.  No return value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) void clkdm_deny_idle_nolock(struct clockdomain *clkdm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 	if (!clkdm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 	if (clkdm->forcewake_count++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 	if (clkdm->flags & CLKDM_CAN_FORCE_WAKEUP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 		clkdm_wakeup_nolock(clkdm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 	if (!(clkdm->flags & CLKDM_CAN_DISABLE_AUTO))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 	if (clkdm->flags & CLKDM_MISSING_IDLE_REPORTING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 	if (!arch_clkdm || !arch_clkdm->clkdm_deny_idle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 	pr_debug("clockdomain: disabling automatic idle transitions for %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 		 clkdm->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 	clkdm->_flags &= ~_CLKDM_FLAG_HWSUP_ENABLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) 	arch_clkdm->clkdm_deny_idle(clkdm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 	pwrdm_state_switch_nolock(clkdm->pwrdm.ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031)  * clkdm_deny_idle - disable hwsup idle transitions for clkdm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032)  * @clkdm: struct clockdomain *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034)  * Prevent the hardware from automatically switching the clockdomain
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035)  * @clkdm into inactive or idle states.  If the clockdomain has
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036)  * downstream clocks enabled in the clock framework, wkdep/sleepdep
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037)  * autodependencies are removed.  No return value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) void clkdm_deny_idle(struct clockdomain *clkdm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 	pwrdm_lock(clkdm->pwrdm.ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) 	clkdm_deny_idle_nolock(clkdm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 	pwrdm_unlock(clkdm->pwrdm.ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047)  * clkdm_in_hwsup - is clockdomain @clkdm have hardware-supervised idle enabled?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048)  * @clkdm: struct clockdomain *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050)  * Returns true if clockdomain @clkdm currently has
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051)  * hardware-supervised idle enabled, or false if it does not or if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052)  * @clkdm is NULL.  It is only valid to call this function after
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053)  * clkdm_init() has been called.  This function does not actually read
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054)  * bits from the hardware; it instead tests an in-memory flag that is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055)  * changed whenever the clockdomain code changes the auto-idle mode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) bool clkdm_in_hwsup(struct clockdomain *clkdm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 	bool ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 	if (!clkdm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 	ret = (clkdm->_flags & _CLKDM_FLAG_HWSUP_ENABLED) ? true : false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070)  * clkdm_missing_idle_reporting - can @clkdm enter autoidle even if in use?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071)  * @clkdm: struct clockdomain *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073)  * Returns true if clockdomain @clkdm has the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074)  * CLKDM_MISSING_IDLE_REPORTING flag set, or false if not or @clkdm is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075)  * null.  More information is available in the documentation for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076)  * CLKDM_MISSING_IDLE_REPORTING macro.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) bool clkdm_missing_idle_reporting(struct clockdomain *clkdm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) 	if (!clkdm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 	return (clkdm->flags & CLKDM_MISSING_IDLE_REPORTING) ? true : false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) /* Public autodep handling functions (deprecated) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089)  * clkdm_add_autodeps - add auto sleepdeps/wkdeps to clkdm upon clock enable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090)  * @clkdm: struct clockdomain *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092)  * Add the "autodep" sleep & wakeup dependencies to clockdomain 'clkdm'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093)  * in hardware-supervised mode.  Meant to be called from clock framework
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094)  * when a clock inside clockdomain 'clkdm' is enabled.	No return value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096)  * XXX autodeps are deprecated and should be removed at the earliest
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097)  * opportunity
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) void clkdm_add_autodeps(struct clockdomain *clkdm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) 	struct clkdm_autodep *autodep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 	if (!autodeps || clkdm->flags & CLKDM_NO_AUTODEPS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 	for (autodep = autodeps; autodep->clkdm.ptr; autodep++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 		if (IS_ERR(autodep->clkdm.ptr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 		pr_debug("clockdomain: %s: adding %s sleepdep/wkdep\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 			 clkdm->name, autodep->clkdm.ptr->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) 		_clkdm_add_sleepdep(clkdm, autodep->clkdm.ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 		_clkdm_add_wkdep(clkdm, autodep->clkdm.ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119)  * clkdm_del_autodeps - remove auto sleepdeps/wkdeps from clkdm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120)  * @clkdm: struct clockdomain *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122)  * Remove the "autodep" sleep & wakeup dependencies from clockdomain 'clkdm'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123)  * in hardware-supervised mode.  Meant to be called from clock framework
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124)  * when a clock inside clockdomain 'clkdm' is disabled.  No return value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126)  * XXX autodeps are deprecated and should be removed at the earliest
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127)  * opportunity
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) void clkdm_del_autodeps(struct clockdomain *clkdm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) 	struct clkdm_autodep *autodep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) 	if (!autodeps || clkdm->flags & CLKDM_NO_AUTODEPS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 	for (autodep = autodeps; autodep->clkdm.ptr; autodep++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) 		if (IS_ERR(autodep->clkdm.ptr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) 		pr_debug("clockdomain: %s: removing %s sleepdep/wkdep\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) 			 clkdm->name, autodep->clkdm.ptr->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) 		_clkdm_del_sleepdep(clkdm, autodep->clkdm.ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) 		_clkdm_del_wkdep(clkdm, autodep->clkdm.ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) /* Clockdomain-to-clock/hwmod framework interface code */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151)  * clkdm_clk_enable - add an enabled downstream clock to this clkdm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152)  * @clkdm: struct clockdomain *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153)  * @clk: struct clk * of the enabled downstream clock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155)  * Increment the usecount of the clockdomain @clkdm and ensure that it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156)  * is awake before @clk is enabled.  Intended to be called by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157)  * clk_enable() code.  If the clockdomain is in software-supervised
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158)  * idle mode, force the clockdomain to wake.  If the clockdomain is in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159)  * hardware-supervised idle mode, add clkdm-pwrdm autodependencies, to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160)  * ensure that devices in the clockdomain can be read from/written to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161)  * by on-chip processors.  Returns -EINVAL if passed null pointers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162)  * returns 0 upon success or if the clockdomain is in hwsup idle mode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) int clkdm_clk_enable(struct clockdomain *clkdm, struct clk *unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) 	if (!clkdm || !arch_clkdm || !arch_clkdm->clkdm_clk_enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) 	pwrdm_lock(clkdm->pwrdm.ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) 	 * For arch's with no autodeps, clkcm_clk_enable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) 	 * should be called for every clock instance or hwmod that is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) 	 * enabled, so the clkdm can be force woken up.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) 	clkdm->usecount++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) 	if (clkdm->usecount > 1 && autodeps) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) 		pwrdm_unlock(clkdm->pwrdm.ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) 	arch_clkdm->clkdm_clk_enable(clkdm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) 	pwrdm_state_switch_nolock(clkdm->pwrdm.ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) 	pwrdm_unlock(clkdm->pwrdm.ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) 	pr_debug("clockdomain: %s: enabled\n", clkdm->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192)  * clkdm_clk_disable - remove an enabled downstream clock from this clkdm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193)  * @clkdm: struct clockdomain *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194)  * @clk: struct clk * of the disabled downstream clock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196)  * Decrement the usecount of this clockdomain @clkdm when @clk is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197)  * disabled.  Intended to be called by clk_disable() code.  If the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198)  * clockdomain usecount goes to 0, put the clockdomain to sleep
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199)  * (software-supervised mode) or remove the clkdm autodependencies
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200)  * (hardware-supervised mode).  Returns -EINVAL if passed null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201)  * pointers; -ERANGE if the @clkdm usecount underflows; or returns 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202)  * upon success or if the clockdomain is in hwsup idle mode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) int clkdm_clk_disable(struct clockdomain *clkdm, struct clk *clk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) 	if (!clkdm || !arch_clkdm || !arch_clkdm->clkdm_clk_disable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) 	pwrdm_lock(clkdm->pwrdm.ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) 	/* corner case: disabling unused clocks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) 	if (clk && (__clk_get_enable_count(clk) == 0) && clkdm->usecount == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) 		goto ccd_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) 	if (clkdm->usecount == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) 		pwrdm_unlock(clkdm->pwrdm.ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) 		WARN_ON(1); /* underflow */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) 		return -ERANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) 	clkdm->usecount--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) 	if (clkdm->usecount > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) 		pwrdm_unlock(clkdm->pwrdm.ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) 	arch_clkdm->clkdm_clk_disable(clkdm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) 	pwrdm_state_switch_nolock(clkdm->pwrdm.ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) 	pr_debug("clockdomain: %s: disabled\n", clkdm->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) ccd_exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) 	pwrdm_unlock(clkdm->pwrdm.ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239)  * clkdm_hwmod_enable - add an enabled downstream hwmod to this clkdm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240)  * @clkdm: struct clockdomain *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241)  * @oh: struct omap_hwmod * of the enabled downstream hwmod
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243)  * Increment the usecount of the clockdomain @clkdm and ensure that it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244)  * is awake before @oh is enabled. Intended to be called by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245)  * module_enable() code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246)  * If the clockdomain is in software-supervised idle mode, force the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247)  * clockdomain to wake.  If the clockdomain is in hardware-supervised idle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248)  * mode, add clkdm-pwrdm autodependencies, to ensure that devices in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249)  * clockdomain can be read from/written to by on-chip processors.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250)  * Returns -EINVAL if passed null pointers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251)  * returns 0 upon success or if the clockdomain is in hwsup idle mode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) int clkdm_hwmod_enable(struct clockdomain *clkdm, struct omap_hwmod *oh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) 	/* The clkdm attribute does not exist yet prior OMAP4 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) 	if (cpu_is_omap24xx() || cpu_is_omap34xx())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) 	 * XXX Rewrite this code to maintain a list of enabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) 	 * downstream hwmods for debugging purposes?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) 	if (!oh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) 	return clkdm_clk_enable(clkdm, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271)  * clkdm_hwmod_disable - remove an enabled downstream hwmod from this clkdm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272)  * @clkdm: struct clockdomain *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273)  * @oh: struct omap_hwmod * of the disabled downstream hwmod
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275)  * Decrement the usecount of this clockdomain @clkdm when @oh is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276)  * disabled. Intended to be called by module_disable() code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277)  * If the clockdomain usecount goes to 0, put the clockdomain to sleep
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278)  * (software-supervised mode) or remove the clkdm autodependencies
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279)  * (hardware-supervised mode).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280)  * Returns -EINVAL if passed null pointers; -ERANGE if the @clkdm usecount
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281)  * underflows; or returns 0 upon success or if the clockdomain is in hwsup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282)  * idle mode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) int clkdm_hwmod_disable(struct clockdomain *clkdm, struct omap_hwmod *oh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) 	/* The clkdm attribute does not exist yet prior OMAP4 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) 	if (cpu_is_omap24xx() || cpu_is_omap34xx())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) 	if (!oh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) 	return clkdm_clk_disable(clkdm, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297)  * _clkdm_save_context - save the context for the control of this clkdm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299)  * Due to a suspend or hibernation operation, the state of the registers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300)  * controlling this clkdm will be lost, save their context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) static int _clkdm_save_context(struct clockdomain *clkdm, void *ununsed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) 	if (!arch_clkdm || !arch_clkdm->clkdm_save_context)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) 	return arch_clkdm->clkdm_save_context(clkdm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311)  * _clkdm_restore_context - restore context for control of this clkdm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313)  * Restore the register values for this clockdomain.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) static int _clkdm_restore_context(struct clockdomain *clkdm, void *ununsed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) 	if (!arch_clkdm || !arch_clkdm->clkdm_restore_context)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) 	return arch_clkdm->clkdm_restore_context(clkdm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324)  * clkdm_save_context - Saves the context for each registered clkdm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326)  * Save the context for each registered clockdomain.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) void clkdm_save_context(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) 	clkdm_for_each(_clkdm_save_context, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334)  * clkdm_restore_context - Restores the context for each registered clkdm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336)  * Restore the context for each registered clockdomain.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) void clkdm_restore_context(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) 	clkdm_for_each(_clkdm_restore_context, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) }