2020-09-17 03:42:10 -07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2020-09-17 03:42:05 -07:00
|
|
|
/*
|
|
|
|
* Phy provider for USB 3.1 controller on HiSilicon Kirin970 platform
|
|
|
|
*
|
2020-09-17 03:42:10 -07:00
|
|
|
* Copyright (C) 2017-2020 Hilisicon Electronics Co., Ltd.
|
2020-09-17 03:42:05 -07:00
|
|
|
* http://www.huawei.com
|
|
|
|
*
|
|
|
|
* Authors: Yu Chen <chenyu56@huawei.com>
|
|
|
|
*/
|
|
|
|
|
2021-01-19 03:44:39 -07:00
|
|
|
#include <linux/bitfield.h>
|
2020-09-17 03:42:10 -07:00
|
|
|
#include <linux/clk.h>
|
2020-09-17 03:42:05 -07:00
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/mfd/syscon.h>
|
|
|
|
#include <linux/module.h>
|
2023-07-14 10:48:35 -07:00
|
|
|
#include <linux/of.h>
|
2020-09-17 03:42:05 -07:00
|
|
|
#include <linux/phy/phy.h>
|
2020-09-17 03:42:10 -07:00
|
|
|
#include <linux/platform_device.h>
|
2020-09-17 03:42:05 -07:00
|
|
|
#include <linux/regmap.h>
|
|
|
|
|
|
|
|
#define SCTRL_SCDEEPSLEEPED (0x0)
|
|
|
|
#define USB_CLK_SELECTED BIT(20)
|
|
|
|
|
|
|
|
#define PERI_CRG_PEREN0 (0x00)
|
|
|
|
#define PERI_CRG_PERDIS0 (0x04)
|
|
|
|
#define PERI_CRG_PEREN4 (0x40)
|
|
|
|
#define PERI_CRG_PERDIS4 (0x44)
|
|
|
|
#define PERI_CRG_PERRSTEN4 (0x90)
|
|
|
|
#define PERI_CRG_PERRSTDIS4 (0x94)
|
|
|
|
#define PERI_CRG_ISODIS (0x148)
|
|
|
|
#define PERI_CRG_PEREN6 (0x410)
|
|
|
|
#define PERI_CRG_PERDIS6 (0x414)
|
|
|
|
|
|
|
|
#define USB_REFCLK_ISO_EN BIT(25)
|
|
|
|
|
|
|
|
#define GT_CLK_USB2PHY_REF BIT(19)
|
|
|
|
|
|
|
|
#define PCTRL_PERI_CTRL3 (0x10)
|
|
|
|
#define PCTRL_PERI_CTRL3_MSK_START (16)
|
|
|
|
#define USB_TCXO_EN BIT(1)
|
|
|
|
|
|
|
|
#define PCTRL_PERI_CTRL24 (0x64)
|
|
|
|
#define SC_CLK_USB3PHY_3MUX1_SEL BIT(25)
|
|
|
|
|
|
|
|
#define USB3OTG_CTRL0 (0x00)
|
2021-01-19 03:44:39 -07:00
|
|
|
#define USB3OTG_CTRL3 (0x0c)
|
2020-09-17 03:42:05 -07:00
|
|
|
#define USB3OTG_CTRL4 (0x10)
|
|
|
|
#define USB3OTG_CTRL5 (0x14)
|
2021-01-19 03:44:39 -07:00
|
|
|
#define USB3OTG_CTRL7 (0x1c)
|
2020-09-17 03:42:05 -07:00
|
|
|
#define USB_MISC_CFG50 (0x50)
|
|
|
|
#define USB_MISC_CFG54 (0x54)
|
|
|
|
#define USB_MISC_CFG58 (0x58)
|
2021-01-19 03:44:39 -07:00
|
|
|
#define USB_MISC_CFG5C (0x5c)
|
|
|
|
#define USB_MISC_CFGA0 (0xa0)
|
2020-09-17 03:42:05 -07:00
|
|
|
#define TCA_CLK_RST (0x200)
|
|
|
|
#define TCA_INTR_EN (0x204)
|
|
|
|
#define TCA_INTR_STS (0x208)
|
|
|
|
#define TCA_GCFG (0x210)
|
|
|
|
#define TCA_TCPC (0x214)
|
2020-09-17 03:42:07 -07:00
|
|
|
#define TCA_SYSMODE_CFG (0x218)
|
2020-09-17 03:42:05 -07:00
|
|
|
#define TCA_VBUS_CTRL (0x240)
|
|
|
|
|
|
|
|
#define CTRL0_USB3_VBUSVLD BIT(7)
|
|
|
|
#define CTRL0_USB3_VBUSVLD_SEL BIT(6)
|
|
|
|
|
|
|
|
#define CTRL3_USB2_VBUSVLDEXT0 BIT(6)
|
|
|
|
#define CTRL3_USB2_VBUSVLDEXTSEL0 BIT(5)
|
|
|
|
|
|
|
|
#define CTRL5_USB2_SIDDQ BIT(0)
|
|
|
|
|
2021-01-19 03:44:39 -07:00
|
|
|
#define CTRL7_USB2_REFCLKSEL_MASK GENMASK(4, 3)
|
|
|
|
#define CTRL7_USB2_REFCLKSEL_ABB (BIT(4) | BIT(3))
|
|
|
|
#define CTRL7_USB2_REFCLKSEL_PAD BIT(4)
|
2020-09-17 03:42:05 -07:00
|
|
|
|
|
|
|
#define CFG50_USB3_PHY_TEST_POWERDOWN BIT(23)
|
|
|
|
|
2021-01-19 03:44:39 -07:00
|
|
|
#define CFG54_USB31PHY_CR_ADDR_MASK GENMASK(31, 16)
|
|
|
|
|
2020-09-17 03:42:05 -07:00
|
|
|
#define CFG54_USB3PHY_REF_USE_PAD BIT(12)
|
|
|
|
#define CFG54_PHY0_PMA_PWR_STABLE BIT(11)
|
|
|
|
#define CFG54_PHY0_PCS_PWR_STABLE BIT(9)
|
|
|
|
#define CFG54_USB31PHY_CR_ACK BIT(7)
|
|
|
|
#define CFG54_USB31PHY_CR_WR_EN BIT(5)
|
|
|
|
#define CFG54_USB31PHY_CR_SEL BIT(4)
|
|
|
|
#define CFG54_USB31PHY_CR_RD_EN BIT(3)
|
|
|
|
#define CFG54_USB31PHY_CR_CLK BIT(2)
|
|
|
|
#define CFG54_USB3_PHY0_ANA_PWR_EN BIT(1)
|
|
|
|
|
2021-01-19 03:44:39 -07:00
|
|
|
#define CFG58_USB31PHY_CR_DATA_MASK GENMASK(31, 16)
|
2020-09-17 03:42:05 -07:00
|
|
|
|
|
|
|
#define CFG5C_USB3_PHY0_SS_MPLLA_SSC_EN BIT(1)
|
|
|
|
|
|
|
|
#define CFGA0_VAUX_RESET BIT(9)
|
|
|
|
#define CFGA0_USB31C_RESET BIT(8)
|
|
|
|
#define CFGA0_USB2PHY_REFCLK_SELECT BIT(4)
|
|
|
|
#define CFGA0_USB3PHY_RESET BIT(1)
|
|
|
|
#define CFGA0_USB2PHY_POR BIT(0)
|
|
|
|
|
|
|
|
#define INTR_EN_XA_TIMEOUT_EVT_EN BIT(1)
|
|
|
|
#define INTR_EN_XA_ACK_EVT_EN BIT(0)
|
|
|
|
|
|
|
|
#define CLK_RST_TCA_REF_CLK_EN BIT(1)
|
|
|
|
#define CLK_RST_SUSPEND_CLK_EN BIT(0)
|
|
|
|
|
|
|
|
#define GCFG_ROLE_HSTDEV BIT(4)
|
2021-01-19 03:44:39 -07:00
|
|
|
#define GCFG_OP_MODE GENMASK(1, 0)
|
2020-09-17 03:42:07 -07:00
|
|
|
#define GCFG_OP_MODE_CTRL_SYNC_MODE BIT(0)
|
2020-09-17 03:42:05 -07:00
|
|
|
|
|
|
|
#define TCPC_VALID BIT(4)
|
|
|
|
#define TCPC_LOW_POWER_EN BIT(3)
|
2021-01-19 03:44:39 -07:00
|
|
|
#define TCPC_MUX_CONTROL_MASK GENMASK(1, 0)
|
2020-09-17 03:42:10 -07:00
|
|
|
#define TCPC_MUX_CONTROL_USB31 BIT(0)
|
2020-09-17 03:42:05 -07:00
|
|
|
|
2020-09-17 03:42:07 -07:00
|
|
|
#define SYSMODE_CFG_TYPEC_DISABLE BIT(3)
|
|
|
|
|
2021-01-19 03:44:39 -07:00
|
|
|
#define VBUS_CTRL_POWERPRESENT_OVERRD GENMASK(3, 2)
|
|
|
|
#define VBUS_CTRL_VBUSVALID_OVERRD GENMASK(1, 0)
|
2020-09-17 03:42:05 -07:00
|
|
|
|
2021-01-19 03:44:39 -07:00
|
|
|
#define KIRIN970_USB_DEFAULT_PHY_PARAM (0xfdfee4)
|
2020-09-17 03:42:05 -07:00
|
|
|
#define KIRIN970_USB_DEFAULT_PHY_VBOOST (0x5)
|
|
|
|
|
|
|
|
#define TX_VBOOST_LVL_REG (0xf)
|
|
|
|
#define TX_VBOOST_LVL_START (6)
|
|
|
|
#define TX_VBOOST_LVL_ENABLE BIT(9)
|
|
|
|
|
2020-09-17 03:42:08 -07:00
|
|
|
struct hi3670_priv {
|
2020-09-17 03:42:05 -07:00
|
|
|
struct device *dev;
|
|
|
|
struct regmap *peri_crg;
|
|
|
|
struct regmap *pctrl;
|
|
|
|
struct regmap *sctrl;
|
|
|
|
struct regmap *usb31misc;
|
|
|
|
|
|
|
|
u32 eye_diagram_param;
|
|
|
|
u32 tx_vboost_lvl;
|
|
|
|
|
|
|
|
u32 peri_crg_offset;
|
|
|
|
u32 pctrl_offset;
|
|
|
|
u32 usb31misc_offset;
|
|
|
|
};
|
|
|
|
|
2020-09-17 03:42:08 -07:00
|
|
|
static int hi3670_phy_cr_clk(struct regmap *usb31misc)
|
2020-09-17 03:42:05 -07:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Clock up */
|
|
|
|
ret = regmap_update_bits(usb31misc, USB_MISC_CFG54,
|
2020-09-17 03:42:10 -07:00
|
|
|
CFG54_USB31PHY_CR_CLK, CFG54_USB31PHY_CR_CLK);
|
2020-09-17 03:42:05 -07:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* Clock down */
|
2021-06-24 07:01:30 -07:00
|
|
|
return regmap_update_bits(usb31misc, USB_MISC_CFG54,
|
|
|
|
CFG54_USB31PHY_CR_CLK, 0);
|
2020-09-17 03:42:05 -07:00
|
|
|
}
|
|
|
|
|
2020-09-17 03:42:08 -07:00
|
|
|
static int hi3670_phy_cr_set_sel(struct regmap *usb31misc)
|
2020-09-17 03:42:05 -07:00
|
|
|
{
|
|
|
|
return regmap_update_bits(usb31misc, USB_MISC_CFG54,
|
2020-09-17 03:42:10 -07:00
|
|
|
CFG54_USB31PHY_CR_SEL, CFG54_USB31PHY_CR_SEL);
|
2020-09-17 03:42:05 -07:00
|
|
|
}
|
|
|
|
|
2020-09-17 03:42:08 -07:00
|
|
|
static int hi3670_phy_cr_start(struct regmap *usb31misc, int direction)
|
2020-09-17 03:42:05 -07:00
|
|
|
{
|
2021-01-19 03:44:39 -07:00
|
|
|
int ret, reg;
|
2020-09-17 03:42:05 -07:00
|
|
|
|
|
|
|
if (direction)
|
2021-01-19 03:44:39 -07:00
|
|
|
reg = CFG54_USB31PHY_CR_WR_EN;
|
2020-09-17 03:42:05 -07:00
|
|
|
else
|
2021-01-19 03:44:39 -07:00
|
|
|
reg = CFG54_USB31PHY_CR_RD_EN;
|
|
|
|
|
|
|
|
ret = regmap_update_bits(usb31misc, USB_MISC_CFG54, reg, reg);
|
2020-09-17 03:42:05 -07:00
|
|
|
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2020-09-17 03:42:08 -07:00
|
|
|
ret = hi3670_phy_cr_clk(usb31misc);
|
2020-09-17 03:42:05 -07:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2021-01-19 03:44:39 -07:00
|
|
|
return regmap_update_bits(usb31misc, USB_MISC_CFG54,
|
|
|
|
CFG54_USB31PHY_CR_RD_EN | CFG54_USB31PHY_CR_WR_EN, 0);
|
2020-09-17 03:42:05 -07:00
|
|
|
}
|
|
|
|
|
2020-09-17 03:42:08 -07:00
|
|
|
static int hi3670_phy_cr_wait_ack(struct regmap *usb31misc)
|
2020-09-17 03:42:05 -07:00
|
|
|
{
|
|
|
|
u32 reg;
|
2021-01-19 03:44:40 -07:00
|
|
|
int retry = 10;
|
2020-09-17 03:42:05 -07:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
while (retry-- > 0) {
|
|
|
|
ret = regmap_read(usb31misc, USB_MISC_CFG54, ®);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
if ((reg & CFG54_USB31PHY_CR_ACK) == CFG54_USB31PHY_CR_ACK)
|
|
|
|
return 0;
|
|
|
|
|
2020-09-17 03:42:08 -07:00
|
|
|
ret = hi3670_phy_cr_clk(usb31misc);
|
2020-09-17 03:42:05 -07:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
2021-01-19 03:44:40 -07:00
|
|
|
|
|
|
|
usleep_range(10, 20);
|
2020-09-17 03:42:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return -ETIMEDOUT;
|
|
|
|
}
|
|
|
|
|
2020-09-17 03:42:08 -07:00
|
|
|
static int hi3670_phy_cr_set_addr(struct regmap *usb31misc, u32 addr)
|
2020-09-17 03:42:05 -07:00
|
|
|
{
|
|
|
|
u32 reg;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = regmap_read(usb31misc, USB_MISC_CFG54, ®);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2021-01-19 03:44:39 -07:00
|
|
|
reg = FIELD_PREP(CFG54_USB31PHY_CR_ADDR_MASK, addr);
|
2020-09-17 03:42:05 -07:00
|
|
|
|
2021-06-24 07:01:30 -07:00
|
|
|
return regmap_update_bits(usb31misc, USB_MISC_CFG54,
|
|
|
|
CFG54_USB31PHY_CR_ADDR_MASK, reg);
|
2020-09-17 03:42:05 -07:00
|
|
|
}
|
|
|
|
|
2020-09-17 03:42:08 -07:00
|
|
|
static int hi3670_phy_cr_read(struct regmap *usb31misc, u32 addr, u32 *val)
|
2020-09-17 03:42:05 -07:00
|
|
|
{
|
2021-06-24 07:01:30 -07:00
|
|
|
int reg, i, ret;
|
2020-09-17 03:42:05 -07:00
|
|
|
|
|
|
|
for (i = 0; i < 100; i++) {
|
2020-09-17 03:42:08 -07:00
|
|
|
ret = hi3670_phy_cr_clk(usb31misc);
|
2020-09-17 03:42:05 -07:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-09-17 03:42:08 -07:00
|
|
|
ret = hi3670_phy_cr_set_sel(usb31misc);
|
2020-09-17 03:42:05 -07:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2020-09-17 03:42:08 -07:00
|
|
|
ret = hi3670_phy_cr_set_addr(usb31misc, addr);
|
2020-09-17 03:42:05 -07:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2020-09-17 03:42:08 -07:00
|
|
|
ret = hi3670_phy_cr_start(usb31misc, 0);
|
2020-09-17 03:42:05 -07:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2020-09-17 03:42:08 -07:00
|
|
|
ret = hi3670_phy_cr_wait_ack(usb31misc);
|
2020-09-17 03:42:05 -07:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = regmap_read(usb31misc, USB_MISC_CFG58, ®);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2021-01-19 03:44:39 -07:00
|
|
|
*val = FIELD_GET(CFG58_USB31PHY_CR_DATA_MASK, reg);
|
2020-09-17 03:42:05 -07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-09-17 03:42:08 -07:00
|
|
|
static int hi3670_phy_cr_write(struct regmap *usb31misc, u32 addr, u32 val)
|
2020-09-17 03:42:05 -07:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
for (i = 0; i < 100; i++) {
|
2020-09-17 03:42:08 -07:00
|
|
|
ret = hi3670_phy_cr_clk(usb31misc);
|
2020-09-17 03:42:05 -07:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-09-17 03:42:08 -07:00
|
|
|
ret = hi3670_phy_cr_set_sel(usb31misc);
|
2020-09-17 03:42:05 -07:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2020-09-17 03:42:08 -07:00
|
|
|
ret = hi3670_phy_cr_set_addr(usb31misc, addr);
|
2020-09-17 03:42:05 -07:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = regmap_write(usb31misc, USB_MISC_CFG58,
|
2021-01-19 03:44:39 -07:00
|
|
|
FIELD_PREP(CFG58_USB31PHY_CR_DATA_MASK, val));
|
2020-09-17 03:42:05 -07:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2020-09-17 03:42:08 -07:00
|
|
|
ret = hi3670_phy_cr_start(usb31misc, 1);
|
2020-09-17 03:42:05 -07:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2021-06-24 07:01:30 -07:00
|
|
|
return hi3670_phy_cr_wait_ack(usb31misc);
|
2020-09-17 03:42:05 -07:00
|
|
|
}
|
|
|
|
|
2020-09-17 03:42:08 -07:00
|
|
|
static int hi3670_phy_set_params(struct hi3670_priv *priv)
|
2020-09-17 03:42:05 -07:00
|
|
|
{
|
|
|
|
u32 reg;
|
|
|
|
int ret;
|
|
|
|
int retry = 3;
|
|
|
|
|
|
|
|
ret = regmap_write(priv->usb31misc, USB3OTG_CTRL4,
|
2020-09-17 03:42:10 -07:00
|
|
|
priv->eye_diagram_param);
|
2020-09-17 03:42:05 -07:00
|
|
|
if (ret) {
|
|
|
|
dev_err(priv->dev, "set USB3OTG_CTRL4 failed\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (retry-- > 0) {
|
2020-09-17 03:42:08 -07:00
|
|
|
ret = hi3670_phy_cr_read(priv->usb31misc,
|
2020-09-17 03:42:10 -07:00
|
|
|
TX_VBOOST_LVL_REG, ®);
|
2020-09-17 03:42:05 -07:00
|
|
|
if (!ret)
|
|
|
|
break;
|
2020-09-17 03:42:10 -07:00
|
|
|
|
|
|
|
if (ret != -ETIMEDOUT) {
|
2020-09-17 03:42:05 -07:00
|
|
|
dev_err(priv->dev, "read TX_VBOOST_LVL_REG failed\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2020-09-17 03:42:10 -07:00
|
|
|
reg |= (TX_VBOOST_LVL_ENABLE | (priv->tx_vboost_lvl << TX_VBOOST_LVL_START));
|
2020-09-17 03:42:08 -07:00
|
|
|
ret = hi3670_phy_cr_write(priv->usb31misc, TX_VBOOST_LVL_REG, reg);
|
2020-09-17 03:42:05 -07:00
|
|
|
if (ret)
|
|
|
|
dev_err(priv->dev, "write TX_VBOOST_LVL_REG failed\n");
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-01-19 03:44:41 -07:00
|
|
|
static bool hi3670_is_abbclk_selected(struct hi3670_priv *priv)
|
2020-09-17 03:42:05 -07:00
|
|
|
{
|
|
|
|
u32 reg;
|
|
|
|
|
|
|
|
if (!priv->sctrl) {
|
|
|
|
dev_err(priv->dev, "priv->sctrl is null!\n");
|
2021-01-19 03:44:41 -07:00
|
|
|
return false;
|
2020-09-17 03:42:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (regmap_read(priv->sctrl, SCTRL_SCDEEPSLEEPED, ®)) {
|
|
|
|
dev_err(priv->dev, "SCTRL_SCDEEPSLEEPED read failed!\n");
|
2021-01-19 03:44:41 -07:00
|
|
|
return false;
|
2020-09-17 03:42:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((reg & USB_CLK_SELECTED) == 0)
|
2021-01-19 03:44:41 -07:00
|
|
|
return false;
|
2020-09-17 03:42:05 -07:00
|
|
|
|
2021-01-19 03:44:41 -07:00
|
|
|
return true;
|
2020-09-17 03:42:05 -07:00
|
|
|
}
|
|
|
|
|
2020-09-17 03:42:08 -07:00
|
|
|
static int hi3670_config_phy_clock(struct hi3670_priv *priv)
|
2020-09-17 03:42:05 -07:00
|
|
|
{
|
|
|
|
u32 val, mask;
|
|
|
|
int ret;
|
|
|
|
|
2021-01-19 03:44:41 -07:00
|
|
|
if (!hi3670_is_abbclk_selected(priv)) {
|
2020-09-17 03:42:05 -07:00
|
|
|
/* usb refclk iso disable */
|
|
|
|
ret = regmap_write(priv->peri_crg, PERI_CRG_ISODIS,
|
2020-09-17 03:42:10 -07:00
|
|
|
USB_REFCLK_ISO_EN);
|
2020-09-17 03:42:05 -07:00
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
|
2020-09-17 03:42:07 -07:00
|
|
|
/* enable usb_tcxo_en */
|
|
|
|
ret = regmap_write(priv->pctrl, PCTRL_PERI_CTRL3,
|
2020-09-17 03:42:10 -07:00
|
|
|
USB_TCXO_EN |
|
|
|
|
(USB_TCXO_EN << PCTRL_PERI_CTRL3_MSK_START));
|
2020-09-17 03:42:07 -07:00
|
|
|
|
2020-09-17 03:42:05 -07:00
|
|
|
/* select usbphy clk from abb */
|
|
|
|
mask = SC_CLK_USB3PHY_3MUX1_SEL;
|
|
|
|
ret = regmap_update_bits(priv->pctrl,
|
2020-09-17 03:42:10 -07:00
|
|
|
PCTRL_PERI_CTRL24, mask, 0);
|
2020-09-17 03:42:05 -07:00
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
ret = regmap_update_bits(priv->usb31misc, USB_MISC_CFGA0,
|
2020-09-17 03:42:10 -07:00
|
|
|
CFGA0_USB2PHY_REFCLK_SELECT, 0);
|
2020-09-17 03:42:05 -07:00
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
ret = regmap_read(priv->usb31misc, USB3OTG_CTRL7, &val);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
val &= ~CTRL7_USB2_REFCLKSEL_MASK;
|
|
|
|
val |= CTRL7_USB2_REFCLKSEL_ABB;
|
|
|
|
ret = regmap_write(priv->usb31misc, USB3OTG_CTRL7, val);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
|
2020-09-17 03:42:10 -07:00
|
|
|
return 0;
|
|
|
|
}
|
2020-09-17 03:42:05 -07:00
|
|
|
|
2020-09-17 03:42:10 -07:00
|
|
|
ret = regmap_update_bits(priv->usb31misc, USB_MISC_CFG54,
|
|
|
|
CFG54_USB3PHY_REF_USE_PAD,
|
|
|
|
CFG54_USB3PHY_REF_USE_PAD);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
2020-09-17 03:42:05 -07:00
|
|
|
|
2020-09-17 03:42:10 -07:00
|
|
|
ret = regmap_update_bits(priv->usb31misc, USB_MISC_CFGA0,
|
|
|
|
CFGA0_USB2PHY_REFCLK_SELECT,
|
|
|
|
CFGA0_USB2PHY_REFCLK_SELECT);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
ret = regmap_read(priv->usb31misc, USB3OTG_CTRL7, &val);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
val &= ~CTRL7_USB2_REFCLKSEL_MASK;
|
|
|
|
val |= CTRL7_USB2_REFCLKSEL_PAD;
|
|
|
|
ret = regmap_write(priv->usb31misc, USB3OTG_CTRL7, val);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
ret = regmap_write(priv->peri_crg,
|
|
|
|
PERI_CRG_PEREN6, GT_CLK_USB2PHY_REF);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
2020-09-17 03:42:05 -07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
out:
|
|
|
|
dev_err(priv->dev, "failed to config phy clock ret: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-09-17 03:42:08 -07:00
|
|
|
static int hi3670_config_tca(struct hi3670_priv *priv)
|
2020-09-17 03:42:05 -07:00
|
|
|
{
|
|
|
|
u32 val, mask;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = regmap_write(priv->usb31misc, TCA_INTR_STS, 0xffff);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
ret = regmap_write(priv->usb31misc, TCA_INTR_EN,
|
2020-09-17 03:42:10 -07:00
|
|
|
INTR_EN_XA_TIMEOUT_EVT_EN | INTR_EN_XA_ACK_EVT_EN);
|
2020-09-17 03:42:05 -07:00
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
mask = CLK_RST_TCA_REF_CLK_EN | CLK_RST_SUSPEND_CLK_EN;
|
|
|
|
ret = regmap_update_bits(priv->usb31misc, TCA_CLK_RST, mask, 0);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
ret = regmap_update_bits(priv->usb31misc, TCA_GCFG,
|
2020-09-17 03:42:10 -07:00
|
|
|
GCFG_ROLE_HSTDEV | GCFG_OP_MODE,
|
|
|
|
GCFG_ROLE_HSTDEV | GCFG_OP_MODE_CTRL_SYNC_MODE);
|
2020-09-17 03:42:07 -07:00
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
ret = regmap_update_bits(priv->usb31misc, TCA_SYSMODE_CFG,
|
2020-09-17 03:42:10 -07:00
|
|
|
SYSMODE_CFG_TYPEC_DISABLE, 0);
|
2020-09-17 03:42:05 -07:00
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
ret = regmap_read(priv->usb31misc, TCA_TCPC, &val);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
val &= ~(TCPC_VALID | TCPC_LOW_POWER_EN | TCPC_MUX_CONTROL_MASK);
|
|
|
|
val |= (TCPC_VALID | TCPC_MUX_CONTROL_USB31);
|
|
|
|
ret = regmap_write(priv->usb31misc, TCA_TCPC, val);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
ret = regmap_write(priv->usb31misc, TCA_VBUS_CTRL,
|
2020-09-17 03:42:10 -07:00
|
|
|
VBUS_CTRL_POWERPRESENT_OVERRD | VBUS_CTRL_VBUSVALID_OVERRD);
|
2020-09-17 03:42:05 -07:00
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
out:
|
|
|
|
dev_err(priv->dev, "failed to config phy clock ret: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-09-17 03:42:08 -07:00
|
|
|
static int hi3670_phy_init(struct phy *phy)
|
2020-09-17 03:42:05 -07:00
|
|
|
{
|
2020-09-17 03:42:08 -07:00
|
|
|
struct hi3670_priv *priv = phy_get_drvdata(phy);
|
2020-09-17 03:42:05 -07:00
|
|
|
u32 val;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* assert controller */
|
2020-09-17 03:42:07 -07:00
|
|
|
val = CFGA0_VAUX_RESET | CFGA0_USB31C_RESET |
|
2020-09-17 03:42:10 -07:00
|
|
|
CFGA0_USB3PHY_RESET | CFGA0_USB2PHY_POR;
|
2020-09-17 03:42:05 -07:00
|
|
|
ret = regmap_update_bits(priv->usb31misc, USB_MISC_CFGA0, val, 0);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
|
2020-09-17 03:42:08 -07:00
|
|
|
ret = hi3670_config_phy_clock(priv);
|
2020-09-17 03:42:05 -07:00
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* Exit from IDDQ mode */
|
|
|
|
ret = regmap_update_bits(priv->usb31misc, USB3OTG_CTRL5,
|
2020-09-17 03:42:10 -07:00
|
|
|
CTRL5_USB2_SIDDQ, 0);
|
2020-09-17 03:42:05 -07:00
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* Release USB31 PHY out of TestPowerDown mode */
|
|
|
|
ret = regmap_update_bits(priv->usb31misc, USB_MISC_CFG50,
|
2020-09-17 03:42:10 -07:00
|
|
|
CFG50_USB3_PHY_TEST_POWERDOWN, 0);
|
2020-09-17 03:42:05 -07:00
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
|
2020-09-17 03:42:07 -07:00
|
|
|
/* Deassert phy */
|
|
|
|
val = CFGA0_USB3PHY_RESET | CFGA0_USB2PHY_POR;
|
|
|
|
ret = regmap_update_bits(priv->usb31misc, USB_MISC_CFGA0, val, val);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
|
2020-09-17 03:42:10 -07:00
|
|
|
usleep_range(100, 120);
|
2020-09-17 03:42:07 -07:00
|
|
|
|
2020-09-17 03:42:05 -07:00
|
|
|
/* Tell the PHY power is stable */
|
|
|
|
val = CFG54_USB3_PHY0_ANA_PWR_EN | CFG54_PHY0_PCS_PWR_STABLE |
|
2020-09-17 03:42:10 -07:00
|
|
|
CFG54_PHY0_PMA_PWR_STABLE;
|
2020-09-17 03:42:05 -07:00
|
|
|
ret = regmap_update_bits(priv->usb31misc, USB_MISC_CFG54,
|
2020-09-17 03:42:10 -07:00
|
|
|
val, val);
|
2020-09-17 03:42:05 -07:00
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
|
2020-09-17 03:42:08 -07:00
|
|
|
ret = hi3670_config_tca(priv);
|
2020-09-17 03:42:05 -07:00
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* Enable SSC */
|
|
|
|
ret = regmap_update_bits(priv->usb31misc, USB_MISC_CFG5C,
|
2020-09-17 03:42:10 -07:00
|
|
|
CFG5C_USB3_PHY0_SS_MPLLA_SSC_EN,
|
|
|
|
CFG5C_USB3_PHY0_SS_MPLLA_SSC_EN);
|
2020-09-17 03:42:05 -07:00
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* Deassert controller */
|
|
|
|
val = CFGA0_VAUX_RESET | CFGA0_USB31C_RESET;
|
|
|
|
ret = regmap_update_bits(priv->usb31misc, USB_MISC_CFGA0, val, val);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
|
2020-09-17 03:42:10 -07:00
|
|
|
usleep_range(100, 120);
|
2020-09-17 03:42:05 -07:00
|
|
|
|
|
|
|
/* Set fake vbus valid signal */
|
|
|
|
val = CTRL0_USB3_VBUSVLD | CTRL0_USB3_VBUSVLD_SEL;
|
|
|
|
ret = regmap_update_bits(priv->usb31misc, USB3OTG_CTRL0, val, val);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
val = CTRL3_USB2_VBUSVLDEXT0 | CTRL3_USB2_VBUSVLDEXTSEL0;
|
|
|
|
ret = regmap_update_bits(priv->usb31misc, USB3OTG_CTRL3, val, val);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
|
2020-09-17 03:42:10 -07:00
|
|
|
usleep_range(100, 120);
|
2020-09-17 03:42:05 -07:00
|
|
|
|
2020-09-17 03:42:08 -07:00
|
|
|
ret = hi3670_phy_set_params(priv);
|
2020-09-17 03:42:05 -07:00
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
out:
|
|
|
|
dev_err(priv->dev, "failed to init phy ret: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-09-17 03:42:08 -07:00
|
|
|
static int hi3670_phy_exit(struct phy *phy)
|
2020-09-17 03:42:05 -07:00
|
|
|
{
|
2020-09-17 03:42:08 -07:00
|
|
|
struct hi3670_priv *priv = phy_get_drvdata(phy);
|
2020-09-17 03:42:05 -07:00
|
|
|
u32 mask;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Assert phy */
|
|
|
|
mask = CFGA0_USB3PHY_RESET | CFGA0_USB2PHY_POR;
|
|
|
|
ret = regmap_update_bits(priv->usb31misc, USB_MISC_CFGA0, mask, 0);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
|
2021-01-19 03:44:41 -07:00
|
|
|
if (!hi3670_is_abbclk_selected(priv)) {
|
2020-09-17 03:42:07 -07:00
|
|
|
/* disable usb_tcxo_en */
|
|
|
|
ret = regmap_write(priv->pctrl, PCTRL_PERI_CTRL3,
|
2020-09-17 03:42:10 -07:00
|
|
|
USB_TCXO_EN << PCTRL_PERI_CTRL3_MSK_START);
|
2020-09-17 03:42:07 -07:00
|
|
|
} else {
|
2020-09-17 03:42:05 -07:00
|
|
|
ret = regmap_write(priv->peri_crg, PERI_CRG_PERDIS6,
|
2020-09-17 03:42:10 -07:00
|
|
|
GT_CLK_USB2PHY_REF);
|
2020-09-17 03:42:05 -07:00
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
out:
|
|
|
|
dev_err(priv->dev, "failed to exit phy ret: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-02-09 01:19:36 -07:00
|
|
|
static const struct phy_ops hi3670_phy_ops = {
|
2020-09-17 03:42:08 -07:00
|
|
|
.init = hi3670_phy_init,
|
|
|
|
.exit = hi3670_phy_exit,
|
2020-09-17 03:42:05 -07:00
|
|
|
.owner = THIS_MODULE,
|
|
|
|
};
|
|
|
|
|
2020-09-17 03:42:08 -07:00
|
|
|
static int hi3670_phy_probe(struct platform_device *pdev)
|
2020-09-17 03:42:05 -07:00
|
|
|
{
|
|
|
|
struct phy_provider *phy_provider;
|
|
|
|
struct device *dev = &pdev->dev;
|
|
|
|
struct phy *phy;
|
2020-09-17 03:42:08 -07:00
|
|
|
struct hi3670_priv *priv;
|
2020-09-17 03:42:05 -07:00
|
|
|
|
|
|
|
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
|
|
|
|
if (!priv)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
priv->dev = dev;
|
|
|
|
priv->peri_crg = syscon_regmap_lookup_by_phandle(dev->of_node,
|
2020-09-17 03:42:10 -07:00
|
|
|
"hisilicon,pericrg-syscon");
|
2020-09-17 03:42:05 -07:00
|
|
|
if (IS_ERR(priv->peri_crg)) {
|
|
|
|
dev_err(dev, "no hisilicon,pericrg-syscon\n");
|
|
|
|
return PTR_ERR(priv->peri_crg);
|
|
|
|
}
|
|
|
|
|
|
|
|
priv->pctrl = syscon_regmap_lookup_by_phandle(dev->of_node,
|
2020-09-17 03:42:10 -07:00
|
|
|
"hisilicon,pctrl-syscon");
|
2020-09-17 03:42:05 -07:00
|
|
|
if (IS_ERR(priv->pctrl)) {
|
|
|
|
dev_err(dev, "no hisilicon,pctrl-syscon\n");
|
|
|
|
return PTR_ERR(priv->pctrl);
|
|
|
|
}
|
|
|
|
|
|
|
|
priv->sctrl = syscon_regmap_lookup_by_phandle(dev->of_node,
|
2020-09-17 03:42:10 -07:00
|
|
|
"hisilicon,sctrl-syscon");
|
2020-09-17 03:42:05 -07:00
|
|
|
if (IS_ERR(priv->sctrl)) {
|
|
|
|
dev_err(dev, "no hisilicon,sctrl-syscon\n");
|
|
|
|
return PTR_ERR(priv->sctrl);
|
|
|
|
}
|
|
|
|
|
2020-09-17 03:42:11 -07:00
|
|
|
/* node of hi3670 phy is a sub-node of usb3_otg_bc */
|
|
|
|
priv->usb31misc = syscon_node_to_regmap(dev->parent->of_node);
|
2020-09-17 03:42:05 -07:00
|
|
|
if (IS_ERR(priv->usb31misc)) {
|
2020-09-17 03:42:11 -07:00
|
|
|
dev_err(dev, "no hisilicon,usb3-otg-bc-syscon\n");
|
2020-09-17 03:42:05 -07:00
|
|
|
return PTR_ERR(priv->usb31misc);
|
|
|
|
}
|
|
|
|
|
2020-09-17 03:42:11 -07:00
|
|
|
if (of_property_read_u32(dev->of_node, "hisilicon,eye-diagram-param",
|
2020-09-17 03:42:10 -07:00
|
|
|
&priv->eye_diagram_param))
|
2020-09-17 03:42:05 -07:00
|
|
|
priv->eye_diagram_param = KIRIN970_USB_DEFAULT_PHY_PARAM;
|
|
|
|
|
2020-09-17 03:42:11 -07:00
|
|
|
if (of_property_read_u32(dev->of_node, "hisilicon,tx-vboost-lvl",
|
2020-09-17 03:42:10 -07:00
|
|
|
&priv->tx_vboost_lvl))
|
2020-09-21 14:21:47 -07:00
|
|
|
priv->tx_vboost_lvl = KIRIN970_USB_DEFAULT_PHY_VBOOST;
|
2020-09-17 03:42:05 -07:00
|
|
|
|
2020-09-17 03:42:08 -07:00
|
|
|
phy = devm_phy_create(dev, NULL, &hi3670_phy_ops);
|
2020-09-17 03:42:05 -07:00
|
|
|
if (IS_ERR(phy))
|
|
|
|
return PTR_ERR(phy);
|
|
|
|
|
|
|
|
phy_set_drvdata(phy, priv);
|
|
|
|
phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
|
|
|
|
return PTR_ERR_OR_ZERO(phy_provider);
|
|
|
|
}
|
|
|
|
|
2020-09-17 03:42:08 -07:00
|
|
|
static const struct of_device_id hi3670_phy_of_match[] = {
|
2020-09-17 03:42:10 -07:00
|
|
|
{ .compatible = "hisilicon,hi3670-usb-phy" },
|
2020-09-17 03:42:05 -07:00
|
|
|
{ },
|
|
|
|
};
|
2020-09-17 03:42:08 -07:00
|
|
|
MODULE_DEVICE_TABLE(of, hi3670_phy_of_match);
|
2020-09-17 03:42:05 -07:00
|
|
|
|
2020-09-17 03:42:08 -07:00
|
|
|
static struct platform_driver hi3670_phy_driver = {
|
|
|
|
.probe = hi3670_phy_probe,
|
2020-09-17 03:42:05 -07:00
|
|
|
.driver = {
|
2020-09-17 03:42:08 -07:00
|
|
|
.name = "hi3670-usb-phy",
|
|
|
|
.of_match_table = hi3670_phy_of_match,
|
2020-09-17 03:42:05 -07:00
|
|
|
}
|
|
|
|
};
|
2020-09-17 03:42:08 -07:00
|
|
|
module_platform_driver(hi3670_phy_driver);
|
2020-09-17 03:42:05 -07:00
|
|
|
|
|
|
|
MODULE_AUTHOR("Yu Chen <chenyu56@huawei.com>");
|
|
|
|
MODULE_LICENSE("GPL v2");
|
|
|
|
MODULE_DESCRIPTION("Hilisicon Kirin970 USB31 PHY Driver");
|