Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * OMAP2/3 clockdomain framework functions
0004  *
0005  * Copyright (C) 2008, 2012 Texas Instruments, Inc.
0006  * Copyright (C) 2008-2011 Nokia Corporation
0007  *
0008  * Paul Walmsley
0009  */
0010 
0011 #ifndef __ARCH_ARM_MACH_OMAP2_CLOCKDOMAIN_H
0012 #define __ARCH_ARM_MACH_OMAP2_CLOCKDOMAIN_H
0013 
0014 #include <linux/init.h>
0015 
0016 #include "powerdomain.h"
0017 #include "clock.h"
0018 
0019 /*
0020  * Clockdomain flags
0021  *
0022  * XXX Document CLKDM_CAN_* flags
0023  *
0024  * CLKDM_NO_AUTODEPS: Prevent "autodeps" from being added/removed from this
0025  *     clockdomain.  (Currently, this applies to OMAP3 clockdomains only.)
0026  * CLKDM_ACTIVE_WITH_MPU: The PRCM guarantees that this clockdomain is
0027  *     active whenever the MPU is active.  True for interconnects and
0028  *     the WKUP clockdomains.
0029  * CLKDM_MISSING_IDLE_REPORTING: The idle status of the IP blocks and
0030  *     clocks inside this clockdomain are not taken into account by
0031  *     the PRCM when determining whether the clockdomain is idle.
0032  *     Without this flag, if the clockdomain is set to
0033  *     hardware-supervised idle mode, the PRCM may transition the
0034  *     enclosing powerdomain to a low power state, even when devices
0035  *     inside the clockdomain and powerdomain are in use.  (An example
0036  *     of such a clockdomain is the EMU clockdomain on OMAP3/4.)  If
0037  *     this flag is set, and the clockdomain does not support the
0038  *     force-sleep mode, then the HW_AUTO mode will be used to put the
0039  *     clockdomain to sleep.  Similarly, if the clockdomain supports
0040  *     the force-wakeup mode, then it will be used whenever a clock or
0041  *     IP block inside the clockdomain is active, rather than the
0042  *     HW_AUTO mode.
0043  */
0044 #define CLKDM_CAN_FORCE_SLEEP           (1 << 0)
0045 #define CLKDM_CAN_FORCE_WAKEUP          (1 << 1)
0046 #define CLKDM_CAN_ENABLE_AUTO           (1 << 2)
0047 #define CLKDM_CAN_DISABLE_AUTO          (1 << 3)
0048 #define CLKDM_NO_AUTODEPS           (1 << 4)
0049 #define CLKDM_ACTIVE_WITH_MPU           (1 << 5)
0050 #define CLKDM_MISSING_IDLE_REPORTING        (1 << 6)
0051 
0052 #define CLKDM_CAN_HWSUP     (CLKDM_CAN_ENABLE_AUTO | CLKDM_CAN_DISABLE_AUTO)
0053 #define CLKDM_CAN_SWSUP     (CLKDM_CAN_FORCE_SLEEP | CLKDM_CAN_FORCE_WAKEUP)
0054 #define CLKDM_CAN_HWSUP_SWSUP   (CLKDM_CAN_SWSUP | CLKDM_CAN_HWSUP)
0055 
0056 /**
0057  * struct clkdm_autodep - clkdm deps to add when entering/exiting hwsup mode
0058  * @clkdm: clockdomain to add wkdep+sleepdep on - set name member only
0059  *
0060  * A clockdomain that should have wkdeps and sleepdeps added when a
0061  * clockdomain should stay active in hwsup mode; and conversely,
0062  * removed when the clockdomain should be allowed to go inactive in
0063  * hwsup mode.
0064  *
0065  * Autodeps are deprecated and should be removed after
0066  * omap_hwmod-based fine-grained module idle control is added.
0067  */
0068 struct clkdm_autodep {
0069     union {
0070         const char *name;
0071         struct clockdomain *ptr;
0072     } clkdm;
0073 };
0074 
0075 /**
0076  * struct clkdm_dep - encode dependencies between clockdomains
0077  * @clkdm_name: clockdomain name
0078  * @clkdm: pointer to the struct clockdomain of @clkdm_name
0079  * @wkdep_usecount: Number of wakeup dependencies causing this clkdm to wake
0080  * @sleepdep_usecount: Number of sleep deps that could prevent clkdm from idle
0081  *
0082  * Statically defined.  @clkdm is resolved from @clkdm_name at runtime and
0083  * should not be pre-initialized.
0084  *
0085  * XXX Should also include hardware (fixed) dependencies.
0086  */
0087 struct clkdm_dep {
0088     const char *clkdm_name;
0089     struct clockdomain *clkdm;
0090     s16 wkdep_usecount;
0091     s16 sleepdep_usecount;
0092 };
0093 
0094 /* Possible flags for struct clockdomain._flags */
0095 #define _CLKDM_FLAG_HWSUP_ENABLED       BIT(0)
0096 
0097 struct omap_hwmod;
0098 
0099 /**
0100  * struct clockdomain - OMAP clockdomain
0101  * @name: clockdomain name
0102  * @pwrdm: powerdomain containing this clockdomain
0103  * @clktrctrl_reg: CLKSTCTRL reg for the given clock domain
0104  * @clktrctrl_mask: CLKTRCTRL/AUTOSTATE field mask in CM_CLKSTCTRL reg
0105  * @flags: Clockdomain capability flags
0106  * @_flags: Flags for use only by internal clockdomain code
0107  * @dep_bit: Bit shift of this clockdomain's PM_WKDEP/CM_SLEEPDEP bit
0108  * @prcm_partition: (OMAP4 only) PRCM partition ID for this clkdm's registers
0109  * @cm_inst: (OMAP4 only) CM instance register offset
0110  * @clkdm_offs: (OMAP4 only) CM clockdomain register offset
0111  * @wkdep_srcs: Clockdomains that can be told to wake this powerdomain up
0112  * @sleepdep_srcs: Clockdomains that can be told to keep this clkdm from inact
0113  * @usecount: Usecount tracking
0114  * @forcewake_count: Usecount for forcing the domain active
0115  * @node: list_head to link all clockdomains together
0116  *
0117  * @prcm_partition should be a macro from mach-omap2/prcm44xx.h (OMAP4 only)
0118  * @cm_inst should be a macro ending in _INST from the OMAP4 CM instance
0119  *     definitions (OMAP4 only)
0120  * @clkdm_offs should be a macro ending in _CDOFFS from the OMAP4 CM instance
0121  *     definitions (OMAP4 only)
0122  */
0123 struct clockdomain {
0124     const char *name;
0125     union {
0126         const char *name;
0127         struct powerdomain *ptr;
0128     } pwrdm;
0129     const u16 clktrctrl_mask;
0130     const u8 flags;
0131     u8 _flags;
0132     const u8 dep_bit;
0133     const u8 prcm_partition;
0134     const u16 cm_inst;
0135     const u16 clkdm_offs;
0136     struct clkdm_dep *wkdep_srcs;
0137     struct clkdm_dep *sleepdep_srcs;
0138     int usecount;
0139     int forcewake_count;
0140     struct list_head node;
0141     u32 context;
0142 };
0143 
0144 /**
0145  * struct clkdm_ops - Arch specific function implementations
0146  * @clkdm_add_wkdep: Add a wakeup dependency between clk domains
0147  * @clkdm_del_wkdep: Delete a wakeup dependency between clk domains
0148  * @clkdm_read_wkdep: Read wakeup dependency state between clk domains
0149  * @clkdm_clear_all_wkdeps: Remove all wakeup dependencies from the clk domain
0150  * @clkdm_add_sleepdep: Add a sleep dependency between clk domains
0151  * @clkdm_del_sleepdep: Delete a sleep dependency between clk domains
0152  * @clkdm_read_sleepdep: Read sleep dependency state between clk domains
0153  * @clkdm_clear_all_sleepdeps: Remove all sleep dependencies from the clk domain
0154  * @clkdm_sleep: Force a clockdomain to sleep
0155  * @clkdm_wakeup: Force a clockdomain to wakeup
0156  * @clkdm_allow_idle: Enable hw supervised idle transitions for clock domain
0157  * @clkdm_deny_idle: Disable hw supervised idle transitions for clock domain
0158  * @clkdm_clk_enable: Put the clkdm in right state for a clock enable
0159  * @clkdm_clk_disable: Put the clkdm in right state for a clock disable
0160  * @clkdm_save_context: Save the current clkdm context
0161  * @clkdm_restore_context: Restore the clkdm context
0162  */
0163 struct clkdm_ops {
0164     int (*clkdm_add_wkdep)(struct clockdomain *clkdm1, struct clockdomain *clkdm2);
0165     int (*clkdm_del_wkdep)(struct clockdomain *clkdm1, struct clockdomain *clkdm2);
0166     int (*clkdm_read_wkdep)(struct clockdomain *clkdm1, struct clockdomain *clkdm2);
0167     int (*clkdm_clear_all_wkdeps)(struct clockdomain *clkdm);
0168     int (*clkdm_add_sleepdep)(struct clockdomain *clkdm1, struct clockdomain *clkdm2);
0169     int (*clkdm_del_sleepdep)(struct clockdomain *clkdm1, struct clockdomain *clkdm2);
0170     int (*clkdm_read_sleepdep)(struct clockdomain *clkdm1, struct clockdomain *clkdm2);
0171     int (*clkdm_clear_all_sleepdeps)(struct clockdomain *clkdm);
0172     int (*clkdm_sleep)(struct clockdomain *clkdm);
0173     int (*clkdm_wakeup)(struct clockdomain *clkdm);
0174     void    (*clkdm_allow_idle)(struct clockdomain *clkdm);
0175     void    (*clkdm_deny_idle)(struct clockdomain *clkdm);
0176     int (*clkdm_clk_enable)(struct clockdomain *clkdm);
0177     int (*clkdm_clk_disable)(struct clockdomain *clkdm);
0178     int (*clkdm_save_context)(struct clockdomain *clkdm);
0179     int (*clkdm_restore_context)(struct clockdomain *clkdm);
0180 };
0181 
0182 int clkdm_register_platform_funcs(struct clkdm_ops *co);
0183 int clkdm_register_autodeps(struct clkdm_autodep *ia);
0184 int clkdm_register_clkdms(struct clockdomain **c);
0185 int clkdm_complete_init(void);
0186 
0187 struct clockdomain *clkdm_lookup(const char *name);
0188 
0189 int clkdm_for_each(int (*fn)(struct clockdomain *clkdm, void *user),
0190             void *user);
0191 struct powerdomain *clkdm_get_pwrdm(struct clockdomain *clkdm);
0192 
0193 int clkdm_add_wkdep(struct clockdomain *clkdm1, struct clockdomain *clkdm2);
0194 int clkdm_del_wkdep(struct clockdomain *clkdm1, struct clockdomain *clkdm2);
0195 int clkdm_read_wkdep(struct clockdomain *clkdm1, struct clockdomain *clkdm2);
0196 int clkdm_clear_all_wkdeps(struct clockdomain *clkdm);
0197 int clkdm_add_sleepdep(struct clockdomain *clkdm1, struct clockdomain *clkdm2);
0198 int clkdm_del_sleepdep(struct clockdomain *clkdm1, struct clockdomain *clkdm2);
0199 int clkdm_read_sleepdep(struct clockdomain *clkdm1, struct clockdomain *clkdm2);
0200 int clkdm_clear_all_sleepdeps(struct clockdomain *clkdm);
0201 
0202 void clkdm_allow_idle_nolock(struct clockdomain *clkdm);
0203 void clkdm_allow_idle(struct clockdomain *clkdm);
0204 void clkdm_deny_idle_nolock(struct clockdomain *clkdm);
0205 void clkdm_deny_idle(struct clockdomain *clkdm);
0206 bool clkdm_in_hwsup(struct clockdomain *clkdm);
0207 bool clkdm_missing_idle_reporting(struct clockdomain *clkdm);
0208 
0209 int clkdm_wakeup_nolock(struct clockdomain *clkdm);
0210 int clkdm_wakeup(struct clockdomain *clkdm);
0211 int clkdm_sleep_nolock(struct clockdomain *clkdm);
0212 int clkdm_sleep(struct clockdomain *clkdm);
0213 
0214 int clkdm_clk_enable(struct clockdomain *clkdm, struct clk *clk);
0215 int clkdm_clk_disable(struct clockdomain *clkdm, struct clk *clk);
0216 int clkdm_hwmod_enable(struct clockdomain *clkdm, struct omap_hwmod *oh);
0217 int clkdm_hwmod_disable(struct clockdomain *clkdm, struct omap_hwmod *oh);
0218 
0219 void clkdm_save_context(void);
0220 void clkdm_restore_context(void);
0221 
0222 extern void __init omap242x_clockdomains_init(void);
0223 extern void __init omap243x_clockdomains_init(void);
0224 extern void __init omap3xxx_clockdomains_init(void);
0225 extern void __init am33xx_clockdomains_init(void);
0226 extern void __init ti814x_clockdomains_init(void);
0227 extern void __init ti816x_clockdomains_init(void);
0228 extern void __init omap44xx_clockdomains_init(void);
0229 extern void __init omap54xx_clockdomains_init(void);
0230 extern void __init dra7xx_clockdomains_init(void);
0231 void am43xx_clockdomains_init(void);
0232 
0233 extern void clkdm_add_autodeps(struct clockdomain *clkdm);
0234 extern void clkdm_del_autodeps(struct clockdomain *clkdm);
0235 
0236 extern struct clkdm_ops omap2_clkdm_operations;
0237 extern struct clkdm_ops omap3_clkdm_operations;
0238 extern struct clkdm_ops omap4_clkdm_operations;
0239 extern struct clkdm_ops am33xx_clkdm_operations;
0240 extern struct clkdm_ops am43xx_clkdm_operations;
0241 
0242 extern struct clkdm_dep gfx_24xx_wkdeps[];
0243 extern struct clkdm_dep dsp_24xx_wkdeps[];
0244 extern struct clockdomain wkup_common_clkdm;
0245 
0246 #endif