Re: [PATCH V2 PROOF OF CONCEPT 2/1] trigger: ledtrig-usbport: read initial state from DT
On 13 July 2016 at 16:48, Jacek Anaszewskiwrote: > On 07/13/2016 02:42 PM, Rafał Miłecki wrote: >> >> This allows specifying USB ports that should be observed by a trigger >> right after activating it. Example: >> >> usb { >> gpios = < 0 GPIO_ACTIVE_HIGH>; >> linux,default-trigger = "usbport"; >> usb-controllers = <>, <>, < USB_HCD_SHARED>; >> usb-ports = "1", "1", "1"; > > > Port is a numerical value, right? > Wouldn't it be better to define it as an array of integers? > > e.g.: usb-ports = <1>. <1>, <1>; Not always. Let me quote this part of "usbport" documentation: > This also allows handling devices with internal hubs (when root hub's port has > always a device (hub) connected). User can simply specify specify internal hub > ports then (e.g. 1-1.1, 1-1.2, etc.). In such case we'd need usb-ports = "1.1", "1.2"; Anyway, there is a discussion ongoing in: [PATCH V2 0/1] usb: add HCD providers so let's see if someone will have a better idea for referencing USB ports inside DT. -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH V2 PROOF OF CONCEPT 2/1] trigger: ledtrig-usbport: read initial state from DT
Hi Rafał, On 07/13/2016 02:42 PM, Rafał Miłecki wrote: This allows specifying USB ports that should be observed by a trigger right after activating it. Example: usb { gpios = < 0 GPIO_ACTIVE_HIGH>; linux,default-trigger = "usbport"; usb-controllers = <>, <>, < USB_HCD_SHARED>; usb-ports = "1", "1", "1"; Port is a numerical value, right? Wouldn't it be better to define it as an array of integers? e.g.: usb-ports = <1>. <1>, <1>; }; Please provide a patch with DT bindings documentation for this trigger. I infer that usb-controllers and usb-ports are new properties. Adding also Felipe, Mark and Rob. Signed-off-by: Rafał Miłecki--- 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 #include #include +#include #include #include +#include #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(>list, _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, ); + if (err) + continue; + + err = of_parse_phandle_with_args(np, "usb-controllers", "#usb-cells", i, ); + if (err) + continue; + + hcd = of_hcd_get_from_provider(); + 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(_data->ports); + usbport_trig_fill(usbport_data); usbport_data->nb.notifier_call = usbport_trig_notify, led_cdev->trigger_data = usbport_data; -- Best regards, Jacek Anaszewski -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH V2 PROOF OF CONCEPT 2/1] trigger: ledtrig-usbport: read initial state from DT
This allows specifying USB ports that should be observed by a trigger right after activating it. Example: usb { gpios = < 0 GPIO_ACTIVE_HIGH>; linux,default-trigger = "usbport"; usb-controllers = <>, <>, < USB_HCD_SHARED>; usb-ports = "1", "1", "1"; }; Signed-off-by: Rafał Miłecki--- 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 #include #include +#include #include #include +#include #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(>list, _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, ); + if (err) + continue; + + err = of_parse_phandle_with_args(np, "usb-controllers", "#usb-cells", i, ); + if (err) + continue; + + hcd = of_hcd_get_from_provider(); + 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(_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 majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html