Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mmc: sdhci-pci: Add support for HS200 tuning mode on AMD, eMMC-4.5.1

This patch adds support for HS200 tuning mode on AMD eMMC-4.5.1

Reviewed-by: Sen, Pankaj <Pankaj.Sen@amd.com>
Reviewed-by: Shah, Nehal-bakulchandra <Nehal-bakulchandra.Shah@amd.com>
Reviewed-by: Agrawal, Nitesh-kumar <Nitesh-kumar.Agrawal@amd.com>
Signed-off-by: S-k, Shyam-sundar <Shyam-sundar.S-k@amd.com>
Acked-by: Adrian Hunter <adrian.hunter@intel.com>
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>

authored by

Shyam Sundar S K and committed by
Ulf Hansson
c31165d7 8336bf68

+91 -3
+91 -3
drivers/mmc/host/sdhci-pci-core.c
··· 865 865 AMD_CHIPSET_UNKNOWN, 866 866 }; 867 867 868 + /* AMD registers */ 869 + #define AMD_SD_AUTO_PATTERN 0xB8 870 + #define AMD_MSLEEP_DURATION 4 871 + #define AMD_SD_MISC_CONTROL 0xD0 872 + #define AMD_MAX_TUNE_VALUE 0x0B 873 + #define AMD_AUTO_TUNE_SEL 0x10800 874 + #define AMD_FIFO_PTR 0x30 875 + #define AMD_BIT_MASK 0x1F 876 + 877 + static void amd_tuning_reset(struct sdhci_host *host) 878 + { 879 + unsigned int val; 880 + 881 + val = sdhci_readw(host, SDHCI_HOST_CONTROL2); 882 + val |= SDHCI_CTRL_PRESET_VAL_ENABLE | SDHCI_CTRL_EXEC_TUNING; 883 + sdhci_writew(host, val, SDHCI_HOST_CONTROL2); 884 + 885 + val = sdhci_readw(host, SDHCI_HOST_CONTROL2); 886 + val &= ~SDHCI_CTRL_EXEC_TUNING; 887 + sdhci_writew(host, val, SDHCI_HOST_CONTROL2); 888 + } 889 + 890 + static void amd_config_tuning_phase(struct pci_dev *pdev, u8 phase) 891 + { 892 + unsigned int val; 893 + 894 + pci_read_config_dword(pdev, AMD_SD_AUTO_PATTERN, &val); 895 + val &= ~AMD_BIT_MASK; 896 + val |= (AMD_AUTO_TUNE_SEL | (phase << 1)); 897 + pci_write_config_dword(pdev, AMD_SD_AUTO_PATTERN, val); 898 + } 899 + 900 + static void amd_enable_manual_tuning(struct pci_dev *pdev) 901 + { 902 + unsigned int val; 903 + 904 + pci_read_config_dword(pdev, AMD_SD_MISC_CONTROL, &val); 905 + val |= AMD_FIFO_PTR; 906 + pci_write_config_dword(pdev, AMD_SD_MISC_CONTROL, val); 907 + } 908 + 909 + static int amd_execute_tuning(struct sdhci_host *host, u32 opcode) 910 + { 911 + struct sdhci_pci_slot *slot = sdhci_priv(host); 912 + struct pci_dev *pdev = slot->chip->pdev; 913 + u8 valid_win = 0; 914 + u8 valid_win_max = 0; 915 + u8 valid_win_end = 0; 916 + u8 ctrl, tune_around; 917 + 918 + amd_tuning_reset(host); 919 + 920 + for (tune_around = 0; tune_around < 12; tune_around++) { 921 + amd_config_tuning_phase(pdev, tune_around); 922 + 923 + if (mmc_send_tuning(host->mmc, opcode, NULL)) { 924 + valid_win = 0; 925 + msleep(AMD_MSLEEP_DURATION); 926 + ctrl = SDHCI_RESET_CMD | SDHCI_RESET_DATA; 927 + sdhci_writeb(host, ctrl, SDHCI_SOFTWARE_RESET); 928 + } else if (++valid_win > valid_win_max) { 929 + valid_win_max = valid_win; 930 + valid_win_end = tune_around; 931 + } 932 + } 933 + 934 + if (!valid_win_max) { 935 + dev_err(&pdev->dev, "no tuning point found\n"); 936 + return -EIO; 937 + } 938 + 939 + amd_config_tuning_phase(pdev, valid_win_end - valid_win_max / 2); 940 + 941 + amd_enable_manual_tuning(pdev); 942 + 943 + host->mmc->retune_period = 0; 944 + 945 + return 0; 946 + } 947 + 868 948 static int amd_probe(struct sdhci_pci_chip *chip) 869 949 { 870 950 struct pci_dev *smbus_dev; ··· 967 887 } 968 888 } 969 889 970 - if ((gen == AMD_CHIPSET_BEFORE_ML) || (gen == AMD_CHIPSET_CZ)) { 890 + if (gen == AMD_CHIPSET_BEFORE_ML || gen == AMD_CHIPSET_CZ) 971 891 chip->quirks2 |= SDHCI_QUIRK2_CLEAR_TRANSFERMODE_REG_BEFORE_CMD; 972 - chip->quirks2 |= SDHCI_QUIRK2_BROKEN_HS200; 973 - } 974 892 975 893 return 0; 976 894 } 977 895 896 + static const struct sdhci_ops amd_sdhci_pci_ops = { 897 + .set_clock = sdhci_set_clock, 898 + .enable_dma = sdhci_pci_enable_dma, 899 + .set_bus_width = sdhci_pci_set_bus_width, 900 + .reset = sdhci_reset, 901 + .set_uhs_signaling = sdhci_set_uhs_signaling, 902 + .platform_execute_tuning = amd_execute_tuning, 903 + }; 904 + 978 905 static const struct sdhci_pci_fixes sdhci_amd = { 979 906 .probe = amd_probe, 907 + .ops = &amd_sdhci_pci_ops, 980 908 }; 981 909 982 910 static const struct pci_device_id pci_ids[] = {