xref: /openbmc/linux/drivers/nfc/st-nci/st-nci.h (revision 46fe7771)
146fe7771SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
2ed06aeefSChristophe Ricard /*
3ed06aeefSChristophe Ricard  * NCI based Driver for STMicroelectronics NFC Chip
4ed06aeefSChristophe Ricard  *
5ed06aeefSChristophe Ricard  * Copyright (C) 2014  STMicroelectronics SAS. All rights reserved.
6ed06aeefSChristophe Ricard  */
7ed06aeefSChristophe Ricard 
8ed06aeefSChristophe Ricard #ifndef __LOCAL_ST_NCI_H_
9ed06aeefSChristophe Ricard #define __LOCAL_ST_NCI_H_
10ed06aeefSChristophe Ricard 
11ed06aeefSChristophe Ricard #include "ndlc.h"
12ed06aeefSChristophe Ricard 
13ed06aeefSChristophe Ricard /* Define private flags: */
14ed06aeefSChristophe Ricard #define ST_NCI_RUNNING			1
15ed06aeefSChristophe Ricard 
16ed06aeefSChristophe Ricard #define ST_NCI_CORE_PROP                0x01
17ed06aeefSChristophe Ricard #define ST_NCI_SET_NFC_MODE             0x02
18ed06aeefSChristophe Ricard 
19f5876627SChristophe Ricard /*
20f5876627SChristophe Ricard  * ref ISO7816-3 chap 8.1. the initial character TS is followed by a
21f5876627SChristophe Ricard  * sequence of at most 32 characters.
22f5876627SChristophe Ricard  */
23f5876627SChristophe Ricard #define ST_NCI_ESE_MAX_LENGTH  33
24f5876627SChristophe Ricard 
25b1fa4dc4SChristophe Ricard #define ST_NCI_DEVICE_MGNT_GATE		0x01
26b1fa4dc4SChristophe Ricard 
27b1fa4dc4SChristophe Ricard #define ST_NCI_VENDOR_OUI 0x0080E1 /* STMicroelectronics */
28b1fa4dc4SChristophe Ricard #define ST_NCI_FACTORY_MODE 2
29b1fa4dc4SChristophe Ricard 
30ed06aeefSChristophe Ricard struct nci_mode_set_cmd {
31ed06aeefSChristophe Ricard 	u8 cmd_type;
32ed06aeefSChristophe Ricard 	u8 mode;
33ed06aeefSChristophe Ricard } __packed;
34ed06aeefSChristophe Ricard 
35ed06aeefSChristophe Ricard struct nci_mode_set_rsp {
36ed06aeefSChristophe Ricard 	u8 status;
37ed06aeefSChristophe Ricard } __packed;
38ed06aeefSChristophe Ricard 
393648dc6dSChristophe Ricard struct st_nci_se_status {
403648dc6dSChristophe Ricard 	bool is_ese_present;
413648dc6dSChristophe Ricard 	bool is_uicc_present;
423648dc6dSChristophe Ricard };
433648dc6dSChristophe Ricard 
44f5876627SChristophe Ricard struct st_nci_se_info {
453648dc6dSChristophe Ricard 	struct st_nci_se_status *se_status;
46f5876627SChristophe Ricard 	u8 atr[ST_NCI_ESE_MAX_LENGTH];
47f5876627SChristophe Ricard 	struct completion req_completion;
48f5876627SChristophe Ricard 
49f5876627SChristophe Ricard 	struct timer_list bwi_timer;
50f5876627SChristophe Ricard 	int wt_timeout; /* in msecs */
51f5876627SChristophe Ricard 	bool bwi_active;
52f5876627SChristophe Ricard 
53f5876627SChristophe Ricard 	struct timer_list se_active_timer;
54f5876627SChristophe Ricard 	bool se_active;
55f5876627SChristophe Ricard 
56f5876627SChristophe Ricard 	bool xch_error;
57f5876627SChristophe Ricard 
58f5876627SChristophe Ricard 	se_io_cb_t cb;
59f5876627SChristophe Ricard 	void *cb_context;
60f5876627SChristophe Ricard };
61f5876627SChristophe Ricard 
62b1fa4dc4SChristophe Ricard /**
63b1fa4dc4SChristophe Ricard  * enum nfc_vendor_cmds - supported nfc vendor commands
64b1fa4dc4SChristophe Ricard  *
65b1fa4dc4SChristophe Ricard  * @FACTORY_MODE: Allow to set the driver into a mode where no secure element
66b1fa4dc4SChristophe Ricard  *	are activated. It does not consider any NFC_ATTR_VENDOR_DATA.
67b1fa4dc4SChristophe Ricard  * @HCI_CLEAR_ALL_PIPES: Allow to execute a HCI clear all pipes command.
68b1fa4dc4SChristophe Ricard  *	It does not consider any NFC_ATTR_VENDOR_DATA.
69b1fa4dc4SChristophe Ricard  * @HCI_DM_PUT_DATA: Allow to configure specific CLF registry as for example
70b1fa4dc4SChristophe Ricard  *	RF trimmings or low level drivers configurations (I2C, SPI, SWP).
71b1fa4dc4SChristophe Ricard  * @HCI_DM_UPDATE_AID: Allow to configure an AID routing into the CLF routing
72b1fa4dc4SChristophe Ricard  *	table following RF technology, CLF mode or protocol.
73b1fa4dc4SChristophe Ricard  * @HCI_DM_GET_INFO: Allow to retrieve CLF information.
74b1fa4dc4SChristophe Ricard  * @HCI_DM_GET_DATA: Allow to retrieve CLF configurable data such as low
75b1fa4dc4SChristophe Ricard  *	level drivers configurations or RF trimmings.
76b1fa4dc4SChristophe Ricard  * @HCI_DM_DIRECT_LOAD: Allow to load a firmware into the CLF. A complete
77b1fa4dc4SChristophe Ricard  *	packet can be more than 8KB.
78b1fa4dc4SChristophe Ricard  * @HCI_DM_RESET: Allow to run a CLF reset in order to "commit" CLF
79b1fa4dc4SChristophe Ricard  *	configuration changes without CLF power off.
80b1fa4dc4SChristophe Ricard  * @HCI_GET_PARAM: Allow to retrieve an HCI CLF parameter (for example the
81b1fa4dc4SChristophe Ricard  *	white list).
82b1fa4dc4SChristophe Ricard  * @HCI_DM_FIELD_GENERATOR: Allow to generate different kind of RF
83b1fa4dc4SChristophe Ricard  *	technology. When using this command to anti-collision is done.
843aacd7feSChristophe Ricard  * @LOOPBACK: Allow to echo a command and test the Dh to CLF connectivity.
85b1fa4dc4SChristophe Ricard  * @HCI_DM_VDC_MEASUREMENT_VALUE: Allow to measure the field applied on the
86b1fa4dc4SChristophe Ricard  *	CLF antenna. A value between 0 and 0x0f is returned. 0 is maximum.
87b1fa4dc4SChristophe Ricard  * @HCI_DM_FWUPD_START: Allow to put CLF into firmware update mode. It is a
88b1fa4dc4SChristophe Ricard  *	specific CLF command as there is no GPIO for this.
89b1fa4dc4SChristophe Ricard  * @HCI_DM_FWUPD_END:  Allow to complete firmware update.
90b1fa4dc4SChristophe Ricard  * @HCI_DM_VDC_VALUE_COMPARISON: Allow to compare the field applied on the
91b1fa4dc4SChristophe Ricard  *	CLF antenna to a reference value.
92b1fa4dc4SChristophe Ricard  * @MANUFACTURER_SPECIFIC: Allow to retrieve manufacturer specific data
93b1fa4dc4SChristophe Ricard  *	received during a NCI_CORE_INIT_CMD.
94b1fa4dc4SChristophe Ricard  */
95b1fa4dc4SChristophe Ricard enum nfc_vendor_cmds {
96b1fa4dc4SChristophe Ricard 	FACTORY_MODE,
97b1fa4dc4SChristophe Ricard 	HCI_CLEAR_ALL_PIPES,
98b1fa4dc4SChristophe Ricard 	HCI_DM_PUT_DATA,
99b1fa4dc4SChristophe Ricard 	HCI_DM_UPDATE_AID,
100b1fa4dc4SChristophe Ricard 	HCI_DM_GET_INFO,
101b1fa4dc4SChristophe Ricard 	HCI_DM_GET_DATA,
102b1fa4dc4SChristophe Ricard 	HCI_DM_DIRECT_LOAD,
103b1fa4dc4SChristophe Ricard 	HCI_DM_RESET,
104b1fa4dc4SChristophe Ricard 	HCI_GET_PARAM,
105b1fa4dc4SChristophe Ricard 	HCI_DM_FIELD_GENERATOR,
1063aacd7feSChristophe Ricard 	LOOPBACK,
107b1fa4dc4SChristophe Ricard 	HCI_DM_FWUPD_START,
108b1fa4dc4SChristophe Ricard 	HCI_DM_FWUPD_END,
109b1fa4dc4SChristophe Ricard 	HCI_DM_VDC_MEASUREMENT_VALUE,
110b1fa4dc4SChristophe Ricard 	HCI_DM_VDC_VALUE_COMPARISON,
111b1fa4dc4SChristophe Ricard 	MANUFACTURER_SPECIFIC,
112b1fa4dc4SChristophe Ricard };
113b1fa4dc4SChristophe Ricard 
114ed06aeefSChristophe Ricard struct st_nci_info {
115ed06aeefSChristophe Ricard 	struct llt_ndlc *ndlc;
116ed06aeefSChristophe Ricard 	unsigned long flags;
1173648dc6dSChristophe Ricard 
118ed06aeefSChristophe Ricard 	struct st_nci_se_info se_info;
119ed06aeefSChristophe Ricard };
120ed06aeefSChristophe Ricard 
121ed06aeefSChristophe Ricard void st_nci_remove(struct nci_dev *ndev);
122ed06aeefSChristophe Ricard int st_nci_probe(struct llt_ndlc *ndlc, int phy_headroom,
1233648dc6dSChristophe Ricard 		 int phy_tailroom, struct st_nci_se_status *se_status);
124ed06aeefSChristophe Ricard 
1253648dc6dSChristophe Ricard int st_nci_se_init(struct nci_dev *ndev, struct st_nci_se_status *se_status);
126f5876627SChristophe Ricard void st_nci_se_deinit(struct nci_dev *ndev);
127f5876627SChristophe Ricard 
128f5876627SChristophe Ricard int st_nci_discover_se(struct nci_dev *ndev);
129f5876627SChristophe Ricard int st_nci_enable_se(struct nci_dev *ndev, u32 se_idx);
130f5876627SChristophe Ricard int st_nci_disable_se(struct nci_dev *ndev, u32 se_idx);
131f5876627SChristophe Ricard int st_nci_se_io(struct nci_dev *ndev, u32 se_idx,
132f5876627SChristophe Ricard 				u8 *apdu, size_t apdu_length,
133f5876627SChristophe Ricard 				se_io_cb_t cb, void *cb_context);
134f5876627SChristophe Ricard int st_nci_hci_load_session(struct nci_dev *ndev);
135f5876627SChristophe Ricard void st_nci_hci_event_received(struct nci_dev *ndev, u8 pipe,
136f5876627SChristophe Ricard 					u8 event, struct sk_buff *skb);
137f5876627SChristophe Ricard void st_nci_hci_cmd_received(struct nci_dev *ndev, u8 pipe, u8 cmd,
138f5876627SChristophe Ricard 						struct sk_buff *skb);
139f5876627SChristophe Ricard 
140b1fa4dc4SChristophe Ricard int st_nci_vendor_cmds_init(struct nci_dev *ndev);
141b1fa4dc4SChristophe Ricard 
142ed06aeefSChristophe Ricard #endif /* __LOCAL_ST_NCI_H_ */
143