162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * OMAP2/3 clockdomain framework functions 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci * Copyright (C) 2008, 2012 Texas Instruments, Inc. 662306a36Sopenharmony_ci * Copyright (C) 2008-2011 Nokia Corporation 762306a36Sopenharmony_ci * 862306a36Sopenharmony_ci * Paul Walmsley 962306a36Sopenharmony_ci */ 1062306a36Sopenharmony_ci 1162306a36Sopenharmony_ci#ifndef __ARCH_ARM_MACH_OMAP2_CLOCKDOMAIN_H 1262306a36Sopenharmony_ci#define __ARCH_ARM_MACH_OMAP2_CLOCKDOMAIN_H 1362306a36Sopenharmony_ci 1462306a36Sopenharmony_ci#include <linux/init.h> 1562306a36Sopenharmony_ci 1662306a36Sopenharmony_ci#include "powerdomain.h" 1762306a36Sopenharmony_ci#include "clock.h" 1862306a36Sopenharmony_ci 1962306a36Sopenharmony_ci/* 2062306a36Sopenharmony_ci * Clockdomain flags 2162306a36Sopenharmony_ci * 2262306a36Sopenharmony_ci * XXX Document CLKDM_CAN_* flags 2362306a36Sopenharmony_ci * 2462306a36Sopenharmony_ci * CLKDM_NO_AUTODEPS: Prevent "autodeps" from being added/removed from this 2562306a36Sopenharmony_ci * clockdomain. (Currently, this applies to OMAP3 clockdomains only.) 2662306a36Sopenharmony_ci * CLKDM_ACTIVE_WITH_MPU: The PRCM guarantees that this clockdomain is 2762306a36Sopenharmony_ci * active whenever the MPU is active. True for interconnects and 2862306a36Sopenharmony_ci * the WKUP clockdomains. 2962306a36Sopenharmony_ci * CLKDM_MISSING_IDLE_REPORTING: The idle status of the IP blocks and 3062306a36Sopenharmony_ci * clocks inside this clockdomain are not taken into account by 3162306a36Sopenharmony_ci * the PRCM when determining whether the clockdomain is idle. 3262306a36Sopenharmony_ci * Without this flag, if the clockdomain is set to 3362306a36Sopenharmony_ci * hardware-supervised idle mode, the PRCM may transition the 3462306a36Sopenharmony_ci * enclosing powerdomain to a low power state, even when devices 3562306a36Sopenharmony_ci * inside the clockdomain and powerdomain are in use. (An example 3662306a36Sopenharmony_ci * of such a clockdomain is the EMU clockdomain on OMAP3/4.) If 3762306a36Sopenharmony_ci * this flag is set, and the clockdomain does not support the 3862306a36Sopenharmony_ci * force-sleep mode, then the HW_AUTO mode will be used to put the 3962306a36Sopenharmony_ci * clockdomain to sleep. Similarly, if the clockdomain supports 4062306a36Sopenharmony_ci * the force-wakeup mode, then it will be used whenever a clock or 4162306a36Sopenharmony_ci * IP block inside the clockdomain is active, rather than the 4262306a36Sopenharmony_ci * HW_AUTO mode. 4362306a36Sopenharmony_ci */ 4462306a36Sopenharmony_ci#define CLKDM_CAN_FORCE_SLEEP (1 << 0) 4562306a36Sopenharmony_ci#define CLKDM_CAN_FORCE_WAKEUP (1 << 1) 4662306a36Sopenharmony_ci#define CLKDM_CAN_ENABLE_AUTO (1 << 2) 4762306a36Sopenharmony_ci#define CLKDM_CAN_DISABLE_AUTO (1 << 3) 4862306a36Sopenharmony_ci#define CLKDM_NO_AUTODEPS (1 << 4) 4962306a36Sopenharmony_ci#define CLKDM_ACTIVE_WITH_MPU (1 << 5) 5062306a36Sopenharmony_ci#define CLKDM_MISSING_IDLE_REPORTING (1 << 6) 5162306a36Sopenharmony_ci 5262306a36Sopenharmony_ci#define CLKDM_CAN_HWSUP (CLKDM_CAN_ENABLE_AUTO | CLKDM_CAN_DISABLE_AUTO) 5362306a36Sopenharmony_ci#define CLKDM_CAN_SWSUP (CLKDM_CAN_FORCE_SLEEP | CLKDM_CAN_FORCE_WAKEUP) 5462306a36Sopenharmony_ci#define CLKDM_CAN_HWSUP_SWSUP (CLKDM_CAN_SWSUP | CLKDM_CAN_HWSUP) 5562306a36Sopenharmony_ci 5662306a36Sopenharmony_ci/** 5762306a36Sopenharmony_ci * struct clkdm_autodep - clkdm deps to add when entering/exiting hwsup mode 5862306a36Sopenharmony_ci * @clkdm: clockdomain to add wkdep+sleepdep on - set name member only 5962306a36Sopenharmony_ci * 6062306a36Sopenharmony_ci * A clockdomain that should have wkdeps and sleepdeps added when a 6162306a36Sopenharmony_ci * clockdomain should stay active in hwsup mode; and conversely, 6262306a36Sopenharmony_ci * removed when the clockdomain should be allowed to go inactive in 6362306a36Sopenharmony_ci * hwsup mode. 6462306a36Sopenharmony_ci * 6562306a36Sopenharmony_ci * Autodeps are deprecated and should be removed after 6662306a36Sopenharmony_ci * omap_hwmod-based fine-grained module idle control is added. 6762306a36Sopenharmony_ci */ 6862306a36Sopenharmony_cistruct clkdm_autodep { 6962306a36Sopenharmony_ci union { 7062306a36Sopenharmony_ci const char *name; 7162306a36Sopenharmony_ci struct clockdomain *ptr; 7262306a36Sopenharmony_ci } clkdm; 7362306a36Sopenharmony_ci}; 7462306a36Sopenharmony_ci 7562306a36Sopenharmony_ci/** 7662306a36Sopenharmony_ci * struct clkdm_dep - encode dependencies between clockdomains 7762306a36Sopenharmony_ci * @clkdm_name: clockdomain name 7862306a36Sopenharmony_ci * @clkdm: pointer to the struct clockdomain of @clkdm_name 7962306a36Sopenharmony_ci * @wkdep_usecount: Number of wakeup dependencies causing this clkdm to wake 8062306a36Sopenharmony_ci * @sleepdep_usecount: Number of sleep deps that could prevent clkdm from idle 8162306a36Sopenharmony_ci * 8262306a36Sopenharmony_ci * Statically defined. @clkdm is resolved from @clkdm_name at runtime and 8362306a36Sopenharmony_ci * should not be pre-initialized. 8462306a36Sopenharmony_ci * 8562306a36Sopenharmony_ci * XXX Should also include hardware (fixed) dependencies. 8662306a36Sopenharmony_ci */ 8762306a36Sopenharmony_cistruct clkdm_dep { 8862306a36Sopenharmony_ci const char *clkdm_name; 8962306a36Sopenharmony_ci struct clockdomain *clkdm; 9062306a36Sopenharmony_ci s16 wkdep_usecount; 9162306a36Sopenharmony_ci s16 sleepdep_usecount; 9262306a36Sopenharmony_ci}; 9362306a36Sopenharmony_ci 9462306a36Sopenharmony_ci/* Possible flags for struct clockdomain._flags */ 9562306a36Sopenharmony_ci#define _CLKDM_FLAG_HWSUP_ENABLED BIT(0) 9662306a36Sopenharmony_ci 9762306a36Sopenharmony_cistruct omap_hwmod; 9862306a36Sopenharmony_ci 9962306a36Sopenharmony_ci/** 10062306a36Sopenharmony_ci * struct clockdomain - OMAP clockdomain 10162306a36Sopenharmony_ci * @name: clockdomain name 10262306a36Sopenharmony_ci * @pwrdm: powerdomain containing this clockdomain 10362306a36Sopenharmony_ci * @clktrctrl_reg: CLKSTCTRL reg for the given clock domain 10462306a36Sopenharmony_ci * @clktrctrl_mask: CLKTRCTRL/AUTOSTATE field mask in CM_CLKSTCTRL reg 10562306a36Sopenharmony_ci * @flags: Clockdomain capability flags 10662306a36Sopenharmony_ci * @_flags: Flags for use only by internal clockdomain code 10762306a36Sopenharmony_ci * @dep_bit: Bit shift of this clockdomain's PM_WKDEP/CM_SLEEPDEP bit 10862306a36Sopenharmony_ci * @prcm_partition: (OMAP4 only) PRCM partition ID for this clkdm's registers 10962306a36Sopenharmony_ci * @cm_inst: (OMAP4 only) CM instance register offset 11062306a36Sopenharmony_ci * @clkdm_offs: (OMAP4 only) CM clockdomain register offset 11162306a36Sopenharmony_ci * @wkdep_srcs: Clockdomains that can be told to wake this powerdomain up 11262306a36Sopenharmony_ci * @sleepdep_srcs: Clockdomains that can be told to keep this clkdm from inact 11362306a36Sopenharmony_ci * @usecount: Usecount tracking 11462306a36Sopenharmony_ci * @forcewake_count: Usecount for forcing the domain active 11562306a36Sopenharmony_ci * @node: list_head to link all clockdomains together 11662306a36Sopenharmony_ci * 11762306a36Sopenharmony_ci * @prcm_partition should be a macro from mach-omap2/prcm44xx.h (OMAP4 only) 11862306a36Sopenharmony_ci * @cm_inst should be a macro ending in _INST from the OMAP4 CM instance 11962306a36Sopenharmony_ci * definitions (OMAP4 only) 12062306a36Sopenharmony_ci * @clkdm_offs should be a macro ending in _CDOFFS from the OMAP4 CM instance 12162306a36Sopenharmony_ci * definitions (OMAP4 only) 12262306a36Sopenharmony_ci */ 12362306a36Sopenharmony_cistruct clockdomain { 12462306a36Sopenharmony_ci const char *name; 12562306a36Sopenharmony_ci union { 12662306a36Sopenharmony_ci const char *name; 12762306a36Sopenharmony_ci struct powerdomain *ptr; 12862306a36Sopenharmony_ci } pwrdm; 12962306a36Sopenharmony_ci const u16 clktrctrl_mask; 13062306a36Sopenharmony_ci const u8 flags; 13162306a36Sopenharmony_ci u8 _flags; 13262306a36Sopenharmony_ci const u8 dep_bit; 13362306a36Sopenharmony_ci const u8 prcm_partition; 13462306a36Sopenharmony_ci const u16 cm_inst; 13562306a36Sopenharmony_ci const u16 clkdm_offs; 13662306a36Sopenharmony_ci struct clkdm_dep *wkdep_srcs; 13762306a36Sopenharmony_ci struct clkdm_dep *sleepdep_srcs; 13862306a36Sopenharmony_ci int usecount; 13962306a36Sopenharmony_ci int forcewake_count; 14062306a36Sopenharmony_ci struct list_head node; 14162306a36Sopenharmony_ci u32 context; 14262306a36Sopenharmony_ci}; 14362306a36Sopenharmony_ci 14462306a36Sopenharmony_ci/** 14562306a36Sopenharmony_ci * struct clkdm_ops - Arch specific function implementations 14662306a36Sopenharmony_ci * @clkdm_add_wkdep: Add a wakeup dependency between clk domains 14762306a36Sopenharmony_ci * @clkdm_del_wkdep: Delete a wakeup dependency between clk domains 14862306a36Sopenharmony_ci * @clkdm_read_wkdep: Read wakeup dependency state between clk domains 14962306a36Sopenharmony_ci * @clkdm_clear_all_wkdeps: Remove all wakeup dependencies from the clk domain 15062306a36Sopenharmony_ci * @clkdm_add_sleepdep: Add a sleep dependency between clk domains 15162306a36Sopenharmony_ci * @clkdm_del_sleepdep: Delete a sleep dependency between clk domains 15262306a36Sopenharmony_ci * @clkdm_read_sleepdep: Read sleep dependency state between clk domains 15362306a36Sopenharmony_ci * @clkdm_clear_all_sleepdeps: Remove all sleep dependencies from the clk domain 15462306a36Sopenharmony_ci * @clkdm_sleep: Force a clockdomain to sleep 15562306a36Sopenharmony_ci * @clkdm_wakeup: Force a clockdomain to wakeup 15662306a36Sopenharmony_ci * @clkdm_allow_idle: Enable hw supervised idle transitions for clock domain 15762306a36Sopenharmony_ci * @clkdm_deny_idle: Disable hw supervised idle transitions for clock domain 15862306a36Sopenharmony_ci * @clkdm_clk_enable: Put the clkdm in right state for a clock enable 15962306a36Sopenharmony_ci * @clkdm_clk_disable: Put the clkdm in right state for a clock disable 16062306a36Sopenharmony_ci * @clkdm_save_context: Save the current clkdm context 16162306a36Sopenharmony_ci * @clkdm_restore_context: Restore the clkdm context 16262306a36Sopenharmony_ci */ 16362306a36Sopenharmony_cistruct clkdm_ops { 16462306a36Sopenharmony_ci int (*clkdm_add_wkdep)(struct clockdomain *clkdm1, struct clockdomain *clkdm2); 16562306a36Sopenharmony_ci int (*clkdm_del_wkdep)(struct clockdomain *clkdm1, struct clockdomain *clkdm2); 16662306a36Sopenharmony_ci int (*clkdm_read_wkdep)(struct clockdomain *clkdm1, struct clockdomain *clkdm2); 16762306a36Sopenharmony_ci int (*clkdm_clear_all_wkdeps)(struct clockdomain *clkdm); 16862306a36Sopenharmony_ci int (*clkdm_add_sleepdep)(struct clockdomain *clkdm1, struct clockdomain *clkdm2); 16962306a36Sopenharmony_ci int (*clkdm_del_sleepdep)(struct clockdomain *clkdm1, struct clockdomain *clkdm2); 17062306a36Sopenharmony_ci int (*clkdm_read_sleepdep)(struct clockdomain *clkdm1, struct clockdomain *clkdm2); 17162306a36Sopenharmony_ci int (*clkdm_clear_all_sleepdeps)(struct clockdomain *clkdm); 17262306a36Sopenharmony_ci int (*clkdm_sleep)(struct clockdomain *clkdm); 17362306a36Sopenharmony_ci int (*clkdm_wakeup)(struct clockdomain *clkdm); 17462306a36Sopenharmony_ci void (*clkdm_allow_idle)(struct clockdomain *clkdm); 17562306a36Sopenharmony_ci void (*clkdm_deny_idle)(struct clockdomain *clkdm); 17662306a36Sopenharmony_ci int (*clkdm_clk_enable)(struct clockdomain *clkdm); 17762306a36Sopenharmony_ci int (*clkdm_clk_disable)(struct clockdomain *clkdm); 17862306a36Sopenharmony_ci int (*clkdm_save_context)(struct clockdomain *clkdm); 17962306a36Sopenharmony_ci int (*clkdm_restore_context)(struct clockdomain *clkdm); 18062306a36Sopenharmony_ci}; 18162306a36Sopenharmony_ci 18262306a36Sopenharmony_ciint clkdm_register_platform_funcs(struct clkdm_ops *co); 18362306a36Sopenharmony_ciint clkdm_register_autodeps(struct clkdm_autodep *ia); 18462306a36Sopenharmony_ciint clkdm_register_clkdms(struct clockdomain **c); 18562306a36Sopenharmony_ciint clkdm_complete_init(void); 18662306a36Sopenharmony_ci 18762306a36Sopenharmony_cistruct clockdomain *clkdm_lookup(const char *name); 18862306a36Sopenharmony_ci 18962306a36Sopenharmony_ciint clkdm_for_each(int (*fn)(struct clockdomain *clkdm, void *user), 19062306a36Sopenharmony_ci void *user); 19162306a36Sopenharmony_cistruct powerdomain *clkdm_get_pwrdm(struct clockdomain *clkdm); 19262306a36Sopenharmony_ci 19362306a36Sopenharmony_ciint clkdm_add_wkdep(struct clockdomain *clkdm1, struct clockdomain *clkdm2); 19462306a36Sopenharmony_ciint clkdm_del_wkdep(struct clockdomain *clkdm1, struct clockdomain *clkdm2); 19562306a36Sopenharmony_ciint clkdm_read_wkdep(struct clockdomain *clkdm1, struct clockdomain *clkdm2); 19662306a36Sopenharmony_ciint clkdm_clear_all_wkdeps(struct clockdomain *clkdm); 19762306a36Sopenharmony_ciint clkdm_add_sleepdep(struct clockdomain *clkdm1, struct clockdomain *clkdm2); 19862306a36Sopenharmony_ciint clkdm_del_sleepdep(struct clockdomain *clkdm1, struct clockdomain *clkdm2); 19962306a36Sopenharmony_ciint clkdm_read_sleepdep(struct clockdomain *clkdm1, struct clockdomain *clkdm2); 20062306a36Sopenharmony_ciint clkdm_clear_all_sleepdeps(struct clockdomain *clkdm); 20162306a36Sopenharmony_ci 20262306a36Sopenharmony_civoid clkdm_allow_idle_nolock(struct clockdomain *clkdm); 20362306a36Sopenharmony_civoid clkdm_allow_idle(struct clockdomain *clkdm); 20462306a36Sopenharmony_civoid clkdm_deny_idle_nolock(struct clockdomain *clkdm); 20562306a36Sopenharmony_civoid clkdm_deny_idle(struct clockdomain *clkdm); 20662306a36Sopenharmony_ci 20762306a36Sopenharmony_ciint clkdm_wakeup(struct clockdomain *clkdm); 20862306a36Sopenharmony_ciint clkdm_sleep(struct clockdomain *clkdm); 20962306a36Sopenharmony_ci 21062306a36Sopenharmony_ciint clkdm_clk_enable(struct clockdomain *clkdm, struct clk *clk); 21162306a36Sopenharmony_ciint clkdm_clk_disable(struct clockdomain *clkdm, struct clk *clk); 21262306a36Sopenharmony_ciint clkdm_hwmod_enable(struct clockdomain *clkdm, struct omap_hwmod *oh); 21362306a36Sopenharmony_ciint clkdm_hwmod_disable(struct clockdomain *clkdm, struct omap_hwmod *oh); 21462306a36Sopenharmony_ci 21562306a36Sopenharmony_civoid clkdm_save_context(void); 21662306a36Sopenharmony_civoid clkdm_restore_context(void); 21762306a36Sopenharmony_ci 21862306a36Sopenharmony_ciextern void __init omap242x_clockdomains_init(void); 21962306a36Sopenharmony_ciextern void __init omap243x_clockdomains_init(void); 22062306a36Sopenharmony_ciextern void __init omap3xxx_clockdomains_init(void); 22162306a36Sopenharmony_ciextern void __init am33xx_clockdomains_init(void); 22262306a36Sopenharmony_ciextern void __init ti814x_clockdomains_init(void); 22362306a36Sopenharmony_ciextern void __init ti816x_clockdomains_init(void); 22462306a36Sopenharmony_ciextern void __init omap44xx_clockdomains_init(void); 22562306a36Sopenharmony_ciextern void __init omap54xx_clockdomains_init(void); 22662306a36Sopenharmony_ciextern void __init dra7xx_clockdomains_init(void); 22762306a36Sopenharmony_civoid am43xx_clockdomains_init(void); 22862306a36Sopenharmony_ci 22962306a36Sopenharmony_ciextern void clkdm_add_autodeps(struct clockdomain *clkdm); 23062306a36Sopenharmony_ciextern void clkdm_del_autodeps(struct clockdomain *clkdm); 23162306a36Sopenharmony_ci 23262306a36Sopenharmony_ciextern struct clkdm_ops omap2_clkdm_operations; 23362306a36Sopenharmony_ciextern struct clkdm_ops omap3_clkdm_operations; 23462306a36Sopenharmony_ciextern struct clkdm_ops omap4_clkdm_operations; 23562306a36Sopenharmony_ciextern struct clkdm_ops am33xx_clkdm_operations; 23662306a36Sopenharmony_ciextern struct clkdm_ops am43xx_clkdm_operations; 23762306a36Sopenharmony_ci 23862306a36Sopenharmony_ciextern struct clkdm_dep gfx_24xx_wkdeps[]; 23962306a36Sopenharmony_ciextern struct clkdm_dep dsp_24xx_wkdeps[]; 24062306a36Sopenharmony_ciextern struct clockdomain wkup_common_clkdm; 24162306a36Sopenharmony_ci 24262306a36Sopenharmony_ci#endif 243