+++ /dev/null
-/** @file\r
- Header file for USB Serial Driver's Data Structures.\r
-\r
-Copyright (c) 2004 - 2013, Intel Corporation. All rights reserved.\r
-Portions Copyright 2012 Ashley DeSimone\r
-SPDX-License-Identifier: BSD-2-Clause-Patent\r
-\r
-**/\r
-\r
-#ifndef _FTDI_USB_SERIAL_DRIVER_H_\r
-#define _FTDI_USB_SERIAL_DRIVER_H_\r
-\r
-#include <Library/BaseMemoryLib.h>\r
-#include <Library/DebugLib.h>\r
-#include <Library/MemoryAllocationLib.h>\r
-#include <Library/UefiBootServicesTableLib.h>\r
-#include <Library/UefiLib.h>\r
-#include <Library/DevicePathLib.h>\r
-\r
-#include <Protocol/DevicePath.h>\r
-#include <Protocol/UsbIo.h>\r
-#include <Protocol/SerialIo.h>\r
-\r
-//\r
-// US English LangID\r
-//\r
-#define USB_US_LANG_ID 0x0409\r
-\r
-//\r
-// Supported Vendor Ids\r
-//\r
-#define VID_FTDI 0x0403\r
-\r
-//\r
-// Supported product ids\r
-//\r
-#define DID_FTDI_FT232 0x6001\r
-\r
-//\r
-// FTDI Commands\r
-//\r
-#define FTDI_COMMAND_RESET_PORT 0\r
-#define FTDI_COMMAND_MODEM_CTRL 1\r
-#define FTDI_COMMAND_SET_FLOW_CTRL 2\r
-#define FTDI_COMMAND_SET_BAUDRATE 3\r
-#define FTDI_COMMAND_SET_DATA 4\r
-#define FTDI_COMMAND_GET_MODEM_STATUS 5\r
-#define FTDI_COMMAND_SET_EVENT_CHAR 6\r
-#define FTDI_COMMAND_SET_ERROR_CHAR 7\r
-#define FTDI_COMMAND_SET_LATENCY_TIMER 9\r
-#define FTDI_COMMAND_GET_LATENCY_TIMER 10\r
-\r
-//\r
-// FTDI_PORT_IDENTIFIER\r
-// Used in the usb control transfers that issue FTDI commands as the index value.\r
-//\r
-#define FTDI_PORT_IDENTIFIER 0x1 // For FTDI USB serial adapter the port\r
- // identifier is always 1.\r
-\r
-//\r
-// RESET_PORT\r
-//\r
-#define RESET_PORT_RESET 0x0 // Purges RX and TX, clears DTR and RTS sets\r
- // flow control to none, disables event\r
- // trigger, sets the event char to 0x0d and\r
- // does nothing to baudrate or data settings\r
-#define RESET_PORT_PURGE_RX 0x1\r
-#define RESET_PORT_PURGE_TX 0x2\r
-\r
-//\r
-// SET_FLOW_CONTROL\r
-//\r
-#define NO_FLOW_CTRL 0x0\r
-#define XON_XOFF_CTRL 0x4\r
-\r
-//\r
-// SET_BAUD_RATE\r
-// To set baud rate, one must calculate an encoding of the baud rate from\r
-// UINT32 to UINT16.See EncodeBaudRateForFtdi() for details\r
-//\r
-#define FTDI_UART_FREQUENCY 3000000\r
-#define FTDI_MIN_DIVISOR 0x20\r
-#define FTDI_MAX_DIVISOR 0x3FFF8\r
-//\r
-// Special case baudrate values\r
-// 300,000 and 200,000 are special cases for calculating the encoded baudrate\r
-//\r
-#define FTDI_SPECIAL_CASE_300_MIN (3000000 * 100) / 103 // minimum adjusted\r
- // value for 300,000\r
-#define FTDI_SPECIAL_CASE_300_MAX (3000000 * 100) / 97 // maximum adjusted\r
- // value for 300,000\r
-#define FTDI_SPECIAL_CASE_200_MIN (2000000 * 100) / 103 // minimum adjusted\r
- // value for 200,000\r
-#define FTDI_SPECIAL_CASE_200_MAX (2000000 * 100) / 97 // maximum adjusted\r
- // value for 200,000\r
-//\r
-// Min and max frequency values that the FTDI chip can attain\r
-//.all generated frequencies must be between these values\r
-//\r
-#define FTDI_MIN_FREQUENCY 46601941 // (3MHz * 1600) / 103 = 46601941\r
-#define FTDI_MAX_FREQUENCY 49484536 // (3MHz * 1600) / 97 = 49484536\r
-\r
-//\r
-// SET_DATA_BITS\r
-//\r
-#define SET_DATA_BITS(n) (n)\r
-\r
-//\r
-// SET_PARITY\r
-//\r
-#define SET_PARITY_NONE 0x0\r
-#define SET_PARITY_ODD BIT8 // (0x1 << 8)\r
-#define SET_PARITY_EVEN BIT9 // (0x2 << 8)\r
-#define SET_PARITY_MARK BIT9 | BIT8 // (0x3 << 8)\r
-#define SET_PARITY_SPACE BIT10 // (0x4 << 8)\r
-\r
-//\r
-// SET_STOP_BITS\r
-//\r
-#define SET_STOP_BITS_1 0x0\r
-#define SET_STOP_BITS_15 BIT11 // (0x1 << 11)\r
-#define SET_STOP_BITS_2 BIT12 // (0x2 << 11)\r
-\r
-//\r
-// SET_MODEM_CTRL\r
-// SET_DTR_HIGH = (1 | (1 << 8)), SET_DTR_LOW = (0 | (1 << 8)\r
-// SET_RTS_HIGH = (2 | (2 << 8)), SET_RTS_LOW = (0 | (2 << 8)\r
-//\r
-#define SET_DTR_HIGH (BIT8 | BIT0)\r
-#define SET_DTR_LOW (BIT8)\r
-#define SET_RTS_HIGH (BIT9 | BIT1)\r
-#define SET_RTS_LOW (BIT9)\r
-\r
-//\r
-// MODEM_STATUS\r
-//\r
-#define CTS_MASK BIT4\r
-#define DSR_MASK BIT5\r
-#define RI_MASK BIT6\r
-#define SD_MASK BIT7\r
-#define MSR_MASK (CTS_MASK | DSR_MASK | RI_MASK | SD_MASK)\r
-\r
-//\r
-// Macro used to check for USB transfer errors\r
-//\r
-#define USB_IS_ERROR(Result, Error) (((Result) & (Error)) != 0)\r
-\r
-//\r
-// USB request timeouts\r
-//\r
-#define WDR_TIMEOUT 5000 // default urb timeout in ms\r
-#define WDR_SHORT_TIMEOUT 1000 // shorter urb timeout in ms\r
-\r
-//\r
-// FTDI timeout\r
-//\r
-#define FTDI_TIMEOUT 16\r
-\r
-//\r
-// FTDI FIFO depth\r
-//\r
-#define FTDI_MAX_RECEIVE_FIFO_DEPTH 384\r
-\r
-//\r
-// FTDI Endpoint Descriptors\r
-//\r
-#define FTDI_ENDPOINT_ADDRESS_IN 0x81 //the endpoint address for the in enpoint generated by the device\r
-#define FTDI_ENDPOINT_ADDRESS_OUT 0x02 //the endpoint address for the out endpoint generated by the device\r
-\r
-//\r
-// Max buffer size for USB transfers\r
-//\r
-#define SW_FIFO_DEPTH 1024\r
-\r
-//\r
-// struct to define a usb device as a vendor and product id pair\r
-//\r
-typedef struct {\r
- UINTN VendorId;\r
- UINTN DeviceId;\r
-} USB_DEVICE;\r
-\r
-//\r
-//struct to describe the control bits of the device\r
-//true indicates enabled\r
-//false indicates disabled\r
-// \r
-typedef struct {\r
- BOOLEAN HardwareFlowControl;\r
- BOOLEAN DtrState;\r
- BOOLEAN RtsState;\r
- BOOLEAN HardwareLoopBack;\r
- BOOLEAN SoftwareLoopBack;\r
-} CONTROL_BITS;\r
-\r
-//\r
-//struct to describe the status bits of the device \r
-//true indicates enabled\r
-//false indicated disabled\r
-//\r
-typedef struct {\r
- BOOLEAN CtsState;\r
- BOOLEAN DsrState;\r
- BOOLEAN RiState;\r
- BOOLEAN SdState;\r
-} STATUS_BITS;\r
-\r
-//\r
-// Structure to describe the last attributes of the Usb Serial device\r
-//\r
-typedef struct {\r
- UINT64 BaudRate;\r
- UINT32 ReceiveFifoDepth;\r
- UINT32 Timeout;\r
- EFI_PARITY_TYPE Parity;\r
- UINT8 DataBits;\r
- EFI_STOP_BITS_TYPE StopBits;\r
-} PREVIOUS_ATTRIBUTES;\r
-\r
-//\r
-// Structure to describe USB serial device\r
-//\r
-#define USB_SER_DEV_SIGNATURE SIGNATURE_32 ('u', 's', 'b', 's')\r
-\r
-typedef struct {\r
- UINTN Signature;\r
- EFI_HANDLE ControllerHandle;\r
- EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
- EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;\r
- UART_DEVICE_PATH UartDevicePath;\r
- UART_FLOW_CONTROL_DEVICE_PATH FlowControlDevicePath;\r
- EFI_USB_IO_PROTOCOL *UsbIo;\r
- EFI_USB_INTERFACE_DESCRIPTOR InterfaceDescriptor;\r
- EFI_USB_ENDPOINT_DESCRIPTOR InEndpointDescriptor;\r
- EFI_USB_ENDPOINT_DESCRIPTOR OutEndpointDescriptor;\r
- EFI_UNICODE_STRING_TABLE *ControllerNameTable;\r
- UINT32 DataBufferHead;\r
- UINT32 DataBufferTail;\r
- UINT8 *DataBuffer;\r
- EFI_SERIAL_IO_PROTOCOL SerialIo;\r
- BOOLEAN Shutdown;\r
- EFI_EVENT PollingLoop;\r
- UINT32 ControlBits;\r
- PREVIOUS_ATTRIBUTES LastSettings;\r
- CONTROL_BITS ControlValues;\r
- STATUS_BITS StatusValues;\r
- UINT8 ReadBuffer[512];\r
-} USB_SER_DEV;\r
-\r
-#define USB_SER_DEV_FROM_THIS(a) \\r
- CR(a, USB_SER_DEV, SerialIo, USB_SER_DEV_SIGNATURE)\r
-\r
-//\r
-// Global Variables\r
-//\r
-extern EFI_DRIVER_BINDING_PROTOCOL gUsbSerialDriverBinding;\r
-extern EFI_COMPONENT_NAME_PROTOCOL gUsbSerialComponentName;\r
-extern EFI_COMPONENT_NAME2_PROTOCOL gUsbSerialComponentName2;\r
-\r
-//\r
-// Functions of Driver Binding Protocol\r
-//\r
-/**\r
- Check whether USB Serial driver supports this device.\r
-\r
- @param This[in] The USB Serial driver binding protocol.\r
- @param Controller[in] The controller handle to check.\r
- @param RemainingDevicePath[in] The remaining device path.\r
-\r
- @retval EFI_SUCCESS The driver supports this controller.\r
- @retval other This device isn't supported.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-UsbSerialDriverBindingSupported (\r
- IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
- IN EFI_HANDLE Controller,\r
- IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
- );\r
-\r
-/**\r
- Starts the Serial device with this driver.\r
-\r
- This function produces Serial IO Protocol and initializes the USB\r
- Serial device to manage this USB Serial device.\r
-\r
- @param This[in] The USB Serial driver binding instance.\r
- @param Controller[in] Handle of device to bind driver to.\r
- @param RemainingDevicePath[in] Optional parameter use to pick a specific\r
- child device to start.\r
-\r
- @retval EFI_SUCCESS The controller is controlled by the USB\r
- Serial driver.\r
- @retval EFI_UNSUPPORTED No interrupt endpoint can be found.\r
- @retval Other This controller cannot be started.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-UsbSerialDriverBindingStart (\r
- IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
- IN EFI_HANDLE Controller,\r
- IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
- );\r
-\r
-/**\r
- Stop the USB Serial device handled by this driver.\r
-\r
- @param This[in] The USB Serial driver binding protocol.\r
- @param Controller[in] The controller to release.\r
- @param NumberOfChildren[in] The number of handles in ChildHandleBuffer.\r
- @param ChildHandleBuffer[in] The array of child handle.\r
-\r
- @retval EFI_SUCCESS The device was stopped.\r
- @retval EFI_UNSUPPORTED Simple Text In Protocol or Simple Text In Ex\r
- Protocol is not installed on Controller.\r
- @retval EFI_DEVICE_ERROR The device could not be stopped due to a\r
- device error.\r
- @retval Others Fail to uninstall protocols attached on the\r
- device.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-UsbSerialDriverBindingStop (\r
- IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
- IN EFI_HANDLE Controller,\r
- IN UINTN NumberOfChildren,\r
- IN EFI_HANDLE *ChildHandleBuffer\r
- );\r
-\r
-//\r
-// Serial IO Member Functions\r
-//\r
-\r
-/**\r
- Writes data to a serial device.\r
-\r
- @param This[in] Protocol instance pointer.\r
- @param BufferSize[in, out] On input, the size of the Buffer. On output,\r
- the amount of data actually written.\r
- @param Buffer[in] The buffer of data to write\r
-\r
- @retval EFI_SUCCESS The data was written.\r
- @retval EFI_DEVICE_ERROR The device reported an error.\r
- @retval EFI_TIMEOUT The data write was stopped due to a timeout.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-WriteSerialIo (\r
- IN EFI_SERIAL_IO_PROTOCOL *This,\r
- IN OUT UINTN *BufferSize,\r
- IN VOID *Buffer\r
- );\r
-\r
-/**\r
- Reads data from a serial device.\r
-\r
- @param This[in] Protocol instance pointer.\r
- @param BufferSize[in, out] On input, the size of the Buffer. On output,\r
- the amount of data returned in Buffer.\r
- @param Buffer[out] The buffer to return the data into.\r
-\r
- @retval EFI_SUCCESS The data was read.\r
- @retval EFI_DEVICE_ERROR The device reported an error.\r
- @retval EFI_TIMEOUT The data write was stopped due to a timeout.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-ReadSerialIo (\r
- IN EFI_SERIAL_IO_PROTOCOL *This,\r
- IN OUT UINTN *BufferSize,\r
- OUT VOID *Buffer\r
- );\r
-\r
-/**\r
- Retrieves the status of the control bits on a serial device.\r
-\r
- @param This[in] Protocol instance pointer.\r
- @param Control[out] A pointer to return the current Control signals\r
- from the serial device.\r
-\r
- @retval EFI_SUCCESS The control bits were read from the serial\r
- device.\r
- @retval EFI_DEVICE_ERROR The serial device is not functioning correctly.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-GetControlBits (\r
- IN EFI_SERIAL_IO_PROTOCOL *This,\r
- OUT UINT32 *Control\r
- );\r
-\r
-/**\r
- Set the control bits on a serial device.\r
-\r
- @param This[in] Protocol instance pointer.\r
- @param Control[in] Set the bits of Control that are settable.\r
-\r
- @retval EFI_SUCCESS The new control bits were set on the serial device.\r
- @retval EFI_UNSUPPORTED The serial device does not support this operation.\r
- @retval EFI_DEVICE_ERROR The serial device is not functioning correctly.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-SetControlBits (\r
- IN EFI_SERIAL_IO_PROTOCOL *This,\r
- IN UINT32 Control\r
- );\r
-\r
-/**\r
- Calls SetAttributesInternal() to set the baud rate, receive FIFO depth,\r
- transmit/receice time out, parity, data buts, and stop bits on a serial device.\r
-\r
- @param This[in] Protocol instance pointer.\r
- @param BaudRate[in] The requested baud rate. A BaudRate value of 0\r
- will use the device's default interface speed.\r
- @param ReveiveFifoDepth[in] The requested depth of the FIFO on the receive\r
- side of the serial interface. A ReceiveFifoDepth\r
- value of 0 will use the device's default FIFO\r
- depth.\r
- @param Timeout[in] The requested time out for a single character in\r
- microseconds.This timeout applies to both the\r
- transmit and receive side of the interface.A\r
- Timeout value of 0 will use the device's default\r
- time out value.\r
- @param Parity[in] The type of parity to use on this serial device.A\r
- Parity value of DefaultParity will use the\r
- device's default parity value.\r
- @param DataBits[in] The number of data bits to use on the serial\r
- device. A DataBits value of 0 will use the\r
- device's default data bit setting.\r
- @param StopBits[in] The number of stop bits to use on this serial\r
- device. A StopBits value of DefaultStopBits will\r
- use the device's default number of stop bits.\r
-\r
- @retval EFI_SUCCESS The attributes were set\r
- @retval EFI_DEVICE_ERROR The attributes were not able to be\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-SetAttributes (\r
- IN EFI_SERIAL_IO_PROTOCOL *This,\r
- IN UINT64 BaudRate,\r
- IN UINT32 ReceiveFifoDepth,\r
- IN UINT32 Timeout,\r
- IN EFI_PARITY_TYPE Parity,\r
- IN UINT8 DataBits,\r
- IN EFI_STOP_BITS_TYPE StopBits\r
- );\r
-\r
-/**\r
- Reset the serial device.\r
-\r
- @param This Protocol instance pointer.\r
-\r
- @retval EFI_SUCCESS The device was reset.\r
- @retval EFI_DEVICE_ERROR The serial device could not be reset.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-SerialReset (\r
- IN EFI_SERIAL_IO_PROTOCOL *This\r
- );\r
-\r
-//\r
-// EFI Component Name Functions\r
-//\r
-\r
-/**\r
- Retrieves a Unicode string that is the user readable name of the driver.\r
-\r
- This function retrieves the user readable name of a driver in the form of a\r
- Unicode string. If the driver specified by This has a user readable name in\r
- the language specified by Language, then a pointer to the driver name is\r
- returned in DriverName, and EFI_SUCCESS is returned. If the driver specified\r
- by This does not support the language specified by Language,\r
- then EFI_UNSUPPORTED is returned.\r
-\r
- @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL\r
- or EFI_COMPONENT_NAME_PROTOCOL instance.\r
- @param Language[in] A pointer to a Null-terminated ASCII string\r
- array indicating the language. This is the\r
- language of the driver name that the caller\r
- is requesting, and it must match one of the\r
- languages specified in SupportedLanguages.\r
- The number of languages supported by a\r
- driver is up to the driver writer. Language\r
- is specified in RFC 4646 or ISO 639-2\r
- language code format.\r
- @param DriverName[out] A pointer to the Unicode string to return.\r
- This Unicode string is the name of the\r
- driver specified by This in the language\r
- specified by Language.\r
-\r
- @retval EFI_SUCCESS The Unicode string for the Driver specified\r
- by This and the language specified by\r
- Language was returned in DriverName.\r
- @retval EFI_INVALID_PARAMETER Language is NULL.\r
- @retval EFI_INVALID_PARAMETER DriverName is NULL.\r
- @retval EFI_UNSUPPORTED The driver specified by This does not\r
- support the language specified by Language.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-UsbSerialComponentNameGetDriverName (\r
- IN EFI_COMPONENT_NAME2_PROTOCOL *This,\r
- IN CHAR8 *Language,\r
- OUT CHAR16 **DriverName\r
- );\r
-\r
-/**\r
- Retrieves a Unicode string that is the user readable name of the controller\r
- that is being managed by a driver.\r
-\r
- This function retrieves the user readable name of the controller specified by\r
- ControllerHandle and ChildHandle in the form of a Unicode string. If the\r
- driver specified by This has a user readable name in the language specified by\r
- Language, then a pointer to the controller name is returned in ControllerName,\r
- and EFI_SUCCESS is returned. If the driver specified by This is not currently\r
- managing the controller specified by ControllerHandle and ChildHandle,\r
- then EFI_UNSUPPORTED is returned. If the driver specified by This does not\r
- support the language specified by Language, then EFI_UNSUPPORTED is returned.\r
-\r
- @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL\r
- or EFI_COMPONENT_NAME_PROTOCOL instance.\r
- @param ControllerHandle[in] The handle of a controller that the driver\r
- specified by This is managing. This handle\r
- specifies the controller whose name is to\r
- be returned.\r
- @param ChildHandle[in] The handle of the child controller to\r
- retrieve the name of. This is an optional\r
- parameter that may be NULL. It will be NULL\r
- for device drivers. It will also be NULL\r
- for a bus drivers that wish to retrieve the\r
- name of the bus controller. It will not be\r
- NULL for a bus driver that wishes to\r
- retrieve the name of a child controller.\r
- @param Language[in] A pointer to a Null-terminated ASCII string\r
- array indicating the language. This is the\r
- language of the driver name that the caller\r
- is requesting, and it must match one of the\r
- languages specified in SupportedLanguages.\r
- The number of languages supported by a\r
- driver is up to the driver writer. Language\r
- is specified in RFC 4646 or ISO 639-2\r
- language code format.\r
- @param ControllerName[out] A pointer to the Unicode string to return.\r
- This Unicode string is the name of the\r
- controller specified by ControllerHandle\r
- and ChildHandle in the language specified\r
- by Language from the point of view of the\r
- driver specified by This.\r
-\r
- @retval EFI_SUCCESS The Unicode string for the user readable\r
- name in the language specified by Language\r
- for the driver specified by This was\r
- returned in DriverName.\r
- @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.\r
- @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a\r
- valid EFI_HANDLE.\r
- @retval EFI_INVALID_PARAMETER Language is NULL.\r
- @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r
- @retval EFI_UNSUPPORTED The driver specified by This is not\r
- currently managing the controller specified\r
- by ControllerHandle and ChildHandle.\r
- @retval EFI_UNSUPPORTED The driver specified by This does not\r
- support the language specified by Language.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-UsbSerialComponentNameGetControllerName (\r
- IN EFI_COMPONENT_NAME2_PROTOCOL *This,\r
- IN EFI_HANDLE ControllerHandle,\r
- IN EFI_HANDLE ChildHandle OPTIONAL,\r
- IN CHAR8 *Language,\r
- OUT CHAR16 **ControllerName\r
- );\r
-\r
-#endif\r