Skip to content

Commit c41cde7

Browse files
ParthibanI17164cfriedt
authored andcommitted
drivers: ethernet: phy: microchip_t1s: fix C45 registers direct access
C45 direct registers access is only supported by the LAN865x internal PHY, not by the LAN867x external PHY, even though the MAC supports it. Restrict C45 direct register access to the LAN865x internal PHY. The LAN867x external PHY supports C45 registers only via indirect access through C22 registers. Signed-off-by: Parthiban Veerasooran <[email protected]>
1 parent 5e6e8da commit c41cde7

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

drivers/ethernet/phy/phy_microchip_t1s.c

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ struct mc_t1s_config {
9696
};
9797

9898
struct mc_t1s_data {
99+
uint32_t phy_id;
99100
const struct device *dev;
100101
struct phy_link_state state;
101102
phy_callback_t cb;
@@ -141,41 +142,41 @@ static int mdio_setup_c45_indirect_access(const struct device *dev, uint16_t dev
141142
static int phy_mc_t1s_c45_read(const struct device *dev, uint8_t devad, uint16_t reg, uint16_t *val)
142143
{
143144
const struct mc_t1s_config *cfg = dev->config;
145+
struct mc_t1s_data *data = dev->data;
144146
int ret;
145147

146-
ret = mdio_read_c45(cfg->mdio, cfg->phy_addr, devad, reg, val);
147-
/* @retval -ENOSYS if read using Clause 45 direct access is not supported */
148-
if (ret == -ENOSYS) {
149-
/* Read C45 registers using C22 indirect access registers */
150-
ret = mdio_setup_c45_indirect_access(dev, devad, reg);
151-
if (ret) {
152-
return ret;
153-
}
148+
/* C45 direct read access is only supported by LAN865x internal PHY */
149+
if (data->phy_id == PHY_ID_LAN865X_REVB) {
150+
return mdio_read_c45(cfg->mdio, cfg->phy_addr, devad, reg, val);
151+
}
154152

155-
return mdio_read(cfg->mdio, cfg->phy_addr, MII_MMD_AADR, val);
153+
/* Read C45 registers using C22 indirect access registers */
154+
ret = mdio_setup_c45_indirect_access(dev, devad, reg);
155+
if (ret) {
156+
return ret;
156157
}
157158

158-
return ret;
159+
return mdio_read(cfg->mdio, cfg->phy_addr, MII_MMD_AADR, val);
159160
}
160161

161162
static int phy_mc_t1s_c45_write(const struct device *dev, uint8_t devad, uint16_t reg, uint16_t val)
162163
{
163164
const struct mc_t1s_config *cfg = dev->config;
165+
struct mc_t1s_data *data = dev->data;
164166
int ret;
165167

166-
ret = mdio_write_c45(cfg->mdio, cfg->phy_addr, devad, reg, val);
167-
/* @retval -ENOSYS if write using Clause 45 direct access is not supported */
168-
if (ret == -ENOSYS) {
169-
/* Write C45 registers using C22 indirect access registers */
170-
ret = mdio_setup_c45_indirect_access(dev, devad, reg);
171-
if (ret) {
172-
return ret;
173-
}
168+
/* C45 direct write access is only supported by LAN865x internal PHY */
169+
if (data->phy_id == PHY_ID_LAN865X_REVB) {
170+
return mdio_write_c45(cfg->mdio, cfg->phy_addr, devad, reg, val);
171+
}
174172

175-
return mdio_write(cfg->mdio, cfg->phy_addr, MII_MMD_AADR, val);
173+
/* Write C45 registers using C22 indirect access registers */
174+
ret = mdio_setup_c45_indirect_access(dev, devad, reg);
175+
if (ret) {
176+
return ret;
176177
}
177178

178-
return ret;
179+
return mdio_write(cfg->mdio, cfg->phy_addr, MII_MMD_AADR, val);
179180
}
180181

181182
static int phy_mc_t1s_get_link(const struct device *dev, struct phy_link_state *state)
@@ -478,17 +479,16 @@ static int phy_mc_t1s_set_dt_plca(const struct device *dev)
478479
static int phy_mc_t1s_init(const struct device *dev)
479480
{
480481
struct mc_t1s_data *data = dev->data;
481-
uint32_t phy_id;
482482
int ret;
483483

484484
data->dev = dev;
485485

486-
ret = phy_mc_t1s_id(dev, &phy_id);
486+
ret = phy_mc_t1s_id(dev, &data->phy_id);
487487
if (ret) {
488488
return ret;
489489
}
490490

491-
switch (phy_id) {
491+
switch (data->phy_id) {
492492
case PHY_ID_LAN867X_REVC1:
493493
case PHY_ID_LAN867X_REVC2:
494494
ret = phy_mc_lan867x_revc_config_init(dev);
@@ -505,7 +505,7 @@ static int phy_mc_t1s_init(const struct device *dev)
505505
}
506506
break;
507507
default:
508-
LOG_ERR("Unsupported PHY ID: %x\n", phy_id);
508+
LOG_ERR("Unsupported PHY ID: %x\n", data->phy_id);
509509
return -ENODEV;
510510
}
511511

0 commit comments

Comments
 (0)