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