ahci_ceva.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. /*
  2. * Copyright (C) 2015 Xilinx, Inc.
  3. * CEVA AHCI SATA platform driver
  4. *
  5. * based on the AHCI SATA platform driver by Jeff Garzik and Anton Vorontsov
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms and conditions of the GNU General Public License,
  9. * version 2, as published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  14. * more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along with
  17. * this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <linux/ahci_platform.h>
  20. #include <linux/kernel.h>
  21. #include <linux/libata.h>
  22. #include <linux/module.h>
  23. #include <linux/of_device.h>
  24. #include <linux/platform_device.h>
  25. #include "ahci.h"
  26. /* Vendor Specific Register Offsets */
  27. #define AHCI_VEND_PCFG 0xA4
  28. #define AHCI_VEND_PPCFG 0xA8
  29. #define AHCI_VEND_PP2C 0xAC
  30. #define AHCI_VEND_PP3C 0xB0
  31. #define AHCI_VEND_PP4C 0xB4
  32. #define AHCI_VEND_PP5C 0xB8
  33. #define AHCI_VEND_PAXIC 0xC0
  34. #define AHCI_VEND_PTC 0xC8
  35. /* Vendor Specific Register bit definitions */
  36. #define PAXIC_ADBW_BW64 0x1
  37. #define PAXIC_MAWIDD (1 << 8)
  38. #define PAXIC_MARIDD (1 << 16)
  39. #define PAXIC_OTL (0x4 << 20)
  40. #define PCFG_TPSS_VAL (0x32 << 16)
  41. #define PCFG_TPRS_VAL (0x2 << 12)
  42. #define PCFG_PAD_VAL 0x2
  43. #define PPCFG_TTA 0x1FFFE
  44. #define PPCFG_PSSO_EN (1 << 28)
  45. #define PPCFG_PSS_EN (1 << 29)
  46. #define PPCFG_ESDF_EN (1 << 31)
  47. #define PP2C_CIBGMN 0x0F
  48. #define PP2C_CIBGMX (0x25 << 8)
  49. #define PP2C_CIBGN (0x18 << 16)
  50. #define PP2C_CINMP (0x29 << 24)
  51. #define PP3C_CWBGMN 0x04
  52. #define PP3C_CWBGMX (0x0B << 8)
  53. #define PP3C_CWBGN (0x08 << 16)
  54. #define PP3C_CWNMP (0x0F << 24)
  55. #define PP4C_BMX 0x0a
  56. #define PP4C_BNM (0x08 << 8)
  57. #define PP4C_SFD (0x4a << 16)
  58. #define PP4C_PTST (0x06 << 24)
  59. #define PP5C_RIT 0x60216
  60. #define PP5C_RCT (0x7f0 << 20)
  61. #define PTC_RX_WM_VAL 0x40
  62. #define PTC_RSVD (1 << 27)
  63. #define PORT0_BASE 0x100
  64. #define PORT1_BASE 0x180
  65. /* Port Control Register Bit Definitions */
  66. #define PORT_SCTL_SPD_GEN2 (0x2 << 4)
  67. #define PORT_SCTL_SPD_GEN1 (0x1 << 4)
  68. #define PORT_SCTL_IPM (0x3 << 8)
  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. struct ceva_ahci_priv {
  75. struct platform_device *ahci_pdev;
  76. int flags;
  77. };
  78. static struct ata_port_operations ahci_ceva_ops = {
  79. .inherits = &ahci_platform_ops,
  80. };
  81. static const struct ata_port_info ahci_ceva_port_info = {
  82. .flags = AHCI_FLAG_COMMON,
  83. .pio_mask = ATA_PIO4,
  84. .udma_mask = ATA_UDMA6,
  85. .port_ops = &ahci_ceva_ops,
  86. };
  87. static void ahci_ceva_setup(struct ahci_host_priv *hpriv)
  88. {
  89. void __iomem *mmio = hpriv->mmio;
  90. struct ceva_ahci_priv *cevapriv = hpriv->plat_data;
  91. u32 tmp;
  92. int i;
  93. /*
  94. * AXI Data bus width to 64
  95. * Set Mem Addr Read, Write ID for data transfers
  96. * Transfer limit to 72 DWord
  97. */
  98. tmp = PAXIC_ADBW_BW64 | PAXIC_MAWIDD | PAXIC_MARIDD | PAXIC_OTL;
  99. writel(tmp, mmio + AHCI_VEND_PAXIC);
  100. /* Set AHCI Enable */
  101. tmp = readl(mmio + HOST_CTL);
  102. tmp |= HOST_AHCI_EN;
  103. writel(tmp, mmio + HOST_CTL);
  104. for (i = 0; i < NR_PORTS; i++) {
  105. /* TPSS TPRS scalars, CISE and Port Addr */
  106. tmp = PCFG_TPSS_VAL | PCFG_TPRS_VAL | (PCFG_PAD_VAL + i);
  107. writel(tmp, mmio + AHCI_VEND_PCFG);
  108. /* Port Phy Cfg register enables */
  109. tmp = PPCFG_TTA | PPCFG_PSS_EN | PPCFG_ESDF_EN;
  110. writel(tmp, mmio + AHCI_VEND_PPCFG);
  111. /* Phy Control OOB timing parameters COMINIT */
  112. tmp = PP2C_CIBGMN | PP2C_CIBGMX | PP2C_CIBGN | PP2C_CINMP;
  113. writel(tmp, mmio + AHCI_VEND_PP2C);
  114. /* Phy Control OOB timing parameters COMWAKE */
  115. tmp = PP3C_CWBGMN | PP3C_CWBGMX | PP3C_CWBGN | PP3C_CWNMP;
  116. writel(tmp, mmio + AHCI_VEND_PP3C);
  117. /* Phy Control Burst timing setting */
  118. tmp = PP4C_BMX | PP4C_BNM | PP4C_SFD | PP4C_PTST;
  119. writel(tmp, mmio + AHCI_VEND_PP4C);
  120. /* Rate Change Timer and Retry Interval Timer setting */
  121. tmp = PP5C_RIT | PP5C_RCT;
  122. writel(tmp, mmio + AHCI_VEND_PP5C);
  123. /* Rx Watermark setting */
  124. tmp = PTC_RX_WM_VAL | PTC_RSVD;
  125. writel(tmp, mmio + AHCI_VEND_PTC);
  126. /* Default to Gen 2 Speed and Gen 1 if Gen2 is broken */
  127. tmp = PORT_SCTL_SPD_GEN2 | PORT_SCTL_IPM;
  128. if (cevapriv->flags & CEVA_FLAG_BROKEN_GEN2)
  129. tmp = PORT_SCTL_SPD_GEN1 | PORT_SCTL_IPM;
  130. writel(tmp, mmio + PORT_SCR_CTL + PORT_BASE + PORT_OFFSET * i);
  131. }
  132. }
  133. static struct scsi_host_template ahci_platform_sht = {
  134. AHCI_SHT(DRV_NAME),
  135. };
  136. static int ceva_ahci_probe(struct platform_device *pdev)
  137. {
  138. struct device_node *np = pdev->dev.of_node;
  139. struct device *dev = &pdev->dev;
  140. struct ahci_host_priv *hpriv;
  141. struct ceva_ahci_priv *cevapriv;
  142. int rc;
  143. cevapriv = devm_kzalloc(dev, sizeof(*cevapriv), GFP_KERNEL);
  144. if (!cevapriv)
  145. return -ENOMEM;
  146. cevapriv->ahci_pdev = pdev;
  147. hpriv = ahci_platform_get_resources(pdev);
  148. if (IS_ERR(hpriv))
  149. return PTR_ERR(hpriv);
  150. rc = ahci_platform_enable_resources(hpriv);
  151. if (rc)
  152. return rc;
  153. if (of_property_read_bool(np, "ceva,broken-gen2"))
  154. cevapriv->flags = CEVA_FLAG_BROKEN_GEN2;
  155. hpriv->plat_data = cevapriv;
  156. /* CEVA specific initialization */
  157. ahci_ceva_setup(hpriv);
  158. rc = ahci_platform_init_host(pdev, hpriv, &ahci_ceva_port_info,
  159. &ahci_platform_sht);
  160. if (rc)
  161. goto disable_resources;
  162. return 0;
  163. disable_resources:
  164. ahci_platform_disable_resources(hpriv);
  165. return rc;
  166. }
  167. static int __maybe_unused ceva_ahci_suspend(struct device *dev)
  168. {
  169. return ahci_platform_suspend_host(dev);
  170. }
  171. static int __maybe_unused ceva_ahci_resume(struct device *dev)
  172. {
  173. return ahci_platform_resume_host(dev);
  174. }
  175. static SIMPLE_DEV_PM_OPS(ahci_ceva_pm_ops, ceva_ahci_suspend, ceva_ahci_resume);
  176. static const struct of_device_id ceva_ahci_of_match[] = {
  177. { .compatible = "ceva,ahci-1v84" },
  178. {},
  179. };
  180. MODULE_DEVICE_TABLE(of, ceva_ahci_of_match);
  181. static struct platform_driver ceva_ahci_driver = {
  182. .probe = ceva_ahci_probe,
  183. .remove = ata_platform_remove_one,
  184. .driver = {
  185. .name = DRV_NAME,
  186. .of_match_table = ceva_ahci_of_match,
  187. .pm = &ahci_ceva_pm_ops,
  188. },
  189. };
  190. module_platform_driver(ceva_ahci_driver);
  191. MODULE_DESCRIPTION("CEVA AHCI SATA platform driver");
  192. MODULE_AUTHOR("Xilinx Inc.");
  193. MODULE_LICENSE("GPL v2");