f_dfu.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * f_dfu.h -- Device Firmware Update gadget
  3. *
  4. * Copyright (C) 2011-2012 Samsung Electronics
  5. * author: Andrzej Pietrasiewicz <andrzej.p@samsung.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. */
  21. #ifndef __F_DFU_H_
  22. #define __F_DFU_H_
  23. #include <linux/compiler.h>
  24. #include <linux/usb/composite.h>
  25. #define DFU_CONFIG_VAL 1
  26. #define DFU_DT_FUNC 0x21
  27. #define DFU_BIT_WILL_DETACH (0x1 << 3)
  28. #define DFU_BIT_MANIFESTATION_TOLERANT (0x1 << 2)
  29. #define DFU_BIT_CAN_UPLOAD (0x1 << 1)
  30. #define DFU_BIT_CAN_DNLOAD 0x1
  31. /* big enough to hold our biggest descriptor */
  32. #define DFU_USB_BUFSIZ 4096
  33. #define USB_REQ_DFU_DETACH 0x00
  34. #define USB_REQ_DFU_DNLOAD 0x01
  35. #define USB_REQ_DFU_UPLOAD 0x02
  36. #define USB_REQ_DFU_GETSTATUS 0x03
  37. #define USB_REQ_DFU_CLRSTATUS 0x04
  38. #define USB_REQ_DFU_GETSTATE 0x05
  39. #define USB_REQ_DFU_ABORT 0x06
  40. #define DFU_STATUS_OK 0x00
  41. #define DFU_STATUS_errTARGET 0x01
  42. #define DFU_STATUS_errFILE 0x02
  43. #define DFU_STATUS_errWRITE 0x03
  44. #define DFU_STATUS_errERASE 0x04
  45. #define DFU_STATUS_errCHECK_ERASED 0x05
  46. #define DFU_STATUS_errPROG 0x06
  47. #define DFU_STATUS_errVERIFY 0x07
  48. #define DFU_STATUS_errADDRESS 0x08
  49. #define DFU_STATUS_errNOTDONE 0x09
  50. #define DFU_STATUS_errFIRMWARE 0x0a
  51. #define DFU_STATUS_errVENDOR 0x0b
  52. #define DFU_STATUS_errUSBR 0x0c
  53. #define DFU_STATUS_errPOR 0x0d
  54. #define DFU_STATUS_errUNKNOWN 0x0e
  55. #define DFU_STATUS_errSTALLEDPKT 0x0f
  56. #define RET_STALL -1
  57. #define RET_ZLP 0
  58. #define RET_STAT_LEN 6
  59. enum dfu_state {
  60. DFU_STATE_appIDLE = 0,
  61. DFU_STATE_appDETACH = 1,
  62. DFU_STATE_dfuIDLE = 2,
  63. DFU_STATE_dfuDNLOAD_SYNC = 3,
  64. DFU_STATE_dfuDNBUSY = 4,
  65. DFU_STATE_dfuDNLOAD_IDLE = 5,
  66. DFU_STATE_dfuMANIFEST_SYNC = 6,
  67. DFU_STATE_dfuMANIFEST = 7,
  68. DFU_STATE_dfuMANIFEST_WAIT_RST = 8,
  69. DFU_STATE_dfuUPLOAD_IDLE = 9,
  70. DFU_STATE_dfuERROR = 10,
  71. };
  72. struct dfu_status {
  73. __u8 bStatus;
  74. __u8 bwPollTimeout[3];
  75. __u8 bState;
  76. __u8 iString;
  77. } __packed;
  78. struct dfu_function_descriptor {
  79. __u8 bLength;
  80. __u8 bDescriptorType;
  81. __u8 bmAttributes;
  82. __le16 wDetachTimeOut;
  83. __le16 wTransferSize;
  84. __le16 bcdDFUVersion;
  85. } __packed;
  86. /* configuration-specific linkup */
  87. int dfu_add(struct usb_configuration *c);
  88. #endif /* __F_DFU_H_ */