linux-hotplug.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mario Limonciello <mario_limonciello@dell.com>
To: linux-hotplug@vger.kernel.org
Subject: Re: [PATCH 2/2] hid2hci: when recovering from S3 use parent devpath
Date: Thu, 06 Aug 2009 22:03:52 +0000	[thread overview]
Message-ID: <4A7B5348.10902@dell.com> (raw)
In-Reply-To: <4A6E19FF.5070207@dell.com>


[-- Attachment #1.1: Type: text/plain, Size: 1008 bytes --]

Hi Kay:

Kay Sievers wrote:
> On Fri, Jul 31, 2009 at 21:35, Mario Limonciello<mario_limonciello@dell.com> wrote:
>   
>
> I guess, we can get rid of all these hacks and the search code, by
> tagging the mouse device we need to find, with:
> ..., ENV{HID2HCI_SWITCH}="1", RUN+="hid2hci --method=dell --devpath=%p"
>
> and for the bluetooth device we just let it trigger the
> tagged mouse device when it goes away, with:
> ..., ENV{REMOVE_CMD}="/sbin/udevadm trigger --action=change --subsystem-match=usb --property-match=HID2HCI_SWITCH=1"
>
> That way the disappearing bluetooth device would just cause
> a "change" event at the mouse device, which would trigger
> the original rule again.
> It would not need any further search logic, and the resume case
> would run the same rules as the plug-in case.
>
>   
Thanks for the suggestion!   I've cleaned up per this advice and am
attaching a new patch.

-- 
Mario Limonciello
*Dell | Linux Engineering*
mario_limonciello@dell.com

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: remove_sibling.diff --]
[-- Type: text/x-patch; name="remove_sibling.diff", Size: 6151 bytes --]

=== modified file 'extras/hid2hci/70-hid2hci.rules'
--- extras/hid2hci/70-hid2hci.rules	2009-07-24 16:06:22 +0000
+++ extras/hid2hci/70-hid2hci.rules	2009-08-06 11:45:36 +0000
@@ -1,6 +1,6 @@
 # do not edit this file, it will be overwritten on update
 
-ACTION!="add", GOTO="hid2hci_end"
+ACTION!="add|change", GOTO="hid2hci_end"
 SUBSYSTEM!="usb", GOTO="hid2hci_end"
 
 # Variety of Dell Bluetooth devices - match on a mouse device that is
@@ -8,7 +8,7 @@
 # Known supported devices: 413c:8154, 413c:8158, 413c:8162
 ATTR{bInterfaceClass}=="03", ATTR{bInterfaceSubClass}=="01", ATTR{bInterfaceProtocol}=="02", \
   ATTRS{bDeviceClass}=="00", ATTRS{idVendor}=="413c", ATTRS{bmAttributes}=="e0", \
-  RUN+="hid2hci --method=dell --devpath=%p"
+  RUN+="hid2hci --method=dell --devpath=%p", ENV{HID2HCI_SWITCH}="1"
 
 # Logitech devices (hidraw)
 KERNEL=="hidraw*", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c70[345abce]|c71[34bc]", \
@@ -21,7 +21,7 @@
 # device needs to be chased down on the USB bus.
 ATTR{bDeviceClass}=="e0", ATTR{bDeviceSubClass}=="01", ATTR{bDeviceProtocol}=="01", \
   ATTR{idVendor}=="413c", ATTR{bmAttributes}=="e0", \
-  ENV{REMOVE_CMD}="hid2hci --method=dell --devpath=%p --find-sibling-intf=03:01:02"
+  ENV{REMOVE_CMD}="/sbin/udevadm trigger --action=change --subsystem-match=usb --property-match=HID2HCI_SWITCH=1"
 
 # CSR devices
 ATTR{idVendor}=="0a12|0458|05ac", ATTR{idProduct}=="1000", RUN+="hid2hci --method=csr --devpath=%p"

=== modified file 'extras/hid2hci/hid2hci.c'
--- extras/hid2hci/hid2hci.c	2009-07-24 16:06:22 +0000
+++ extras/hid2hci/hid2hci.c	2009-08-05 08:07:51 +0000
@@ -191,70 +191,14 @@
 	return NULL;
 }
 
-static struct usb_dev_handle *find_device(struct udev_device *udev_dev, const char *sibling_intf)
+static struct usb_dev_handle *find_device(struct udev_device *udev_dev)
 {
-	struct udev *udev = udev_device_get_udev(udev_dev);
 	struct usb_device *dev;
-	struct udev_device *udev_parent;
-	char str[UTIL_NAME_SIZE];
-	struct udev_enumerate *enumerate;
-	struct udev_list_entry *entry;
-	struct usb_dev_handle *handle = NULL;
-
-	if (sibling_intf == NULL) {
-		dev = usb_device_open_from_udev(udev_dev);
-		if (dev == NULL)
-			return NULL;
-		return usb_open(dev);
-	}
-
-	/* find matching sibling of the current usb_device, they share the same hub */
-	udev_parent = udev_device_get_parent_with_subsystem_devtype(udev_dev, "usb", "usb_device");
-	if (udev_parent == NULL)
-		return NULL;
-
-	enumerate = udev_enumerate_new(udev);
-	if (enumerate == NULL)
-		return NULL;
-
-	udev_enumerate_add_match_subsystem(enumerate, "usb");
-
-	/* match all childs of the parent */
-	util_strscpyl(str, sizeof(str), udev_device_get_sysname(udev_parent), "*", NULL);
-	udev_enumerate_add_match_sysname(enumerate, str);
-
-	/* match the specified interface */
-	util_strscpy(str, sizeof(str), sibling_intf);
-	str[2] = '\0';
-	str[5] = '\0';
-	str[8] = '\0';
-	if (strcmp(str, "-1") != 0)
-		udev_enumerate_add_match_sysattr(enumerate, "bInterfaceClass", str);
-	if (strcmp(&str[3], "-1") != 0)
-		udev_enumerate_add_match_sysattr(enumerate, "bInterfaceSubClass", &str[3]);
-	if (strcmp(&str[6], "-1") != 0)
-		udev_enumerate_add_match_sysattr(enumerate, "bInterfaceProtocol", &str[6]);
-
-	udev_enumerate_scan_devices(enumerate);
-	udev_list_entry_foreach(entry, udev_enumerate_get_list_entry(enumerate)) {
-		struct udev_device *udev_device;
-
-		udev_device = udev_device_new_from_syspath(udev, udev_list_entry_get_name(entry));
-		if (udev_device != NULL) {
-			/* get the usb_device of the usb_interface we matched */
-			udev_parent = udev_device_get_parent_with_subsystem_devtype(udev_device, "usb", "usb_device");
-			if (udev_parent == NULL)
-				continue;
-			/* only look at the first matching device */
-			dev = usb_device_open_from_udev(udev_parent);
-			if (dev != NULL)
-				handle = usb_open(dev);
-			udev_device_unref(udev_device);
-			break;
-		}
-}
-	udev_enumerate_unref(enumerate);
-	return handle;
+
+	dev = usb_device_open_from_udev(udev_dev);
+	if (dev == NULL)
+		return NULL;
+	return usb_open(dev);
 }
 
 static void usage(const char *error)
@@ -268,7 +212,6 @@
 		"  --mode=               mode to switch to [hid|hci] (default hci)\n"
 		"  --devpath=            sys device path\n"
 		"  --method=             method to use to switch [csr|logitech-hid|dell]\n"
-		"  --find-sibling-intf=  find the sibling device with 00:00:00 (class:subclass:prot)\n"
 		"  --help\n\n");
 }
 
@@ -279,7 +222,6 @@
 		{ "mode", required_argument, NULL, 'm' },
 		{ "devpath", required_argument, NULL, 'p' },
 		{ "method", required_argument, NULL, 'M' },
-		{ "find-sibling-intf", required_argument, NULL, 'I' },
 		{ }
 	};
 	enum method {
@@ -294,14 +236,13 @@
 	int (*usb_switch)(struct usb_dev_handle *dev, enum mode mode) = NULL;
 	enum mode mode = HCI;
 	const char *devpath = NULL;
-	const char *sibling_intf = NULL;
 	int err = -1;
 	int rc = 1;
 
 	for (;;) {
 		int option;
 
-		option = getopt_long(argc, argv, "m:p:M:I:qh", options, NULL);
+		option = getopt_long(argc, argv, "m:p:M:qh", options, NULL);
 		if (option == -1)
 			break;
 
@@ -333,9 +274,6 @@
 				exit(1);
 			}
 			break;
-		case 'I':
-			sibling_intf = optarg;
-			break;
 		case 'h':
 			usage(NULL);
 		default:
@@ -377,10 +315,10 @@
 			}
 		}
 
-		handle = find_device(dev, sibling_intf);
+		handle = find_device(dev);
 		if (handle == NULL) {
-			fprintf(stderr, "error: unable to handle '%s' (intf=%s)\n",
-				udev_device_get_syspath(dev), sibling_intf);
+			fprintf(stderr, "error: unable to handle '%s'\n",
+				udev_device_get_syspath(dev));
 			goto exit;
 		}
 		err = usb_switch(handle, mode);
@@ -402,8 +340,8 @@
 	}
 
 	if (err < 0)
-		fprintf(stderr, "error: switching device '%s' (intf=%s) failed.\n",
-			udev_device_get_syspath(udev_dev), sibling_intf);
+		fprintf(stderr, "error: switching device '%s' failed.\n",
+			udev_device_get_syspath(udev_dev));
 exit:
 	udev_device_unref(udev_dev);
 	udev_unref(udev);


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 260 bytes --]

  parent reply	other threads:[~2009-08-06 22:03 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-27 21:19 [PATCH 2/2] hid2hci: when recovering from S3 use parent devpath Mario Limonciello
2009-07-27 21:35 ` Marcel Holtmann
2009-07-27 22:36 ` Mario Limonciello
2009-07-27 22:42 ` Marcel Holtmann
2009-07-28  0:04 ` Kay Sievers
2009-07-28 18:10 ` Mario Limonciello
2009-07-31 18:53 ` Kay Sievers
2009-07-31 19:35 ` Mario Limonciello
2009-08-05  7:47 ` Kay Sievers
2009-08-06 22:03 ` Mario Limonciello [this message]
2009-08-07  0:27 ` Kay Sievers
2009-08-07  0:44 ` Marcel Holtmann
2009-08-07  0:57 ` Kay Sievers
2009-08-07  1:28 ` Marco d'Itri
2009-08-07  1:47 ` Kay Sievers
2009-08-07  3:48 ` Marco d'Itri
2009-08-11 17:49 ` Karl O. Pinc
2009-08-11 22:22 ` Marcel Holtmann

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=4A7B5348.10902@dell.com \
    --to=mario_limonciello@dell.com \
    --cc=linux-hotplug@vger.kernel.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: 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).