Skip to content

Commit 3254c5b

Browse files
drivers: mdio_nxp_enet_qos: Add Clause 45 support.
Adds handler for C45 read/write phy transactions. Signed-off-by: Peter van der Perk <peter.vanderperk@nxp.com>
1 parent 9f0dc12 commit 3254c5b

File tree

1 file changed

+75
-14
lines changed

1 file changed

+75
-14
lines changed

drivers/mdio/mdio_nxp_enet_qos.c

Lines changed: 75 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ struct mdio_transaction {
3232
};
3333
uint8_t portaddr;
3434
uint8_t regaddr;
35+
uint16_t regaddr_c45;
3536
enet_qos_t *base;
3637
struct k_mutex *mdio_bus_mutex;
3738
};
@@ -44,32 +45,53 @@ static bool check_busy(enet_qos_t *base)
4445
return ENET_QOS_REG_GET(MAC_MDIO_ADDRESS, GB, val);
4546
}
4647

47-
static int do_transaction(struct mdio_transaction *mdio)
48+
static int do_transaction(struct mdio_transaction *mdio, bool clause45)
4849
{
4950
enet_qos_t *base = mdio->base;
5051
uint8_t goc_1_code;
5152
int ret;
5253

5354
k_mutex_lock(mdio->mdio_bus_mutex, K_FOREVER);
5455

55-
if (mdio->op == MDIO_OP_C22_WRITE) {
56-
base->MAC_MDIO_DATA =
57-
/* Prepare the data to be written */
58-
ENET_QOS_REG_PREP(MAC_MDIO_DATA, GD, mdio->write_data);
59-
goc_1_code = 0b0;
60-
} else if (mdio->op == MDIO_OP_C22_READ) {
61-
goc_1_code = 0b1;
56+
if (clause45) {
57+
if (mdio->op == MDIO_OP_C45_WRITE) {
58+
goc_1_code = 0b0;
59+
base->MAC_MDIO_DATA =
60+
/* Prepare the data and regaddr to be written */
61+
ENET_QOS_REG_PREP(MAC_MDIO_DATA, GD, mdio->write_data) |
62+
ENET_QOS_REG_PREP(MAC_MDIO_DATA, RA, mdio->regaddr_c45);
63+
} else if (mdio->op == MDIO_OP_C45_READ) {
64+
goc_1_code = 0b1;
65+
base->MAC_MDIO_DATA =
66+
/* Prepare the regaddr to be written */
67+
ENET_QOS_REG_PREP(MAC_MDIO_DATA, RA, mdio->regaddr_c45);
68+
} else {
69+
ret = -EINVAL;
70+
goto done;
71+
}
6272
} else {
63-
ret = -EINVAL;
64-
goto done;
73+
if (mdio->op == MDIO_OP_C22_WRITE) {
74+
base->MAC_MDIO_DATA =
75+
/* Prepare the data to be written */
76+
ENET_QOS_REG_PREP(MAC_MDIO_DATA, GD, mdio->write_data);
77+
goc_1_code = 0b0;
78+
} else if (mdio->op == MDIO_OP_C22_READ) {
79+
goc_1_code = 0b1;
80+
} else {
81+
ret = -EINVAL;
82+
goto done;
83+
}
6584
}
6685
base->MAC_MDIO_ADDRESS &= ~(
86+
ENET_QOS_REG_PREP(MAC_MDIO_ADDRESS, C45E, 0b1) |
6787
ENET_QOS_REG_PREP(MAC_MDIO_ADDRESS, GOC_1, 0b1) |
6888
ENET_QOS_REG_PREP(MAC_MDIO_ADDRESS, GOC_0, 0b1) |
6989
ENET_QOS_REG_PREP(MAC_MDIO_ADDRESS, PA, 0b11111) |
7090
ENET_QOS_REG_PREP(MAC_MDIO_ADDRESS, RDA, 0b11111));
7191

7292
base->MAC_MDIO_ADDRESS |=
93+
/* C45E */
94+
ENET_QOS_REG_PREP(MAC_MDIO_ADDRESS, C45E, clause45) |
7395
/* OP command */
7496
ENET_QOS_REG_PREP(MAC_MDIO_ADDRESS, GOC_1, goc_1_code) |
7597
ENET_QOS_REG_PREP(MAC_MDIO_ADDRESS, GOC_0, 0b1) |
@@ -82,7 +104,6 @@ static int do_transaction(struct mdio_transaction *mdio)
82104
/* Start the transaction */
83105
ENET_QOS_REG_PREP(MAC_MDIO_ADDRESS, GB, 0b1);
84106

85-
86107
ret = -ETIMEDOUT;
87108
for (int i = CONFIG_MDIO_NXP_ENET_QOS_RECHECK_COUNT; i > 0; i--) {
88109
if (!check_busy(base)) {
@@ -97,7 +118,7 @@ static int do_transaction(struct mdio_transaction *mdio)
97118
goto done;
98119
}
99120

100-
if (mdio->op == MDIO_OP_C22_READ) {
121+
if (mdio->op == MDIO_OP_C22_READ || mdio->op == MDIO_OP_C45_READ) {
101122
uint32_t val = mdio->base->MAC_MDIO_DATA;
102123

103124
*mdio->read_data =
@@ -127,7 +148,7 @@ static int nxp_enet_qos_mdio_read(const struct device *dev,
127148
.mdio_bus_mutex = &data->mdio_mutex,
128149
};
129150

130-
return do_transaction(&mdio_read);
151+
return do_transaction(&mdio_read, false);
131152
}
132153

133154
static int nxp_enet_qos_mdio_write(const struct device *dev,
@@ -146,12 +167,52 @@ static int nxp_enet_qos_mdio_write(const struct device *dev,
146167
.mdio_bus_mutex = &data->mdio_mutex,
147168
};
148169

149-
return do_transaction(&mdio_write);
170+
return do_transaction(&mdio_write, false);
171+
}
172+
173+
static int nxp_enet_qos_mdio_read_c45(const struct device *dev, uint8_t portaddr, uint8_t devaddr,
174+
uint16_t regaddr, uint16_t *read_data)
175+
{
176+
const struct nxp_enet_qos_mdio_config *config = dev->config;
177+
struct nxp_enet_qos_mdio_data *data = dev->data;
178+
enet_qos_t *base = ENET_QOS_MODULE_CFG(config->enet_dev)->base;
179+
struct mdio_transaction mdio_read = {
180+
.op = MDIO_OP_C45_READ,
181+
.read_data = read_data,
182+
.portaddr = portaddr,
183+
.regaddr = devaddr,
184+
.regaddr_c45 = regaddr,
185+
.base = base,
186+
.mdio_bus_mutex = &data->mdio_mutex,
187+
};
188+
189+
return do_transaction(&mdio_read, true);
190+
}
191+
192+
int nxp_enet_qos_mdio_write_c45(const struct device *dev, uint8_t portaddr, uint8_t devaddr,
193+
uint16_t regaddr, uint16_t write_data)
194+
{
195+
const struct nxp_enet_qos_mdio_config *config = dev->config;
196+
struct nxp_enet_qos_mdio_data *data = dev->data;
197+
enet_qos_t *base = ENET_QOS_MODULE_CFG(config->enet_dev)->base;
198+
struct mdio_transaction mdio_write = {
199+
.op = MDIO_OP_C45_WRITE,
200+
.write_data = write_data,
201+
.portaddr = portaddr,
202+
.regaddr = devaddr,
203+
.regaddr_c45 = regaddr,
204+
.base = base,
205+
.mdio_bus_mutex = &data->mdio_mutex,
206+
};
207+
208+
return do_transaction(&mdio_write, true);
150209
}
151210

152211
static DEVICE_API(mdio, nxp_enet_qos_mdio_api) = {
153212
.read = nxp_enet_qos_mdio_read,
154213
.write = nxp_enet_qos_mdio_write,
214+
.read_c45 = nxp_enet_qos_mdio_read_c45,
215+
.write_c45 = nxp_enet_qos_mdio_write_c45,
155216
};
156217

157218
static int nxp_enet_qos_mdio_init(const struct device *dev)

0 commit comments

Comments
 (0)