ahci_qoriq.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. /*
  2. * Freescale QorIQ AHCI SATA platform driver
  3. *
  4. * Copyright 2015 Freescale, Inc.
  5. * Tang Yuantian <Yuantian.Tang@freescale.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2, or (at your option)
  10. * any later version.
  11. */
  12. #include <linux/kernel.h>
  13. #include <linux/module.h>
  14. #include <linux/pm.h>
  15. #include <linux/ahci_platform.h>
  16. #include <linux/device.h>
  17. #include <linux/of_address.h>
  18. #include <linux/of.h>
  19. #include <linux/of_device.h>
  20. #include <linux/platform_device.h>
  21. #include <linux/libata.h>
  22. #include "ahci.h"
  23. #define DRV_NAME "ahci-qoriq"
  24. /* port register definition */
  25. #define PORT_PHY1 0xA8
  26. #define PORT_PHY2 0xAC
  27. #define PORT_PHY3 0xB0
  28. #define PORT_PHY4 0xB4
  29. #define PORT_PHY5 0xB8
  30. #define PORT_TRANS 0xC8
  31. /* port register default value */
  32. #define AHCI_PORT_PHY_1_CFG 0xa003fffe
  33. #define AHCI_PORT_PHY_2_CFG 0x28183411
  34. #define AHCI_PORT_PHY_3_CFG 0x0e081004
  35. #define AHCI_PORT_PHY_4_CFG 0x00480811
  36. #define AHCI_PORT_PHY_5_CFG 0x192c96a4
  37. #define AHCI_PORT_TRANS_CFG 0x08000025
  38. #define SATA_ECC_DISABLE 0x00020000
  39. enum ahci_qoriq_type {
  40. AHCI_LS1021A,
  41. AHCI_LS1043A,
  42. AHCI_LS2080A,
  43. };
  44. struct ahci_qoriq_priv {
  45. struct ccsr_ahci *reg_base;
  46. enum ahci_qoriq_type type;
  47. void __iomem *ecc_addr;
  48. };
  49. static const struct of_device_id ahci_qoriq_of_match[] = {
  50. { .compatible = "fsl,ls1021a-ahci", .data = (void *)AHCI_LS1021A},
  51. { .compatible = "fsl,ls1043a-ahci", .data = (void *)AHCI_LS1043A},
  52. { .compatible = "fsl,ls2080a-ahci", .data = (void *)AHCI_LS2080A},
  53. {},
  54. };
  55. MODULE_DEVICE_TABLE(of, ahci_qoriq_of_match);
  56. static int ahci_qoriq_hardreset(struct ata_link *link, unsigned int *class,
  57. unsigned long deadline)
  58. {
  59. const unsigned long *timing = sata_ehc_deb_timing(&link->eh_context);
  60. void __iomem *port_mmio = ahci_port_base(link->ap);
  61. u32 px_cmd, px_is, px_val;
  62. struct ata_port *ap = link->ap;
  63. struct ahci_port_priv *pp = ap->private_data;
  64. struct ahci_host_priv *hpriv = ap->host->private_data;
  65. struct ahci_qoriq_priv *qoriq_priv = hpriv->plat_data;
  66. u8 *d2h_fis = pp->rx_fis + RX_FIS_D2H_REG;
  67. struct ata_taskfile tf;
  68. bool online;
  69. int rc;
  70. bool ls1021a_workaround = (qoriq_priv->type == AHCI_LS1021A);
  71. DPRINTK("ENTER\n");
  72. ahci_stop_engine(ap);
  73. /*
  74. * There is a errata on ls1021a Rev1.0 and Rev2.0 which is:
  75. * A-009042: The device detection initialization sequence
  76. * mistakenly resets some registers.
  77. *
  78. * Workaround for this is:
  79. * The software should read and store PxCMD and PxIS values
  80. * before issuing the device detection initialization sequence.
  81. * After the sequence is complete, software should restore the
  82. * PxCMD and PxIS with the stored values.
  83. */
  84. if (ls1021a_workaround) {
  85. px_cmd = readl(port_mmio + PORT_CMD);
  86. px_is = readl(port_mmio + PORT_IRQ_STAT);
  87. }
  88. /* clear D2H reception area to properly wait for D2H FIS */
  89. ata_tf_init(link->device, &tf);
  90. tf.command = ATA_BUSY;
  91. ata_tf_to_fis(&tf, 0, 0, d2h_fis);
  92. rc = sata_link_hardreset(link, timing, deadline, &online,
  93. ahci_check_ready);
  94. /* restore the PxCMD and PxIS on ls1021 */
  95. if (ls1021a_workaround) {
  96. px_val = readl(port_mmio + PORT_CMD);
  97. if (px_val != px_cmd)
  98. writel(px_cmd, port_mmio + PORT_CMD);
  99. px_val = readl(port_mmio + PORT_IRQ_STAT);
  100. if (px_val != px_is)
  101. writel(px_is, port_mmio + PORT_IRQ_STAT);
  102. }
  103. hpriv->start_engine(ap);
  104. if (online)
  105. *class = ahci_dev_classify(ap);
  106. DPRINTK("EXIT, rc=%d, class=%u\n", rc, *class);
  107. return rc;
  108. }
  109. static struct ata_port_operations ahci_qoriq_ops = {
  110. .inherits = &ahci_ops,
  111. .hardreset = ahci_qoriq_hardreset,
  112. };
  113. static struct ata_port_info ahci_qoriq_port_info = {
  114. .flags = AHCI_FLAG_COMMON | ATA_FLAG_NCQ,
  115. .pio_mask = ATA_PIO4,
  116. .udma_mask = ATA_UDMA6,
  117. .port_ops = &ahci_qoriq_ops,
  118. };
  119. static struct scsi_host_template ahci_qoriq_sht = {
  120. AHCI_SHT(DRV_NAME),
  121. };
  122. static int ahci_qoriq_phy_init(struct ahci_host_priv *hpriv)
  123. {
  124. struct ahci_qoriq_priv *qpriv = hpriv->plat_data;
  125. void __iomem *reg_base = hpriv->mmio;
  126. switch (qpriv->type) {
  127. case AHCI_LS1021A:
  128. writel(SATA_ECC_DISABLE, qpriv->ecc_addr);
  129. writel(AHCI_PORT_PHY_1_CFG, reg_base + PORT_PHY1);
  130. writel(AHCI_PORT_PHY_2_CFG, reg_base + PORT_PHY2);
  131. writel(AHCI_PORT_PHY_3_CFG, reg_base + PORT_PHY3);
  132. writel(AHCI_PORT_PHY_4_CFG, reg_base + PORT_PHY4);
  133. writel(AHCI_PORT_PHY_5_CFG, reg_base + PORT_PHY5);
  134. writel(AHCI_PORT_TRANS_CFG, reg_base + PORT_TRANS);
  135. break;
  136. case AHCI_LS1043A:
  137. case AHCI_LS2080A:
  138. writel(AHCI_PORT_PHY_1_CFG, reg_base + PORT_PHY1);
  139. break;
  140. }
  141. return 0;
  142. }
  143. static int ahci_qoriq_probe(struct platform_device *pdev)
  144. {
  145. struct device_node *np = pdev->dev.of_node;
  146. struct device *dev = &pdev->dev;
  147. struct ahci_host_priv *hpriv;
  148. struct ahci_qoriq_priv *qoriq_priv;
  149. const struct of_device_id *of_id;
  150. struct resource *res;
  151. int rc;
  152. hpriv = ahci_platform_get_resources(pdev);
  153. if (IS_ERR(hpriv))
  154. return PTR_ERR(hpriv);
  155. of_id = of_match_node(ahci_qoriq_of_match, np);
  156. if (!of_id)
  157. return -ENODEV;
  158. qoriq_priv = devm_kzalloc(dev, sizeof(*qoriq_priv), GFP_KERNEL);
  159. if (!qoriq_priv)
  160. return -ENOMEM;
  161. qoriq_priv->type = (enum ahci_qoriq_type)of_id->data;
  162. if (qoriq_priv->type == AHCI_LS1021A) {
  163. res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
  164. "sata-ecc");
  165. qoriq_priv->ecc_addr = devm_ioremap_resource(dev, res);
  166. if (IS_ERR(qoriq_priv->ecc_addr))
  167. return PTR_ERR(qoriq_priv->ecc_addr);
  168. }
  169. rc = ahci_platform_enable_resources(hpriv);
  170. if (rc)
  171. return rc;
  172. hpriv->plat_data = qoriq_priv;
  173. rc = ahci_qoriq_phy_init(hpriv);
  174. if (rc)
  175. goto disable_resources;
  176. /* Workaround for ls2080a */
  177. if (qoriq_priv->type == AHCI_LS2080A) {
  178. hpriv->flags |= AHCI_HFLAG_NO_NCQ;
  179. ahci_qoriq_port_info.flags &= ~ATA_FLAG_NCQ;
  180. }
  181. rc = ahci_platform_init_host(pdev, hpriv, &ahci_qoriq_port_info,
  182. &ahci_qoriq_sht);
  183. if (rc)
  184. goto disable_resources;
  185. return 0;
  186. disable_resources:
  187. ahci_platform_disable_resources(hpriv);
  188. return rc;
  189. }
  190. #ifdef CONFIG_PM_SLEEP
  191. static int ahci_qoriq_resume(struct device *dev)
  192. {
  193. struct ata_host *host = dev_get_drvdata(dev);
  194. struct ahci_host_priv *hpriv = host->private_data;
  195. int rc;
  196. rc = ahci_platform_enable_resources(hpriv);
  197. if (rc)
  198. return rc;
  199. rc = ahci_qoriq_phy_init(hpriv);
  200. if (rc)
  201. goto disable_resources;
  202. rc = ahci_platform_resume_host(dev);
  203. if (rc)
  204. goto disable_resources;
  205. /* We resumed so update PM runtime state */
  206. pm_runtime_disable(dev);
  207. pm_runtime_set_active(dev);
  208. pm_runtime_enable(dev);
  209. return 0;
  210. disable_resources:
  211. ahci_platform_disable_resources(hpriv);
  212. return rc;
  213. }
  214. #endif
  215. static SIMPLE_DEV_PM_OPS(ahci_qoriq_pm_ops, ahci_platform_suspend,
  216. ahci_qoriq_resume);
  217. static struct platform_driver ahci_qoriq_driver = {
  218. .probe = ahci_qoriq_probe,
  219. .remove = ata_platform_remove_one,
  220. .driver = {
  221. .name = DRV_NAME,
  222. .of_match_table = ahci_qoriq_of_match,
  223. .pm = &ahci_qoriq_pm_ops,
  224. },
  225. };
  226. module_platform_driver(ahci_qoriq_driver);
  227. MODULE_DESCRIPTION("Freescale QorIQ AHCI SATA platform driver");
  228. MODULE_AUTHOR("Tang Yuantian <Yuantian.Tang@freescale.com>");
  229. MODULE_LICENSE("GPL");