Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

clk: qcom: gdsc: Add support for Memory RET/OFF

Along with the GDSC power switch, there is additional control
to either retain all memory (core and peripheral) within a given
powerdomain or to turn them off while the GDSC is powered down.
Add support for these by modelling a RET state where all
memory is retained and an OFF state where all memory gets turned
off.
The controls provided are granular enough to be able to support
various differnt levels of RET states, like a 'shallow RET' with all memory
retained and a 'deep RET' with some memory retained while some others
are lost. The current patch does not support this and considers
just one RET state where all memory is retained. Futher work, if
needed can support multiple different levels of RET state.

Signed-off-by: Rajendra Nayak <rnayak@codeaurora.org>
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>

authored by

Rajendra Nayak and committed by
Stephen Boyd
014e193c 5e5cc241

+46
+33
drivers/clk/qcom/gdsc.c
··· 34 34 #define EN_FEW_WAIT_VAL (0x8 << 16) 35 35 #define CLK_DIS_WAIT_VAL (0x2 << 12) 36 36 37 + #define RETAIN_MEM BIT(14) 38 + #define RETAIN_PERIPH BIT(13) 39 + 37 40 #define TIMEOUT_US 100 38 41 39 42 #define domain_to_gdsc(domain) container_of(domain, struct gdsc, pd) ··· 84 81 return -ETIMEDOUT; 85 82 } 86 83 84 + static inline void gdsc_force_mem_on(struct gdsc *sc) 85 + { 86 + int i; 87 + u32 mask = RETAIN_MEM | RETAIN_PERIPH; 88 + 89 + for (i = 0; i < sc->cxc_count; i++) 90 + regmap_update_bits(sc->regmap, sc->cxcs[i], mask, mask); 91 + } 92 + 93 + static inline void gdsc_clear_mem_on(struct gdsc *sc) 94 + { 95 + int i; 96 + u32 mask = RETAIN_MEM | RETAIN_PERIPH; 97 + 98 + for (i = 0; i < sc->cxc_count; i++) 99 + regmap_update_bits(sc->regmap, sc->cxcs[i], mask, 0); 100 + } 101 + 87 102 static int gdsc_enable(struct generic_pm_domain *domain) 88 103 { 89 104 struct gdsc *sc = domain_to_gdsc(domain); ··· 110 89 ret = gdsc_toggle_logic(sc, true); 111 90 if (ret) 112 91 return ret; 92 + 93 + if (sc->pwrsts & PWRSTS_OFF) 94 + gdsc_force_mem_on(sc); 95 + 113 96 /* 114 97 * If clocks to this power domain were already on, they will take an 115 98 * additional 4 clock cycles to re-enable after the power domain is ··· 129 104 static int gdsc_disable(struct generic_pm_domain *domain) 130 105 { 131 106 struct gdsc *sc = domain_to_gdsc(domain); 107 + 108 + if (sc->pwrsts & PWRSTS_OFF) 109 + gdsc_clear_mem_on(sc); 132 110 133 111 return gdsc_toggle_logic(sc, false); 134 112 } ··· 156 128 on = gdsc_is_enabled(sc); 157 129 if (on < 0) 158 130 return on; 131 + 132 + if (on || (sc->pwrsts & PWRSTS_RET)) 133 + gdsc_force_mem_on(sc); 134 + else 135 + gdsc_clear_mem_on(sc); 159 136 160 137 sc->pd.power_off = gdsc_disable; 161 138 sc->pd.power_on = gdsc_enable;
+13
drivers/clk/qcom/gdsc.h
··· 19 19 20 20 struct regmap; 21 21 22 + /* Powerdomain allowable state bitfields */ 23 + #define PWRSTS_OFF BIT(0) 24 + #define PWRSTS_RET BIT(1) 25 + #define PWRSTS_ON BIT(2) 26 + #define PWRSTS_OFF_ON (PWRSTS_OFF | PWRSTS_ON) 27 + #define PWRSTS_RET_ON (PWRSTS_RET | PWRSTS_ON) 28 + 22 29 /** 23 30 * struct gdsc - Globally Distributed Switch Controller 24 31 * @pd: generic power domain 25 32 * @regmap: regmap for MMIO accesses 26 33 * @gdscr: gsdc control register 34 + * @cxcs: offsets of branch registers to toggle mem/periph bits in 35 + * @cxc_count: number of @cxcs 36 + * @pwrsts: Possible powerdomain power states 27 37 */ 28 38 struct gdsc { 29 39 struct generic_pm_domain pd; 30 40 struct regmap *regmap; 31 41 unsigned int gdscr; 42 + unsigned int *cxcs; 43 + unsigned int cxc_count; 44 + const u8 pwrsts; 32 45 }; 33 46 34 47 #ifdef CONFIG_QCOM_GDSC