]> git.baikalelectronics.ru Git - kernel.git/commitdiff
USB: dwc2: Add OTG support for Ingenic SoCs.
author周琰杰 (Zhou Yanjie) <zhouyanjie@wanyeetech.com>
Thu, 14 Apr 2022 19:25:36 +0000 (03:25 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 21 Apr 2022 17:22:00 +0000 (19:22 +0200)
Add OTG support for the JZ4775 SoC, the JZ4780 SoC, the X1000 SoC,
the X1600 SoC, the X1700 SoC, the X1830 SoC, and the X2000 SoC
from Ingenic.

Introduce support for disable Ingenic overcurrent detection, once
selected, it enables the GOTGCTL register bits VbvalidOvEn and
VbvalidOvVal to disable the VBUS overcurrent detection.

This patch is derived from Dragan Čečavac (in the kernel 3.18.3
tree of CI20). It is very useful for the MIPS Creator CI20 (r1).
Without this patch, OTG port of CI20 has a great probability to
face overcurrent warning, which breaks the OTG functionality.

Acked-by: Minas Harutyunyan <Minas.Harutyunyan@synopsys.com>
Signed-off-by: Dragan Čečavac <dragancecavac@yahoo.com>
Signed-off-by: 周琰杰 (Zhou Yanjie) <zhouyanjie@wanyeetech.com>
Link: https://lore.kernel.org/r/1649964337-114337-3-git-send-email-zhouyanjie@wanyeetech.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/dwc2/core.c
drivers/usb/dwc2/core.h
drivers/usb/dwc2/params.c

index cf0bcd0dc320e12bee2c332e3b10ea9e6e65b183..dc4fc72ab1b66be50f781aff194e169e0958393e 100644 (file)
@@ -1153,6 +1153,7 @@ static void dwc2_set_turnaround_time(struct dwc2_hsotg *hsotg)
 int dwc2_phy_init(struct dwc2_hsotg *hsotg, bool select_phy)
 {
        u32 usbcfg;
+       u32 otgctl;
        int retval = 0;
 
        if ((hsotg->params.speed == DWC2_SPEED_PARAM_FULL ||
@@ -1187,6 +1188,14 @@ int dwc2_phy_init(struct dwc2_hsotg *hsotg, bool select_phy)
                dwc2_writel(hsotg, usbcfg, GUSBCFG);
        }
 
+       if (!hsotg->params.activate_ingenic_overcurrent_detection) {
+               if (dwc2_is_host_mode(hsotg)) {
+                       otgctl = readl(hsotg->regs + GOTGCTL);
+                       otgctl |= GOTGCTL_VBVALOEN | GOTGCTL_VBVALOVAL;
+                       writel(otgctl, hsotg->regs + GOTGCTL);
+               }
+       }
+
        return retval;
 }
 
index 88c337bf564ff08b2829ca25cb0e7eae2d9298c3..0683852e47e41801d2dcc3eef995bc90a0ebc49b 100644 (file)
@@ -426,6 +426,10 @@ enum dwc2_ep0_state {
  *                     detection using GGPIO register.
  *                     0 - Deactivate the external level detection (default)
  *                     1 - Activate the external level detection
+ * @activate_ingenic_overcurrent_detection: Activate Ingenic overcurrent
+ *                     detection.
+ *                     0 - Deactivate the overcurrent detection
+ *                     1 - Activate the overcurrent detection (default)
  * @g_dma:              Enables gadget dma usage (default: autodetect).
  * @g_dma_desc:         Enables gadget descriptor DMA (default: autodetect).
  * @g_rx_fifo_size:    The periodic rx fifo size for the device, in
@@ -494,6 +498,7 @@ struct dwc2_core_params {
        u8 hird_threshold;
        bool activate_stm_fs_transceiver;
        bool activate_stm_id_vb_detection;
+       bool activate_ingenic_overcurrent_detection;
        bool ipg_isoc_en;
        u16 max_packet_count;
        u32 max_transfer_size;
index 1306f4ec788da5b05599fecf48bf1bb3ebcec5cd..fdb8a42fff86038cf8497e08dd117c7377910250 100644 (file)
@@ -73,6 +73,47 @@ static void dwc2_set_his_params(struct dwc2_hsotg *hsotg)
        p->power_down = DWC2_POWER_DOWN_PARAM_NONE;
 }
 
+static void dwc2_set_jz4775_params(struct dwc2_hsotg *hsotg)
+{
+       struct dwc2_core_params *p = &hsotg->params;
+
+       p->otg_caps.hnp_support = false;
+       p->speed = DWC2_SPEED_PARAM_HIGH;
+       p->phy_type = DWC2_PHY_TYPE_PARAM_UTMI;
+       p->phy_utmi_width = 16;
+       p->activate_ingenic_overcurrent_detection =
+               !device_property_read_bool(hsotg->dev, "disable-over-current");
+}
+
+static void dwc2_set_x1600_params(struct dwc2_hsotg *hsotg)
+{
+       struct dwc2_core_params *p = &hsotg->params;
+
+       p->otg_caps.hnp_support = false;
+       p->speed = DWC2_SPEED_PARAM_HIGH;
+       p->host_channels = 16;
+       p->phy_type = DWC2_PHY_TYPE_PARAM_UTMI;
+       p->phy_utmi_width = 16;
+       p->activate_ingenic_overcurrent_detection =
+               !device_property_read_bool(hsotg->dev, "disable-over-current");
+}
+
+static void dwc2_set_x2000_params(struct dwc2_hsotg *hsotg)
+{
+       struct dwc2_core_params *p = &hsotg->params;
+
+       p->otg_caps.hnp_support = false;
+       p->speed = DWC2_SPEED_PARAM_HIGH;
+       p->host_rx_fifo_size = 1024;
+       p->host_nperio_tx_fifo_size = 1024;
+       p->host_perio_tx_fifo_size = 1024;
+       p->host_channels = 16;
+       p->phy_type = DWC2_PHY_TYPE_PARAM_UTMI;
+       p->phy_utmi_width = 16;
+       p->activate_ingenic_overcurrent_detection =
+               !device_property_read_bool(hsotg->dev, "disable-over-current");
+}
+
 static void dwc2_set_s3c6400_params(struct dwc2_hsotg *hsotg)
 {
        struct dwc2_core_params *p = &hsotg->params;
@@ -221,7 +262,14 @@ static void dwc2_set_stm32mp15_hsotg_params(struct dwc2_hsotg *hsotg)
 
 const struct of_device_id dwc2_of_match_table[] = {
        { .compatible = "brcm,bcm2835-usb", .data = dwc2_set_bcm_params },
-       { .compatible = "hisilicon,hi6220-usb", .data = dwc2_set_his_params  },
+       { .compatible = "hisilicon,hi6220-usb", .data = dwc2_set_his_params },
+       { .compatible = "ingenic,jz4775-otg", .data = dwc2_set_jz4775_params },
+       { .compatible = "ingenic,jz4780-otg", .data = dwc2_set_jz4775_params },
+       { .compatible = "ingenic,x1000-otg", .data = dwc2_set_jz4775_params },
+       { .compatible = "ingenic,x1600-otg", .data = dwc2_set_x1600_params },
+       { .compatible = "ingenic,x1700-otg", .data = dwc2_set_x1600_params },
+       { .compatible = "ingenic,x1830-otg", .data = dwc2_set_x1600_params },
+       { .compatible = "ingenic,x2000-otg", .data = dwc2_set_x2000_params },
        { .compatible = "rockchip,rk3066-usb", .data = dwc2_set_rk_params },
        { .compatible = "lantiq,arx100-usb", .data = dwc2_set_ltq_params },
        { .compatible = "lantiq,xrx200-usb", .data = dwc2_set_ltq_params },