X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=drivers%2Fusb%2Fgadget%2Fepautoconf.c;h=0df4b2a103e845953a883f42faac86fe846ee6f4;hb=19d829fa60fc4e6df514a046142faaaf9fc8185d;hp=c7fad3992e0490bbf0fa1297c04858b391670684;hpb=23cd138503f90ff6af109c0096727ba641942614;p=u-boot diff --git a/drivers/usb/gadget/epautoconf.c b/drivers/usb/gadget/epautoconf.c index c7fad3992e..0df4b2a103 100644 --- a/drivers/usb/gadget/epautoconf.c +++ b/drivers/usb/gadget/epautoconf.c @@ -3,19 +3,9 @@ * * Copyright (C) 2004 David Brownell * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * SPDX-License-Identifier: GPL-2.0+ * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * SPDX-License-Identifier: GPL-2.0+ * * Ported to U-boot by: Thomas Smits and * Remy Bohmer @@ -25,6 +15,7 @@ #include #include #include +#include #include "gadget_chips.h" #define isdigit(c) ('0' <= (c) && (c) <= '9') @@ -32,7 +23,7 @@ /* we must assign addresses for configurable endpoints (like net2280) */ static unsigned epnum; -// #define MANY_ENDPOINTS +/* #define MANY_ENDPOINTS */ #ifdef MANY_ENDPOINTS /* more than 15 configurable endpoints */ static unsigned in_epnum; @@ -55,8 +46,7 @@ static unsigned in_epnum; * NOTE: each endpoint is unidirectional, as specified by its USB * descriptor; and isn't specific to a configuration or altsetting. */ -static int -ep_matches ( +static int ep_matches( struct usb_gadget *gadget, struct usb_ep *ep, struct usb_endpoint_descriptor *desc @@ -83,37 +73,37 @@ ep_matches ( * direction-restriction: "in", "out". */ if ('-' != ep->name[2]) { - tmp = strrchr (ep->name, '-'); + tmp = strrchr(ep->name, '-'); if (tmp) { switch (type) { case USB_ENDPOINT_XFER_INT: /* bulk endpoints handle interrupt transfers, * except the toggle-quirky iso-synch kind */ - if ('s' == tmp[2]) // == "-iso" + if ('s' == tmp[2]) /* == "-iso" */ return 0; /* for now, avoid PXA "interrupt-in"; * it's documented as never using DATA1. */ - if (gadget_is_pxa (gadget) - && 'i' == tmp [1]) + if (gadget_is_pxa(gadget) + && 'i' == tmp[1]) return 0; break; case USB_ENDPOINT_XFER_BULK: - if ('b' != tmp[1]) // != "-bulk" + if ('b' != tmp[1]) /* != "-bulk" */ return 0; break; case USB_ENDPOINT_XFER_ISOC: - if ('s' != tmp[2]) // != "-iso" + if ('s' != tmp[2]) /* != "-iso" */ return 0; } } else { - tmp = ep->name + strlen (ep->name); + tmp = ep->name + strlen(ep->name); } /* direction-restriction: "..in-..", "out-.." */ tmp--; - if (!isdigit (*tmp)) { + if (!isdigit(*tmp)) { if (desc->bEndpointAddress & USB_DIR_IN) { if ('n' != *tmp) return 0; @@ -128,7 +118,7 @@ ep_matches ( * where it's an output parameter representing the full speed limit. * the usb spec fixes high speed bulk maxpacket at 512 bytes. */ - max = 0x7ff & le16_to_cpu(desc->wMaxPacketSize); + max = 0x7ff & le16_to_cpu(get_unaligned(&desc->wMaxPacketSize)); switch (type) { case USB_ENDPOINT_XFER_INT: /* INT: limit 64 bytes full speed, 1024 high speed */ @@ -144,7 +134,8 @@ ep_matches ( return 0; /* BOTH: "high bandwidth" works only at high speed */ - if ((desc->wMaxPacketSize & __constant_cpu_to_le16(3<<11))) { + if ((get_unaligned(&desc->wMaxPacketSize) & + __constant_cpu_to_le16(3<<11))) { if (!gadget->is_dualspeed) return 0; /* configure your hardware with enough buffering!! */ @@ -155,8 +146,8 @@ ep_matches ( /* MATCH!! */ /* report address */ - if (isdigit (ep->name [2])) { - u8 num = simple_strtol (&ep->name [2], NULL, 10); + if (isdigit(ep->name[2])) { + u8 num = simple_strtoul(&ep->name[2], NULL, 10); desc->bEndpointAddress |= num; #ifdef MANY_ENDPOINTS } else if (desc->bEndpointAddress & USB_DIR_IN) { @@ -177,18 +168,18 @@ ep_matches ( /* min() doesn't work on bitfields with gcc-3.5 */ if (size > 64) size = 64; - desc->wMaxPacketSize = cpu_to_le16(size); + put_unaligned(cpu_to_le16(size), &desc->wMaxPacketSize); } return 1; } static struct usb_ep * -find_ep (struct usb_gadget *gadget, const char *name) +find_ep(struct usb_gadget *gadget, const char *name) { struct usb_ep *ep; - list_for_each_entry (ep, &gadget->ep_list, ep_list) { - if (0 == strcmp (ep->name, name)) + list_for_each_entry(ep, &gadget->ep_list, ep_list) { + if (0 == strcmp(ep->name, name)) return ep; } return NULL; @@ -224,7 +215,7 @@ find_ep (struct usb_gadget *gadget, const char *name) * * On failure, this returns a null endpoint descriptor. */ -struct usb_ep * usb_ep_autoconfig ( +struct usb_ep *usb_ep_autoconfig( struct usb_gadget *gadget, struct usb_endpoint_descriptor *desc ) @@ -237,44 +228,44 @@ struct usb_ep * usb_ep_autoconfig ( /* First, apply chip-specific "best usage" knowledge. * This might make a good usb_gadget_ops hook ... */ - if (gadget_is_net2280 (gadget) && type == USB_ENDPOINT_XFER_INT) { + if (gadget_is_net2280(gadget) && type == USB_ENDPOINT_XFER_INT) { /* ep-e, ep-f are PIO with only 64 byte fifos */ - ep = find_ep (gadget, "ep-e"); - if (ep && ep_matches (gadget, ep, desc)) + ep = find_ep(gadget, "ep-e"); + if (ep && ep_matches(gadget, ep, desc)) return ep; - ep = find_ep (gadget, "ep-f"); - if (ep && ep_matches (gadget, ep, desc)) + ep = find_ep(gadget, "ep-f"); + if (ep && ep_matches(gadget, ep, desc)) return ep; - } else if (gadget_is_goku (gadget)) { + } else if (gadget_is_goku(gadget)) { if (USB_ENDPOINT_XFER_INT == type) { /* single buffering is enough */ - ep = find_ep (gadget, "ep3-bulk"); - if (ep && ep_matches (gadget, ep, desc)) + ep = find_ep(gadget, "ep3-bulk"); + if (ep && ep_matches(gadget, ep, desc)) return ep; } else if (USB_ENDPOINT_XFER_BULK == type && (USB_DIR_IN & desc->bEndpointAddress)) { /* DMA may be available */ - ep = find_ep (gadget, "ep2-bulk"); - if (ep && ep_matches (gadget, ep, desc)) + ep = find_ep(gadget, "ep2-bulk"); + if (ep && ep_matches(gadget, ep, desc)) return ep; } - } else if (gadget_is_sh (gadget) && USB_ENDPOINT_XFER_INT == type) { + } else if (gadget_is_sh(gadget) && USB_ENDPOINT_XFER_INT == type) { /* single buffering is enough; maybe 8 byte fifo is too */ - ep = find_ep (gadget, "ep3in-bulk"); - if (ep && ep_matches (gadget, ep, desc)) + ep = find_ep(gadget, "ep3in-bulk"); + if (ep && ep_matches(gadget, ep, desc)) return ep; - } else if (gadget_is_mq11xx (gadget) && USB_ENDPOINT_XFER_INT == type) { - ep = find_ep (gadget, "ep1-bulk"); - if (ep && ep_matches (gadget, ep, desc)) + } else if (gadget_is_mq11xx(gadget) && USB_ENDPOINT_XFER_INT == type) { + ep = find_ep(gadget, "ep1-bulk"); + if (ep && ep_matches(gadget, ep, desc)) return ep; } /* Second, look at endpoints until an unclaimed one looks usable */ - list_for_each_entry (ep, &gadget->ep_list, ep_list) { - if (ep_matches (gadget, ep, desc)) + list_for_each_entry(ep, &gadget->ep_list, ep_list) { + if (ep_matches(gadget, ep, desc)) return ep; } @@ -291,11 +282,11 @@ struct usb_ep * usb_ep_autoconfig ( * state such as ep->driver_data and the record of assigned endpoints * used by usb_ep_autoconfig(). */ -void usb_ep_autoconfig_reset (struct usb_gadget *gadget) +void usb_ep_autoconfig_reset(struct usb_gadget *gadget) { struct usb_ep *ep; - list_for_each_entry (ep, &gadget->ep_list, ep_list) { + list_for_each_entry(ep, &gadget->ep_list, ep_list) { ep->driver_data = NULL; } #ifdef MANY_ENDPOINTS @@ -303,4 +294,3 @@ void usb_ep_autoconfig_reset (struct usb_gadget *gadget) #endif epnum = 0; } -