linux-omap.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Roger Quadros <rogerq@ti.com>
To: tony@atomide.com, kishon@ti.com, balbi@ti.com
Cc: nsekhar@ti.com, nm@ti.com, george.cherian@ti.com,
	linux-omap@vger.kernel.org, linux-usb@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
Subject: [PATCH v2 3/6] phy: core: Support regulator supply for PHY power
Date: Thu, 3 Jul 2014 12:42:19 +0300	[thread overview]
Message-ID: <53B5257B.8040609@ti.com> (raw)
In-Reply-To: <1404302638-3003-4-git-send-email-rogerq@ti.com>

From: Roger Quadros <rogerq@ti.com>

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 <rogerq@ti.com>
---
 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 <linux/phy/phy.h>
 #include <linux/idr.h>
 #include <linux/pm_runtime.h>
+#include <linux/regulator/consumer.h>
 
 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 <linux/of.h>
 #include <linux/device.h>
 #include <linux/pm_runtime.h>
+#include <linux/regulator/consumer.h>
 
 struct phy;
 
@@ -65,6 +66,7 @@ struct phy {
 	int			init_count;
 	int			power_count;
 	struct phy_attrs	attrs;
+	struct regulator	*pwr;
 };
 
 /**
-- 
1.8.3.2


  parent reply	other threads:[~2014-07-03  9:42 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-02 12:03 [PATCH 0/6] omap: phy: dra7-evm PHY fixes for 3.16 Roger Quadros
2014-07-02 12:03 ` [PATCH 1/6] ARM: dts: dra7-evm: Make VDDA_1V8_PHY supply always on Roger Quadros
2014-07-02 13:05   ` Nishanth Menon
2014-07-02 14:37     ` Roger Quadros
2014-07-03  9:40   ` [PATCH v2 " Roger Quadros
2014-07-02 12:03 ` [PATCH 2/6] phy: core: Fix error path in phy_create() Roger Quadros
2014-07-02 12:03 ` [PATCH 3/6] phy: core: Support regulator supply for PHY power Roger Quadros
2014-07-02 12:32   ` Sergei Shtylyov
2014-07-03  8:02     ` Roger Quadros
2014-07-03  9:42   ` Roger Quadros [this message]
2014-07-02 12:03 ` [PATCH 4/6] phy: core: Add phy-supply to DT binding documentation Roger Quadros
2014-07-02 12:03 ` [PATCH 5/6] phy: omap-usb2: Balance pm_runtime_enable() on probe failure Roger Quadros
2014-07-03 13:31   ` Kishon Vijay Abraham I
2014-07-03 16:50     ` Roger Quadros
2014-07-02 12:03 ` [PATCH 6/6] ARM: dts: dra7-evm: Add regulator information to USB2 PHYs Roger Quadros
  -- strict thread matches above, loose matches on Subject: below --
2014-07-04  9:55 [PATCH v2 0/6] omap: phy: dra7-evm PHY fixes for 3.16 Roger Quadros
2014-07-04  9:55 ` [PATCH v2 3/6] phy: core: Support regulator supply for PHY power Roger Quadros

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=53B5257B.8040609@ti.com \
    --to=rogerq@ti.com \
    --cc=balbi@ti.com \
    --cc=george.cherian@ti.com \
    --cc=kishon@ti.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=nm@ti.com \
    --cc=nsekhar@ti.com \
    --cc=sergei.shtylyov@cogentembedded.com \
    --cc=tony@atomide.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).