All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marek Vasut <marex@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 1/3] usb:gadget:composite USB composite gadget support
Date: Tue, 17 Apr 2012 09:47:33 +0200	[thread overview]
Message-ID: <201204170947.34137.marex@denx.de> (raw)
In-Reply-To: <1334647664-30422-2-git-send-email-l.majewski@samsung.com>

Dear Lukasz Majewski,

> USB Composite gadget implementation for u-boot. It builds on top
> of USB UDC drivers.
> 
> This commit is based on following files from Linux Kernel v2.6.36:
> 
> ./include/linux/usb/composite.h
> ./drivers/usb/gadget/composite.c
> 
> SHA1: d187abb9a83e6c6b6e9f2ca17962bdeafb4bc903
> 
> Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
> Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
> Cc: Marek Vasut <marex@denx.de>
> 
> ---
> Changes for v2:
> - Squash the kernel files with u-boot compatibility layer.
> - Removal of dead/kernel specific code
> - Comments corrected according to u-boot coding style
> ---
>  drivers/usb/gadget/composite.c  | 1091
> +++++++++++++++++++++++++++++++++++++++ include/linux/usb/composite.h   | 
> 350 +++++++++++++
>  include/usb/lin_gadget_compat.h |   25 +-
>  3 files changed, 1464 insertions(+), 2 deletions(-)
>  create mode 100644 drivers/usb/gadget/composite.c
>  create mode 100644 include/linux/usb/composite.h

[...]

> +int usb_string_ids_n(struct usb_composite_dev *c, unsigned n)
> +{
> +	unsigned next = c->next_string_id;
> +	if (unlikely(n > 254 || (unsigned)next + n > 254))

This unlikely() call is unlikely part of uboot :)

> +		return -ENODEV;
> +	c->next_string_id += n;
> +	return next + 1;
> +}
> +
> +static void composite_setup_complete(struct usb_ep *ep, struct usb_request
> *req) +{
> +	if (req->status || req->actual != req->length)
> +		debug("%s: setup complete --> %d, %d/%d\n", __func__,
> +				req->status, req->actual, req->length);
> +}
> +
> +/*

[...]

> +
> +static void composite_unbind(struct usb_gadget *gadget)
> +{
> +	struct usb_composite_dev	*cdev = get_gadget_data(gadget);
> +
> +	/*
> +	 * composite_disconnect() must already have been called
> +	 * by the underlying peripheral controller driver!
> +	 * so there's no i/o concurrency that could affect the
> +	 * state protected by cdev->lock.
> +	 */
> +	BUG_ON(cdev->config);

Do we have BUG_ON() defined in uboot ?

> +
> +	while (!list_empty(&cdev->configs)) {
> +		struct usb_configuration	*c;
> +
> +		c = list_first_entry(&cdev->configs,
> +				struct usb_configuration, list);
> +		while (!list_empty(&c->functions)) {
> +			struct usb_function		*f;
> +
> +			f = list_first_entry(&c->functions,
> +					struct usb_function, list);
> +			list_del(&f->list);
> +			if (f->unbind) {
> +				debug("unbind function '%s'/%p\n",
> +						f->name, f);
> +				f->unbind(c, f);
> +			}
> +		}
> +		list_del(&c->list);
> +		if (c->unbind) {
> +			debug("unbind config '%s'/%p\n", c->label, c);
> +			c->unbind(c);
> +		}
> +	}
> +	if (composite->unbind)
> +		composite->unbind(cdev);
> +
> +	if (cdev->req) {
> +		kfree(cdev->req->buf);
> +		usb_ep_free_request(gadget->ep0, cdev->req);
> +	}
> +	kfree(cdev);
> +	set_gadget_data(gadget, NULL);
> +
> +	composite = NULL;
> +}
> +
> +static int composite_bind(struct usb_gadget *gadget)
> +{
> +	struct usb_composite_dev	*cdev;
> +	int				status = -ENOMEM;
> +
> +	cdev = calloc(sizeof *cdev, 1);
> +	if (!cdev)
> +		return status;
> +
> +	cdev->gadget = gadget;
> +	set_gadget_data(gadget, cdev);
> +	INIT_LIST_HEAD(&cdev->configs);
> +
> +	/* preallocate control response and buffer */
> +	cdev->req = usb_ep_alloc_request(gadget->ep0, GFP_KERNEL);
> +	if (!cdev->req)
> +		goto fail;
> +	cdev->req->buf = kmalloc(USB_BUFSIZ, GFP_KERNEL);
> +	if (!cdev->req->buf)
> +		goto fail;
> +	cdev->req->complete = composite_setup_complete;
> +	gadget->ep0->driver_data = cdev;
> +
> +	cdev->bufsiz = USB_BUFSIZ;
> +	cdev->driver = composite;
> +
> +	usb_gadget_set_selfpowered(gadget);
> +	usb_ep_autoconfig_reset(cdev->gadget);
> +
> +	status = composite->bind(cdev);
> +	if (status < 0)
> +		goto fail;
> +
> +	cdev->desc = *composite->dev;
> +	cdev->desc.bMaxPacketSize0 = gadget->ep0->maxpacket;
> +
> +	debug("%s: ready\n", composite->name);
> +	return 0;
> +
> +fail:
> +	composite_unbind(gadget);
> +	return status;
> +}
> +
> +static void
> +composite_suspend(struct usb_gadget *gadget)
> +{
> +	struct usb_composite_dev	*cdev = get_gadget_data(gadget);
> +	struct usb_function		*f;
> +
> +	debug("%s: suspend\n", __func__);
> +	if (cdev->config) {
> +		list_for_each_entry(f, &cdev->config->functions, list) {
> +			if (f->suspend)
> +				f->suspend(f);
> +		}
> +	}
> +	if (composite->suspend)
> +		composite->suspend(cdev);
> +
> +	cdev->suspended = 1;
> +}
> +
> +static void
> +composite_resume(struct usb_gadget *gadget)
> +{
> +	struct usb_composite_dev	*cdev = get_gadget_data(gadget);
> +	struct usb_function		*f;
> +
> +	debug("%s: resume\n", __func__);
> +	if (composite->resume)
> +		composite->resume(cdev);
> +	if (cdev->config) {
> +		list_for_each_entry(f, &cdev->config->functions, list) {
> +			if (f->resume)
> +				f->resume(f);
> +		}
> +	}
> +
> +	cdev->suspended = 0;
> +}
> +
> +static struct usb_gadget_driver composite_driver = {
> +	.speed		= USB_SPEED_HIGH,
> +
> +	.bind		= composite_bind,
> +	.unbind	= composite_unbind,

You have some weird indent in here?

> +
> +	.setup		= composite_setup,
> +	.disconnect	= composite_disconnect,
> +
> +	.suspend	= composite_suspend,
> +	.resume	= composite_resume,
> +};
> +

I think this patch is getting much better ;-)

  reply	other threads:[~2012-04-17  7:47 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-12  7:15 [U-Boot] [PATCH 0/4] usb:gadget:composite: Support for composite gadget framework Lukasz Majewski
2012-04-12  7:15 ` [U-Boot] [PATCH 1/4] usb:gadget:composite Composite framework - files from Linux kernel Lukasz Majewski
2012-04-14  9:46   ` Marek Vasut
2012-04-14 13:41   ` Wolfgang Denk
2012-04-14 13:42   ` Wolfgang Denk
2012-04-16  9:10     ` Lukasz Majewski
2012-04-16 13:59       ` Wolfgang Denk
2012-04-12  7:15 ` [U-Boot] [PATCH 2/4] usb:gadget:composite: Linux composite.{h/c} code adjustement for u-boot Lukasz Majewski
2012-04-14 13:46   ` Wolfgang Denk
2012-04-16  9:23     ` Lukasz Majewski
2012-04-16 14:01       ` Wolfgang Denk
2012-04-12  7:15 ` [U-Boot] [PATCH 3/4] usb:gadget: Wrapper for extracting usb_gadget from linux's device Lukasz Majewski
2012-04-14  9:47   ` Marek Vasut
2012-04-12  7:15 ` [U-Boot] [PATCH 4/4] usb:gadget: Extend device struct to device_data pointer Lukasz Majewski
2012-04-17  7:27 ` [U-Boot] [PATCH v2 0/3] usb:gadget:composite: Support for composite gadget framework Lukasz Majewski
2012-04-17  7:27   ` [U-Boot] [PATCH v2 1/3] usb:gadget:composite USB composite gadget support Lukasz Majewski
2012-04-17  7:47     ` Marek Vasut [this message]
2012-04-17 12:45       ` Lukasz Majewski
2012-04-17  7:27   ` [U-Boot] [PATCH v2 2/3] usb:gadget:composite: Support for composite at gadget.h Lukasz Majewski
2012-04-17  7:27   ` [U-Boot] [PATCH v2 3/3] usb:udc:samsung Add functions for storing private gadget data in UDC driver Lukasz Majewski
2012-04-17  7:59     ` Marek Vasut
2012-04-17 14:07 ` [U-Boot] [PATCH v3 0/3] usb:gadget:composite: Support for composite gadget framework Lukasz Majewski
2012-04-17 14:07   ` [U-Boot] [PATCH v3 1/3] usb:gadget:composite USB composite gadget support Lukasz Majewski
2012-04-17 15:32     ` Marek Vasut
2012-04-17 14:07   ` [U-Boot] [PATCH v3 2/3] usb:gadget:composite: Support for composite at gadget.h Lukasz Majewski
2012-04-17 14:07   ` [U-Boot] [PATCH v3 3/3] usb:udc:samsung Add functions for storing private gadget data in UDC driver Lukasz Majewski
2012-04-18 15:26 ` [U-Boot] [PATCH v4 0/3] usb:gadget:composite: Support for composite gadget framework Lukasz Majewski
2012-04-18 15:26   ` [U-Boot] [PATCH v4 1/3] usb:gadget:composite USB composite gadget support Lukasz Majewski
2012-04-25 22:53     ` Marek Vasut
2012-04-26  7:02       ` Lukasz Majewski
2012-04-29 23:22         ` Marek Vasut
2012-04-18 15:26   ` [U-Boot] [PATCH v4 2/3] usb:gadget:composite: Support for composite at gadget.h Lukasz Majewski
2012-04-29 23:23     ` Marek Vasut
2012-04-18 15:26   ` [U-Boot] [PATCH v4 3/3] usb:udc:samsung Add functions for storing private gadget data in UDC driver Lukasz Majewski
2012-04-29 23:25     ` Marek Vasut
2012-04-30  6:58       ` Lukasz Majewski
2012-04-30 12:31         ` Marek Vasut
2012-04-30 13:11           ` Lukasz Majewski
2012-04-30 13:38         ` Wolfgang Denk
2012-04-30 14:23           ` Lukasz Majewski
2012-04-30 14:51     ` [U-Boot] [PATCH v4 RESEND " Lukasz Majewski
2012-04-30 15:22       ` Marek Vasut
2012-04-30 15:23       ` Wolfgang Denk
2012-04-30 15:46         ` Lukasz Majewski
2012-04-25 15:53   ` [U-Boot] [PATCH v4 0/3] usb:gadget:composite: Support for composite gadget framework Lukasz Majewski
2012-04-25 17:06     ` Marek Vasut
2012-05-01 19:53 ` [U-Boot] [PATCH 0/4] " Marek Vasut
2012-05-02  7:10   ` Lukasz Majewski
2012-05-02 10:37     ` Marek Vasut

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=201204170947.34137.marex@denx.de \
    --to=marex@denx.de \
    --cc=u-boot@lists.denx.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.