[PATCH RESEND 2/2] phy: phy-mtk-tphy: add properties for phy tuning

2023-12-12 Thread Chunfeng Yun
Add properties to improve eye diagram which sometimes need adjust
some parameters of u2phy;
Add a property to tune disconnect threshold;

Signed-off-by: Chunfeng Yun 
---
 drivers/phy/phy-mtk-tphy.c | 58 +-
 1 file changed, 57 insertions(+), 1 deletion(-)

diff --git a/drivers/phy/phy-mtk-tphy.c b/drivers/phy/phy-mtk-tphy.c
index 1883f9f83e..ea9edf212c 100644
--- a/drivers/phy/phy-mtk-tphy.c
+++ b/drivers/phy/phy-mtk-tphy.c
@@ -47,6 +47,11 @@
 #define PA0_USB20_PLL_PREDIV   GENMASK(7, 6)
 #define PA0_RG_USB20_INTR_EN   BIT(5)
 
+#define U3P_USBPHYACR1 0x004
+#define PA1_RG_INTR_CALGENMASK(23, 19)
+#define PA1_RG_VRT_SEL GENMASK(14, 12)
+#define PA1_RG_TERM_SELGENMASK(10, 8)
+
 #define U3P_USBPHYACR2 0x008
 #define PA2_RG_U2PLL_BWGENMASK(21, 19)
 
@@ -56,8 +61,10 @@
 #define PA5_RG_U2_HS_100U_U3_ENBIT(11)
 
 #define U3P_USBPHYACR6 0x018
+#define PA6_RG_U2_PRE_EMP  GENMASK(31, 30)
 #define PA6_RG_U2_BC11_SW_EN   BIT(23)
 #define PA6_RG_U2_OTG_VBUSCMP_EN   BIT(20)
+#define PA6_RG_U2_DISCTH   GENMASK(7, 4)
 #define PA6_RG_U2_SQTH GENMASK(3, 0)
 
 #define U3P_U2PHYACR4  0x020
@@ -240,7 +247,7 @@ struct u3phy_banks {
 
 struct mtk_phy_instance {
void __iomem *port_base;
-   const struct device_node *np;
+   struct device_node *np;
union {
struct u2phy_banks u2_banks;
struct u3phy_banks u3_banks;
@@ -250,6 +257,11 @@ struct mtk_phy_instance {
struct clk da_ref_clk;  /* reference clock of analog phy */
u32 index;
u32 type;
+
+   u32 eye_vrt;
+   u32 eye_term;
+   u32 discth;
+   u32 pre_emphasis;
 };
 
 struct mtk_tphy {
@@ -564,6 +576,47 @@ static void phy_v2_banks_init(struct mtk_tphy *tphy,
}
 }
 
+static void phy_parse_property(struct mtk_tphy *tphy,
+  struct mtk_phy_instance *instance)
+{
+   ofnode node = np_to_ofnode(instance->np);
+
+   if (instance->type != PHY_TYPE_USB2)
+   return;
+
+   ofnode_read_u32(node, "mediatek,eye-vrt", &instance->eye_vrt);
+   ofnode_read_u32(node, "mediatek,eye-term", &instance->eye_term);
+   ofnode_read_u32(node, "mediatek,discth", &instance->discth);
+   ofnode_read_u32(node, "mediatek,pre-emphasis", &instance->pre_emphasis);
+
+   dev_dbg(tphy->dev, "vrt:%d, term:%d, disc:%d, emp:%d\n",
+   instance->eye_vrt, instance->eye_term,
+   instance->discth, instance->pre_emphasis);
+}
+
+static void u2_phy_props_set(struct mtk_tphy *tphy,
+struct mtk_phy_instance *instance)
+{
+   struct u2phy_banks *u2_banks = &instance->u2_banks;
+   void __iomem *com = u2_banks->com;
+
+   if (instance->eye_vrt)
+   clrsetbits_le32(com + U3P_USBPHYACR1, PA1_RG_VRT_SEL,
+   FIELD_PREP(PA1_RG_VRT_SEL, instance->eye_vrt));
+
+   if (instance->eye_term)
+   clrsetbits_le32(com + U3P_USBPHYACR1, PA1_RG_TERM_SEL,
+   FIELD_PREP(PA1_RG_TERM_SEL, 
instance->eye_term));
+
+   if (instance->discth)
+   clrsetbits_le32(com + U3P_USBPHYACR6, PA6_RG_U2_DISCTH,
+   FIELD_PREP(PA6_RG_U2_DISCTH, instance->discth));
+
+   if (instance->pre_emphasis)
+   clrsetbits_le32(com + U3P_USBPHYACR6, PA6_RG_U2_PRE_EMP,
+   FIELD_PREP(PA6_RG_U2_PRE_EMP, 
instance->pre_emphasis));
+}
+
 static int mtk_phy_init(struct phy *phy)
 {
struct mtk_tphy *tphy = dev_get_priv(phy->dev);
@@ -586,6 +639,7 @@ static int mtk_phy_init(struct phy *phy)
switch (instance->type) {
case PHY_TYPE_USB2:
u2_phy_instance_init(tphy, instance);
+   u2_phy_props_set(tphy, instance);
break;
case PHY_TYPE_USB3:
u3_phy_instance_init(tphy, instance);
@@ -692,6 +746,8 @@ static int mtk_phy_xlate(struct phy *phy,
return -EINVAL;
}
 
+   phy_parse_property(tphy, instance);
+
return 0;
 }
 
-- 
2.25.1



[PATCH RESEND 1/2] dt-bindings: phy-mtk-tphy: add properties for phy tuning

2023-12-12 Thread Chunfeng Yun
Add properties to improve eye diagram which sometimes need adjust
some parameters of u2phy;
Add a property to tune disconnect threshold;

Signed-off-by: Chunfeng Yun 
---
 doc/device-tree-bindings/phy/phy-mtk-tphy.txt | 9 +
 1 file changed, 9 insertions(+)

diff --git a/doc/device-tree-bindings/phy/phy-mtk-tphy.txt 
b/doc/device-tree-bindings/phy/phy-mtk-tphy.txt
index 3042c39d09..300e236b5b 100644
--- a/doc/device-tree-bindings/phy/phy-mtk-tphy.txt
+++ b/doc/device-tree-bindings/phy/phy-mtk-tphy.txt
@@ -52,6 +52,15 @@ Optional properties (port (child) node):
  "da_ref": the reference clock of analog phy, used if the 
clocks
of analog and digital phys are separated, otherwise uses
"ref" clock only if needed.
+- mediatek,eye-vrt : The selection of VRT reference voltage (U2 phy),
+ the value is [1, 7]
+- mediatek,eye-term: The selection of HS_TX TERM reference voltage (U2 
phy),
+ the value is [1, 7]
+- mediatek,discth  : The selection of disconnect threshold (U2 phy),
+ the value is [1, 15]
+- mediatek,pre-emphasis: The level of pre-emphasis which used to widen
+ the eye opening and boost eye swing,
+ the value is [1, 3]
 
 Example:
 
-- 
2.25.1



[PATCH 2/2] phy: phy-mtk-tphy: add properties for phy tuning

2023-11-05 Thread Chunfeng Yun
Add properties to improve eye diagram which sometimes need adjust
some parameters of u2phy;
Add a property to tune disconnect threshold;

Signed-off-by: Chunfeng Yun 
---
 drivers/phy/phy-mtk-tphy.c | 58 +-
 1 file changed, 57 insertions(+), 1 deletion(-)

diff --git a/drivers/phy/phy-mtk-tphy.c b/drivers/phy/phy-mtk-tphy.c
index 1883f9f83e..ea9edf212c 100644
--- a/drivers/phy/phy-mtk-tphy.c
+++ b/drivers/phy/phy-mtk-tphy.c
@@ -47,6 +47,11 @@
 #define PA0_USB20_PLL_PREDIV   GENMASK(7, 6)
 #define PA0_RG_USB20_INTR_EN   BIT(5)
 
+#define U3P_USBPHYACR1 0x004
+#define PA1_RG_INTR_CALGENMASK(23, 19)
+#define PA1_RG_VRT_SEL GENMASK(14, 12)
+#define PA1_RG_TERM_SELGENMASK(10, 8)
+
 #define U3P_USBPHYACR2 0x008
 #define PA2_RG_U2PLL_BWGENMASK(21, 19)
 
@@ -56,8 +61,10 @@
 #define PA5_RG_U2_HS_100U_U3_ENBIT(11)
 
 #define U3P_USBPHYACR6 0x018
+#define PA6_RG_U2_PRE_EMP  GENMASK(31, 30)
 #define PA6_RG_U2_BC11_SW_EN   BIT(23)
 #define PA6_RG_U2_OTG_VBUSCMP_EN   BIT(20)
+#define PA6_RG_U2_DISCTH   GENMASK(7, 4)
 #define PA6_RG_U2_SQTH GENMASK(3, 0)
 
 #define U3P_U2PHYACR4  0x020
@@ -240,7 +247,7 @@ struct u3phy_banks {
 
 struct mtk_phy_instance {
void __iomem *port_base;
-   const struct device_node *np;
+   struct device_node *np;
union {
struct u2phy_banks u2_banks;
struct u3phy_banks u3_banks;
@@ -250,6 +257,11 @@ struct mtk_phy_instance {
struct clk da_ref_clk;  /* reference clock of analog phy */
u32 index;
u32 type;
+
+   u32 eye_vrt;
+   u32 eye_term;
+   u32 discth;
+   u32 pre_emphasis;
 };
 
 struct mtk_tphy {
@@ -564,6 +576,47 @@ static void phy_v2_banks_init(struct mtk_tphy *tphy,
}
 }
 
+static void phy_parse_property(struct mtk_tphy *tphy,
+  struct mtk_phy_instance *instance)
+{
+   ofnode node = np_to_ofnode(instance->np);
+
+   if (instance->type != PHY_TYPE_USB2)
+   return;
+
+   ofnode_read_u32(node, "mediatek,eye-vrt", &instance->eye_vrt);
+   ofnode_read_u32(node, "mediatek,eye-term", &instance->eye_term);
+   ofnode_read_u32(node, "mediatek,discth", &instance->discth);
+   ofnode_read_u32(node, "mediatek,pre-emphasis", &instance->pre_emphasis);
+
+   dev_dbg(tphy->dev, "vrt:%d, term:%d, disc:%d, emp:%d\n",
+   instance->eye_vrt, instance->eye_term,
+   instance->discth, instance->pre_emphasis);
+}
+
+static void u2_phy_props_set(struct mtk_tphy *tphy,
+struct mtk_phy_instance *instance)
+{
+   struct u2phy_banks *u2_banks = &instance->u2_banks;
+   void __iomem *com = u2_banks->com;
+
+   if (instance->eye_vrt)
+   clrsetbits_le32(com + U3P_USBPHYACR1, PA1_RG_VRT_SEL,
+   FIELD_PREP(PA1_RG_VRT_SEL, instance->eye_vrt));
+
+   if (instance->eye_term)
+   clrsetbits_le32(com + U3P_USBPHYACR1, PA1_RG_TERM_SEL,
+   FIELD_PREP(PA1_RG_TERM_SEL, 
instance->eye_term));
+
+   if (instance->discth)
+   clrsetbits_le32(com + U3P_USBPHYACR6, PA6_RG_U2_DISCTH,
+   FIELD_PREP(PA6_RG_U2_DISCTH, instance->discth));
+
+   if (instance->pre_emphasis)
+   clrsetbits_le32(com + U3P_USBPHYACR6, PA6_RG_U2_PRE_EMP,
+   FIELD_PREP(PA6_RG_U2_PRE_EMP, 
instance->pre_emphasis));
+}
+
 static int mtk_phy_init(struct phy *phy)
 {
struct mtk_tphy *tphy = dev_get_priv(phy->dev);
@@ -586,6 +639,7 @@ static int mtk_phy_init(struct phy *phy)
switch (instance->type) {
case PHY_TYPE_USB2:
u2_phy_instance_init(tphy, instance);
+   u2_phy_props_set(tphy, instance);
break;
case PHY_TYPE_USB3:
u3_phy_instance_init(tphy, instance);
@@ -692,6 +746,8 @@ static int mtk_phy_xlate(struct phy *phy,
return -EINVAL;
}
 
+   phy_parse_property(tphy, instance);
+
return 0;
 }
 
-- 
2.25.1



[PATCH 1/2] dt-bindings: phy-mtk-tphy: add properties for phy tuning

2023-11-05 Thread Chunfeng Yun
Add properties to improve eye diagram which sometimes need adjust
some parameters of u2phy;
Add a property to tune disconnect threshold;

Signed-off-by: Chunfeng Yun 
---
 doc/device-tree-bindings/phy/phy-mtk-tphy.txt | 9 +
 1 file changed, 9 insertions(+)

diff --git a/doc/device-tree-bindings/phy/phy-mtk-tphy.txt 
b/doc/device-tree-bindings/phy/phy-mtk-tphy.txt
index 3042c39d09..300e236b5b 100644
--- a/doc/device-tree-bindings/phy/phy-mtk-tphy.txt
+++ b/doc/device-tree-bindings/phy/phy-mtk-tphy.txt
@@ -52,6 +52,15 @@ Optional properties (port (child) node):
  "da_ref": the reference clock of analog phy, used if the 
clocks
of analog and digital phys are separated, otherwise uses
"ref" clock only if needed.
+- mediatek,eye-vrt : The selection of VRT reference voltage (U2 phy),
+ the value is [1, 7]
+- mediatek,eye-term: The selection of HS_TX TERM reference voltage (U2 
phy),
+ the value is [1, 7]
+- mediatek,discth  : The selection of disconnect threshold (U2 phy),
+ the value is [1, 15]
+- mediatek,pre-emphasis: The level of pre-emphasis which used to widen
+ the eye opening and boost eye swing,
+ the value is [1, 3]
 
 Example:
 
-- 
2.25.1



[PATCH v2 1/5] phy: phy-mtk-tphy: remove macros to prepare bitfield value

2023-02-17 Thread Chunfeng Yun
Prefer to make use of FIELD_PREP() macro to prepare bitfield value,
then no need local macros anymore.

Signed-off-by: Chunfeng Yun 
---
v2: new patch
---
 drivers/phy/phy-mtk-tphy.c | 122 ++---
 1 file changed, 47 insertions(+), 75 deletions(-)

diff --git a/drivers/phy/phy-mtk-tphy.c b/drivers/phy/phy-mtk-tphy.c
index 2dd964f7b2..24e6124b76 100644
--- a/drivers/phy/phy-mtk-tphy.c
+++ b/drivers/phy/phy-mtk-tphy.c
@@ -14,6 +14,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -48,14 +49,12 @@
 #define U3P_USBPHYACR5 0x014
 #define PA5_RG_U2_HSTX_SRCAL_ENBIT(15)
 #define PA5_RG_U2_HSTX_SRCTRL  GENMASK(14, 12)
-#define PA5_RG_U2_HSTX_SRCTRL_VAL(x)   ((0x7 & (x)) << 12)
 #define PA5_RG_U2_HS_100U_U3_ENBIT(11)
 
 #define U3P_USBPHYACR6 0x018
 #define PA6_RG_U2_BC11_SW_EN   BIT(23)
 #define PA6_RG_U2_OTG_VBUSCMP_EN   BIT(20)
 #define PA6_RG_U2_SQTH GENMASK(3, 0)
-#define PA6_RG_U2_SQTH_VAL(x)  (0xf & (x))
 
 #define U3P_U2PHYACR4  0x020
 #define P2C_RG_USB20_GPIO_CTL  BIT(9)
@@ -72,11 +71,9 @@
 #define P2C_FORCE_SUSPENDM BIT(18)
 #define P2C_FORCE_TERMSEL  BIT(17)
 #define P2C_RG_DATAIN  GENMASK(13, 10)
-#define P2C_RG_DATAIN_VAL(x)   ((0xf & (x)) << 10)
 #define P2C_RG_DMPULLDOWN  BIT(7)
 #define P2C_RG_DPPULLDOWN  BIT(6)
 #define P2C_RG_XCVRSEL GENMASK(5, 4)
-#define P2C_RG_XCVRSEL_VAL(x)  ((0x3 & (x)) << 4)
 #define P2C_RG_SUSPENDMBIT(3)
 #define P2C_RG_TERMSEL BIT(2)
 #define P2C_DTM0_PART_MASK \
@@ -104,72 +101,53 @@
 
 #define U3P_U3_PHYA_REG0   0x000
 #define P3A_RG_CLKDRV_OFF  GENMASK(3, 2)
-#define P3A_RG_CLKDRV_OFF_VAL(x)   ((0x3 & (x)) << 2)
 
 #define U3P_U3_PHYA_REG1   0x004
 #define P3A_RG_CLKDRV_AMP  GENMASK(31, 29)
-#define P3A_RG_CLKDRV_AMP_VAL(x)   ((0x7 & (x)) << 29)
 
 #define U3P_U3_PHYA_REG6   0x018
 #define P3A_RG_TX_EIDLE_CM GENMASK(31, 28)
-#define P3A_RG_TX_EIDLE_CM_VAL(x)  ((0xf & (x)) << 28)
 
 #define U3P_U3_PHYA_REG9   0x024
 #define P3A_RG_RX_DAC_MUX  GENMASK(5, 1)
-#define P3A_RG_RX_DAC_MUX_VAL(x)   ((0x1f & (x)) << 1)
 
 #define U3P_U3_PHYA_DA_REG00x100
 #define P3A_RG_XTAL_EXT_PE2H   GENMASK(17, 16)
-#define P3A_RG_XTAL_EXT_PE2H_VAL(x)((0x3 & (x)) << 16)
 #define P3A_RG_XTAL_EXT_PE1H   GENMASK(13, 12)
-#define P3A_RG_XTAL_EXT_PE1H_VAL(x)((0x3 & (x)) << 12)
 #define P3A_RG_XTAL_EXT_EN_U3  GENMASK(11, 10)
-#define P3A_RG_XTAL_EXT_EN_U3_VAL(x)   ((0x3 & (x)) << 10)
 
 #define U3P_U3_PHYA_DA_REG40x108
 #define P3A_RG_PLL_DIVEN_PE2H  GENMASK(21, 19)
 #define P3A_RG_PLL_BC_PE2H GENMASK(7, 6)
-#define P3A_RG_PLL_BC_PE2H_VAL(x)  ((0x3 & (x)) << 6)
 
 #define U3P_U3_PHYA_DA_REG50x10c
 #define P3A_RG_PLL_BR_PE2H GENMASK(29, 28)
-#define P3A_RG_PLL_BR_PE2H_VAL(x)  ((0x3 & (x)) << 28)
 #define P3A_RG_PLL_IC_PE2H GENMASK(15, 12)
-#define P3A_RG_PLL_IC_PE2H_VAL(x)  ((0xf & (x)) << 12)
 
 #define U3P_U3_PHYA_DA_REG60x110
 #define P3A_RG_PLL_IR_PE2H GENMASK(19, 16)
-#define P3A_RG_PLL_IR_PE2H_VAL(x)  ((0xf & (x)) << 16)
 
 #define U3P_U3_PHYA_DA_REG70x114
 #define P3A_RG_PLL_BP_PE2H GENMASK(19, 16)
-#define P3A_RG_PLL_BP_PE2H_VAL(x)  ((0xf & (x)) << 16)
 
 #define U3P_U3_PHYA_DA_REG20   0x13c
 #define P3A_RG_PLL_DELTA1_PE2H GENMASK(31, 16)
-#define P3A_RG_PLL_DELTA1_PE2H_VAL(x)  ((0x & (x)) << 16)
 
 #define U3P_U3_PHYA_DA_REG25   0x148
 #define P3A_RG_PLL_DELTA_PE2H  GENMASK(15, 0)
-#define P3A_RG_PLL_DELTA_PE2H_VAL(x)   (0x & (x))
 
 #define U3P_U3_PHYD_LFPS1  0x00c
 #define P3D_RG_FWAKE_THGENMASK(21, 16)
-#define P3D_RG_FWAKE_TH_VAL(x) ((0x3f & (x)) << 16)
 
 #define U3P_U3_PHYD_CDR1   0x05c
 #define P3D_RG_CDR_BIR_LTD1GENMASK(28, 24)
-#define P3D_RG_CDR_BIR_LTD1_VAL(x) ((0x1f & (x)) << 24)
 #define P3D_RG_CDR_BIR_LTD0GENMASK(12, 8)
-#define P3D_RG_CDR_BIR_LTD0_VAL(x) ((0x1f & (x)) << 8)
 
 #define U3P_U3_PHYD_RXDET1 0x128
 #define P3D_RG_RXDET_STB2_SET  GENMASK(17, 9)
-#define P3D_RG_RXDET_STB2_SET_VAL(x)   ((0x1ff & (x)) << 9)
 
 #define U3P_U3_PHYD_RXDET2 0x12c
 #define P3D_RG_RXDET_STB2_SET_P3   GENMASK(8, 0)
-#define P3D_RG_RXDET_STB2_SET_P3_VAL(x)(0x1ff & (x))
 
 #define U3P_SPLLC_XTALCTL3  

[PATCH v2 4/5] dt-bindings: phy-mtk-tphy: add support mt8195

2023-02-17 Thread Chunfeng Yun
Add a new compatible for mt8195 to add a workaround for hardware
issue.

Signed-off-by: Chunfeng Yun 
---
v2: no change
---
 doc/device-tree-bindings/phy/phy-mtk-tphy.txt | 1 +
 1 file changed, 1 insertion(+)

diff --git a/doc/device-tree-bindings/phy/phy-mtk-tphy.txt 
b/doc/device-tree-bindings/phy/phy-mtk-tphy.txt
index 8cd23d8c0b..3042c39d09 100644
--- a/doc/device-tree-bindings/phy/phy-mtk-tphy.txt
+++ b/doc/device-tree-bindings/phy/phy-mtk-tphy.txt
@@ -8,6 +8,7 @@ Required properties (controller (parent) node):
  - compatible  : should be one of
  "mediatek,generic-tphy-v1"
  "mediatek,generic-tphy-v2"
+ "mediatek,mt8195-tphy"
 
 - #address-cells:  the number of cells used to represent physical
base addresses.
-- 
2.18.0



[PATCH v2 5/5] dt-bindings: usb: mtk-xhci: add support mt8195

2023-02-17 Thread Chunfeng Yun
Add a new compatible for mt8195 to add a workaround for hardware
issue.

Signed-off-by: Chunfeng Yun 
---
v2: no change
---
 doc/device-tree-bindings/usb/mediatek,mtk-xhci.txt | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/doc/device-tree-bindings/usb/mediatek,mtk-xhci.txt 
b/doc/device-tree-bindings/usb/mediatek,mtk-xhci.txt
index 2a298f7b16..e26e9618eb 100644
--- a/doc/device-tree-bindings/usb/mediatek,mtk-xhci.txt
+++ b/doc/device-tree-bindings/usb/mediatek,mtk-xhci.txt
@@ -3,7 +3,9 @@ MediaTek xHCI
 The device node for USB3 host controller on MediaTek SoCs.
 
 Required properties:
- - compatible : should be "mediatek,mtk-xhci"
+ - compatible : should be one of
+   "mediatek,mtk-xhci"
+   "mediatek,mt8195-xhci"
  - reg : specifies physical base address and size of the registers
  - reg-names: should be "mac" for xHCI MAC and "ippc" for IP port control
  - power-domains : a phandle to USB power domain node to control USB's
-- 
2.18.0



[PATCH v2 2/5] phy: phy-mtk-tphy: add support mt8195

2023-02-17 Thread Chunfeng Yun
The T-PHY controller is designed to use use PLL integer mode, but
in fact use fractional mode for some ones on mt8195 by mistake,
this causes signal degradation (e.g. eye diagram test fail), fix
it by switching PLL to 26Mhz from default 48Mhz to improve signal
quality.

Signed-off-by: Chunfeng Yun 
---
v2: use FIELD_PREP() macro
---
 drivers/phy/phy-mtk-tphy.c | 91 +-
 1 file changed, 81 insertions(+), 10 deletions(-)

diff --git a/drivers/phy/phy-mtk-tphy.c b/drivers/phy/phy-mtk-tphy.c
index 24e6124b76..1883f9f83e 100644
--- a/drivers/phy/phy-mtk-tphy.c
+++ b/drivers/phy/phy-mtk-tphy.c
@@ -44,8 +44,12 @@
 
 #define U3P_USBPHYACR0 0x000
 #define PA0_RG_U2PLL_FORCE_ON  BIT(15)
+#define PA0_USB20_PLL_PREDIV   GENMASK(7, 6)
 #define PA0_RG_USB20_INTR_EN   BIT(5)
 
+#define U3P_USBPHYACR2 0x008
+#define PA2_RG_U2PLL_BWGENMASK(21, 19)
+
 #define U3P_USBPHYACR5 0x014
 #define PA5_RG_U2_HSTX_SRCAL_ENBIT(15)
 #define PA5_RG_U2_HSTX_SRCTRL  GENMASK(14, 12)
@@ -62,6 +66,14 @@
 #define P2C_U2_GPIO_CTR_MSK\
(P2C_RG_USB20_GPIO_CTL | P2C_USB20_GPIO_MODE)
 
+#define U3P_U2PHYA_RESV0x030
+#define P2R_RG_U2PLL_FBDIV_26M 0x1bb13b
+#define P2R_RG_U2PLL_FBDIV_48M 0x3c
+
+#define U3P_U2PHYA_RESV1   0x044
+#define P2R_RG_U2PLL_REFCLK_SELBIT(5)
+#define P2R_RG_U2PLL_FRA_ENBIT(3)
+
 #define U3P_U2PHYDTM0  0x068
 #define P2C_FORCE_UART_EN  BIT(26)
 #define P2C_FORCE_DATAIN   BIT(23)
@@ -202,6 +214,17 @@ enum mtk_phy_version {
MTK_TPHY_V2,
 };
 
+struct tphy_pdata {
+   enum mtk_phy_version version;
+
+   /*
+* workaround only for mt8195:
+* u2phy should use integer mode instead of fractional mode of
+* 48M PLL, fix it by switching PLL to 26M from default 48M
+*/
+   bool sw_pll_48m_to_26m;
+};
+
 struct u2phy_banks {
void __iomem *misc;
void __iomem *fmreg;
@@ -232,11 +255,32 @@ struct mtk_phy_instance {
 struct mtk_tphy {
struct udevice *dev;
void __iomem *sif_base;
-   enum mtk_phy_version version;
+   const struct tphy_pdata *pdata;
struct mtk_phy_instance **phys;
int nphys;
 };
 
+/* workaround only for mt8195 */
+static void u2_phy_pll_26m_set(struct mtk_tphy *tphy,
+  struct mtk_phy_instance *instance)
+{
+   struct u2phy_banks *u2_banks = &instance->u2_banks;
+
+   if (!tphy->pdata->sw_pll_48m_to_26m)
+   return;
+
+   clrsetbits_le32(u2_banks->com + U3P_USBPHYACR0, PA0_USB20_PLL_PREDIV,
+   FIELD_PREP(PA0_USB20_PLL_PREDIV, 0));
+
+   clrsetbits_le32(u2_banks->com + U3P_USBPHYACR2, PA2_RG_U2PLL_BW,
+   FIELD_PREP(PA2_RG_U2PLL_BW, 3));
+
+   writel(P2R_RG_U2PLL_FBDIV_26M, u2_banks->com + U3P_U2PHYA_RESV);
+
+   setbits_le32(u2_banks->com + U3P_U2PHYA_RESV1,
+P2R_RG_U2PLL_FRA_EN | P2R_RG_U2PLL_REFCLK_SEL);
+}
+
 static void u2_phy_instance_init(struct mtk_tphy *tphy,
 struct mtk_phy_instance *instance)
 {
@@ -266,6 +310,8 @@ static void u2_phy_instance_init(struct mtk_tphy *tphy,
PA5_RG_U2_HSTX_SRCTRL,
FIELD_PREP(PA5_RG_U2_HSTX_SRCTRL, 4));
 
+   u2_phy_pll_26m_set(tphy, instance);
+
dev_dbg(tphy->dev, "%s(%d)\n", __func__, instance->index);
 }
 
@@ -350,7 +396,7 @@ static void pcie_phy_instance_init(struct mtk_tphy *tphy,
 {
struct u3phy_banks *u3_banks = &instance->u3_banks;
 
-   if (tphy->version != MTK_TPHY_V1)
+   if (tphy->pdata->version != MTK_TPHY_V1)
return;
 
clrsetbits_le32(u3_banks->phya + U3P_U3_PHYA_DA_REG0,
@@ -634,11 +680,14 @@ static int mtk_phy_xlate(struct phy *phy,
return -EINVAL;
}
 
-   if (tphy->version == MTK_TPHY_V1) {
+   switch (tphy->pdata->version) {
+   case MTK_TPHY_V1:
phy_v1_banks_init(tphy, instance);
-   } else if (tphy->version == MTK_TPHY_V2) {
+   break;
+   case MTK_TPHY_V2:
phy_v2_banks_init(tphy, instance);
-   } else {
+   break;
+   default:
dev_err(phy->dev, "phy version is not supported\n");
return -EINVAL;
}
@@ -668,13 +717,12 @@ static int mtk_tphy_probe(struct udevice *dev)
return -ENOMEM;
 
tphy->dev = dev;
-   tphy->version = dev_get_driver_data(dev);
+   tphy->pdata = (void *)dev_get_driver_data(dev);
 
/* v1 has shared banks for usb/pcie mode, */
/* but not for sata mode */
-   if (tphy->version == MTK_TPHY_V1) {
+ 

[PATCH v2 3/5] usb: xhci-mtk: modify the SOF/ITP interval for mt8195

2023-02-17 Thread Chunfeng Yun
There are 4 USB controllers on MT8195, the controllers (IP1~IP3,
exclude IP0) have a wrong default SOF/ITP interval which is
calculated from the frame counter clock 24Mhz by default, but
in fact, the frame counter clock is 48Mhz, so we shall set the
accurate interval according to 48Mhz for those controllers.

Note:
The first controller no need set it, but if set it, shall change
tphy's pll at the same time.

Signed-off-by: Chunfeng Yun 
---
v2: use FIELD_PREP() suggested by Marek
---
 drivers/usb/host/xhci-mtk.c | 49 -
 1 file changed, 48 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/host/xhci-mtk.c b/drivers/usb/host/xhci-mtk.c
index 3838a990ec..63dfb793c6 100644
--- a/drivers/usb/host/xhci-mtk.c
+++ b/drivers/usb/host/xhci-mtk.c
@@ -14,8 +14,9 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
+#include 
 #include 
 
 /* IPPC (IP Port Control) registers */
@@ -50,6 +51,25 @@
 #define IPPC_U3_CTRL(p)(IPPC_U3_CTRL_0P + ((p) * 0x08))
 #define IPPC_U2_CTRL(p)(IPPC_U2_CTRL_0P + ((p) * 0x08))
 
+/* xHCI CSR */
+#define LS_EOF_CFG 0x930
+#define LSEOF_OFFSET   0x89
+
+#define FS_EOF_CFG 0x934
+#define FSEOF_OFFSET   0x2e
+
+#define SS_GEN1_EOF_CFG0x93c
+#define SSG1EOF_OFFSET 0x78
+
+#define HFCNTR_CFG 0x944
+#define ITP_DELTA_CLK_MASK GENMASK(5, 1)
+#define FRMCNT_LEV1_RANG_MASK  GENMASK(19, 8)
+
+#define SS_GEN2_EOF_CFG0x990
+#define SSG2EOF_OFFSET 0x3c
+
+#define XSEOF_OFFSET_MASK  GENMASK(11, 0)
+
 struct mtk_xhci {
struct xhci_ctrl ctrl;  /* Needs to come first in this struct! */
struct xhci_hccr *hcd;
@@ -65,6 +85,30 @@ struct mtk_xhci {
u32 u2p_dis_msk;
 };
 
+/*
+ * workaround for mt8195:
+ * MT8195 has 4 controllers, the controller1~3's default SOF/ITP interval
+ * is calculated from the frame counter clock 24M, but in fact, the clock
+ * is 48M.
+ */
+static void xhci_mtk_set_frame_interval(struct mtk_xhci *mtk)
+{
+   void __iomem *mac = (void __iomem *)mtk->hcd;
+
+   if (!ofnode_device_is_compatible(dev_ofnode(mtk->dev), 
"mediatek,mt8195-xhci"))
+   return;
+
+   clrsetbits_le32(mac + HFCNTR_CFG,
+   ITP_DELTA_CLK_MASK | FRMCNT_LEV1_RANG_MASK,
+   FIELD_PREP(ITP_DELTA_CLK_MASK, 0xa) |
+   FIELD_PREP(FRMCNT_LEV1_RANG_MASK, 0x12b));
+
+   clrsetbits_le32(mac + LS_EOF_CFG, XSEOF_OFFSET_MASK, LSEOF_OFFSET);
+   clrsetbits_le32(mac + FS_EOF_CFG, XSEOF_OFFSET_MASK, FSEOF_OFFSET);
+   clrsetbits_le32(mac + SS_GEN1_EOF_CFG, XSEOF_OFFSET_MASK, 
SSG1EOF_OFFSET);
+   clrsetbits_le32(mac + SS_GEN2_EOF_CFG, XSEOF_OFFSET_MASK, 
SSG2EOF_OFFSET);
+}
+
 static int xhci_mtk_host_enable(struct mtk_xhci *mtk)
 {
int u3_ports_disabed = 0;
@@ -278,6 +322,8 @@ static int xhci_mtk_probe(struct udevice *dev)
if (ret)
goto ssusb_init_err;
 
+   xhci_mtk_set_frame_interval(mtk);
+
mtk->ctrl.quirks = XHCI_MTK_HOST;
hcor = (struct xhci_hcor *)((uintptr_t)mtk->hcd +
HC_LENGTH(xhci_readl(&mtk->hcd->cr_capbase)));
@@ -308,6 +354,7 @@ static int xhci_mtk_remove(struct udevice *dev)
 
 static const struct udevice_id xhci_mtk_ids[] = {
{ .compatible = "mediatek,mtk-xhci" },
+   { .compatible = "mediatek,mt8195-xhci" },
{ }
 };
 
-- 
2.18.0



[PATCH 3/4] dt-bindings: phy-mtk-tphy: add support mt8195

2023-02-10 Thread Chunfeng Yun
Add a new compatible for mt8195 to add a workaround for hardware
issue.

Signed-off-by: Chunfeng Yun 
---
 doc/device-tree-bindings/phy/phy-mtk-tphy.txt | 1 +
 1 file changed, 1 insertion(+)

diff --git a/doc/device-tree-bindings/phy/phy-mtk-tphy.txt 
b/doc/device-tree-bindings/phy/phy-mtk-tphy.txt
index 8cd23d8c0b..3042c39d09 100644
--- a/doc/device-tree-bindings/phy/phy-mtk-tphy.txt
+++ b/doc/device-tree-bindings/phy/phy-mtk-tphy.txt
@@ -8,6 +8,7 @@ Required properties (controller (parent) node):
  - compatible  : should be one of
  "mediatek,generic-tphy-v1"
  "mediatek,generic-tphy-v2"
+ "mediatek,mt8195-tphy"
 
 - #address-cells:  the number of cells used to represent physical
base addresses.
-- 
2.18.0



[PATCH 2/4] usb: xhci-mtk: modify the SOF/ITP interval for mt8195

2023-02-10 Thread Chunfeng Yun
There are 4 USB controllers on MT8195, the controllers (IP1~IP3,
exclude IP0) have a wrong default SOF/ITP interval which is
calculated from the frame counter clock 24Mhz by default, but
in fact, the frame counter clock is 48Mhz, so we shall set the
accurate interval according to 48Mhz for those controllers.

Note:
The first controller no need set it, but if set it, shall change
tphy's pll at the same time.

Signed-off-by: Chunfeng Yun 
---
 drivers/usb/host/xhci-mtk.c | 47 +
 1 file changed, 47 insertions(+)

diff --git a/drivers/usb/host/xhci-mtk.c b/drivers/usb/host/xhci-mtk.c
index 3838a990ec..46f8039960 100644
--- a/drivers/usb/host/xhci-mtk.c
+++ b/drivers/usb/host/xhci-mtk.c
@@ -50,6 +50,27 @@
 #define IPPC_U3_CTRL(p)(IPPC_U3_CTRL_0P + ((p) * 0x08))
 #define IPPC_U2_CTRL(p)(IPPC_U2_CTRL_0P + ((p) * 0x08))
 
+/* xHCI CSR */
+#define LS_EOF_CFG 0x930
+#define LSEOF_OFFSET   0x89
+
+#define FS_EOF_CFG 0x934
+#define FSEOF_OFFSET   0x2e
+
+#define SS_GEN1_EOF_CFG0x93c
+#define SSG1EOF_OFFSET 0x78
+
+#define HFCNTR_CFG 0x944
+#define ITP_DELTA_CLK  (0xa << 1)
+#define ITP_DELTA_CLK_MASK GENMASK(5, 1)
+#define FRMCNT_LEV1_RANG   (0x12b << 8)
+#define FRMCNT_LEV1_RANG_MASK  GENMASK(19, 8)
+
+#define SS_GEN2_EOF_CFG0x990
+#define SSG2EOF_OFFSET 0x3c
+
+#define XSEOF_OFFSET_MASK  GENMASK(11, 0)
+
 struct mtk_xhci {
struct xhci_ctrl ctrl;  /* Needs to come first in this struct! */
struct xhci_hccr *hcd;
@@ -65,6 +86,29 @@ struct mtk_xhci {
u32 u2p_dis_msk;
 };
 
+/*
+ * workaround for mt8195:
+ * MT8195 has 4 controllers, the controller1~3's default SOF/ITP interval
+ * is calculated from the frame counter clock 24M, but in fact, the clock
+ * is 48M.
+ */
+static void xhci_mtk_set_frame_interval(struct mtk_xhci *mtk)
+{
+   void __iomem *mac = (void __iomem *)mtk->hcd;
+
+   if (!ofnode_device_is_compatible(dev_ofnode(mtk->dev), 
"mediatek,mt8195-xhci"))
+   return;
+
+   clrsetbits_le32(mac + HFCNTR_CFG,
+   ITP_DELTA_CLK_MASK | FRMCNT_LEV1_RANG_MASK,
+   ITP_DELTA_CLK | FRMCNT_LEV1_RANG);
+
+   clrsetbits_le32(mac + LS_EOF_CFG, XSEOF_OFFSET_MASK, LSEOF_OFFSET);
+   clrsetbits_le32(mac + FS_EOF_CFG, XSEOF_OFFSET_MASK, FSEOF_OFFSET);
+   clrsetbits_le32(mac + SS_GEN1_EOF_CFG, XSEOF_OFFSET_MASK, 
SSG1EOF_OFFSET);
+   clrsetbits_le32(mac + SS_GEN2_EOF_CFG, XSEOF_OFFSET_MASK, 
SSG2EOF_OFFSET);
+}
+
 static int xhci_mtk_host_enable(struct mtk_xhci *mtk)
 {
int u3_ports_disabed = 0;
@@ -278,6 +322,8 @@ static int xhci_mtk_probe(struct udevice *dev)
if (ret)
goto ssusb_init_err;
 
+   xhci_mtk_set_frame_interval(mtk);
+
mtk->ctrl.quirks = XHCI_MTK_HOST;
hcor = (struct xhci_hcor *)((uintptr_t)mtk->hcd +
HC_LENGTH(xhci_readl(&mtk->hcd->cr_capbase)));
@@ -308,6 +354,7 @@ static int xhci_mtk_remove(struct udevice *dev)
 
 static const struct udevice_id xhci_mtk_ids[] = {
{ .compatible = "mediatek,mtk-xhci" },
+   { .compatible = "mediatek,mt8195-xhci" },
{ }
 };
 
-- 
2.18.0



[PATCH 4/4] dt-bindings: usb: mtk-xhci: add support mt8195

2023-02-10 Thread Chunfeng Yun
Add a new compatible for mt8195 to add a workaround for hardware
issue.

Signed-off-by: Chunfeng Yun 
---
 doc/device-tree-bindings/usb/mediatek,mtk-xhci.txt | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/doc/device-tree-bindings/usb/mediatek,mtk-xhci.txt 
b/doc/device-tree-bindings/usb/mediatek,mtk-xhci.txt
index 2a298f7b16..e26e9618eb 100644
--- a/doc/device-tree-bindings/usb/mediatek,mtk-xhci.txt
+++ b/doc/device-tree-bindings/usb/mediatek,mtk-xhci.txt
@@ -3,7 +3,9 @@ MediaTek xHCI
 The device node for USB3 host controller on MediaTek SoCs.
 
 Required properties:
- - compatible : should be "mediatek,mtk-xhci"
+ - compatible : should be one of
+   "mediatek,mtk-xhci"
+   "mediatek,mt8195-xhci"
  - reg : specifies physical base address and size of the registers
  - reg-names: should be "mac" for xHCI MAC and "ippc" for IP port control
  - power-domains : a phandle to USB power domain node to control USB's
-- 
2.18.0



[PATCH 1/4] phy: phy-mtk-tphy: add support mt8195

2023-02-10 Thread Chunfeng Yun
The T-PHY controller is designed to use use PLL integer mode, but
in fact use fractional mode for some ones on mt8195 by mistake,
this causes signal degradation (e.g. eye diagram test fail), fix
it by switching PLL to 26Mhz from default 48Mhz to improve signal
quality.

Signed-off-by: Chunfeng Yun 
---
 drivers/phy/phy-mtk-tphy.c | 93 ++
 1 file changed, 83 insertions(+), 10 deletions(-)

diff --git a/drivers/phy/phy-mtk-tphy.c b/drivers/phy/phy-mtk-tphy.c
index 2dd964f7b2..bdad0053d4 100644
--- a/drivers/phy/phy-mtk-tphy.c
+++ b/drivers/phy/phy-mtk-tphy.c
@@ -43,8 +43,14 @@
 
 #define U3P_USBPHYACR0 0x000
 #define PA0_RG_U2PLL_FORCE_ON  BIT(15)
+#define PA0_USB20_PLL_PREDIV   GENMASK(7, 6)
+#define PA0_USB20_PLL_PREDIV_VAL(x)((0x3 & (x)) << 6)
 #define PA0_RG_USB20_INTR_EN   BIT(5)
 
+#define U3P_USBPHYACR2 0x008
+#define PA2_RG_U2PLL_BWGENMASK(21, 19)
+#define PA2_RG_U2PLL_BW_VAL(x) ((0x7 & (x)) << 19)
+
 #define U3P_USBPHYACR5 0x014
 #define PA5_RG_U2_HSTX_SRCAL_ENBIT(15)
 #define PA5_RG_U2_HSTX_SRCTRL  GENMASK(14, 12)
@@ -63,6 +69,14 @@
 #define P2C_U2_GPIO_CTR_MSK\
(P2C_RG_USB20_GPIO_CTL | P2C_USB20_GPIO_MODE)
 
+#define U3P_U2PHYA_RESV0x030
+#define P2R_RG_U2PLL_FBDIV_26M 0x1bb13b
+#define P2R_RG_U2PLL_FBDIV_48M 0x3c
+
+#define U3P_U2PHYA_RESV1   0x044
+#define P2R_RG_U2PLL_REFCLK_SELBIT(5)
+#define P2R_RG_U2PLL_FRA_ENBIT(3)
+
 #define U3P_U2PHYDTM0  0x068
 #define P2C_FORCE_UART_EN  BIT(26)
 #define P2C_FORCE_DATAIN   BIT(23)
@@ -239,6 +253,17 @@ enum mtk_phy_version {
MTK_TPHY_V2,
 };
 
+struct tphy_pdata {
+   enum mtk_phy_version version;
+
+   /*
+* workaround only for mt8195:
+* u2phy should use integer mode instead of fractional mode of
+* 48M PLL, fix it by switching PLL to 26M from default 48M
+*/
+   bool sw_pll_48m_to_26m;
+};
+
 struct u2phy_banks {
void __iomem *misc;
void __iomem *fmreg;
@@ -269,11 +294,32 @@ struct mtk_phy_instance {
 struct mtk_tphy {
struct udevice *dev;
void __iomem *sif_base;
-   enum mtk_phy_version version;
+   const struct tphy_pdata *pdata;
struct mtk_phy_instance **phys;
int nphys;
 };
 
+/* workaround only for mt8195 */
+static void u2_phy_pll_26m_set(struct mtk_tphy *tphy,
+  struct mtk_phy_instance *instance)
+{
+   struct u2phy_banks *u2_banks = &instance->u2_banks;
+
+   if (!tphy->pdata->sw_pll_48m_to_26m)
+   return;
+
+   clrsetbits_le32(u2_banks->com + U3P_USBPHYACR0, PA0_USB20_PLL_PREDIV,
+   PA0_USB20_PLL_PREDIV_VAL(0));
+
+   clrsetbits_le32(u2_banks->com + U3P_USBPHYACR2, PA2_RG_U2PLL_BW,
+   PA2_RG_U2PLL_BW_VAL(3));
+
+   writel(P2R_RG_U2PLL_FBDIV_26M, u2_banks->com + U3P_U2PHYA_RESV);
+
+   setbits_le32(u2_banks->com + U3P_U2PHYA_RESV1,
+P2R_RG_U2PLL_FRA_EN | P2R_RG_U2PLL_REFCLK_SEL);
+}
+
 static void u2_phy_instance_init(struct mtk_tphy *tphy,
 struct mtk_phy_instance *instance)
 {
@@ -301,6 +347,8 @@ static void u2_phy_instance_init(struct mtk_tphy *tphy,
clrsetbits_le32(u2_banks->com + U3P_USBPHYACR5,
PA5_RG_U2_HSTX_SRCTRL, PA5_RG_U2_HSTX_SRCTRL_VAL(4));
 
+   u2_phy_pll_26m_set(tphy, instance);
+
dev_dbg(tphy->dev, "%s(%d)\n", __func__, instance->index);
 }
 
@@ -382,7 +430,7 @@ static void pcie_phy_instance_init(struct mtk_tphy *tphy,
 {
struct u3phy_banks *u3_banks = &instance->u3_banks;
 
-   if (tphy->version != MTK_TPHY_V1)
+   if (tphy->pdata->version != MTK_TPHY_V1)
return;
 
clrsetbits_le32(u3_banks->phya + U3P_U3_PHYA_DA_REG0,
@@ -662,11 +710,14 @@ static int mtk_phy_xlate(struct phy *phy,
return -EINVAL;
}
 
-   if (tphy->version == MTK_TPHY_V1) {
+   switch (tphy->pdata->version) {
+   case MTK_TPHY_V1:
phy_v1_banks_init(tphy, instance);
-   } else if (tphy->version == MTK_TPHY_V2) {
+   break;
+   case MTK_TPHY_V2:
phy_v2_banks_init(tphy, instance);
-   } else {
+   break;
+   default:
dev_err(phy->dev, "phy version is not supported\n");
return -EINVAL;
}
@@ -696,13 +747,12 @@ static int mtk_tphy_probe(struct udevice *dev)
return -ENOMEM;
 
tphy->dev = dev;
-   tphy->version = dev_get_driver_data(dev);
+   tphy->pdata = (void *)dev_get_driver_data(dev);
 
/* v1 has shared banks f

Re: [RESEND PATCH] usb: mtu3: flush cache for the first GPD when allocate GPD ring

2021-11-12 Thread Chunfeng Yun
Hi Marek,

On Thu, 2021-10-21 at 13:33 +0800, Chunfeng Yun wrote:
> When allocate the GPD ring, and tell its address to the controller,
> then
> the driver starts or resumes the QMU, the controller will try to
> access
> the first GPD, so need flush the first one to avoid wrong GPD status.
> 
> Reported-by: Xin Lin 
> Signed-off-by: Chunfeng Yun 
> ---
>  drivers/usb/mtu3/mtu3_qmu.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/usb/mtu3/mtu3_qmu.c
> b/drivers/usb/mtu3/mtu3_qmu.c
> index 95eaf6d236..e8dc0095ab 100644
> --- a/drivers/usb/mtu3/mtu3_qmu.c
> +++ b/drivers/usb/mtu3/mtu3_qmu.c
> @@ -112,6 +112,7 @@ int mtu3_gpd_ring_alloc(struct mtu3_ep *mep)
>   memset(gpd, 0, QMU_GPD_RING_SIZE);
>   ring->dma = (dma_addr_t)gpd;
>   gpd_ring_init(ring, gpd);
> + mtu3_flush_cache((uintptr_t)gpd, sizeof(*gpd));
>  
>   return 0;
>  }
Could you please pick up this patch?

Thanks



Re: [RESEND PATCH] usb: mtu3: flush cache for the first GPD when allocate GPD ring

2021-11-12 Thread Chunfeng Yun
Hi Marek,

On Thu, 2021-10-21 at 13:33 +0800, Chunfeng Yun wrote:
> When allocate the GPD ring, and tell its address to the controller,
> then
> the driver starts or resumes the QMU, the controller will try to
> access
> the first GPD, so need flush the first one to avoid wrong GPD status.
> 
> Reported-by: Xin Lin 
> Signed-off-by: Chunfeng Yun 
> ---
>  drivers/usb/mtu3/mtu3_qmu.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/usb/mtu3/mtu3_qmu.c
> b/drivers/usb/mtu3/mtu3_qmu.c
> index 95eaf6d236..e8dc0095ab 100644
> --- a/drivers/usb/mtu3/mtu3_qmu.c
> +++ b/drivers/usb/mtu3/mtu3_qmu.c
> @@ -112,6 +112,7 @@ int mtu3_gpd_ring_alloc(struct mtu3_ep *mep)
>   memset(gpd, 0, QMU_GPD_RING_SIZE);
>   ring->dma = (dma_addr_t)gpd;
>   gpd_ring_init(ring, gpd);
> + mtu3_flush_cache((uintptr_t)gpd, sizeof(*gpd));
>  
>   return 0;
>  }
Could you please pick up this patch?

Thanks



Re: [RESEND PATCH] usb: mtu3: flush cache for the first GPD when allocate GPD ring

2021-11-12 Thread Chunfeng Yun
Hi Marek,

On Thu, 2021-10-21 at 13:33 +0800, Chunfeng Yun wrote:
> When allocate the GPD ring, and tell its address to the controller,
> then
> the driver starts or resumes the QMU, the controller will try to
> access
> the first GPD, so need flush the first one to avoid wrong GPD status.
> 
> Reported-by: Xin Lin 
> Signed-off-by: Chunfeng Yun 
> ---
>  drivers/usb/mtu3/mtu3_qmu.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/usb/mtu3/mtu3_qmu.c
> b/drivers/usb/mtu3/mtu3_qmu.c
> index 95eaf6d236..e8dc0095ab 100644
> --- a/drivers/usb/mtu3/mtu3_qmu.c
> +++ b/drivers/usb/mtu3/mtu3_qmu.c
> @@ -112,6 +112,7 @@ int mtu3_gpd_ring_alloc(struct mtu3_ep *mep)
>   memset(gpd, 0, QMU_GPD_RING_SIZE);
>   ring->dma = (dma_addr_t)gpd;
>   gpd_ring_init(ring, gpd);
> + mtu3_flush_cache((uintptr_t)gpd, sizeof(*gpd));
>  
>   return 0;
>  }

Could you please pick up this patch?

Thanks



Re: [RESEND PATCH] usb: mtu3: flush cache for the first GPD when allocate GPD ring

2021-11-12 Thread Chunfeng Yun
Hi Marek,

On Thu, 2021-10-21 at 13:33 +0800, Chunfeng Yun wrote:
> When allocate the GPD ring, and tell its address to the controller,
> then
> the driver starts or resumes the QMU, the controller will try to
> access
> the first GPD, so need flush the first one to avoid wrong GPD status.
> 
> Reported-by: Xin Lin 
> Signed-off-by: Chunfeng Yun 
> ---
>  drivers/usb/mtu3/mtu3_qmu.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/usb/mtu3/mtu3_qmu.c
> b/drivers/usb/mtu3/mtu3_qmu.c
> index 95eaf6d236..e8dc0095ab 100644
> --- a/drivers/usb/mtu3/mtu3_qmu.c
> +++ b/drivers/usb/mtu3/mtu3_qmu.c
> @@ -112,6 +112,7 @@ int mtu3_gpd_ring_alloc(struct mtu3_ep *mep)
>   memset(gpd, 0, QMU_GPD_RING_SIZE);
>   ring->dma = (dma_addr_t)gpd;
>   gpd_ring_init(ring, gpd);
> + mtu3_flush_cache((uintptr_t)gpd, sizeof(*gpd));
>  
>   return 0;
>  }

Could you please pick up this patch?

Thanks



Re: [RESEND PATCH] usb: mtu3: flush cache for the first GPD when allocate GPD ring

2021-11-02 Thread Chunfeng Yun
Hi Marek,

On Thu, 2021-10-21 at 13:33 +0800, Chunfeng Yun wrote:
> When allocate the GPD ring, and tell its address to the controller,
> then
> the driver starts or resumes the QMU, the controller will try to
> access
> the first GPD, so need flush the first one to avoid wrong GPD status.
> 
> Reported-by: Xin Lin 
> Signed-off-by: Chunfeng Yun 
> ---
>  drivers/usb/mtu3/mtu3_qmu.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/usb/mtu3/mtu3_qmu.c
> b/drivers/usb/mtu3/mtu3_qmu.c
> index 95eaf6d236..e8dc0095ab 100644
> --- a/drivers/usb/mtu3/mtu3_qmu.c
> +++ b/drivers/usb/mtu3/mtu3_qmu.c
> @@ -112,6 +112,7 @@ int mtu3_gpd_ring_alloc(struct mtu3_ep *mep)
>   memset(gpd, 0, QMU_GPD_RING_SIZE);
>   ring->dma = (dma_addr_t)gpd;
>   gpd_ring_init(ring, gpd);
> + mtu3_flush_cache((uintptr_t)gpd, sizeof(*gpd));
>  
>   return 0;
>  }
Could you please pick up this patch?

Thanks



[RESEND PATCH] usb: mtu3: flush cache for the first GPD when allocate GPD ring

2021-10-20 Thread Chunfeng Yun
When allocate the GPD ring, and tell its address to the controller, then
the driver starts or resumes the QMU, the controller will try to access
the first GPD, so need flush the first one to avoid wrong GPD status.

Reported-by: Xin Lin 
Signed-off-by: Chunfeng Yun 
---
 drivers/usb/mtu3/mtu3_qmu.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/usb/mtu3/mtu3_qmu.c b/drivers/usb/mtu3/mtu3_qmu.c
index 95eaf6d236..e8dc0095ab 100644
--- a/drivers/usb/mtu3/mtu3_qmu.c
+++ b/drivers/usb/mtu3/mtu3_qmu.c
@@ -112,6 +112,7 @@ int mtu3_gpd_ring_alloc(struct mtu3_ep *mep)
memset(gpd, 0, QMU_GPD_RING_SIZE);
ring->dma = (dma_addr_t)gpd;
gpd_ring_init(ring, gpd);
+   mtu3_flush_cache((uintptr_t)gpd, sizeof(*gpd));
 
return 0;
 }
-- 
2.25.1



[PATCH] usb: mtu3: flush cache for the first GPD when allocate GPD ring

2021-09-22 Thread Chunfeng Yun
When allocate the GPD ring, and tell its address to the controller, then
the driver starts or resumes the QMU, the controller will try to access
the first GPD, so need flush the first one to avoid wrong GPD status.

Reported-by: Xin Lin 
Signed-off-by: Chunfeng Yun 
---
 drivers/usb/mtu3/mtu3_qmu.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/usb/mtu3/mtu3_qmu.c b/drivers/usb/mtu3/mtu3_qmu.c
index 95eaf6d236..e8dc0095ab 100644
--- a/drivers/usb/mtu3/mtu3_qmu.c
+++ b/drivers/usb/mtu3/mtu3_qmu.c
@@ -112,6 +112,7 @@ int mtu3_gpd_ring_alloc(struct mtu3_ep *mep)
memset(gpd, 0, QMU_GPD_RING_SIZE);
ring->dma = (dma_addr_t)gpd;
gpd_ring_init(ring, gpd);
+   mtu3_flush_cache((uintptr_t)gpd, sizeof(*gpd));
 
return 0;
 }
-- 
2.25.1



Re: USB 3.1 (3.2) support in U-Boot?

2021-04-26 Thread Chunfeng Yun
On Mon, 2021-04-26 at 20:22 +0800, Bin Meng wrote:
> Hi Stefan,
> 
> On Mon, Apr 26, 2021 at 6:21 PM Stefan Roese  wrote:
> >
> > Hi All,
> >
> > does anyone know of the USB 3.1 support status in mainline U-Boot? I've
> > only seen these related patches:
> >
> > commit d92e866f6008fdd6483735c6fd1ed95c8fdc87b1
> > Author: Chunfeng Yun 
> > Date:   Wed Oct 14 15:08:28 2020 +0800
> >
> >  usb: common: add define of usb_speed_string()
> >
> >  There is only declaration of usb_speed_string(), but no definition,
> >  so add it to avoid build error when call it.
> >
> >  Signed-off-by: Chunfeng Yun 
> >  Reviewed-by: Bin Meng 
> >
> > commit a4de6e380fd1078c3f06210a0be0f3f8a69062dc
> > Author: Chunfeng Yun 
> > Date:   Wed Oct 14 15:08:27 2020 +0800
> >
> >  usb: add USB_SPEED_SUPER_PLUS
> >
> >  Add enum USB_SPEED_SUPER_PLUS for USB3.1
> >
> >  Signed-off-by: Chunfeng Yun 
> >  Reviewed-by: Bin Meng 
> >
> >
> > With no real functional changes. So has anyone already successfully
> > tested an USB 3.1 controller in recent U-Boot?
> 
> I have not tested USB 3.1/3.2 in U-Boot. Maybe Chunfeng did.

I only tested USB 3.2 GEN1 (5G), didn't test USB3.2 GEN2, added this
enum just for building pass

> 
> Regards,
> Bin



Re: [PATCH 2/3] ARM: mediatek: Add MT8175 support

2021-03-31 Thread Chunfeng Yun
t; + };
> +
> + u2port1: usb-phy@1000 {
> + reg = <0x1000 0x400>;
> +         clocks = <&topckgen_cg CLK_TOP_SSUSB_PHY_CK_EN>,
> +  <&topckgen_cg CLK_TOP_USB20_48M_EN>;
> + clock-names = "ref", "da_ref";
> + #phy-cells = <1>;
> + status = "okay";
> + };
> + };
> +
> + usb: usb@11201000 {
> + compatible ="mediatek,mt8175-mtu3", "mediatek,mtu3";
> + reg = <0 0x11203e00 0 0x0100>;
> + reg-names = "ippc";
> + phys = <&u2port0 PHY_TYPE_USB2>,
> +<&u2port1 PHY_TYPE_USB2>;
> + clocks = <&topckgen_cg CLK_TOP_SSUSB_TOP_CK_EN>,
> +  <&infracfg CLK_IFR_SSUSB_REF>,
> +  <&infracfg CLK_IFR_SSUSB_SYS>,
> +  <&infracfg CLK_IFR_ICUSB>;
> + clock-names = "sys_ck", "ref_ck", "mcu_ck",
> +   "dma_ck";
> + #address-cells = <2>;
> + #size-cells = <2>;
> + ranges;
> + status = "disabled";
> +
> + ssusb: ssusb@1120 {
> + compatible = "mediatek,ssusb";
> + reg = <0 0x1120 0 0x3e00>;
> + reg-names = "mac";
> + interrupts = ;
> + status = "disabled";
> + };
> + };
> + };
> +};

For usb / phy nodes:

Reviewed-by: Chunfeng Yun 

Thanks a lot

> diff --git a/arch/arm/mach-mediatek/Kconfig b/arch/arm/mach-mediatek/Kconfig
> index e067604d9b39..4a91fb764175 100644
> --- a/arch/arm/mach-mediatek/Kconfig
> +++ b/arch/arm/mach-mediatek/Kconfig
> @@ -41,6 +41,14 @@ config TARGET_MT7629
> including DDR3, crypto engine, 3x3 11n/ac Wi-Fi, Gigabit Ethernet,
> switch, USB3.0, PCIe, UART, SPI, I2C and PWM.
>  
> +config TARGET_MT8175
> + bool "MediaTek MT8175 SoC"
> + select ARM64
> + help
> +   The MediaTek MT8175 is a ARM64-based SoC with a quad-core Cortex-A53.
> +   It is including UART, SPI, USB2.0 dual role, SD and MMC cards, NAND, 
> PWM,
> +   I2C, I2S, S/PDIF, and several LPDDR3 and LPDDR4 options.
> +
>  config TARGET_MT8183
>   bool "MediaTek MT8183 SoC"
>   select ARM64
> @@ -83,6 +91,7 @@ endchoice
>  source "board/mediatek/mt7622/Kconfig"
>  source "board/mediatek/mt7623/Kconfig"
>  source "board/mediatek/mt7629/Kconfig"
> +source "board/mediatek/mt8175/Kconfig"
>  source "board/mediatek/mt8183/Kconfig"
>  source "board/mediatek/mt8512/Kconfig"
>  source "board/mediatek/mt8516/Kconfig"
> diff --git a/arch/arm/mach-mediatek/Makefile b/arch/arm/mach-mediatek/Makefile
> index 0f5b0c16d2cb..ba030fb0b373 100644
> --- a/arch/arm/mach-mediatek/Makefile
> +++ b/arch/arm/mach-mediatek/Makefile
> @@ -7,6 +7,7 @@ obj-$(CONFIG_MT8512) += mt8512/
>  obj-$(CONFIG_TARGET_MT7622) += mt7622/
>  obj-$(CONFIG_TARGET_MT7623) += mt7623/
>  obj-$(CONFIG_TARGET_MT7629) += mt7629/
> +obj-$(CONFIG_TARGET_MT8175) += mt8175/
>  obj-$(CONFIG_TARGET_MT8183) += mt8183/
>  obj-$(CONFIG_TARGET_MT8516) += mt8516/
>  obj-$(CONFIG_TARGET_MT8518) += mt8518/
> diff --git a/arch/arm/mach-mediatek/mt8175/Makefile 
> b/arch/arm/mach-mediatek/mt8175/Makefile
> new file mode 100644
> index ..886ab7e4eb9f
> --- /dev/null
> +++ b/arch/arm/mach-mediatek/mt8175/Makefile
> @@ -0,0 +1,3 @@
> +# SPDX-License-Identifier:   GPL-2.0
> +
> +obj-y += init.o
> diff --git a/arch/arm/mach-mediatek/mt8175/init.c 
> b/arch/arm/mach-mediatek/mt8175/init.c
> new file mode 100644
> index ..5161c1ce78d5
> --- /dev/null
> +++ b/arch/arm/mach-mediatek/mt8175/init.c
> @@ -0,0 +1,75 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Copyright (C) 2021 MediaTek Inc.
> + * Copyright (C) 2021 BayLibre, SAS
> + * Author: Fabien Parent 
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +DECLARE_GLOBAL_DATA_PTR;
> +
> +int dram_init(void)
> +{
> + int ret;
> +
> + ret = fdtdec_setup_memory_banksize();
> + if (ret)
> + return ret;
> +
> + return fdtdec_setup_mem_size_base();
> +}
> +
> +int dram_init_banksize(void)
> +{
> + gd->bd->bi_dram[0].start = gd->ram_base;
> + gd->bd->bi_dram[0].size = gd->ram_size;
> +
> + return 0;
> +}
> +
> +int mtk_pll_early_init(void)
> +{
> + return 0;
> +}
> +
> +int mtk_soc_early_init(void)
> +{
> + return 0;
> +}
> +
> +void reset_cpu(ulong addr)
> +{
> + psci_system_reset();
> +}
> +
> +int print_cpuinfo(void)
> +{
> + printf("CPU:   MediaTek MT8175\n");
> + return 0;
> +}
> +
> +static struct mm_region mt8175_mem_map[] = {
> + {
> + /* DDR */
> + .virt = 0x4000UL,
> + .phys = 0x4000UL,
> + .size = 0x4000UL,
> + .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | PTE_BLOCK_OUTER_SHARE,
> + }, {
> + .virt = 0xUL,
> + .phys = 0xUL,
> + .size = 0x2000UL,
> + .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
> +  PTE_BLOCK_NON_SHARE |
> +  PTE_BLOCK_PXN | PTE_BLOCK_UXN
> + }, {
> + 0,
> + }
> +};
> +
> +struct mm_region *mem_map = mt8175_mem_map;



Re: [PATCH 2/3] ARM: mediatek: Add MT8175 support

2021-03-29 Thread Chunfeng Yun
On Mon, 2021-03-29 at 21:27 +0200, Fabien Parent wrote:
> Add MT8175 SoC support.
> 
> Signed-off-by: Fabien Parent 
> ---
>  arch/arm/dts/mt8175.dtsi   | 247 +
>  arch/arm/mach-mediatek/Kconfig |   9 +
>  arch/arm/mach-mediatek/Makefile|   1 +
>  arch/arm/mach-mediatek/mt8175/Makefile |   3 +
>  arch/arm/mach-mediatek/mt8175/init.c   |  75 
>  5 files changed, 335 insertions(+)
>  create mode 100644 arch/arm/dts/mt8175.dtsi
>  create mode 100644 arch/arm/mach-mediatek/mt8175/Makefile
>  create mode 100644 arch/arm/mach-mediatek/mt8175/init.c
> 
> diff --git a/arch/arm/dts/mt8175.dtsi b/arch/arm/dts/mt8175.dtsi
> new file mode 100644
> index ..98320e44cd5c
> --- /dev/null
> +++ b/arch/arm/dts/mt8175.dtsi
> @@ -0,0 +1,247 @@
> +// SPDX-License-Identifier: (GPL-2.0 OR MIT)
> +/*
> + * Copyright (C) 2021 MediaTek Inc.
> + * Copyright (C) 2021 BayLibre, SAS
> + * Author: Ben Ho 
> + * Erin Lo 
> + * Fabien Parent 
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +/ {
> + compatible = "mediatek,mt8175";
> + interrupt-parent = <&sysirq>;
> + #address-cells = <2>;
> + #size-cells = <2>;
> +
> + cpus {
> + #address-cells = <1>;
> + #size-cells = <0>;
[...]
> + uart2: uart2@11004000 {
> + compatible = "mediatek,mt8175-uart",
> +  "mediatek,hsuart";
> + reg = <0 0x11004000 0 0x1000>;
> + interrupts = ;
> + clocks = <&topckgen CLK_TOP_CLK26M>, <&infracfg 
> CLK_IFR_UART2>;
> + clock-names = "baud", "bus";
> + status = "disabled";
> + };
> +
> + mmc0: mmc@1123 {
> + compatible = "mediatek,mt8175-mmc", 
> "mediatek,mt8183-mmc";
> + reg = <0 0x1123 0 0x1000>,
> +   <0 0x11cd 0 0x1000>;
> + interrupts = ;
> + clocks = <&topckgen CLK_TOP_MSDC50_0_SEL>,
> +  <&infracfg CLK_IFR_MSDC0_HCLK>,
> +  <&infracfg CLK_IFR_MSDC0_SRC>;
> + clock-names = "source", "hclk", "source_cg";
> + status = "disabled";
> + };
> +
> + u3phy: usb-phy@11cc {
> + compatible = "mediatek,generic-tphy-v2";
> + #address-cells = <2>;
<1>
> + #size-cells = <2>;
<1>
> + ranges;
Please use  as following,

ranges = <0 0 0x11cc 0x2000>;

> + status = "okay";
> +
> + u2port0: usb-phy@11cc {
u2port0: usb-phy@0
> + reg = <0 0x11cc 0 0x400>;
reg = <0 0x400>;
> + clocks = <&topckgen_cg CLK_TOP_SSUSB_PHY_CK_EN>,
> +  <&topckgen_cg CLK_TOP_USB20_48M_EN>;
> + clock-names = "ref", "da_ref";
> + #phy-cells = <1>;
> + status = "okay";
> + };
> +
> + u2port1: usb-phy@11cc1000 {
u2port1: usb-phy@1000
> + reg = <0 0x11cc1000 0 0x400>;
reg = <0x1000 0x400>;
> + clocks = <&topckgen_cg CLK_TOP_SSUSB_PHY_CK_EN>,
> +  <&topckgen_cg CLK_TOP_USB20_48M_EN>;
> + clock-names = "ref", "da_ref";
> + #phy-cells = <1>;
> + status = "okay";
> + };
> + };
> +
> + usb: usb@11201000 {
> + compatible ="mediatek,mt8175-mtu3", "mediatek,mtu3";
> + reg = <0 0x1120 0 0x3e00>,
> +   <0 0x11203e00 0 0x0100>;
> + reg-names = "mac", "ippc";
No need mac reg, it's in subnode
> + interrupts = ;
remove it, it's also in subnode

> + phys = <&u2port0 PHY_TYPE_USB2>,
> +<&u2port1 PHY_TYPE_USB2>;
> + clocks = <&topckgen_cg CLK_TOP_SSUSB_TOP_CK_EN>,
> +  <&infracfg CLK_IFR_SSUSB_REF>,
> +  <&infracfg CLK_IFR_SSUSB_SYS>,
> +  <&infracfg CLK_IFR_ICUSB>;
> + clock-names = "sys_ck", "ref_ck", "mcu_ck",
> +   "dma_ck";
> + #address-cells = <2>;
> + #size-cells = <2>;
> + ranges;
> + status = "disabled";
> +
> + ssusb: ssusb@1120 {
> + compatible = "mediatek,ssusb";
> + reg = <0 0x1120 0 0x3e00>;
> +

Re: [PATCH 3/3] board: Add MT8175 pumpkin board support

2021-03-29 Thread Chunfeng Yun
is not set
> +CONFIG_OF_LIBFDT_OVERLAY=y
> +# CONFIG_EFI_LOADER is not set
> diff --git a/include/configs/mt8175.h b/include/configs/mt8175.h
> new file mode 100644
> index ..1f7a8032a65f
> --- /dev/null
> +++ b/include/configs/mt8175.h
> @@ -0,0 +1,41 @@
> +/* SPDX-License-Identifier: GPL-2.0+ */
> +/*
> + * Configuration for MT8175 based boards
> + *
> + * Copyright (C) 2021 BayLibre, SAS
> + * Author: Fabien Parent  + */
> +
> +#ifndef __MT8175_H
> +#define __MT8175_H
> +
> +#include 
> +
> +#define CONFIG_SYS_LOAD_ADDR CONFIG_SYS_TEXT_BASE
> +#define CONFIG_SYS_MALLOC_LENSZ_4M
> +
> +#define CONFIG_CPU_ARMV8
> +#define COUNTER_FREQUENCY1300
> +
> +#define CONFIG_SYS_NS16550_SERIAL
> +#define CONFIG_SYS_NS16550_REG_SIZE  -4
> +#define CONFIG_SYS_NS16550_MEM32
> +#define CONFIG_SYS_NS16550_COM1  0x11005200
> +#define CONFIG_SYS_NS16550_CLK   2600
> +
> +#define CONFIG_SYS_INIT_SP_ADDR  (CONFIG_SYS_TEXT_BASE + SZ_2M - 
> \
> +  GENERATED_GBL_DATA_SIZE)
> +
> +#define CONFIG_SYS_BOOTM_LEN SZ_64M
> +
> +/* Environment settings */
> +#include 
> +
> +#define BOOT_TARGET_DEVICES(func) \
> + func(MMC, mmc, 0)
> +
> +#define CONFIG_EXTRA_ENV_SETTINGS \
> + "scriptaddr=0x4000\0" \
> + BOOTENV
> +
> +#endif

For usb related:

Reviewed-by: Chunfeng Yun 

Thanks a lot




[PATCH] usb: mtu3: flush cache for next GPD

2021-03-03 Thread Chunfeng Yun
When flush cache of the current GPD and resume QMU, the controller
will try to access the next GPD after processing the current one,
if not flush the next GPD, the controller may get wrong GPD status.

Signed-off-by: Chunfeng Yun 
---
 drivers/usb/mtu3/mtu3_qmu.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/usb/mtu3/mtu3_qmu.c b/drivers/usb/mtu3/mtu3_qmu.c
index 801c2bc416..95eaf6d236 100644
--- a/drivers/usb/mtu3/mtu3_qmu.c
+++ b/drivers/usb/mtu3/mtu3_qmu.c
@@ -198,6 +198,7 @@ static int mtu3_prepare_tx_gpd(struct mtu3_ep *mep, struct 
mtu3_request *mreq)
 
enq->flag &= ~GPD_FLAGS_HWO;
gpd->next_gpd = cpu_to_le32((u32)gpd_virt_to_dma(ring, enq));
+   mtu3_flush_cache((uintptr_t)enq, sizeof(*gpd));
 
if (req->zero)
gpd->ext_flag |= GPD_EXT_FLAG_ZLP;
@@ -234,6 +235,8 @@ static int mtu3_prepare_rx_gpd(struct mtu3_ep *mep, struct 
mtu3_request *mreq)
 
enq->flag &= ~GPD_FLAGS_HWO;
gpd->next_gpd = cpu_to_le32((u32)gpd_virt_to_dma(ring, enq));
+   mtu3_flush_cache((uintptr_t)enq, sizeof(*gpd));
+
gpd->flag |= GPD_FLAGS_IOC | GPD_FLAGS_HWO;
 
mreq->gpd = gpd;
-- 
2.18.0



Re: [PATCH v2 1/1] pinctrl: mediatek: correct error handling

2020-12-27 Thread Chunfeng Yun
On Sun, 2020-12-27 at 21:18 +0100, Heinrich Schuchardt wrote:
> If no GPIO controller is found, the return value should not depend on a
> random value on the stack. Initialize variable ret.
> 
> The problem was indicated by cppcheck.
> 
> Signed-off-by: Heinrich Schuchardt 
> ---
> v2:
>   move the assigment to the certain code-path (Andy)
> ---
>  drivers/pinctrl/mediatek/pinctrl-mtk-common.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/pinctrl/mediatek/pinctrl-mtk-common.c 
> b/drivers/pinctrl/mediatek/pinctrl-mtk-common.c
> index 6553dde45c..4dd3f73ead 100644
> --- a/drivers/pinctrl/mediatek/pinctrl-mtk-common.c
> +++ b/drivers/pinctrl/mediatek/pinctrl-mtk-common.c
> @@ -615,6 +615,7 @@ static int mtk_gpiochip_register(struct udevice *parent)
>   if (!drv)
>   return -ENOENT;
> 
> + ret = -ENOENT;
>   dev_for_each_subnode(node, parent)
>   if (ofnode_read_bool(node, "gpio-controller")) {
>   ret = 0;
> --
Acked-by: Chunfeng Yun 

Thanks

> 2.29.2
> 



[RESEND PATCH 2/2] dt-bindings: usb: mtk-xhci: add optional properies to disable ports

2020-12-22 Thread Chunfeng Yun
Add optional properies to disable usb2 or usb3 ports, they are used
when provided ports are not used on some special platforms.

Signed-off-by: Chunfeng Yun 
---
 doc/device-tree-bindings/usb/mediatek,mtk-xhci.txt | 4 
 1 file changed, 4 insertions(+)

diff --git a/doc/device-tree-bindings/usb/mediatek,mtk-xhci.txt 
b/doc/device-tree-bindings/usb/mediatek,mtk-xhci.txt
index 0447468a2d..2a298f7b16 100644
--- a/doc/device-tree-bindings/usb/mediatek,mtk-xhci.txt
+++ b/doc/device-tree-bindings/usb/mediatek,mtk-xhci.txt
@@ -25,6 +25,10 @@ Required properties:
 
 Optional properties:
  - vbus-supply : reference to the VBUS regulator;
+ - mediatek,u3p-dis-msk : mask to disable u3ports, bit0 for u3port0,
+   bit1 for u3port1, ... etc;
+ - mediatek,u2p-dis-msk : mask to disable u2ports, bit0 for u2port0,
+   bit1 for u2port1, ... etc;
 
 Example:
 xhci: usb@1a0c {
-- 
2.18.0



[RESEND PATCH 1/2] usb: xhci-mtk: support option to disable ports

2020-12-22 Thread Chunfeng Yun
Add support to disable specific ports, it's useful for some
scenarios:
1. usb3 PHY is shared whith PCIe or SATA, the corresponding
   usb3 port can be disabled;
2. some usb2 or usb3 ports are not used on special platforms,
   they should be disabled to save power.

Signed-off-by: Chunfeng Yun 
---
 drivers/usb/host/xhci-mtk.c | 23 ---
 1 file changed, 20 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/host/xhci-mtk.c b/drivers/usb/host/xhci-mtk.c
index f62e232d21..ebda80f2af 100644
--- a/drivers/usb/host/xhci-mtk.c
+++ b/drivers/usb/host/xhci-mtk.c
@@ -61,10 +61,13 @@ struct mtk_xhci {
struct phy_bulk phys;
int num_u2ports;
int num_u3ports;
+   u32 u3p_dis_msk;
+   u32 u2p_dis_msk;
 };
 
 static int xhci_mtk_host_enable(struct mtk_xhci *mtk)
 {
+   int u3_ports_disabed = 0;
u32 value;
u32 check_val;
int ret;
@@ -73,15 +76,23 @@ static int xhci_mtk_host_enable(struct mtk_xhci *mtk)
/* power on host ip */
clrbits_le32(mtk->ippc + IPPC_IP_PW_CTRL1, CTRL1_IP_HOST_PDN);
 
-   /* power on and enable all u3 ports */
+   /* power on and enable u3 ports except skipped ones */
for (i = 0; i < mtk->num_u3ports; i++) {
+   if (BIT(i) & mtk->u3p_dis_msk) {
+   u3_ports_disabed++;
+   continue;
+   }
+
clrsetbits_le32(mtk->ippc + IPPC_U3_CTRL(i),
CTRL_U3_PORT_PDN | CTRL_U3_PORT_DIS,
CTRL_U3_PORT_HOST_SEL);
}
 
-   /* power on and enable all u2 ports */
+   /* power on and enable u2 ports except skipped ones */
for (i = 0; i < mtk->num_u2ports; i++) {
+   if (BIT(i) & mtk->u2p_dis_msk)
+   continue;
+
clrsetbits_le32(mtk->ippc + IPPC_U2_CTRL(i),
CTRL_U2_PORT_PDN | CTRL_U2_PORT_DIS,
CTRL_U2_PORT_HOST_SEL);
@@ -94,7 +105,7 @@ static int xhci_mtk_host_enable(struct mtk_xhci *mtk)
check_val = STS1_SYSPLL_STABLE | STS1_REF_RST |
STS1_SYS125_RST | STS1_XHCI_RST;
 
-   if (mtk->num_u3ports)
+   if (mtk->num_u3ports > u3_ports_disabed)
check_val |= STS1_U3_MAC_RST;
 
ret = readl_poll_timeout(mtk->ippc + IPPC_IP_PW_STS1, value,
@@ -176,6 +187,12 @@ static int xhci_mtk_ofdata_get(struct mtk_xhci *mtk)
if (ret)
debug("can't get vbus regulator %d!\n", ret);
 
+   /* optional properties to disable ports, ignore the error */
+   dev_read_u32(dev, "mediatek,u3p-dis-msk", &mtk->u3p_dis_msk);
+   dev_read_u32(dev, "mediatek,u2p-dis-msk", &mtk->u2p_dis_msk);
+   dev_info(dev, "ports disabled mask: u3p-0x%x, u2p-0x%x\n",
+mtk->u3p_dis_msk, mtk->u2p_dis_msk);
+
return 0;
 }
 
-- 
2.18.0



[PATCH 2/2] dt-bindings: usb: mtk-xhci: add optional properies to disable ports

2020-11-23 Thread Chunfeng Yun
Add optional properies to disable usb2 or usb3 ports, they are used
when provided ports are not used on some special platforms.

Signed-off-by: Chunfeng Yun 
---
 doc/device-tree-bindings/usb/mediatek,mtk-xhci.txt | 4 
 1 file changed, 4 insertions(+)

diff --git a/doc/device-tree-bindings/usb/mediatek,mtk-xhci.txt 
b/doc/device-tree-bindings/usb/mediatek,mtk-xhci.txt
index 0447468a2d..2a298f7b16 100644
--- a/doc/device-tree-bindings/usb/mediatek,mtk-xhci.txt
+++ b/doc/device-tree-bindings/usb/mediatek,mtk-xhci.txt
@@ -25,6 +25,10 @@ Required properties:
 
 Optional properties:
  - vbus-supply : reference to the VBUS regulator;
+ - mediatek,u3p-dis-msk : mask to disable u3ports, bit0 for u3port0,
+   bit1 for u3port1, ... etc;
+ - mediatek,u2p-dis-msk : mask to disable u2ports, bit0 for u2port0,
+   bit1 for u2port1, ... etc;
 
 Example:
 xhci: usb@1a0c {
-- 
2.18.0



[PATCH 1/2] usb: xhci-mtk: support option to disable ports

2020-11-23 Thread Chunfeng Yun
Add support to disable specific ports, it's useful for some
scenarios:
1. usb3 PHY is shared whith PCIe or SATA, the corresponding
   usb3 port can be disabled;
2. some usb2 or usb3 ports are not used on special platforms,
   they should be disabled to save power.

Signed-off-by: Chunfeng Yun 
---
 drivers/usb/host/xhci-mtk.c | 23 ---
 1 file changed, 20 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/host/xhci-mtk.c b/drivers/usb/host/xhci-mtk.c
index f62e232d21..ebda80f2af 100644
--- a/drivers/usb/host/xhci-mtk.c
+++ b/drivers/usb/host/xhci-mtk.c
@@ -61,10 +61,13 @@ struct mtk_xhci {
struct phy_bulk phys;
int num_u2ports;
int num_u3ports;
+   u32 u3p_dis_msk;
+   u32 u2p_dis_msk;
 };
 
 static int xhci_mtk_host_enable(struct mtk_xhci *mtk)
 {
+   int u3_ports_disabed = 0;
u32 value;
u32 check_val;
int ret;
@@ -73,15 +76,23 @@ static int xhci_mtk_host_enable(struct mtk_xhci *mtk)
/* power on host ip */
clrbits_le32(mtk->ippc + IPPC_IP_PW_CTRL1, CTRL1_IP_HOST_PDN);
 
-   /* power on and enable all u3 ports */
+   /* power on and enable u3 ports except skipped ones */
for (i = 0; i < mtk->num_u3ports; i++) {
+   if (BIT(i) & mtk->u3p_dis_msk) {
+   u3_ports_disabed++;
+   continue;
+   }
+
clrsetbits_le32(mtk->ippc + IPPC_U3_CTRL(i),
CTRL_U3_PORT_PDN | CTRL_U3_PORT_DIS,
CTRL_U3_PORT_HOST_SEL);
}
 
-   /* power on and enable all u2 ports */
+   /* power on and enable u2 ports except skipped ones */
for (i = 0; i < mtk->num_u2ports; i++) {
+   if (BIT(i) & mtk->u2p_dis_msk)
+   continue;
+
clrsetbits_le32(mtk->ippc + IPPC_U2_CTRL(i),
CTRL_U2_PORT_PDN | CTRL_U2_PORT_DIS,
CTRL_U2_PORT_HOST_SEL);
@@ -94,7 +105,7 @@ static int xhci_mtk_host_enable(struct mtk_xhci *mtk)
check_val = STS1_SYSPLL_STABLE | STS1_REF_RST |
STS1_SYS125_RST | STS1_XHCI_RST;
 
-   if (mtk->num_u3ports)
+   if (mtk->num_u3ports > u3_ports_disabed)
check_val |= STS1_U3_MAC_RST;
 
ret = readl_poll_timeout(mtk->ippc + IPPC_IP_PW_STS1, value,
@@ -176,6 +187,12 @@ static int xhci_mtk_ofdata_get(struct mtk_xhci *mtk)
if (ret)
debug("can't get vbus regulator %d!\n", ret);
 
+   /* optional properties to disable ports, ignore the error */
+   dev_read_u32(dev, "mediatek,u3p-dis-msk", &mtk->u3p_dis_msk);
+   dev_read_u32(dev, "mediatek,u2p-dis-msk", &mtk->u2p_dis_msk);
+   dev_info(dev, "ports disabled mask: u3p-0x%x, u2p-0x%x\n",
+mtk->u3p_dis_msk, mtk->u2p_dis_msk);
+
return 0;
 }
 
-- 
2.18.0



Re: [PATCH next] usb: mtu3: fix build error caused by dev_xxx()

2020-10-19 Thread Chunfeng Yun
On Tue, 2020-10-20 at 14:15 +0800, Bin Meng wrote:
> Hi Chunfeng,
> 
> On Tue, Oct 20, 2020 at 10:22 AM Chunfeng Yun  
> wrote:
> >
> > On Tue, 2020-10-20 at 00:15 +0200, Marek Vasut wrote:
> > > On 10/19/20 2:19 PM, Chunfeng Yun wrote:
> > > > Due to the following to patches:
> > > > 4a1989c0bc77 ("dm: Don't undefine dev_xxx macros")
> > > > 69dae8902b16 ("linux/compat.h: Remove redefinition of dev_xxx macros")
> > > >
> > > > Need include device_compat.h and no need use __maybe_unused anymore
> > > > to fix unused variable warning
> > > >
> > > > Signed-off-by: Chunfeng Yun 
> > > > ---
> > > > Please squash in: ab703ebb1cc0 ("usb: add MediaTek USB3 DRD driver")
> > > > in u-boot-usb/next
> > >
> > > Applied, thanks.
> > Thank you!
> >
> > >
> > > > Sorry for inconvenience
> > >
> > > Please make use of the CI next time.
> > Is there any reference about CI I can see?
> >
> 
> You can use Microsoft Azure (recommended), or Travis-CI to test your patches.

Thank you

> 
> Regards,
> Bin



Re: [PATCH next] usb: mtu3: fix build error caused by dev_xxx()

2020-10-19 Thread Chunfeng Yun
On Tue, 2020-10-20 at 00:15 +0200, Marek Vasut wrote:
> On 10/19/20 2:19 PM, Chunfeng Yun wrote:
> > Due to the following to patches:
> > 4a1989c0bc77 ("dm: Don't undefine dev_xxx macros")
> > 69dae8902b16 ("linux/compat.h: Remove redefinition of dev_xxx macros")
> > 
> > Need include device_compat.h and no need use __maybe_unused anymore
> > to fix unused variable warning
> > 
> > Signed-off-by: Chunfeng Yun 
> > ---
> > Please squash in: ab703ebb1cc0 ("usb: add MediaTek USB3 DRD driver")
> > in u-boot-usb/next
> 
> Applied, thanks.
Thank you!

> 
> > Sorry for inconvenience
> 
> Please make use of the CI next time.
Is there any reference about CI I can see?



Re: [PATCH next] usb: mtu3: fix build warning/error

2020-10-19 Thread Chunfeng Yun
On Mon, 2020-10-19 at 12:34 +0200, Marek Vasut wrote:
> On 10/19/20 11:32 AM, Chunfeng Yun wrote:
> > On Mon, 2020-10-19 at 08:07 +0200, Marek Vasut wrote:
> >> On 10/19/20 5:46 AM, Chunfeng Yun wrote:
> >>> Fix up the following build warning/error:
> >>> 1. unused variable 'mtu' in mtu3_gadget_dequeue() and
> >>>mtu3_gadget_ep_set_halt()
> >>> 2. implicit declaration of function ‘flush_dcache_range’ and
> >>>‘invalidate_dcache_range’
> >>
> >> Which patch of the ones in usb/next do I squash this in ?
> > 
> > squash in:  ab703ebb1c usb: add MediaTek USB3 DRD driver
> > 
> > Thanks a lot
> 
> Build fails:
> https://gitlab.denx.de/u-boot/custodians/u-boot-usb/-/pipelines/5036

Sorry, the patch is already sent out, thanks



[PATCH next] usb: mtu3: fix build error caused by dev_xxx()

2020-10-19 Thread Chunfeng Yun
Due to the following to patches:
4a1989c0bc77 ("dm: Don't undefine dev_xxx macros")
69dae8902b16 ("linux/compat.h: Remove redefinition of dev_xxx macros")

Need include device_compat.h and no need use __maybe_unused anymore
to fix unused variable warning

Signed-off-by: Chunfeng Yun 
---
Please squash in: ab703ebb1cc0 ("usb: add MediaTek USB3 DRD driver")
in u-boot-usb/next

Sorry for inconvenience
---
 drivers/usb/mtu3/mtu3.h| 1 +
 drivers/usb/mtu3/mtu3_gadget.c | 4 ++--
 drivers/usb/mtu3/mtu3_plat.c   | 3 ++-
 3 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/mtu3/mtu3.h b/drivers/usb/mtu3/mtu3.h
index a51251c661..8a7ae83ee9 100644
--- a/drivers/usb/mtu3/mtu3.h
+++ b/drivers/usb/mtu3/mtu3.h
@@ -13,6 +13,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/drivers/usb/mtu3/mtu3_gadget.c b/drivers/usb/mtu3/mtu3_gadget.c
index c981407b29..027b7e6111 100644
--- a/drivers/usb/mtu3/mtu3_gadget.c
+++ b/drivers/usb/mtu3/mtu3_gadget.c
@@ -306,7 +306,7 @@ static int mtu3_gadget_dequeue(struct usb_ep *ep, struct 
usb_request *req)
struct mtu3_ep *mep = to_mtu3_ep(ep);
struct mtu3_request *mreq = to_mtu3_request(req);
struct mtu3_request *r;
-   __maybe_unused struct mtu3 *mtu = mep->mtu;
+   struct mtu3 *mtu = mep->mtu;
unsigned long flags;
int ret = 0;
 
@@ -344,7 +344,7 @@ done:
 static int mtu3_gadget_ep_set_halt(struct usb_ep *ep, int value)
 {
struct mtu3_ep *mep = to_mtu3_ep(ep);
-   __maybe_unused struct mtu3 *mtu = mep->mtu;
+   struct mtu3 *mtu = mep->mtu;
struct mtu3_request *mreq;
unsigned long flags = 0;
int ret = 0;
diff --git a/drivers/usb/mtu3/mtu3_plat.c b/drivers/usb/mtu3/mtu3_plat.c
index 24ffdb360a..3795e695e8 100644
--- a/drivers/usb/mtu3/mtu3_plat.c
+++ b/drivers/usb/mtu3/mtu3_plat.c
@@ -347,7 +347,8 @@ static int mtu3_glue_bind(struct udevice *parent)
 
ret = device_bind_driver_to_node(parent, driver, name, node, &dev);
if (ret)
-   dev_err("%s: not able to bind usb device mode\n", __func__);
+   dev_err(parent, "%s: not able to bind usb device mode\n",
+   __func__);
 
return ret;
 }
-- 
2.18.0


Re: [PATCH next] usb: mtu3: fix build warning/error

2020-10-19 Thread Chunfeng Yun
On Mon, 2020-10-19 at 08:07 +0200, Marek Vasut wrote:
> On 10/19/20 5:46 AM, Chunfeng Yun wrote:
> > Fix up the following build warning/error:
> > 1. unused variable 'mtu' in mtu3_gadget_dequeue() and
> >mtu3_gadget_ep_set_halt()
> > 2. implicit declaration of function ‘flush_dcache_range’ and
> >‘invalidate_dcache_range’
> 
> Which patch of the ones in usb/next do I squash this in ?

squash in:  ab703ebb1c usb: add MediaTek USB3 DRD driver

Thanks a lot


[PATCH next] usb: mtu3: fix build warning/error

2020-10-18 Thread Chunfeng Yun
Fix up the following build warning/error:
1. unused variable 'mtu' in mtu3_gadget_dequeue() and
   mtu3_gadget_ep_set_halt()
2. implicit declaration of function ‘flush_dcache_range’ and
   ‘invalidate_dcache_range’

Signed-off-by: Chunfeng Yun 
---
 drivers/usb/mtu3/mtu3_gadget.c | 4 ++--
 drivers/usb/mtu3/mtu3_qmu.c| 1 +
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/mtu3/mtu3_gadget.c b/drivers/usb/mtu3/mtu3_gadget.c
index 027b7e6111..c981407b29 100644
--- a/drivers/usb/mtu3/mtu3_gadget.c
+++ b/drivers/usb/mtu3/mtu3_gadget.c
@@ -306,7 +306,7 @@ static int mtu3_gadget_dequeue(struct usb_ep *ep, struct 
usb_request *req)
struct mtu3_ep *mep = to_mtu3_ep(ep);
struct mtu3_request *mreq = to_mtu3_request(req);
struct mtu3_request *r;
-   struct mtu3 *mtu = mep->mtu;
+   __maybe_unused struct mtu3 *mtu = mep->mtu;
unsigned long flags;
int ret = 0;
 
@@ -344,7 +344,7 @@ done:
 static int mtu3_gadget_ep_set_halt(struct usb_ep *ep, int value)
 {
struct mtu3_ep *mep = to_mtu3_ep(ep);
-   struct mtu3 *mtu = mep->mtu;
+   __maybe_unused struct mtu3 *mtu = mep->mtu;
struct mtu3_request *mreq;
unsigned long flags = 0;
int ret = 0;
diff --git a/drivers/usb/mtu3/mtu3_qmu.c b/drivers/usb/mtu3/mtu3_qmu.c
index f602e50c2f..801c2bc416 100644
--- a/drivers/usb/mtu3/mtu3_qmu.c
+++ b/drivers/usb/mtu3/mtu3_qmu.c
@@ -19,6 +19,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 
-- 
2.18.0


Re: [PATCH next v10] usb: add MediaTek USB3 DRD driver

2020-10-18 Thread Chunfeng Yun
On Fri, 2020-10-16 at 14:08 +0200, Marek Vasut wrote:
> On 10/16/20 5:38 AM, Chunfeng Yun wrote:
> > This patch adds support for the MediaTek USB3 DRD controller,
> > its host side is based on xHCI, this driver supports device mode
> > and host mode.
> 
> Build failed, please fix:
> https://gitlab.denx.de/u-boot/custodians/u-boot-usb/-/pipelines/5012

Ok, will fix the build warning, thanks



Re: [PATCH v9] usb: add MediaTek USB3 DRD driver

2020-10-15 Thread Chunfeng Yun
On Thu, 2020-10-15 at 14:28 +0200, Marek Vasut wrote:
> On 10/15/20 3:49 AM, Chunfeng Yun wrote:
> > Hi Marek,
> 
> Hi,
> 
> > On Wed, 2020-10-14 at 15:03 +0200, Marek Vasut wrote:
> >> On 10/14/20 2:29 PM, Chunfeng Yun wrote:
> >>> On Wed, 2020-10-14 at 12:56 +0200, Marek Vasut wrote:
> >>>> On 10/14/20 10:50 AM, Chunfeng Yun wrote:
> >>>>> This patch adds support for the MediaTek USB3 DRD controller,
> >>>>> its host side is based on xHCI, this driver supports device mode
> >>>>> and host mode.
> >>>>
> >>>> This patch doesn't seem to apply to u-boot-usb/next , 
> > This may cause u-boot-usb/next build error, due to no gadget driver is
> > built, because I enabled the following configs in patch 764751784727
> > ("configs: mt8512: enable fastboot and USB host related configs"):
> > CONFIG_DM_USB_GADGET=y
> > CONFIG_USB_MTU3=y
> > CONFIG_USB_GADGET=y
> > 
> > but the mtu3 driver is not yet applied in u-boot-usb/next (although
> > CONFIG_USB_MTU3 is enabled); and
> > CONFIG_DM_USB_GADGET requires a gadget driver to define
> > dm_usb_gadget_handle_interrupts(), then the build error happened.
> > 
> >> and also,
> >>>> u-boot-usb/next does not build:
> >>>
> >>> There is error:
> >>>  aarch64:  +   mt8512_bm1_emmc
> >>> +aarch64-linux-ld.bfd: drivers/usb/gadget/udc/built-in.o: in function
> >>> `usb_gadget_handle_interrupts':
> >>> +drivers/usb/gadget/udc/udc-uclass.c:56: undefined reference to
> >>> `dm_usb_gadget_handle_interrupts'
> >>>
> >>> It seems that the gadget of mtu3 is not enabled, but the default mode is
> >>> gadget mode, not sure why not works.
> > I tested it again, and look at the CI pipeline 4997, the mtu3 driver is
> > not applied into u-boot-usb/next, so will build error.
> > 
> > Please apply the following patch to u-boot-usb/next, it will build pass:
> > https://patchwork.ozlabs.org/project/uboot/patch/1602681717-20850-1-git-send-email-chunfeng@mediatek.com/
> > [RESEND,v9] usb: add MediaTek USB3 DRD driver
> > 
> > 
> > The following patch is not needed anymore, please ignore it
> > https://patchwork.ozlabs.org/project/uboot/patch/1602680044-19794-1-git-send-email-chunfeng@mediatek.com/
> > [v2] configs: mt8512: enable device mode of mtu3 explicitly
> 
> OK, so, please rebase whatever is left on top of usb/next and resend.
Ok, thanks

> This patch does not apply on top of usb/next, sorry.



Re: [PATCH v2] configs: mt8512: enable device mode of mtu3 explicitly

2020-10-14 Thread Chunfeng Yun
On Wed, 2020-10-14 at 15:31 +0200, Marek Vasut wrote:
> On 10/14/20 3:03 PM, Chunfeng Yun wrote:
> > On Wed, 2020-10-14 at 15:01 +0200, Marek Vasut wrote:
> >> On 10/14/20 2:54 PM, Chunfeng Yun wrote:
> >>> Set CONFIG_USB_MTU3_GADGET=y to enable device mode explicitly,
> >>> try to avoid build error:
> >>> "undefined reference to `dm_usb_gadget_handle_interrupts'"
> >>>
> >>> Fixes: 764751784727 ("configs: mt8512: enable fastboot and USB host 
> >>> related configs")
> >>
> >> Should I just squash this into ^ that commit in usb/next ?
> > Fine to me if it can fix the build error, thanks
> 
> So, can you please test it and then send me all the patches you want me
> to apply and possibly add a note in them if they should be squashed
> somewhere ?
As I explained in another email, just apply the following patch into
u-boot-usb/next will fix build error:
https://patchwork.ozlabs.org/project/uboot/patch/1602681717-20850-1-git-send-email-chunfeng@mediatek.com/
[RESEND,v9] usb: add MediaTek USB3 DRD driver

Thank you

> 
> Thanks



Re: [PATCH v9] usb: add MediaTek USB3 DRD driver

2020-10-14 Thread Chunfeng Yun
Hi Marek,

On Wed, 2020-10-14 at 15:03 +0200, Marek Vasut wrote:
> On 10/14/20 2:29 PM, Chunfeng Yun wrote:
> > On Wed, 2020-10-14 at 12:56 +0200, Marek Vasut wrote:
> >> On 10/14/20 10:50 AM, Chunfeng Yun wrote:
> >>> This patch adds support for the MediaTek USB3 DRD controller,
> >>> its host side is based on xHCI, this driver supports device mode
> >>> and host mode.
> >>
> >> This patch doesn't seem to apply to u-boot-usb/next , 
This may cause u-boot-usb/next build error, due to no gadget driver is
built, because I enabled the following configs in patch 764751784727
("configs: mt8512: enable fastboot and USB host related configs"):
CONFIG_DM_USB_GADGET=y
CONFIG_USB_MTU3=y
CONFIG_USB_GADGET=y

but the mtu3 driver is not yet applied in u-boot-usb/next (although
CONFIG_USB_MTU3 is enabled); and
CONFIG_DM_USB_GADGET requires a gadget driver to define
dm_usb_gadget_handle_interrupts(), then the build error happened.

> and also,
> >> u-boot-usb/next does not build:
> > 
> > There is error:
> >  aarch64:  +   mt8512_bm1_emmc
> > +aarch64-linux-ld.bfd: drivers/usb/gadget/udc/built-in.o: in function
> > `usb_gadget_handle_interrupts':
> > +drivers/usb/gadget/udc/udc-uclass.c:56: undefined reference to
> > `dm_usb_gadget_handle_interrupts'
> > 
> > It seems that the gadget of mtu3 is not enabled, but the default mode is
> > gadget mode, not sure why not works.
I tested it again, and look at the CI pipeline 4997, the mtu3 driver is
not applied into u-boot-usb/next, so will build error.

Please apply the following patch to u-boot-usb/next, it will build pass:
https://patchwork.ozlabs.org/project/uboot/patch/1602681717-20850-1-git-send-email-chunfeng@mediatek.com/
[RESEND,v9] usb: add MediaTek USB3 DRD driver


The following patch is not needed anymore, please ignore it
https://patchwork.ozlabs.org/project/uboot/patch/1602680044-19794-1-git-send-email-chunfeng@mediatek.com/
[v2] configs: mt8512: enable device mode of mtu3 explicitly

Thanks a lot

> > 
> > I sent a patch to try to fix it:
> > 
> > https://patchwork.ozlabs.org/project/uboot/patch/1602678229-19372-1-git-send-email-chunfeng@mediatek.com/
> > configs: mt8512: enable device mode of mtu3 explicitly
> > 
> > 
> > Sorry for inconvenience
> 
> That's fine, but can you please rebase this on usb/next and resend, so I
> can apply it ?
> 
> Also, you can use either of the travis/gitlab CI to build-test the
> patches before submitting them.



Re: [PATCH v2] configs: mt8512: enable device mode of mtu3 explicitly

2020-10-14 Thread Chunfeng Yun
On Wed, 2020-10-14 at 15:31 +0200, Marek Vasut wrote:
> On 10/14/20 3:03 PM, Chunfeng Yun wrote:
> > On Wed, 2020-10-14 at 15:01 +0200, Marek Vasut wrote:
> >> On 10/14/20 2:54 PM, Chunfeng Yun wrote:
> >>> Set CONFIG_USB_MTU3_GADGET=y to enable device mode explicitly,
> >>> try to avoid build error:
> >>> "undefined reference to `dm_usb_gadget_handle_interrupts'"
> >>>
> >>> Fixes: 764751784727 ("configs: mt8512: enable fastboot and USB host 
> >>> related configs")
> >>
> >> Should I just squash this into ^ that commit in usb/next ?
> > Fine to me if it can fix the build error, thanks
> 
> So, can you please test it and then send me all the patches you want me
> to apply and possibly add a note in them if they should be squashed
> somewhere ?
Ok, I'll test and send them again, please apply them directly, that may
be easier

Thanks a lot

> 
> Thanks



Re: [PATCH v2] configs: mt8512: enable device mode of mtu3 explicitly

2020-10-14 Thread Chunfeng Yun
On Wed, 2020-10-14 at 15:01 +0200, Marek Vasut wrote:
> On 10/14/20 2:54 PM, Chunfeng Yun wrote:
> > Set CONFIG_USB_MTU3_GADGET=y to enable device mode explicitly,
> > try to avoid build error:
> > "undefined reference to `dm_usb_gadget_handle_interrupts'"
> > 
> > Fixes: 764751784727 ("configs: mt8512: enable fastboot and USB host related 
> > configs")
> 
> Should I just squash this into ^ that commit in usb/next ?
Fine to me if it can fix the build error, thanks



[PATCH v2] configs: mt8512: enable device mode of mtu3 explicitly

2020-10-14 Thread Chunfeng Yun
Set CONFIG_USB_MTU3_GADGET=y to enable device mode explicitly,
try to avoid build error:
"undefined reference to `dm_usb_gadget_handle_interrupts'"

Fixes: 764751784727 ("configs: mt8512: enable fastboot and USB host related 
configs")

Signed-off-by: Chunfeng Yun 
---
v2: change fixes info suggested by Bin
---
 configs/mt8512_bm1_emmc_defconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/configs/mt8512_bm1_emmc_defconfig 
b/configs/mt8512_bm1_emmc_defconfig
index aaf59f52a8..c25a42cd3d 100644
--- a/configs/mt8512_bm1_emmc_defconfig
+++ b/configs/mt8512_bm1_emmc_defconfig
@@ -53,6 +53,7 @@ CONFIG_DM_USB=y
 CONFIG_DM_USB_GADGET=y
 CONFIG_USB_XHCI_HCD=y
 CONFIG_USB_MTU3=y
+CONFIG_USB_MTU3_GADGET=y
 # CONFIG_USB_MTU3_HOST is not set
 CONFIG_USB_STORAGE=y
 CONFIG_USB_GADGET=y
-- 
2.18.0


Re: [PATCH] configs: mt8512: enable device mode of mtu3 explicitly

2020-10-14 Thread Chunfeng Yun
On Wed, 2020-10-14 at 20:33 +0800, Bin Meng wrote:
> On Wed, Oct 14, 2020 at 8:24 PM Chunfeng Yun  
> wrote:
> >
> > Set CONFIG_USB_MTU3_GADGET=y to enable it explicitly,
> > try to avoid build error:
> > "undefined reference to `dm_usb_gadget_handle_interrupts'"
> >
> > fixes: 311412ead0 ("configs: mt8512: enable fastboot and USB host related 
> > configs")
> 
> This should be "Fixes:" followed by 12 digit commit id
Ok
> 
> I can't find 311412ead0 in my tree
Sorry, I used my local change id, will use one got from u-boot-usb/next
branch
> 
> >
> > Signed-off-by: Chunfeng Yun 
> > ---
> >  configs/mt8512_bm1_emmc_defconfig | 1 +
> >  1 file changed, 1 insertion(+)
> >
> > diff --git a/configs/mt8512_bm1_emmc_defconfig 
> > b/configs/mt8512_bm1_emmc_defconfig
> > index aaf59f52a8..c25a42cd3d 100644
> > --- a/configs/mt8512_bm1_emmc_defconfig
> > +++ b/configs/mt8512_bm1_emmc_defconfig
> > @@ -53,6 +53,7 @@ CONFIG_DM_USB=y
> >  CONFIG_DM_USB_GADGET=y
> >  CONFIG_USB_XHCI_HCD=y
> >  CONFIG_USB_MTU3=y
> > +CONFIG_USB_MTU3_GADGET=y
> >  # CONFIG_USB_MTU3_HOST is not set
> >  CONFIG_USB_STORAGE=y
> >  CONFIG_USB_GADGET=y
> 
> Regards,
> Bin



Re: [PATCH v9] usb: add MediaTek USB3 DRD driver

2020-10-14 Thread Chunfeng Yun
On Wed, 2020-10-14 at 12:56 +0200, Marek Vasut wrote:
> On 10/14/20 10:50 AM, Chunfeng Yun wrote:
> > This patch adds support for the MediaTek USB3 DRD controller,
> > its host side is based on xHCI, this driver supports device mode
> > and host mode.
> 
> This patch doesn't seem to apply to u-boot-usb/next , and also,
> u-boot-usb/next does not build:

There is error:
 aarch64:  +   mt8512_bm1_emmc
+aarch64-linux-ld.bfd: drivers/usb/gadget/udc/built-in.o: in function
`usb_gadget_handle_interrupts':
+drivers/usb/gadget/udc/udc-uclass.c:56: undefined reference to
`dm_usb_gadget_handle_interrupts'

It seems that the gadget of mtu3 is not enabled, but the default mode is
gadget mode, not sure why not works.

I sent a patch to try to fix it:

https://patchwork.ozlabs.org/project/uboot/patch/1602678229-19372-1-git-send-email-chunfeng@mediatek.com/
configs: mt8512: enable device mode of mtu3 explicitly


Sorry for inconvenience


> 
> https://gitlab.denx.de/u-boot/custodians/u-boot-usb/-/jobs/163995



[PATCH] configs: mt8512: enable device mode of mtu3 explicitly

2020-10-14 Thread Chunfeng Yun
Set CONFIG_USB_MTU3_GADGET=y to enable it explicitly,
try to avoid build error:
"undefined reference to `dm_usb_gadget_handle_interrupts'"

fixes: 311412ead0 ("configs: mt8512: enable fastboot and USB host related 
configs")

Signed-off-by: Chunfeng Yun 
---
 configs/mt8512_bm1_emmc_defconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/configs/mt8512_bm1_emmc_defconfig 
b/configs/mt8512_bm1_emmc_defconfig
index aaf59f52a8..c25a42cd3d 100644
--- a/configs/mt8512_bm1_emmc_defconfig
+++ b/configs/mt8512_bm1_emmc_defconfig
@@ -53,6 +53,7 @@ CONFIG_DM_USB=y
 CONFIG_DM_USB_GADGET=y
 CONFIG_USB_XHCI_HCD=y
 CONFIG_USB_MTU3=y
+CONFIG_USB_MTU3_GADGET=y
 # CONFIG_USB_MTU3_HOST is not set
 CONFIG_USB_STORAGE=y
 CONFIG_USB_GADGET=y
-- 
2.18.0


Re: [PATCH v8 5/9] usb: add MediaTek USB3 DRD driver

2020-10-14 Thread Chunfeng Yun
On Wed, 2020-10-14 at 10:22 +0200, Marek Vasut wrote:
> On 10/14/20 9:08 AM, Chunfeng Yun wrote:
> > This patch adds support for the MediaTek USB3 DRD controller,
> > its host side is based on xHCI, this driver supports device mode
> > and host mode.
> 
> This one does not apply, can you rebase just this one on top of usb/next
> and resend ? I picked the other patches into there already, so you don't
> have to resend the whole series.
Ok
> 
> [...]
> 
> > +#defineMU3D_EP_TXCR0(epnum)(U3D_TX1CSR0 + (((epnum) - 1) * 0x10))
> > +#defineMU3D_EP_TXCR1(epnum)(U3D_TX1CSR1 + (((epnum) - 1) * 0x10))
> > +#defineMU3D_EP_TXCR2(epnum)(U3D_TX1CSR2 + (((epnum) - 1) * 0x10))
> > +
> > +#defineMU3D_EP_RXCR0(epnum)(U3D_RX1CSR0 + (((epnum) - 1) * 0x10))
> > +#defineMU3D_EP_RXCR1(epnum)(U3D_RX1CSR1 + (((epnum) - 1) * 0x10))
> > +#defineMU3D_EP_RXCR2(epnum)(U3D_RX1CSR2 + (((epnum) - 1) * 0x10))
> 
> #define[space] please, use consistently.
Will fix it

Thanks
> 
> > +#define USB_QMU_RQCSR(epnum)   (U3D_RXQCSR1 + (((epnum) - 1) * 0x10))
> > +#define USB_QMU_RQSAR(epnum)   (U3D_RXQSAR1 + (((epnum) - 1) * 0x10))
> > +#define USB_QMU_RQCPR(epnum)   (U3D_RXQCPR1 + (((epnum) - 1) * 0x10))
> 
> [...]



Re: [PATCH v8 8/9] configs: mt8512: enable fastboot and USB host related configs

2020-10-14 Thread Chunfeng Yun
Hi Bin,

Thank you again


On Wed, 2020-10-14 at 16:05 +0800, Bin Meng wrote:
> On Wed, Oct 14, 2020 at 3:08 PM Chunfeng Yun  
> wrote:
> >
> > Enable mtu3, xhci, tphy drivers.
> > Device mode: enable fastboot;
> > Host mode: enable USB, FAT commands, and fixed regulator,
> > mass storage drivers;
> > Due to device mode is enabled by default, comment out
> > the host mode config here.
> >
> > Signed-off-by: Chunfeng Yun 
> > ---
> > v8 changes:
> >   1. add CONFIG_USB_XHCI_HCD due to Kconfig changes
> >   2. modify comment of CONFIG_USB_MTU3_HOST suggested by Bin
> >   3. merge [v7 8/10] add [v7 9/10] suggested by Bin
> >
> > v2~v7: no changes
> > ---
> >  configs/mt8512_bm1_emmc_defconfig | 26 ++
> >  1 file changed, 26 insertions(+)
> >
> 
> Reviewed-by: Bin Meng 



[PATCH v8 8/9] configs: mt8512: enable fastboot and USB host related configs

2020-10-14 Thread Chunfeng Yun
Enable mtu3, xhci, tphy drivers.
Device mode: enable fastboot;
Host mode: enable USB, FAT commands, and fixed regulator,
mass storage drivers;
Due to device mode is enabled by default, comment out
the host mode config here.

Signed-off-by: Chunfeng Yun 
---
v8 changes:
  1. add CONFIG_USB_XHCI_HCD due to Kconfig changes
  2. modify comment of CONFIG_USB_MTU3_HOST suggested by Bin
  3. merge [v7 8/10] add [v7 9/10] suggested by Bin

v2~v7: no changes
---
 configs/mt8512_bm1_emmc_defconfig | 26 ++
 1 file changed, 26 insertions(+)

diff --git a/configs/mt8512_bm1_emmc_defconfig 
b/configs/mt8512_bm1_emmc_defconfig
index 950507fddc..aaf59f52a8 100644
--- a/configs/mt8512_bm1_emmc_defconfig
+++ b/configs/mt8512_bm1_emmc_defconfig
@@ -9,11 +9,16 @@ CONFIG_DM_GPIO=y
 CONFIG_TARGET_MT8512=y
 CONFIG_DEFAULT_DEVICE_TREE="mt8512-bm1-emmc"
 CONFIG_FIT=y
+CONFIG_EFI_PARTITION=y
 CONFIG_FIT_SIGNATURE=y
 CONFIG_DEFAULT_FDT_FILE="mt8512-bm1-emmc.dtb"
 CONFIG_SYS_PROMPT="MT8512> "
 CONFIG_CMD_BOOTMENU=y
 CONFIG_CMD_MMC=y
+CONFIG_CMD_USB=y
+CONFIG_CMD_FAT=y
+CONFIG_CMD_FS_GENERIC=y
+# CONFIG_DOS_PARTITION is not set
 CONFIG_ENV_OVERWRITE=y
 CONFIG_REGMAP=y
 CONFIG_SYSCON=y
@@ -26,6 +31,16 @@ CONFIG_PINCONF=y
 CONFIG_PINCTRL_MT8512=y
 CONFIG_RAM=y
 CONFIG_BAUDRATE=921600
+CONFIG_USB_FUNCTION_FASTBOOT=y
+CONFIG_FASTBOOT_BUF_ADDR=0x5600
+CONFIG_FASTBOOT_BUF_SIZE=0x1e0
+CONFIG_FASTBOOT_FLASH=y
+CONFIG_FASTBOOT_FLASH_MMC_DEV=0
+CONFIG_FASTBOOT_MMC_BOOT1_SUPPORT=y
+CONFIG_PHY=y
+CONFIG_PHY_MTK_TPHY=y
+CONFIG_DM_REGULATOR=y
+CONFIG_DM_REGULATOR_FIXED=y
 CONFIG_DM_SERIAL=y
 CONFIG_MTK_SERIAL=y
 CONFIG_TIMER=y
@@ -33,3 +48,14 @@ CONFIG_MTK_TIMER=y
 CONFIG_WDT=y
 CONFIG_WDT_MTK=y
 CONFIG_LZO=y
+CONFIG_USB=y
+CONFIG_DM_USB=y
+CONFIG_DM_USB_GADGET=y
+CONFIG_USB_XHCI_HCD=y
+CONFIG_USB_MTU3=y
+# CONFIG_USB_MTU3_HOST is not set
+CONFIG_USB_STORAGE=y
+CONFIG_USB_GADGET=y
+CONFIG_USB_GADGET_MANUFACTURER="MediaTek"
+CONFIG_USB_GADGET_VENDOR_NUM=0x0e8d
+CONFIG_USB_GADGET_PRODUCT_NUM=0x201c
-- 
2.18.0


[PATCH v8 7/9] arm: dts: mt8512: add usb related nodes

2020-10-14 Thread Chunfeng Yun
Add usb, usb phy, and fixed regulators nodes

Signed-off-by: Chunfeng Yun 
Acked-by: Bin Meng 
---
v8: add Acked-by Bin

v5~v7: no changes

v4: add host related properties, add subnode.

v3: remove unused property mediatek,discth

v2: no changes
---
 arch/arm/dts/mt8512-bm1-emmc.dts | 34 ++
 arch/arm/dts/mt8512.dtsi | 49 +++-
 2 files changed, 82 insertions(+), 1 deletion(-)

diff --git a/arch/arm/dts/mt8512-bm1-emmc.dts b/arch/arm/dts/mt8512-bm1-emmc.dts
index 296ed93b9e..12511b5fed 100644
--- a/arch/arm/dts/mt8512-bm1-emmc.dts
+++ b/arch/arm/dts/mt8512-bm1-emmc.dts
@@ -43,6 +43,25 @@
regulator-boot-on;
regulator-always-on;
};
+
+   usb_p0_vbus: regulator@0 {
+   compatible = "regulator-fixed";
+   regulator-name = "p0_vbus";
+   regulator-min-microvolt = <500>;
+   regulator-max-microvolt = <500>;
+   gpio = <&gpio 27 GPIO_ACTIVE_HIGH>;
+   enable-active-high;
+   };
+
+   usb_p1_vbus: regulator@1 {
+   compatible = "regulator-fixed";
+   regulator-name = "p1_vbus";
+   regulator-min-microvolt = <500>;
+   regulator-max-microvolt = <500>;
+   gpio = <&gpio 32 GPIO_ACTIVE_HIGH>;
+   enable-active-high;
+   regulator-always-on;
+   };
 };
 
 &mmc0 {
@@ -95,6 +114,21 @@
};
 };
 
+&ssusb {
+   dr_mode = "peripheral";
+   maximum-speed = "high-speed";
+   status = "okay";
+};
+
+&usb3 {
+   vbus-supply = <&usb_p0_vbus>;
+   status = "okay";
+};
+
+&u3phy {
+   status = "okay";
+};
+
 &uart0 {
pinctrl-names = "default";
pinctrl-0 = <&uart0_pins>;
diff --git a/arch/arm/dts/mt8512.dtsi b/arch/arm/dts/mt8512.dtsi
index 01a02a7ebf..bdb84f8ef0 100644
--- a/arch/arm/dts/mt8512.dtsi
+++ b/arch/arm/dts/mt8512.dtsi
@@ -9,6 +9,7 @@
 #include 
 #include 
 #include 
+#include 
 
 / {
compatible = "mediatek,mt8512";
@@ -100,6 +101,52 @@
status = "disabled";
};
 
+   usb3: usb@11213e00 {
+   compatible = "mediatek,mt8512-mtu3", "mediatek,mtu3";
+   reg = <0x11213e00 0x0100>;
+   reg-names = "ippc";
+   phys = <&u2port0 PHY_TYPE_USB2>, <&u2port1 PHY_TYPE_USB2>;
+   clocks = <&infracfg CLK_INFRA_USB_SYS>,
+<&topckgen CLK_TOP_SSUSB_TOP_CK_EN>,
+<&infracfg CLK_INFRA_ICUSB>;
+   clock-names = "sys_ck", "ref_ck", "mcu_ck";
+   #address-cells = <1>;
+   #size-cells = <1>;
+   ranges;
+   status = "disabled";
+
+   ssusb: usb@1121 {
+   compatible = "mediatek,ssusb";
+   reg = <0x1121 0x3e00>;
+   interrupts = ;
+   reg-names = "mac";
+   status = "disabled";
+   };
+   };
+
+   u3phy: usb-phy@11cc {
+   compatible = "mediatek,mt8512-tphy",
+"mediatek,generic-tphy-v2";
+   #address-cells = <1>;
+   #size-cells = <1>;
+   ranges;
+   status = "disabled";
+
+   u2port0: usb-phy@11cc {
+   reg = <0x11cc 0x400>;
+   clocks = <&topckgen CLK_TOP_USB20_48M_EN>;
+   clock-names = "ref";
+   #phy-cells = <1>;
+   status = "okay";
+   };
+
+   u2port1: usb-phy@11c4 {
+   reg = <0x11c4 0x400>;
+   #phy-cells = <1>;
+   status = "okay";
+   };
+   };
+
mmc0: mmc@1123 {
compatible = "mediatek,mt8512-mmc";
reg = <0x1123 0x1000>,
@@ -112,4 +159,4 @@
status = "disabled";
};
 
-};
\ No newline at end of file
+};
-- 
2.18.0


[PATCH v8 4/9] usb: common: add define of usb_speed_string()

2020-10-14 Thread Chunfeng Yun
There is only declaration of usb_speed_string(), but no definition,
so add it to avoid build error when call it.

Signed-off-by: Chunfeng Yun 
Reviewed-by: Bin Meng 
---
v8: add Reviewed-by Bin

v7: no changes

v6: modify commit message suggested by Roger

v5: no changes

v4: new patch
---
 drivers/usb/common/common.c | 7 +++
 include/linux/usb/ch9.h | 4 
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/common/common.c b/drivers/usb/common/common.c
index 76f5a9ce60..5e5c3c3e3d 100644
--- a/drivers/usb/common/common.c
+++ b/drivers/usb/common/common.c
@@ -49,6 +49,13 @@ static const char *const speed_names[] = {
[USB_SPEED_SUPER_PLUS] = "super-speed-plus",
 };
 
+const char *usb_speed_string(enum usb_device_speed speed)
+{
+   if (speed < 0 || speed >= ARRAY_SIZE(speed_names))
+   speed = USB_SPEED_UNKNOWN;
+   return speed_names[speed];
+}
+
 enum usb_device_speed usb_get_maximum_speed(ofnode node)
 {
const char *max_speed;
diff --git a/include/linux/usb/ch9.h b/include/linux/usb/ch9.h
index 7d225ee9cb..a8fa5d7449 100644
--- a/include/linux/usb/ch9.h
+++ b/include/linux/usb/ch9.h
@@ -959,8 +959,6 @@ enum usb_device_speed {
USB_SPEED_SUPER_PLUS,   /* usb 3.1 */
 };
 
-#ifdef __KERNEL__
-
 /**
  * usb_speed_string() - Returns human readable-name of the speed.
  * @speed: The speed to return human-readable name for.  If it's not
@@ -969,8 +967,6 @@ enum usb_device_speed {
  */
 extern const char *usb_speed_string(enum usb_device_speed speed);
 
-#endif
-
 enum usb_device_state {
/* NOTATTACHED isn't in the USB spec, and this state acts
 * the same as ATTACHED ... but it's clearer this way.
-- 
2.18.0


[PATCH v8 6/9] usb: gadget: Add bcdDevice for the MTU3 USB Gadget Controller

2020-10-14 Thread Chunfeng Yun
Add an entry in usb_gadget_controller_number() for the MTU3
gadget controller. It is used to bind the USB Ethernet driver.

Signed-off-by: Chunfeng Yun 
Reviewed-by: Bin Meng 
---
v8: add Reviewed-by Bin

v4~v7: no changes

v3: new patch
---
 drivers/usb/gadget/gadget_chips.h | 8 
 1 file changed, 8 insertions(+)

diff --git a/drivers/usb/gadget/gadget_chips.h 
b/drivers/usb/gadget/gadget_chips.h
index 587204cfb7..0cdf47c2dd 100644
--- a/drivers/usb/gadget/gadget_chips.h
+++ b/drivers/usb/gadget/gadget_chips.h
@@ -161,6 +161,12 @@
 #define gadget_is_max3420(g)0
 #endif
 
+#ifdef CONFIG_USB_MTU3_GADGET
+#define gadget_is_mtu3(g)(!strcmp("mtu3-gadget", (g)->name))
+#else
+#define gadget_is_mtu3(g)0
+#endif
+
 /**
  * usb_gadget_controller_number - support bcdDevice id convention
  * @gadget: the controller being driven
@@ -224,5 +230,7 @@ static inline int usb_gadget_controller_number(struct 
usb_gadget *gadget)
return 0x24;
else if (gadget_is_max3420(gadget))
return 0x25;
+   else if (gadget_is_mtu3(gadget))
+   return 0x26;
return -ENOENT;
 }
-- 
2.18.0


[PATCH v8 9/9] MAINTAINERS: add USB driver to ARM MEDIATEK

2020-10-14 Thread Chunfeng Yun
Add MediaTek USB3 Dual-Role controller driver to ARM MEDIATEK,
and add myself as a maintainer for it.

Signed-off-by: Chunfeng Yun 
Reviewed-by: Bin Meng 
---
v8: add Reviewed-by Bin

v6~v7: no changes

v5: add mtu3/, xhci-mtk.c, and myself as maintainer for MTK USB

v4: new patch
---
 MAINTAINERS | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index fb9ba37984..5047ec6598 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -266,6 +266,7 @@ F:  arch/arm/include/asm/arch-pxa/
 ARM MEDIATEK
 M: Ryder Lee 
 M: Weijie Gao 
+M: Chunfeng Yun 
 R: GSS_MTK_Uboot_upstream 
 S: Maintained
 F: arch/arm/mach-mediatek/
@@ -282,6 +283,8 @@ F:  drivers/power/domain/mtk-power-domain.c
 F: drivers/ram/mediatek/
 F: drivers/spi/mtk_snfi_spi.c
 F: drivers/timer/mtk_timer.c
+F: drivers/usb/host/xhci-mtk.c
+F: drivers/usb/mtu3/
 F: drivers/watchdog/mtk_wdt.c
 F: drivers/net/mtk_eth.c
 F: drivers/reset/reset-mediatek.c
-- 
2.18.0


[PATCH v8 2/9] dt-bindings: usb: mtu3: add bindings for MediaTek USB3 DRD

2020-10-14 Thread Chunfeng Yun
Add dt-binding for MediaTek USB3 DRD Driver which it's ported
from the Linux kernel DTS binding:
Documentation/devicetree/bindings/usb/mediatek,mtu3.txt
Commit ID:
34d0545978b6 ("dt-bindings: usb: mtu3: fix typo of DMA clock name")

Due to Dual-Role switch is not supported in Uboot, some properties
are removed or changed.

Signed-off-by: Chunfeng Yun 
---
v8: add commit ID the binding referenced suggested by Bin

v5~v7: no changes

v4: Add support host mode, introduce some new properties and subnode

v2~v3: no changes
---
 .../usb/mediatek,mtu3.txt | 79 +++
 1 file changed, 79 insertions(+)
 create mode 100644 doc/device-tree-bindings/usb/mediatek,mtu3.txt

diff --git a/doc/device-tree-bindings/usb/mediatek,mtu3.txt 
b/doc/device-tree-bindings/usb/mediatek,mtu3.txt
new file mode 100644
index 00..ab877bfa89
--- /dev/null
+++ b/doc/device-tree-bindings/usb/mediatek,mtu3.txt
@@ -0,0 +1,79 @@
+The device node for Mediatek USB3 DRD controller
+
+Required properties:
+ - compatible : should be "mediatek,-mtu3", "mediatek,mtu3",
+   soc-model is the name of SoC, such as mt8512 etc,
+   when using "mediatek,mtu3" compatible string, you need SoC specific
+   ones in addition, one of:
+   - "mediatek,mt8512-mtu3"
+ - reg : specifies physical base address and size of the registers
+ - reg-names: should be
+   - "ippc" : IP Port Control
+ - power-domains : a phandle to USB power domain node to control USB's MTCMOS
+ - clocks : a list of phandle + clock-specifier pairs, one for each
+   entry in clock-names
+ - clock-names : must contain "sys_ck" for clock of controller,
+   the following clocks are optional:
+   "ref_ck", "mcu_ck", "dma_ck" and "xhci_ck";
+ - phys : list of all the USB PHYs on this HCD
+ - #address-cells, #size-cells : used for sub-nodes with 'reg' property
+ - ranges : allows valid 1:1 translation between child's address space and
+   parent's address space
+
+Optional properties:
+ - vusb33-supply : regulator of USB AVDD3.3v
+ - vbus-supply : regulator of VBUS 5v, needed when supports host mode.
+
+Sub-nodes:
+Required properties:
+ - compatible : should be "mediatek,ssusb"
+ - reg : specifies physical base address and size of the registers
+ - reg-names: should be
+   - "mac" : SSUSB MAC, include xHCI and device
+ - interrupts : interrupt used by xHCI or device
+ - dr_mode : should be one of "host" or "peripheral",
+   see : usb/generic.txt
+
+Optional properties:
+ - pinctrl-names : a pinctrl state named "default" is optional
+ - pinctrl-0 : pin control group
+   See: pinctrl/pinctrl-bindings.txt
+
+ - device mode:
+   - maximum-speed : valid arguments are "full-speed", "high-speed",
+   "super-speed" and "super-speed-plus",
+   see: usb/generic.txt
+   - mediatek,force-vbus : force vbus as valid by SW
+
+ - host mode (dr_mode is "host"):
+   - mediatek,u3p-dis-msk : mask to disable u3ports, bit0 for u3port0,
+   bit1 for u3port1, ... etc;
+
+Example:
+usb3: usb@11213e00 {
+   compatible = "mediatek,mt8512-mtu3", "mediatek,mtu3";
+   reg = <0x11213e00 0x0100>;
+   reg-names = "ippc";
+   phys = <&u2port0 PHY_TYPE_USB2>, <&u2port1 PHY_TYPE_USB2>;
+   power-domains = <&scpsys MT8512_POWER_DOMAIN_USB>;
+   clocks = <&infracfg CLK_INFRA_USB_SYS>,
+<&topckgen CLK_TOP_SSUSB_TOP_CK_EN>,
+<&infracfg CLK_INFRA_ICUSB>;
+   clock-names = "sys_ck", "ref_ck", "mcu_ck";
+   vusb33-supply = ;
+   vbus-supply = <&usb_p0_vbus>;
+   #address-cells = <1>;
+   #size-cells = <1>;
+   ranges;
+   status = "disabled";
+
+   ssusb: usb@1121 {
+   compatible = "mediatek,ssusb";
+   reg = <0x1121 0x3e00>;
+   interrupts = ;
+   reg-names = "mac";
+   dr_mode = "peripheral";
+   maximum-speed = "high-speed";
+   status = "disabled";
+   };
+};
-- 
2.18.0


[PATCH v8 1/9] dt-binding: usb: add bindings for some common properties

2020-10-14 Thread Chunfeng Yun
Add bindings for common properties, include maximum-speed,
dr_mode and phy_type

Signed-off-by: Chunfeng Yun 
Reviewed-by: Bin Meng 
---
v8: add Reviewed-by Bin

v2~v7: no changes
---
 doc/device-tree-bindings/usb/generic.txt | 31 
 1 file changed, 31 insertions(+)
 create mode 100644 doc/device-tree-bindings/usb/generic.txt

diff --git a/doc/device-tree-bindings/usb/generic.txt 
b/doc/device-tree-bindings/usb/generic.txt
new file mode 100644
index 00..a02a198dfb
--- /dev/null
+++ b/doc/device-tree-bindings/usb/generic.txt
@@ -0,0 +1,31 @@
+Generic USB Properties
+
+Optional properties:
+ - maximum-speed: tells USB controllers we want to work up to a certain
+   speed. Valid arguments are "super-speed-plus",
+   "super-speed", "high-speed", "full-speed" and
+   "low-speed". In case this isn't passed via DT, USB
+   controllers should default to their maximum HW
+   capability.
+ - dr_mode: tells Dual-Role USB controllers that we want to work on a
+   particular mode. Valid arguments are "host",
+   "peripheral" and "otg". In case this attribute isn't
+   passed via DT, USB DRD controllers should default to
+   OTG.
+ - phy_type: tells USB controllers that we want to configure the core to 
support
+   a UTMI+ PHY with an 8- or 16-bit interface if UTMI+ is
+   selected. Valid arguments are "utmi" and "utmi_wide".
+   In case this isn't passed via DT, USB controllers should
+   default to HW capability.
+
+This is an attribute to a USB controller such as:
+
+dwc3@4a03 {
+   compatible = "synopsys,dwc3";
+   reg = <0x4a03 0xcfff>;
+   interrupts = <0 92 4>
+   usb-phy = <&usb2_phy>, <&usb3,phy>;
+   maximum-speed = "super-speed";
+   dr_mode = "otg";
+   phy_type = "utmi_wide";
+};
-- 
2.18.0


[PATCH v8 0/9] Add support MediaTek USB3 DRD driver

2020-10-14 Thread Chunfeng Yun
These patches introduce the MediaTek USB3 Dual-Role Controller
driver.
The driver can be configured as Peripheral only and Host only
(based on xHCI) modes, and it's ported from Linux Kernel 5.8-rc1

v8 changes suggested by Bin:
1. modify Kconfig and mt8512 defconfig
2. merge [v7 8/10] and [v7 9/10]
3. modify some commit log

v7 changes:
1. use xhci quirk flag XHCI_MTK_HOST

v6 changes:
1. modify commit message of [4/10]

v5 changes:
1. change condition of readl_poll_timeout() when check clocks
2. add xhci-mtk.c and myself as maintainer for MTK USB

v4 changes:
1. [4/10], [9/10] and [10/10] are new patches
2. add a glue driver
3. add host driver and rebuild host flow
4. support force_vbus mode for device
5. update bindings to support glue driver

v3 changes:
1. add patch [5/7]
2. add udc_set_speed()
3. simplify some code flow

v2 changes:
1. simplify QMU operations

Chunfeng Yun (9):
  dt-binding: usb: add bindings for some common properties
  dt-bindings: usb: mtu3: add bindings for MediaTek USB3 DRD
  usb: add USB_SPEED_SUPER_PLUS
  usb: common: add define of usb_speed_string()
  usb: add MediaTek USB3 DRD driver
  usb: gadget: Add bcdDevice for the MTU3 USB Gadget Controller
  arm: dts: mt8512: add usb related nodes
  configs: mt8512: enable fastboot and USB host related configs
  MAINTAINERS: add USB driver to ARM MEDIATEK

 MAINTAINERS   |   3 +
 Makefile  |   1 +
 arch/arm/dts/mt8512-bm1-emmc.dts  |  34 +
 arch/arm/dts/mt8512.dtsi  |  49 +-
 configs/mt8512_bm1_emmc_defconfig |  26 +
 doc/device-tree-bindings/usb/generic.txt  |  31 +
 .../usb/mediatek,mtu3.txt |  79 ++
 drivers/usb/Kconfig   |   2 +
 drivers/usb/common/common.c   |   8 +
 drivers/usb/gadget/gadget_chips.h |   8 +
 drivers/usb/mtu3/Kconfig  |  44 +
 drivers/usb/mtu3/Makefile |  11 +
 drivers/usb/mtu3/mtu3.h   | 423 
 drivers/usb/mtu3/mtu3_core.c  | 838 
 drivers/usb/mtu3/mtu3_dr.h|  52 +
 drivers/usb/mtu3/mtu3_gadget.c| 686 +
 drivers/usb/mtu3/mtu3_gadget_ep0.c| 933 ++
 drivers/usb/mtu3/mtu3_host.c  | 141 +++
 drivers/usb/mtu3/mtu3_hw_regs.h   | 515 ++
 drivers/usb/mtu3/mtu3_plat.c  | 368 +++
 drivers/usb/mtu3/mtu3_qmu.c   | 504 ++
 drivers/usb/mtu3/mtu3_qmu.h   |  37 +
 include/linux/usb/ch9.h   |   5 +-
 23 files changed, 4793 insertions(+), 5 deletions(-)
 create mode 100644 doc/device-tree-bindings/usb/generic.txt
 create mode 100644 doc/device-tree-bindings/usb/mediatek,mtu3.txt
 create mode 100644 drivers/usb/mtu3/Kconfig
 create mode 100644 drivers/usb/mtu3/Makefile
 create mode 100644 drivers/usb/mtu3/mtu3.h
 create mode 100644 drivers/usb/mtu3/mtu3_core.c
 create mode 100644 drivers/usb/mtu3/mtu3_dr.h
 create mode 100644 drivers/usb/mtu3/mtu3_gadget.c
 create mode 100644 drivers/usb/mtu3/mtu3_gadget_ep0.c
 create mode 100644 drivers/usb/mtu3/mtu3_host.c
 create mode 100644 drivers/usb/mtu3/mtu3_hw_regs.h
 create mode 100644 drivers/usb/mtu3/mtu3_plat.c
 create mode 100644 drivers/usb/mtu3/mtu3_qmu.c
 create mode 100644 drivers/usb/mtu3/mtu3_qmu.h

-- 
2.18.0


[PATCH v8 3/9] usb: add USB_SPEED_SUPER_PLUS

2020-10-14 Thread Chunfeng Yun
Add enum USB_SPEED_SUPER_PLUS for USB3.1

Signed-off-by: Chunfeng Yun 
Reviewed-by: Bin Meng 
---
v8: add Reviewed-by Bin

v5~v7: no changes

v4: also add it into speed_names array

v2~v3: no changes
---
 drivers/usb/common/common.c | 1 +
 include/linux/usb/ch9.h | 1 +
 2 files changed, 2 insertions(+)

diff --git a/drivers/usb/common/common.c b/drivers/usb/common/common.c
index d4ae18693c..76f5a9ce60 100644
--- a/drivers/usb/common/common.c
+++ b/drivers/usb/common/common.c
@@ -46,6 +46,7 @@ static const char *const speed_names[] = {
[USB_SPEED_HIGH] = "high-speed",
[USB_SPEED_WIRELESS] = "wireless",
[USB_SPEED_SUPER] = "super-speed",
+   [USB_SPEED_SUPER_PLUS] = "super-speed-plus",
 };
 
 enum usb_device_speed usb_get_maximum_speed(ofnode node)
diff --git a/include/linux/usb/ch9.h b/include/linux/usb/ch9.h
index 989a5fcbd9..7d225ee9cb 100644
--- a/include/linux/usb/ch9.h
+++ b/include/linux/usb/ch9.h
@@ -956,6 +956,7 @@ enum usb_device_speed {
USB_SPEED_HIGH, /* usb 2.0 */
USB_SPEED_WIRELESS, /* wireless (usb 2.5) */
USB_SPEED_SUPER,/* usb 3.0 */
+   USB_SPEED_SUPER_PLUS,   /* usb 3.1 */
 };
 
 #ifdef __KERNEL__
-- 
2.18.0


Re: [PATCH next v7 09/10] configs: mt8512: add USB host related configs

2020-10-13 Thread Chunfeng Yun
On Tue, 2020-10-13 at 22:34 +0800, Bin Meng wrote:
> On Fri, Sep 18, 2020 at 5:12 PM Chunfeng Yun  
> wrote:
> >
> > Add USB, FAT commands, and fixed regulator, mass storage
> > drivers.
> > Due to device mode is enabled by default, comment out
> > the host mode config here.
> 
> This patch should be squashed into patch [08/10]
Ok

> 
> >
> > Signed-off-by: Chunfeng Yun 
> > ---
> > v5~v7: no changes
> >
> > v4: new patch
> > ---
> >  configs/mt8512_bm1_emmc_defconfig | 7 +++
> >  1 file changed, 7 insertions(+)
> >
> > diff --git a/configs/mt8512_bm1_emmc_defconfig 
> > b/configs/mt8512_bm1_emmc_defconfig
> > index d41446f..6b5454c 100644
> > --- a/configs/mt8512_bm1_emmc_defconfig
> > +++ b/configs/mt8512_bm1_emmc_defconfig
> > @@ -15,6 +15,10 @@ CONFIG_DEFAULT_FDT_FILE="mt8512-bm1-emmc.dtb"
> >  CONFIG_SYS_PROMPT="MT8512> "
> >  CONFIG_CMD_BOOTMENU=y
> >  CONFIG_CMD_MMC=y
> > +CONFIG_CMD_USB=y
> > +CONFIG_CMD_FAT=y
> > +CONFIG_CMD_FS_GENERIC=y
> > +# CONFIG_DOS_PARTITION is not set
> >  CONFIG_ENV_OVERWRITE=y
> >  CONFIG_REGMAP=y
> >  CONFIG_SYSCON=y
> > @@ -36,6 +40,7 @@ CONFIG_FASTBOOT_MMC_BOOT1_SUPPORT=y
> >  CONFIG_PHY=y
> >  CONFIG_PHY_MTK_TPHY=y
> >  CONFIG_DM_REGULATOR=y
> > +CONFIG_DM_REGULATOR_FIXED=y
> >  CONFIG_DM_SERIAL=y
> >  CONFIG_MTK_SERIAL=y
> >  CONFIG_TIMER=y
> > @@ -48,6 +53,8 @@ CONFIG_DM_USB=y
> >  CONFIG_DM_USB_GADGET=y
> >  CONFIG_USB_MTU3=y
> >  CONFIG_USB_MTU3_GADGET=y
> > +#CONFIG_USB_MTU3_HOST=y
> 
> This should be :
> 
> # CONFIG_USB_MTU3_HOST is not set
Will modify it.

Thanks a lot

> 
> > +CONFIG_USB_STORAGE=y
> >  CONFIG_USB_GADGET=y
> >  CONFIG_USB_GADGET_MANUFACTURER="MediaTek"
> >  CONFIG_USB_GADGET_VENDOR_NUM=0x0e8d
> > --
> 
> Regards,
> Bin



Re: [PATCH next v7 05/10] usb: add MediaTek USB3 DRD driver

2020-10-13 Thread Chunfeng Yun
On Tue, 2020-10-13 at 22:26 +0800, Bin Meng wrote:
> On Fri, Sep 18, 2020 at 5:12 PM Chunfeng Yun  
> wrote:
> >
> > This patch adds support for the MediaTek USB3 DRD controller,
> > its host side is based on xHCI, this driver supports device mode
> > and host mode.
> >
> > Signed-off-by: Chunfeng Yun 
> 
> I can only comment some generic stuff, since I have no access to the
> controller datasheet.
It's good enough, I and my workmate will test the function

> 
> > ---
> > v7:
> > 1. use xhci quirk flag XHCI_MTK_HOST
> >
> > v6: no changes
> >
> > v5:
> > 1. change condition of readl_poll_timeout() when check clocks
> >
> > v4:
> > 1. remove unused member @busy and @wedged, use their flags instead
> > 2. support force_vbus mode
> > 3. add a glue driver using UCLASS_NOP
> > 4. add host driver, and rebuild host flow
> >
> > v3 changes
> > 1. add ->udc_set_speed()
> > 2. simplify some code flow
> >
> > v2: simplify QMU operations
> > ---
> >  Makefile   |   1 +
> >  drivers/usb/Kconfig|   2 +
> >  drivers/usb/mtu3/Kconfig   |  45 ++
> >  drivers/usb/mtu3/Makefile  |  11 +
> >  drivers/usb/mtu3/mtu3.h| 423 +
> >  drivers/usb/mtu3/mtu3_core.c   | 838 +
> >  drivers/usb/mtu3/mtu3_dr.h |  52 +++
> >  drivers/usb/mtu3/mtu3_gadget.c | 686 +++
> >  drivers/usb/mtu3/mtu3_gadget_ep0.c | 933 
> > +
> >  drivers/usb/mtu3/mtu3_host.c   | 141 ++
> >  drivers/usb/mtu3/mtu3_hw_regs.h| 515 
> >  drivers/usb/mtu3/mtu3_plat.c   | 368 +++
> >  drivers/usb/mtu3/mtu3_qmu.c| 504 
> >  drivers/usb/mtu3/mtu3_qmu.h|  37 ++
> >  14 files changed, 4556 insertions(+)
> >  create mode 100644 drivers/usb/mtu3/Kconfig
> >  create mode 100644 drivers/usb/mtu3/Makefile
> >  create mode 100644 drivers/usb/mtu3/mtu3.h
> >  create mode 100644 drivers/usb/mtu3/mtu3_core.c
> >  create mode 100644 drivers/usb/mtu3/mtu3_dr.h
> >  create mode 100644 drivers/usb/mtu3/mtu3_gadget.c
> >  create mode 100644 drivers/usb/mtu3/mtu3_gadget_ep0.c
> >  create mode 100644 drivers/usb/mtu3/mtu3_host.c
> >  create mode 100644 drivers/usb/mtu3/mtu3_hw_regs.h
> >  create mode 100644 drivers/usb/mtu3/mtu3_plat.c
> >  create mode 100644 drivers/usb/mtu3/mtu3_qmu.c
> >  create mode 100644 drivers/usb/mtu3/mtu3_qmu.h
> >
> > diff --git a/Makefile b/Makefile
> > index 7a05fc7..2dcc41a 100644
> > --- a/Makefile
> > +++ b/Makefile
> > @@ -795,6 +795,7 @@ libs-y += drivers/usb/eth/
> >  libs-$(CONFIG_USB_GADGET) += drivers/usb/gadget/
> >  libs-$(CONFIG_USB_GADGET) += drivers/usb/gadget/udc/
> >  libs-y += drivers/usb/host/
> > +libs-y += drivers/usb/mtu3/
> >  libs-y += drivers/usb/musb/
> >  libs-y += drivers/usb/musb-new/
> >  libs-y += drivers/usb/phy/
> > diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig
> > index 34881a1..fedc013 100644
> > --- a/drivers/usb/Kconfig
> > +++ b/drivers/usb/Kconfig
> > @@ -72,6 +72,8 @@ source "drivers/usb/cdns3/Kconfig"
> >
> >  source "drivers/usb/dwc3/Kconfig"
> >
> > +source "drivers/usb/mtu3/Kconfig"
> > +
> >  source "drivers/usb/musb/Kconfig"
> >
> >  source "drivers/usb/musb-new/Kconfig"
> > diff --git a/drivers/usb/mtu3/Kconfig b/drivers/usb/mtu3/Kconfig
> > new file mode 100644
> > index 000..66651ad
> > --- /dev/null
> > +++ b/drivers/usb/mtu3/Kconfig
> > @@ -0,0 +1,45 @@
> > +# SPDX-License-Identifier: GPL-2.0
> > +#
> > +# For MTK USB3.0 IP
> > +
> > +config USB_MTU3
> > +   bool "MediaTek USB3 Dual Role controller"
> > +   depends on USB || USB_GADGET
> > +   depends on ARCH_MEDIATEK
> > +   help
> > + Say Y here if your system runs on MediaTek SoCs with
> > + Dual Role SuperSpeed USB controller. You can select usb
> > + mode as peripheral role or host role.
> > +
> > + If you don't know what this is, please say N.
> > +
> > +if USB_MTU3
> > +choice
> > +   bool "MTU3 Mode Selection"
> > +   default USB_MTU3_GADGET if USB_GADGET
> > +   default USB_MTU3_HOST if (USB && !USB_GADGET)
> > +
> > +c

Re: [PATCH next v7 03/10] usb: add USB_SPEED_SUPER_PLUS

2020-10-13 Thread Chunfeng Yun
On Tue, 2020-10-13 at 22:19 +0800, Bin Meng wrote:
> On Fri, Sep 18, 2020 at 5:12 PM Chunfeng Yun  
> wrote:
> >
> > Add enum USB_SPEED_SUPER_PLUS for USB3.1
> >
> > Signed-off-by: Chunfeng Yun 
> > ---
> > v5~v7: no changes
> >
> > v4: also add it into speed_names array
> >
> > v2~v3: no changes
> > ---
> >  drivers/usb/common/common.c | 1 +
> >  include/linux/usb/ch9.h | 1 +
> >  2 files changed, 2 insertions(+)
> >
> > diff --git a/drivers/usb/common/common.c b/drivers/usb/common/common.c
> > index d4ae186..76f5a9c 100644
> > --- a/drivers/usb/common/common.c
> > +++ b/drivers/usb/common/common.c
> > @@ -46,6 +46,7 @@ static const char *const speed_names[] = {
> > [USB_SPEED_HIGH] = "high-speed",
> > [USB_SPEED_WIRELESS] = "wireless",
> > [USB_SPEED_SUPER] = "super-speed",
> > +   [USB_SPEED_SUPER_PLUS] = "super-speed-plus",
> >  };
> >
> >  enum usb_device_speed usb_get_maximum_speed(ofnode node)
> > diff --git a/include/linux/usb/ch9.h b/include/linux/usb/ch9.h
> > index 989a5fc..7d225ee 100644
> > --- a/include/linux/usb/ch9.h
> > +++ b/include/linux/usb/ch9.h
> > @@ -956,6 +956,7 @@ enum usb_device_speed {
> > USB_SPEED_HIGH, /* usb 2.0 */
> > USB_SPEED_WIRELESS, /* wireless (usb 2.5) */
> > USB_SPEED_SUPER,/* usb 3.0 */
> > +   USB_SPEED_SUPER_PLUS,   /* usb 3.1 */
> >  };
> >
> >  #ifdef __KERNEL__
> 
> Should we add usb 3.2 as well?
I found the patches to support USB3.2 are still in public review for
Linux kernel, so no need support it currently

> 
> Reviewed-by: Bin Meng 



Re: [PATCH next v7 02/10] dt-bindings: usb: mtu3: add bindings for MediaTek USB3 DRD

2020-10-13 Thread Chunfeng Yun
On Tue, 2020-10-13 at 22:18 +0800, Bin Meng wrote:
> On Fri, Sep 18, 2020 at 5:12 PM Chunfeng Yun  
> wrote:
> >
> > Add dt-binding for MediaTek USB3 DRD Driver
> 
> There are some differences compared to the one in the Linux kernel:
Some properties are removed due to dual-role switch is not supported in
Uboot.

> https://github.com/torvalds/linux/blob/master/Documentation/devicetree/bindings/usb/mediatek%2Cmtu3.txt
> 
> Please specify which kernel commit id the device bindings are referenced here.
Ok, will add it in next version

Thanks

> 
> >
> > Signed-off-by: Chunfeng Yun 
> > ---
> > v5~v7: no changes
> >
> > v4:
> >   Add support host mode, introduce some new properties and subnode
> >
> > v2~v3: no changes
> > ---
> >  doc/device-tree-bindings/usb/mediatek,mtu3.txt | 79 
> > ++
> >  1 file changed, 79 insertions(+)
> >  create mode 100644 doc/device-tree-bindings/usb/mediatek,mtu3.txt
> >
> 
> Regards,
> Bin



Re: [PATCH next v7 00/10] Add support MediaTek USB3 DRD driver

2020-10-13 Thread Chunfeng Yun
Hi Bin,

Gentle ping...

Could you help to review this series?

Thanks a lot


On Mon, 2020-09-28 at 04:12 +0200, Marek Vasut wrote:
> On 9/28/20 4:01 AM, Chunfeng Yun wrote:
> [...]
> >>  create mode 100644 drivers/usb/mtu3/mtu3_core.c
> >>  create mode 100644 drivers/usb/mtu3/mtu3_dr.h
> >>  create mode 100644 drivers/usb/mtu3/mtu3_gadget.c
> >>  create mode 100644 drivers/usb/mtu3/mtu3_gadget_ep0.c
> >>  create mode 100644 drivers/usb/mtu3/mtu3_host.c
> >>  create mode 100644 drivers/usb/mtu3/mtu3_hw_regs.h
> >>  create mode 100644 drivers/usb/mtu3/mtu3_plat.c
> >>  create mode 100644 drivers/usb/mtu3/mtu3_qmu.c
> >>  create mode 100644 drivers/usb/mtu3/mtu3_qmu.h
> 
> Since this is USB3 driver, you want this reviewed by Bin



Re: [PATCH next v7 00/10] Add support MediaTek USB3 DRD driver

2020-09-27 Thread Chunfeng Yun
Hi Marek,

On Mon, 2020-09-28 at 04:12 +0200, Marek Vasut wrote:
> On 9/28/20 4:01 AM, Chunfeng Yun wrote:
> [...]
> >>  create mode 100644 drivers/usb/mtu3/mtu3_core.c
> >>  create mode 100644 drivers/usb/mtu3/mtu3_dr.h
> >>  create mode 100644 drivers/usb/mtu3/mtu3_gadget.c
> >>  create mode 100644 drivers/usb/mtu3/mtu3_gadget_ep0.c
> >>  create mode 100644 drivers/usb/mtu3/mtu3_host.c
> >>  create mode 100644 drivers/usb/mtu3/mtu3_hw_regs.h
> >>  create mode 100644 drivers/usb/mtu3/mtu3_plat.c
> >>  create mode 100644 drivers/usb/mtu3/mtu3_qmu.c
> >>  create mode 100644 drivers/usb/mtu3/mtu3_qmu.h
> 
> Since this is USB3 driver, you want this reviewed by Bin
Got it.

Hi Bin,

  Would you please help to review this series?

Thank you Marek and Bin




Re: [PATCH next v7 00/10] Add support MediaTek USB3 DRD driver

2020-09-27 Thread Chunfeng Yun
Hi Marek, Lukasz

   Any comments on this patch series?

Thanks a lot


On Fri, 2020-09-18 at 17:10 +0800, Chunfeng Yun wrote:
> These patches introduce the MediaTek USB3 Dual-Role Controller
> driver.
> The driver can be configured as Peripheral only and Host only(xHCI)
> modes, and it's ported from Linux Kernel 5.8-rc1
> 
> v7 changes
> 1. use xhci quirk flag XHCI_MTK_HOST
> 
> v6 changes
> 1. modify commit message of [4/10]
> 
> v5 changes:
> 1. change condition of readl_poll_timeout() when check clocks
> 2. add xhci-mtk.c and myself as maintainer for MTK USB
> 
> v4 changes:
> 1. [4/10], [9/10] and [10/10] are new patches
> 2. add a glue driver
> 3. add host driver and rebuild host flow
> 4. support force_vbus mode for device
> 5. update bindings to support glue driver
> 
> v3 changes:
> 1. add patch [5/7]
> 2. add udc_set_speed()
> 3. simplify some code flow
> 
> v2 changes:
> 1. simplify QMU operations
> 
> Chunfeng Yun (10):
>   dt-binding: usb: add bindings for some common properties
>   dt-bindings: usb: mtu3: add bindings for MediaTek USB3 DRD
>   usb: add USB_SPEED_SUPER_PLUS
>   usb: common: add define of usb_speed_string()
>   usb: add MediaTek USB3 DRD driver
>   usb: gadget: Add bcdDevice for the MTU3 USB Gadget Controller
>   arm: dts: mt8512: add usb related nodes
>   configs: mt8512: enable fastboot
>   configs: mt8512: add USB host related configs
>   MAINTAINERS: add USB driver to ARM MEDIATEK
> 
>  MAINTAINERS|   3 +
>  Makefile   |   1 +
>  arch/arm/dts/mt8512-bm1-emmc.dts   |  34 +
>  arch/arm/dts/mt8512.dtsi   |  49 +-
>  configs/mt8512_bm1_emmc_defconfig  |  26 +
>  doc/device-tree-bindings/usb/generic.txt   |  31 +
>  doc/device-tree-bindings/usb/mediatek,mtu3.txt |  79 +++
>  drivers/usb/Kconfig|   2 +
>  drivers/usb/common/common.c|   8 +
>  drivers/usb/gadget/gadget_chips.h  |   8 +
>  drivers/usb/mtu3/Kconfig   |  45 ++
>  drivers/usb/mtu3/Makefile  |  11 +
>  drivers/usb/mtu3/mtu3.h| 423 +++
>  drivers/usb/mtu3/mtu3_core.c   | 838 ++
>  drivers/usb/mtu3/mtu3_dr.h |  52 ++
>  drivers/usb/mtu3/mtu3_gadget.c | 686 ++
>  drivers/usb/mtu3/mtu3_gadget_ep0.c | 933 
> +
>  drivers/usb/mtu3/mtu3_host.c   | 141 
>  drivers/usb/mtu3/mtu3_hw_regs.h| 515 ++
>  drivers/usb/mtu3/mtu3_plat.c   | 368 ++
>  drivers/usb/mtu3/mtu3_qmu.c| 504 +
>  drivers/usb/mtu3/mtu3_qmu.h|  37 +
>  include/linux/usb/ch9.h|   5 +-
>  23 files changed, 4794 insertions(+), 5 deletions(-)
>  create mode 100644 doc/device-tree-bindings/usb/generic.txt
>  create mode 100644 doc/device-tree-bindings/usb/mediatek,mtu3.txt
>  create mode 100644 drivers/usb/mtu3/Kconfig
>  create mode 100644 drivers/usb/mtu3/Makefile
>  create mode 100644 drivers/usb/mtu3/mtu3.h
>  create mode 100644 drivers/usb/mtu3/mtu3_core.c
>  create mode 100644 drivers/usb/mtu3/mtu3_dr.h
>  create mode 100644 drivers/usb/mtu3/mtu3_gadget.c
>  create mode 100644 drivers/usb/mtu3/mtu3_gadget_ep0.c
>  create mode 100644 drivers/usb/mtu3/mtu3_host.c
>  create mode 100644 drivers/usb/mtu3/mtu3_hw_regs.h
>  create mode 100644 drivers/usb/mtu3/mtu3_plat.c
>  create mode 100644 drivers/usb/mtu3/mtu3_qmu.c
>  create mode 100644 drivers/usb/mtu3/mtu3_qmu.h
> 



[PATCH next v7 07/10] arm: dts: mt8512: add usb related nodes

2020-09-18 Thread Chunfeng Yun
Add usb, usb phy, and fixed regulators nodes

Signed-off-by: Chunfeng Yun 
---
v5~v7: no changes

v4: add host related properties, add subnode.

v3: remove unused property mediatek,discth

v2: no changes
---
 arch/arm/dts/mt8512-bm1-emmc.dts | 34 
 arch/arm/dts/mt8512.dtsi | 49 +++-
 2 files changed, 82 insertions(+), 1 deletion(-)

diff --git a/arch/arm/dts/mt8512-bm1-emmc.dts b/arch/arm/dts/mt8512-bm1-emmc.dts
index 296ed93..12511b5 100644
--- a/arch/arm/dts/mt8512-bm1-emmc.dts
+++ b/arch/arm/dts/mt8512-bm1-emmc.dts
@@ -43,6 +43,25 @@
regulator-boot-on;
regulator-always-on;
};
+
+   usb_p0_vbus: regulator@0 {
+   compatible = "regulator-fixed";
+   regulator-name = "p0_vbus";
+   regulator-min-microvolt = <500>;
+   regulator-max-microvolt = <500>;
+   gpio = <&gpio 27 GPIO_ACTIVE_HIGH>;
+   enable-active-high;
+   };
+
+   usb_p1_vbus: regulator@1 {
+   compatible = "regulator-fixed";
+   regulator-name = "p1_vbus";
+   regulator-min-microvolt = <500>;
+   regulator-max-microvolt = <500>;
+   gpio = <&gpio 32 GPIO_ACTIVE_HIGH>;
+   enable-active-high;
+   regulator-always-on;
+   };
 };
 
 &mmc0 {
@@ -95,6 +114,21 @@
};
 };
 
+&ssusb {
+   dr_mode = "peripheral";
+   maximum-speed = "high-speed";
+   status = "okay";
+};
+
+&usb3 {
+   vbus-supply = <&usb_p0_vbus>;
+   status = "okay";
+};
+
+&u3phy {
+   status = "okay";
+};
+
 &uart0 {
pinctrl-names = "default";
pinctrl-0 = <&uart0_pins>;
diff --git a/arch/arm/dts/mt8512.dtsi b/arch/arm/dts/mt8512.dtsi
index 01a02a7..bdb84f8 100644
--- a/arch/arm/dts/mt8512.dtsi
+++ b/arch/arm/dts/mt8512.dtsi
@@ -9,6 +9,7 @@
 #include 
 #include 
 #include 
+#include 
 
 / {
compatible = "mediatek,mt8512";
@@ -100,6 +101,52 @@
status = "disabled";
};
 
+   usb3: usb@11213e00 {
+   compatible = "mediatek,mt8512-mtu3", "mediatek,mtu3";
+   reg = <0x11213e00 0x0100>;
+   reg-names = "ippc";
+   phys = <&u2port0 PHY_TYPE_USB2>, <&u2port1 PHY_TYPE_USB2>;
+   clocks = <&infracfg CLK_INFRA_USB_SYS>,
+<&topckgen CLK_TOP_SSUSB_TOP_CK_EN>,
+<&infracfg CLK_INFRA_ICUSB>;
+   clock-names = "sys_ck", "ref_ck", "mcu_ck";
+   #address-cells = <1>;
+   #size-cells = <1>;
+   ranges;
+   status = "disabled";
+
+   ssusb: usb@1121 {
+   compatible = "mediatek,ssusb";
+   reg = <0x1121 0x3e00>;
+   interrupts = ;
+   reg-names = "mac";
+   status = "disabled";
+   };
+   };
+
+   u3phy: usb-phy@11cc {
+   compatible = "mediatek,mt8512-tphy",
+"mediatek,generic-tphy-v2";
+   #address-cells = <1>;
+   #size-cells = <1>;
+   ranges;
+   status = "disabled";
+
+   u2port0: usb-phy@11cc {
+   reg = <0x11cc 0x400>;
+   clocks = <&topckgen CLK_TOP_USB20_48M_EN>;
+   clock-names = "ref";
+   #phy-cells = <1>;
+   status = "okay";
+   };
+
+   u2port1: usb-phy@11c4 {
+   reg = <0x11c4 0x400>;
+   #phy-cells = <1>;
+   status = "okay";
+   };
+   };
+
mmc0: mmc@1123 {
compatible = "mediatek,mt8512-mmc";
reg = <0x1123 0x1000>,
@@ -112,4 +159,4 @@
status = "disabled";
};
 
-};
\ No newline at end of file
+};
-- 
1.9.1


[PATCH next v7 08/10] configs: mt8512: enable fastboot

2020-09-18 Thread Chunfeng Yun
Enable fastboot to support download image from usb, also enable
usb related drivers, such as usb phy etc.

Signed-off-by: Chunfeng Yun 
---
v2~v7: no changes
---
 configs/mt8512_bm1_emmc_defconfig | 19 +++
 1 file changed, 19 insertions(+)

diff --git a/configs/mt8512_bm1_emmc_defconfig 
b/configs/mt8512_bm1_emmc_defconfig
index 950507f..d41446f 100644
--- a/configs/mt8512_bm1_emmc_defconfig
+++ b/configs/mt8512_bm1_emmc_defconfig
@@ -9,6 +9,7 @@ CONFIG_DM_GPIO=y
 CONFIG_TARGET_MT8512=y
 CONFIG_DEFAULT_DEVICE_TREE="mt8512-bm1-emmc"
 CONFIG_FIT=y
+CONFIG_EFI_PARTITION=y
 CONFIG_FIT_SIGNATURE=y
 CONFIG_DEFAULT_FDT_FILE="mt8512-bm1-emmc.dtb"
 CONFIG_SYS_PROMPT="MT8512> "
@@ -26,6 +27,15 @@ CONFIG_PINCONF=y
 CONFIG_PINCTRL_MT8512=y
 CONFIG_RAM=y
 CONFIG_BAUDRATE=921600
+CONFIG_USB_FUNCTION_FASTBOOT=y
+CONFIG_FASTBOOT_BUF_ADDR=0x5600
+CONFIG_FASTBOOT_BUF_SIZE=0x1e0
+CONFIG_FASTBOOT_FLASH=y
+CONFIG_FASTBOOT_FLASH_MMC_DEV=0
+CONFIG_FASTBOOT_MMC_BOOT1_SUPPORT=y
+CONFIG_PHY=y
+CONFIG_PHY_MTK_TPHY=y
+CONFIG_DM_REGULATOR=y
 CONFIG_DM_SERIAL=y
 CONFIG_MTK_SERIAL=y
 CONFIG_TIMER=y
@@ -33,3 +43,12 @@ CONFIG_MTK_TIMER=y
 CONFIG_WDT=y
 CONFIG_WDT_MTK=y
 CONFIG_LZO=y
+CONFIG_USB=y
+CONFIG_DM_USB=y
+CONFIG_DM_USB_GADGET=y
+CONFIG_USB_MTU3=y
+CONFIG_USB_MTU3_GADGET=y
+CONFIG_USB_GADGET=y
+CONFIG_USB_GADGET_MANUFACTURER="MediaTek"
+CONFIG_USB_GADGET_VENDOR_NUM=0x0e8d
+CONFIG_USB_GADGET_PRODUCT_NUM=0x201c
-- 
1.9.1


[PATCH next v7 09/10] configs: mt8512: add USB host related configs

2020-09-18 Thread Chunfeng Yun
Add USB, FAT commands, and fixed regulator, mass storage
drivers.
Due to device mode is enabled by default, comment out
the host mode config here.

Signed-off-by: Chunfeng Yun 
---
v5~v7: no changes

v4: new patch
---
 configs/mt8512_bm1_emmc_defconfig | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/configs/mt8512_bm1_emmc_defconfig 
b/configs/mt8512_bm1_emmc_defconfig
index d41446f..6b5454c 100644
--- a/configs/mt8512_bm1_emmc_defconfig
+++ b/configs/mt8512_bm1_emmc_defconfig
@@ -15,6 +15,10 @@ CONFIG_DEFAULT_FDT_FILE="mt8512-bm1-emmc.dtb"
 CONFIG_SYS_PROMPT="MT8512> "
 CONFIG_CMD_BOOTMENU=y
 CONFIG_CMD_MMC=y
+CONFIG_CMD_USB=y
+CONFIG_CMD_FAT=y
+CONFIG_CMD_FS_GENERIC=y
+# CONFIG_DOS_PARTITION is not set
 CONFIG_ENV_OVERWRITE=y
 CONFIG_REGMAP=y
 CONFIG_SYSCON=y
@@ -36,6 +40,7 @@ CONFIG_FASTBOOT_MMC_BOOT1_SUPPORT=y
 CONFIG_PHY=y
 CONFIG_PHY_MTK_TPHY=y
 CONFIG_DM_REGULATOR=y
+CONFIG_DM_REGULATOR_FIXED=y
 CONFIG_DM_SERIAL=y
 CONFIG_MTK_SERIAL=y
 CONFIG_TIMER=y
@@ -48,6 +53,8 @@ CONFIG_DM_USB=y
 CONFIG_DM_USB_GADGET=y
 CONFIG_USB_MTU3=y
 CONFIG_USB_MTU3_GADGET=y
+#CONFIG_USB_MTU3_HOST=y
+CONFIG_USB_STORAGE=y
 CONFIG_USB_GADGET=y
 CONFIG_USB_GADGET_MANUFACTURER="MediaTek"
 CONFIG_USB_GADGET_VENDOR_NUM=0x0e8d
-- 
1.9.1


[PATCH next v7 00/10] Add support MediaTek USB3 DRD driver

2020-09-18 Thread Chunfeng Yun
These patches introduce the MediaTek USB3 Dual-Role Controller
driver.
The driver can be configured as Peripheral only and Host only(xHCI)
modes, and it's ported from Linux Kernel 5.8-rc1

v7 changes
1. use xhci quirk flag XHCI_MTK_HOST

v6 changes
1. modify commit message of [4/10]

v5 changes:
1. change condition of readl_poll_timeout() when check clocks
2. add xhci-mtk.c and myself as maintainer for MTK USB

v4 changes:
1. [4/10], [9/10] and [10/10] are new patches
2. add a glue driver
3. add host driver and rebuild host flow
4. support force_vbus mode for device
5. update bindings to support glue driver

v3 changes:
1. add patch [5/7]
2. add udc_set_speed()
3. simplify some code flow

v2 changes:
1. simplify QMU operations

Chunfeng Yun (10):
  dt-binding: usb: add bindings for some common properties
  dt-bindings: usb: mtu3: add bindings for MediaTek USB3 DRD
  usb: add USB_SPEED_SUPER_PLUS
  usb: common: add define of usb_speed_string()
  usb: add MediaTek USB3 DRD driver
  usb: gadget: Add bcdDevice for the MTU3 USB Gadget Controller
  arm: dts: mt8512: add usb related nodes
  configs: mt8512: enable fastboot
  configs: mt8512: add USB host related configs
  MAINTAINERS: add USB driver to ARM MEDIATEK

 MAINTAINERS|   3 +
 Makefile   |   1 +
 arch/arm/dts/mt8512-bm1-emmc.dts   |  34 +
 arch/arm/dts/mt8512.dtsi   |  49 +-
 configs/mt8512_bm1_emmc_defconfig  |  26 +
 doc/device-tree-bindings/usb/generic.txt   |  31 +
 doc/device-tree-bindings/usb/mediatek,mtu3.txt |  79 +++
 drivers/usb/Kconfig|   2 +
 drivers/usb/common/common.c|   8 +
 drivers/usb/gadget/gadget_chips.h  |   8 +
 drivers/usb/mtu3/Kconfig   |  45 ++
 drivers/usb/mtu3/Makefile  |  11 +
 drivers/usb/mtu3/mtu3.h| 423 +++
 drivers/usb/mtu3/mtu3_core.c   | 838 ++
 drivers/usb/mtu3/mtu3_dr.h |  52 ++
 drivers/usb/mtu3/mtu3_gadget.c | 686 ++
 drivers/usb/mtu3/mtu3_gadget_ep0.c | 933 +
 drivers/usb/mtu3/mtu3_host.c   | 141 
 drivers/usb/mtu3/mtu3_hw_regs.h| 515 ++
 drivers/usb/mtu3/mtu3_plat.c   | 368 ++
 drivers/usb/mtu3/mtu3_qmu.c| 504 +
 drivers/usb/mtu3/mtu3_qmu.h|  37 +
 include/linux/usb/ch9.h|   5 +-
 23 files changed, 4794 insertions(+), 5 deletions(-)
 create mode 100644 doc/device-tree-bindings/usb/generic.txt
 create mode 100644 doc/device-tree-bindings/usb/mediatek,mtu3.txt
 create mode 100644 drivers/usb/mtu3/Kconfig
 create mode 100644 drivers/usb/mtu3/Makefile
 create mode 100644 drivers/usb/mtu3/mtu3.h
 create mode 100644 drivers/usb/mtu3/mtu3_core.c
 create mode 100644 drivers/usb/mtu3/mtu3_dr.h
 create mode 100644 drivers/usb/mtu3/mtu3_gadget.c
 create mode 100644 drivers/usb/mtu3/mtu3_gadget_ep0.c
 create mode 100644 drivers/usb/mtu3/mtu3_host.c
 create mode 100644 drivers/usb/mtu3/mtu3_hw_regs.h
 create mode 100644 drivers/usb/mtu3/mtu3_plat.c
 create mode 100644 drivers/usb/mtu3/mtu3_qmu.c
 create mode 100644 drivers/usb/mtu3/mtu3_qmu.h

-- 
1.9.1


[PATCH next v7 10/10] MAINTAINERS: add USB driver to ARM MEDIATEK

2020-09-18 Thread Chunfeng Yun
Add MediaTek USB3 Dual-Role controller driver to ARM MEDIATEK,
and add myself as a maintainer for it.

Signed-off-by: Chunfeng Yun 
---
v6~v7: no changes

v5: add mtu3/, xhci-mtk.c, and myself as maintainer for MTK USB

v4: new patch
---
 MAINTAINERS | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 7e46470..08724f8 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -262,6 +262,7 @@ F:  arch/arm/include/asm/arch-pxa/
 ARM MEDIATEK
 M: Ryder Lee 
 M: Weijie Gao 
+M: Chunfeng Yun 
 R: GSS_MTK_Uboot_upstream 
 S: Maintained
 F: arch/arm/mach-mediatek/
@@ -278,6 +279,8 @@ F:  drivers/power/domain/mtk-power-domain.c
 F: drivers/ram/mediatek/
 F: drivers/spi/mtk_snfi_spi.c
 F: drivers/timer/mtk_timer.c
+F: drivers/usb/host/xhci-mtk.c
+F: drivers/usb/mtu3/
 F: drivers/watchdog/mtk_wdt.c
 F: drivers/net/mtk_eth.c
 F: drivers/reset/reset-mediatek.c
-- 
1.9.1


[PATCH next v7 03/10] usb: add USB_SPEED_SUPER_PLUS

2020-09-18 Thread Chunfeng Yun
Add enum USB_SPEED_SUPER_PLUS for USB3.1

Signed-off-by: Chunfeng Yun 
---
v5~v7: no changes

v4: also add it into speed_names array

v2~v3: no changes
---
 drivers/usb/common/common.c | 1 +
 include/linux/usb/ch9.h | 1 +
 2 files changed, 2 insertions(+)

diff --git a/drivers/usb/common/common.c b/drivers/usb/common/common.c
index d4ae186..76f5a9c 100644
--- a/drivers/usb/common/common.c
+++ b/drivers/usb/common/common.c
@@ -46,6 +46,7 @@ static const char *const speed_names[] = {
[USB_SPEED_HIGH] = "high-speed",
[USB_SPEED_WIRELESS] = "wireless",
[USB_SPEED_SUPER] = "super-speed",
+   [USB_SPEED_SUPER_PLUS] = "super-speed-plus",
 };
 
 enum usb_device_speed usb_get_maximum_speed(ofnode node)
diff --git a/include/linux/usb/ch9.h b/include/linux/usb/ch9.h
index 989a5fc..7d225ee 100644
--- a/include/linux/usb/ch9.h
+++ b/include/linux/usb/ch9.h
@@ -956,6 +956,7 @@ enum usb_device_speed {
USB_SPEED_HIGH, /* usb 2.0 */
USB_SPEED_WIRELESS, /* wireless (usb 2.5) */
USB_SPEED_SUPER,/* usb 3.0 */
+   USB_SPEED_SUPER_PLUS,   /* usb 3.1 */
 };
 
 #ifdef __KERNEL__
-- 
1.9.1


[PATCH next v7 06/10] usb: gadget: Add bcdDevice for the MTU3 USB Gadget Controller

2020-09-18 Thread Chunfeng Yun
Add an entry in usb_gadget_controller_number() for the MTU3
gadget controller. It is used to bind the USB Ethernet driver.

Signed-off-by: Chunfeng Yun 
---
v4~v7: no changes

v3: new patch
---
 drivers/usb/gadget/gadget_chips.h | 8 
 1 file changed, 8 insertions(+)

diff --git a/drivers/usb/gadget/gadget_chips.h 
b/drivers/usb/gadget/gadget_chips.h
index 587204c..0cdf47c 100644
--- a/drivers/usb/gadget/gadget_chips.h
+++ b/drivers/usb/gadget/gadget_chips.h
@@ -161,6 +161,12 @@
 #define gadget_is_max3420(g)0
 #endif
 
+#ifdef CONFIG_USB_MTU3_GADGET
+#define gadget_is_mtu3(g)(!strcmp("mtu3-gadget", (g)->name))
+#else
+#define gadget_is_mtu3(g)0
+#endif
+
 /**
  * usb_gadget_controller_number - support bcdDevice id convention
  * @gadget: the controller being driven
@@ -224,5 +230,7 @@ static inline int usb_gadget_controller_number(struct 
usb_gadget *gadget)
return 0x24;
else if (gadget_is_max3420(gadget))
return 0x25;
+   else if (gadget_is_mtu3(gadget))
+   return 0x26;
return -ENOENT;
 }
-- 
1.9.1


[PATCH next v7 01/10] dt-binding: usb: add bindings for some common properties

2020-09-18 Thread Chunfeng Yun
Add bindings for common properties, include maximum-speed,
dr_mode and phy_type

Signed-off-by: Chunfeng Yun 
---
v2~v7: no changes
---
 doc/device-tree-bindings/usb/generic.txt | 31 +++
 1 file changed, 31 insertions(+)
 create mode 100644 doc/device-tree-bindings/usb/generic.txt

diff --git a/doc/device-tree-bindings/usb/generic.txt 
b/doc/device-tree-bindings/usb/generic.txt
new file mode 100644
index 000..a02a198
--- /dev/null
+++ b/doc/device-tree-bindings/usb/generic.txt
@@ -0,0 +1,31 @@
+Generic USB Properties
+
+Optional properties:
+ - maximum-speed: tells USB controllers we want to work up to a certain
+   speed. Valid arguments are "super-speed-plus",
+   "super-speed", "high-speed", "full-speed" and
+   "low-speed". In case this isn't passed via DT, USB
+   controllers should default to their maximum HW
+   capability.
+ - dr_mode: tells Dual-Role USB controllers that we want to work on a
+   particular mode. Valid arguments are "host",
+   "peripheral" and "otg". In case this attribute isn't
+   passed via DT, USB DRD controllers should default to
+   OTG.
+ - phy_type: tells USB controllers that we want to configure the core to 
support
+   a UTMI+ PHY with an 8- or 16-bit interface if UTMI+ is
+   selected. Valid arguments are "utmi" and "utmi_wide".
+   In case this isn't passed via DT, USB controllers should
+   default to HW capability.
+
+This is an attribute to a USB controller such as:
+
+dwc3@4a03 {
+   compatible = "synopsys,dwc3";
+   reg = <0x4a03 0xcfff>;
+   interrupts = <0 92 4>
+   usb-phy = <&usb2_phy>, <&usb3,phy>;
+   maximum-speed = "super-speed";
+   dr_mode = "otg";
+   phy_type = "utmi_wide";
+};
-- 
1.9.1


[PATCH next v7 02/10] dt-bindings: usb: mtu3: add bindings for MediaTek USB3 DRD

2020-09-18 Thread Chunfeng Yun
Add dt-binding for MediaTek USB3 DRD Driver

Signed-off-by: Chunfeng Yun 
---
v5~v7: no changes

v4:
  Add support host mode, introduce some new properties and subnode

v2~v3: no changes
---
 doc/device-tree-bindings/usb/mediatek,mtu3.txt | 79 ++
 1 file changed, 79 insertions(+)
 create mode 100644 doc/device-tree-bindings/usb/mediatek,mtu3.txt

diff --git a/doc/device-tree-bindings/usb/mediatek,mtu3.txt 
b/doc/device-tree-bindings/usb/mediatek,mtu3.txt
new file mode 100644
index 000..ab877bf
--- /dev/null
+++ b/doc/device-tree-bindings/usb/mediatek,mtu3.txt
@@ -0,0 +1,79 @@
+The device node for Mediatek USB3 DRD controller
+
+Required properties:
+ - compatible : should be "mediatek,-mtu3", "mediatek,mtu3",
+   soc-model is the name of SoC, such as mt8512 etc,
+   when using "mediatek,mtu3" compatible string, you need SoC specific
+   ones in addition, one of:
+   - "mediatek,mt8512-mtu3"
+ - reg : specifies physical base address and size of the registers
+ - reg-names: should be
+   - "ippc" : IP Port Control
+ - power-domains : a phandle to USB power domain node to control USB's MTCMOS
+ - clocks : a list of phandle + clock-specifier pairs, one for each
+   entry in clock-names
+ - clock-names : must contain "sys_ck" for clock of controller,
+   the following clocks are optional:
+   "ref_ck", "mcu_ck", "dma_ck" and "xhci_ck";
+ - phys : list of all the USB PHYs on this HCD
+ - #address-cells, #size-cells : used for sub-nodes with 'reg' property
+ - ranges : allows valid 1:1 translation between child's address space and
+   parent's address space
+
+Optional properties:
+ - vusb33-supply : regulator of USB AVDD3.3v
+ - vbus-supply : regulator of VBUS 5v, needed when supports host mode.
+
+Sub-nodes:
+Required properties:
+ - compatible : should be "mediatek,ssusb"
+ - reg : specifies physical base address and size of the registers
+ - reg-names: should be
+   - "mac" : SSUSB MAC, include xHCI and device
+ - interrupts : interrupt used by xHCI or device
+ - dr_mode : should be one of "host" or "peripheral",
+   see : usb/generic.txt
+
+Optional properties:
+ - pinctrl-names : a pinctrl state named "default" is optional
+ - pinctrl-0 : pin control group
+   See: pinctrl/pinctrl-bindings.txt
+
+ - device mode:
+   - maximum-speed : valid arguments are "full-speed", "high-speed",
+   "super-speed" and "super-speed-plus",
+   see: usb/generic.txt
+   - mediatek,force-vbus : force vbus as valid by SW
+
+ - host mode (dr_mode is "host"):
+   - mediatek,u3p-dis-msk : mask to disable u3ports, bit0 for u3port0,
+   bit1 for u3port1, ... etc;
+
+Example:
+usb3: usb@11213e00 {
+   compatible = "mediatek,mt8512-mtu3", "mediatek,mtu3";
+   reg = <0x11213e00 0x0100>;
+   reg-names = "ippc";
+   phys = <&u2port0 PHY_TYPE_USB2>, <&u2port1 PHY_TYPE_USB2>;
+   power-domains = <&scpsys MT8512_POWER_DOMAIN_USB>;
+   clocks = <&infracfg CLK_INFRA_USB_SYS>,
+<&topckgen CLK_TOP_SSUSB_TOP_CK_EN>,
+<&infracfg CLK_INFRA_ICUSB>;
+   clock-names = "sys_ck", "ref_ck", "mcu_ck";
+   vusb33-supply = ;
+   vbus-supply = <&usb_p0_vbus>;
+   #address-cells = <1>;
+   #size-cells = <1>;
+   ranges;
+   status = "disabled";
+
+   ssusb: usb@1121 {
+   compatible = "mediatek,ssusb";
+   reg = <0x1121 0x3e00>;
+   interrupts = ;
+   reg-names = "mac";
+   dr_mode = "peripheral";
+   maximum-speed = "high-speed";
+   status = "disabled";
+   };
+};
-- 
1.9.1


[PATCH next v7 04/10] usb: common: add define of usb_speed_string()

2020-09-18 Thread Chunfeng Yun
There is only declaration of usb_speed_string(), but no definition,
so add it to avoid build error when call it.

Signed-off-by: Chunfeng Yun 
---
v7: no changes

v6: modify commit message suggested by Roger

v5: no changes

v4: new patch
---
 drivers/usb/common/common.c | 7 +++
 include/linux/usb/ch9.h | 4 
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/common/common.c b/drivers/usb/common/common.c
index 76f5a9c..5e5c3c3 100644
--- a/drivers/usb/common/common.c
+++ b/drivers/usb/common/common.c
@@ -49,6 +49,13 @@ static const char *const speed_names[] = {
[USB_SPEED_SUPER_PLUS] = "super-speed-plus",
 };
 
+const char *usb_speed_string(enum usb_device_speed speed)
+{
+   if (speed < 0 || speed >= ARRAY_SIZE(speed_names))
+   speed = USB_SPEED_UNKNOWN;
+   return speed_names[speed];
+}
+
 enum usb_device_speed usb_get_maximum_speed(ofnode node)
 {
const char *max_speed;
diff --git a/include/linux/usb/ch9.h b/include/linux/usb/ch9.h
index 7d225ee..a8fa5d7 100644
--- a/include/linux/usb/ch9.h
+++ b/include/linux/usb/ch9.h
@@ -959,8 +959,6 @@ enum usb_device_speed {
USB_SPEED_SUPER_PLUS,   /* usb 3.1 */
 };
 
-#ifdef __KERNEL__
-
 /**
  * usb_speed_string() - Returns human readable-name of the speed.
  * @speed: The speed to return human-readable name for.  If it's not
@@ -969,8 +967,6 @@ enum usb_device_speed {
  */
 extern const char *usb_speed_string(enum usb_device_speed speed);
 
-#endif
-
 enum usb_device_state {
/* NOTATTACHED isn't in the USB spec, and this state acts
 * the same as ATTACHED ... but it's clearer this way.
-- 
1.9.1


[PATCH v6 09/10] configs: mt8512: add USB host related configs

2020-09-14 Thread Chunfeng Yun
Add USB, FAT commands, and fixed regulator, mass storage
drivers.
Due to device mode is enabled by default, comment out
the host mode config here.

Signed-off-by: Chunfeng Yun 
---
v5~v6: no changes

v4: new patch
---
 configs/mt8512_bm1_emmc_defconfig | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/configs/mt8512_bm1_emmc_defconfig 
b/configs/mt8512_bm1_emmc_defconfig
index 4b94bff..1ed3dd2 100644
--- a/configs/mt8512_bm1_emmc_defconfig
+++ b/configs/mt8512_bm1_emmc_defconfig
@@ -15,6 +15,10 @@ CONFIG_DEFAULT_FDT_FILE="mt8512-bm1-emmc.dtb"
 CONFIG_SYS_PROMPT="MT8512> "
 CONFIG_CMD_BOOTMENU=y
 CONFIG_CMD_MMC=y
+CONFIG_CMD_USB=y
+CONFIG_CMD_FAT=y
+CONFIG_CMD_FS_GENERIC=y
+# CONFIG_DOS_PARTITION is not set
 CONFIG_ENV_OVERWRITE=y
 CONFIG_REGMAP=y
 CONFIG_SYSCON=y
@@ -36,6 +40,7 @@ CONFIG_FASTBOOT_MMC_BOOT1_SUPPORT=y
 CONFIG_PHY=y
 CONFIG_PHY_MTK_TPHY=y
 CONFIG_DM_REGULATOR=y
+CONFIG_DM_REGULATOR_FIXED=y
 CONFIG_DM_SERIAL=y
 CONFIG_MTK_SERIAL=y
 CONFIG_TIMER=y
@@ -48,6 +53,8 @@ CONFIG_DM_USB=y
 CONFIG_DM_USB_GADGET=y
 CONFIG_USB_MTU3=y
 CONFIG_USB_MTU3_GADGET=y
+#CONFIG_USB_MTU3_HOST=y
+CONFIG_USB_STORAGE=y
 CONFIG_USB_GADGET=y
 CONFIG_USB_GADGET_MANUFACTURER="MediaTek"
 CONFIG_USB_GADGET_VENDOR_NUM=0x0e8d
-- 
1.9.1


[PATCH v6 10/10] MAINTAINERS: add USB driver to ARM MEDIATEK

2020-09-14 Thread Chunfeng Yun
Add MediaTek USB3 Dual-Role controller driver to ARM MEDIATEK,
and add myself as a maintainer for it.

Signed-off-by: Chunfeng Yun 
---
v6: no changes

v5: add mtu3/, xhci-mtk.c, and myself as maintainer for MTK USB

v4: new patch
---
 MAINTAINERS | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 889a73f..4fd1f8f 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -249,6 +249,7 @@ F:  arch/arm/include/asm/arch-pxa/
 ARM MEDIATEK
 M: Ryder Lee 
 M: Weijie Gao 
+M: Chunfeng Yun 
 R: GSS_MTK_Uboot_upstream 
 S: Maintained
 F: arch/arm/mach-mediatek/
@@ -265,6 +266,8 @@ F:  drivers/power/domain/mtk-power-domain.c
 F: drivers/ram/mediatek/
 F: drivers/spi/mtk_snfi_spi.c
 F: drivers/timer/mtk_timer.c
+F: drivers/usb/host/xhci-mtk.c
+F: drivers/usb/mtu3/
 F: drivers/watchdog/mtk_wdt.c
 F: drivers/net/mtk_eth.c
 F: drivers/reset/reset-mediatek.c
-- 
1.9.1


[PATCH v6 07/10] arm: dts: mt8512: add usb related nodes

2020-09-14 Thread Chunfeng Yun
Add usb, usb phy, and fixed regulators nodes

Signed-off-by: Chunfeng Yun 
---
v5~v6: no changes

v4: add host related properties, add subnode.

v3: remove unused property mediatek,discth

v2: no changes
---
 arch/arm/dts/mt8512-bm1-emmc.dts | 34 
 arch/arm/dts/mt8512.dtsi | 49 +++-
 2 files changed, 82 insertions(+), 1 deletion(-)

diff --git a/arch/arm/dts/mt8512-bm1-emmc.dts b/arch/arm/dts/mt8512-bm1-emmc.dts
index 296ed93..12511b5 100644
--- a/arch/arm/dts/mt8512-bm1-emmc.dts
+++ b/arch/arm/dts/mt8512-bm1-emmc.dts
@@ -43,6 +43,25 @@
regulator-boot-on;
regulator-always-on;
};
+
+   usb_p0_vbus: regulator@0 {
+   compatible = "regulator-fixed";
+   regulator-name = "p0_vbus";
+   regulator-min-microvolt = <500>;
+   regulator-max-microvolt = <500>;
+   gpio = <&gpio 27 GPIO_ACTIVE_HIGH>;
+   enable-active-high;
+   };
+
+   usb_p1_vbus: regulator@1 {
+   compatible = "regulator-fixed";
+   regulator-name = "p1_vbus";
+   regulator-min-microvolt = <500>;
+   regulator-max-microvolt = <500>;
+   gpio = <&gpio 32 GPIO_ACTIVE_HIGH>;
+   enable-active-high;
+   regulator-always-on;
+   };
 };
 
 &mmc0 {
@@ -95,6 +114,21 @@
};
 };
 
+&ssusb {
+   dr_mode = "peripheral";
+   maximum-speed = "high-speed";
+   status = "okay";
+};
+
+&usb3 {
+   vbus-supply = <&usb_p0_vbus>;
+   status = "okay";
+};
+
+&u3phy {
+   status = "okay";
+};
+
 &uart0 {
pinctrl-names = "default";
pinctrl-0 = <&uart0_pins>;
diff --git a/arch/arm/dts/mt8512.dtsi b/arch/arm/dts/mt8512.dtsi
index 01a02a7..bdb84f8 100644
--- a/arch/arm/dts/mt8512.dtsi
+++ b/arch/arm/dts/mt8512.dtsi
@@ -9,6 +9,7 @@
 #include 
 #include 
 #include 
+#include 
 
 / {
compatible = "mediatek,mt8512";
@@ -100,6 +101,52 @@
status = "disabled";
};
 
+   usb3: usb@11213e00 {
+   compatible = "mediatek,mt8512-mtu3", "mediatek,mtu3";
+   reg = <0x11213e00 0x0100>;
+   reg-names = "ippc";
+   phys = <&u2port0 PHY_TYPE_USB2>, <&u2port1 PHY_TYPE_USB2>;
+   clocks = <&infracfg CLK_INFRA_USB_SYS>,
+<&topckgen CLK_TOP_SSUSB_TOP_CK_EN>,
+<&infracfg CLK_INFRA_ICUSB>;
+   clock-names = "sys_ck", "ref_ck", "mcu_ck";
+   #address-cells = <1>;
+   #size-cells = <1>;
+   ranges;
+   status = "disabled";
+
+   ssusb: usb@1121 {
+   compatible = "mediatek,ssusb";
+   reg = <0x1121 0x3e00>;
+   interrupts = ;
+   reg-names = "mac";
+   status = "disabled";
+   };
+   };
+
+   u3phy: usb-phy@11cc {
+   compatible = "mediatek,mt8512-tphy",
+"mediatek,generic-tphy-v2";
+   #address-cells = <1>;
+   #size-cells = <1>;
+   ranges;
+   status = "disabled";
+
+   u2port0: usb-phy@11cc {
+   reg = <0x11cc 0x400>;
+   clocks = <&topckgen CLK_TOP_USB20_48M_EN>;
+   clock-names = "ref";
+   #phy-cells = <1>;
+   status = "okay";
+   };
+
+   u2port1: usb-phy@11c4 {
+   reg = <0x11c4 0x400>;
+   #phy-cells = <1>;
+   status = "okay";
+   };
+   };
+
mmc0: mmc@1123 {
compatible = "mediatek,mt8512-mmc";
reg = <0x1123 0x1000>,
@@ -112,4 +159,4 @@
status = "disabled";
};
 
-};
\ No newline at end of file
+};
-- 
1.9.1


[PATCH v6 03/10] usb: add USB_SPEED_SUPER_PLUS

2020-09-14 Thread Chunfeng Yun
Add enum USB_SPEED_SUPER_PLUS for USB3.1

Signed-off-by: Chunfeng Yun 
---
v5~v6: no changes

v4: also add it into speed_names array

v2~v3: no changes
---
 drivers/usb/common/common.c | 1 +
 include/linux/usb/ch9.h | 1 +
 2 files changed, 2 insertions(+)

diff --git a/drivers/usb/common/common.c b/drivers/usb/common/common.c
index d4ae186..76f5a9c 100644
--- a/drivers/usb/common/common.c
+++ b/drivers/usb/common/common.c
@@ -46,6 +46,7 @@ static const char *const speed_names[] = {
[USB_SPEED_HIGH] = "high-speed",
[USB_SPEED_WIRELESS] = "wireless",
[USB_SPEED_SUPER] = "super-speed",
+   [USB_SPEED_SUPER_PLUS] = "super-speed-plus",
 };
 
 enum usb_device_speed usb_get_maximum_speed(ofnode node)
diff --git a/include/linux/usb/ch9.h b/include/linux/usb/ch9.h
index 989a5fc..7d225ee 100644
--- a/include/linux/usb/ch9.h
+++ b/include/linux/usb/ch9.h
@@ -956,6 +956,7 @@ enum usb_device_speed {
USB_SPEED_HIGH, /* usb 2.0 */
USB_SPEED_WIRELESS, /* wireless (usb 2.5) */
USB_SPEED_SUPER,/* usb 3.0 */
+   USB_SPEED_SUPER_PLUS,   /* usb 3.1 */
 };
 
 #ifdef __KERNEL__
-- 
1.9.1


[PATCH v6 04/10] usb: common: add define of usb_speed_string()

2020-09-14 Thread Chunfeng Yun
There is only declaration of usb_speed_string(), but no definition,
so add it to avoid build error when call it.

Signed-off-by: Chunfeng Yun 
---
v6: modify commit message suggested by Roger

v5: no changes

v4: new patch
---
 drivers/usb/common/common.c | 7 +++
 include/linux/usb/ch9.h | 4 
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/common/common.c b/drivers/usb/common/common.c
index 76f5a9c..5e5c3c3 100644
--- a/drivers/usb/common/common.c
+++ b/drivers/usb/common/common.c
@@ -49,6 +49,13 @@ static const char *const speed_names[] = {
[USB_SPEED_SUPER_PLUS] = "super-speed-plus",
 };
 
+const char *usb_speed_string(enum usb_device_speed speed)
+{
+   if (speed < 0 || speed >= ARRAY_SIZE(speed_names))
+   speed = USB_SPEED_UNKNOWN;
+   return speed_names[speed];
+}
+
 enum usb_device_speed usb_get_maximum_speed(ofnode node)
 {
const char *max_speed;
diff --git a/include/linux/usb/ch9.h b/include/linux/usb/ch9.h
index 7d225ee..a8fa5d7 100644
--- a/include/linux/usb/ch9.h
+++ b/include/linux/usb/ch9.h
@@ -959,8 +959,6 @@ enum usb_device_speed {
USB_SPEED_SUPER_PLUS,   /* usb 3.1 */
 };
 
-#ifdef __KERNEL__
-
 /**
  * usb_speed_string() - Returns human readable-name of the speed.
  * @speed: The speed to return human-readable name for.  If it's not
@@ -969,8 +967,6 @@ enum usb_device_speed {
  */
 extern const char *usb_speed_string(enum usb_device_speed speed);
 
-#endif
-
 enum usb_device_state {
/* NOTATTACHED isn't in the USB spec, and this state acts
 * the same as ATTACHED ... but it's clearer this way.
-- 
1.9.1


[PATCH v6 08/10] configs: mt8512: enable fastboot

2020-09-14 Thread Chunfeng Yun
Enable fastboot to support download image from usb, also enable
usb related drivers, such as usb phy etc.

Signed-off-by: Chunfeng Yun 
---
v2~v6: no changes
---
 configs/mt8512_bm1_emmc_defconfig | 19 +++
 1 file changed, 19 insertions(+)

diff --git a/configs/mt8512_bm1_emmc_defconfig 
b/configs/mt8512_bm1_emmc_defconfig
index 10a2083..4b94bff 100644
--- a/configs/mt8512_bm1_emmc_defconfig
+++ b/configs/mt8512_bm1_emmc_defconfig
@@ -9,6 +9,7 @@ CONFIG_TARGET_MT8512=y
 CONFIG_NR_DRAM_BANKS=1
 CONFIG_DEFAULT_DEVICE_TREE="mt8512-bm1-emmc"
 CONFIG_FIT=y
+CONFIG_EFI_PARTITION=y
 CONFIG_FIT_SIGNATURE=y
 CONFIG_DEFAULT_FDT_FILE="mt8512-bm1-emmc.dtb"
 CONFIG_SYS_PROMPT="MT8512> "
@@ -26,6 +27,15 @@ CONFIG_PINCONF=y
 CONFIG_PINCTRL_MT8512=y
 CONFIG_RAM=y
 CONFIG_BAUDRATE=921600
+CONFIG_USB_FUNCTION_FASTBOOT=y
+CONFIG_FASTBOOT_BUF_ADDR=0x5600
+CONFIG_FASTBOOT_BUF_SIZE=0x1e0
+CONFIG_FASTBOOT_FLASH=y
+CONFIG_FASTBOOT_FLASH_MMC_DEV=0
+CONFIG_FASTBOOT_MMC_BOOT1_SUPPORT=y
+CONFIG_PHY=y
+CONFIG_PHY_MTK_TPHY=y
+CONFIG_DM_REGULATOR=y
 CONFIG_DM_SERIAL=y
 CONFIG_MTK_SERIAL=y
 CONFIG_TIMER=y
@@ -33,3 +43,12 @@ CONFIG_MTK_TIMER=y
 CONFIG_WDT=y
 CONFIG_WDT_MTK=y
 CONFIG_LZO=y
+CONFIG_USB=y
+CONFIG_DM_USB=y
+CONFIG_DM_USB_GADGET=y
+CONFIG_USB_MTU3=y
+CONFIG_USB_MTU3_GADGET=y
+CONFIG_USB_GADGET=y
+CONFIG_USB_GADGET_MANUFACTURER="MediaTek"
+CONFIG_USB_GADGET_VENDOR_NUM=0x0e8d
+CONFIG_USB_GADGET_PRODUCT_NUM=0x201c
-- 
1.9.1


[PATCH v6 06/10] usb: gadget: Add bcdDevice for the MTU3 USB Gadget Controller

2020-09-14 Thread Chunfeng Yun
Add an entry in usb_gadget_controller_number() for the MTU3
gadget controller. It is used to bind the USB Ethernet driver.

Signed-off-by: Chunfeng Yun 
---
v4~v6: no changes

v3: new patch
---
 drivers/usb/gadget/gadget_chips.h | 8 
 1 file changed, 8 insertions(+)

diff --git a/drivers/usb/gadget/gadget_chips.h 
b/drivers/usb/gadget/gadget_chips.h
index 91b0285..2dc4c47 100644
--- a/drivers/usb/gadget/gadget_chips.h
+++ b/drivers/usb/gadget/gadget_chips.h
@@ -155,6 +155,12 @@
 #define gadget_is_cdns3(g)0
 #endif
 
+#ifdef CONFIG_USB_MTU3_GADGET
+#define gadget_is_mtu3(g)(!strcmp("mtu3-gadget", (g)->name))
+#else
+#define gadget_is_mtu3(g)0
+#endif
+
 /**
  * usb_gadget_controller_number - support bcdDevice id convention
  * @gadget: the controller being driven
@@ -216,5 +222,7 @@ static inline int usb_gadget_controller_number(struct 
usb_gadget *gadget)
return 0x23;
else if (gadget_is_cdns3(gadget))
return 0x24;
+   else if (gadget_is_mtu3(gadget))
+   return 0x25;
return -ENOENT;
 }
-- 
1.9.1


[PATCH v6 01/10] dt-binding: usb: add bindings for some common properties

2020-09-14 Thread Chunfeng Yun
Add bindings for common properties, include maximum-speed,
dr_mode and phy_type

Signed-off-by: Chunfeng Yun 
---
v2~v6: no changes
---
 doc/device-tree-bindings/usb/generic.txt | 31 +++
 1 file changed, 31 insertions(+)
 create mode 100644 doc/device-tree-bindings/usb/generic.txt

diff --git a/doc/device-tree-bindings/usb/generic.txt 
b/doc/device-tree-bindings/usb/generic.txt
new file mode 100644
index 000..a02a198
--- /dev/null
+++ b/doc/device-tree-bindings/usb/generic.txt
@@ -0,0 +1,31 @@
+Generic USB Properties
+
+Optional properties:
+ - maximum-speed: tells USB controllers we want to work up to a certain
+   speed. Valid arguments are "super-speed-plus",
+   "super-speed", "high-speed", "full-speed" and
+   "low-speed". In case this isn't passed via DT, USB
+   controllers should default to their maximum HW
+   capability.
+ - dr_mode: tells Dual-Role USB controllers that we want to work on a
+   particular mode. Valid arguments are "host",
+   "peripheral" and "otg". In case this attribute isn't
+   passed via DT, USB DRD controllers should default to
+   OTG.
+ - phy_type: tells USB controllers that we want to configure the core to 
support
+   a UTMI+ PHY with an 8- or 16-bit interface if UTMI+ is
+   selected. Valid arguments are "utmi" and "utmi_wide".
+   In case this isn't passed via DT, USB controllers should
+   default to HW capability.
+
+This is an attribute to a USB controller such as:
+
+dwc3@4a03 {
+   compatible = "synopsys,dwc3";
+   reg = <0x4a03 0xcfff>;
+   interrupts = <0 92 4>
+   usb-phy = <&usb2_phy>, <&usb3,phy>;
+   maximum-speed = "super-speed";
+   dr_mode = "otg";
+   phy_type = "utmi_wide";
+};
-- 
1.9.1


[PATCH v6 02/10] dt-bindings: usb: mtu3: add bindings for MediaTek USB3 DRD

2020-09-14 Thread Chunfeng Yun
Add dt-binding for MediaTek USB3 DRD Driver

Signed-off-by: Chunfeng Yun 
---
v5~v6: no changes

v4:
  Add support host mode, introduce some new properties and subnode

v2~v3: no changes
---
 doc/device-tree-bindings/usb/mediatek,mtu3.txt | 79 ++
 1 file changed, 79 insertions(+)
 create mode 100644 doc/device-tree-bindings/usb/mediatek,mtu3.txt

diff --git a/doc/device-tree-bindings/usb/mediatek,mtu3.txt 
b/doc/device-tree-bindings/usb/mediatek,mtu3.txt
new file mode 100644
index 000..ab877bf
--- /dev/null
+++ b/doc/device-tree-bindings/usb/mediatek,mtu3.txt
@@ -0,0 +1,79 @@
+The device node for Mediatek USB3 DRD controller
+
+Required properties:
+ - compatible : should be "mediatek,-mtu3", "mediatek,mtu3",
+   soc-model is the name of SoC, such as mt8512 etc,
+   when using "mediatek,mtu3" compatible string, you need SoC specific
+   ones in addition, one of:
+   - "mediatek,mt8512-mtu3"
+ - reg : specifies physical base address and size of the registers
+ - reg-names: should be
+   - "ippc" : IP Port Control
+ - power-domains : a phandle to USB power domain node to control USB's MTCMOS
+ - clocks : a list of phandle + clock-specifier pairs, one for each
+   entry in clock-names
+ - clock-names : must contain "sys_ck" for clock of controller,
+   the following clocks are optional:
+   "ref_ck", "mcu_ck", "dma_ck" and "xhci_ck";
+ - phys : list of all the USB PHYs on this HCD
+ - #address-cells, #size-cells : used for sub-nodes with 'reg' property
+ - ranges : allows valid 1:1 translation between child's address space and
+   parent's address space
+
+Optional properties:
+ - vusb33-supply : regulator of USB AVDD3.3v
+ - vbus-supply : regulator of VBUS 5v, needed when supports host mode.
+
+Sub-nodes:
+Required properties:
+ - compatible : should be "mediatek,ssusb"
+ - reg : specifies physical base address and size of the registers
+ - reg-names: should be
+   - "mac" : SSUSB MAC, include xHCI and device
+ - interrupts : interrupt used by xHCI or device
+ - dr_mode : should be one of "host" or "peripheral",
+   see : usb/generic.txt
+
+Optional properties:
+ - pinctrl-names : a pinctrl state named "default" is optional
+ - pinctrl-0 : pin control group
+   See: pinctrl/pinctrl-bindings.txt
+
+ - device mode:
+   - maximum-speed : valid arguments are "full-speed", "high-speed",
+   "super-speed" and "super-speed-plus",
+   see: usb/generic.txt
+   - mediatek,force-vbus : force vbus as valid by SW
+
+ - host mode (dr_mode is "host"):
+   - mediatek,u3p-dis-msk : mask to disable u3ports, bit0 for u3port0,
+   bit1 for u3port1, ... etc;
+
+Example:
+usb3: usb@11213e00 {
+   compatible = "mediatek,mt8512-mtu3", "mediatek,mtu3";
+   reg = <0x11213e00 0x0100>;
+   reg-names = "ippc";
+   phys = <&u2port0 PHY_TYPE_USB2>, <&u2port1 PHY_TYPE_USB2>;
+   power-domains = <&scpsys MT8512_POWER_DOMAIN_USB>;
+   clocks = <&infracfg CLK_INFRA_USB_SYS>,
+<&topckgen CLK_TOP_SSUSB_TOP_CK_EN>,
+<&infracfg CLK_INFRA_ICUSB>;
+   clock-names = "sys_ck", "ref_ck", "mcu_ck";
+   vusb33-supply = ;
+   vbus-supply = <&usb_p0_vbus>;
+   #address-cells = <1>;
+   #size-cells = <1>;
+   ranges;
+   status = "disabled";
+
+   ssusb: usb@1121 {
+   compatible = "mediatek,ssusb";
+   reg = <0x1121 0x3e00>;
+   interrupts = ;
+   reg-names = "mac";
+   dr_mode = "peripheral";
+   maximum-speed = "high-speed";
+   status = "disabled";
+   };
+};
-- 
1.9.1


[PATCH v6 00/10] Add support MediaTek USB3 DRD driver

2020-09-14 Thread Chunfeng Yun
These patches introduce the MediaTek USB3 Dual-Role Controller
driver.
The driver can be configured as Peripheral only and Host only(xHCI)
modes, and it's ported from Linux Kernel 5.8-rc1

v6 changes
1. modify commit message of [4/10]

v5 changes:
1. change condition of readl_poll_timeout() when check clocks
2. add xhci-mtk.c and myself as maintainer for MTK USB

v4 changes:
1. [4/10], [9/10] and [10/10] are new patches
2. add a glue driver
3. add host driver and rebuild host flow
4. support force_vbus mode for device
5. update bindings to support glue driver

v3 changes:
1. add patch [5/7]
2. add udc_set_speed()
3. simplify some code flow

v2 changes:
1. simplify QMU operations

Chunfeng Yun (10):
  dt-binding: usb: add bindings for some common properties
  dt-bindings: usb: mtu3: add bindings for MediaTek USB3 DRD
  usb: add USB_SPEED_SUPER_PLUS
  usb: common: add define of usb_speed_string()
  usb: add MediaTek USB3 DRD driver
  usb: gadget: Add bcdDevice for the MTU3 USB Gadget Controller
  arm: dts: mt8512: add usb related nodes
  configs: mt8512: enable fastboot
  configs: mt8512: add USB host related configs
  MAINTAINERS: add USB driver to ARM MEDIATEK

 MAINTAINERS|   3 +
 Makefile   |   1 +
 arch/arm/dts/mt8512-bm1-emmc.dts   |  34 +
 arch/arm/dts/mt8512.dtsi   |  49 +-
 configs/mt8512_bm1_emmc_defconfig  |  26 +
 doc/device-tree-bindings/usb/generic.txt   |  31 +
 doc/device-tree-bindings/usb/mediatek,mtu3.txt |  79 +++
 drivers/usb/Kconfig|   2 +
 drivers/usb/common/common.c|   8 +
 drivers/usb/gadget/gadget_chips.h  |   8 +
 drivers/usb/mtu3/Kconfig   |  45 ++
 drivers/usb/mtu3/Makefile  |  11 +
 drivers/usb/mtu3/mtu3.h| 423 +++
 drivers/usb/mtu3/mtu3_core.c   | 838 ++
 drivers/usb/mtu3/mtu3_dr.h |  52 ++
 drivers/usb/mtu3/mtu3_gadget.c | 686 ++
 drivers/usb/mtu3/mtu3_gadget_ep0.c | 933 +
 drivers/usb/mtu3/mtu3_host.c   | 141 
 drivers/usb/mtu3/mtu3_hw_regs.h| 515 ++
 drivers/usb/mtu3/mtu3_plat.c   | 367 ++
 drivers/usb/mtu3/mtu3_qmu.c| 504 +
 drivers/usb/mtu3/mtu3_qmu.h|  37 +
 include/linux/usb/ch9.h|   5 +-
 23 files changed, 4793 insertions(+), 5 deletions(-)
 create mode 100644 doc/device-tree-bindings/usb/generic.txt
 create mode 100644 doc/device-tree-bindings/usb/mediatek,mtu3.txt
 create mode 100644 drivers/usb/mtu3/Kconfig
 create mode 100644 drivers/usb/mtu3/Makefile
 create mode 100644 drivers/usb/mtu3/mtu3.h
 create mode 100644 drivers/usb/mtu3/mtu3_core.c
 create mode 100644 drivers/usb/mtu3/mtu3_dr.h
 create mode 100644 drivers/usb/mtu3/mtu3_gadget.c
 create mode 100644 drivers/usb/mtu3/mtu3_gadget_ep0.c
 create mode 100644 drivers/usb/mtu3/mtu3_host.c
 create mode 100644 drivers/usb/mtu3/mtu3_hw_regs.h
 create mode 100644 drivers/usb/mtu3/mtu3_plat.c
 create mode 100644 drivers/usb/mtu3/mtu3_qmu.c
 create mode 100644 drivers/usb/mtu3/mtu3_qmu.h

-- 
1.9.1


Re: [PATCH v3 9/9] usb: xhci: convert to readx_poll_sleep_timeout()

2020-09-08 Thread Chunfeng Yun
Hi Marek,

 I've sent out v4;

Hi Frank,

  Please forward this email to Marek, thanks a lot


On Tue, 2020-09-08 at 13:13 +0200, Marek Vasut wrote:
> On 9/8/20 3:44 AM, Bin Meng wrote:
> > On Mon, Sep 7, 2020 at 3:14 PM Chunfeng Yun  
> > wrote:
> >>
> >> Use readx_poll_sleep_timeout() to poll the register status
> >>
> >> Signed-off-by: Chunfeng Yun 
> >> ---
> >> v3: no changes
> >>
> >> v2: fix typo of title suggested by Frank
> >> ---
> >>  drivers/usb/host/xhci.c | 25 +++--
> >>  1 file changed, 11 insertions(+), 14 deletions(-)
> >>
> > 
> > Reviewed-by: Bin Meng 
> 
> Thanks. So now I have half of a RESEND patchset with RB tags, and
> another half of just RB tags without patchset. Can someone of you please
> collect the tags and resend the patchset once more with the collected
> tags, so it's all in one place ?
> 
> Thank you



[PATCH v4 6/9] usb: xhci: convert to TRB_LEN() and TRB_INTR_TARGET()

2020-09-08 Thread Chunfeng Yun
For normal TRB fields:
use TRB_LEN(x) instead of ((x) & TRB_LEN_MASK);
and use TRB_INTR_TARGET(x) instead of
(((x) & TRB_INTR_TARGET_MASK) << TRB_INTR_TARGET_SHIFT)

Signed-off-by: Chunfeng Yun 
Reviewed-by: Bin Meng 
---
v4:  keep code alignment and add reviewed-by Bin

v3: merge patch [v2 6/11] and [v2 7/11] into one, both for normal TRB fileds

v2: no changes
---
 drivers/usb/host/xhci-ring.c | 16 +++-
 include/usb/xhci.h   |  3 ---
 2 files changed, 7 insertions(+), 12 deletions(-)

diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index 13c98fb..9ef72ef 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -688,10 +688,9 @@ int xhci_bulk_tx(struct usb_device *udev, unsigned long 
pipe,
  length, maxpacketsize,
  more_trbs_coming);
 
-   length_field = ((trb_buff_len & TRB_LEN_MASK) |
+   length_field = (TRB_LEN(trb_buff_len) |
TRB_TD_SIZE(remainder) |
-   ((0 & TRB_INTR_TARGET_MASK) <<
-   TRB_INTR_TARGET_SHIFT));
+   TRB_INTR_TARGET(0));
 
trb_fields[0] = lower_32_bits(addr);
trb_fields[1] = upper_32_bits(addr);
@@ -849,8 +848,7 @@ int xhci_ctrl_tx(struct usb_device *udev, unsigned long 
pipe,
trb_fields[1] = le16_to_cpu(req->index) |
le16_to_cpu(req->length) << 16;
/* TRB_LEN | (TRB_INTR_TARGET) */
-   trb_fields[2] = (8 | ((0 & TRB_INTR_TARGET_MASK) <<
-   TRB_INTR_TARGET_SHIFT));
+   trb_fields[2] = (TRB_LEN(8) | TRB_INTR_TARGET(0));
/* Immediate data in pointer */
trb_fields[3] = field;
queue_trb(ctrl, ep_ring, true, trb_fields);
@@ -866,11 +864,11 @@ int xhci_ctrl_tx(struct usb_device *udev, unsigned long 
pipe,
 
remainder = xhci_td_remainder(ctrl, 0, length, length,
  usb_maxpacket(udev, pipe), true);
-   length_field = (length & TRB_LEN_MASK) | TRB_TD_SIZE(remainder) |
-   ((0 & TRB_INTR_TARGET_MASK) << TRB_INTR_TARGET_SHIFT);
+   length_field = TRB_LEN(length) | TRB_TD_SIZE(remainder) |
+  TRB_INTR_TARGET(0);
debug("length_field = %d, length = %d,"
"xhci_td_remainder(length) = %d , TRB_INTR_TARGET(0) = %d\n",
-   length_field, (length & TRB_LEN_MASK),
+   length_field, TRB_LEN(length),
TRB_TD_SIZE(remainder), 0);
 
if (length > 0) {
@@ -901,7 +899,7 @@ int xhci_ctrl_tx(struct usb_device *udev, unsigned long 
pipe,
 
trb_fields[0] = 0;
trb_fields[1] = 0;
-   trb_fields[2] = ((0 & TRB_INTR_TARGET_MASK) << TRB_INTR_TARGET_SHIFT);
+   trb_fields[2] = TRB_INTR_TARGET(0);
/* Event on completion */
trb_fields[3] = field | TRB_IOC |
TRB_TYPE(TRB_STATUS) | ep_ring->cycle_state;
diff --git a/include/usb/xhci.h b/include/usb/xhci.h
index bdba51d..35c6604 100644
--- a/include/usb/xhci.h
+++ b/include/usb/xhci.h
@@ -847,12 +847,9 @@ struct xhci_event_cmd {
 /* Normal TRB fields */
 /* transfer_len bitmasks - bits 0:16 */
 #defineTRB_LEN(p)  ((p) & 0x1)
-#defineTRB_LEN_MASK(0x1)
 /* TD Size, packets remaining in this TD, bits 21:17 (5 bits, so max 31) */
 #define TRB_TD_SIZE(p)  (min((p), (u32)31) << 17)
 /* Interrupter Target - which MSI-X vector to target the completion event at */
-#defineTRB_INTR_TARGET_SHIFT   (22)
-#defineTRB_INTR_TARGET_MASK(0x3ff)
 #define TRB_INTR_TARGET(p) (((p) & 0x3ff) << 22)
 #define GET_INTR_TARGET(p) (((p) >> 22) & 0x3ff)
 #define TRB_TBC(p) (((p) & 0x3) << 7)
-- 
1.9.1


[PATCH v4 5/9] usb: xhci: convert to TRB_TYPE()

2020-09-08 Thread Chunfeng Yun
Use TRB_TYPE(p) instead of ((p) << TRB_TYPE_SHIFT)

Signed-off-by: Chunfeng Yun 
Reviewed-by: Bin Meng 
---
v4: no changes

v3: add reviewed-by Bin

v2: no changes
---
 drivers/usb/host/xhci-mem.c  |  3 +--
 drivers/usb/host/xhci-ring.c | 11 +--
 include/usb/xhci.h   |  1 -
 3 files changed, 6 insertions(+), 9 deletions(-)

diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index 1da0524..d627aa5 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -236,8 +236,7 @@ static void xhci_link_segments(struct xhci_segment *prev,
 */
val = le32_to_cpu(prev->trbs[TRBS_PER_SEGMENT-1].link.control);
val &= ~TRB_TYPE_BITMASK;
-   val |= (TRB_LINK << TRB_TYPE_SHIFT);
-
+   val |= TRB_TYPE(TRB_LINK);
prev->trbs[TRBS_PER_SEGMENT-1].link.control = cpu_to_le32(val);
}
 }
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index 3f915ae..13c98fb 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -696,7 +696,7 @@ int xhci_bulk_tx(struct usb_device *udev, unsigned long 
pipe,
trb_fields[0] = lower_32_bits(addr);
trb_fields[1] = upper_32_bits(addr);
trb_fields[2] = length_field;
-   trb_fields[3] = field | (TRB_NORMAL << TRB_TYPE_SHIFT);
+   trb_fields[3] = field | TRB_TYPE(TRB_NORMAL);
 
queue_trb(ctrl, ring, (num_trbs > 1), trb_fields);
 
@@ -823,7 +823,7 @@ int xhci_ctrl_tx(struct usb_device *udev, unsigned long 
pipe,
/* Queue setup TRB - see section 6.4.1.2.1 */
/* FIXME better way to translate setup_packet into two u32 fields? */
field = 0;
-   field |= TRB_IDT | (TRB_SETUP << TRB_TYPE_SHIFT);
+   field |= TRB_IDT | TRB_TYPE(TRB_SETUP);
if (start_cycle == 0)
field |= 0x1;
 
@@ -860,9 +860,9 @@ int xhci_ctrl_tx(struct usb_device *udev, unsigned long 
pipe,
/* If there's data, queue data TRBs */
/* Only set interrupt on short packet for IN endpoints */
if (usb_pipein(pipe))
-   field = TRB_ISP | (TRB_DATA << TRB_TYPE_SHIFT);
+   field = TRB_ISP | TRB_TYPE(TRB_DATA);
else
-   field = (TRB_DATA << TRB_TYPE_SHIFT);
+   field = TRB_TYPE(TRB_DATA);
 
remainder = xhci_td_remainder(ctrl, 0, length, length,
  usb_maxpacket(udev, pipe), true);
@@ -904,8 +904,7 @@ int xhci_ctrl_tx(struct usb_device *udev, unsigned long 
pipe,
trb_fields[2] = ((0 & TRB_INTR_TARGET_MASK) << TRB_INTR_TARGET_SHIFT);
/* Event on completion */
trb_fields[3] = field | TRB_IOC |
-   (TRB_STATUS << TRB_TYPE_SHIFT) |
-   ep_ring->cycle_state;
+   TRB_TYPE(TRB_STATUS) | ep_ring->cycle_state;
 
queue_trb(ctrl, ep_ring, false, trb_fields);
 
diff --git a/include/usb/xhci.h b/include/usb/xhci.h
index cf4c020..bdba51d 100644
--- a/include/usb/xhci.h
+++ b/include/usb/xhci.h
@@ -903,7 +903,6 @@ union xhci_trb {
 /* TRB bit mask */
 #defineTRB_TYPE_BITMASK(0xfc00)
 #define TRB_TYPE(p)((p) << 10)
-#define TRB_TYPE_SHIFT (10)
 #define TRB_FIELD_TO_TYPE(p)   (((p) & TRB_TYPE_BITMASK) >> 10)
 
 /* TRB type IDs */
-- 
1.9.1


[PATCH v4 9/9] usb: xhci: convert to readx_poll_sleep_timeout()

2020-09-08 Thread Chunfeng Yun
Use readx_poll_sleep_timeout() to poll the register status

Signed-off-by: Chunfeng Yun 
Reviewed-by: Bin Meng 
---
v4: add reviewed-by Bin

v3: no changes

v2: fix typo of title suggested by Frank
---
 drivers/usb/host/xhci.c | 25 +++--
 1 file changed, 11 insertions(+), 14 deletions(-)

diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index fe30101..3547a9b 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -33,6 +33,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #ifndef CONFIG_USB_MAX_CONTROLLER_COUNT
@@ -143,23 +144,19 @@ struct xhci_ctrl *xhci_get_ctrl(struct usb_device *udev)
  * @param usec time to wait till
  * @return 0 if handshake is success else < 0 on failure
  */
-static int handshake(uint32_t volatile *ptr, uint32_t mask,
-   uint32_t done, int usec)
+static int
+handshake(uint32_t volatile *ptr, uint32_t mask, uint32_t done, int usec)
 {
uint32_t result;
+   int ret;
+
+   ret = readx_poll_sleep_timeout(xhci_readl, ptr, result,
+(result & mask) == done || result == U32_MAX,
+1, usec);
+   if (result == U32_MAX)  /* card removed */
+   return -ENODEV;
 
-   do {
-   result = xhci_readl(ptr);
-   if (result == ~(uint32_t)0)
-   return -ENODEV;
-   result &= mask;
-   if (result == done)
-   return 0;
-   usec--;
-   udelay(1);
-   } while (usec > 0);
-
-   return -ETIMEDOUT;
+   return ret;
 }
 
 /**
-- 
1.9.1


[PATCH v4 7/9] usb: xhci: convert to TRB_TX_TYPE()

2020-09-08 Thread Chunfeng Yun
Use TRB_TX_TYPE() instead of (TRB_DATA_OUT/IN << TRB_TX_TYPE_SHIFT)

Signed-off-by: Chunfeng Yun 
Reviewed-by: Bin Meng 
---
v4: add reviewed-by Bin

v2~v3: no changes
---
 drivers/usb/host/xhci-ring.c | 4 ++--
 include/usb/xhci.h   | 1 -
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index 9ef72ef..b118207 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -830,9 +830,9 @@ int xhci_ctrl_tx(struct usb_device *udev, unsigned long 
pipe,
if (ctrl->hci_version >= 0x100 || ctrl->quirks & XHCI_MTK_HOST) {
if (length > 0) {
if (req->requesttype & USB_DIR_IN)
-   field |= (TRB_DATA_IN << TRB_TX_TYPE_SHIFT);
+   field |= TRB_TX_TYPE(TRB_DATA_IN);
else
-   field |= (TRB_DATA_OUT << TRB_TX_TYPE_SHIFT);
+   field |= TRB_TX_TYPE(TRB_DATA_OUT);
}
}
 
diff --git a/include/usb/xhci.h b/include/usb/xhci.h
index 35c6604..07b1aeb 100644
--- a/include/usb/xhci.h
+++ b/include/usb/xhci.h
@@ -879,7 +879,6 @@ struct xhci_event_cmd {
 /* Control transfer TRB specific fields */
 #define TRB_DIR_IN (1<<16)
 #defineTRB_TX_TYPE(p)  ((p) << 16)
-#defineTRB_TX_TYPE_SHIFT   (16)
 #defineTRB_DATA_OUT2
 #defineTRB_DATA_IN 3
 
-- 
1.9.1


[PATCH v4 3/9] usb: xhci: add quirks flag to support MediaTek xHCI 0.96

2020-09-08 Thread Chunfeng Yun
There some vendor quirks for MTK xHCI 0.96 host controller:
1. It defines some extra SW scheduling parameters for HW
   to minimize the scheduling effort for synchronous and
   interrupt endpoints. The parameters are put into reserved
   DWs of slot context and endpoint context.
2. Its TDS in  Normal TRB defines a number of packets that
   remains to be transferred for a TD after processing all
   Max packets in all previous TRBs.

Signed-off-by: Chunfeng Yun 
Tested-by: Frank Wunderlich 
Reviewed-by: Bin Meng 
---
v4: no changes

v3: fix typo, and add reviewed-by Bin

v2: add Tested-by Frank
---
 drivers/usb/host/xhci-mtk.c  | 1 +
 drivers/usb/host/xhci-ring.c | 9 +++--
 drivers/usb/host/xhci.c  | 2 +-
 include/usb/xhci.h   | 2 ++
 4 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/host/xhci-mtk.c b/drivers/usb/host/xhci-mtk.c
index 8ff7185..f3f181d 100644
--- a/drivers/usb/host/xhci-mtk.c
+++ b/drivers/usb/host/xhci-mtk.c
@@ -258,6 +258,7 @@ static int xhci_mtk_probe(struct udevice *dev)
if (ret)
goto ssusb_init_err;
 
+   mtk->ctrl.quirks = XHCI_MTK_HOST;
hcor = (struct xhci_hcor *)((uintptr_t)mtk->hcd +
HC_LENGTH(xhci_readl(&mtk->hcd->cr_capbase)));
 
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index 603e0e5..3f915ae 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -332,7 +332,8 @@ static u32 xhci_td_remainder(struct xhci_ctrl *ctrl, int 
transferred,
 {
u32 total_packet_count;
 
-   if (ctrl->hci_version < 0x100)
+   /* MTK xHCI 0.96 contains some features from 1.0 */
+   if (ctrl->hci_version < 0x100 && !(ctrl->quirks & XHCI_MTK_HOST))
return ((td_total_len - transferred) >> 10);
 
/* One TRB with a zero-length data packet. */
@@ -340,6 +341,10 @@ static u32 xhci_td_remainder(struct xhci_ctrl *ctrl, int 
transferred,
trb_buff_len == td_total_len)
return 0;
 
+   /* for MTK xHCI 0.96, TD size include this TRB, but not in 1.x */
+   if ((ctrl->quirks & XHCI_MTK_HOST) && (ctrl->hci_version < 0x100))
+   trb_buff_len = 0;
+
total_packet_count = DIV_ROUND_UP(td_total_len, maxp);
 
/* Queueing functions don't count the current TRB into transferred */
@@ -823,7 +828,7 @@ int xhci_ctrl_tx(struct usb_device *udev, unsigned long 
pipe,
field |= 0x1;
 
/* xHCI 1.0 6.4.1.2.1: Transfer Type field */
-   if (ctrl->hci_version >= 0x100) {
+   if (ctrl->hci_version >= 0x100 || ctrl->quirks & XHCI_MTK_HOST) {
if (length > 0) {
if (req->requesttype & USB_DIR_IN)
field |= (TRB_DATA_IN << TRB_TX_TYPE_SHIFT);
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index 4be1411..51edeb2 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -650,7 +650,7 @@ static int xhci_set_configuration(struct usb_device *udev)
 * are put into reserved DWs in Slot and Endpoint Contexts
 * for synchronous endpoints.
 */
-   if (IS_ENABLED(CONFIG_USB_XHCI_MTK)) {
+   if (ctrl->quirks & XHCI_MTK_HOST) {
ep_ctx[ep_index]->reserved[0] =
cpu_to_le32(EP_BPKTS(1) | EP_BBM(1));
}
diff --git a/include/usb/xhci.h b/include/usb/xhci.h
index 15926eb..3de46cd 100644
--- a/include/usb/xhci.h
+++ b/include/usb/xhci.h
@@ -1230,6 +1230,8 @@ struct xhci_ctrl {
struct xhci_virt_device *devs[MAX_HC_SLOTS];
int rootdev;
u16 hci_version;
+   u32 quirks;
+#define XHCI_MTK_HOST  BIT(0)
 };
 
 unsigned long trb_addr(struct xhci_segment *seg, union xhci_trb *trb);
-- 
1.9.1


[PATCH v4 8/9] usb: xhci: use macros with parameter to fill ep_info2

2020-09-08 Thread Chunfeng Yun
Use macros with parameter to fill ep_info2, then some macros
for MASK and SHIFT can be removed

Signed-off-by: Chunfeng Yun 
Reviewed-by: Bin Meng 
---
v4: add reviewed-by Bin

v3: merge patch [v2 9/11] and [v2 10/11] into one, both for ep_info2

v2: no changes
---
 drivers/usb/host/xhci-mem.c | 15 +--
 drivers/usb/host/xhci.c |  6 ++
 include/usb/xhci.h  |  6 --
 3 files changed, 7 insertions(+), 20 deletions(-)

diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index d627aa5..0b49614 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -825,25 +825,22 @@ void xhci_setup_addressable_virt_dev(struct xhci_ctrl 
*ctrl,
 
/* Step 4 - ring already allocated */
/* Step 5 */
-   ep0_ctx->ep_info2 = cpu_to_le32(CTRL_EP << EP_TYPE_SHIFT);
+   ep0_ctx->ep_info2 = cpu_to_le32(EP_TYPE(CTRL_EP));
debug("SPEED = %d\n", speed);
 
switch (speed) {
case USB_SPEED_SUPER:
-   ep0_ctx->ep_info2 |= cpu_to_le32(((512 & MAX_PACKET_MASK) <<
-   MAX_PACKET_SHIFT));
+   ep0_ctx->ep_info2 |= cpu_to_le32(MAX_PACKET(512));
debug("Setting Packet size = 512bytes\n");
break;
case USB_SPEED_HIGH:
/* USB core guesses at a 64-byte max packet first for FS devices */
case USB_SPEED_FULL:
-   ep0_ctx->ep_info2 |= cpu_to_le32(((64 & MAX_PACKET_MASK) <<
-   MAX_PACKET_SHIFT));
+   ep0_ctx->ep_info2 |= cpu_to_le32(MAX_PACKET(64));
debug("Setting Packet size = 64bytes\n");
break;
case USB_SPEED_LOW:
-   ep0_ctx->ep_info2 |= cpu_to_le32(((8 & MAX_PACKET_MASK) <<
-   MAX_PACKET_SHIFT));
+   ep0_ctx->ep_info2 |= cpu_to_le32(MAX_PACKET(8));
debug("Setting Packet size = 8bytes\n");
break;
default:
@@ -852,9 +849,7 @@ void xhci_setup_addressable_virt_dev(struct xhci_ctrl *ctrl,
}
 
/* EP 0 can handle "burst" sizes of 1, so Max Burst Size field is 0 */
-   ep0_ctx->ep_info2 |=
-   cpu_to_le32(((0 & MAX_BURST_MASK) << MAX_BURST_SHIFT) |
-   ((3 & ERROR_COUNT_MASK) << ERROR_COUNT_SHIFT));
+   ep0_ctx->ep_info2 |= cpu_to_le32(MAX_BURST(0) | ERROR_COUNT(3));
 
trb_64 = virt_to_phys(virt_dev->eps[0].ring->first_seg->trbs);
ep0_ctx->deq = cpu_to_le64(trb_64 | virt_dev->eps[0].ring->cycle_state);
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index 5f3a0fb..fe30101 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -618,8 +618,7 @@ static int xhci_set_configuration(struct usb_device *udev)
cpu_to_le32(EP_MAX_ESIT_PAYLOAD_HI(max_esit_payload) |
EP_INTERVAL(interval) | EP_MULT(mult));
 
-   ep_ctx[ep_index]->ep_info2 =
-   cpu_to_le32(ep_type << EP_TYPE_SHIFT);
+   ep_ctx[ep_index]->ep_info2 = cpu_to_le32(EP_TYPE(ep_type));
ep_ctx[ep_index]->ep_info2 |=
cpu_to_le32(MAX_PACKET
(get_unaligned(&endpt_desc->wMaxPacketSize)));
@@ -832,8 +831,7 @@ int xhci_check_maxpacket(struct usb_device *udev)
ctrl->devs[slot_id]->out_ctx, ep_index);
in_ctx = ctrl->devs[slot_id]->in_ctx;
ep_ctx = xhci_get_ep_ctx(ctrl, in_ctx, ep_index);
-   ep_ctx->ep_info2 &= cpu_to_le32(~((0x & MAX_PACKET_MASK)
-   << MAX_PACKET_SHIFT));
+   ep_ctx->ep_info2 &= cpu_to_le32(~MAX_PACKET(MAX_PACKET_MASK));
ep_ctx->ep_info2 |= cpu_to_le32(MAX_PACKET(max_packet_size));
 
/*
diff --git a/include/usb/xhci.h b/include/usb/xhci.h
index 07b1aeb..e1d3823 100644
--- a/include/usb/xhci.h
+++ b/include/usb/xhci.h
@@ -632,11 +632,8 @@ struct xhci_ep_ctx {
  */
 #defineFORCE_EVENT (0x1)
 #define ERROR_COUNT(p) (((p) & 0x3) << 1)
-#define ERROR_COUNT_SHIFT  (1)
-#define ERROR_COUNT_MASK   (0x3)
 #define CTX_TO_EP_TYPE(p)  (((p) >> 3) & 0x7)
 #define EP_TYPE(p) ((p) << 3)
-#define EP_TYPE_SHIFT  (3)
 #define ISOC_OUT_EP1
 #define BULK_OUT_EP2
 #define INT_OUT_EP 3
@@ -647,13 +644,10 @@ struct xhci_ep_ctx {
 /* bit 6 reserved */
 /* bit 7 is Host Initiate Disable - for disabling stream selection */
 #define MAX_BURST(p)   (((p)&0xff) << 8)
-#define MAX_BURST_MASK (0xff)
-#define M

[PATCH v4 2/9] usb: xhci: create one unified function to calculate TRB TD remainder

2020-09-08 Thread Chunfeng Yun
xhci versions 1.0 and later report the untransferred data remaining in a
TD a bit differently than older hosts.

We used to have separate functions for these, and needed to check host
version before calling the right function.

Now Mediatek host has an additional quirk on how it uses the TD Size
field for remaining data. To prevent yet another function for calculating
remainder we instead want to make one quirk friendly unified function.

Porting from the Linux:
c840d6ce772d("xhci: create one unified function to calculate TRB TD remainder.")
124c39371114("xhci: use boolean to indicate last trb in td remainder 
calculation")

Signed-off-by: Chunfeng Yun 
Reviewed-by: Bin Meng 
---
v4 changes:
1. remove the ending period in the commit title
2. use true instead of 1
3. add Reviewed-by Bin

v2~v3: no changes
---
 drivers/usb/host/xhci-ring.c | 105 +--
 include/usb/xhci.h   |   2 +
 2 files changed, 52 insertions(+), 55 deletions(-)

diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index 79bfc34..603e0e5 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -298,55 +298,52 @@ void xhci_queue_command(struct xhci_ctrl *ctrl, u8 *ptr, 
u32 slot_id,
xhci_writel(&ctrl->dba->doorbell[0], DB_VALUE_HOST);
 }
 
-/**
- * The TD size is the number of bytes remaining in the TD (including this TRB),
- * right shifted by 10.
- * It must fit in bits 21:17, so it can't be bigger than 31.
+/*
+ * For xHCI 1.0 host controllers, TD size is the number of max packet sized
+ * packets remaining in the TD (*not* including this TRB).
  *
- * @param remainderremaining packets to be sent
- * @return remainder if remainder is less than max else max
- */
-static u32 xhci_td_remainder(unsigned int remainder)
-{
-   u32 max = (1 << (21 - 17 + 1)) - 1;
-
-   if ((remainder >> 10) >= max)
-   return max << 17;
-   else
-   return (remainder >> 10) << 17;
-}
-
-/**
- * Finds out the remanining packets to be sent
+ * Total TD packet count = total_packet_count =
+ * DIV_ROUND_UP(TD size in bytes / wMaxPacketSize)
+ *
+ * Packets transferred up to and including this TRB = packets_transferred =
+ * rounddown(total bytes transferred including this TRB / wMaxPacketSize)
+ *
+ * TD size = total_packet_count - packets_transferred
  *
- * @param running_totaltotal size sent so far
+ * For xHCI 0.96 and older, TD size field should be the remaining bytes
+ * including this TRB, right shifted by 10
+ *
+ * For all hosts it must fit in bits 21:17, so it can't be bigger than 31.
+ * This is taken care of in the TRB_TD_SIZE() macro
+ *
+ * The last TRB in a TD must have the TD size set to zero.
+ *
+ * @param ctrl host controller data structure
+ * @param transferred  total size sent so far
  * @param trb_buff_len length of the TRB Buffer
- * @param total_packet_count   total packet count
- * @param maxpacketsizemax packet size of current pipe
- * @param num_trbs_leftnumber of TRBs left to be processed
- * @return 0 if running_total or trb_buff_len is 0, else remainder
+ * @param td_total_len total packet count
+ * @param maxp max packet size of current pipe
+ * @param more_trbs_coming indicate last trb in TD
+ * @return remainder
  */
-static u32 xhci_v1_0_td_remainder(int running_total,
-   int trb_buff_len,
-   unsigned int total_packet_count,
-   int maxpacketsize,
-   unsigned int num_trbs_left)
+static u32 xhci_td_remainder(struct xhci_ctrl *ctrl, int transferred,
+int trb_buff_len, unsigned int td_total_len,
+int maxp, bool more_trbs_coming)
 {
-   int packets_transferred;
+   u32 total_packet_count;
+
+   if (ctrl->hci_version < 0x100)
+   return ((td_total_len - transferred) >> 10);
 
/* One TRB with a zero-length data packet. */
-   if (num_trbs_left == 0 || (running_total == 0 && trb_buff_len == 0))
+   if (!more_trbs_coming || (transferred == 0 && trb_buff_len == 0) ||
+   trb_buff_len == td_total_len)
return 0;
 
-   /*
-* All the TRB queueing functions don't count the current TRB in
-* running_total.
-*/
-   packets_transferred = (running_total + trb_buff_len) / maxpacketsize;
+   total_packet_count = DIV_ROUND_UP(td_total_len, maxp);
 
-   if ((total_packet_count - packets_transferred) > 31)
-   return 31 << 17;
-   return (total_packet_count - packets_transferred) << 17;
+   /* Queueing functions don't count the current TRB into transferred */
+   return (total_packet_count - ((transferred + trb_buff_len) / maxp

[PATCH v4 1/9] usb: xhci: add a member hci_version in xhci_ctrl struct

2020-09-08 Thread Chunfeng Yun
Add a member to save xHCI version, it's used some times.

Signed-off-by: Chunfeng Yun 
Reviewed-by: Bin Meng 
---
v4: no changes

v3: add reviewed-by Bin

v2: no changes
---
 drivers/usb/host/xhci-ring.c | 4 ++--
 drivers/usb/host/xhci.c  | 1 +
 include/usb/xhci.h   | 1 +
 3 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index 092ed6e..79bfc34 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -682,7 +682,7 @@ int xhci_bulk_tx(struct usb_device *udev, unsigned long 
pipe,
field |= TRB_ISP;
 
/* Set the TRB length, TD size, and interrupter fields. */
-   if (HC_VERSION(xhci_readl(&ctrl->hccr->cr_capbase)) < 0x100)
+   if (ctrl->hci_version < 0x100)
remainder = xhci_td_remainder(length - running_total);
else
remainder = xhci_v1_0_td_remainder(running_total,
@@ -830,7 +830,7 @@ int xhci_ctrl_tx(struct usb_device *udev, unsigned long 
pipe,
field |= 0x1;
 
/* xHCI 1.0 6.4.1.2.1: Transfer Type field */
-   if (HC_VERSION(xhci_readl(&ctrl->hccr->cr_capbase)) >= 0x100) {
+   if (ctrl->hci_version >= 0x100) {
if (length > 0) {
if (req->requesttype & USB_DIR_IN)
field |= (TRB_DATA_IN << TRB_TX_TYPE_SHIFT);
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index 126dabc..4be1411 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -1283,6 +1283,7 @@ static int xhci_lowlevel_init(struct xhci_ctrl *ctrl)
 
reg = HC_VERSION(xhci_readl(&hccr->cr_capbase));
printf("USB XHCI %x.%02x\n", reg >> 8, reg & 0xff);
+   ctrl->hci_version = reg;
 
return 0;
 }
diff --git a/include/usb/xhci.h b/include/usb/xhci.h
index 7d34103..a3e5914 100644
--- a/include/usb/xhci.h
+++ b/include/usb/xhci.h
@@ -1227,6 +1227,7 @@ struct xhci_ctrl {
struct xhci_scratchpad *scratchpad;
struct xhci_virt_device *devs[MAX_HC_SLOTS];
int rootdev;
+   u16 hci_version;
 };
 
 unsigned long trb_addr(struct xhci_segment *seg, union xhci_trb *trb);
-- 
1.9.1


[PATCH v4 4/9] usb: xhci: convert to HCS_MAX_PORTS()

2020-09-08 Thread Chunfeng Yun
Use HCS_MAX_PORTS(p) instead of
((p & HCS_MAX_PORTS_MASK) >> HCS_MAX_PORTS_SHIFT)

Signed-off-by: Chunfeng Yun 
Reviewed-by: Bin Meng 
---
v4: no changes

v3: add reviewed-by Bin

v2: no changes
---
 drivers/usb/host/xhci.c | 3 +--
 include/usb/xhci.h  | 2 --
 2 files changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index 51edeb2..5f3a0fb 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -1257,8 +1257,7 @@ static int xhci_lowlevel_init(struct xhci_ctrl *ctrl)
return -ENOMEM;
 
reg = xhci_readl(&hccr->cr_hcsparams1);
-   descriptor.hub.bNbrPorts = ((reg & HCS_MAX_PORTS_MASK) >>
-   HCS_MAX_PORTS_SHIFT);
+   descriptor.hub.bNbrPorts = HCS_MAX_PORTS(reg);
printf("Register %x NbrPorts %d\n", reg, descriptor.hub.bNbrPorts);
 
/* Port Indicators */
diff --git a/include/usb/xhci.h b/include/usb/xhci.h
index 3de46cd..cf4c020 100644
--- a/include/usb/xhci.h
+++ b/include/usb/xhci.h
@@ -101,8 +101,6 @@ struct xhci_hccr {
 /* bits 8:18, Max Interrupters */
 #define HCS_MAX_INTRS(p)   (((p) >> 8) & 0x7ff)
 /* bits 24:31, Max Ports - max value is 0x7F = 127 ports */
-#define HCS_MAX_PORTS_SHIFT24
-#define HCS_MAX_PORTS_MASK (0xff << HCS_MAX_PORTS_SHIFT)
 #define HCS_MAX_PORTS(p)   (((p) >> 24) & 0xff)
 
 /* HCSPARAMS2 - hcs_params2 - bitmasks */
-- 
1.9.1


Re: [PATCH v3 2/9] usb: xhci: create one unified function to calculate TRB TD remainder.

2020-09-08 Thread Chunfeng Yun
On Tue, 2020-09-08 at 13:41 +0800, Bin Meng wrote:
> On Mon, Sep 7, 2020 at 3:14 PM Chunfeng Yun  wrote:
> >
> 
> nits: please remove the ending period in the commit title
Ok, will fix it

> 
> > xhci versions 1.0 and later report the untransferred data remaining in a
> > TD a bit differently than older hosts.
> >
> > We used to have separate functions for these, and needed to check host
> > version before calling the right function.
> >
> > Now Mediatek host has an additional quirk on how it uses the TD Size
> > field for remaining data. To prevent yet another function for calculating
> > remainder we instead want to make one quirk friendly unified function.
> >
> > Porting from the Linux:
> > c840d6ce772d("xhci: create one unified function to calculate TRB TD 
> > remainder.")
> > 124c39371114("xhci: use boolean to indicate last trb in td remainder 
> > calculation")
> >
> > Signed-off-by: Chunfeng Yun 
> > ---
> > v2~v3: no changes
> > ---
> >  drivers/usb/host/xhci-ring.c | 105 
> > +--
> >  include/usb/xhci.h   |   2 +
> >  2 files changed, 52 insertions(+), 55 deletions(-)
> >
> > diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
> > index 79bfc34..0f86b01 100644
> > --- a/drivers/usb/host/xhci-ring.c
> > +++ b/drivers/usb/host/xhci-ring.c
> > @@ -298,55 +298,52 @@ void xhci_queue_command(struct xhci_ctrl *ctrl, u8 
> > *ptr, u32 slot_id,
> > xhci_writel(&ctrl->dba->doorbell[0], DB_VALUE_HOST);
> >  }
> >
> > -/**
> > - * The TD size is the number of bytes remaining in the TD (including this 
> > TRB),
> > - * right shifted by 10.
> > - * It must fit in bits 21:17, so it can't be bigger than 31.
> > +/*
> > + * For xHCI 1.0 host controllers, TD size is the number of max packet sized
> > + * packets remaining in the TD (*not* including this TRB).
> >   *
> > - * @param remainderremaining packets to be sent
> > - * @return remainder if remainder is less than max else max
> > - */
> > -static u32 xhci_td_remainder(unsigned int remainder)
> > -{
> > -   u32 max = (1 << (21 - 17 + 1)) - 1;
> > -
> > -   if ((remainder >> 10) >= max)
> > -   return max << 17;
> > -   else
> > -   return (remainder >> 10) << 17;
> > -}
> > -
> > -/**
> > - * Finds out the remanining packets to be sent
> > + * Total TD packet count = total_packet_count =
> > + * DIV_ROUND_UP(TD size in bytes / wMaxPacketSize)
> > + *
> > + * Packets transferred up to and including this TRB = packets_transferred =
> > + * rounddown(total bytes transferred including this TRB / 
> > wMaxPacketSize)
> > + *
> > + * TD size = total_packet_count - packets_transferred
> >   *
> > - * @param running_totaltotal size sent so far
> > + * For xHCI 0.96 and older, TD size field should be the remaining bytes
> > + * including this TRB, right shifted by 10
> > + *
> > + * For all hosts it must fit in bits 21:17, so it can't be bigger than 31.
> > + * This is taken care of in the TRB_TD_SIZE() macro
> > + *
> > + * The last TRB in a TD must have the TD size set to zero.
> > + *
> > + * @param ctrl host controller data structure
> > + * @param transferred  total size sent so far
> >   * @param trb_buff_len length of the TRB Buffer
> > - * @param total_packet_count   total packet count
> > - * @param maxpacketsizemax packet size of current pipe
> > - * @param num_trbs_leftnumber of TRBs left to be processed
> > - * @return 0 if running_total or trb_buff_len is 0, else remainder
> > + * @param td_total_len total packet count
> > + * @param maxp max packet size of current pipe
> > + * @param more_trbs_coming indicate last trb in TD
> > + * @return remainder
> >   */
> > -static u32 xhci_v1_0_td_remainder(int running_total,
> > -   int trb_buff_len,
> > -   unsigned int total_packet_count,
> > -   int maxpacketsize,
> > -   unsigned int num_trbs_left)
> > +static u32 xhci_td_remainder(struct xhci_ctrl *ctrl, int transferred,
> > +int trb_buff_len, unsigned int td_total_len,
> > +int maxp, bool more_trbs_coming)
> >  {
> > -   int packets_transferre

Re: [PATCH v3 6/9] usb: xhci: convert to TRB_LEN() and TRB_INTR_TARGET()

2020-09-08 Thread Chunfeng Yun
On Tue, 2020-09-08 at 09:30 +0800, Bin Meng wrote:
> On Mon, Sep 7, 2020 at 3:14 PM Chunfeng Yun  wrote:
> >
> > For normal TRB fields:
> > use TRB_LEN(x) instead of ((x) & TRB_LEN_MASK);
> > and use TRB_INTR_TARGET(x) instead of
> > (((x) & TRB_INTR_TARGET_MASK) << TRB_INTR_TARGET_SHIFT)
> >
> > Signed-off-by: Chunfeng Yun 
> > ---
> > v3: merge patch [v2 6/11] and [v2 7/11] into one, both for normal TRB fileds
> >
> > v2: no changes
> > ---
> >  drivers/usb/host/xhci-ring.c | 16 +++-
> >  include/usb/xhci.h   |  3 ---
> >  2 files changed, 7 insertions(+), 12 deletions(-)
> >
> > diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
> > index 87891fd..99c84f9 100644
> > --- a/drivers/usb/host/xhci-ring.c
> > +++ b/drivers/usb/host/xhci-ring.c
> > @@ -688,10 +688,9 @@ int xhci_bulk_tx(struct usb_device *udev, unsigned 
> > long pipe,
> >   length, maxpacketsize,
> >   more_trbs_coming);
> >
> > -   length_field = ((trb_buff_len & TRB_LEN_MASK) |
> > +   length_field = (TRB_LEN(trb_buff_len) |
> > TRB_TD_SIZE(remainder) |
> > -   ((0 & TRB_INTR_TARGET_MASK) <<
> > -   TRB_INTR_TARGET_SHIFT));
> > +   TRB_INTR_TARGET(0));
> 
> nits: should be aligned to TRB_LEN(length)
Ok, will check it again

> 
> >
> > trb_fields[0] = lower_32_bits(addr);
> > trb_fields[1] = upper_32_bits(addr);
> > @@ -849,8 +848,7 @@ int xhci_ctrl_tx(struct usb_device *udev, unsigned long 
> > pipe,
> > trb_fields[1] = le16_to_cpu(req->index) |
> > le16_to_cpu(req->length) << 16;
> > /* TRB_LEN | (TRB_INTR_TARGET) */
> > -   trb_fields[2] = (8 | ((0 & TRB_INTR_TARGET_MASK) <<
> > -   TRB_INTR_TARGET_SHIFT));
> > +   trb_fields[2] = (TRB_LEN(8) | TRB_INTR_TARGET(0));
> > /* Immediate data in pointer */
> > trb_fields[3] = field;
> > queue_trb(ctrl, ep_ring, true, trb_fields);
> > @@ -866,11 +864,11 @@ int xhci_ctrl_tx(struct usb_device *udev, unsigned 
> > long pipe,
> >
> > remainder = xhci_td_remainder(ctrl, 0, length, length,
> >   usb_maxpacket(udev, pipe), 1);
> > -   length_field = (length & TRB_LEN_MASK) | TRB_TD_SIZE(remainder) |
> > -   ((0 & TRB_INTR_TARGET_MASK) << 
> > TRB_INTR_TARGET_SHIFT);
> > +   length_field = TRB_LEN(length) | TRB_TD_SIZE(remainder) |
> > +   TRB_INTR_TARGET(0);
> > debug("length_field = %d, length = %d,"
> > "xhci_td_remainder(length) = %d , TRB_INTR_TARGET(0) = 
> > %d\n",
> > -   length_field, (length & TRB_LEN_MASK),
> > +   length_field, TRB_LEN(length),
> > TRB_TD_SIZE(remainder), 0);
> >
> > if (length > 0) {
> > @@ -901,7 +899,7 @@ int xhci_ctrl_tx(struct usb_device *udev, unsigned long 
> > pipe,
> >
> > trb_fields[0] = 0;
> > trb_fields[1] = 0;
> > -   trb_fields[2] = ((0 & TRB_INTR_TARGET_MASK) << 
> > TRB_INTR_TARGET_SHIFT);
> > +   trb_fields[2] = TRB_INTR_TARGET(0);
> > /* Event on completion */
> > trb_fields[3] = field | TRB_IOC |
> > TRB_TYPE(TRB_STATUS) | ep_ring->cycle_state;
> > diff --git a/include/usb/xhci.h b/include/usb/xhci.h
> > index bdba51d..35c6604 100644
> > --- a/include/usb/xhci.h
> > +++ b/include/usb/xhci.h
> > @@ -847,12 +847,9 @@ struct xhci_event_cmd {
> >  /* Normal TRB fields */
> >  /* transfer_len bitmasks - bits 0:16 */
> >  #defineTRB_LEN(p)  ((p) & 0x1)
> > -#defineTRB_LEN_MASK(0x1)
> >  /* TD Size, packets remaining in this TD, bits 21:17 (5 bits, so max 31) */
> >  #define TRB_TD_SIZE(p)  (min((p), (u32)31) << 17)
> >  /* Interrupter Target - which MSI-X vector to target the completion event 
> > at */
> > -#defineTRB_INTR_TARGET_SHIFT   (22)
> > -#defineTRB_INTR_TARGET_MASK(0x3ff)
> >  #define TRB_INTR_TARGET(p) (((p) & 0x3ff) << 22)
> >  #define GET_INTR_TARGET(p) (((p) >> 22) & 0x3ff)
> >  #define TRB_TBC(p) (((p) & 0x3) << 7)
> > --
> 
> Reviewed-by: Bin Meng 
Thanks




Re: [PATCH RESEND v2 05/11] usb: xhci: convert to TRB_TYPE()

2020-09-07 Thread Chunfeng Yun
Hi Bin,

On Fri, 2020-09-04 at 15:19 +0800, Bin Meng wrote:
> Hi Marek,
> 
> On Fri, Sep 4, 2020 at 3:05 PM Marek Vasut  wrote:
> >
> > On 9/4/20 8:54 AM, Bin Meng wrote:
> > > On Wed, Aug 26, 2020 at 5:31 PM Chunfeng Yun  
> > > wrote:
> > >>
> > >> Use TRB_TYPE(p) instead of ((p) << TRB_TYPE_SHIFT)
> > >>
> > >> Signed-off-by: Chunfeng Yun 
> > >> ---
> > >> v2: no changes
> > >> ---
> > >>  drivers/usb/host/xhci-mem.c  |  3 +--
> > >>  drivers/usb/host/xhci-ring.c | 11 +--
> > >>  include/usb/xhci.h   |  1 -
> > >>  3 files changed, 6 insertions(+), 9 deletions(-)
> > >>
> > >
> > > Reviewed-by: Bin Meng 
> >
> > Can we please collect the RBs in one posting of the series, not two
> > postings ?
> >
> 
> Oops, it looks I replied the old version. Sorry. I will use the latest 
> version.
Due to Frank and I both resend v2, this may cause some confusion, so I
send out v3, and just merge some patch that you don't review, please
look at it. Thanks a lot

> 
> Regards,
> Bin



[PATCH v3 8/9] usb: xhci: use macros with parameter to fill ep_info2

2020-09-07 Thread Chunfeng Yun
Use macros with parameter to fill ep_info2, then some macros
for MASK and SHIFT can be removed

Signed-off-by: Chunfeng Yun 
---
v3: merge patch [v2 9/11] and [v2 10/11] into one, both for ep_info2

v2: no changes
---
 drivers/usb/host/xhci-mem.c | 15 +--
 drivers/usb/host/xhci.c |  6 ++
 include/usb/xhci.h  |  6 --
 3 files changed, 7 insertions(+), 20 deletions(-)

diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index d627aa5..0b49614 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -825,25 +825,22 @@ void xhci_setup_addressable_virt_dev(struct xhci_ctrl 
*ctrl,
 
/* Step 4 - ring already allocated */
/* Step 5 */
-   ep0_ctx->ep_info2 = cpu_to_le32(CTRL_EP << EP_TYPE_SHIFT);
+   ep0_ctx->ep_info2 = cpu_to_le32(EP_TYPE(CTRL_EP));
debug("SPEED = %d\n", speed);
 
switch (speed) {
case USB_SPEED_SUPER:
-   ep0_ctx->ep_info2 |= cpu_to_le32(((512 & MAX_PACKET_MASK) <<
-   MAX_PACKET_SHIFT));
+   ep0_ctx->ep_info2 |= cpu_to_le32(MAX_PACKET(512));
debug("Setting Packet size = 512bytes\n");
break;
case USB_SPEED_HIGH:
/* USB core guesses at a 64-byte max packet first for FS devices */
case USB_SPEED_FULL:
-   ep0_ctx->ep_info2 |= cpu_to_le32(((64 & MAX_PACKET_MASK) <<
-   MAX_PACKET_SHIFT));
+   ep0_ctx->ep_info2 |= cpu_to_le32(MAX_PACKET(64));
debug("Setting Packet size = 64bytes\n");
break;
case USB_SPEED_LOW:
-   ep0_ctx->ep_info2 |= cpu_to_le32(((8 & MAX_PACKET_MASK) <<
-   MAX_PACKET_SHIFT));
+   ep0_ctx->ep_info2 |= cpu_to_le32(MAX_PACKET(8));
debug("Setting Packet size = 8bytes\n");
break;
default:
@@ -852,9 +849,7 @@ void xhci_setup_addressable_virt_dev(struct xhci_ctrl *ctrl,
}
 
/* EP 0 can handle "burst" sizes of 1, so Max Burst Size field is 0 */
-   ep0_ctx->ep_info2 |=
-   cpu_to_le32(((0 & MAX_BURST_MASK) << MAX_BURST_SHIFT) |
-   ((3 & ERROR_COUNT_MASK) << ERROR_COUNT_SHIFT));
+   ep0_ctx->ep_info2 |= cpu_to_le32(MAX_BURST(0) | ERROR_COUNT(3));
 
trb_64 = virt_to_phys(virt_dev->eps[0].ring->first_seg->trbs);
ep0_ctx->deq = cpu_to_le64(trb_64 | virt_dev->eps[0].ring->cycle_state);
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index 5f3a0fb..fe30101 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -618,8 +618,7 @@ static int xhci_set_configuration(struct usb_device *udev)
cpu_to_le32(EP_MAX_ESIT_PAYLOAD_HI(max_esit_payload) |
EP_INTERVAL(interval) | EP_MULT(mult));
 
-   ep_ctx[ep_index]->ep_info2 =
-   cpu_to_le32(ep_type << EP_TYPE_SHIFT);
+   ep_ctx[ep_index]->ep_info2 = cpu_to_le32(EP_TYPE(ep_type));
ep_ctx[ep_index]->ep_info2 |=
cpu_to_le32(MAX_PACKET
(get_unaligned(&endpt_desc->wMaxPacketSize)));
@@ -832,8 +831,7 @@ int xhci_check_maxpacket(struct usb_device *udev)
ctrl->devs[slot_id]->out_ctx, ep_index);
in_ctx = ctrl->devs[slot_id]->in_ctx;
ep_ctx = xhci_get_ep_ctx(ctrl, in_ctx, ep_index);
-   ep_ctx->ep_info2 &= cpu_to_le32(~((0x & MAX_PACKET_MASK)
-   << MAX_PACKET_SHIFT));
+   ep_ctx->ep_info2 &= cpu_to_le32(~MAX_PACKET(MAX_PACKET_MASK));
ep_ctx->ep_info2 |= cpu_to_le32(MAX_PACKET(max_packet_size));
 
/*
diff --git a/include/usb/xhci.h b/include/usb/xhci.h
index 07b1aeb..e1d3823 100644
--- a/include/usb/xhci.h
+++ b/include/usb/xhci.h
@@ -632,11 +632,8 @@ struct xhci_ep_ctx {
  */
 #defineFORCE_EVENT (0x1)
 #define ERROR_COUNT(p) (((p) & 0x3) << 1)
-#define ERROR_COUNT_SHIFT  (1)
-#define ERROR_COUNT_MASK   (0x3)
 #define CTX_TO_EP_TYPE(p)  (((p) >> 3) & 0x7)
 #define EP_TYPE(p) ((p) << 3)
-#define EP_TYPE_SHIFT  (3)
 #define ISOC_OUT_EP1
 #define BULK_OUT_EP2
 #define INT_OUT_EP 3
@@ -647,13 +644,10 @@ struct xhci_ep_ctx {
 /* bit 6 reserved */
 /* bit 7 is Host Initiate Disable - for disabling stream selection */
 #define MAX_BURST(p)   (((p)&0xff) << 8)
-#define MAX_BURST_MASK (0xff)
-#define MAX_BURST_SHIFT(8)
 #define CTX_TO_MAX_BURST(p)

[PATCH v3 9/9] usb: xhci: convert to readx_poll_sleep_timeout()

2020-09-07 Thread Chunfeng Yun
Use readx_poll_sleep_timeout() to poll the register status

Signed-off-by: Chunfeng Yun 
---
v3: no changes

v2: fix typo of title suggested by Frank
---
 drivers/usb/host/xhci.c | 25 +++--
 1 file changed, 11 insertions(+), 14 deletions(-)

diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index fe30101..3547a9b 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -33,6 +33,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #ifndef CONFIG_USB_MAX_CONTROLLER_COUNT
@@ -143,23 +144,19 @@ struct xhci_ctrl *xhci_get_ctrl(struct usb_device *udev)
  * @param usec time to wait till
  * @return 0 if handshake is success else < 0 on failure
  */
-static int handshake(uint32_t volatile *ptr, uint32_t mask,
-   uint32_t done, int usec)
+static int
+handshake(uint32_t volatile *ptr, uint32_t mask, uint32_t done, int usec)
 {
uint32_t result;
+   int ret;
+
+   ret = readx_poll_sleep_timeout(xhci_readl, ptr, result,
+(result & mask) == done || result == U32_MAX,
+1, usec);
+   if (result == U32_MAX)  /* card removed */
+   return -ENODEV;
 
-   do {
-   result = xhci_readl(ptr);
-   if (result == ~(uint32_t)0)
-   return -ENODEV;
-   result &= mask;
-   if (result == done)
-   return 0;
-   usec--;
-   udelay(1);
-   } while (usec > 0);
-
-   return -ETIMEDOUT;
+   return ret;
 }
 
 /**
-- 
1.9.1


[PATCH v3 5/9] usb: xhci: convert to TRB_TYPE()

2020-09-07 Thread Chunfeng Yun
Use TRB_TYPE(p) instead of ((p) << TRB_TYPE_SHIFT)

Signed-off-by: Chunfeng Yun 
Reviewed-by: Bin Meng 
---
v3: add reviewed-by Bin

v2: no changes
---
 drivers/usb/host/xhci-mem.c  |  3 +--
 drivers/usb/host/xhci-ring.c | 11 +--
 include/usb/xhci.h   |  1 -
 3 files changed, 6 insertions(+), 9 deletions(-)

diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index 1da0524..d627aa5 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -236,8 +236,7 @@ static void xhci_link_segments(struct xhci_segment *prev,
 */
val = le32_to_cpu(prev->trbs[TRBS_PER_SEGMENT-1].link.control);
val &= ~TRB_TYPE_BITMASK;
-   val |= (TRB_LINK << TRB_TYPE_SHIFT);
-
+   val |= TRB_TYPE(TRB_LINK);
prev->trbs[TRBS_PER_SEGMENT-1].link.control = cpu_to_le32(val);
}
 }
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index cf8b9d2..87891fd 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -696,7 +696,7 @@ int xhci_bulk_tx(struct usb_device *udev, unsigned long 
pipe,
trb_fields[0] = lower_32_bits(addr);
trb_fields[1] = upper_32_bits(addr);
trb_fields[2] = length_field;
-   trb_fields[3] = field | (TRB_NORMAL << TRB_TYPE_SHIFT);
+   trb_fields[3] = field | TRB_TYPE(TRB_NORMAL);
 
queue_trb(ctrl, ring, (num_trbs > 1), trb_fields);
 
@@ -823,7 +823,7 @@ int xhci_ctrl_tx(struct usb_device *udev, unsigned long 
pipe,
/* Queue setup TRB - see section 6.4.1.2.1 */
/* FIXME better way to translate setup_packet into two u32 fields? */
field = 0;
-   field |= TRB_IDT | (TRB_SETUP << TRB_TYPE_SHIFT);
+   field |= TRB_IDT | TRB_TYPE(TRB_SETUP);
if (start_cycle == 0)
field |= 0x1;
 
@@ -860,9 +860,9 @@ int xhci_ctrl_tx(struct usb_device *udev, unsigned long 
pipe,
/* If there's data, queue data TRBs */
/* Only set interrupt on short packet for IN endpoints */
if (usb_pipein(pipe))
-   field = TRB_ISP | (TRB_DATA << TRB_TYPE_SHIFT);
+   field = TRB_ISP | TRB_TYPE(TRB_DATA);
else
-   field = (TRB_DATA << TRB_TYPE_SHIFT);
+   field = TRB_TYPE(TRB_DATA);
 
remainder = xhci_td_remainder(ctrl, 0, length, length,
  usb_maxpacket(udev, pipe), 1);
@@ -904,8 +904,7 @@ int xhci_ctrl_tx(struct usb_device *udev, unsigned long 
pipe,
trb_fields[2] = ((0 & TRB_INTR_TARGET_MASK) << TRB_INTR_TARGET_SHIFT);
/* Event on completion */
trb_fields[3] = field | TRB_IOC |
-   (TRB_STATUS << TRB_TYPE_SHIFT) |
-   ep_ring->cycle_state;
+   TRB_TYPE(TRB_STATUS) | ep_ring->cycle_state;
 
queue_trb(ctrl, ep_ring, false, trb_fields);
 
diff --git a/include/usb/xhci.h b/include/usb/xhci.h
index cf4c020..bdba51d 100644
--- a/include/usb/xhci.h
+++ b/include/usb/xhci.h
@@ -903,7 +903,6 @@ union xhci_trb {
 /* TRB bit mask */
 #defineTRB_TYPE_BITMASK(0xfc00)
 #define TRB_TYPE(p)((p) << 10)
-#define TRB_TYPE_SHIFT (10)
 #define TRB_FIELD_TO_TYPE(p)   (((p) & TRB_TYPE_BITMASK) >> 10)
 
 /* TRB type IDs */
-- 
1.9.1


  1   2   3   4   >