From: "Rafał Miłecki" <zajec5-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> To: Greg Kroah-Hartman <gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org> Cc: linux-usb-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-leds-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, "Rafał Miłecki" <zajec5-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>, "Richard Purdie" <rpurdie-Fm38FmjxZ/leoWH0uzbU5w@public.gmane.org>, "Jacek Anaszewski" <j.anaszewski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>, "open list" <linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org> Subject: [PATCH V2 PROOF OF CONCEPT 2/1] trigger: ledtrig-usbport: read initial state from DT Date: Wed, 13 Jul 2016 14:42:14 +0200 [thread overview] Message-ID: <1468413734-9569-3-git-send-email-zajec5@gmail.com> (raw) In-Reply-To: <1468413734-9569-1-git-send-email-zajec5-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> This allows specifying USB ports that should be observed by a trigger right after activating it. Example: usb { gpios = <&gpio 0 GPIO_ACTIVE_HIGH>; linux,default-trigger = "usbport"; usb-controllers = <&ohci>, <&ehci>, <&xhci USB_HCD_SHARED>; usb-ports = "1", "1", "1"; }; Signed-off-by: Rafał Miłecki <zajec5-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> --- drivers/leds/trigger/ledtrig-usbport.c | 72 ++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/drivers/leds/trigger/ledtrig-usbport.c b/drivers/leds/trigger/ledtrig-usbport.c index eb20a8f..5724f63 100644 --- a/drivers/leds/trigger/ledtrig-usbport.c +++ b/drivers/leds/trigger/ledtrig-usbport.c @@ -12,8 +12,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/provider.h> #include "../leds.h" struct usbport_trig_port { @@ -94,6 +96,75 @@ static bool usbport_trig_match(struct usbport_trig_data *usbport_data, return false; } +static int usbport_trig_new_port(struct usbport_trig_data *usbport_data, + int busnum, const char *suffix) +{ + struct usbport_trig_port *port; + size_t len; + int tmp; + + tmp = busnum; + len = 1; + while (tmp >= 10) { + tmp /= 10; + len++; + } + len++; /* '-' */ + len += strlen(suffix); + len++; /* '\0' */ + + port = kzalloc(sizeof(*port), GFP_KERNEL); + if (!port) + return -ENOMEM; + + port->name = kzalloc(len, GFP_KERNEL); + if (!port->name) { + kfree(port); + return -ENOMEM; + } + snprintf(port->name, len, "%d-%s", busnum, suffix); + + list_add_tail(&port->list, &usbport_data->ports); + + return 0; +} + +static int usbport_trig_fill(struct usbport_trig_data *usbport_data) +{ + struct device_node *np = usbport_data->led_cdev->dev->of_node; + struct of_phandle_args args; + int count, i; + int err = 0; + + if (!np) + return -ENOENT; + + count = of_property_count_strings(np, "usb-ports"); + if (count < 0) + return count; + + for (i = 0; i < count; i++) { + const char *port; + struct usb_hcd *hcd; + + err = of_property_read_string_index(np, "usb-ports", i, &port); + if (err) + continue; + + err = of_parse_phandle_with_args(np, "usb-controllers", "#usb-cells", i, &args); + if (err) + continue; + + hcd = of_hcd_get_from_provider(&args); + if (!IS_ERR(hcd)) + usbport_trig_new_port(usbport_data, hcd->self.busnum, port); + + of_node_put(args.np); + } + + return err; +} + static int usbport_trig_notify(struct notifier_block *nb, unsigned long action, void *data) { @@ -129,6 +200,7 @@ static void usbport_trig_activate(struct led_classdev *led_cdev) return; usbport_data->led_cdev = led_cdev; INIT_LIST_HEAD(&usbport_data->ports); + usbport_trig_fill(usbport_data); usbport_data->nb.notifier_call = usbport_trig_notify, led_cdev->trigger_data = usbport_data; -- 1.8.4.5 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html
WARNING: multiple messages have this Message-ID (diff)
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, devicetree@vger.kernel.org, "Rafał Miłecki" <zajec5@gmail.com>, "Richard Purdie" <rpurdie@rpsys.net>, "Jacek Anaszewski" <j.anaszewski@samsung.com>, linux-kernel@vger.kernel.org (open list) Subject: [PATCH V2 PROOF OF CONCEPT 2/1] trigger: ledtrig-usbport: read initial state from DT Date: Wed, 13 Jul 2016 14:42:14 +0200 [thread overview] Message-ID: <1468413734-9569-3-git-send-email-zajec5@gmail.com> (raw) In-Reply-To: <1468413734-9569-1-git-send-email-zajec5@gmail.com> This allows specifying USB ports that should be observed by a trigger right after activating it. Example: usb { gpios = <&gpio 0 GPIO_ACTIVE_HIGH>; linux,default-trigger = "usbport"; usb-controllers = <&ohci>, <&ehci>, <&xhci USB_HCD_SHARED>; usb-ports = "1", "1", "1"; }; Signed-off-by: Rafał Miłecki <zajec5@gmail.com> --- drivers/leds/trigger/ledtrig-usbport.c | 72 ++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/drivers/leds/trigger/ledtrig-usbport.c b/drivers/leds/trigger/ledtrig-usbport.c index eb20a8f..5724f63 100644 --- a/drivers/leds/trigger/ledtrig-usbport.c +++ b/drivers/leds/trigger/ledtrig-usbport.c @@ -12,8 +12,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/provider.h> #include "../leds.h" struct usbport_trig_port { @@ -94,6 +96,75 @@ static bool usbport_trig_match(struct usbport_trig_data *usbport_data, return false; } +static int usbport_trig_new_port(struct usbport_trig_data *usbport_data, + int busnum, const char *suffix) +{ + struct usbport_trig_port *port; + size_t len; + int tmp; + + tmp = busnum; + len = 1; + while (tmp >= 10) { + tmp /= 10; + len++; + } + len++; /* '-' */ + len += strlen(suffix); + len++; /* '\0' */ + + port = kzalloc(sizeof(*port), GFP_KERNEL); + if (!port) + return -ENOMEM; + + port->name = kzalloc(len, GFP_KERNEL); + if (!port->name) { + kfree(port); + return -ENOMEM; + } + snprintf(port->name, len, "%d-%s", busnum, suffix); + + list_add_tail(&port->list, &usbport_data->ports); + + return 0; +} + +static int usbport_trig_fill(struct usbport_trig_data *usbport_data) +{ + struct device_node *np = usbport_data->led_cdev->dev->of_node; + struct of_phandle_args args; + int count, i; + int err = 0; + + if (!np) + return -ENOENT; + + count = of_property_count_strings(np, "usb-ports"); + if (count < 0) + return count; + + for (i = 0; i < count; i++) { + const char *port; + struct usb_hcd *hcd; + + err = of_property_read_string_index(np, "usb-ports", i, &port); + if (err) + continue; + + err = of_parse_phandle_with_args(np, "usb-controllers", "#usb-cells", i, &args); + if (err) + continue; + + hcd = of_hcd_get_from_provider(&args); + if (!IS_ERR(hcd)) + usbport_trig_new_port(usbport_data, hcd->self.busnum, port); + + of_node_put(args.np); + } + + return err; +} + static int usbport_trig_notify(struct notifier_block *nb, unsigned long action, void *data) { @@ -129,6 +200,7 @@ static void usbport_trig_activate(struct led_classdev *led_cdev) return; usbport_data->led_cdev = led_cdev; INIT_LIST_HEAD(&usbport_data->ports); + usbport_trig_fill(usbport_data); usbport_data->nb.notifier_call = usbport_trig_notify, led_cdev->trigger_data = usbport_data; -- 1.8.4.5
next prev parent reply other threads:[~2016-07-13 12:42 UTC|newest] Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top 2016-07-12 12:35 [PATCH 0/2] usb: add HCD providers Rafał Miłecki 2016-07-12 12:35 ` [PATCH 1/2] usb: core: add support for " Rafał Miłecki 2016-07-12 12:35 ` Rafał Miłecki [not found] ` <1468326921-26485-2-git-send-email-zajec5-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 2016-08-09 13:56 ` Greg Kroah-Hartman 2016-08-09 13:56 ` Greg Kroah-Hartman 2016-07-12 12:35 ` [PATCH 2/2] ohci-platform: register HCD provider Rafał Miłecki 2016-07-12 12:35 ` Rafał Miłecki 2016-07-12 12:35 ` [PATCH PROOF OF CONCEPT 3/2] trigger: ledtrig-usbport: read initial state from DT Rafał Miłecki 2016-07-12 12:35 ` Rafał Miłecki 2016-07-13 4:51 ` [PATCH 0/2] usb: add HCD providers Peter Chen 2016-07-13 5:21 ` Rafał Miłecki [not found] ` <CACna6rw6QOuY247qvDmO4mKrW3y4yXoeM3qr8SXAwn3CuYAMpw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 2016-07-13 8:02 ` Peter Chen 2016-07-13 9:31 ` Rafał Miłecki [not found] ` <1468326921-26485-1-git-send-email-zajec5-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 2016-07-13 12:42 ` [PATCH V2 0/1] " Rafał Miłecki [not found] ` <1468413734-9569-1-git-send-email-zajec5-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 2016-07-13 12:42 ` [PATCH V2 1/1] usb: core: add support for " Rafał Miłecki 2016-07-13 12:42 ` Rafał Miłecki 2016-07-13 12:42 ` Rafał Miłecki [this message] 2016-07-13 12:42 ` [PATCH V2 PROOF OF CONCEPT 2/1] trigger: ledtrig-usbport: read initial state from DT Rafał Miłecki [not found] ` <1468413734-9569-3-git-send-email-zajec5-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 2016-07-13 14:48 ` Jacek Anaszewski 2016-07-13 14:48 ` Jacek Anaszewski [not found] ` <578654A7.2020909-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org> 2016-07-13 15:05 ` Rafał Miłecki 2016-07-13 15:05 ` Rafał Miłecki 2016-07-13 13:20 ` [PATCH V2 0/1] usb: add HCD providers Felipe Balbi [not found] ` <87lh15isi7.fsf-VuQAYsv1563Yd54FQh9/CA@public.gmane.org> 2016-07-13 13:34 ` Rafał Miłecki [not found] ` <CACna6rxGN5evQhRpNORUP4RP3-pMa292pQW=4=VWLLnzJyhJJw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 2016-07-13 13:50 ` Felipe Balbi [not found] ` <87inw9ir4k.fsf-VuQAYsv1563Yd54FQh9/CA@public.gmane.org> 2016-07-13 14:40 ` Rafał Miłecki 2016-07-14 9:48 ` Peter Chen 2016-07-14 10:05 ` Felipe Balbi 2016-07-14 15:52 ` Rafał Miłecki 2016-07-15 2:28 ` Peter Chen 2016-07-15 5:48 ` Rafał Miłecki 2016-07-15 6:22 ` Peter Chen 2016-07-15 9:35 ` Rafał Miłecki
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=1468413734-9569-3-git-send-email-zajec5@gmail.com \ --to=zajec5-re5jqeeqqe8avxtiumwx3w@public.gmane.org \ --cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \ --cc=gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org \ --cc=j.anaszewski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org \ --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \ --cc=linux-leds-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \ --cc=linux-usb-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \ --cc=rpurdie-Fm38FmjxZ/leoWH0uzbU5w@public.gmane.org \ /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: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.