mmc: sdhci-pci-gli: Add runtime PM for GL9763E
PATCH 1/1 mmc: sdhci-pci-gli: Add runtime PM for GL9763E
From: Ben Chuang <[email protected]>
Add runtime PM for GL9763E and disable PLL in runtime suspend. So power gated of upstream port can be enabled.
--- drivers/mmc/host/sdhci-pci-gli.c | 54 ++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+)
drivers/mmc/host/sdhci-pci-gli.c +54 -0
@@ -873,6 +873,55 @@ static void gli_set_gl9763e(struct sdhci_pci_slot *slot)pci_write_config_dword (pdev,PCIE_GLI_9763E_VHS , value); } +#ifdef CONFIG_PM +static int gl9763e_runtime_suspend (struct sdhci_pci_chip *chip) +{ +struct sdhci_pci_slot *slot = chip->slots[0 ]; +struct sdhci_host *host = slot->host; +u16 clock; + + clock =sdhci_readw (host,SDHCI_CLOCK_CONTROL ); + clock &= ~(SDHCI_CLOCK_PLL_EN |SDHCI_CLOCK_CARD_EN ); +sdhci_writew (host, clock,SDHCI_CLOCK_CONTROL ); + +return 0 ; +} + +static int gl9763e_runtime_resume (struct sdhci_pci_chip *chip) +{ +struct sdhci_pci_slot *slot = chip->slots[0 ]; +struct sdhci_host *host = slot->host; +ktime_t timeout; +u16 clock; + + clock =sdhci_readw (host,SDHCI_CLOCK_CONTROL ); + + clock |=SDHCI_CLOCK_PLL_EN ; + clock &= ~SDHCI_CLOCK_INT_STABLE ; +sdhci_writew (host, clock,SDHCI_CLOCK_CONTROL ); + + timeout =ktime_add_ms (ktime_get (),150 ); +while (1 ) { +bool timedout =ktime_after (ktime_get (), timeout); + + clock =sdhci_readw (host,SDHCI_CLOCK_CONTROL ); +if (clock &SDHCI_CLOCK_INT_STABLE ) +break ; +if (timedout) { +pr_err ("%s: PLL clock never stabilised.\n" , +mmc_hostname (host->mmc)); +sdhci_dumpregs (host); +break ; + } +udelay (10 ); + } + clock |=SDHCI_CLOCK_CARD_EN ; +sdhci_writew (host, clock,SDHCI_CLOCK_CONTROL ); + +return 0 ; +} +#endif +static int gli_probe_slot_gl9763e (struct sdhci_pci_slot *slot) {struct pci_dev *pdev = slot->chip->pdev;
@@ -982,6 +1031,11 @@ const struct sdhci_pci_fixes sdhci_gl9763e = {#ifdef CONFIG_PM_SLEEP .resume = sdhci_cqhci_gli_resume, .suspend = sdhci_cqhci_gli_suspend, +#endif +#ifdef CONFIG_PM + .runtime_suspend = gl9763e_runtime_suspend, + .runtime_resume = gl9763e_runtime_resume, + .allow_runtime_pm = true, #endif .add_host = gl9763e_add_host, };
Signature · 1 line
2.35.1
PATCH 1/1 mmc: sdhci-pci-gli: Add runtime PM for GL9763E
From: Ben Chuang <[email protected]>
Add runtime PM for GL9763E and disable PLL in runtime suspend. So power gated of upstream port can be enabled.
--- drivers/mmc/host/sdhci-pci-gli.c | 54 ++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+)
drivers/mmc/host/sdhci-pci-gli.c +54 -0
@@ -873,6 +873,55 @@ static void gli_set_gl9763e(struct sdhci_pci_slot *slot)pci_write_config_dword (pdev,PCIE_GLI_9763E_VHS , value); } +#ifdef CONFIG_PM +static int gl9763e_runtime_suspend (struct sdhci_pci_chip *chip) +{ +struct sdhci_pci_slot *slot = chip->slots[0 ]; +struct sdhci_host *host = slot->host; +u16 clock; + + clock =sdhci_readw (host,SDHCI_CLOCK_CONTROL ); + clock &= ~(SDHCI_CLOCK_PLL_EN |SDHCI_CLOCK_CARD_EN ); +sdhci_writew (host, clock,SDHCI_CLOCK_CONTROL ); + +return 0 ; +} + +static int gl9763e_runtime_resume (struct sdhci_pci_chip *chip) +{ +struct sdhci_pci_slot *slot = chip->slots[0 ]; +struct sdhci_host *host = slot->host; +ktime_t timeout; +u16 clock; + + clock =sdhci_readw (host,SDHCI_CLOCK_CONTROL ); + + clock |=SDHCI_CLOCK_PLL_EN ; + clock &= ~SDHCI_CLOCK_INT_STABLE ; +sdhci_writew (host, clock,SDHCI_CLOCK_CONTROL ); + + timeout =ktime_add_ms (ktime_get (),150 ); +while (1 ) { +bool timedout =ktime_after (ktime_get (), timeout); + + clock =sdhci_readw (host,SDHCI_CLOCK_CONTROL ); +if (clock &SDHCI_CLOCK_INT_STABLE ) +break ; +if (timedout) { +pr_err ("%s: PLL clock never stabilised.\n" , +mmc_hostname (host->mmc)); +sdhci_dumpregs (host); +break ; + } +udelay (10 ); + } + clock |=SDHCI_CLOCK_CARD_EN ; +sdhci_writew (host, clock,SDHCI_CLOCK_CONTROL ); + +return 0 ; +} +#endif +static int gli_probe_slot_gl9763e (struct sdhci_pci_slot *slot) {struct pci_dev *pdev = slot->chip->pdev;
@@ -982,6 +1031,11 @@ const struct sdhci_pci_fixes sdhci_gl9763e = {#ifdef CONFIG_PM_SLEEP .resume = sdhci_cqhci_gli_resume, .suspend = sdhci_cqhci_gli_suspend, +#endif +#ifdef CONFIG_PM + .runtime_suspend = gl9763e_runtime_suspend, + .runtime_resume = gl9763e_runtime_resume, + .allow_runtime_pm = true, #endif .add_host = gl9763e_add_host, };
Signature · 1 line
2.35.1
Quoted 57 lines · Ben Chuang
From: Ben Chuang <[email protected]>
Add runtime PM for GL9763E and disable PLL in runtime suspend. So power gated of upstream port can be enabled.
Signed-off-by Ben Chuang <[email protected]>Tested-by Kevin Chang <[email protected]>--- drivers/mmc/host/sdhci-pci-gli.c | 54 ++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+)drivers/mmc/host/sdhci-pci-gli.c +37
-0@@ -873,6 +873,55 @@ static void gli_set_gl9763e(struct sdhci_pci_slot *slot)pci_write_config_dword (pdev,PCIE_GLI_9763E_VHS , value); } +#ifdef CONFIG_PM +static int gl9763e_runtime_suspend (struct sdhci_pci_chip *chip) +{ +struct sdhci_pci_slot *slot = chip->slots[0 ]; +struct sdhci_host *host = slot->host; +u16 clock; + + clock =sdhci_readw (host,SDHCI_CLOCK_CONTROL ); + clock &= ~(SDHCI_CLOCK_PLL_EN |SDHCI_CLOCK_CARD_EN ); +sdhci_writew (host, clock,SDHCI_CLOCK_CONTROL ); + +return 0 ; +} + +static int gl9763e_runtime_resume (struct sdhci_pci_chip *chip) +{ +struct sdhci_pci_slot *slot = chip->slots[0 ]; +struct sdhci_host *host = slot->host; +ktime_t timeout; +u16 clock; + + clock =sdhci_readw (host,SDHCI_CLOCK_CONTROL ); + + clock |=SDHCI_CLOCK_PLL_EN ; + clock &= ~SDHCI_CLOCK_INT_STABLE ; +sdhci_writew (host, clock,SDHCI_CLOCK_CONTROL ); + + timeout =ktime_add_ms (ktime_get (),150 ); +while (1 ) { +bool timedout =ktime_after (ktime_get (), timeout); + + clock =sdhci_readw (host,SDHCI_CLOCK_CONTROL ); +if (clock &SDHCI_CLOCK_INT_STABLE ) +break ; +if (timedout) { +pr_err ("%s: PLL clock never stabilised.\n" , +mmc_hostname (host->mmc));
drivers/mmc/host/sdhci-pci-gli.c static void gli_set_gl9763e(struct sdhci_pci_slot *slot) · line 922
Quoted 10 lines
drivers/mmc/host/sdhci-pci-gli.c +10
-0+sdhci_dumpregs (host); +break ; + } +udelay (10 ); + } + clock |=SDHCI_CLOCK_CARD_EN ; +sdhci_writew (host, clock,SDHCI_CLOCK_CONTROL ); + +return 0 ; +}
Both functions above look very similar to what sdhci_set_clock() does. Can you use that, rather than open coding the above?
Other than that, I would appreciate it if Adrian could have a look at this too. For example, I wonder if perhaps sdhci_runtime_suspend|resume_host() should be called in these paths too.
Quoted 18 lines
drivers/mmc/host/sdhci-pci-gli.c +7
-1+#endif +static int gli_probe_slot_gl9763e (struct sdhci_pci_slot *slot) {struct pci_dev *pdev = slot->chip->pdev;@@ -982,6 +1031,11 @@ const struct sdhci_pci_fixes sdhci_gl9763e = {#ifdef CONFIG_PM_SLEEP .resume = sdhci_cqhci_gli_resume, .suspend = sdhci_cqhci_gli_suspend, +#endif +#ifdef CONFIG_PM + .runtime_suspend = gl9763e_runtime_suspend, + .runtime_resume = gl9763e_runtime_resume, + .allow_runtime_pm = true, #endif .add_host = gl9763e_add_host, }; --
Quoted 2 lines
2.35.1
Kind regards
Uffe
Adrian Hunter
maintainerQuoted 55 lines · Ulf Hansson
Quoted 54 lines · Ben Chuang
From: Ben Chuang <[email protected]>
Add runtime PM for GL9763E and disable PLL in runtime suspend. So power gated of upstream port can be enabled.
Signed-off-by Ben Chuang <[email protected]>Tested-by Kevin Chang <[email protected]>--- drivers/mmc/host/sdhci-pci-gli.c | 54 ++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+)drivers/mmc/host/sdhci-pci-gli.c +34
-0@@ -873,6 +873,55 @@ static void gli_set_gl9763e(struct sdhci_pci_slot *slot)pci_write_config_dword (pdev,PCIE_GLI_9763E_VHS , value); } +#ifdef CONFIG_PM +static int gl9763e_runtime_suspend (struct sdhci_pci_chip *chip) +{ +struct sdhci_pci_slot *slot = chip->slots[0 ]; +struct sdhci_host *host = slot->host; +u16 clock; + + clock =sdhci_readw (host,SDHCI_CLOCK_CONTROL ); + clock &= ~(SDHCI_CLOCK_PLL_EN |SDHCI_CLOCK_CARD_EN ); +sdhci_writew (host, clock,SDHCI_CLOCK_CONTROL ); + +return 0 ; +} + +static int gl9763e_runtime_resume (struct sdhci_pci_chip *chip) +{ +struct sdhci_pci_slot *slot = chip->slots[0 ]; +struct sdhci_host *host = slot->host; +ktime_t timeout; +u16 clock; + + clock =sdhci_readw (host,SDHCI_CLOCK_CONTROL ); + + clock |=SDHCI_CLOCK_PLL_EN ; + clock &= ~SDHCI_CLOCK_INT_STABLE ; +sdhci_writew (host, clock,SDHCI_CLOCK_CONTROL ); + + timeout =ktime_add_ms (ktime_get (),150 ); +while (1 ) { +bool timedout =ktime_after (ktime_get (), timeout); + + clock =sdhci_readw (host,SDHCI_CLOCK_CONTROL ); +if (clock &SDHCI_CLOCK_INT_STABLE ) +break ;
Quoted 8 lines
drivers/mmc/host/sdhci-pci-gli.c static void gli_set_gl9763e(struct sdhci_pci_slot *slot) · line 917
Quoted 8 lines
drivers/mmc/host/sdhci-pci-gli.c +8
-0+if (timedout) { +pr_err ("%s: PLL clock never stabilised.\n" , +mmc_hostname (host->mmc)); +sdhci_dumpregs (host); +break ; + } +udelay (10 ); + }
Could use something like read_poll_timeout() here e.g.
if (read_poll_timeout(sdhci_readw, clk, (clk & SDHCI_CLOCK_INT_STABLE),
1000, 150000, false, host, SDHCI_CLOCK_CONTROL)) {
pr_err("%s: PLL clock never stabilised.\n",
mmc_hostname(host->mmc));
sdhci_dumpregs(host);
}Quoted 9 lines
drivers/mmc/host/sdhci-pci-gli.c static void gli_set_gl9763e(struct sdhci_pci_slot *slot) · line 922
Quoted 5 lines
drivers/mmc/host/sdhci-pci-gli.c +5
-0+ clock |=SDHCI_CLOCK_CARD_EN ; +sdhci_writew (host, clock,SDHCI_CLOCK_CONTROL ); + +return 0 ; +}Both functions above look very similar to what
sdhci_set_clock()does. Can you use that, rather than open coding the above?
Quoted 4 lines
Other than that, I would appreciate it if Adrian could have a look at this too. For example, I wonder if perhaps sdhci_runtime_suspend|resume_host() should be called in these paths too.
Assuming the host controller does not lose state information, it should be fine.
Quoted 24 lines
Quoted 19 lines
drivers/mmc/host/sdhci-pci-gli.c +7
-1+#endif +static int gli_probe_slot_gl9763e (struct sdhci_pci_slot *slot) {struct pci_dev *pdev = slot->chip->pdev;@@ -982,6 +1031,11 @@ const struct sdhci_pci_fixes sdhci_gl9763e = {#ifdef CONFIG_PM_SLEEP .resume = sdhci_cqhci_gli_resume, .suspend = sdhci_cqhci_gli_suspend, +#endif +#ifdef CONFIG_PM + .runtime_suspend = gl9763e_runtime_suspend, + .runtime_resume = gl9763e_runtime_resume, + .allow_runtime_pm = true, #endif .add_host = gl9763e_add_host, }; --Quoted 2 lines
2.35.1
Kind regards
Uffe
Hi,
Quoted 68 lines · Adrian Hunter
Quoted 55 lines · Ulf Hansson
Quoted 54 lines · Ben Chuang
From: Ben Chuang <[email protected]>
Add runtime PM for GL9763E and disable PLL in runtime suspend. So power gated of upstream port can be enabled.
Signed-off-by Ben Chuang <[email protected]>Tested-by Kevin Chang <[email protected]>--- drivers/mmc/host/sdhci-pci-gli.c | 54 ++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+)drivers/mmc/host/sdhci-pci-gli.c +34
-0@@ -873,6 +873,55 @@ static void gli_set_gl9763e(struct sdhci_pci_slot *slot)pci_write_config_dword (pdev,PCIE_GLI_9763E_VHS , value); } +#ifdef CONFIG_PM +static int gl9763e_runtime_suspend (struct sdhci_pci_chip *chip) +{ +struct sdhci_pci_slot *slot = chip->slots[0 ]; +struct sdhci_host *host = slot->host; +u16 clock; + + clock =sdhci_readw (host,SDHCI_CLOCK_CONTROL ); + clock &= ~(SDHCI_CLOCK_PLL_EN |SDHCI_CLOCK_CARD_EN ); +sdhci_writew (host, clock,SDHCI_CLOCK_CONTROL ); + +return 0 ; +} + +static int gl9763e_runtime_resume (struct sdhci_pci_chip *chip) +{ +struct sdhci_pci_slot *slot = chip->slots[0 ]; +struct sdhci_host *host = slot->host; +ktime_t timeout; +u16 clock; + + clock =sdhci_readw (host,SDHCI_CLOCK_CONTROL ); + + clock |=SDHCI_CLOCK_PLL_EN ; + clock &= ~SDHCI_CLOCK_INT_STABLE ; +sdhci_writew (host, clock,SDHCI_CLOCK_CONTROL ); + + timeout =ktime_add_ms (ktime_get (),150 ); +while (1 ) { +bool timedout =ktime_after (ktime_get (), timeout); + + clock =sdhci_readw (host,SDHCI_CLOCK_CONTROL ); +if (clock &SDHCI_CLOCK_INT_STABLE ) +break ;Quoted 8 lines
drivers/mmc/host/sdhci-pci-gli.c static void gli_set_gl9763e(struct sdhci_pci_slot *slot) · line 917
Quoted 8 lines
drivers/mmc/host/sdhci-pci-gli.c +8
-0+if (timedout) { +pr_err ("%s: PLL clock never stabilised.\n" , +mmc_hostname (host->mmc)); +sdhci_dumpregs (host); +break ; + } +udelay (10 ); + }Could use something like
read_poll_timeout()here e.g.
Quoted 8 lines
if (read_poll_timeout(sdhci_readw, clk, (clk & SDHCI_CLOCK_INT_STABLE),
1000, 150000, false, host, SDHCI_CLOCK_CONTROL)) {
pr_err("%s: PLL clock never stabilised.\n",
mmc_hostname(host->mmc));
sdhci_dumpregs(host);
}Thanks for the tip. I will prepare the next patch.
Quoted 9 lines
Quoted 9 lines
drivers/mmc/host/sdhci-pci-gli.c static void gli_set_gl9763e(struct sdhci_pci_slot *slot) · line 922
Quoted 5 lines
drivers/mmc/host/sdhci-pci-gli.c +5
-0+ clock |=SDHCI_CLOCK_CARD_EN ; +sdhci_writew (host, clock,SDHCI_CLOCK_CONTROL ); + +return 0 ; +}Both functions above look very similar to what
sdhci_set_clock()does. Can you use that, rather than open coding the above?
The codes turn on/off the clock but it doesn't change the clock. Using sdhci_set_clock() needs to store the clock value because it clears the clock.
Quoted 7 lines
Quoted 4 lines
Other than that, I would appreciate it if Adrian could have a look at this too. For example, I wonder if perhaps sdhci_runtime_suspend|resume_host() should be called in these paths too.
Assuming the host controller does not lose state information, it should be fine.
Yes, the host always has aux. power and keep state.
Thank you both for your comments.
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
drivers/mmc/host/sdhci-pci-gli.c +7
-0+#endif +static int gli_probe_slot_gl9763e (struct sdhci_pci_slot *slot) {struct pci_dev *pdev = slot->chip->pdev;@@ -982,6 +1031,11 @@ const struct sdhci_pci_fixes sdhci_gl9763e = {#ifdef CONFIG_PM_SLEEP .resume = sdhci_cqhci_gli_resume, .suspend = sdhci_cqhci_gli_suspend, +#endif +#ifdef CONFIG_PM + .runtime_suspend = gl9763e_runtime_suspend, + .runtime_resume = gl9763e_runtime_resume, + .allow_runtime_pm = true,#endif
Quoted 9 lines
Quoted 8 lines
Quoted 5 lines
drivers/mmc/host/sdhci-pci-gli.c +0
-1.add_host = gl9763e_add_host, }; --2.35.1
Kind regards
Uffe
Best regards,
Ben
Quoted 93 lines · Ben Chuang
Hi,
Quoted 68 lines · Adrian Hunter
Quoted 55 lines · Ulf Hansson
Quoted 54 lines · Ben Chuang
From: Ben Chuang <[email protected]>
Add runtime PM for GL9763E and disable PLL in runtime suspend. So power gated of upstream port can be enabled.
Signed-off-by Ben Chuang <[email protected]>Tested-by Kevin Chang <[email protected]>--- drivers/mmc/host/sdhci-pci-gli.c | 54 ++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+)drivers/mmc/host/sdhci-pci-gli.c +34
-0@@ -873,6 +873,55 @@ static void gli_set_gl9763e(struct sdhci_pci_slot *slot)pci_write_config_dword (pdev,PCIE_GLI_9763E_VHS , value); } +#ifdef CONFIG_PM +static int gl9763e_runtime_suspend (struct sdhci_pci_chip *chip) +{ +struct sdhci_pci_slot *slot = chip->slots[0 ]; +struct sdhci_host *host = slot->host; +u16 clock; + + clock =sdhci_readw (host,SDHCI_CLOCK_CONTROL ); + clock &= ~(SDHCI_CLOCK_PLL_EN |SDHCI_CLOCK_CARD_EN ); +sdhci_writew (host, clock,SDHCI_CLOCK_CONTROL ); + +return 0 ; +} + +static int gl9763e_runtime_resume (struct sdhci_pci_chip *chip) +{ +struct sdhci_pci_slot *slot = chip->slots[0 ]; +struct sdhci_host *host = slot->host; +ktime_t timeout; +u16 clock; + + clock =sdhci_readw (host,SDHCI_CLOCK_CONTROL ); + + clock |=SDHCI_CLOCK_PLL_EN ; + clock &= ~SDHCI_CLOCK_INT_STABLE ; +sdhci_writew (host, clock,SDHCI_CLOCK_CONTROL ); + + timeout =ktime_add_ms (ktime_get (),150 ); +while (1 ) { +bool timedout =ktime_after (ktime_get (), timeout); + + clock =sdhci_readw (host,SDHCI_CLOCK_CONTROL ); +if (clock &SDHCI_CLOCK_INT_STABLE ) +break ;Quoted 8 lines
drivers/mmc/host/sdhci-pci-gli.c static void gli_set_gl9763e(struct sdhci_pci_slot *slot) · line 917
Quoted 8 lines
drivers/mmc/host/sdhci-pci-gli.c +8
-0+if (timedout) { +pr_err ("%s: PLL clock never stabilised.\n" , +mmc_hostname (host->mmc)); +sdhci_dumpregs (host); +break ; + } +udelay (10 ); + }Could use something like
read_poll_timeout()here e.g.Quoted 8 lines
if (read_poll_timeout(sdhci_readw, clk, (clk & SDHCI_CLOCK_INT_STABLE), 1000, 150000, false, host, SDHCI_CLOCK_CONTROL)) { pr_err("%s: PLL clock never stabilised.\n", mmc_hostname(host->mmc)); sdhci_dumpregs(host); }Thanks for the tip. I will prepare the next patch.
Quoted 9 lines
Quoted 9 lines
drivers/mmc/host/sdhci-pci-gli.c static void gli_set_gl9763e(struct sdhci_pci_slot *slot) · line 922
Quoted 5 lines
drivers/mmc/host/sdhci-pci-gli.c +5
-0+ clock |=SDHCI_CLOCK_CARD_EN ; +sdhci_writew (host, clock,SDHCI_CLOCK_CONTROL ); + +return 0 ; +}Both functions above look very similar to what
sdhci_set_clock()does. Can you use that, rather than open coding the above?
Quoted 3 lines
The codes turn on/off the clock but it doesn't change the clock. Using
sdhci_set_clock()needs to store the clock value because it clears the clock.
Well, in that case at least you can call sdhci_enable_clk() from gl9763e_runtime_resume(), rather than open coding it (the code looks like a direct copy of that code). All you need is to give the sdhci_enable_clk() the correct "clk" as in-parameter.
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Other than that, I would appreciate it if Adrian could have a look at this too. For example, I wonder if perhaps sdhci_runtime_suspend|resume_host() should be called in these paths too.
Quoted 6 lines
Quoted 2 lines
Assuming the host controller does not lose state information, it should be fine.
Yes, the host always has aux. power and keep state.
Thank you both for your comments.
Okay, thanks for confirming!
[...]
Kind regards
Uffe
A message that is not in the archive (sent off-list or not yet received): CACT4zj_6k=0gNRw=EFHR=9-7fWJ=bT4Q1VsPMWrkVPftjLb=Hw@mail.gmail.com
Hi,
Quoted 95 lines · Ulf Hansson
Quoted 93 lines · Ben Chuang
Hi,
Quoted 68 lines · Adrian Hunter
Quoted 55 lines · Ulf Hansson
Quoted 54 lines · Ben Chuang
From: Ben Chuang <[email protected]>
Add runtime PM for GL9763E and disable PLL in runtime suspend. So power gated of upstream port can be enabled.
Signed-off-by Ben Chuang <[email protected]>Tested-by Kevin Chang <[email protected]>--- drivers/mmc/host/sdhci-pci-gli.c | 54 ++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+)drivers/mmc/host/sdhci-pci-gli.c +34
-0@@ -873,6 +873,55 @@ static void gli_set_gl9763e(struct sdhci_pci_slot *slot)pci_write_config_dword (pdev,PCIE_GLI_9763E_VHS , value); } +#ifdef CONFIG_PM +static int gl9763e_runtime_suspend (struct sdhci_pci_chip *chip) +{ +struct sdhci_pci_slot *slot = chip->slots[0 ]; +struct sdhci_host *host = slot->host; +u16 clock; + + clock =sdhci_readw (host,SDHCI_CLOCK_CONTROL ); + clock &= ~(SDHCI_CLOCK_PLL_EN |SDHCI_CLOCK_CARD_EN ); +sdhci_writew (host, clock,SDHCI_CLOCK_CONTROL ); + +return 0 ; +} + +static int gl9763e_runtime_resume (struct sdhci_pci_chip *chip) +{ +struct sdhci_pci_slot *slot = chip->slots[0 ]; +struct sdhci_host *host = slot->host; +ktime_t timeout; +u16 clock; + + clock =sdhci_readw (host,SDHCI_CLOCK_CONTROL ); + + clock |=SDHCI_CLOCK_PLL_EN ; + clock &= ~SDHCI_CLOCK_INT_STABLE ; +sdhci_writew (host, clock,SDHCI_CLOCK_CONTROL ); + + timeout =ktime_add_ms (ktime_get (),150 ); +while (1 ) { +bool timedout =ktime_after (ktime_get (), timeout); + + clock =sdhci_readw (host,SDHCI_CLOCK_CONTROL ); +if (clock &SDHCI_CLOCK_INT_STABLE ) +break ;Quoted 8 lines
drivers/mmc/host/sdhci-pci-gli.c static void gli_set_gl9763e(struct sdhci_pci_slot *slot) · line 917
Quoted 8 lines
drivers/mmc/host/sdhci-pci-gli.c +8
-0+if (timedout) { +pr_err ("%s: PLL clock never stabilised.\n" , +mmc_hostname (host->mmc)); +sdhci_dumpregs (host); +break ; + } +udelay (10 ); + }Could use something like
read_poll_timeout()here e.g.Quoted 8 lines
if (read_poll_timeout(sdhci_readw, clk, (clk & SDHCI_CLOCK_INT_STABLE), 1000, 150000, false, host, SDHCI_CLOCK_CONTROL)) { pr_err("%s: PLL clock never stabilised.\n", mmc_hostname(host->mmc)); sdhci_dumpregs(host); }Thanks for the tip. I will prepare the next patch.
Quoted 9 lines
Quoted 9 lines
drivers/mmc/host/sdhci-pci-gli.c static void gli_set_gl9763e(struct sdhci_pci_slot *slot) · line 922
Quoted 5 lines
drivers/mmc/host/sdhci-pci-gli.c +5
-0+ clock |=SDHCI_CLOCK_CARD_EN ; +sdhci_writew (host, clock,SDHCI_CLOCK_CONTROL ); + +return 0 ; +}Both functions above look very similar to what
sdhci_set_clock()does. Can you use that, rather than open coding the above?
Quoted 9 lines
Quoted 3 lines
The codes turn on/off the clock but it doesn't change the clock. Using
sdhci_set_clock()needs to store the clock value because it clears the clock.Well, in that case at least you can call
sdhci_enable_clk()fromgl9763e_runtime_resume(), rather than open coding it (the code looks like a direct copy of that code). All you need is to give thesdhci_enable_clk()the correct "clk" as in-parameter.
I want to explain a little more,
gl9763e is used as a boot disk controller.
In gl9763e_runtime_suspend(), gl9763e still needs the internal clock to keep states.
So gl9763e_runtime_suspend() only clears SDHCI_CLOCK_PLL_EN and SDHCI_CLOCK_CARD_EN.
The SDHCI_CLOCK_INT_EN is still one (1) In runtime suspend,
If using sdhci_enable_clk() in gl9763e_runtime_resume(), sdhci_enable_clk() only fills one (1) to this bit (SDHCI_CLOCK_INT_EN) again, it cannot cause internal stable bit
(SDHCI_CLOCK_INT_STABLE) to one for gl9763e in the first while loop.
Quoted 11 lines
Quoted 11 lines
Quoted 8 lines
Quoted 5 lines
Other than that, I would appreciate it if Adrian could have a look at this too. For example, I wonder if perhaps sdhci_runtime_suspend|resume_host() should be called in these paths too.
Assuming the host controller does not lose state information, it should be fine.
Yes, the host always has aux. power and keep state.
Quoted 8 lines
Quoted 1 line
Thank you both for your comments.
Okay, thanks for confirming!
[...]
Kind regards
Uffe
Best regards,
Ben
Quoted 115 lines · Ben Chuang
Hi,
Quoted 95 lines · Ulf Hansson
Quoted 93 lines · Ben Chuang
Hi,
Quoted 68 lines · Adrian Hunter
Quoted 55 lines · Ulf Hansson
Quoted 54 lines · Ben Chuang
From: Ben Chuang <[email protected]>
Add runtime PM for GL9763E and disable PLL in runtime suspend. So power gated of upstream port can be enabled.
Signed-off-by Ben Chuang <[email protected]>Tested-by Kevin Chang <[email protected]>--- drivers/mmc/host/sdhci-pci-gli.c | 54 ++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+)drivers/mmc/host/sdhci-pci-gli.c +34
-0@@ -873,6 +873,55 @@ static void gli_set_gl9763e(struct sdhci_pci_slot *slot)pci_write_config_dword (pdev,PCIE_GLI_9763E_VHS , value); } +#ifdef CONFIG_PM +static int gl9763e_runtime_suspend (struct sdhci_pci_chip *chip) +{ +struct sdhci_pci_slot *slot = chip->slots[0 ]; +struct sdhci_host *host = slot->host; +u16 clock; + + clock =sdhci_readw (host,SDHCI_CLOCK_CONTROL ); + clock &= ~(SDHCI_CLOCK_PLL_EN |SDHCI_CLOCK_CARD_EN ); +sdhci_writew (host, clock,SDHCI_CLOCK_CONTROL ); + +return 0 ; +} + +static int gl9763e_runtime_resume (struct sdhci_pci_chip *chip) +{ +struct sdhci_pci_slot *slot = chip->slots[0 ]; +struct sdhci_host *host = slot->host; +ktime_t timeout; +u16 clock; + + clock =sdhci_readw (host,SDHCI_CLOCK_CONTROL ); + + clock |=SDHCI_CLOCK_PLL_EN ; + clock &= ~SDHCI_CLOCK_INT_STABLE ; +sdhci_writew (host, clock,SDHCI_CLOCK_CONTROL ); + + timeout =ktime_add_ms (ktime_get (),150 ); +while (1 ) { +bool timedout =ktime_after (ktime_get (), timeout); + + clock =sdhci_readw (host,SDHCI_CLOCK_CONTROL ); +if (clock &SDHCI_CLOCK_INT_STABLE ) +break ;Quoted 8 lines
drivers/mmc/host/sdhci-pci-gli.c static void gli_set_gl9763e(struct sdhci_pci_slot *slot) · line 917
Quoted 8 lines
drivers/mmc/host/sdhci-pci-gli.c +8
-0+if (timedout) { +pr_err ("%s: PLL clock never stabilised.\n" , +mmc_hostname (host->mmc)); +sdhci_dumpregs (host); +break ; + } +udelay (10 ); + }Could use something like
read_poll_timeout()here e.g.Quoted 8 lines
if (read_poll_timeout(sdhci_readw, clk, (clk & SDHCI_CLOCK_INT_STABLE), 1000, 150000, false, host, SDHCI_CLOCK_CONTROL)) { pr_err("%s: PLL clock never stabilised.\n", mmc_hostname(host->mmc)); sdhci_dumpregs(host); }Thanks for the tip. I will prepare the next patch.
Quoted 9 lines
Quoted 9 lines
drivers/mmc/host/sdhci-pci-gli.c static void gli_set_gl9763e(struct sdhci_pci_slot *slot) · line 922
Quoted 5 lines
drivers/mmc/host/sdhci-pci-gli.c +5
-0+ clock |=SDHCI_CLOCK_CARD_EN ; +sdhci_writew (host, clock,SDHCI_CLOCK_CONTROL ); + +return 0 ; +}Both functions above look very similar to what
sdhci_set_clock()does. Can you use that, rather than open coding the above?Quoted 9 lines
Quoted 3 lines
The codes turn on/off the clock but it doesn't change the clock. Using
sdhci_set_clock()needs to store the clock value because it clears the clock.Well, in that case at least you can call
sdhci_enable_clk()fromgl9763e_runtime_resume(), rather than open coding it (the code looks like a direct copy of that code). All you need is to give thesdhci_enable_clk()the correct "clk" as in-parameter.I want to explain a little more,
gl9763e is used as a boot disk controller.
Ingl9763e_runtime_suspend(), gl9763e still needs the internal clock to keep states. Sogl9763e_runtime_suspend()only clearsSDHCI_CLOCK_PLL_ENandSDHCI_CLOCK_CARD_EN. TheSDHCI_CLOCK_INT_ENis still one (1) In runtime suspend,
Quoted 3 lines
If using
sdhci_enable_clk()ingl9763e_runtime_resume(),sdhci_enable_clk()only fills one (1) to this bit (SDHCI_CLOCK_INT_EN) again, it cannot cause internal stable bit (SDHCI_CLOCK_INT_STABLE) to one for gl9763e in the first while loop.
Okay, I get it now, thanks for clarifying.
In any case, the loop in sdhci_enable_clk() that polls the SDHCI_CLOCK_CONTROL register to see if the SDHCI_CLOCK_INT_STABLE is set, could perhaps be split out to a function that you can use here as well.
[...]
Kind regards
Uffe