Lines Matching refs:sc

54 static int gdsc_pm_runtime_get(struct gdsc *sc)  in gdsc_pm_runtime_get()  argument
56 if (!sc->dev) in gdsc_pm_runtime_get()
59 return pm_runtime_resume_and_get(sc->dev); in gdsc_pm_runtime_get()
62 static int gdsc_pm_runtime_put(struct gdsc *sc) in gdsc_pm_runtime_put() argument
64 if (!sc->dev) in gdsc_pm_runtime_put()
67 return pm_runtime_put_sync(sc->dev); in gdsc_pm_runtime_put()
71 static int gdsc_check_status(struct gdsc *sc, enum gdsc_status status) in gdsc_check_status() argument
77 if (sc->flags & POLL_CFG_GDSCR) in gdsc_check_status()
78 reg = sc->gdscr + CFG_GDSCR_OFFSET; in gdsc_check_status()
79 else if (sc->gds_hw_ctrl) in gdsc_check_status()
80 reg = sc->gds_hw_ctrl; in gdsc_check_status()
82 reg = sc->gdscr; in gdsc_check_status()
84 ret = regmap_read(sc->regmap, reg, &val); in gdsc_check_status()
88 if (sc->flags & POLL_CFG_GDSCR) { in gdsc_check_status()
107 static int gdsc_hwctrl(struct gdsc *sc, bool en) in gdsc_hwctrl() argument
111 return regmap_update_bits(sc->regmap, sc->gdscr, HW_CONTROL_MASK, val); in gdsc_hwctrl()
114 static int gdsc_poll_status(struct gdsc *sc, enum gdsc_status status) in gdsc_poll_status() argument
120 if (gdsc_check_status(sc, status)) in gdsc_poll_status()
124 if (gdsc_check_status(sc, status)) in gdsc_poll_status()
130 static int gdsc_toggle_logic(struct gdsc *sc, enum gdsc_status status) in gdsc_toggle_logic() argument
135 if (status == GDSC_ON && sc->rsupply) { in gdsc_toggle_logic()
136 ret = regulator_enable(sc->rsupply); in gdsc_toggle_logic()
141 ret = regmap_update_bits(sc->regmap, sc->gdscr, SW_COLLAPSE_MASK, val); in gdsc_toggle_logic()
146 if ((sc->flags & VOTABLE) && status == GDSC_OFF) { in gdsc_toggle_logic()
156 if (sc->gds_hw_ctrl) { in gdsc_toggle_logic()
170 ret = gdsc_poll_status(sc, status); in gdsc_toggle_logic()
171 WARN(ret, "%s status stuck at 'o%s'", sc->pd.name, status ? "ff" : "n"); in gdsc_toggle_logic()
173 if (!ret && status == GDSC_OFF && sc->rsupply) { in gdsc_toggle_logic()
174 ret = regulator_disable(sc->rsupply); in gdsc_toggle_logic()
182 static inline int gdsc_deassert_reset(struct gdsc *sc) in gdsc_deassert_reset() argument
186 for (i = 0; i < sc->reset_count; i++) in gdsc_deassert_reset()
187 sc->rcdev->ops->deassert(sc->rcdev, sc->resets[i]); in gdsc_deassert_reset()
191 static inline int gdsc_assert_reset(struct gdsc *sc) in gdsc_assert_reset() argument
195 for (i = 0; i < sc->reset_count; i++) in gdsc_assert_reset()
196 sc->rcdev->ops->assert(sc->rcdev, sc->resets[i]); in gdsc_assert_reset()
200 static inline void gdsc_force_mem_on(struct gdsc *sc) in gdsc_force_mem_on() argument
205 if (!(sc->flags & NO_RET_PERIPH)) in gdsc_force_mem_on()
208 for (i = 0; i < sc->cxc_count; i++) in gdsc_force_mem_on()
209 regmap_update_bits(sc->regmap, sc->cxcs[i], mask, mask); in gdsc_force_mem_on()
212 static inline void gdsc_clear_mem_on(struct gdsc *sc) in gdsc_clear_mem_on() argument
217 if (!(sc->flags & NO_RET_PERIPH)) in gdsc_clear_mem_on()
220 for (i = 0; i < sc->cxc_count; i++) in gdsc_clear_mem_on()
221 regmap_update_bits(sc->regmap, sc->cxcs[i], mask, 0); in gdsc_clear_mem_on()
224 static inline void gdsc_deassert_clamp_io(struct gdsc *sc) in gdsc_deassert_clamp_io() argument
226 regmap_update_bits(sc->regmap, sc->clamp_io_ctrl, in gdsc_deassert_clamp_io()
230 static inline void gdsc_assert_clamp_io(struct gdsc *sc) in gdsc_assert_clamp_io() argument
232 regmap_update_bits(sc->regmap, sc->clamp_io_ctrl, in gdsc_assert_clamp_io()
236 static inline void gdsc_assert_reset_aon(struct gdsc *sc) in gdsc_assert_reset_aon() argument
238 regmap_update_bits(sc->regmap, sc->clamp_io_ctrl, in gdsc_assert_reset_aon()
241 regmap_update_bits(sc->regmap, sc->clamp_io_ctrl, in gdsc_assert_reset_aon()
245 static void gdsc_retain_ff_on(struct gdsc *sc) in gdsc_retain_ff_on() argument
249 regmap_update_bits(sc->regmap, sc->gdscr, mask, mask); in gdsc_retain_ff_on()
252 static int _gdsc_enable(struct gdsc *sc) in _gdsc_enable() argument
256 if (sc->pwrsts == PWRSTS_ON) in _gdsc_enable()
257 return gdsc_deassert_reset(sc); in _gdsc_enable()
259 if (sc->flags & SW_RESET) { in _gdsc_enable()
260 gdsc_assert_reset(sc); in _gdsc_enable()
262 gdsc_deassert_reset(sc); in _gdsc_enable()
265 if (sc->flags & CLAMP_IO) { in _gdsc_enable()
266 if (sc->flags & AON_RESET) in _gdsc_enable()
267 gdsc_assert_reset_aon(sc); in _gdsc_enable()
268 gdsc_deassert_clamp_io(sc); in _gdsc_enable()
271 ret = gdsc_toggle_logic(sc, GDSC_ON); in _gdsc_enable()
275 if (sc->pwrsts & PWRSTS_OFF) in _gdsc_enable()
276 gdsc_force_mem_on(sc); in _gdsc_enable()
288 if (sc->flags & HW_CTRL) { in _gdsc_enable()
289 ret = gdsc_hwctrl(sc, true); in _gdsc_enable()
303 if (sc->flags & RETAIN_FF_ENABLE) in _gdsc_enable()
304 gdsc_retain_ff_on(sc); in _gdsc_enable()
311 struct gdsc *sc = domain_to_gdsc(domain); in gdsc_enable() local
314 ret = gdsc_pm_runtime_get(sc); in gdsc_enable()
318 return _gdsc_enable(sc); in gdsc_enable()
321 static int _gdsc_disable(struct gdsc *sc) in _gdsc_disable() argument
325 if (sc->pwrsts == PWRSTS_ON) in _gdsc_disable()
326 return gdsc_assert_reset(sc); in _gdsc_disable()
329 if (sc->flags & HW_CTRL) { in _gdsc_disable()
330 ret = gdsc_hwctrl(sc, false); in _gdsc_disable()
341 ret = gdsc_poll_status(sc, GDSC_ON); in _gdsc_disable()
346 if (sc->pwrsts & PWRSTS_OFF) in _gdsc_disable()
347 gdsc_clear_mem_on(sc); in _gdsc_disable()
349 ret = gdsc_toggle_logic(sc, GDSC_OFF); in _gdsc_disable()
353 if (sc->flags & CLAMP_IO) in _gdsc_disable()
354 gdsc_assert_clamp_io(sc); in _gdsc_disable()
361 struct gdsc *sc = domain_to_gdsc(domain); in gdsc_disable() local
364 ret = _gdsc_disable(sc); in gdsc_disable()
366 gdsc_pm_runtime_put(sc); in gdsc_disable()
371 static int gdsc_init(struct gdsc *sc) in gdsc_init() argument
384 ret = regmap_update_bits(sc->regmap, sc->gdscr, mask, val); in gdsc_init()
389 if (sc->pwrsts == PWRSTS_ON) { in gdsc_init()
390 ret = gdsc_toggle_logic(sc, GDSC_ON); in gdsc_init()
395 on = gdsc_check_status(sc, GDSC_ON); in gdsc_init()
401 if (sc->rsupply) { in gdsc_init()
402 ret = regulator_enable(sc->rsupply); in gdsc_init()
411 if (sc->flags & VOTABLE) { in gdsc_init()
412 ret = regmap_update_bits(sc->regmap, sc->gdscr, in gdsc_init()
419 if (sc->flags & HW_CTRL) { in gdsc_init()
420 ret = gdsc_hwctrl(sc, true); in gdsc_init()
430 if (sc->flags & RETAIN_FF_ENABLE) in gdsc_init()
431 gdsc_retain_ff_on(sc); in gdsc_init()
432 } else if (sc->flags & ALWAYS_ON) { in gdsc_init()
434 gdsc_enable(&sc->pd); in gdsc_init()
438 if (on || (sc->pwrsts & PWRSTS_RET)) in gdsc_init()
439 gdsc_force_mem_on(sc); in gdsc_init()
441 gdsc_clear_mem_on(sc); in gdsc_init()
443 if (sc->flags & ALWAYS_ON) in gdsc_init()
444 sc->pd.flags |= GENPD_FLAG_ALWAYS_ON; in gdsc_init()
445 if (!sc->pd.power_off) in gdsc_init()
446 sc->pd.power_off = gdsc_disable; in gdsc_init()
447 if (!sc->pd.power_on) in gdsc_init()
448 sc->pd.power_on = gdsc_enable; in gdsc_init()
449 pm_genpd_init(&sc->pd, NULL, !on); in gdsc_init()