diff options
Diffstat (limited to 'drivers/ata/ahci_platform.c')
| -rw-r--r-- | drivers/ata/ahci_platform.c | 174 | 
1 files changed, 41 insertions, 133 deletions
diff --git a/drivers/ata/ahci_platform.c b/drivers/ata/ahci_platform.c index 6fef1fa75c5..b10d81ddb52 100644 --- a/drivers/ata/ahci_platform.c +++ b/drivers/ata/ahci_platform.c @@ -13,67 +13,37 @@   */  #include <linux/kernel.h> -#include <linux/gfp.h>  #include <linux/module.h> -#include <linux/init.h> -#include <linux/interrupt.h> +#include <linux/pm.h>  #include <linux/device.h> +#include <linux/of_device.h>  #include <linux/platform_device.h>  #include <linux/libata.h>  #include <linux/ahci_platform.h>  #include "ahci.h" -static struct scsi_host_template ahci_platform_sht = { -	AHCI_SHT("ahci_platform"), +static const struct ata_port_info ahci_port_info = { +	.flags		= AHCI_FLAG_COMMON, +	.pio_mask	= ATA_PIO4, +	.udma_mask	= ATA_UDMA6, +	.port_ops	= &ahci_platform_ops,  }; -static int __init ahci_probe(struct platform_device *pdev) +static int ahci_probe(struct platform_device *pdev)  {  	struct device *dev = &pdev->dev; -	struct ahci_platform_data *pdata = dev->platform_data; -	struct ata_port_info pi = { -		.flags		= AHCI_FLAG_COMMON, -		.pio_mask	= ATA_PIO4, -		.udma_mask	= ATA_UDMA6, -		.port_ops	= &ahci_ops, -	}; -	const struct ata_port_info *ppi[] = { &pi, NULL }; +	struct ahci_platform_data *pdata = dev_get_platdata(dev);  	struct ahci_host_priv *hpriv; -	struct ata_host *host; -	struct resource *mem; -	int irq; -	int n_ports; -	int i; +	unsigned long hflags = 0;  	int rc; -	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); -	if (!mem) { -		dev_err(dev, "no mmio space\n"); -		return -EINVAL; -	} - -	irq = platform_get_irq(pdev, 0); -	if (irq <= 0) { -		dev_err(dev, "no irq\n"); -		return -EINVAL; -	} - -	if (pdata && pdata->ata_port_info) -		pi = *pdata->ata_port_info; - -	hpriv = devm_kzalloc(dev, sizeof(*hpriv), GFP_KERNEL); -	if (!hpriv) { -		dev_err(dev, "can't alloc ahci_host_priv\n"); -		return -ENOMEM; -	} +	hpriv = ahci_platform_get_resources(pdev); +	if (IS_ERR(hpriv)) +		return PTR_ERR(hpriv); -	hpriv->flags |= (unsigned long)pi.private_data; - -	hpriv->mmio = devm_ioremap(dev, mem->start, resource_size(mem)); -	if (!hpriv->mmio) { -		dev_err(dev, "can't map %pR\n", mem); -		return -ENOMEM; -	} +	rc = ahci_platform_enable_resources(hpriv); +	if (rc) +		return rc;  	/*  	 * Some platforms might need to prepare for mmio region access, @@ -84,112 +54,50 @@ static int __init ahci_probe(struct platform_device *pdev)  	if (pdata && pdata->init) {  		rc = pdata->init(dev, hpriv->mmio);  		if (rc) -			return rc; -	} - -	ahci_save_initial_config(dev, hpriv, -		pdata ? pdata->force_port_map : 0, -		pdata ? pdata->mask_port_map  : 0); - -	/* prepare host */ -	if (hpriv->cap & HOST_CAP_NCQ) -		pi.flags |= ATA_FLAG_NCQ; - -	if (hpriv->cap & HOST_CAP_PMP) -		pi.flags |= ATA_FLAG_PMP; - -	ahci_set_em_messages(hpriv, &pi); - -	/* CAP.NP sometimes indicate the index of the last enabled -	 * port, at other times, that of the last possible port, so -	 * determining the maximum port number requires looking at -	 * both CAP.NP and port_map. -	 */ -	n_ports = max(ahci_nr_ports(hpriv->cap), fls(hpriv->port_map)); - -	host = ata_host_alloc_pinfo(dev, ppi, n_ports); -	if (!host) { -		rc = -ENOMEM; -		goto err0; -	} - -	host->private_data = hpriv; - -	if (!(hpriv->cap & HOST_CAP_SSS) || ahci_ignore_sss) -		host->flags |= ATA_HOST_PARALLEL_SCAN; -	else -		printk(KERN_INFO "ahci: SSS flag set, parallel bus scan disabled\n"); - -	if (pi.flags & ATA_FLAG_EM) -		ahci_reset_em(host); - -	for (i = 0; i < host->n_ports; i++) { -		struct ata_port *ap = host->ports[i]; - -		ata_port_desc(ap, "mmio %pR", mem); -		ata_port_desc(ap, "port 0x%x", 0x100 + ap->port_no * 0x80); - -		/* set enclosure management message type */ -		if (ap->flags & ATA_FLAG_EM) -			ap->em_message_type = hpriv->em_msg_type; - -		/* disabled/not-implemented port */ -		if (!(hpriv->port_map & (1 << i))) -			ap->ops = &ata_dummy_port_ops; +			goto disable_resources;  	} -	rc = ahci_reset_controller(host); -	if (rc) -		goto err0; - -	ahci_init_controller(host); -	ahci_print_info(host, "platform"); +	if (of_device_is_compatible(dev->of_node, "hisilicon,hisi-ahci")) +		hflags |= AHCI_HFLAG_NO_FBS | AHCI_HFLAG_NO_NCQ; -	rc = ata_host_activate(host, irq, ahci_interrupt, IRQF_SHARED, -			       &ahci_platform_sht); +	rc = ahci_platform_init_host(pdev, hpriv, &ahci_port_info, +				     hflags, 0, 0);  	if (rc) -		goto err0; +		goto pdata_exit;  	return 0; -err0: +pdata_exit:  	if (pdata && pdata->exit)  		pdata->exit(dev); +disable_resources: +	ahci_platform_disable_resources(hpriv);  	return rc;  } -static int __devexit ahci_remove(struct platform_device *pdev) -{ -	struct device *dev = &pdev->dev; -	struct ahci_platform_data *pdata = dev->platform_data; -	struct ata_host *host = dev_get_drvdata(dev); - -	ata_host_detach(host); +static SIMPLE_DEV_PM_OPS(ahci_pm_ops, ahci_platform_suspend, +			 ahci_platform_resume); -	if (pdata && pdata->exit) -		pdata->exit(dev); - -	return 0; -} +static const struct of_device_id ahci_of_match[] = { +	{ .compatible = "snps,spear-ahci", }, +	{ .compatible = "snps,exynos5440-ahci", }, +	{ .compatible = "ibm,476gtr-ahci", }, +	{ .compatible = "snps,dwc-ahci", }, +	{ .compatible = "hisilicon,hisi-ahci", }, +	{}, +}; +MODULE_DEVICE_TABLE(of, ahci_of_match);  static struct platform_driver ahci_driver = { -	.remove = __devexit_p(ahci_remove), +	.probe = ahci_probe, +	.remove = ata_platform_remove_one,  	.driver = {  		.name = "ahci",  		.owner = THIS_MODULE, +		.of_match_table = ahci_of_match, +		.pm = &ahci_pm_ops,  	},  }; - -static int __init ahci_init(void) -{ -	return platform_driver_probe(&ahci_driver, ahci_probe); -} -module_init(ahci_init); - -static void __exit ahci_exit(void) -{ -	platform_driver_unregister(&ahci_driver); -} -module_exit(ahci_exit); +module_platform_driver(ahci_driver);  MODULE_DESCRIPTION("AHCI SATA platform driver");  MODULE_AUTHOR("Anton Vorontsov <avorontsov@ru.mvista.com>");  | 
