ahci_platform.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * AHCI SATA platform driver
  4. *
  5. * Copyright 2004-2005 Red Hat, Inc.
  6. * Jeff Garzik <[email protected]>
  7. * Copyright 2010 MontaVista Software, LLC.
  8. * Anton Vorontsov <[email protected]>
  9. */
  10. #include <linux/kernel.h>
  11. #include <linux/module.h>
  12. #include <linux/pm.h>
  13. #include <linux/device.h>
  14. #include <linux/of_device.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/libata.h>
  17. #include <linux/ahci_platform.h>
  18. #include <linux/acpi.h>
  19. #include <linux/pci_ids.h>
  20. #include "ahci.h"
  21. #define DRV_NAME "ahci"
  22. static const struct ata_port_info ahci_port_info = {
  23. .flags = AHCI_FLAG_COMMON,
  24. .pio_mask = ATA_PIO4,
  25. .udma_mask = ATA_UDMA6,
  26. .port_ops = &ahci_platform_ops,
  27. };
  28. static const struct ata_port_info ahci_port_info_nolpm = {
  29. .flags = AHCI_FLAG_COMMON | ATA_FLAG_NO_LPM,
  30. .pio_mask = ATA_PIO4,
  31. .udma_mask = ATA_UDMA6,
  32. .port_ops = &ahci_platform_ops,
  33. };
  34. static struct scsi_host_template ahci_platform_sht = {
  35. AHCI_SHT(DRV_NAME),
  36. };
  37. static int ahci_probe(struct platform_device *pdev)
  38. {
  39. struct device *dev = &pdev->dev;
  40. struct ahci_host_priv *hpriv;
  41. const struct ata_port_info *port;
  42. int rc;
  43. hpriv = ahci_platform_get_resources(pdev,
  44. AHCI_PLATFORM_GET_RESETS);
  45. if (IS_ERR(hpriv))
  46. return PTR_ERR(hpriv);
  47. rc = ahci_platform_enable_resources(hpriv);
  48. if (rc)
  49. return rc;
  50. if (of_device_is_compatible(dev->of_node, "hisilicon,hisi-ahci"))
  51. hpriv->flags |= AHCI_HFLAG_NO_FBS | AHCI_HFLAG_NO_NCQ;
  52. port = acpi_device_get_match_data(dev);
  53. if (!port)
  54. port = &ahci_port_info;
  55. rc = ahci_platform_init_host(pdev, hpriv, port,
  56. &ahci_platform_sht);
  57. if (rc)
  58. goto disable_resources;
  59. return 0;
  60. disable_resources:
  61. ahci_platform_disable_resources(hpriv);
  62. return rc;
  63. }
  64. static SIMPLE_DEV_PM_OPS(ahci_pm_ops, ahci_platform_suspend,
  65. ahci_platform_resume);
  66. static const struct of_device_id ahci_of_match[] = {
  67. { .compatible = "generic-ahci", },
  68. /* Keep the following compatibles for device tree compatibility */
  69. { .compatible = "ibm,476gtr-ahci", },
  70. { .compatible = "hisilicon,hisi-ahci", },
  71. { .compatible = "cavium,octeon-7130-ahci", },
  72. { /* sentinel */ }
  73. };
  74. MODULE_DEVICE_TABLE(of, ahci_of_match);
  75. static const struct acpi_device_id ahci_acpi_match[] = {
  76. { "APMC0D33", (unsigned long)&ahci_port_info_nolpm },
  77. { ACPI_DEVICE_CLASS(PCI_CLASS_STORAGE_SATA_AHCI, 0xffffff) },
  78. {},
  79. };
  80. MODULE_DEVICE_TABLE(acpi, ahci_acpi_match);
  81. static struct platform_driver ahci_driver = {
  82. .probe = ahci_probe,
  83. .remove = ata_platform_remove_one,
  84. .shutdown = ahci_platform_shutdown,
  85. .driver = {
  86. .name = DRV_NAME,
  87. .of_match_table = ahci_of_match,
  88. .acpi_match_table = ahci_acpi_match,
  89. .pm = &ahci_pm_ops,
  90. },
  91. };
  92. module_platform_driver(ahci_driver);
  93. MODULE_DESCRIPTION("AHCI SATA platform driver");
  94. MODULE_AUTHOR("Anton Vorontsov <[email protected]>");
  95. MODULE_LICENSE("GPL");
  96. MODULE_ALIAS("platform:ahci");