2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2015-09-30 15:26:55 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2015 - 2016 Xilinx, Inc.
|
|
|
|
* Michal Simek <michal.simek@xilinx.com>
|
|
|
|
*/
|
|
|
|
#include <common.h>
|
2016-09-08 13:06:22 +00:00
|
|
|
#include <dm.h>
|
2015-09-30 15:26:55 +00:00
|
|
|
#include <ahci.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2015-09-30 15:26:55 +00:00
|
|
|
#include <scsi.h>
|
|
|
|
#include <asm/io.h>
|
2019-04-17 10:10:50 +00:00
|
|
|
#include <linux/ioport.h>
|
2015-09-30 15:26:55 +00:00
|
|
|
|
|
|
|
/* Vendor Specific Register Offsets */
|
|
|
|
#define AHCI_VEND_PCFG 0xA4
|
|
|
|
#define AHCI_VEND_PPCFG 0xA8
|
|
|
|
#define AHCI_VEND_PP2C 0xAC
|
|
|
|
#define AHCI_VEND_PP3C 0xB0
|
|
|
|
#define AHCI_VEND_PP4C 0xB4
|
|
|
|
#define AHCI_VEND_PP5C 0xB8
|
2018-07-13 09:25:30 +00:00
|
|
|
#define AHCI_VEND_AXICC 0xBc
|
2015-09-30 15:26:55 +00:00
|
|
|
#define AHCI_VEND_PAXIC 0xC0
|
|
|
|
#define AHCI_VEND_PTC 0xC8
|
|
|
|
|
|
|
|
/* Vendor Specific Register bit definitions */
|
|
|
|
#define PAXIC_ADBW_BW64 0x1
|
|
|
|
#define PAXIC_MAWIDD (1 << 8)
|
|
|
|
#define PAXIC_MARIDD (1 << 16)
|
|
|
|
#define PAXIC_OTL (0x4 << 20)
|
|
|
|
|
|
|
|
#define PCFG_TPSS_VAL (0x32 << 16)
|
|
|
|
#define PCFG_TPRS_VAL (0x2 << 12)
|
|
|
|
#define PCFG_PAD_VAL 0x2
|
|
|
|
|
|
|
|
#define PPCFG_TTA 0x1FFFE
|
|
|
|
#define PPCFG_PSSO_EN (1 << 28)
|
|
|
|
#define PPCFG_PSS_EN (1 << 29)
|
|
|
|
#define PPCFG_ESDF_EN (1 << 31)
|
|
|
|
|
|
|
|
#define PP2C_CIBGMN 0x0F
|
|
|
|
#define PP2C_CIBGMX (0x25 << 8)
|
|
|
|
#define PP2C_CIBGN (0x18 << 16)
|
|
|
|
#define PP2C_CINMP (0x29 << 24)
|
|
|
|
|
|
|
|
#define PP3C_CWBGMN 0x04
|
|
|
|
#define PP3C_CWBGMX (0x0B << 8)
|
|
|
|
#define PP3C_CWBGN (0x08 << 16)
|
|
|
|
#define PP3C_CWNMP (0x0F << 24)
|
|
|
|
|
|
|
|
#define PP4C_BMX 0x0a
|
|
|
|
#define PP4C_BNM (0x08 << 8)
|
|
|
|
#define PP4C_SFD (0x4a << 16)
|
|
|
|
#define PP4C_PTST (0x06 << 24)
|
|
|
|
|
|
|
|
#define PP5C_RIT 0x60216
|
|
|
|
#define PP5C_RCT (0x7f0 << 20)
|
|
|
|
|
|
|
|
#define PTC_RX_WM_VAL 0x40
|
|
|
|
#define PTC_RSVD (1 << 27)
|
|
|
|
|
|
|
|
#define PORT0_BASE 0x100
|
|
|
|
#define PORT1_BASE 0x180
|
|
|
|
|
|
|
|
/* Port Control Register Bit Definitions */
|
|
|
|
#define PORT_SCTL_SPD_GEN3 (0x3 << 4)
|
|
|
|
#define PORT_SCTL_SPD_GEN2 (0x2 << 4)
|
|
|
|
#define PORT_SCTL_SPD_GEN1 (0x1 << 4)
|
|
|
|
#define PORT_SCTL_IPM (0x3 << 8)
|
|
|
|
|
|
|
|
#define PORT_BASE 0x100
|
|
|
|
#define PORT_OFFSET 0x80
|
|
|
|
#define NR_PORTS 2
|
|
|
|
#define DRV_NAME "ahci-ceva"
|
|
|
|
#define CEVA_FLAG_BROKEN_GEN2 1
|
|
|
|
|
2018-07-13 09:25:30 +00:00
|
|
|
/* flag bit definition */
|
|
|
|
#define FLAG_COHERENT 1
|
|
|
|
|
|
|
|
/* register config value */
|
|
|
|
#define CEVA_PHY1_CFG 0xa003fffe
|
|
|
|
#define CEVA_PHY2_CFG 0x28184d1f
|
|
|
|
#define CEVA_PHY3_CFG 0x0e081509
|
|
|
|
#define CEVA_TRANS_CFG 0x08000029
|
|
|
|
#define CEVA_AXICC_CFG 0x3fffffff
|
|
|
|
|
2018-08-01 06:15:43 +00:00
|
|
|
/* for ls1021a */
|
2018-10-22 02:39:49 +00:00
|
|
|
#define LS1021_AHCI_VEND_AXICC 0xC0
|
2018-08-01 06:15:43 +00:00
|
|
|
#define LS1021_CEVA_PHY2_CFG 0x28183414
|
|
|
|
#define LS1021_CEVA_PHY3_CFG 0x0e080e06
|
|
|
|
#define LS1021_CEVA_PHY4_CFG 0x064a080b
|
|
|
|
#define LS1021_CEVA_PHY5_CFG 0x2aa86470
|
|
|
|
|
2019-04-17 10:10:50 +00:00
|
|
|
/* ecc val pair */
|
|
|
|
#define ECC_DIS_VAL_CH1 0x00020000
|
2018-10-22 02:39:49 +00:00
|
|
|
#define ECC_DIS_VAL_CH2 0x80000000
|
2019-04-17 10:10:50 +00:00
|
|
|
#define ECC_DIS_VAL_CH3 0x40000000
|
2018-07-13 09:25:30 +00:00
|
|
|
|
|
|
|
enum ceva_soc {
|
|
|
|
CEVA_1V84,
|
|
|
|
CEVA_LS1012A,
|
2018-08-01 06:15:43 +00:00
|
|
|
CEVA_LS1021A,
|
2019-04-17 10:10:50 +00:00
|
|
|
CEVA_LS1028A,
|
2018-08-01 03:35:15 +00:00
|
|
|
CEVA_LS1043A,
|
2018-10-11 10:34:19 +00:00
|
|
|
CEVA_LS1046A,
|
2018-10-22 02:39:49 +00:00
|
|
|
CEVA_LS1088A,
|
2018-10-22 02:43:20 +00:00
|
|
|
CEVA_LS2080A,
|
2018-07-13 09:25:30 +00:00
|
|
|
};
|
|
|
|
|
2018-04-06 11:32:52 +00:00
|
|
|
struct ceva_sata_priv {
|
|
|
|
ulong base;
|
2019-04-17 10:10:50 +00:00
|
|
|
ulong ecc_base;
|
2018-07-13 09:25:30 +00:00
|
|
|
enum ceva_soc soc;
|
|
|
|
ulong flag;
|
2018-04-06 11:32:52 +00:00
|
|
|
};
|
|
|
|
|
2018-07-13 09:25:30 +00:00
|
|
|
static int ceva_init_sata(struct ceva_sata_priv *priv)
|
2015-09-30 15:26:55 +00:00
|
|
|
{
|
2019-04-17 10:10:50 +00:00
|
|
|
ulong ecc_addr = priv->ecc_base;
|
2018-07-13 09:25:30 +00:00
|
|
|
ulong base = priv->base;
|
2015-09-30 15:26:55 +00:00
|
|
|
ulong tmp;
|
|
|
|
|
2018-07-13 09:25:30 +00:00
|
|
|
switch (priv->soc) {
|
|
|
|
case CEVA_1V84:
|
|
|
|
tmp = PAXIC_ADBW_BW64 | PAXIC_MAWIDD | PAXIC_MARIDD | PAXIC_OTL;
|
|
|
|
writel(tmp, base + AHCI_VEND_PAXIC);
|
|
|
|
tmp = PCFG_TPSS_VAL | PCFG_TPRS_VAL | PCFG_PAD_VAL;
|
|
|
|
writel(tmp, base + AHCI_VEND_PCFG);
|
|
|
|
tmp = PPCFG_TTA | PPCFG_PSS_EN | PPCFG_ESDF_EN;
|
|
|
|
writel(tmp, base + AHCI_VEND_PPCFG);
|
2015-09-30 15:26:55 +00:00
|
|
|
tmp = PTC_RX_WM_VAL | PTC_RSVD;
|
2018-07-13 09:25:30 +00:00
|
|
|
writel(tmp, base + AHCI_VEND_PTC);
|
|
|
|
break;
|
|
|
|
|
2018-08-01 06:15:43 +00:00
|
|
|
case CEVA_LS1021A:
|
2019-04-17 10:10:50 +00:00
|
|
|
if (!ecc_addr)
|
|
|
|
return -EINVAL;
|
|
|
|
writel(ECC_DIS_VAL_CH1, ecc_addr);
|
2018-08-01 06:15:43 +00:00
|
|
|
writel(CEVA_PHY1_CFG, base + AHCI_VEND_PPCFG);
|
|
|
|
writel(LS1021_CEVA_PHY2_CFG, base + AHCI_VEND_PP2C);
|
|
|
|
writel(LS1021_CEVA_PHY3_CFG, base + AHCI_VEND_PP3C);
|
|
|
|
writel(LS1021_CEVA_PHY4_CFG, base + AHCI_VEND_PP4C);
|
|
|
|
writel(LS1021_CEVA_PHY5_CFG, base + AHCI_VEND_PP5C);
|
|
|
|
writel(CEVA_TRANS_CFG, base + AHCI_VEND_PTC);
|
|
|
|
break;
|
|
|
|
|
2018-07-13 09:25:30 +00:00
|
|
|
case CEVA_LS1012A:
|
2018-08-01 03:35:15 +00:00
|
|
|
case CEVA_LS1043A:
|
2018-10-11 10:34:19 +00:00
|
|
|
case CEVA_LS1046A:
|
2019-04-17 10:10:50 +00:00
|
|
|
if (!ecc_addr)
|
|
|
|
return -EINVAL;
|
|
|
|
writel(ECC_DIS_VAL_CH2, ecc_addr);
|
2018-10-22 02:43:20 +00:00
|
|
|
/* fallthrough */
|
|
|
|
case CEVA_LS2080A:
|
2018-10-22 02:39:49 +00:00
|
|
|
writel(CEVA_PHY1_CFG, base + AHCI_VEND_PPCFG);
|
|
|
|
writel(CEVA_TRANS_CFG, base + AHCI_VEND_PTC);
|
|
|
|
break;
|
|
|
|
|
2019-04-17 10:10:50 +00:00
|
|
|
case CEVA_LS1028A:
|
2018-10-22 02:39:49 +00:00
|
|
|
case CEVA_LS1088A:
|
2019-04-17 10:10:50 +00:00
|
|
|
if (!ecc_addr)
|
|
|
|
return -EINVAL;
|
|
|
|
writel(ECC_DIS_VAL_CH3, ecc_addr);
|
2018-07-13 09:25:30 +00:00
|
|
|
writel(CEVA_PHY1_CFG, base + AHCI_VEND_PPCFG);
|
|
|
|
writel(CEVA_TRANS_CFG, base + AHCI_VEND_PTC);
|
|
|
|
break;
|
2015-09-30 15:26:55 +00:00
|
|
|
}
|
2018-07-13 09:25:30 +00:00
|
|
|
|
2019-04-17 10:10:50 +00:00
|
|
|
if (priv->flag & FLAG_COHERENT)
|
|
|
|
writel(CEVA_AXICC_CFG, base + AHCI_VEND_AXICC);
|
|
|
|
|
2015-09-30 15:26:55 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2016-09-08 13:06:22 +00:00
|
|
|
|
2018-04-06 11:32:52 +00:00
|
|
|
static int sata_ceva_bind(struct udevice *dev)
|
2016-09-08 13:06:22 +00:00
|
|
|
{
|
2018-04-06 11:32:52 +00:00
|
|
|
struct udevice *scsi_dev;
|
|
|
|
|
|
|
|
return ahci_bind_scsi(dev, &scsi_dev);
|
|
|
|
}
|
2016-09-08 13:06:22 +00:00
|
|
|
|
2018-04-06 11:32:52 +00:00
|
|
|
static int sata_ceva_probe(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct ceva_sata_priv *priv = dev_get_priv(dev);
|
2017-06-15 03:28:37 +00:00
|
|
|
|
2018-07-13 09:25:30 +00:00
|
|
|
ceva_init_sata(priv);
|
2017-11-02 14:45:34 +00:00
|
|
|
|
2018-04-06 11:32:52 +00:00
|
|
|
return ahci_probe_scsi(dev, priv->base);
|
2016-09-08 13:06:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct udevice_id sata_ceva_ids[] = {
|
2018-07-13 09:25:30 +00:00
|
|
|
{ .compatible = "ceva,ahci-1v84", .data = CEVA_1V84 },
|
|
|
|
{ .compatible = "fsl,ls1012a-ahci", .data = CEVA_LS1012A },
|
2018-08-01 06:15:43 +00:00
|
|
|
{ .compatible = "fsl,ls1021a-ahci", .data = CEVA_LS1021A },
|
2019-04-17 10:10:50 +00:00
|
|
|
{ .compatible = "fsl,ls1028a-ahci", .data = CEVA_LS1028A },
|
2018-08-01 03:35:15 +00:00
|
|
|
{ .compatible = "fsl,ls1043a-ahci", .data = CEVA_LS1043A },
|
2018-10-11 10:34:19 +00:00
|
|
|
{ .compatible = "fsl,ls1046a-ahci", .data = CEVA_LS1046A },
|
2018-10-22 02:39:49 +00:00
|
|
|
{ .compatible = "fsl,ls1088a-ahci", .data = CEVA_LS1088A },
|
2018-10-22 02:43:20 +00:00
|
|
|
{ .compatible = "fsl,ls2080a-ahci", .data = CEVA_LS2080A },
|
2016-09-08 13:06:22 +00:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
2020-12-03 23:55:21 +00:00
|
|
|
static int sata_ceva_of_to_plat(struct udevice *dev)
|
2016-09-08 13:06:22 +00:00
|
|
|
{
|
2018-04-06 11:32:52 +00:00
|
|
|
struct ceva_sata_priv *priv = dev_get_priv(dev);
|
2019-04-17 10:10:50 +00:00
|
|
|
struct resource res_regs;
|
|
|
|
int ret;
|
2016-09-08 13:06:22 +00:00
|
|
|
|
2018-07-13 09:25:30 +00:00
|
|
|
if (dev_read_bool(dev, "dma-coherent"))
|
|
|
|
priv->flag |= FLAG_COHERENT;
|
|
|
|
|
|
|
|
priv->base = dev_read_addr(dev);
|
2018-04-06 11:32:52 +00:00
|
|
|
if (priv->base == FDT_ADDR_T_NONE)
|
2016-09-08 13:06:22 +00:00
|
|
|
return -EINVAL;
|
|
|
|
|
2021-10-13 16:14:20 +00:00
|
|
|
ret = dev_read_resource_byname(dev, "sata-ecc", &res_regs);
|
2019-04-17 10:10:50 +00:00
|
|
|
if (ret)
|
|
|
|
priv->ecc_base = 0;
|
|
|
|
else
|
|
|
|
priv->ecc_base = res_regs.start;
|
|
|
|
|
2018-07-13 09:25:30 +00:00
|
|
|
priv->soc = dev_get_driver_data(dev);
|
|
|
|
|
2019-04-17 10:10:50 +00:00
|
|
|
debug("ccsr-sata-base %lx\t ecc-base %lx\n",
|
|
|
|
priv->base,
|
|
|
|
priv->ecc_base);
|
|
|
|
|
2016-09-08 13:06:22 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(ceva_host_blk) = {
|
|
|
|
.name = "ceva_sata",
|
2018-04-06 11:32:52 +00:00
|
|
|
.id = UCLASS_AHCI,
|
2016-09-08 13:06:22 +00:00
|
|
|
.of_match = sata_ceva_ids,
|
2018-04-06 11:32:52 +00:00
|
|
|
.bind = sata_ceva_bind,
|
2017-06-15 03:28:43 +00:00
|
|
|
.ops = &scsi_ops,
|
2020-12-03 23:55:17 +00:00
|
|
|
.priv_auto = sizeof(struct ceva_sata_priv),
|
2016-09-08 13:06:22 +00:00
|
|
|
.probe = sata_ceva_probe,
|
2020-12-03 23:55:21 +00:00
|
|
|
.of_to_plat = sata_ceva_of_to_plat,
|
2016-09-08 13:06:22 +00:00
|
|
|
};
|