From: Andy Gross <agross@codeaurora.org>
To: Josh Cartwright <joshc@codeaurora.org>
Cc: Felipe Balbi <balbi@ti.com>,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
Kishon Vijay Abraham I <kishon@ti.com>,
Jack Pham <jackp@codeaurora.org>,
Kumar Gala <galak@codeaurora.org>,
linux-arm-msm@vger.kernel.org, linux-usb@vger.kernel.org,
"Ivan T. Ivanov" <iivanov@mm-sol.com>,
Bjorn Andersson <bjorn.andersson@sonymobile.com>
Subject: Re: [PATCH v8 3/3] phy: Add Qualcomm DWC3 HS/SS PHY driver
Date: Fri, 12 Sep 2014 13:57:12 -0500 [thread overview]
Message-ID: <20140912185712.GB8756@qualcomm.com> (raw)
In-Reply-To: <20140912175023.GR3749@joshc.qualcomm.com>
On Fri, Sep 12, 2014 at 12:50:23PM -0500, Josh Cartwright wrote:
> Hey Andy-
>
> Mostly cosmetic things below:
>
> On Fri, Sep 12, 2014 at 12:29:46PM -0500, Andy Gross wrote:
> > This patch adds a new driver for the Qualcomm USB 3.0 PHY that exists on some
> > Qualcomm platforms. This driver uses the generic PHY framework and will
> > interact with the DWC3 controller.
> >
> > Signed-off-by: Andy Gross <agross@codeaurora.org>
> > ---
> > drivers/phy/Kconfig | 11 +
> > drivers/phy/Makefile | 1 +
> > drivers/phy/phy-qcom-dwc3.c | 500 +++++++++++++++++++++++++++++++++++++++++++
> > 3 files changed, 512 insertions(+)
> > create mode 100644 drivers/phy/phy-qcom-dwc3.c
> >
> > diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
> > index 0dd7427..5d56161 100644
> > --- a/drivers/phy/Kconfig
> > +++ b/drivers/phy/Kconfig
> > @@ -230,4 +230,15 @@ config PHY_XGENE
> > help
> > This option enables support for APM X-Gene SoC multi-purpose PHY.
> >
> > +config PHY_QCOM_DWC3
> > + tristate "QCOM DWC3 USB PHY support"
> > + depends on ARCH_QCOM
> > + depends on HAS_IOMEM
> > + depends on OF
> > + select GENERIC_PHY
> > + help
> > + This option enables support for the Synopsis PHYs present inside the
> > + Qualcomm USB3.0 DWC3 controller. This driver supports both HS and SS
> > + PHY controllers.
> > +
> > endmenu
> > diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
> > index 95c69ed..aa16f30 100644
> > --- a/drivers/phy/Makefile
> > +++ b/drivers/phy/Makefile
> > @@ -28,3 +28,4 @@ obj-$(CONFIG_PHY_QCOM_IPQ806X_SATA) += phy-qcom-ipq806x-sata.o
> > obj-$(CONFIG_PHY_ST_SPEAR1310_MIPHY) += phy-spear1310-miphy.o
> > obj-$(CONFIG_PHY_ST_SPEAR1340_MIPHY) += phy-spear1340-miphy.o
> > obj-$(CONFIG_PHY_XGENE) += phy-xgene.o
> > +obj-$(CONFIG_PHY_QCOM_DWC3) += phy-qcom-dwc3.o
> > diff --git a/drivers/phy/phy-qcom-dwc3.c b/drivers/phy/phy-qcom-dwc3.c
> > new file mode 100644
> > index 0000000..05b8e1d
> > --- /dev/null
> > +++ b/drivers/phy/phy-qcom-dwc3.c
> [..]
> > +/* TX OVRD DRV LO register bits */
> > +#define TX_OVRD_DRV_LO_AMPLITUDE_MASK 0x007F
> > +#define TX_OVRD_DRV_LO_PREEMPH_MASK 0x3F80
> > +#define TX_OVRD_DRV_LO_PREEMPH_SHIFT 7
> > +#define TX_OVRD_DRV_LO_EN BIT(14)
> > +
> > +struct qcom_dwc3_usb_phy;
>
> Do you need this?
No, this was a set of interim changes that should have been squashed.
Incidently, this was used when I had a separate ops table for the phys.
> > +
> > +enum qcom_dwc3_phy_id {
> > + QCOM_DWC3_PHY_UTMI = 0,
> > + QCOM_DWC3_PHY_PIPE,
> > + QCOM_DWC3_PHYS_NUM,
> > +};
> > +
> > +struct qcom_dwc3_usb_phy {
> > + void __iomem *base;
> > + struct device *dev;
> > + struct phy *phy;
> > + enum qcom_dwc3_phy_id index;
> > +
> > + struct clk *xo_clk;
> > + struct clk *ref_clk;
> > +};
> > +
> > +/**
> > + * Write register and read back masked value to confirm it is written
> > + *
> > + * @base - QCOM DWC3 PHY base virtual address.
> > + * @offset - register offset.
> > + * @mask - register bitmask specifying what should be updated
> > + * @val - value to write.
> > + */
> > +static inline void qcom_dwc3_phy_write_readback(
> > + struct qcom_dwc3_usb_phy *phy_dwc3, u32 offset,
> > + const u32 mask, u32 val)
> > +{
> > + u32 write_val, tmp = readl(phy_dwc3->base + offset);
> > +
> > + tmp &= ~mask; /* retain other bits */
> > + write_val = tmp | val;
> > +
> > + writel(write_val, phy_dwc3->base + offset);
> > +
> > + /* Read back to see if val was written */
> > + tmp = readl(phy_dwc3->base + offset);
> > + tmp &= mask; /* clear other bits */
> > +
> > + if (tmp != val)
> > + dev_err(phy_dwc3->dev, "write: %x to QSCRATCH: %x FAILED\n",
> > + val, offset);
> > +}
> > +
> > +static int wait_for_latch(void __iomem *addr)
> > +{
> > + u32 retry = 10;
> > +
> > + while (true) {
> > + if (!readl(addr))
> > + break;
> > +
> > + if (--retry == 0)
> > + return -ETIMEDOUT;
> > +
> > + usleep_range(10, 20);
> > + }
> > +
> > + return 0;
> > +}
> > +
> > +/**
> > + * Write SSPHY register
> > + *
> > + * @base - QCOM DWC3 PHY base virtual address.
> > + * @addr - SSPHY address to write.
> > + * @val - value to write.
> > + */
> > +static int qcom_dwc3_ss_write_phycreg(void __iomem *base, u32 addr, u32 val)
> > +{
> > + writel(addr, base + CR_PROTOCOL_DATA_IN_REG);
> > + writel(0x1, base + CR_PROTOCOL_CAP_ADDR_REG);
> > +
> > + if (wait_for_latch(base + CR_PROTOCOL_CAP_ADDR_REG))
> > + return 1;
>
> I'm not too familiar with the GENERIC_PHY infrastructure, does it
> understand that '1' is an error case? I'm wondering if you should
> instead propogate the -ETIMEDOUT up.
Actually, yeah I need to return something < 0. Let me respin to fix that.
> > +
> > + writel(val, base + CR_PROTOCOL_DATA_IN_REG);
> > + writel(0x1, base + CR_PROTOCOL_CAP_DATA_REG);
> > +
> > + if (wait_for_latch(base + CR_PROTOCOL_CAP_DATA_REG))
> > + return 1;
> > +
> > + writel(0x1, base + CR_PROTOCOL_WRITE_REG);
> > +
> > + if (wait_for_latch(base + CR_PROTOCOL_WRITE_REG))
> > + return 1;
> > +
> > + return 0;
> > +}
> > +
> [..]
> > +
> > +static struct phy_ops qcom_dwc3_phy_ops = {
> > + .init = qcom_dwc3_phy_init,
> > + .exit = qcom_dwc3_phy_exit,
> > + .power_on = qcom_dwc3_phy_power_on,
> > + .power_off = qcom_dwc3_phy_power_off,
> > + .owner = THIS_MODULE,
> > +};
> > +
> > +static const struct of_device_id qcom_dwc3_phy_table[] = {
> > + {
> > + .compatible = "qcom,dwc3-hs-usb-phy",
> > + .data = (void *)QCOM_DWC3_PHY_UTMI,
> > + },
> > + {
> > + .compatible = "qcom,dwc3-ss-usb-phy",
> > + .data = (void *)QCOM_DWC3_PHY_PIPE,
> > + },
> > + { /* Sentinel */ }
> > +};
> > +MODULE_DEVICE_TABLE(of, qcom_dwc3_phy_table);
>
> I'd suggest just creating a separate ops table, and have '.data' point
> to it. Might cleanup all of the switch() statements above. You could
> also probably drop the 'index' member of 'struct qcom_dwc3_usb_phy', and
> maybe even 'enum qcom_dwc3_phy_id' altogether.
Or just put in two function handlers that I point to in the probe and key off of
the compat.
--
sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
hosted by The Linux Foundation
WARNING: multiple messages have this Message-ID (diff)
From: agross@codeaurora.org (Andy Gross)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v8 3/3] phy: Add Qualcomm DWC3 HS/SS PHY driver
Date: Fri, 12 Sep 2014 13:57:12 -0500 [thread overview]
Message-ID: <20140912185712.GB8756@qualcomm.com> (raw)
In-Reply-To: <20140912175023.GR3749@joshc.qualcomm.com>
On Fri, Sep 12, 2014 at 12:50:23PM -0500, Josh Cartwright wrote:
> Hey Andy-
>
> Mostly cosmetic things below:
>
> On Fri, Sep 12, 2014 at 12:29:46PM -0500, Andy Gross wrote:
> > This patch adds a new driver for the Qualcomm USB 3.0 PHY that exists on some
> > Qualcomm platforms. This driver uses the generic PHY framework and will
> > interact with the DWC3 controller.
> >
> > Signed-off-by: Andy Gross <agross@codeaurora.org>
> > ---
> > drivers/phy/Kconfig | 11 +
> > drivers/phy/Makefile | 1 +
> > drivers/phy/phy-qcom-dwc3.c | 500 +++++++++++++++++++++++++++++++++++++++++++
> > 3 files changed, 512 insertions(+)
> > create mode 100644 drivers/phy/phy-qcom-dwc3.c
> >
> > diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
> > index 0dd7427..5d56161 100644
> > --- a/drivers/phy/Kconfig
> > +++ b/drivers/phy/Kconfig
> > @@ -230,4 +230,15 @@ config PHY_XGENE
> > help
> > This option enables support for APM X-Gene SoC multi-purpose PHY.
> >
> > +config PHY_QCOM_DWC3
> > + tristate "QCOM DWC3 USB PHY support"
> > + depends on ARCH_QCOM
> > + depends on HAS_IOMEM
> > + depends on OF
> > + select GENERIC_PHY
> > + help
> > + This option enables support for the Synopsis PHYs present inside the
> > + Qualcomm USB3.0 DWC3 controller. This driver supports both HS and SS
> > + PHY controllers.
> > +
> > endmenu
> > diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
> > index 95c69ed..aa16f30 100644
> > --- a/drivers/phy/Makefile
> > +++ b/drivers/phy/Makefile
> > @@ -28,3 +28,4 @@ obj-$(CONFIG_PHY_QCOM_IPQ806X_SATA) += phy-qcom-ipq806x-sata.o
> > obj-$(CONFIG_PHY_ST_SPEAR1310_MIPHY) += phy-spear1310-miphy.o
> > obj-$(CONFIG_PHY_ST_SPEAR1340_MIPHY) += phy-spear1340-miphy.o
> > obj-$(CONFIG_PHY_XGENE) += phy-xgene.o
> > +obj-$(CONFIG_PHY_QCOM_DWC3) += phy-qcom-dwc3.o
> > diff --git a/drivers/phy/phy-qcom-dwc3.c b/drivers/phy/phy-qcom-dwc3.c
> > new file mode 100644
> > index 0000000..05b8e1d
> > --- /dev/null
> > +++ b/drivers/phy/phy-qcom-dwc3.c
> [..]
> > +/* TX OVRD DRV LO register bits */
> > +#define TX_OVRD_DRV_LO_AMPLITUDE_MASK 0x007F
> > +#define TX_OVRD_DRV_LO_PREEMPH_MASK 0x3F80
> > +#define TX_OVRD_DRV_LO_PREEMPH_SHIFT 7
> > +#define TX_OVRD_DRV_LO_EN BIT(14)
> > +
> > +struct qcom_dwc3_usb_phy;
>
> Do you need this?
No, this was a set of interim changes that should have been squashed.
Incidently, this was used when I had a separate ops table for the phys.
> > +
> > +enum qcom_dwc3_phy_id {
> > + QCOM_DWC3_PHY_UTMI = 0,
> > + QCOM_DWC3_PHY_PIPE,
> > + QCOM_DWC3_PHYS_NUM,
> > +};
> > +
> > +struct qcom_dwc3_usb_phy {
> > + void __iomem *base;
> > + struct device *dev;
> > + struct phy *phy;
> > + enum qcom_dwc3_phy_id index;
> > +
> > + struct clk *xo_clk;
> > + struct clk *ref_clk;
> > +};
> > +
> > +/**
> > + * Write register and read back masked value to confirm it is written
> > + *
> > + * @base - QCOM DWC3 PHY base virtual address.
> > + * @offset - register offset.
> > + * @mask - register bitmask specifying what should be updated
> > + * @val - value to write.
> > + */
> > +static inline void qcom_dwc3_phy_write_readback(
> > + struct qcom_dwc3_usb_phy *phy_dwc3, u32 offset,
> > + const u32 mask, u32 val)
> > +{
> > + u32 write_val, tmp = readl(phy_dwc3->base + offset);
> > +
> > + tmp &= ~mask; /* retain other bits */
> > + write_val = tmp | val;
> > +
> > + writel(write_val, phy_dwc3->base + offset);
> > +
> > + /* Read back to see if val was written */
> > + tmp = readl(phy_dwc3->base + offset);
> > + tmp &= mask; /* clear other bits */
> > +
> > + if (tmp != val)
> > + dev_err(phy_dwc3->dev, "write: %x to QSCRATCH: %x FAILED\n",
> > + val, offset);
> > +}
> > +
> > +static int wait_for_latch(void __iomem *addr)
> > +{
> > + u32 retry = 10;
> > +
> > + while (true) {
> > + if (!readl(addr))
> > + break;
> > +
> > + if (--retry == 0)
> > + return -ETIMEDOUT;
> > +
> > + usleep_range(10, 20);
> > + }
> > +
> > + return 0;
> > +}
> > +
> > +/**
> > + * Write SSPHY register
> > + *
> > + * @base - QCOM DWC3 PHY base virtual address.
> > + * @addr - SSPHY address to write.
> > + * @val - value to write.
> > + */
> > +static int qcom_dwc3_ss_write_phycreg(void __iomem *base, u32 addr, u32 val)
> > +{
> > + writel(addr, base + CR_PROTOCOL_DATA_IN_REG);
> > + writel(0x1, base + CR_PROTOCOL_CAP_ADDR_REG);
> > +
> > + if (wait_for_latch(base + CR_PROTOCOL_CAP_ADDR_REG))
> > + return 1;
>
> I'm not too familiar with the GENERIC_PHY infrastructure, does it
> understand that '1' is an error case? I'm wondering if you should
> instead propogate the -ETIMEDOUT up.
Actually, yeah I need to return something < 0. Let me respin to fix that.
> > +
> > + writel(val, base + CR_PROTOCOL_DATA_IN_REG);
> > + writel(0x1, base + CR_PROTOCOL_CAP_DATA_REG);
> > +
> > + if (wait_for_latch(base + CR_PROTOCOL_CAP_DATA_REG))
> > + return 1;
> > +
> > + writel(0x1, base + CR_PROTOCOL_WRITE_REG);
> > +
> > + if (wait_for_latch(base + CR_PROTOCOL_WRITE_REG))
> > + return 1;
> > +
> > + return 0;
> > +}
> > +
> [..]
> > +
> > +static struct phy_ops qcom_dwc3_phy_ops = {
> > + .init = qcom_dwc3_phy_init,
> > + .exit = qcom_dwc3_phy_exit,
> > + .power_on = qcom_dwc3_phy_power_on,
> > + .power_off = qcom_dwc3_phy_power_off,
> > + .owner = THIS_MODULE,
> > +};
> > +
> > +static const struct of_device_id qcom_dwc3_phy_table[] = {
> > + {
> > + .compatible = "qcom,dwc3-hs-usb-phy",
> > + .data = (void *)QCOM_DWC3_PHY_UTMI,
> > + },
> > + {
> > + .compatible = "qcom,dwc3-ss-usb-phy",
> > + .data = (void *)QCOM_DWC3_PHY_PIPE,
> > + },
> > + { /* Sentinel */ }
> > +};
> > +MODULE_DEVICE_TABLE(of, qcom_dwc3_phy_table);
>
> I'd suggest just creating a separate ops table, and have '.data' point
> to it. Might cleanup all of the switch() statements above. You could
> also probably drop the 'index' member of 'struct qcom_dwc3_usb_phy', and
> maybe even 'enum qcom_dwc3_phy_id' altogether.
Or just put in two function handlers that I point to in the probe and key off of
the compat.
--
sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
hosted by The Linux Foundation
next prev parent reply other threads:[~2014-09-12 18:57 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-12 17:29 [PATCH v8 0/3] DWC3 USB support for Qualcomm platform Andy Gross
2014-09-12 17:29 ` Andy Gross
2014-09-12 17:29 ` [PATCH v8 1/3] usb: dwc3: qcom: Add device tree binding Andy Gross
2014-09-12 17:29 ` Andy Gross
2014-09-12 17:29 ` Andy Gross
[not found] ` <1410542986-24419-1-git-send-email-agross-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
2014-09-12 17:29 ` [PATCH v8 2/3] usb: dwc3: Add Qualcomm DWC3 glue layer driver Andy Gross
2014-09-12 17:29 ` Andy Gross
2014-09-12 17:29 ` Andy Gross
2014-09-12 17:47 ` Felipe Balbi
2014-09-12 17:47 ` Felipe Balbi
2014-09-12 17:47 ` Felipe Balbi
2014-09-12 18:53 ` Andy Gross
2014-09-12 18:53 ` Andy Gross
2014-09-12 17:29 ` [PATCH v8 3/3] phy: Add Qualcomm DWC3 HS/SS PHY driver Andy Gross
2014-09-12 17:29 ` Andy Gross
[not found] ` <1410542986-24419-4-git-send-email-agross-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
2014-09-12 17:50 ` Josh Cartwright
2014-09-12 17:50 ` Josh Cartwright
2014-09-12 17:50 ` Josh Cartwright
2014-09-12 18:57 ` Andy Gross [this message]
2014-09-12 18:57 ` Andy Gross
2014-09-12 17:50 ` Felipe Balbi
2014-09-12 17:50 ` Felipe Balbi
2014-09-12 17:50 ` Felipe Balbi
2014-09-12 19:03 ` Stephen Boyd
2014-09-12 19:03 ` Stephen Boyd
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=20140912185712.GB8756@qualcomm.com \
--to=agross@codeaurora.org \
--cc=balbi@ti.com \
--cc=bjorn.andersson@sonymobile.com \
--cc=devicetree@vger.kernel.org \
--cc=galak@codeaurora.org \
--cc=iivanov@mm-sol.com \
--cc=jackp@codeaurora.org \
--cc=joshc@codeaurora.org \
--cc=kishon@ti.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.