ahci_qoriq.c 7.6 KB

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