From: Vishal Thanki <vishalthanki@gmail.com>
To: andrew@lunn.ch, f.fainelli@gmail.com, ujhelyi.m@gmail.com,
netdev@vger.kernel.org
Cc: Vishal Thanki <vishalthanki@gmail.com>
Subject: [PATCH 2/3] net: phy: at8030: Expose the Link and Activity LEDs
Date: Wed, 23 Mar 2016 18:51:39 +0100 [thread overview]
Message-ID: <1458755500-15571-3-git-send-email-vishalthanki@gmail.com> (raw)
In-Reply-To: <1458755500-15571-1-git-send-email-vishalthanki@gmail.com>
Expose these LEDs by means of a platform device which
can be controlled by a suitable LED driver.
Signed-off-by: Vishal Thanki <vishalthanki@gmail.com>
---
drivers/net/phy/at803x.c | 55 +++++++++++++++++++++++++++++++++++++++++++++-
include/linux/phy/at803x.h | 45 +++++++++++++++++++++++++++++++++++++
2 files changed, 99 insertions(+), 1 deletion(-)
create mode 100644 include/linux/phy/at803x.h
diff --git a/drivers/net/phy/at803x.c b/drivers/net/phy/at803x.c
index 1e901c7..8fdb5ff 100644
--- a/drivers/net/phy/at803x.c
+++ b/drivers/net/phy/at803x.c
@@ -18,6 +18,8 @@
#include <linux/etherdevice.h>
#include <linux/of_gpio.h>
#include <linux/gpio/consumer.h>
+#include <linux/platform_device.h>
+#include <linux/phy/at803x.h>
#define AT803X_INTR_ENABLE 0x12
#define AT803X_INTR_ENABLE_AUTONEG_ERR BIT(15)
@@ -34,6 +36,7 @@
#define AT803X_SMART_SPEED 0x14
#define AT803X_LED_CONTROL 0x18
+#define AT803X_LED_MANUAL_CTRL 0x19
#define AT803X_DEVICE_ADDR 0x03
#define AT803X_LOC_MAC_ADDR_0_15_OFFSET 0x804C
@@ -117,6 +120,46 @@ static inline int at803x_enable_tx_delay(struct phy_device *phydev)
AT803X_DEBUG_TX_CLK_DLY_EN);
}
+static struct at803x_phy_led leds[] = {
+ {
+ .cdev.name = "at803x-link",
+ .id = AT803X_LINK,
+ .reg = AT803X_LED_MANUAL_CTRL,
+ },
+ {
+ .cdev.name = "at803x-act",
+ .id = AT803X_ACT,
+ .reg = AT803X_LED_MANUAL_CTRL,
+ },
+};
+
+static struct at803x_phy_leds led_grp = {
+ .leds = leds,
+ .nr_leds = ARRAY_SIZE(leds),
+};
+
+static struct platform_device *pdev;
+
+static int at803x_led_init(struct phy_device *phydev)
+{
+ led_grp.phydev = phydev;
+
+ pdev = platform_device_alloc("at803x-led", 0);
+ if (!pdev) {
+ pr_info("Failed to allocate LED\n");
+ return -ENOMEM;
+ }
+
+ platform_set_drvdata(pdev, &led_grp);
+
+ return platform_device_add(pdev);
+}
+
+static void at803x_led_cleanup(struct phy_device *phydev)
+{
+ platform_device_del(pdev);
+}
+
/* save relevant PHY registers to private copy */
static void at803x_context_save(struct phy_device *phydev,
struct at803x_context *context)
@@ -285,9 +328,18 @@ static int at803x_probe(struct phy_device *phydev)
phydev->priv = priv;
+ if (phydev->drv->flags & PHY_HAS_LED_CTRL)
+ return at803x_led_init(phydev);
+
return 0;
}
+static void at803x_remove(struct phy_device *phydev)
+{
+ if (phydev->drv->flags & PHY_HAS_LED_CTRL)
+ at803x_led_cleanup(phydev);
+}
+
static int at803x_config_init(struct phy_device *phydev)
{
int ret;
@@ -411,11 +463,12 @@ static struct phy_driver at803x_driver[] = {
.suspend = at803x_suspend,
.resume = at803x_resume,
.features = PHY_BASIC_FEATURES,
- .flags = PHY_HAS_INTERRUPT,
+ .flags = PHY_HAS_INTERRUPT | PHY_HAS_LED_CTRL,
.config_aneg = genphy_config_aneg,
.read_status = genphy_read_status,
.ack_interrupt = at803x_ack_interrupt,
.config_intr = at803x_config_intr,
+ .remove = at803x_remove,
}, {
/* ATHEROS 8031 */
.phy_id = ATH8031_PHY_ID,
diff --git a/include/linux/phy/at803x.h b/include/linux/phy/at803x.h
new file mode 100644
index 0000000..f33bfcf
--- /dev/null
+++ b/include/linux/phy/at803x.h
@@ -0,0 +1,45 @@
+#ifndef _AT803X_H
+#define _AT803X_H
+
+#include <linux/leds.h>
+#include <linux/phy/phy.h>
+#include <linux/workqueue.h>
+#include <linux/spinlock.h>
+
+enum at803x_led_type {
+ AT803X_LINK,
+ AT803X_ACT,
+};
+
+union at803x_led_manual_ctrl {
+ struct {
+ u16 led_tx:2;
+ u16 led_rx:2;
+ u16 res3:2;
+ u16 led_lnk_10_100_ctrl:2;
+ u16 res2:4;
+ u16 led_act_ctrl:1;
+ u16 res1:3;
+
+ } field;
+ u16 value;
+};
+
+struct at803x_phy_led {
+ struct work_struct work;
+ struct led_classdev cdev;
+ enum led_brightness value;
+ union at803x_led_manual_ctrl regval;
+ enum at803x_led_type id;
+ struct at803x_phy_leds *led_grp;
+ spinlock_t lock;
+ u16 reg;
+};
+
+struct at803x_phy_leds {
+ struct phy_device *phydev;
+ struct at803x_phy_led *leds;
+ int nr_leds;
+};
+
+#endif
--
2.4.3
next prev parent reply other threads:[~2016-03-23 17:51 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-23 17:51 [PATCH 0/3] Control ethernet PHY LEDs via LED subsystem Vishal Thanki
2016-03-23 17:51 ` [PATCH 1/3] net: phy: Add ethernet PHY LED triggers Vishal Thanki
2016-03-23 17:51 ` Vishal Thanki [this message]
2016-03-23 18:56 ` [PATCH 2/3] net: phy: at8030: Expose the Link and Activity LEDs Andrew Lunn
2016-03-23 17:51 ` [PATCH 3/3] led: at8030: Add LED driver for AT8030 ethernet PHY Vishal Thanki
2016-03-23 18:52 ` Andrew Lunn
2016-03-23 18:50 ` [PATCH 0/3] Control ethernet PHY LEDs via LED subsystem Andrew Lunn
2016-03-23 20:24 ` Vishal Thanki
2016-03-23 21:10 ` Andrew Lunn
2016-03-23 21:24 ` Vishal Thanki
2016-03-24 13:29 ` Andrew Lunn
2016-03-24 17:35 ` Vishal Thanki
2016-03-24 18:50 ` Andrew Lunn
2016-03-28 15:43 ` Stephen Hemminger
2016-03-28 16:10 ` 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=1458755500-15571-3-git-send-email-vishalthanki@gmail.com \
--to=vishalthanki@gmail.com \
--cc=andrew@lunn.ch \
--cc=f.fainelli@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=ujhelyi.m@gmail.com \
/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).