Skip to content

Commit c9d5033

Browse files
hadessgregkh
authored andcommitted
USB: Make it possible to "subclass" usb_device_driver
The kernel currenly has only 2 usb_device_drivers, one generic one, one that completely replaces the generic one to make USB devices usable over a network. Use the newly exported generic driver functions when a driver declares to want them run, in addition to its own code. This makes it possible to write drivers that extend the generic USB driver. Note that this patch is not enough for another driver to automatically get selected. Signed-off-by: Bastien Nocera <[email protected]> Acked-by: Alan Stern <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent ef0f7d1 commit c9d5033

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

drivers/usb/core/driver.c

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,16 @@ static int usb_probe_device(struct device *dev)
261261
*/
262262
if (!udriver->supports_autosuspend)
263263
error = usb_autoresume_device(udev);
264+
if (error)
265+
return error;
264266

265-
if (!error)
266-
error = udriver->probe(udev);
267+
if (udriver->generic_subclass)
268+
error = usb_generic_driver_probe(udev);
269+
if (error)
270+
return error;
271+
272+
error = udriver->probe(udev);
273+
/* TODO: fallback to generic driver in case of error */
267274
return error;
268275
}
269276

@@ -273,7 +280,10 @@ static int usb_unbind_device(struct device *dev)
273280
struct usb_device *udev = to_usb_device(dev);
274281
struct usb_device_driver *udriver = to_usb_device_driver(dev->driver);
275282

276-
udriver->disconnect(udev);
283+
if (udriver->disconnect)
284+
udriver->disconnect(udev);
285+
if (udriver->generic_subclass)
286+
usb_generic_driver_disconnect(udev);
277287
if (!udriver->supports_autosuspend)
278288
usb_autosuspend_device(udev);
279289
return 0;
@@ -1149,7 +1159,10 @@ static int usb_suspend_device(struct usb_device *udev, pm_message_t msg)
11491159
udev->do_remote_wakeup = 0;
11501160
udriver = &usb_generic_driver;
11511161
}
1152-
status = udriver->suspend(udev, msg);
1162+
if (udriver->suspend)
1163+
status = udriver->suspend(udev, msg);
1164+
if (status == 0 && udriver->generic_subclass)
1165+
status = usb_generic_driver_suspend(udev, msg);
11531166

11541167
done:
11551168
dev_vdbg(&udev->dev, "%s: status %d\n", __func__, status);
@@ -1181,7 +1194,10 @@ static int usb_resume_device(struct usb_device *udev, pm_message_t msg)
11811194
udev->reset_resume = 1;
11821195

11831196
udriver = to_usb_device_driver(udev->dev.driver);
1184-
status = udriver->resume(udev, msg);
1197+
if (udriver->generic_subclass)
1198+
status = usb_generic_driver_resume(udev, msg);
1199+
if (status == 0 && udriver->resume)
1200+
status = udriver->resume(udev, msg);
11851201

11861202
done:
11871203
dev_vdbg(&udev->dev, "%s: status %d\n", __func__, status);

include/linux/usb.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,6 +1228,9 @@ struct usb_driver {
12281228
* @drvwrap: Driver-model core structure wrapper.
12291229
* @supports_autosuspend: if set to 0, the USB core will not allow autosuspend
12301230
* for devices bound to this driver.
1231+
* @generic_subclass: if set to 1, the generic USB driver's probe, disconnect,
1232+
* resume and suspend functions will be called in addition to the driver's
1233+
* own, so this part of the setup does not need to be replicated.
12311234
*
12321235
* USB drivers must provide all the fields listed above except drvwrap.
12331236
*/
@@ -1242,6 +1245,7 @@ struct usb_device_driver {
12421245
const struct attribute_group **dev_groups;
12431246
struct usbdrv_wrap drvwrap;
12441247
unsigned int supports_autosuspend:1;
1248+
unsigned int generic_subclass:1;
12451249
};
12461250
#define to_usb_device_driver(d) container_of(d, struct usb_device_driver, \
12471251
drvwrap.driver)

0 commit comments

Comments
 (0)