first and last commit

This commit is contained in:
Chris Nutter committed 2023-07-08 13:03:17 -07:00
commit 1bf4efd552
2612 files changed
+636500

No files matched your search

+95
View File
@@ -0,0 +1,95 @@
#ifndef _SYNOPSYS_OTG_PUBLIC_H_
#define _SYNOPSYS_OTG_PUBLIC_H_
#include <sys/types.h>
#include <drivers/usb/usb_chap9.h>
__BEGIN_DECLS
//===================================================================================
// Enums, structs and Typedefs
//===================================================================================
enum
{
USB_IO_ERROR = -1,
USB_IO_SUCCESS = 0,
USB_IO_ABORTED
};
enum
{
CABLE_CONNECTED = 0,
CABLE_DISCONNECTED,
USB_RESET,
USB_ENUM_DONE
};
enum {
CONNECTION_SPEED_FULL = 0,
CONNECTION_SPEED_HIGH
};
struct usb_device_io_request
{
u_int32_t endpoint;
volatile u_int8_t *io_buffer;
int status;
int io_length;
int return_count;
void (*callback) (struct usb_device_io_request *io_request);
struct usb_device_io_request *next;
};
struct usb_endpoint_instance
{
int endpoint_address;
int max_packet_size;
int attributes;
int bInterval;
int transfer_size;
int packet_count;
struct usb_endpoint_instance *next_ep;
struct usb_device_io_request *io_head;
struct usb_device_io_request *io_tail;
int tx_fifo_number;
};
struct usb_controller_ops
{
void (*start) (void);
void (*stop) (void);
void (*set_address) (int new_address);
void (*stall_endpoint) (u_int32_t endpoint, bool stall);
void (*reset_endpoint_data_toggle) (u_int32_t endpoint);
bool (*is_endpoint_stalled) (u_int32_t endpoint);
void (*do_endpoint_io) (struct usb_device_io_request *req);
void (*activate_endpoint) (u_int32_t endpoint, int type, int max_packet_size, int interval);
void (*deactivate_endpoint) (u_int32_t endpoint);
void (*abort_endpoint) (u_int32_t endpoint);
void (*do_test_mode)(int test_selector);
int (*get_connection_speed) (void);
};
struct usb_interface_instance
{
int (*interface_request_handler) (struct usb_device_request *request, u_int8_t ** out_data);
void (*non_setup_data_phase_finished_callback) (int data_rcvd);
void (*activate_interface) (void);
void (*bus_reset_handler) (void);
int (*get_interface_handler) (void);
int (*set_interface_handler) (int alt_setting);
};
//===================================================================================
// Global APIs
//===================================================================================
void usb_init (void);
__END_DECLS
#endif
+213
View File
@@ -0,0 +1,213 @@
/*
* Copyright (C) 2007-2008 Apple Inc. All rights reserved.
* Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
*
* This document is the property of Apple Computer, Inc.
* It is considered confidential and proprietary.
*
* This document may not be reproduced or transmitted in any form,
* in whole or in part, without the express written permission of
* Apple Computer, Inc.
*/
#ifndef _USB_CHAP9_H_
#define _USB_CHAP9_H_
#include <sys/types.h>
//====================================================================
// USB Descriptor Types
//====================================================================
#define USB_DT_DEVICE 1
#define USB_DT_CONFIGURATION 2
#define USB_DT_STRING 3
#define USB_DT_INTERFACE 4
#define USB_DT_ENDPOINT 5
#define USB_DT_DEVICE_QUALIFIER 6
#define USB_DT_OTHER_SPEED_CONFIGURATION 7
//====================================================================
// USB Endpoints Types
//====================================================================
#define USB_ENDPOINT_CONTROL 0x00
#define USB_ENDPOINT_ISOCHRONOUS 0x01
#define USB_ENDPOINT_BULK 0x02
#define USB_ENDPOINT_INTERRUPT 0x03
//====================================================================
// USB Standard Request Types
//====================================================================
#define USB_REQ_GET_STATUS 0x00
#define USB_REQ_CLEAR_FEATURE 0x01
#define USB_REQ_SET_FEATURE 0x03
#define USB_REQ_SET_ADDRESS 0x05
#define USB_REQ_GET_DESCRIPTOR 0x06
#define USB_REQ_SET_DESCRIPTOR 0x07
#define USB_REQ_GET_CONFIGURATION 0x08
#define USB_REQ_SET_CONFIGURATION 0x09
#define USB_REQ_GET_INTERFACE 0x0A
#define USB_REQ_SET_INTERFACE 0x0B
//====================================================================
// USB Feature Types
//====================================================================
#define USB_FEATURE_ENDPOINT_HALT 0x00
#define USB_FEATURE_REMOTE_WAKEUP 0x01
#define USB_FEATURE_TEST_MODE 0x02
//====================================================================
// USB Device Request Types
//====================================================================
#define USB_REQ_TYPE_STANDARD 0x00
#define USB_REQ_TYPE_CLASS 0x20
#define USB_REQ_TYPE_VENDOR 0x40
//====================================================================
// USB Class Codes
//====================================================================
#define USB_CLASS_INTERFACE_SPECIFIC 0
#define USB_CLASS_VENDOR_SPECIFIC 0xff
//====================================================================
// USB Chap9 specific consts
//====================================================================
#define USB_DT_DEVICE_SIZE 18
#define USB_DT_CONFIGURATION_SIZE 9
#define USB_DT_INTERFACE_SIZE 9
#define USB_DT_ENDPOINT_SIZE 7
#define USB_DT_DEVICE_QUALIFIER_SIZE 10
#define USB_DT_STRING_SIZE 6
#define USB_DIR_OUT 0
#define USB_DIR_IN 0x80
#define USB_ENDPOINT_MASK 0x03
#define USB_ENDPOINT_NUMBER_MASK 0x0f
#define USB_ENDPOINT_DIR_MASK 0x80
#define USB_BCD_VERSION 0x0200
#define USB_REQ_DIRECTION_MASK 0x80
#define USB_REQ_TYPE_MASK 0x60
#define USB_REQ_RECIPIENT_MASK 0x1f
#define USB_REQ_DEVICE2HOST 0x80
#define USB_REQ_HOST2DEVICE 0x00
#define USB_REQ_RECIPIENT_DEVICE 0x00
#define USB_REQ_RECIPIENT_INTERFACE 0x01
#define USB_REQ_RECIPIENT_ENDPOINT 0x02
#define USB_REQ_RECIPIENT_OTHER 0x03
#define SETUP_PACKET_LEN 0x8
#define EP0_IN 0x80
#define EP0_OUT 0x0
//====================================================================
// Enums, structs and typedefs
//====================================================================
struct usb_device_request
{
u_int8_t bmRequestType;
u_int8_t bRequest;
u_int16_t wValue;
u_int16_t wIndex;
u_int16_t wLength;
} __attribute__((packed));
struct usb_device_descriptor
{
u_int8_t bLength;
u_int8_t bDescriptorType;
u_int16_t bcdUSB;
u_int8_t bDeviceClass;
u_int8_t bDeviceSubClass;
u_int8_t bDeviceProtocol;
u_int8_t bMaxPacketSize0;
u_int16_t idVendor;
u_int16_t idProduct;
u_int16_t bcdDevice;
u_int8_t iManufacturer;
u_int8_t iProduct;
u_int8_t iSerialNumber;
u_int8_t bNumConfigurations;
} __attribute__((packed));
struct usb_configuration_descriptor
{
u_int8_t bLength;
u_int8_t bDescriptorType;
u_int16_t wTotalLength;
u_int8_t bNumInterfaces;
u_int8_t bConfigurationValue;
u_int8_t iConfiguration;
u_int8_t bmAttributes;
u_int8_t bMaxPower;
} __attribute__((packed));
struct usb_interface_descriptor
{
u_int8_t bLength;
u_int8_t bDescriptorType;
u_int8_t bInterfaceNumber;
u_int8_t bAlternateSetting;
u_int8_t bNumEndpoints;
u_int8_t bInterfaceClass;
u_int8_t bInterfaceSubClass;
u_int8_t bInterfaceProtocol;
u_int8_t iInterface;
} __attribute__((packed));
struct usb_endpoint_descriptor
{
u_int8_t bLength;
u_int8_t bDescriptorType;
u_int8_t bEndpointAddress;
u_int8_t bmAttributes;
u_int16_t wMaxPacketSize;
u_int8_t bInterval;
} __attribute__((packed));
struct usb_string_descriptor
{
u_int8_t bLength;
u_int8_t bDescriptorType;
u_int8_t wData[2];
} __attribute__((packed));
struct usb_device_qualifier_descriptor
{
u_int8_t bLength;
u_int8_t bDescriptorType;
u_int16_t bcdUSB;
u_int8_t bDeviceClass;
u_int8_t bDeviceSubClass;
u_int8_t bDeviceProtocol;
u_int8_t bMaxPacketSize0;
u_int8_t bNumConfigurations;
u_int8_t bReserved;
} __attribute__((packed));
enum
{
DEVICE_ST_UNKNOWN = -1,
DEVICE_ST_INIT = 0,
DEVICE_ST_ATTACHED,
DEVICE_ST_POWERED,
DEVICE_ST_DEFAULT,
DEVICE_ST_ADDRESSED,
DEVICE_ST_CONFIGURED,
DEVICE_ST_SUSPENDED
};
//====================================================================
// USB driver specific consts
//====================================================================
#define EP0_MAX_PACKET_SIZE 0x40
#define HS_BULK_EP_MAX_PACKET_SIZE 0x200
#define HS_INT_EP_MAX_PACKET_SIZE 0x40
#define FS_EP_MAX_PACKET_SIZE 0x40
#endif // _USB_CHAP9_H_
+62
View File
@@ -0,0 +1,62 @@
/*
* Copyright (C) 2010-2013 Apple Inc. All rights reserved.
*
* This document is the property of Apple Computer, Inc.
* It is considered confidential and proprietary.
*
* This document may not be reproduced or transmitted in any form,
* in whole or in part, without the express written permission of
* Apple Computer, Inc.
*/
#ifndef _USB_CONTROLLER_H_
#define _USB_CONTROLLER_H_
#include <sys/types.h>
#include <drivers/usb/usb_core.h>
__BEGIN_DECLS
#define MAX_SUPPORTED_USB_CONTROLLER (2)
typedef enum {
USB_CONTROLLER_synopsys_otg,
USB_CONTROLLER_dbgfifo,
} USB_CONTROLLER_T;
struct usb_controller_functions {
int (*init)(void);
void (*free_func)(void);
int (*start)(void);
void (*stop)(void);
void (*set_address)(uint32_t new_address);
int (*get_connection_speed)(void);
void (*activate_endpoint)(uint32_t endpoint, int type, int max_packet_size, int interval);
void (*do_endpoint_io)(struct usb_device_io_request *req);
void (*stall_endpoint)(uint32_t endpoint, bool stall);
void (*reset_endpoint_data_toggle)(uint32_t endpoint);
bool (*is_endpoint_stalled)(uint32_t endpoint);
void (*do_test_mode)(uint32_t selector);
void (*abort_endpoint)(uint32_t endpoint);
void (*deactivate_endpoint)(uint32_t endpoint);
};
int usb_controller_register(const struct usb_controller_functions *controller_functions);
int usb_controller_init(void);
void usb_controller_free(void);
int usb_controller_start(void);
void usb_controller_stop(void);
void usb_controller_set_address(u_int32_t new_address);
int usb_controller_get_connection_speed(void);
void usb_controller_activate_endpoint(u_int32_t endpoint, int type, int max_packet_size, int interval);
void usb_controller_do_endpoint_io(struct usb_device_io_request *req);
void usb_controller_stall_endpoint(u_int32_t endpoint, bool stall);
void usb_controller_reset_endpoint_data_toggle(u_int32_t endpoint);
bool usb_controller_is_endpoint_stalled(u_int32_t endpoint);
void usb_controller_do_test_mode(u_int32_t selector);
void usb_controller_abort_endpoint(u_int32_t endpoint);
void usb_controller_deactivate_endpoint(u_int32_t endpoint);
__END_DECLS
#endif // _USB_CONTROLLER_H_
+149
View File
@@ -0,0 +1,149 @@
/*
* Copyright (C) 2007-2013 Apple Inc. All rights reserved.
*
* This document is the property of Apple Computer, Inc.
* It is considered confidential and proprietary.
*
* This document may not be reproduced or transmitted in any form,
* in whole or in part, without the express written permission of
* Apple Computer, Inc.
*/
#ifndef _USB_CORE_H_
#define _USB_CORE_H_
#include <sys/types.h>
#include <drivers/usb/usb_chap9.h>
__BEGIN_DECLS
//===================================================================================
// consts and macros
//===================================================================================
#define APPLE_USB_DFU_INTF 0
#define APPLE_USB_TRNSFR_INTF APPLE_USB_DFU_INTF
#define APPLE_USB_SERIAL_INTF 0x1
#define APPLE_USB_SERIAL_CONFIG_STRING_IDX 4
#define APPLE_USB_SERIAL_INTF_STRING_INDEX 5
#define APPLE_USB_SERIAL_EP_BULK_IN 0x81
#define APPLE_USB_SERIAL_EP_BULK_OUT 0x2
#define APPLE_USB_TRNSFR_EP_BULK_OUT 0x4
#define APPLE_USB_TRNSFR_EP_BULK_IN 0x85
#define APPLE_USB_DFU_TOTAL_INTFS 1
#define APPLE_USB_DFU_CLASS 0xfe
#define APPLE_USB_DFU_SUBCLASS 0x1
#define APPLE_USB_DFU_PROTOCOL 0x0
#define APPLE_USB_SERIAL_TOTAL_EPS 2
#define APPLE_USB_SERIAL_TOTAL_INTFS 2
#define APPLE_USB_SERIAL_CLASS 0xff
#define APPLE_USB_SERIAL_SUBCLASS 0xff
#define APPLE_USB_SERIAL_PROTOCOL 0x51
#if WITH_BULK_UPLOAD
#define APPLE_USB_TRNSFR_TOTAL_EPS 2
#else
#define APPLE_USB_TRNSFR_TOTAL_EPS 1
#endif
#define APPLE_USB_TRNSFR_TOTAL_INTFS 1
#define APPLE_USB_DFU_TRNSFR_CLASS 0xfe
#define APPLE_USB_DFU_TRNSFR_SUBCLASS 0x1
#define APPLE_USB_DFU_TRNSFR_PROTOCOL 0x2
#define APPLE_USB_TRNSFR_CLASS APPLE_USB_DFU_TRNSFR_CLASS
#define APPLE_USB_TRNSFR_SUBCLASS APPLE_USB_DFU_TRNSFR_SUBCLASS
#define APPLE_USB_TRNSFR_PROTOCOL APPLE_USB_DFU_TRNSFR_PROTOCOL
//===================================================================================
// Enums, structs and Typedefs
//===================================================================================
enum
{
USB_IO_ERROR = -1,
USB_IO_SUCCESS = 0,
USB_IO_ABORTED
};
enum
{
CABLE_CONNECTED = 0,
CABLE_DISCONNECTED,
USB_RESET,
USB_ENUM_DONE
};
enum {
CONNECTION_SPEED_FULL = 0,
CONNECTION_SPEED_HIGH
};
#if WITH_RECOVERY_MODE
enum {
PR_RESET_REQUEST = 0, // put device into reset state before starting restore with bulk blaster protocol
PR_VENDOR_REQUEST = 0,
PR_VENDOR_BLIND_REQUEST // return success on usb before executing the command, primarily for fsboot or reboot
};
#endif
struct usb_device_io_request
{
u_int32_t endpoint;
volatile u_int8_t *io_buffer;
int status;
u_int32_t io_length;
u_int32_t return_count;
void (*callback) (struct usb_device_io_request *io_request);
struct usb_device_io_request *next;
};
struct usb_interface_instance
{
int total_interfaces;
struct usb_interface_descriptor *interface_descs;
int total_other_descs;
void *other_descs;
int total_endpoints;
struct usb_endpoint_descriptor *endpoint_descs;
int total_string_descs;
char **string_descs;
int (*handle_request) (struct usb_device_request *request, u_int8_t ** out_data);
void (*non_setup_data_phase_finished_callback) (u_int32_t data_rcvd);
void (*activate_interface) (void);
void (*deactivate_interface) (void);
void (*activate_endpoints) (void);
void (*deactivate_endpoints) (void);
void (*handle_bus_reset) (void);
int (*handle_get_interface) (void);
int (*handle_set_interface) (int alt_setting);
int (*handle_vendor_request) (struct usb_device_request *request);
};
//===================================================================================
// Global APIs
//===================================================================================
int usb_core_init (const char *config_desc_string);
void usb_core_free (void);
int usb_core_start();
void usb_core_stop();
void usb_core_handle_usb_control_receive (u_int8_t *ep0_rx_buffer, bool is_setup, int receive_length, bool *data_phase);
void usb_core_register_interface (struct usb_interface_instance *if_ops);
void usb_core_event_handler (int event);
void usb_core_do_transfer (int endpoint, u_int8_t *buffer, int length, void (*callback)(struct usb_device_io_request *));
void usb_core_send_zlp (void);
void usb_core_complete_endpoint_io (struct usb_device_io_request *req);
void usb_core_activate_endpoint (u_int32_t endpoint, int type, int max_packet_size, int interval);
void usb_core_deactivate_endpoint (u_int32_t endpoint);
void usb_core_abort_endpoint (int endpoint);
bool usb_core_get_connection_speed (void);
bool usb_core_get_cable_state (void);
__END_DECLS
#endif
+13
View File
@@ -0,0 +1,13 @@
/*
* Copyright (C) 2010-2014 Apple Inc. All rights reserved.
*
* This document is the property of Apple Inc.
* It is considered confidential and proprietary.
*
* This document may not be reproduced or transmitted in any form,
* in whole or in part, without the express written permission of
* Apple Inc.
*/
int usb_send_data_to_file(const char *filename, size_t amount, uintptr_t address, int printCompletionStatus);
+53
View File
@@ -0,0 +1,53 @@
/*
* Copyright (C) 2007-2013 Apple Inc. All rights reserved.
*
* This document is the property of Apple Computer, Inc.
* It is considered confidential and proprietary.
*
* This document may not be reproduced or transmitted in any form,
* in whole or in part, without the express written permission of
* Apple Computer, Inc.
*/
#ifndef _USB_PUBLIC_H_
#define _USB_PUBLIC_H_
#include <drivers/usb/usb_controller.h>
__BEGIN_DECLS
enum {
USB_TRANSFER_TYPE_DFU_GET,
USB_TRANSFER_TYPE_DFU_PUT,
USB_TRANSFER_TYPE_BULK_GET,
USB_TRANSFER_TYPE_BULK_PUT
};
//===================================================================================
// Global APIs
//===================================================================================
int usb_early_init();
int usb_init_with_controller(struct usb_controller_functions *controller_funcs);
int usb_init();
void usb_quiesce(void);
int getDFUImage(void* buffer, int len);
int usb_dfu_init(void);
void usb_dfu_exit(void);
int usb_transfer_init(void);
void usb_transfer_exit(void);
void usb_transfer_prepare(int type, void *address, u_int32_t maxlen);
u_int32_t usb_transfer_start();
int usb_serial_early_init(void);
int usb_serial_init(void);
void usb_serial_exit(void);
void usb_serial_putchar(int);
int usb_serial_send_cmd_string(u_int8_t *buffer, u_int32_t len);
bool usb_serial_is_active();
__END_DECLS
#endif