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 11 #include <linux/kernel.h> 12 #include <linux/module.h> 13 #include <linux/pm.h> 14 #include <linux/device.h> 15 #include <linux/platform_device.h> 16 #include <linux/property.h> 17 #include <linux/libata.h> 18 #include <linux/ahci_platform.h> 19 #include <linux/pci_ids.h> 20 #include "ahci.h" 21 22 #define DRV_NAME "ahci" 23 24 static const struct ata_port_info ahci_port_info = { 25 .flags = AHCI_FLAG_COMMON, 26 .pio_mask = ATA_PIO4, 27 .udma_mask = ATA_UDMA6, 28 .port_ops = &ahci_platform_ops, 29 }; 30 31 static const struct ata_port_info ahci_port_info_nolpm = { 32 .flags = AHCI_FLAG_COMMON | ATA_FLAG_NO_LPM, 33 .pio_mask = ATA_PIO4, 34 .udma_mask = ATA_UDMA6, 35 .port_ops = &ahci_platform_ops, 36 }; 37 38 static const struct scsi_host_template ahci_platform_sht = { 39 AHCI_SHT(DRV_NAME), 40 }; 41 42 static int ahci_probe(struct platform_device *pdev) 43 { 44 struct device *dev = &pdev->dev; 45 struct ahci_host_priv *hpriv; 46 const struct ata_port_info *port; 47 int rc; 48 49 hpriv = ahci_platform_get_resources(pdev, 50 AHCI_PLATFORM_GET_RESETS); 51 if (IS_ERR(hpriv)) 52 return PTR_ERR(hpriv); 53 54 rc = ahci_platform_enable_resources(hpriv); 55 if (rc) 56 return rc; 57 58 if (device_is_compatible(dev, "hisilicon,hisi-ahci")) 59 hpriv->flags |= AHCI_HFLAG_NO_FBS | AHCI_HFLAG_NO_NCQ; 60 61 port = device_get_match_data(dev); 62 if (!port) 63 port = &ahci_port_info; 64 65 rc = ahci_platform_init_host(pdev, hpriv, port, 66 &ahci_platform_sht); 67 if (rc) 68 goto disable_resources; 69 70 return 0; 71 disable_resources: 72 ahci_platform_disable_resources(hpriv); 73 return rc; 74 } 75 76 static SIMPLE_DEV_PM_OPS(ahci_pm_ops, ahci_platform_suspend, 77 ahci_platform_resume); 78 79 static const struct of_device_id ahci_of_match[] = { 80 { .compatible = "generic-ahci", }, 81 /* Keep the following compatibles for device tree compatibility */ 82 { .compatible = "ibm,476gtr-ahci", }, 83 { .compatible = "hisilicon,hisi-ahci", }, 84 { .compatible = "cavium,octeon-7130-ahci", }, 85 { /* sentinel */ } 86 }; 87 MODULE_DEVICE_TABLE(of, ahci_of_match); 88 89 static const struct acpi_device_id ahci_acpi_match[] = { 90 { "APMC0D33", (unsigned long)&ahci_port_info_nolpm }, 91 { ACPI_DEVICE_CLASS(PCI_CLASS_STORAGE_SATA_AHCI, 0xffffff) }, 92 {}, 93 }; 94 MODULE_DEVICE_TABLE(acpi, ahci_acpi_match); 95 96 static struct platform_driver ahci_driver = { 97 .probe = ahci_probe, 98 .remove = ata_platform_remove_one, 99 .shutdown = ahci_platform_shutdown, 100 .driver = { 101 .name = DRV_NAME, 102 .of_match_table = ahci_of_match, 103 .acpi_match_table = ahci_acpi_match, 104 .pm = &ahci_pm_ops, 105 }, 106 }; 107 module_platform_driver(ahci_driver); 108 109 MODULE_DESCRIPTION("AHCI SATA platform driver"); 110 MODULE_AUTHOR("Anton Vorontsov <avorontsov@ru.mvista.com>"); 111 MODULE_LICENSE("GPL"); 112 MODULE_ALIAS("platform:ahci"); 113