ahci_mvebu.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 AHCI_VENDOR_SPECIFIC_0_ADDR 0xa0
  21. #define AHCI_VENDOR_SPECIFIC_0_DATA 0xa4
  22. #define AHCI_WINDOW_CTRL(win) (0x60 + ((win) << 4))
  23. #define AHCI_WINDOW_BASE(win) (0x64 + ((win) << 4))
  24. #define AHCI_WINDOW_SIZE(win) (0x68 + ((win) << 4))
  25. static void ahci_mvebu_mbus_config(struct ahci_host_priv *hpriv,
  26. const struct mbus_dram_target_info *dram)
  27. {
  28. int i;
  29. for (i = 0; i < 4; i++) {
  30. writel(0, hpriv->mmio + AHCI_WINDOW_CTRL(i));
  31. writel(0, hpriv->mmio + AHCI_WINDOW_BASE(i));
  32. writel(0, hpriv->mmio + AHCI_WINDOW_SIZE(i));
  33. }
  34. for (i = 0; i < dram->num_cs; i++) {
  35. const struct mbus_dram_window *cs = dram->cs + i;
  36. writel((cs->mbus_attr << 8) |
  37. (dram->mbus_dram_target_id << 4) | 1,
  38. hpriv->mmio + AHCI_WINDOW_CTRL(i));
  39. writel(cs->base, hpriv->mmio + AHCI_WINDOW_BASE(i));
  40. writel(((cs->size - 1) & 0xffff0000),
  41. hpriv->mmio + AHCI_WINDOW_SIZE(i));
  42. }
  43. }
  44. static void ahci_mvebu_regret_option(struct ahci_host_priv *hpriv)
  45. {
  46. /*
  47. * Enable the regret bit to allow the SATA unit to regret a
  48. * request that didn't receive an acknowlegde and avoid a
  49. * deadlock
  50. */
  51. writel(0x4, hpriv->mmio + AHCI_VENDOR_SPECIFIC_0_ADDR);
  52. writel(0x80, hpriv->mmio + AHCI_VENDOR_SPECIFIC_0_DATA);
  53. }
  54. static const struct ata_port_info ahci_mvebu_port_info = {
  55. .flags = AHCI_FLAG_COMMON,
  56. .pio_mask = ATA_PIO4,
  57. .udma_mask = ATA_UDMA6,
  58. .port_ops = &ahci_platform_ops,
  59. };
  60. static int ahci_mvebu_probe(struct platform_device *pdev)
  61. {
  62. struct ahci_host_priv *hpriv;
  63. const struct mbus_dram_target_info *dram;
  64. int rc;
  65. hpriv = ahci_platform_get_resources(pdev);
  66. if (IS_ERR(hpriv))
  67. return PTR_ERR(hpriv);
  68. rc = ahci_platform_enable_resources(hpriv);
  69. if (rc)
  70. return rc;
  71. dram = mv_mbus_dram_info();
  72. if (!dram)
  73. return -ENODEV;
  74. ahci_mvebu_mbus_config(hpriv, dram);
  75. ahci_mvebu_regret_option(hpriv);
  76. rc = ahci_platform_init_host(pdev, hpriv, &ahci_mvebu_port_info);
  77. if (rc)
  78. goto disable_resources;
  79. return 0;
  80. disable_resources:
  81. ahci_platform_disable_resources(hpriv);
  82. return rc;
  83. }
  84. static const struct of_device_id ahci_mvebu_of_match[] = {
  85. { .compatible = "marvell,armada-380-ahci", },
  86. { },
  87. };
  88. MODULE_DEVICE_TABLE(of, ahci_mvebu_of_match);
  89. /*
  90. * We currently don't provide power management related operations,
  91. * since there is no suspend/resume support at the platform level for
  92. * Armada 38x for the moment.
  93. */
  94. static struct platform_driver ahci_mvebu_driver = {
  95. .probe = ahci_mvebu_probe,
  96. .remove = ata_platform_remove_one,
  97. .driver = {
  98. .name = "ahci-mvebu",
  99. .of_match_table = ahci_mvebu_of_match,
  100. },
  101. };
  102. module_platform_driver(ahci_mvebu_driver);
  103. MODULE_DESCRIPTION("Marvell EBU AHCI SATA driver");
  104. MODULE_AUTHOR("Thomas Petazzoni <thomas.petazzoni@free-electrons.com>, Marcin Wojtas <mw@semihalf.com>");
  105. MODULE_LICENSE("GPL");
  106. MODULE_ALIAS("platform:ahci_mvebu");