Juergen Beisert wrote: > Arvid Brodin wrote: >> What's the best way to get a notification in user space when an overcurrent >> event occurs on a usb port? The idea is to let a user application notify >> the user that something is wrong. > > Long time ago (linux-2.6.36) we did this in one of our projects, to forward > this event to userland. > > From: Juergen Beisert <jbe@xxxxxxxxxxxxxx> > Date: Wed, 11 Aug 2010 14:18:04 +0200 > Subject: [PATCH] Generate a uevent when an overcurrent event happens > > This quick hack generates a 'uevent' to userland and adds the 'POWERFAIL=1' > environment variable for this report. Any userland program listening to the > 'uevent' interface can filter for the presence of this environment variable > to distinguish this special 'uevent' from other 'add' or 'remove' events. > > Current disadvantage: Due to the fact, the hub driver tries to enable the > port again immediately (it does not wait for user interaction) this powerfail > event gets reported twice: First time when it really happens and second time > when the external overcurrent detection device will be reset. The second > false positive report must be sorted out by the userland application. > > Signed-off-by: Juergen Beisert <jbe@xxxxxxxxxxxxxx> > Signed-off-by: Michael Grzeschik <m.grzeschik@xxxxxxxxxxxxxx> > --- > drivers/usb/core/hub.c | 4 ++++ > 1 file changed, 4 insertions(+), 0 deletions(-) > > diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c > index 84c18971..c615292 100644 > --- a/drivers/usb/core/hub.c > +++ b/drivers/usb/core/hub.c > @@ -3372,9 +3372,13 @@ static void hub_events(void) > } > > if (portchange & USB_PORT_STAT_C_OVERCURRENT) { > + char event[] = "POWERFAIL=1"; > + char *envp[] = { event, NULL }; > + > dev_err (hub_dev, > "over-current change on port %d\n", > i); > + kobject_uevent_env(&hub->intfdev->kobj, KOBJ_CHANGE, envp); > clear_port_feature(hdev, i, > USB_PORT_FEAT_C_OVER_CURRENT); > hub_power_on(hub, true); > Thank you, this might be useful! -- Arvid Brodin Enea Services Stockholm AB -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html