1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  * NCI based driver for Samsung S3FWRN5 NFC chip
4  *
5  * Copyright (C) 2015 Samsung Electrnoics
6  * Robert Baldyga <r.baldyga@samsung.com>
7  */
8 
9 #ifndef __LOCAL_S3FWRN5_FIRMWARE_H_
10 #define __LOCAL_S3FWRN5_FIRMWARE_H_
11 
12 /* FW Message Types */
13 #define S3FWRN5_FW_MSG_CMD			0x00
14 #define S3FWRN5_FW_MSG_RSP			0x01
15 #define S3FWRN5_FW_MSG_DATA			0x02
16 
17 /* FW Return Codes */
18 #define S3FWRN5_FW_RET_SUCCESS			0x00
19 #define S3FWRN5_FW_RET_MESSAGE_TYPE_INVALID	0x01
20 #define S3FWRN5_FW_RET_COMMAND_INVALID		0x02
21 #define S3FWRN5_FW_RET_PAGE_DATA_OVERFLOW	0x03
22 #define S3FWRN5_FW_RET_SECT_DATA_OVERFLOW	0x04
23 #define S3FWRN5_FW_RET_AUTHENTICATION_FAIL	0x05
24 #define S3FWRN5_FW_RET_FLASH_OPERATION_FAIL	0x06
25 #define S3FWRN5_FW_RET_ADDRESS_OUT_OF_RANGE	0x07
26 #define S3FWRN5_FW_RET_PARAMETER_INVALID	0x08
27 
28 /* ---- FW Packet structures ---- */
29 #define S3FWRN5_FW_HDR_SIZE 4
30 
31 struct s3fwrn5_fw_header {
32 	__u8 type;
33 	__u8 code;
34 	__u16 len;
35 };
36 
37 #define S3FWRN5_FW_CMD_RESET			0x00
38 
39 #define S3FWRN5_FW_CMD_GET_BOOTINFO		0x01
40 
41 struct s3fwrn5_fw_cmd_get_bootinfo_rsp {
42 	__u8 hw_version[4];
43 	__u16 sector_size;
44 	__u16 page_size;
45 	__u16 frame_max_size;
46 	__u16 hw_buffer_size;
47 };
48 
49 #define S3FWRN5_FW_CMD_ENTER_UPDATE_MODE	0x02
50 
51 struct s3fwrn5_fw_cmd_enter_updatemode {
52 	__u16 hashcode_size;
53 	__u16 signature_size;
54 };
55 
56 #define S3FWRN5_FW_CMD_UPDATE_SECTOR		0x04
57 
58 struct s3fwrn5_fw_cmd_update_sector {
59 	__u32 base_address;
60 };
61 
62 #define S3FWRN5_FW_CMD_COMPLETE_UPDATE_MODE	0x05
63 
64 struct s3fwrn5_fw_image {
65 	const struct firmware *fw;
66 
67 	char date[13];
68 	u32 version;
69 	const void *sig;
70 	u32 sig_size;
71 	const void *image;
72 	u32 image_sectors;
73 	const void *custom_sig;
74 	u32 custom_sig_size;
75 };
76 
77 struct s3fwrn5_fw_info {
78 	struct nci_dev *ndev;
79 	struct s3fwrn5_fw_image fw;
80 	char fw_name[NFC_FIRMWARE_NAME_MAXSIZE + 1];
81 
82 	const void *sig;
83 	u32 sig_size;
84 	u32 sector_size;
85 	u32 base_addr;
86 
87 	struct completion completion;
88 	struct sk_buff *rsp;
89 	char parity;
90 };
91 
92 int s3fwrn5_fw_request_firmware(struct s3fwrn5_fw_info *fw_info);
93 void s3fwrn5_fw_init(struct s3fwrn5_fw_info *fw_info, const char *fw_name);
94 int s3fwrn5_fw_setup(struct s3fwrn5_fw_info *fw_info);
95 bool s3fwrn5_fw_check_version(const struct s3fwrn5_fw_info *fw_info, u32 version);
96 int s3fwrn5_fw_download(struct s3fwrn5_fw_info *fw_info);
97 void s3fwrn5_fw_cleanup(struct s3fwrn5_fw_info *fw_info);
98 
99 int s3fwrn5_fw_recv_frame(struct nci_dev *ndev, struct sk_buff *skb);
100 
101 #endif /* __LOCAL_S3FWRN5_FIRMWARE_H_ */
102