X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;ds=sidebyside;f=drivers%2Fserial%2Fusbtty.c;h=353109c0700af1e66641bca0451685a7c66cc0a4;hb=470135be276b2d92c6da464c68839202d4ff0d08;hp=a263b2c1fc593ea015f685c6f3ace3806e6f01c8;hpb=8b0affecb98f91142015ccf8c43653e1ad87c156;p=u-boot diff --git a/drivers/serial/usbtty.c b/drivers/serial/usbtty.c index a263b2c1fc..353109c070 100644 --- a/drivers/serial/usbtty.c +++ b/drivers/serial/usbtty.c @@ -5,20 +5,7 @@ * (C) Copyright 2006 * Bryan O'Donoghue, bodonoghue@codehermit.ie * - * 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. - * - * 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+ */ #include @@ -63,7 +50,7 @@ /* * Buffers to hold input and output data */ -#define USBTTY_BUFFER_SIZE 256 +#define USBTTY_BUFFER_SIZE 2048 static circbuf_t usbtty_input; static circbuf_t usbtty_output; @@ -133,6 +120,19 @@ static struct usb_device_descriptor device_descriptor = { }; +#if defined(CONFIG_USBD_HS) +static struct usb_qualifier_descriptor qualifier_descriptor = { + .bLength = sizeof(struct usb_qualifier_descriptor), + .bDescriptorType = USB_DT_QUAL, + .bcdUSB = cpu_to_le16(USB_BCD_VERSION), + .bDeviceClass = COMMUNICATIONS_DEVICE_CLASS, + .bDeviceSubClass = 0x00, + .bDeviceProtocol = 0x00, + .bMaxPacketSize0 = EP0_MAX_PACKET_SIZE, + .bNumConfigurations = NUM_CONFIGS +}; +#endif + /* * Static CDC ACM specific descriptors */ @@ -389,7 +389,7 @@ static void str2wide (char *str, u16 * wide) * Test whether a character is in the RX buffer */ -int usbtty_tstc (void) +int usbtty_tstc(struct stdio_dev *dev) { struct usb_endpoint_instance *endpoint = &endpoint_instance[rx_endpoint]; @@ -409,7 +409,7 @@ int usbtty_tstc (void) * written into its argument c. */ -int usbtty_getc (void) +int usbtty_getc(struct stdio_dev *dev) { char c; struct usb_endpoint_instance *endpoint = @@ -429,16 +429,17 @@ int usbtty_getc (void) /* * Output a single byte to the usb client port. */ -void usbtty_putc (const char c) +void usbtty_putc(struct stdio_dev *dev, const char c) { if (!usbtty_configured ()) return; - buf_push (&usbtty_output, &c, 1); /* If \n, also do \r */ if (c == '\n') buf_push (&usbtty_output, "\r", 1); + buf_push(&usbtty_output, &c, 1); + /* Poll at end to handle new data... */ if ((usbtty_output.size + 2) >= usbtty_output.totalsize) { usbtty_poll (); @@ -475,7 +476,7 @@ static void __usbtty_puts (const char *str, int len) if (space) { write_buffer (&usbtty_output); - n = MIN (space, MIN (len, maxlen)); + n = min(space, min(len, maxlen)); buf_push (&usbtty_output, str, n); str += n; @@ -484,7 +485,7 @@ static void __usbtty_puts (const char *str, int len) } } -void usbtty_puts (const char *str) +void usbtty_puts(struct stdio_dev *dev, const char *str) { int n; int len; @@ -498,8 +499,8 @@ void usbtty_puts (const char *str) n = next_nl_pos (str); if (str[n] == '\n') { - __usbtty_puts (str, n + 1); - __usbtty_puts ("\r", 1); + __usbtty_puts("\r", 1); + __usbtty_puts(str, n + 1); str += (n + 1); len -= (n + 1); } else { @@ -525,9 +526,9 @@ int drv_usbtty_init (void) int snlen; /* Ger seiral number */ - if (!(sn = getenv("serial#"))) { + sn = env_get("serial#"); + if (!sn) sn = "000000000000"; - } snlen = strlen(sn); if (snlen > sizeof(serial_number) - 1) { printf ("Warning: serial number %s is too long (%d > %lu)\n", @@ -539,10 +540,9 @@ int drv_usbtty_init (void) /* Decide on which type of UDC device to be. */ - - if(!(tt = getenv("usbtty"))) { + tt = env_get("usbtty"); + if (!tt) tt = "generic"; - } usbtty_init_terminal_type(strcmp(tt,"cdc_acm")); /* prepare buffers... */ @@ -638,6 +638,9 @@ static void usbtty_init_instances (void) memset (device_instance, 0, sizeof (struct usb_device_instance)); device_instance->device_state = STATE_INIT; device_instance->device_descriptor = &device_descriptor; +#if defined(CONFIG_USBD_HS) + device_instance->qualifier_descriptor = &qualifier_descriptor; +#endif device_instance->event = usbtty_event_handler; device_instance->cdc_recv_setup = usbtty_cdc_setup; device_instance->bus = bus_instance; @@ -751,6 +754,10 @@ static void usbtty_init_terminal_type(short type) device_descriptor.idProduct = cpu_to_le16(CONFIG_USBD_PRODUCTID_CDCACM); +#if defined(CONFIG_USBD_HS) + qualifier_descriptor.bDeviceClass = + COMMUNICATIONS_DEVICE_CLASS; +#endif /* Assign endpoint indices */ tx_endpoint = ACM_TX_ENDPOINT; rx_endpoint = ACM_RX_ENDPOINT; @@ -779,7 +786,9 @@ static void usbtty_init_terminal_type(short type) device_descriptor.bDeviceClass = 0xFF; device_descriptor.idProduct = cpu_to_le16(CONFIG_USBD_PRODUCTID_GSERIAL); - +#if defined(CONFIG_USBD_HS) + qualifier_descriptor.bDeviceClass = 0xFF; +#endif /* Assign endpoint indices */ tx_endpoint = GSERIAL_TX_ENDPOINT; rx_endpoint = GSERIAL_RX_ENDPOINT; @@ -840,6 +849,13 @@ static int write_buffer (circbuf_t * buf) struct urb *current_urb = NULL; current_urb = next_urb (device_instance, endpoint); + + if (!current_urb) { + TTYERR ("current_urb is NULL, buf->size %d\n", + buf->size); + return 0; + } + /* TX data still exists - send it now */ if(endpoint->sent < current_urb->actual_length){ @@ -861,19 +877,13 @@ static int write_buffer (circbuf_t * buf) */ while (buf->size > 0) { - if (!current_urb) { - TTYERR ("current_urb is NULL, buf->size %d\n", - buf->size); - return total; - } - dest = (char*)current_urb->buffer + current_urb->actual_length; space_avail = current_urb->buffer_length - current_urb->actual_length; - popnum = MIN (space_avail, buf->size); + popnum = min(space_avail, (int)buf->size); if (popnum == 0) break; @@ -932,6 +942,9 @@ static int usbtty_configured (void) static void usbtty_event_handler (struct usb_device_instance *device, usb_device_event_t event, int data) { +#if defined(CONFIG_USBD_HS) + int i; +#endif switch (event) { case DEVICE_RESET: case DEVICE_BUS_INACTIVE: @@ -942,6 +955,29 @@ static void usbtty_event_handler (struct usb_device_instance *device, break; case DEVICE_ADDRESS_ASSIGNED: +#if defined(CONFIG_USBD_HS) + /* + * is_usbd_high_speed routine needs to be defined by + * specific gadget driver + * It returns true if device enumerates at High speed + * Retuns false otherwise + */ + for (i = 0; i < NUM_ENDPOINTS; i++) { + if (((ep_descriptor_ptrs[i]->bmAttributes & + USB_ENDPOINT_XFERTYPE_MASK) == + USB_ENDPOINT_XFER_BULK) + && is_usbd_high_speed()) { + + ep_descriptor_ptrs[i]->wMaxPacketSize = + CONFIG_USBD_SERIAL_BULK_HS_PKTSIZE; + } + + endpoint_instance[i + 1].tx_packetSize = + ep_descriptor_ptrs[i]->wMaxPacketSize; + endpoint_instance[i + 1].rcv_packetSize = + ep_descriptor_ptrs[i]->wMaxPacketSize; + } +#endif usbtty_init_endpoints (); default: