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 3/3] led: at8030: Add LED driver for AT8030 ethernet PHY
Date: Wed, 23 Mar 2016 18:51:40 +0100 [thread overview]
Message-ID: <1458755500-15571-4-git-send-email-vishalthanki@gmail.com> (raw)
In-Reply-To: <1458755500-15571-1-git-send-email-vishalthanki@gmail.com>
This patch adds support for controlling the Link and
Activity LED of AT8030 ethernet PHY through LED subsystem.
Signed-off-by: Vishal Thanki <vishalthanki@gmail.com>
---
drivers/leds/Kconfig | 7 ++
drivers/leds/Makefile | 1 +
drivers/leds/leds-at803x.c | 158 +++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 166 insertions(+)
create mode 100644 drivers/leds/leds-at803x.c
diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
index 1f64151..07781ac 100644
--- a/drivers/leds/Kconfig
+++ b/drivers/leds/Kconfig
@@ -615,6 +615,13 @@ config LEDS_VERSATILE
This option enabled support for the LEDs on the ARM Versatile
and RealView boards. Say Y to enabled these.
+config LEDS_AT803X
+ tristate "LED support for the AT803X Ethernet PHY (Experimental)"
+ depends on LEDS_CLASS
+ help
+ This option enabled support for the LEDs on AT803X ethernet PHY.
+
+
comment "LED Triggers"
source "drivers/leds/trigger/Kconfig"
diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
index cb2013d..2d1ae65 100644
--- a/drivers/leds/Makefile
+++ b/drivers/leds/Makefile
@@ -67,6 +67,7 @@ obj-$(CONFIG_LEDS_KTD2692) += leds-ktd2692.o
obj-$(CONFIG_LEDS_POWERNV) += leds-powernv.o
obj-$(CONFIG_LEDS_SEAD3) += leds-sead3.o
obj-$(CONFIG_LEDS_IS31FL32XX) += leds-is31fl32xx.o
+obj-$(CONFIG_LEDS_AT803X) += leds-at803x.o
# LED SPI Drivers
obj-$(CONFIG_LEDS_DAC124S085) += leds-dac124s085.o
diff --git a/drivers/leds/leds-at803x.c b/drivers/leds/leds-at803x.c
new file mode 100644
index 0000000..58eb0c4
--- /dev/null
+++ b/drivers/leds/leds-at803x.c
@@ -0,0 +1,158 @@
+#include <linux/kernel.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <linux/leds.h>
+#include <linux/io.h>
+#include <linux/module.h>
+#include <linux/phy.h>
+#include <linux/phy/at803x.h>
+
+#define LED_TX_NORMAL 0x0
+#define LED_TX_BLINK 0x1
+#define LED_TX_OFF 0x2
+#define LED_TX_ON 0x3
+
+#define LED_RX_NORMAL 0x0
+#define LED_RX_BLINK 0x1
+#define LED_RX_OFF 0x2
+#define LED_RX_ON 0x3
+
+#define LED_ACT_BLINK 0x1
+
+#define LED_LINK_NORMAL 0x0
+#define LED_LINK_BLINK LED_ACT_BLINK
+#define LED_LINK_OFF 0x2
+#define LED_LINK_ON 0x3
+
+#define LED_ACT_ACTIVE 0x0
+#define LED_ACT_LINK 0x1
+
+static void at803x_led_work(struct work_struct *work)
+{
+ struct at803x_phy_led *led =
+ container_of(work, struct at803x_phy_led, work);
+ union at803x_led_manual_ctrl regval = led->regval;
+
+ phy_write(led->led_grp->phydev, led->reg, regval.value);
+}
+
+static int at803x_blink_set(struct led_classdev *cdev,
+ unsigned long *delay_on,
+ unsigned long *delay_off)
+{
+ struct at803x_phy_led *led =
+ container_of(cdev, struct at803x_phy_led, cdev);
+ union at803x_led_manual_ctrl regval = {.value = 0};
+ int id = led->id;
+ unsigned long flags;
+
+ spin_lock_irqsave(&led->lock, flags);
+ switch (id) {
+ case AT803X_LINK:
+ /* Can't configure LED_LINK to blink */
+ break;
+ case AT803X_ACT:
+ /*
+ * LED will be ON when link is established
+ * and it will blink when link is active.
+ * delay_on/delay_off values are ignored.
+ */
+ regval.field.led_act_ctrl = LED_ACT_LINK;
+ break;
+ }
+ led->regval = regval;
+
+ schedule_work(&led->work);
+ spin_unlock_irqrestore(&led->lock, flags);
+ return 0;
+}
+
+
+static void at803x_phy_led_brightness_set(struct led_classdev *led_cdev,
+ enum led_brightness value)
+{
+ struct at803x_phy_led *led =
+ container_of(led_cdev, struct at803x_phy_led, cdev);
+ union at803x_led_manual_ctrl regval = led->regval;
+ int id = led->id;
+ unsigned long flags;
+
+ spin_lock_irqsave(&led->lock, flags);
+ switch (id) {
+ case AT803X_LINK:
+ regval.field.led_lnk_10_100_ctrl = value == LED_FULL ?
+ LED_LINK_ON : LED_LINK_OFF;
+ break;
+ case AT803X_ACT:
+ /* LED_ACT status is controlled via LED_TX and LED_RX */
+ regval.field.led_tx = value == LED_FULL ?
+ LED_TX_ON : LED_TX_OFF;
+ regval.field.led_rx = value == LED_FULL ?
+ LED_RX_ON : LED_RX_OFF;
+ break;
+ }
+
+ led->value = value;
+ led->regval = regval;
+ schedule_work(&led->work);
+ spin_unlock_irqrestore(&led->lock, flags);
+}
+
+static int at803x_phy_led_probe(struct platform_device *pdev)
+{
+ int i;
+ int ret;
+ struct at803x_phy_leds *led_grp = platform_get_drvdata(pdev);
+ struct at803x_phy_led *leds = led_grp->leds;
+
+ for (i = 0; i < led_grp->nr_leds; i++) {
+
+ leds[i].cdev.brightness_set = at803x_phy_led_brightness_set;
+ leds[i].cdev.blink_set = at803x_blink_set;
+
+ ret = led_classdev_register(&pdev->dev, &leds[i].cdev);
+ if (ret < 0)
+ goto err;
+
+ leds[i].led_grp = led_grp;
+ leds[i].regval.value = phy_read(led_grp->phydev, leds[i].reg);
+ INIT_WORK(&leds[i].work, at803x_led_work);
+ spin_lock_init(&leds[i].lock);
+
+ }
+
+ return 0;
+
+err:
+ for (i = i - 1; i >= 0; i--)
+ led_classdev_unregister(&leds[i].cdev);
+
+ return ret;
+}
+
+static int at803x_phy_led_remove(struct platform_device *pdev)
+{
+ int i;
+ struct at803x_phy_leds *led_grp = platform_get_drvdata(pdev);
+ struct at803x_phy_led *leds = led_grp->leds;
+
+
+ for (i = 0; i < led_grp->nr_leds; i++)
+ led_classdev_unregister(&leds[i].cdev);
+
+ return 0;
+}
+
+static struct platform_driver at803x_phy_led_driver = {
+ .probe = at803x_phy_led_probe,
+ .remove = at803x_phy_led_remove,
+ .driver = {
+ .name = "at803x-led",
+ },
+};
+
+module_platform_driver(at803x_phy_led_driver);
+
+MODULE_DESCRIPTION("at803x PHY LED driver");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:leds-at803x");
--
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 ` [PATCH 2/3] net: phy: at8030: Expose the Link and Activity LEDs Vishal Thanki
2016-03-23 18:56 ` Andrew Lunn
2016-03-23 17:51 ` Vishal Thanki [this message]
2016-03-23 18:52 ` [PATCH 3/3] led: at8030: Add LED driver for AT8030 ethernet PHY 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-4-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).