ahci_mvebu.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /*
  2. * AHCI glue platform driver for Marvell EBU SOCs
  3. *
  4. * Copyright (C) 2014 Marvell
  5. *
  6. * Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
  7. * Marcin Wojtas <mw@semihalf.com>
  8. *
  9. * This file is licensed under the terms of the GNU General Public
  10. * License version 2. This program is licensed "as is" without any
  11. * warranty of any kind, whether express or implied.
  12. */
  13. #include <linux/ahci_platform.h>
  14. #include <linux/kernel.h>
  15. #include <linux/mbus.h>
  16. #include <linux/module.h>
  17. #include <linux/of_device.h>
  18. #include <linux/platform_device.h>
  19. #include "ahci.h"
  20. #define DRV_NAME "ahci-mvebu"
  21. #define AHCI_VENDOR_SPECIFIC_0_ADDR 0xa0
  22. #define AHCI_VENDOR_SPECIFIC_0_DATA 0xa4
  23. #define AHCI_WINDOW_CTRL(win) (0x60 + ((win) << 4))
  24. #define AHCI_WINDOW_BASE(win) (0x64 + ((win) << 4))
  25. #define AHCI_WINDOW_SIZE(win) (0x68 + ((win) << 4))
  26. static void ahci_mvebu_mbus_config(struct ahci_host_priv *hpriv,
  27. const struct mbus_dram_target_info *dram)
  28. {
  29. int i;
  30. for (i = 0; i < 4; i++) {
  31. writel(0, hpriv->mmio + AHCI_WINDOW_CTRL(i));
  32. writel(0, hpriv->mmio + AHCI_WINDOW_BASE(i));
  33. writel(0, hpriv->mmio + AHCI_WINDOW_SIZE(i));
  34. }
  35. for (i = 0; i < dram->num_cs; i++) {
  36. const struct mbus_dram_window *cs = dram->cs + i;
  37. writel((cs->mbus_attr << 8) |
  38. (dram->mbus_dram_target_id << 4) | 1,
  39. hpriv->mmio + AHCI_WINDOW_CTRL(i));
  40. writel(cs->base >> 16, hpriv->mmio + AHCI_WINDOW_BASE(i));
  41. writel(((cs->size - 1) & 0xffff0000),
  42. hpriv->mmio + AHCI_WINDOW_SIZE(i));
  43. }
  44. }
  45. static void ahci_mvebu_regret_option(struct ahci_host_priv *hpriv)
  46. {
  47. /*
  48. * Enable the regret bit to allow the SATA unit to regret a
  49. * request that didn't receive an acknowlegde and avoid a
  50. * deadlock
  51. */
  52. writel(0x4, hpriv->mmio + AHCI_VENDOR_SPECIFIC_0_ADDR);
  53. writel(0x80, hpriv->mmio + AHCI_VENDOR_SPECIFIC_0_DATA);
  54. }
  55. #ifdef CONFIG_PM_SLEEP
  56. static int ahci_mvebu_suspend(struct platform_device *pdev, pm_message_t state)
  57. {
  58. return ahci_platform_suspend_host(&pdev->dev);
  59. }
  60. static int ahci_mvebu_resume(struct platform_device *pdev)
  61. {
  62. struct ata_host *host = platform_get_drvdata(pdev);
  63. struct ahci_host_priv *hpriv = host->private_data;
  64. const struct mbus_dram_target_info *dram;
  65. dram = mv_mbus_dram_info();
  66. if (dram)
  67. ahci_mvebu_mbus_config(hpriv, dram);
  68. ahci_mvebu_regret_option(hpriv);
  69. return ahci_platform_resume_host(&pdev->dev);
  70. }
  71. #else
  72. #define ahci_mvebu_suspend NULL
  73. #define ahci_mvebu_resume NULL
  74. #endif
  75. static const struct ata_port_info ahci_mvebu_port_info = {
  76. .flags = AHCI_FLAG_COMMON,
  77. .pio_mask = ATA_PIO4,
  78. .udma_mask = ATA_UDMA6,
  79. .port_ops = &ahci_platform_ops,
  80. };
  81. static struct scsi_host_template ahci_platform_sht = {
  82. AHCI_SHT(DRV_NAME),
  83. };
  84. static int ahci_mvebu_probe(struct platform_device *pdev)
  85. {
  86. struct ahci_host_priv *hpriv;
  87. const struct mbus_dram_target_info *dram;
  88. int rc;
  89. hpriv = ahci_platform_get_resources(pdev);
  90. if (IS_ERR(hpriv))
  91. return PTR_ERR(hpriv);
  92. rc = ahci_platform_enable_resources(hpriv);
  93. if (rc)
  94. return rc;
  95. dram = mv_mbus_dram_info();
  96. if (!dram)
  97. return -ENODEV;
  98. ahci_mvebu_mbus_config(hpriv, dram);
  99. ahci_mvebu_regret_option(hpriv);
  100. rc = ahci_platform_init_host(pdev, hpriv, &ahci_mvebu_port_info,
  101. &ahci_platform_sht);
  102. if (rc)
  103. goto disable_resources;
  104. return 0;
  105. disable_resources:
  106. ahci_platform_disable_resources(hpriv);
  107. return rc;
  108. }
  109. static const struct of_device_id ahci_mvebu_of_match[] = {
  110. { .compatible = "marvell,armada-380-ahci", },
  111. { },
  112. };
  113. MODULE_DEVICE_TABLE(of, ahci_mvebu_of_match);
  114. /*
  115. * We currently don't provide power management related operations,
  116. * since there is no suspend/resume support at the platform level for
  117. * Armada 38x for the moment.
  118. */
  119. static struct platform_driver ahci_mvebu_driver = {
  120. .probe = ahci_mvebu_probe,
  121. .remove = ata_platform_remove_one,
  122. .suspend = ahci_mvebu_suspend,
  123. .resume = ahci_mvebu_resume,
  124. .driver = {
  125. .name = DRV_NAME,
  126. .of_match_table = ahci_mvebu_of_match,
  127. },
  128. };
  129. module_platform_driver(ahci_mvebu_driver);
  130. MODULE_DESCRIPTION("Marvell EBU AHCI SATA driver");
  131. MODULE_AUTHOR("Thomas Petazzoni <thomas.petazzoni@free-electrons.com>, Marcin Wojtas <mw@semihalf.com>");
  132. MODULE_LICENSE("GPL");
  133. MODULE_ALIAS("platform:ahci_mvebu");