Skip to content

Commit f7ccdaa

Browse files
Jagadeesh Konastorulf
authored andcommitted
clk: qcom: gdsc: Add set and get hwmode callbacks to switch GDSC mode
Some GDSC client drivers require the GDSC mode to be switched dynamically to HW mode at runtime to gain the power benefits. Typically such client drivers require the GDSC to be brought up in SW mode initially to enable the required dependent clocks and configure the hardware to proper state. Once initial hardware set up is done, they switch the GDSC to HW mode to save power. At the end of usecase, they switch the GDSC back to SW mode and disable the GDSC. Introduce HW_CTRL_TRIGGER flag to register the set_hwmode_dev and get_hwmode_dev callbacks for GDSC's whose respective client drivers require the GDSC mode to be switched dynamically at runtime using dev_pm_genpd_set_hwmode() API. Signed-off-by: Jagadeesh Kona <[email protected]> Signed-off-by: Abel Vesa <[email protected]> Reviewed-by: Bryan O'Donoghue <[email protected]> Reviewed-by: Taniya Das <[email protected]> Reviewed-by: Bjorn Andersson <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Ulf Hansson <[email protected]>
1 parent 0155aaf commit f7ccdaa

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

drivers/clk/qcom/gdsc.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,43 @@ static int gdsc_disable(struct generic_pm_domain *domain)
363363
return 0;
364364
}
365365

366+
static int gdsc_set_hwmode(struct generic_pm_domain *domain, struct device *dev, bool mode)
367+
{
368+
struct gdsc *sc = domain_to_gdsc(domain);
369+
int ret;
370+
371+
ret = gdsc_hwctrl(sc, mode);
372+
if (ret)
373+
return ret;
374+
375+
/*
376+
* Wait for the GDSC to go through a power down and
377+
* up cycle. If we poll the status register before the
378+
* power cycle is finished we might read incorrect values.
379+
*/
380+
udelay(1);
381+
382+
/*
383+
* When the GDSC is switched to HW mode, HW can disable the GDSC.
384+
* When the GDSC is switched back to SW mode, the GDSC will be enabled
385+
* again, hence we need to poll for GDSC to complete the power up.
386+
*/
387+
if (!mode)
388+
return gdsc_poll_status(sc, GDSC_ON);
389+
390+
return 0;
391+
}
392+
393+
static bool gdsc_get_hwmode(struct generic_pm_domain *domain, struct device *dev)
394+
{
395+
struct gdsc *sc = domain_to_gdsc(domain);
396+
u32 val;
397+
398+
regmap_read(sc->regmap, sc->gdscr, &val);
399+
400+
return !!(val & HW_CONTROL_MASK);
401+
}
402+
366403
static int gdsc_init(struct gdsc *sc)
367404
{
368405
u32 mask, val;
@@ -451,6 +488,10 @@ static int gdsc_init(struct gdsc *sc)
451488
sc->pd.power_off = gdsc_disable;
452489
if (!sc->pd.power_on)
453490
sc->pd.power_on = gdsc_enable;
491+
if (sc->flags & HW_CTRL_TRIGGER) {
492+
sc->pd.set_hwmode_dev = gdsc_set_hwmode;
493+
sc->pd.get_hwmode_dev = gdsc_get_hwmode;
494+
}
454495

455496
ret = pm_genpd_init(&sc->pd, NULL, !on);
456497
if (ret)

drivers/clk/qcom/gdsc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ struct gdsc {
6767
#define ALWAYS_ON BIT(6)
6868
#define RETAIN_FF_ENABLE BIT(7)
6969
#define NO_RET_PERIPH BIT(8)
70+
#define HW_CTRL_TRIGGER BIT(9)
7071
struct reset_controller_dev *rcdev;
7172
unsigned int *resets;
7273
unsigned int reset_count;

0 commit comments

Comments
 (0)