]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - drivers/serial/usbtty.c
mtd: nand: omap: fix error-codes returned from omap-elm driver
[karo-tx-uboot.git] / drivers / serial / usbtty.c
index d8b13879176491c7ede5eb46e10d7a18f5174a5b..6b912efafdc74e07099a28b2e531968a0212fe3e 100644 (file)
@@ -5,26 +5,14 @@
  * (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 <common.h>
 #include <config.h>
 #include <circbuf.h>
-#include <devices.h>
+#include <stdio_dev.h>
+#include <asm/unaligned.h>
 #include "usbtty.h"
 #include "usb_cdc_acm.h"
 #include "usbdescriptors.h"
@@ -62,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;
 
@@ -70,7 +58,7 @@ static circbuf_t usbtty_output;
 /*
  * Instance variables
  */
-static device_t usbttydev;
+static struct stdio_dev usbttydev;
 static struct usb_device_instance device_instance[1];
 static struct usb_bus_instance bus_instance[1];
 static struct usb_configuration_instance config_instance[NUM_CONFIGS];
@@ -94,7 +82,7 @@ static char serial_number[16];
  * Descriptors, Strings, Local variables.
  */
 
-/* defined and used by usbdcore_ep0.c */
+/* defined and used by gadget/ep0.c */
 extern struct usb_string_descriptor **usb_strings;
 
 /* Indicies, References */
@@ -132,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
  */
@@ -554,11 +555,11 @@ int drv_usbtty_init (void)
        usbtty_init_strings ();
        usbtty_init_instances ();
 
+       usbtty_init_endpoints ();
+
        udc_startup_events (device_instance);/* Enable dev, init udc pointers */
        udc_connect ();         /* Enable pullup for host detection */
 
-       usbtty_init_endpoints ();
-
        /* Device initialization */
        memset (&usbttydev, 0, sizeof (usbttydev));
 
@@ -570,7 +571,7 @@ int drv_usbtty_init (void)
        usbttydev.putc = usbtty_putc;   /* 'putc' function */
        usbttydev.puts = usbtty_puts;   /* 'puts' function */
 
-       rc = device_register (&usbttydev);
+       rc = stdio_register (&usbttydev);
 
        return (rc == 0) ? 1 : rc;
 }
@@ -626,6 +627,9 @@ static void usbtty_init_strings (void)
        usb_strings = usbtty_string_table;
 }
 
+#define init_wMaxPacketSize(x) le16_to_cpu(get_unaligned(\
+                       &ep_descriptor_ptrs[(x) - 1]->wMaxPacketSize));
+
 static void usbtty_init_instances (void)
 {
        int i;
@@ -634,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;
@@ -688,14 +695,12 @@ static void usbtty_init_instances (void)
                endpoint_instance[i].rcv_attributes =
                        ep_descriptor_ptrs[i - 1]->bmAttributes;
 
-               endpoint_instance[i].rcv_packetSize =
-                       le16_to_cpu(ep_descriptor_ptrs[i - 1]->wMaxPacketSize);
+               endpoint_instance[i].rcv_packetSize = init_wMaxPacketSize(i);
 
                endpoint_instance[i].tx_attributes =
                        ep_descriptor_ptrs[i - 1]->bmAttributes;
 
-               endpoint_instance[i].tx_packetSize =
-                       le16_to_cpu(ep_descriptor_ptrs[i - 1]->wMaxPacketSize);
+               endpoint_instance[i].tx_packetSize = init_wMaxPacketSize(i);
 
                endpoint_instance[i].tx_attributes =
                        ep_descriptor_ptrs[i - 1]->bmAttributes;
@@ -749,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;
@@ -777,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;
@@ -930,6 +941,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:
@@ -940,6 +954,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: