dt-bindings: phy: mediatek: tphy: support type switch by pericfg
Subsystems (5)
Chunfeng Yun
maintainerPATCH v2 1/9 dt-bindings: phy: mediatek: tphy: support type switch by pericfg
Add support type switch by pericfg register between USB3, PCIe, SATA, SGMII, this is used to replace the way through efuse or jumper.
---
v2: add reviewed-by Rob
--- .../devicetree/bindings/phy/mediatek,tphy.yaml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
Documentation/devicetree/bindings/phy/mediatek,tphy.yaml +16 -0
@@ -201,6 +201,22 @@ patternProperties: Specify the flag to enable BC1.2 if support it type: boolean + 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 - "#phy-cells"
Signature · 1 line
2.25.1
Chunfeng Yun
maintainerPATCH v2 2/9 phy: phy-mtk-tphy: use clock bulk to get clocks
Use clock bulk helpers to get/enable/disable clocks
---
v2: no changes
--- drivers/phy/mediatek/phy-mtk-tphy.c | 43 +++++++++-------------------- 1 file changed, 13 insertions(+), 30 deletions(-)
drivers/phy/mediatek/phy-mtk-tphy.c +13 -30
@@ -280,6 +280,8 @@#define RG_CDR_BIRLTD0_GEN3_MSK GENMASK(4, 0)#define RG_CDR_BIRLTD0_GEN3_VAL (x) (0x1f & (x)) +#define TPHY_CLKS_CNT 2 +enum mtk_phy_version {MTK_PHY_V1 =1 ,MTK_PHY_V2 ,
@@ -318,8 +320,7 @@ struct mtk_phy_instance {struct u2phy_banks u2_banks;struct u3phy_banks u3_banks; }; -struct clk *ref_clk;/* reference clock of (digital) phy */ -struct clk *da_ref_clk;/* reference clock of analog phy */ +struct clk_bulk_data clks[TPHY_CLKS_CNT ];u32 index;u8 type;int eye_src;
@@ -974,18 +975,9 @@ static int mtk_phy_init(struct phy *phy)struct mtk_tphy *tphy =dev_get_drvdata (phy->dev.parent);int ret; - ret =clk_prepare_enable (instance->ref_clk); -if (ret) { -dev_err (tphy->dev,"failed to enable ref_clk\n" ); + ret =clk_bulk_prepare_enable (TPHY_CLKS_CNT , instance->clks); +if (ret)return ret; - } - - ret =clk_prepare_enable (instance->da_ref_clk); -if (ret) { -dev_err (tphy->dev,"failed to enable da_ref\n" ); -clk_disable_unprepare (instance->ref_clk); -return ret; - }switch (instance->type) {case PHY_TYPE_USB2 :
@@ -1003,8 +995,7 @@ static int mtk_phy_init(struct phy *phy)break ;default :dev_err (tphy->dev,"incompatible PHY type\n" ); -clk_disable_unprepare (instance->ref_clk); -clk_disable_unprepare (instance->da_ref_clk); +clk_bulk_disable_unprepare (TPHY_CLKS_CNT , instance->clks);return -EINVAL ; }
@@ -1047,8 +1038,7 @@ static int mtk_phy_exit(struct phy *phy)if (instance->type ==PHY_TYPE_USB2 )u2_phy_instance_exit (tphy, instance); -clk_disable_unprepare (instance->ref_clk); -clk_disable_unprepare (instance->da_ref_clk); +clk_bulk_disable_unprepare (TPHY_CLKS_CNT , instance->clks);return 0 ; }
@@ -1211,6 +1201,7 @@ static int mtk_tphy_probe(struct platform_device *pdev) port =0 ;for_each_child_of_node (np, child_np) {struct mtk_phy_instance *instance; +struct clk_bulk_data *clks;struct phy *phy; instance =devm_kzalloc (dev,sizeof (*instance),GFP_KERNEL );
@@ -1247,20 +1238,12 @@ static int mtk_tphy_probe(struct platform_device *pdev)phy_set_drvdata (phy, instance); port++; - instance->ref_clk =devm_clk_get_optional (&phy->dev,"ref" ); -if (IS_ERR (instance->ref_clk)) { -dev_err (dev,"failed to get ref_clk(id-%d)\n" , port); - retval =PTR_ERR (instance->ref_clk); + clks = instance->clks; + clks[0 ].id ="ref" ;/* digital (& analog) clock */ + clks[1 ].id ="da_ref" ;/* analog clock */ + retval =devm_clk_bulk_get_optional (&phy->dev,TPHY_CLKS_CNT , clks); +if (retval) goto put_child; - } - - instance->da_ref_clk = -devm_clk_get_optional (&phy->dev,"da_ref" ); -if (IS_ERR (instance->da_ref_clk)) { -dev_err (dev,"failed to get da_ref_clk(id-%d)\n" , port); - retval =PTR_ERR (instance->da_ref_clk); - goto put_child; - } } provider =devm_of_phy_provider_register (dev, mtk_phy_xlate);
Signature · 1 line
2.25.1
Chunfeng Yun
maintainerPATCH v2 3/9 phy: phy-mtk-tphy: support type switch by pericfg
In reply to Chunfeng YunAdd support type switch between USB3, PCIe, SATA and SGMII by pericfg register, this is used to take the place of efuse or jumper.
---
v2: no changes
--- drivers/phy/mediatek/phy-mtk-tphy.c | 84 ++++++++++++++++++++++++++++- 1 file changed, 82 insertions(+), 2 deletions(-)
drivers/phy/mediatek/phy-mtk-tphy.c +82 -2
@@ -10,11 +10,13 @@#include <linux/delay.h> #include <linux/io.h> #include <linux/iopoll.h> +#include <linux/mfd/syscon.h> #include <linux/module.h> #include <linux/of_address.h> #include <linux/of_device.h> #include <linux/phy/phy.h> #include <linux/platform_device.h> +#include <linux/regmap.h> /* version V1 sub-banks offset base address */ /* banks shared by multiple phys */
@@ -280,6 +282,14 @@#define RG_CDR_BIRLTD0_GEN3_MSK GENMASK(4, 0)#define RG_CDR_BIRLTD0_GEN3_VAL (x) (0x1f & (x)) +/* PHY switch between pcie/usb3/sgmii/sata */ +#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 +#define RG_PHY_SW_SATA 0x3 +#define TPHY_CLKS_CNT 2enum mtk_phy_version {
@@ -322,7 +332,10 @@ struct mtk_phy_instance { };struct clk_bulk_data clks[TPHY_CLKS_CNT ];u32 index; -u8 type; +u32 type; +struct regmap *type_sw; +u32 type_sw_reg; +u32 type_sw_index;int eye_src;int eye_vrt;int eye_term;
@@ -969,6 +982,64 @@ static void u2_phy_props_set(struct mtk_tphy *tphy, } } +/* type switch for usb3/pcie/sgmii/sata */ +static int phy_type_syscon_get (struct mtk_phy_instance *instance, +struct device_node *dn) +{ +struct of_phandle_args args; +int ret; + +/* type switch function is optional */ +if (!of_property_read_bool (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 mtk_phy_instance *instance) +{ +int type; +u32 mask; + +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_SATA : + type =RG_PHY_SW_SATA ; +break ; +case PHY_TYPE_USB2 : +default : +return 0 ; + } + + mask =RG_PHY_SW_TYPE << (instance->type_sw_index *BITS_PER_BYTE ); +regmap_update_bits (instance->type_sw, instance->type_sw_reg, mask, type); + +return 0 ; +} +static int mtk_phy_init (struct phy *phy) {struct mtk_phy_instance *instance =phy_get_drvdata (phy);
@@ -993,6 +1064,9 @@ static int mtk_phy_init(struct phy *phy)case PHY_TYPE_SATA :sata_phy_instance_init (tphy, instance);break ; +case PHY_TYPE_SGMII : +/* nothing to do, only used to set type */ +break ;default :dev_err (tphy->dev,"incompatible PHY type\n" );clk_bulk_disable_unprepare (TPHY_CLKS_CNT , instance->clks);
@@ -1081,7 +1155,8 @@ static struct phy *mtk_phy_xlate(struct device *dev,if (!(instance->type ==PHY_TYPE_USB2 || instance->type ==PHY_TYPE_USB3 || instance->type ==PHY_TYPE_PCIE || - instance->type ==PHY_TYPE_SATA )) { + instance->type ==PHY_TYPE_SATA || + instance->type ==PHY_TYPE_SGMII )) {dev_err (dev,"unsupported device type: %d\n" , instance->type);return ERR_PTR (-EINVAL ); }
@@ -1100,6 +1175,7 @@ static struct phy *mtk_phy_xlate(struct device *dev, }phy_parse_property (tphy, instance); +phy_type_set (instance);return instance->phy; }
@@ -1244,6 +1320,10 @@ static int mtk_tphy_probe(struct platform_device *pdev) retval =devm_clk_bulk_get_optional (&phy->dev,TPHY_CLKS_CNT , clks);if (retval) goto put_child; + + retval =phy_type_syscon_get (instance, child_np); +if (retval) + goto put_child; } provider =devm_of_phy_provider_register (dev, mtk_phy_xlate);
Signature · 1 line
2.25.1
Chunfeng Yun
maintainerPATCH v2 4/9 phy: phy-mtk-tphy: print error log using child device
In reply to Chunfeng YunPrint error log using child devices instead of parent device.
---
v2: no changes
--- drivers/phy/mediatek/phy-mtk-tphy.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/phy/mediatek/phy-mtk-tphy.c +6 -4
@@ -1278,6 +1278,7 @@ static int mtk_tphy_probe(struct platform_device *pdev)for_each_child_of_node (np, child_np) {struct mtk_phy_instance *instance;struct clk_bulk_data *clks; +struct device *subdev;struct phy *phy; instance =devm_kzalloc (dev,sizeof (*instance),GFP_KERNEL );
@@ -1295,16 +1296,17 @@ static int mtk_tphy_probe(struct platform_device *pdev) goto put_child; } + subdev = &phy->dev; retval =of_address_to_resource (child_np,0 , &res);if (retval) { -dev_err (dev,"failed to get address resource(id-%d)\n" , +dev_err (subdev,"failed to get address resource(id-%d)\n" , port); goto put_child; } - instance->port_base =devm_ioremap_resource (&phy->dev, &res); + instance->port_base =devm_ioremap_resource (subdev, &res);if (IS_ERR (instance->port_base)) { -dev_err (dev,"failed to remap phy regs\n" ); +dev_err (subdev,"failed to remap phy regs\n" ); retval =PTR_ERR (instance->port_base); goto put_child; }
@@ -1317,7 +1319,7 @@ static int mtk_tphy_probe(struct platform_device *pdev) clks = instance->clks; clks[0 ].id ="ref" ;/* digital (& analog) clock */ clks[1 ].id ="da_ref" ;/* analog clock */ - retval =devm_clk_bulk_get_optional (&phy->dev,TPHY_CLKS_CNT , clks); + retval =devm_clk_bulk_get_optional (subdev,TPHY_CLKS_CNT , clks);if (retval) goto put_child;
Signature · 1 line
2.25.1
Chunfeng Yun
maintainerPATCH v2 5/9 phy: phy-mtk-tphy: remove error log of ioremap failure
In reply to Chunfeng Yundevm_ioremap_resource() will print log if error happens.
---
v2: no changes
--- drivers/phy/mediatek/phy-mtk-tphy.c | 1 - 1 file changed, 1 deletion(-)
drivers/phy/mediatek/phy-mtk-tphy.c +0 -1
@@ -1306,7 +1306,6 @@ static int mtk_tphy_probe(struct platform_device *pdev) instance->port_base =devm_ioremap_resource (subdev, &res);if (IS_ERR (instance->port_base)) { -dev_err (subdev,"failed to remap phy regs\n" ); retval =PTR_ERR (instance->port_base); goto put_child; }
Signature · 1 line
2.25.1
Chunfeng Yun
maintainerPATCH v2 6/9 phy: phy-mtk-ufs: use clock bulk to get clocks
In reply to Chunfeng YunUse clock bulk helpers to get/enable/disable clocks
---
v2: no changes
--- drivers/phy/mediatek/phy-mtk-ufs.c | 44 ++++++++---------------------- 1 file changed, 11 insertions(+), 33 deletions(-)
drivers/phy/mediatek/phy-mtk-ufs.c +11 -33
@@ -31,11 +31,12 @@#define FRC_CDR_ISO_EN BIT(19)#define CDR_ISO_EN BIT(20) +#define UFSPHY_CLKS_CNT 2 +struct ufs_mtk_phy {struct device *dev;void __iomem *mmio; -struct clk *mp_clk; -struct clk *unipro_clk; +struct clk_bulk_data clks[UFSPHY_CLKS_CNT ]; };static inline u32 mphy_readl (struct ufs_mtk_phy *phy,u32 reg)
@@ -74,20 +75,11 @@ static struct ufs_mtk_phy *get_ufs_mtk_phy(struct phy *generic_phy)static int ufs_mtk_phy_clk_init (struct ufs_mtk_phy *phy) {struct device *dev = phy->dev; +struct clk_bulk_data *clks = phy->clks; - phy->unipro_clk =devm_clk_get (dev,"unipro" ); -if (IS_ERR (phy->unipro_clk)) { -dev_err (dev,"failed to get clock: unipro" ); -return PTR_ERR (phy->unipro_clk); - } - - phy->mp_clk =devm_clk_get (dev,"mp" ); -if (IS_ERR (phy->mp_clk)) { -dev_err (dev,"failed to get clock: mp" ); -return PTR_ERR (phy->mp_clk); - } - -return 0 ; + clks[0 ].id ="unipro" ; + clks[1 ].id ="mp" ; +return devm_clk_bulk_get (dev,UFSPHY_CLKS_CNT , clks); }static void ufs_mtk_phy_set_active (struct ufs_mtk_phy *phy)
@@ -150,26 +142,13 @@ static int ufs_mtk_phy_power_on(struct phy *generic_phy)struct ufs_mtk_phy *phy =get_ufs_mtk_phy (generic_phy);int ret; - ret =clk_prepare_enable (phy->unipro_clk); -if (ret) { -dev_err (phy->dev,"unipro_clk enable failed %d\n" , ret); - goto out; - } - - ret =clk_prepare_enable (phy->mp_clk); -if (ret) { -dev_err (phy->dev,"mp_clk enable failed %d\n" , ret); - goto out_unprepare_unipro_clk; - } + ret =clk_bulk_prepare_enable (UFSPHY_CLKS_CNT , phy->clks); +if (ret) +return ret;ufs_mtk_phy_set_active (phy);return 0 ; - -out_unprepare_unipro_clk: -clk_disable_unprepare (phy->unipro_clk); -out: -return ret; }static int ufs_mtk_phy_power_off (struct phy *generic_phy)
@@ -178,8 +157,7 @@ static int ufs_mtk_phy_power_off(struct phy *generic_phy)ufs_mtk_phy_set_deep_hibern (phy); -clk_disable_unprepare (phy->unipro_clk); -clk_disable_unprepare (phy->mp_clk); +clk_bulk_disable_unprepare (UFSPHY_CLKS_CNT , phy->clks);return 0 ; }
Signature · 1 line
2.25.1
Chunfeng Yun
maintainerPATCH v2 7/9 phy: phy-mtk-hdmi: convert to devm_platform_ioremap_resource
In reply to Chunfeng YunUse devm_platform_ioremap_resource to simplify code
---
v2: add acked-by CK
--- drivers/phy/mediatek/phy-mtk-hdmi.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/phy/mediatek/phy-mtk-hdmi.c +2 -5
@@ -100,7 +100,6 @@ static int mtk_hdmi_phy_probe(struct platform_device *pdev) {struct device *dev = &pdev->dev;struct mtk_hdmi_phy *hdmi_phy; -struct resource *mem;struct clk *ref_clk;const char *ref_clk_name;struct clk_init_data clk_init = {
@@ -116,11 +115,9 @@ static int mtk_hdmi_phy_probe(struct platform_device *pdev)if (!hdmi_phy)return -ENOMEM ; - mem =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); - hdmi_phy->regs =devm_ioremap_resource (dev, mem); -if (IS_ERR (hdmi_phy->regs)) { + hdmi_phy->regs =devm_platform_ioremap_resource (pdev,0 ); +if (IS_ERR (hdmi_phy->regs))return PTR_ERR (hdmi_phy->regs); - } ref_clk =devm_clk_get (dev,"pll_ref" );if (IS_ERR (ref_clk)) {
Signature · 1 line
2.25.1
Chunfeng Yun
maintainerPATCH v2 8/9 phy: phy-mtk-mipi-dsi: remove dummy assignment of error number
In reply to Chunfeng YunReturn the error number directly without assignment
---
v2: add acked-by CK
--- drivers/phy/mediatek/phy-mtk-mipi-dsi.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/phy/mediatek/phy-mtk-mipi-dsi.c +2 -4
@@ -203,10 +203,8 @@ static int mtk_mipi_tx_probe(struct platform_device *pdev)phy_set_drvdata (phy, mipi_tx); phy_provider =devm_of_phy_provider_register (dev, of_phy_simple_xlate); -if (IS_ERR (phy_provider)) { - ret =PTR_ERR (phy_provider); -return ret; - } +if (IS_ERR (phy_provider)) +return PTR_ERR (phy_provider); mipi_tx->dev = dev;
Signature · 1 line
2.25.1
Chunfeng Yun
maintainerPATCH v2 9/9 phy: phy-mtk-mipi-dsi: convert to devm_platform_ioremap_resource
In reply to Chunfeng YunUse devm_platform_ioremap_resource to simplify code
---
v2: add acked-by CK
--- drivers/phy/mediatek/phy-mtk-mipi-dsi.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/phy/mediatek/phy-mtk-mipi-dsi.c +2 -5
@@ -130,7 +130,6 @@ static int mtk_mipi_tx_probe(struct platform_device *pdev) {struct device *dev = &pdev->dev;struct mtk_mipi_tx *mipi_tx; -struct resource *mem;const char *ref_clk_name;struct clk *ref_clk;struct clk_init_data clk_init = {
@@ -148,11 +147,9 @@ static int mtk_mipi_tx_probe(struct platform_device *pdev) mipi_tx->driver_data =of_device_get_match_data (dev); - mem =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); - mipi_tx->regs =devm_ioremap_resource (dev, mem); -if (IS_ERR (mipi_tx->regs)) { + mipi_tx->regs =devm_platform_ioremap_resource (pdev,0 ); +if (IS_ERR (mipi_tx->regs))return PTR_ERR (mipi_tx->regs); - } ref_clk =devm_clk_get (dev,NULL );if (IS_ERR (ref_clk)) {
Signature · 1 line
2.25.1