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