Skip to contentSkip to conversation

net: phy: broadcom: add helper to write/read RDB registers

PATCH Superseded Michael Walle 2 participants 9 messages Apr 19, 2020

Subsystems (6)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 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 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
index e77b274a09fd..d5f9a2701989 100644
@@ -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
index 129df819be8c..4d3de91cda6c 100644
@@ -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
index 6462c5447872..e14f78b3c8a4 100644
@@ -114,6 +114,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
#1 lore raw

PATCH v2 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 v1:
none

 drivers/net/phy/Kconfig    |  10 +
 drivers/net/phy/Makefile   |   1 +
 drivers/net/phy/bcm54140.c | 478 +++++++++++++++++++++++++++++++++++++
 include/linux/brcmphy.h    |   1 +
 4 files changed, 490 insertions(+)
 create mode 100644 drivers/net/phy/bcm54140.c
drivers/net/phy/Kconfig +10 -0
index 3fa33d27eeba..cb7936b577de 100644
@@ -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
index 2f5c7093a65b..cd345b75d127 100644
@@ -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 +478 -0

478 lines not on this page · raw message

include/linux/brcmphy.h +1 -0
index e14f78b3c8a4..5a346a985a5b 100644
@@ -24,6 +24,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
maintainer
#2 lore raw

Re: [PATCH net-next v2 2/3] net: phy: add Broadcom BCM54140 support

On Sun, Apr 19, 2020 at 12:12:48PM +0200, Michael Walle wrote:

Hi Michael

drivers/net/phy/bcm54140.c line 102

Quoted 4 lines
drivers/net/phy/bcm54140.c new file +4 -0
+static int bcm54140_b0_workaround(struct phy_device *phydev)
+{
+	int spare3;
+	int ret;

Could you add a comment about what this is working around?

Quoted 8 lines
drivers/net/phy/bcm54140.c new file +8 -0
+static int bcm54140_phy_probe(struct phy_device *phydev)
+{
+	struct bcm54140_phy_priv *priv;
+	int ret;
+
+	priv = devm_kzalloc(&phydev->mdio.dev, sizeof(*priv), GFP_KERNEL);
+	if (!priv)
+		return -ENOMEM;

drivers/net/phy/bcm54140.c line 223

Quoted 10 lines
drivers/net/phy/bcm54140.c new file +10 -0
+
+	phydev->priv = priv;
+
+	ret = bcm54140_get_base_addr_and_port(phydev);
+	if (ret)
+		return ret;
+
+	dev_info(&phydev->mdio.dev,
+		 "probed (port %d, base PHY address %d)\n",
+		 priv->port, priv->base_addr);

phydev_dbg() ? Do we need to see this message four times?

Quoted 17 lines
drivers/net/phy/bcm54140.c new file +17 -0
+
+	return 0;
+}
+
+static int bcm54140_config_init(struct phy_device *phydev)
+{
+	u16 reg = 0xffff;
+	int ret;
+
+	/* Apply hardware errata */
+	ret = bcm54140_b0_workaround(phydev);
+	if (ret)
+		return ret;
+
+	/* Unmask events we are interested in. */
+	reg &= ~(BCM54140_RDB_INT_DUPLEX |
+		 BCM54140_RDB_INT_SPEED |

drivers/net/phy/bcm54140.c line 250

Quoted 10 lines
drivers/net/phy/bcm54140.c new file +10 -0
+		 BCM54140_RDB_INT_LINK);
+	ret = bcm_phy_write_rdb(phydev, BCM54140_RDB_IMR, reg);
+	if (ret)
+		return ret;
+
+	/* LED1=LINKSPD[1], LED2=LINKSPD[2], LED3=ACTIVITY */
+	ret = bcm_phy_modify_rdb(phydev, BCM54140_RDB_SPARE1,
+				 0, BCM54140_RDB_SPARE1_LSLM);
+	if (ret)
+		return ret;

What are the reset default for LEDs? Can the LEDs be configured via strapping pins? There is currently no good solution for this. Whatever you pick will be wrong for somebody else. At minimum, strapping pins, if they exist, should not be overridden.

#3 lore raw

Re: [PATCH net-next v2 2/3] net: phy: add Broadcom BCM54140 support

Am 2020-04-19 17:49, schrieb Andrew Lunn:

Quoted 10 lines · Michael Walle

Hi Michael

drivers/net/phy/bcm54140.c line 102

Quoted 4 lines
drivers/net/phy/bcm54140.c new file +4 -0
+static int bcm54140_b0_workaround(struct phy_device *phydev)
+{
+	int spare3;
+	int ret;

Could you add a comment about what this is working around?

sure

Quoted 13 lines
Quoted 13 lines
drivers/net/phy/bcm54140.c new file +12 -0
+static int bcm54140_phy_probe(struct phy_device *phydev)
+{
+	struct bcm54140_phy_priv *priv;
+	int ret;
+
+	priv = devm_kzalloc(&phydev->mdio.dev, sizeof(*priv), GFP_KERNEL);
+	if (!priv)
+		return -ENOMEM;
+
+	phydev->priv = priv;
+
+	ret = bcm54140_get_base_addr_and_port(phydev);
Quoted 8 lines

drivers/net/phy/bcm54140.c line 223

Quoted 6 lines
drivers/net/phy/bcm54140.c new file +6 -0
+	if (ret)
+		return ret;
+
+	dev_info(&phydev->mdio.dev,
+		 "probed (port %d, base PHY address %d)\n",
+		 priv->port, priv->base_addr);

phydev_dbg() ? Do we need to see this message four times?

ok. every phy will have a different port. And keep in mind, that you might have less than four ports/PHYs here. So I'd like to keep that as a phydev_dbg() if you agree.

Quoted 25 lines
Quoted 25 lines
drivers/net/phy/bcm54140.c new file +24 -0
+
+	return 0;
+}
+
+static int bcm54140_config_init(struct phy_device *phydev)
+{
+	u16 reg = 0xffff;
+	int ret;
+
+	/* Apply hardware errata */
+	ret = bcm54140_b0_workaround(phydev);
+	if (ret)
+		return ret;
+
+	/* Unmask events we are interested in. */
+	reg &= ~(BCM54140_RDB_INT_DUPLEX |
+		 BCM54140_RDB_INT_SPEED |
+		 BCM54140_RDB_INT_LINK);
+	ret = bcm_phy_write_rdb(phydev, BCM54140_RDB_IMR, reg);
+	if (ret)
+		return ret;
+
+	/* LED1=LINKSPD[1], LED2=LINKSPD[2], LED3=ACTIVITY */
+	ret = bcm_phy_modify_rdb(phydev, BCM54140_RDB_SPARE1,
Quoted 8 lines

drivers/net/phy/bcm54140.c line 250

Quoted 3 lines
drivers/net/phy/bcm54140.c new file +3 -0
+				 0, BCM54140_RDB_SPARE1_LSLM);
+	if (ret)
+		return ret;

What are the reset default for LEDs? Can the LEDs be configured via strapping pins? There is currently no good solution for this. Whatever you pick will be wrong for somebody else. At minimum, strapping pins, if they exist, should not be overridden.

Fair enough. There are no strapping options, just the "default behaviour", where LED1/2 indicates the speed, and LED3 just activity (no link indication). And I just noticed that in this case the comment above is wrong, because it is actually link/activity. Further, there are myriad configuration options which I didn't want to encode altogether. So I've just chosen the typical one (which actually matches our hardware), ie. to have the "activity/led mode". The application note mentions some other concrete modes, but I don't know if its worth implementing them. Maybe we can have a enumeration of some distinct modes? Ie.

   broadcom,led-mode = <BCM54140_NO_CHANGE>;
   broadcom,led-mode = <BCM54140_ACT_LINK_MODE>;

-michael

maintainer
#4 lore raw

Re: [PATCH net-next v2 2/3] net: phy: add Broadcom BCM54140 support

Quoted 21 lines · Michael Walle
Quoted 12 lines
Quoted 12 lines
drivers/net/phy/bcm54140.c new file +12 -0
+static int bcm54140_phy_probe(struct phy_device *phydev)
+{
+	struct bcm54140_phy_priv *priv;
+	int ret;
+
+	priv = devm_kzalloc(&phydev->mdio.dev, sizeof(*priv), GFP_KERNEL);
+	if (!priv)
+		return -ENOMEM;
+
+	phydev->priv = priv;
+
+	ret = bcm54140_get_base_addr_and_port(phydev);
Quoted 8 lines

drivers/net/phy/bcm54140.c line 223

Quoted 6 lines
drivers/net/phy/bcm54140.c new file +6 -0
+	if (ret)
+		return ret;
+
+	dev_info(&phydev->mdio.dev,
+		 "probed (port %d, base PHY address %d)\n",
+		 priv->port, priv->base_addr);

phydev_dbg() ? Do we need to see this message four times?

Quoted 3 lines

ok. every phy will have a different port. And keep in mind, that you might have less than four ports/PHYs here. So I'd like to keep that as a phydev_dbg() if you agree.

phydev_dbg() is fine.

Quoted 45 lines
Quoted 26 lines
Quoted 26 lines
drivers/net/phy/bcm54140.c new file +24 -0
+
+	return 0;
+}
+
+static int bcm54140_config_init(struct phy_device *phydev)
+{
+	u16 reg = 0xffff;
+	int ret;
+
+	/* Apply hardware errata */
+	ret = bcm54140_b0_workaround(phydev);
+	if (ret)
+		return ret;
+
+	/* Unmask events we are interested in. */
+	reg &= ~(BCM54140_RDB_INT_DUPLEX |
+		 BCM54140_RDB_INT_SPEED |
+		 BCM54140_RDB_INT_LINK);
+	ret = bcm_phy_write_rdb(phydev, BCM54140_RDB_IMR, reg);
+	if (ret)
+		return ret;
+
+	/* LED1=LINKSPD[1], LED2=LINKSPD[2], LED3=ACTIVITY */
+	ret = bcm_phy_modify_rdb(phydev, BCM54140_RDB_SPARE1,
Quoted 8 lines

drivers/net/phy/bcm54140.c line 250

Quoted 3 lines
drivers/net/phy/bcm54140.c new file +3 -0
+				 0, BCM54140_RDB_SPARE1_LSLM);
+	if (ret)
+		return ret;

What are the reset default for LEDs? Can the LEDs be configured via strapping pins? There is currently no good solution for this. Whatever you pick will be wrong for somebody else. At minimum, strapping pins, if they exist, should not be overridden.

Fair enough. There are no strapping options, just the "default behaviour", where LED1/2 indicates the speed, and LED3 just activity (no link indication). And I just noticed that in this case the comment above is wrong, because it is actually link/activity. Further, there are myriad configuration options which I didn't want to encode altogether. So I've just chosen the typical one (which actually matches our hardware), ie. to have the "activity/led mode". The application note mentions some other concrete modes, but I don't know if its worth implementing them. Maybe we can have a enumeration of some distinct modes? Ie.

Quoted 2 lines
   broadcom,led-mode = <BCM54140_NO_CHANGE>;
   broadcom,led-mode = <BCM54140_ACT_LINK_MODE>;

Configuring LEDs is a mess at the moment. No two PHYs do it the same. For a long time i've had a TODO item to make PHY LEDs work just like every other LED in linux, and you can set trigger actions which are then implemented in hardware.

We have been pushing back on adding DT properties, it just makes the problem worse. If reset defaults are good enough for you, please leave it at that.

Thanks
Andrew

#5 lore raw

Re: [PATCH net-next v2 2/3] net: phy: add Broadcom BCM54140 support

Am 2020-04-19 18:49, schrieb Andrew Lunn:

Quoted 48 lines · Michael Walle
Quoted 44 lines
Quoted 25 lines
Quoted 25 lines
drivers/net/phy/bcm54140.c new file +24 -0
+
+	return 0;
+}
+
+static int bcm54140_config_init(struct phy_device *phydev)
+{
+	u16 reg = 0xffff;
+	int ret;
+
+	/* Apply hardware errata */
+	ret = bcm54140_b0_workaround(phydev);
+	if (ret)
+		return ret;
+
+	/* Unmask events we are interested in. */
+	reg &= ~(BCM54140_RDB_INT_DUPLEX |
+		 BCM54140_RDB_INT_SPEED |
+		 BCM54140_RDB_INT_LINK);
+	ret = bcm_phy_write_rdb(phydev, BCM54140_RDB_IMR, reg);
+	if (ret)
+		return ret;
+
+	/* LED1=LINKSPD[1], LED2=LINKSPD[2], LED3=ACTIVITY */
+	ret = bcm_phy_modify_rdb(phydev, BCM54140_RDB_SPARE1,
Quoted 8 lines

drivers/net/phy/bcm54140.c line 250

Quoted 3 lines
drivers/net/phy/bcm54140.c new file +3 -0
+				 0, BCM54140_RDB_SPARE1_LSLM);
+	if (ret)
+		return ret;

What are the reset default for LEDs? Can the LEDs be configured via strapping pins? There is currently no good solution for this. Whatever you pick will be wrong for somebody else. At minimum, strapping pins, if they exist, should not be overridden.

Fair enough. There are no strapping options, just the "default behaviour", where LED1/2 indicates the speed, and LED3 just activity (no link indication). And I just noticed that in this case the comment above is wrong, because it is actually link/activity. Further, there are myriad configuration options which I didn't want to encode altogether. So I've just chosen the typical one (which actually matches our hardware), ie. to have the "activity/led mode". The application note mentions some other concrete modes, but I don't know if its worth implementing them. Maybe we can have a enumeration of some distinct modes? Ie.

Quoted 2 lines
   broadcom,led-mode = <BCM54140_NO_CHANGE>;
   broadcom,led-mode = <BCM54140_ACT_LINK_MODE>;
Quoted 8 lines

Configuring LEDs is a mess at the moment. No two PHYs do it the same. For a long time i've had a TODO item to make PHY LEDs work just like every other LED in linux, and you can set trigger actions which are then implemented in hardware.

We have been pushing back on adding DT properties, it just makes the problem worse. If reset defaults are good enough for you, please leave it at that.

Unfortunately not. We need the link/act, which I presume will also be used by most other users, thus the driver enables this setting. I don't know any board which just have an activity led, that is just off and blinks for a short time if there is RX or TX, which is the reset default setting of this PHY.

-michael

#6 lore raw

PATCH v2 3/3 net: phy: bcm54140: add hwmon support

In reply to Michael Walle

The PHY supports monitoring its die temperature as well as two analog voltages. Add support for it.

---
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       | 397 +++++++++++++++++++++++++++++++
 4 files changed, 444 insertions(+)
 create mode 100644 Documentation/hwmon/bcm54140.rst
Documentation/hwmon/bcm54140.rst new file +45 -0
new file mode 100644
index 000000000000..bc6ea4b45966
@@ -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
index f022583f96f6..19ad0846736d 100644
@@ -42,6 +42,7 @@ Hardware Monitoring Kernel Drivers
    asb100
    asc7621
    aspeed-pwm-tacho
+   bcm54140
    bel-pfe
    coretemp
    da9052
drivers/net/phy/Kconfig +1 -0
index cb7936b577de..bacfee41b564 100644
@@ -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 +397 -0

427 lines not on this page · raw message

Signature · 1 line
2.20.1
maintainer
#7 lore raw

Re: [PATCH net-next v2 3/3] net: phy: bcm54140: add hwmon support

On Sun, Apr 19, 2020 at 12:12:49PM +0200, Michael Walle wrote:

Hi Michael

You have an #if here...

Quoted 33 lines
drivers/net/phy/bcm54140.c +33 -0
+#if IS_ENABLED(CONFIG_HWMON)
+static umode_t bcm54140_hwmon_is_visible(const void *data,
+					 enum hwmon_sensor_types type,
+					 u32 attr, int channel)
+{
+	switch (type) {
+	case hwmon_in:
+		switch (attr) {
+		case hwmon_in_min:
+		case hwmon_in_max:
+			return 0644;
+		case hwmon_in_label:
+		case hwmon_in_input:
+		case hwmon_in_alarm:
+			return 0444;
+		default:
+			return 0;
+		}
+	case hwmon_temp:
+		switch (attr) {
+		case hwmon_temp_min:
+		case hwmon_temp_max:
+			return 0644;
+		case hwmon_temp_input:
+		case hwmon_temp_alarm:
+			return 0444;
+		default:
+			return 0;
+		}
+	default:
+		return 0;
+	}
+}

...

drivers/net/phy/bcm54140.c static int bcm54140_get_base_addr_and_port(struct phy_device *phydev) · line 523

Quoted 9 lines
drivers/net/phy/bcm54140.c +3 -0
+static const struct hwmon_chip_info bcm54140_chip_info = {
+	.ops = &bcm54140_hwmon_ops,
+	.info = bcm54140_hwmon_info,
 };
 
 static int bcm54140_phy_base_read_rdb(struct phy_device *phydev, u16 rdb)
@@ -203,6 +522,72 @@ static int bcm54140_get_base_addr_and_port(struct phy_device *phydev)
 	return 0;
 }

Still inside the #if. Some original code is now inside the #if/#endif. Is this correct? Hard to see from just the patch.

Quoted 12 lines
drivers/net/phy/bcm54140.c +11 -0
+/* Check if one PHY has already done the init of the parts common to all PHYs
+ * in the Quad PHY package.
+ */
+static bool bcm54140_is_pkg_init(struct phy_device *phydev)
+{
+	struct bcm54140_phy_priv *priv = phydev->priv;
+	struct mii_bus *bus = phydev->mdio.bus;
+	int base_addr = priv->base_addr;
+	struct phy_device *phy;
+	int i;
+

...

Quoted 7 lines
drivers/net/phy/bcm54140.c +7 -0
+static int bcm54140_phy_probe_once(struct phy_device *phydev)
+{
+	struct device *hwmon;
+	int ret;
+
+	/* enable hardware monitoring */
+	ret = bcm54140_enable_monitoring(phydev);

drivers/net/phy/bcm54140.c static int bcm54140_get_base_addr_and_port(struct phy_device *phydev) · line 589

Quoted 10 lines
drivers/net/phy/bcm54140.c +10 -0
+	if (ret)
+		return ret;
+
+	hwmon = devm_hwmon_device_register_with_info(&phydev->mdio.dev,
+						     "BCM54140", phydev,
+						     &bcm54140_chip_info,
+						     NULL);
+	return PTR_ERR_OR_ZERO(hwmon);
+}
+#endif

Thanks
Andrew

#8 lore raw

Re: [PATCH net-next v2 3/3] net: phy: bcm54140: add hwmon support

Am 2020-04-19 17:56, schrieb Andrew Lunn:

Quoted 48 lines · Michael Walle

Hi Michael

You have an #if here...

Quoted 33 lines
drivers/net/phy/bcm54140.c +33 -0
+#if IS_ENABLED(CONFIG_HWMON)
+static umode_t bcm54140_hwmon_is_visible(const void *data,
+					 enum hwmon_sensor_types type,
+					 u32 attr, int channel)
+{
+	switch (type) {
+	case hwmon_in:
+		switch (attr) {
+		case hwmon_in_min:
+		case hwmon_in_max:
+			return 0644;
+		case hwmon_in_label:
+		case hwmon_in_input:
+		case hwmon_in_alarm:
+			return 0444;
+		default:
+			return 0;
+		}
+	case hwmon_temp:
+		switch (attr) {
+		case hwmon_temp_min:
+		case hwmon_temp_max:
+			return 0644;
+		case hwmon_temp_input:
+		case hwmon_temp_alarm:
+			return 0444;
+		default:
+			return 0;
+		}
+	default:
+		return 0;
+	}
+}

...

Quoted 5 lines
drivers/net/phy/bcm54140.c +3 -0
+static const struct hwmon_chip_info bcm54140_chip_info = {
+	.ops = &bcm54140_hwmon_ops,
+	.info = bcm54140_hwmon_info,
 };
Quoted 10 lines

drivers/net/phy/bcm54140.c static int bcm54140_get_base_addr_and_port(struct · line 524

Quoted 6 lines

static int bcm54140_phy_base_read_rdb(struct phy_device *phydev, u16
rdb)

drivers/net/phy/bcm54140.c +0 -0
@@ -203,6 +522,72 @@ static int bcm54140_get_base_addr_and_port(struct 
 phy_device *phydev)
 	return 0;
 }

Still inside the #if. Some original code is now inside the #if/#endif. Is this correct? Hard to see from just the patch.

Whoops you're correct, something got messed up here. Will fix that in the next version.

-michael

Quoted 38 lines
Quoted 14 lines
(quoted diff) +1 -0
+/* Check if one PHY has already done the init of the parts common to 

all PHYs
+ * in the Quad PHY package.
+ */

drivers/net/phy/bcm54140.c +8 -0
+static bool bcm54140_is_pkg_init(struct phy_device *phydev)
+{
+	struct bcm54140_phy_priv *priv = phydev->priv;
+	struct mii_bus *bus = phydev->mdio.bus;
+	int base_addr = priv->base_addr;
+	struct phy_device *phy;
+	int i;
+

...

Quoted 7 lines
drivers/net/phy/bcm54140.c +7 -0
+static int bcm54140_phy_probe_once(struct phy_device *phydev)
+{
+	struct device *hwmon;
+	int ret;
+
+	/* enable hardware monitoring */
+	ret = bcm54140_enable_monitoring(phydev);

drivers/net/phy/bcm54140.c static int bcm54140_get_base_addr_and_port(struct phy_device *phydev) · line 589

Quoted 10 lines
drivers/net/phy/bcm54140.c +10 -0
+	if (ret)
+		return ret;
+
+	hwmon = devm_hwmon_device_register_with_info(&phydev->mdio.dev,
+						     "BCM54140", phydev,
+						     &bcm54140_chip_info,
+						     NULL);
+	return PTR_ERR_OR_ZERO(hwmon);
+}
+#endif

Thanks
Andrew