Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  * AHCI SATA platform driver
0004  *
0005  * Copyright 2004-2005  Red Hat, Inc.
0006  *   Jeff Garzik <jgarzik@pobox.com>
0007  * Copyright 2010  MontaVista Software, LLC.
0008  *   Anton Vorontsov <avorontsov@ru.mvista.com>
0009  */
0010 
0011 #include <linux/kernel.h>
0012 #include <linux/module.h>
0013 #include <linux/pm.h>
0014 #include <linux/device.h>
0015 #include <linux/of_device.h>
0016 #include <linux/platform_device.h>
0017 #include <linux/libata.h>
0018 #include <linux/ahci_platform.h>
0019 #include <linux/acpi.h>
0020 #include <linux/pci_ids.h>
0021 #include "ahci.h"
0022 
0023 #define DRV_NAME "ahci"
0024 
0025 static const struct ata_port_info ahci_port_info = {
0026     .flags      = AHCI_FLAG_COMMON,
0027     .pio_mask   = ATA_PIO4,
0028     .udma_mask  = ATA_UDMA6,
0029     .port_ops   = &ahci_platform_ops,
0030 };
0031 
0032 static const struct ata_port_info ahci_port_info_nolpm = {
0033     .flags      = AHCI_FLAG_COMMON | ATA_FLAG_NO_LPM,
0034     .pio_mask   = ATA_PIO4,
0035     .udma_mask  = ATA_UDMA6,
0036     .port_ops   = &ahci_platform_ops,
0037 };
0038 
0039 static struct scsi_host_template ahci_platform_sht = {
0040     AHCI_SHT(DRV_NAME),
0041 };
0042 
0043 static int ahci_probe(struct platform_device *pdev)
0044 {
0045     struct device *dev = &pdev->dev;
0046     struct ahci_host_priv *hpriv;
0047     const struct ata_port_info *port;
0048     int rc;
0049 
0050     hpriv = ahci_platform_get_resources(pdev,
0051                         AHCI_PLATFORM_GET_RESETS);
0052     if (IS_ERR(hpriv))
0053         return PTR_ERR(hpriv);
0054 
0055     rc = ahci_platform_enable_resources(hpriv);
0056     if (rc)
0057         return rc;
0058 
0059     of_property_read_u32(dev->of_node,
0060                  "ports-implemented", &hpriv->force_port_map);
0061 
0062     if (of_device_is_compatible(dev->of_node, "hisilicon,hisi-ahci"))
0063         hpriv->flags |= AHCI_HFLAG_NO_FBS | AHCI_HFLAG_NO_NCQ;
0064 
0065     port = acpi_device_get_match_data(dev);
0066     if (!port)
0067         port = &ahci_port_info;
0068 
0069     rc = ahci_platform_init_host(pdev, hpriv, port,
0070                      &ahci_platform_sht);
0071     if (rc)
0072         goto disable_resources;
0073 
0074     return 0;
0075 disable_resources:
0076     ahci_platform_disable_resources(hpriv);
0077     return rc;
0078 }
0079 
0080 static SIMPLE_DEV_PM_OPS(ahci_pm_ops, ahci_platform_suspend,
0081              ahci_platform_resume);
0082 
0083 static const struct of_device_id ahci_of_match[] = {
0084     { .compatible = "generic-ahci", },
0085     /* Keep the following compatibles for device tree compatibility */
0086     { .compatible = "snps,spear-ahci", },
0087     { .compatible = "ibm,476gtr-ahci", },
0088     { .compatible = "snps,dwc-ahci", },
0089     { .compatible = "hisilicon,hisi-ahci", },
0090     { .compatible = "cavium,octeon-7130-ahci", },
0091     { /* sentinel */ }
0092 };
0093 MODULE_DEVICE_TABLE(of, ahci_of_match);
0094 
0095 static const struct acpi_device_id ahci_acpi_match[] = {
0096     { "APMC0D33", (unsigned long)&ahci_port_info_nolpm },
0097     { ACPI_DEVICE_CLASS(PCI_CLASS_STORAGE_SATA_AHCI, 0xffffff) },
0098     {},
0099 };
0100 MODULE_DEVICE_TABLE(acpi, ahci_acpi_match);
0101 
0102 static struct platform_driver ahci_driver = {
0103     .probe = ahci_probe,
0104     .remove = ata_platform_remove_one,
0105     .shutdown = ahci_platform_shutdown,
0106     .driver = {
0107         .name = DRV_NAME,
0108         .of_match_table = ahci_of_match,
0109         .acpi_match_table = ahci_acpi_match,
0110         .pm = &ahci_pm_ops,
0111     },
0112 };
0113 module_platform_driver(ahci_driver);
0114 
0115 MODULE_DESCRIPTION("AHCI SATA platform driver");
0116 MODULE_AUTHOR("Anton Vorontsov <avorontsov@ru.mvista.com>");
0117 MODULE_LICENSE("GPL");
0118 MODULE_ALIAS("platform:ahci");