Skip to content

Commit c3ed387

Browse files
amd-anathcjb
authored andcommitted
mmc: sdhci: add support for programmable clock mode
Host Controller v3.00 supports programmable clock mode as an optional feature. The support for this mode is indicated by non-zero value in bits 48-55 of the Capabilities register. If supported, the actual value of Clock Multiplier is one more than the value provided in the bit fields. We only set Clock Generator Select (bit 5) and SDCLK Frequency Select (bits 8-15) of the Clock Control register in case Preset Value Enable is not set, otherwise these fields are automatically set by the Host Controller based on the UHS mode selected. Also, since the maximum and minimum clock frequency in this mode can be (Base Clock * Clock Mul) and (Base Clock * Clock Mul)/1024 respectively, f_max and f_min have been recalculated to reflect this change. Tested by Zhangfei Gao with a Toshiba uhs card and general hs card, on mmp2 in SDMA mode. Signed-off-by: Arindam Nath <arindam.nath@amd.com> Reviewed-by: Philip Rakity <prakity@marvell.com> Tested-by: Philip Rakity <prakity@marvell.com> Acked-by: Zhangfei Gao <zhangfei.gao@marvell.com> Signed-off-by: Chris Ball <cjb@laptop.org>
1 parent 4d55c5a commit c3ed387

3 files changed

Lines changed: 70 additions & 15 deletions

File tree

‎drivers/mmc/host/sdhci.c‎

Lines changed: 66 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,8 +1013,8 @@ static void sdhci_finish_command(struct sdhci_host *host)
10131013

10141014
static void sdhci_set_clock(struct sdhci_host *host, unsigned int clock)
10151015
{
1016-
int div;
1017-
u16 clk;
1016+
int div = 0; /* Initialized for compiler warning */
1017+
u16 clk = 0;
10181018
unsigned long timeout;
10191019

10201020
if (clock == host->clock)
@@ -1032,25 +1032,56 @@ static void sdhci_set_clock(struct sdhci_host *host, unsigned int clock)
10321032
goto out;
10331033

10341034
if (host->version >= SDHCI_SPEC_300) {
1035-
/* Version 3.00 divisors must be a multiple of 2. */
1036-
if (host->max_clk <= clock)
1037-
div = 1;
1038-
else {
1039-
for (div = 2; div < SDHCI_MAX_DIV_SPEC_300; div += 2) {
1040-
if ((host->max_clk / div) <= clock)
1041-
break;
1035+
/*
1036+
* Check if the Host Controller supports Programmable Clock
1037+
* Mode.
1038+
*/
1039+
if (host->clk_mul) {
1040+
u16 ctrl;
1041+
1042+
/*
1043+
* We need to figure out whether the Host Driver needs
1044+
* to select Programmable Clock Mode, or the value can
1045+
* be set automatically by the Host Controller based on
1046+
* the Preset Value registers.
1047+
*/
1048+
ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2);
1049+
if (!(ctrl & SDHCI_CTRL_PRESET_VAL_ENABLE)) {
1050+
for (div = 1; div <= 1024; div++) {
1051+
if (((host->max_clk * host->clk_mul) /
1052+
div) <= clock)
1053+
break;
1054+
}
1055+
/*
1056+
* Set Programmable Clock Mode in the Clock
1057+
* Control register.
1058+
*/
1059+
clk = SDHCI_PROG_CLOCK_MODE;
1060+
div--;
1061+
}
1062+
} else {
1063+
/* Version 3.00 divisors must be a multiple of 2. */
1064+
if (host->max_clk <= clock)
1065+
div = 1;
1066+
else {
1067+
for (div = 2; div < SDHCI_MAX_DIV_SPEC_300;
1068+
div += 2) {
1069+
if ((host->max_clk / div) <= clock)
1070+
break;
1071+
}
10421072
}
1073+
div >>= 1;
10431074
}
10441075
} else {
10451076
/* Version 2.00 divisors must be a power of 2. */
10461077
for (div = 1; div < SDHCI_MAX_DIV_SPEC_200; div *= 2) {
10471078
if ((host->max_clk / div) <= clock)
10481079
break;
10491080
}
1081+
div >>= 1;
10501082
}
1051-
div >>= 1;
10521083

1053-
clk = (div & SDHCI_DIV_MASK) << SDHCI_DIVIDER_SHIFT;
1084+
clk |= (div & SDHCI_DIV_MASK) << SDHCI_DIVIDER_SHIFT;
10541085
clk |= ((div & SDHCI_DIV_HI_MASK) >> SDHCI_DIV_MASK_LEN)
10551086
<< SDHCI_DIVIDER_HI_SHIFT;
10561087
clk |= SDHCI_CLOCK_INT_EN;
@@ -2307,18 +2338,38 @@ int sdhci_add_host(struct sdhci_host *host)
23072338
if (caps[0] & SDHCI_TIMEOUT_CLK_UNIT)
23082339
host->timeout_clk *= 1000;
23092340

2341+
/*
2342+
* In case of Host Controller v3.00, find out whether clock
2343+
* multiplier is supported.
2344+
*/
2345+
host->clk_mul = (caps[1] & SDHCI_CLOCK_MUL_MASK) >>
2346+
SDHCI_CLOCK_MUL_SHIFT;
2347+
2348+
/*
2349+
* In case the value in Clock Multiplier is 0, then programmable
2350+
* clock mode is not supported, otherwise the actual clock
2351+
* multiplier is one more than the value of Clock Multiplier
2352+
* in the Capabilities Register.
2353+
*/
2354+
if (host->clk_mul)
2355+
host->clk_mul += 1;
2356+
23102357
/*
23112358
* Set host parameters.
23122359
*/
23132360
mmc->ops = &sdhci_ops;
2361+
mmc->f_max = host->max_clk;
23142362
if (host->ops->get_min_clock)
23152363
mmc->f_min = host->ops->get_min_clock(host);
2316-
else if (host->version >= SDHCI_SPEC_300)
2317-
mmc->f_min = host->max_clk / SDHCI_MAX_DIV_SPEC_300;
2318-
else
2364+
else if (host->version >= SDHCI_SPEC_300) {
2365+
if (host->clk_mul) {
2366+
mmc->f_min = (host->max_clk * host->clk_mul) / 1024;
2367+
mmc->f_max = host->max_clk * host->clk_mul;
2368+
} else
2369+
mmc->f_min = host->max_clk / SDHCI_MAX_DIV_SPEC_300;
2370+
} else
23192371
mmc->f_min = host->max_clk / SDHCI_MAX_DIV_SPEC_200;
23202372

2321-
mmc->f_max = host->max_clk;
23222373
mmc->caps |= MMC_CAP_SDIO_IRQ | MMC_CAP_ERASE;
23232374

23242375
/*

‎drivers/mmc/host/sdhci.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
#define SDHCI_DIV_MASK 0xFF
102102
#define SDHCI_DIV_MASK_LEN 8
103103
#define SDHCI_DIV_HI_MASK 0x300
104+
#define SDHCI_PROG_CLOCK_MODE 0x0020
104105
#define SDHCI_CLOCK_CARD_EN 0x0004
105106
#define SDHCI_CLOCK_INT_STABLE 0x0002
106107
#define SDHCI_CLOCK_INT_EN 0x0001
@@ -191,6 +192,8 @@
191192
#define SDHCI_DRIVER_TYPE_C 0x00000020
192193
#define SDHCI_DRIVER_TYPE_D 0x00000040
193194
#define SDHCI_USE_SDR50_TUNING 0x00002000
195+
#define SDHCI_CLOCK_MUL_MASK 0x00FF0000
196+
#define SDHCI_CLOCK_MUL_SHIFT 16
194197

195198
#define SDHCI_CAPABILITIES_1 0x44
196199

‎include/linux/mmc/sdhci.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ struct sdhci_host {
117117

118118
unsigned int max_clk; /* Max possible freq (MHz) */
119119
unsigned int timeout_clk; /* Timeout freq (KHz) */
120+
unsigned int clk_mul; /* Clock Muliplier value */
120121

121122
unsigned int clock; /* Current clock (MHz) */
122123
u8 pwr; /* Current voltage */

0 commit comments

Comments
 (0)