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 20 #ifndef __LOCAL_S3FWRN5_FIRMWARE_H_ 21 #define __LOCAL_S3FWRN5_FIRMWARE_H_ 22 23 /* FW Message Types */ 24 #define S3FWRN5_FW_MSG_CMD 0x00 25 #define S3FWRN5_FW_MSG_RSP 0x01 26 #define S3FWRN5_FW_MSG_DATA 0x02 27 28 /* FW Return Codes */ 29 #define S3FWRN5_FW_RET_SUCCESS 0x00 30 #define S3FWRN5_FW_RET_MESSAGE_TYPE_INVALID 0x01 31 #define S3FWRN5_FW_RET_COMMAND_INVALID 0x02 32 #define S3FWRN5_FW_RET_PAGE_DATA_OVERFLOW 0x03 33 #define S3FWRN5_FW_RET_SECT_DATA_OVERFLOW 0x04 34 #define S3FWRN5_FW_RET_AUTHENTICATION_FAIL 0x05 35 #define S3FWRN5_FW_RET_FLASH_OPERATION_FAIL 0x06 36 #define S3FWRN5_FW_RET_ADDRESS_OUT_OF_RANGE 0x07 37 #define S3FWRN5_FW_RET_PARAMETER_INVALID 0x08 38 39 /* ---- FW Packet structures ---- */ 40 #define S3FWRN5_FW_HDR_SIZE 4 41 42 struct s3fwrn5_fw_header { 43 __u8 type; 44 __u8 code; 45 __u16 len; 46 }; 47 48 #define S3FWRN5_FW_CMD_RESET 0x00 49 50 #define S3FWRN5_FW_CMD_GET_BOOTINFO 0x01 51 52 struct s3fwrn5_fw_cmd_get_bootinfo_rsp { 53 __u8 hw_version[4]; 54 __u16 sector_size; 55 __u16 page_size; 56 __u16 frame_max_size; 57 __u16 hw_buffer_size; 58 }; 59 60 #define S3FWRN5_FW_CMD_ENTER_UPDATE_MODE 0x02 61 62 struct s3fwrn5_fw_cmd_enter_updatemode { 63 __u16 hashcode_size; 64 __u16 signature_size; 65 }; 66 67 #define S3FWRN5_FW_CMD_UPDATE_SECTOR 0x04 68 69 struct s3fwrn5_fw_cmd_update_sector { 70 __u32 base_address; 71 }; 72 73 #define S3FWRN5_FW_CMD_COMPLETE_UPDATE_MODE 0x05 74 75 struct s3fwrn5_fw_image { 76 const struct firmware *fw; 77 78 char date[13]; 79 u32 version; 80 const void *sig; 81 u32 sig_size; 82 const void *image; 83 u32 image_sectors; 84 const void *custom_sig; 85 u32 custom_sig_size; 86 }; 87 88 struct s3fwrn5_fw_info { 89 struct nci_dev *ndev; 90 struct s3fwrn5_fw_image fw; 91 char fw_name[NFC_FIRMWARE_NAME_MAXSIZE + 1]; 92 93 const void *sig; 94 u32 sig_size; 95 u32 sector_size; 96 u32 base_addr; 97 98 struct completion completion; 99 struct sk_buff *rsp; 100 char parity; 101 }; 102 103 void s3fwrn5_fw_init(struct s3fwrn5_fw_info *fw_info, const char *fw_name); 104 int s3fwrn5_fw_setup(struct s3fwrn5_fw_info *fw_info); 105 bool s3fwrn5_fw_check_version(struct s3fwrn5_fw_info *fw_info, u32 version); 106 int s3fwrn5_fw_download(struct s3fwrn5_fw_info *fw_info); 107 void s3fwrn5_fw_cleanup(struct s3fwrn5_fw_info *fw_info); 108 109 int s3fwrn5_fw_recv_frame(struct nci_dev *ndev, struct sk_buff *skb); 110 111 #endif /* __LOCAL_S3FWRN5_FIRMWARE_H_ */ 112