From patchwork Sat Jan 18 23:48:49 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 3509201 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id E91959F1C3 for ; Sun, 19 Jan 2014 11:40:40 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 070D12011E for ; Sun, 19 Jan 2014 11:40:40 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id F3AEB2011B for ; Sun, 19 Jan 2014 11:40:38 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1W4qi5-0004Km-9x; Sun, 19 Jan 2014 11:38:39 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1W4qhY-00083x-7G; Sun, 19 Jan 2014 11:38:04 +0000 Received: from mx1.redhat.com ([209.132.183.28]) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1W4fdw-0003JU-Ts for linux-arm-kernel@lists.infradead.org; Sat, 18 Jan 2014 23:49:40 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s0INnGJv006702 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sat, 18 Jan 2014 18:49:16 -0500 Received: from shalem.localdomain.com (vpn1-4-230.ams2.redhat.com [10.36.4.230]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id s0INmuki020501; Sat, 18 Jan 2014 18:49:14 -0500 From: Hans de Goede To: Tejun Heo Subject: [RFC v3 07/13] ahci-platform: Add support for an optional regulator for sata-target power Date: Sun, 19 Jan 2014 00:48:49 +0100 Message-Id: <1390088935-7193-8-git-send-email-hdegoede@redhat.com> In-Reply-To: <1390088935-7193-1-git-send-email-hdegoede@redhat.com> References: <1390088935-7193-1-git-send-email-hdegoede@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-Bad-Reply: References and In-Reply-To but no 'Re:' in Subject. X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140118_184937_254235_5CF49C4C X-CRM114-Status: GOOD ( 14.90 ) X-Spam-Score: -7.3 (-------) X-Mailman-Approved-At: Sun, 19 Jan 2014 06:37:13 -0500 Cc: devicetree , Hans de Goede , linux-ide@vger.kernel.org, Oliver Schinagl , Richard Zhu , linux-sunxi@googlegroups.com, Maxime Ripard , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.7 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Hans de Goede --- .../devicetree/bindings/ata/ahci-platform.txt | 1 + drivers/ata/ahci.h | 2 ++ drivers/ata/ahci_platform.c | 39 +++++++++++++++++++--- 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/Documentation/devicetree/bindings/ata/ahci-platform.txt b/Documentation/devicetree/bindings/ata/ahci-platform.txt index 3ced07d..1ac807f 100644 --- a/Documentation/devicetree/bindings/ata/ahci-platform.txt +++ b/Documentation/devicetree/bindings/ata/ahci-platform.txt @@ -11,6 +11,7 @@ Required properties: Optional properties: - dma-coherent : Present if dma operations are coherent - clocks : a list of phandle + clock specifier pairs +- target-supply : regulator for SATA target power Example: sata@ffe08000 { diff --git a/drivers/ata/ahci.h b/drivers/ata/ahci.h index 7950b3a..c3e0c49 100644 --- a/drivers/ata/ahci.h +++ b/drivers/ata/ahci.h @@ -36,6 +36,7 @@ #define _AHCI_H #include +#include #include /* Enclosure Management Control */ @@ -323,6 +324,7 @@ struct ahci_host_priv { u32 em_buf_sz; /* EM buffer size in byte */ u32 em_msg_type; /* EM message type */ struct clk *clks[AHCI_MAX_CLKS]; /* Optional */ + struct regulator *target_pwr; /* Optional */ void *plat_data; /* Other platform data */ /* Optional ahci_start_engine override */ void (*start_engine)(struct ata_port *ap); diff --git a/drivers/ata/ahci_platform.c b/drivers/ata/ahci_platform.c index 75a3d47..3bc2dab 100644 --- a/drivers/ata/ahci_platform.c +++ b/drivers/ata/ahci_platform.c @@ -181,6 +181,13 @@ static int ahci_probe(struct platform_device *pdev) hpriv->clks[i] = clk; } + hpriv->target_pwr = devm_regulator_get_optional(dev, "target"); + if (IS_ERR(hpriv->target_pwr)) { + if (PTR_ERR(hpriv->target_pwr) == -EPROBE_DEFER) + return -EPROBE_DEFER; + hpriv->target_pwr = NULL; + } + rc = ahci_enable_clks(dev, hpriv); if (rc) goto free_clk; @@ -197,6 +204,12 @@ static int ahci_probe(struct platform_device *pdev) goto disable_unprepare_clk; } + if (hpriv->target_pwr) { + rc = regulator_enable(hpriv->target_pwr); + if (rc) + goto pdata_exit; + } + ahci_save_initial_config(dev, hpriv, pdata ? pdata->force_port_map : 0, pdata ? pdata->mask_port_map : 0); @@ -220,7 +233,7 @@ static int ahci_probe(struct platform_device *pdev) host = ata_host_alloc_pinfo(dev, ppi, n_ports); if (!host) { rc = -ENOMEM; - goto pdata_exit; + goto disable_regulator; } host->private_data = hpriv; @@ -250,7 +263,7 @@ static int ahci_probe(struct platform_device *pdev) rc = ahci_reset_controller(host); if (rc) - goto pdata_exit; + goto disable_regulator; ahci_init_controller(host); ahci_print_info(host, "platform"); @@ -258,9 +271,12 @@ static int ahci_probe(struct platform_device *pdev) rc = ata_host_activate(host, irq, ahci_interrupt, IRQF_SHARED, &ahci_platform_sht); if (rc) - goto pdata_exit; + goto disable_regulator; return 0; +disable_regulator: + if (hpriv->target_pwr) + regulator_disable(hpriv->target_pwr); pdata_exit: if (pdata && pdata->exit) pdata->exit(dev); @@ -277,6 +293,9 @@ static void ahci_host_stop(struct ata_host *host) struct ahci_platform_data *pdata = dev_get_platdata(dev); struct ahci_host_priv *hpriv = host->private_data; + if (hpriv->target_pwr) + regulator_disable(hpriv->target_pwr); + if (pdata && pdata->exit) pdata->exit(dev); @@ -313,6 +332,9 @@ static int ahci_suspend(struct device *dev) if (rc) return rc; + if (hpriv->target_pwr) + regulator_disable(hpriv->target_pwr); + if (pdata && pdata->suspend) pdata->suspend(dev); @@ -338,10 +360,16 @@ static int ahci_resume(struct device *dev) goto disable_unprepare_clk; } + if (hpriv->target_pwr) { + rc = regulator_enable(hpriv->target_pwr); + if (rc) + goto pdata_suspend; + } + if (dev->power.power_state.event == PM_EVENT_SUSPEND) { rc = ahci_reset_controller(host); if (rc) - goto pdata_suspend; + goto disable_regulator; ahci_init_controller(host); } @@ -350,6 +378,9 @@ static int ahci_resume(struct device *dev) return 0; +disable_regulator: + if (hpriv->target_pwr) + regulator_disable(hpriv->target_pwr); pdata_suspend: if (pdata && pdata->suspend) pdata->suspend(dev);