]> git.sur5r.net Git - u-boot/blobdiff - drivers/serial/usbtty.c
digsy MTC: Add 'mtc' command.
[u-boot] / drivers / serial / usbtty.c
index a3b50131dfc1bc47c20f58a3927364e6dd12c6f3..f711d0b18b1a967877698d271bd5a4fff915fab6 100644 (file)
  */
 
 #include <common.h>
-
-#ifdef CONFIG_USB_TTY
-
+#include <config.h>
 #include <circbuf.h>
 #include <devices.h>
 #include "usbtty.h"
 #include "usb_cdc_acm.h"
 #include "usbdescriptors.h"
-#include <config.h>            /* If defined, override Linux identifiers with
-                                * vendor specific ones */
 
-#if 0
+#ifdef DEBUG
 #define TTYDBG(fmt,args...)\
        serial_printf("[%s] %s %d: "fmt, __FILE__,__FUNCTION__,__LINE__,##args)
 #else
@@ -98,7 +94,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 */
@@ -123,7 +119,7 @@ static struct usb_configuration_descriptor  *configuration_descriptor = 0;
 static struct usb_device_descriptor device_descriptor = {
        .bLength = sizeof(struct usb_device_descriptor),
        .bDescriptorType =      USB_DT_DEVICE,
-       .bcdUSB =               cpu_to_le16(USB_BCD_VERSION),
+       .bcdUSB =               cpu_to_le16(USB_BCD_VERSION),
        .bDeviceSubClass =      0x00,
        .bDeviceProtocol =      0x00,
        .bMaxPacketSize0 =      EP0_MAX_PACKET_SIZE,
@@ -154,8 +150,7 @@ struct acm_config_desc {
 
        /* Slave Interface */
        struct usb_interface_descriptor data_class_interface;
-       struct usb_endpoint_descriptor
-               data_endpoints[NUM_ENDPOINTS-1] __attribute__((packed));
+       struct usb_endpoint_descriptor data_endpoints[NUM_ENDPOINTS-1];
 } __attribute__((packed));
 
 static struct acm_config_desc acm_configuration_descriptors[NUM_CONFIGS] = {
@@ -163,11 +158,11 @@ static struct acm_config_desc acm_configuration_descriptors[NUM_CONFIGS] = {
                .configuration_desc ={
                        .bLength =
                                sizeof(struct usb_configuration_descriptor),
-                       .bDescriptorType = USB_DT_CONFIG,
+                       .bDescriptorType = USB_DT_CONFIG,
                        .wTotalLength =
                                cpu_to_le16(sizeof(struct acm_config_desc)),
-                       .bNumInterfaces = NUM_ACM_INTERFACES,
-                       .bConfigurationValue = 1,
+                       .bNumInterfaces = NUM_ACM_INTERFACES,
+                       .bConfigurationValue = 1,
                        .iConfiguration = STR_CONFIG,
                        .bmAttributes =
                                BMATTRIBUTE_SELF_POWERED|BMATTRIBUTE_RESERVED,
@@ -220,7 +215,7 @@ static struct acm_config_desc acm_configuration_descriptors[NUM_CONFIGS] = {
                        .bLength =
                                sizeof(struct usb_endpoint_descriptor),
                        .bDescriptorType        = USB_DT_ENDPOINT,
-                       .bEndpointAddress       = 0x01 | USB_DIR_IN,
+                       .bEndpointAddress       = UDC_INT_ENDPOINT | USB_DIR_IN,
                        .bmAttributes           = USB_ENDPOINT_XFER_INT,
                        .wMaxPacketSize
                                = cpu_to_le16(CONFIG_USBD_SERIAL_INT_PKTSIZE),
@@ -246,7 +241,7 @@ static struct acm_config_desc acm_configuration_descriptors[NUM_CONFIGS] = {
                                .bLength                =
                                        sizeof(struct usb_endpoint_descriptor),
                                .bDescriptorType        = USB_DT_ENDPOINT,
-                               .bEndpointAddress       = 0x02 | USB_DIR_OUT,
+                               .bEndpointAddress       = UDC_OUT_ENDPOINT | USB_DIR_OUT,
                                .bmAttributes           =
                                        USB_ENDPOINT_XFER_BULK,
                                .wMaxPacketSize         =
@@ -257,7 +252,7 @@ static struct acm_config_desc acm_configuration_descriptors[NUM_CONFIGS] = {
                                .bLength                =
                                        sizeof(struct usb_endpoint_descriptor),
                                .bDescriptorType        = USB_DT_ENDPOINT,
-                               .bEndpointAddress       = 0x03 | USB_DIR_IN,
+                               .bEndpointAddress       = UDC_IN_ENDPOINT | USB_DIR_IN,
                                .bmAttributes           =
                                        USB_ENDPOINT_XFER_BULK,
                                .wMaxPacketSize         =
@@ -269,9 +264,9 @@ static struct acm_config_desc acm_configuration_descriptors[NUM_CONFIGS] = {
 };
 
 static struct rs232_emu rs232_desc={
-               .dter           =       115200,
-               .stop_bits      =       0x00,
-               .parity         =       0x00,
+               .dter           =       115200,
+               .stop_bits      =       0x00,
+               .parity         =       0x00,
                .data_bits      =       0x08
 };
 
@@ -284,10 +279,8 @@ static struct rs232_emu rs232_desc={
 struct gserial_config_desc {
 
        struct usb_configuration_descriptor configuration_desc;
-       struct usb_interface_descriptor
-               interface_desc[NUM_GSERIAL_INTERFACES] __attribute__((packed));
-       struct usb_endpoint_descriptor
-               data_endpoints[NUM_ENDPOINTS] __attribute__((packed));
+       struct usb_interface_descriptor interface_desc[NUM_GSERIAL_INTERFACES];
+       struct usb_endpoint_descriptor data_endpoints[NUM_ENDPOINTS];
 
 } __attribute__((packed));
 
@@ -322,13 +315,13 @@ gserial_configuration_descriptors[NUM_CONFIGS] ={
                                        COMMUNICATIONS_NO_PROTOCOL,
                                .iInterface = STR_DATA_INTERFACE
                        },
-               },
+               },
                .data_endpoints  = {
                        {
                                .bLength =
                                        sizeof(struct usb_endpoint_descriptor),
                                .bDescriptorType =      USB_DT_ENDPOINT,
-                               .bEndpointAddress =     0x01 | USB_DIR_OUT,
+                               .bEndpointAddress =     UDC_OUT_ENDPOINT | USB_DIR_OUT,
                                .bmAttributes =         USB_ENDPOINT_XFER_BULK,
                                .wMaxPacketSize =
                                        cpu_to_le16(CONFIG_USBD_SERIAL_OUT_PKTSIZE),
@@ -338,19 +331,19 @@ gserial_configuration_descriptors[NUM_CONFIGS] ={
                                .bLength =
                                        sizeof(struct usb_endpoint_descriptor),
                                .bDescriptorType =      USB_DT_ENDPOINT,
-                               .bEndpointAddress =     0x02 | USB_DIR_IN,
+                               .bEndpointAddress =     UDC_IN_ENDPOINT | USB_DIR_IN,
                                .bmAttributes =         USB_ENDPOINT_XFER_BULK,
                                .wMaxPacketSize =
                                        cpu_to_le16(CONFIG_USBD_SERIAL_IN_PKTSIZE),
-                               .bInterval =            0xFF,
+                               .bInterval =            0xFF,
                        },
                        {
                                .bLength =
                                        sizeof(struct usb_endpoint_descriptor),
                                .bDescriptorType =      USB_DT_ENDPOINT,
-                               .bEndpointAddress =     0x03 | USB_DIR_IN,
+                               .bEndpointAddress =     UDC_INT_ENDPOINT | USB_DIR_IN,
                                .bmAttributes =         USB_ENDPOINT_XFER_INT,
-                               .wMaxPacketSize =
+                               .wMaxPacketSize =
                                        cpu_to_le16(CONFIG_USBD_SERIAL_INT_PKTSIZE),
                                .bInterval =            0xFF,
                        },
@@ -437,6 +430,9 @@ int usbtty_getc (void)
  */
 void usbtty_putc (const char c)
 {
+       if (!usbtty_configured ())
+               return;
+
        buf_push (&usbtty_output, &c, 1);
        /* If \n, also do \r */
        if (c == '\n')
@@ -490,8 +486,12 @@ static void __usbtty_puts (const char *str, int len)
 void usbtty_puts (const char *str)
 {
        int n;
-       int len = strlen (str);
+       int len;
+
+       if (!usbtty_configured ())
+               return;
 
+       len = strlen (str);
        /* add '\r' for each '\n' */
        while (len > 0) {
                n = next_nl_pos (str);
@@ -529,8 +529,8 @@ int drv_usbtty_init (void)
        }
        snlen = strlen(sn);
        if (snlen > sizeof(serial_number) - 1) {
-               printf ("Warning: serial number %s is too long (%d > %d)\n",
-                       sn, snlen, sizeof(serial_number) - 1);
+               printf ("Warning: serial number %s is too long (%d > %lu)\n",
+                       sn, snlen, (ulong)(sizeof(serial_number) - 1));
                snlen = sizeof(serial_number) - 1;
        }
        memcpy (serial_number, sn, snlen);
@@ -953,14 +953,14 @@ int usbtty_cdc_setup(struct usb_device_request *request, struct urb *urb)
 {
        switch (request->bRequest){
 
-               case ACM_SET_CONTROL_LINE_STATE:        /* Implies DTE ready */
+               case ACM_SET_CONTROL_LINE_STATE:        /* Implies DTE ready */
                        break;
-               case ACM_SEND_ENCAPSULATED_COMMAND :    /* Required */
+               case ACM_SEND_ENCAPSULATED_COMMAND :    /* Required */
                        break;
                case ACM_SET_LINE_ENCODING :            /* DTE stop/parity bits
                                                         * per character */
                        break;
-               case ACM_GET_ENCAPSULATED_RESPONSE :    /* request response */
+               case ACM_GET_ENCAPSULATED_RESPONSE :    /* request response */
                        break;
                case ACM_GET_LINE_ENCODING :            /* request DTE rate,
                                                         * stop/parity bits */
@@ -968,7 +968,7 @@ int usbtty_cdc_setup(struct usb_device_request *request, struct urb *urb)
                        urb->actual_length = sizeof(rs232_desc);
 
                        break;
-               default:
+               default:
                        return 1;
        }
        return 0;
@@ -1007,6 +1007,3 @@ void usbtty_poll (void)
        udc_irq();
 
 }
-
-
-#endif