Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 19b10a88 authored by Sebastian Andrzej Siewior's avatar Sebastian Andrzej Siewior Committed by Felipe Balbi
Browse files

usb: gadget: allocate & giveback serial ports instead hard code them



This patch removes gserial_setup() and gserial_cleanup() and adds
gserial_alloc_line() and gserial_free_line() to replace them.

The initial setup of u_serial happens now on module load time. A
maximum of four TTY ports can be requested which is the current limit.
In theory we could extend this limit, the hard limit is the number of
available endpoints.
alloc_tty_driver() is now called at module init time with the max
available ports. The per-line footprint here is on 32bit is 3 * size of
pointer + 60 bytes (for cdevs).
The remaining memory (struct gs_port) is allocated once a port is
requested.

With this change it is possible to load g_multi and g_serial at the same
time. GS0 receives the module that is loaded first, GS1 is received by
the next module and so on. With the configfs interface the port number
can be exported and the device node is more predictable. Nothing changes
for g_serial and friends as long as one module is used.

Signed-off-by: default avatarSebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: default avatarFelipe Balbi <balbi@ti.com>
parent b4735778
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -111,6 +111,7 @@ FSG_MODULE_PARAMETERS(/* no prefix */, fsg_mod_data);
static struct fsg_common fsg_common;

/*-------------------------------------------------------------------------*/
static unsigned char tty_line;

/*
 * We _always_ have both ACM and mass storage functions.
@@ -125,7 +126,7 @@ static int __init acm_ms_do_config(struct usb_configuration *c)
	}


	status = acm_bind_config(c, 0);
	status = acm_bind_config(c, tty_line);
	if (status < 0)
		return status;

@@ -152,7 +153,7 @@ static int __init acm_ms_bind(struct usb_composite_dev *cdev)
	void			*retp;

	/* set up serial link layer */
	status = gserial_setup(cdev->gadget, 1);
	status = gserial_alloc_line(&tty_line);
	if (status < 0)
		return status;

@@ -188,14 +189,13 @@ static int __init acm_ms_bind(struct usb_composite_dev *cdev)
fail1:
	fsg_common_put(&fsg_common);
fail0:
	gserial_cleanup();
	gserial_free_line(tty_line);
	return status;
}

static int __exit acm_ms_unbind(struct usb_composite_dev *cdev)
{
	gserial_cleanup();

	gserial_free_line(tty_line);
	return 0;
}

+5 −4
Original line number Diff line number Diff line
@@ -108,6 +108,7 @@ static u8 hostaddr[ETH_ALEN];

/*-------------------------------------------------------------------------*/

static unsigned char tty_line;
/*
 * We _always_ have both CDC ECM and CDC ACM functions.
 */
@@ -124,7 +125,7 @@ static int __init cdc_do_config(struct usb_configuration *c)
	if (status < 0)
		return status;

	status = acm_bind_config(c, 0);
	status = acm_bind_config(c, tty_line);
	if (status < 0)
		return status;

@@ -157,7 +158,7 @@ static int __init cdc_bind(struct usb_composite_dev *cdev)
		return status;

	/* set up serial link layer */
	status = gserial_setup(cdev->gadget, 1);
	status = gserial_alloc_line(&tty_line);
	if (status < 0)
		goto fail0;

@@ -183,7 +184,7 @@ static int __init cdc_bind(struct usb_composite_dev *cdev)
	return 0;

fail1:
	gserial_cleanup();
	gserial_free_line(tty_line);
fail0:
	gether_cleanup();
	return status;
@@ -191,7 +192,7 @@ fail0:

static int __exit cdc_unbind(struct usb_composite_dev *cdev)
{
	gserial_cleanup();
	gserial_free_line(tty_line);
	gether_cleanup();
	return 0;
}
+7 −3
Original line number Diff line number Diff line
@@ -231,6 +231,10 @@ static void dbgp_unbind(struct usb_gadget *gadget)
	gadget->ep0->driver_data = NULL;
}

#ifdef CONFIG_USB_G_DBGP_SERIAL
static unsigned char tty_line;
#endif

static int __init dbgp_configure_endpoints(struct usb_gadget *gadget)
{
	int stp;
@@ -268,7 +272,7 @@ static int __init dbgp_configure_endpoints(struct usb_gadget *gadget)
	dbgp.serial->in->desc = &i_desc;
	dbgp.serial->out->desc = &o_desc;

	if (gserial_setup(gadget, 1) < 0) {
	if (gserial_alloc_line(&tty_line)) {
		stp = 3;
		goto fail_3;
	}
@@ -377,7 +381,7 @@ static int dbgp_setup(struct usb_gadget *gadget,
#ifdef CONFIG_USB_G_DBGP_PRINTK
		err = dbgp_enable_ep();
#else
		err = gserial_connect(dbgp.serial, 0);
		err = gserial_connect(dbgp.serial, tty_line);
#endif
		if (err < 0)
			goto fail;
@@ -420,7 +424,7 @@ static void __exit dbgp_exit(void)
{
	usb_gadget_unregister_driver(&dbgp_driver);
#ifdef CONFIG_USB_G_DBGP_SERIAL
	gserial_cleanup();
	gserial_free_line(tty_line);
#endif
}

+0 −3
Original line number Diff line number Diff line
@@ -719,9 +719,6 @@ acm_unbind(struct usb_configuration *c, struct usb_function *f)
 *
 * Returns zero on success, else negative errno.
 *
 * Caller must have called @gserial_setup() with enough ports to
 * handle all the ones it binds.  Caller is also responsible
 * for calling @gserial_cleanup() before module unload.
 */
int acm_bind_config(struct usb_configuration *c, u8 port_num)
{
+0 −4
Original line number Diff line number Diff line
@@ -406,10 +406,6 @@ static inline bool can_support_obex(struct usb_configuration *c)
 * Context: single threaded during gadget setup
 *
 * Returns zero on success, else negative errno.
 *
 * Caller must have called @gserial_setup() with enough ports to
 * handle all the ones it binds.  Caller is also responsible
 * for calling @gserial_cleanup() before module unload.
 */
int __init obex_bind_config(struct usb_configuration *c, u8 port_num)
{
Loading