firmware.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * NCI based driver for Samsung S3FWRN5 NFC chip
  3. *
  4. * Copyright (C) 2015 Samsung Electrnoics
  5. * Robert Baldyga <r.baldyga@samsung.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms and conditions of the GNU General Public License,
  9. * version 2 or later, as published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef __LOCAL_S3FWRN5_FIRMWARE_H_
  20. #define __LOCAL_S3FWRN5_FIRMWARE_H_
  21. /* FW Message Types */
  22. #define S3FWRN5_FW_MSG_CMD 0x00
  23. #define S3FWRN5_FW_MSG_RSP 0x01
  24. #define S3FWRN5_FW_MSG_DATA 0x02
  25. /* FW Return Codes */
  26. #define S3FWRN5_FW_RET_SUCCESS 0x00
  27. #define S3FWRN5_FW_RET_MESSAGE_TYPE_INVALID 0x01
  28. #define S3FWRN5_FW_RET_COMMAND_INVALID 0x02
  29. #define S3FWRN5_FW_RET_PAGE_DATA_OVERFLOW 0x03
  30. #define S3FWRN5_FW_RET_SECT_DATA_OVERFLOW 0x04
  31. #define S3FWRN5_FW_RET_AUTHENTICATION_FAIL 0x05
  32. #define S3FWRN5_FW_RET_FLASH_OPERATION_FAIL 0x06
  33. #define S3FWRN5_FW_RET_ADDRESS_OUT_OF_RANGE 0x07
  34. #define S3FWRN5_FW_RET_PARAMETER_INVALID 0x08
  35. /* ---- FW Packet structures ---- */
  36. #define S3FWRN5_FW_HDR_SIZE 4
  37. struct s3fwrn5_fw_header {
  38. __u8 type;
  39. __u8 code;
  40. __u16 len;
  41. };
  42. #define S3FWRN5_FW_CMD_RESET 0x00
  43. #define S3FWRN5_FW_CMD_GET_BOOTINFO 0x01
  44. struct s3fwrn5_fw_cmd_get_bootinfo_rsp {
  45. __u8 hw_version[4];
  46. __u16 sector_size;
  47. __u16 page_size;
  48. __u16 frame_max_size;
  49. __u16 hw_buffer_size;
  50. };
  51. #define S3FWRN5_FW_CMD_ENTER_UPDATE_MODE 0x02
  52. struct s3fwrn5_fw_cmd_enter_updatemode {
  53. __u16 hashcode_size;
  54. __u16 signature_size;
  55. };
  56. #define S3FWRN5_FW_CMD_UPDATE_SECTOR 0x04
  57. struct s3fwrn5_fw_cmd_update_sector {
  58. __u32 base_address;
  59. };
  60. #define S3FWRN5_FW_CMD_COMPLETE_UPDATE_MODE 0x05
  61. struct s3fwrn5_fw_image {
  62. const struct firmware *fw;
  63. char date[13];
  64. u32 version;
  65. const void *sig;
  66. u32 sig_size;
  67. const void *image;
  68. u32 image_sectors;
  69. const void *custom_sig;
  70. u32 custom_sig_size;
  71. };
  72. struct s3fwrn5_fw_info {
  73. struct nci_dev *ndev;
  74. struct s3fwrn5_fw_image fw;
  75. char fw_name[NFC_FIRMWARE_NAME_MAXSIZE + 1];
  76. const void *sig;
  77. u32 sig_size;
  78. u32 sector_size;
  79. u32 base_addr;
  80. struct completion completion;
  81. struct sk_buff *rsp;
  82. char parity;
  83. };
  84. void s3fwrn5_fw_init(struct s3fwrn5_fw_info *fw_info, const char *fw_name);
  85. int s3fwrn5_fw_setup(struct s3fwrn5_fw_info *fw_info);
  86. bool s3fwrn5_fw_check_version(struct s3fwrn5_fw_info *fw_info, u32 version);
  87. int s3fwrn5_fw_download(struct s3fwrn5_fw_info *fw_info);
  88. void s3fwrn5_fw_cleanup(struct s3fwrn5_fw_info *fw_info);
  89. int s3fwrn5_fw_recv_frame(struct nci_dev *ndev, struct sk_buff *skb);
  90. #endif /* __LOCAL_S3FWRN5_FIRMWARE_H_ */