devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Rafał Miłecki" <zajec5@gmail.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-usb@vger.kernel.org, linux-leds@vger.kernel.org,
	"Richard Purdie" <rpurdie@rpsys.net>,
	"Jacek Anaszewski" <jacek.anaszewski@gmail.com>,
	"Pavel Machek" <pavel@ucw.cz>,
	devicetree@vger.kernel.org, "Rob Herring" <robh+dt@kernel.org>,
	"Mark Rutland" <mark.rutland@arm.com>,
	"Rafał Miłecki" <rafal@milecki.pl>
Subject: [PATCH V2 2/2] usb: core: read USB ports from DT in the usbport LED trigger driver
Date: Fri, 20 Jan 2017 22:56:04 +0100	[thread overview]
Message-ID: <20170120215605.15728-2-zajec5@gmail.com> (raw)
In-Reply-To: <20170120215605.15728-1-zajec5@gmail.com>

From: Rafał Miłecki <rafal@milecki.pl>

This adds support for using description of relation between LEDs and USB
ports from device tree. If DT has properly described LEDs, trigger will
know when to turn them on.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
---
V2: Update to use "led-triggers"
---
 drivers/usb/core/ledtrig-usbport.c | 54 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 54 insertions(+)

diff --git a/drivers/usb/core/ledtrig-usbport.c b/drivers/usb/core/ledtrig-usbport.c
index 1713248ab15a..aee80748eb7a 100644
--- a/drivers/usb/core/ledtrig-usbport.c
+++ b/drivers/usb/core/ledtrig-usbport.c
@@ -11,8 +11,10 @@
 #include <linux/device.h>
 #include <linux/leds.h>
 #include <linux/module.h>
+#include <linux/of.h>
 #include <linux/slab.h>
 #include <linux/usb.h>
+#include <linux/usb/of.h>
 
 struct usbport_trig_data {
 	struct led_classdev *led_cdev;
@@ -123,6 +125,55 @@ static const struct attribute_group ports_group = {
  * Adding & removing ports
  ***************************************/
 
+/**
+ * usbport_trig_port_observed - Check if port should be observed
+ */
+static bool usbport_trig_port_observed(struct usbport_trig_data *usbport_data,
+				       struct usb_device *usb_dev, int port1)
+{
+	struct device *dev = usbport_data->led_cdev->dev;
+	struct device_node *led_np = dev->of_node;
+	struct of_phandle_args args;
+	struct device_node *port_np;
+	int count, i;
+
+	if (!led_np)
+		return false;
+
+	/* Get node of port being added */
+	port_np = usb_of_get_child_node(usb_dev->dev.of_node, port1);
+	if (!port_np)
+		return false;
+
+	/* Amount of ports this LED references */
+	count = of_count_phandle_with_args(led_np, "led-triggers", NULL);
+	if (count < 0) {
+		dev_warn(dev, "Failed to get USB ports for %s\n",
+			 led_np->full_name);
+		return false;
+	}
+
+	/* Check if port is on this LED's list */
+	for (i = 0; i < count; i++) {
+		int err;
+
+		err = of_parse_phandle_with_args(led_np, "led-triggers", NULL,
+						 i, &args);
+		if (err) {
+			dev_err(dev, "Failed to get USB port phandle at index %d: %d\n",
+				i, err);
+			continue;
+		}
+
+		of_node_put(args.np);
+
+		if (args.np == port_np)
+			return true;
+	}
+
+	return false;
+}
+
 static int usbport_trig_add_port(struct usbport_trig_data *usbport_data,
 				 struct usb_device *usb_dev,
 				 const char *hub_name, int portnum)
@@ -141,6 +192,8 @@ static int usbport_trig_add_port(struct usbport_trig_data *usbport_data,
 	port->data = usbport_data;
 	port->hub = usb_dev;
 	port->portnum = portnum;
+	port->observed = usbport_trig_port_observed(usbport_data, usb_dev,
+						    portnum);
 
 	len = strlen(hub_name) + 8;
 	port->port_name = kzalloc(len, GFP_KERNEL);
@@ -255,6 +308,7 @@ static void usbport_trig_activate(struct led_classdev *led_cdev)
 	if (err)
 		goto err_free;
 	usb_for_each_dev(usbport_data, usbport_trig_add_usb_dev_ports);
+	usbport_trig_update_count(usbport_data);
 
 	/* Notifications */
 	usbport_data->nb.notifier_call = usbport_trig_notify,
-- 
2.11.0

  reply	other threads:[~2017-01-20 21:56 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-20 21:56 [PATCH V2 1/2] dt-bindings: leds: document new led-triggers property Rafał Miłecki
2017-01-20 21:56 ` Rafał Miłecki [this message]
2017-01-20 21:56 ` [EXAMPLE V2 3/2] ARM: BCM53573: Specify ports for USB LED for Tenda AC9 Rafał Miłecki
2017-01-20 22:35 ` [PATCH V2 1/2] dt-bindings: leds: document new led-triggers property Jacek Anaszewski
     [not found]   ` <29f27028-20f3-3eb9-502f-1b51958640f9-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-01-21 16:24     ` Rafał Miłecki
     [not found]       ` <CACna6rx-qJ5eLMOUbMcaAxaOp9avrj1sa-8zZo2m+rVvY+Kvjw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-01-21 21:42         ` Jacek Anaszewski
     [not found]           ` <46084d98-fddb-1b92-e9ca-d55957a442ae-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-01-25  9:03             ` Rafał Miłecki
     [not found]               ` <CACna6rx5HsSb=rXCjVth_2ed87tUSBJEZHHxTC_S1YOztLjp1A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-01-25 21:04                 ` Jacek Anaszewski
2017-01-31 16:11                   ` Rafał Miłecki
     [not found]                     ` <f9bda1d6-4265-8fe6-58ba-d6da5b462a0c-g1n6cQUeyibVItvQsEIGlw@public.gmane.org>
2017-01-31 21:34                       ` Jacek Anaszewski
2017-02-01  7:38                         ` Rafał Miłecki
     [not found]                         ` <c4f1d3c4-d972-e305-abb9-a5c6e9e184e9-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-02-01 15:56                           ` Rafał Miłecki
     [not found]                             ` <d3535c2c-2a7c-4e8d-552c-666f76043b7d-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-02-01 21:26                               ` Jacek Anaszewski
2017-02-01 21:55                                 ` Rafał Miłecki
2017-02-02 20:44                                   ` Jacek Anaszewski
2017-02-02 23:00                                     ` Rafał Miłecki
     [not found]                                       ` <aa97923a-d46c-ad90-a96a-0017129daeb8-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-02-03 11:05                                         ` Pavel Machek
2017-02-07 21:41                                       ` Jacek Anaszewski
2017-02-07 22:57                                   ` Rob Herring
2017-01-23 16:45     ` Rob Herring
2017-01-23 20:51       ` Jacek Anaszewski
2017-01-25  9:18         ` Rafał Miłecki
     [not found]           ` <2aed99c3-7ebe-8b16-5d75-8d0d5b20c27e-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-01-25 21:04             ` Jacek Anaszewski
2017-01-25  9:08       ` Rafał Miłecki
     [not found]         ` <d791bf97-d2f0-1f33-724a-9dd0c4f631ae-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-01-25 21:04           ` Jacek Anaszewski

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=20170120215605.15728-2-zajec5@gmail.com \
    --to=zajec5@gmail.com \
    --cc=devicetree@vger.kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jacek.anaszewski@gmail.com \
    --cc=linux-leds@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=pavel@ucw.cz \
    --cc=rafal@milecki.pl \
    --cc=robh+dt@kernel.org \
    --cc=rpurdie@rpsys.net \
    /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).