net: mdio: mdio-bcm-unimac: Manage clock around I/O accesses
authorFlorian Fainelli <florian.fainelli@broadcom.com>
Mon, 19 Feb 2024 20:40:51 +0000 (12:40 -0800)
committerDavid S. Miller <davem@davemloft.net>
Wed, 21 Feb 2024 12:46:17 +0000 (12:46 +0000)
commitee975351cf0c2a11cdf97eae58265c126cb32850
tree29d7eea046fbfd5f5d430a068c80a10b7c98c249
parent78b88ef392c1ccc189c74cf73c179cf59d23a258
net: mdio: mdio-bcm-unimac: Manage clock around I/O accesses

Up until now we have managed not to have the mdio-bcm-unimac manage its
clock except during probe and suspend/resume. This works most of the
time, except where it does not.

With a fully modular build, we can get into a situation whereby the
GENET driver is fully registered, and so is the mdio-bcm-unimac driver,
however the Ethernet PHY driver is not yet, because it depends on a
resource that is not yet available (e.g.: GPIO provider). In that state,
the network device is not usable yet, and so to conserve power, the
GENET driver will have turned off its "main" clock which feeds its MDIO
controller.

When the PHY driver finally probes however, we make an access to the PHY
registers to e.g.: disable interrupts, and this causes a bus error
within the MDIO controller space because the MDIO controller clock(s)
are turned off.

To remedy that, we manage the clock around all of the I/O accesses to
the hardware which are done exclusively during read, write and clock
divider configuration.

This ensures that the register space is accessible, and this also
ensures that there are not unnecessarily elevated reference counts
keeping the clocks active when the network device is administratively
turned off. It would be the case with the previous way of managing the
clock.

Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
Signed-off-by: Florian Fainelli <florian.fainelli@broadcom.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/mdio/mdio-bcm-unimac.c
include/linux/platform_data/mdio-bcm-unimac.h