developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 1 | From 13b169a35dfff523263d20d0d97e46401f6c692f Mon Sep 17 00:00:00 2001 |
| 2 | From: Sam Shih <sam.shih@mediatek.com> |
| 3 | Date: Fri, 2 Jun 2023 13:06:31 +0800 |
| 4 | Subject: [PATCH] |
| 5 | [networking][999-2714-mt7531-gsw-port5_external_phy_init.patch] |
developer | fd40db2 | 2021-04-29 10:08:25 +0800 | [diff] [blame] | 6 | |
developer | fd40db2 | 2021-04-29 10:08:25 +0800 | [diff] [blame] | 7 | --- |
| 8 | drivers/net/phy/mtk/mt753x/Makefile | 3 +- |
| 9 | drivers/net/phy/mtk/mt753x/mt7531.c | 3 + |
| 10 | drivers/net/phy/mtk/mt753x/mt753x.h | 1 + |
| 11 | drivers/net/phy/mtk/mt753x/mt753x_extphy.c | 69 ++++++++++++++++++++++ |
| 12 | drivers/net/phy/mtk/mt753x/mt753x_extphy.h | 18 ++++++ |
| 13 | 5 files changed, 93 insertions(+), 1 deletion(-) |
| 14 | create mode 100644 drivers/net/phy/mtk/mt753x/mt753x_extphy.c |
| 15 | create mode 100644 drivers/net/phy/mtk/mt753x/mt753x_extphy.h |
| 16 | |
| 17 | diff --git a/drivers/net/phy/mtk/mt753x/Makefile b/drivers/net/phy/mtk/mt753x/Makefile |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 18 | index b5a63fe91..16e977528 100644 |
developer | fd40db2 | 2021-04-29 10:08:25 +0800 | [diff] [blame] | 19 | --- a/drivers/net/phy/mtk/mt753x/Makefile |
| 20 | +++ b/drivers/net/phy/mtk/mt753x/Makefile |
| 21 | @@ -7,5 +7,6 @@ obj-$(CONFIG_MT753X_GSW) += mt753x.o |
| 22 | mt753x-$(CONFIG_SWCONFIG) += mt753x_swconfig.o |
| 23 | |
| 24 | mt753x-y += mt753x_mdio.o mt7530.o mt7531.o \ |
| 25 | - mt753x_common.o mt753x_vlan.o mt753x_nl.o mt753x_phy.o |
| 26 | + mt753x_common.o mt753x_vlan.o mt753x_nl.o mt753x_phy.o \ |
| 27 | + mt753x_extphy.o |
| 28 | |
| 29 | diff --git a/drivers/net/phy/mtk/mt753x/mt7531.c b/drivers/net/phy/mtk/mt753x/mt7531.c |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 30 | index 512a89a94..3e2187d21 100755 |
developer | fd40db2 | 2021-04-29 10:08:25 +0800 | [diff] [blame] | 31 | --- a/drivers/net/phy/mtk/mt753x/mt7531.c |
| 32 | +++ b/drivers/net/phy/mtk/mt753x/mt7531.c |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 33 | @@ -264,6 +264,9 @@ static int mt7531_set_port_sgmii_force_mode(struct gsw_mt753x *gsw, u32 port, |
developer | fd40db2 | 2021-04-29 10:08:25 +0800 | [diff] [blame] | 34 | return -EINVAL; |
| 35 | } |
| 36 | |
| 37 | + if (port == 5) |
| 38 | + extphy_init(gsw, port); |
| 39 | + |
| 40 | port_base = port - 5; |
| 41 | |
| 42 | switch (port_cfg->speed) { |
| 43 | diff --git a/drivers/net/phy/mtk/mt753x/mt753x.h b/drivers/net/phy/mtk/mt753x/mt753x.h |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 44 | index 252ce350f..c23fd9e5f 100644 |
developer | fd40db2 | 2021-04-29 10:08:25 +0800 | [diff] [blame] | 45 | --- a/drivers/net/phy/mtk/mt753x/mt753x.h |
| 46 | +++ b/drivers/net/phy/mtk/mt753x/mt753x.h |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 47 | @@ -147,6 +147,7 @@ int mt753x_phy_calibration(struct gsw_mt753x *gsw, u8 phyaddr); |
| 48 | int extphy_init(struct gsw_mt753x *gsw, int addr); |
developer | fd40db2 | 2021-04-29 10:08:25 +0800 | [diff] [blame] | 49 | |
| 50 | int mt753x_phy_calibration(struct gsw_mt753x *gsw, u8 phyaddr); |
| 51 | +int extphy_init(struct gsw_mt753x *gsw, int addr); |
| 52 | |
| 53 | /* MDIO Indirect Access Registers */ |
| 54 | #define MII_MMD_ACC_CTL_REG 0x0d |
| 55 | diff --git a/drivers/net/phy/mtk/mt753x/mt753x_extphy.c b/drivers/net/phy/mtk/mt753x/mt753x_extphy.c |
| 56 | new file mode 100644 |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 57 | index 000000000..f58e8a62d |
developer | fd40db2 | 2021-04-29 10:08:25 +0800 | [diff] [blame] | 58 | --- /dev/null |
| 59 | +++ b/drivers/net/phy/mtk/mt753x/mt753x_extphy.c |
| 60 | @@ -0,0 +1,69 @@ |
| 61 | +/* |
| 62 | + * Driver for MediaTek MT7531 gigabit switch |
| 63 | + * |
| 64 | + * Copyright (C) 2018 MediaTek Inc. All Rights Reserved. |
| 65 | + * |
| 66 | + * Author: Landen Chao <landen.chao@mediatek.com> |
| 67 | + * |
| 68 | + * SPDX-License-Identifier: GPL-2.0+ |
| 69 | + */ |
| 70 | + |
| 71 | +#include <linux/kernel.h> |
| 72 | +#include <linux/mii.h> |
| 73 | + |
| 74 | +#include "mt753x.h" |
| 75 | +#include "mt753x_regs.h" |
| 76 | +#include "mt753x_extphy.h" |
| 77 | + |
| 78 | +int gpy211_init(struct gsw_mt753x *gsw, int addr) |
| 79 | +{ |
| 80 | + /* Enable rate adaption */ |
| 81 | + gsw->mmd_write(gsw, addr, 0x1e, 0x8, 0x24e2); |
| 82 | + |
| 83 | + return 0; |
| 84 | +} |
| 85 | + |
| 86 | +static struct mt753x_extphy_id extphy_tbl[] = { |
| 87 | + {0x67c9de00, 0x0fffffff0, gpy211_init}, |
| 88 | +}; |
| 89 | + |
| 90 | +static u32 get_cl22_phy_id(struct gsw_mt753x *gsw, int addr) |
| 91 | +{ |
| 92 | + int phy_reg; |
| 93 | + u32 phy_id = 0; |
| 94 | + |
| 95 | + phy_reg = gsw->mii_read(gsw, addr, MII_PHYSID1); |
| 96 | + if (phy_reg < 0) |
| 97 | + return 0; |
| 98 | + phy_id = (phy_reg & 0xffff) << 16; |
| 99 | + |
| 100 | + /* Grab the bits from PHYIR2, and put them in the lower half */ |
| 101 | + phy_reg = gsw->mii_read(gsw, addr, MII_PHYSID2); |
| 102 | + if (phy_reg < 0) |
| 103 | + return 0; |
| 104 | + |
| 105 | + phy_id |= (phy_reg & 0xffff); |
| 106 | + |
| 107 | + return phy_id; |
| 108 | +} |
| 109 | + |
| 110 | +static inline bool phy_id_is_match(u32 id, struct mt753x_extphy_id *phy) |
| 111 | +{ |
| 112 | + return ((id & phy->phy_id_mask) == (phy->phy_id & phy->phy_id_mask)); |
| 113 | +} |
| 114 | + |
| 115 | +int extphy_init(struct gsw_mt753x *gsw, int addr) |
| 116 | +{ |
| 117 | + int i; |
| 118 | + u32 phy_id; |
| 119 | + struct mt753x_extphy_id *extphy; |
| 120 | + |
| 121 | + phy_id = get_cl22_phy_id(gsw, addr); |
| 122 | + for (i = 0; i < ARRAY_SIZE(extphy_tbl); i++) { |
| 123 | + extphy = &extphy_tbl[i]; |
| 124 | + if(phy_id_is_match(phy_id, extphy)) |
| 125 | + extphy->init(gsw, addr); |
| 126 | + } |
| 127 | + |
| 128 | + return 0; |
| 129 | +} |
| 130 | diff --git a/drivers/net/phy/mtk/mt753x/mt753x_extphy.h b/drivers/net/phy/mtk/mt753x/mt753x_extphy.h |
| 131 | new file mode 100644 |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 132 | index 000000000..2b72c8a9d |
developer | fd40db2 | 2021-04-29 10:08:25 +0800 | [diff] [blame] | 133 | --- /dev/null |
| 134 | +++ b/drivers/net/phy/mtk/mt753x/mt753x_extphy.h |
| 135 | @@ -0,0 +1,18 @@ |
| 136 | +/* |
| 137 | + * Driver for MediaTek MT753x gigabit switch |
| 138 | + * |
| 139 | + * Copyright (C) 2018 MediaTek Inc. All Rights Reserved. |
| 140 | + * |
| 141 | + * Author: Landen Chao <landen.chao@mediatek.com> |
| 142 | + * |
| 143 | + * SPDX-License-Identifier: GPL-2.0+ |
| 144 | + */ |
| 145 | + |
| 146 | +#ifndef _MT753X_EXTPHY_H_ |
| 147 | +#define _MT753X_EXTPHY_H_ |
| 148 | +struct mt753x_extphy_id { |
| 149 | + u32 phy_id; |
| 150 | + u32 phy_id_mask; |
| 151 | + int (*init)(struct gsw_mt753x *gsw, int addr); |
| 152 | +}; |
| 153 | +#endif |
| 154 | -- |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 155 | 2.34.1 |
developer | fd40db2 | 2021-04-29 10:08:25 +0800 | [diff] [blame] | 156 | |