From patchwork Wed Jul 2 12:03:55 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Quadros X-Patchwork-Id: 32970 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pd0-f200.google.com (mail-pd0-f200.google.com [209.85.192.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id C48D820672 for ; Wed, 2 Jul 2014 12:04:42 +0000 (UTC) Received: by mail-pd0-f200.google.com with SMTP id v10sf51577677pde.11 for ; Wed, 02 Jul 2014 05:04:42 -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:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe:content-type; bh=BJvQ/9Ct9M9lJ3+jLf6HlIr15AIRd8p5KSXH4B/rR7w=; b=gw+XMrJYslT3549CDQPsHKMzo/cngKHPRRN9SpxEJwuR0ax+LMJ6Mm/Ej5ieYIHV8v fPScULRF0UNjnGfor84kQQfCVuR3CS6tR8ixxWWuxWThbNmDEs+7H7G9HDRPBcKMMXUa +hu0n+bI1AMhBGV56YYf/6jjVyLpvZoA18icKsRiV0vWdlcza8Ig+goCaC1MGKPAPB26 PWs3TGslHCe2wVDDY0P3/znkqJ6dUU2Z3pzZxpGrj2kNqzOKWgRMy36OS6XnpiERZnY/ oCosKvHOQJeKSnsvwdbvqsZ9jtYbnjux3SiqibF3hfmQiXWzkin0/jtlmDXJCNXK/wCm e/3Q== X-Gm-Message-State: ALoCoQlCwCgPKKveIjotCf6Cs5zdx3vyNJKfEswT9LWoQ/Py66Nz/MNYNSSASomqlEEb6za2G8Oy X-Received: by 10.66.122.101 with SMTP id lr5mr1398978pab.19.1404302682027; Wed, 02 Jul 2014 05:04:42 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.106.99 with SMTP id d90ls9950qgf.57.gmail; Wed, 02 Jul 2014 05:04:41 -0700 (PDT) X-Received: by 10.221.40.193 with SMTP id tr1mr1636896vcb.31.1404302681922; Wed, 02 Jul 2014 05:04:41 -0700 (PDT) Received: from mail-vc0-f173.google.com (mail-vc0-f173.google.com [209.85.220.173]) by mx.google.com with ESMTPS id o5si12806547vcj.31.2014.07.02.05.04.41 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 02 Jul 2014 05:04:41 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.173 as permitted sender) client-ip=209.85.220.173; Received: by mail-vc0-f173.google.com with SMTP id lf12so10305665vcb.32 for ; Wed, 02 Jul 2014 05:04:41 -0700 (PDT) X-Received: by 10.58.76.225 with SMTP id n1mr1393707vew.32.1404302681814; Wed, 02 Jul 2014 05:04:41 -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 tc5csp287913vcb; Wed, 2 Jul 2014 05:04:41 -0700 (PDT) X-Received: by 10.68.99.194 with SMTP id es2mr69732863pbb.100.1404302681110; Wed, 02 Jul 2014 05:04:41 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ay4si30076842pbc.122.2014.07.02.05.04.40; Wed, 02 Jul 2014 05:04:40 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-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 S1752724AbaGBMEU (ORCPT + 27 others); Wed, 2 Jul 2014 08:04:20 -0400 Received: from comal.ext.ti.com ([198.47.26.152]:47284 "EHLO comal.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751524AbaGBMEQ (ORCPT ); Wed, 2 Jul 2014 08:04:16 -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 s62C4Fm6031029; Wed, 2 Jul 2014 07:04:15 -0500 Received: from DLEE71.ent.ti.com (dlee71.ent.ti.com [157.170.170.114]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id s62C4FgH007777; Wed, 2 Jul 2014 07:04:15 -0500 Received: from dlep33.itg.ti.com (157.170.170.75) by DLEE71.ent.ti.com (157.170.170.114) with Microsoft SMTP Server id 14.3.174.1; Wed, 2 Jul 2014 07:04:13 -0500 Received: from localhost.localdomain (ileax41-snat.itg.ti.com [10.172.224.153]) by dlep33.itg.ti.com (8.14.3/8.13.8) with ESMTP id s62C41PI005005; Wed, 2 Jul 2014 07:04:11 -0500 From: Roger Quadros To: , , CC: , , , , , , Roger Quadros Subject: [PATCH 3/6] phy: core: Support regulator supply for PHY power Date: Wed, 2 Jul 2014 15:03:55 +0300 Message-ID: <1404302638-3003-4-git-send-email-rogerq@ti.com> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1404302638-3003-1-git-send-email-rogerq@ti.com> References: <1404302638-3003-1-git-send-email-rogerq@ti.com> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@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.173 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: , 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 | 32 ++++++++++++++++++++++++++++++++ include/linux/phy/phy.h | 2 ++ 2 files changed, 34 insertions(+) diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c index 49c4465..d817107 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,10 @@ EXPORT_SYMBOL_GPL(devm_phy_create); void phy_destroy(struct phy *phy) { pm_runtime_disable(&phy->dev); + + if (phy->pwr) + regulator_put(phy->pwr); + device_unregister(&phy->dev); } EXPORT_SYMBOL_GPL(phy_destroy); @@ -800,6 +829,9 @@ static void phy_release(struct device *dev) phy = to_phy(dev); dev_vdbg(dev, "releasing '%s'\n", dev_name(dev)); + if (phy->pwr) + 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; }; /**