net: phy: broadcom: add helper to write/read RDB registers
Subsystems (6)
PATCH v3 1/3 net: phy: broadcom: add helper to write/read RDB registers
RDB (Register Data Base) registers are used on newer Broadcom PHYs. Add helper to read, write and modify these registers.
---
changes since v2:
none
changes since v1:
- corrected typo
- added Reviewed-by
drivers/net/phy/bcm-phy-lib.c | 80 +++++++++++++++++++++++++++++++++++ drivers/net/phy/bcm-phy-lib.h | 9 ++++ include/linux/brcmphy.h | 3 ++ 3 files changed, 92 insertions(+)
drivers/net/phy/bcm-phy-lib.c +80 -0
@@ -155,6 +155,86 @@ int bcm_phy_write_shadow(struct phy_device *phydev, u16 shadow, }EXPORT_SYMBOL_GPL (bcm_phy_write_shadow); +int __bcm_phy_read_rdb (struct phy_device *phydev,u16 rdb) +{ +int val; + + val =__phy_write (phydev,MII_BCM54XX_RDB_ADDR , rdb); +if (val <0 ) +return val; + +return __phy_read (phydev,MII_BCM54XX_RDB_DATA ); +} +EXPORT_SYMBOL_GPL (__bcm_phy_read_rdb); + +int bcm_phy_read_rdb (struct phy_device *phydev,u16 rdb) +{ +int ret; + +phy_lock_mdio_bus (phydev); + ret =__bcm_phy_read_rdb (phydev, rdb); +phy_unlock_mdio_bus (phydev); + +return ret; +} +EXPORT_SYMBOL_GPL (bcm_phy_read_rdb); + +int __bcm_phy_write_rdb (struct phy_device *phydev,u16 rdb,u16 val) +{ +int ret; + + ret =__phy_write (phydev,MII_BCM54XX_RDB_ADDR , rdb); +if (ret <0 ) +return ret; + +return __phy_write (phydev,MII_BCM54XX_RDB_DATA , val); +} +EXPORT_SYMBOL_GPL (__bcm_phy_write_rdb); + +int bcm_phy_write_rdb (struct phy_device *phydev,u16 rdb,u16 val) +{ +int ret; + +phy_lock_mdio_bus (phydev); + ret =__bcm_phy_write_rdb (phydev, rdb, val); +phy_unlock_mdio_bus (phydev); + +return ret; +} +EXPORT_SYMBOL_GPL (bcm_phy_write_rdb); + +int __bcm_phy_modify_rdb (struct phy_device *phydev,u16 rdb,u16 mask,u16 set) +{ +int new, ret; + + ret =__phy_write (phydev,MII_BCM54XX_RDB_ADDR , rdb); +if (ret <0 ) +return ret; + + ret =__phy_read (phydev,MII_BCM54XX_RDB_DATA ); +if (ret <0 ) +return ret; + + new = (ret & ~mask) | set; +if (new == ret) +return 0 ; + +return __phy_write (phydev,MII_BCM54XX_RDB_DATA , new); +} +EXPORT_SYMBOL_GPL (__bcm_phy_modify_rdb); + +int bcm_phy_modify_rdb (struct phy_device *phydev,u16 rdb,u16 mask,u16 set) +{ +int ret; + +phy_lock_mdio_bus (phydev); + ret =__bcm_phy_modify_rdb (phydev, rdb, mask, set); +phy_unlock_mdio_bus (phydev); + +return ret; +} +EXPORT_SYMBOL_GPL (bcm_phy_modify_rdb); +int bcm_phy_enable_apd (struct phy_device *phydev,bool dll_pwr_down) {int val;
drivers/net/phy/bcm-phy-lib.h +9 -0
@@ -48,6 +48,15 @@ int bcm_phy_write_shadow(struct phy_device *phydev, u16 shadow, u16 val);int bcm_phy_read_shadow (struct phy_device *phydev,u16 shadow); +int __bcm_phy_write_rdb (struct phy_device *phydev,u16 rdb,u16 val); +int bcm_phy_write_rdb (struct phy_device *phydev,u16 rdb,u16 val); +int __bcm_phy_read_rdb (struct phy_device *phydev,u16 rdb); +int bcm_phy_read_rdb (struct phy_device *phydev,u16 rdb); +int __bcm_phy_modify_rdb (struct phy_device *phydev,u16 rdb,u16 mask, +u16 set); +int bcm_phy_modify_rdb (struct phy_device *phydev,u16 rdb,u16 mask, +u16 set); +int bcm_phy_ack_intr (struct phy_device *phydev);int bcm_phy_config_intr (struct phy_device *phydev);
include/linux/brcmphy.h +3 -0
@@ -115,6 +115,9 @@#define MII_BCM54XX_SHD_VAL (x) ((x & 0x1f) << 10)#define MII_BCM54XX_SHD_DATA (x) ((x & 0x3ff) << 0) +#define MII_BCM54XX_RDB_ADDR 0x1e +#define MII_BCM54XX_RDB_DATA 0x1f +/* * AUXILIARY CONTROL SHADOW ACCESS REGISTERS. (PHY REG 0x18) */
Signature · 1 line
2.20.1
PATCH v3 2/3 net: phy: add Broadcom BCM54140 support
The Broadcom BCM54140 is a Quad SGMII/QSGMII Copper/Fiber Gigabit Ethernet transceiver.
This also adds support for tunables to set and get downshift and energy detect auto power-down.
The PHY has four ports and each port has its own PHY address. There are per-port registers as well as global registers. Unfortunately, the global registers can only be accessed by reading and writing from/to the PHY address of the first port. Further, there is no way to find out what port you actually are by just reading the per-port registers. We therefore, have to scan the bus on the PHY probe to determine the port and thus what address we need to access the global registers.
---
changes since v2:
- consistent naming eg. bcm54140_phy_xx -> bcm54140_xx
- add comment about the errata
- corrected comment about the LED mode
- convert dev_info() to phydev_dbg()
changes since v1:
none
drivers/net/phy/Kconfig | 10 + drivers/net/phy/Makefile | 1 + drivers/net/phy/bcm54140.c | 481 +++++++++++++++++++++++++++++++++++++ include/linux/brcmphy.h | 1 + 4 files changed, 493 insertions(+) create mode 100644 drivers/net/phy/bcm54140.c
drivers/net/phy/Kconfig +10 -0
@@ -346,6 +346,16 @@ config BROADCOM_PHY Currently supports the BCM5411, BCM5421, BCM5461, BCM54616S, BCM5464, BCM5481, BCM54810 and BCM5482 PHYs. +config BCM54140_PHY + tristate "Broadcom BCM54140 PHY" + depends on PHYLIB + select BCM_NET_PHYLIB + help + Support the Broadcom BCM54140 Quad SGMII/QSGMII PHY. + + This driver also supports the hardware monitoring of this PHY and + exposes voltage and temperature sensors. + config BCM84881_PHY tristate "Broadcom BCM84881 PHY" depends on PHYLIB
drivers/net/phy/Makefile +1 -0
@@ -68,6 +68,7 @@ obj-$(CONFIG_BCM87XX_PHY) += bcm87xx.o obj-$(CONFIG_BCM_CYGNUS_PHY) += bcm-cygnus.o obj-$(CONFIG_BCM_NET_PHYLIB) += bcm-phy-lib.o obj-$(CONFIG_BROADCOM_PHY) += broadcom.o +obj-$(CONFIG_BCM54140_PHY) += bcm54140.o obj-$(CONFIG_BCM84881_PHY) += bcm84881.o obj-$(CONFIG_CICADA_PHY) += cicada.o obj-$(CONFIG_CORTINA_PHY) += cortina.o
drivers/net/phy/bcm54140.c new file +481 -0
481 lines not on this page · raw message
include/linux/brcmphy.h +1 -0
@@ -25,6 +25,7 @@#define PHY_ID_BCM5461 0x002060c0#define PHY_ID_BCM54612E 0x03625e60#define PHY_ID_BCM54616S 0x03625d10 +#define PHY_ID_BCM54140 0xae025019#define PHY_ID_BCM57780 0x03625d90#define PHY_ID_BCM89610 0x03625cd0
Signature · 1 line
2.20.1
Re: [PATCH net-next v3 2/3] net: phy: add Broadcom BCM54140 support
Quoted 15 lines · Michael Walle
The Broadcom BCM54140 is a Quad SGMII/QSGMII Copper/Fiber Gigabit Ethernet transceiver.
This also adds support for tunables to set and get downshift and energy detect auto power-down.
The PHY has four ports and each port has its own PHY address. There are per-port registers as well as global registers. Unfortunately, the global registers can only be accessed by reading and writing from/to the PHY address of the first port. Further, there is no way to find out what port you actually are by just reading the per-port registers. We therefore, have to scan the bus on the PHY probe to determine the port and thus what address we need to access the global registers.
Quoted 1 line
Signed-off-by Michael Walle <[email protected]>
Andrew
Re: [PATCH net-next v3 2/3] net: phy: add Broadcom BCM54140 support
In reply to Michael WalleFrom: Michael Walle <[email protected]>
Date: Mon, 20 Apr 2020 20:21:12 +0200
Quoted 15 lines
The Broadcom BCM54140 is a Quad SGMII/QSGMII Copper/Fiber Gigabit Ethernet transceiver.
This also adds support for tunables to set and get downshift and energy detect auto power-down.
The PHY has four ports and each port has its own PHY address. There are per-port registers as well as global registers. Unfortunately, the global registers can only be accessed by reading and writing from/to the PHY address of the first port. Further, there is no way to find out what port you actually are by just reading the per-port registers. We therefore, have to scan the bus on the PHY probe to determine the port and thus what address we need to access the global registers.
Quoted 1 line
Signed-off-by Michael Walle <[email protected]>
Applied.
PATCH v3 3/3 net: phy: bcm54140: add hwmon support
In reply to Michael WalleThe PHY supports monitoring its die temperature as well as two analog voltages. Add support for it.
---
changes since v2:
- fixed messed up #if IS_ENABLED(CONFIG_HWMON) fences
- removed channel parameter from bcm54140_hwmon_read_temp()
changes since v1:
- add IS_ENABLED(CONFIG_HWMON) guards
- clamp values before conversion
- add mutex alarm_lock
- use mdiobus_get_phy()
- make CONFIG_BCM54140_PHY depend on HWMON (or disabled altogether)
- add BCM54140_HWMON_IN_xx(ch) macros
Btw. is it possible to rely on the compiler to strip away unused function calls. For exmaple, instead of using the
#if IS_ENABLED(CONFIG_HWMON) guards, one could use the following:
if (IS_ENABLED(CONFIG_HWMON))
if (!bcm54140_is_pkg_init(phydev)) {
ret = bcm54140_phy_probe_once(phydev);
if (ret)
return ret;
}
}This will then optimize away the devm_hwmon_device_register() call.
Documentation/hwmon/bcm54140.rst | 45 ++++ Documentation/hwmon/index.rst | 1 + drivers/net/phy/Kconfig | 1 + drivers/net/phy/bcm54140.c | 396 +++++++++++++++++++++++++++++++ 4 files changed, 443 insertions(+) create mode 100644 Documentation/hwmon/bcm54140.rst
Documentation/hwmon/bcm54140.rst new file +45 -0
@@ -0,0 +1,45 @@ +.. SPDX-License-Identifier: GPL-2.0-only + +Broadcom BCM54140 Quad SGMII/QSGMII PHY +======================================= + +Supported chips: + + * Broadcom BCM54140 + + Datasheet: not public + +Author: Michael Walle <[email protected]> + +Description +----------- + +The Broadcom BCM54140 is a Quad SGMII/QSGMII PHY which supports monitoring +its die temperature as well as two analog voltages. + +The AVDDL is a 1.0V analogue voltage, the AVDDH is a 3.3V analogue voltage. +Both voltages and the temperature are measured in a round-robin fashion. + +Sysfs entries +------------- + +The following attributes are supported. + +======================= ======================================================== +in0_label "AVDDL" +in0_input Measured AVDDL voltage. +in0_min Minimum AVDDL voltage. +in0_max Maximum AVDDL voltage. +in0_alarm AVDDL voltage alarm. + +in1_label "AVDDH" +in1_input Measured AVDDH voltage. +in1_min Minimum AVDDH voltage. +in1_max Maximum AVDDH voltage. +in1_alarm AVDDH voltage alarm. + +temp1_input Die temperature. +temp1_min Minimum die temperature. +temp1_max Maximum die temperature. +temp1_alarm Die temperature alarm. +======================= ========================================================
Documentation/hwmon/index.rst +1 -0
@@ -42,6 +42,7 @@ Hardware Monitoring Kernel Drivers asb100 asc7621 aspeed-pwm-tacho + bcm54140 bel-pfe coretemp da9052
drivers/net/phy/Kconfig +1 -0
@@ -349,6 +349,7 @@ config BROADCOM_PHY config BCM54140_PHY tristate "Broadcom BCM54140 PHY" depends on PHYLIB + depends on HWMON || HWMON=n select BCM_NET_PHYLIB help Support the Broadcom BCM54140 Quad SGMII/QSGMII PHY.
drivers/net/phy/bcm54140.c +396 -0
422 lines not on this page · raw message
Signature · 1 line
2.20.1
Re: [PATCH net-next v3 3/3] net: phy: bcm54140: add hwmon support
Quoted 5 lines · Michael Walle
The PHY supports monitoring its die temperature as well as two analog voltages. Add support for it.
Signed-off-by Michael Walle <[email protected]>Acked-by Guenter Roeck <[email protected]>
Andrew
Re: [PATCH net-next v3 3/3] net: phy: bcm54140: add hwmon support
In reply to Michael WalleFrom: Michael Walle <[email protected]>
Date: Mon, 20 Apr 2020 20:21:13 +0200
Quoted 5 lines
The PHY supports monitoring its die temperature as well as two analog voltages. Add support for it.
Signed-off-by Michael Walle <[email protected]>Acked-by Guenter Roeck <[email protected]>
Applied.
From: Michael Walle <[email protected]>
Date: Mon, 20 Apr 2020 20:21:11 +0200
Quoted 5 lines
RDB (Register Data Base) registers are used on newer Broadcom PHYs. Add helper to read, write and modify these registers.
Signed-off-by Michael Walle <[email protected]>Reviewed-by Florian Fainelli <[email protected]>
Applied.