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-only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Copyright (C) 2014  STMicroelectronics SAS. All rights reserved.
^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) #ifndef __LOCAL_ST21NFCA_H_
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #define __LOCAL_ST21NFCA_H_
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <net/nfc/hci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/workqueue.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #define HCI_MODE 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) /* framing in HCI mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #define ST21NFCA_SOF_EOF_LEN    2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) /* Almost every time value is 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #define ST21NFCA_HCI_LLC_LEN    1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) /* Size in worst case :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  * In normal case CRC len = 2 but byte stuffing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  * may appear in case one CRC byte = ST21NFCA_SOF_EOF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #define ST21NFCA_HCI_LLC_CRC    4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #define ST21NFCA_HCI_LLC_LEN_CRC        (ST21NFCA_SOF_EOF_LEN + \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 						ST21NFCA_HCI_LLC_LEN + \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 						ST21NFCA_HCI_LLC_CRC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #define ST21NFCA_HCI_LLC_MIN_SIZE       (1 + ST21NFCA_HCI_LLC_LEN_CRC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) /* Worst case when adding byte stuffing between each byte */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #define ST21NFCA_HCI_LLC_MAX_PAYLOAD    29
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #define ST21NFCA_HCI_LLC_MAX_SIZE       (ST21NFCA_HCI_LLC_LEN_CRC + 1 + \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 					ST21NFCA_HCI_LLC_MAX_PAYLOAD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) /* Reader RF commands */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #define ST21NFCA_WR_XCHG_DATA           0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) #define ST21NFCA_DEVICE_MGNT_GATE       0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) #define ST21NFCA_RF_READER_F_GATE       0x14
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) #define ST21NFCA_RF_CARD_F_GATE		0x24
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #define ST21NFCA_APDU_READER_GATE	0xf0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #define ST21NFCA_CONNECTIVITY_GATE	0x41
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47)  * ref ISO7816-3 chap 8.1. the initial character TS is followed by a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48)  * sequence of at most 32 characters.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) #define ST21NFCA_ESE_MAX_LENGTH		33
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) #define ST21NFCA_ESE_HOST_ID		0xc0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) #define DRIVER_DESC "HCI NFC driver for ST21NFCA"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) #define ST21NFCA_HCI_MODE		0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) #define ST21NFCA_NUM_DEVICES		256
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) #define ST21NFCA_VENDOR_OUI		0x0080E1 /* STMicroelectronics */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) #define ST21NFCA_FACTORY_MODE		2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) struct st21nfca_se_status {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	bool is_ese_present;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	bool is_uicc_present;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) enum st21nfca_state {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	ST21NFCA_ST_COLD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	ST21NFCA_ST_READY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72)  * enum nfc_vendor_cmds - supported nfc vendor commands
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74)  * @FACTORY_MODE: Allow to set the driver into a mode where no secure element
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75)  *	are activated. It does not consider any NFC_ATTR_VENDOR_DATA.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76)  * @HCI_CLEAR_ALL_PIPES: Allow to execute a HCI clear all pipes command.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77)  *	It does not consider any NFC_ATTR_VENDOR_DATA.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78)  * @HCI_DM_PUT_DATA: Allow to configure specific CLF registry as for example
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79)  *	RF trimmings or low level drivers configurations (I2C, SPI, SWP).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80)  * @HCI_DM_UPDATE_AID: Allow to configure an AID routing into the CLF routing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81)  *	table following RF technology, CLF mode or protocol.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82)  * @HCI_DM_GET_INFO: Allow to retrieve CLF information.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83)  * @HCI_DM_GET_DATA: Allow to retrieve CLF configurable data such as low
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84)  *	level drivers configurations or RF trimmings.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85)  * @HCI_DM_LOAD: Allow to load a firmware into the CLF. A complete
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86)  *	packet can be more than 8KB.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87)  * @HCI_DM_RESET: Allow to run a CLF reset in order to "commit" CLF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88)  *	configuration changes without CLF power off.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89)  * @HCI_GET_PARAM: Allow to retrieve an HCI CLF parameter (for example the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90)  *	white list).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91)  * @HCI_DM_FIELD_GENERATOR: Allow to generate different kind of RF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92)  *	technology. When using this command to anti-collision is done.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93)  * @HCI_LOOPBACK: Allow to echo a command and test the Dh to CLF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94)  *	connectivity.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) enum nfc_vendor_cmds {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	FACTORY_MODE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	HCI_CLEAR_ALL_PIPES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	HCI_DM_PUT_DATA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	HCI_DM_UPDATE_AID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	HCI_DM_GET_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	HCI_DM_GET_DATA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	HCI_DM_LOAD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	HCI_DM_RESET,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	HCI_GET_PARAM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	HCI_DM_FIELD_GENERATOR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	HCI_LOOPBACK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) struct st21nfca_vendor_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	struct completion req_completion;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	struct sk_buff *rx_skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) struct st21nfca_dep_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	struct sk_buff *tx_pending;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	struct work_struct tx_work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	u8 curr_nfc_dep_pni;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	u32 idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	u8 to;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	u8 did;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	u8 bsi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	u8 bri;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	u8 lri;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) struct st21nfca_se_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	u8 atr[ST21NFCA_ESE_MAX_LENGTH];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	struct completion req_completion;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	struct timer_list bwi_timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	int wt_timeout; /* in msecs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	bool bwi_active;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	struct timer_list se_active_timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	bool se_active;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	int expected_pipes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	int count_pipes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	bool xch_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	se_io_cb_t cb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	void *cb_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) struct st21nfca_hci_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	struct nfc_phy_ops *phy_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	void *phy_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	struct nfc_hci_dev *hdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	struct st21nfca_se_status *se_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	enum st21nfca_state state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	struct mutex info_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	int async_cb_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	data_exchange_cb_t async_cb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	void *async_cb_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	struct st21nfca_dep_info dep_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	struct st21nfca_se_info se_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	struct st21nfca_vendor_info vendor_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) int st21nfca_hci_probe(void *phy_id, struct nfc_phy_ops *phy_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		       char *llc_name, int phy_headroom, int phy_tailroom,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 		       int phy_payload, struct nfc_hci_dev **hdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		       struct st21nfca_se_status *se_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) void st21nfca_hci_remove(struct nfc_hci_dev *hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) int st21nfca_dep_event_received(struct nfc_hci_dev *hdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 				u8 event, struct sk_buff *skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) int st21nfca_tm_send_dep_res(struct nfc_hci_dev *hdev, struct sk_buff *skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) int st21nfca_im_send_atr_req(struct nfc_hci_dev *hdev, u8 *gb, size_t gb_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) int st21nfca_im_send_dep_req(struct nfc_hci_dev *hdev, struct sk_buff *skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) void st21nfca_dep_init(struct nfc_hci_dev *hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) void st21nfca_dep_deinit(struct nfc_hci_dev *hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) int st21nfca_connectivity_event_received(struct nfc_hci_dev *hdev, u8 host,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 					u8 event, struct sk_buff *skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) int st21nfca_apdu_reader_event_received(struct nfc_hci_dev *hdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 					u8 event, struct sk_buff *skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) int st21nfca_hci_discover_se(struct nfc_hci_dev *hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) int st21nfca_hci_enable_se(struct nfc_hci_dev *hdev, u32 se_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) int st21nfca_hci_disable_se(struct nfc_hci_dev *hdev, u32 se_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) int st21nfca_hci_se_io(struct nfc_hci_dev *hdev, u32 se_idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		u8 *apdu, size_t apdu_length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		se_io_cb_t cb, void *cb_context);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) void st21nfca_se_init(struct nfc_hci_dev *hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) void st21nfca_se_deinit(struct nfc_hci_dev *hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) int st21nfca_hci_loopback_event_received(struct nfc_hci_dev *ndev, u8 event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 					 struct sk_buff *skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) int st21nfca_vendor_cmds_init(struct nfc_hci_dev *ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) #endif /* __LOCAL_ST21NFCA_H_ */