Skip to content

Commit 346ed0c

Browse files
committed
drivers: ethernet: phy: vsc8541: Use 16-bit values for MDIO access
The internal register read/write functions used uint32_t for the values even though the registers are only 16 bits wide, resulting in a bunch of casting. Change the internal functions to use uint16_t and wrap them for the external read/write API which uses uint32_t. Signed-off-by: Robert Hancock <robert.hancock@calian.com>
1 parent 3ed64ec commit 346ed0c

File tree

1 file changed

+38
-20
lines changed

1 file changed

+38
-20
lines changed

drivers/ethernet/phy/phy_microchip_vsc8541.c

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ struct mc_vsc8541_data {
8989
uint8_t link_monitor_thread_stack[STACK_SIZE];
9090
};
9191

92-
static int phy_mc_vsc8541_read(const struct device *dev, uint16_t reg_addr, uint32_t *data);
93-
static int phy_mc_vsc8541_write(const struct device *dev, uint16_t reg_addr, uint32_t data);
92+
static int phy_mc_vsc8541_read(const struct device *dev, uint16_t reg_addr, uint16_t *data);
93+
static int phy_mc_vsc8541_write(const struct device *dev, uint16_t reg_addr, uint16_t data);
9494
static void phy_mc_vsc8541_link_monitor(void *arg1, void *arg2, void *arg3);
9595

9696
#if CONFIG_PHY_VERIFY_DEVICE_IDENTIFICATION
@@ -102,11 +102,11 @@ static int phy_mc_vsc8541_verify_phy_id(const struct device *dev)
102102
uint16_t phy_id_1;
103103
uint16_t phy_id_2;
104104

105-
if (phy_mc_vsc8541_read(dev, MII_PHYID1R, (uint32_t *)&phy_id_1) < 0) {
105+
if (phy_mc_vsc8541_read(dev, MII_PHYID1R, &phy_id_1) < 0) {
106106
return -EINVAL;
107107
}
108108

109-
if (phy_mc_vsc8541_read(dev, MII_PHYID2R, (uint32_t *)&phy_id_2) < 0) {
109+
if (phy_mc_vsc8541_read(dev, MII_PHYID2R, &phy_id_2) < 0) {
110110
return -EINVAL;
111111
}
112112

@@ -133,7 +133,7 @@ static int phy_mc_vsc8541_reset(const struct device *dev)
133133
{
134134
const struct mc_vsc8541_config *cfg = dev->config;
135135
int ret;
136-
uint32_t reg = 0U;
136+
uint16_t reg = 0U;
137137

138138
#if DT_ANY_INST_HAS_PROP_STATUS_OKAY(reset_gpios)
139139

@@ -219,10 +219,10 @@ static int phy_mc_vsc8541_reset(const struct device *dev)
219219
static int phy_mc_vsc8541_get_speed(const struct device *dev, struct phy_link_state *state)
220220
{
221221
int ret;
222-
uint32_t aux_status;
223-
uint32_t link10_status;
224-
uint32_t link100_status;
225-
uint32_t link1000_status;
222+
uint16_t aux_status;
223+
uint16_t link10_status;
224+
uint16_t link100_status;
225+
uint16_t link1000_status;
226226
bool is_duplex;
227227

228228
ret = phy_mc_vsc8541_read(dev, PHY_REG_PAGE0_EXT_DEV_AUX, &aux_status);
@@ -317,8 +317,8 @@ static int phy_mc_vsc8541_init(const struct device *dev)
317317
static int phy_mc_vsc8541_get_link(const struct device *dev, struct phy_link_state *state)
318318
{
319319
int ret;
320-
uint32_t reg_sr;
321-
uint32_t reg_cr;
320+
uint16_t reg_sr;
321+
uint16_t reg_cr;
322322
bool hasLink;
323323
bool auto_negotiation_finished = true;
324324

@@ -412,7 +412,7 @@ void phy_mc_vsc8541_link_monitor(void *arg1, void *arg2, void *arg3)
412412
* - to speed up, we store the last used page and only swap page if needed
413413
*
414414
*/
415-
static int phy_mc_vsc8541_read(const struct device *dev, uint16_t reg_addr, uint32_t *data)
415+
static int phy_mc_vsc8541_read(const struct device *dev, uint16_t reg_addr, uint16_t *data)
416416
{
417417
const struct mc_vsc8541_config *cfg = dev->config;
418418
struct mc_vsc8541_data *dev_data = dev->data;
@@ -421,7 +421,7 @@ static int phy_mc_vsc8541_read(const struct device *dev, uint16_t reg_addr, uint
421421
*data = 0U;
422422

423423
/* decode page */
424-
uint32_t page = reg_addr >> 8;
424+
uint16_t page = reg_addr >> 8;
425425

426426
/* mask out lower byte */
427427
reg_addr &= 0x00ff;
@@ -431,15 +431,15 @@ static int phy_mc_vsc8541_read(const struct device *dev, uint16_t reg_addr, uint
431431

432432
/* select page, given by register upper byte */
433433
if (dev_data->active_page != page) {
434-
ret = mdio_write(cfg->mdio_dev, cfg->addr, PHY_REG_PAGE_SELECTOR, (uint16_t)page);
434+
ret = mdio_write(cfg->mdio_dev, cfg->addr, PHY_REG_PAGE_SELECTOR, page);
435435
if (ret < 0) {
436436
goto read_end;
437437
}
438438
dev_data->active_page = (int)page;
439439
}
440440

441441
/* select register, given by register lower byte */
442-
ret = mdio_read(cfg->mdio_dev, cfg->addr, reg_addr, (uint16_t *)data);
442+
ret = mdio_read(cfg->mdio_dev, cfg->addr, reg_addr, data);
443443

444444
read_end:
445445
mdio_bus_disable(cfg->mdio_dev);
@@ -448,6 +448,15 @@ static int phy_mc_vsc8541_read(const struct device *dev, uint16_t reg_addr, uint
448448
return ret;
449449
}
450450

451+
/**
452+
* @brief Reading of phy register content at given address via mdio interface
453+
* For external API using uint32_t as data type
454+
*/
455+
static int phy_mc_vsc8541_read_ext(const struct device *dev, uint16_t reg_addr, uint32_t *data)
456+
{
457+
return phy_mc_vsc8541_read(dev, reg_addr, (uint16_t *)data);
458+
}
459+
451460
/**
452461
* @brief Writing of new value to phy register at given address via mdio interface
453462
*
@@ -456,14 +465,14 @@ static int phy_mc_vsc8541_read(const struct device *dev, uint16_t reg_addr, uint
456465
* - to speed up, we store the last used page and only swap page if needed
457466
*
458467
*/
459-
static int phy_mc_vsc8541_write(const struct device *dev, uint16_t reg_addr, uint32_t data)
468+
static int phy_mc_vsc8541_write(const struct device *dev, uint16_t reg_addr, uint16_t data)
460469
{
461470
const struct mc_vsc8541_config *cfg = dev->config;
462471
struct mc_vsc8541_data *dev_data = dev->data;
463472
int ret;
464473

465474
/* decode page */
466-
uint32_t page = reg_addr >> 8;
475+
uint16_t page = reg_addr >> 8;
467476

468477
/* mask out lower byte */
469478
reg_addr &= 0x00ff;
@@ -481,7 +490,7 @@ static int phy_mc_vsc8541_write(const struct device *dev, uint16_t reg_addr, uin
481490
}
482491

483492
/* write register, given by lower byte */
484-
ret = mdio_write(cfg->mdio_dev, cfg->addr, reg_addr, (uint16_t)data);
493+
ret = mdio_write(cfg->mdio_dev, cfg->addr, reg_addr, data);
485494

486495
write_end:
487496
mdio_bus_disable(cfg->mdio_dev);
@@ -490,12 +499,21 @@ static int phy_mc_vsc8541_write(const struct device *dev, uint16_t reg_addr, uin
490499
return ret;
491500
}
492501

502+
/**
503+
* @brief Writing of new value to phy register at given address via mdio interface
504+
* For external API using uint32_t as data type
505+
*/
506+
static int phy_mc_vsc8541_write_ext(const struct device *dev, uint16_t reg_addr, uint32_t data)
507+
{
508+
return phy_mc_vsc8541_write(dev, reg_addr, (uint16_t)data);
509+
}
510+
493511
static DEVICE_API(ethphy, mc_vsc8541_phy_api) = {
494512
.get_link = phy_mc_vsc8541_get_link,
495513
.cfg_link = phy_mc_vsc8541_cfg_link,
496514
.link_cb_set = phy_mc_vsc8541_link_cb_set,
497-
.read = phy_mc_vsc8541_read,
498-
.write = phy_mc_vsc8541_write,
515+
.read = phy_mc_vsc8541_read_ext,
516+
.write = phy_mc_vsc8541_write_ext,
499517
};
500518

501519
#if DT_ANY_INST_HAS_PROP_STATUS_OKAY(reset_gpios)

0 commit comments

Comments
 (0)