Skip to content

Commit e3d8296

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 2a996cf commit e3d8296

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) {
@@ -470,7 +470,7 @@ void phy_mc_vsc8541_link_monitor(void *arg1, void *arg2, void *arg3)
470470
* - to speed up, we store the last used page and only swap page if needed
471471
*
472472
*/
473-
static int phy_mc_vsc8541_read(const struct device *dev, uint16_t reg_addr, uint32_t *data)
473+
static int phy_mc_vsc8541_read(const struct device *dev, uint16_t reg_addr, uint16_t *data)
474474
{
475475
const struct mc_vsc8541_config *cfg = dev->config;
476476
struct mc_vsc8541_data *dev_data = dev->data;
@@ -479,7 +479,7 @@ static int phy_mc_vsc8541_read(const struct device *dev, uint16_t reg_addr, uint
479479
*data = 0U;
480480

481481
/* decode page */
482-
uint32_t page = reg_addr >> 8;
482+
uint16_t page = reg_addr >> 8;
483483

484484
/* mask out lower byte */
485485
reg_addr &= 0x00ff;
@@ -488,7 +488,7 @@ static int phy_mc_vsc8541_read(const struct device *dev, uint16_t reg_addr, uint
488488

489489
/* select page, given by register upper byte */
490490
if (dev_data->active_page != page) {
491-
ret = mdio_write(cfg->mdio_dev, cfg->addr, PHY_REG_PAGE_SELECTOR, (uint16_t)page);
491+
ret = mdio_write(cfg->mdio_dev, cfg->addr, PHY_REG_PAGE_SELECTOR, page);
492492
if (ret) {
493493
mdio_bus_disable(cfg->mdio_dev);
494494
return ret;
@@ -497,7 +497,7 @@ static int phy_mc_vsc8541_read(const struct device *dev, uint16_t reg_addr, uint
497497
}
498498

499499
/* select register, given by register lower byte */
500-
ret = mdio_read(cfg->mdio_dev, cfg->addr, reg_addr, (uint16_t *)data);
500+
ret = mdio_read(cfg->mdio_dev, cfg->addr, reg_addr, data);
501501
mdio_bus_disable(cfg->mdio_dev);
502502
if (ret) {
503503
return ret;
@@ -506,6 +506,15 @@ static int phy_mc_vsc8541_read(const struct device *dev, uint16_t reg_addr, uint
506506
return 0;
507507
}
508508

509+
/**
510+
* @brief Reading of phy register content at given address via mdio interface
511+
* For external API using uint32_t as data type
512+
*/
513+
static int phy_mc_vsc8541_read_ext(const struct device *dev, uint16_t reg_addr, uint32_t *data)
514+
{
515+
return phy_mc_vsc8541_read(dev, reg_addr, (uint16_t *)data);
516+
}
517+
509518
/**
510519
* @brief Writing of new value to phy register at given address via mdio interface
511520
*
@@ -514,14 +523,14 @@ static int phy_mc_vsc8541_read(const struct device *dev, uint16_t reg_addr, uint
514523
* - to speed up, we store the last used page and only swap page if needed
515524
*
516525
*/
517-
static int phy_mc_vsc8541_write(const struct device *dev, uint16_t reg_addr, uint32_t data)
526+
static int phy_mc_vsc8541_write(const struct device *dev, uint16_t reg_addr, uint16_t data)
518527
{
519528
const struct mc_vsc8541_config *cfg = dev->config;
520529
struct mc_vsc8541_data *dev_data = dev->data;
521530
int ret;
522531

523532
/* decode page */
524-
uint32_t page = reg_addr >> 8;
533+
uint16_t page = reg_addr >> 8;
525534

526535
/* mask out lower byte */
527536
reg_addr &= 0x00ff;
@@ -539,7 +548,7 @@ static int phy_mc_vsc8541_write(const struct device *dev, uint16_t reg_addr, uin
539548
}
540549

541550
/* write register, given by lower byte */
542-
ret = mdio_write(cfg->mdio_dev, cfg->addr, reg_addr, (uint16_t)data);
551+
ret = mdio_write(cfg->mdio_dev, cfg->addr, reg_addr, data);
543552
mdio_bus_disable(cfg->mdio_dev);
544553
if (ret) {
545554
return ret;
@@ -548,12 +557,17 @@ static int phy_mc_vsc8541_write(const struct device *dev, uint16_t reg_addr, uin
548557
return 0;
549558
}
550559

560+
static int phy_mc_vsc8541_write_ext(const struct device *dev, uint16_t reg_addr, uint32_t data)
561+
{
562+
return phy_mc_vsc8541_write(dev, reg_addr, (uint16_t)data);
563+
}
564+
551565
static DEVICE_API(ethphy, mc_vsc8541_phy_api) = {
552566
.get_link = phy_mc_vsc8541_get_link,
553567
.cfg_link = phy_mc_vsc8541_cfg_link,
554568
.link_cb_set = phy_mc_vsc8541_link_cb_set,
555-
.read = phy_mc_vsc8541_read,
556-
.write = phy_mc_vsc8541_write,
569+
.read = phy_mc_vsc8541_read_ext,
570+
.write = phy_mc_vsc8541_write_ext,
557571
};
558572

559573
#if DT_ANY_INST_HAS_PROP_STATUS_OKAY(reset_gpios)

0 commit comments

Comments
 (0)