From patchwork Sun Oct 30 06:21:22 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: JiSheng Zhang X-Patchwork-Id: 122586 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 440AFB6F92 for ; Sun, 30 Oct 2011 17:07:31 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750838Ab1J3GH0 (ORCPT ); Sun, 30 Oct 2011 02:07:26 -0400 Received: from mail-iy0-f174.google.com ([209.85.210.174]:47056 "EHLO mail-iy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750724Ab1J3GH0 (ORCPT ); Sun, 30 Oct 2011 02:07:26 -0400 Received: by iaby12 with SMTP id y12so5802136iab.19 for ; Sat, 29 Oct 2011 23:07:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=date:from:to:cc:subject:message-id:x-mailer:mime-version :content-type:content-transfer-encoding; bh=95cEsg6wyxQfWmHWJtnRXtMxKrgi/8m8dTXLiCChQ9o=; b=wNWyqvtPLJ9KAGmoPVVoGMROfDg9LzDQm8IQlO2S+Wk3cni8d5uzK/jxoSNoN8eBRs UO6sOoqgrqnjnHz4GEITlr9Gp4iibtTEW3Q1p9W39Ocp1W0Ed4bSn071J7XjZOjVSCDx FSncUUaRUhTibHq2T0Xn0MijbGerm+PX8QEMw= Received: by 10.42.166.9 with SMTP id m9mr13672060icy.54.1319954845683; Sat, 29 Oct 2011 23:07:25 -0700 (PDT) Received: from ustc ([211.161.97.142]) by mx.google.com with ESMTPS id u8sm8437605igm.4.2011.10.29.23.07.21 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 29 Oct 2011 23:07:25 -0700 (PDT) Date: Sun, 30 Oct 2011 14:21:22 +0800 From: JiSheng Zhang To: jgarzik@pobox.com Cc: linux-ide@vger.kernel.org, avorontsov@mvista.com, linux-kernel@vger.kernel.org Subject: [PATCH] ahci_platform: add suspend & resume support Message-ID: <20111030142122.560216e2@ustc> X-Mailer: Claws Mail 3.7.8 (GTK+ 2.24.6; i486-pc-linux-gnu) Mime-Version: 1.0 Sender: linux-ide-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ide@vger.kernel.org Signed-off-by: JiSheng Zhang --- drivers/ata/ahci_platform.c | 54 +++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 54 insertions(+), 0 deletions(-) diff --git a/drivers/ata/ahci_platform.c b/drivers/ata/ahci_platform.c index c03277d..60ff9eb 100644 --- a/drivers/ata/ahci_platform.c +++ b/drivers/ata/ahci_platform.c @@ -202,12 +202,66 @@ static int __devexit ahci_remove(struct platform_device *pdev) return 0; } +#ifdef CONFIG_PM +static int ahci_suspend(struct platform_device *pdev, pm_message_t mesg) +{ + struct ata_host *host = dev_get_drvdata(&pdev->dev); + struct ahci_host_priv *hpriv = host->private_data; + void __iomem *mmio = hpriv->mmio; + u32 ctl; + + if (mesg.event & PM_EVENT_SLEEP) { + /* AHCI spec rev1.1 section 8.3.3: + * Software must disable interrupts prior to requesting a + * transition of the HBA to D3 state. + */ + ctl = readl(mmio + HOST_CTL); + ctl &= ~HOST_IRQ_EN; + writel(ctl, mmio + HOST_CTL); + readl(mmio + HOST_CTL); /* flush */ + } + + return ata_host_suspend(host, mesg); +} + +static int ahci_resume(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); + struct ahci_host_priv *hpriv = host->private_data; + int rc; + + if (pdata && pdata->init) { + rc = pdata->init(dev, hpriv->mmio); + if (rc) + return rc; + } + + if (pdev->dev.power.power_state.event == PM_EVENT_SUSPEND) { + rc = ahci_reset_controller(host); + if (rc) + return rc; + + ahci_init_controller(host); + } + + ata_host_resume(host); + + return 0; +} +#endif + static struct platform_driver ahci_driver = { .remove = __devexit_p(ahci_remove), .driver = { .name = "ahci", .owner = THIS_MODULE, }, +#ifdef CONFIG_PM + .suspend = ahci_suspend, + .resume = ahci_resume, +#endif .id_table = ahci_devtype, };