Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Eddie Cai | f646092 | 2017-12-15 08:17:10 +0800 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2017 |
| 4 | * |
| 5 | * Eddie Cai <eddie.cai.linux@gmail.com> |
Eddie Cai | f646092 | 2017-12-15 08:17:10 +0800 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #ifndef _F_ROCKUSB_H_ |
| 9 | #define _F_ROCKUSB_H_ |
| 10 | #include <blk.h> |
| 11 | |
| 12 | #define ROCKUSB_VERSION "0.1" |
| 13 | |
| 14 | #define ROCKUSB_INTERFACE_CLASS 0xff |
| 15 | #define ROCKUSB_INTERFACE_SUB_CLASS 0x06 |
| 16 | #define ROCKUSB_INTERFACE_PROTOCOL 0x05 |
| 17 | |
| 18 | #define RX_ENDPOINT_MAXIMUM_PACKET_SIZE_2_0 0x0200 |
| 19 | #define RX_ENDPOINT_MAXIMUM_PACKET_SIZE_1_1 0x0040 |
| 20 | #define TX_ENDPOINT_MAXIMUM_PACKET_SIZE 0x0040 |
| 21 | |
| 22 | #define EP_BUFFER_SIZE 4096 |
| 23 | /* |
| 24 | * EP_BUFFER_SIZE must always be an integral multiple of maxpacket size |
| 25 | * (64 or 512 or 1024), else we break on certain controllers like DWC3 |
| 26 | * that expect bulk OUT requests to be divisible by maxpacket size. |
| 27 | */ |
| 28 | |
| 29 | #define RKUSB_BUF_SIZE EP_BUFFER_SIZE * 2 |
Alberto Panizzo | 4594021 | 2018-07-12 13:05:44 +0200 | [diff] [blame^] | 30 | #define RKBLOCK_BUF_SIZE 4096 |
Eddie Cai | f646092 | 2017-12-15 08:17:10 +0800 | [diff] [blame] | 31 | |
| 32 | #define RKUSB_STATUS_IDLE 0 |
| 33 | #define RKUSB_STATUS_CMD 1 |
| 34 | #define RKUSB_STATUS_RXDATA 2 |
| 35 | #define RKUSB_STATUS_TXDATA 3 |
| 36 | #define RKUSB_STATUS_CSW 4 |
| 37 | #define RKUSB_STATUS_RXDATA_PREPARE 5 |
| 38 | #define RKUSB_STATUS_TXDATA_PREPARE 6 |
| 39 | |
| 40 | enum rkusb_command { |
| 41 | K_FW_TEST_UNIT_READY = 0x00, |
| 42 | K_FW_READ_FLASH_ID = 0x01, |
| 43 | K_FW_SET_DEVICE_ID = 0x02, |
| 44 | K_FW_TEST_BAD_BLOCK = 0x03, |
| 45 | K_FW_READ_10 = 0x04, |
| 46 | K_FW_WRITE_10 = 0x05, |
| 47 | K_FW_ERASE_10 = 0x06, |
| 48 | K_FW_WRITE_SPARE = 0x07, |
| 49 | K_FW_READ_SPARE = 0x08, |
| 50 | |
| 51 | K_FW_ERASE_10_FORCE = 0x0b, |
| 52 | K_FW_GET_VERSION = 0x0c, |
| 53 | |
| 54 | K_FW_LBA_READ_10 = 0x14, |
| 55 | K_FW_LBA_WRITE_10 = 0x15, |
| 56 | K_FW_ERASE_SYS_DISK = 0x16, |
| 57 | K_FW_SDRAM_READ_10 = 0x17, |
| 58 | K_FW_SDRAM_WRITE_10 = 0x18, |
| 59 | K_FW_SDRAM_EXECUTE = 0x19, |
| 60 | K_FW_READ_FLASH_INFO = 0x1A, |
| 61 | K_FW_GET_CHIP_VER = 0x1B, |
| 62 | K_FW_LOW_FORMAT = 0x1C, |
| 63 | K_FW_SET_RESET_FLAG = 0x1E, |
| 64 | K_FW_SPI_READ_10 = 0x21, |
| 65 | K_FW_SPI_WRITE_10 = 0x22, |
| 66 | |
| 67 | K_FW_SESSION = 0X30, |
| 68 | K_FW_RESET = 0xff, |
| 69 | }; |
| 70 | |
| 71 | #define CBW_DIRECTION_OUT 0x00 |
| 72 | #define CBW_DIRECTION_IN 0x80 |
| 73 | |
| 74 | struct cmd_dispatch_info { |
| 75 | enum rkusb_command cmd; |
| 76 | /* call back function to handle rockusb command */ |
| 77 | void (*cb)(struct usb_ep *ep, struct usb_request *req); |
| 78 | }; |
| 79 | |
| 80 | /* Bulk-only data structures */ |
| 81 | |
| 82 | /* Command Block Wrapper */ |
| 83 | struct fsg_bulk_cb_wrap { |
| 84 | __le32 signature; /* Contains 'USBC' */ |
| 85 | u32 tag; /* Unique per command id */ |
| 86 | __le32 data_transfer_length; /* Size of the data */ |
| 87 | u8 flags; /* Direction in bit 7 */ |
| 88 | u8 lun; /* lun (normally 0) */ |
| 89 | u8 length; /* Of the CDB, <= MAX_COMMAND_SIZE */ |
| 90 | u8 CDB[16]; /* Command Data Block */ |
| 91 | }; |
| 92 | |
| 93 | #define USB_BULK_CB_WRAP_LEN 31 |
| 94 | #define USB_BULK_CB_SIG 0x43425355 /* Spells out USBC */ |
| 95 | #define USB_BULK_IN_FLAG 0x80 |
| 96 | |
| 97 | /* Command status Wrapper */ |
| 98 | struct bulk_cs_wrap { |
| 99 | __le32 signature; /* Should = 'USBS' */ |
| 100 | u32 tag; /* Same as original command */ |
| 101 | __le32 residue; /* Amount not transferred */ |
| 102 | u8 status; /* See below */ |
| 103 | }; |
| 104 | |
| 105 | #define USB_BULK_CS_WRAP_LEN 13 |
| 106 | #define USB_BULK_CS_SIG 0x53425355 /* Spells out 'USBS' */ |
| 107 | #define USB_STATUS_PASS 0 |
| 108 | #define USB_STATUS_FAIL 1 |
| 109 | #define USB_STATUS_PHASE_ERROR 2 |
| 110 | |
| 111 | #define CSW_GOOD 0x00 |
| 112 | #define CSW_FAIL 0x01 |
| 113 | |
| 114 | struct f_rockusb { |
| 115 | struct usb_function usb_function; |
| 116 | struct usb_ep *in_ep, *out_ep; |
| 117 | struct usb_request *in_req, *out_req; |
| 118 | char *dev_type; |
| 119 | unsigned int dev_index; |
| 120 | unsigned int tag; |
| 121 | unsigned int lba; |
| 122 | unsigned int dl_size; |
| 123 | unsigned int dl_bytes; |
Alberto Panizzo | 4594021 | 2018-07-12 13:05:44 +0200 | [diff] [blame^] | 124 | unsigned int ul_size; |
| 125 | unsigned int ul_bytes; |
Eddie Cai | f646092 | 2017-12-15 08:17:10 +0800 | [diff] [blame] | 126 | struct blk_desc *desc; |
| 127 | int reboot_flag; |
| 128 | void *buf; |
| 129 | void *buf_head; |
| 130 | }; |
| 131 | |
| 132 | /* init rockusb device, tell rockusb which device you want to read/write*/ |
| 133 | void rockusb_dev_init(char *dev_type, int dev_index); |
| 134 | #endif /* _F_ROCKUSB_H_ */ |
| 135 | |