2018-12-04 10:12:59 +00:00
|
|
|
// 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>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2018-12-04 10:12:59 +00:00
|
|
|
#include <dm/device.h>
|
|
|
|
#include <generic-phy.h>
|
|
|
|
#include <asm/io.h>
|
2019-09-11 09:33:56 +00:00
|
|
|
#include <asm/arch/psc_defs.h>
|
2020-05-10 17:40:13 +00:00
|
|
|
#include <linux/bitops.h>
|
2020-05-10 17:40:11 +00:00
|
|
|
#include <linux/delay.h>
|
2023-09-15 00:21:46 +00:00
|
|
|
#include <linux/printk.h>
|
2018-12-04 10:12:59 +00:00
|
|
|
|
|
|
|
/* 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 {
|
2019-09-11 09:33:56 +00:00
|
|
|
u32 psc_domain;
|
2018-12-04 10:12:59 +00:00
|
|
|
void __iomem *reg;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int keystone_usb_init(struct phy *phy)
|
|
|
|
{
|
|
|
|
u32 val;
|
2019-09-11 09:33:56 +00:00
|
|
|
int rc;
|
2018-12-04 10:12:59 +00:00
|
|
|
struct udevice *dev = phy->dev;
|
|
|
|
struct keystone_usb_phy *keystone = dev_get_priv(dev);
|
|
|
|
|
2019-09-11 09:33:56 +00:00
|
|
|
/* Release USB from reset */
|
|
|
|
rc = psc_enable_module(keystone->psc_domain);
|
|
|
|
if (rc) {
|
|
|
|
debug("Cannot enable USB module");
|
|
|
|
return -rc;
|
|
|
|
}
|
|
|
|
mdelay(10);
|
|
|
|
|
2018-12-04 10:12:59 +00:00
|
|
|
/*
|
|
|
|
* 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)
|
|
|
|
{
|
2019-09-11 09:33:56 +00:00
|
|
|
struct udevice *dev = phy->dev;
|
|
|
|
struct keystone_usb_phy *keystone = dev_get_priv(dev);
|
|
|
|
|
|
|
|
if (psc_disable_module(keystone->psc_domain))
|
|
|
|
debug("failed to disable USB module!\n");
|
|
|
|
|
2018-12-04 10:12:59 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int keystone_usb_phy_probe(struct udevice *dev)
|
|
|
|
{
|
2019-09-11 09:33:56 +00:00
|
|
|
int rc;
|
2018-12-04 10:12:59 +00:00
|
|
|
struct keystone_usb_phy *keystone = dev_get_priv(dev);
|
|
|
|
|
2019-09-11 09:33:56 +00:00
|
|
|
rc = dev_read_u32(dev, "psc-domain", &keystone->psc_domain);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
2018-12-04 10:12:59 +00:00
|
|
|
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,
|
2020-12-03 23:55:17 +00:00
|
|
|
.priv_auto = sizeof(struct keystone_usb_phy),
|
2018-12-04 10:12:59 +00:00
|
|
|
};
|