sata_ceva.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2015 - 2016 Xilinx, Inc.
  4. * Michal Simek <michal.simek@xilinx.com>
  5. */
  6. #include <common.h>
  7. #include <dm.h>
  8. #include <ahci.h>
  9. #include <scsi.h>
  10. #include <asm/arch/hardware.h>
  11. #include <asm/io.h>
  12. /* Vendor Specific Register Offsets */
  13. #define AHCI_VEND_PCFG 0xA4
  14. #define AHCI_VEND_PPCFG 0xA8
  15. #define AHCI_VEND_PP2C 0xAC
  16. #define AHCI_VEND_PP3C 0xB0
  17. #define AHCI_VEND_PP4C 0xB4
  18. #define AHCI_VEND_PP5C 0xB8
  19. #define AHCI_VEND_PAXIC 0xC0
  20. #define AHCI_VEND_PTC 0xC8
  21. /* Vendor Specific Register bit definitions */
  22. #define PAXIC_ADBW_BW64 0x1
  23. #define PAXIC_MAWIDD (1 << 8)
  24. #define PAXIC_MARIDD (1 << 16)
  25. #define PAXIC_OTL (0x4 << 20)
  26. #define PCFG_TPSS_VAL (0x32 << 16)
  27. #define PCFG_TPRS_VAL (0x2 << 12)
  28. #define PCFG_PAD_VAL 0x2
  29. #define PPCFG_TTA 0x1FFFE
  30. #define PPCFG_PSSO_EN (1 << 28)
  31. #define PPCFG_PSS_EN (1 << 29)
  32. #define PPCFG_ESDF_EN (1 << 31)
  33. #define PP2C_CIBGMN 0x0F
  34. #define PP2C_CIBGMX (0x25 << 8)
  35. #define PP2C_CIBGN (0x18 << 16)
  36. #define PP2C_CINMP (0x29 << 24)
  37. #define PP3C_CWBGMN 0x04
  38. #define PP3C_CWBGMX (0x0B << 8)
  39. #define PP3C_CWBGN (0x08 << 16)
  40. #define PP3C_CWNMP (0x0F << 24)
  41. #define PP4C_BMX 0x0a
  42. #define PP4C_BNM (0x08 << 8)
  43. #define PP4C_SFD (0x4a << 16)
  44. #define PP4C_PTST (0x06 << 24)
  45. #define PP5C_RIT 0x60216
  46. #define PP5C_RCT (0x7f0 << 20)
  47. #define PTC_RX_WM_VAL 0x40
  48. #define PTC_RSVD (1 << 27)
  49. #define PORT0_BASE 0x100
  50. #define PORT1_BASE 0x180
  51. /* Port Control Register Bit Definitions */
  52. #define PORT_SCTL_SPD_GEN3 (0x3 << 4)
  53. #define PORT_SCTL_SPD_GEN2 (0x2 << 4)
  54. #define PORT_SCTL_SPD_GEN1 (0x1 << 4)
  55. #define PORT_SCTL_IPM (0x3 << 8)
  56. #define PORT_BASE 0x100
  57. #define PORT_OFFSET 0x80
  58. #define NR_PORTS 2
  59. #define DRV_NAME "ahci-ceva"
  60. #define CEVA_FLAG_BROKEN_GEN2 1
  61. struct ceva_sata_priv {
  62. ulong base;
  63. };
  64. static int ceva_init_sata(ulong mmio)
  65. {
  66. ulong tmp;
  67. int i;
  68. /*
  69. * AXI Data bus width to 64
  70. * Set Mem Addr Read, Write ID for data transfers
  71. * Transfer limit to 72 DWord
  72. */
  73. tmp = PAXIC_ADBW_BW64 | PAXIC_MAWIDD | PAXIC_MARIDD | PAXIC_OTL;
  74. writel(tmp, mmio + AHCI_VEND_PAXIC);
  75. /* Set AHCI Enable */
  76. tmp = readl(mmio + HOST_CTL);
  77. tmp |= HOST_AHCI_EN;
  78. writel(tmp, mmio + HOST_CTL);
  79. for (i = 0; i < NR_PORTS; i++) {
  80. /* TPSS TPRS scalars, CISE and Port Addr */
  81. tmp = PCFG_TPSS_VAL | PCFG_TPRS_VAL | (PCFG_PAD_VAL + i);
  82. writel(tmp, mmio + AHCI_VEND_PCFG);
  83. /* Port Phy Cfg register enables */
  84. tmp = PPCFG_TTA | PPCFG_PSS_EN | PPCFG_ESDF_EN;
  85. writel(tmp, mmio + AHCI_VEND_PPCFG);
  86. /* Rx Watermark setting */
  87. tmp = PTC_RX_WM_VAL | PTC_RSVD;
  88. writel(tmp, mmio + AHCI_VEND_PTC);
  89. /* Default to Gen 2 Speed and Gen 1 if Gen2 is broken */
  90. tmp = PORT_SCTL_SPD_GEN3 | PORT_SCTL_IPM;
  91. writel(tmp, mmio + PORT_SCR_CTL + PORT_BASE + PORT_OFFSET * i);
  92. }
  93. return 0;
  94. }
  95. static int sata_ceva_bind(struct udevice *dev)
  96. {
  97. struct udevice *scsi_dev;
  98. return ahci_bind_scsi(dev, &scsi_dev);
  99. }
  100. static int sata_ceva_probe(struct udevice *dev)
  101. {
  102. struct ceva_sata_priv *priv = dev_get_priv(dev);
  103. ceva_init_sata(priv->base);
  104. return ahci_probe_scsi(dev, priv->base);
  105. }
  106. static const struct udevice_id sata_ceva_ids[] = {
  107. { .compatible = "ceva,ahci-1v84" },
  108. { }
  109. };
  110. static int sata_ceva_ofdata_to_platdata(struct udevice *dev)
  111. {
  112. struct ceva_sata_priv *priv = dev_get_priv(dev);
  113. priv->base = devfdt_get_addr(dev);
  114. if (priv->base == FDT_ADDR_T_NONE)
  115. return -EINVAL;
  116. return 0;
  117. }
  118. U_BOOT_DRIVER(ceva_host_blk) = {
  119. .name = "ceva_sata",
  120. .id = UCLASS_AHCI,
  121. .of_match = sata_ceva_ids,
  122. .bind = sata_ceva_bind,
  123. .ops = &scsi_ops,
  124. .priv_auto_alloc_size = sizeof(struct ceva_sata_priv),
  125. .probe = sata_ceva_probe,
  126. .ofdata_to_platdata = sata_ceva_ofdata_to_platdata,
  127. };