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

sata_rcar: Add R-Car Gen2 SATA PHY support

R-Car Gen2 SoCs have a different PHY which is not compatible
with the older R-Car H1 (R8A7779) version.
This adds OF/platform device id tables and PHY initialization
callbacks for the following Gen2 SoCs:
* R-Car H2: R8A7790;
* R-Car M2: R8A7791.

PHY initialization method is chosen based on the device id.
Default PHY settings are applied for Gen2 SoCs, which should
suit the Gen2 boards available.

While at it, this also adds "sata-r8a7779" compatibility string
for R8A7779 SATA, while keeping the old one for compatibility.

Signed-off-by: Valentine Barshak <valentine.barshak@cogentembedded.com>
Signed-off-by: Tejun Heo <tj@kernel.org>

authored by

Valentine Barshak and committed by
Tejun Heo
e67adb4e cb85696d

+102 -16
+102 -16
drivers/ata/sata_rcar.c
··· 15 15 #include <linux/module.h> 16 16 #include <linux/ata.h> 17 17 #include <linux/libata.h> 18 + #include <linux/of_device.h> 18 19 #include <linux/platform_device.h> 19 20 #include <linux/clk.h> 20 21 #include <linux/err.h> ··· 124 123 125 124 #define SATA_RCAR_DMA_BOUNDARY 0x1FFFFFFEUL 126 125 126 + /* Gen2 Physical Layer Control Registers */ 127 + #define RCAR_GEN2_PHY_CTL1_REG 0x1704 128 + #define RCAR_GEN2_PHY_CTL1 0x34180002 129 + #define RCAR_GEN2_PHY_CTL1_SS 0xC180 /* Spread Spectrum */ 130 + 131 + #define RCAR_GEN2_PHY_CTL2_REG 0x170C 132 + #define RCAR_GEN2_PHY_CTL2 0x00002303 133 + 134 + #define RCAR_GEN2_PHY_CTL3_REG 0x171C 135 + #define RCAR_GEN2_PHY_CTL3 0x000B0194 136 + 137 + #define RCAR_GEN2_PHY_CTL4_REG 0x1724 138 + #define RCAR_GEN2_PHY_CTL4 0x00030994 139 + 140 + #define RCAR_GEN2_PHY_CTL5_REG 0x1740 141 + #define RCAR_GEN2_PHY_CTL5 0x03004001 142 + #define RCAR_GEN2_PHY_CTL5_DC BIT(1) /* DC connection */ 143 + #define RCAR_GEN2_PHY_CTL5_TR BIT(2) /* Termination Resistor */ 144 + 145 + enum sata_rcar_type { 146 + RCAR_GEN1_SATA, 147 + RCAR_GEN2_SATA, 148 + }; 149 + 127 150 struct sata_rcar_priv { 128 151 void __iomem *base; 129 152 struct clk *clk; 153 + enum sata_rcar_type type; 130 154 }; 131 155 132 - static void sata_rcar_phy_initialize(struct sata_rcar_priv *priv) 156 + static void sata_rcar_gen1_phy_preinit(struct sata_rcar_priv *priv) 133 157 { 134 158 void __iomem *base = priv->base; 135 159 ··· 167 141 iowrite32(0, base + SATAPHYRESET_REG); 168 142 } 169 143 170 - static void sata_rcar_phy_write(struct sata_rcar_priv *priv, u16 reg, u32 val, 171 - int group) 144 + static void sata_rcar_gen1_phy_write(struct sata_rcar_priv *priv, u16 reg, 145 + u32 val, int group) 172 146 { 173 147 void __iomem *base = priv->base; 174 148 int timeout; ··· 194 168 pr_err("%s timeout\n", __func__); 195 169 /* idle state */ 196 170 iowrite32(0, base + SATAPHYADDR_REG); 171 + } 172 + 173 + static void sata_rcar_gen1_phy_init(struct sata_rcar_priv *priv) 174 + { 175 + sata_rcar_gen1_phy_preinit(priv); 176 + sata_rcar_gen1_phy_write(priv, SATAPCTLR1_REG, 0x00200188, 0); 177 + sata_rcar_gen1_phy_write(priv, SATAPCTLR1_REG, 0x00200188, 1); 178 + sata_rcar_gen1_phy_write(priv, SATAPCTLR3_REG, 0x0000A061, 0); 179 + sata_rcar_gen1_phy_write(priv, SATAPCTLR2_REG, 0x20000000, 0); 180 + sata_rcar_gen1_phy_write(priv, SATAPCTLR2_REG, 0x20000000, 1); 181 + sata_rcar_gen1_phy_write(priv, SATAPCTLR4_REG, 0x28E80000, 0); 182 + } 183 + 184 + static void sata_rcar_gen2_phy_init(struct sata_rcar_priv *priv) 185 + { 186 + void __iomem *base = priv->base; 187 + 188 + iowrite32(RCAR_GEN2_PHY_CTL1, base + RCAR_GEN2_PHY_CTL1_REG); 189 + iowrite32(RCAR_GEN2_PHY_CTL2, base + RCAR_GEN2_PHY_CTL2_REG); 190 + iowrite32(RCAR_GEN2_PHY_CTL3, base + RCAR_GEN2_PHY_CTL3_REG); 191 + iowrite32(RCAR_GEN2_PHY_CTL4, base + RCAR_GEN2_PHY_CTL4_REG); 192 + iowrite32(RCAR_GEN2_PHY_CTL5 | RCAR_GEN2_PHY_CTL5_DC | 193 + RCAR_GEN2_PHY_CTL5_TR, base + RCAR_GEN2_PHY_CTL5_REG); 197 194 } 198 195 199 196 static void sata_rcar_freeze(struct ata_port *ap) ··· 787 738 u32 val; 788 739 789 740 /* reset and setup phy */ 790 - sata_rcar_phy_initialize(priv); 791 - sata_rcar_phy_write(priv, SATAPCTLR1_REG, 0x00200188, 0); 792 - sata_rcar_phy_write(priv, SATAPCTLR1_REG, 0x00200188, 1); 793 - sata_rcar_phy_write(priv, SATAPCTLR3_REG, 0x0000A061, 0); 794 - sata_rcar_phy_write(priv, SATAPCTLR2_REG, 0x20000000, 0); 795 - sata_rcar_phy_write(priv, SATAPCTLR2_REG, 0x20000000, 1); 796 - sata_rcar_phy_write(priv, SATAPCTLR4_REG, 0x28E80000, 0); 741 + switch (priv->type) { 742 + case RCAR_GEN1_SATA: 743 + sata_rcar_gen1_phy_init(priv); 744 + break; 745 + case RCAR_GEN2_SATA: 746 + sata_rcar_gen2_phy_init(priv); 747 + break; 748 + default: 749 + dev_warn(host->dev, "SATA phy is not initialized\n"); 750 + break; 751 + } 797 752 798 753 /* SATA-IP reset state */ 799 754 val = ioread32(base + ATAPI_CONTROL1_REG); ··· 823 770 iowrite32(ATAPI_INT_ENABLE_SATAINT, base + ATAPI_INT_ENABLE_REG); 824 771 } 825 772 773 + static struct of_device_id sata_rcar_match[] = { 774 + { 775 + /* Deprecated by "renesas,sata-r8a7779" */ 776 + .compatible = "renesas,rcar-sata", 777 + .data = (void *)RCAR_GEN1_SATA, 778 + }, 779 + { 780 + .compatible = "renesas,sata-r8a7779", 781 + .data = (void *)RCAR_GEN1_SATA, 782 + }, 783 + { 784 + .compatible = "renesas,sata-r8a7790", 785 + .data = (void *)RCAR_GEN2_SATA 786 + }, 787 + { 788 + .compatible = "renesas,sata-r8a7791", 789 + .data = (void *)RCAR_GEN2_SATA 790 + }, 791 + { }, 792 + }; 793 + MODULE_DEVICE_TABLE(of, sata_rcar_match); 794 + 795 + static const struct platform_device_id sata_rcar_id_table[] = { 796 + { "sata_rcar", RCAR_GEN1_SATA }, /* Deprecated by "sata-r8a7779" */ 797 + { "sata-r8a7779", RCAR_GEN1_SATA }, 798 + { "sata-r8a7790", RCAR_GEN2_SATA }, 799 + { "sata-r8a7791", RCAR_GEN2_SATA }, 800 + { }, 801 + }; 802 + MODULE_DEVICE_TABLE(platform, sata_rcar_id_table); 803 + 826 804 static int sata_rcar_probe(struct platform_device *pdev) 827 805 { 806 + const struct of_device_id *of_id; 828 807 struct ata_host *host; 829 808 struct sata_rcar_priv *priv; 830 809 struct resource *mem; ··· 871 786 GFP_KERNEL); 872 787 if (!priv) 873 788 return -ENOMEM; 789 + 790 + of_id = of_match_device(sata_rcar_match, &pdev->dev); 791 + if (of_id) 792 + priv->type = (enum sata_rcar_type)of_id->data; 793 + else 794 + priv->type = platform_get_device_id(pdev)->driver_data; 874 795 875 796 priv->clk = devm_clk_get(&pdev->dev, NULL); 876 797 if (IS_ERR(priv->clk)) { ··· 983 892 }; 984 893 #endif 985 894 986 - static struct of_device_id sata_rcar_match[] = { 987 - { .compatible = "renesas,rcar-sata", }, 988 - {}, 989 - }; 990 - MODULE_DEVICE_TABLE(of, sata_rcar_match); 991 - 992 895 static struct platform_driver sata_rcar_driver = { 993 896 .probe = sata_rcar_probe, 994 897 .remove = sata_rcar_remove, 898 + .id_table = sata_rcar_id_table, 995 899 .driver = { 996 900 .name = DRV_NAME, 997 901 .owner = THIS_MODULE,