Lines Matching full:sc
59 static int gdsc_check_status(struct gdsc *sc, enum gdsc_status status) in gdsc_check_status() argument
65 if (sc->flags & POLL_CFG_GDSCR) in gdsc_check_status()
66 reg = sc->gdscr + CFG_GDSCR_OFFSET; in gdsc_check_status()
67 else if (sc->gds_hw_ctrl) in gdsc_check_status()
68 reg = sc->gds_hw_ctrl; in gdsc_check_status()
70 reg = sc->gdscr; in gdsc_check_status()
72 ret = regmap_read(sc->regmap, reg, &val); in gdsc_check_status()
76 if (sc->flags & POLL_CFG_GDSCR) { in gdsc_check_status()
95 static int gdsc_hwctrl(struct gdsc *sc, bool en) in gdsc_hwctrl() argument
99 return regmap_update_bits(sc->regmap, sc->gdscr, HW_CONTROL_MASK, val); in gdsc_hwctrl()
102 static int gdsc_poll_status(struct gdsc *sc, enum gdsc_status status) in gdsc_poll_status() argument
108 if (gdsc_check_status(sc, status)) in gdsc_poll_status()
112 if (gdsc_check_status(sc, status)) in gdsc_poll_status()
118 static int gdsc_toggle_logic(struct gdsc *sc, enum gdsc_status status) in gdsc_toggle_logic() argument
123 if (status == GDSC_ON && sc->rsupply) { in gdsc_toggle_logic()
124 ret = regulator_enable(sc->rsupply); in gdsc_toggle_logic()
129 ret = regmap_update_bits(sc->regmap, sc->gdscr, SW_COLLAPSE_MASK, val); in gdsc_toggle_logic()
134 if ((sc->flags & VOTABLE) && status == GDSC_OFF) { in gdsc_toggle_logic()
144 if (sc->gds_hw_ctrl) { in gdsc_toggle_logic()
158 ret = gdsc_poll_status(sc, status); in gdsc_toggle_logic()
159 WARN(ret, "%s status stuck at 'o%s'", sc->pd.name, status ? "ff" : "n"); in gdsc_toggle_logic()
161 if (!ret && status == GDSC_OFF && sc->rsupply) { in gdsc_toggle_logic()
162 ret = regulator_disable(sc->rsupply); in gdsc_toggle_logic()
170 static inline int gdsc_deassert_reset(struct gdsc *sc) in gdsc_deassert_reset() argument
174 for (i = 0; i < sc->reset_count; i++) in gdsc_deassert_reset()
175 sc->rcdev->ops->deassert(sc->rcdev, sc->resets[i]); in gdsc_deassert_reset()
179 static inline int gdsc_assert_reset(struct gdsc *sc) in gdsc_assert_reset() argument
183 for (i = 0; i < sc->reset_count; i++) in gdsc_assert_reset()
184 sc->rcdev->ops->assert(sc->rcdev, sc->resets[i]); in gdsc_assert_reset()
188 static inline void gdsc_force_mem_on(struct gdsc *sc) in gdsc_force_mem_on() argument
193 if (!(sc->flags & NO_RET_PERIPH)) in gdsc_force_mem_on()
196 for (i = 0; i < sc->cxc_count; i++) in gdsc_force_mem_on()
197 regmap_update_bits(sc->regmap, sc->cxcs[i], mask, mask); in gdsc_force_mem_on()
200 static inline void gdsc_clear_mem_on(struct gdsc *sc) in gdsc_clear_mem_on() argument
205 if (!(sc->flags & NO_RET_PERIPH)) in gdsc_clear_mem_on()
208 for (i = 0; i < sc->cxc_count; i++) in gdsc_clear_mem_on()
209 regmap_update_bits(sc->regmap, sc->cxcs[i], mask, 0); in gdsc_clear_mem_on()
212 static inline void gdsc_deassert_clamp_io(struct gdsc *sc) in gdsc_deassert_clamp_io() argument
214 regmap_update_bits(sc->regmap, sc->clamp_io_ctrl, in gdsc_deassert_clamp_io()
218 static inline void gdsc_assert_clamp_io(struct gdsc *sc) in gdsc_assert_clamp_io() argument
220 regmap_update_bits(sc->regmap, sc->clamp_io_ctrl, in gdsc_assert_clamp_io()
224 static inline void gdsc_assert_reset_aon(struct gdsc *sc) in gdsc_assert_reset_aon() argument
226 regmap_update_bits(sc->regmap, sc->clamp_io_ctrl, in gdsc_assert_reset_aon()
229 regmap_update_bits(sc->regmap, sc->clamp_io_ctrl, in gdsc_assert_reset_aon()
233 static void gdsc_retain_ff_on(struct gdsc *sc) in gdsc_retain_ff_on() argument
237 regmap_update_bits(sc->regmap, sc->gdscr, mask, mask); in gdsc_retain_ff_on()
242 struct gdsc *sc = domain_to_gdsc(domain); in gdsc_enable() local
245 if (sc->pwrsts == PWRSTS_ON) in gdsc_enable()
246 return gdsc_deassert_reset(sc); in gdsc_enable()
248 if (sc->flags & SW_RESET) { in gdsc_enable()
249 gdsc_assert_reset(sc); in gdsc_enable()
251 gdsc_deassert_reset(sc); in gdsc_enable()
254 if (sc->flags & CLAMP_IO) { in gdsc_enable()
255 if (sc->flags & AON_RESET) in gdsc_enable()
256 gdsc_assert_reset_aon(sc); in gdsc_enable()
257 gdsc_deassert_clamp_io(sc); in gdsc_enable()
260 ret = gdsc_toggle_logic(sc, GDSC_ON); in gdsc_enable()
264 if (sc->pwrsts & PWRSTS_OFF) in gdsc_enable()
265 gdsc_force_mem_on(sc); in gdsc_enable()
277 if (sc->flags & HW_CTRL) { in gdsc_enable()
278 ret = gdsc_hwctrl(sc, true); in gdsc_enable()
292 if (sc->flags & RETAIN_FF_ENABLE) in gdsc_enable()
293 gdsc_retain_ff_on(sc); in gdsc_enable()
300 struct gdsc *sc = domain_to_gdsc(domain); in gdsc_disable() local
303 if (sc->pwrsts == PWRSTS_ON) in gdsc_disable()
304 return gdsc_assert_reset(sc); in gdsc_disable()
307 if (sc->flags & HW_CTRL) { in gdsc_disable()
308 ret = gdsc_hwctrl(sc, false); in gdsc_disable()
319 ret = gdsc_poll_status(sc, GDSC_ON); in gdsc_disable()
324 if (sc->pwrsts & PWRSTS_OFF) in gdsc_disable()
325 gdsc_clear_mem_on(sc); in gdsc_disable()
327 ret = gdsc_toggle_logic(sc, GDSC_OFF); in gdsc_disable()
331 if (sc->flags & CLAMP_IO) in gdsc_disable()
332 gdsc_assert_clamp_io(sc); in gdsc_disable()
337 static int gdsc_init(struct gdsc *sc) in gdsc_init() argument
350 if (!sc->en_rest_wait_val) in gdsc_init()
351 sc->en_rest_wait_val = EN_REST_WAIT_VAL; in gdsc_init()
352 if (!sc->en_few_wait_val) in gdsc_init()
353 sc->en_few_wait_val = EN_FEW_WAIT_VAL; in gdsc_init()
354 if (!sc->clk_dis_wait_val) in gdsc_init()
355 sc->clk_dis_wait_val = CLK_DIS_WAIT_VAL; in gdsc_init()
357 val = sc->en_rest_wait_val << EN_REST_WAIT_SHIFT | in gdsc_init()
358 sc->en_few_wait_val << EN_FEW_WAIT_SHIFT | in gdsc_init()
359 sc->clk_dis_wait_val << CLK_DIS_WAIT_SHIFT; in gdsc_init()
361 ret = regmap_update_bits(sc->regmap, sc->gdscr, mask, val); in gdsc_init()
366 if (sc->pwrsts == PWRSTS_ON) { in gdsc_init()
367 ret = gdsc_toggle_logic(sc, GDSC_ON); in gdsc_init()
372 on = gdsc_check_status(sc, GDSC_ON); in gdsc_init()
378 if (sc->rsupply) { in gdsc_init()
379 ret = regulator_enable(sc->rsupply); in gdsc_init()
388 if (sc->flags & VOTABLE) { in gdsc_init()
389 ret = regmap_update_bits(sc->regmap, sc->gdscr, in gdsc_init()
396 if (sc->flags & HW_CTRL) { in gdsc_init()
397 ret = gdsc_hwctrl(sc, true); in gdsc_init()
407 if (sc->flags & RETAIN_FF_ENABLE) in gdsc_init()
408 gdsc_retain_ff_on(sc); in gdsc_init()
409 } else if (sc->flags & ALWAYS_ON) { in gdsc_init()
411 gdsc_enable(&sc->pd); in gdsc_init()
415 if (on || (sc->pwrsts & PWRSTS_RET)) in gdsc_init()
416 gdsc_force_mem_on(sc); in gdsc_init()
418 gdsc_clear_mem_on(sc); in gdsc_init()
420 if (sc->flags & ALWAYS_ON) in gdsc_init()
421 sc->pd.flags |= GENPD_FLAG_ALWAYS_ON; in gdsc_init()
422 if (!sc->pd.power_off) in gdsc_init()
423 sc->pd.power_off = gdsc_disable; in gdsc_init()
424 if (!sc->pd.power_on) in gdsc_init()
425 sc->pd.power_on = gdsc_enable; in gdsc_init()
426 pm_genpd_init(&sc->pd, NULL, !on); in gdsc_init()