From patchwork Wed Apr 3 08:45:08 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fabio Baltieri X-Patchwork-Id: 15841 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id AF4B023E21 for ; Wed, 3 Apr 2013 08:47:45 +0000 (UTC) Received: from mail-qa0-f71.google.com (mail-qa0-f71.google.com [209.85.216.71]) by fiordland.canonical.com (Postfix) with ESMTP id 5089AA184B7 for ; Wed, 3 Apr 2013 08:47:45 +0000 (UTC) Received: by mail-qa0-f71.google.com with SMTP id k4sf2102533qaq.6 for ; Wed, 03 Apr 2013 01:47:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:mime-version:x-beenthere:x-received:received-spf :x-received:x-forwarded-to:x-forwarded-for:delivered-to:x-received :received-spf:x-received:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:x-gm-message-state:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-google-group-id:list-post:list-help:list-archive:list-unsubscribe; bh=6XrXEB68/14MYws/zitHw5KUdkacOCOwLWJl/WtRGFA=; b=MSNwQXqcSB7CjiPEyaJLXTKAzEqUAg59N/S1rndBV/v80AwHCqB83Je72g/D1B+jTK L5qAr2P78T0p07fFW48/8y2mLdvWtrfABQWiS8J1ZbRfxZ98dtSZKwIP/ciA8xADAWWV LBzRvQkIRDLjfxgFelOOwcD88VSqJXVfPy4j85q2p6wXxjRkFBQNG63905ykLk5bhUPd j06jjlv1Ytzlz1mlEVjhI9nWAHRrUkNFPiskCjPl78pspKokjMwKDfoFLuFdMc8sk9Il Y7gVMlJ3g4fHPPIbEwmdMXR1Tl1r0pfhsPs+cu11jfLMhWX800zun3pXQ3IAEhiTPBu8 ls5g== X-Received: by 10.224.185.79 with SMTP id cn15mr703769qab.4.1364978864840; Wed, 03 Apr 2013 01:47:44 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.98.101 with SMTP id eh5ls786091qeb.95.gmail; Wed, 03 Apr 2013 01:47:44 -0700 (PDT) X-Received: by 10.52.65.73 with SMTP id v9mr450805vds.30.1364978864713; Wed, 03 Apr 2013 01:47:44 -0700 (PDT) Received: from mail-vb0-x234.google.com (mail-vb0-x234.google.com [2607:f8b0:400c:c02::234]) by mx.google.com with ESMTPS id d10si4247662vdv.119.2013.04.03.01.47.44 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 03 Apr 2013 01:47:44 -0700 (PDT) Received-SPF: neutral (google.com: 2607:f8b0:400c:c02::234 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=2607:f8b0:400c:c02::234; Received: by mail-vb0-f52.google.com with SMTP id w8so264398vbf.11 for ; Wed, 03 Apr 2013 01:47:44 -0700 (PDT) X-Received: by 10.220.106.14 with SMTP id v14mr548051vco.2.1364978864574; Wed, 03 Apr 2013 01:47:44 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.59.4.204 with SMTP id cg12csp160644ved; Wed, 3 Apr 2013 01:47:43 -0700 (PDT) X-Received: by 10.14.218.71 with SMTP id j47mr1808150eep.28.1364978863492; Wed, 03 Apr 2013 01:47:43 -0700 (PDT) Received: from mail-ee0-f42.google.com (mail-ee0-f42.google.com [74.125.83.42]) by mx.google.com with ESMTPS id a1si7557615eez.181.2013.04.03.01.47.43 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 03 Apr 2013 01:47:43 -0700 (PDT) Received-SPF: neutral (google.com: 74.125.83.42 is neither permitted nor denied by best guess record for domain of fabio.baltieri@linaro.org) client-ip=74.125.83.42; Received: by mail-ee0-f42.google.com with SMTP id b47so560877eek.15 for ; Wed, 03 Apr 2013 01:47:43 -0700 (PDT) X-Received: by 10.14.5.137 with SMTP id 9mr1798046eel.30.1364978862970; Wed, 03 Apr 2013 01:47:42 -0700 (PDT) Received: from localhost ([2a01:2003:1:1e91:8e70:5aff:feac:ad8]) by mx.google.com with ESMTPS id 44sm6904720eek.5.2013.04.03.01.47.35 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 03 Apr 2013 01:47:42 -0700 (PDT) From: Fabio Baltieri To: Felipe Balbi Cc: Linus Walleij , Praveena Nadahally , linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, Fabio Baltieri , Mian Yousaf Kaukab , Sakethram Bommisetti Subject: [PATCH 07/12] usb: phy: ab8500-usb: enable/disable regulator on phy events Date: Wed, 3 Apr 2013 10:45:08 +0200 Message-Id: <1364978713-19612-8-git-send-email-fabio.baltieri@linaro.org> X-Mailer: git-send-email 1.8.1.3 In-Reply-To: <1364978713-19612-1-git-send-email-fabio.baltieri@linaro.org> References: <1364978713-19612-1-git-send-email-fabio.baltieri@linaro.org> X-Gm-Message-State: ALoCoQmq6AnSlEdEFrSeuo2Ty/XqB/B/iJzS58GAGprFDvUO4EvsZUYsa3U/8fN/OszJEm++2QOz X-Original-Sender: fabio.baltieri@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 2607:f8b0:400c:c02::234 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Add ab8500_usb_regulator_{enable,disable} functions to control USB phy regulators on corresponding ab8500_usb_phy_{enable,disable} events. This contains some workaround and optimization for specific AB8500 versions. Signed-off-by: Mian Yousaf Kaukab Signed-off-by: Sakethram Bommisetti Signed-off-by: Praveena Nadahally Acked-by: Linus Walleij Signed-off-by: Fabio Baltieri --- drivers/usb/phy/phy-ab8500-usb.c | 68 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 66 insertions(+), 2 deletions(-) diff --git a/drivers/usb/phy/phy-ab8500-usb.c b/drivers/usb/phy/phy-ab8500-usb.c index 1c6eec9..803ad93 100644 --- a/drivers/usb/phy/phy-ab8500-usb.c +++ b/drivers/usb/phy/phy-ab8500-usb.c @@ -130,6 +130,7 @@ struct ab8500_usb { struct regulator *v_ape; struct regulator *v_musb; struct regulator *v_ulpi; + int saved_v_ulpi; int previous_link_status_state; }; @@ -161,6 +162,67 @@ static void ab8500_usb_wd_workaround(struct ab8500_usb *ab) 0); } +static void ab8500_usb_regulator_enable(struct ab8500_usb *ab) +{ + int ret, volt; + + regulator_enable(ab->v_ape); + + if (!is_ab8500_2p0_or_earlier(ab->ab8500)) { + ab->saved_v_ulpi = regulator_get_voltage(ab->v_ulpi); + if (ab->saved_v_ulpi < 0) + dev_err(ab->dev, "Failed to get v_ulpi voltage\n"); + + ret = regulator_set_voltage(ab->v_ulpi, 1300000, 1350000); + if (ret < 0) + dev_err(ab->dev, "Failed to set the Vintcore to 1.3V, ret=%d\n", + ret); + + ret = regulator_set_optimum_mode(ab->v_ulpi, 28000); + if (ret < 0) + dev_err(ab->dev, "Failed to set optimum mode (ret=%d)\n", + ret); + } + + regulator_enable(ab->v_ulpi); + + if (!is_ab8500_2p0_or_earlier(ab->ab8500)) { + volt = regulator_get_voltage(ab->v_ulpi); + if ((volt != 1300000) && (volt != 1350000)) + dev_err(ab->dev, "Vintcore is not set to 1.3V volt=%d\n", + volt); + } + + regulator_enable(ab->v_musb); +} + +static void ab8500_usb_regulator_disable(struct ab8500_usb *ab) +{ + int ret; + + regulator_disable(ab->v_musb); + + regulator_disable(ab->v_ulpi); + + /* USB is not the only consumer of Vintcore, restore old settings */ + if (!is_ab8500_2p0_or_earlier(ab->ab8500)) { + if (ab->saved_v_ulpi > 0) { + ret = regulator_set_voltage(ab->v_ulpi, + ab->saved_v_ulpi, ab->saved_v_ulpi); + if (ret < 0) + dev_err(ab->dev, "Failed to set the Vintcore to %duV, ret=%d\n", + ab->saved_v_ulpi, ret); + } + + ret = regulator_set_optimum_mode(ab->v_ulpi, 0); + if (ret < 0) + dev_err(ab->dev, "Failed to set optimum mode (ret=%d)\n", + ret); + } + + regulator_disable(ab->v_ape); +} + static void ab8500_usb_wd_linkstatus(struct ab8500_usb *ab, u8 bit) { /* Workaround for v2.0 bug # 31952 */ @@ -178,6 +240,8 @@ static void ab8500_usb_phy_enable(struct ab8500_usb *ab, bool sel_host) bit = sel_host ? AB8500_BIT_PHY_CTRL_HOST_EN : AB8500_BIT_PHY_CTRL_DEVICE_EN; + ab8500_usb_regulator_enable(ab); + abx500_mask_and_set_register_interruptible(ab->dev, AB8500_USB, AB8500_USB_PHY_CTRL_REG, bit, bit); @@ -197,6 +261,8 @@ static void ab8500_usb_phy_disable(struct ab8500_usb *ab, bool sel_host) /* Needed to disable the phy.*/ ab8500_usb_wd_workaround(ab); + + ab8500_usb_regulator_disable(ab); } #define ab8500_usb_host_phy_en(ab) ab8500_usb_phy_enable(ab, true) @@ -543,7 +609,6 @@ static int ab8500_usb_set_peripheral(struct usb_otg *otg, */ if (!gadget) { - /* TODO: Disable regulators. */ otg->gadget = NULL; schedule_work(&ab->phy_dis_work); } else { @@ -575,7 +640,6 @@ static int ab8500_usb_set_host(struct usb_otg *otg, struct usb_bus *host) */ if (!host) { - /* TODO: Disable regulators. */ otg->host = NULL; schedule_work(&ab->phy_dis_work); } else {