1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2015 - 2016 Xilinx, Inc.
8 #include <generic-phy.h>
13 #include <dm/device_compat.h>
14 #include <linux/ioport.h>
16 /* Vendor Specific Register Offsets */
17 #define AHCI_VEND_PCFG 0xA4
18 #define AHCI_VEND_PPCFG 0xA8
19 #define AHCI_VEND_PP2C 0xAC
20 #define AHCI_VEND_PP3C 0xB0
21 #define AHCI_VEND_PP4C 0xB4
22 #define AHCI_VEND_PP5C 0xB8
23 #define AHCI_VEND_AXICC 0xBc
24 #define AHCI_VEND_PAXIC 0xC0
25 #define AHCI_VEND_PTC 0xC8
27 /* Vendor Specific Register bit definitions */
28 #define PAXIC_ADBW_BW64 0x1
29 #define PAXIC_MAWIDD (1 << 8)
30 #define PAXIC_MARIDD (1 << 16)
31 #define PAXIC_OTL (0x4 << 20)
33 #define PCFG_TPSS_VAL (0x32 << 16)
34 #define PCFG_TPRS_VAL (0x2 << 12)
35 #define PCFG_PAD_VAL 0x2
37 #define PPCFG_TTA 0x1FFFE
38 #define PPCFG_PSSO_EN (1 << 28)
39 #define PPCFG_PSS_EN (1 << 29)
40 #define PPCFG_ESDF_EN (1 << 31)
42 #define PP2C_CIBGMN 0x0F
43 #define PP2C_CIBGMX (0x25 << 8)
44 #define PP2C_CIBGN (0x18 << 16)
45 #define PP2C_CINMP (0x29 << 24)
47 #define PP3C_CWBGMN 0x04
48 #define PP3C_CWBGMX (0x0B << 8)
49 #define PP3C_CWBGN (0x08 << 16)
50 #define PP3C_CWNMP (0x0F << 24)
53 #define PP4C_BNM (0x08 << 8)
54 #define PP4C_SFD (0x4a << 16)
55 #define PP4C_PTST (0x06 << 24)
57 #define PP5C_RIT 0x60216
58 #define PP5C_RCT (0x7f0 << 20)
60 #define PTC_RX_WM_VAL 0x40
61 #define PTC_RSVD (1 << 27)
63 #define PORT0_BASE 0x100
64 #define PORT1_BASE 0x180
66 /* Port Control Register Bit Definitions */
67 #define PORT_SCTL_SPD_GEN3 (0x3 << 4)
68 #define PORT_SCTL_SPD_GEN2 (0x2 << 4)
69 #define PORT_SCTL_SPD_GEN1 (0x1 << 4)
70 #define PORT_SCTL_IPM (0x3 << 8)
72 #define PORT_BASE 0x100
73 #define PORT_OFFSET 0x80
75 #define DRV_NAME "ahci-ceva"
76 #define CEVA_FLAG_BROKEN_GEN2 1
78 /* flag bit definition */
79 #define FLAG_COHERENT 1
81 /* register config value */
82 #define CEVA_PHY1_CFG 0xa003fffe
83 #define CEVA_PHY2_CFG 0x28184d1f
84 #define CEVA_PHY3_CFG 0x0e081509
85 #define CEVA_TRANS_CFG 0x08000029
86 #define CEVA_AXICC_CFG 0x3fffffff
89 #define LS1021_AHCI_VEND_AXICC 0xC0
90 #define LS1021_CEVA_PHY2_CFG 0x28183414
91 #define LS1021_CEVA_PHY3_CFG 0x0e080e06
92 #define LS1021_CEVA_PHY4_CFG 0x064a080b
93 #define LS1021_CEVA_PHY5_CFG 0x2aa86470
96 #define ECC_DIS_VAL_CH1 0x00020000
97 #define ECC_DIS_VAL_CH2 0x80000000
98 #define ECC_DIS_VAL_CH3 0x40000000
111 struct ceva_sata_priv {
118 static int ceva_init_sata(struct ceva_sata_priv *priv)
120 ulong ecc_addr = priv->ecc_base;
121 ulong base = priv->base;
126 tmp = PAXIC_ADBW_BW64 | PAXIC_MAWIDD | PAXIC_MARIDD | PAXIC_OTL;
127 writel(tmp, base + AHCI_VEND_PAXIC);
128 tmp = PCFG_TPSS_VAL | PCFG_TPRS_VAL | PCFG_PAD_VAL;
129 writel(tmp, base + AHCI_VEND_PCFG);
130 tmp = PPCFG_TTA | PPCFG_PSS_EN | PPCFG_ESDF_EN;
131 writel(tmp, base + AHCI_VEND_PPCFG);
132 tmp = PTC_RX_WM_VAL | PTC_RSVD;
133 writel(tmp, base + AHCI_VEND_PTC);
139 writel(ECC_DIS_VAL_CH1, ecc_addr);
140 writel(CEVA_PHY1_CFG, base + AHCI_VEND_PPCFG);
141 writel(LS1021_CEVA_PHY2_CFG, base + AHCI_VEND_PP2C);
142 writel(LS1021_CEVA_PHY3_CFG, base + AHCI_VEND_PP3C);
143 writel(LS1021_CEVA_PHY4_CFG, base + AHCI_VEND_PP4C);
144 writel(LS1021_CEVA_PHY5_CFG, base + AHCI_VEND_PP5C);
145 writel(CEVA_TRANS_CFG, base + AHCI_VEND_PTC);
153 writel(ECC_DIS_VAL_CH2, ecc_addr);
156 writel(CEVA_PHY1_CFG, base + AHCI_VEND_PPCFG);
157 writel(CEVA_TRANS_CFG, base + AHCI_VEND_PTC);
164 writel(ECC_DIS_VAL_CH3, ecc_addr);
165 writel(CEVA_PHY1_CFG, base + AHCI_VEND_PPCFG);
166 writel(CEVA_TRANS_CFG, base + AHCI_VEND_PTC);
170 if (priv->flag & FLAG_COHERENT)
171 writel(CEVA_AXICC_CFG, base + AHCI_VEND_AXICC);
176 static int sata_ceva_bind(struct udevice *dev)
178 struct udevice *scsi_dev;
180 return ahci_bind_scsi(dev, &scsi_dev);
183 static int sata_ceva_probe(struct udevice *dev)
185 struct ceva_sata_priv *priv = dev_get_priv(dev);
188 struct reset_ctl_bulk resets;
190 ret = generic_phy_get_by_index(dev, 0, &phy);
192 dev_dbg(dev, "Perform PHY initialization\n");
193 ret = generic_phy_init(&phy);
196 } else if (ret != -ENOENT) {
197 dev_dbg(dev, "could not get phy (err %d)\n", ret);
201 /* reset is optional */
202 ret = reset_get_bulk(dev, &resets);
203 if (ret && ret != -ENOTSUPP && ret != -ENOENT) {
204 dev_dbg(dev, "Getting reset fails (err %d)\n", ret);
208 /* Just trigger reset when reset is specified */
210 dev_dbg(dev, "Perform IP reset\n");
211 ret = reset_deassert_bulk(&resets);
213 dev_dbg(dev, "Reset fails (err %d)\n", ret);
214 reset_release_bulk(&resets);
219 if (generic_phy_valid(&phy)) {
220 dev_dbg(dev, "Perform PHY power on\n");
221 ret = generic_phy_power_on(&phy);
223 dev_dbg(dev, "PHY power on failed (err %d)\n", ret);
228 ceva_init_sata(priv);
230 return ahci_probe_scsi(dev, priv->base);
233 static const struct udevice_id sata_ceva_ids[] = {
234 { .compatible = "ceva,ahci-1v84", .data = CEVA_1V84 },
235 { .compatible = "fsl,ls1012a-ahci", .data = CEVA_LS1012A },
236 { .compatible = "fsl,ls1021a-ahci", .data = CEVA_LS1021A },
237 { .compatible = "fsl,ls1028a-ahci", .data = CEVA_LS1028A },
238 { .compatible = "fsl,ls1043a-ahci", .data = CEVA_LS1043A },
239 { .compatible = "fsl,ls1046a-ahci", .data = CEVA_LS1046A },
240 { .compatible = "fsl,ls1088a-ahci", .data = CEVA_LS1088A },
241 { .compatible = "fsl,ls2080a-ahci", .data = CEVA_LS2080A },
245 static int sata_ceva_of_to_plat(struct udevice *dev)
247 struct ceva_sata_priv *priv = dev_get_priv(dev);
248 struct resource res_regs;
251 if (dev_read_bool(dev, "dma-coherent"))
252 priv->flag |= FLAG_COHERENT;
254 priv->base = dev_read_addr(dev);
255 if (priv->base == FDT_ADDR_T_NONE)
258 ret = dev_read_resource_byname(dev, "sata-ecc", &res_regs);
262 priv->ecc_base = res_regs.start;
264 priv->soc = dev_get_driver_data(dev);
266 debug("ccsr-sata-base %lx\t ecc-base %lx\n",
273 U_BOOT_DRIVER(ceva_host_blk) = {
276 .of_match = sata_ceva_ids,
277 .bind = sata_ceva_bind,
279 .priv_auto = sizeof(struct ceva_sata_priv),
280 .probe = sata_ceva_probe,
281 .of_to_plat = sata_ceva_of_to_plat,