Skip to content

Commit

Permalink
add dwc3 v2 support
Browse files Browse the repository at this point in the history
  • Loading branch information
SamulKyull authored and SamulKyull committed Jul 2, 2024
1 parent 60d6d4f commit e51eba1
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,4 @@ sphinx_*/

# Kernel DIr
kernel/
drivers/
10 changes: 5 additions & 5 deletions bsp/drivers/usb/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ menu "USB Drivers"

if AW_BSP && USB_SUPPORT

source "bsp/drivers/usb/dwc3/Kconfig"
source "$(BSP_TOP)drivers/usb/dwc3/Kconfig"

if USB

source "bsp/drivers/usb/host/Kconfig"
source "$(BSP_TOP)drivers/usb/host/Kconfig"

endif # USB

source "bsp/drivers/usb/sunxi_usb/Kconfig"
source "$(BSP_TOP)drivers/usb/sunxi_usb/Kconfig"

source "bsp/drivers/usb/typec/Kconfig"
source "$(BSP_TOP)drivers/usb/typec/Kconfig"

source "bsp/drivers/usb/gadget/Kconfig"
source "$(BSP_TOP)drivers/usb/gadget/Kconfig"

endif # USB_SUPPORT

Expand Down
30 changes: 28 additions & 2 deletions bsp/drivers/usb/dwc3/phy-sunxi-plat.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include <linux/phy/phy.h>
#include <linux/platform_device.h>
#include <linux/reset.h>
#include <linux/of_device.h>
#include <sunxi-log.h>

#include <sunxi-log.h>

Expand Down Expand Up @@ -63,11 +65,16 @@
#define PHY_REG_U2_PHYCTL(u2phy_base_addr) ((u2phy_base_addr) \
+ PHY_USB2_PHYCTL)

struct sunxi_phy_of_data {
bool has_vbusvldext;
};

struct sunxi_phy {
struct phy *phy;
void __iomem *u2;
struct reset_control *reset;
struct clk *clk;
const struct sunxi_phy_of_data *drvdata;
};

static void phy_u2_set(struct sunxi_phy *phy, bool enable)
Expand All @@ -85,7 +92,8 @@ static void phy_u2_set(struct sunxi_phy *phy, bool enable)
#endif

val = readl(PHY_REG_U2_PHYCTL(phy->u2));
tmp = OTGDISABLE | VBUSVLDEXT;
if (phy->drvdata->has_vbusvldext)
tmp = OTGDISABLE | VBUSVLDEXT;
if (enable) {
val |= tmp;
val &= ~SIDDQ; /* write 0 to enable phy */
Expand Down Expand Up @@ -148,10 +156,14 @@ static int phy_sunxi_plat_probe(struct platform_device *pdev)
struct sunxi_phy *phy;
struct device *dev = &pdev->dev;
struct phy_provider *phy_provider;
const struct sunxi_phy_of_data *data;

data = of_device_get_match_data(&pdev->dev);

phy = devm_kzalloc(dev, sizeof(*phy), GFP_KERNEL);
if (!phy)
return -ENOMEM;
phy->drvdata = data;

phy->clk = devm_clk_get(dev, NULL);
if (IS_ERR(phy->clk)) {
Expand Down Expand Up @@ -181,8 +193,22 @@ static int phy_sunxi_plat_probe(struct platform_device *pdev)
return PTR_ERR_OR_ZERO(phy_provider);
}

static const struct sunxi_phy_of_data sunxi_phy_v1_of_data = {
.has_vbusvldext = true,
};

static const struct sunxi_phy_of_data sunxi_phy_v2_of_data = {
.has_vbusvldext = false,
};
static const struct of_device_id phy_sunxi_plat_of_match[] = {
{ .compatible = "allwinner,sunxi-plat-phy" },
{
.compatible = "allwinner,sunxi-plat-phy",
.data = &sunxi_phy_v1_of_data,
},
{
.compatible = "allwinner,sunxi-plat-phy-v2",
.data = &sunxi_phy_v2_of_data,
},
{ /* Sentinel */ }
};
MODULE_DEVICE_TABLE(of, phy_sunxi_plat_of_match);
Expand Down
50 changes: 44 additions & 6 deletions bsp/drivers/usb/host/sunxi-hci.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ static atomic_t usb2_enable_passly_cnt = ATOMIC_INIT(0);
static atomic_t usb3_enable_passly_cnt = ATOMIC_INIT(0);
static atomic_t usb4_enable_passly_cnt = ATOMIC_INIT(0);

static atomic_t usb0_enable_siddq_cnt = ATOMIC_INIT(0);
static atomic_t usb1_enable_siddq_cnt = ATOMIC_INIT(0);
static atomic_t usb2_enable_siddq_cnt = ATOMIC_INIT(0);
static atomic_t usb3_enable_siddq_cnt = ATOMIC_INIT(0);

static atomic_t usb_standby_cnt[4];

ATOMIC_NOTIFIER_HEAD(usb_pm_notifier_list);
Expand Down Expand Up @@ -939,10 +944,33 @@ static void USBC_SelectPhyToHci(struct sunxi_hci_hcd *sunxi_hci)
USBC_Writel(reg_value, (sunxi_hci->otg_vbase + SUNXI_OTG_PHY_CFG));
}

static unsigned char USBC_SIDDP_Disable_Check(struct sunxi_hci_hcd *sunxi_hci)
{
if (sunxi_hci->usbc_no == HCI0_USBC_NO && atomic_read(&usb0_enable_siddq_cnt) == 0)
return 1;
else if (sunxi_hci->usbc_no == HCI1_USBC_NO && atomic_read(&usb1_enable_siddq_cnt) == 0)
return 1;
else if (sunxi_hci->usbc_no == HCI2_USBC_NO && atomic_read(&usb2_enable_siddq_cnt) == 0)
return 1;
else if (sunxi_hci->usbc_no == HCI3_USBC_NO && atomic_read(&usb3_enable_siddq_cnt) == 0)
return 1;
else
return 0;
}

static void USBC_Clean_SIDDP(struct sunxi_hci_hcd *sunxi_hci)
{
int reg_value = 0;

if (sunxi_hci->usbc_no == HCI0_USBC_NO)
atomic_add(1, &usb0_enable_siddq_cnt);
else if (sunxi_hci->usbc_no == HCI1_USBC_NO)
atomic_add(1, &usb1_enable_siddq_cnt);
else if (sunxi_hci->usbc_no == HCI2_USBC_NO)
atomic_add(1, &usb2_enable_siddq_cnt);
else if (sunxi_hci->usbc_no == HCI3_USBC_NO)
atomic_add(1, &usb3_enable_siddq_cnt);

reg_value = USBC_Readl(sunxi_hci->usb_vbase + SUNXI_HCI_PHY_CTRL);
reg_value &= ~(0x01 << SUNXI_HCI_PHY_CTRL_SIDDQ);
USBC_Writel(reg_value, (sunxi_hci->usb_vbase + SUNXI_HCI_PHY_CTRL));
Expand All @@ -951,10 +979,20 @@ static void USBC_Clean_SIDDP(struct sunxi_hci_hcd *sunxi_hci)
static void USBC_Set_SIDDP(struct sunxi_hci_hcd *sunxi_hci)
{
int reg_value = 0;

reg_value = USBC_Readl(sunxi_hci->usb_vbase + SUNXI_HCI_PHY_CTRL);
reg_value |= (0x01 << SUNXI_HCI_PHY_CTRL_SIDDQ);
USBC_Writel(reg_value, (sunxi_hci->usb_vbase + SUNXI_HCI_PHY_CTRL));
if (sunxi_hci->usbc_no == HCI0_USBC_NO)
atomic_sub(1, &usb0_enable_siddq_cnt);
else if (sunxi_hci->usbc_no == HCI1_USBC_NO)
atomic_sub(1, &usb1_enable_siddq_cnt);
else if (sunxi_hci->usbc_no == HCI2_USBC_NO)
atomic_sub(1, &usb2_enable_siddq_cnt);
else if (sunxi_hci->usbc_no == HCI3_USBC_NO)
atomic_sub(1, &usb3_enable_siddq_cnt);

if (USBC_SIDDP_Disable_Check(sunxi_hci)) {
reg_value = USBC_Readl(sunxi_hci->usb_vbase + SUNXI_HCI_PHY_CTRL);
reg_value |= (0x01 << SUNXI_HCI_PHY_CTRL_SIDDQ);
USBC_Writel(reg_value, (sunxi_hci->usb_vbase + SUNXI_HCI_PHY_CTRL));
}
}

#if IS_ENABLED(CONFIG_ARCH_SUN50IW10)
Expand Down Expand Up @@ -1391,6 +1429,8 @@ static int open_clock(struct sunxi_hci_hcd *sunxi_hci, u32 ohci)

static int close_clock(struct sunxi_hci_hcd *sunxi_hci, u32 ohci)
{
if (sunxi_hci->is_suspend_flag == 0)
USBC_Set_SIDDP(sunxi_hci);
if (sunxi_hci->clk_is_open) {
sunxi_hci->clk_is_open = 0;

Expand Down Expand Up @@ -1457,8 +1497,6 @@ static int close_clock(struct sunxi_hci_hcd *sunxi_hci, u32 ohci)
sunxi_hci->clk_is_open,
sunxi_hci->mod_usb);
}
if (sunxi_hci->is_suspend_flag == 0)
USBC_Set_SIDDP(sunxi_hci);
#if IS_ENABLED(CONFIG_ARCH_SUN55IW3)
usb_phyx_res_cal(sunxi_hci->usbc_no, false);
#endif
Expand Down

0 comments on commit e51eba1

Please sign in to comment.