From: "Marek Behún" <marek.behun@nic.cz>
To: netdev@vger.kernel.org
Cc: linux-leds@vger.kernel.org, "Pavel Machek" <pavel@ucw.cz>,
"Dan Murphy" <dmurphy@ti.com>,
"Ondřej Jirman" <megous@megous.com>,
"Russell King" <linux@armlinux.org.uk>,
"Andrew Lunn" <andrew@lunn.ch>,
linux-kernel@vger.kernel.org,
"Matthias Schiffer" <matthias.schiffer@ew.tq-group.com>,
"David S. Miller" <davem@davemloft.net>,
"Marek Behún" <marek.behun@nic.cz>
Subject: [PATCH net-next + leds v2 5/7] net: phy: add support for LEDs controlled by ethernet PHY chips
Date: Wed, 9 Sep 2020 18:25:50 +0200 [thread overview]
Message-ID: <20200909162552.11032-6-marek.behun@nic.cz> (raw)
In-Reply-To: <20200909162552.11032-1-marek.behun@nic.cz>
This patch uses the new API for HW controlled LEDs to add support for
probing and control of LEDs connected to an ethernet PHY chip.
A PHY driver wishing to utilize this API needs to implement the methods
in struct hw_controlled_led_ops and set the member led_ops in struct
phy_driver to point to that structure.
Signed-off-by: Marek Behún <marek.behun@nic.cz>
---
drivers/net/phy/phy_device.c | 103 +++++++++++++++++++++++++++++++++++
include/linux/phy.h | 4 ++
2 files changed, 107 insertions(+)
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 38f56d39f1229..54d5c88e4d4b2 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -2820,6 +2820,103 @@ static bool phy_drv_supports_irq(struct phy_driver *phydrv)
return phydrv->config_intr && phydrv->ack_interrupt;
}
+#if IS_ENABLED(CONFIG_LEDS_HW_CONTROLLED)
+
+/* PHY mutex lock wrappers for operations on PHY HW controlled LEDs, so that PHY drivers
+ * implementing these operations don't have to lock phydev->lock themselves.
+ */
+static int phy_led_init(struct device *dev, struct hw_controlled_led *led)
+{
+ struct phy_device *phydev = to_phy_device(dev);
+ int ret;
+
+ mutex_lock(&phydev->lock);
+ ret = phydev->drv->led_ops->led_init(dev, led);
+ mutex_unlock(&phydev->lock);
+
+ return ret;
+}
+
+static int phy_led_brightness_set(struct device *dev, struct hw_controlled_led *led,
+ enum led_brightness brightness)
+{
+ struct phy_device *phydev = to_phy_device(dev);
+ int ret;
+
+ mutex_lock(&phydev->lock);
+ ret = phydev->drv->led_ops->led_brightness_set(dev, led, brightness);
+ mutex_unlock(&phydev->lock);
+
+ return ret;
+}
+
+static const char *phy_led_iter_hw_mode(struct device *dev, struct hw_controlled_led *led,
+ void **iter)
+{
+ struct phy_device *phydev = to_phy_device(dev);
+ const char *ret;
+
+ mutex_lock(&phydev->lock);
+ ret = phydev->drv->led_ops->led_iter_hw_mode(dev, led, iter);
+ mutex_unlock(&phydev->lock);
+
+ return ret;
+}
+
+static int phy_led_set_hw_mode(struct device *dev, struct hw_controlled_led *led, const char *mode)
+{
+ struct phy_device *phydev = to_phy_device(dev);
+ int ret;
+
+ mutex_lock(&phydev->lock);
+ ret = phydev->drv->led_ops->led_set_hw_mode(dev, led, mode);
+ mutex_unlock(&phydev->lock);
+
+ return ret;
+}
+
+static const char *phy_led_get_hw_mode(struct device *dev, struct hw_controlled_led *led)
+{
+ struct phy_device *phydev = to_phy_device(dev);
+ const char *ret;
+
+ mutex_lock(&phydev->lock);
+ ret = phydev->drv->led_ops->led_get_hw_mode(dev, led);
+ mutex_unlock(&phydev->lock);
+
+ return ret;
+}
+
+static const struct hw_controlled_led_ops phy_hw_controlled_led_ops = {
+ .led_init = phy_led_init,
+ .led_brightness_set = phy_led_brightness_set,
+ .led_iter_hw_mode = phy_led_iter_hw_mode,
+ .led_set_hw_mode = phy_led_set_hw_mode,
+ .led_get_hw_mode = phy_led_get_hw_mode,
+};
+
+static int of_phy_probe_leds(struct phy_device *phydev)
+{
+ char devicename[32];
+
+ if (!phydev->drv->led_ops)
+ return 0;
+
+ snprintf(devicename, sizeof(devicename), "ethernet-phy%i", phydev->phyindex);
+
+ return of_register_hw_controlled_leds(&phydev->mdio.dev, devicename,
+ &phy_hw_controlled_led_ops);
+}
+
+#else /* !IS_ENABLED(CONFIG_LEDS_HW_CONTROLLED) */
+
+static inline int of_phy_probe_leds(struct phy_device *phydev)
+{
+ return 0;
+}
+
+#endif /* !IS_ENABLED(CONFIG_LEDS_HW_CONTROLLED) */
+
/**
* phy_probe - probe and init a PHY device
* @dev: device to probe and init
@@ -2922,6 +3019,12 @@ static int phy_probe(struct device *dev)
mutex_unlock(&phydev->lock);
+ /* LEDs have to be registered with phydev mutex unlocked, because some operations can be
+ * called during registration that lock the mutex themselves
+ */
+ if (!err)
+ of_phy_probe_leds(phydev);
+
return err;
}
diff --git a/include/linux/phy.h b/include/linux/phy.h
index 52881e21ad951..8a4ab72c74dd4 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -14,6 +14,7 @@
#include <linux/compiler.h>
#include <linux/spinlock.h>
#include <linux/ethtool.h>
+#include <linux/leds-hw-controlled.h>
#include <linux/linkmode.h>
#include <linux/netlink.h>
#include <linux/mdio.h>
@@ -741,6 +742,9 @@ struct phy_driver {
int (*set_loopback)(struct phy_device *dev, bool enable);
int (*get_sqi)(struct phy_device *dev);
int (*get_sqi_max)(struct phy_device *dev);
+
+ /* PHY connected and controlled LEDs */
+ const struct hw_controlled_led_ops *led_ops;
};
#define to_phy_driver(d) container_of(to_mdio_common_driver(d), \
struct phy_driver, mdiodrv)
--
2.26.2
next prev parent reply other threads:[~2020-09-09 16:35 UTC|newest]
Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-09 16:25 [PATCH net-next + leds v2 0/7] PLEASE REVIEW: Add support for LEDs on Marvell PHYs Marek Behún
2020-09-09 16:25 ` [PATCH net-next + leds v2 1/7] dt-bindings: leds: document binding for HW controlled LEDs Marek Behún
2020-09-09 18:27 ` Andrew Lunn
2020-09-09 18:33 ` Marek Behún
2020-09-09 20:59 ` Rob Herring
2020-09-09 21:07 ` Marek Behun
2020-09-09 21:31 ` Rob Herring
2020-09-09 21:43 ` Marek Behun
2020-09-09 20:56 ` Rob Herring
2020-09-09 21:15 ` Rob Herring
2020-09-09 21:58 ` Marek Behun
2020-09-09 16:25 ` [PATCH net-next + leds v2 2/7] leds: add generic API for LEDs that can be controlled by hardware Marek Behún
2020-09-09 18:20 ` Randy Dunlap
2020-09-09 18:31 ` Marek Behún
2020-09-09 18:43 ` Randy Dunlap
2020-09-09 20:48 ` Pavel Machek
2020-09-09 21:20 ` Marek Behun
2020-09-09 21:40 ` Pavel Machek
2020-09-09 22:15 ` Marek Behun
2020-09-09 22:20 ` Pavel Machek
2020-09-09 16:25 ` [PATCH net-next + leds v2 3/7] net: phy: add simple incrementing phyindex member to phy_device struct Marek Behún
2020-09-10 12:20 ` Pavel Machek
2020-09-09 16:25 ` [PATCH net-next + leds v2 4/7] dt-bindings: net: ethernet-phy: add description for PHY LEDs Marek Behún
2020-09-09 16:25 ` Marek Behún [this message]
2020-09-10 12:22 ` [PATCH net-next + leds v2 5/7] net: phy: add support for LEDs controlled by ethernet PHY chips Pavel Machek
2020-09-09 16:25 ` [PATCH net-next + leds v2 6/7] net: phy: marvell: add support for LEDs controlled by Marvell PHYs Marek Behún
2020-09-10 12:23 ` Pavel Machek
2020-09-10 13:15 ` Andrew Lunn
2020-09-10 14:15 ` Marek Behún
2020-09-10 14:46 ` Andrew Lunn
2020-09-10 15:00 ` Andrew Lunn
2020-09-11 7:12 ` Matthias Schiffer
2020-09-11 12:42 ` Andrew Lunn
2020-09-11 12:52 ` Marek Behún
2020-09-10 20:23 ` Pavel Machek
2020-09-10 20:31 ` Andrew Lunn
2020-09-10 20:39 ` Pavel Machek
2020-09-10 20:41 ` Marek Behun
2020-09-10 18:24 ` Pavel Machek
2020-09-10 18:31 ` Andrew Lunn
2020-09-10 18:34 ` Russell King - ARM Linux admin
2020-09-10 20:31 ` Marek Behun
2020-09-10 21:44 ` Russell King - ARM Linux admin
2020-09-11 12:53 ` Marek Behún
2020-09-09 16:25 ` [PATCH net-next + mvebu v2 7/7] arm64: dts: armada-3720-turris-mox: add nodes for ethernet PHY LEDs Marek Behún
2020-09-10 12:25 ` Pavel Machek
2020-09-09 21:42 ` [PATCH net-next + leds v2 0/7] PLEASE REVIEW: Add support for LEDs on Marvell PHYs Andrew Lunn
2020-09-09 22:11 ` Marek Behun
2020-09-09 22:39 ` Andrew Lunn
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200909162552.11032-6-marek.behun@nic.cz \
--to=marek.behun@nic.cz \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=dmurphy@ti.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-leds@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=matthias.schiffer@ew.tq-group.com \
--cc=megous@megous.com \
--cc=netdev@vger.kernel.org \
--cc=pavel@ucw.cz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).