ahci_platform.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 <jgarzik@pobox.com>
  7. * Copyright 2010 MontaVista Software, LLC.
  8. * Anton Vorontsov <avorontsov@ru.mvista.com>
  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. of_property_read_u32(dev->of_node,
  51. "ports-implemented", &hpriv->force_port_map);
  52. if (of_device_is_compatible(dev->of_node, "hisilicon,hisi-ahci"))
  53. hpriv->flags |= AHCI_HFLAG_NO_FBS | AHCI_HFLAG_NO_NCQ;
  54. port = acpi_device_get_match_data(dev);
  55. if (!port)
  56. port = &ahci_port_info;
  57. rc = ahci_platform_init_host(pdev, hpriv, port,
  58. &ahci_platform_sht);
  59. if (rc)
  60. goto disable_resources;
  61. return 0;
  62. disable_resources:
  63. ahci_platform_disable_resources(hpriv);
  64. return rc;
  65. }
  66. static SIMPLE_DEV_PM_OPS(ahci_pm_ops, ahci_platform_suspend,
  67. ahci_platform_resume);
  68. static const struct of_device_id ahci_of_match[] = {
  69. { .compatible = "generic-ahci", },
  70. /* Keep the following compatibles for device tree compatibility */
  71. { .compatible = "snps,spear-ahci", },
  72. { .compatible = "ibm,476gtr-ahci", },
  73. { .compatible = "snps,dwc-ahci", },
  74. { .compatible = "hisilicon,hisi-ahci", },
  75. { .compatible = "cavium,octeon-7130-ahci", },
  76. {},
  77. };
  78. MODULE_DEVICE_TABLE(of, ahci_of_match);
  79. static const struct acpi_device_id ahci_acpi_match[] = {
  80. { "APMC0D33", (unsigned long)&ahci_port_info_nolpm },
  81. { ACPI_DEVICE_CLASS(PCI_CLASS_STORAGE_SATA_AHCI, 0xffffff) },
  82. {},
  83. };
  84. MODULE_DEVICE_TABLE(acpi, ahci_acpi_match);
  85. static struct platform_driver ahci_driver = {
  86. .probe = ahci_probe,
  87. .remove = ata_platform_remove_one,
  88. .shutdown = ahci_platform_shutdown,
  89. .driver = {
  90. .name = DRV_NAME,
  91. .of_match_table = ahci_of_match,
  92. .acpi_match_table = ahci_acpi_match,
  93. .pm = &ahci_pm_ops,
  94. },
  95. };
  96. module_platform_driver(ahci_driver);
  97. MODULE_DESCRIPTION("AHCI SATA platform driver");
  98. MODULE_AUTHOR("Anton Vorontsov <avorontsov@ru.mvista.com>");
  99. MODULE_LICENSE("GPL");
  100. MODULE_ALIAS("platform:ahci");