From patchwork Thu Jul 3 09:42:19 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Quadros X-Patchwork-Id: 33016 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oa0-f72.google.com (mail-oa0-f72.google.com [209.85.219.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 0698320560 for ; Thu, 3 Jul 2014 09:42:47 +0000 (UTC) Received: by mail-oa0-f72.google.com with SMTP id eb12sf74889746oac.7 for ; Thu, 03 Jul 2014 02:42:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:message-id:date:from:user-agent :mime-version:to:cc:subject:references:in-reply-to:sender:precedence :list-id:x-original-sender:x-original-authentication-results :mailing-list:list-post:list-help:list-archive:list-unsubscribe :content-type:content-transfer-encoding; bh=QsX2OvoOQFj5euvRudOVV+PLnPutgLaxekRFs7Osn34=; b=EQsE6ytF/5P8PXqnEs3HRc8ex2tTDhIZHY3Pf4Tentes330Sx7IioNyKUI85IUFi9C xmRqqL/1R5roWm3RTuN9AekQYEEUnEBJ88GrTOK7O+jNSe3w5igFYWOErtlzvcfAg1Uv rj0hO+xbpWoyXfnubl/dGsgISY5d05cFljl6px8UXHGOVRyD0/lYbOQLUHoWNlpPRk6B 2YUBj5hV0kNEuxAPztWwv4yxmb+1eCr9yxcLSMbY/jpuwM24IXO0vAO6fdPDcaryuj0m SEedI9sSdC8jEpxB7AjDa9gAEeVcliUsH8QhQx0gIUbIqdj21EtgfTzXpMYZ0AGzlPgw QhUw== X-Gm-Message-State: ALoCoQkIXn1EB1DS0LlNDHaAYUm3XzWJTOT/ivVlsD5v3p+Hbc4hg+rZylpxUCjURJ9zNZLXlNpN X-Received: by 10.182.43.196 with SMTP id y4mr1677492obl.35.1404380567667; Thu, 03 Jul 2014 02:42:47 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.89.203 with SMTP id v69ls364398qgd.6.gmail; Thu, 03 Jul 2014 02:42:47 -0700 (PDT) X-Received: by 10.221.20.199 with SMTP id qp7mr2808770vcb.24.1404380567577; Thu, 03 Jul 2014 02:42:47 -0700 (PDT) Received: from mail-vc0-f174.google.com (mail-vc0-f174.google.com [209.85.220.174]) by mx.google.com with ESMTPS id iq6si13981319vcb.100.2014.07.03.02.42.47 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 03 Jul 2014 02:42:47 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.174 as permitted sender) client-ip=209.85.220.174; Received: by mail-vc0-f174.google.com with SMTP id hy4so11386135vcb.33 for ; Thu, 03 Jul 2014 02:42:47 -0700 (PDT) X-Received: by 10.52.117.209 with SMTP id kg17mr2357686vdb.28.1404380567499; Thu, 03 Jul 2014 02:42:47 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.37.5 with SMTP id tc5csp359255vcb; Thu, 3 Jul 2014 02:42:46 -0700 (PDT) X-Received: by 10.70.101.234 with SMTP id fj10mr3461538pdb.61.1404380566454; Thu, 03 Jul 2014 02:42:46 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id or12si3394070pab.153.2014.07.03.02.42.45; Thu, 03 Jul 2014 02:42:45 -0700 (PDT) Received-SPF: none (google.com: linux-omap-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965200AbaGCJmc (ORCPT + 6 others); Thu, 3 Jul 2014 05:42:32 -0400 Received: from comal.ext.ti.com ([198.47.26.152]:48182 "EHLO comal.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965218AbaGCJm2 (ORCPT ); Thu, 3 Jul 2014 05:42:28 -0400 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by comal.ext.ti.com (8.13.7/8.13.7) with ESMTP id s639gQ8F007638; Thu, 3 Jul 2014 04:42:26 -0500 Received: from DFLE73.ent.ti.com (dfle73.ent.ti.com [128.247.5.110]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id s639gQSS010384; Thu, 3 Jul 2014 04:42:26 -0500 Received: from dflp33.itg.ti.com (10.64.6.16) by DFLE73.ent.ti.com (128.247.5.110) with Microsoft SMTP Server id 14.3.174.1; Thu, 3 Jul 2014 04:42:26 -0500 Received: from [192.168.2.6] (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp33.itg.ti.com (8.14.3/8.13.8) with ESMTP id s639gNeq009385; Thu, 3 Jul 2014 04:42:23 -0500 Message-ID: <53B5257B.8040609@ti.com> Date: Thu, 3 Jul 2014 12:42:19 +0300 From: Roger Quadros User-Agent: Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20100101 Thunderbird/24.3.0 MIME-Version: 1.0 To: , , CC: , , , , , , Sergei Shtylyov Subject: [PATCH v2 3/6] phy: core: Support regulator supply for PHY power References: <1404302638-3003-1-git-send-email-rogerq@ti.com> <1404302638-3003-4-git-send-email-rogerq@ti.com> In-Reply-To: <1404302638-3003-4-git-send-email-rogerq@ti.com> Sender: linux-omap-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: rogerq@ti.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.174 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Roger Quadros Some PHYs can be powered by an external power regulator. e.g. USB_HS PHY on DRA7 SoC. Make the PHY core support a power regulator. Signed-off-by: Roger Quadros --- drivers/phy/phy-core.c | 27 +++++++++++++++++++++++++++ include/linux/phy/phy.h | 2 ++ 2 files changed, 29 insertions(+) diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c index 49c4465..2add59c 100644 --- a/drivers/phy/phy-core.c +++ b/drivers/phy/phy-core.c @@ -21,6 +21,7 @@ #include #include #include +#include static struct class *phy_class; static DEFINE_MUTEX(phy_provider_mutex); @@ -226,6 +227,12 @@ int phy_power_on(struct phy *phy) if (!phy) return 0; + if (phy->pwr) { + ret = regulator_enable(phy->pwr); + if (ret) + return ret; + } + ret = phy_pm_runtime_get_sync(phy); if (ret < 0 && ret != -ENOTSUPP) return ret; @@ -247,6 +254,8 @@ int phy_power_on(struct phy *phy) out: mutex_unlock(&phy->mutex); phy_pm_runtime_put_sync(phy); + if (phy->pwr) + regulator_disable(phy->pwr); return ret; } @@ -272,6 +281,9 @@ int phy_power_off(struct phy *phy) mutex_unlock(&phy->mutex); phy_pm_runtime_put(phy); + if (phy->pwr) + regulator_disable(phy->pwr); + return 0; } EXPORT_SYMBOL_GPL(phy_power_off); @@ -588,6 +600,16 @@ struct phy *phy_create(struct device *dev, const struct phy_ops *ops, goto free_phy; } + /* phy-supply */ + phy->pwr = regulator_get_optional(dev, "phy"); + if (IS_ERR(phy->pwr)) { + if (PTR_ERR(phy->pwr) == -EPROBE_DEFER) { + ret = -EPROBE_DEFER; + goto free_ida; + } + phy->pwr = NULL; + } + device_initialize(&phy->dev); mutex_init(&phy->mutex); @@ -617,6 +639,9 @@ put_dev: put_device(&phy->dev); /* calls phy_release() which frees resources */ return ERR_PTR(ret); +free_ida: + ida_simple_remove(&phy_ida, phy->id); + free_phy: kfree(phy); return ERR_PTR(ret); @@ -664,6 +689,7 @@ EXPORT_SYMBOL_GPL(devm_phy_create); void phy_destroy(struct phy *phy) { pm_runtime_disable(&phy->dev); + regulator_put(phy->pwr); device_unregister(&phy->dev); } EXPORT_SYMBOL_GPL(phy_destroy); @@ -800,6 +826,7 @@ static void phy_release(struct device *dev) phy = to_phy(dev); dev_vdbg(dev, "releasing '%s'\n", dev_name(dev)); + regulator_put(phy->pwr); ida_simple_remove(&phy_ida, phy->id); kfree(phy); } diff --git a/include/linux/phy/phy.h b/include/linux/phy/phy.h index 2760744..9a86945 100644 --- a/include/linux/phy/phy.h +++ b/include/linux/phy/phy.h @@ -18,6 +18,7 @@ #include #include #include +#include struct phy; @@ -65,6 +66,7 @@ struct phy { int init_count; int power_count; struct phy_attrs attrs; + struct regulator *pwr; }; /**