2 * NCI based driver for Samsung S3FWRN5 NFC chip
4 * Copyright (C) 2015 Samsung Electrnoics
5 * Robert Baldyga <r.baldyga@samsung.com>
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.
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.
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/>.
20 #include <linux/completion.h>
21 #include <linux/firmware.h>
26 static int s3fwrn5_nci_prop_rsp(struct nci_dev
*ndev
, struct sk_buff
*skb
)
28 __u8 status
= skb
->data
[0];
30 nci_req_complete(ndev
, status
);
34 static struct nci_driver_ops s3fwrn5_nci_prop_ops
[] = {
36 .opcode
= nci_opcode_pack(NCI_GID_PROPRIETARY
,
38 .rsp
= s3fwrn5_nci_prop_rsp
,
41 .opcode
= nci_opcode_pack(NCI_GID_PROPRIETARY
,
43 .rsp
= s3fwrn5_nci_prop_rsp
,
46 .opcode
= nci_opcode_pack(NCI_GID_PROPRIETARY
,
48 .rsp
= s3fwrn5_nci_prop_rsp
,
51 .opcode
= nci_opcode_pack(NCI_GID_PROPRIETARY
,
52 NCI_PROP_GET_RFREG_VER
),
53 .rsp
= s3fwrn5_nci_prop_rsp
,
56 .opcode
= nci_opcode_pack(NCI_GID_PROPRIETARY
,
57 NCI_PROP_SET_RFREG_VER
),
58 .rsp
= s3fwrn5_nci_prop_rsp
,
61 .opcode
= nci_opcode_pack(NCI_GID_PROPRIETARY
,
62 NCI_PROP_START_RFREG
),
63 .rsp
= s3fwrn5_nci_prop_rsp
,
66 .opcode
= nci_opcode_pack(NCI_GID_PROPRIETARY
,
68 .rsp
= s3fwrn5_nci_prop_rsp
,
71 .opcode
= nci_opcode_pack(NCI_GID_PROPRIETARY
,
73 .rsp
= s3fwrn5_nci_prop_rsp
,
76 .opcode
= nci_opcode_pack(NCI_GID_PROPRIETARY
,
78 .rsp
= s3fwrn5_nci_prop_rsp
,
82 void s3fwrn5_nci_get_prop_ops(struct nci_driver_ops
**ops
, size_t *n
)
84 *ops
= s3fwrn5_nci_prop_ops
;
85 *n
= ARRAY_SIZE(s3fwrn5_nci_prop_ops
);
88 #define S3FWRN5_RFREG_SECTION_SIZE 252
90 int s3fwrn5_nci_rf_configure(struct s3fwrn5_info
*info
, const char *fw_name
)
92 const struct firmware
*fw
;
93 struct nci_prop_fw_cfg_cmd fw_cfg
;
94 struct nci_prop_set_rfreg_cmd set_rfreg
;
95 struct nci_prop_stop_rfreg_cmd stop_rfreg
;
100 ret
= request_firmware(&fw
, fw_name
, &info
->ndev
->nfc_dev
->dev
);
104 /* Compute rfreg checksum */
107 for (i
= 0; i
< fw
->size
; i
+= 4)
108 checksum
+= *((u32
*)(fw
->data
+i
));
110 /* Set default clock configuration for external crystal */
112 fw_cfg
.clk_type
= 0x01;
113 fw_cfg
.clk_speed
= 0xff;
114 fw_cfg
.clk_req
= 0xff;
115 ret
= nci_prop_cmd(info
->ndev
, NCI_PROP_FW_CFG
,
116 sizeof(fw_cfg
), (__u8
*)&fw_cfg
);
120 /* Start rfreg configuration */
122 dev_info(&info
->ndev
->nfc_dev
->dev
,
123 "rfreg configuration update: %s\n", fw_name
);
125 ret
= nci_prop_cmd(info
->ndev
, NCI_PROP_START_RFREG
, 0, NULL
);
127 dev_err(&info
->ndev
->nfc_dev
->dev
,
128 "Unable to start rfreg update\n");
135 for (i
= 0; i
< fw
->size
; i
+= S3FWRN5_RFREG_SECTION_SIZE
) {
136 len
= (fw
->size
- i
< S3FWRN5_RFREG_SECTION_SIZE
) ?
137 (fw
->size
- i
) : S3FWRN5_RFREG_SECTION_SIZE
;
138 memcpy(set_rfreg
.data
, fw
->data
+i
, len
);
139 ret
= nci_prop_cmd(info
->ndev
, NCI_PROP_SET_RFREG
,
140 len
+1, (__u8
*)&set_rfreg
);
142 dev_err(&info
->ndev
->nfc_dev
->dev
,
143 "rfreg update error (code=%d)\n", ret
);
149 /* Finish rfreg configuration */
151 stop_rfreg
.checksum
= checksum
& 0xffff;
152 ret
= nci_prop_cmd(info
->ndev
, NCI_PROP_STOP_RFREG
,
153 sizeof(stop_rfreg
), (__u8
*)&stop_rfreg
);
155 dev_err(&info
->ndev
->nfc_dev
->dev
,
156 "Unable to stop rfreg update\n");
160 dev_info(&info
->ndev
->nfc_dev
->dev
,
161 "rfreg configuration update: success\n");
163 release_firmware(fw
);