Lines Matching full:sc
54 static int gdsc_check_status(struct gdsc *sc, enum gdsc_status status) in gdsc_check_status() argument
60 if (sc->flags & POLL_CFG_GDSCR) in gdsc_check_status()
61 reg = sc->gdscr + CFG_GDSCR_OFFSET; in gdsc_check_status()
62 else if (sc->gds_hw_ctrl) in gdsc_check_status()
63 reg = sc->gds_hw_ctrl; in gdsc_check_status()
65 reg = sc->gdscr; in gdsc_check_status()
67 ret = regmap_read(sc->regmap, reg, &val); in gdsc_check_status()
71 if (sc->flags & POLL_CFG_GDSCR) { in gdsc_check_status()
90 static int gdsc_hwctrl(struct gdsc *sc, bool en) in gdsc_hwctrl() argument
94 return regmap_update_bits(sc->regmap, sc->gdscr, HW_CONTROL_MASK, val); in gdsc_hwctrl()
97 static int gdsc_poll_status(struct gdsc *sc, enum gdsc_status status) in gdsc_poll_status() argument
103 if (gdsc_check_status(sc, status)) in gdsc_poll_status()
107 if (gdsc_check_status(sc, status)) in gdsc_poll_status()
113 static int gdsc_toggle_logic(struct gdsc *sc, enum gdsc_status status) in gdsc_toggle_logic() argument
118 if (status == GDSC_ON && sc->rsupply) { in gdsc_toggle_logic()
119 ret = regulator_enable(sc->rsupply); in gdsc_toggle_logic()
124 ret = regmap_update_bits(sc->regmap, sc->gdscr, SW_COLLAPSE_MASK, val); in gdsc_toggle_logic()
129 if ((sc->flags & VOTABLE) && status == GDSC_OFF) { in gdsc_toggle_logic()
139 if (sc->gds_hw_ctrl) { in gdsc_toggle_logic()
153 ret = gdsc_poll_status(sc, status); in gdsc_toggle_logic()
154 WARN(ret, "%s status stuck at 'o%s'", sc->pd.name, status ? "ff" : "n"); in gdsc_toggle_logic()
156 if (!ret && status == GDSC_OFF && sc->rsupply) { in gdsc_toggle_logic()
157 ret = regulator_disable(sc->rsupply); in gdsc_toggle_logic()
165 static inline int gdsc_deassert_reset(struct gdsc *sc) in gdsc_deassert_reset() argument
169 for (i = 0; i < sc->reset_count; i++) in gdsc_deassert_reset()
170 sc->rcdev->ops->deassert(sc->rcdev, sc->resets[i]); in gdsc_deassert_reset()
174 static inline int gdsc_assert_reset(struct gdsc *sc) in gdsc_assert_reset() argument
178 for (i = 0; i < sc->reset_count; i++) in gdsc_assert_reset()
179 sc->rcdev->ops->assert(sc->rcdev, sc->resets[i]); in gdsc_assert_reset()
183 static inline void gdsc_force_mem_on(struct gdsc *sc) in gdsc_force_mem_on() argument
188 if (!(sc->flags & NO_RET_PERIPH)) in gdsc_force_mem_on()
191 for (i = 0; i < sc->cxc_count; i++) in gdsc_force_mem_on()
192 regmap_update_bits(sc->regmap, sc->cxcs[i], mask, mask); in gdsc_force_mem_on()
195 static inline void gdsc_clear_mem_on(struct gdsc *sc) in gdsc_clear_mem_on() argument
200 if (!(sc->flags & NO_RET_PERIPH)) in gdsc_clear_mem_on()
203 for (i = 0; i < sc->cxc_count; i++) in gdsc_clear_mem_on()
204 regmap_update_bits(sc->regmap, sc->cxcs[i], mask, 0); in gdsc_clear_mem_on()
207 static inline void gdsc_deassert_clamp_io(struct gdsc *sc) in gdsc_deassert_clamp_io() argument
209 regmap_update_bits(sc->regmap, sc->clamp_io_ctrl, in gdsc_deassert_clamp_io()
213 static inline void gdsc_assert_clamp_io(struct gdsc *sc) in gdsc_assert_clamp_io() argument
215 regmap_update_bits(sc->regmap, sc->clamp_io_ctrl, in gdsc_assert_clamp_io()
219 static inline void gdsc_assert_reset_aon(struct gdsc *sc) in gdsc_assert_reset_aon() argument
221 regmap_update_bits(sc->regmap, sc->clamp_io_ctrl, in gdsc_assert_reset_aon()
224 regmap_update_bits(sc->regmap, sc->clamp_io_ctrl, in gdsc_assert_reset_aon()
228 static void gdsc_retain_ff_on(struct gdsc *sc) in gdsc_retain_ff_on() argument
232 regmap_update_bits(sc->regmap, sc->gdscr, mask, mask); in gdsc_retain_ff_on()
237 struct gdsc *sc = domain_to_gdsc(domain); in gdsc_enable() local
240 if (sc->pwrsts == PWRSTS_ON) in gdsc_enable()
241 return gdsc_deassert_reset(sc); in gdsc_enable()
243 if (sc->flags & SW_RESET) { in gdsc_enable()
244 gdsc_assert_reset(sc); in gdsc_enable()
246 gdsc_deassert_reset(sc); in gdsc_enable()
249 if (sc->flags & CLAMP_IO) { in gdsc_enable()
250 if (sc->flags & AON_RESET) in gdsc_enable()
251 gdsc_assert_reset_aon(sc); in gdsc_enable()
252 gdsc_deassert_clamp_io(sc); in gdsc_enable()
255 ret = gdsc_toggle_logic(sc, GDSC_ON); in gdsc_enable()
259 if (sc->pwrsts & PWRSTS_OFF) in gdsc_enable()
260 gdsc_force_mem_on(sc); in gdsc_enable()
272 if (sc->flags & HW_CTRL) { in gdsc_enable()
273 ret = gdsc_hwctrl(sc, true); in gdsc_enable()
287 if (sc->flags & RETAIN_FF_ENABLE) in gdsc_enable()
288 gdsc_retain_ff_on(sc); in gdsc_enable()
295 struct gdsc *sc = domain_to_gdsc(domain); in gdsc_disable() local
298 if (sc->pwrsts == PWRSTS_ON) in gdsc_disable()
299 return gdsc_assert_reset(sc); in gdsc_disable()
302 if (sc->flags & HW_CTRL) { in gdsc_disable()
303 ret = gdsc_hwctrl(sc, false); in gdsc_disable()
314 ret = gdsc_poll_status(sc, GDSC_ON); in gdsc_disable()
319 if (sc->pwrsts & PWRSTS_OFF) in gdsc_disable()
320 gdsc_clear_mem_on(sc); in gdsc_disable()
322 ret = gdsc_toggle_logic(sc, GDSC_OFF); in gdsc_disable()
326 if (sc->flags & CLAMP_IO) in gdsc_disable()
327 gdsc_assert_clamp_io(sc); in gdsc_disable()
332 static int gdsc_init(struct gdsc *sc) in gdsc_init() argument
345 ret = regmap_update_bits(sc->regmap, sc->gdscr, mask, val); in gdsc_init()
350 if (sc->pwrsts == PWRSTS_ON) { in gdsc_init()
351 ret = gdsc_toggle_logic(sc, GDSC_ON); in gdsc_init()
356 on = gdsc_check_status(sc, GDSC_ON); in gdsc_init()
362 if (sc->rsupply) { in gdsc_init()
363 ret = regulator_enable(sc->rsupply); in gdsc_init()
372 if (sc->flags & VOTABLE) { in gdsc_init()
373 ret = regmap_update_bits(sc->regmap, sc->gdscr, in gdsc_init()
380 if (sc->flags & HW_CTRL) { in gdsc_init()
381 ret = gdsc_hwctrl(sc, true); in gdsc_init()
391 if (sc->flags & RETAIN_FF_ENABLE) in gdsc_init()
392 gdsc_retain_ff_on(sc); in gdsc_init()
393 } else if (sc->flags & ALWAYS_ON) { in gdsc_init()
395 gdsc_enable(&sc->pd); in gdsc_init()
399 if (on || (sc->pwrsts & PWRSTS_RET)) in gdsc_init()
400 gdsc_force_mem_on(sc); in gdsc_init()
402 gdsc_clear_mem_on(sc); in gdsc_init()
404 if (sc->flags & ALWAYS_ON) in gdsc_init()
405 sc->pd.flags |= GENPD_FLAG_ALWAYS_ON; in gdsc_init()
406 if (!sc->pd.power_off) in gdsc_init()
407 sc->pd.power_off = gdsc_disable; in gdsc_init()
408 if (!sc->pd.power_on) in gdsc_init()
409 sc->pd.power_on = gdsc_enable; in gdsc_init()
410 pm_genpd_init(&sc->pd, NULL, !on); in gdsc_init()