]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
PHY: Add phy driver for the keystone USB PHY
authorJean-Jacques Hiblot <jjhiblot@ti.com>
Tue, 4 Dec 2018 10:12:59 +0000 (11:12 +0100)
committerMarek Vasut <marex@denx.de>
Fri, 14 Dec 2018 16:59:09 +0000 (17:59 +0100)
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
drivers/phy/Kconfig
drivers/phy/Makefile
drivers/phy/keystone-usb-phy.c [new file with mode: 0644]

index 3921e39d7bce703316c72e96c6e013523cf57d4d..825ee7c3beb315b5c3dcd52145afcc41b5f642e3 100644 (file)
@@ -164,4 +164,14 @@ config OMAP_USB2_PHY
 
          This PHY is found on OMAP devices supporting USB2.
 
+
+config KEYSTONE_USB_PHY
+       bool "Support TI Keystone USB PHY"
+       depends on PHY
+       depends on ARCH_KEYSTONE
+       help
+         Support for the USB PHY found on some Keystone (k2) processors
+
+         This PHY is found on some Keystone (K2) devices supporting USB.
+
 endmenu
index 53dd5bd0f773b790eab2e0130b38537de1c82252..099551d693082596878f52bbc592962e70429fb3 100644 (file)
@@ -18,3 +18,4 @@ 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
 obj-$(CONFIG_OMAP_USB2_PHY) += omap-usb2-phy.o
+obj-$(CONFIG_KEYSTONE_USB_PHY) += keystone-usb-phy.o
diff --git a/drivers/phy/keystone-usb-phy.c b/drivers/phy/keystone-usb-phy.c
new file mode 100644 (file)
index 0000000..e8146ca
--- /dev/null
@@ -0,0 +1,109 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2017 Texas Instruments Incorporated - http://www.ti.com/
+ * Written by Jean-Jacques Hiblot  <jjhiblot@ti.com>
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <dm/device.h>
+#include <generic-phy.h>
+#include <asm/io.h>
+
+/* USB PHY control register offsets */
+#define USB_PHY_CTL_UTMI               0x0000
+#define USB_PHY_CTL_PIPE               0x0004
+#define USB_PHY_CTL_PARAM_1            0x0008
+#define USB_PHY_CTL_PARAM_2            0x000c
+#define USB_PHY_CTL_CLOCK              0x0010
+#define USB_PHY_CTL_PLL                        0x0014
+
+#define PHY_OTG_VBUSVLDECTSEL          BIT(16)
+#define PHY_REF_SSP_EN                 BIT(29)
+
+struct keystone_usb_phy {
+       void __iomem *reg;
+};
+
+static int keystone_usb_init(struct phy *phy)
+{
+       u32 val;
+       struct udevice *dev = phy->dev;
+       struct keystone_usb_phy *keystone = dev_get_priv(dev);
+
+       /*
+        * VBUSVLDEXTSEL has a default value of 1 in BootCfg but shouldn't.
+        * It should always be cleared because our USB PHY has an onchip VBUS
+        * analog comparator.
+        */
+       val = readl(keystone->reg + USB_PHY_CTL_CLOCK);
+       /* quit selecting the vbusvldextsel by default! */
+       val &= ~PHY_OTG_VBUSVLDECTSEL;
+       writel(val, keystone->reg + USB_PHY_CTL_CLOCK);
+
+       return 0;
+}
+
+static int keystone_usb_power_on(struct phy *phy)
+{
+       u32 val;
+       struct udevice *dev = phy->dev;
+       struct keystone_usb_phy *keystone = dev_get_priv(dev);
+
+       val = readl(keystone->reg + USB_PHY_CTL_CLOCK);
+       val |= PHY_REF_SSP_EN;
+       writel(val, keystone->reg + USB_PHY_CTL_CLOCK);
+
+       return 0;
+}
+
+static int keystone_usb_power_off(struct phy *phy)
+{
+       u32 val;
+       struct udevice *dev = phy->dev;
+       struct keystone_usb_phy *keystone = dev_get_priv(dev);
+
+       val = readl(keystone->reg + USB_PHY_CTL_CLOCK);
+       val &= ~PHY_REF_SSP_EN;
+       writel(val, keystone->reg + USB_PHY_CTL_CLOCK);
+
+       return 0;
+}
+
+static int keystone_usb_exit(struct phy *phy)
+{
+       return 0;
+}
+
+static int keystone_usb_phy_probe(struct udevice *dev)
+{
+       struct keystone_usb_phy *keystone = dev_get_priv(dev);
+
+       keystone->reg = dev_remap_addr_index(dev, 0);
+       if (!keystone->reg) {
+               pr_err("unable to remap usb phy\n");
+               return -EINVAL;
+       }
+       return 0;
+}
+
+static const struct udevice_id keystone_usb_phy_ids[] = {
+       { .compatible = "ti,keystone-usbphy" },
+       { }
+};
+
+static struct phy_ops keystone_usb_phy_ops = {
+       .init = keystone_usb_init,
+       .power_on = keystone_usb_power_on,
+       .power_off = keystone_usb_power_off,
+       .exit = keystone_usb_exit,
+};
+
+U_BOOT_DRIVER(keystone_usb_phy) = {
+       .name   = "keystone_usb_phy",
+       .id     = UCLASS_PHY,
+       .of_match = keystone_usb_phy_ids,
+       .ops = &keystone_usb_phy_ops,
+       .probe = keystone_usb_phy_probe,
+       .priv_auto_alloc_size = sizeof(struct keystone_usb_phy),
+};