Skip to content

Commit 54f4c25

Browse files
committed
Merge branch 'phy-ackage-addr-mmd-apis'
Christian Marangi says: ==================== net: phy: add PHY package base addr + mmd APIs This small series is required for the upcoming qca807x PHY that will make use of PHY package mmd API and the new implementation with read/write based on base addr. The MMD PHY package patch currently has no use but it will be used in the upcoming patch and it does complete what a PHY package may require in addition to basic read/write to setup global PHY address. (Changelog for all the revision is present in the single patch) ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents dd78428 + d63710f commit 54f4c25

File tree

6 files changed

+266
-78
lines changed

6 files changed

+266
-78
lines changed

drivers/net/phy/bcm54140.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@
128128
#define BCM54140_DEFAULT_DOWNSHIFT 5
129129
#define BCM54140_MAX_DOWNSHIFT 9
130130

131+
enum bcm54140_global_phy {
132+
BCM54140_BASE_ADDR = 0,
133+
};
134+
131135
struct bcm54140_priv {
132136
int port;
133137
int base_addr;
@@ -429,11 +433,13 @@ static int bcm54140_base_read_rdb(struct phy_device *phydev, u16 rdb)
429433
int ret;
430434

431435
phy_lock_mdio_bus(phydev);
432-
ret = __phy_package_write(phydev, MII_BCM54XX_RDB_ADDR, rdb);
436+
ret = __phy_package_write(phydev, BCM54140_BASE_ADDR,
437+
MII_BCM54XX_RDB_ADDR, rdb);
433438
if (ret < 0)
434439
goto out;
435440

436-
ret = __phy_package_read(phydev, MII_BCM54XX_RDB_DATA);
441+
ret = __phy_package_read(phydev, BCM54140_BASE_ADDR,
442+
MII_BCM54XX_RDB_DATA);
437443

438444
out:
439445
phy_unlock_mdio_bus(phydev);
@@ -446,11 +452,13 @@ static int bcm54140_base_write_rdb(struct phy_device *phydev,
446452
int ret;
447453

448454
phy_lock_mdio_bus(phydev);
449-
ret = __phy_package_write(phydev, MII_BCM54XX_RDB_ADDR, rdb);
455+
ret = __phy_package_write(phydev, BCM54140_BASE_ADDR,
456+
MII_BCM54XX_RDB_ADDR, rdb);
450457
if (ret < 0)
451458
goto out;
452459

453-
ret = __phy_package_write(phydev, MII_BCM54XX_RDB_DATA, val);
460+
ret = __phy_package_write(phydev, BCM54140_BASE_ADDR,
461+
MII_BCM54XX_RDB_DATA, val);
454462

455463
out:
456464
phy_unlock_mdio_bus(phydev);

drivers/net/phy/mscc/mscc.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,11 @@ struct vsc8531_private {
416416
* gpio_lock: used for PHC operations. Common for all PHYs as the load/save GPIO
417417
* is shared.
418418
*/
419+
420+
enum vsc85xx_global_phy {
421+
VSC88XX_BASE_ADDR = 0,
422+
};
423+
419424
struct vsc85xx_shared_private {
420425
struct mutex gpio_lock;
421426
};

drivers/net/phy/mscc/mscc_main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ int phy_base_write(struct phy_device *phydev, u32 regnum, u16 val)
711711
dump_stack();
712712
}
713713

714-
return __phy_package_write(phydev, regnum, val);
714+
return __phy_package_write(phydev, VSC88XX_BASE_ADDR, regnum, val);
715715
}
716716

717717
/* phydev->bus->mdio_lock should be locked when using this function */
@@ -722,7 +722,7 @@ int phy_base_read(struct phy_device *phydev, u32 regnum)
722722
dump_stack();
723723
}
724724

725-
return __phy_package_read(phydev, regnum);
725+
return __phy_package_read(phydev, VSC88XX_BASE_ADDR, regnum);
726726
}
727727

728728
u32 vsc85xx_csr_read(struct phy_device *phydev,

drivers/net/phy/phy-core.c

Lines changed: 170 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,28 @@ static void mmd_phy_indirect(struct mii_bus *bus, int phy_addr, int devad,
540540
devad | MII_MMD_CTRL_NOINCR);
541541
}
542542

543+
static int mmd_phy_read(struct mii_bus *bus, int phy_addr, bool is_c45,
544+
int devad, u32 regnum)
545+
{
546+
if (is_c45)
547+
return __mdiobus_c45_read(bus, phy_addr, devad, regnum);
548+
549+
mmd_phy_indirect(bus, phy_addr, devad, regnum);
550+
/* Read the content of the MMD's selected register */
551+
return __mdiobus_read(bus, phy_addr, MII_MMD_DATA);
552+
}
553+
554+
static int mmd_phy_write(struct mii_bus *bus, int phy_addr, bool is_c45,
555+
int devad, u32 regnum, u16 val)
556+
{
557+
if (is_c45)
558+
return __mdiobus_c45_write(bus, phy_addr, devad, regnum, val);
559+
560+
mmd_phy_indirect(bus, phy_addr, devad, regnum);
561+
/* Write the data into MMD's selected register */
562+
return __mdiobus_write(bus, phy_addr, MII_MMD_DATA, val);
563+
}
564+
543565
/**
544566
* __phy_read_mmd - Convenience function for reading a register
545567
* from an MMD on a given PHY.
@@ -551,26 +573,14 @@ static void mmd_phy_indirect(struct mii_bus *bus, int phy_addr, int devad,
551573
*/
552574
int __phy_read_mmd(struct phy_device *phydev, int devad, u32 regnum)
553575
{
554-
int val;
555-
556576
if (regnum > (u16)~0 || devad > 32)
557577
return -EINVAL;
558578

559-
if (phydev->drv && phydev->drv->read_mmd) {
560-
val = phydev->drv->read_mmd(phydev, devad, regnum);
561-
} else if (phydev->is_c45) {
562-
val = __mdiobus_c45_read(phydev->mdio.bus, phydev->mdio.addr,
563-
devad, regnum);
564-
} else {
565-
struct mii_bus *bus = phydev->mdio.bus;
566-
int phy_addr = phydev->mdio.addr;
567-
568-
mmd_phy_indirect(bus, phy_addr, devad, regnum);
579+
if (phydev->drv && phydev->drv->read_mmd)
580+
return phydev->drv->read_mmd(phydev, devad, regnum);
569581

570-
/* Read the content of the MMD's selected register */
571-
val = __mdiobus_read(bus, phy_addr, MII_MMD_DATA);
572-
}
573-
return val;
582+
return mmd_phy_read(phydev->mdio.bus, phydev->mdio.addr,
583+
phydev->is_c45, devad, regnum);
574584
}
575585
EXPORT_SYMBOL(__phy_read_mmd);
576586

@@ -607,28 +617,14 @@ EXPORT_SYMBOL(phy_read_mmd);
607617
*/
608618
int __phy_write_mmd(struct phy_device *phydev, int devad, u32 regnum, u16 val)
609619
{
610-
int ret;
611-
612620
if (regnum > (u16)~0 || devad > 32)
613621
return -EINVAL;
614622

615-
if (phydev->drv && phydev->drv->write_mmd) {
616-
ret = phydev->drv->write_mmd(phydev, devad, regnum, val);
617-
} else if (phydev->is_c45) {
618-
ret = __mdiobus_c45_write(phydev->mdio.bus, phydev->mdio.addr,
619-
devad, regnum, val);
620-
} else {
621-
struct mii_bus *bus = phydev->mdio.bus;
622-
int phy_addr = phydev->mdio.addr;
623-
624-
mmd_phy_indirect(bus, phy_addr, devad, regnum);
623+
if (phydev->drv && phydev->drv->write_mmd)
624+
return phydev->drv->write_mmd(phydev, devad, regnum, val);
625625

626-
/* Write the data into MMD's selected register */
627-
__mdiobus_write(bus, phy_addr, MII_MMD_DATA, val);
628-
629-
ret = 0;
630-
}
631-
return ret;
626+
return mmd_phy_write(phydev->mdio.bus, phydev->mdio.addr,
627+
phydev->is_c45, devad, regnum, val);
632628
}
633629
EXPORT_SYMBOL(__phy_write_mmd);
634630

@@ -654,6 +650,146 @@ int phy_write_mmd(struct phy_device *phydev, int devad, u32 regnum, u16 val)
654650
}
655651
EXPORT_SYMBOL(phy_write_mmd);
656652

653+
/**
654+
* __phy_package_read_mmd - read MMD reg relative to PHY package base addr
655+
* @phydev: The phy_device struct
656+
* @addr_offset: The offset to be added to PHY package base_addr
657+
* @devad: The MMD to read from
658+
* @regnum: The register on the MMD to read
659+
*
660+
* Convenience helper for reading a register of an MMD on a given PHY
661+
* using the PHY package base address. The base address is added to
662+
* the addr_offset value.
663+
*
664+
* Same calling rules as for __phy_read();
665+
*
666+
* NOTE: It's assumed that the entire PHY package is either C22 or C45.
667+
*/
668+
int __phy_package_read_mmd(struct phy_device *phydev,
669+
unsigned int addr_offset, int devad,
670+
u32 regnum)
671+
{
672+
int addr = phy_package_address(phydev, addr_offset);
673+
674+
if (addr < 0)
675+
return addr;
676+
677+
if (regnum > (u16)~0 || devad > 32)
678+
return -EINVAL;
679+
680+
return mmd_phy_read(phydev->mdio.bus, addr, phydev->is_c45, devad,
681+
regnum);
682+
}
683+
EXPORT_SYMBOL(__phy_package_read_mmd);
684+
685+
/**
686+
* phy_package_read_mmd - read MMD reg relative to PHY package base addr
687+
* @phydev: The phy_device struct
688+
* @addr_offset: The offset to be added to PHY package base_addr
689+
* @devad: The MMD to read from
690+
* @regnum: The register on the MMD to read
691+
*
692+
* Convenience helper for reading a register of an MMD on a given PHY
693+
* using the PHY package base address. The base address is added to
694+
* the addr_offset value.
695+
*
696+
* Same calling rules as for phy_read();
697+
*
698+
* NOTE: It's assumed that the entire PHY package is either C22 or C45.
699+
*/
700+
int phy_package_read_mmd(struct phy_device *phydev,
701+
unsigned int addr_offset, int devad,
702+
u32 regnum)
703+
{
704+
int addr = phy_package_address(phydev, addr_offset);
705+
int val;
706+
707+
if (addr < 0)
708+
return addr;
709+
710+
if (regnum > (u16)~0 || devad > 32)
711+
return -EINVAL;
712+
713+
phy_lock_mdio_bus(phydev);
714+
val = mmd_phy_read(phydev->mdio.bus, addr, phydev->is_c45, devad,
715+
regnum);
716+
phy_unlock_mdio_bus(phydev);
717+
718+
return val;
719+
}
720+
EXPORT_SYMBOL(phy_package_read_mmd);
721+
722+
/**
723+
* __phy_package_write_mmd - write MMD reg relative to PHY package base addr
724+
* @phydev: The phy_device struct
725+
* @addr_offset: The offset to be added to PHY package base_addr
726+
* @devad: The MMD to write to
727+
* @regnum: The register on the MMD to write
728+
* @val: value to write to @regnum
729+
*
730+
* Convenience helper for writing a register of an MMD on a given PHY
731+
* using the PHY package base address. The base address is added to
732+
* the addr_offset value.
733+
*
734+
* Same calling rules as for __phy_write();
735+
*
736+
* NOTE: It's assumed that the entire PHY package is either C22 or C45.
737+
*/
738+
int __phy_package_write_mmd(struct phy_device *phydev,
739+
unsigned int addr_offset, int devad,
740+
u32 regnum, u16 val)
741+
{
742+
int addr = phy_package_address(phydev, addr_offset);
743+
744+
if (addr < 0)
745+
return addr;
746+
747+
if (regnum > (u16)~0 || devad > 32)
748+
return -EINVAL;
749+
750+
return mmd_phy_write(phydev->mdio.bus, addr, phydev->is_c45, devad,
751+
regnum, val);
752+
}
753+
EXPORT_SYMBOL(__phy_package_write_mmd);
754+
755+
/**
756+
* phy_package_write_mmd - write MMD reg relative to PHY package base addr
757+
* @phydev: The phy_device struct
758+
* @addr_offset: The offset to be added to PHY package base_addr
759+
* @devad: The MMD to write to
760+
* @regnum: The register on the MMD to write
761+
* @val: value to write to @regnum
762+
*
763+
* Convenience helper for writing a register of an MMD on a given PHY
764+
* using the PHY package base address. The base address is added to
765+
* the addr_offset value.
766+
*
767+
* Same calling rules as for phy_write();
768+
*
769+
* NOTE: It's assumed that the entire PHY package is either C22 or C45.
770+
*/
771+
int phy_package_write_mmd(struct phy_device *phydev,
772+
unsigned int addr_offset, int devad,
773+
u32 regnum, u16 val)
774+
{
775+
int addr = phy_package_address(phydev, addr_offset);
776+
int ret;
777+
778+
if (addr < 0)
779+
return addr;
780+
781+
if (regnum > (u16)~0 || devad > 32)
782+
return -EINVAL;
783+
784+
phy_lock_mdio_bus(phydev);
785+
ret = mmd_phy_write(phydev->mdio.bus, addr, phydev->is_c45, devad,
786+
regnum, val);
787+
phy_unlock_mdio_bus(phydev);
788+
789+
return ret;
790+
}
791+
EXPORT_SYMBOL(phy_package_write_mmd);
792+
657793
/**
658794
* phy_modify_changed - Function for modifying a PHY register
659795
* @phydev: the phy_device struct

0 commit comments

Comments
 (0)