ahci_mvebu.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. static int ahci_mvebu_suspend(struct platform_device *pdev, pm_message_t state)
  56. {
  57. return ahci_platform_suspend_host(&pdev->dev);
  58. }
  59. static int ahci_mvebu_resume(struct platform_device *pdev)
  60. {
  61. struct ata_host *host = platform_get_drvdata(pdev);
  62. struct ahci_host_priv *hpriv = host->private_data;
  63. const struct mbus_dram_target_info *dram;
  64. dram = mv_mbus_dram_info();
  65. if (dram)
  66. ahci_mvebu_mbus_config(hpriv, dram);
  67. ahci_mvebu_regret_option(hpriv);
  68. return ahci_platform_resume_host(&pdev->dev);
  69. }
  70. static const struct ata_port_info ahci_mvebu_port_info = {
  71. .flags = AHCI_FLAG_COMMON,
  72. .pio_mask = ATA_PIO4,
  73. .udma_mask = ATA_UDMA6,
  74. .port_ops = &ahci_platform_ops,
  75. };
  76. static struct scsi_host_template ahci_platform_sht = {
  77. AHCI_SHT(DRV_NAME),
  78. };
  79. static int ahci_mvebu_probe(struct platform_device *pdev)
  80. {
  81. struct ahci_host_priv *hpriv;
  82. const struct mbus_dram_target_info *dram;
  83. int rc;
  84. hpriv = ahci_platform_get_resources(pdev);
  85. if (IS_ERR(hpriv))
  86. return PTR_ERR(hpriv);
  87. rc = ahci_platform_enable_resources(hpriv);
  88. if (rc)
  89. return rc;
  90. dram = mv_mbus_dram_info();
  91. if (!dram)
  92. return -ENODEV;
  93. ahci_mvebu_mbus_config(hpriv, dram);
  94. ahci_mvebu_regret_option(hpriv);
  95. rc = ahci_platform_init_host(pdev, hpriv, &ahci_mvebu_port_info,
  96. &ahci_platform_sht);
  97. if (rc)
  98. goto disable_resources;
  99. return 0;
  100. disable_resources:
  101. ahci_platform_disable_resources(hpriv);
  102. return rc;
  103. }
  104. static const struct of_device_id ahci_mvebu_of_match[] = {
  105. { .compatible = "marvell,armada-380-ahci", },
  106. { },
  107. };
  108. MODULE_DEVICE_TABLE(of, ahci_mvebu_of_match);
  109. /*
  110. * We currently don't provide power management related operations,
  111. * since there is no suspend/resume support at the platform level for
  112. * Armada 38x for the moment.
  113. */
  114. static struct platform_driver ahci_mvebu_driver = {
  115. .probe = ahci_mvebu_probe,
  116. .remove = ata_platform_remove_one,
  117. .suspend = ahci_mvebu_suspend,
  118. .resume = ahci_mvebu_resume,
  119. .driver = {
  120. .name = DRV_NAME,
  121. .of_match_table = ahci_mvebu_of_match,
  122. },
  123. };
  124. module_platform_driver(ahci_mvebu_driver);
  125. MODULE_DESCRIPTION("Marvell EBU AHCI SATA driver");
  126. MODULE_AUTHOR("Thomas Petazzoni <thomas.petazzoni@free-electrons.com>, Marcin Wojtas <mw@semihalf.com>");
  127. MODULE_LICENSE("GPL");
  128. MODULE_ALIAS("platform:ahci_mvebu");