Add mt7988 XS-PHY
cover Add mt7988 XS-PHY
From: Frank Wunderlich <[email protected]>
Mediatek XS-Phy is a high speed phy used for pcie and usb on mt7988 platform.
It requires a topmisc power controller to switch between USB and PCI mode. This topmisc system controller is also used by ethernet-node which is not upstreamed yet.
---
regading syscon-fallback...i know that it should be avoided ;)
based on these commits:
ba5095ebbc7a ("mfd: syscon: Allow syscon nodes without a "syscon" compatible") 5728c92ae112 ("mfd: syscon: Restore device_node_to_regmap() for non-syscon nodes")
I tried to get it working without syscon by changing
instance->type_sw = syscon_node_to_regmap(args.np); todevice_node_to_regmap()
then xsphy was probed sucessfully, but all pcie (not only the one with xsphy) stopped working.
for ethernet its driver uses syscon_regmap_lookup_by_phandle which needs to be patched in syscon driver to also use device_node_to_regmap instead of syscon_node_to_regmap (with create=true). But have not tried this.
regarding the pcie issue when dropping the syscon compatible i would leave this compatible, but send this patchset as RFC. Maybe anyone can solve this.
Daniel Golle (1):
phy: mediatek: xsphy: support type switch by pericfg
Frank Wunderlich (4):
dt-bindings: phy: mtk-xs-phy: Add mt7988 compatible
dt-bindings: phy: mtk-xs-phy: support type switch by pericfg
dt-bindings: power: Add binding for MediaTek MT7988 topmisc power
controller
arm64: dts: mediatek: mt7988: Add xsphy for ssusb0/pcie2
.../bindings/phy/mediatek,xsphy.yaml | 17 ++++ .../power/mediatek,power-controller.yaml | 35 +++++--- arch/arm64/boot/dts/mediatek/mt7988a.dtsi | 39 +++++++++ drivers/phy/mediatek/phy-mtk-xsphy.c | 85 ++++++++++++++++++- 4 files changed, 164 insertions(+), 12 deletions(-)
Signature · 1 line
2.43.0
RFC 1/5 dt-bindings: phy: mtk-xs-phy: Add mt7988 compatible
From: Frank Wunderlich <[email protected]>
Add compatible for xs-phy on mt7988.
--- Documentation/devicetree/bindings/phy/mediatek,xsphy.yaml | 1 + 1 file changed, 1 insertion(+)
Documentation/devicetree/bindings/phy/mediatek,xsphy.yaml +1 -0
@@ -49,6 +49,7 @@ properties: - enum: - mediatek,mt3611-xsphy - mediatek,mt3612-xsphy + - mediatek,mt7988-xsphy - const: mediatek,xsphy reg:
Signature · 7 lines
2.43.0 -- linux-phy mailing list [email protected] https://lists.infradead.org/mailman/listinfo/linux-phy
RFC 2/5 dt-bindings: phy: mtk-xs-phy: support type switch by pericfg
In reply to Frank WunderlichFrom: Frank Wunderlich <[email protected]>
Add support for type switch by pericfg register between USB3, PCIe, ...
--- .../devicetree/bindings/phy/mediatek,xsphy.yaml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
Documentation/devicetree/bindings/phy/mediatek,xsphy.yaml +16 -0
@@ -151,6 +151,22 @@ patternProperties: minimum: 1 maximum: 31 + mediatek,syscon-type: + $ref: /schemas/types.yaml#/definitions/phandle-array + maxItems: 1 + description: + A phandle to syscon used to access the register of type switch, + the field should always be 3 cells long. + items: + items: + - description: + The first cell represents a phandle to syscon + - description: + The second cell represents the register offset + - description: + The third cell represents the index of config segment + enum: [0, 1, 2, 3] + required: - reg - clocks
Signature · 1 line
2.43.0
RFC 3/5 dt-bindings: power: Add binding for MediaTek MT7988 topmisc power controller
In reply to Frank WunderlichFrom: Frank Wunderlich <[email protected]>
Topmisc is a systemcontroller used for xs-phy and ethernet on mt7988. Add binding for it.
--- .../power/mediatek,power-controller.yaml | 35 +++++++++++++------ 1 file changed, 24 insertions(+), 11 deletions(-)
Documentation/devicetree/bindings/power/mediatek,power-controller.yaml +24 -11
@@ -22,17 +22,27 @@ properties: pattern: '^power-controller(@[0-9a-f]+)?$' compatible: - enum: - - mediatek,mt6735-power-controller - - mediatek,mt6795-power-controller - - mediatek,mt8167-power-controller - - mediatek,mt8173-power-controller - - mediatek,mt8183-power-controller - - mediatek,mt8186-power-controller - - mediatek,mt8188-power-controller - - mediatek,mt8192-power-controller - - mediatek,mt8195-power-controller - - mediatek,mt8365-power-controller + oneOf: + - items: + - enum: + - mediatek,mt6735-power-controller + - mediatek,mt6795-power-controller + - mediatek,mt8167-power-controller + - mediatek,mt8173-power-controller + - mediatek,mt8183-power-controller + - mediatek,mt8186-power-controller + - mediatek,mt8188-power-controller + - mediatek,mt8192-power-controller + - mediatek,mt8195-power-controller + - mediatek,mt8365-power-controller + - items: + - enum: + - mediatek,mt7988-topmisc + - const: syscon + - const: mediatek,mt7988-power-controller + + reg: + maxItems: 1 '#power-domain-cells': const: 1
@@ -43,6 +53,9 @@ properties: '#size-cells': const: 0 + '#clock-cells': + const: 1 + patternProperties: "^power-domain@[0-9a-f]+$": $ref: "#/$defs/power-domain-node"
Signature · 1 line
2.43.0
Rob Herring (Arm)
maintainerRe: [RFC 3/5] dt-bindings: power: Add binding for MediaTek MT7988 topmisc power controller
Quoted 10 lines · Frank Wunderlich
From: Frank Wunderlich <[email protected]>
Topmisc is a systemcontroller used for xs-phy and ethernet on mt7988. Add binding for it.
Signed-off-by Frank Wunderlich <[email protected]>--- .../power/mediatek,power-controller.yaml | 35 +++++++++++++------ 1 file changed, 24 insertions(+), 11 deletions(-)
My bot found errors running 'make dt_binding_check' on your patch:
yamllint warnings/errors:./Documentation/devicetree/bindings/power/mediatek,power-controller.yaml:27:9: [warning] wrong indentation: expected 10 but found 8 (indentation) ./Documentation/devicetree/bindings/power/mediatek,power-controller.yaml:28:11: [warning] wrong indentation: expected 12 but found 10 (indentation) ./Documentation/devicetree/bindings/power/mediatek,power-controller.yaml:39:9: [warning] wrong indentation: expected 10 but found 8 (indentation) ./Documentation/devicetree/bindings/power/mediatek,power-controller.yaml:40:11: [warning] wrong indentation: expected 12 but found 10 (indentation)
dtschema/dtc warnings/errors:
doc reference errors (make refcheckdocs):
See https://patchwork.ozlabs.org/project/devicetree-bindings/patch/[email protected]
The base for the series is generally the latest rc1. A different dependency should be noted in *this* patch.
If you already ran 'make dt_binding_check' and didn't see the above error(s), then make sure 'yamllint' is installed and dt-schema is up to date:
pip3 install dtschema --upgrade
Please check and re-submit after running the above command yourself. Note that DT_SCHEMA_FILES can be set to your schema file to speed up checking your schema. However, it must be unset to test all examples with your schema.
AngeloGioacchino Del Regno
maintainerRe: [RFC 3/5] dt-bindings: power: Add binding for MediaTek MT7988 topmisc power controller
In reply to Frank WunderlichIl 13/04/25 10:58, Frank Wunderlich ha scritto:
Quoted 4 lines
From: Frank Wunderlich <[email protected]>
Topmisc is a systemcontroller used for xs-phy and ethernet on mt7988. Add binding for it.
That's the wrong binding... check mfd/syscon.yaml :-)
P.S.: Is there any reset controller in topmisc? Any clock?
If yes, syscon.yaml is also wrong, and you need a driver for that.
Remember: If it turns out *later* that this has clk/resets and the bindings are already set for just a syscon, it's gonna be way harder!
Cheers,
Angelo
Quoted 59 lines
Signed-off-by Frank Wunderlich <[email protected]>--- .../power/mediatek,power-controller.yaml | 35 +++++++++++++------ 1 file changed, 24 insertions(+), 11 deletions(-)Documentation/devicetree/bindings/power/mediatek,power-controller.yaml +24
-11@@ -22,17 +22,27 @@ properties: pattern: '^power-controller(@[0-9a-f]+)?$' compatible: - enum: - - mediatek,mt6735-power-controller - - mediatek,mt6795-power-controller - - mediatek,mt8167-power-controller - - mediatek,mt8173-power-controller - - mediatek,mt8183-power-controller - - mediatek,mt8186-power-controller - - mediatek,mt8188-power-controller - - mediatek,mt8192-power-controller - - mediatek,mt8195-power-controller - - mediatek,mt8365-power-controller + oneOf: + - items: + - enum: + - mediatek,mt6735-power-controller + - mediatek,mt6795-power-controller + - mediatek,mt8167-power-controller + - mediatek,mt8173-power-controller + - mediatek,mt8183-power-controller + - mediatek,mt8186-power-controller + - mediatek,mt8188-power-controller + - mediatek,mt8192-power-controller + - mediatek,mt8195-power-controller + - mediatek,mt8365-power-controller + - items: + - enum: + - mediatek,mt7988-topmisc + - const: syscon + - const: mediatek,mt7988-power-controller + + reg: + maxItems: 1 '#power-domain-cells': const: 1@@ -43,6 +53,9 @@ properties: '#size-cells': const: 0 + '#clock-cells': + const: 1 + patternProperties: "^power-domain@[0-9a-f]+$": $ref: "#/$defs/power-domain-node"
Re: [RFC 3/5] dt-bindings: power: Add binding for MediaTek MT7988 topmisc power controller
Hi Angelo,
Am 14. April 2025 12:25:23 MESZ schrieb AngeloGioacchino Del Regno <[email protected]>:
Quoted 8 lines
Il 13/04/25 10:58, Frank Wunderlich ha scritto:
Quoted 4 lines
From: Frank Wunderlich <[email protected]>
Topmisc is a systemcontroller used for xs-phy and ethernet on mt7988. Add binding for it.
That's the wrong binding... check
mfd/syscon.yaml:-)
Quoted 7 lines
P.S.: Is there any reset controller in topmisc? Any clock?
If yes,syscon.yamlis also wrong, and you need a driver for that.
Remember: If it turns out *later* that this has clk/resets and the bindings are already set for just a syscon, it's gonna be way harder!Cheers,
Angelo
Ok based on the power-domain-cells property i guessed powercontroller is the right place.
But based on your suggestion i tried moving compatible to syscon binding and made dtbs_check here.
I can confirm dropping the unexpected properties reported by syscon binding (power-domain-cells,clock-cells,adress-cells and size-cells) are not needed for function (xsphy and ethernet).
For verifying that there are really no clocks/resets in topmisc (have not found it in public available register documents) i asked mtk (waiting for answer).
Also got it working without the syscon compatible by changing ethernet driver too (after this change xsphy was also working).
Eth:
https://github.com/frank-w/BPI-Router-Linux/commit/d866e648717800b6f6395ad36c38f9effcf0498d
Xsphy:
<https://github.com/frank-w/BPI-Router-Linux/commit/0121a94df99700487704ca056b210b13db07e90c>
regards Frank
AngeloGioacchino Del Regno
maintainerRe: [RFC 3/5] dt-bindings: power: Add binding for MediaTek MT7988 topmisc power controller
Il 15/04/25 11:52, Frank Wunderlich ha scritto:
Quoted 16 lines
Hi Angelo,
Am 14. April 2025 12:25:23 MESZ schrieb AngeloGioacchino Del Regno <[email protected]>:
Quoted 13 lines
Il 13/04/25 10:58, Frank Wunderlich ha scritto:
Quoted 4 lines
From: Frank Wunderlich <[email protected]>
Topmisc is a systemcontroller used for xs-phy and ethernet on mt7988. Add binding for it.
That's the wrong binding... check
mfd/syscon.yaml:-)
P.S.: Is there any reset controller in topmisc? Any clock?
If yes,syscon.yamlis also wrong, and you need a driver for that.
Remember: If it turns out *later* that this has clk/resets and the bindings are already set for just a syscon, it's gonna be way harder!
Quoted 4 lines
Quoted 2 lines
Cheers,
AngeloOk based on the power-domain-cells property i guessed powercontroller is the right place.
power-domain-cells, but without any power domain assignment, so that was wrong :)))
Quoted 8 lines
But based on your suggestion i tried moving compatible to syscon binding and made
dtbs_checkhere.I can confirm dropping the unexpected properties reported by syscon binding (power-domain-cells,clock-cells,adress-cells and size-cells) are not needed for function (xsphy and ethernet).
For verifying that there are really no clocks/resets in topmisc (have not found it in public available register documents) i asked mtk (waiting for answer).
Also got it working without the syscon compatible by changing ethernet driver too (after this change xsphy was also working).
Perfect, a bit of a cleanup and you're done, then!
Cheers!
Re: [RFC 3/5] dt-bindings: power: Add binding for MediaTek MT7988 topmisc power controller
Am 15. April 2025 11:59:06 MESZ schrieb AngeloGioacchino Del Regno <[email protected]>:
Quoted 27 lines
Il 15/04/25 11:52, Frank Wunderlich ha scritto:
Quoted 16 lines
Hi Angelo,
Am 14. April 2025 12:25:23 MESZ schrieb AngeloGioacchino Del Regno <[email protected]>:
Quoted 13 lines
Il 13/04/25 10:58, Frank Wunderlich ha scritto:
Quoted 4 lines
From: Frank Wunderlich <[email protected]>
Topmisc is a systemcontroller used for xs-phy and ethernet on mt7988. Add binding for it.
That's the wrong binding... check
mfd/syscon.yaml:-)
P.S.: Is there any reset controller in topmisc? Any clock?
If yes,syscon.yamlis also wrong, and you need a driver for that.
Remember: If it turns out *later* that this has clk/resets and the bindings are already set for just a syscon, it's gonna be way harder!Quoted 4 lines
Quoted 2 lines
Cheers,
AngeloOk based on the power-domain-cells property i guessed powercontroller is the right place.
power-domain-cells, but without any power domain assignment, so that was wrong :)))
Quoted 3 lines
But based on your suggestion i tried moving compatible to syscon binding and made
dtbs_checkhere.
Quoted 7 lines
Quoted 5 lines
I can confirm dropping the unexpected properties reported by syscon binding (power-domain-cells,clock-cells,adress-cells and size-cells) are not needed for function (xsphy and ethernet).
For verifying that there are really no clocks/resets in topmisc (have not found it in public available register documents) i asked mtk (waiting for answer).
Also got it working without the syscon compatible by changing ethernet driver too (after this change xsphy was also working).
Perfect, a bit of a cleanup and you're done, then!
If i do not have to change/merge driver code...and i hope getting response from mtk soon.
Quoted 12 lines
Cheers!
regards Frank
Re: [RFC 3/5] dt-bindings: power: Add binding for MediaTek MT7988 topmisc power controller
In reply to AngeloGioacchino Del RegnoAm 15. April 2025 11:59:06 MESZ schrieb AngeloGioacchino Del Regno <[email protected]>:
Quoted 29 lines
Il 15/04/25 11:52, Frank Wunderlich ha scritto:
Quoted 16 lines
Hi Angelo,
Am 14. April 2025 12:25:23 MESZ schrieb AngeloGioacchino Del Regno <[email protected]>:
Quoted 13 lines
Il 13/04/25 10:58, Frank Wunderlich ha scritto:
Quoted 4 lines
From: Frank Wunderlich <[email protected]>
Topmisc is a systemcontroller used for xs-phy and ethernet on mt7988. Add binding for it.
That's the wrong binding... check
mfd/syscon.yaml:-)
P.S.: Is there any reset controller in topmisc? Any clock?
If yes,syscon.yamlis also wrong, and you need a driver for that.
Remember: If it turns out *later* that this has clk/resets and the bindings are already set for just a syscon, it's gonna be way harder!Quoted 4 lines
Quoted 2 lines
Cheers,
AngeloOk based on the power-domain-cells property i guessed powercontroller is the right place.
power-domain-cells, but without any power domain assignment, so that was wrong :)))
Quoted 5 lines
But based on your suggestion i tried moving compatible to syscon binding and made
dtbs_checkhere.I can confirm dropping the unexpected properties reported by syscon binding (power-domain-cells,clock-cells,adress-cells and size-cells) are not needed for function (xsphy and ethernet).
Quoted 18 lines
Quoted 3 lines
For verifying that there are really no clocks/resets in topmisc (have not found it in public available register documents) i asked mtk (waiting for answer).
Also got it working without the syscon compatible by changing ethernet driver too (after this change xsphy was also working).
Perfect, a bit of a cleanup and you're done, then!
Cheers!
Got response from MTK and basicly topmisc contains a powercontroller (for cpu and internal 2g5) but currently not needed because ATF already switch this on. The second part is the pcs/phy muxing and 3rd some unneeded switches (where i have no detailed information). But no clocks or resets as these are handled in the connected platform driver (xsphy/ethernet).
So my original binding imho made more sense.
The syscon binding seems to need syscon fallback and shows error about unexpected "compatible" property. The binding itself does not contain any properties but references syscon-common where iiuc compatible property must have at least 2 items and requires the "syscon" fallback.
Mtk suggests splitting topmisc into the 2 blocks by only using the mux part as syscon with splitting the reg. If powerdomain really is needed then a second topmisc node could be added and bound to a new driver.
But this would need a bit more of testing.
regards Frank
AngeloGioacchino Del Regno
maintainerRe: [RFC 3/5] dt-bindings: power: Add binding for MediaTek MT7988 topmisc power controller
Il 15/04/25 16:03, Frank Wunderlich ha scritto:
Quoted 49 lines
Am 15. April 2025 11:59:06 MESZ schrieb AngeloGioacchino Del Regno <[email protected]>:
Quoted 29 lines
Il 15/04/25 11:52, Frank Wunderlich ha scritto:
Quoted 16 lines
Hi Angelo,
Am 14. April 2025 12:25:23 MESZ schrieb AngeloGioacchino Del Regno <[email protected]>:
Quoted 13 lines
Il 13/04/25 10:58, Frank Wunderlich ha scritto:
Quoted 4 lines
From: Frank Wunderlich <[email protected]>
Topmisc is a systemcontroller used for xs-phy and ethernet on mt7988. Add binding for it.
That's the wrong binding... check
mfd/syscon.yaml:-)
P.S.: Is there any reset controller in topmisc? Any clock?
If yes,syscon.yamlis also wrong, and you need a driver for that.
Remember: If it turns out *later* that this has clk/resets and the bindings are already set for just a syscon, it's gonna be way harder!Quoted 4 lines
Quoted 2 lines
Cheers,
AngeloOk based on the power-domain-cells property i guessed powercontroller is the right place.
power-domain-cells, but without any power domain assignment, so that was wrong :)))
Quoted 5 lines
But based on your suggestion i tried moving compatible to syscon binding and made
dtbs_checkhere.I can confirm dropping the unexpected properties reported by syscon binding (power-domain-cells,clock-cells,adress-cells and size-cells) are not needed for function (xsphy and ethernet).
Quoted 18 lines
Quoted 3 lines
For verifying that there are really no clocks/resets in topmisc (have not found it in public available register documents) i asked mtk (waiting for answer).
Also got it working without the syscon compatible by changing ethernet driver too (after this change xsphy was also working).
Perfect, a bit of a cleanup and you're done, then!
Cheers!
Quoted 8 lines
Got response from MTK and basicly topmisc contains a powercontroller (for cpu and internal 2g5) but currently not needed because ATF already switch this on. The second part is the pcs/phy muxing and 3rd some unneeded switches (where i have no detailed information). But no clocks or resets as these are handled in the connected platform driver (xsphy/ethernet).
So my original binding imho made more sense.
The syscon binding seems to need syscon fallback and shows error about unexpected "compatible" property. The binding itself does not contain any properties but references syscon-common where iiuc compatible property must have at least 2 items and requires the "syscon" fallback.
Mtk suggests splitting topmisc into the 2 blocks by only using the mux part as syscon with splitting the reg. If powerdomain really is needed then a second topmisc node could be added and bound to a new driver.
I agree with MediaTek's suggestion. Split it, that just makes more sense.
Besides, if the first part (the power controller in topmisc) is managed by ATF it's a good idea to avoid touching anything in there from the kernel :-)
Quoted 2 lines
But this would need a bit more of testing.
regards Frank
RFC 4/5 phy: mediatek: xsphy: support type switch by pericfg
In reply to Frank WunderlichFrom: Daniel Golle <[email protected]>
Patch from Sam Shih <[email protected]> found in MediaTek SDK released under GPL.
Get syscon and use it to set the PHY type.
Extend support to PCIe and SGMII mode in addition to USB2 and USB3.
--- drivers/phy/mediatek/phy-mtk-xsphy.c | 85 +++++++++++++++++++++++++++- 1 file changed, 84 insertions(+), 1 deletion(-)
drivers/phy/mediatek/phy-mtk-xsphy.c +84 -1
@@ -11,10 +11,12 @@#include <linux/clk.h> #include <linux/delay.h> #include <linux/iopoll.h> +#include <linux/mfd/syscon.h> #include <linux/module.h> #include <linux/of_address.h> #include <linux/phy/phy.h> #include <linux/platform_device.h> +#include <linux/regmap.h> #include "phy-mtk-io.h"
@@ -81,12 +83,22 @@#define XSP_SR_COEF_DIVISOR 1000#define XSP_FM_DET_CYCLE_CNT 1024 +/* PHY switch between pcie/usb3/sgmii */ +#define USB_PHY_SWITCH_CTRL 0x0 +#define RG_PHY_SW_TYPE GENMASK(3, 0) +#define RG_PHY_SW_PCIE 0x0 +#define RG_PHY_SW_USB3 0x1 +#define RG_PHY_SW_SGMII 0x2 +struct xsphy_instance {struct phy *phy;void __iomem *port_base;struct clk *ref_clk;/* reference clock of anolog phy */ u32 index;u32 type; +struct regmap *type_sw; +u32 type_sw_reg; +u32 type_sw_index;/* only for HQA test */ int efuse_intr;int efuse_tx_imp;
@@ -259,6 +271,10 @@ static void phy_parse_property(struct mtk_xsphy *xsphy, inst->efuse_intr, inst->efuse_tx_imp, inst->efuse_rx_imp);break ; +case PHY_TYPE_PCIE : +case PHY_TYPE_SGMII : +/* nothing to do */ +break ;default :dev_err (xsphy->dev,"incompatible phy type\n" );return ;
@@ -305,6 +321,62 @@ static void u3_phy_props_set(struct mtk_xsphy *xsphy, RG_XTP_LN0_RX_IMPSEL, inst->efuse_rx_imp); } +/* type switch for usb3/pcie/sgmii */ +static int phy_type_syscon_get (struct xsphy_instance *instance, +struct device_node *dn) +{ +struct of_phandle_args args; +int ret; + +/* type switch function is optional */ +if (!of_property_present (dn,"mediatek,syscon-type" )) +return 0 ; + + ret =of_parse_phandle_with_fixed_args (dn,"mediatek,syscon-type" , +2 ,0 , &args); +if (ret) +return ret; + + instance->type_sw_reg = args.args[0 ]; + instance->type_sw_index = args.args[1 ] &0x3 ;/* <=3 */ + instance->type_sw =syscon_node_to_regmap (args.np); +of_node_put (args.np); +dev_info (&instance->phy->dev,"type_sw - reg %#x, index %d\n" , + instance->type_sw_reg, instance->type_sw_index); + +return PTR_ERR_OR_ZERO (instance->type_sw); +} + +static int phy_type_set (struct xsphy_instance *instance) +{ +int type; +u32 offset; + +if (!instance->type_sw) +return 0 ; + +switch (instance->type) { +case PHY_TYPE_USB3 : + type =RG_PHY_SW_USB3 ; +break ; +case PHY_TYPE_PCIE : + type =RG_PHY_SW_PCIE ; +break ; +case PHY_TYPE_SGMII : + type =RG_PHY_SW_SGMII ; +break ; +case PHY_TYPE_USB2 : +default : +return 0 ; + } + + offset = instance->type_sw_index *BITS_PER_BYTE ; +regmap_update_bits (instance->type_sw, instance->type_sw_reg, +RG_PHY_SW_TYPE << offset, type << offset); + +return 0 ; +} +static int mtk_phy_init (struct phy *phy) {struct xsphy_instance *inst =phy_get_drvdata (phy);
@@ -325,6 +397,10 @@ static int mtk_phy_init(struct phy *phy)case PHY_TYPE_USB3 :u3_phy_props_set (xsphy, inst);break ; +case PHY_TYPE_PCIE : +case PHY_TYPE_SGMII : +/* nothing to do, only used to set type */ +break ;default :dev_err (xsphy->dev,"incompatible phy type\n" );clk_disable_unprepare (inst->ref_clk);
@@ -403,12 +479,15 @@ static struct phy *mtk_phy_xlate(struct device *dev, inst->type = args->args[0 ];if (!(inst->type ==PHY_TYPE_USB2 || - inst->type ==PHY_TYPE_USB3 )) { + inst->type ==PHY_TYPE_USB3 || + inst->type ==PHY_TYPE_PCIE || + inst->type ==PHY_TYPE_SGMII )) {dev_err (dev,"unsupported phy type: %d\n" , inst->type);return ERR_PTR (-EINVAL ); }phy_parse_property (xsphy, inst); +phy_type_set (inst);return inst->phy; }
@@ -510,6 +589,10 @@ static int mtk_xsphy_probe(struct platform_device *pdev)dev_err (dev,"failed to get ref_clk(id-%d)\n" , port);return PTR_ERR (inst->ref_clk); } + + retval =phy_type_syscon_get (inst, child_np); +if (retval) +return retval; } provider =devm_of_phy_provider_register (dev, mtk_phy_xlate);
Signature · 7 lines
2.43.0 -- linux-phy mailing list [email protected] https://lists.infradead.org/mailman/listinfo/linux-phy
AngeloGioacchino Del Regno
maintainerRe: [RFC 4/5] phy: mediatek: xsphy: support type switch by pericfg
Il 13/04/25 10:58, Frank Wunderlich ha scritto:
Quoted 8 lines
From: Daniel Golle <[email protected]>
Patch from Sam Shih <[email protected]> found in MediaTek SDK released under GPL.
Get syscon and use it to set the PHY type.
Extend support to PCIe and SGMII mode in addition to USB2 and USB3.
That's really exactly the same code that is in phy-mtk-tphy.c ... and actually there's a whole lot of code that is duplicated between TPHY and XSPHY...
It's even possible to just add the XSPHY to the TPHY driver and call it a day if we really want to, but I'll leave that decision to the maintainer.
Another way would be to add a phy-mtk-tphy-common.c and migrate all of the common code that can be shared from both XSPHY and TPHY in there....
Besides, if you check the register layout - even that is something like 90% the same (actually, looks like even more than that, but for the sake of being conservative...) so this really points me at believing that, despite the naming change, those IPs are just incremental versions, or XSPHY is simply a reduced functionality TPHY.
Either way, those are sharing really too much code to just keep duplicating :-)
P.S.: Those comments are only for the code, not for the binding.
Cheers,
Angelo
Quoted 158 lines
Signed-off-by Daniel Golle <[email protected]>--- drivers/phy/mediatek/phy-mtk-xsphy.c | 85 +++++++++++++++++++++++++++- 1 file changed, 84 insertions(+), 1 deletion(-)drivers/phy/mediatek/phy-mtk-xsphy.c +84
-1@@ -11,10 +11,12 @@#include <linux/clk.h> #include <linux/delay.h> #include <linux/iopoll.h> +#include <linux/mfd/syscon.h> #include <linux/module.h> #include <linux/of_address.h> #include <linux/phy/phy.h> #include <linux/platform_device.h> +#include <linux/regmap.h> #include "phy-mtk-io.h" @@ -81,12 +83,22 @@#define XSP_SR_COEF_DIVISOR 1000#define XSP_FM_DET_CYCLE_CNT 1024 +/* PHY switch between pcie/usb3/sgmii */ +#define USB_PHY_SWITCH_CTRL 0x0 +#define RG_PHY_SW_TYPE GENMASK(3, 0) +#define RG_PHY_SW_PCIE 0x0 +#define RG_PHY_SW_USB3 0x1 +#define RG_PHY_SW_SGMII 0x2 +struct xsphy_instance {struct phy *phy;void __iomem *port_base;struct clk *ref_clk;/* reference clock of anolog phy */ u32 index;u32 type; +struct regmap *type_sw; +u32 type_sw_reg; +u32 type_sw_index;/* only for HQA test */ int efuse_intr;int efuse_tx_imp;@@ -259,6 +271,10 @@ static void phy_parse_property(struct mtk_xsphy *xsphy, inst->efuse_intr, inst->efuse_tx_imp, inst->efuse_rx_imp);break ; +case PHY_TYPE_PCIE : +case PHY_TYPE_SGMII : +/* nothing to do */ +break ;default :dev_err (xsphy->dev,"incompatible phy type\n" );return ;@@ -305,6 +321,62 @@ static void u3_phy_props_set(struct mtk_xsphy *xsphy, RG_XTP_LN0_RX_IMPSEL, inst->efuse_rx_imp); } +/* type switch for usb3/pcie/sgmii */ +static int phy_type_syscon_get (struct xsphy_instance *instance, +struct device_node *dn) +{ +struct of_phandle_args args; +int ret; + +/* type switch function is optional */ +if (!of_property_present (dn,"mediatek,syscon-type" )) +return 0 ; + + ret =of_parse_phandle_with_fixed_args (dn,"mediatek,syscon-type" , +2 ,0 , &args); +if (ret) +return ret; + + instance->type_sw_reg = args.args[0 ]; + instance->type_sw_index = args.args[1 ] &0x3 ;/* <=3 */ + instance->type_sw =syscon_node_to_regmap (args.np); +of_node_put (args.np); +dev_info (&instance->phy->dev,"type_sw - reg %#x, index %d\n" , + instance->type_sw_reg, instance->type_sw_index); + +return PTR_ERR_OR_ZERO (instance->type_sw); +} + +static int phy_type_set (struct xsphy_instance *instance) +{ +int type; +u32 offset; + +if (!instance->type_sw) +return 0 ; + +switch (instance->type) { +case PHY_TYPE_USB3 : + type =RG_PHY_SW_USB3 ; +break ; +case PHY_TYPE_PCIE : + type =RG_PHY_SW_PCIE ; +break ; +case PHY_TYPE_SGMII : + type =RG_PHY_SW_SGMII ; +break ; +case PHY_TYPE_USB2 : +default : +return 0 ; + } + + offset = instance->type_sw_index *BITS_PER_BYTE ; +regmap_update_bits (instance->type_sw, instance->type_sw_reg, +RG_PHY_SW_TYPE << offset, type << offset); + +return 0 ; +} +static int mtk_phy_init (struct phy *phy) {struct xsphy_instance *inst =phy_get_drvdata (phy);@@ -325,6 +397,10 @@ static int mtk_phy_init(struct phy *phy)case PHY_TYPE_USB3 :u3_phy_props_set (xsphy, inst);break ; +case PHY_TYPE_PCIE : +case PHY_TYPE_SGMII : +/* nothing to do, only used to set type */ +break ;default :dev_err (xsphy->dev,"incompatible phy type\n" );clk_disable_unprepare (inst->ref_clk);@@ -403,12 +479,15 @@ static struct phy *mtk_phy_xlate(struct device *dev, inst->type = args->args[0 ];if (!(inst->type ==PHY_TYPE_USB2 || - inst->type ==PHY_TYPE_USB3 )) { + inst->type ==PHY_TYPE_USB3 || + inst->type ==PHY_TYPE_PCIE || + inst->type ==PHY_TYPE_SGMII )) {dev_err (dev,"unsupported phy type: %d\n" , inst->type);return ERR_PTR (-EINVAL ); }phy_parse_property (xsphy, inst); +phy_type_set (inst);return inst->phy; }@@ -510,6 +589,10 @@ static int mtk_xsphy_probe(struct platform_device *pdev)dev_err (dev,"failed to get ref_clk(id-%d)\n" , port);return PTR_ERR (inst->ref_clk); } + + retval =phy_type_syscon_get (inst, child_np); +if (retval) +return retval; } provider =devm_of_phy_provider_register (dev, mtk_phy_xlate);
RFC 5/5 arm64: dts: mediatek: mt7988: Add xsphy for ssusb0/pcie2
In reply to Frank WunderlichFrom: Frank Wunderlich <[email protected]>
First usb and third pcie controller on mt7988 need a xs-phy to work properly.
--- arch/arm64/boot/dts/mediatek/mt7988a.dtsi | 39 +++++++++++++++++++++++ 1 file changed, 39 insertions(+)
arch/arm64/boot/dts/mediatek/mt7988a.dtsi +39 -0
@@ -334,6 +334,8 @@ usb@11190000 { <&infracfg CLK_INFRA_133M_USB_HCK>, <&infracfg CLK_INFRA_USB_XHCI>; clock-names = "sys_ck", "ref_ck", "mcu_ck", "dma_ck", "xhci_ck"; + phys = <&xphyu2port0 PHY_TYPE_USB2>, + <&xphyu3port0 PHY_TYPE_USB3>; status = "disabled"; };
@@ -398,6 +400,9 @@ pcie2: pcie@11280000 { pinctrl-0 = <&pcie2_pins>; status = "disabled"; + phys = <&xphyu3port0 PHY_TYPE_PCIE>; + phy-names = "pcie-phy"; + #interrupt-cells = <1>; interrupt-map-mask = <0 0 0 0x7>; interrupt-map = <0 0 0 1 &pcie_intc2 0>,
@@ -548,6 +553,40 @@ tphyu3port0: usb-phy@11c50700 { }; }; + topmisc: power-controller@11d10000 { + compatible = "mediatek,mt7988-topmisc", "syscon", + "mediatek,mt7988-power-controller"; + reg = <0 0x11d10000 0 0x10000>; + #clock-cells = <1>; + #power-domain-cells = <1>; + #address-cells = <1>; + #size-cells = <0>; + }; + + xs-phy@11e10000 { + compatible = "mediatek,mt7988-xsphy", + "mediatek,xsphy"; + #address-cells = <2>; + #size-cells = <2>; + ranges; + status = "disabled"; + + xphyu2port0: usb-phy@11e10000 { + reg = <0 0x11e10000 0 0x400>; + clocks = <&infracfg CLK_INFRA_USB_UTMI>; + clock-names = "ref"; + #phy-cells = <1>; + }; + + xphyu3port0: usb-phy@11e13000 { + reg = <0 0x11e13400 0 0x500>; + clocks = <&infracfg CLK_INFRA_USB_PIPE>; + clock-names = "ref"; + #phy-cells = <1>; + mediatek,syscon-type = <&topmisc 0x218 0>; + }; + }; + clock-controller@11f40000 { compatible = "mediatek,mt7988-xfi-pll"; reg = <0 0x11f40000 0 0x1000>;
Signature · 1 line
2.43.0
AngeloGioacchino Del Regno
maintainerRe: [RFC 5/5] arm64: dts: mediatek: mt7988: Add xsphy for ssusb0/pcie2
Il 13/04/25 10:58, Frank Wunderlich ha scritto:
Quoted 38 lines
From: Frank Wunderlich <[email protected]>
First usb and third pcie controller on mt7988 need a xs-phy to work properly.
Signed-off-by Frank Wunderlich <[email protected]>--- arch/arm64/boot/dts/mediatek/mt7988a.dtsi | 39 +++++++++++++++++++++++ 1 file changed, 39 insertions(+)arch/arm64/boot/dts/mediatek/mt7988a.dtsi +6
-0@@ -334,6 +334,8 @@ usb@11190000 { <&infracfg CLK_INFRA_133M_USB_HCK>, <&infracfg CLK_INFRA_USB_XHCI>; clock-names = "sys_ck", "ref_ck", "mcu_ck", "dma_ck", "xhci_ck"; + phys = <&xphyu2port0 PHY_TYPE_USB2>, + <&xphyu3port0 PHY_TYPE_USB3>; status = "disabled"; };@@ -398,6 +400,9 @@ pcie2: pcie@11280000 { pinctrl-0 = <&pcie2_pins>; status = "disabled"; + phys = <&xphyu3port0 PHY_TYPE_PCIE>; + phy-names = "pcie-phy"; + #interrupt-cells = <1>; interrupt-map-mask = <0 0 0 0x7>; interrupt-map = <0 0 0 1 &pcie_intc2 0>,@@ -548,6 +553,40 @@ tphyu3port0: usb-phy@11c50700 { }; }; + topmisc: power-controller@11d10000 {
arch/arm64/boot/dts/mediatek/mt7988a.dtsi tphyu3port0: usb-phy@11c50700 { · line 566
Quoted 10 lines
arch/arm64/boot/dts/mediatek/mt7988a.dtsi +10
-0+ compatible = "mediatek,mt7988-topmisc", "syscon", + "mediatek,mt7988-power-controller"; + reg = <0 0x11d10000 0 0x10000>; + #clock-cells = <1>; + #power-domain-cells = <1>; + #address-cells = <1>; + #size-cells = <0>; + }; + + xs-phy@11e10000 {
That shall be just "phy@addr"
arch/arm64/boot/dts/mediatek/mt7988a.dtsi tphyu3port0: usb-phy@11c50700 { · line 574
Quoted 8 lines
arch/arm64/boot/dts/mediatek/mt7988a.dtsi +8
-0+ compatible = "mediatek,mt7988-xsphy", + "mediatek,xsphy"; + #address-cells = <2>; + #size-cells = <2>; + ranges; + status = "disabled"; + + xphyu2port0: usb-phy@11e10000 {
Perhaps just u2port0/u3port0 like done on the other MediaTek SoC DTs is better for consistency :-)
Cheers!
Quoted 18 lines
arch/arm64/boot/dts/mediatek/mt7988a.dtsi +15
-0+ reg = <0 0x11e10000 0 0x400>; + clocks = <&infracfg CLK_INFRA_USB_UTMI>; + clock-names = "ref"; + #phy-cells = <1>; + }; + + xphyu3port0: usb-phy@11e13000 { + reg = <0 0x11e13400 0 0x500>; + clocks = <&infracfg CLK_INFRA_USB_PIPE>; + clock-names = "ref"; + #phy-cells = <1>; + mediatek,syscon-type = <&topmisc 0x218 0>; + }; + }; + clock-controller@11f40000 { compatible = "mediatek,mt7988-xfi-pll"; reg = <0 0x11f40000 0 0x1000>;
Re: [RFC 5/5] arm64: dts: mediatek: mt7988: Add xsphy for ssusb0/pcie2
Am 14. April 2025 12:27:30 MESZ schrieb AngeloGioacchino Del Regno <[email protected]>:
Quoted 6 lines
Il 13/04/25 10:58, Frank Wunderlich ha scritto:
arch/arm64/boot/dts/mediatek/mt7988a.dtsi tphyu3port0: usb-phy@11c50700 { · line 566
Quoted 3 lines
From: Frank Wunderlich <[email protected]>
arch/arm64/boot/dts/mediatek/mt7988a.dtsi +1
-0+ xs-phy@11e10000 {That shall be just "phy@addr"
Ok
Quoted 11 lines
arch/arm64/boot/dts/mediatek/mt7988a.dtsi tphyu3port0: usb-phy@11c50700 { · line 574
Quoted 8 lines
arch/arm64/boot/dts/mediatek/mt7988a.dtsi +8
-0+ compatible = "mediatek,mt7988-xsphy", + "mediatek,xsphy"; + #address-cells = <2>; + #size-cells = <2>; + ranges; + status = "disabled"; + + xphyu2port0: usb-phy@11e10000 {Perhaps just u2port0/u3port0 like done on the other MediaTek SoC DTs is better for consistency :-)
Mt7988 also have a tphy where we have it named tphyu3port. Leaving this imho would increase confusion.
Quoted 2 lines
Cheers!
regards Frank