From: Kishon Vijay Abraham I <kishon@ti.com>
To: <gregkh@linuxfoundation.org>, <kishon@ti.com>,
<linux-kernel@vger.kernel.org>
Subject: [PATCH 24/28] phy: ti-pipe3: streamline PHY operations
Date: Sat, 8 Mar 2014 14:59:25 +0530 [thread overview]
Message-ID: <1394270969-11851-25-git-send-email-kishon@ti.com> (raw)
In-Reply-To: <1394270969-11851-1-git-send-email-kishon@ti.com>
From: Roger Quadros <rogerq@ti.com>
Limit .power_on() and .power_off() to just control the
PHY power and not the DPLL. The DPLL will be enabled
in .init() and idled in .exit().
Don't reprogram the DPLL if it has been already locked
by the bootloader. This fixes a problem with SATA, where
it fails if SATA was used by the bootloader.
Signed-off-by: Roger Quadros <rogerq@ti.com>
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
drivers/phy/phy-ti-pipe3.c | 114 ++++++++++++++++++++++++--------------------
1 file changed, 63 insertions(+), 51 deletions(-)
diff --git a/drivers/phy/phy-ti-pipe3.c b/drivers/phy/phy-ti-pipe3.c
index baa3f78d..12cc900 100644
--- a/drivers/phy/phy-ti-pipe3.c
+++ b/drivers/phy/phy-ti-pipe3.c
@@ -47,7 +47,8 @@
#define PLL_SD_MASK 0x0003FC00
#define PLL_SD_SHIFT 10
#define SET_PLL_GO 0x1
-#define PLL_TICOPWDN 0x10000
+#define PLL_LDOPWDN BIT(15)
+#define PLL_TICOPWDN BIT(16)
#define PLL_LOCK 0x2
#define PLL_IDLE 0x1
@@ -56,7 +57,8 @@
* value required for the PIPE3PHY_PLL_CONFIGURATION2.PLL_IDLE status
* to be correctly reflected in the PIPE3PHY_PLL_STATUS register.
*/
-# define PLL_IDLE_TIME 100;
+#define PLL_IDLE_TIME 100 /* in milliseconds */
+#define PLL_LOCK_TIME 100 /* in milliseconds */
struct pipe3_dpll_params {
u16 m;
@@ -132,24 +134,6 @@ static struct pipe3_dpll_params *ti_pipe3_get_dpll_params(struct ti_pipe3 *phy)
static int ti_pipe3_power_off(struct phy *x)
{
struct ti_pipe3 *phy = phy_get_drvdata(x);
- int val;
- int timeout = PLL_IDLE_TIME;
-
- val = ti_pipe3_readl(phy->pll_ctrl_base, PLL_CONFIGURATION2);
- val |= PLL_IDLE;
- ti_pipe3_writel(phy->pll_ctrl_base, PLL_CONFIGURATION2, val);
-
- do {
- val = ti_pipe3_readl(phy->pll_ctrl_base, PLL_STATUS);
- if (val & PLL_TICOPWDN)
- break;
- udelay(5);
- } while (--timeout);
-
- if (!timeout) {
- dev_err(phy->dev, "power off failed\n");
- return -EBUSY;
- }
omap_control_phy_power(phy->control_dev, 0);
@@ -159,44 +143,34 @@ static int ti_pipe3_power_off(struct phy *x)
static int ti_pipe3_power_on(struct phy *x)
{
struct ti_pipe3 *phy = phy_get_drvdata(x);
- int val;
- int timeout = PLL_IDLE_TIME;
-
- val = ti_pipe3_readl(phy->pll_ctrl_base, PLL_CONFIGURATION2);
- val &= ~PLL_IDLE;
- ti_pipe3_writel(phy->pll_ctrl_base, PLL_CONFIGURATION2, val);
- do {
- val = ti_pipe3_readl(phy->pll_ctrl_base, PLL_STATUS);
- if (!(val & PLL_TICOPWDN))
- break;
- udelay(5);
- } while (--timeout);
-
- if (!timeout) {
- dev_err(phy->dev, "power on failed\n");
- return -EBUSY;
- }
+ omap_control_phy_power(phy->control_dev, 1);
return 0;
}
-static void ti_pipe3_dpll_relock(struct ti_pipe3 *phy)
+static int ti_pipe3_dpll_wait_lock(struct ti_pipe3 *phy)
{
u32 val;
unsigned long timeout;
- ti_pipe3_writel(phy->pll_ctrl_base, PLL_GO, SET_PLL_GO);
-
- timeout = jiffies + msecs_to_jiffies(20);
+ timeout = jiffies + msecs_to_jiffies(PLL_LOCK_TIME);
do {
+ cpu_relax();
val = ti_pipe3_readl(phy->pll_ctrl_base, PLL_STATUS);
if (val & PLL_LOCK)
break;
- } while (!WARN_ON(time_after(jiffies, timeout)));
+ } while (!time_after(jiffies, timeout));
+
+ if (!(val & PLL_LOCK)) {
+ dev_err(phy->dev, "DPLL failed to lock\n");
+ return -EBUSY;
+ }
+
+ return 0;
}
-static int ti_pipe3_dpll_lock(struct ti_pipe3 *phy)
+static int ti_pipe3_dpll_program(struct ti_pipe3 *phy)
{
u32 val;
struct pipe3_dpll_params *dpll_params;
@@ -230,27 +204,65 @@ static int ti_pipe3_dpll_lock(struct ti_pipe3 *phy)
val |= dpll_params->sd << PLL_SD_SHIFT;
ti_pipe3_writel(phy->pll_ctrl_base, PLL_CONFIGURATION3, val);
- ti_pipe3_dpll_relock(phy);
+ ti_pipe3_writel(phy->pll_ctrl_base, PLL_GO, SET_PLL_GO);
- return 0;
+ return ti_pipe3_dpll_wait_lock(phy);
}
static int ti_pipe3_init(struct phy *x)
{
struct ti_pipe3 *phy = phy_get_drvdata(x);
- int ret;
+ u32 val;
+ int ret = 0;
- ret = ti_pipe3_dpll_lock(phy);
- if (ret)
- return ret;
+ /* Bring it out of IDLE if it is IDLE */
+ val = ti_pipe3_readl(phy->pll_ctrl_base, PLL_CONFIGURATION2);
+ if (val & PLL_IDLE) {
+ val &= ~PLL_IDLE;
+ ti_pipe3_writel(phy->pll_ctrl_base, PLL_CONFIGURATION2, val);
+ ret = ti_pipe3_dpll_wait_lock(phy);
+ }
- omap_control_phy_power(phy->control_dev, 1);
+ /* Program the DPLL only if not locked */
+ val = ti_pipe3_readl(phy->pll_ctrl_base, PLL_STATUS);
+ if (!(val & PLL_LOCK))
+ if (ti_pipe3_dpll_program(phy))
+ return -EINVAL;
- return 0;
+ return ret;
}
+static int ti_pipe3_exit(struct phy *x)
+{
+ struct ti_pipe3 *phy = phy_get_drvdata(x);
+ u32 val;
+ unsigned long timeout;
+
+ /* Put DPLL in IDLE mode */
+ val = ti_pipe3_readl(phy->pll_ctrl_base, PLL_CONFIGURATION2);
+ val |= PLL_IDLE;
+ ti_pipe3_writel(phy->pll_ctrl_base, PLL_CONFIGURATION2, val);
+
+ /* wait for LDO and Oscillator to power down */
+ timeout = jiffies + msecs_to_jiffies(PLL_IDLE_TIME);
+ do {
+ cpu_relax();
+ val = ti_pipe3_readl(phy->pll_ctrl_base, PLL_STATUS);
+ if ((val & PLL_TICOPWDN) && (val & PLL_LDOPWDN))
+ break;
+ } while (!time_after(jiffies, timeout));
+
+ if (!(val & PLL_TICOPWDN) || !(val & PLL_LDOPWDN)) {
+ dev_err(phy->dev, "Failed to power down: PLL_STATUS 0x%x\n",
+ val);
+ return -EBUSY;
+ }
+
+ return 0;
+}
static struct phy_ops ops = {
.init = ti_pipe3_init,
+ .exit = ti_pipe3_exit,
.power_on = ti_pipe3_power_on,
.power_off = ti_pipe3_power_off,
.owner = THIS_MODULE,
--
1.7.9.5
next prev parent reply other threads:[~2014-03-08 9:33 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-08 9:29 [GIT PULL 00/28] PHY for 3.15 Kishon Vijay Abraham I
2014-03-08 9:29 ` [PATCH 01/28] usb: phy: twl4030-usb: Silence checkpatch warnings Kishon Vijay Abraham I
2014-03-08 9:29 ` [PATCH 02/28] usb: phy: twl4030-usb: Remove redundant semicolon Kishon Vijay Abraham I
2014-03-08 9:29 ` [PATCH 03/28] usb: phy: bcm-kona-usb2: Use PTR_ERR_OR_ZERO Kishon Vijay Abraham I
2014-03-08 9:29 ` [PATCH 04/28] phy: Select PHY_EXYNOS_MIPI_VIDEO by default for ARCH_EXYNOS Kishon Vijay Abraham I
2014-03-08 9:29 ` [PATCH 05/28] phy: Select PHY_EXYNOS_DP_VIDEO " Kishon Vijay Abraham I
2014-03-08 9:29 ` [PATCH 06/28] PHY: Exynos: Add Exynos5250 SATA PHY driver Kishon Vijay Abraham I
2014-03-08 9:29 ` [PATCH 07/28] PHY: sunxi: Add driver for sunxi usb phy Kishon Vijay Abraham I
2014-03-08 9:29 ` [PATCH 08/28] phy: mvebu-sata: prepare new Dove DT Kconfig variable Kishon Vijay Abraham I
2014-03-08 9:29 ` [PATCH 09/28] drivers: phy: usb3/pipe3: Adapt pipe3 driver to Generic PHY Framework Kishon Vijay Abraham I
2014-03-08 9:29 ` [PATCH 10/28] usb: phy: omap-usb2: remove *set_suspend* callback from omap-usb2 Kishon Vijay Abraham I
2014-03-08 9:29 ` [PATCH 11/28] phy: omap-usb2: move omap_usb.h from linux/usb/ to linux/phy/ Kishon Vijay Abraham I
2014-03-08 9:29 ` [PATCH 12/28] phy: core: Add an exported of_phy_get function Kishon Vijay Abraham I
2014-03-08 9:29 ` [PATCH 13/28] phy: core: Add devm_of_phy_get to phy-core Kishon Vijay Abraham I
2014-03-08 9:29 ` [PATCH 14/28] phy: Add new Exynos USB 2.0 PHY driver Kishon Vijay Abraham I
2014-03-08 9:29 ` [PATCH 15/28] phy: Add Exynos 5250 support to the " Kishon Vijay Abraham I
2014-03-08 9:29 ` [PATCH 16/28] phy: omap-usb2: Adapt phy-omap-usb2 for AM437x Kishon Vijay Abraham I
2014-03-08 9:29 ` [PATCH 17/28] phy: omap-usb2: Provide workaround for USB2PHY false disconnect Kishon Vijay Abraham I
2014-03-08 9:29 ` [PATCH 18/28] phy: omap-usb2: Add different compatible for OMAP5 Kishon Vijay Abraham I
2014-03-08 9:29 ` [PATCH 19/28] phy: rename struct omap_control_usb to struct omap_control_phy Kishon Vijay Abraham I
2014-03-08 9:29 ` [PATCH 20/28] phy: omap-control: update dra7 and am437 usb2 bindings Kishon Vijay Abraham I
2014-03-08 9:29 ` [PATCH 21/28] phy: ti-pipe3: cleanup clock handling Kishon Vijay Abraham I
2014-03-08 9:29 ` [PATCH 22/28] phy: ti-pipe3: Add SATA DPLL support Kishon Vijay Abraham I
2014-03-08 9:29 ` [PATCH 23/28] phy: ti-pipe3: Don't get 'wkupclk' and 'refclk' for SATA PHY Kishon Vijay Abraham I
2014-03-08 9:29 ` Kishon Vijay Abraham I [this message]
2014-03-08 9:29 ` [PATCH 25/28] phy: ti-pipe3: Fix suspend/resume and module reload Kishon Vijay Abraham I
2014-03-08 9:29 ` [PATCH 26/28] phy: omap: Depend on OMAP_OCP2SCP bus driver Kishon Vijay Abraham I
2014-03-08 9:29 ` [PATCH 27/28] Documentation: Add APM X-Gene SoC 15Gbps Multi-purpose PHY driver binding documentation Kishon Vijay Abraham I
2014-03-08 9:29 ` [PATCH 28/28] PHY: add APM X-Gene SoC 15Gbps Multi-purpose PHY driver Kishon Vijay Abraham I
2014-03-08 16:42 ` [GIT PULL 00/28] PHY for 3.15 Greg KH
2014-03-09 7:35 ` Kishon Vijay Abraham I
2014-03-09 16:55 ` Greg KH
2014-03-09 7:27 ` [PATCH 16/28 v2] phy: omap-usb2: Adapt phy-omap-usb2 for AM437x Kishon Vijay Abraham I
2014-03-09 7:27 ` [PATCH 17/28 v2] phy: omap-usb2: Provide workaround for USB2PHY false disconnect Kishon Vijay Abraham I
2014-03-09 7:27 ` [PATCH 18/28 v2] phy: omap-usb2: Add different compatible for OMAP5 Kishon Vijay Abraham I
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=1394270969-11851-25-git-send-email-kishon@ti.com \
--to=kishon@ti.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
/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
all inboxes | Powered by JetHome®