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

mmc: sdhci-of-arasan: Add support for ZynqMP Platform Tap Delays Setup

Apart from taps set by auto tuning, ZynqMP platform has feature to set
the tap values manually. Add support to set tap delay values in HW via
ZynqMP SoC framework.

Signed-off-by: Manish Narani <manish.narani@xilinx.com>
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>

authored by

Manish Narani and committed by
Ulf Hansson
a5c8b2ae 1297eacf

+204 -2
+204 -2
drivers/mmc/host/sdhci-of-arasan.c
··· 22 22 #include <linux/phy/phy.h> 23 23 #include <linux/regmap.h> 24 24 #include <linux/of.h> 25 + #include <linux/firmware/xlnx-zynqmp.h> 25 26 26 27 #include "cqhci.h" 27 28 #include "sdhci-pltfm.h" ··· 32 31 #define VENDOR_ENHANCED_STROBE BIT(0) 33 32 34 33 #define PHY_CLK_TOO_SLOW_HZ 400000 34 + 35 + /* Default settings for ZynqMP Clock Phases */ 36 + #define ZYNQMP_ICLK_PHASE {0, 63, 63, 0, 63, 0, 0, 183, 54, 0, 0} 37 + #define ZYNQMP_OCLK_PHASE {0, 72, 60, 0, 60, 72, 135, 48, 72, 135, 0} 35 38 36 39 /* 37 40 * On some SoCs the syscon area has a feature where the upper 16-bits of ··· 85 80 * @clk_phase_in: Array of Input Clock Phase Delays for all speed modes 86 81 * @clk_phase_out: Array of Output Clock Phase Delays for all speed modes 87 82 * @set_clk_delays: Function pointer for setting Clock Delays 83 + * @clk_of_data: Platform specific runtime clock data storage pointer 88 84 */ 89 85 struct sdhci_arasan_clk_data { 90 86 struct clk_hw sdcardclk_hw; ··· 95 89 int clk_phase_in[MMC_TIMING_MMC_HS400 + 1]; 96 90 int clk_phase_out[MMC_TIMING_MMC_HS400 + 1]; 97 91 void (*set_clk_delays)(struct sdhci_host *host); 92 + void *clk_of_data; 93 + }; 94 + 95 + struct sdhci_arasan_zynqmp_clk_data { 96 + const struct zynqmp_eemi_ops *eemi_ops; 98 97 }; 99 98 100 99 /** ··· 551 540 .compatible = "arasan,sdhci-4.9a", 552 541 .data = &sdhci_arasan_data, 553 542 }, 543 + { 544 + .compatible = "xlnx,zynqmp-8.9a", 545 + .data = &sdhci_arasan_data, 546 + }, 554 547 { /* sentinel */ } 555 548 }; 556 549 MODULE_DEVICE_TABLE(of, sdhci_arasan_of_match); ··· 611 596 612 597 static const struct clk_ops arasan_sampleclk_ops = { 613 598 .recalc_rate = sdhci_arasan_sampleclk_recalc_rate, 599 + }; 600 + 601 + /** 602 + * sdhci_zynqmp_sdcardclk_set_phase - Set the SD Output Clock Tap Delays 603 + * 604 + * Set the SD Output Clock Tap Delays for Output path 605 + * 606 + * @hw: Pointer to the hardware clock structure. 607 + * @degrees The clock phase shift between 0 - 359. 608 + * Return: 0 on success and error value on error 609 + */ 610 + static int sdhci_zynqmp_sdcardclk_set_phase(struct clk_hw *hw, int degrees) 611 + 612 + { 613 + struct sdhci_arasan_clk_data *clk_data = 614 + container_of(hw, struct sdhci_arasan_clk_data, sdcardclk_hw); 615 + struct sdhci_arasan_data *sdhci_arasan = 616 + container_of(clk_data, struct sdhci_arasan_data, clk_data); 617 + struct sdhci_host *host = sdhci_arasan->host; 618 + struct sdhci_arasan_zynqmp_clk_data *zynqmp_clk_data = 619 + clk_data->clk_of_data; 620 + const struct zynqmp_eemi_ops *eemi_ops = zynqmp_clk_data->eemi_ops; 621 + const char *clk_name = clk_hw_get_name(hw); 622 + u32 node_id = !strcmp(clk_name, "clk_out_sd0") ? NODE_SD_0 : NODE_SD_1; 623 + u8 tap_delay, tap_max = 0; 624 + int ret; 625 + 626 + /* 627 + * This is applicable for SDHCI_SPEC_300 and above 628 + * ZynqMP does not set phase for <=25MHz clock. 629 + * If degrees is zero, no need to do anything. 630 + */ 631 + if (host->version < SDHCI_SPEC_300 || 632 + host->timing == MMC_TIMING_LEGACY || 633 + host->timing == MMC_TIMING_UHS_SDR12 || !degrees) 634 + return 0; 635 + 636 + switch (host->timing) { 637 + case MMC_TIMING_MMC_HS: 638 + case MMC_TIMING_SD_HS: 639 + case MMC_TIMING_UHS_SDR25: 640 + case MMC_TIMING_UHS_DDR50: 641 + case MMC_TIMING_MMC_DDR52: 642 + /* For 50MHz clock, 30 Taps are available */ 643 + tap_max = 30; 644 + break; 645 + case MMC_TIMING_UHS_SDR50: 646 + /* For 100MHz clock, 15 Taps are available */ 647 + tap_max = 15; 648 + break; 649 + case MMC_TIMING_UHS_SDR104: 650 + case MMC_TIMING_MMC_HS200: 651 + /* For 200MHz clock, 8 Taps are available */ 652 + tap_max = 8; 653 + default: 654 + break; 655 + } 656 + 657 + tap_delay = (degrees * tap_max) / 360; 658 + 659 + /* Set the Clock Phase */ 660 + ret = eemi_ops->ioctl(node_id, IOCTL_SET_SD_TAPDELAY, 661 + PM_TAPDELAY_OUTPUT, tap_delay, NULL); 662 + if (ret) 663 + pr_err("Error setting Output Tap Delay\n"); 664 + 665 + return ret; 666 + } 667 + 668 + static const struct clk_ops zynqmp_sdcardclk_ops = { 669 + .recalc_rate = sdhci_arasan_sdcardclk_recalc_rate, 670 + .set_phase = sdhci_zynqmp_sdcardclk_set_phase, 671 + }; 672 + 673 + /** 674 + * sdhci_zynqmp_sampleclk_set_phase - Set the SD Input Clock Tap Delays 675 + * 676 + * Set the SD Input Clock Tap Delays for Input path 677 + * 678 + * @hw: Pointer to the hardware clock structure. 679 + * @degrees The clock phase shift between 0 - 359. 680 + * Return: 0 on success and error value on error 681 + */ 682 + static int sdhci_zynqmp_sampleclk_set_phase(struct clk_hw *hw, int degrees) 683 + 684 + { 685 + struct sdhci_arasan_clk_data *clk_data = 686 + container_of(hw, struct sdhci_arasan_clk_data, sampleclk_hw); 687 + struct sdhci_arasan_data *sdhci_arasan = 688 + container_of(clk_data, struct sdhci_arasan_data, clk_data); 689 + struct sdhci_host *host = sdhci_arasan->host; 690 + struct sdhci_arasan_zynqmp_clk_data *zynqmp_clk_data = 691 + clk_data->clk_of_data; 692 + const struct zynqmp_eemi_ops *eemi_ops = zynqmp_clk_data->eemi_ops; 693 + const char *clk_name = clk_hw_get_name(hw); 694 + u32 node_id = !strcmp(clk_name, "clk_in_sd0") ? NODE_SD_0 : NODE_SD_1; 695 + u8 tap_delay, tap_max = 0; 696 + int ret; 697 + 698 + /* 699 + * This is applicable for SDHCI_SPEC_300 and above 700 + * ZynqMP does not set phase for <=25MHz clock. 701 + * If degrees is zero, no need to do anything. 702 + */ 703 + if (host->version < SDHCI_SPEC_300 || 704 + host->timing == MMC_TIMING_LEGACY || 705 + host->timing == MMC_TIMING_UHS_SDR12 || !degrees) 706 + return 0; 707 + 708 + switch (host->timing) { 709 + case MMC_TIMING_MMC_HS: 710 + case MMC_TIMING_SD_HS: 711 + case MMC_TIMING_UHS_SDR25: 712 + case MMC_TIMING_UHS_DDR50: 713 + case MMC_TIMING_MMC_DDR52: 714 + /* For 50MHz clock, 120 Taps are available */ 715 + tap_max = 120; 716 + break; 717 + case MMC_TIMING_UHS_SDR50: 718 + /* For 100MHz clock, 60 Taps are available */ 719 + tap_max = 60; 720 + break; 721 + case MMC_TIMING_UHS_SDR104: 722 + case MMC_TIMING_MMC_HS200: 723 + /* For 200MHz clock, 30 Taps are available */ 724 + tap_max = 30; 725 + default: 726 + break; 727 + } 728 + 729 + tap_delay = (degrees * tap_max) / 360; 730 + 731 + /* Set the Clock Phase */ 732 + ret = eemi_ops->ioctl(node_id, IOCTL_SET_SD_TAPDELAY, 733 + PM_TAPDELAY_INPUT, tap_delay, NULL); 734 + if (ret) 735 + pr_err("Error setting Input Tap Delay\n"); 736 + 737 + return ret; 738 + } 739 + 740 + static const struct clk_ops zynqmp_sampleclk_ops = { 741 + .recalc_rate = sdhci_arasan_sampleclk_recalc_rate, 742 + .set_phase = sdhci_zynqmp_sampleclk_set_phase, 614 743 }; 615 744 616 745 /** ··· 883 724 static void arasan_dt_parse_clk_phases(struct device *dev, 884 725 struct sdhci_arasan_clk_data *clk_data) 885 726 { 727 + int *iclk_phase, *oclk_phase; 728 + u32 mio_bank = 0; 729 + int i; 730 + 886 731 /* 887 732 * This has been kept as a pointer and is assigned a function here. 888 733 * So that different controller variants can assign their own handling 889 734 * function. 890 735 */ 891 736 clk_data->set_clk_delays = sdhci_arasan_set_clk_delays; 737 + 738 + if (of_device_is_compatible(dev->of_node, "xlnx,zynqmp-8.9a")) { 739 + iclk_phase = (int [MMC_TIMING_MMC_HS400 + 1]) ZYNQMP_ICLK_PHASE; 740 + oclk_phase = (int [MMC_TIMING_MMC_HS400 + 1]) ZYNQMP_OCLK_PHASE; 741 + 742 + of_property_read_u32(dev->of_node, "xlnx,mio-bank", &mio_bank); 743 + if (mio_bank == 2) { 744 + oclk_phase[MMC_TIMING_UHS_SDR104] = 90; 745 + oclk_phase[MMC_TIMING_MMC_HS200] = 90; 746 + } 747 + 748 + for (i = 0; i <= MMC_TIMING_MMC_HS400; i++) { 749 + clk_data->clk_phase_in[i] = iclk_phase[i]; 750 + clk_data->clk_phase_out[i] = oclk_phase[i]; 751 + } 752 + } 892 753 893 754 arasan_dt_read_clk_phase(dev, clk_data, MMC_TIMING_LEGACY, 894 755 "clk-phase-legacy"); ··· 968 789 sdcardclk_init.parent_names = &parent_clk_name; 969 790 sdcardclk_init.num_parents = 1; 970 791 sdcardclk_init.flags = CLK_GET_RATE_NOCACHE; 971 - sdcardclk_init.ops = &arasan_sdcardclk_ops; 792 + if (of_device_is_compatible(np, "xlnx,zynqmp-8.9a")) 793 + sdcardclk_init.ops = &zynqmp_sdcardclk_ops; 794 + else 795 + sdcardclk_init.ops = &arasan_sdcardclk_ops; 972 796 973 797 clk_data->sdcardclk_hw.init = &sdcardclk_init; 974 798 clk_data->sdcardclk = ··· 1020 838 sampleclk_init.parent_names = &parent_clk_name; 1021 839 sampleclk_init.num_parents = 1; 1022 840 sampleclk_init.flags = CLK_GET_RATE_NOCACHE; 1023 - sampleclk_init.ops = &arasan_sampleclk_ops; 841 + if (of_device_is_compatible(np, "xlnx,zynqmp-8.9a")) 842 + sampleclk_init.ops = &zynqmp_sampleclk_ops; 843 + else 844 + sampleclk_init.ops = &arasan_sampleclk_ops; 1024 845 1025 846 clk_data->sampleclk_hw.init = &sampleclk_init; 1026 847 clk_data->sampleclk = ··· 1231 1046 ret = sdhci_arasan_register_sdclk(sdhci_arasan, clk_xin, &pdev->dev); 1232 1047 if (ret) 1233 1048 goto clk_disable_all; 1049 + 1050 + if (of_device_is_compatible(np, "xlnx,zynqmp-8.9a")) { 1051 + struct sdhci_arasan_zynqmp_clk_data *zynqmp_clk_data; 1052 + const struct zynqmp_eemi_ops *eemi_ops; 1053 + 1054 + zynqmp_clk_data = devm_kzalloc(&pdev->dev, 1055 + sizeof(*zynqmp_clk_data), 1056 + GFP_KERNEL); 1057 + eemi_ops = zynqmp_pm_get_eemi_ops(); 1058 + if (IS_ERR(eemi_ops)) { 1059 + ret = PTR_ERR(eemi_ops); 1060 + goto unreg_clk; 1061 + } 1062 + 1063 + zynqmp_clk_data->eemi_ops = eemi_ops; 1064 + sdhci_arasan->clk_data.clk_of_data = zynqmp_clk_data; 1065 + } 1234 1066 1235 1067 arasan_dt_parse_clk_phases(&pdev->dev, &sdhci_arasan->clk_data); 1236 1068