From 332c42a9ff7f75a4d9dd263a6e5da32b45de12ec Mon Sep 17 00:00:00 2001 From: Samuel Morris Date: Tue, 29 May 2018 10:06:11 +0000 Subject: ata: ahci: rpm_put port on port_stop to match rpm_get in port_start This change balances out the final ahci_port_resume in port_start to ensure reference counts are correct after port stop. Signed-off-by: Samuel Morris Signed-off-by: Tejun Heo --- drivers/ata/libahci.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'drivers/ata') diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c index 965842a08743..5038cee7d982 100644 --- a/drivers/ata/libahci.c +++ b/drivers/ata/libahci.c @@ -2436,6 +2436,8 @@ static void ahci_port_stop(struct ata_port *ap) * re-enabling INTx. */ writel(1 << ap->port_no, host_mmio + HOST_IRQ_STAT); + + ahci_rpm_put_port(ap); } void ahci_print_info(struct ata_host *host, const char *scc_s) -- cgit v1.2.3 From aece27a2f01be4bb7683790f69cd1bed3a0929a2 Mon Sep 17 00:00:00 2001 From: Samuel Morris Date: Tue, 29 May 2018 10:06:12 +0000 Subject: ata: ahci_platform: allow disabling of hotplug to save power A number of resources remain powered to support hotplug. On platforms I've worked with, allowing the ahci_platform to suspend saves about 150mW. This patch enables rpm and allows the device to be auto-suspended through sysfs. Signed-off-by: Samuel Morris Signed-off-by: Tejun Heo --- drivers/ata/ahci_platform.c | 11 ++++-- drivers/ata/libahci_platform.c | 82 +++++++++++++++++++++++++++++++++--------- include/linux/ahci_platform.h | 2 ++ 3 files changed, 76 insertions(+), 19 deletions(-) (limited to 'drivers/ata') diff --git a/drivers/ata/ahci_platform.c b/drivers/ata/ahci_platform.c index 99f9a895a459..757729376eda 100644 --- a/drivers/ata/ahci_platform.c +++ b/drivers/ata/ahci_platform.c @@ -68,8 +68,13 @@ disable_resources: return rc; } -static SIMPLE_DEV_PM_OPS(ahci_pm_ops, ahci_platform_suspend, - ahci_platform_resume); +#ifdef CONFIG_PM_SLEEP +static const struct dev_pm_ops ahci_pm_ops = { + SET_SYSTEM_SLEEP_PM_OPS(ahci_platform_suspend, ahci_platform_resume) + SET_RUNTIME_PM_OPS(ahci_platform_runtime_suspend, + ahci_platform_runtime_resume, NULL) +}; +#endif static const struct of_device_id ahci_of_match[] = { { .compatible = "generic-ahci", }, @@ -98,7 +103,9 @@ static struct platform_driver ahci_driver = { .name = DRV_NAME, .of_match_table = ahci_of_match, .acpi_match_table = ahci_acpi_match, +#ifdef CONFIG_PM_SLEEP .pm = &ahci_pm_ops, +#endif }, }; module_platform_driver(ahci_driver); diff --git a/drivers/ata/libahci_platform.c b/drivers/ata/libahci_platform.c index 30cc8f1a31e1..feee2e11fb33 100644 --- a/drivers/ata/libahci_platform.c +++ b/drivers/ata/libahci_platform.c @@ -257,7 +257,7 @@ static void ahci_platform_put_resources(struct device *dev, void *res) int c; if (hpriv->got_runtime_pm) { - pm_runtime_put_sync(dev); + pm_runtime_allow(dev); pm_runtime_disable(dev); } @@ -475,8 +475,10 @@ struct ahci_host_priv *ahci_platform_get_resources(struct platform_device *pdev) if (rc == -EPROBE_DEFER) goto err_out; } + + pm_runtime_set_active(dev); pm_runtime_enable(dev); - pm_runtime_get_sync(dev); + pm_runtime_forbid(dev); hpriv->got_runtime_pm = true; devres_remove_group(dev, NULL); @@ -705,6 +707,21 @@ int ahci_platform_resume_host(struct device *dev) } EXPORT_SYMBOL_GPL(ahci_platform_resume_host); +static int _ahci_platform_suspend(struct device *dev) +{ + struct ata_host *host = dev_get_drvdata(dev); + struct ahci_host_priv *hpriv = host->private_data; + int rc; + + rc = ahci_platform_suspend_host(dev); + if (rc) + return rc; + + ahci_platform_disable_resources(hpriv); + + return 0; +} + /** * ahci_platform_suspend - Suspend an ahci-platform device * @dev: the platform device to suspend @@ -716,20 +733,45 @@ EXPORT_SYMBOL_GPL(ahci_platform_resume_host); * 0 on success otherwise a negative error code */ int ahci_platform_suspend(struct device *dev) +{ + return _ahci_platform_suspend(dev); +} +EXPORT_SYMBOL_GPL(ahci_platform_suspend); + +/** + * ahci_platform_runtime_suspend - Runtime suspend an ahci-platform device + * @dev: the platform device to suspend + * + * This function suspends the host associated with the device, followed by + * disabling all the resources of the device. + * + * RETURNS: + * 0 on success otherwise a negative error code + */ +int ahci_platform_runtime_suspend(struct device *dev) +{ + return _ahci_platform_suspend(dev); +} +EXPORT_SYMBOL_GPL(ahci_platform_runtime_suspend); + +static int _ahci_platform_resume(struct device *dev) { struct ata_host *host = dev_get_drvdata(dev); struct ahci_host_priv *hpriv = host->private_data; int rc; - rc = ahci_platform_suspend_host(dev); + rc = ahci_platform_enable_resources(hpriv); if (rc) return rc; - ahci_platform_disable_resources(hpriv); + rc = ahci_platform_resume_host(dev); + if (rc) { + ahci_platform_disable_resources(hpriv); + return rc; + } return 0; } -EXPORT_SYMBOL_GPL(ahci_platform_suspend); /** * ahci_platform_resume - Resume an ahci-platform device @@ -743,31 +785,37 @@ EXPORT_SYMBOL_GPL(ahci_platform_suspend); */ int ahci_platform_resume(struct device *dev) { - struct ata_host *host = dev_get_drvdata(dev); - struct ahci_host_priv *hpriv = host->private_data; int rc; - rc = ahci_platform_enable_resources(hpriv); + rc = _ahci_platform_resume(dev); if (rc) return rc; - rc = ahci_platform_resume_host(dev); - if (rc) - goto disable_resources; - /* We resumed so update PM runtime state */ pm_runtime_disable(dev); pm_runtime_set_active(dev); pm_runtime_enable(dev); return 0; - -disable_resources: - ahci_platform_disable_resources(hpriv); - - return rc; } EXPORT_SYMBOL_GPL(ahci_platform_resume); + +/** + * ahci_platform_runtime_resume - Runtime resume an ahci-platform device + * @dev: the platform device to resume + * + * This function enables all the resources of the device followed by + * resuming the host associated with the device. + * + * RETURNS: + * 0 on success otherwise a negative error code + */ +int ahci_platform_runtime_resume(struct device *dev) +{ + return _ahci_platform_resume(dev); +} +EXPORT_SYMBOL_GPL(ahci_platform_runtime_resume); + #endif MODULE_DESCRIPTION("AHCI SATA platform library"); diff --git a/include/linux/ahci_platform.h b/include/linux/ahci_platform.h index 1b0a17b22cd3..6396e6982103 100644 --- a/include/linux/ahci_platform.h +++ b/include/linux/ahci_platform.h @@ -42,5 +42,7 @@ int ahci_platform_suspend_host(struct device *dev); int ahci_platform_resume_host(struct device *dev); int ahci_platform_suspend(struct device *dev); int ahci_platform_resume(struct device *dev); +int ahci_platform_runtime_suspend(struct device *dev); +int ahci_platform_runtime_resume(struct device *dev); #endif /* _AHCI_PLATFORM_H */ -- cgit v1.2.3 From 23ebda2fc715534d383d59ae6740d4e3ebd43798 Mon Sep 17 00:00:00 2001 From: Sebastian Andrzej Siewior Date: Wed, 11 Jul 2018 17:21:05 +0200 Subject: libata: remove ata_sff_data_xfer_noirq() ata_sff_data_xfer_noirq() is invoked via the ->sff_data_xfer hook. The latter is invoked by ata_pio_sector(), atapi_send_cdb() and __atapi_pio_bytes() which in turn is invoked by ata_sff_hsm_move(). The latter function requires that the "ap->lock" lock is held which needs to be taken with disabled interrupts. There is no need have to have ata_sff_data_xfer_noirq() which invokes ata_sff_data_xfer32() with disabled interrupts because at this point the interrupts are already disabled. Remove the function and its references to it and replace all callers with ata_sff_data_xfer32(). Signed-off-by: Sebastian Andrzej Siewior Signed-off-by: Tejun Heo --- Documentation/driver-api/libata.rst | 3 +-- drivers/ata/libata-sff.c | 30 ------------------------------ drivers/ata/pata_cmd640.c | 2 +- drivers/ata/pata_icside.c | 2 +- drivers/ata/pata_imx.c | 2 +- drivers/ata/pata_legacy.c | 6 +++--- drivers/ata/pata_palmld.c | 2 +- drivers/ata/pata_pcmcia.c | 2 +- drivers/ata/pata_platform.c | 2 +- drivers/ata/pata_via.c | 2 +- include/linux/libata.h | 2 -- 11 files changed, 11 insertions(+), 44 deletions(-) (limited to 'drivers/ata') diff --git a/Documentation/driver-api/libata.rst b/Documentation/driver-api/libata.rst index 4adc056f7635..70e180e6b93d 100644 --- a/Documentation/driver-api/libata.rst +++ b/Documentation/driver-api/libata.rst @@ -118,8 +118,7 @@ PIO data read/write All bmdma-style drivers must implement this hook. This is the low-level operation that actually copies the data bytes during a PIO data transfer. Typically the driver will choose one of -:c:func:`ata_sff_data_xfer_noirq`, :c:func:`ata_sff_data_xfer`, or -:c:func:`ata_sff_data_xfer32`. +:c:func:`ata_sff_data_xfer`, or :c:func:`ata_sff_data_xfer32`. ATA command execute ~~~~~~~~~~~~~~~~~~~ diff --git a/drivers/ata/libata-sff.c b/drivers/ata/libata-sff.c index cc2f2e35f4c2..c5ea0fc635e5 100644 --- a/drivers/ata/libata-sff.c +++ b/drivers/ata/libata-sff.c @@ -657,36 +657,6 @@ unsigned int ata_sff_data_xfer32(struct ata_queued_cmd *qc, unsigned char *buf, } EXPORT_SYMBOL_GPL(ata_sff_data_xfer32); -/** - * ata_sff_data_xfer_noirq - Transfer data by PIO - * @qc: queued command - * @buf: data buffer - * @buflen: buffer length - * @rw: read/write - * - * Transfer data from/to the device data register by PIO. Do the - * transfer with interrupts disabled. - * - * LOCKING: - * Inherited from caller. - * - * RETURNS: - * Bytes consumed. - */ -unsigned int ata_sff_data_xfer_noirq(struct ata_queued_cmd *qc, unsigned char *buf, - unsigned int buflen, int rw) -{ - unsigned long flags; - unsigned int consumed; - - local_irq_save(flags); - consumed = ata_sff_data_xfer32(qc, buf, buflen, rw); - local_irq_restore(flags); - - return consumed; -} -EXPORT_SYMBOL_GPL(ata_sff_data_xfer_noirq); - /** * ata_pio_sector - Transfer a sector of data. * @qc: Command on going diff --git a/drivers/ata/pata_cmd640.c b/drivers/ata/pata_cmd640.c index c47caa807fa9..e3532eda7b05 100644 --- a/drivers/ata/pata_cmd640.c +++ b/drivers/ata/pata_cmd640.c @@ -178,7 +178,7 @@ static struct scsi_host_template cmd640_sht = { static struct ata_port_operations cmd640_port_ops = { .inherits = &ata_sff_port_ops, /* In theory xfer_noirq is not needed once we kill the prefetcher */ - .sff_data_xfer = ata_sff_data_xfer_noirq, + .sff_data_xfer = ata_sff_data_xfer32, .sff_irq_check = cmd640_sff_irq_check, .qc_issue = cmd640_qc_issue, .cable_detect = ata_cable_40wire, diff --git a/drivers/ata/pata_icside.c b/drivers/ata/pata_icside.c index 188f2f2eb21f..c272f2cbb47c 100644 --- a/drivers/ata/pata_icside.c +++ b/drivers/ata/pata_icside.c @@ -324,7 +324,7 @@ static struct ata_port_operations pata_icside_port_ops = { .inherits = &ata_bmdma_port_ops, /* no need to build any PRD tables for DMA */ .qc_prep = ata_noop_qc_prep, - .sff_data_xfer = ata_sff_data_xfer_noirq, + .sff_data_xfer = ata_sff_data_xfer32, .bmdma_setup = pata_icside_bmdma_setup, .bmdma_start = pata_icside_bmdma_start, .bmdma_stop = pata_icside_bmdma_stop, diff --git a/drivers/ata/pata_imx.c b/drivers/ata/pata_imx.c index d4caa23f5a88..108101325efd 100644 --- a/drivers/ata/pata_imx.c +++ b/drivers/ata/pata_imx.c @@ -102,7 +102,7 @@ static struct scsi_host_template pata_imx_sht = { static struct ata_port_operations pata_imx_port_ops = { .inherits = &ata_sff_port_ops, - .sff_data_xfer = ata_sff_data_xfer_noirq, + .sff_data_xfer = ata_sff_data_xfer32, .cable_detect = ata_cable_unknown, .set_piomode = pata_imx_set_piomode, }; diff --git a/drivers/ata/pata_legacy.c b/drivers/ata/pata_legacy.c index 53828b6c3044..8ea4b8431fc8 100644 --- a/drivers/ata/pata_legacy.c +++ b/drivers/ata/pata_legacy.c @@ -246,12 +246,12 @@ static const struct ata_port_operations legacy_base_port_ops = { static struct ata_port_operations simple_port_ops = { .inherits = &legacy_base_port_ops, - .sff_data_xfer = ata_sff_data_xfer_noirq, + .sff_data_xfer = ata_sff_data_xfer32, }; static struct ata_port_operations legacy_port_ops = { .inherits = &legacy_base_port_ops, - .sff_data_xfer = ata_sff_data_xfer_noirq, + .sff_data_xfer = ata_sff_data_xfer32, .set_mode = legacy_set_mode, }; @@ -341,7 +341,7 @@ static unsigned int pdc_data_xfer_vlb(struct ata_queued_cmd *qc, } local_irq_restore(flags); } else - buflen = ata_sff_data_xfer_noirq(qc, buf, buflen, rw); + buflen = ata_sff_data_xfer32(qc, buf, buflen, rw); return buflen; } diff --git a/drivers/ata/pata_palmld.c b/drivers/ata/pata_palmld.c index 8c0d7d736b7a..d071ab6864a8 100644 --- a/drivers/ata/pata_palmld.c +++ b/drivers/ata/pata_palmld.c @@ -44,7 +44,7 @@ static struct scsi_host_template palmld_sht = { static struct ata_port_operations palmld_port_ops = { .inherits = &ata_sff_port_ops, - .sff_data_xfer = ata_sff_data_xfer_noirq, + .sff_data_xfer = ata_sff_data_xfer32, .cable_detect = ata_cable_40wire, }; diff --git a/drivers/ata/pata_pcmcia.c b/drivers/ata/pata_pcmcia.c index a541eacc5e95..9b0e6c72e3f9 100644 --- a/drivers/ata/pata_pcmcia.c +++ b/drivers/ata/pata_pcmcia.c @@ -151,7 +151,7 @@ static struct scsi_host_template pcmcia_sht = { static struct ata_port_operations pcmcia_port_ops = { .inherits = &ata_sff_port_ops, - .sff_data_xfer = ata_sff_data_xfer_noirq, + .sff_data_xfer = ata_sff_data_xfer32, .cable_detect = ata_cable_40wire, .set_mode = pcmcia_set_mode, }; diff --git a/drivers/ata/pata_platform.c b/drivers/ata/pata_platform.c index c503ded87bb8..d6f8f5406442 100644 --- a/drivers/ata/pata_platform.c +++ b/drivers/ata/pata_platform.c @@ -49,7 +49,7 @@ static struct scsi_host_template pata_platform_sht = { static struct ata_port_operations pata_platform_port_ops = { .inherits = &ata_sff_port_ops, - .sff_data_xfer = ata_sff_data_xfer_noirq, + .sff_data_xfer = ata_sff_data_xfer32, .cable_detect = ata_cable_unknown, .set_mode = pata_platform_set_mode, }; diff --git a/drivers/ata/pata_via.c b/drivers/ata/pata_via.c index 1ca6bcab369f..fd19f1ce83aa 100644 --- a/drivers/ata/pata_via.c +++ b/drivers/ata/pata_via.c @@ -471,7 +471,7 @@ static struct ata_port_operations via_port_ops = { static struct ata_port_operations via_port_ops_noirq = { .inherits = &via_port_ops, - .sff_data_xfer = ata_sff_data_xfer_noirq, + .sff_data_xfer = ata_sff_data_xfer32, }; /** diff --git a/include/linux/libata.h b/include/linux/libata.h index 8b8946dd63b9..aa8583655a18 100644 --- a/include/linux/libata.h +++ b/include/linux/libata.h @@ -1832,8 +1832,6 @@ extern unsigned int ata_sff_data_xfer(struct ata_queued_cmd *qc, unsigned char *buf, unsigned int buflen, int rw); extern unsigned int ata_sff_data_xfer32(struct ata_queued_cmd *qc, unsigned char *buf, unsigned int buflen, int rw); -extern unsigned int ata_sff_data_xfer_noirq(struct ata_queued_cmd *qc, - unsigned char *buf, unsigned int buflen, int rw); extern void ata_sff_irq_on(struct ata_port *ap); extern void ata_sff_irq_clear(struct ata_port *ap); extern int ata_sff_hsm_move(struct ata_port *ap, struct ata_queued_cmd *qc, -- cgit v1.2.3 From 7cf5fc65f9efe0838fcea4e04f48bafa6ee6eae6 Mon Sep 17 00:00:00 2001 From: Corentin Labbe Date: Thu, 12 Jul 2018 11:41:29 +0000 Subject: ata: ahci_platform: correct parameter documentation for ahci_platform_shutdown The documentation about parameter for ahci_platform_shutdown has a typo. This fix the following build warning: drivers/ata/libahci_platform.c:693: warning: Function parameter or member 'pdev' not described in 'ahci_platform_shutdown' drivers/ata/libahci_platform.c:693: warning: Excess function parameter 'dev' description in 'ahci_platform_shutdow Signed-off-by: Corentin Labbe Reviewed-by: Hans de Goede Signed-off-by: Tejun Heo --- drivers/ata/libahci_platform.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/ata') diff --git a/drivers/ata/libahci_platform.c b/drivers/ata/libahci_platform.c index feee2e11fb33..70052c046559 100644 --- a/drivers/ata/libahci_platform.c +++ b/drivers/ata/libahci_platform.c @@ -607,7 +607,7 @@ static void ahci_host_stop(struct ata_host *host) /** * ahci_platform_shutdown - Disable interrupts and stop DMA for host ports - * @dev: platform device pointer for the host + * @pdev: platform device pointer for the host * * This function is called during system shutdown and performs the minimal * deconfiguration required to ensure that an ahci_platform host cannot -- cgit v1.2.3 From a4b9f5ed02e235132ca781dce77deb8cab177f36 Mon Sep 17 00:00:00 2001 From: Corentin Labbe Date: Thu, 12 Jul 2018 11:41:30 +0000 Subject: ata: ahci_platform: convert kzallloc to kcalloc It's better to kcalloc instead of kzalloc(n * sizeof()) Signed-off-by: Corentin Labbe Reviewed-by: Hans de Goede Signed-off-by: Tejun Heo --- drivers/ata/libahci_platform.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'drivers/ata') diff --git a/drivers/ata/libahci_platform.c b/drivers/ata/libahci_platform.c index 70052c046559..be9f54423a9b 100644 --- a/drivers/ata/libahci_platform.c +++ b/drivers/ata/libahci_platform.c @@ -351,7 +351,7 @@ struct ahci_host_priv *ahci_platform_get_resources(struct platform_device *pdev) struct ahci_host_priv *hpriv; struct clk *clk; struct device_node *child; - int i, sz, enabled_ports = 0, rc = -ENOMEM, child_nodes; + int i, enabled_ports = 0, rc = -ENOMEM, child_nodes; u32 mask_port_map = 0; if (!devres_open_group(dev, NULL, GFP_KERNEL)) @@ -403,14 +403,12 @@ struct ahci_host_priv *ahci_platform_get_resources(struct platform_device *pdev) if (!child_nodes) hpriv->nports = 1; - sz = hpriv->nports * sizeof(*hpriv->phys); - hpriv->phys = devm_kzalloc(dev, sz, GFP_KERNEL); + hpriv->phys = devm_kcalloc(dev, hpriv->nports, sizeof(*hpriv->phys), GFP_KERNEL); if (!hpriv->phys) { rc = -ENOMEM; goto err_out; } - sz = hpriv->nports * sizeof(*hpriv->target_pwrs); - hpriv->target_pwrs = kzalloc(sz, GFP_KERNEL); + hpriv->target_pwrs = kcalloc(hpriv->nports, sizeof(*hpriv->target_pwrs), GFP_KERNEL); if (!hpriv->target_pwrs) { rc = -ENOMEM; goto err_out; -- cgit v1.2.3 From bd0038b1b4f499d814d8f33a55b1df5ea6cf3b85 Mon Sep 17 00:00:00 2001 From: Corentin Labbe Date: Thu, 12 Jul 2018 11:41:31 +0000 Subject: ata: ahci_platform: convert kcalloc to devm_kcalloc Like phys, target_pwrs could be allocated with devm_ function Signed-off-by: Corentin Labbe Reviewed-by: Hans de Goede Signed-off-by: Tejun Heo --- drivers/ata/libahci_platform.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'drivers/ata') diff --git a/drivers/ata/libahci_platform.c b/drivers/ata/libahci_platform.c index be9f54423a9b..fe8939e161ea 100644 --- a/drivers/ata/libahci_platform.c +++ b/drivers/ata/libahci_platform.c @@ -271,8 +271,6 @@ static void ahci_platform_put_resources(struct device *dev, void *res) for (c = 0; c < hpriv->nports; c++) if (hpriv->target_pwrs && hpriv->target_pwrs[c]) regulator_put(hpriv->target_pwrs[c]); - - kfree(hpriv->target_pwrs); } static int ahci_platform_get_phy(struct ahci_host_priv *hpriv, u32 port, @@ -408,7 +406,7 @@ struct ahci_host_priv *ahci_platform_get_resources(struct platform_device *pdev) rc = -ENOMEM; goto err_out; } - hpriv->target_pwrs = kcalloc(hpriv->nports, sizeof(*hpriv->target_pwrs), GFP_KERNEL); + hpriv->target_pwrs = devm_kcalloc(dev, hpriv->nports, sizeof(*hpriv->target_pwrs), GFP_KERNEL); if (!hpriv->target_pwrs) { rc = -ENOMEM; goto err_out; -- cgit v1.2.3 From 32a5342ac19ad07000cfe06e97acf9544cc7cf28 Mon Sep 17 00:00:00 2001 From: Paul Menzel Date: Sun, 8 Jul 2018 09:11:34 +0200 Subject: ata: Guard ata_scsi_dump_cdb() by ATA_VERBOSE_DEBUG Defining `ATA_DEBUG` nothing can be really seen, as the log is spammed with CDB messages. Therefore, guard the print by `ATA_VERBOSE_DEBUG`. Signed-off-by: Paul Menzel Signed-off-by: Tejun Heo --- drivers/ata/libata-scsi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers/ata') diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index 6a91d04351d9..980190c9eb48 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -4288,10 +4288,10 @@ static inline ata_xlat_func_t ata_get_xlat_func(struct ata_device *dev, u8 cmd) static inline void ata_scsi_dump_cdb(struct ata_port *ap, struct scsi_cmnd *cmd) { -#ifdef ATA_DEBUG +#ifdef ATA_VERBOSE_DEBUG struct scsi_device *scsidev = cmd->device; - DPRINTK("CDB (%u:%d,%d,%lld) %9ph\n", + VPRINTK("CDB (%u:%d,%d,%lld) %9ph\n", ap->print_id, scsidev->channel, scsidev->id, scsidev->lun, cmd->cmnd); -- cgit v1.2.3 From bb376673ee32c8aaac27c7599eb556db32869792 Mon Sep 17 00:00:00 2001 From: Paul Menzel Date: Sun, 8 Jul 2018 09:18:21 +0200 Subject: ata: Only output sg element mapped number in verbose debug Defining `ATA_DEBUG` there are a lof of messages like below in the log. [ 16.345472] ata_sg_setup: 1 sg elements mapped As that is too verbose, only output these messages in verbose debug. Signed-off-by: Paul Menzel Signed-off-by: Tejun Heo --- drivers/ata/libata-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/ata') diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index 27d15ed7fa3d..1e28d054851f 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -5063,7 +5063,7 @@ static int ata_sg_setup(struct ata_queued_cmd *qc) if (n_elem < 1) return -1; - DPRINTK("%d sg elements mapped\n", n_elem); + VPRINTK("%d sg elements mapped\n", n_elem); qc->orig_n_elem = qc->n_elem; qc->n_elem = n_elem; qc->flags |= ATA_QCFLAG_DMAMAP; -- cgit v1.2.3 From c01e229f24eb133ca85453597447477974b07f20 Mon Sep 17 00:00:00 2001 From: Geert Uytterhoeven Date: Fri, 20 Jul 2018 14:27:38 +0200 Subject: ata: sata_rcar: Provide a short-hand for &pdev->dev No functional changes. Signed-off-by: Geert Uytterhoeven Reviewed-by: Sergei Shtylyov Signed-off-by: Tejun Heo --- drivers/ata/sata_rcar.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'drivers/ata') diff --git a/drivers/ata/sata_rcar.c b/drivers/ata/sata_rcar.c index 6456e07db72a..f972c2c5ebd3 100644 --- a/drivers/ata/sata_rcar.c +++ b/drivers/ata/sata_rcar.c @@ -881,6 +881,7 @@ MODULE_DEVICE_TABLE(of, sata_rcar_match); static int sata_rcar_probe(struct platform_device *pdev) { + struct device *dev = &pdev->dev; struct ata_host *host; struct sata_rcar_priv *priv; struct resource *mem; @@ -891,15 +892,14 @@ static int sata_rcar_probe(struct platform_device *pdev) if (irq <= 0) return -EINVAL; - priv = devm_kzalloc(&pdev->dev, sizeof(struct sata_rcar_priv), - GFP_KERNEL); + priv = devm_kzalloc(dev, sizeof(struct sata_rcar_priv), GFP_KERNEL); if (!priv) return -ENOMEM; - priv->type = (enum sata_rcar_type)of_device_get_match_data(&pdev->dev); - priv->clk = devm_clk_get(&pdev->dev, NULL); + priv->type = (enum sata_rcar_type)of_device_get_match_data(dev); + priv->clk = devm_clk_get(dev, NULL); if (IS_ERR(priv->clk)) { - dev_err(&pdev->dev, "failed to get access to sata clock\n"); + dev_err(dev, "failed to get access to sata clock\n"); return PTR_ERR(priv->clk); } @@ -907,9 +907,9 @@ static int sata_rcar_probe(struct platform_device *pdev) if (ret) return ret; - host = ata_host_alloc(&pdev->dev, 1); + host = ata_host_alloc(dev, 1); if (!host) { - dev_err(&pdev->dev, "ata_host_alloc failed\n"); + dev_err(dev, "ata_host_alloc failed\n"); ret = -ENOMEM; goto cleanup; } @@ -917,7 +917,7 @@ static int sata_rcar_probe(struct platform_device *pdev) host->private_data = priv; mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); - priv->base = devm_ioremap_resource(&pdev->dev, mem); + priv->base = devm_ioremap_resource(dev, mem); if (IS_ERR(priv->base)) { ret = PTR_ERR(priv->base); goto cleanup; -- cgit v1.2.3 From 1ecd34ddf63ef1d4015da5e5de6881e6845a6b0a Mon Sep 17 00:00:00 2001 From: Geert Uytterhoeven Date: Fri, 20 Jul 2018 14:27:39 +0200 Subject: ata: sata_rcar: Add rudimentary Runtime PM support Replace the explicit clock handling to enable/disable the SATA module by calls to Runtime PM. This makes the driver independent of actual SoC clock/power hierarchies, and is needed to support virtualization, where the guest is not in full control of power management. Signed-off-by: Geert Uytterhoeven Reviewed-by: Sergei Shtylyov Signed-off-by: Tejun Heo --- drivers/ata/sata_rcar.c | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) (limited to 'drivers/ata') diff --git a/drivers/ata/sata_rcar.c b/drivers/ata/sata_rcar.c index f972c2c5ebd3..3b8ed10bfb8f 100644 --- a/drivers/ata/sata_rcar.c +++ b/drivers/ata/sata_rcar.c @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #define DRV_NAME "sata_rcar" @@ -152,7 +152,6 @@ enum sata_rcar_type { struct sata_rcar_priv { void __iomem *base; - struct clk *clk; enum sata_rcar_type type; }; @@ -897,21 +896,17 @@ static int sata_rcar_probe(struct platform_device *pdev) return -ENOMEM; priv->type = (enum sata_rcar_type)of_device_get_match_data(dev); - priv->clk = devm_clk_get(dev, NULL); - if (IS_ERR(priv->clk)) { - dev_err(dev, "failed to get access to sata clock\n"); - return PTR_ERR(priv->clk); - } - ret = clk_prepare_enable(priv->clk); - if (ret) - return ret; + pm_runtime_enable(dev); + ret = pm_runtime_get_sync(dev); + if (ret < 0) + goto err_pm_disable; host = ata_host_alloc(dev, 1); if (!host) { dev_err(dev, "ata_host_alloc failed\n"); ret = -ENOMEM; - goto cleanup; + goto err_pm_put; } host->private_data = priv; @@ -920,7 +915,7 @@ static int sata_rcar_probe(struct platform_device *pdev) priv->base = devm_ioremap_resource(dev, mem); if (IS_ERR(priv->base)) { ret = PTR_ERR(priv->base); - goto cleanup; + goto err_pm_put; } /* setup port */ @@ -934,9 +929,10 @@ static int sata_rcar_probe(struct platform_device *pdev) if (!ret) return 0; -cleanup: - clk_disable_unprepare(priv->clk); - +err_pm_put: + pm_runtime_put(dev); +err_pm_disable: + pm_runtime_disable(dev); return ret; } @@ -954,7 +950,8 @@ static int sata_rcar_remove(struct platform_device *pdev) iowrite32(0, base + SATAINTSTAT_REG); iowrite32(0x7ff, base + SATAINTMASK_REG); - clk_disable_unprepare(priv->clk); + pm_runtime_put(&pdev->dev); + pm_runtime_disable(&pdev->dev); return 0; } @@ -974,7 +971,7 @@ static int sata_rcar_suspend(struct device *dev) /* mask */ iowrite32(0x7ff, base + SATAINTMASK_REG); - clk_disable_unprepare(priv->clk); + pm_runtime_put(dev); } return ret; @@ -987,8 +984,8 @@ static int sata_rcar_resume(struct device *dev) void __iomem *base = priv->base; int ret; - ret = clk_prepare_enable(priv->clk); - if (ret) + ret = pm_runtime_get_sync(dev); + if (ret < 0) return ret; if (priv->type == RCAR_GEN3_SATA) { @@ -1012,11 +1009,10 @@ static int sata_rcar_resume(struct device *dev) static int sata_rcar_restore(struct device *dev) { struct ata_host *host = dev_get_drvdata(dev); - struct sata_rcar_priv *priv = host->private_data; int ret; - ret = clk_prepare_enable(priv->clk); - if (ret) + ret = pm_runtime_get_sync(dev); + if (ret < 0) return ret; sata_rcar_setup_port(host); -- cgit v1.2.3 From 04ba9488199e3ee9971769cee585ec6847013ed2 Mon Sep 17 00:00:00 2001 From: Corentin Labbe Date: Tue, 17 Jul 2018 10:49:35 +0000 Subject: Revert "ata: ahci_platform: convert kcalloc to devm_kcalloc" Since ahci_platform_put_resources() use target_pwrs after "devm_" freed it, we cannot use devm_kcalloc for allocating target_pwrs. This reverts commit bd0038b1b4f499d814d8f33a55b1df5ea6cf3b85. Reported-and-reviwed-by: Mikko Perttunen Tested-by: Marcel Ziswiler Tested-by: Jon Hunter Signed-off-by: Corentin Labbe Signed-off-by: Tejun Heo --- drivers/ata/libahci_platform.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'drivers/ata') diff --git a/drivers/ata/libahci_platform.c b/drivers/ata/libahci_platform.c index fe8939e161ea..2ceebaf2ed56 100644 --- a/drivers/ata/libahci_platform.c +++ b/drivers/ata/libahci_platform.c @@ -271,6 +271,8 @@ static void ahci_platform_put_resources(struct device *dev, void *res) for (c = 0; c < hpriv->nports; c++) if (hpriv->target_pwrs && hpriv->target_pwrs[c]) regulator_put(hpriv->target_pwrs[c]); + + kfree(hpriv->target_pwrs); } static int ahci_platform_get_phy(struct ahci_host_priv *hpriv, u32 port, @@ -406,7 +408,11 @@ struct ahci_host_priv *ahci_platform_get_resources(struct platform_device *pdev) rc = -ENOMEM; goto err_out; } - hpriv->target_pwrs = devm_kcalloc(dev, hpriv->nports, sizeof(*hpriv->target_pwrs), GFP_KERNEL); + /* + * We cannot use devm_ here, since ahci_platform_put_resources() uses + * target_pwrs after devm_ have freed memory + */ + hpriv->target_pwrs = kcalloc(hpriv->nports, sizeof(*hpriv->target_pwrs), GFP_KERNEL); if (!hpriv->target_pwrs) { rc = -ENOMEM; goto err_out; -- cgit v1.2.3 From a5ec5a7bfd1f28d1905499641c9f589be36808c1 Mon Sep 17 00:00:00 2001 From: Srinivas Pandruvada Date: Fri, 27 Jul 2018 13:47:02 -0700 Subject: ata: ahci: Support state with min power but Partial low power state MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently when min_power policy is selected, the partial low power state is not entered and link will try aggressively enter to only slumber state. Add a new policy which still enable DEVSLP but also try to enter partial low power state. This policy is presented as "min_power_with_partial". For information the difference between partial and slumber Partial – PHY logic is powered up, and in a reduced power state. The link PM exit latency to active state maximum is 10 ns. Slumber – PHY logic is powered up, and in a reduced power state. The link PM exit latency to active state maximum is 10 ms. Devslp – PHY logic is powered down. The link PM exit latency from this state to active state maximum is 20 ms, unless otherwise specified by DETO. Suggested-and-reviewed-by: Hans de Goede Signed-off-by: Srinivas Pandruvada Signed-off-by: Tejun Heo --- drivers/ata/libahci.c | 5 ++++- drivers/ata/libata-core.c | 1 + drivers/ata/libata-scsi.c | 1 + include/linux/libata.h | 3 ++- 4 files changed, 8 insertions(+), 2 deletions(-) (limited to 'drivers/ata') diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c index 5038cee7d982..f79dce613e54 100644 --- a/drivers/ata/libahci.c +++ b/drivers/ata/libahci.c @@ -800,6 +800,8 @@ static int ahci_set_lpm(struct ata_link *link, enum ata_lpm_policy policy, cmd |= PORT_CMD_ALPE; if (policy == ATA_LPM_MIN_POWER) cmd |= PORT_CMD_ASP; + else if (policy == ATA_LPM_MIN_POWER_WITH_PARTIAL) + cmd &= ~PORT_CMD_ASP; /* write out new cmd value */ writel(cmd, port_mmio + PORT_CMD); @@ -810,7 +812,8 @@ static int ahci_set_lpm(struct ata_link *link, enum ata_lpm_policy policy, if ((hpriv->cap2 & HOST_CAP2_SDS) && (hpriv->cap2 & HOST_CAP2_SADM) && (link->device->flags & ATA_DFLAG_DEVSLP)) { - if (policy == ATA_LPM_MIN_POWER) + if (policy == ATA_LPM_MIN_POWER || + policy == ATA_LPM_MIN_POWER_WITH_PARTIAL) ahci_set_aggressive_devslp(ap, true); else ahci_set_aggressive_devslp(ap, false); diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index 1e28d054851f..f1b1be17383b 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -3967,6 +3967,7 @@ int sata_link_scr_lpm(struct ata_link *link, enum ata_lpm_policy policy, scontrol |= (0x6 << 8); break; case ATA_LPM_MED_POWER_WITH_DIPM: + case ATA_LPM_MIN_POWER_WITH_PARTIAL: case ATA_LPM_MIN_POWER: if (ata_link_nr_enabled(link) > 0) /* no restrictions on LPM transitions */ diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index 980190c9eb48..63c25f1499c3 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -110,6 +110,7 @@ static const char *ata_lpm_policy_names[] = { [ATA_LPM_MAX_POWER] = "max_performance", [ATA_LPM_MED_POWER] = "medium_power", [ATA_LPM_MED_POWER_WITH_DIPM] = "med_power_with_dipm", + [ATA_LPM_MIN_POWER_WITH_PARTIAL] = "min_power_with_partial", [ATA_LPM_MIN_POWER] = "min_power", }; diff --git a/include/linux/libata.h b/include/linux/libata.h index aa8583655a18..80c2bd202367 100644 --- a/include/linux/libata.h +++ b/include/linux/libata.h @@ -522,7 +522,8 @@ enum ata_lpm_policy { ATA_LPM_MAX_POWER, ATA_LPM_MED_POWER, ATA_LPM_MED_POWER_WITH_DIPM, /* Med power + DIPM as win IRST does */ - ATA_LPM_MIN_POWER, + ATA_LPM_MIN_POWER_WITH_PARTIAL, /* Min Power + partial and slumber */ + ATA_LPM_MIN_POWER, /* Min power + no partial (slumber only) */ }; enum ata_lpm_hints { -- cgit v1.2.3 From b1a9585cc396cac5a9e5a09b2721f3b8568e62d0 Mon Sep 17 00:00:00 2001 From: Srinivas Pandruvada Date: Fri, 27 Jul 2018 13:47:03 -0700 Subject: ata: ahci: Enable DEVSLP by default on x86 with SLP_S0 One of the requirement for modern x86 system to enter lowest power mode (SLP_S0) is SATA IP block to be off. This is true even during when platform is suspended to idle and not only in opportunistic (runtime) suspend. Several of these system don't have traditional ACPI S3, so it is important that they enter SLP_S0 state, to avoid draining battery even during suspend. So it is important that out of the box Linux installation reach this state. SATA IP block doesn't get turned off till SATA is in DEVSLP mode. Here user has to either use scsi-host sysfs or tools like powertop to set the sata-host link_power_management_policy to min_power. This change sets by default link power management policy to min_power with partial (preferred) or slumber support on idle for some platforms. To avoid regressions, the following conditions are used: - User didn't override the policy from module parameter - The kernel config is already set to use med_power_with_dipm or deeper - System is a SLP_S0 capable using ACPI low power idle flag This combination will make sure that systems are fairly recent and since getting shipped with SLP_S0 support, the DEVSLP function is already validated. Signed-off-by: Srinivas Pandruvada Reviewed-by: Hans de Goede Signed-off-by: Tejun Heo --- drivers/ata/ahci.c | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) (limited to 'drivers/ata') diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c index 738fb22978dd..b14dccda0154 100644 --- a/drivers/ata/ahci.c +++ b/drivers/ata/ahci.c @@ -609,7 +609,7 @@ static int marvell_enable = 1; module_param(marvell_enable, int, 0644); MODULE_PARM_DESC(marvell_enable, "Marvell SATA via AHCI (1 = enabled)"); -static int mobile_lpm_policy = CONFIG_SATA_MOBILE_LPM_POLICY; +static int mobile_lpm_policy = -1; module_param(mobile_lpm_policy, int, 0644); MODULE_PARM_DESC(mobile_lpm_policy, "Default LPM policy for mobile chipsets"); @@ -1550,6 +1550,37 @@ static int ahci_init_msi(struct pci_dev *pdev, unsigned int n_ports, return pci_alloc_irq_vectors(pdev, 1, 1, PCI_IRQ_MSIX); } +static void ahci_update_initial_lpm_policy(struct ata_port *ap, + struct ahci_host_priv *hpriv) +{ + int policy = CONFIG_SATA_MOBILE_LPM_POLICY; + + + /* Ignore processing for non mobile platforms */ + if (!(hpriv->flags & AHCI_HFLAG_IS_MOBILE)) + return; + + /* user modified policy via module param */ + if (mobile_lpm_policy != -1) { + policy = mobile_lpm_policy; + goto update_policy; + } + +#ifdef CONFIG_ACPI + if (policy > ATA_LPM_MED_POWER && + (acpi_gbl_FADT.flags & ACPI_FADT_LOW_POWER_S0)) { + if (hpriv->cap & HOST_CAP_PART) + policy = ATA_LPM_MIN_POWER_WITH_PARTIAL; + else if (hpriv->cap & HOST_CAP_SSC) + policy = ATA_LPM_MIN_POWER; + } +#endif + +update_policy: + if (policy >= ATA_LPM_UNKNOWN && policy <= ATA_LPM_MIN_POWER) + ap->target_lpm_policy = policy; +} + static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) { unsigned int board_id = ent->driver_data; @@ -1747,10 +1778,7 @@ static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) if (ap->flags & ATA_FLAG_EM) ap->em_message_type = hpriv->em_msg_type; - if ((hpriv->flags & AHCI_HFLAG_IS_MOBILE) && - mobile_lpm_policy >= ATA_LPM_UNKNOWN && - mobile_lpm_policy <= ATA_LPM_MIN_POWER) - ap->target_lpm_policy = mobile_lpm_policy; + ahci_update_initial_lpm_policy(ap, hpriv); /* disabled/not-implemented port */ if (!(hpriv->port_map & (1 << i))) -- cgit v1.2.3 From 2dbb3ec29a6c069035857a2fc4c24e80e5dfe3cc Mon Sep 17 00:00:00 2001 From: Srinivas Pandruvada Date: Mon, 2 Jul 2018 12:01:53 -0700 Subject: ata: libahci: Correct setting of DEVSLP register We have seen that on some platforms, SATA device never show any DEVSLP residency. This prevent power gating of SATA IP, which prevent system to transition to low power mode in systems with SLP_S0 aka modern standby systems. The PHY logic is off only in DEVSLP not in slumber. Reference: https://www.intel.com/content/dam/www/public/us/en/documents/datasheets /332995-skylake-i-o-platform-datasheet-volume-1.pdf Section 28.7.6.1 Here driver is trying to do read-modify-write the devslp register. But not resetting the bits for which this driver will modify values (DITO, MDAT and DETO). So simply reset those bits before updating to new values. Signed-off-by: Srinivas Pandruvada Reviewed-by: Rafael J. Wysocki Reviewed-by: Hans de Goede Signed-off-by: Tejun Heo --- drivers/ata/libahci.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'drivers/ata') diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c index f79dce613e54..fdb7d7bf7626 100644 --- a/drivers/ata/libahci.c +++ b/drivers/ata/libahci.c @@ -2162,6 +2162,8 @@ static void ahci_set_aggressive_devslp(struct ata_port *ap, bool sleep) deto = 20; } + /* Make dito, mdat, deto bits to 0s */ + devslp &= ~GENMASK_ULL(24, 2); devslp |= ((dito << PORT_DEVSLP_DITO_OFFSET) | (mdat << PORT_DEVSLP_MDAT_OFFSET) | (deto << PORT_DEVSLP_DETO_OFFSET) | -- cgit v1.2.3 From 11c291461b6ea8d1195a96d6bba6673a94aacebc Mon Sep 17 00:00:00 2001 From: Srinivas Pandruvada Date: Mon, 2 Jul 2018 12:01:54 -0700 Subject: ata: libahci: Allow reconfigure of DEVSLP register There are two modes in which DEVSLP can be entered. The OS initiated or hardware autonomous. In hardware autonomous mode, BIOS configures the AHCI controller and the device to enable DEVSLP. But they may not be ideal for all cases. So in this case, OS should be able to reconfigure DEVSLP register. Currently if the DEVSLP is already enabled, we can't set again as it will simply return. There are some systems where the firmware is setting high DITO by default, in this case we can't modify here to correct settings. With the default in several seconds, we are not able to transition to DEVSLP. This change will allow reconfiguration of devslp register if DITO is different. Signed-off-by: Srinivas Pandruvada Reviewed-by: Hans de Goede Signed-off-by: Tejun Heo --- drivers/ata/libahci.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'drivers/ata') diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c index fdb7d7bf7626..313fd74ddaef 100644 --- a/drivers/ata/libahci.c +++ b/drivers/ata/libahci.c @@ -2107,7 +2107,7 @@ static void ahci_set_aggressive_devslp(struct ata_port *ap, bool sleep) struct ahci_host_priv *hpriv = ap->host->private_data; void __iomem *port_mmio = ahci_port_base(ap); struct ata_device *dev = ap->link.device; - u32 devslp, dm, dito, mdat, deto; + u32 devslp, dm, dito, mdat, deto, dito_conf; int rc; unsigned int err_mask; @@ -2131,8 +2131,15 @@ static void ahci_set_aggressive_devslp(struct ata_port *ap, bool sleep) return; } - /* device sleep was already enabled */ - if (devslp & PORT_DEVSLP_ADSE) + dm = (devslp & PORT_DEVSLP_DM_MASK) >> PORT_DEVSLP_DM_OFFSET; + dito = devslp_idle_timeout / (dm + 1); + if (dito > 0x3ff) + dito = 0x3ff; + + dito_conf = (devslp >> PORT_DEVSLP_DITO_OFFSET) & 0x3FF; + + /* device sleep was already enabled and same dito */ + if ((devslp & PORT_DEVSLP_ADSE) && (dito_conf == dito)) return; /* set DITO, MDAT, DETO and enable DevSlp, need to stop engine first */ @@ -2140,11 +2147,6 @@ static void ahci_set_aggressive_devslp(struct ata_port *ap, bool sleep) if (rc) return; - dm = (devslp & PORT_DEVSLP_DM_MASK) >> PORT_DEVSLP_DM_OFFSET; - dito = devslp_idle_timeout / (dm + 1); - if (dito > 0x3ff) - dito = 0x3ff; - /* Use the nominal value 10 ms if the read MDAT is zero, * the nominal value of DETO is 20 ms. */ -- cgit v1.2.3 From eac7e072d7e99fad1b6e817c608b03c48205241e Mon Sep 17 00:00:00 2001 From: Tejun Heo Date: Mon, 6 Aug 2018 10:22:35 -0700 Subject: Revert "ata: ahci_platform: allow disabling of hotplug to save power" This reverts commit aece27a2f01be4bb7683790f69cd1bed3a0929a2. Causes boot failure on some devices. http://lore.kernel.org/r/CA+G9fYuKW_jCFZPqG4tz=QY9ROfHO38KiCp9XTA+KaDOFVtcqQ@mail.gmail.com Signed-off-by: Tejun Heo --- drivers/ata/ahci_platform.c | 11 ++---- drivers/ata/libahci_platform.c | 82 +++++++++--------------------------------- include/linux/ahci_platform.h | 2 -- 3 files changed, 19 insertions(+), 76 deletions(-) (limited to 'drivers/ata') diff --git a/drivers/ata/ahci_platform.c b/drivers/ata/ahci_platform.c index 757729376eda..99f9a895a459 100644 --- a/drivers/ata/ahci_platform.c +++ b/drivers/ata/ahci_platform.c @@ -68,13 +68,8 @@ disable_resources: return rc; } -#ifdef CONFIG_PM_SLEEP -static const struct dev_pm_ops ahci_pm_ops = { - SET_SYSTEM_SLEEP_PM_OPS(ahci_platform_suspend, ahci_platform_resume) - SET_RUNTIME_PM_OPS(ahci_platform_runtime_suspend, - ahci_platform_runtime_resume, NULL) -}; -#endif +static SIMPLE_DEV_PM_OPS(ahci_pm_ops, ahci_platform_suspend, + ahci_platform_resume); static const struct of_device_id ahci_of_match[] = { { .compatible = "generic-ahci", }, @@ -103,9 +98,7 @@ static struct platform_driver ahci_driver = { .name = DRV_NAME, .of_match_table = ahci_of_match, .acpi_match_table = ahci_acpi_match, -#ifdef CONFIG_PM_SLEEP .pm = &ahci_pm_ops, -#endif }, }; module_platform_driver(ahci_driver); diff --git a/drivers/ata/libahci_platform.c b/drivers/ata/libahci_platform.c index 2ceebaf2ed56..8fbb532b62dd 100644 --- a/drivers/ata/libahci_platform.c +++ b/drivers/ata/libahci_platform.c @@ -257,7 +257,7 @@ static void ahci_platform_put_resources(struct device *dev, void *res) int c; if (hpriv->got_runtime_pm) { - pm_runtime_allow(dev); + pm_runtime_put_sync(dev); pm_runtime_disable(dev); } @@ -477,10 +477,8 @@ struct ahci_host_priv *ahci_platform_get_resources(struct platform_device *pdev) if (rc == -EPROBE_DEFER) goto err_out; } - - pm_runtime_set_active(dev); pm_runtime_enable(dev); - pm_runtime_forbid(dev); + pm_runtime_get_sync(dev); hpriv->got_runtime_pm = true; devres_remove_group(dev, NULL); @@ -709,21 +707,6 @@ int ahci_platform_resume_host(struct device *dev) } EXPORT_SYMBOL_GPL(ahci_platform_resume_host); -static int _ahci_platform_suspend(struct device *dev) -{ - struct ata_host *host = dev_get_drvdata(dev); - struct ahci_host_priv *hpriv = host->private_data; - int rc; - - rc = ahci_platform_suspend_host(dev); - if (rc) - return rc; - - ahci_platform_disable_resources(hpriv); - - return 0; -} - /** * ahci_platform_suspend - Suspend an ahci-platform device * @dev: the platform device to suspend @@ -735,45 +718,20 @@ static int _ahci_platform_suspend(struct device *dev) * 0 on success otherwise a negative error code */ int ahci_platform_suspend(struct device *dev) -{ - return _ahci_platform_suspend(dev); -} -EXPORT_SYMBOL_GPL(ahci_platform_suspend); - -/** - * ahci_platform_runtime_suspend - Runtime suspend an ahci-platform device - * @dev: the platform device to suspend - * - * This function suspends the host associated with the device, followed by - * disabling all the resources of the device. - * - * RETURNS: - * 0 on success otherwise a negative error code - */ -int ahci_platform_runtime_suspend(struct device *dev) -{ - return _ahci_platform_suspend(dev); -} -EXPORT_SYMBOL_GPL(ahci_platform_runtime_suspend); - -static int _ahci_platform_resume(struct device *dev) { struct ata_host *host = dev_get_drvdata(dev); struct ahci_host_priv *hpriv = host->private_data; int rc; - rc = ahci_platform_enable_resources(hpriv); + rc = ahci_platform_suspend_host(dev); if (rc) return rc; - rc = ahci_platform_resume_host(dev); - if (rc) { - ahci_platform_disable_resources(hpriv); - return rc; - } + ahci_platform_disable_resources(hpriv); return 0; } +EXPORT_SYMBOL_GPL(ahci_platform_suspend); /** * ahci_platform_resume - Resume an ahci-platform device @@ -787,37 +745,31 @@ static int _ahci_platform_resume(struct device *dev) */ int ahci_platform_resume(struct device *dev) { + struct ata_host *host = dev_get_drvdata(dev); + struct ahci_host_priv *hpriv = host->private_data; int rc; - rc = _ahci_platform_resume(dev); + rc = ahci_platform_enable_resources(hpriv); if (rc) return rc; + rc = ahci_platform_resume_host(dev); + if (rc) + goto disable_resources; + /* We resumed so update PM runtime state */ pm_runtime_disable(dev); pm_runtime_set_active(dev); pm_runtime_enable(dev); return 0; -} -EXPORT_SYMBOL_GPL(ahci_platform_resume); -/** - * ahci_platform_runtime_resume - Runtime resume an ahci-platform device - * @dev: the platform device to resume - * - * This function enables all the resources of the device followed by - * resuming the host associated with the device. - * - * RETURNS: - * 0 on success otherwise a negative error code - */ -int ahci_platform_runtime_resume(struct device *dev) -{ - return _ahci_platform_resume(dev); -} -EXPORT_SYMBOL_GPL(ahci_platform_runtime_resume); +disable_resources: + ahci_platform_disable_resources(hpriv); + return rc; +} +EXPORT_SYMBOL_GPL(ahci_platform_resume); #endif MODULE_DESCRIPTION("AHCI SATA platform library"); diff --git a/include/linux/ahci_platform.h b/include/linux/ahci_platform.h index 6396e6982103..1b0a17b22cd3 100644 --- a/include/linux/ahci_platform.h +++ b/include/linux/ahci_platform.h @@ -42,7 +42,5 @@ int ahci_platform_suspend_host(struct device *dev); int ahci_platform_resume_host(struct device *dev); int ahci_platform_suspend(struct device *dev); int ahci_platform_resume(struct device *dev); -int ahci_platform_runtime_suspend(struct device *dev); -int ahci_platform_runtime_resume(struct device *dev); #endif /* _AHCI_PLATFORM_H */ -- cgit v1.2.3 From e207610fffbc339d14c663a6966454b8e9b2deff Mon Sep 17 00:00:00 2001 From: Wolfram Sang Date: Mon, 6 Aug 2018 12:40:05 +0200 Subject: ata: sata_rcar: really mask all interrupts on Gen2 and later Since R-Car Gen2, a new bit has been introduced to the interrupt mask register. Update the code to handle it properly as well. Signed-off-by: Wolfram Sang Reviewed-by: Sergei Shtylyov Signed-off-by: Tejun Heo --- drivers/ata/sata_rcar.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'drivers/ata') diff --git a/drivers/ata/sata_rcar.c b/drivers/ata/sata_rcar.c index 3b8ed10bfb8f..1ad168f76ef3 100644 --- a/drivers/ata/sata_rcar.c +++ b/drivers/ata/sata_rcar.c @@ -109,6 +109,8 @@ #define SATAINTMASK_ERRMSK BIT(2) #define SATAINTMASK_ERRCRTMSK BIT(1) #define SATAINTMASK_ATAMSK BIT(0) +#define SATAINTMASK_ALL_GEN1 0x7ff +#define SATAINTMASK_ALL_GEN2 0xfff #define SATA_RCAR_INT_MASK (SATAINTMASK_SERRMSK | \ SATAINTMASK_ATAMSK) @@ -152,6 +154,7 @@ enum sata_rcar_type { struct sata_rcar_priv { void __iomem *base; + u32 sataint_mask; enum sata_rcar_type type; }; @@ -225,7 +228,7 @@ static void sata_rcar_freeze(struct ata_port *ap) struct sata_rcar_priv *priv = ap->host->private_data; /* mask */ - iowrite32(0x7ff, priv->base + SATAINTMASK_REG); + iowrite32(priv->sataint_mask, priv->base + SATAINTMASK_REG); ata_sff_freeze(ap); } @@ -241,7 +244,7 @@ static void sata_rcar_thaw(struct ata_port *ap) ata_sff_thaw(ap); /* unmask */ - iowrite32(0x7ff & ~SATA_RCAR_INT_MASK, base + SATAINTMASK_REG); + iowrite32(priv->sataint_mask & ~SATA_RCAR_INT_MASK, base + SATAINTMASK_REG); } static void sata_rcar_ioread16_rep(void __iomem *reg, void *buffer, int count) @@ -735,7 +738,7 @@ static irqreturn_t sata_rcar_interrupt(int irq, void *dev_instance) if (!sataintstat) goto done; /* ack */ - iowrite32(~sataintstat & 0x7ff, base + SATAINTSTAT_REG); + iowrite32(~sataintstat & priv->sataint_mask, base + SATAINTSTAT_REG); ap = host->ports[0]; @@ -808,7 +811,7 @@ static void sata_rcar_init_module(struct sata_rcar_priv *priv) /* ack and mask */ iowrite32(0, base + SATAINTSTAT_REG); - iowrite32(0x7ff, base + SATAINTMASK_REG); + iowrite32(priv->sataint_mask, base + SATAINTMASK_REG); /* enable interrupts */ iowrite32(ATAPI_INT_ENABLE_SATAINT, base + ATAPI_INT_ENABLE_REG); @@ -818,9 +821,12 @@ static void sata_rcar_init_controller(struct ata_host *host) { struct sata_rcar_priv *priv = host->private_data; + priv->sataint_mask = SATAINTMASK_ALL_GEN2; + /* reset and setup phy */ switch (priv->type) { case RCAR_GEN1_SATA: + priv->sataint_mask = SATAINTMASK_ALL_GEN1; sata_rcar_gen1_phy_init(priv); break; case RCAR_GEN2_SATA: @@ -948,7 +954,7 @@ static int sata_rcar_remove(struct platform_device *pdev) iowrite32(0, base + ATAPI_INT_ENABLE_REG); /* ack and mask */ iowrite32(0, base + SATAINTSTAT_REG); - iowrite32(0x7ff, base + SATAINTMASK_REG); + iowrite32(priv->sataint_mask, base + SATAINTMASK_REG); pm_runtime_put(&pdev->dev); pm_runtime_disable(&pdev->dev); @@ -969,7 +975,7 @@ static int sata_rcar_suspend(struct device *dev) /* disable interrupts */ iowrite32(0, base + ATAPI_INT_ENABLE_REG); /* mask */ - iowrite32(0x7ff, base + SATAINTMASK_REG); + iowrite32(priv->sataint_mask, base + SATAINTMASK_REG); pm_runtime_put(dev); } @@ -994,7 +1000,7 @@ static int sata_rcar_resume(struct device *dev) } else { /* ack and mask */ iowrite32(0, base + SATAINTSTAT_REG); - iowrite32(0x7ff, base + SATAINTMASK_REG); + iowrite32(priv->sataint_mask, base + SATAINTMASK_REG); /* enable interrupts */ iowrite32(ATAPI_INT_ENABLE_SATAINT, -- cgit v1.2.3 From 96b954895470fa1f64232fd9b1e31f445b8a3c35 Mon Sep 17 00:00:00 2001 From: Masaharu Hayakawa Date: Mon, 6 Aug 2018 12:42:00 +0200 Subject: ata: sata_rcar: exclude setting of PHY registers in Gen3 According to documentation, setting of PHY registers is unnecessary with R-Car Gen3. The registers are not even described. So, don't initialize them. Signed-off-by: Masaharu Hayakawa [wsa: updated commit message] Signed-off-by: Wolfram Sang Reviewed-by: Sergei Shtylyov Signed-off-by: Tejun Heo --- drivers/ata/sata_rcar.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers/ata') diff --git a/drivers/ata/sata_rcar.c b/drivers/ata/sata_rcar.c index 1ad168f76ef3..10ecb232245d 100644 --- a/drivers/ata/sata_rcar.c +++ b/drivers/ata/sata_rcar.c @@ -830,10 +830,11 @@ static void sata_rcar_init_controller(struct ata_host *host) sata_rcar_gen1_phy_init(priv); break; case RCAR_GEN2_SATA: - case RCAR_GEN3_SATA: case RCAR_R8A7790_ES1_SATA: sata_rcar_gen2_phy_init(priv); break; + case RCAR_GEN3_SATA: + break; default: dev_warn(host->dev, "SATA phy is not initialized\n"); break; @@ -995,7 +996,6 @@ static int sata_rcar_resume(struct device *dev) return ret; if (priv->type == RCAR_GEN3_SATA) { - sata_rcar_gen2_phy_init(priv); sata_rcar_init_module(priv); } else { /* ack and mask */ -- cgit v1.2.3 From 16af2d65842d343c2f95733c3993a0b5baab08f9 Mon Sep 17 00:00:00 2001 From: Kunihiko Hayashi Date: Wed, 22 Aug 2018 21:13:01 +0900 Subject: ata: add an extra argument to ahci_platform_get_resources() Add an extra argument to ahci_platform_get_resources(), that is for the bitmap representing the resource to get in this function. Currently there is no resources to be defined, so all the callers set '0' to the argument. Suggested-by: Hans de Goede Cc: Thierry Reding Cc: Matthias Brugger Cc: Patrice Chotard Cc: Maxime Ripard Signed-off-by: Kunihiko Hayashi Reviewed-by: Hans de Goede Signed-off-by: Tejun Heo --- drivers/ata/ahci_brcm.c | 2 +- drivers/ata/ahci_ceva.c | 2 +- drivers/ata/ahci_da850.c | 2 +- drivers/ata/ahci_dm816.c | 2 +- drivers/ata/ahci_imx.c | 2 +- drivers/ata/ahci_mtk.c | 2 +- drivers/ata/ahci_mvebu.c | 2 +- drivers/ata/ahci_platform.c | 2 +- drivers/ata/ahci_qoriq.c | 2 +- drivers/ata/ahci_seattle.c | 2 +- drivers/ata/ahci_st.c | 2 +- drivers/ata/ahci_sunxi.c | 2 +- drivers/ata/ahci_tegra.c | 2 +- drivers/ata/ahci_xgene.c | 2 +- drivers/ata/libahci_platform.c | 4 +++- include/linux/ahci_platform.h | 2 +- 16 files changed, 18 insertions(+), 16 deletions(-) (limited to 'drivers/ata') diff --git a/drivers/ata/ahci_brcm.c b/drivers/ata/ahci_brcm.c index ea430819c80b..f3d557777d82 100644 --- a/drivers/ata/ahci_brcm.c +++ b/drivers/ata/ahci_brcm.c @@ -425,7 +425,7 @@ static int brcm_ahci_probe(struct platform_device *pdev) brcm_sata_phys_enable(priv); - hpriv = ahci_platform_get_resources(pdev); + hpriv = ahci_platform_get_resources(pdev, 0); if (IS_ERR(hpriv)) return PTR_ERR(hpriv); hpriv->plat_data = priv; diff --git a/drivers/ata/ahci_ceva.c b/drivers/ata/ahci_ceva.c index 5ecc9d46cb54..dc78c98cb9f1 100644 --- a/drivers/ata/ahci_ceva.c +++ b/drivers/ata/ahci_ceva.c @@ -213,7 +213,7 @@ static int ceva_ahci_probe(struct platform_device *pdev) cevapriv->ahci_pdev = pdev; - hpriv = ahci_platform_get_resources(pdev); + hpriv = ahci_platform_get_resources(pdev, 0); if (IS_ERR(hpriv)) return PTR_ERR(hpriv); diff --git a/drivers/ata/ahci_da850.c b/drivers/ata/ahci_da850.c index 9b34dff64536..ebaa657f28c4 100644 --- a/drivers/ata/ahci_da850.c +++ b/drivers/ata/ahci_da850.c @@ -171,7 +171,7 @@ static int ahci_da850_probe(struct platform_device *pdev) u32 mpy; int rc; - hpriv = ahci_platform_get_resources(pdev); + hpriv = ahci_platform_get_resources(pdev, 0); if (IS_ERR(hpriv)) return PTR_ERR(hpriv); diff --git a/drivers/ata/ahci_dm816.c b/drivers/ata/ahci_dm816.c index fbd827c3a75c..89509c3efb01 100644 --- a/drivers/ata/ahci_dm816.c +++ b/drivers/ata/ahci_dm816.c @@ -148,7 +148,7 @@ static int ahci_dm816_probe(struct platform_device *pdev) struct ahci_host_priv *hpriv; int rc; - hpriv = ahci_platform_get_resources(pdev); + hpriv = ahci_platform_get_resources(pdev, 0); if (IS_ERR(hpriv)) return PTR_ERR(hpriv); diff --git a/drivers/ata/ahci_imx.c b/drivers/ata/ahci_imx.c index 6822e2f33f7e..b00799d208f5 100644 --- a/drivers/ata/ahci_imx.c +++ b/drivers/ata/ahci_imx.c @@ -1127,7 +1127,7 @@ static int imx_ahci_probe(struct platform_device *pdev) return ret; } - hpriv = ahci_platform_get_resources(pdev); + hpriv = ahci_platform_get_resources(pdev, 0); if (IS_ERR(hpriv)) return PTR_ERR(hpriv); diff --git a/drivers/ata/ahci_mtk.c b/drivers/ata/ahci_mtk.c index 0ae6971c2a4c..8bc1a26ffc31 100644 --- a/drivers/ata/ahci_mtk.c +++ b/drivers/ata/ahci_mtk.c @@ -142,7 +142,7 @@ static int mtk_ahci_probe(struct platform_device *pdev) if (!plat) return -ENOMEM; - hpriv = ahci_platform_get_resources(pdev); + hpriv = ahci_platform_get_resources(pdev, 0); if (IS_ERR(hpriv)) return PTR_ERR(hpriv); diff --git a/drivers/ata/ahci_mvebu.c b/drivers/ata/ahci_mvebu.c index 0045dacd814b..adbe38fb9c35 100644 --- a/drivers/ata/ahci_mvebu.c +++ b/drivers/ata/ahci_mvebu.c @@ -158,7 +158,7 @@ static int ahci_mvebu_probe(struct platform_device *pdev) const struct mbus_dram_target_info *dram; int rc; - hpriv = ahci_platform_get_resources(pdev); + hpriv = ahci_platform_get_resources(pdev, 0); if (IS_ERR(hpriv)) return PTR_ERR(hpriv); diff --git a/drivers/ata/ahci_platform.c b/drivers/ata/ahci_platform.c index 99f9a895a459..570927316962 100644 --- a/drivers/ata/ahci_platform.c +++ b/drivers/ata/ahci_platform.c @@ -43,7 +43,7 @@ static int ahci_probe(struct platform_device *pdev) struct ahci_host_priv *hpriv; int rc; - hpriv = ahci_platform_get_resources(pdev); + hpriv = ahci_platform_get_resources(pdev, 0); if (IS_ERR(hpriv)) return PTR_ERR(hpriv); diff --git a/drivers/ata/ahci_qoriq.c b/drivers/ata/ahci_qoriq.c index cfdef4d44ae9..ce59253ec158 100644 --- a/drivers/ata/ahci_qoriq.c +++ b/drivers/ata/ahci_qoriq.c @@ -250,7 +250,7 @@ static int ahci_qoriq_probe(struct platform_device *pdev) struct resource *res; int rc; - hpriv = ahci_platform_get_resources(pdev); + hpriv = ahci_platform_get_resources(pdev, 0); if (IS_ERR(hpriv)) return PTR_ERR(hpriv); diff --git a/drivers/ata/ahci_seattle.c b/drivers/ata/ahci_seattle.c index 1d31c0c0fc20..e57b6f92c288 100644 --- a/drivers/ata/ahci_seattle.c +++ b/drivers/ata/ahci_seattle.c @@ -164,7 +164,7 @@ static int ahci_seattle_probe(struct platform_device *pdev) int rc; struct ahci_host_priv *hpriv; - hpriv = ahci_platform_get_resources(pdev); + hpriv = ahci_platform_get_resources(pdev, 0); if (IS_ERR(hpriv)) return PTR_ERR(hpriv); diff --git a/drivers/ata/ahci_st.c b/drivers/ata/ahci_st.c index bc345f249555..21c5c44832ef 100644 --- a/drivers/ata/ahci_st.c +++ b/drivers/ata/ahci_st.c @@ -156,7 +156,7 @@ static int st_ahci_probe(struct platform_device *pdev) if (!drv_data) return -ENOMEM; - hpriv = ahci_platform_get_resources(pdev); + hpriv = ahci_platform_get_resources(pdev, 0); if (IS_ERR(hpriv)) return PTR_ERR(hpriv); hpriv->plat_data = drv_data; diff --git a/drivers/ata/ahci_sunxi.c b/drivers/ata/ahci_sunxi.c index b26437430163..631610b72aa5 100644 --- a/drivers/ata/ahci_sunxi.c +++ b/drivers/ata/ahci_sunxi.c @@ -181,7 +181,7 @@ static int ahci_sunxi_probe(struct platform_device *pdev) struct ahci_host_priv *hpriv; int rc; - hpriv = ahci_platform_get_resources(pdev); + hpriv = ahci_platform_get_resources(pdev, 0); if (IS_ERR(hpriv)) return PTR_ERR(hpriv); diff --git a/drivers/ata/ahci_tegra.c b/drivers/ata/ahci_tegra.c index 64d848409fe2..004f2608818e 100644 --- a/drivers/ata/ahci_tegra.c +++ b/drivers/ata/ahci_tegra.c @@ -494,7 +494,7 @@ static int tegra_ahci_probe(struct platform_device *pdev) int ret; unsigned int i; - hpriv = ahci_platform_get_resources(pdev); + hpriv = ahci_platform_get_resources(pdev, 0); if (IS_ERR(hpriv)) return PTR_ERR(hpriv); diff --git a/drivers/ata/ahci_xgene.c b/drivers/ata/ahci_xgene.c index ad58da7c9aff..7e157e1bf65e 100644 --- a/drivers/ata/ahci_xgene.c +++ b/drivers/ata/ahci_xgene.c @@ -759,7 +759,7 @@ static int xgene_ahci_probe(struct platform_device *pdev) &xgene_ahci_v2_port_info }; int rc; - hpriv = ahci_platform_get_resources(pdev); + hpriv = ahci_platform_get_resources(pdev, 0); if (IS_ERR(hpriv)) return PTR_ERR(hpriv); diff --git a/drivers/ata/libahci_platform.c b/drivers/ata/libahci_platform.c index 8fbb532b62dd..679f763410c0 100644 --- a/drivers/ata/libahci_platform.c +++ b/drivers/ata/libahci_platform.c @@ -332,6 +332,7 @@ static int ahci_platform_get_regulator(struct ahci_host_priv *hpriv, u32 port, /** * ahci_platform_get_resources - Get platform resources * @pdev: platform device to get resources for + * @flags: bitmap representing the resource to get * * This function allocates an ahci_host_priv struct, and gets the following * resources, storing a reference to them inside the returned struct: @@ -345,7 +346,8 @@ static int ahci_platform_get_regulator(struct ahci_host_priv *hpriv, u32 port, * RETURNS: * The allocated ahci_host_priv on success, otherwise an ERR_PTR value */ -struct ahci_host_priv *ahci_platform_get_resources(struct platform_device *pdev) +struct ahci_host_priv *ahci_platform_get_resources(struct platform_device *pdev, + unsigned int flags) { struct device *dev = &pdev->dev; struct ahci_host_priv *hpriv; diff --git a/include/linux/ahci_platform.h b/include/linux/ahci_platform.h index 1b0a17b22cd3..6490be1f8a16 100644 --- a/include/linux/ahci_platform.h +++ b/include/linux/ahci_platform.h @@ -30,7 +30,7 @@ void ahci_platform_disable_regulators(struct ahci_host_priv *hpriv); int ahci_platform_enable_resources(struct ahci_host_priv *hpriv); void ahci_platform_disable_resources(struct ahci_host_priv *hpriv); struct ahci_host_priv *ahci_platform_get_resources( - struct platform_device *pdev); + struct platform_device *pdev, unsigned int flags); int ahci_platform_init_host(struct platform_device *pdev, struct ahci_host_priv *hpriv, const struct ata_port_info *pi_template, -- cgit v1.2.3 From 9d2ab99573970838108add835442a03e23f8577b Mon Sep 17 00:00:00 2001 From: Kunihiko Hayashi Date: Wed, 22 Aug 2018 21:13:02 +0900 Subject: ata: libahci_platform: add reset control support Add support to get and control a list of resets for the device as optional and shared. These resets must be kept de-asserted until the device is enabled. This is specified as shared because some SoCs like UniPhier series have common reset controls with all ahci controller instances. However, according to Thierry's view, https://www.spinics.net/lists/linux-ide/msg55357.html some hardware-specific drivers already use their own resets, and the common reset make a path to occur double controls of resets. The ahci_platform_get_resources() can get and control the reset only when the second argument includes AHCI_PLATFORM_GET_RESETS bit. Suggested-by: Hans de Goede Cc: Thierry Reding Signed-off-by: Kunihiko Hayashi Reviewed-by: Hans de Goede Signed-off-by: Tejun Heo --- .../devicetree/bindings/ata/ahci-platform.txt | 1 + drivers/ata/ahci.h | 1 + drivers/ata/libahci_platform.c | 31 ++++++++++++++++++---- include/linux/ahci_platform.h | 2 ++ 4 files changed, 30 insertions(+), 5 deletions(-) (limited to 'drivers/ata') diff --git a/Documentation/devicetree/bindings/ata/ahci-platform.txt b/Documentation/devicetree/bindings/ata/ahci-platform.txt index c760ecb81381..f4006d3c9fdf 100644 --- a/Documentation/devicetree/bindings/ata/ahci-platform.txt +++ b/Documentation/devicetree/bindings/ata/ahci-platform.txt @@ -30,6 +30,7 @@ compatible: Optional properties: - dma-coherent : Present if dma operations are coherent - clocks : a list of phandle + clock specifier pairs +- resets : a list of phandle + reset specifier pairs - target-supply : regulator for SATA target power - phys : reference to the SATA PHY node - phy-names : must be "sata-phy" diff --git a/drivers/ata/ahci.h b/drivers/ata/ahci.h index 1609ebab4e23..6a1515f0da40 100644 --- a/drivers/ata/ahci.h +++ b/drivers/ata/ahci.h @@ -350,6 +350,7 @@ struct ahci_host_priv { u32 em_msg_type; /* EM message type */ bool got_runtime_pm; /* Did we do pm_runtime_get? */ struct clk *clks[AHCI_MAX_CLKS]; /* Optional */ + struct reset_control *rsts; /* Optional */ struct regulator **target_pwrs; /* Optional */ /* * If platform uses PHYs. There is a 1:1 relation between the port number and diff --git a/drivers/ata/libahci_platform.c b/drivers/ata/libahci_platform.c index 679f763410c0..c92c10d55374 100644 --- a/drivers/ata/libahci_platform.c +++ b/drivers/ata/libahci_platform.c @@ -25,6 +25,7 @@ #include #include #include +#include #include "ahci.h" static void ahci_host_stop(struct ata_host *host); @@ -195,7 +196,8 @@ EXPORT_SYMBOL_GPL(ahci_platform_disable_regulators); * following order: * 1) Regulator * 2) Clocks (through ahci_platform_enable_clks) - * 3) Phys + * 3) Resets + * 4) Phys * * If resource enabling fails at any point the previous enabled resources * are disabled in reverse order. @@ -215,12 +217,19 @@ int ahci_platform_enable_resources(struct ahci_host_priv *hpriv) if (rc) goto disable_regulator; - rc = ahci_platform_enable_phys(hpriv); + rc = reset_control_deassert(hpriv->rsts); if (rc) goto disable_clks; + rc = ahci_platform_enable_phys(hpriv); + if (rc) + goto disable_resets; + return 0; +disable_resets: + reset_control_assert(hpriv->rsts); + disable_clks: ahci_platform_disable_clks(hpriv); @@ -238,13 +247,16 @@ EXPORT_SYMBOL_GPL(ahci_platform_enable_resources); * This function disables all ahci_platform managed resources in the * following order: * 1) Phys - * 2) Clocks (through ahci_platform_disable_clks) - * 3) Regulator + * 2) Resets + * 3) Clocks (through ahci_platform_disable_clks) + * 4) Regulator */ void ahci_platform_disable_resources(struct ahci_host_priv *hpriv) { ahci_platform_disable_phys(hpriv); + reset_control_assert(hpriv->rsts); + ahci_platform_disable_clks(hpriv); ahci_platform_disable_regulators(hpriv); @@ -341,7 +353,8 @@ static int ahci_platform_get_regulator(struct ahci_host_priv *hpriv, u32 port, * 2) regulator for controlling the targets power (optional) * 3) 0 - AHCI_MAX_CLKS clocks, as specified in the devs devicetree node, * or for non devicetree enabled platforms a single clock - * 4) phys (optional) + * 4) resets, if flags has AHCI_PLATFORM_GET_RESETS (optional) + * 5) phys (optional) * * RETURNS: * The allocated ahci_host_priv on success, otherwise an ERR_PTR value @@ -395,6 +408,14 @@ struct ahci_host_priv *ahci_platform_get_resources(struct platform_device *pdev, hpriv->clks[i] = clk; } + if (flags & AHCI_PLATFORM_GET_RESETS) { + hpriv->rsts = devm_reset_control_array_get_optional_shared(dev); + if (IS_ERR(hpriv->rsts)) { + rc = PTR_ERR(hpriv->rsts); + goto err_out; + } + } + hpriv->nports = child_nodes = of_get_child_count(dev->of_node); /* diff --git a/include/linux/ahci_platform.h b/include/linux/ahci_platform.h index 6490be1f8a16..eaedca5fe6fc 100644 --- a/include/linux/ahci_platform.h +++ b/include/linux/ahci_platform.h @@ -43,4 +43,6 @@ int ahci_platform_resume_host(struct device *dev); int ahci_platform_suspend(struct device *dev); int ahci_platform_resume(struct device *dev); +#define AHCI_PLATFORM_GET_RESETS 0x01 + #endif /* _AHCI_PLATFORM_H */ -- cgit v1.2.3 From 2d17f460c5d79fa9fc794e813377f3276acf81ce Mon Sep 17 00:00:00 2001 From: Kunihiko Hayashi Date: Wed, 22 Aug 2018 21:13:03 +0900 Subject: ata: ahci_platform: enable to get and control reset Unlike SoC-specific driver, generic ahci_platform driver doesn't have any chances to control resets. This adds AHCI_PLATFORM_GET_RESETS to ahci_platform_get_resources() on the generic driver to enable reset control support. Suggested-by: Hans de Goede Cc: Thierry Reding Signed-off-by: Kunihiko Hayashi Reviewed-by: Hans de Goede Signed-off-by: Tejun Heo --- drivers/ata/ahci_platform.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'drivers/ata') diff --git a/drivers/ata/ahci_platform.c b/drivers/ata/ahci_platform.c index 570927316962..ddd930852b2e 100644 --- a/drivers/ata/ahci_platform.c +++ b/drivers/ata/ahci_platform.c @@ -43,7 +43,8 @@ static int ahci_probe(struct platform_device *pdev) struct ahci_host_priv *hpriv; int rc; - hpriv = ahci_platform_get_resources(pdev, 0); + hpriv = ahci_platform_get_resources(pdev, + AHCI_PLATFORM_GET_RESETS); if (IS_ERR(hpriv)) return PTR_ERR(hpriv); -- cgit v1.2.3