ahci_qoriq.c 7.3 KB

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