1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
/* SPDX-License-Identifier: GPL-2.0-only */
/*
* Copyright (c) 2019-2020, The Linux Foundation. All rights reserved.
*/
#ifndef _NFC_I3C_DRV_H_
#define _NFC_I3C_DRV_H_
#include <linux/i3c/master.h>
#include <linux/i3c/device.h>
//to to kept same as dt
#define NFC_I3C_DRV_STR "qcom,sn-nci-i3c"
#define NFC_I3C_MANU_ID (0x011B)
#define NFC_I3C_PART_ID (0)
//Byte indicating I3C Read
#define NFC_I3C_READ 1
//Byte indicating I3C Write
#define NFC_I3C_WRITE 0
// Maximum no of IBI slot
#define NUM_NFC_IBI_SLOT 1
// Maximum IBI payload length
#define MAX_IBI_PAYLOAD_LEN 0
// CRC len to be read
#define FW_CRC_LEN 2
// FW DNLD HDR length
#define FW_HDR_LEN 2
// Time to wait before retrying I3C writes, in micro seconds
#define RETRY_WAIT_TIME_USEC (2000)
// Retry count for enable/disable IBI CCC
#define RETRY_COUNT_IBI (3)
// I3C WorkQueue name
#define NFC_I3C_WORKQUEUE "nfc_i3c_workq"
/* Time(in ms) to wait for NCI packet respones */
#define MAX_IBI_WAIT_TIME (2000)
struct nfc_dev;
/**
* struct nci_buf - NCI buffer used to store and retrieve read data from device.
* @read_offset: The offset pointing to data available to read in nci buf.
* @write_offset: The offset pointing to free buf available to write.
* @total_size: Size of nci buf.
* @kbuf: allocated nci buf.
*/
struct nci_buf {
unsigned int read_offset;
unsigned int write_offset;
size_t total_size;
char *kbuf;
};
/**
* struct i3c_dev Structure representing device and driver data.
* @i3c_device Structure to represent I3C device.
* @wq: NCI workqueue for handling IBI request.
* @work: Work added to workqueue to read data from IBI handler.
* @buf Driver buf store read data from device.Read call will
* fetch from this buffer.
* @nci_buf_mutex: mutex to protect NCI buf retrieve/store .
* @read_cplt: Completion to wait for read data to be available.
* @read_kbuf_len: Temp buf len to hold I3C data.
* @read_kbuf: Temp buf to hold I3C data.
* @read_hdr Header size for reads.
* @ibi_enabled: IBI enabled or not.
* @pm_state: PM state of NFC I3C device.
* @nfc_read_direct Do NFC read bypassing the read buffer.
* @is_probe_done Is NFC I3C probe completed.
*/
struct i3c_dev {
struct i3c_device *device;
struct workqueue_struct *wq;
struct work_struct work;
struct nci_buf buf;
struct mutex nci_buf_mutex;
struct completion read_cplt;
size_t read_kbuf_len;
char *read_kbuf;
unsigned char read_hdr;
bool ibi_enabled;
atomic_t pm_state;
int (*nfc_read_direct)(struct nfc_dev *dev,
char *buf, size_t count);
bool is_probe_done;
};
int nfc_i3c_dev_probe(struct i3c_device *device);
int nfc_i3c_dev_remove(struct i3c_device *device);
int nfc_i3c_dev_suspend(struct device *device);
int nfc_i3c_dev_resume(struct device *device);
#if IS_ENABLED(CONFIG_NFC_QTI_I3C)
int i3c_enable_ibi(struct nfc_dev *dev);
int i3c_disable_ibi(struct nfc_dev *dev);
int i3c_write(struct nfc_dev *dev, const char *buf, const size_t count,
int max_retry_cnt);
int i3c_read(struct nfc_dev *dev, char *buf, size_t count);
int i3c_nci_kbuf_retrieve(struct nfc_dev *dev, char *buf,
size_t count);
#else
static inline int i3c_enable_ibi(struct nfc_dev *dev)
{
return -ENXIO;
}
static inline int i3c_disable_ibi(struct nfc_dev *dev)
{
return -ENXIO;
}
static inline int i3c_write(struct nfc_dev *dev,
const char *buf, const size_t count, int max_retry_cnt)
{
return -ENXIO;
}
static inline int i3c_read(struct nfc_dev *dev,
char *buf, size_t count)
{
return -ENXIO;
}
static inline int i3c_nci_kbuf_retrieve(struct nfc_dev *dev,
char *buf, size_t count)
{
return -ENXIO;
}
#endif
#endif //_NFC_I3C_DRV_H_
|