USB: serial: allow subdrivers to modify port-endpoint mapping

Allow subdrivers to modify the port-endpoint mapping by passing the
endpoint descriptors to calc_num_ports.

The callback can now also be used to verify that the required endpoints
exists and abort probing otherwise.

This will allow us to get rid of a few hacks in subdrivers that are
already modifying the port-endpoint mapping (or aborting probe due to
missing endpoints), but only after the port structures have been setup.

Signed-off-by: Johan Hovold <johan@kernel.org>
This commit is contained in:
Johan Hovold
2017-03-16 17:13:30 +01:00
parent 2ac8fc51dd
commit 07814246dd
10 changed files with 42 additions and 26 deletions

View File

@@ -181,6 +181,17 @@ static inline void usb_set_serial_data(struct usb_serial *serial, void *data)
serial->private = data;
}
struct usb_serial_endpoints {
unsigned char num_bulk_in;
unsigned char num_bulk_out;
unsigned char num_interrupt_in;
unsigned char num_interrupt_out;
struct usb_endpoint_descriptor *bulk_in[MAX_NUM_PORTS];
struct usb_endpoint_descriptor *bulk_out[MAX_NUM_PORTS];
struct usb_endpoint_descriptor *interrupt_in[MAX_NUM_PORTS];
struct usb_endpoint_descriptor *interrupt_out[MAX_NUM_PORTS];
};
/**
* usb_serial_driver - describes a usb serial driver
* @description: pointer to a string that describes this driver. This string
@@ -196,8 +207,9 @@ static inline void usb_set_serial_data(struct usb_serial *serial, void *data)
* (0 = end-point size)
* @bulk_out_size: bytes to allocate for bulk-out buffer (0 = end-point size)
* @calc_num_ports: pointer to a function to determine how many ports this
* device has dynamically. It will be called after the probe()
* callback is called, but before attach()
* device has dynamically. It can also be used to verify the number of
* endpoints or to modify the port-endpoint mapping. It will be called
* after the probe() callback is called, but before attach().
* @probe: pointer to the driver's probe function.
* This will be called when the device is inserted into the system,
* but before the device has been fully initialized by the usb_serial
@@ -249,7 +261,8 @@ struct usb_serial_driver {
int (*probe)(struct usb_serial *serial, const struct usb_device_id *id);
int (*attach)(struct usb_serial *serial);
int (*calc_num_ports) (struct usb_serial *serial);
int (*calc_num_ports)(struct usb_serial *serial,
struct usb_serial_endpoints *epds);
void (*disconnect)(struct usb_serial *serial);
void (*release)(struct usb_serial *serial);