blob: 2d496305d0924eb457d0af68a5dac0c86e300dc4 [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.
4 * Michal Simek <michal.simek@xilinx.com>
Michal Simekd54b1af2015-09-30 17:26:55 +02005 */
6#include <common.h>
Michal Simek008838d2016-09-08 15:06:22 +02007#include <dm.h>
Michal Simekd54b1af2015-09-30 17:26:55 +02008#include <ahci.h>
9#include <scsi.h>
Michal Simekd54b1af2015-09-30 17:26:55 +020010#include <asm/io.h>
Peng Ma57e363a2019-04-17 10:10:50 +000011#include <linux/ioport.h>
Michal Simekd54b1af2015-09-30 17:26:55 +020012
13/* Vendor Specific Register Offsets */
14#define AHCI_VEND_PCFG 0xA4
15#define AHCI_VEND_PPCFG 0xA8
16#define AHCI_VEND_PP2C 0xAC
17#define AHCI_VEND_PP3C 0xB0
18#define AHCI_VEND_PP4C 0xB4
19#define AHCI_VEND_PP5C 0xB8
Yuantian Tang88d3a1a2018-07-13 17:25:30 +080020#define AHCI_VEND_AXICC 0xBc
Michal Simekd54b1af2015-09-30 17:26:55 +020021#define AHCI_VEND_PAXIC 0xC0
22#define AHCI_VEND_PTC 0xC8
23
24/* Vendor Specific Register bit definitions */
25#define PAXIC_ADBW_BW64 0x1
26#define PAXIC_MAWIDD (1 << 8)
27#define PAXIC_MARIDD (1 << 16)
28#define PAXIC_OTL (0x4 << 20)
29
30#define PCFG_TPSS_VAL (0x32 << 16)
31#define PCFG_TPRS_VAL (0x2 << 12)
32#define PCFG_PAD_VAL 0x2
33
34#define PPCFG_TTA 0x1FFFE
35#define PPCFG_PSSO_EN (1 << 28)
36#define PPCFG_PSS_EN (1 << 29)
37#define PPCFG_ESDF_EN (1 << 31)
38
39#define PP2C_CIBGMN 0x0F
40#define PP2C_CIBGMX (0x25 << 8)
41#define PP2C_CIBGN (0x18 << 16)
42#define PP2C_CINMP (0x29 << 24)
43
44#define PP3C_CWBGMN 0x04
45#define PP3C_CWBGMX (0x0B << 8)
46#define PP3C_CWBGN (0x08 << 16)
47#define PP3C_CWNMP (0x0F << 24)
48
49#define PP4C_BMX 0x0a
50#define PP4C_BNM (0x08 << 8)
51#define PP4C_SFD (0x4a << 16)
52#define PP4C_PTST (0x06 << 24)
53
54#define PP5C_RIT 0x60216
55#define PP5C_RCT (0x7f0 << 20)
56
57#define PTC_RX_WM_VAL 0x40
58#define PTC_RSVD (1 << 27)
59
60#define PORT0_BASE 0x100
61#define PORT1_BASE 0x180
62
63/* Port Control Register Bit Definitions */
64#define PORT_SCTL_SPD_GEN3 (0x3 << 4)
65#define PORT_SCTL_SPD_GEN2 (0x2 << 4)
66#define PORT_SCTL_SPD_GEN1 (0x1 << 4)
67#define PORT_SCTL_IPM (0x3 << 8)
68
69#define PORT_BASE 0x100
70#define PORT_OFFSET 0x80
71#define NR_PORTS 2
72#define DRV_NAME "ahci-ceva"
73#define CEVA_FLAG_BROKEN_GEN2 1
74
Yuantian Tang88d3a1a2018-07-13 17:25:30 +080075/* flag bit definition */
76#define FLAG_COHERENT 1
77
78/* register config value */
79#define CEVA_PHY1_CFG 0xa003fffe
80#define CEVA_PHY2_CFG 0x28184d1f
81#define CEVA_PHY3_CFG 0x0e081509
82#define CEVA_TRANS_CFG 0x08000029
83#define CEVA_AXICC_CFG 0x3fffffff
84
Peng Ma50b5be82018-08-01 14:15:43 +080085/* for ls1021a */
Peng Ma08deeff2018-10-22 10:39:49 +080086#define LS1021_AHCI_VEND_AXICC 0xC0
Peng Ma50b5be82018-08-01 14:15:43 +080087#define LS1021_CEVA_PHY2_CFG 0x28183414
88#define LS1021_CEVA_PHY3_CFG 0x0e080e06
89#define LS1021_CEVA_PHY4_CFG 0x064a080b
90#define LS1021_CEVA_PHY5_CFG 0x2aa86470
91
Peng Ma57e363a2019-04-17 10:10:50 +000092/* ecc val pair */
93#define ECC_DIS_VAL_CH1 0x00020000
Peng Ma08deeff2018-10-22 10:39:49 +080094#define ECC_DIS_VAL_CH2 0x80000000
Peng Ma57e363a2019-04-17 10:10:50 +000095#define ECC_DIS_VAL_CH3 0x40000000
Yuantian Tang88d3a1a2018-07-13 17:25:30 +080096
97enum ceva_soc {
98 CEVA_1V84,
99 CEVA_LS1012A,
Peng Ma50b5be82018-08-01 14:15:43 +0800100 CEVA_LS1021A,
Peng Ma57e363a2019-04-17 10:10:50 +0000101 CEVA_LS1028A,
Peng Macc688fc2018-08-01 11:35:15 +0800102 CEVA_LS1043A,
Peng Ma66135b52018-10-11 10:34:19 +0000103 CEVA_LS1046A,
Peng Ma08deeff2018-10-22 10:39:49 +0800104 CEVA_LS1088A,
Peng Macc403e52018-10-22 10:43:20 +0800105 CEVA_LS2080A,
Yuantian Tang88d3a1a2018-07-13 17:25:30 +0800106};
107
Michal Simekafb0a412018-04-06 13:32:52 +0200108struct ceva_sata_priv {
109 ulong base;
Peng Ma57e363a2019-04-17 10:10:50 +0000110 ulong ecc_base;
Yuantian Tang88d3a1a2018-07-13 17:25:30 +0800111 enum ceva_soc soc;
112 ulong flag;
Michal Simekafb0a412018-04-06 13:32:52 +0200113};
114
Yuantian Tang88d3a1a2018-07-13 17:25:30 +0800115static int ceva_init_sata(struct ceva_sata_priv *priv)
Michal Simekd54b1af2015-09-30 17:26:55 +0200116{
Peng Ma57e363a2019-04-17 10:10:50 +0000117 ulong ecc_addr = priv->ecc_base;
Yuantian Tang88d3a1a2018-07-13 17:25:30 +0800118 ulong base = priv->base;
Michal Simekd54b1af2015-09-30 17:26:55 +0200119 ulong tmp;
Michal Simekd54b1af2015-09-30 17:26:55 +0200120
Yuantian Tang88d3a1a2018-07-13 17:25:30 +0800121 switch (priv->soc) {
122 case CEVA_1V84:
123 tmp = PAXIC_ADBW_BW64 | PAXIC_MAWIDD | PAXIC_MARIDD | PAXIC_OTL;
124 writel(tmp, base + AHCI_VEND_PAXIC);
125 tmp = PCFG_TPSS_VAL | PCFG_TPRS_VAL | PCFG_PAD_VAL;
126 writel(tmp, base + AHCI_VEND_PCFG);
Michal Simekd54b1af2015-09-30 17:26:55 +0200127 tmp = PPCFG_TTA | PPCFG_PSS_EN | PPCFG_ESDF_EN;
Yuantian Tang88d3a1a2018-07-13 17:25:30 +0800128 writel(tmp, base + AHCI_VEND_PPCFG);
Michal Simekd54b1af2015-09-30 17:26:55 +0200129 tmp = PTC_RX_WM_VAL | PTC_RSVD;
Yuantian Tang88d3a1a2018-07-13 17:25:30 +0800130 writel(tmp, base + AHCI_VEND_PTC);
131 break;
Michal Simekd54b1af2015-09-30 17:26:55 +0200132
Peng Ma50b5be82018-08-01 14:15:43 +0800133 case CEVA_LS1021A:
Peng Ma57e363a2019-04-17 10:10:50 +0000134 if (!ecc_addr)
135 return -EINVAL;
136 writel(ECC_DIS_VAL_CH1, ecc_addr);
Peng Ma50b5be82018-08-01 14:15:43 +0800137 writel(CEVA_PHY1_CFG, base + AHCI_VEND_PPCFG);
138 writel(LS1021_CEVA_PHY2_CFG, base + AHCI_VEND_PP2C);
139 writel(LS1021_CEVA_PHY3_CFG, base + AHCI_VEND_PP3C);
140 writel(LS1021_CEVA_PHY4_CFG, base + AHCI_VEND_PP4C);
141 writel(LS1021_CEVA_PHY5_CFG, base + AHCI_VEND_PP5C);
142 writel(CEVA_TRANS_CFG, base + AHCI_VEND_PTC);
Peng Ma50b5be82018-08-01 14:15:43 +0800143 break;
144
Yuantian Tang88d3a1a2018-07-13 17:25:30 +0800145 case CEVA_LS1012A:
Peng Macc688fc2018-08-01 11:35:15 +0800146 case CEVA_LS1043A:
Peng Ma66135b52018-10-11 10:34:19 +0000147 case CEVA_LS1046A:
Peng Ma57e363a2019-04-17 10:10:50 +0000148 if (!ecc_addr)
149 return -EINVAL;
150 writel(ECC_DIS_VAL_CH2, ecc_addr);
Peng Macc403e52018-10-22 10:43:20 +0800151 /* fallthrough */
152 case CEVA_LS2080A:
Peng Ma08deeff2018-10-22 10:39:49 +0800153 writel(CEVA_PHY1_CFG, base + AHCI_VEND_PPCFG);
154 writel(CEVA_TRANS_CFG, base + AHCI_VEND_PTC);
Peng Ma08deeff2018-10-22 10:39:49 +0800155 break;
156
Peng Ma57e363a2019-04-17 10:10:50 +0000157 case CEVA_LS1028A:
Peng Ma08deeff2018-10-22 10:39:49 +0800158 case CEVA_LS1088A:
Peng Ma57e363a2019-04-17 10:10:50 +0000159 if (!ecc_addr)
160 return -EINVAL;
161 writel(ECC_DIS_VAL_CH3, ecc_addr);
Yuantian Tang88d3a1a2018-07-13 17:25:30 +0800162 writel(CEVA_PHY1_CFG, base + AHCI_VEND_PPCFG);
163 writel(CEVA_TRANS_CFG, base + AHCI_VEND_PTC);
Yuantian Tang88d3a1a2018-07-13 17:25:30 +0800164 break;
Michal Simekd54b1af2015-09-30 17:26:55 +0200165 }
Yuantian Tang88d3a1a2018-07-13 17:25:30 +0800166
Peng Ma57e363a2019-04-17 10:10:50 +0000167 if (priv->flag & FLAG_COHERENT)
168 writel(CEVA_AXICC_CFG, base + AHCI_VEND_AXICC);
169
Michal Simekd54b1af2015-09-30 17:26:55 +0200170 return 0;
171}
Michal Simek008838d2016-09-08 15:06:22 +0200172
Michal Simekafb0a412018-04-06 13:32:52 +0200173static int sata_ceva_bind(struct udevice *dev)
Michal Simek008838d2016-09-08 15:06:22 +0200174{
Michal Simekafb0a412018-04-06 13:32:52 +0200175 struct udevice *scsi_dev;
176
177 return ahci_bind_scsi(dev, &scsi_dev);
178}
Michal Simek008838d2016-09-08 15:06:22 +0200179
Michal Simekafb0a412018-04-06 13:32:52 +0200180static int sata_ceva_probe(struct udevice *dev)
181{
182 struct ceva_sata_priv *priv = dev_get_priv(dev);
Simon Glass84fac542017-06-14 21:28:37 -0600183
Yuantian Tang88d3a1a2018-07-13 17:25:30 +0800184 ceva_init_sata(priv);
Michal Simek364dbb42017-11-02 15:45:34 +0100185
Michal Simekafb0a412018-04-06 13:32:52 +0200186 return ahci_probe_scsi(dev, priv->base);
Michal Simek008838d2016-09-08 15:06:22 +0200187}
188
189static const struct udevice_id sata_ceva_ids[] = {
Yuantian Tang88d3a1a2018-07-13 17:25:30 +0800190 { .compatible = "ceva,ahci-1v84", .data = CEVA_1V84 },
191 { .compatible = "fsl,ls1012a-ahci", .data = CEVA_LS1012A },
Peng Ma50b5be82018-08-01 14:15:43 +0800192 { .compatible = "fsl,ls1021a-ahci", .data = CEVA_LS1021A },
Peng Ma57e363a2019-04-17 10:10:50 +0000193 { .compatible = "fsl,ls1028a-ahci", .data = CEVA_LS1028A },
Peng Macc688fc2018-08-01 11:35:15 +0800194 { .compatible = "fsl,ls1043a-ahci", .data = CEVA_LS1043A },
Peng Ma66135b52018-10-11 10:34:19 +0000195 { .compatible = "fsl,ls1046a-ahci", .data = CEVA_LS1046A },
Peng Ma08deeff2018-10-22 10:39:49 +0800196 { .compatible = "fsl,ls1088a-ahci", .data = CEVA_LS1088A },
Peng Macc403e52018-10-22 10:43:20 +0800197 { .compatible = "fsl,ls2080a-ahci", .data = CEVA_LS2080A },
Michal Simek008838d2016-09-08 15:06:22 +0200198 { }
199};
200
201static int sata_ceva_ofdata_to_platdata(struct udevice *dev)
202{
Michal Simekafb0a412018-04-06 13:32:52 +0200203 struct ceva_sata_priv *priv = dev_get_priv(dev);
Peng Ma57e363a2019-04-17 10:10:50 +0000204 struct resource res_regs;
205 int ret;
Michal Simek008838d2016-09-08 15:06:22 +0200206
Yuantian Tang88d3a1a2018-07-13 17:25:30 +0800207 if (dev_read_bool(dev, "dma-coherent"))
208 priv->flag |= FLAG_COHERENT;
209
210 priv->base = dev_read_addr(dev);
Michal Simekafb0a412018-04-06 13:32:52 +0200211 if (priv->base == FDT_ADDR_T_NONE)
Michal Simek008838d2016-09-08 15:06:22 +0200212 return -EINVAL;
213
Peng Ma57e363a2019-04-17 10:10:50 +0000214 ret = dev_read_resource_byname(dev, "ecc-addr", &res_regs);
215 if (ret)
216 priv->ecc_base = 0;
217 else
218 priv->ecc_base = res_regs.start;
219
Yuantian Tang88d3a1a2018-07-13 17:25:30 +0800220 priv->soc = dev_get_driver_data(dev);
221
Peng Ma57e363a2019-04-17 10:10:50 +0000222 debug("ccsr-sata-base %lx\t ecc-base %lx\n",
223 priv->base,
224 priv->ecc_base);
225
Michal Simek008838d2016-09-08 15:06:22 +0200226 return 0;
227}
228
229U_BOOT_DRIVER(ceva_host_blk) = {
230 .name = "ceva_sata",
Michal Simekafb0a412018-04-06 13:32:52 +0200231 .id = UCLASS_AHCI,
Michal Simek008838d2016-09-08 15:06:22 +0200232 .of_match = sata_ceva_ids,
Michal Simekafb0a412018-04-06 13:32:52 +0200233 .bind = sata_ceva_bind,
Simon Glassc4dfa892017-06-14 21:28:43 -0600234 .ops = &scsi_ops,
Michal Simekafb0a412018-04-06 13:32:52 +0200235 .priv_auto_alloc_size = sizeof(struct ceva_sata_priv),
Michal Simek008838d2016-09-08 15:06:22 +0200236 .probe = sata_ceva_probe,
237 .ofdata_to_platdata = sata_ceva_ofdata_to_platdata,
Michal Simek008838d2016-09-08 15:06:22 +0200238};