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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
|
/* Copyright (c) 2011-2017, The Linux Foundation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 and
* only version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#ifndef _USB_BAM_H_
#define _USB_BAM_H_
#include <linux/msm-sps.h>
#include <linux/device.h>
#include <linux/errno.h>
#include <linux/types.h>
#define MAX_BAMS NUM_CTRL /* Bam per USB controllers */
/* Supported USB controllers*/
enum usb_ctrl {
USB_CTRL_UNUSED = 0,
NUM_CTRL,
};
enum peer_bam {
QDSS_P_BAM = 0,
MAX_PEER_BAMS,
};
enum usb_bam_pipe_dir {
USB_TO_PEER_PERIPHERAL,
PEER_PERIPHERAL_TO_USB,
};
enum usb_pipe_mem_type {
SPS_PIPE_MEM = 0, /* Default, SPS dedicated pipe memory */
SYSTEM_MEM, /* System RAM, requires allocation */
OCI_MEM, /* Shared memory among peripherals */
};
enum usb_bam_pipe_type {
USB_BAM_PIPE_BAM2BAM = 0, /* Connection is BAM2BAM (default) */
USB_BAM_PIPE_SYS2BAM, /* Connection is SYS2BAM or BAM2SYS
* depending on usb_bam_pipe_dir
*/
USB_BAM_MAX_PIPE_TYPES,
};
#if IS_ENABLED(CONFIG_USB_BAM)
/**
* Connect USB-to-Peripheral SPS connection.
*
* This function returns the allocated pipe number.
*
* @bam_type - USB BAM type - dwc3/CI/hsic
*
* @idx - Connection index.
*
* @bam_pipe_idx - allocated pipe index.
*
* @iova - IPA address of USB peer BAM (i.e. QDSS BAM)
*
* @return 0 on success, negative value on error
*
*/
int usb_bam_connect(enum usb_ctrl bam_type, int idx, u32 *bam_pipe_idx,
unsigned long iova);
/**
* Register a wakeup callback from peer BAM.
*
* @bam_type - USB BAM type - dwc3/CI/hsic
*
* @idx - Connection index.
*
* @callback - the callback function
*
* @return 0 on success, negative value on error
*/
int usb_bam_register_wake_cb(enum usb_ctrl bam_type, u8 idx,
int (*callback)(void *), void *param);
/**
* Register callbacks for start/stop of transfers.
*
* @bam_type - USB BAM type - dwc3/CI/hsic
*
* @idx - Connection index
*
* @start - the callback function that will be called in USB
* driver to start transfers
* @stop - the callback function that will be called in USB
* driver to stop transfers
*
* @param - context that the caller can supply
*
* @return 0 on success, negative value on error
*/
int usb_bam_register_start_stop_cbs(enum usb_ctrl bam_type,
u8 idx,
void (*start)(void *, enum usb_bam_pipe_dir),
void (*stop)(void *, enum usb_bam_pipe_dir),
void *param);
/**
* Disconnect USB-to-Periperal SPS connection.
*
* @bam_type - USB BAM type - dwc3/CI/hsic
*
* @idx - Connection index.
*
* @return 0 on success, negative value on error
*/
int usb_bam_disconnect_pipe(enum usb_ctrl bam_type, u8 idx);
/**
* Returns usb bam connection parameters.
*
* @bam_type - USB BAM type - dwc3/CI/hsic
*
* @idx - Connection index.
*
* @usb_bam_pipe_idx - Usb bam pipe index.
*
* @desc_fifo - Descriptor fifo parameters.
*
* @data_fifo - Data fifo parameters.
*
* @return pipe index on success, negative value on error.
*/
int get_bam2bam_connection_info(enum usb_ctrl bam_type, u8 idx,
u32 *usb_bam_pipe_idx, struct sps_mem_buffer *desc_fifo,
struct sps_mem_buffer *data_fifo, enum usb_pipe_mem_type *mem_type);
/**
* Returns usb bam connection parameters for qdss pipe.
* @usb_bam_handle - Usb bam handle.
* @usb_bam_pipe_idx - Usb bam pipe index.
* @peer_pipe_idx - Peer pipe index.
* @desc_fifo - Descriptor fifo parameters.
* @data_fifo - Data fifo parameters.
* @return pipe index on success, negative value on error.
*/
int get_qdss_bam_connection_info(
unsigned long *usb_bam_handle, u32 *usb_bam_pipe_idx,
u32 *peer_pipe_idx, struct sps_mem_buffer *desc_fifo,
struct sps_mem_buffer *data_fifo, enum usb_pipe_mem_type *mem_type);
/*
* Indicates if the client of the USB BAM is ready to start
* sending/receiving transfers.
*
* @bam_type - USB BAM type - dwc3/CI/hsic
*
* @client - Usb pipe peer (a2, ipa, qdss...)
*
* @dir - In (from peer to usb) or out (from usb to peer)
*
* @num - Pipe number.
*
* @return 0 on success, negative value on error
*/
int usb_bam_get_connection_idx(enum usb_ctrl bam_type, enum peer_bam client,
enum usb_bam_pipe_dir dir, u32 num);
/*
* return the usb controller bam type used for the supplied connection index
*
* @core_name - Core name (ssusb/hsusb/hsic).
*
* @return usb control bam type
*/
enum usb_ctrl usb_bam_get_bam_type(const char *core_name);
/*
* Indicates the type of connection the USB side of the connection is.
*
* @bam_type - USB BAM type - dwc3/CI/hsic
*
* @idx - Pipe number.
*
* @type - Type of connection
*
* @return 0 on success, negative value on error
*/
int usb_bam_get_pipe_type(enum usb_ctrl bam_type,
u8 idx, enum usb_bam_pipe_type *type);
/* Allocates memory for data fifo and descriptor fifos. */
int usb_bam_alloc_fifos(enum usb_ctrl cur_bam, u8 idx);
/* Frees memory for data fifo and descriptor fifos. */
int usb_bam_free_fifos(enum usb_ctrl cur_bam, u8 idx);
int get_qdss_bam_info(enum usb_ctrl cur_bam, u8 idx,
phys_addr_t *p_addr, u32 *bam_size);
#else
static inline int usb_bam_connect(enum usb_ctrl bam, u8 idx, u32 *bam_pipe_idx,
unsigned long iova)
{
return -ENODEV;
}
static inline int usb_bam_register_wake_cb(enum usb_ctrl bam_type, u8 idx,
int (*callback)(void *), void *param)
{
return -ENODEV;
}
static inline int usb_bam_register_start_stop_cbs(enum usb_ctrl bam, u8 idx,
void (*start)(void *, enum usb_bam_pipe_dir),
void (*stop)(void *, enum usb_bam_pipe_dir),
void *param)
{
return -ENODEV;
}
static inline int usb_bam_disconnect_pipe(enum usb_ctrl bam_type, u8 idx)
{
return -ENODEV;
}
static inline int get_bam2bam_connection_info(enum usb_ctrl bam_type, u8 idx,
u32 *usb_bam_pipe_idx, struct sps_mem_buffer *desc_fifo,
struct sps_mem_buffer *data_fifo, enum usb_pipe_mem_type *mem_type)
{
return -ENODEV;
}
static inline int get_qdss_bam_connection_info(
unsigned long *usb_bam_handle, u32 *usb_bam_pipe_idx,
u32 *peer_pipe_idx, struct sps_mem_buffer *desc_fifo,
struct sps_mem_buffer *data_fifo, enum usb_pipe_mem_type *mem_type)
{
return -ENODEV;
}
static inline int usb_bam_get_connection_idx(enum usb_ctrl bam_type,
enum peer_bam client, enum usb_bam_pipe_dir dir, u32 num)
{
return -ENODEV;
}
static inline enum usb_ctrl usb_bam_get_bam_type(const char *core_nam)
{
return -ENODEV;
}
static inline int usb_bam_get_pipe_type(enum usb_ctrl bam_type, u8 idx,
enum usb_bam_pipe_type *type)
{
return -ENODEV;
}
static inline int usb_bam_alloc_fifos(enum usb_ctrl cur_bam, u8 idx)
{
return false;
}
static inline int usb_bam_free_fifos(enum usb_ctrl cur_bam, u8 idx)
{
return false;
}
static inline int get_qdss_bam_info(enum usb_ctrl cur_bam, u8 idx,
phys_addr_t *p_addr, u32 *bam_size)
{
return false;
}
#endif
/* CONFIG_PM */
#ifdef CONFIG_PM
static inline int get_pm_runtime_counter(struct device *dev)
{
return atomic_read(&dev->power.usage_count);
}
#else
/* !CONFIG_PM */
static inline int get_pm_runtime_counter(struct device *dev)
{ return -EOPNOTSUPP; }
#endif
#endif /* _USB_BAM_H_ */
|