Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Michal Simek | d54b1af | 2015-09-30 17:26:55 +0200 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2015 - 2016 Xilinx, Inc. |
| 4 | * Michal Simek <michal.simek@xilinx.com> |
Michal Simek | d54b1af | 2015-09-30 17:26:55 +0200 | [diff] [blame] | 5 | */ |
| 6 | #include <common.h> |
Michal Simek | 008838d | 2016-09-08 15:06:22 +0200 | [diff] [blame] | 7 | #include <dm.h> |
Michal Simek | d54b1af | 2015-09-30 17:26:55 +0200 | [diff] [blame] | 8 | #include <ahci.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 9 | #include <log.h> |
Michal Simek | d54b1af | 2015-09-30 17:26:55 +0200 | [diff] [blame] | 10 | #include <scsi.h> |
Michal Simek | d54b1af | 2015-09-30 17:26:55 +0200 | [diff] [blame] | 11 | #include <asm/io.h> |
Peng Ma | 57e363a | 2019-04-17 10:10:50 +0000 | [diff] [blame] | 12 | #include <linux/ioport.h> |
Michal Simek | d54b1af | 2015-09-30 17:26:55 +0200 | [diff] [blame] | 13 | |
| 14 | /* Vendor Specific Register Offsets */ |
| 15 | #define AHCI_VEND_PCFG 0xA4 |
| 16 | #define AHCI_VEND_PPCFG 0xA8 |
| 17 | #define AHCI_VEND_PP2C 0xAC |
| 18 | #define AHCI_VEND_PP3C 0xB0 |
| 19 | #define AHCI_VEND_PP4C 0xB4 |
| 20 | #define AHCI_VEND_PP5C 0xB8 |
Yuantian Tang | 88d3a1a | 2018-07-13 17:25:30 +0800 | [diff] [blame] | 21 | #define AHCI_VEND_AXICC 0xBc |
Michal Simek | d54b1af | 2015-09-30 17:26:55 +0200 | [diff] [blame] | 22 | #define AHCI_VEND_PAXIC 0xC0 |
| 23 | #define AHCI_VEND_PTC 0xC8 |
| 24 | |
| 25 | /* Vendor Specific Register bit definitions */ |
| 26 | #define PAXIC_ADBW_BW64 0x1 |
| 27 | #define PAXIC_MAWIDD (1 << 8) |
| 28 | #define PAXIC_MARIDD (1 << 16) |
| 29 | #define PAXIC_OTL (0x4 << 20) |
| 30 | |
| 31 | #define PCFG_TPSS_VAL (0x32 << 16) |
| 32 | #define PCFG_TPRS_VAL (0x2 << 12) |
| 33 | #define PCFG_PAD_VAL 0x2 |
| 34 | |
| 35 | #define PPCFG_TTA 0x1FFFE |
| 36 | #define PPCFG_PSSO_EN (1 << 28) |
| 37 | #define PPCFG_PSS_EN (1 << 29) |
| 38 | #define PPCFG_ESDF_EN (1 << 31) |
| 39 | |
| 40 | #define PP2C_CIBGMN 0x0F |
| 41 | #define PP2C_CIBGMX (0x25 << 8) |
| 42 | #define PP2C_CIBGN (0x18 << 16) |
| 43 | #define PP2C_CINMP (0x29 << 24) |
| 44 | |
| 45 | #define PP3C_CWBGMN 0x04 |
| 46 | #define PP3C_CWBGMX (0x0B << 8) |
| 47 | #define PP3C_CWBGN (0x08 << 16) |
| 48 | #define PP3C_CWNMP (0x0F << 24) |
| 49 | |
| 50 | #define PP4C_BMX 0x0a |
| 51 | #define PP4C_BNM (0x08 << 8) |
| 52 | #define PP4C_SFD (0x4a << 16) |
| 53 | #define PP4C_PTST (0x06 << 24) |
| 54 | |
| 55 | #define PP5C_RIT 0x60216 |
| 56 | #define PP5C_RCT (0x7f0 << 20) |
| 57 | |
| 58 | #define PTC_RX_WM_VAL 0x40 |
| 59 | #define PTC_RSVD (1 << 27) |
| 60 | |
| 61 | #define PORT0_BASE 0x100 |
| 62 | #define PORT1_BASE 0x180 |
| 63 | |
| 64 | /* Port Control Register Bit Definitions */ |
| 65 | #define PORT_SCTL_SPD_GEN3 (0x3 << 4) |
| 66 | #define PORT_SCTL_SPD_GEN2 (0x2 << 4) |
| 67 | #define PORT_SCTL_SPD_GEN1 (0x1 << 4) |
| 68 | #define PORT_SCTL_IPM (0x3 << 8) |
| 69 | |
| 70 | #define PORT_BASE 0x100 |
| 71 | #define PORT_OFFSET 0x80 |
| 72 | #define NR_PORTS 2 |
| 73 | #define DRV_NAME "ahci-ceva" |
| 74 | #define CEVA_FLAG_BROKEN_GEN2 1 |
| 75 | |
Yuantian Tang | 88d3a1a | 2018-07-13 17:25:30 +0800 | [diff] [blame] | 76 | /* flag bit definition */ |
| 77 | #define FLAG_COHERENT 1 |
| 78 | |
| 79 | /* register config value */ |
| 80 | #define CEVA_PHY1_CFG 0xa003fffe |
| 81 | #define CEVA_PHY2_CFG 0x28184d1f |
| 82 | #define CEVA_PHY3_CFG 0x0e081509 |
| 83 | #define CEVA_TRANS_CFG 0x08000029 |
| 84 | #define CEVA_AXICC_CFG 0x3fffffff |
| 85 | |
Peng Ma | 50b5be8 | 2018-08-01 14:15:43 +0800 | [diff] [blame] | 86 | /* for ls1021a */ |
Peng Ma | 08deeff | 2018-10-22 10:39:49 +0800 | [diff] [blame] | 87 | #define LS1021_AHCI_VEND_AXICC 0xC0 |
Peng Ma | 50b5be8 | 2018-08-01 14:15:43 +0800 | [diff] [blame] | 88 | #define LS1021_CEVA_PHY2_CFG 0x28183414 |
| 89 | #define LS1021_CEVA_PHY3_CFG 0x0e080e06 |
| 90 | #define LS1021_CEVA_PHY4_CFG 0x064a080b |
| 91 | #define LS1021_CEVA_PHY5_CFG 0x2aa86470 |
| 92 | |
Peng Ma | 57e363a | 2019-04-17 10:10:50 +0000 | [diff] [blame] | 93 | /* ecc val pair */ |
| 94 | #define ECC_DIS_VAL_CH1 0x00020000 |
Peng Ma | 08deeff | 2018-10-22 10:39:49 +0800 | [diff] [blame] | 95 | #define ECC_DIS_VAL_CH2 0x80000000 |
Peng Ma | 57e363a | 2019-04-17 10:10:50 +0000 | [diff] [blame] | 96 | #define ECC_DIS_VAL_CH3 0x40000000 |
Yuantian Tang | 88d3a1a | 2018-07-13 17:25:30 +0800 | [diff] [blame] | 97 | |
| 98 | enum ceva_soc { |
| 99 | CEVA_1V84, |
| 100 | CEVA_LS1012A, |
Peng Ma | 50b5be8 | 2018-08-01 14:15:43 +0800 | [diff] [blame] | 101 | CEVA_LS1021A, |
Peng Ma | 57e363a | 2019-04-17 10:10:50 +0000 | [diff] [blame] | 102 | CEVA_LS1028A, |
Peng Ma | cc688fc | 2018-08-01 11:35:15 +0800 | [diff] [blame] | 103 | CEVA_LS1043A, |
Peng Ma | 66135b5 | 2018-10-11 10:34:19 +0000 | [diff] [blame] | 104 | CEVA_LS1046A, |
Peng Ma | 08deeff | 2018-10-22 10:39:49 +0800 | [diff] [blame] | 105 | CEVA_LS1088A, |
Peng Ma | cc403e5 | 2018-10-22 10:43:20 +0800 | [diff] [blame] | 106 | CEVA_LS2080A, |
Yuantian Tang | 88d3a1a | 2018-07-13 17:25:30 +0800 | [diff] [blame] | 107 | }; |
| 108 | |
Michal Simek | afb0a41 | 2018-04-06 13:32:52 +0200 | [diff] [blame] | 109 | struct ceva_sata_priv { |
| 110 | ulong base; |
Peng Ma | 57e363a | 2019-04-17 10:10:50 +0000 | [diff] [blame] | 111 | ulong ecc_base; |
Yuantian Tang | 88d3a1a | 2018-07-13 17:25:30 +0800 | [diff] [blame] | 112 | enum ceva_soc soc; |
| 113 | ulong flag; |
Michal Simek | afb0a41 | 2018-04-06 13:32:52 +0200 | [diff] [blame] | 114 | }; |
| 115 | |
Yuantian Tang | 88d3a1a | 2018-07-13 17:25:30 +0800 | [diff] [blame] | 116 | static int ceva_init_sata(struct ceva_sata_priv *priv) |
Michal Simek | d54b1af | 2015-09-30 17:26:55 +0200 | [diff] [blame] | 117 | { |
Peng Ma | 57e363a | 2019-04-17 10:10:50 +0000 | [diff] [blame] | 118 | ulong ecc_addr = priv->ecc_base; |
Yuantian Tang | 88d3a1a | 2018-07-13 17:25:30 +0800 | [diff] [blame] | 119 | ulong base = priv->base; |
Michal Simek | d54b1af | 2015-09-30 17:26:55 +0200 | [diff] [blame] | 120 | ulong tmp; |
Michal Simek | d54b1af | 2015-09-30 17:26:55 +0200 | [diff] [blame] | 121 | |
Yuantian Tang | 88d3a1a | 2018-07-13 17:25:30 +0800 | [diff] [blame] | 122 | switch (priv->soc) { |
| 123 | case CEVA_1V84: |
| 124 | tmp = PAXIC_ADBW_BW64 | PAXIC_MAWIDD | PAXIC_MARIDD | PAXIC_OTL; |
| 125 | writel(tmp, base + AHCI_VEND_PAXIC); |
| 126 | tmp = PCFG_TPSS_VAL | PCFG_TPRS_VAL | PCFG_PAD_VAL; |
| 127 | writel(tmp, base + AHCI_VEND_PCFG); |
Michal Simek | d54b1af | 2015-09-30 17:26:55 +0200 | [diff] [blame] | 128 | tmp = PPCFG_TTA | PPCFG_PSS_EN | PPCFG_ESDF_EN; |
Yuantian Tang | 88d3a1a | 2018-07-13 17:25:30 +0800 | [diff] [blame] | 129 | writel(tmp, base + AHCI_VEND_PPCFG); |
Michal Simek | d54b1af | 2015-09-30 17:26:55 +0200 | [diff] [blame] | 130 | tmp = PTC_RX_WM_VAL | PTC_RSVD; |
Yuantian Tang | 88d3a1a | 2018-07-13 17:25:30 +0800 | [diff] [blame] | 131 | writel(tmp, base + AHCI_VEND_PTC); |
| 132 | break; |
Michal Simek | d54b1af | 2015-09-30 17:26:55 +0200 | [diff] [blame] | 133 | |
Peng Ma | 50b5be8 | 2018-08-01 14:15:43 +0800 | [diff] [blame] | 134 | case CEVA_LS1021A: |
Peng Ma | 57e363a | 2019-04-17 10:10:50 +0000 | [diff] [blame] | 135 | if (!ecc_addr) |
| 136 | return -EINVAL; |
| 137 | writel(ECC_DIS_VAL_CH1, ecc_addr); |
Peng Ma | 50b5be8 | 2018-08-01 14:15:43 +0800 | [diff] [blame] | 138 | writel(CEVA_PHY1_CFG, base + AHCI_VEND_PPCFG); |
| 139 | writel(LS1021_CEVA_PHY2_CFG, base + AHCI_VEND_PP2C); |
| 140 | writel(LS1021_CEVA_PHY3_CFG, base + AHCI_VEND_PP3C); |
| 141 | writel(LS1021_CEVA_PHY4_CFG, base + AHCI_VEND_PP4C); |
| 142 | writel(LS1021_CEVA_PHY5_CFG, base + AHCI_VEND_PP5C); |
| 143 | writel(CEVA_TRANS_CFG, base + AHCI_VEND_PTC); |
Peng Ma | 50b5be8 | 2018-08-01 14:15:43 +0800 | [diff] [blame] | 144 | break; |
| 145 | |
Yuantian Tang | 88d3a1a | 2018-07-13 17:25:30 +0800 | [diff] [blame] | 146 | case CEVA_LS1012A: |
Peng Ma | cc688fc | 2018-08-01 11:35:15 +0800 | [diff] [blame] | 147 | case CEVA_LS1043A: |
Peng Ma | 66135b5 | 2018-10-11 10:34:19 +0000 | [diff] [blame] | 148 | case CEVA_LS1046A: |
Peng Ma | 57e363a | 2019-04-17 10:10:50 +0000 | [diff] [blame] | 149 | if (!ecc_addr) |
| 150 | return -EINVAL; |
| 151 | writel(ECC_DIS_VAL_CH2, ecc_addr); |
Peng Ma | cc403e5 | 2018-10-22 10:43:20 +0800 | [diff] [blame] | 152 | /* fallthrough */ |
| 153 | case CEVA_LS2080A: |
Peng Ma | 08deeff | 2018-10-22 10:39:49 +0800 | [diff] [blame] | 154 | writel(CEVA_PHY1_CFG, base + AHCI_VEND_PPCFG); |
| 155 | writel(CEVA_TRANS_CFG, base + AHCI_VEND_PTC); |
Peng Ma | 08deeff | 2018-10-22 10:39:49 +0800 | [diff] [blame] | 156 | break; |
| 157 | |
Peng Ma | 57e363a | 2019-04-17 10:10:50 +0000 | [diff] [blame] | 158 | case CEVA_LS1028A: |
Peng Ma | 08deeff | 2018-10-22 10:39:49 +0800 | [diff] [blame] | 159 | case CEVA_LS1088A: |
Peng Ma | 57e363a | 2019-04-17 10:10:50 +0000 | [diff] [blame] | 160 | if (!ecc_addr) |
| 161 | return -EINVAL; |
| 162 | writel(ECC_DIS_VAL_CH3, ecc_addr); |
Yuantian Tang | 88d3a1a | 2018-07-13 17:25:30 +0800 | [diff] [blame] | 163 | writel(CEVA_PHY1_CFG, base + AHCI_VEND_PPCFG); |
| 164 | writel(CEVA_TRANS_CFG, base + AHCI_VEND_PTC); |
Yuantian Tang | 88d3a1a | 2018-07-13 17:25:30 +0800 | [diff] [blame] | 165 | break; |
Michal Simek | d54b1af | 2015-09-30 17:26:55 +0200 | [diff] [blame] | 166 | } |
Yuantian Tang | 88d3a1a | 2018-07-13 17:25:30 +0800 | [diff] [blame] | 167 | |
Peng Ma | 57e363a | 2019-04-17 10:10:50 +0000 | [diff] [blame] | 168 | if (priv->flag & FLAG_COHERENT) |
| 169 | writel(CEVA_AXICC_CFG, base + AHCI_VEND_AXICC); |
| 170 | |
Michal Simek | d54b1af | 2015-09-30 17:26:55 +0200 | [diff] [blame] | 171 | return 0; |
| 172 | } |
Michal Simek | 008838d | 2016-09-08 15:06:22 +0200 | [diff] [blame] | 173 | |
Michal Simek | afb0a41 | 2018-04-06 13:32:52 +0200 | [diff] [blame] | 174 | static int sata_ceva_bind(struct udevice *dev) |
Michal Simek | 008838d | 2016-09-08 15:06:22 +0200 | [diff] [blame] | 175 | { |
Michal Simek | afb0a41 | 2018-04-06 13:32:52 +0200 | [diff] [blame] | 176 | struct udevice *scsi_dev; |
| 177 | |
| 178 | return ahci_bind_scsi(dev, &scsi_dev); |
| 179 | } |
Michal Simek | 008838d | 2016-09-08 15:06:22 +0200 | [diff] [blame] | 180 | |
Michal Simek | afb0a41 | 2018-04-06 13:32:52 +0200 | [diff] [blame] | 181 | static int sata_ceva_probe(struct udevice *dev) |
| 182 | { |
| 183 | struct ceva_sata_priv *priv = dev_get_priv(dev); |
Simon Glass | 84fac54 | 2017-06-14 21:28:37 -0600 | [diff] [blame] | 184 | |
Yuantian Tang | 88d3a1a | 2018-07-13 17:25:30 +0800 | [diff] [blame] | 185 | ceva_init_sata(priv); |
Michal Simek | 364dbb4 | 2017-11-02 15:45:34 +0100 | [diff] [blame] | 186 | |
Michal Simek | afb0a41 | 2018-04-06 13:32:52 +0200 | [diff] [blame] | 187 | return ahci_probe_scsi(dev, priv->base); |
Michal Simek | 008838d | 2016-09-08 15:06:22 +0200 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | static const struct udevice_id sata_ceva_ids[] = { |
Yuantian Tang | 88d3a1a | 2018-07-13 17:25:30 +0800 | [diff] [blame] | 191 | { .compatible = "ceva,ahci-1v84", .data = CEVA_1V84 }, |
| 192 | { .compatible = "fsl,ls1012a-ahci", .data = CEVA_LS1012A }, |
Peng Ma | 50b5be8 | 2018-08-01 14:15:43 +0800 | [diff] [blame] | 193 | { .compatible = "fsl,ls1021a-ahci", .data = CEVA_LS1021A }, |
Peng Ma | 57e363a | 2019-04-17 10:10:50 +0000 | [diff] [blame] | 194 | { .compatible = "fsl,ls1028a-ahci", .data = CEVA_LS1028A }, |
Peng Ma | cc688fc | 2018-08-01 11:35:15 +0800 | [diff] [blame] | 195 | { .compatible = "fsl,ls1043a-ahci", .data = CEVA_LS1043A }, |
Peng Ma | 66135b5 | 2018-10-11 10:34:19 +0000 | [diff] [blame] | 196 | { .compatible = "fsl,ls1046a-ahci", .data = CEVA_LS1046A }, |
Peng Ma | 08deeff | 2018-10-22 10:39:49 +0800 | [diff] [blame] | 197 | { .compatible = "fsl,ls1088a-ahci", .data = CEVA_LS1088A }, |
Peng Ma | cc403e5 | 2018-10-22 10:43:20 +0800 | [diff] [blame] | 198 | { .compatible = "fsl,ls2080a-ahci", .data = CEVA_LS2080A }, |
Michal Simek | 008838d | 2016-09-08 15:06:22 +0200 | [diff] [blame] | 199 | { } |
| 200 | }; |
| 201 | |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 202 | static int sata_ceva_of_to_plat(struct udevice *dev) |
Michal Simek | 008838d | 2016-09-08 15:06:22 +0200 | [diff] [blame] | 203 | { |
Michal Simek | afb0a41 | 2018-04-06 13:32:52 +0200 | [diff] [blame] | 204 | struct ceva_sata_priv *priv = dev_get_priv(dev); |
Peng Ma | 57e363a | 2019-04-17 10:10:50 +0000 | [diff] [blame] | 205 | struct resource res_regs; |
| 206 | int ret; |
Michal Simek | 008838d | 2016-09-08 15:06:22 +0200 | [diff] [blame] | 207 | |
Yuantian Tang | 88d3a1a | 2018-07-13 17:25:30 +0800 | [diff] [blame] | 208 | if (dev_read_bool(dev, "dma-coherent")) |
| 209 | priv->flag |= FLAG_COHERENT; |
| 210 | |
| 211 | priv->base = dev_read_addr(dev); |
Michal Simek | afb0a41 | 2018-04-06 13:32:52 +0200 | [diff] [blame] | 212 | if (priv->base == FDT_ADDR_T_NONE) |
Michal Simek | 008838d | 2016-09-08 15:06:22 +0200 | [diff] [blame] | 213 | return -EINVAL; |
| 214 | |
Peng Ma | 57e363a | 2019-04-17 10:10:50 +0000 | [diff] [blame] | 215 | ret = dev_read_resource_byname(dev, "ecc-addr", &res_regs); |
| 216 | if (ret) |
| 217 | priv->ecc_base = 0; |
| 218 | else |
| 219 | priv->ecc_base = res_regs.start; |
| 220 | |
Yuantian Tang | 88d3a1a | 2018-07-13 17:25:30 +0800 | [diff] [blame] | 221 | priv->soc = dev_get_driver_data(dev); |
| 222 | |
Peng Ma | 57e363a | 2019-04-17 10:10:50 +0000 | [diff] [blame] | 223 | debug("ccsr-sata-base %lx\t ecc-base %lx\n", |
| 224 | priv->base, |
| 225 | priv->ecc_base); |
| 226 | |
Michal Simek | 008838d | 2016-09-08 15:06:22 +0200 | [diff] [blame] | 227 | return 0; |
| 228 | } |
| 229 | |
| 230 | U_BOOT_DRIVER(ceva_host_blk) = { |
| 231 | .name = "ceva_sata", |
Michal Simek | afb0a41 | 2018-04-06 13:32:52 +0200 | [diff] [blame] | 232 | .id = UCLASS_AHCI, |
Michal Simek | 008838d | 2016-09-08 15:06:22 +0200 | [diff] [blame] | 233 | .of_match = sata_ceva_ids, |
Michal Simek | afb0a41 | 2018-04-06 13:32:52 +0200 | [diff] [blame] | 234 | .bind = sata_ceva_bind, |
Simon Glass | c4dfa89 | 2017-06-14 21:28:43 -0600 | [diff] [blame] | 235 | .ops = &scsi_ops, |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 236 | .priv_auto = sizeof(struct ceva_sata_priv), |
Michal Simek | 008838d | 2016-09-08 15:06:22 +0200 | [diff] [blame] | 237 | .probe = sata_ceva_probe, |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 238 | .of_to_plat = sata_ceva_of_to_plat, |
Michal Simek | 008838d | 2016-09-08 15:06:22 +0200 | [diff] [blame] | 239 | }; |