All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ramon Fried <ramon.fried@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 05/14] phy: db410c: Add MSM USB PHY driver
Date: Fri, 21 Sep 2018 13:35:47 +0300	[thread overview]
Message-ID: <20180921103555.16240-6-ramon.fried@gmail.com> (raw)
In-Reply-To: <20180921103555.16240-1-ramon.fried@gmail.com>

Add a PHY driver for the Qualcomm dragonboard 410c which
allows switching on/off and resetting the phy connected
to the EHCI controllers and USBHS controller.

Signed-off-by: Ramon Fried <ramon.fried@gmail.com>
---

Changes in v2: None

 MAINTAINERS                    |   1 +
 drivers/phy/Kconfig            |   8 +++
 drivers/phy/Makefile           |   1 +
 drivers/phy/msm8916-usbh-phy.c | 109 +++++++++++++++++++++++++++++++++
 4 files changed, 119 insertions(+)
 create mode 100644 drivers/phy/msm8916-usbh-phy.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 39d28e5d45..1a5b543dc7 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -209,6 +209,7 @@ S:	Maintained
 F:	arch/arm/mach-snapdragon/
 F:	drivers/gpio/msm_gpio.c
 F:	drivers/mmc/msm_sdhci.c
+F:	drivers/phy/msm8916-usbh-phy.c
 F:	drivers/serial/serial_msm.c
 F:	drivers/smem/msm_smem.c
 F:	drivers/usb/host/ehci-msm.c
diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
index e0822bb775..bcc8e22795 100644
--- a/drivers/phy/Kconfig
+++ b/drivers/phy/Kconfig
@@ -139,4 +139,12 @@ config MESON_GXL_USB_PHY
 	  This is the generic phy driver for the Amlogic Meson GXL
 	  USB2 and USB3 PHYS.
 
+config MSM8916_USB_PHY
+	bool "Qualcomm MSM8916 USB PHY support"
+	depends on PHY
+	help
+          Support the USB PHY in msm8916
+
+	  This PHY is found on qualcomm dragonboard410c development board.
+
 endmenu
diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
index 178fb4530e..1e1e4ca11e 100644
--- a/drivers/phy/Makefile
+++ b/drivers/phy/Makefile
@@ -15,3 +15,4 @@ obj-$(CONFIG_STI_USB_PHY) += sti_usb_phy.o
 obj-$(CONFIG_PHY_RCAR_GEN2) += phy-rcar-gen2.o
 obj-$(CONFIG_PHY_STM32_USBPHYC) += phy-stm32-usbphyc.o
 obj-$(CONFIG_MESON_GXL_USB_PHY) += meson-gxl-usb2.o meson-gxl-usb3.o
+obj-$(CONFIG_MSM8916_USB_PHY) += msm8916-usbh-phy.o
diff --git a/drivers/phy/msm8916-usbh-phy.c b/drivers/phy/msm8916-usbh-phy.c
new file mode 100644
index 0000000000..2c90738fca
--- /dev/null
+++ b/drivers/phy/msm8916-usbh-phy.c
@@ -0,0 +1,109 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2018 Ramon Fried <ramon.fried@gmail.com>
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <generic-phy.h>
+#include <usb/ehci-ci.h>
+#include <usb/ulpi.h>
+#include <asm/io.h>
+
+/* PHY viewport regs */
+#define ULPI_MISC_A_READ		0x96
+#define ULPI_MISC_A_SET			0x97
+#define ULPI_MISC_A_CLEAR		0x98
+#define ULPI_MISC_A_VBUSVLDEXT		BIT(0)
+#define ULPI_MISC_A_VBUSVLDEXTSEL	BIT(1)
+#define GEN2_SESS_VLD_CTRL_EN		BIT(7)
+#define SESS_VLD_CTRL			BIT(25)
+
+struct msm_phy_priv {
+	void __iomem *regs;
+	struct usb_ehci *ehci; /* Start of IP core*/
+	struct ulpi_viewport ulpi_vp; /* ULPI Viewport */
+};
+
+static int msm_phy_power_on(struct phy *phy)
+{
+	struct msm_phy_priv *priv = dev_get_priv(phy->dev);
+
+	/* Select and enable external configuration with USB PHY */
+	ulpi_write(&priv->ulpi_vp, (u8 *)ULPI_MISC_A_SET,
+		   ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT);
+
+	return 0;
+}
+
+static int msm_phy_power_off(struct phy *phy)
+{
+	struct msm_phy_priv *priv = dev_get_priv(phy->dev);
+
+	/* Disable VBUS mimicing in the controller. */
+	ulpi_write(&priv->ulpi_vp, (u8 *)ULPI_MISC_A_CLEAR,
+		   ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT);
+	return 0;
+}
+
+static int msm_phy_reset(struct phy *phy)
+{
+	struct msm_phy_priv *p = dev_get_priv(phy->dev);
+
+	/* select ULPI phy */
+	writel(PORT_PTS_ULPI, &p->ehci->portsc);
+
+	/* Enable sess_vld */
+	setbits_le32(&p->ehci->genconfig2, GEN2_SESS_VLD_CTRL_EN);
+
+	/* Enable external vbus configuration in the LINK */
+	setbits_le32(&p->ehci->usbcmd, SESS_VLD_CTRL);
+
+	/* USB_OTG_HS_AHB_BURST */
+	writel(0x0, &p->ehci->sbuscfg);
+
+	/* USB_OTG_HS_AHB_MODE: HPROT_MODE */
+	/* Bus access related config. */
+	writel(0x08, &p->ehci->sbusmode);
+
+	return 0;
+}
+
+static int msm_phy_probe(struct udevice *dev)
+{
+	struct msm_phy_priv *priv = dev_get_priv(dev);
+
+	priv->regs = dev_remap_addr(dev);
+	if (!priv->regs)
+		return -EINVAL;
+
+	priv->ehci = (struct usb_ehci *)priv->regs;
+	priv->ulpi_vp.port_num = 0;
+
+	/* Warning: this will not work if viewport address is > 64 bit due to
+	 * ULPI design.
+	 */
+	priv->ulpi_vp.viewport_addr = (phys_addr_t)&priv->ehci->ulpi_viewpoint;
+
+	return 0;
+}
+
+static struct phy_ops msm_phy_ops = {
+	.power_on = msm_phy_power_on,
+	.power_off = msm_phy_power_off,
+	.reset = msm_phy_reset,
+};
+
+static const struct udevice_id msm_phy_ids[] = {
+	{ .compatible = "qcom,apq8016-usbphy" },
+	{ }
+};
+
+U_BOOT_DRIVER(msm8916_usbphy) = {
+	.name		= "msm8916_usbphy",
+	.id		= UCLASS_PHY,
+	.of_match	= msm_phy_ids,
+	.ops		= &msm_phy_ops,
+	.probe		= msm_phy_probe,
+	.priv_auto_alloc_size = sizeof(struct msm_phy_priv),
+};
-- 
2.18.0

  parent reply	other threads:[~2018-09-21 10:35 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-21 10:35 [U-Boot] [PATCH v2 00/14] Introduce fastboot support for dragonboard410c Ramon Fried
2018-09-21 10:35 ` [U-Boot] [PATCH v2 01/14] ehci: Replace board_prepare_usb with board_usb_init Ramon Fried
2018-09-30 19:25   ` [U-Boot] [U-Boot, v2, " Tom Rini
2018-09-21 10:35 ` [U-Boot] [PATCH v2 02/14] ehci: msm: Add missing platdata Ramon Fried
2018-09-30 19:25   ` [U-Boot] [U-Boot,v2,02/14] " Tom Rini
2018-09-21 10:35 ` [U-Boot] [PATCH v2 03/14] dts: db410c: add alias for USB Ramon Fried
2018-09-30 19:25   ` [U-Boot] [U-Boot,v2,03/14] " Tom Rini
2018-09-21 10:35 ` [U-Boot] [PATCH v2 04/14] db410c: serial# env using msm board serial Ramon Fried
2018-09-30 19:25   ` [U-Boot] [U-Boot, v2, " Tom Rini
2018-09-21 10:35 ` Ramon Fried [this message]
2018-09-30 19:25   ` [U-Boot] [U-Boot,v2,05/14] phy: db410c: Add MSM USB PHY driver Tom Rini
2018-09-21 10:35 ` [U-Boot] [PATCH v2 06/14] dts: db410c: Add bindings for MSM USB phy Ramon Fried
2018-09-30 19:25   ` [U-Boot] [U-Boot, v2, " Tom Rini
2018-09-21 10:35 ` [U-Boot] [PATCH v2 07/14] configs: db410c: Enable USB PHY Ramon Fried
2018-09-30 19:25   ` [U-Boot] [U-Boot,v2,07/14] " Tom Rini
2018-09-21 10:35 ` [U-Boot] [PATCH v2 08/14] ehci: msm: switch to generic PHY uclass Ramon Fried
2018-09-30 19:25   ` [U-Boot] [U-Boot, v2, " Tom Rini
2018-09-21 10:35 ` [U-Boot] [PATCH v2 09/14] ehci: msm: use init_type in probe Ramon Fried
2018-09-30 19:25   ` [U-Boot] [U-Boot,v2,09/14] " Tom Rini
2018-09-21 10:35 ` [U-Boot] [PATCH v2 10/14] usb:ci_udc: Introduce init_after_reset phy function Ramon Fried
2018-09-30 19:26   ` [U-Boot] [U-Boot, v2, " Tom Rini
2018-10-01 12:49   ` [U-Boot] [PATCH v2 " Lukasz Majewski
2018-09-21 10:35 ` [U-Boot] [PATCH v2 11/14] usb: ehci-msm: Add init_after_reset for CI_UDC Ramon Fried
2018-09-30 19:26   ` [U-Boot] [U-Boot, v2, " Tom Rini
2018-09-21 10:35 ` [U-Boot] [PATCH v2 12/14] DB410c: Enable fastboot support Ramon Fried
2018-09-30 19:26   ` [U-Boot] [U-Boot,v2,12/14] " Tom Rini
2018-09-21 10:35 ` [U-Boot] [PATCH v2 13/14] db410c: automatically launch fastboot Ramon Fried
2018-09-30 19:26   ` [U-Boot] [U-Boot, v2, " Tom Rini
2018-09-21 10:35 ` [U-Boot] [PATCH v2 14/14] usb:ci_udc: don't overwrite configuration on pullup Ramon Fried
2018-09-30 19:26   ` [U-Boot] [U-Boot, v2, " Tom Rini
2018-10-01 12:50   ` [U-Boot] [PATCH v2 " Lukasz Majewski

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=20180921103555.16240-6-ramon.fried@gmail.com \
    --to=ramon.fried@gmail.com \
    --cc=u-boot@lists.denx.de \
    /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.