Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /* -------------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Copyright (C) 2014-2016, Intel Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * -------------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/nfc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/i2c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/firmware.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <net/nfc/nci_core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include "fdp.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #define FDP_OTP_PATCH_NAME			"otp.bin"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #define FDP_RAM_PATCH_NAME			"ram.bin"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #define FDP_FW_HEADER_SIZE			576
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #define FDP_FW_UPDATE_SLEEP			1000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #define NCI_GET_VERSION_TIMEOUT			8000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #define NCI_PATCH_REQUEST_TIMEOUT		8000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #define FDP_PATCH_CONN_DEST			0xC2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #define FDP_PATCH_CONN_PARAM_TYPE		0xA0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #define NCI_PATCH_TYPE_RAM			0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #define NCI_PATCH_TYPE_OTP			0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #define NCI_PATCH_TYPE_EOT			0xFF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #define NCI_PARAM_ID_FW_RAM_VERSION		0xA0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #define NCI_PARAM_ID_FW_OTP_VERSION		0xA1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #define NCI_PARAM_ID_OTP_LIMITED_VERSION	0xC5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #define NCI_PARAM_ID_KEY_INDEX_ID		0xC6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #define NCI_GID_PROP				0x0F
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #define NCI_OP_PROP_PATCH_OID			0x08
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #define NCI_OP_PROP_SET_PDATA_OID		0x23
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) struct fdp_nci_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	struct nfc_phy_ops *phy_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	struct fdp_i2c_phy *phy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	struct nci_dev *ndev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	const struct firmware *otp_patch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	const struct firmware *ram_patch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	u32 otp_patch_version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	u32 ram_patch_version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	u32 otp_version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	u32 ram_version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	u32 limited_otp_version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	u8 key_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	u8 *fw_vsc_cfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	u8 clock_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	u32 clock_freq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	atomic_t data_pkt_counter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	void (*data_pkt_counter_cb)(struct nci_dev *ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	u8 setup_patch_sent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	u8 setup_patch_ntf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	u8 setup_patch_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	u8 setup_reset_ntf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	wait_queue_head_t setup_wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) static u8 nci_core_get_config_otp_ram_version[5] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	0x04,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	NCI_PARAM_ID_FW_RAM_VERSION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	NCI_PARAM_ID_FW_OTP_VERSION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	NCI_PARAM_ID_OTP_LIMITED_VERSION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	NCI_PARAM_ID_KEY_INDEX_ID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) struct nci_core_get_config_rsp {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	u8 status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	u8 count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	u8 data[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) static int fdp_nci_create_conn(struct nci_dev *ndev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	struct fdp_nci_info *info = nci_get_drvdata(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	struct core_conn_create_dest_spec_params param;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	int r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	/* proprietary destination specific paramerer without value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	param.type = FDP_PATCH_CONN_PARAM_TYPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	param.length = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	r = nci_core_conn_create(info->ndev, FDP_PATCH_CONN_DEST, 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 				 sizeof(param), &param);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	if (r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	return nci_get_conn_info_by_dest_type_params(ndev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 						     FDP_PATCH_CONN_DEST, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) static inline int fdp_nci_get_versions(struct nci_dev *ndev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	return nci_core_cmd(ndev, NCI_OP_CORE_GET_CONFIG_CMD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 			    sizeof(nci_core_get_config_otp_ram_version),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 			    (__u8 *) &nci_core_get_config_otp_ram_version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) static inline int fdp_nci_patch_cmd(struct nci_dev *ndev, u8 type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	return nci_prop_cmd(ndev, NCI_OP_PROP_PATCH_OID, sizeof(type), &type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) static inline int fdp_nci_set_production_data(struct nci_dev *ndev, u8 len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 					      char *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	return nci_prop_cmd(ndev, NCI_OP_PROP_SET_PDATA_OID, len, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) static int fdp_nci_set_clock(struct nci_dev *ndev, u8 clock_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 			     u32 clock_freq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	u32 fc = 13560;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	u32 nd, num, delta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	char data[9];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	nd = (24 * fc) / clock_freq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	delta = 24 * fc - nd * clock_freq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	num = (32768 * delta) / clock_freq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	data[0] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	data[1] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	data[2] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	data[3] = 0x10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	data[4] = 0x04;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	data[5] = num & 0xFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	data[6] = (num >> 8) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	data[7] = nd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	data[8] = clock_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	return fdp_nci_set_production_data(ndev, 9, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) static void fdp_nci_send_patch_cb(struct nci_dev *ndev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	struct fdp_nci_info *info = nci_get_drvdata(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	info->setup_patch_sent = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	wake_up(&info->setup_wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)  * Register a packet sent counter and a callback
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)  * We have no other way of knowing when all firmware packets were sent out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)  * on the i2c bus. We need to know that in order to close the connection and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)  * send the patch end message.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) static void fdp_nci_set_data_pkt_counter(struct nci_dev *ndev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 				  void (*cb)(struct nci_dev *ndev), int count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	struct fdp_nci_info *info = nci_get_drvdata(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	struct device *dev = &info->phy->i2c_dev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	dev_dbg(dev, "NCI data pkt counter %d\n", count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	atomic_set(&info->data_pkt_counter, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	info->data_pkt_counter_cb = cb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)  * The device is expecting a stream of packets. All packets need to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)  * have the PBF flag set to 0x0 (last packet) even if the firmware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)  * file is segmented and there are multiple packets. If we give the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)  * whole firmware to nci_send_data it will segment it and it will set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)  * the PBF flag to 0x01 so we need to do the segmentation here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)  * The firmware will be analyzed and applied when we send NCI_OP_PROP_PATCH_CMD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)  * command with NCI_PATCH_TYPE_EOT parameter. The device will send a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)  * NFCC_PATCH_NTF packaet and a NCI_OP_CORE_RESET_NTF packet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) static int fdp_nci_send_patch(struct nci_dev *ndev, u8 conn_id, u8 type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	struct fdp_nci_info *info = nci_get_drvdata(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	const struct firmware *fw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	unsigned long len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	int max_size, payload_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	if ((type == NCI_PATCH_TYPE_OTP && !info->otp_patch) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	    (type == NCI_PATCH_TYPE_RAM && !info->ram_patch))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	if (type == NCI_PATCH_TYPE_OTP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		fw = info->otp_patch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		fw = info->ram_patch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	max_size = nci_conn_max_data_pkt_payload_size(ndev, conn_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	if (max_size <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	len = fw->size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	fdp_nci_set_data_pkt_counter(ndev, fdp_nci_send_patch_cb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 				     DIV_ROUND_UP(fw->size, max_size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	while (len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		payload_size = min_t(unsigned long, max_size, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		skb = nci_skb_alloc(ndev, (NCI_CTRL_HDR_SIZE + payload_size),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 				    GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		if (!skb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 			fdp_nci_set_data_pkt_counter(ndev, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 			return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 		skb_reserve(skb, NCI_CTRL_HDR_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		skb_put_data(skb, fw->data + (fw->size - len), payload_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		rc = nci_send_data(ndev, conn_id, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 			fdp_nci_set_data_pkt_counter(ndev, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 			return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		len -= payload_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) static int fdp_nci_open(struct nci_dev *ndev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	int r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	struct fdp_nci_info *info = nci_get_drvdata(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	struct device *dev = &info->phy->i2c_dev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	dev_dbg(dev, "%s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	r = info->phy_ops->enable(info->phy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) static int fdp_nci_close(struct nci_dev *ndev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	struct fdp_nci_info *info = nci_get_drvdata(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	struct device *dev = &info->phy->i2c_dev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	dev_dbg(dev, "%s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) static int fdp_nci_send(struct nci_dev *ndev, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	struct fdp_nci_info *info = nci_get_drvdata(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	struct device *dev = &info->phy->i2c_dev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	dev_dbg(dev, "%s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	if (atomic_dec_and_test(&info->data_pkt_counter))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		info->data_pkt_counter_cb(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	return info->phy_ops->write(info->phy, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) int fdp_nci_recv_frame(struct nci_dev *ndev, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	struct fdp_nci_info *info = nci_get_drvdata(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	struct device *dev = &info->phy->i2c_dev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	dev_dbg(dev, "%s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	return nci_recv_frame(ndev, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) EXPORT_SYMBOL(fdp_nci_recv_frame);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) static int fdp_nci_request_firmware(struct nci_dev *ndev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	struct fdp_nci_info *info = nci_get_drvdata(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	struct device *dev = &info->phy->i2c_dev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	u8 *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	int r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	r = request_firmware(&info->ram_patch, FDP_RAM_PATCH_NAME, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	if (r < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 		nfc_err(dev, "RAM patch request error\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 		goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	data = (u8 *) info->ram_patch->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	info->ram_patch_version =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 		data[FDP_FW_HEADER_SIZE] |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 		(data[FDP_FW_HEADER_SIZE + 1] << 8) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 		(data[FDP_FW_HEADER_SIZE + 2] << 16) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 		(data[FDP_FW_HEADER_SIZE + 3] << 24);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	dev_dbg(dev, "RAM patch version: %d, size: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 		  info->ram_patch_version, (int) info->ram_patch->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	r = request_firmware(&info->otp_patch, FDP_OTP_PATCH_NAME, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	if (r < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 		nfc_err(dev, "OTP patch request error\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	data = (u8 *) info->otp_patch->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	info->otp_patch_version =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 		data[FDP_FW_HEADER_SIZE] |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 		(data[FDP_FW_HEADER_SIZE + 1] << 8) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 		(data[FDP_FW_HEADER_SIZE+2] << 16) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 		(data[FDP_FW_HEADER_SIZE+3] << 24);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	dev_dbg(dev, "OTP patch version: %d, size: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 		 info->otp_patch_version, (int) info->otp_patch->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) static void fdp_nci_release_firmware(struct nci_dev *ndev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	struct fdp_nci_info *info = nci_get_drvdata(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	if (info->otp_patch) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 		release_firmware(info->otp_patch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 		info->otp_patch = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	if (info->ram_patch) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 		release_firmware(info->ram_patch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 		info->ram_patch = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) static int fdp_nci_patch_otp(struct nci_dev *ndev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	struct fdp_nci_info *info = nci_get_drvdata(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	struct device *dev = &info->phy->i2c_dev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	int conn_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	int r = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	if (info->otp_version >= info->otp_patch_version)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	info->setup_patch_sent = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	info->setup_reset_ntf = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	info->setup_patch_ntf = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	/* Patch init request */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	r = fdp_nci_patch_cmd(ndev, NCI_PATCH_TYPE_OTP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	if (r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	/* Patch data connection creation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	conn_id = fdp_nci_create_conn(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	if (conn_id < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 		r = conn_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	/* Send the patch over the data connection */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	r = fdp_nci_send_patch(ndev, conn_id, NCI_PATCH_TYPE_OTP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	if (r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	/* Wait for all the packets to be send over i2c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	wait_event_interruptible(info->setup_wq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 				 info->setup_patch_sent == 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	/* make sure that the NFCC processed the last data packet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	msleep(FDP_FW_UPDATE_SLEEP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	/* Close the data connection */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	r = nci_core_conn_close(info->ndev, conn_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	if (r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	/* Patch finish message */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	if (fdp_nci_patch_cmd(ndev, NCI_PATCH_TYPE_EOT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 		nfc_err(dev, "OTP patch error 0x%x\n", r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 		r = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	/* If the patch notification didn't arrive yet, wait for it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	wait_event_interruptible(info->setup_wq, info->setup_patch_ntf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	/* Check if the patching was successful */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	r = info->setup_patch_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	if (r) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 		nfc_err(dev, "OTP patch error 0x%x\n", r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 		r = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	 * We need to wait for the reset notification before we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	 * can continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	wait_event_interruptible(info->setup_wq, info->setup_reset_ntf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) static int fdp_nci_patch_ram(struct nci_dev *ndev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	struct fdp_nci_info *info = nci_get_drvdata(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	struct device *dev = &info->phy->i2c_dev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 	int conn_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	int r = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	if (info->ram_version >= info->ram_patch_version)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	info->setup_patch_sent = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 	info->setup_reset_ntf = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 	info->setup_patch_ntf = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 	/* Patch init request */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	r = fdp_nci_patch_cmd(ndev, NCI_PATCH_TYPE_RAM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	if (r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 	/* Patch data connection creation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	conn_id = fdp_nci_create_conn(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	if (conn_id < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 		r = conn_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	/* Send the patch over the data connection */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	r = fdp_nci_send_patch(ndev, conn_id, NCI_PATCH_TYPE_RAM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	if (r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	/* Wait for all the packets to be send over i2c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	wait_event_interruptible(info->setup_wq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 				 info->setup_patch_sent == 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 	/* make sure that the NFCC processed the last data packet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	msleep(FDP_FW_UPDATE_SLEEP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	/* Close the data connection */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	r = nci_core_conn_close(info->ndev, conn_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	if (r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	/* Patch finish message */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	if (fdp_nci_patch_cmd(ndev, NCI_PATCH_TYPE_EOT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 		nfc_err(dev, "RAM patch error 0x%x\n", r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 		r = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 	/* If the patch notification didn't arrive yet, wait for it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	wait_event_interruptible(info->setup_wq, info->setup_patch_ntf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	/* Check if the patching was successful */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	r = info->setup_patch_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 	if (r) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 		nfc_err(dev, "RAM patch error 0x%x\n", r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 		r = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 	 * We need to wait for the reset notification before we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 	 * can continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 	wait_event_interruptible(info->setup_wq, info->setup_reset_ntf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 	return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) static int fdp_nci_setup(struct nci_dev *ndev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 	/* Format: total length followed by an NCI packet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 	struct fdp_nci_info *info = nci_get_drvdata(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 	struct device *dev = &info->phy->i2c_dev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 	int r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 	u8 patched = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 	dev_dbg(dev, "%s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 	r = nci_core_init(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 	if (r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 		goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 	/* Get RAM and OTP version */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 	r = fdp_nci_get_versions(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 	if (r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 		goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 	/* Load firmware from disk */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 	r = fdp_nci_request_firmware(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 	if (r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 		goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 	/* Update OTP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 	if (info->otp_version < info->otp_patch_version) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 		r = fdp_nci_patch_otp(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 		if (r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 			goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 		patched = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 	/* Update RAM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 	if (info->ram_version < info->ram_patch_version) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 		r = fdp_nci_patch_ram(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 		if (r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 			goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 		patched = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 	/* Release the firmware buffers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 	fdp_nci_release_firmware(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 	/* If a patch was applied the new version is checked */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 	if (patched) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 		r = nci_core_init(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 		if (r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 			goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 		r = fdp_nci_get_versions(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 		if (r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 			goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 		if (info->otp_version != info->otp_patch_version ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 		    info->ram_version != info->ram_patch_version) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 			nfc_err(dev, "Firmware update failed");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 			r = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 			goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 	 * We initialized the devices but the NFC subsystem expects
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 	 * it to not be initialized.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 	return nci_core_reset(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 	fdp_nci_release_firmware(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 	nfc_err(dev, "Setup error %d\n", r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 	return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) static int fdp_nci_post_setup(struct nci_dev *ndev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 	struct fdp_nci_info *info = nci_get_drvdata(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 	struct device *dev = &info->phy->i2c_dev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 	int r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 	/* Check if the device has VSC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 	if (info->fw_vsc_cfg && info->fw_vsc_cfg[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 		/* Set the vendor specific configuration */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 		r = fdp_nci_set_production_data(ndev, info->fw_vsc_cfg[3],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 						&info->fw_vsc_cfg[4]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 		if (r) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 			nfc_err(dev, "Vendor specific config set error %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 				r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 			return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 	/* Set clock type and frequency */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 	r = fdp_nci_set_clock(ndev, info->clock_type, info->clock_freq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 	if (r) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 		nfc_err(dev, "Clock set error %d\n", r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 		return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 	 * In order to apply the VSC FDP needs a reset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 	r = nci_core_reset(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 	if (r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 		return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 	/**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 	 * The nci core was initialized when post setup was called
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 	 * so we leave it like that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) 	return nci_core_init(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) static int fdp_nci_core_reset_ntf_packet(struct nci_dev *ndev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) 					  struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 	struct fdp_nci_info *info = nci_get_drvdata(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) 	struct device *dev = &info->phy->i2c_dev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) 	dev_dbg(dev, "%s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 	info->setup_reset_ntf = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) 	wake_up(&info->setup_wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) static int fdp_nci_prop_patch_ntf_packet(struct nci_dev *ndev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) 					  struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) 	struct fdp_nci_info *info = nci_get_drvdata(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) 	struct device *dev = &info->phy->i2c_dev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 	dev_dbg(dev, "%s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) 	info->setup_patch_ntf = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 	info->setup_patch_status = skb->data[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) 	wake_up(&info->setup_wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) static int fdp_nci_prop_patch_rsp_packet(struct nci_dev *ndev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) 					  struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) 	struct fdp_nci_info *info = nci_get_drvdata(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) 	struct device *dev = &info->phy->i2c_dev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) 	u8 status = skb->data[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 	dev_dbg(dev, "%s: status 0x%x\n", __func__, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) 	nci_req_complete(ndev, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) static int fdp_nci_prop_set_production_data_rsp_packet(struct nci_dev *ndev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) 							struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) 	struct fdp_nci_info *info = nci_get_drvdata(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) 	struct device *dev = &info->phy->i2c_dev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) 	u8 status = skb->data[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) 	dev_dbg(dev, "%s: status 0x%x\n", __func__, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) 	nci_req_complete(ndev, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) static int fdp_nci_core_get_config_rsp_packet(struct nci_dev *ndev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) 						struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) 	struct fdp_nci_info *info = nci_get_drvdata(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) 	struct device *dev = &info->phy->i2c_dev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) 	struct nci_core_get_config_rsp *rsp = (void *) skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) 	u8 i, *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) 	if (rsp->status == NCI_STATUS_OK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) 		p = rsp->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) 		for (i = 0; i < 4; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) 			switch (*p++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) 			case NCI_PARAM_ID_FW_RAM_VERSION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) 				p++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) 				info->ram_version = le32_to_cpup((__le32 *) p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) 				p += 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) 			case NCI_PARAM_ID_FW_OTP_VERSION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) 				p++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) 				info->otp_version = le32_to_cpup((__le32 *) p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) 				p += 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) 			case NCI_PARAM_ID_OTP_LIMITED_VERSION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) 				p++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) 				info->otp_version = le32_to_cpup((__le32 *) p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) 				p += 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) 			case NCI_PARAM_ID_KEY_INDEX_ID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) 				p++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) 				info->key_index = *p++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) 	dev_dbg(dev, "OTP version %d\n", info->otp_version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) 	dev_dbg(dev, "RAM version %d\n", info->ram_version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) 	dev_dbg(dev, "key index %d\n", info->key_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) 	dev_dbg(dev, "%s: status 0x%x\n", __func__, rsp->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) 	nci_req_complete(ndev, rsp->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) static struct nci_driver_ops fdp_core_ops[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) 		.opcode = NCI_OP_CORE_GET_CONFIG_RSP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) 		.rsp = fdp_nci_core_get_config_rsp_packet,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) 		.opcode = NCI_OP_CORE_RESET_NTF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) 		.ntf = fdp_nci_core_reset_ntf_packet,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) static struct nci_driver_ops fdp_prop_ops[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) 		.opcode = nci_opcode_pack(NCI_GID_PROP, NCI_OP_PROP_PATCH_OID),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) 		.rsp = fdp_nci_prop_patch_rsp_packet,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) 		.ntf = fdp_nci_prop_patch_ntf_packet,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) 		.opcode = nci_opcode_pack(NCI_GID_PROP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) 					  NCI_OP_PROP_SET_PDATA_OID),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) 		.rsp = fdp_nci_prop_set_production_data_rsp_packet,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) static struct nci_ops nci_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) 	.open = fdp_nci_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) 	.close = fdp_nci_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) 	.send = fdp_nci_send,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) 	.setup = fdp_nci_setup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) 	.post_setup = fdp_nci_post_setup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) 	.prop_ops = fdp_prop_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) 	.n_prop_ops = ARRAY_SIZE(fdp_prop_ops),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) 	.core_ops = fdp_core_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) 	.n_core_ops = ARRAY_SIZE(fdp_core_ops),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) int fdp_nci_probe(struct fdp_i2c_phy *phy, struct nfc_phy_ops *phy_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) 			struct nci_dev **ndevp, int tx_headroom,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) 			int tx_tailroom, u8 clock_type, u32 clock_freq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) 			u8 *fw_vsc_cfg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) 	struct device *dev = &phy->i2c_dev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) 	struct fdp_nci_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) 	struct nci_dev *ndev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) 	u32 protocols;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) 	int r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) 	info = devm_kzalloc(dev, sizeof(struct fdp_nci_info), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) 	if (!info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) 	info->phy = phy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) 	info->phy_ops = phy_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) 	info->clock_type = clock_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) 	info->clock_freq = clock_freq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) 	info->fw_vsc_cfg = fw_vsc_cfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) 	init_waitqueue_head(&info->setup_wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) 	protocols = NFC_PROTO_JEWEL_MASK |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) 		    NFC_PROTO_MIFARE_MASK |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) 		    NFC_PROTO_FELICA_MASK |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) 		    NFC_PROTO_ISO14443_MASK |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) 		    NFC_PROTO_ISO14443_B_MASK |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) 		    NFC_PROTO_NFC_DEP_MASK |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) 		    NFC_PROTO_ISO15693_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) 	ndev = nci_allocate_device(&nci_ops, protocols, tx_headroom,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) 				   tx_tailroom);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) 	if (!ndev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) 		nfc_err(dev, "Cannot allocate nfc ndev\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) 	r = nci_register_device(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) 	if (r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) 		goto err_regdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) 	*ndevp = ndev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) 	info->ndev = ndev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) 	nci_set_drvdata(ndev, info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) err_regdev:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) 	nci_free_device(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) 	return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) EXPORT_SYMBOL(fdp_nci_probe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) void fdp_nci_remove(struct nci_dev *ndev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) 	struct fdp_nci_info *info = nci_get_drvdata(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) 	struct device *dev = &info->phy->i2c_dev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) 	dev_dbg(dev, "%s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) 	nci_unregister_device(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) 	nci_free_device(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) EXPORT_SYMBOL(fdp_nci_remove);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) MODULE_DESCRIPTION("NFC NCI driver for Intel Fields Peak NFC controller");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) MODULE_AUTHOR("Robert Dolca <robert.dolca@intel.com>");