Skip to content

Commit 46f4a69

Browse files
ahunter6Ulf Hansson
authored andcommitted
mmc: sdhci: Add LTR support for some Intel BYT based controllers
Some Intel BYT based host controllers support the setting of latency tolerance. Accordingly, implement the PM QoS ->set_latency_tolerance() callback. The raw register values are also exposed via debugfs. Intel EHL controllers require this support. Signed-off-by: Adrian Hunter <adrian.hunter@intel.com> Fixes: cb3a7d4 ("mmc: sdhci-pci: Add support for Intel EHL") Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/20200818104508.7149-1-adrian.hunter@intel.com Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
1 parent c92a6af commit 46f4a69

1 file changed

Lines changed: 154 additions & 0 deletions

File tree

‎drivers/mmc/host/sdhci-pci-core.c‎

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
#include <linux/iopoll.h>
2525
#include <linux/gpio.h>
2626
#include <linux/pm_runtime.h>
27+
#include <linux/pm_qos.h>
28+
#include <linux/debugfs.h>
2729
#include <linux/mmc/slot-gpio.h>
2830
#include <linux/mmc/sdhci-pci-data.h>
2931
#include <linux/acpi.h>
@@ -516,6 +518,8 @@ struct intel_host {
516518
bool rpm_retune_ok;
517519
u32 glk_rx_ctrl1;
518520
u32 glk_tun_val;
521+
u32 active_ltr;
522+
u32 idle_ltr;
519523
};
520524

521525
static const guid_t intel_dsm_guid =
@@ -760,6 +764,108 @@ static int intel_execute_tuning(struct mmc_host *mmc, u32 opcode)
760764
return 0;
761765
}
762766

767+
#define INTEL_ACTIVELTR 0x804
768+
#define INTEL_IDLELTR 0x808
769+
770+
#define INTEL_LTR_REQ BIT(15)
771+
#define INTEL_LTR_SCALE_MASK GENMASK(11, 10)
772+
#define INTEL_LTR_SCALE_1US (2 << 10)
773+
#define INTEL_LTR_SCALE_32US (3 << 10)
774+
#define INTEL_LTR_VALUE_MASK GENMASK(9, 0)
775+
776+
static void intel_cache_ltr(struct sdhci_pci_slot *slot)
777+
{
778+
struct intel_host *intel_host = sdhci_pci_priv(slot);
779+
struct sdhci_host *host = slot->host;
780+
781+
intel_host->active_ltr = readl(host->ioaddr + INTEL_ACTIVELTR);
782+
intel_host->idle_ltr = readl(host->ioaddr + INTEL_IDLELTR);
783+
}
784+
785+
static void intel_ltr_set(struct device *dev, s32 val)
786+
{
787+
struct sdhci_pci_chip *chip = dev_get_drvdata(dev);
788+
struct sdhci_pci_slot *slot = chip->slots[0];
789+
struct intel_host *intel_host = sdhci_pci_priv(slot);
790+
struct sdhci_host *host = slot->host;
791+
u32 ltr;
792+
793+
pm_runtime_get_sync(dev);
794+
795+
/*
796+
* Program latency tolerance (LTR) accordingly what has been asked
797+
* by the PM QoS layer or disable it in case we were passed
798+
* negative value or PM_QOS_LATENCY_ANY.
799+
*/
800+
ltr = readl(host->ioaddr + INTEL_ACTIVELTR);
801+
802+
if (val == PM_QOS_LATENCY_ANY || val < 0) {
803+
ltr &= ~INTEL_LTR_REQ;
804+
} else {
805+
ltr |= INTEL_LTR_REQ;
806+
ltr &= ~INTEL_LTR_SCALE_MASK;
807+
ltr &= ~INTEL_LTR_VALUE_MASK;
808+
809+
if (val > INTEL_LTR_VALUE_MASK) {
810+
val >>= 5;
811+
if (val > INTEL_LTR_VALUE_MASK)
812+
val = INTEL_LTR_VALUE_MASK;
813+
ltr |= INTEL_LTR_SCALE_32US | val;
814+
} else {
815+
ltr |= INTEL_LTR_SCALE_1US | val;
816+
}
817+
}
818+
819+
if (ltr == intel_host->active_ltr)
820+
goto out;
821+
822+
writel(ltr, host->ioaddr + INTEL_ACTIVELTR);
823+
writel(ltr, host->ioaddr + INTEL_IDLELTR);
824+
825+
/* Cache the values into lpss structure */
826+
intel_cache_ltr(slot);
827+
out:
828+
pm_runtime_put_autosuspend(dev);
829+
}
830+
831+
static bool intel_use_ltr(struct sdhci_pci_chip *chip)
832+
{
833+
switch (chip->pdev->device) {
834+
case PCI_DEVICE_ID_INTEL_BYT_EMMC:
835+
case PCI_DEVICE_ID_INTEL_BYT_EMMC2:
836+
case PCI_DEVICE_ID_INTEL_BYT_SDIO:
837+
case PCI_DEVICE_ID_INTEL_BYT_SD:
838+
case PCI_DEVICE_ID_INTEL_BSW_EMMC:
839+
case PCI_DEVICE_ID_INTEL_BSW_SDIO:
840+
case PCI_DEVICE_ID_INTEL_BSW_SD:
841+
return false;
842+
default:
843+
return true;
844+
}
845+
}
846+
847+
static void intel_ltr_expose(struct sdhci_pci_chip *chip)
848+
{
849+
struct device *dev = &chip->pdev->dev;
850+
851+
if (!intel_use_ltr(chip))
852+
return;
853+
854+
dev->power.set_latency_tolerance = intel_ltr_set;
855+
dev_pm_qos_expose_latency_tolerance(dev);
856+
}
857+
858+
static void intel_ltr_hide(struct sdhci_pci_chip *chip)
859+
{
860+
struct device *dev = &chip->pdev->dev;
861+
862+
if (!intel_use_ltr(chip))
863+
return;
864+
865+
dev_pm_qos_hide_latency_tolerance(dev);
866+
dev->power.set_latency_tolerance = NULL;
867+
}
868+
763869
static void byt_probe_slot(struct sdhci_pci_slot *slot)
764870
{
765871
struct mmc_host_ops *ops = &slot->host->mmc_host_ops;
@@ -774,6 +880,43 @@ static void byt_probe_slot(struct sdhci_pci_slot *slot)
774880
ops->start_signal_voltage_switch = intel_start_signal_voltage_switch;
775881

776882
device_property_read_u32(dev, "max-frequency", &mmc->f_max);
883+
884+
if (!mmc->slotno) {
885+
slot->chip->slots[mmc->slotno] = slot;
886+
intel_ltr_expose(slot->chip);
887+
}
888+
}
889+
890+
static void byt_add_debugfs(struct sdhci_pci_slot *slot)
891+
{
892+
struct intel_host *intel_host = sdhci_pci_priv(slot);
893+
struct mmc_host *mmc = slot->host->mmc;
894+
struct dentry *dir = mmc->debugfs_root;
895+
896+
if (!intel_use_ltr(slot->chip))
897+
return;
898+
899+
debugfs_create_x32("active_ltr", 0444, dir, &intel_host->active_ltr);
900+
debugfs_create_x32("idle_ltr", 0444, dir, &intel_host->idle_ltr);
901+
902+
intel_cache_ltr(slot);
903+
}
904+
905+
static int byt_add_host(struct sdhci_pci_slot *slot)
906+
{
907+
int ret = sdhci_add_host(slot->host);
908+
909+
if (!ret)
910+
byt_add_debugfs(slot);
911+
return ret;
912+
}
913+
914+
static void byt_remove_slot(struct sdhci_pci_slot *slot, int dead)
915+
{
916+
struct mmc_host *mmc = slot->host->mmc;
917+
918+
if (!mmc->slotno)
919+
intel_ltr_hide(slot->chip);
777920
}
778921

779922
static int byt_emmc_probe_slot(struct sdhci_pci_slot *slot)
@@ -854,6 +997,8 @@ static int glk_emmc_add_host(struct sdhci_pci_slot *slot)
854997
if (ret)
855998
goto cleanup;
856999

1000+
byt_add_debugfs(slot);
1001+
8571002
return 0;
8581003

8591004
cleanup:
@@ -1031,6 +1176,8 @@ static const struct sdhci_pci_fixes sdhci_intel_byt_emmc = {
10311176
#endif
10321177
.allow_runtime_pm = true,
10331178
.probe_slot = byt_emmc_probe_slot,
1179+
.add_host = byt_add_host,
1180+
.remove_slot = byt_remove_slot,
10341181
.quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC |
10351182
SDHCI_QUIRK_NO_LED,
10361183
.quirks2 = SDHCI_QUIRK2_PRESET_VALUE_BROKEN |
@@ -1044,6 +1191,7 @@ static const struct sdhci_pci_fixes sdhci_intel_glk_emmc = {
10441191
.allow_runtime_pm = true,
10451192
.probe_slot = glk_emmc_probe_slot,
10461193
.add_host = glk_emmc_add_host,
1194+
.remove_slot = byt_remove_slot,
10471195
#ifdef CONFIG_PM_SLEEP
10481196
.suspend = sdhci_cqhci_suspend,
10491197
.resume = sdhci_cqhci_resume,
@@ -1074,6 +1222,8 @@ static const struct sdhci_pci_fixes sdhci_ni_byt_sdio = {
10741222
SDHCI_QUIRK2_PRESET_VALUE_BROKEN,
10751223
.allow_runtime_pm = true,
10761224
.probe_slot = ni_byt_sdio_probe_slot,
1225+
.add_host = byt_add_host,
1226+
.remove_slot = byt_remove_slot,
10771227
.ops = &sdhci_intel_byt_ops,
10781228
.priv_size = sizeof(struct intel_host),
10791229
};
@@ -1091,6 +1241,8 @@ static const struct sdhci_pci_fixes sdhci_intel_byt_sdio = {
10911241
SDHCI_QUIRK2_PRESET_VALUE_BROKEN,
10921242
.allow_runtime_pm = true,
10931243
.probe_slot = byt_sdio_probe_slot,
1244+
.add_host = byt_add_host,
1245+
.remove_slot = byt_remove_slot,
10941246
.ops = &sdhci_intel_byt_ops,
10951247
.priv_size = sizeof(struct intel_host),
10961248
};
@@ -1110,6 +1262,8 @@ static const struct sdhci_pci_fixes sdhci_intel_byt_sd = {
11101262
.allow_runtime_pm = true,
11111263
.own_cd_for_runtime_pm = true,
11121264
.probe_slot = byt_sd_probe_slot,
1265+
.add_host = byt_add_host,
1266+
.remove_slot = byt_remove_slot,
11131267
.ops = &sdhci_intel_byt_ops,
11141268
.priv_size = sizeof(struct intel_host),
11151269
};

0 commit comments

Comments
 (0)