f_rockusb.h 3.6 KB

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