Subsystems (6)
Chunfeng Yun
maintainerQuoted 1 line
From
ac1e8724bfa47494223bad0af450c1a63cd2fe0cMon Sep 17 00:00:00 2001
From: Chunfeng Yun <[email protected]>
Date: Wed, 22 Jul 2015 21:15:15 +0800
Subject: [PATCH 0/5] *** SUBJECT HERE ***
The patch supports MediaTek's xHCI controller.
There are some differences from xHCI spec:
1. The interval is specified in 250 * 8ns increments for Interrupt Moderation Interval(IMODI) of the Interrupter Moderation(IMOD) register, it is 8 times as much as that defined in xHCI spec.
2. For the value of TD Size in Normal TRB, MTK's xHCI controller defines a number of packets that remain to be transferred for a TD after processing all Max packets in all previous TRBs,that means don't include the current TRB's, but in xHCI spec it includes the current ones.
3. To minimize the scheduling effort for synchronous endpoints in xHC, the MTK architecture defines some extra SW scheduling parameters for HW. According to these parameters provided by SW, the xHC can easily decide whether a synchronous endpoint should be scheduled in a specific uFrame. The extra SW scheduling parameters are put into reserved DWs in Slot and Endpoint Context. And a bandwidth scheduler algorithm is added to support such feature.
A usb3.0 phy driver is also added which used by mt65xx SoCs platform, it supports two usb2.0 ports and one usb3.0 port.
Change in v3:
1. implement generic phy
2. move opperations for IPPC and wakeup from phy driver to xHCI driver
3. seperate quirk functions into a single C file to fix up dependence issue
Chunfeng Yun (5):
dt-bindings: Add usb3.0 phy binding for MT65xx SoCs
dt-bindings: Add a binding for Mediatek xHCI host controller
usb: phy: add usb3.0 phy driver for mt65xx SoCs
xhci: mediatek: support MTK xHCI host controller
arm64: dts: mediatek: add xHCI & usb phy for mt8173
.../devicetree/bindings/phy/phy-mt65xx-u3.txt | 21 + .../devicetree/bindings/usb/mt8173-xhci.txt | 50 ++ arch/arm64/boot/dts/mediatek/mt8173-evb.dts | 15 + arch/arm64/boot/dts/mediatek/mt8173.dtsi | 31 + drivers/phy/Kconfig | 9 + drivers/phy/Makefile | 1 + drivers/phy/phy-mt65xx-usb3.c | 426 +++++++++++ drivers/usb/host/Kconfig | 9 + drivers/usb/host/Makefile | 4 + drivers/usb/host/xhci-mtk-sch.c | 436 +++++++++++ drivers/usb/host/xhci-mtk.c | 836 +++++++++++++++++++++ drivers/usb/host/xhci-mtk.h | 135 ++++ drivers/usb/host/xhci-ring.c | 35 +- drivers/usb/host/xhci.c | 19 +- drivers/usb/host/xhci.h | 1 + 15 files changed, 2021 insertions(+), 7 deletions(-) create mode 100644 Documentation/devicetree/bindings/phy/phy-mt65xx-u3.txt create mode 100644 Documentation/devicetree/bindings/usb/mt8173-xhci.txt create mode 100644 drivers/phy/phy-mt65xx-usb3.c create mode 100644 drivers/usb/host/xhci-mtk-sch.c create mode 100644 drivers/usb/host/xhci-mtk.c create mode 100644 drivers/usb/host/xhci-mtk.h
--
1.8.1.1.dirty
In-Reply-To:
Chunfeng Yun
maintainerPATCH v3 1/5 dt-bindings: Add usb3.0 phy binding for MT65xx SoCs
add a DT binding documentation of usb3.0 phy for MT65xx SoCs from Mediatek.
--- .../devicetree/bindings/phy/phy-mt65xx-u3.txt | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Documentation/devicetree/bindings/phy/phy-mt65xx-u3.txt
Documentation/devicetree/bindings/phy/phy-mt65xx-u3.txt new file +21 -0
@@ -0,0 +1,21 @@ +MT65xx USB3.0 PHY + +The device node for Mediatek SOC usb3.0 phy + +Required properties: + - compatible : Should be "mediatek,mt8173-u3phy" + - reg : Offset and length of registers for phy domain + - clocks : must support all clocks that phy need + - clock-names: should be "u3phya_ref" for u3phya reference clock. + - #phy-cells : must be 1 for the phy + +Example: + +u3phy: usb-phy at 11290000 { + compatible = "mediatek,mt8173-u3phy"; + reg = <0 0x11290000 0 0x3000>; + clocks = <&apmixedsys CLK_APMIXED_REF2USB_TX>; + clock-names = "u3phya_ref"; + #phy-cells = <1>; + status = "okay"; +};
Signature · 1 line
1.8.1.1.dirty
Chunfeng Yun
maintainerPATCH v3 2/5 dt-bindings: Add a binding for Mediatek xHCI host controller
In reply to Chunfeng Yunadd a DT binding documentation of xHCI host controller for the MT8173 SoC from Mediatek.
--- .../devicetree/bindings/usb/mt8173-xhci.txt | 50 ++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 Documentation/devicetree/bindings/usb/mt8173-xhci.txt
Documentation/devicetree/bindings/usb/mt8173-xhci.txt new file +50 -0
@@ -0,0 +1,50 @@ +MT65XX xhci + +The device node for Mediatek SOC usb3.0 host controller + +Required properties: + - compatible : supports "mediatek,mt8173-xhci" + - reg : Offset and length of registers + - interrupts : Interrupt mode, number and trigger mode + - power-domains: to enable usb's mtcmos + - vusb33-supply: regulator of usb avdd3.3v + - clocks : must support all clocks that xhci needs + - clock-names: should be "sys_mac" for sys and mac clocks, and + "wakeup_deb_p0", "wakeup_deb_p1" for wakeup debounce control + clocks + - phys : the phys that xhci will bind, currently supports up to two + phys, so phy index should not greater than one. + - phy-names : should be "phy-X" format, X equals to 0 or 1 + - usb3-lpm-capable: supports USB3 LPM + - mediatek,usb-wakeup: to access usb wakeup control register + - mediatek,wakeup-src: 1: ip sleep wakeup mode; 2: line state wakeup + mode; others means don't enable wakeup source of usb + - mediatek,u2port-num: the number should not greater than the number + of phys + +Optional properties: + - vbus-supply : reference to the VBUS regulator; + +Example: +usb: usb30 at 11270000 { + compatible = "mediatek,mt8173-xhci"; + reg = <0 0x11270000 0 0x4000>, + <0 0x11280000 0 0x0800>; + interrupts = <GIC_SPI 115 IRQ_TYPE_LEVEL_LOW>; + power-domains = <&scpsys MT8173_POWER_DOMAIN_USB>; + clocks = <&topckgen CLK_TOP_USB30_SEL>, + <&pericfg CLK_PERI_USB0>, + <&pericfg CLK_PERI_USB1>; + clock-names = "sys_mac", + "wakeup_deb_p0", + "wakeup_deb_p1"; + phys = <&u3phy 0>, <&u3phy 1>; + phy-names = "phy-0", "phy-1"; + vusb33-supply = <&mt6397_vusb_reg>; + vbus-supply = <&usb_p1_vbus>; + usb3-lpm-capable; + mediatek,usb-wakeup = <&pericfg>; + mediatek,wakeup-src = <1>; + mediatek,u2port-num = <2>; + status = "okay"; +};
Signature · 1 line
1.8.1.1.dirty
Re: [PATCH v3 2/5] dt-bindings: Add a binding for Mediatek xHCI host controller
Quoted 15 lines · Chunfeng Yun
add a DT binding documentation of xHCI host controller for the MT8173 SoC from Mediatek.
Signed-off-by Chunfeng Yun <[email protected]>--- .../devicetree/bindings/usb/mt8173-xhci.txt | 50 ++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 Documentation/devicetree/bindings/usb/mt8173-xhci.txtDocumentation/devicetree/bindings/usb/mt8173-xhci.txt new file +0
-0
Documentation/devicetree/bindings/usb/mt8173-xhci.txt line 7
Quoted 7 lines
Documentation/devicetree/bindings/usb/mt8173-xhci.txt new file +7
-0@@ -0,0 +1,50 @@ +MT65XX xhci + +The device node for Mediatek SOC usb3.0 host controller + +Required properties: + - compatible : supports "mediatek,mt8173-xhci" + - reg : Offset and length of registers
Your example has multiple reg entries.
Please list what each entry is, and the order you expect them in.
Documentation/devicetree/bindings/usb/mt8173-xhci.txt line 17
Quoted 10 lines
Documentation/devicetree/bindings/usb/mt8173-xhci.txt new file +10
-0+ - interrupts : Interrupt mode, number and trigger mode + - power-domains: to enable usb's mtcmos + - vusb33-supply: regulator of usb avdd3.3v + - clocks : must support all clocks that xhci needs + - clock-names: should be "sys_mac" for sys and mac clocks, and + "wakeup_deb_p0", "wakeup_deb_p1" for wakeup debounce control + clocks + - phys : the phys that xhci will bind, currently supports up to two + phys, so phy index should not greater than one. + - phy-names : should be "phy-X" format, X equals to 0 or 1
This seems somewhat pointless.
Documentation/devicetree/bindings/usb/mt8173-xhci.txt line 19
Quoted 2 lines
Documentation/devicetree/bindings/usb/mt8173-xhci.txt new file +2
-0+ - usb3-lpm-capable: supports USB3 LPM + - mediatek,usb-wakeup: to access usb wakeup control register
What exactly does this property imply?
Documentation/devicetree/bindings/usb/mt8173-xhci.txt line 21
Quoted 2 lines
Documentation/devicetree/bindings/usb/mt8173-xhci.txt new file +2
-0+ - mediatek,wakeup-src: 1: ip sleep wakeup mode; 2: line state wakeup + mode; others means don't enable wakeup source of usb
This sounds like configuration rather than a hardware property. Why do you think this needs to be in the DT?
Documentation/devicetree/bindings/usb/mt8173-xhci.txt line 23
Quoted 2 lines
Documentation/devicetree/bindings/usb/mt8173-xhci.txt new file +2
-0+ - mediatek,u2port-num: the number should not greater than the number + of phys
What exactly does this property imply?
Mark.
Quoted 30 lines
Documentation/devicetree/bindings/usb/mt8173-xhci.txt new file +27
-0+ +Optional properties: + - vbus-supply : reference to the VBUS regulator; + +Example: +usb: usb30 at 11270000 { + compatible = "mediatek,mt8173-xhci"; + reg = <0 0x11270000 0 0x4000>, + <0 0x11280000 0 0x0800>; + interrupts = <GIC_SPI 115 IRQ_TYPE_LEVEL_LOW>; + power-domains = <&scpsys MT8173_POWER_DOMAIN_USB>; + clocks = <&topckgen CLK_TOP_USB30_SEL>, + <&pericfg CLK_PERI_USB0>, + <&pericfg CLK_PERI_USB1>; + clock-names = "sys_mac", + "wakeup_deb_p0", + "wakeup_deb_p1"; + phys = <&u3phy 0>, <&u3phy 1>; + phy-names = "phy-0", "phy-1"; + vusb33-supply = <&mt6397_vusb_reg>; + vbus-supply = <&usb_p1_vbus>; + usb3-lpm-capable; + mediatek,usb-wakeup = <&pericfg>; + mediatek,wakeup-src = <1>; + mediatek,u2port-num = <2>; + status = "okay"; +};Signature · 1 line
1.8.1.1.dirty
chunfeng yun
maintainerRe: [PATCH v3 2/5] dt-bindings: Add a binding for Mediatek xHCI host controller
Hi,
Quoted 26 lines · Mark Rutland
Quoted 15 lines · Chunfeng Yun
add a DT binding documentation of xHCI host controller for the MT8173 SoC from Mediatek.
Signed-off-by Chunfeng Yun <[email protected]>--- .../devicetree/bindings/usb/mt8173-xhci.txt | 50 ++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 Documentation/devicetree/bindings/usb/mt8173-xhci.txtDocumentation/devicetree/bindings/usb/mt8173-xhci.txt new file +0
-0Documentation/devicetree/bindings/usb/mt8173-xhci.txt line 7
Quoted 7 lines
Documentation/devicetree/bindings/usb/mt8173-xhci.txt new file +7
-0@@ -0,0 +1,50 @@ +MT65XX xhci + +The device node for Mediatek SOC usb3.0 host controller + +Required properties: + - compatible : supports "mediatek,mt8173-xhci" + - reg : Offset and length of registersYour example has multiple reg entries.
Quoted 2 lines
Please list what each entry is, and the order you expect them in.
Ok
Quoted 4 lines
Quoted 4 lines
Documentation/devicetree/bindings/usb/mt8173-xhci.txt new file +4
-0+ - interrupts : Interrupt mode, number and trigger mode + - power-domains: to enable usb's mtcmos + - vusb33-supply: regulator of usb avdd3.3v + - clocks : must support all clocks that xhci needs
Quoted 9 lines
Documentation/devicetree/bindings/usb/mt8173-xhci.txt line 17
Quoted 6 lines
Documentation/devicetree/bindings/usb/mt8173-xhci.txt new file +6
-0+ - clock-names: should be "sys_mac" for sys and mac clocks, and + "wakeup_deb_p0", "wakeup_deb_p1" for wakeup debounce control + clocks + - phys : the phys that xhci will bind, currently supports up to two + phys, so phy index should not greater than one. + - phy-names : should be "phy-X" format, X equals to 0 or 1This seems somewhat pointless.
I'll describe it more exactly.
Quoted 5 lines
Documentation/devicetree/bindings/usb/mt8173-xhci.txt line 19
Quoted 2 lines
Documentation/devicetree/bindings/usb/mt8173-xhci.txt new file +2
-0+ - usb3-lpm-capable: supports USB3 LPM + - mediatek,usb-wakeup: to access usb wakeup control registerWhat exactly does this property imply?
There are some control registers for usb wakeup which are put in another module, here to get the node of that module, and then use regmap and syscon to operate it.
Quoted 6 lines
Documentation/devicetree/bindings/usb/mt8173-xhci.txt line 21
Quoted 2 lines
Documentation/devicetree/bindings/usb/mt8173-xhci.txt new file +2
-0+ - mediatek,wakeup-src: 1: ip sleep wakeup mode; 2: line state wakeup + mode; others means don't enable wakeup source of usbThis sounds like configuration rather than a hardware property. Why do you think this needs to be in the DT?
Yes, it's better to put it in the DT.
Quoted 5 lines
Documentation/devicetree/bindings/usb/mt8173-xhci.txt line 23
Quoted 2 lines
Documentation/devicetree/bindings/usb/mt8173-xhci.txt new file +2
-0+ - mediatek,u2port-num: the number should not greater than the number + of physWhat exactly does this property imply?
On some platform, it only makes use of partial usb ports, so disable others to save power.
Quoted 32 lines
Mark.
Quoted 30 lines
Documentation/devicetree/bindings/usb/mt8173-xhci.txt new file +27
-0+ +Optional properties: + - vbus-supply : reference to the VBUS regulator; + +Example: +usb: usb30 at 11270000 { + compatible = "mediatek,mt8173-xhci"; + reg = <0 0x11270000 0 0x4000>, + <0 0x11280000 0 0x0800>; + interrupts = <GIC_SPI 115 IRQ_TYPE_LEVEL_LOW>; + power-domains = <&scpsys MT8173_POWER_DOMAIN_USB>; + clocks = <&topckgen CLK_TOP_USB30_SEL>, + <&pericfg CLK_PERI_USB0>, + <&pericfg CLK_PERI_USB1>; + clock-names = "sys_mac", + "wakeup_deb_p0", + "wakeup_deb_p1"; + phys = <&u3phy 0>, <&u3phy 1>; + phy-names = "phy-0", "phy-1"; + vusb33-supply = <&mt6397_vusb_reg>; + vbus-supply = <&usb_p1_vbus>; + usb3-lpm-capable; + mediatek,usb-wakeup = <&pericfg>; + mediatek,wakeup-src = <1>; + mediatek,u2port-num = <2>; + status = "okay"; +};Signature · 1 line
1.8.1.1.dirty
Re: [PATCH v3 2/5] dt-bindings: Add a binding for Mediatek xHCI host controller
Hi,
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
+ - mediatek,usb-wakeup: to access usb wakeup control register
What exactly does this property imply?
There are some control registers for usb wakeup which are put in another module, here to get the node of that module, and then use regmap and syscon to operate it.
Ok. You need to specify the type of this property (i.e. that it is a phandle to a syscon node). The description makes it sound like a boolean.
Quoted 8 lines
Quoted 7 lines
Documentation/devicetree/bindings/usb/mt8173-xhci.txt line 21
Quoted 3 lines
+ - mediatek,wakeup-src: 1: ip sleep wakeup mode; 2: line state wakeup
Documentation/devicetree/bindings/usb/mt8173-xhci.txt new file +1
-0+ mode; others means don't enable wakeup source of usbThis sounds like configuration rather than a hardware property. Why do you think this needs to be in the DT?
Yes, it's better to put it in the DT.
That doesn't answer my question.
_why_ do you think this needs to be in the DT? What do you think is better for it being there?
Quoted 8 lines
Quoted 6 lines
Documentation/devicetree/bindings/usb/mt8173-xhci.txt line 23
Quoted 3 lines
+ - mediatek,u2port-num: the number should not greater than the number
Documentation/devicetree/bindings/usb/mt8173-xhci.txt new file +1
-0+ of physWhat exactly does this property imply?
On some platform, it only makes use of partial usb ports, so disable others to save power.
What exactly do you mean by "partial USB ports"?
If a phy isn't wired up, it won't be listed in the phys property, if it is then disabling it sounds like a run-time decision.
Thanks,
Mark.
chunfeng yun
maintainerRe: [PATCH v3 2/5] dt-bindings: Add a binding for Mediatek xHCI host controller
hi,
Quoted 4 lines · Mark Rutland
Hi,
Quoted 2 lines
Quoted 2 lines
Quoted 1 line
+ - mediatek,usb-wakeup: to access usb wakeup control register
Quoted 9 lines
Quoted 5 lines
Quoted 2 lines
What exactly does this property imply?
There are some control registers for usb wakeup which are put in another module, here to get the node of that module, and then use regmap and syscon to operate it.
Ok. You need to specify the type of this property (i.e. that it is a phandle to a syscon node). The description makes it sound like a boolean.
Is it ok to add a prefix of syscon, and name it syscon-usb-wakeup?
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Documentation/devicetree/bindings/usb/mt8173-xhci.txt line 21
Quoted 3 lines
+ - mediatek,wakeup-src: 1: ip sleep wakeup mode; 2: line state wakeup
Documentation/devicetree/bindings/usb/mt8173-xhci.txt new file +1
-0+ mode; others means don't enable wakeup source of usbThis sounds like configuration rather than a hardware property. Why do you think this needs to be in the DT?
Quoted 7 lines
Quoted 1 line
Yes, it's better to put it in the DT.
That doesn't answer my question.
_why_ do you think this needs to be in the DT? What do you think is better for it being there?
It is unthoughtful to put it here;
There is different configuration on platforms, such as on tablet which only needs line-state wakeup (because system can't enter suspend when plug in usb cable, so don't need ip-sleep-wakeup to remote wakeup system), and on box just needs ip-sleep wakeup mode. so it is better to put in each board's dts.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Documentation/devicetree/bindings/usb/mt8173-xhci.txt line 23
Quoted 3 lines
+ - mediatek,u2port-num: the number should not greater than the number
Documentation/devicetree/bindings/usb/mt8173-xhci.txt new file +1
-0+ of physWhat exactly does this property imply?
Quoted 8 lines
Quoted 2 lines
On some platform, it only makes use of partial usb ports, so disable others to save power.
What exactly do you mean by "partial USB ports"?
If a phy isn't wired up, it won't be listed in the phys property, if it is then disabling it sounds like a run-time decision.
Yes, you are right.
This confuse me a little before. It was a property of old phy driver at first, and then ported it here, so did not remove it temp. After I re-write the phy driver, I will remove it.
Thanks a lot.
Quoted 2 lines
Thanks,
Mark.
Chunfeng Yun
maintainerPATCH v3 3/5 usb: phy: add usb3.0 phy driver for mt65xx SoCs
In reply to Chunfeng Yunsupport usb3.0 phy of mt65xx SoCs
--- drivers/phy/Kconfig | 9 + drivers/phy/Makefile | 1 + drivers/phy/phy-mt65xx-usb3.c | 426 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 436 insertions(+) create mode 100644 drivers/phy/phy-mt65xx-usb3.c
drivers/phy/Kconfig +9 -0
@@ -193,6 +193,15 @@ config PHY_HIX5HD2_SATA help Support for SATA PHY on Hisilicon hix5hd2 Soc. +config PHY_MT65XX_USB3 + tristate "Mediatek USB3.0 PHY Driver" + depends on ARCH_MEDIATEK && OF + select GENERIC_PHY + help + Say 'Y' here to add support for Mediatek USB3.0 PHY driver + for mt65xx SoCs. it supports two usb2.0 ports and + one usb3.0 port. + config PHY_SUN4I_USB tristate "Allwinner sunxi SoC USB PHY driver" depends on ARCH_SUNXI && HAS_IOMEM && OF
drivers/phy/Makefile +1 -0
@@ -22,6 +22,7 @@ obj-$(CONFIG_TI_PIPE3) += phy-ti-pipe3.o obj-$(CONFIG_TWL4030_USB) += phy-twl4030-usb.o obj-$(CONFIG_PHY_EXYNOS5250_SATA) += phy-exynos5250-sata.o obj-$(CONFIG_PHY_HIX5HD2_SATA) += phy-hix5hd2-sata.o +obj-$(CONFIG_PHY_MT65XX_USB3) += phy-mt65xx-usb3.o obj-$(CONFIG_PHY_SUN4I_USB) += phy-sun4i-usb.o obj-$(CONFIG_PHY_SUN9I_USB) += phy-sun9i-usb.o obj-$(CONFIG_PHY_SAMSUNG_USB2) += phy-exynos-usb2.o
drivers/phy/phy-mt65xx-usb3.c new file +426 -0
426 lines not on this page · raw message
Signature · 1 line
1.8.1.1.dirty
Re: [PATCH v3 3/5] usb: phy: add usb3.0 phy driver for mt65xx SoCs
Hi,
Quoted 3 lines · Chunfeng Yun
support usb3.0 phy of mt65xx SoCs
Signed-off-by Chunfeng Yun <[email protected]>
you missed Kishon here.
Quoted 474 lines
--- drivers/phy/Kconfig | 9 + drivers/phy/Makefile | 1 + drivers/phy/phy-mt65xx-usb3.c | 426 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 436 insertions(+) create mode 100644 drivers/phy/phy-mt65xx-usb3.cdrivers/phy/Kconfig +9
-0@@ -193,6 +193,15 @@ config PHY_HIX5HD2_SATA help Support for SATA PHY on Hisilicon hix5hd2 Soc. +config PHY_MT65XX_USB3 + tristate "Mediatek USB3.0 PHY Driver" + depends on ARCH_MEDIATEK && OF + select GENERIC_PHY + help + Say 'Y' here to add support for Mediatek USB3.0 PHY driver + for mt65xx SoCs. it supports two usb2.0 ports and + one usb3.0 port. + config PHY_SUN4I_USB tristate "Allwinner sunxi SoC USB PHY driver" depends on ARCH_SUNXI && HAS_IOMEM && OFdrivers/phy/Makefile +1
-0@@ -22,6 +22,7 @@ obj-$(CONFIG_TI_PIPE3) += phy-ti-pipe3.o obj-$(CONFIG_TWL4030_USB) += phy-twl4030-usb.o obj-$(CONFIG_PHY_EXYNOS5250_SATA) += phy-exynos5250-sata.o obj-$(CONFIG_PHY_HIX5HD2_SATA) += phy-hix5hd2-sata.o +obj-$(CONFIG_PHY_MT65XX_USB3) += phy-mt65xx-usb3.o obj-$(CONFIG_PHY_SUN4I_USB) += phy-sun4i-usb.o obj-$(CONFIG_PHY_SUN9I_USB) += phy-sun9i-usb.o obj-$(CONFIG_PHY_SAMSUNG_USB2) += phy-exynos-usb2.odrivers/phy/phy-mt65xx-usb3.c new file +426
-0@@ -0,0 +1,426 @@ +/* +* Copyright (c) 2015 MediaTek Inc. +* Author: Chunfeng.Yun <[email protected]> +* +* This software is licensed under the terms of the GNU General Public +* License version 2, as published by the Free Software Foundation, and +* may be copied, distributed, and modified under those terms. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +*/ + +#include <linux/clk.h> +#include <linux/delay.h> +#include <linux/io.h> +#include <linux/module.h> +#include <linux/of_address.h> +#include <linux/of_device.h> +#include <linux/of_gpio.h> +#include <linux/of.h> +#include <linux/phy/phy.h> +#include <linux/platform_device.h> +#include <linux/pm_runtime.h> +#include <linux/regulator/consumer.h> +#include <linux/resource.h> + +/* +* for sifslv2 register +* relative to USB3_SIF2_BASE base address +*/ +#define SSUSB_SIFSLV_SPLLC (0x0000) +#define SSUSB_SIFSLV_U2PHY_COM_BASE (0x0800) +#define SSUSB_SIFSLV_U3PHYD_BASE (0x0900) +#define SSUSB_USB30_PHYA_SIV_B_BASE (0x0b00) +#define SSUSB_SIFSLV_U3PHYA_DA_BASE (0x0c00) + +/*port1 refs. +0x800(refer to port0)*/ +#define U3P_PORT_INTERVAL (0x800)/*based on port0 */ +#define U3P_PHY_DELTA (index) ((U3P_PORT_INTERVAL) * (index)) + +#define U3P_USBPHYACR0 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0000) +#define PA0_RG_U2PLL_FORCE_ON (0x1 << 15) + +#define U3P_USBPHYACR2 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0008) +#define PA2_RG_SIF_U2PLL_FORCE_EN (0x1 << 18) + +#define U3P_USBPHYACR5 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0014) +#define PA5_RG_U2_HSTX_SRCTRL (0x7 << 12) +#define PA5_RG_U2_HSTX_SRCTRL_VAL (x) ((0x7 & (x)) << 12) +#define PA5_RG_U2_HS_100U_U3_EN (0x1 << 11) + +#define U3P_USBPHYACR6 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0018) +#define PA6_RG_U2_ISO_EN (0x1 << 31) +#define PA6_RG_U2_BC11_SW_EN (0x1 << 23) +#define PA6_RG_U2_OTG_VBUSCMP_EN (0x1 << 20) + +#define U3P_U2PHYACR4 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0020) +#define P2C_RG_USB20_GPIO_CTL (0x1 << 9) +#define P2C_USB20_GPIO_MODE (0x1 << 8) +#define P2C_U2_GPIO_CTR_MSK (P2C_RG_USB20_GPIO_CTL | P2C_USB20_GPIO_MODE) + +#define U3D_U2PHYDCR0 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0060) +#define P2C_RG_SIF_U2PLL_FORCE_ON (0x1 << 24) + +#define U3P_U2PHYDTM0 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0068) +#define P2C_FORCE_UART_EN (0x1 << 26) +#define P2C_FORCE_DATAIN (0x1 << 23) +#define P2C_FORCE_DM_PULLDOWN (0x1 << 21) +#define P2C_FORCE_DP_PULLDOWN (0x1 << 20) +#define P2C_FORCE_XCVRSEL (0x1 << 19) +#define P2C_FORCE_SUSPENDM (0x1 << 18) +#define P2C_FORCE_TERMSEL (0x1 << 17) +#define P2C_RG_DATAIN (0xf << 10) +#define P2C_RG_DATAIN_VAL (x) ((0xf & (x)) << 10) +#define P2C_RG_DMPULLDOWN (0x1 << 7) +#define P2C_RG_DPPULLDOWN (0x1 << 6) +#define P2C_RG_XCVRSEL (0x3 << 4) +#define P2C_RG_XCVRSEL_VAL (x) ((0x3 & (x)) << 4) +#define P2C_RG_SUSPENDM (0x1 << 3) +#define P2C_RG_TERMSEL (0x1 << 2) +#define P2C_DTM0_PART_MASK \ + (P2C_FORCE_DATAIN | P2C_FORCE_DM_PULLDOWN | \ + P2C_FORCE_DP_PULLDOWN | P2C_FORCE_XCVRSEL | \ + P2C_FORCE_TERMSEL | P2C_RG_DMPULLDOWN | \ + P2C_RG_DPPULLDOWN | P2C_RG_TERMSEL) + +#define U3P_U2PHYDTM1 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x006C) +#define P2C_RG_UART_EN (0x1 << 16) +#define P2C_RG_VBUSVALID (0x1 << 5) +#define P2C_RG_SESSEND (0x1 << 4) +#define P2C_RG_AVALID (0x1 << 2) + +#define U3P_U3_PHYA_REG0 (SSUSB_USB30_PHYA_SIV_B_BASE + 0x0000) +#define P3A_RG_U3_VUSB10_ON (1 << 5) + +#define U3P_U3_PHYA_REG6 (SSUSB_USB30_PHYA_SIV_B_BASE + 0x0018) +#define P3A_RG_TX_EIDLE_CM (0xf << 28) +#define P3A_RG_TX_EIDLE_CM_VAL (x) ((0xf & (x)) << 28) + +#define U3P_U3_PHYA_REG9 (SSUSB_USB30_PHYA_SIV_B_BASE + 0x0024) +#define P3A_RG_RX_DAC_MUX (0x1f << 1) +#define P3A_RG_RX_DAC_MUX_VAL (x) ((0x1f & (x)) << 1) + +#define U3P_U3PHYA_DA_REG0 (SSUSB_SIFSLV_U3PHYA_DA_BASE + 0x0) +#define P3A_RG_XTAL_EXT_EN_U3 (0x3 << 10) +#define P3A_RG_XTAL_EXT_EN_U3_VAL (x) ((0x3 & (x)) << 10) + +#define U3P_PHYD_CDR1 (SSUSB_SIFSLV_U3PHYD_BASE + 0x5c) +#define P3D_RG_CDR_BIR_LTD1 (0x1f << 24) +#define P3D_RG_CDR_BIR_LTD1_VAL (x) ((0x1f & (x)) << 24) +#define P3D_RG_CDR_BIR_LTD0 (0x1f << 8) +#define P3D_RG_CDR_BIR_LTD0_VAL (x) ((0x1f & (x)) << 8) + +#define U3P_XTALCTL3 (SSUSB_SIFSLV_SPLLC + 0x18) +#define XC3_RG_U3_XTAL_RX_PWD (0x1 << 9) +#define XC3_RG_U3_FRC_XTAL_RX_PWD (0x1 << 8) + +#define MT65XX_MAX_PHYS 2 + +struct mt65xx_phy_instance { +struct phy *phy; +u32 index; +u32 delta;/* increament refers to port0 */ +}; + +struct mt65xx_u3phy { +struct device *dev; +void __iomem *sif_base;/* include sif2 */ +struct clk *u3phya_ref;/* reference clock of usb3 anolog phy */ +struct mt65xx_phy_instance phys[MT65XX_MAX_PHYS ]; +}; + +static struct mt65xx_u3phy *to_usbdrd_phy ( +struct mt65xx_phy_instance *instance) +{ + return container_of((instance), struct mt65xx_u3phy, + phys[(instance)->index]); +} + +static void phy_instance_init (struct mt65xx_phy_instance *instance) +{ +struct mt65xx_u3phy *u3phy =to_usbdrd_phy (instance); +void __iomem *sif_base = u3phy->sif_base + instance->delta; +u32 index = instance->index; +u32 tmp; + +/* switch to USB function. (system register, force ip into usb mode) */ + tmp =readl (sif_base +U3P_U2PHYDTM0 ); + tmp &= ~P2C_FORCE_UART_EN ; +writel (tmp, sif_base +U3P_U2PHYDTM0 ); + + tmp =readl (sif_base +U3P_U2PHYDTM1 ); + tmp &= ~P2C_RG_UART_EN ; +writel (tmp, sif_base +U3P_U2PHYDTM1 ); + +if (!index) { + tmp =readl (sif_base +U3P_U2PHYACR4 ); + tmp &= ~P2C_U2_GPIO_CTR_MSK ; +writel (tmp, sif_base +U3P_U2PHYACR4 ); + } + +/* DP/DM BC1.1 path Disable */ + tmp =readl (sif_base +U3P_USBPHYACR6 ); + tmp &= ~PA6_RG_U2_BC11_SW_EN ; +writel (tmp, sif_base +U3P_USBPHYACR6 ); + + tmp =readl (sif_base +U3P_U3PHYA_DA_REG0 ); + tmp &= ~P3A_RG_XTAL_EXT_EN_U3 ; + tmp |=P3A_RG_XTAL_EXT_EN_U3_VAL (2 ); +writel (tmp, sif_base +U3P_U3PHYA_DA_REG0 ); + + tmp =readl (sif_base +U3P_U3_PHYA_REG9 ); + tmp &= ~P3A_RG_RX_DAC_MUX ; + tmp |=P3A_RG_RX_DAC_MUX_VAL (4 ); +writel (tmp, sif_base +U3P_U3_PHYA_REG9 ); + + tmp =readl (sif_base +U3P_U3_PHYA_REG6 ); + tmp &= ~P3A_RG_TX_EIDLE_CM ; + tmp |=P3A_RG_TX_EIDLE_CM_VAL (0xe ); +writel (tmp, sif_base +U3P_U3_PHYA_REG6 ); + + tmp =readl (sif_base +U3P_PHYD_CDR1 ); + tmp &= ~(P3D_RG_CDR_BIR_LTD0 |P3D_RG_CDR_BIR_LTD1 ); + tmp |=P3D_RG_CDR_BIR_LTD0_VAL (0xc ) |P3D_RG_CDR_BIR_LTD1_VAL (0x3 ); +writel (tmp, sif_base +U3P_PHYD_CDR1 ); + +dev_dbg (u3phy->dev,"%s(%d)\n" , __func__, index); +} + +static void phy_instance_power_on (struct mt65xx_phy_instance *instance) +{ +struct mt65xx_u3phy *u3phy =to_usbdrd_phy (instance); +void __iomem *sif_base = u3phy->sif_base + instance->delta; +u32 index = instance->index; +u32 tmp; + +if (!index) { +/* Set RG_SSUSB_VUSB10_ON as 1 after VUSB10 ready */ + tmp =readl (sif_base +U3P_U3_PHYA_REG0 ); + tmp |=P3A_RG_U3_VUSB10_ON ; +writel (tmp, sif_base +U3P_U3_PHYA_REG0 ); + } + +/* (force_suspendm=0) (let suspendm=1, enable usb 480MHz pll) */ + tmp =readl (sif_base +U3P_U2PHYDTM0 ); + tmp &= ~(P2C_FORCE_SUSPENDM |P2C_RG_XCVRSEL ); + tmp &= ~(P2C_RG_DATAIN |P2C_DTM0_PART_MASK ); +writel (tmp, sif_base +U3P_U2PHYDTM0 ); + +/* OTG Enable */ + tmp =readl (sif_base +U3P_USBPHYACR6 ); + tmp |=PA6_RG_U2_OTG_VBUSCMP_EN ; +writel (tmp, sif_base +U3P_USBPHYACR6 ); + +if (!index) { + tmp =readl (sif_base +U3P_XTALCTL3 ); + tmp |=XC3_RG_U3_XTAL_RX_PWD |XC3_RG_U3_FRC_XTAL_RX_PWD ; +writel (tmp, sif_base +U3P_XTALCTL3 ); +/* [mt8173]disable Change 100uA current from SSUSB */ + tmp =readl (sif_base +U3P_USBPHYACR5 ); + tmp &= ~PA5_RG_U2_HS_100U_U3_EN ; +writel (tmp, sif_base +U3P_USBPHYACR5 ); + } +udelay (800 ); + + tmp =readl (sif_base +U3P_U2PHYDTM1 ); + tmp |=P2C_RG_VBUSVALID |P2C_RG_AVALID ; + tmp &= ~P2C_RG_SESSEND ; +writel (tmp, sif_base +U3P_U2PHYDTM1 ); +/* USB 2.0 slew rate calibration */ + tmp =readl (sif_base +U3P_USBPHYACR5 ); + tmp &= ~PA5_RG_U2_HSTX_SRCTRL ; + tmp |=PA5_RG_U2_HSTX_SRCTRL_VAL (4 ); +writel (tmp, sif_base +U3P_USBPHYACR5 ); + +dev_dbg (u3phy->dev,"%s(%d)(delta: 0x%x)\n" , __func__, + index, u3phy->phys[index].delta); +} + +static void phy_instance_power_off (struct mt65xx_phy_instance *instance) +{ +struct mt65xx_u3phy *u3phy =to_usbdrd_phy (instance); +void __iomem *sif_base = u3phy->sif_base + instance->delta; +u32 index = instance->index; +u32 tmp; + + tmp =readl (sif_base +U3P_U2PHYDTM0 ); + tmp &= ~(P2C_RG_XCVRSEL |P2C_RG_DATAIN ); + tmp |=P2C_RG_XCVRSEL_VAL (1 ) |P2C_RG_DATAIN_VAL (0 ); + tmp |=P2C_FORCE_SUSPENDM ; +writel (tmp, sif_base +U3P_U2PHYDTM0 ); + +/* OTG Disable */ + tmp =readl (sif_base +U3P_USBPHYACR6 ); + tmp &= ~PA6_RG_U2_OTG_VBUSCMP_EN ; +writel (tmp, sif_base +U3P_USBPHYACR6 ); +if (!index) { +/* (also disable)Change 100uA current switch to USB2.0 */ + tmp =readl (sif_base +U3P_USBPHYACR5 ); + tmp &= ~PA5_RG_U2_HS_100U_U3_EN ; +writel (tmp, sif_base +U3P_USBPHYACR5 ); + } +udelay (800 ); + +/* let suspendm=0, set utmi into analog power down */ + tmp =readl (sif_base +U3P_U2PHYDTM0 ); + tmp &= ~P2C_RG_SUSPENDM ; +writel (tmp, sif_base +U3P_U2PHYDTM0 ); +udelay (1 ); + + tmp =readl (sif_base +U3P_U2PHYDTM1 ); + tmp &= ~(P2C_RG_VBUSVALID |P2C_RG_AVALID ); + tmp |=P2C_RG_SESSEND ; +writel (tmp, sif_base +U3P_U2PHYDTM1 ); + +if (!index) { + tmp =readl (sif_base +U3P_U3_PHYA_REG0 ); + tmp &= ~P3A_RG_U3_VUSB10_ON ; +writel (tmp, sif_base +U3P_U3_PHYA_REG0 ); + } + +dev_dbg (u3phy->dev,"%s(%d)\n" , __func__, index); +} + +static int u3phy_clk_enable (struct mt65xx_u3phy *u3phy) +{ +int ret; + + ret =clk_prepare_enable (u3phy->u3phya_ref); +if (ret) { +dev_err (u3phy->dev,"failed to enable u3phya_ref\n" ); +return ret; + } +udelay (100 ); + +return 0 ; +} + +static int mt65xx_phy_init (struct phy *phy) +{ +struct mt65xx_phy_instance *instance =phy_get_drvdata (phy); + +phy_instance_init (instance); +return 0 ; +} + +static int mt65xx_phy_power_on (struct phy *phy) +{ +struct mt65xx_phy_instance *instance =phy_get_drvdata (phy); + +phy_instance_power_on (instance); +msleep (20 ); +return 0 ; +} + +static int mt65xx_phy_power_off (struct phy *phy) +{ +struct mt65xx_phy_instance *instance =phy_get_drvdata (phy); + +phy_instance_power_off (instance); +return 0 ; +} + +static struct phy *mt65xx_phy_xlate (struct device *dev, +struct of_phandle_args *args) +{ +struct mt65xx_u3phy *u3phy =dev_get_drvdata (dev); + +if (WARN_ON (args->args[0 ] >MT65XX_MAX_PHYS )) +return ERR_PTR (-ENODEV ); + +return u3phy->phys[args->args[0 ]].phy; +} + +static struct phy_ops mt65xx_u3phy_ops = { + .init = mt65xx_phy_init, + .power_on = mt65xx_phy_power_on, + .power_off = mt65xx_phy_power_off, + .owner =THIS_MODULE , +}; + +static const struct of_device_id mt65xx_u3phy_id_table[] = { + { .compatible ="mediatek,mt8173-u3phy" ,}, + { }, +}; +MODULE_DEVICE_TABLE (of, mt65xx_u3phy_id_table); + + +static int mt65xx_u3phy_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct phy_provider *phy_provider; +struct resource *sif_res; +struct mt65xx_u3phy *u3phy; +int i; + + u3phy =devm_kzalloc (dev,sizeof (*u3phy),GFP_KERNEL ); +if (!u3phy) +return -ENOMEM ; + + u3phy->dev = dev; +platform_set_drvdata (pdev, u3phy); + + sif_res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); + u3phy->sif_base =devm_ioremap_resource (dev, sif_res); +if (IS_ERR (u3phy->sif_base)) { +dev_err (dev,"failed to remap sif regs\n" ); +return PTR_ERR (u3phy->sif_base); + } + + u3phy->u3phya_ref =devm_clk_get (dev,"u3phya_ref" ); +if (IS_ERR (u3phy->u3phya_ref)) { +dev_err (dev,"error to get u3phya_ref\n" ); +return PTR_ERR (u3phy->u3phya_ref); + } + +for (i =0 ; i <MT65XX_MAX_PHYS ; i++) { +struct mt65xx_phy_instance *instance; +struct phy *phy; + + phy =devm_phy_create (dev,NULL , &mt65xx_u3phy_ops); +if (IS_ERR (phy)) { +dev_err (dev,"failed to create mt65xx_u3phy phy\n" ); +return PTR_ERR (phy); + } + instance = &u3phy->phys[i]; + instance->phy = phy; + instance->index = i; + instance->delta =U3P_PHY_DELTA (i); +phy_set_drvdata (phy, instance); + } + + phy_provider =devm_of_phy_provider_register (dev, mt65xx_phy_xlate); +if (IS_ERR (phy_provider)) { +dev_err (dev,"Failed to register phy provider\n" ); +return PTR_ERR (phy_provider); + } + +return u3phy_clk_enable (u3phy); +} + +static int mt65xx_u3phy_remove (struct platform_device *pdev) +{ +struct mt65xx_u3phy *u3phy =platform_get_drvdata (pdev); + +clk_disable_unprepare (u3phy->u3phya_ref); + +return 0 ; +} + +static struct platform_driver mt65xx_u3phy_driver = { + .probe = mt65xx_u3phy_probe, + .remove = mt65xx_u3phy_remove, + .driver = { + .name ="mt65xx-u3phy" , + .of_match_table = mt65xx_u3phy_id_table, + }, +}; + +module_platform_driver (mt65xx_u3phy_driver); + +MODULE_DESCRIPTION ("Mt65xx USB PHY driver" ); +MODULE_LICENSE ("GPL v2" );Signature · 1 line
1.8.1.1.dirty
Signature · 8 lines
balbi -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20150722/2a1b1f8e/attachment-0001.sig>
chunfeng yun
maintainerRe: [PATCH v3 3/5] usb: phy: add usb3.0 phy driver for mt65xx SoCs
hi,
Quoted 9 lines · Felipe Balbi
Hi,
Quoted 3 lines · Chunfeng Yun
support usb3.0 phy of mt65xx SoCs
Signed-off-by Chunfeng Yun <[email protected]>you missed Kishon here.
Thank you.
Quoted 475 lines
Quoted 474 lines
--- drivers/phy/Kconfig | 9 + drivers/phy/Makefile | 1 + drivers/phy/phy-mt65xx-usb3.c | 426 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 436 insertions(+) create mode 100644 drivers/phy/phy-mt65xx-usb3.cdrivers/phy/Kconfig +9
-0@@ -193,6 +193,15 @@ config PHY_HIX5HD2_SATA help Support for SATA PHY on Hisilicon hix5hd2 Soc. +config PHY_MT65XX_USB3 + tristate "Mediatek USB3.0 PHY Driver" + depends on ARCH_MEDIATEK && OF + select GENERIC_PHY + help + Say 'Y' here to add support for Mediatek USB3.0 PHY driver + for mt65xx SoCs. it supports two usb2.0 ports and + one usb3.0 port. + config PHY_SUN4I_USB tristate "Allwinner sunxi SoC USB PHY driver" depends on ARCH_SUNXI && HAS_IOMEM && OFdrivers/phy/Makefile +1
-0@@ -22,6 +22,7 @@ obj-$(CONFIG_TI_PIPE3) += phy-ti-pipe3.o obj-$(CONFIG_TWL4030_USB) += phy-twl4030-usb.o obj-$(CONFIG_PHY_EXYNOS5250_SATA) += phy-exynos5250-sata.o obj-$(CONFIG_PHY_HIX5HD2_SATA) += phy-hix5hd2-sata.o +obj-$(CONFIG_PHY_MT65XX_USB3) += phy-mt65xx-usb3.o obj-$(CONFIG_PHY_SUN4I_USB) += phy-sun4i-usb.o obj-$(CONFIG_PHY_SUN9I_USB) += phy-sun9i-usb.o obj-$(CONFIG_PHY_SAMSUNG_USB2) += phy-exynos-usb2.odrivers/phy/phy-mt65xx-usb3.c new file +426
-0@@ -0,0 +1,426 @@ +/* +* Copyright (c) 2015 MediaTek Inc. +* Author: Chunfeng.Yun <[email protected]> +* +* This software is licensed under the terms of the GNU General Public +* License version 2, as published by the Free Software Foundation, and +* may be copied, distributed, and modified under those terms. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +*/ + +#include <linux/clk.h> +#include <linux/delay.h> +#include <linux/io.h> +#include <linux/module.h> +#include <linux/of_address.h> +#include <linux/of_device.h> +#include <linux/of_gpio.h> +#include <linux/of.h> +#include <linux/phy/phy.h> +#include <linux/platform_device.h> +#include <linux/pm_runtime.h> +#include <linux/regulator/consumer.h> +#include <linux/resource.h> + +/* +* for sifslv2 register +* relative to USB3_SIF2_BASE base address +*/ +#define SSUSB_SIFSLV_SPLLC (0x0000) +#define SSUSB_SIFSLV_U2PHY_COM_BASE (0x0800) +#define SSUSB_SIFSLV_U3PHYD_BASE (0x0900) +#define SSUSB_USB30_PHYA_SIV_B_BASE (0x0b00) +#define SSUSB_SIFSLV_U3PHYA_DA_BASE (0x0c00) + +/*port1 refs. +0x800(refer to port0)*/ +#define U3P_PORT_INTERVAL (0x800)/*based on port0 */ +#define U3P_PHY_DELTA (index) ((U3P_PORT_INTERVAL) * (index)) + +#define U3P_USBPHYACR0 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0000) +#define PA0_RG_U2PLL_FORCE_ON (0x1 << 15) + +#define U3P_USBPHYACR2 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0008) +#define PA2_RG_SIF_U2PLL_FORCE_EN (0x1 << 18) + +#define U3P_USBPHYACR5 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0014) +#define PA5_RG_U2_HSTX_SRCTRL (0x7 << 12) +#define PA5_RG_U2_HSTX_SRCTRL_VAL (x) ((0x7 & (x)) << 12) +#define PA5_RG_U2_HS_100U_U3_EN (0x1 << 11) + +#define U3P_USBPHYACR6 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0018) +#define PA6_RG_U2_ISO_EN (0x1 << 31) +#define PA6_RG_U2_BC11_SW_EN (0x1 << 23) +#define PA6_RG_U2_OTG_VBUSCMP_EN (0x1 << 20) + +#define U3P_U2PHYACR4 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0020) +#define P2C_RG_USB20_GPIO_CTL (0x1 << 9) +#define P2C_USB20_GPIO_MODE (0x1 << 8) +#define P2C_U2_GPIO_CTR_MSK (P2C_RG_USB20_GPIO_CTL | P2C_USB20_GPIO_MODE) + +#define U3D_U2PHYDCR0 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0060) +#define P2C_RG_SIF_U2PLL_FORCE_ON (0x1 << 24) + +#define U3P_U2PHYDTM0 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0068) +#define P2C_FORCE_UART_EN (0x1 << 26) +#define P2C_FORCE_DATAIN (0x1 << 23) +#define P2C_FORCE_DM_PULLDOWN (0x1 << 21) +#define P2C_FORCE_DP_PULLDOWN (0x1 << 20) +#define P2C_FORCE_XCVRSEL (0x1 << 19) +#define P2C_FORCE_SUSPENDM (0x1 << 18) +#define P2C_FORCE_TERMSEL (0x1 << 17) +#define P2C_RG_DATAIN (0xf << 10) +#define P2C_RG_DATAIN_VAL (x) ((0xf & (x)) << 10) +#define P2C_RG_DMPULLDOWN (0x1 << 7) +#define P2C_RG_DPPULLDOWN (0x1 << 6) +#define P2C_RG_XCVRSEL (0x3 << 4) +#define P2C_RG_XCVRSEL_VAL (x) ((0x3 & (x)) << 4) +#define P2C_RG_SUSPENDM (0x1 << 3) +#define P2C_RG_TERMSEL (0x1 << 2) +#define P2C_DTM0_PART_MASK \ + (P2C_FORCE_DATAIN | P2C_FORCE_DM_PULLDOWN | \ + P2C_FORCE_DP_PULLDOWN | P2C_FORCE_XCVRSEL | \ + P2C_FORCE_TERMSEL | P2C_RG_DMPULLDOWN | \ + P2C_RG_DPPULLDOWN | P2C_RG_TERMSEL) + +#define U3P_U2PHYDTM1 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x006C) +#define P2C_RG_UART_EN (0x1 << 16) +#define P2C_RG_VBUSVALID (0x1 << 5) +#define P2C_RG_SESSEND (0x1 << 4) +#define P2C_RG_AVALID (0x1 << 2) + +#define U3P_U3_PHYA_REG0 (SSUSB_USB30_PHYA_SIV_B_BASE + 0x0000) +#define P3A_RG_U3_VUSB10_ON (1 << 5) + +#define U3P_U3_PHYA_REG6 (SSUSB_USB30_PHYA_SIV_B_BASE + 0x0018) +#define P3A_RG_TX_EIDLE_CM (0xf << 28) +#define P3A_RG_TX_EIDLE_CM_VAL (x) ((0xf & (x)) << 28) + +#define U3P_U3_PHYA_REG9 (SSUSB_USB30_PHYA_SIV_B_BASE + 0x0024) +#define P3A_RG_RX_DAC_MUX (0x1f << 1) +#define P3A_RG_RX_DAC_MUX_VAL (x) ((0x1f & (x)) << 1) + +#define U3P_U3PHYA_DA_REG0 (SSUSB_SIFSLV_U3PHYA_DA_BASE + 0x0) +#define P3A_RG_XTAL_EXT_EN_U3 (0x3 << 10) +#define P3A_RG_XTAL_EXT_EN_U3_VAL (x) ((0x3 & (x)) << 10) + +#define U3P_PHYD_CDR1 (SSUSB_SIFSLV_U3PHYD_BASE + 0x5c) +#define P3D_RG_CDR_BIR_LTD1 (0x1f << 24) +#define P3D_RG_CDR_BIR_LTD1_VAL (x) ((0x1f & (x)) << 24) +#define P3D_RG_CDR_BIR_LTD0 (0x1f << 8) +#define P3D_RG_CDR_BIR_LTD0_VAL (x) ((0x1f & (x)) << 8) + +#define U3P_XTALCTL3 (SSUSB_SIFSLV_SPLLC + 0x18) +#define XC3_RG_U3_XTAL_RX_PWD (0x1 << 9) +#define XC3_RG_U3_FRC_XTAL_RX_PWD (0x1 << 8) + +#define MT65XX_MAX_PHYS 2 + +struct mt65xx_phy_instance { +struct phy *phy; +u32 index; +u32 delta;/* increament refers to port0 */ +}; + +struct mt65xx_u3phy { +struct device *dev; +void __iomem *sif_base;/* include sif2 */ +struct clk *u3phya_ref;/* reference clock of usb3 anolog phy */ +struct mt65xx_phy_instance phys[MT65XX_MAX_PHYS ]; +}; + +static struct mt65xx_u3phy *to_usbdrd_phy ( +struct mt65xx_phy_instance *instance) +{ + return container_of((instance), struct mt65xx_u3phy, + phys[(instance)->index]); +} + +static void phy_instance_init (struct mt65xx_phy_instance *instance) +{ +struct mt65xx_u3phy *u3phy =to_usbdrd_phy (instance); +void __iomem *sif_base = u3phy->sif_base + instance->delta; +u32 index = instance->index; +u32 tmp; + +/* switch to USB function. (system register, force ip into usb mode) */ + tmp =readl (sif_base +U3P_U2PHYDTM0 ); + tmp &= ~P2C_FORCE_UART_EN ; +writel (tmp, sif_base +U3P_U2PHYDTM0 ); + + tmp =readl (sif_base +U3P_U2PHYDTM1 ); + tmp &= ~P2C_RG_UART_EN ; +writel (tmp, sif_base +U3P_U2PHYDTM1 ); + +if (!index) { + tmp =readl (sif_base +U3P_U2PHYACR4 ); + tmp &= ~P2C_U2_GPIO_CTR_MSK ; +writel (tmp, sif_base +U3P_U2PHYACR4 ); + } + +/* DP/DM BC1.1 path Disable */ + tmp =readl (sif_base +U3P_USBPHYACR6 ); + tmp &= ~PA6_RG_U2_BC11_SW_EN ; +writel (tmp, sif_base +U3P_USBPHYACR6 ); + + tmp =readl (sif_base +U3P_U3PHYA_DA_REG0 ); + tmp &= ~P3A_RG_XTAL_EXT_EN_U3 ; + tmp |=P3A_RG_XTAL_EXT_EN_U3_VAL (2 ); +writel (tmp, sif_base +U3P_U3PHYA_DA_REG0 ); + + tmp =readl (sif_base +U3P_U3_PHYA_REG9 ); + tmp &= ~P3A_RG_RX_DAC_MUX ; + tmp |=P3A_RG_RX_DAC_MUX_VAL (4 ); +writel (tmp, sif_base +U3P_U3_PHYA_REG9 ); + + tmp =readl (sif_base +U3P_U3_PHYA_REG6 ); + tmp &= ~P3A_RG_TX_EIDLE_CM ; + tmp |=P3A_RG_TX_EIDLE_CM_VAL (0xe ); +writel (tmp, sif_base +U3P_U3_PHYA_REG6 ); + + tmp =readl (sif_base +U3P_PHYD_CDR1 ); + tmp &= ~(P3D_RG_CDR_BIR_LTD0 |P3D_RG_CDR_BIR_LTD1 ); + tmp |=P3D_RG_CDR_BIR_LTD0_VAL (0xc ) |P3D_RG_CDR_BIR_LTD1_VAL (0x3 ); +writel (tmp, sif_base +U3P_PHYD_CDR1 ); + +dev_dbg (u3phy->dev,"%s(%d)\n" , __func__, index); +} + +static void phy_instance_power_on (struct mt65xx_phy_instance *instance) +{ +struct mt65xx_u3phy *u3phy =to_usbdrd_phy (instance); +void __iomem *sif_base = u3phy->sif_base + instance->delta; +u32 index = instance->index; +u32 tmp; + +if (!index) { +/* Set RG_SSUSB_VUSB10_ON as 1 after VUSB10 ready */ + tmp =readl (sif_base +U3P_U3_PHYA_REG0 ); + tmp |=P3A_RG_U3_VUSB10_ON ; +writel (tmp, sif_base +U3P_U3_PHYA_REG0 ); + } + +/* (force_suspendm=0) (let suspendm=1, enable usb 480MHz pll) */ + tmp =readl (sif_base +U3P_U2PHYDTM0 ); + tmp &= ~(P2C_FORCE_SUSPENDM |P2C_RG_XCVRSEL ); + tmp &= ~(P2C_RG_DATAIN |P2C_DTM0_PART_MASK ); +writel (tmp, sif_base +U3P_U2PHYDTM0 ); + +/* OTG Enable */ + tmp =readl (sif_base +U3P_USBPHYACR6 ); + tmp |=PA6_RG_U2_OTG_VBUSCMP_EN ; +writel (tmp, sif_base +U3P_USBPHYACR6 ); + +if (!index) { + tmp =readl (sif_base +U3P_XTALCTL3 ); + tmp |=XC3_RG_U3_XTAL_RX_PWD |XC3_RG_U3_FRC_XTAL_RX_PWD ; +writel (tmp, sif_base +U3P_XTALCTL3 ); +/* [mt8173]disable Change 100uA current from SSUSB */ + tmp =readl (sif_base +U3P_USBPHYACR5 ); + tmp &= ~PA5_RG_U2_HS_100U_U3_EN ; +writel (tmp, sif_base +U3P_USBPHYACR5 ); + } +udelay (800 ); + + tmp =readl (sif_base +U3P_U2PHYDTM1 ); + tmp |=P2C_RG_VBUSVALID |P2C_RG_AVALID ; + tmp &= ~P2C_RG_SESSEND ; +writel (tmp, sif_base +U3P_U2PHYDTM1 ); +/* USB 2.0 slew rate calibration */ + tmp =readl (sif_base +U3P_USBPHYACR5 ); + tmp &= ~PA5_RG_U2_HSTX_SRCTRL ; + tmp |=PA5_RG_U2_HSTX_SRCTRL_VAL (4 ); +writel (tmp, sif_base +U3P_USBPHYACR5 ); + +dev_dbg (u3phy->dev,"%s(%d)(delta: 0x%x)\n" , __func__, + index, u3phy->phys[index].delta); +} + +static void phy_instance_power_off (struct mt65xx_phy_instance *instance) +{ +struct mt65xx_u3phy *u3phy =to_usbdrd_phy (instance); +void __iomem *sif_base = u3phy->sif_base + instance->delta; +u32 index = instance->index; +u32 tmp; + + tmp =readl (sif_base +U3P_U2PHYDTM0 ); + tmp &= ~(P2C_RG_XCVRSEL |P2C_RG_DATAIN ); + tmp |=P2C_RG_XCVRSEL_VAL (1 ) |P2C_RG_DATAIN_VAL (0 ); + tmp |=P2C_FORCE_SUSPENDM ; +writel (tmp, sif_base +U3P_U2PHYDTM0 ); + +/* OTG Disable */ + tmp =readl (sif_base +U3P_USBPHYACR6 ); + tmp &= ~PA6_RG_U2_OTG_VBUSCMP_EN ; +writel (tmp, sif_base +U3P_USBPHYACR6 ); +if (!index) { +/* (also disable)Change 100uA current switch to USB2.0 */ + tmp =readl (sif_base +U3P_USBPHYACR5 ); + tmp &= ~PA5_RG_U2_HS_100U_U3_EN ; +writel (tmp, sif_base +U3P_USBPHYACR5 ); + } +udelay (800 ); + +/* let suspendm=0, set utmi into analog power down */ + tmp =readl (sif_base +U3P_U2PHYDTM0 ); + tmp &= ~P2C_RG_SUSPENDM ; +writel (tmp, sif_base +U3P_U2PHYDTM0 ); +udelay (1 ); + + tmp =readl (sif_base +U3P_U2PHYDTM1 ); + tmp &= ~(P2C_RG_VBUSVALID |P2C_RG_AVALID ); + tmp |=P2C_RG_SESSEND ; +writel (tmp, sif_base +U3P_U2PHYDTM1 ); + +if (!index) { + tmp =readl (sif_base +U3P_U3_PHYA_REG0 ); + tmp &= ~P3A_RG_U3_VUSB10_ON ; +writel (tmp, sif_base +U3P_U3_PHYA_REG0 ); + } + +dev_dbg (u3phy->dev,"%s(%d)\n" , __func__, index); +} + +static int u3phy_clk_enable (struct mt65xx_u3phy *u3phy) +{ +int ret; + + ret =clk_prepare_enable (u3phy->u3phya_ref); +if (ret) { +dev_err (u3phy->dev,"failed to enable u3phya_ref\n" ); +return ret; + } +udelay (100 ); + +return 0 ; +} + +static int mt65xx_phy_init (struct phy *phy) +{ +struct mt65xx_phy_instance *instance =phy_get_drvdata (phy); + +phy_instance_init (instance); +return 0 ; +} + +static int mt65xx_phy_power_on (struct phy *phy) +{ +struct mt65xx_phy_instance *instance =phy_get_drvdata (phy); + +phy_instance_power_on (instance); +msleep (20 ); +return 0 ; +} + +static int mt65xx_phy_power_off (struct phy *phy) +{ +struct mt65xx_phy_instance *instance =phy_get_drvdata (phy); + +phy_instance_power_off (instance); +return 0 ; +} + +static struct phy *mt65xx_phy_xlate (struct device *dev, +struct of_phandle_args *args) +{ +struct mt65xx_u3phy *u3phy =dev_get_drvdata (dev); + +if (WARN_ON (args->args[0 ] >MT65XX_MAX_PHYS )) +return ERR_PTR (-ENODEV ); + +return u3phy->phys[args->args[0 ]].phy; +} + +static struct phy_ops mt65xx_u3phy_ops = { + .init = mt65xx_phy_init, + .power_on = mt65xx_phy_power_on, + .power_off = mt65xx_phy_power_off, + .owner =THIS_MODULE , +}; + +static const struct of_device_id mt65xx_u3phy_id_table[] = { + { .compatible ="mediatek,mt8173-u3phy" ,}, + { }, +}; +MODULE_DEVICE_TABLE (of, mt65xx_u3phy_id_table); + + +static int mt65xx_u3phy_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct phy_provider *phy_provider; +struct resource *sif_res; +struct mt65xx_u3phy *u3phy; +int i; + + u3phy =devm_kzalloc (dev,sizeof (*u3phy),GFP_KERNEL ); +if (!u3phy) +return -ENOMEM ; + + u3phy->dev = dev; +platform_set_drvdata (pdev, u3phy); + + sif_res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); + u3phy->sif_base =devm_ioremap_resource (dev, sif_res); +if (IS_ERR (u3phy->sif_base)) { +dev_err (dev,"failed to remap sif regs\n" ); +return PTR_ERR (u3phy->sif_base); + } + + u3phy->u3phya_ref =devm_clk_get (dev,"u3phya_ref" ); +if (IS_ERR (u3phy->u3phya_ref)) { +dev_err (dev,"error to get u3phya_ref\n" ); +return PTR_ERR (u3phy->u3phya_ref); + } + +for (i =0 ; i <MT65XX_MAX_PHYS ; i++) { +struct mt65xx_phy_instance *instance; +struct phy *phy; + + phy =devm_phy_create (dev,NULL , &mt65xx_u3phy_ops); +if (IS_ERR (phy)) { +dev_err (dev,"failed to create mt65xx_u3phy phy\n" ); +return PTR_ERR (phy); + } + instance = &u3phy->phys[i]; + instance->phy = phy; + instance->index = i; + instance->delta =U3P_PHY_DELTA (i); +phy_set_drvdata (phy, instance); + } + + phy_provider =devm_of_phy_provider_register (dev, mt65xx_phy_xlate); +if (IS_ERR (phy_provider)) { +dev_err (dev,"Failed to register phy provider\n" ); +return PTR_ERR (phy_provider); + } + +return u3phy_clk_enable (u3phy); +} + +static int mt65xx_u3phy_remove (struct platform_device *pdev) +{ +struct mt65xx_u3phy *u3phy =platform_get_drvdata (pdev); + +clk_disable_unprepare (u3phy->u3phya_ref); + +return 0 ; +} + +static struct platform_driver mt65xx_u3phy_driver = { + .probe = mt65xx_u3phy_probe, + .remove = mt65xx_u3phy_remove, + .driver = { + .name ="mt65xx-u3phy" , + .of_match_table = mt65xx_u3phy_id_table, + }, +}; + +module_platform_driver (mt65xx_u3phy_driver); + +MODULE_DESCRIPTION ("Mt65xx USB PHY driver" ); +MODULE_LICENSE ("GPL v2" );Signature · 1 line
1.8.1.1.dirty
Re: [PATCH v3 3/5] usb: phy: add usb3.0 phy driver for mt65xx SoCs
Hi,
Quoted 76 lines · chunfeng yun
hi,
Quoted 9 lines · Felipe Balbi
Hi,
Quoted 3 lines · Chunfeng Yun
support usb3.0 phy of mt65xx SoCs
Signed-off-by Chunfeng Yun <[email protected]>you missed Kishon here.
Thank you.
Quoted 64 lines
Quoted 64 lines
--- drivers/phy/Kconfig | 9 + drivers/phy/Makefile | 1 + drivers/phy/phy-mt65xx-usb3.c | 426 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 436 insertions(+) create mode 100644 drivers/phy/phy-mt65xx-usb3.cdrivers/phy/Kconfig +9
-0@@ -193,6 +193,15 @@ config PHY_HIX5HD2_SATA help Support for SATA PHY on Hisilicon hix5hd2 Soc. +config PHY_MT65XX_USB3 + tristate "Mediatek USB3.0 PHY Driver" + depends on ARCH_MEDIATEK && OF + select GENERIC_PHY + help + Say 'Y' here to add support for Mediatek USB3.0 PHY driver + for mt65xx SoCs. it supports two usb2.0 ports and + one usb3.0 port. + config PHY_SUN4I_USB tristate "Allwinner sunxi SoC USB PHY driver" depends on ARCH_SUNXI && HAS_IOMEM && OFdrivers/phy/Makefile +1
-0@@ -22,6 +22,7 @@ obj-$(CONFIG_TI_PIPE3) += phy-ti-pipe3.o obj-$(CONFIG_TWL4030_USB) += phy-twl4030-usb.o obj-$(CONFIG_PHY_EXYNOS5250_SATA) += phy-exynos5250-sata.o obj-$(CONFIG_PHY_HIX5HD2_SATA) += phy-hix5hd2-sata.o +obj-$(CONFIG_PHY_MT65XX_USB3) += phy-mt65xx-usb3.o obj-$(CONFIG_PHY_SUN4I_USB) += phy-sun4i-usb.o obj-$(CONFIG_PHY_SUN9I_USB) += phy-sun9i-usb.o obj-$(CONFIG_PHY_SAMSUNG_USB2) += phy-exynos-usb2.odrivers/phy/phy-mt65xx-usb3.c new file +19
-0@@ -0,0 +1,426 @@ +/* +* Copyright (c) 2015 MediaTek Inc. +* Author: Chunfeng.Yun <[email protected]> +* +* This software is licensed under the terms of the GNU General Public +* License version 2, as published by the Free Software Foundation, and +* may be copied, distributed, and modified under those terms. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +*/ + +#include <linux/clk.h> +#include <linux/delay.h> +#include <linux/io.h> +#include <linux/module.h>
Quoted 8 lines
Quoted 8 lines
drivers/phy/phy-mt65xx-usb3.c line 27
Quoted 8 lines
drivers/phy/phy-mt65xx-usb3.c new file +8
-0+#include <linux/of_address.h> +#include <linux/of_device.h> +#include <linux/of_gpio.h> +#include <linux/of.h> +#include <linux/phy/phy.h> +#include <linux/platform_device.h> +#include <linux/pm_runtime.h> +#include <linux/regulator/consumer.h>
Lot of these #include are not required. Add only those what are required by this driver.
Quoted 8 lines
Quoted 8 lines
drivers/phy/phy-mt65xx-usb3.c line 35
Quoted 8 lines
drivers/phy/phy-mt65xx-usb3.c new file +8
-0+#include <linux/resource.h> + +/* +* for sifslv2 register +* relative to USB3_SIF2_BASE base address +*/ +#define SSUSB_SIFSLV_SPLLC (0x0000) +#define SSUSB_SIFSLV_U2PHY_COM_BASE (0x0800)
Looks like all this base address can come from dt.
Quoted 99 lines
Quoted 99 lines
Quoted 99 lines
drivers/phy/phy-mt65xx-usb3.c new file +99
-0+#define SSUSB_SIFSLV_U3PHYD_BASE (0x0900) +#define SSUSB_USB30_PHYA_SIV_B_BASE (0x0b00) +#define SSUSB_SIFSLV_U3PHYA_DA_BASE (0x0c00) + +/*port1 refs. +0x800(refer to port0)*/ +#define U3P_PORT_INTERVAL (0x800)/*based on port0 */ +#define U3P_PHY_DELTA (index) ((U3P_PORT_INTERVAL) * (index)) + +#define U3P_USBPHYACR0 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0000) +#define PA0_RG_U2PLL_FORCE_ON (0x1 << 15) + +#define U3P_USBPHYACR2 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0008) +#define PA2_RG_SIF_U2PLL_FORCE_EN (0x1 << 18) + +#define U3P_USBPHYACR5 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0014) +#define PA5_RG_U2_HSTX_SRCTRL (0x7 << 12) +#define PA5_RG_U2_HSTX_SRCTRL_VAL (x) ((0x7 & (x)) << 12) +#define PA5_RG_U2_HS_100U_U3_EN (0x1 << 11) + +#define U3P_USBPHYACR6 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0018) +#define PA6_RG_U2_ISO_EN (0x1 << 31) +#define PA6_RG_U2_BC11_SW_EN (0x1 << 23) +#define PA6_RG_U2_OTG_VBUSCMP_EN (0x1 << 20) + +#define U3P_U2PHYACR4 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0020) +#define P2C_RG_USB20_GPIO_CTL (0x1 << 9) +#define P2C_USB20_GPIO_MODE (0x1 << 8) +#define P2C_U2_GPIO_CTR_MSK (P2C_RG_USB20_GPIO_CTL | P2C_USB20_GPIO_MODE) + +#define U3D_U2PHYDCR0 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0060) +#define P2C_RG_SIF_U2PLL_FORCE_ON (0x1 << 24) + +#define U3P_U2PHYDTM0 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0068) +#define P2C_FORCE_UART_EN (0x1 << 26) +#define P2C_FORCE_DATAIN (0x1 << 23) +#define P2C_FORCE_DM_PULLDOWN (0x1 << 21) +#define P2C_FORCE_DP_PULLDOWN (0x1 << 20) +#define P2C_FORCE_XCVRSEL (0x1 << 19) +#define P2C_FORCE_SUSPENDM (0x1 << 18) +#define P2C_FORCE_TERMSEL (0x1 << 17) +#define P2C_RG_DATAIN (0xf << 10) +#define P2C_RG_DATAIN_VAL (x) ((0xf & (x)) << 10) +#define P2C_RG_DMPULLDOWN (0x1 << 7) +#define P2C_RG_DPPULLDOWN (0x1 << 6) +#define P2C_RG_XCVRSEL (0x3 << 4) +#define P2C_RG_XCVRSEL_VAL (x) ((0x3 & (x)) << 4) +#define P2C_RG_SUSPENDM (0x1 << 3) +#define P2C_RG_TERMSEL (0x1 << 2) +#define P2C_DTM0_PART_MASK \ + (P2C_FORCE_DATAIN | P2C_FORCE_DM_PULLDOWN | \ + P2C_FORCE_DP_PULLDOWN | P2C_FORCE_XCVRSEL | \ + P2C_FORCE_TERMSEL | P2C_RG_DMPULLDOWN | \ + P2C_RG_DPPULLDOWN | P2C_RG_TERMSEL) + +#define U3P_U2PHYDTM1 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x006C) +#define P2C_RG_UART_EN (0x1 << 16) +#define P2C_RG_VBUSVALID (0x1 << 5) +#define P2C_RG_SESSEND (0x1 << 4) +#define P2C_RG_AVALID (0x1 << 2) + +#define U3P_U3_PHYA_REG0 (SSUSB_USB30_PHYA_SIV_B_BASE + 0x0000) +#define P3A_RG_U3_VUSB10_ON (1 << 5) + +#define U3P_U3_PHYA_REG6 (SSUSB_USB30_PHYA_SIV_B_BASE + 0x0018) +#define P3A_RG_TX_EIDLE_CM (0xf << 28) +#define P3A_RG_TX_EIDLE_CM_VAL (x) ((0xf & (x)) << 28) + +#define U3P_U3_PHYA_REG9 (SSUSB_USB30_PHYA_SIV_B_BASE + 0x0024) +#define P3A_RG_RX_DAC_MUX (0x1f << 1) +#define P3A_RG_RX_DAC_MUX_VAL (x) ((0x1f & (x)) << 1) + +#define U3P_U3PHYA_DA_REG0 (SSUSB_SIFSLV_U3PHYA_DA_BASE + 0x0) +#define P3A_RG_XTAL_EXT_EN_U3 (0x3 << 10) +#define P3A_RG_XTAL_EXT_EN_U3_VAL (x) ((0x3 & (x)) << 10) + +#define U3P_PHYD_CDR1 (SSUSB_SIFSLV_U3PHYD_BASE + 0x5c) +#define P3D_RG_CDR_BIR_LTD1 (0x1f << 24) +#define P3D_RG_CDR_BIR_LTD1_VAL (x) ((0x1f & (x)) << 24) +#define P3D_RG_CDR_BIR_LTD0 (0x1f << 8) +#define P3D_RG_CDR_BIR_LTD0_VAL (x) ((0x1f & (x)) << 8) + +#define U3P_XTALCTL3 (SSUSB_SIFSLV_SPLLC + 0x18) +#define XC3_RG_U3_XTAL_RX_PWD (0x1 << 9) +#define XC3_RG_U3_FRC_XTAL_RX_PWD (0x1 << 8) + +#define MT65XX_MAX_PHYS 2 + +struct mt65xx_phy_instance { +struct phy *phy; +u32 index; +u32 delta;/* increament refers to port0 */ +}; + +struct mt65xx_u3phy { +struct device *dev; +void __iomem *sif_base;/* include sif2 */ +struct clk *u3phya_ref;/* reference clock of usb3 anolog phy */ +struct mt65xx_phy_instance phys[MT65XX_MAX_PHYS ]; +};
Quoted 8 lines
Quoted 8 lines
drivers/phy/phy-mt65xx-usb3.c line 142
Quoted 8 lines
drivers/phy/phy-mt65xx-usb3.c new file +8
-0+ +static struct mt65xx_u3phy *to_usbdrd_phy ( +struct mt65xx_phy_instance *instance) +{ + return container_of((instance), struct mt65xx_u3phy, + phys[(instance)->index]); +} +
.
.
<<snip>>
.
.
Quoted 10 lines
Quoted 10 lines
drivers/phy/phy-mt65xx-usb3.c line 336
Quoted 10 lines
drivers/phy/phy-mt65xx-usb3.c new file +10
-0+static struct phy *mt65xx_phy_xlate (struct device *dev, +struct of_phandle_args *args) +{ +struct mt65xx_u3phy *u3phy =dev_get_drvdata (dev); + +if (WARN_ON (args->args[0 ] >MT65XX_MAX_PHYS )) +return ERR_PTR (-ENODEV ); + +return u3phy->phys[args->args[0 ]].phy; +}
If the driver doesn't have to get any data from dt, then custom xlate is not required at all. All you have to do is create separate nodes for every individual phy and keep it as the child node of the phy_provider dt node. Note that the phy consumer dt node should now use the label given for the chld-nodes and not the phy_provider. Look at drivers/phy/phy-miphy365x.c for reference.
Cheers
Kishon
chunfeng yun
maintainerRe: [PATCH v3 3/5] usb: phy: add usb3.0 phy driver for mt65xx SoCs
hi,
Quoted 82 lines · Kishon Vijay Abraham I
Hi,
Quoted 79 lines · chunfeng yun
hi,
Quoted 9 lines · Felipe Balbi
Hi,
Quoted 3 lines · Chunfeng Yun
support usb3.0 phy of mt65xx SoCs
Signed-off-by Chunfeng Yun <[email protected]>you missed Kishon here.
Thank you.
Quoted 67 lines
Quoted 67 lines
--- drivers/phy/Kconfig | 9 + drivers/phy/Makefile | 1 + drivers/phy/phy-mt65xx-usb3.c | 426 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 436 insertions(+) create mode 100644 drivers/phy/phy-mt65xx-usb3.cdrivers/phy/Kconfig +9
-0@@ -193,6 +193,15 @@ config PHY_HIX5HD2_SATA help Support for SATA PHY on Hisilicon hix5hd2 Soc. +config PHY_MT65XX_USB3 + tristate "Mediatek USB3.0 PHY Driver" + depends on ARCH_MEDIATEK && OF + select GENERIC_PHY + help + Say 'Y' here to add support for Mediatek USB3.0 PHY driver + for mt65xx SoCs. it supports two usb2.0 ports and + one usb3.0 port. + config PHY_SUN4I_USB tristate "Allwinner sunxi SoC USB PHY driver" depends on ARCH_SUNXI && HAS_IOMEM && OFdrivers/phy/Makefile +1
-0@@ -22,6 +22,7 @@ obj-$(CONFIG_TI_PIPE3) += phy-ti-pipe3.o obj-$(CONFIG_TWL4030_USB) += phy-twl4030-usb.o obj-$(CONFIG_PHY_EXYNOS5250_SATA) += phy-exynos5250-sata.o obj-$(CONFIG_PHY_HIX5HD2_SATA) += phy-hix5hd2-sata.o +obj-$(CONFIG_PHY_MT65XX_USB3) += phy-mt65xx-usb3.o obj-$(CONFIG_PHY_SUN4I_USB) += phy-sun4i-usb.o obj-$(CONFIG_PHY_SUN9I_USB) += phy-sun9i-usb.o obj-$(CONFIG_PHY_SAMSUNG_USB2) += phy-exynos-usb2.odrivers/phy/phy-mt65xx-usb3.c new file +22
-0@@ -0,0 +1,426 @@ +/* +* Copyright (c) 2015 MediaTek Inc. +* Author: Chunfeng.Yun <[email protected]> +* +* This software is licensed under the terms of the GNU General Public +* License version 2, as published by the Free Software Foundation, and +* may be copied, distributed, and modified under those terms. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +*/ + +#include <linux/clk.h> +#include <linux/delay.h> +#include <linux/io.h> +#include <linux/module.h> +#include <linux/of_address.h> +#include <linux/of_device.h> +#include <linux/of_gpio.h>
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
drivers/phy/phy-mt65xx-usb3.c line 27
Quoted 5 lines
drivers/phy/phy-mt65xx-usb3.c new file +5
-0+#include <linux/of.h> +#include <linux/phy/phy.h> +#include <linux/platform_device.h> +#include <linux/pm_runtime.h> +#include <linux/regulator/consumer.h> Lot of these #include are not required. Add only those what are required by this driver.
The dummy header files will be removed later
Quoted 10 lines
Quoted 8 lines
Quoted 8 lines
drivers/phy/phy-mt65xx-usb3.c line 35
Quoted 8 lines
drivers/phy/phy-mt65xx-usb3.c new file +8
-0+#include <linux/resource.h> + +/* +* for sifslv2 register +* relative to USB3_SIF2_BASE base address +*/ +#define SSUSB_SIFSLV_SPLLC (0x0000) +#define SSUSB_SIFSLV_U2PHY_COM_BASE (0x0800)Looks like all this base address can come from dt.
The phy supports multi-ports, and these are sub-segment registers for port0, and other ports can be calculated from the bases. So I think it's better to use the same base address in dts
Quoted 113 lines
Quoted 99 lines
Quoted 99 lines
Quoted 99 lines
drivers/phy/phy-mt65xx-usb3.c new file +99
-0+#define SSUSB_SIFSLV_U3PHYD_BASE (0x0900) +#define SSUSB_USB30_PHYA_SIV_B_BASE (0x0b00) +#define SSUSB_SIFSLV_U3PHYA_DA_BASE (0x0c00) + +/*port1 refs. +0x800(refer to port0)*/ +#define U3P_PORT_INTERVAL (0x800)/*based on port0 */ +#define U3P_PHY_DELTA (index) ((U3P_PORT_INTERVAL) * (index)) + +#define U3P_USBPHYACR0 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0000) +#define PA0_RG_U2PLL_FORCE_ON (0x1 << 15) + +#define U3P_USBPHYACR2 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0008) +#define PA2_RG_SIF_U2PLL_FORCE_EN (0x1 << 18) + +#define U3P_USBPHYACR5 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0014) +#define PA5_RG_U2_HSTX_SRCTRL (0x7 << 12) +#define PA5_RG_U2_HSTX_SRCTRL_VAL (x) ((0x7 & (x)) << 12) +#define PA5_RG_U2_HS_100U_U3_EN (0x1 << 11) + +#define U3P_USBPHYACR6 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0018) +#define PA6_RG_U2_ISO_EN (0x1 << 31) +#define PA6_RG_U2_BC11_SW_EN (0x1 << 23) +#define PA6_RG_U2_OTG_VBUSCMP_EN (0x1 << 20) + +#define U3P_U2PHYACR4 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0020) +#define P2C_RG_USB20_GPIO_CTL (0x1 << 9) +#define P2C_USB20_GPIO_MODE (0x1 << 8) +#define P2C_U2_GPIO_CTR_MSK (P2C_RG_USB20_GPIO_CTL | P2C_USB20_GPIO_MODE) + +#define U3D_U2PHYDCR0 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0060) +#define P2C_RG_SIF_U2PLL_FORCE_ON (0x1 << 24) + +#define U3P_U2PHYDTM0 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0068) +#define P2C_FORCE_UART_EN (0x1 << 26) +#define P2C_FORCE_DATAIN (0x1 << 23) +#define P2C_FORCE_DM_PULLDOWN (0x1 << 21) +#define P2C_FORCE_DP_PULLDOWN (0x1 << 20) +#define P2C_FORCE_XCVRSEL (0x1 << 19) +#define P2C_FORCE_SUSPENDM (0x1 << 18) +#define P2C_FORCE_TERMSEL (0x1 << 17) +#define P2C_RG_DATAIN (0xf << 10) +#define P2C_RG_DATAIN_VAL (x) ((0xf & (x)) << 10) +#define P2C_RG_DMPULLDOWN (0x1 << 7) +#define P2C_RG_DPPULLDOWN (0x1 << 6) +#define P2C_RG_XCVRSEL (0x3 << 4) +#define P2C_RG_XCVRSEL_VAL (x) ((0x3 & (x)) << 4) +#define P2C_RG_SUSPENDM (0x1 << 3) +#define P2C_RG_TERMSEL (0x1 << 2) +#define P2C_DTM0_PART_MASK \ + (P2C_FORCE_DATAIN | P2C_FORCE_DM_PULLDOWN | \ + P2C_FORCE_DP_PULLDOWN | P2C_FORCE_XCVRSEL | \ + P2C_FORCE_TERMSEL | P2C_RG_DMPULLDOWN | \ + P2C_RG_DPPULLDOWN | P2C_RG_TERMSEL) + +#define U3P_U2PHYDTM1 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x006C) +#define P2C_RG_UART_EN (0x1 << 16) +#define P2C_RG_VBUSVALID (0x1 << 5) +#define P2C_RG_SESSEND (0x1 << 4) +#define P2C_RG_AVALID (0x1 << 2) + +#define U3P_U3_PHYA_REG0 (SSUSB_USB30_PHYA_SIV_B_BASE + 0x0000) +#define P3A_RG_U3_VUSB10_ON (1 << 5) + +#define U3P_U3_PHYA_REG6 (SSUSB_USB30_PHYA_SIV_B_BASE + 0x0018) +#define P3A_RG_TX_EIDLE_CM (0xf << 28) +#define P3A_RG_TX_EIDLE_CM_VAL (x) ((0xf & (x)) << 28) + +#define U3P_U3_PHYA_REG9 (SSUSB_USB30_PHYA_SIV_B_BASE + 0x0024) +#define P3A_RG_RX_DAC_MUX (0x1f << 1) +#define P3A_RG_RX_DAC_MUX_VAL (x) ((0x1f & (x)) << 1) + +#define U3P_U3PHYA_DA_REG0 (SSUSB_SIFSLV_U3PHYA_DA_BASE + 0x0) +#define P3A_RG_XTAL_EXT_EN_U3 (0x3 << 10) +#define P3A_RG_XTAL_EXT_EN_U3_VAL (x) ((0x3 & (x)) << 10) + +#define U3P_PHYD_CDR1 (SSUSB_SIFSLV_U3PHYD_BASE + 0x5c) +#define P3D_RG_CDR_BIR_LTD1 (0x1f << 24) +#define P3D_RG_CDR_BIR_LTD1_VAL (x) ((0x1f & (x)) << 24) +#define P3D_RG_CDR_BIR_LTD0 (0x1f << 8) +#define P3D_RG_CDR_BIR_LTD0_VAL (x) ((0x1f & (x)) << 8) + +#define U3P_XTALCTL3 (SSUSB_SIFSLV_SPLLC + 0x18) +#define XC3_RG_U3_XTAL_RX_PWD (0x1 << 9) +#define XC3_RG_U3_FRC_XTAL_RX_PWD (0x1 << 8) + +#define MT65XX_MAX_PHYS 2 + +struct mt65xx_phy_instance { +struct phy *phy; +u32 index; +u32 delta;/* increament refers to port0 */ +}; + +struct mt65xx_u3phy { +struct device *dev; +void __iomem *sif_base;/* include sif2 */ +struct clk *u3phya_ref;/* reference clock of usb3 anolog phy */ +struct mt65xx_phy_instance phys[MT65XX_MAX_PHYS ]; +};Quoted 8 lines
Quoted 8 lines
drivers/phy/phy-mt65xx-usb3.c line 142
Quoted 8 lines
drivers/phy/phy-mt65xx-usb3.c new file +8
-0+ +static struct mt65xx_u3phy *to_usbdrd_phy ( +struct mt65xx_phy_instance *instance) +{ + return container_of((instance), struct mt65xx_u3phy, + phys[(instance)->index]); +} +.
.
<<snip>>
.
.
Quoted 17 lines
Quoted 10 lines
Quoted 10 lines
drivers/phy/phy-mt65xx-usb3.c line 336
Quoted 10 lines
drivers/phy/phy-mt65xx-usb3.c new file +10
-0+static struct phy *mt65xx_phy_xlate (struct device *dev, +struct of_phandle_args *args) +{ +struct mt65xx_u3phy *u3phy =dev_get_drvdata (dev); + +if (WARN_ON (args->args[0 ] >MT65XX_MAX_PHYS )) +return ERR_PTR (-ENODEV ); + +return u3phy->phys[args->args[0 ]].phy; +}If the driver doesn't have to get any data from dt, then custom xlate is not required at all. All you have to do is create separate nodes for every individual phy and keep it as the child node of the
phy_providerdt node. Note that the phy consumer dt node should now use the label given for the chld-nodes and not thephy_provider. Look atdrivers/phy/phy-miphy365x.cfor reference.
It is multi-port PHY, and these ports share some registers from offset [0, 0x7ff], and port0 segment is [0x800, 0xfff], port1 segment is [0x1000, 0x17ff], etc, so I think maybe it is not suitable to create separate nodes in dts for each port.
BTW: I refer to phy-exynos5-usbdrd.c which is multi-channel usb3.0 phy to write this driver.
thanks
Quoted 2 lines
Cheers
Kishon
Re: [PATCH v3 3/5] usb: phy: add usb3.0 phy driver for mt65xx SoCs
Hi,
Quoted 104 lines · chunfeng yun
hi,
Quoted 82 lines · Kishon Vijay Abraham I
Hi,
Quoted 79 lines · chunfeng yun
hi,
Quoted 9 lines · Felipe Balbi
Hi,
Quoted 3 lines · Chunfeng Yun
support usb3.0 phy of mt65xx SoCs
Signed-off-by Chunfeng Yun <[email protected]>you missed Kishon here.
Thank you.
Quoted 67 lines
Quoted 67 lines
--- drivers/phy/Kconfig | 9 + drivers/phy/Makefile | 1 + drivers/phy/phy-mt65xx-usb3.c | 426 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 436 insertions(+) create mode 100644 drivers/phy/phy-mt65xx-usb3.cdrivers/phy/Kconfig +9
-0@@ -193,6 +193,15 @@ config PHY_HIX5HD2_SATA help Support for SATA PHY on Hisilicon hix5hd2 Soc. +config PHY_MT65XX_USB3 + tristate "Mediatek USB3.0 PHY Driver" + depends on ARCH_MEDIATEK && OF + select GENERIC_PHY + help + Say 'Y' here to add support for Mediatek USB3.0 PHY driver + for mt65xx SoCs. it supports two usb2.0 ports and + one usb3.0 port. + config PHY_SUN4I_USB tristate "Allwinner sunxi SoC USB PHY driver" depends on ARCH_SUNXI && HAS_IOMEM && OFdrivers/phy/Makefile +1
-0@@ -22,6 +22,7 @@ obj-$(CONFIG_TI_PIPE3) += phy-ti-pipe3.o obj-$(CONFIG_TWL4030_USB) += phy-twl4030-usb.o obj-$(CONFIG_PHY_EXYNOS5250_SATA) += phy-exynos5250-sata.o obj-$(CONFIG_PHY_HIX5HD2_SATA) += phy-hix5hd2-sata.o +obj-$(CONFIG_PHY_MT65XX_USB3) += phy-mt65xx-usb3.o obj-$(CONFIG_PHY_SUN4I_USB) += phy-sun4i-usb.o obj-$(CONFIG_PHY_SUN9I_USB) += phy-sun9i-usb.o obj-$(CONFIG_PHY_SAMSUNG_USB2) += phy-exynos-usb2.odrivers/phy/phy-mt65xx-usb3.c new file +22
-0@@ -0,0 +1,426 @@ +/* +* Copyright (c) 2015 MediaTek Inc. +* Author: Chunfeng.Yun <[email protected]> +* +* This software is licensed under the terms of the GNU General Public +* License version 2, as published by the Free Software Foundation, and +* may be copied, distributed, and modified under those terms. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +*/ + +#include <linux/clk.h> +#include <linux/delay.h> +#include <linux/io.h> +#include <linux/module.h> +#include <linux/of_address.h> +#include <linux/of_device.h> +#include <linux/of_gpio.h> Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
drivers/phy/phy-mt65xx-usb3.c line 27
Quoted 5 lines
drivers/phy/phy-mt65xx-usb3.c new file +5
-0+#include <linux/of.h> +#include <linux/phy/phy.h> +#include <linux/platform_device.h> +#include <linux/pm_runtime.h> +#include <linux/regulator/consumer.h> Lot of these #include are not required. Add only those what are required by this driver.
The dummy header files will be removed later
Quoted 10 lines
Quoted 8 lines
Quoted 8 lines
drivers/phy/phy-mt65xx-usb3.c line 35
Quoted 8 lines
drivers/phy/phy-mt65xx-usb3.c new file +8
-0+#include <linux/resource.h> + +/* +* for sifslv2 register +* relative to USB3_SIF2_BASE base address +*/ +#define SSUSB_SIFSLV_SPLLC (0x0000) +#define SSUSB_SIFSLV_U2PHY_COM_BASE (0x0800)Looks like all this base address can come from dt.
Quoted 3 lines
The phy supports multi-ports, and these are sub-segment registers for port0, and other ports can be calculated from the bases. So I think it's better to use the same base address in dts
Nope. Except for the register offsets everything else can come from dt.
Quoted 131 lines
Quoted 114 lines
Quoted 100 lines
Quoted 100 lines
Quoted 100 lines
drivers/phy/phy-mt65xx-usb3.c new file +99
-0+#define SSUSB_SIFSLV_U3PHYD_BASE (0x0900) +#define SSUSB_USB30_PHYA_SIV_B_BASE (0x0b00) +#define SSUSB_SIFSLV_U3PHYA_DA_BASE (0x0c00) + +/*port1 refs. +0x800(refer to port0)*/ +#define U3P_PORT_INTERVAL (0x800)/*based on port0 */ +#define U3P_PHY_DELTA (index) ((U3P_PORT_INTERVAL) * (index)) + +#define U3P_USBPHYACR0 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0000) +#define PA0_RG_U2PLL_FORCE_ON (0x1 << 15) + +#define U3P_USBPHYACR2 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0008) +#define PA2_RG_SIF_U2PLL_FORCE_EN (0x1 << 18) + +#define U3P_USBPHYACR5 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0014) +#define PA5_RG_U2_HSTX_SRCTRL (0x7 << 12) +#define PA5_RG_U2_HSTX_SRCTRL_VAL (x) ((0x7 & (x)) << 12) +#define PA5_RG_U2_HS_100U_U3_EN (0x1 << 11) + +#define U3P_USBPHYACR6 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0018) +#define PA6_RG_U2_ISO_EN (0x1 << 31) +#define PA6_RG_U2_BC11_SW_EN (0x1 << 23) +#define PA6_RG_U2_OTG_VBUSCMP_EN (0x1 << 20) + +#define U3P_U2PHYACR4 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0020) +#define P2C_RG_USB20_GPIO_CTL (0x1 << 9) +#define P2C_USB20_GPIO_MODE (0x1 << 8) +#define P2C_U2_GPIO_CTR_MSK (P2C_RG_USB20_GPIO_CTL | P2C_USB20_GPIO_MODE) + +#define U3D_U2PHYDCR0 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0060) +#define P2C_RG_SIF_U2PLL_FORCE_ON (0x1 << 24) + +#define U3P_U2PHYDTM0 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0068) +#define P2C_FORCE_UART_EN (0x1 << 26) +#define P2C_FORCE_DATAIN (0x1 << 23) +#define P2C_FORCE_DM_PULLDOWN (0x1 << 21) +#define P2C_FORCE_DP_PULLDOWN (0x1 << 20) +#define P2C_FORCE_XCVRSEL (0x1 << 19) +#define P2C_FORCE_SUSPENDM (0x1 << 18) +#define P2C_FORCE_TERMSEL (0x1 << 17) +#define P2C_RG_DATAIN (0xf << 10) +#define P2C_RG_DATAIN_VAL (x) ((0xf & (x)) << 10) +#define P2C_RG_DMPULLDOWN (0x1 << 7) +#define P2C_RG_DPPULLDOWN (0x1 << 6) +#define P2C_RG_XCVRSEL (0x3 << 4) +#define P2C_RG_XCVRSEL_VAL (x) ((0x3 & (x)) << 4) +#define P2C_RG_SUSPENDM (0x1 << 3) +#define P2C_RG_TERMSEL (0x1 << 2) +#define P2C_DTM0_PART_MASK \ + (P2C_FORCE_DATAIN | P2C_FORCE_DM_PULLDOWN | \ + P2C_FORCE_DP_PULLDOWN | P2C_FORCE_XCVRSEL | \ + P2C_FORCE_TERMSEL | P2C_RG_DMPULLDOWN | \ + P2C_RG_DPPULLDOWN | P2C_RG_TERMSEL) + +#define U3P_U2PHYDTM1 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x006C) +#define P2C_RG_UART_EN (0x1 << 16) +#define P2C_RG_VBUSVALID (0x1 << 5) +#define P2C_RG_SESSEND (0x1 << 4) +#define P2C_RG_AVALID (0x1 << 2) + +#define U3P_U3_PHYA_REG0 (SSUSB_USB30_PHYA_SIV_B_BASE + 0x0000) +#define P3A_RG_U3_VUSB10_ON (1 << 5) + +#define U3P_U3_PHYA_REG6 (SSUSB_USB30_PHYA_SIV_B_BASE + 0x0018) +#define P3A_RG_TX_EIDLE_CM (0xf << 28) +#define P3A_RG_TX_EIDLE_CM_VAL (x) ((0xf & (x)) << 28) + +#define U3P_U3_PHYA_REG9 (SSUSB_USB30_PHYA_SIV_B_BASE + 0x0024) +#define P3A_RG_RX_DAC_MUX (0x1f << 1) +#define P3A_RG_RX_DAC_MUX_VAL (x) ((0x1f & (x)) << 1) + +#define U3P_U3PHYA_DA_REG0 (SSUSB_SIFSLV_U3PHYA_DA_BASE + 0x0) +#define P3A_RG_XTAL_EXT_EN_U3 (0x3 << 10) +#define P3A_RG_XTAL_EXT_EN_U3_VAL (x) ((0x3 & (x)) << 10) + +#define U3P_PHYD_CDR1 (SSUSB_SIFSLV_U3PHYD_BASE + 0x5c) +#define P3D_RG_CDR_BIR_LTD1 (0x1f << 24) +#define P3D_RG_CDR_BIR_LTD1_VAL (x) ((0x1f & (x)) << 24) +#define P3D_RG_CDR_BIR_LTD0 (0x1f << 8) +#define P3D_RG_CDR_BIR_LTD0_VAL (x) ((0x1f & (x)) << 8) + +#define U3P_XTALCTL3 (SSUSB_SIFSLV_SPLLC + 0x18) +#define XC3_RG_U3_XTAL_RX_PWD (0x1 << 9) +#define XC3_RG_U3_FRC_XTAL_RX_PWD (0x1 << 8) + +#define MT65XX_MAX_PHYS 2 + +struct mt65xx_phy_instance { +struct phy *phy; +u32 index; +u32 delta;/* increament refers to port0 */ +}; + +struct mt65xx_u3phy { +struct device *dev; +void __iomem *sif_base;/* include sif2 */ +struct clk *u3phya_ref;/* reference clock of usb3 anolog phy */ +struct mt65xx_phy_instance phys[MT65XX_MAX_PHYS ]; +};Quoted 8 lines
Quoted 8 lines
drivers/phy/phy-mt65xx-usb3.c line 142
Quoted 8 lines
drivers/phy/phy-mt65xx-usb3.c new file +8
-0+ +static struct mt65xx_u3phy *to_usbdrd_phy ( +struct mt65xx_phy_instance *instance) +{ + return container_of((instance), struct mt65xx_u3phy, + phys[(instance)->index]); +} +.
.
<<snip>>
.
.Quoted 17 lines
Quoted 10 lines
Quoted 10 lines
drivers/phy/phy-mt65xx-usb3.c line 336
Quoted 10 lines
drivers/phy/phy-mt65xx-usb3.c new file +10
-0+static struct phy *mt65xx_phy_xlate (struct device *dev, +struct of_phandle_args *args) +{ +struct mt65xx_u3phy *u3phy =dev_get_drvdata (dev); + +if (WARN_ON (args->args[0 ] >MT65XX_MAX_PHYS )) +return ERR_PTR (-ENODEV ); + +return u3phy->phys[args->args[0 ]].phy; +}If the driver doesn't have to get any data from dt, then custom xlate is not required at all. All you have to do is create separate nodes for every individual phy and keep it as the child node of the
phy_providerdt node. Note that the phy consumer dt node should now use the label given for the chld-nodes and not thephy_provider. Look atdrivers/phy/phy-miphy365x.cfor reference.
Quoted 2 lines
It is multi-port PHY, and these ports share some registers from offset [0,
0x7ff], and port0 segment is [0x800,0xfff], port1 segment is
The shared registers can be added in the 'phy_provider' dt node and the port specific registers can be added in the sub-node of phy_provider.
Quoted 2 lines
[
0x1000,0x17ff], etc, so I think maybe it is not suitable to create separate nodes in dts for each port.
Sorry, don't agree with you here.
Quoted 2 lines
BTW: I refer to
phy-exynos5-usbdrd.cwhich is multi-channel usb3.0 phy to write this driver.
Bad driver to refer to. It was added when phy-core was just merged to the linux kernel. And later new features had been added to the phy-core just to better support multi-phy phy-providers. If it is not for maintaining old dtbs compatibility, that driver would have been changed as well.
Thanks
Kishon
chunfeng yun
maintainerRe: [PATCH v3 3/5] usb: phy: add usb3.0 phy driver for mt65xx SoCs
Quoted 251 lines · Kishon Vijay Abraham I
Hi,
Quoted 104 lines · chunfeng yun
hi,
Quoted 82 lines · Kishon Vijay Abraham I
Hi,
Quoted 79 lines · chunfeng yun
hi,
Quoted 9 lines · Felipe Balbi
Hi,
Quoted 3 lines · Chunfeng Yun
support usb3.0 phy of mt65xx SoCs
Signed-off-by Chunfeng Yun <[email protected]>you missed Kishon here.
Thank you.
Quoted 67 lines
Quoted 67 lines
--- drivers/phy/Kconfig | 9 + drivers/phy/Makefile | 1 + drivers/phy/phy-mt65xx-usb3.c | 426 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 436 insertions(+) create mode 100644 drivers/phy/phy-mt65xx-usb3.cdrivers/phy/Kconfig +9
-0@@ -193,6 +193,15 @@ config PHY_HIX5HD2_SATA help Support for SATA PHY on Hisilicon hix5hd2 Soc. +config PHY_MT65XX_USB3 + tristate "Mediatek USB3.0 PHY Driver" + depends on ARCH_MEDIATEK && OF + select GENERIC_PHY + help + Say 'Y' here to add support for Mediatek USB3.0 PHY driver + for mt65xx SoCs. it supports two usb2.0 ports and + one usb3.0 port. + config PHY_SUN4I_USB tristate "Allwinner sunxi SoC USB PHY driver" depends on ARCH_SUNXI && HAS_IOMEM && OFdrivers/phy/Makefile +1
-0@@ -22,6 +22,7 @@ obj-$(CONFIG_TI_PIPE3) += phy-ti-pipe3.o obj-$(CONFIG_TWL4030_USB) += phy-twl4030-usb.o obj-$(CONFIG_PHY_EXYNOS5250_SATA) += phy-exynos5250-sata.o obj-$(CONFIG_PHY_HIX5HD2_SATA) += phy-hix5hd2-sata.o +obj-$(CONFIG_PHY_MT65XX_USB3) += phy-mt65xx-usb3.o obj-$(CONFIG_PHY_SUN4I_USB) += phy-sun4i-usb.o obj-$(CONFIG_PHY_SUN9I_USB) += phy-sun9i-usb.o obj-$(CONFIG_PHY_SAMSUNG_USB2) += phy-exynos-usb2.odrivers/phy/phy-mt65xx-usb3.c new file +22
-0@@ -0,0 +1,426 @@ +/* +* Copyright (c) 2015 MediaTek Inc. +* Author: Chunfeng.Yun <[email protected]> +* +* This software is licensed under the terms of the GNU General Public +* License version 2, as published by the Free Software Foundation, and +* may be copied, distributed, and modified under those terms. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +*/ + +#include <linux/clk.h> +#include <linux/delay.h> +#include <linux/io.h> +#include <linux/module.h> +#include <linux/of_address.h> +#include <linux/of_device.h> +#include <linux/of_gpio.h> Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
drivers/phy/phy-mt65xx-usb3.c line 27
Quoted 5 lines
drivers/phy/phy-mt65xx-usb3.c new file +5
-0+#include <linux/of.h> +#include <linux/phy/phy.h> +#include <linux/platform_device.h> +#include <linux/pm_runtime.h> +#include <linux/regulator/consumer.h> Lot of these #include are not required. Add only those what are required by this driver.
The dummy header files will be removed later
Quoted 10 lines
Quoted 8 lines
Quoted 8 lines
drivers/phy/phy-mt65xx-usb3.c line 35
Quoted 8 lines
drivers/phy/phy-mt65xx-usb3.c new file +8
-0+#include <linux/resource.h> + +/* +* for sifslv2 register +* relative to USB3_SIF2_BASE base address +*/ +#define SSUSB_SIFSLV_SPLLC (0x0000) +#define SSUSB_SIFSLV_U2PHY_COM_BASE (0x0800)Looks like all this base address can come from dt.
Quoted 3 lines
The phy supports multi-ports, and these are sub-segment registers for port0, and other ports can be calculated from the bases. So I think it's better to use the same base address in dts
Nope. Except for the register offsets everything else can come from dt.
Quoted 131 lines
Quoted 114 lines
Quoted 100 lines
Quoted 100 lines
Quoted 100 lines
drivers/phy/phy-mt65xx-usb3.c new file +99
-0+#define SSUSB_SIFSLV_U3PHYD_BASE (0x0900) +#define SSUSB_USB30_PHYA_SIV_B_BASE (0x0b00) +#define SSUSB_SIFSLV_U3PHYA_DA_BASE (0x0c00) + +/*port1 refs. +0x800(refer to port0)*/ +#define U3P_PORT_INTERVAL (0x800)/*based on port0 */ +#define U3P_PHY_DELTA (index) ((U3P_PORT_INTERVAL) * (index)) + +#define U3P_USBPHYACR0 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0000) +#define PA0_RG_U2PLL_FORCE_ON (0x1 << 15) + +#define U3P_USBPHYACR2 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0008) +#define PA2_RG_SIF_U2PLL_FORCE_EN (0x1 << 18) + +#define U3P_USBPHYACR5 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0014) +#define PA5_RG_U2_HSTX_SRCTRL (0x7 << 12) +#define PA5_RG_U2_HSTX_SRCTRL_VAL (x) ((0x7 & (x)) << 12) +#define PA5_RG_U2_HS_100U_U3_EN (0x1 << 11) + +#define U3P_USBPHYACR6 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0018) +#define PA6_RG_U2_ISO_EN (0x1 << 31) +#define PA6_RG_U2_BC11_SW_EN (0x1 << 23) +#define PA6_RG_U2_OTG_VBUSCMP_EN (0x1 << 20) + +#define U3P_U2PHYACR4 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0020) +#define P2C_RG_USB20_GPIO_CTL (0x1 << 9) +#define P2C_USB20_GPIO_MODE (0x1 << 8) +#define P2C_U2_GPIO_CTR_MSK (P2C_RG_USB20_GPIO_CTL | P2C_USB20_GPIO_MODE) + +#define U3D_U2PHYDCR0 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0060) +#define P2C_RG_SIF_U2PLL_FORCE_ON (0x1 << 24) + +#define U3P_U2PHYDTM0 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0068) +#define P2C_FORCE_UART_EN (0x1 << 26) +#define P2C_FORCE_DATAIN (0x1 << 23) +#define P2C_FORCE_DM_PULLDOWN (0x1 << 21) +#define P2C_FORCE_DP_PULLDOWN (0x1 << 20) +#define P2C_FORCE_XCVRSEL (0x1 << 19) +#define P2C_FORCE_SUSPENDM (0x1 << 18) +#define P2C_FORCE_TERMSEL (0x1 << 17) +#define P2C_RG_DATAIN (0xf << 10) +#define P2C_RG_DATAIN_VAL (x) ((0xf & (x)) << 10) +#define P2C_RG_DMPULLDOWN (0x1 << 7) +#define P2C_RG_DPPULLDOWN (0x1 << 6) +#define P2C_RG_XCVRSEL (0x3 << 4) +#define P2C_RG_XCVRSEL_VAL (x) ((0x3 & (x)) << 4) +#define P2C_RG_SUSPENDM (0x1 << 3) +#define P2C_RG_TERMSEL (0x1 << 2) +#define P2C_DTM0_PART_MASK \ + (P2C_FORCE_DATAIN | P2C_FORCE_DM_PULLDOWN | \ + P2C_FORCE_DP_PULLDOWN | P2C_FORCE_XCVRSEL | \ + P2C_FORCE_TERMSEL | P2C_RG_DMPULLDOWN | \ + P2C_RG_DPPULLDOWN | P2C_RG_TERMSEL) + +#define U3P_U2PHYDTM1 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x006C) +#define P2C_RG_UART_EN (0x1 << 16) +#define P2C_RG_VBUSVALID (0x1 << 5) +#define P2C_RG_SESSEND (0x1 << 4) +#define P2C_RG_AVALID (0x1 << 2) + +#define U3P_U3_PHYA_REG0 (SSUSB_USB30_PHYA_SIV_B_BASE + 0x0000) +#define P3A_RG_U3_VUSB10_ON (1 << 5) + +#define U3P_U3_PHYA_REG6 (SSUSB_USB30_PHYA_SIV_B_BASE + 0x0018) +#define P3A_RG_TX_EIDLE_CM (0xf << 28) +#define P3A_RG_TX_EIDLE_CM_VAL (x) ((0xf & (x)) << 28) + +#define U3P_U3_PHYA_REG9 (SSUSB_USB30_PHYA_SIV_B_BASE + 0x0024) +#define P3A_RG_RX_DAC_MUX (0x1f << 1) +#define P3A_RG_RX_DAC_MUX_VAL (x) ((0x1f & (x)) << 1) + +#define U3P_U3PHYA_DA_REG0 (SSUSB_SIFSLV_U3PHYA_DA_BASE + 0x0) +#define P3A_RG_XTAL_EXT_EN_U3 (0x3 << 10) +#define P3A_RG_XTAL_EXT_EN_U3_VAL (x) ((0x3 & (x)) << 10) + +#define U3P_PHYD_CDR1 (SSUSB_SIFSLV_U3PHYD_BASE + 0x5c) +#define P3D_RG_CDR_BIR_LTD1 (0x1f << 24) +#define P3D_RG_CDR_BIR_LTD1_VAL (x) ((0x1f & (x)) << 24) +#define P3D_RG_CDR_BIR_LTD0 (0x1f << 8) +#define P3D_RG_CDR_BIR_LTD0_VAL (x) ((0x1f & (x)) << 8) + +#define U3P_XTALCTL3 (SSUSB_SIFSLV_SPLLC + 0x18) +#define XC3_RG_U3_XTAL_RX_PWD (0x1 << 9) +#define XC3_RG_U3_FRC_XTAL_RX_PWD (0x1 << 8) + +#define MT65XX_MAX_PHYS 2 + +struct mt65xx_phy_instance { +struct phy *phy; +u32 index; +u32 delta;/* increament refers to port0 */ +}; + +struct mt65xx_u3phy { +struct device *dev; +void __iomem *sif_base;/* include sif2 */ +struct clk *u3phya_ref;/* reference clock of usb3 anolog phy */ +struct mt65xx_phy_instance phys[MT65XX_MAX_PHYS ]; +};Quoted 8 lines
Quoted 8 lines
drivers/phy/phy-mt65xx-usb3.c line 142
Quoted 8 lines
drivers/phy/phy-mt65xx-usb3.c new file +8
-0+ +static struct mt65xx_u3phy *to_usbdrd_phy ( +struct mt65xx_phy_instance *instance) +{ + return container_of((instance), struct mt65xx_u3phy, + phys[(instance)->index]); +} +.
.
<<snip>>
.
.Quoted 17 lines
Quoted 10 lines
Quoted 10 lines
drivers/phy/phy-mt65xx-usb3.c line 336
Quoted 10 lines
drivers/phy/phy-mt65xx-usb3.c new file +10
-0+static struct phy *mt65xx_phy_xlate (struct device *dev, +struct of_phandle_args *args) +{ +struct mt65xx_u3phy *u3phy =dev_get_drvdata (dev); + +if (WARN_ON (args->args[0 ] >MT65XX_MAX_PHYS )) +return ERR_PTR (-ENODEV ); + +return u3phy->phys[args->args[0 ]].phy; +}If the driver doesn't have to get any data from dt, then custom xlate is not required at all. All you have to do is create separate nodes for every individual phy and keep it as the child node of the
phy_providerdt node. Note that the phy consumer dt node should now use the label given for the chld-nodes and not thephy_provider. Look atdrivers/phy/phy-miphy365x.cfor reference.Quoted 2 lines
It is multi-port PHY, and these ports share some registers from offset [0,
0x7ff], and port0 segment is [0x800,0xfff], port1 segment isThe shared registers can be added in the '
phy_provider' dt node and the port specific registers can be added in the sub-node ofphy_provider.Quoted 2 lines
[
0x1000,0x17ff], etc, so I think maybe it is not suitable to create separate nodes in dts for each port.
Quoted 9 lines
Sorry, don't agree with you here.
Quoted 2 lines
BTW: I refer to
phy-exynos5-usbdrd.cwhich is multi-channel usb3.0 phy to write this driver.Bad driver to refer to. It was added when phy-core was just merged to the linux kernel. And later new features had been added to the phy-core just to better support multi-phy phy-providers. If it is not for maintaining old dtbs compatibility, that driver would have been changed as well.
I know a little about it now, and re-write the driver later. Thanks a lot for your kindly explanation and guidance:-)
Quoted 2 lines
Thanks
Kishon
Re: [PATCH v3 3/5] usb: phy: add usb3.0 phy driver for mt65xx SoCs
In reply to Chunfeng YunHi Chungfeng,
Comments inline.
Quoted 76 lines · Chunfeng Yun
support usb3.0 phy of mt65xx SoCs
Signed-off-by Chunfeng Yun <[email protected]>--- drivers/phy/Kconfig | 9 + drivers/phy/Makefile | 1 + drivers/phy/phy-mt65xx-usb3.c | 426 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 436 insertions(+) create mode 100644 drivers/phy/phy-mt65xx-usb3.cdrivers/phy/Kconfig +9
-0@@ -193,6 +193,15 @@ config PHY_HIX5HD2_SATA help Support for SATA PHY on Hisilicon hix5hd2 Soc. +config PHY_MT65XX_USB3 + tristate "Mediatek USB3.0 PHY Driver" + depends on ARCH_MEDIATEK && OF + select GENERIC_PHY + help + Say 'Y' here to add support for Mediatek USB3.0 PHY driver + for mt65xx SoCs. it supports two usb2.0 ports and + one usb3.0 port. + config PHY_SUN4I_USB tristate "Allwinner sunxi SoC USB PHY driver" depends on ARCH_SUNXI && HAS_IOMEM && OFdrivers/phy/Makefile +1
-0@@ -22,6 +22,7 @@ obj-$(CONFIG_TI_PIPE3) += phy-ti-pipe3.o obj-$(CONFIG_TWL4030_USB) += phy-twl4030-usb.o obj-$(CONFIG_PHY_EXYNOS5250_SATA) += phy-exynos5250-sata.o obj-$(CONFIG_PHY_HIX5HD2_SATA) += phy-hix5hd2-sata.o +obj-$(CONFIG_PHY_MT65XX_USB3) += phy-mt65xx-usb3.o obj-$(CONFIG_PHY_SUN4I_USB) += phy-sun4i-usb.o obj-$(CONFIG_PHY_SUN9I_USB) += phy-sun9i-usb.o obj-$(CONFIG_PHY_SAMSUNG_USB2) += phy-exynos-usb2.odrivers/phy/phy-mt65xx-usb3.c new file +28
-0@@ -0,0 +1,426 @@ +/* +* Copyright (c) 2015 MediaTek Inc. +* Author: Chunfeng.Yun <[email protected]> +* +* This software is licensed under the terms of the GNU General Public +* License version 2, as published by the Free Software Foundation, and +* may be copied, distributed, and modified under those terms. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +*/ + +#include <linux/clk.h> +#include <linux/delay.h> +#include <linux/io.h> +#include <linux/module.h> +#include <linux/of_address.h> +#include <linux/of_device.h> +#include <linux/of_gpio.h> +#include <linux/of.h> +#include <linux/phy/phy.h> +#include <linux/platform_device.h> +#include <linux/pm_runtime.h> +#include <linux/regulator/consumer.h> +#include <linux/resource.h>
drivers/phy/phy-mt65xx-usb3.c line 38
Quoted 10 lines
drivers/phy/phy-mt65xx-usb3.c new file +10
-0+ +/* +* for sifslv2 register +* relative to USB3_SIF2_BASE base address +*/ +#define SSUSB_SIFSLV_SPLLC (0x0000) +#define SSUSB_SIFSLV_U2PHY_COM_BASE (0x0800) +#define SSUSB_SIFSLV_U3PHYD_BASE (0x0900) +#define SSUSB_USB30_PHYA_SIV_B_BASE (0x0b00) +#define SSUSB_SIFSLV_U3PHYA_DA_BASE (0x0c00)
You don't need () here. Same for all following numeric constants.
drivers/phy/phy-mt65xx-usb3.c line 42
Quoted 4 lines
drivers/phy/phy-mt65xx-usb3.c new file +4
-0+ +/*port1 refs. +0x800(refer to port0)*/ +#define U3P_PORT_INTERVAL (0x800)/*based on port0 */ +#define U3P_PHY_DELTA (index) ((U3P_PORT_INTERVAL) * (index))
Indent with tab. It might also be a good idea to align the indentations of all the macros.
drivers/phy/phy-mt65xx-usb3.c line 45
Quoted 3 lines
drivers/phy/phy-mt65xx-usb3.c new file +3
-0+ +#define U3P_USBPHYACR0 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0000) +#define PA0_RG_U2PLL_FORCE_ON (0x1 << 15)
Use BIT() instead? Same for all following (0x1 << xx) macros.
Quoted 389 lines
drivers/phy/phy-mt65xx-usb3.c new file +381
-1+ +#define U3P_USBPHYACR2 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0008) +#define PA2_RG_SIF_U2PLL_FORCE_EN (0x1 << 18) + +#define U3P_USBPHYACR5 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0014) +#define PA5_RG_U2_HSTX_SRCTRL (0x7 << 12) +#define PA5_RG_U2_HSTX_SRCTRL_VAL (x) ((0x7 & (x)) << 12) +#define PA5_RG_U2_HS_100U_U3_EN (0x1 << 11) + +#define U3P_USBPHYACR6 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0018) +#define PA6_RG_U2_ISO_EN (0x1 << 31) +#define PA6_RG_U2_BC11_SW_EN (0x1 << 23) +#define PA6_RG_U2_OTG_VBUSCMP_EN (0x1 << 20) + +#define U3P_U2PHYACR4 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0020) +#define P2C_RG_USB20_GPIO_CTL (0x1 << 9) +#define P2C_USB20_GPIO_MODE (0x1 << 8) +#define P2C_U2_GPIO_CTR_MSK (P2C_RG_USB20_GPIO_CTL | P2C_USB20_GPIO_MODE) + +#define U3D_U2PHYDCR0 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0060) +#define P2C_RG_SIF_U2PLL_FORCE_ON (0x1 << 24) + +#define U3P_U2PHYDTM0 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0068) +#define P2C_FORCE_UART_EN (0x1 << 26) +#define P2C_FORCE_DATAIN (0x1 << 23) +#define P2C_FORCE_DM_PULLDOWN (0x1 << 21) +#define P2C_FORCE_DP_PULLDOWN (0x1 << 20) +#define P2C_FORCE_XCVRSEL (0x1 << 19) +#define P2C_FORCE_SUSPENDM (0x1 << 18) +#define P2C_FORCE_TERMSEL (0x1 << 17) +#define P2C_RG_DATAIN (0xf << 10) +#define P2C_RG_DATAIN_VAL (x) ((0xf & (x)) << 10) +#define P2C_RG_DMPULLDOWN (0x1 << 7) +#define P2C_RG_DPPULLDOWN (0x1 << 6) +#define P2C_RG_XCVRSEL (0x3 << 4) +#define P2C_RG_XCVRSEL_VAL (x) ((0x3 & (x)) << 4) +#define P2C_RG_SUSPENDM (0x1 << 3) +#define P2C_RG_TERMSEL (0x1 << 2) +#define P2C_DTM0_PART_MASK \ + (P2C_FORCE_DATAIN | P2C_FORCE_DM_PULLDOWN | \ + P2C_FORCE_DP_PULLDOWN | P2C_FORCE_XCVRSEL | \ + P2C_FORCE_TERMSEL | P2C_RG_DMPULLDOWN | \ + P2C_RG_DPPULLDOWN | P2C_RG_TERMSEL) + +#define U3P_U2PHYDTM1 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x006C) +#define P2C_RG_UART_EN (0x1 << 16) +#define P2C_RG_VBUSVALID (0x1 << 5) +#define P2C_RG_SESSEND (0x1 << 4) +#define P2C_RG_AVALID (0x1 << 2) + +#define U3P_U3_PHYA_REG0 (SSUSB_USB30_PHYA_SIV_B_BASE + 0x0000) +#define P3A_RG_U3_VUSB10_ON (1 << 5) + +#define U3P_U3_PHYA_REG6 (SSUSB_USB30_PHYA_SIV_B_BASE + 0x0018) +#define P3A_RG_TX_EIDLE_CM (0xf << 28) +#define P3A_RG_TX_EIDLE_CM_VAL (x) ((0xf & (x)) << 28) + +#define U3P_U3_PHYA_REG9 (SSUSB_USB30_PHYA_SIV_B_BASE + 0x0024) +#define P3A_RG_RX_DAC_MUX (0x1f << 1) +#define P3A_RG_RX_DAC_MUX_VAL (x) ((0x1f & (x)) << 1) + +#define U3P_U3PHYA_DA_REG0 (SSUSB_SIFSLV_U3PHYA_DA_BASE + 0x0) +#define P3A_RG_XTAL_EXT_EN_U3 (0x3 << 10) +#define P3A_RG_XTAL_EXT_EN_U3_VAL (x) ((0x3 & (x)) << 10) + +#define U3P_PHYD_CDR1 (SSUSB_SIFSLV_U3PHYD_BASE + 0x5c) +#define P3D_RG_CDR_BIR_LTD1 (0x1f << 24) +#define P3D_RG_CDR_BIR_LTD1_VAL (x) ((0x1f & (x)) << 24) +#define P3D_RG_CDR_BIR_LTD0 (0x1f << 8) +#define P3D_RG_CDR_BIR_LTD0_VAL (x) ((0x1f & (x)) << 8) + +#define U3P_XTALCTL3 (SSUSB_SIFSLV_SPLLC + 0x18) +#define XC3_RG_U3_XTAL_RX_PWD (0x1 << 9) +#define XC3_RG_U3_FRC_XTAL_RX_PWD (0x1 << 8) + +#define MT65XX_MAX_PHYS 2 + +struct mt65xx_phy_instance { +struct phy *phy; +u32 index; +u32 delta;/* increament refers to port0 */ +}; + +struct mt65xx_u3phy { +struct device *dev; +void __iomem *sif_base;/* include sif2 */ +struct clk *u3phya_ref;/* reference clock of usb3 anolog phy */ +struct mt65xx_phy_instance phys[MT65XX_MAX_PHYS ]; +}; + +static struct mt65xx_u3phy *to_usbdrd_phy ( +struct mt65xx_phy_instance *instance) +{ + return container_of((instance), struct mt65xx_u3phy, + phys[(instance)->index]); +} + +static void phy_instance_init (struct mt65xx_phy_instance *instance) +{ +struct mt65xx_u3phy *u3phy =to_usbdrd_phy (instance); +void __iomem *sif_base = u3phy->sif_base + instance->delta; +u32 index = instance->index; +u32 tmp; + +/* switch to USB function. (system register, force ip into usb mode) */ + tmp =readl (sif_base +U3P_U2PHYDTM0 ); + tmp &= ~P2C_FORCE_UART_EN ; +writel (tmp, sif_base +U3P_U2PHYDTM0 ); + + tmp =readl (sif_base +U3P_U2PHYDTM1 ); + tmp &= ~P2C_RG_UART_EN ; +writel (tmp, sif_base +U3P_U2PHYDTM1 ); + +if (!index) { + tmp =readl (sif_base +U3P_U2PHYACR4 ); + tmp &= ~P2C_U2_GPIO_CTR_MSK ; +writel (tmp, sif_base +U3P_U2PHYACR4 ); + } + +/* DP/DM BC1.1 path Disable */ + tmp =readl (sif_base +U3P_USBPHYACR6 ); + tmp &= ~PA6_RG_U2_BC11_SW_EN ; +writel (tmp, sif_base +U3P_USBPHYACR6 ); + + tmp =readl (sif_base +U3P_U3PHYA_DA_REG0 ); + tmp &= ~P3A_RG_XTAL_EXT_EN_U3 ; + tmp |=P3A_RG_XTAL_EXT_EN_U3_VAL (2 ); +writel (tmp, sif_base +U3P_U3PHYA_DA_REG0 ); + + tmp =readl (sif_base +U3P_U3_PHYA_REG9 ); + tmp &= ~P3A_RG_RX_DAC_MUX ; + tmp |=P3A_RG_RX_DAC_MUX_VAL (4 ); +writel (tmp, sif_base +U3P_U3_PHYA_REG9 ); + + tmp =readl (sif_base +U3P_U3_PHYA_REG6 ); + tmp &= ~P3A_RG_TX_EIDLE_CM ; + tmp |=P3A_RG_TX_EIDLE_CM_VAL (0xe ); +writel (tmp, sif_base +U3P_U3_PHYA_REG6 ); + + tmp =readl (sif_base +U3P_PHYD_CDR1 ); + tmp &= ~(P3D_RG_CDR_BIR_LTD0 |P3D_RG_CDR_BIR_LTD1 ); + tmp |=P3D_RG_CDR_BIR_LTD0_VAL (0xc ) |P3D_RG_CDR_BIR_LTD1_VAL (0x3 ); +writel (tmp, sif_base +U3P_PHYD_CDR1 ); + +dev_dbg (u3phy->dev,"%s(%d)\n" , __func__, index); +} + +static void phy_instance_power_on (struct mt65xx_phy_instance *instance) +{ +struct mt65xx_u3phy *u3phy =to_usbdrd_phy (instance); +void __iomem *sif_base = u3phy->sif_base + instance->delta; +u32 index = instance->index; +u32 tmp; + +if (!index) { +/* Set RG_SSUSB_VUSB10_ON as 1 after VUSB10 ready */ + tmp =readl (sif_base +U3P_U3_PHYA_REG0 ); + tmp |=P3A_RG_U3_VUSB10_ON ; +writel (tmp, sif_base +U3P_U3_PHYA_REG0 ); + } + +/* (force_suspendm=0) (let suspendm=1, enable usb 480MHz pll) */ + tmp =readl (sif_base +U3P_U2PHYDTM0 ); + tmp &= ~(P2C_FORCE_SUSPENDM |P2C_RG_XCVRSEL ); + tmp &= ~(P2C_RG_DATAIN |P2C_DTM0_PART_MASK ); +writel (tmp, sif_base +U3P_U2PHYDTM0 ); + +/* OTG Enable */ + tmp =readl (sif_base +U3P_USBPHYACR6 ); + tmp |=PA6_RG_U2_OTG_VBUSCMP_EN ; +writel (tmp, sif_base +U3P_USBPHYACR6 ); + +if (!index) { + tmp =readl (sif_base +U3P_XTALCTL3 ); + tmp |=XC3_RG_U3_XTAL_RX_PWD |XC3_RG_U3_FRC_XTAL_RX_PWD ; +writel (tmp, sif_base +U3P_XTALCTL3 ); +/* [mt8173]disable Change 100uA current from SSUSB */ + tmp =readl (sif_base +U3P_USBPHYACR5 ); + tmp &= ~PA5_RG_U2_HS_100U_U3_EN ; +writel (tmp, sif_base +U3P_USBPHYACR5 ); + } +udelay (800 ); + + tmp =readl (sif_base +U3P_U2PHYDTM1 ); + tmp |=P2C_RG_VBUSVALID |P2C_RG_AVALID ; + tmp &= ~P2C_RG_SESSEND ; +writel (tmp, sif_base +U3P_U2PHYDTM1 ); +/* USB 2.0 slew rate calibration */ + tmp =readl (sif_base +U3P_USBPHYACR5 ); + tmp &= ~PA5_RG_U2_HSTX_SRCTRL ; + tmp |=PA5_RG_U2_HSTX_SRCTRL_VAL (4 ); +writel (tmp, sif_base +U3P_USBPHYACR5 ); + +dev_dbg (u3phy->dev,"%s(%d)(delta: 0x%x)\n" , __func__, + index, u3phy->phys[index].delta); +} + +static void phy_instance_power_off (struct mt65xx_phy_instance *instance) +{ +struct mt65xx_u3phy *u3phy =to_usbdrd_phy (instance); +void __iomem *sif_base = u3phy->sif_base + instance->delta; +u32 index = instance->index; +u32 tmp; + + tmp =readl (sif_base +U3P_U2PHYDTM0 ); + tmp &= ~(P2C_RG_XCVRSEL |P2C_RG_DATAIN ); + tmp |=P2C_RG_XCVRSEL_VAL (1 ) |P2C_RG_DATAIN_VAL (0 ); + tmp |=P2C_FORCE_SUSPENDM ; +writel (tmp, sif_base +U3P_U2PHYDTM0 ); + +/* OTG Disable */ + tmp =readl (sif_base +U3P_USBPHYACR6 ); + tmp &= ~PA6_RG_U2_OTG_VBUSCMP_EN ; +writel (tmp, sif_base +U3P_USBPHYACR6 ); +if (!index) { +/* (also disable)Change 100uA current switch to USB2.0 */ + tmp =readl (sif_base +U3P_USBPHYACR5 ); + tmp &= ~PA5_RG_U2_HS_100U_U3_EN ; +writel (tmp, sif_base +U3P_USBPHYACR5 ); + } +udelay (800 ); + +/* let suspendm=0, set utmi into analog power down */ + tmp =readl (sif_base +U3P_U2PHYDTM0 ); + tmp &= ~P2C_RG_SUSPENDM ; +writel (tmp, sif_base +U3P_U2PHYDTM0 ); +udelay (1 ); + + tmp =readl (sif_base +U3P_U2PHYDTM1 ); + tmp &= ~(P2C_RG_VBUSVALID |P2C_RG_AVALID ); + tmp |=P2C_RG_SESSEND ; +writel (tmp, sif_base +U3P_U2PHYDTM1 ); + +if (!index) { + tmp =readl (sif_base +U3P_U3_PHYA_REG0 ); + tmp &= ~P3A_RG_U3_VUSB10_ON ; +writel (tmp, sif_base +U3P_U3_PHYA_REG0 ); + } + +dev_dbg (u3phy->dev,"%s(%d)\n" , __func__, index); +} + +static int u3phy_clk_enable (struct mt65xx_u3phy *u3phy) +{ +int ret; + + ret =clk_prepare_enable (u3phy->u3phya_ref); +if (ret) { +dev_err (u3phy->dev,"failed to enable u3phya_ref\n" ); +return ret; + } +udelay (100 ); + +return 0 ; +} + +static int mt65xx_phy_init (struct phy *phy) +{ +struct mt65xx_phy_instance *instance =phy_get_drvdata (phy); + +phy_instance_init (instance); +return 0 ; +} + +static int mt65xx_phy_power_on (struct phy *phy) +{ +struct mt65xx_phy_instance *instance =phy_get_drvdata (phy); + +phy_instance_power_on (instance); +msleep (20 ); +return 0 ; +} + +static int mt65xx_phy_power_off (struct phy *phy) +{ +struct mt65xx_phy_instance *instance =phy_get_drvdata (phy); + +phy_instance_power_off (instance); +return 0 ; +} + +static struct phy *mt65xx_phy_xlate (struct device *dev, +struct of_phandle_args *args) +{ +struct mt65xx_u3phy *u3phy =dev_get_drvdata (dev); + +if (WARN_ON (args->args[0 ] >MT65XX_MAX_PHYS )) +return ERR_PTR (-ENODEV ); + +return u3phy->phys[args->args[0 ]].phy; +} + +static struct phy_ops mt65xx_u3phy_ops = { + .init = mt65xx_phy_init, + .power_on = mt65xx_phy_power_on, + .power_off = mt65xx_phy_power_off, + .owner =THIS_MODULE , +}; + +static const struct of_device_id mt65xx_u3phy_id_table[] = { + { .compatible ="mediatek,mt8173-u3phy" ,}, + { }, +}; +MODULE_DEVICE_TABLE (of, mt65xx_u3phy_id_table); + + +static int mt65xx_u3phy_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct phy_provider *phy_provider; +struct resource *sif_res; +struct mt65xx_u3phy *u3phy; +int i; + + u3phy =devm_kzalloc (dev,sizeof (*u3phy),GFP_KERNEL ); +if (!u3phy) +return -ENOMEM ; + + u3phy->dev = dev; +platform_set_drvdata (pdev, u3phy); + + sif_res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); + u3phy->sif_base =devm_ioremap_resource (dev, sif_res); +if (IS_ERR (u3phy->sif_base)) { +dev_err (dev,"failed to remap sif regs\n" ); +return PTR_ERR (u3phy->sif_base); + } + + u3phy->u3phya_ref =devm_clk_get (dev,"u3phya_ref" ); +if (IS_ERR (u3phy->u3phya_ref)) { +dev_err (dev,"error to get u3phya_ref\n" ); +return PTR_ERR (u3phy->u3phya_ref); + } + +for (i =0 ; i <MT65XX_MAX_PHYS ; i++) { +struct mt65xx_phy_instance *instance; +struct phy *phy; + + phy =devm_phy_create (dev,NULL , &mt65xx_u3phy_ops); +if (IS_ERR (phy)) { +dev_err (dev,"failed to create mt65xx_u3phy phy\n" ); +return PTR_ERR (phy); + } + instance = &u3phy->phys[i]; + instance->phy = phy; + instance->index = i; + instance->delta =U3P_PHY_DELTA (i); +phy_set_drvdata (phy, instance); + } + + phy_provider =devm_of_phy_provider_register (dev, mt65xx_phy_xlate); +if (IS_ERR (phy_provider)) { +dev_err (dev,"Failed to register phy provider\n" ); +return PTR_ERR (phy_provider); + } + +return u3phy_clk_enable (u3phy); +} + +static int mt65xx_u3phy_remove (struct platform_device *pdev) +{ +struct mt65xx_u3phy *u3phy =platform_get_drvdata (pdev); + +clk_disable_unprepare (u3phy->u3phya_ref); + +return 0 ; +} + +static struct platform_driver mt65xx_u3phy_driver = { + .probe = mt65xx_u3phy_probe, + .remove = mt65xx_u3phy_remove, + .driver = { + .name ="mt65xx-u3phy" , + .of_match_table = mt65xx_u3phy_id_table, + }, +}; + +module_platform_driver (mt65xx_u3phy_driver); + +MODULE_DESCRIPTION ("Mt65xx USB PHY driver" ); +MODULE_LICENSE ("GPL v2" ); --1.8.1.1.dirty
_______________________________________________
Linux-mediatek mailing list
Linux-mediatek at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek
chunfeng yun
maintainerRe: [PATCH v3 3/5] usb: phy: add usb3.0 phy driver for mt65xx SoCs
hi Ricky,
Quoted 86 lines · Ricky Liang
Hi Chungfeng,
Comments inline.
Quoted 80 lines · Chunfeng Yun
support usb3.0 phy of mt65xx SoCs
Signed-off-by Chunfeng Yun <[email protected]>--- drivers/phy/Kconfig | 9 + drivers/phy/Makefile | 1 + drivers/phy/phy-mt65xx-usb3.c | 426 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 436 insertions(+) create mode 100644 drivers/phy/phy-mt65xx-usb3.cdrivers/phy/Kconfig +9
-0@@ -193,6 +193,15 @@ config PHY_HIX5HD2_SATA help Support for SATA PHY on Hisilicon hix5hd2 Soc. +config PHY_MT65XX_USB3 + tristate "Mediatek USB3.0 PHY Driver" + depends on ARCH_MEDIATEK && OF + select GENERIC_PHY + help + Say 'Y' here to add support for Mediatek USB3.0 PHY driver + for mt65xx SoCs. it supports two usb2.0 ports and + one usb3.0 port. + config PHY_SUN4I_USB tristate "Allwinner sunxi SoC USB PHY driver" depends on ARCH_SUNXI && HAS_IOMEM && OFdrivers/phy/Makefile +1
-0@@ -22,6 +22,7 @@ obj-$(CONFIG_TI_PIPE3) += phy-ti-pipe3.o obj-$(CONFIG_TWL4030_USB) += phy-twl4030-usb.o obj-$(CONFIG_PHY_EXYNOS5250_SATA) += phy-exynos5250-sata.o obj-$(CONFIG_PHY_HIX5HD2_SATA) += phy-hix5hd2-sata.o +obj-$(CONFIG_PHY_MT65XX_USB3) += phy-mt65xx-usb3.o obj-$(CONFIG_PHY_SUN4I_USB) += phy-sun4i-usb.o obj-$(CONFIG_PHY_SUN9I_USB) += phy-sun9i-usb.o obj-$(CONFIG_PHY_SAMSUNG_USB2) += phy-exynos-usb2.odrivers/phy/phy-mt65xx-usb3.c new file +32
-0@@ -0,0 +1,426 @@ +/* +* Copyright (c) 2015 MediaTek Inc. +* Author: Chunfeng.Yun <[email protected]> +* +* This software is licensed under the terms of the GNU General Public +* License version 2, as published by the Free Software Foundation, and +* may be copied, distributed, and modified under those terms. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +*/ + +#include <linux/clk.h> +#include <linux/delay.h> +#include <linux/io.h> +#include <linux/module.h> +#include <linux/of_address.h> +#include <linux/of_device.h> +#include <linux/of_gpio.h> +#include <linux/of.h> +#include <linux/phy/phy.h> +#include <linux/platform_device.h> +#include <linux/pm_runtime.h> +#include <linux/regulator/consumer.h> +#include <linux/resource.h> + +/* +* for sifslv2 register +* relative to USB3_SIF2_BASE base address
Quoted 9 lines
drivers/phy/phy-mt65xx-usb3.c line 38
Quoted 6 lines
drivers/phy/phy-mt65xx-usb3.c new file +6
-0+*/ +#define SSUSB_SIFSLV_SPLLC (0x0000) +#define SSUSB_SIFSLV_U2PHY_COM_BASE (0x0800) +#define SSUSB_SIFSLV_U3PHYD_BASE (0x0900) +#define SSUSB_USB30_PHYA_SIV_B_BASE (0x0b00) +#define SSUSB_SIFSLV_U3PHYA_DA_BASE (0x0c00)You don't need () here. Same for all following numeric constants.
Ok, I will delete them.
Quoted 8 lines
drivers/phy/phy-mt65xx-usb3.c line 42
Quoted 4 lines
drivers/phy/phy-mt65xx-usb3.c new file +4
-0+ +/*port1 refs. +0x800(refer to port0)*/ +#define U3P_PORT_INTERVAL (0x800)/*based on port0 */ +#define U3P_PHY_DELTA (index) ((U3P_PORT_INTERVAL) * (index))Indent with tab. It might also be a good idea to align the indentations of all the macros.
OK
Quoted 6 lines
drivers/phy/phy-mt65xx-usb3.c line 45
Quoted 3 lines
drivers/phy/phy-mt65xx-usb3.c new file +3
-0+ +#define U3P_USBPHYACR0 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0000) +#define PA0_RG_U2PLL_FORCE_ON (0x1 << 15)Use
BIT()instead? Same for all following (0x1<< xx) macros.
I'll do it.
thanks.
Quoted 389 lines
Quoted 389 lines
drivers/phy/phy-mt65xx-usb3.c new file +381
-1+ +#define U3P_USBPHYACR2 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0008) +#define PA2_RG_SIF_U2PLL_FORCE_EN (0x1 << 18) + +#define U3P_USBPHYACR5 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0014) +#define PA5_RG_U2_HSTX_SRCTRL (0x7 << 12) +#define PA5_RG_U2_HSTX_SRCTRL_VAL (x) ((0x7 & (x)) << 12) +#define PA5_RG_U2_HS_100U_U3_EN (0x1 << 11) + +#define U3P_USBPHYACR6 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0018) +#define PA6_RG_U2_ISO_EN (0x1 << 31) +#define PA6_RG_U2_BC11_SW_EN (0x1 << 23) +#define PA6_RG_U2_OTG_VBUSCMP_EN (0x1 << 20) + +#define U3P_U2PHYACR4 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0020) +#define P2C_RG_USB20_GPIO_CTL (0x1 << 9) +#define P2C_USB20_GPIO_MODE (0x1 << 8) +#define P2C_U2_GPIO_CTR_MSK (P2C_RG_USB20_GPIO_CTL | P2C_USB20_GPIO_MODE) + +#define U3D_U2PHYDCR0 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0060) +#define P2C_RG_SIF_U2PLL_FORCE_ON (0x1 << 24) + +#define U3P_U2PHYDTM0 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0068) +#define P2C_FORCE_UART_EN (0x1 << 26) +#define P2C_FORCE_DATAIN (0x1 << 23) +#define P2C_FORCE_DM_PULLDOWN (0x1 << 21) +#define P2C_FORCE_DP_PULLDOWN (0x1 << 20) +#define P2C_FORCE_XCVRSEL (0x1 << 19) +#define P2C_FORCE_SUSPENDM (0x1 << 18) +#define P2C_FORCE_TERMSEL (0x1 << 17) +#define P2C_RG_DATAIN (0xf << 10) +#define P2C_RG_DATAIN_VAL (x) ((0xf & (x)) << 10) +#define P2C_RG_DMPULLDOWN (0x1 << 7) +#define P2C_RG_DPPULLDOWN (0x1 << 6) +#define P2C_RG_XCVRSEL (0x3 << 4) +#define P2C_RG_XCVRSEL_VAL (x) ((0x3 & (x)) << 4) +#define P2C_RG_SUSPENDM (0x1 << 3) +#define P2C_RG_TERMSEL (0x1 << 2) +#define P2C_DTM0_PART_MASK \ + (P2C_FORCE_DATAIN | P2C_FORCE_DM_PULLDOWN | \ + P2C_FORCE_DP_PULLDOWN | P2C_FORCE_XCVRSEL | \ + P2C_FORCE_TERMSEL | P2C_RG_DMPULLDOWN | \ + P2C_RG_DPPULLDOWN | P2C_RG_TERMSEL) + +#define U3P_U2PHYDTM1 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x006C) +#define P2C_RG_UART_EN (0x1 << 16) +#define P2C_RG_VBUSVALID (0x1 << 5) +#define P2C_RG_SESSEND (0x1 << 4) +#define P2C_RG_AVALID (0x1 << 2) + +#define U3P_U3_PHYA_REG0 (SSUSB_USB30_PHYA_SIV_B_BASE + 0x0000) +#define P3A_RG_U3_VUSB10_ON (1 << 5) + +#define U3P_U3_PHYA_REG6 (SSUSB_USB30_PHYA_SIV_B_BASE + 0x0018) +#define P3A_RG_TX_EIDLE_CM (0xf << 28) +#define P3A_RG_TX_EIDLE_CM_VAL (x) ((0xf & (x)) << 28) + +#define U3P_U3_PHYA_REG9 (SSUSB_USB30_PHYA_SIV_B_BASE + 0x0024) +#define P3A_RG_RX_DAC_MUX (0x1f << 1) +#define P3A_RG_RX_DAC_MUX_VAL (x) ((0x1f & (x)) << 1) + +#define U3P_U3PHYA_DA_REG0 (SSUSB_SIFSLV_U3PHYA_DA_BASE + 0x0) +#define P3A_RG_XTAL_EXT_EN_U3 (0x3 << 10) +#define P3A_RG_XTAL_EXT_EN_U3_VAL (x) ((0x3 & (x)) << 10) + +#define U3P_PHYD_CDR1 (SSUSB_SIFSLV_U3PHYD_BASE + 0x5c) +#define P3D_RG_CDR_BIR_LTD1 (0x1f << 24) +#define P3D_RG_CDR_BIR_LTD1_VAL (x) ((0x1f & (x)) << 24) +#define P3D_RG_CDR_BIR_LTD0 (0x1f << 8) +#define P3D_RG_CDR_BIR_LTD0_VAL (x) ((0x1f & (x)) << 8) + +#define U3P_XTALCTL3 (SSUSB_SIFSLV_SPLLC + 0x18) +#define XC3_RG_U3_XTAL_RX_PWD (0x1 << 9) +#define XC3_RG_U3_FRC_XTAL_RX_PWD (0x1 << 8) + +#define MT65XX_MAX_PHYS 2 + +struct mt65xx_phy_instance { +struct phy *phy; +u32 index; +u32 delta;/* increament refers to port0 */ +}; + +struct mt65xx_u3phy { +struct device *dev; +void __iomem *sif_base;/* include sif2 */ +struct clk *u3phya_ref;/* reference clock of usb3 anolog phy */ +struct mt65xx_phy_instance phys[MT65XX_MAX_PHYS ]; +}; + +static struct mt65xx_u3phy *to_usbdrd_phy ( +struct mt65xx_phy_instance *instance) +{ + return container_of((instance), struct mt65xx_u3phy, + phys[(instance)->index]); +} + +static void phy_instance_init (struct mt65xx_phy_instance *instance) +{ +struct mt65xx_u3phy *u3phy =to_usbdrd_phy (instance); +void __iomem *sif_base = u3phy->sif_base + instance->delta; +u32 index = instance->index; +u32 tmp; + +/* switch to USB function. (system register, force ip into usb mode) */ + tmp =readl (sif_base +U3P_U2PHYDTM0 ); + tmp &= ~P2C_FORCE_UART_EN ; +writel (tmp, sif_base +U3P_U2PHYDTM0 ); + + tmp =readl (sif_base +U3P_U2PHYDTM1 ); + tmp &= ~P2C_RG_UART_EN ; +writel (tmp, sif_base +U3P_U2PHYDTM1 ); + +if (!index) { + tmp =readl (sif_base +U3P_U2PHYACR4 ); + tmp &= ~P2C_U2_GPIO_CTR_MSK ; +writel (tmp, sif_base +U3P_U2PHYACR4 ); + } + +/* DP/DM BC1.1 path Disable */ + tmp =readl (sif_base +U3P_USBPHYACR6 ); + tmp &= ~PA6_RG_U2_BC11_SW_EN ; +writel (tmp, sif_base +U3P_USBPHYACR6 ); + + tmp =readl (sif_base +U3P_U3PHYA_DA_REG0 ); + tmp &= ~P3A_RG_XTAL_EXT_EN_U3 ; + tmp |=P3A_RG_XTAL_EXT_EN_U3_VAL (2 ); +writel (tmp, sif_base +U3P_U3PHYA_DA_REG0 ); + + tmp =readl (sif_base +U3P_U3_PHYA_REG9 ); + tmp &= ~P3A_RG_RX_DAC_MUX ; + tmp |=P3A_RG_RX_DAC_MUX_VAL (4 ); +writel (tmp, sif_base +U3P_U3_PHYA_REG9 ); + + tmp =readl (sif_base +U3P_U3_PHYA_REG6 ); + tmp &= ~P3A_RG_TX_EIDLE_CM ; + tmp |=P3A_RG_TX_EIDLE_CM_VAL (0xe ); +writel (tmp, sif_base +U3P_U3_PHYA_REG6 ); + + tmp =readl (sif_base +U3P_PHYD_CDR1 ); + tmp &= ~(P3D_RG_CDR_BIR_LTD0 |P3D_RG_CDR_BIR_LTD1 ); + tmp |=P3D_RG_CDR_BIR_LTD0_VAL (0xc ) |P3D_RG_CDR_BIR_LTD1_VAL (0x3 ); +writel (tmp, sif_base +U3P_PHYD_CDR1 ); + +dev_dbg (u3phy->dev,"%s(%d)\n" , __func__, index); +} + +static void phy_instance_power_on (struct mt65xx_phy_instance *instance) +{ +struct mt65xx_u3phy *u3phy =to_usbdrd_phy (instance); +void __iomem *sif_base = u3phy->sif_base + instance->delta; +u32 index = instance->index; +u32 tmp; + +if (!index) { +/* Set RG_SSUSB_VUSB10_ON as 1 after VUSB10 ready */ + tmp =readl (sif_base +U3P_U3_PHYA_REG0 ); + tmp |=P3A_RG_U3_VUSB10_ON ; +writel (tmp, sif_base +U3P_U3_PHYA_REG0 ); + } + +/* (force_suspendm=0) (let suspendm=1, enable usb 480MHz pll) */ + tmp =readl (sif_base +U3P_U2PHYDTM0 ); + tmp &= ~(P2C_FORCE_SUSPENDM |P2C_RG_XCVRSEL ); + tmp &= ~(P2C_RG_DATAIN |P2C_DTM0_PART_MASK ); +writel (tmp, sif_base +U3P_U2PHYDTM0 ); + +/* OTG Enable */ + tmp =readl (sif_base +U3P_USBPHYACR6 ); + tmp |=PA6_RG_U2_OTG_VBUSCMP_EN ; +writel (tmp, sif_base +U3P_USBPHYACR6 ); + +if (!index) { + tmp =readl (sif_base +U3P_XTALCTL3 ); + tmp |=XC3_RG_U3_XTAL_RX_PWD |XC3_RG_U3_FRC_XTAL_RX_PWD ; +writel (tmp, sif_base +U3P_XTALCTL3 ); +/* [mt8173]disable Change 100uA current from SSUSB */ + tmp =readl (sif_base +U3P_USBPHYACR5 ); + tmp &= ~PA5_RG_U2_HS_100U_U3_EN ; +writel (tmp, sif_base +U3P_USBPHYACR5 ); + } +udelay (800 ); + + tmp =readl (sif_base +U3P_U2PHYDTM1 ); + tmp |=P2C_RG_VBUSVALID |P2C_RG_AVALID ; + tmp &= ~P2C_RG_SESSEND ; +writel (tmp, sif_base +U3P_U2PHYDTM1 ); +/* USB 2.0 slew rate calibration */ + tmp =readl (sif_base +U3P_USBPHYACR5 ); + tmp &= ~PA5_RG_U2_HSTX_SRCTRL ; + tmp |=PA5_RG_U2_HSTX_SRCTRL_VAL (4 ); +writel (tmp, sif_base +U3P_USBPHYACR5 ); + +dev_dbg (u3phy->dev,"%s(%d)(delta: 0x%x)\n" , __func__, + index, u3phy->phys[index].delta); +} + +static void phy_instance_power_off (struct mt65xx_phy_instance *instance) +{ +struct mt65xx_u3phy *u3phy =to_usbdrd_phy (instance); +void __iomem *sif_base = u3phy->sif_base + instance->delta; +u32 index = instance->index; +u32 tmp; + + tmp =readl (sif_base +U3P_U2PHYDTM0 ); + tmp &= ~(P2C_RG_XCVRSEL |P2C_RG_DATAIN ); + tmp |=P2C_RG_XCVRSEL_VAL (1 ) |P2C_RG_DATAIN_VAL (0 ); + tmp |=P2C_FORCE_SUSPENDM ; +writel (tmp, sif_base +U3P_U2PHYDTM0 ); + +/* OTG Disable */ + tmp =readl (sif_base +U3P_USBPHYACR6 ); + tmp &= ~PA6_RG_U2_OTG_VBUSCMP_EN ; +writel (tmp, sif_base +U3P_USBPHYACR6 ); +if (!index) { +/* (also disable)Change 100uA current switch to USB2.0 */ + tmp =readl (sif_base +U3P_USBPHYACR5 ); + tmp &= ~PA5_RG_U2_HS_100U_U3_EN ; +writel (tmp, sif_base +U3P_USBPHYACR5 ); + } +udelay (800 ); + +/* let suspendm=0, set utmi into analog power down */ + tmp =readl (sif_base +U3P_U2PHYDTM0 ); + tmp &= ~P2C_RG_SUSPENDM ; +writel (tmp, sif_base +U3P_U2PHYDTM0 ); +udelay (1 ); + + tmp =readl (sif_base +U3P_U2PHYDTM1 ); + tmp &= ~(P2C_RG_VBUSVALID |P2C_RG_AVALID ); + tmp |=P2C_RG_SESSEND ; +writel (tmp, sif_base +U3P_U2PHYDTM1 ); + +if (!index) { + tmp =readl (sif_base +U3P_U3_PHYA_REG0 ); + tmp &= ~P3A_RG_U3_VUSB10_ON ; +writel (tmp, sif_base +U3P_U3_PHYA_REG0 ); + } + +dev_dbg (u3phy->dev,"%s(%d)\n" , __func__, index); +} + +static int u3phy_clk_enable (struct mt65xx_u3phy *u3phy) +{ +int ret; + + ret =clk_prepare_enable (u3phy->u3phya_ref); +if (ret) { +dev_err (u3phy->dev,"failed to enable u3phya_ref\n" ); +return ret; + } +udelay (100 ); + +return 0 ; +} + +static int mt65xx_phy_init (struct phy *phy) +{ +struct mt65xx_phy_instance *instance =phy_get_drvdata (phy); + +phy_instance_init (instance); +return 0 ; +} + +static int mt65xx_phy_power_on (struct phy *phy) +{ +struct mt65xx_phy_instance *instance =phy_get_drvdata (phy); + +phy_instance_power_on (instance); +msleep (20 ); +return 0 ; +} + +static int mt65xx_phy_power_off (struct phy *phy) +{ +struct mt65xx_phy_instance *instance =phy_get_drvdata (phy); + +phy_instance_power_off (instance); +return 0 ; +} + +static struct phy *mt65xx_phy_xlate (struct device *dev, +struct of_phandle_args *args) +{ +struct mt65xx_u3phy *u3phy =dev_get_drvdata (dev); + +if (WARN_ON (args->args[0 ] >MT65XX_MAX_PHYS )) +return ERR_PTR (-ENODEV ); + +return u3phy->phys[args->args[0 ]].phy; +} + +static struct phy_ops mt65xx_u3phy_ops = { + .init = mt65xx_phy_init, + .power_on = mt65xx_phy_power_on, + .power_off = mt65xx_phy_power_off, + .owner =THIS_MODULE , +}; + +static const struct of_device_id mt65xx_u3phy_id_table[] = { + { .compatible ="mediatek,mt8173-u3phy" ,}, + { }, +}; +MODULE_DEVICE_TABLE (of, mt65xx_u3phy_id_table); + + +static int mt65xx_u3phy_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct phy_provider *phy_provider; +struct resource *sif_res; +struct mt65xx_u3phy *u3phy; +int i; + + u3phy =devm_kzalloc (dev,sizeof (*u3phy),GFP_KERNEL ); +if (!u3phy) +return -ENOMEM ; + + u3phy->dev = dev; +platform_set_drvdata (pdev, u3phy); + + sif_res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); + u3phy->sif_base =devm_ioremap_resource (dev, sif_res); +if (IS_ERR (u3phy->sif_base)) { +dev_err (dev,"failed to remap sif regs\n" ); +return PTR_ERR (u3phy->sif_base); + } + + u3phy->u3phya_ref =devm_clk_get (dev,"u3phya_ref" ); +if (IS_ERR (u3phy->u3phya_ref)) { +dev_err (dev,"error to get u3phya_ref\n" ); +return PTR_ERR (u3phy->u3phya_ref); + } + +for (i =0 ; i <MT65XX_MAX_PHYS ; i++) { +struct mt65xx_phy_instance *instance; +struct phy *phy; + + phy =devm_phy_create (dev,NULL , &mt65xx_u3phy_ops); +if (IS_ERR (phy)) { +dev_err (dev,"failed to create mt65xx_u3phy phy\n" ); +return PTR_ERR (phy); + } + instance = &u3phy->phys[i]; + instance->phy = phy; + instance->index = i; + instance->delta =U3P_PHY_DELTA (i); +phy_set_drvdata (phy, instance); + } + + phy_provider =devm_of_phy_provider_register (dev, mt65xx_phy_xlate); +if (IS_ERR (phy_provider)) { +dev_err (dev,"Failed to register phy provider\n" ); +return PTR_ERR (phy_provider); + } + +return u3phy_clk_enable (u3phy); +} + +static int mt65xx_u3phy_remove (struct platform_device *pdev) +{ +struct mt65xx_u3phy *u3phy =platform_get_drvdata (pdev); + +clk_disable_unprepare (u3phy->u3phya_ref); + +return 0 ; +} + +static struct platform_driver mt65xx_u3phy_driver = { + .probe = mt65xx_u3phy_probe, + .remove = mt65xx_u3phy_remove, + .driver = { + .name ="mt65xx-u3phy" , + .of_match_table = mt65xx_u3phy_id_table, + }, +}; + +module_platform_driver (mt65xx_u3phy_driver); + +MODULE_DESCRIPTION ("Mt65xx USB PHY driver" ); +MODULE_LICENSE ("GPL v2" ); --1.8.1.1.dirty
_______________________________________________
Linux-mediatek mailing list
Linux-mediatek at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek
Chunfeng Yun
maintainerPATCH v3 4/5 xhci: mediatek: support MTK xHCI host controller
In reply to Chunfeng YunMTK xhci host controller defines some extra SW scheduling parameters for HW to minimize the scheduling effort for synchronous and interrupt endpoints. The parameters are put into reseved DWs of slot context and endpoint context
--- drivers/usb/host/Kconfig | 9 + drivers/usb/host/Makefile | 4 + drivers/usb/host/xhci-mtk-sch.c | 436 +++++++++++++++++++++ drivers/usb/host/xhci-mtk.c | 836 ++++++++++++++++++++++++++++++++++++++++ drivers/usb/host/xhci-mtk.h | 135 +++++++ drivers/usb/host/xhci-ring.c | 35 +- drivers/usb/host/xhci.c | 19 +- drivers/usb/host/xhci.h | 1 + 8 files changed, 1468 insertions(+), 7 deletions(-) create mode 100644 drivers/usb/host/xhci-mtk-sch.c create mode 100644 drivers/usb/host/xhci-mtk.c create mode 100644 drivers/usb/host/xhci-mtk.h
drivers/usb/host/Kconfig +9 -0
@@ -34,6 +34,15 @@ config USB_XHCI_PCI config USB_XHCI_PLATFORM tristate +config USB_XHCI_MTK + tristate "xHCI support for Mediatek MT65xx" + select MFD_SYSCON + depends on ARCH_MEDIATEK || COMPILE_TEST + ---help--- + Say 'Y' to enable the support for the xHCI host controller + found in Mediatek MT65xx SoCs. + If unsure, say N. + config USB_XHCI_MVEBU tristate "xHCI support for Marvell Armada 375/38x" select USB_XHCI_PLATFORM
drivers/usb/host/Makefile +4 -0
@@ -13,6 +13,9 @@ fhci-$(CONFIG_FHCI_DEBUG) += fhci-dbg.o xhci-hcd-y := xhci.o xhci-mem.o xhci-hcd-y += xhci-ring.o xhci-hub.o xhci-dbg.o xhci-hcd-y += xhci-trace.o +ifneq ($(CONFIG_USB_XHCI_MTK), ) + xhci-hcd-y += xhci-mtk-sch.o +endif xhci-plat-hcd-y := xhci-plat.o ifneq ($(CONFIG_USB_XHCI_MVEBU), )
@@ -30,6 +33,7 @@ endif obj-$(CONFIG_USB_XHCI_PCI) += xhci-pci.o obj-$(CONFIG_USB_XHCI_PLATFORM) += xhci-plat-hcd.o +obj-$(CONFIG_USB_XHCI_MTK) += xhci-mtk.o obj-$(CONFIG_USB_EHCI_HCD) += ehci-hcd.o obj-$(CONFIG_USB_EHCI_PCI) += ehci-pci.o
drivers/usb/host/xhci-mtk-sch.c new file +436 -0
436 lines not on this page · raw message
drivers/usb/host/xhci-mtk.c new file +836 -0
836 lines not on this page · raw message
drivers/usb/host/xhci-mtk.h new file +135 -0
135 lines not on this page · raw message
drivers/usb/host/xhci-ring.c +29 -6
@@ -68,6 +68,7 @@#include <linux/slab.h> #include "xhci.h" #include "xhci-trace.h" +#include "xhci-mtk.h" /* * Returns zero if the TRB isn't in this segment, otherwise it returns the DMA
@@ -3131,9 +3132,14 @@ static int queue_bulk_sg_tx(struct xhci_hcd *xhci, gfp_t mem_flags,/* Set the TRB length, TD size, and interrupter fields. */ if (xhci->hci_version <0x100 ) { - remainder =xhci_td_remainder ( +if (xhci->quirks &XHCI_MTK_HOST ) { + remainder =xhci_mtk_td_remainder_quirk ( + running_total, trb_buff_len, urb); + }else { + remainder =xhci_td_remainder ( urb->transfer_buffer_length - running_total); + } }else { remainder = xhci_v1_0_td_remainder(running_total, trb_buff_len, total_packet_count, urb,
@@ -3286,9 +3292,14 @@ int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags,/* Set the TRB length, TD size, and interrupter fields. */ if (xhci->hci_version <0x100 ) { - remainder =xhci_td_remainder ( +if (xhci->quirks &XHCI_MTK_HOST ) { + remainder =xhci_mtk_td_remainder_quirk ( + running_total, trb_buff_len, urb); + }else { + remainder =xhci_td_remainder ( urb->transfer_buffer_length - running_total); + } }else { remainder = xhci_v1_0_td_remainder(running_total, trb_buff_len, total_packet_count, urb,
@@ -3383,7 +3394,7 @@ int xhci_queue_ctrl_tx(struct xhci_hcd *xhci, gfp_t mem_flags, field |=0x1 ;/* xHCI 1.0 6.4.1.2.1: Transfer Type field */ -if (xhci->hci_version ==0x100 ) { +if ((xhci->hci_version ==0x100 ) || (xhci->quirks &XHCI_MTK_HOST )) {if (urb->transfer_buffer_length >0 ) {if (setup->bRequestType &USB_DIR_IN ) field |=TRB_TX_TYPE (TRB_DATA_IN );
@@ -3407,8 +3418,14 @@ int xhci_queue_ctrl_tx(struct xhci_hcd *xhci, gfp_t mem_flags, field =TRB_TYPE (TRB_DATA ); length_field =TRB_LEN (urb->transfer_buffer_length) | -xhci_td_remainder (urb->transfer_buffer_length) |TRB_INTR_TARGET (0 ); + +if (xhci->quirks &XHCI_MTK_HOST ) + length_field |=xhci_mtk_td_remainder_quirk (0 , + urb->transfer_buffer_length, urb); +else + length_field |=xhci_td_remainder (urb->transfer_buffer_length); +if (urb->transfer_buffer_length >0 ) {if (setup->bRequestType &USB_DIR_IN ) field |=TRB_DIR_IN ;
@@ -3632,8 +3649,14 @@ static int xhci_queue_isoc_tx(struct xhci_hcd *xhci, gfp_t mem_flags,/* Set the TRB length, TD size, & interrupter fields. */ if (xhci->hci_version <0x100 ) { - remainder =xhci_td_remainder ( - td_len - running_total); +if (xhci->quirks &XHCI_MTK_HOST ) { + remainder =xhci_mtk_td_remainder_quirk ( + running_total, trb_buff_len, + urb); + }else { + remainder =xhci_td_remainder ( + td_len - running_total); + } }else { remainder = xhci_v1_0_td_remainder( running_total, trb_buff_len,
drivers/usb/host/xhci.c +18 -1
@@ -31,6 +31,7 @@#include "xhci.h" #include "xhci-trace.h" +#include "xhci-mtk.h" #define DRIVER_AUTHOR "Sarah Sharp"#define DRIVER_DESC "'eXtensible' Host Controller (xHC) Driver"
@@ -623,7 +624,11 @@ int xhci_run(struct usb_hcd *hcd) "// Set the interrupt modulation register"); temp =readl (&xhci->ir_set->irq_control); temp &= ~ER_IRQ_INTERVAL_MASK ; - temp |= (u32 )160 ; +/* +* the increment interval is 8 times as much as that defined +* in xHCI spec on MTK's controller +*/ + temp |= (u32) ((xhci->quirks &XHCI_MTK_HOST ) ?20 :160 );writel (temp, &xhci->ir_set->irq_control);/* Set the HCD state before we enable the irqs */
@@ -1688,6 +1693,9 @@ int xhci_drop_endpoint(struct usb_hcd *hcd, struct usb_device *udev,xhci_endpoint_zero (xhci, xhci->devs[udev->slot_id], ep); +if (xhci->quirks &XHCI_MTK_HOST ) +xhci_mtk_drop_ep_quirk (hcd, udev, ep); + xhci_dbg(xhci, "drop ep 0x%x, slot id %d, new drop flags = %#x, new add flags = %#x\n", (unsigned int) ep->desc.bEndpointAddress, udev->slot_id,
@@ -1783,6 +1791,15 @@ int xhci_add_endpoint(struct usb_hcd *hcd, struct usb_device *udev,return -ENOMEM ; } +if (xhci->quirks &XHCI_MTK_HOST ) { + ret =xhci_mtk_add_ep_quirk (hcd, udev, ep); +if (ret <0 ) { +xhci_free_or_cache_endpoint_ring (xhci, + virt_dev, ep_index); +return ret; + } + } + ctrl_ctx->add_flags |=cpu_to_le32 (added_ctxs); new_add_flags =le32_to_cpu (ctrl_ctx->add_flags);
drivers/usb/host/xhci.h +1 -0
@@ -1567,6 +1567,7 @@ struct xhci_hcd {/* For controllers with a broken beyond repair streams implementation */ #define XHCI_BROKEN_STREAMS (1 << 19)#define XHCI_PME_STUCK_QUIRK (1 << 20) +#define XHCI_MTK_HOST (1 << 21)unsigned int num_active_eps;unsigned int limit_active_eps;/* There are two roothubs to keep track of bus suspend info for */
Signature · 1 line
1.8.1.1.dirty
Chunfeng Yun
maintainerPATCH v3 5/5 arm64: dts: mediatek: add xHCI & usb phy for mt8173
In reply to Chunfeng Yunadd xHCI and phy drivers for MT8173-EVB
--- arch/arm64/boot/dts/mediatek/mt8173-evb.dts | 15 ++++++++++++++ arch/arm64/boot/dts/mediatek/mt8173.dtsi | 31 +++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+)
arch/arm64/boot/dts/mediatek/mt8173-evb.dts +15 -0
@@ -13,6 +13,7 @@ */ /dts-v1/; +#include <dt-bindings/gpio/gpio.h> #include "mt8173.dtsi" / {
@@ -32,6 +33,15 @@ }; chosen { }; + + usb_p1_vbus: fixedregulator at 0 { + compatible = "regulator-fixed"; + regulator-name = "usb_vbus"; + regulator-min-microvolt = <5000000>; + regulator-max-microvolt = <5000000>; + gpio = <&pio 130 GPIO_ACTIVE_HIGH>; + enable-active-high; + }; }; &pwrap {
@@ -211,3 +221,8 @@ &uart0 { status = "okay"; }; + +&usb { + vusb33-supply = <&mt6397_vusb_reg>; + vbus-supply = <&usb_p1_vbus>; +};
arch/arm64/boot/dts/mediatek/mt8173.dtsi +31 -0
@@ -14,6 +14,7 @@ #include <dt-bindings/clock/mt8173-clk.h> #include <dt-bindings/interrupt-controller/irq.h> #include <dt-bindings/interrupt-controller/arm-gic.h> +#include <dt-bindings/power/mt8173-power.h> #include <dt-bindings/reset-controller/mt8173-resets.h> #include "mt8173-pinfunc.h"
@@ -393,6 +394,36 @@ #size-cells = <0>; status = "disabled"; }; + + usb: usb30 at 11270000 { + compatible = "mediatek,mt8173-xhci"; + reg = <0 0x11270000 0 0x4000>, + <0 0x11280000 0 0x0800>; + interrupts = <GIC_SPI 115 IRQ_TYPE_LEVEL_LOW>; + power-domains = <&scpsys MT8173_POWER_DOMAIN_USB>; + clocks = <&topckgen CLK_TOP_USB30_SEL>, + <&pericfg CLK_PERI_USB0>, + <&pericfg CLK_PERI_USB1>; + clock-names = "sys_mac", + "wakeup_deb_p0", + "wakeup_deb_p1"; + phys = <&u3phy 0>, <&u3phy 1>; + phy-names = "phy-0", "phy-1"; + usb3-lpm-capable; + mediatek,usb-wakeup = <&pericfg>; + mediatek,wakeup-src = <1>; + mediatek,u2port-num = <2>; + status = "okay"; + }; + + u3phy: usb-phy at 11290000 { + compatible = "mediatek,mt8173-u3phy"; + reg = <0 0x11290000 0 0x3000>; + clocks = <&apmixedsys CLK_APMIXED_REF2USB_TX>; + clock-names = "u3phya_ref"; + #phy-cells = <1>; + status = "okay"; + }; }; };
Signature · 1 line
1.8.1.1.dirty
Re: [PATCH v3 5/5] arm64: dts: mediatek: add xHCI & usb phy for mt8173
Hello.
Quoted 21 lines · Chunfeng Yun
add xHCI and phy drivers for MT8173-EVB
Signed-off-by Chunfeng Yun <[email protected]>--- arch/arm64/boot/dts/mediatek/mt8173-evb.dts | 15 ++++++++++++++ arch/arm64/boot/dts/mediatek/mt8173.dtsi | 31 +++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+)arch/arm64/boot/dts/mediatek/mt8173-evb.dts +1
-0@@ -13,6 +13,7 @@ */ /dts-v1/; +#include <dt-bindings/gpio/gpio.h> #include "mt8173.dtsi" / {
arch/arm64/boot/dts/mediatek/mt8173-evb.dts line 37
Quoted 5 lines
arch/arm64/boot/dts/mediatek/mt8173-evb.dts +2
-0@@ -32,6 +33,15 @@ }; chosen { }; + + usb_p1_vbus: fixedregulator at 0 {
Just "regulator at 0" please. This is more in line with what ePAPR requires
from the node names.
Quoted 10 lines
arch/arm64/boot/dts/mediatek/mt8173-evb.dts +7
-0+ compatible = "regulator-fixed"; + regulator-name = "usb_vbus"; + regulator-min-microvolt = <5000000>; + regulator-max-microvolt = <5000000>; + gpio = <&pio 130 GPIO_ACTIVE_HIGH>; + enable-active-high; + }; }; &pwrap {
[...]
Quoted 4 lines
arch/arm64/boot/dts/mediatek/mt8173.dtsi +0
-0
[...]
arch/arm64/boot/dts/mediatek/mt8173.dtsi line 398
Quoted 6 lines
arch/arm64/boot/dts/mediatek/mt8173.dtsi +2
-0@@ -393,6 +394,36 @@ #size-cells = <0>; status = "disabled"; }; + + usb: usb30 at 11270000 {
ePAPR standardizes the name "usb" for such nodes, please fix.
[...]
MBR, Sergei
chunfeng yun
maintainerRe: [PATCH v3 5/5] arm64: dts: mediatek: add xHCI & usb phy for mt8173
hi
Quoted 59 lines · Sergei Shtylyov
Hello.
Quoted 21 lines · Chunfeng Yun
add xHCI and phy drivers for MT8173-EVB
Signed-off-by Chunfeng Yun <[email protected]>--- arch/arm64/boot/dts/mediatek/mt8173-evb.dts | 15 ++++++++++++++ arch/arm64/boot/dts/mediatek/mt8173.dtsi | 31 +++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+)arch/arm64/boot/dts/mediatek/mt8173-evb.dts +1
-0@@ -13,6 +13,7 @@ */ /dts-v1/; +#include <dt-bindings/gpio/gpio.h> #include "mt8173.dtsi" / {arch/arm64/boot/dts/mediatek/mt8173-evb.dts line 37
Quoted 5 lines
arch/arm64/boot/dts/mediatek/mt8173-evb.dts +2
-0@@ -32,6 +33,15 @@ }; chosen { }; + + usb_p1_vbus: fixedregulator at 0 {Just "regulator at 0" please. This is more in line with what ePAPR requires
from the node names.Quoted 10 lines
arch/arm64/boot/dts/mediatek/mt8173-evb.dts +7
-0+ compatible = "regulator-fixed"; + regulator-name = "usb_vbus"; + regulator-min-microvolt = <5000000>; + regulator-max-microvolt = <5000000>; + gpio = <&pio 130 GPIO_ACTIVE_HIGH>; + enable-active-high; + }; }; &pwrap {[...]
Quoted 4 lines
arch/arm64/boot/dts/mediatek/mt8173.dtsi +0
-0[...]
arch/arm64/boot/dts/mediatek/mt8173.dtsi line 398
Quoted 6 lines
arch/arm64/boot/dts/mediatek/mt8173.dtsi +2
-0@@ -393,6 +394,36 @@ #size-cells = <0>; status = "disabled"; }; + + usb: usb30 at 11270000 {ePAPR standardizes the name "usb" for such nodes, please fix.
Quoted 2 lines
[...]
ok, I'll revise it, thanks a lot
Quoted 2 lines
MBR, Sergei
chunfeng yun
maintainerRe: [PATCH v3 0/5] Mediatek xHCI support
In reply to Chunfeng YunSorry, add a title
Quoted 67 lines · Chunfeng Yun
From
ac1e8724bfa47494223bad0af450c1a63cd2fe0cMon Sep 17 00:00:00 2001
From: Chunfeng Yun <[email protected]>
Date: Wed, 22 Jul 2015 21:15:15 +0800
Subject: [PATCH 0/5] *** SUBJECT HERE ***The patch supports MediaTek's xHCI controller.
There are some differences from xHCI spec:
1. The interval is specified in 250 * 8ns increments for Interrupt Moderation Interval(IMODI) of the Interrupter Moderation(IMOD) register, it is 8 times as much as that defined in xHCI spec.2. For the value of TD Size in Normal TRB, MTK's xHCI controller defines a number of packets that remain to be transferred for a TD after processing all Max packets in all previous TRBs,that means don't include the current TRB's, but in xHCI spec it includes the current ones.
3. To minimize the scheduling effort for synchronous endpoints in xHC, the MTK architecture defines some extra SW scheduling parameters for HW. According to these parameters provided by SW, the xHC can easily decide whether a synchronous endpoint should be scheduled in a specific uFrame. The extra SW scheduling parameters are put into reserved DWs in Slot and Endpoint Context. And a bandwidth scheduler algorithm is added to support such feature.
A usb3.0 phy driver is also added which used by mt65xx SoCs platform, it supports two usb2.0 ports and one usb3.0 port.
Change in v3:
1. implement generic phy
2. move opperations for IPPC and wakeup from phy driver to xHCI driver
3. seperate quirk functions into a single C file to fix up dependence issueChunfeng Yun (5):
dt-bindings: Add usb3.0 phy binding for MT65xx SoCs
dt-bindings: Add a binding for Mediatek xHCI host controller
usb: phy: add usb3.0 phy driver for mt65xx SoCs
xhci: mediatek: support MTK xHCI host controller
arm64: dts: mediatek: add xHCI & usb phy for mt8173.../devicetree/bindings/phy/phy-mt65xx-u3.txt | 21 + .../devicetree/bindings/usb/mt8173-xhci.txt | 50 ++ arch/arm64/boot/dts/mediatek/mt8173-evb.dts | 15 + arch/arm64/boot/dts/mediatek/mt8173.dtsi | 31 + drivers/phy/Kconfig | 9 + drivers/phy/Makefile | 1 + drivers/phy/phy-mt65xx-usb3.c | 426 +++++++++++ drivers/usb/host/Kconfig | 9 + drivers/usb/host/Makefile | 4 + drivers/usb/host/xhci-mtk-sch.c | 436 +++++++++++ drivers/usb/host/xhci-mtk.c | 836 +++++++++++++++++++++ drivers/usb/host/xhci-mtk.h | 135 ++++ drivers/usb/host/xhci-ring.c | 35 +- drivers/usb/host/xhci.c | 19 +- drivers/usb/host/xhci.h | 1 + 15 files changed, 2021 insertions(+), 7 deletions(-) create mode 100644 Documentation/devicetree/bindings/phy/phy-mt65xx-u3.txt create mode 100644 Documentation/devicetree/bindings/usb/mt8173-xhci.txt create mode 100644 drivers/phy/phy-mt65xx-usb3.c create mode 100644 drivers/usb/host/xhci-mtk-sch.c create mode 100644 drivers/usb/host/xhci-mtk.c create mode 100644 drivers/usb/host/xhci-mtk.h--
1.8.1.1.dirtyIn-Reply-To: