blob: a81b3165992a922ffbe749982c7e2a459f863486 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Michal Simekd54b1af2015-09-30 17:26:55 +02002/*
3 * (C) Copyright 2015 - 2016 Xilinx, Inc.
Michal Simeka8c94362023-07-10 14:35:49 +02004 * Michal Simek <michal.simek@amd.com>
Michal Simekd54b1af2015-09-30 17:26:55 +02005 */
Michal Simek008838d2016-09-08 15:06:22 +02006#include <dm.h>
Michal Simekd54b1af2015-09-30 17:26:55 +02007#include <ahci.h>
Michal Simekc8bc6982022-02-07 10:36:33 +01008#include <generic-phy.h>
Simon Glass0f2af882020-05-10 11:40:05 -06009#include <log.h>
Michal Simekc8bc6982022-02-07 10:36:33 +010010#include <reset.h>
Michal Simekd54b1af2015-09-30 17:26:55 +020011#include <scsi.h>
Michal Simekd54b1af2015-09-30 17:26:55 +020012#include <asm/io.h>
Michal Simekc8bc6982022-02-07 10:36:33 +010013#include <dm/device_compat.h>
Peng Ma57e363a2019-04-17 10:10:50 +000014#include <linux/ioport.h>
Michal Simekd54b1af2015-09-30 17:26:55 +020015
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
Yuantian Tang88d3a1a2018-07-13 17:25:30 +080023#define AHCI_VEND_AXICC 0xBc
Michal Simekd54b1af2015-09-30 17:26:55 +020024#define AHCI_VEND_PAXIC 0xC0
25#define AHCI_VEND_PTC 0xC8
26
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)
32
33#define PCFG_TPSS_VAL (0x32 << 16)
34#define PCFG_TPRS_VAL (0x2 << 12)
35#define PCFG_PAD_VAL 0x2
36
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)
41
42#define PP2C_CIBGMN 0x0F
43#define PP2C_CIBGMX (0x25 << 8)
44#define PP2C_CIBGN (0x18 << 16)
45#define PP2C_CINMP (0x29 << 24)
46
47#define PP3C_CWBGMN 0x04
48#define PP3C_CWBGMX (0x0B << 8)
49#define PP3C_CWBGN (0x08 << 16)
50#define PP3C_CWNMP (0x0F << 24)
51
52#define PP4C_BMX 0x0a
53#define PP4C_BNM (0x08 << 8)
54#define PP4C_SFD (0x4a << 16)
55#define PP4C_PTST (0x06 << 24)
56
57#define PP5C_RIT 0x60216
58#define PP5C_RCT (0x7f0 << 20)
59
60#define PTC_RX_WM_VAL 0x40
61#define PTC_RSVD (1 << 27)
62
63#define PORT0_BASE 0x100
64#define PORT1_BASE 0x180
65
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)
71
72#define PORT_BASE 0x100
73#define PORT_OFFSET 0x80
74#define NR_PORTS 2
75#define DRV_NAME "ahci-ceva"
76#define CEVA_FLAG_BROKEN_GEN2 1
77
Yuantian Tang88d3a1a2018-07-13 17:25:30 +080078/* flag bit definition */
79#define FLAG_COHERENT 1
80
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
87
Peng Ma50b5be82018-08-01 14:15:43 +080088/* for ls1021a */
Peng Ma08deeff2018-10-22 10:39:49 +080089#define LS1021_AHCI_VEND_AXICC 0xC0
Peng Ma50b5be82018-08-01 14:15:43 +080090#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
94
Peng Ma57e363a2019-04-17 10:10:50 +000095/* ecc val pair */
96#define ECC_DIS_VAL_CH1 0x00020000
Peng Ma08deeff2018-10-22 10:39:49 +080097#define ECC_DIS_VAL_CH2 0x80000000
Peng Ma57e363a2019-04-17 10:10:50 +000098#define ECC_DIS_VAL_CH3 0x40000000
Yuantian Tang88d3a1a2018-07-13 17:25:30 +080099
100enum ceva_soc {
101 CEVA_1V84,
102 CEVA_LS1012A,
Peng Ma50b5be82018-08-01 14:15:43 +0800103 CEVA_LS1021A,
Peng Ma57e363a2019-04-17 10:10:50 +0000104 CEVA_LS1028A,
Peng Macc688fc2018-08-01 11:35:15 +0800105 CEVA_LS1043A,
Peng Ma66135b52018-10-11 10:34:19 +0000106 CEVA_LS1046A,
Peng Ma08deeff2018-10-22 10:39:49 +0800107 CEVA_LS1088A,
Peng Macc403e52018-10-22 10:43:20 +0800108 CEVA_LS2080A,
Yuantian Tang88d3a1a2018-07-13 17:25:30 +0800109};
110
Michal Simekafb0a412018-04-06 13:32:52 +0200111struct ceva_sata_priv {
112 ulong base;
Peng Ma57e363a2019-04-17 10:10:50 +0000113 ulong ecc_base;
Yuantian Tang88d3a1a2018-07-13 17:25:30 +0800114 enum ceva_soc soc;
115 ulong flag;
Michal Simekafb0a412018-04-06 13:32:52 +0200116};
117
Yuantian Tang88d3a1a2018-07-13 17:25:30 +0800118static int ceva_init_sata(struct ceva_sata_priv *priv)
Michal Simekd54b1af2015-09-30 17:26:55 +0200119{
Peng Ma57e363a2019-04-17 10:10:50 +0000120 ulong ecc_addr = priv->ecc_base;
Yuantian Tang88d3a1a2018-07-13 17:25:30 +0800121 ulong base = priv->base;
Michal Simekd54b1af2015-09-30 17:26:55 +0200122 ulong tmp;
Michal Simekd54b1af2015-09-30 17:26:55 +0200123
Yuantian Tang88d3a1a2018-07-13 17:25:30 +0800124 switch (priv->soc) {
125 case CEVA_1V84:
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);
Michal Simekd54b1af2015-09-30 17:26:55 +0200130 tmp = PPCFG_TTA | PPCFG_PSS_EN | PPCFG_ESDF_EN;
Yuantian Tang88d3a1a2018-07-13 17:25:30 +0800131 writel(tmp, base + AHCI_VEND_PPCFG);
Michal Simekd54b1af2015-09-30 17:26:55 +0200132 tmp = PTC_RX_WM_VAL | PTC_RSVD;
Yuantian Tang88d3a1a2018-07-13 17:25:30 +0800133 writel(tmp, base + AHCI_VEND_PTC);
134 break;
Michal Simekd54b1af2015-09-30 17:26:55 +0200135
Peng Ma50b5be82018-08-01 14:15:43 +0800136 case CEVA_LS1021A:
Peng Ma57e363a2019-04-17 10:10:50 +0000137 if (!ecc_addr)
138 return -EINVAL;
139 writel(ECC_DIS_VAL_CH1, ecc_addr);
Peng Ma50b5be82018-08-01 14:15:43 +0800140 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);
Peng Ma50b5be82018-08-01 14:15:43 +0800146 break;
147
Yuantian Tang88d3a1a2018-07-13 17:25:30 +0800148 case CEVA_LS1012A:
Peng Macc688fc2018-08-01 11:35:15 +0800149 case CEVA_LS1043A:
Peng Ma66135b52018-10-11 10:34:19 +0000150 case CEVA_LS1046A:
Peng Ma57e363a2019-04-17 10:10:50 +0000151 if (!ecc_addr)
152 return -EINVAL;
153 writel(ECC_DIS_VAL_CH2, ecc_addr);
Peng Macc403e52018-10-22 10:43:20 +0800154 /* fallthrough */
155 case CEVA_LS2080A:
Peng Ma08deeff2018-10-22 10:39:49 +0800156 writel(CEVA_PHY1_CFG, base + AHCI_VEND_PPCFG);
157 writel(CEVA_TRANS_CFG, base + AHCI_VEND_PTC);
Peng Ma08deeff2018-10-22 10:39:49 +0800158 break;
159
Peng Ma57e363a2019-04-17 10:10:50 +0000160 case CEVA_LS1028A:
Peng Ma08deeff2018-10-22 10:39:49 +0800161 case CEVA_LS1088A:
Peng Ma57e363a2019-04-17 10:10:50 +0000162 if (!ecc_addr)
163 return -EINVAL;
164 writel(ECC_DIS_VAL_CH3, ecc_addr);
Yuantian Tang88d3a1a2018-07-13 17:25:30 +0800165 writel(CEVA_PHY1_CFG, base + AHCI_VEND_PPCFG);
166 writel(CEVA_TRANS_CFG, base + AHCI_VEND_PTC);
Yuantian Tang88d3a1a2018-07-13 17:25:30 +0800167 break;
Michal Simekd54b1af2015-09-30 17:26:55 +0200168 }
Yuantian Tang88d3a1a2018-07-13 17:25:30 +0800169
Peng Ma57e363a2019-04-17 10:10:50 +0000170 if (priv->flag & FLAG_COHERENT)
171 writel(CEVA_AXICC_CFG, base + AHCI_VEND_AXICC);
172
Michal Simekd54b1af2015-09-30 17:26:55 +0200173 return 0;
174}
Michal Simek008838d2016-09-08 15:06:22 +0200175
Michal Simekafb0a412018-04-06 13:32:52 +0200176static int sata_ceva_bind(struct udevice *dev)
Michal Simek008838d2016-09-08 15:06:22 +0200177{
Michal Simekafb0a412018-04-06 13:32:52 +0200178 struct udevice *scsi_dev;
179
180 return ahci_bind_scsi(dev, &scsi_dev);
181}
Michal Simek008838d2016-09-08 15:06:22 +0200182
Michal Simekafb0a412018-04-06 13:32:52 +0200183static int sata_ceva_probe(struct udevice *dev)
184{
185 struct ceva_sata_priv *priv = dev_get_priv(dev);
Michal Simekc8bc6982022-02-07 10:36:33 +0100186 struct phy phy;
187 int ret;
188 struct reset_ctl_bulk resets;
189
190 ret = generic_phy_get_by_index(dev, 0, &phy);
191 if (!ret) {
192 dev_dbg(dev, "Perform PHY initialization\n");
193 ret = generic_phy_init(&phy);
194 if (ret)
195 return ret;
196 } else if (ret != -ENOENT) {
197 dev_dbg(dev, "could not get phy (err %d)\n", ret);
198 return ret;
199 }
200
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);
205 return ret;
206 }
207
208 /* Just trigger reset when reset is specified */
209 if (!ret) {
210 dev_dbg(dev, "Perform IP reset\n");
211 ret = reset_deassert_bulk(&resets);
212 if (ret) {
213 dev_dbg(dev, "Reset fails (err %d)\n", ret);
214 reset_release_bulk(&resets);
215 return ret;
216 }
217 }
218
Jonas Karlman9eec9652023-08-31 22:16:37 +0000219 if (generic_phy_valid(&phy)) {
Michal Simekc8bc6982022-02-07 10:36:33 +0100220 dev_dbg(dev, "Perform PHY power on\n");
221 ret = generic_phy_power_on(&phy);
222 if (ret) {
223 dev_dbg(dev, "PHY power on failed (err %d)\n", ret);
224 return ret;
225 }
226 }
Simon Glass84fac542017-06-14 21:28:37 -0600227
Yuantian Tang88d3a1a2018-07-13 17:25:30 +0800228 ceva_init_sata(priv);
Michal Simek364dbb42017-11-02 15:45:34 +0100229
Michal Simekafb0a412018-04-06 13:32:52 +0200230 return ahci_probe_scsi(dev, priv->base);
Michal Simek008838d2016-09-08 15:06:22 +0200231}
232
233static const struct udevice_id sata_ceva_ids[] = {
Yuantian Tang88d3a1a2018-07-13 17:25:30 +0800234 { .compatible = "ceva,ahci-1v84", .data = CEVA_1V84 },
235 { .compatible = "fsl,ls1012a-ahci", .data = CEVA_LS1012A },
Peng Ma50b5be82018-08-01 14:15:43 +0800236 { .compatible = "fsl,ls1021a-ahci", .data = CEVA_LS1021A },
Peng Ma57e363a2019-04-17 10:10:50 +0000237 { .compatible = "fsl,ls1028a-ahci", .data = CEVA_LS1028A },
Peng Macc688fc2018-08-01 11:35:15 +0800238 { .compatible = "fsl,ls1043a-ahci", .data = CEVA_LS1043A },
Peng Ma66135b52018-10-11 10:34:19 +0000239 { .compatible = "fsl,ls1046a-ahci", .data = CEVA_LS1046A },
Peng Ma08deeff2018-10-22 10:39:49 +0800240 { .compatible = "fsl,ls1088a-ahci", .data = CEVA_LS1088A },
Peng Macc403e52018-10-22 10:43:20 +0800241 { .compatible = "fsl,ls2080a-ahci", .data = CEVA_LS2080A },
Michal Simek008838d2016-09-08 15:06:22 +0200242 { }
243};
244
Simon Glassaad29ae2020-12-03 16:55:21 -0700245static int sata_ceva_of_to_plat(struct udevice *dev)
Michal Simek008838d2016-09-08 15:06:22 +0200246{
Michal Simekafb0a412018-04-06 13:32:52 +0200247 struct ceva_sata_priv *priv = dev_get_priv(dev);
Peng Ma57e363a2019-04-17 10:10:50 +0000248 struct resource res_regs;
249 int ret;
Michal Simek008838d2016-09-08 15:06:22 +0200250
Yuantian Tang88d3a1a2018-07-13 17:25:30 +0800251 if (dev_read_bool(dev, "dma-coherent"))
252 priv->flag |= FLAG_COHERENT;
253
254 priv->base = dev_read_addr(dev);
Michal Simekafb0a412018-04-06 13:32:52 +0200255 if (priv->base == FDT_ADDR_T_NONE)
Michal Simek008838d2016-09-08 15:06:22 +0200256 return -EINVAL;
257
Michael Walle0234b5f2021-10-13 18:14:20 +0200258 ret = dev_read_resource_byname(dev, "sata-ecc", &res_regs);
Peng Ma57e363a2019-04-17 10:10:50 +0000259 if (ret)
260 priv->ecc_base = 0;
261 else
262 priv->ecc_base = res_regs.start;
263
Yuantian Tang88d3a1a2018-07-13 17:25:30 +0800264 priv->soc = dev_get_driver_data(dev);
265
Peng Ma57e363a2019-04-17 10:10:50 +0000266 debug("ccsr-sata-base %lx\t ecc-base %lx\n",
267 priv->base,
268 priv->ecc_base);
269
Michal Simek008838d2016-09-08 15:06:22 +0200270 return 0;
271}
272
273U_BOOT_DRIVER(ceva_host_blk) = {
274 .name = "ceva_sata",
Michal Simekafb0a412018-04-06 13:32:52 +0200275 .id = UCLASS_AHCI,
Michal Simek008838d2016-09-08 15:06:22 +0200276 .of_match = sata_ceva_ids,
Michal Simekafb0a412018-04-06 13:32:52 +0200277 .bind = sata_ceva_bind,
Simon Glassc4dfa892017-06-14 21:28:43 -0600278 .ops = &scsi_ops,
Simon Glass8a2b47f2020-12-03 16:55:17 -0700279 .priv_auto = sizeof(struct ceva_sata_priv),
Michal Simek008838d2016-09-08 15:06:22 +0200280 .probe = sata_ceva_probe,
Simon Glassaad29ae2020-12-03 16:55:21 -0700281 .of_to_plat = sata_ceva_of_to_plat,
Michal Simek008838d2016-09-08 15:06:22 +0200282};