Skip to content

Commit 9303ff1

Browse files
committed
drivers: ethernet: 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 3d147da commit 9303ff1

File tree

1 file changed

+34
-20
lines changed

1 file changed

+34
-20
lines changed

drivers/ethernet/phy/phy_microchip_vsc8541.c

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ struct mc_vsc8541_data {
110110
uint8_t link_monitor_thread_stack[STACK_SIZE];
111111
};
112112

113-
static int phy_mc_vsc8541_read(const struct device *dev, uint16_t reg_addr, uint32_t *data);
114-
static int phy_mc_vsc8541_write(const struct device *dev, uint16_t reg_addr, uint32_t data);
113+
static int phy_mc_vsc8541_read(const struct device *dev, uint16_t reg_addr, uint16_t *data);
114+
static int phy_mc_vsc8541_write(const struct device *dev, uint16_t reg_addr, uint16_t data);
115115
static void phy_mc_vsc8541_link_monitor(void *arg1, void *arg2, void *arg3);
116116

117117
#if CONFIG_PHY_VERIFY_DEVICE_IDENTIFICATION
@@ -123,11 +123,11 @@ static int phy_mc_vsc8541_verify_phy_id(const struct device *dev)
123123
uint16_t phy_id_1;
124124
uint16_t phy_id_2;
125125

126-
if (0 != phy_mc_vsc8541_read(dev, PHY_REG_PAGE0_ID1, (uint32_t *)&phy_id_1)) {
126+
if (0 != phy_mc_vsc8541_read(dev, PHY_REG_PAGE0_ID1, &phy_id_1)) {
127127
return -EINVAL;
128128
}
129129

130-
if (0 != phy_mc_vsc8541_read(dev, PHY_REG_PAGE0_ID2, (uint32_t *)&phy_id_2)) {
130+
if (0 != phy_mc_vsc8541_read(dev, PHY_REG_PAGE0_ID2, &phy_id_2)) {
131131
return -EINVAL;
132132
}
133133

@@ -216,7 +216,7 @@ static int phy_mc_vsc8541_reset(const struct device *dev)
216216
}
217217

218218
/* wait for phy finished software reset */
219-
uint32_t reg = 0;
219+
uint16_t reg = 0;
220220

221221
do {
222222
phy_mc_vsc8541_read(dev, PHY_REG_PAGE0_BMCR, &reg);
@@ -271,10 +271,10 @@ static int phy_mc_vsc8541_reset(const struct device *dev)
271271
static int phy_mc_vsc8541_get_speed(const struct device *dev, struct phy_link_state *state)
272272
{
273273
int ret;
274-
uint32_t status;
275-
uint32_t link10_status;
276-
uint32_t link100_status;
277-
uint32_t link1000_status;
274+
uint16_t status;
275+
uint16_t link10_status;
276+
uint16_t link100_status;
277+
uint16_t link1000_status;
278278

279279
ret = phy_mc_vsc8541_read(dev, PHY_REG_PAGE0_BMSR, &status);
280280
if (ret) {
@@ -361,8 +361,8 @@ static int phy_mc_vsc8541_init(const struct device *dev)
361361
static int phy_mc_vsc8541_get_link(const struct device *dev, struct phy_link_state *state)
362362
{
363363
int ret;
364-
uint32_t reg_sr;
365-
uint32_t reg_cr;
364+
uint16_t reg_sr;
365+
uint16_t reg_cr;
366366

367367
ret = phy_mc_vsc8541_read(dev, PHY_REG_PAGE0_BMSR, &reg_sr);
368368
if (ret) {
@@ -460,7 +460,7 @@ void phy_mc_vsc8541_link_monitor(void *arg1, void *arg2, void *arg3)
460460
* - to speed up, we store the last used page and only swap page if needed
461461
*
462462
*/
463-
static int phy_mc_vsc8541_read(const struct device *dev, uint16_t reg_addr, uint32_t *data)
463+
static int phy_mc_vsc8541_read(const struct device *dev, uint16_t reg_addr, uint16_t *data)
464464
{
465465
const struct mc_vsc8541_config *cfg = dev->config;
466466
struct mc_vsc8541_data *dev_data = dev->data;
@@ -469,7 +469,7 @@ static int phy_mc_vsc8541_read(const struct device *dev, uint16_t reg_addr, uint
469469
*data = 0U;
470470

471471
/* decode page */
472-
uint32_t page = reg_addr >> 8;
472+
uint16_t page = reg_addr >> 8;
473473

474474
/* mask out lower byte */
475475
reg_addr &= 0x00ff;
@@ -478,7 +478,7 @@ static int phy_mc_vsc8541_read(const struct device *dev, uint16_t reg_addr, uint
478478

479479
/* select page, given by register upper byte */
480480
if (dev_data->active_page != page) {
481-
ret = mdio_write(cfg->mdio_dev, cfg->addr, PHY_REG_PAGE_SELECTOR, (uint16_t)page);
481+
ret = mdio_write(cfg->mdio_dev, cfg->addr, PHY_REG_PAGE_SELECTOR, page);
482482
if (ret) {
483483
mdio_bus_disable(cfg->mdio_dev);
484484
return ret;
@@ -487,7 +487,7 @@ static int phy_mc_vsc8541_read(const struct device *dev, uint16_t reg_addr, uint
487487
}
488488

489489
/* select register, given by register lower byte */
490-
ret = mdio_read(cfg->mdio_dev, cfg->addr, reg_addr, (uint16_t *)data);
490+
ret = mdio_read(cfg->mdio_dev, cfg->addr, reg_addr, data);
491491
mdio_bus_disable(cfg->mdio_dev);
492492
if (ret) {
493493
return ret;
@@ -496,6 +496,15 @@ static int phy_mc_vsc8541_read(const struct device *dev, uint16_t reg_addr, uint
496496
return 0;
497497
}
498498

499+
/**
500+
* @brief Reading of phy register content at given address via mdio interface
501+
* For external API using uint32_t as data type
502+
*/
503+
static int phy_mc_vsc8541_read_ext(const struct device *dev, uint16_t reg_addr, uint32_t *data)
504+
{
505+
return phy_mc_vsc8541_read(dev, reg_addr, (uint16_t *)data);
506+
}
507+
499508
/**
500509
* @brief Writing of new value to phy register at given address via mdio interface
501510
*
@@ -504,14 +513,14 @@ static int phy_mc_vsc8541_read(const struct device *dev, uint16_t reg_addr, uint
504513
* - to speed up, we store the last used page and only swap page if needed
505514
*
506515
*/
507-
static int phy_mc_vsc8541_write(const struct device *dev, uint16_t reg_addr, uint32_t data)
516+
static int phy_mc_vsc8541_write(const struct device *dev, uint16_t reg_addr, uint16_t data)
508517
{
509518
const struct mc_vsc8541_config *cfg = dev->config;
510519
struct mc_vsc8541_data *dev_data = dev->data;
511520
int ret;
512521

513522
/* decode page */
514-
uint32_t page = reg_addr >> 8;
523+
uint16_t page = reg_addr >> 8;
515524

516525
/* mask out lower byte */
517526
reg_addr &= 0x00ff;
@@ -529,7 +538,7 @@ static int phy_mc_vsc8541_write(const struct device *dev, uint16_t reg_addr, uin
529538
}
530539

531540
/* write register, given by lower byte */
532-
ret = mdio_write(cfg->mdio_dev, cfg->addr, reg_addr, (uint16_t)data);
541+
ret = mdio_write(cfg->mdio_dev, cfg->addr, reg_addr, data);
533542
mdio_bus_disable(cfg->mdio_dev);
534543
if (ret) {
535544
return ret;
@@ -538,11 +547,16 @@ static int phy_mc_vsc8541_write(const struct device *dev, uint16_t reg_addr, uin
538547
return 0;
539548
}
540549

550+
static int phy_mc_vsc8541_write_ext(const struct device *dev, uint16_t reg_addr, uint32_t data)
551+
{
552+
return phy_mc_vsc8541_write(dev, reg_addr, (uint16_t)data);
553+
}
554+
541555
static DEVICE_API(ethphy, mc_vsc8541_phy_api) = {
542556
.get_link = phy_mc_vsc8541_get_link,
543557
.link_cb_set = phy_mc_vsc8541_link_cb_set,
544-
.read = phy_mc_vsc8541_read,
545-
.write = phy_mc_vsc8541_write,
558+
.read = phy_mc_vsc8541_read_ext,
559+
.write = phy_mc_vsc8541_write_ext,
546560
};
547561

548562
#if DT_ANY_INST_HAS_PROP_STATUS_OKAY(reset_gpios)

0 commit comments

Comments
 (0)