blob: b2dd49c3c982fc33539f3bffd36838a71602170b [file] [log] [blame]
Shimrit Malichidbf43d72013-03-16 03:32:27 +02001/* Copyright (c) 2011-2013, The Linux Foundation. All rights reserved.
Ofir Cohenc7827e42011-12-13 20:10:01 +02002 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 */
12
13#ifndef _USB_BAM_H_
14#define _USB_BAM_H_
Shimrit Malichi255b5342012-08-02 21:01:43 +030015#include "sps.h"
Ofir Cohence5e3f22012-11-16 15:47:40 +020016#include <mach/ipa.h>
Shimrit Malichidbf43d72013-03-16 03:32:27 +020017#include <linux/usb/msm_hsusb.h>
Ofir Cohenc7827e42011-12-13 20:10:01 +020018
Shimrit Malichidbf43d72013-03-16 03:32:27 +020019enum usb_bam {
20 SSUSB_BAM = 0,
21 HSUSB_BAM,
22 HSIC_BAM,
23 MAX_BAMS,
24};
25
26enum peer_bam {
27 A2_P_BAM = 0,
28 QDSS_P_BAM,
29 IPA_P_BAM,
30 MAX_PEER_BAMS,
31};
32
Amit Blaye5bb35e2012-05-08 20:38:20 +030033enum usb_bam_pipe_dir {
34 USB_TO_PEER_PERIPHERAL,
35 PEER_PERIPHERAL_TO_USB,
36};
37
Shimrit Malichidbf43d72013-03-16 03:32:27 +020038enum usb_pipe_mem_type {
39 SPS_PIPE_MEM = 0, /* Default, SPS dedicated pipe memory */
40 USB_PRIVATE_MEM, /* USB's private memory */
41 SYSTEM_MEM, /* System RAM, requires allocation */
Vamsi Krishnafd09ddd2013-03-27 15:39:49 -070042 OCI_MEM, /* Shared memory among peripherals */
Shimrit Malichidbf43d72013-03-16 03:32:27 +020043};
44
Ido Shayevitz1ef192f2013-04-25 21:14:34 +030045enum usb_bam_event_type {
46 USB_BAM_EVENT_WAKEUP_PIPE = 0, /* Wake a pipe */
47 USB_BAM_EVENT_WAKEUP, /* Wake a bam (first pipe waked) */
48 USB_BAM_EVENT_INACTIVITY, /* Inactivity on all pipes */
49};
50
Ofir Cohence5e3f22012-11-16 15:47:40 +020051struct usb_bam_connect_ipa_params {
Shimrit Malichidbf43d72013-03-16 03:32:27 +020052 u8 src_idx;
53 u8 dst_idx;
Ofir Cohence5e3f22012-11-16 15:47:40 +020054 u32 *src_pipe;
55 u32 *dst_pipe;
56 enum usb_bam_pipe_dir dir;
57 /* client handle assigned by IPA to client */
58 u32 prod_clnt_hdl;
59 u32 cons_clnt_hdl;
60 /* params assigned by the CD */
61 enum ipa_client_type client;
62 struct ipa_ep_cfg ipa_ep_cfg;
63 void *priv;
64 void (*notify)(void *priv, enum ipa_dp_evt_type evt,
65 unsigned long data);
Ido Shayevitz1ef192f2013-04-25 21:14:34 +030066 int (*activity_notify)(void *priv);
67 int (*inactivity_notify)(void *priv);
Ofir Cohence5e3f22012-11-16 15:47:40 +020068};
69
Shimrit Malichidbf43d72013-03-16 03:32:27 +020070/**
71* struct usb_bam_event_info: suspend/resume event information.
Ido Shayevitz1ef192f2013-04-25 21:14:34 +030072* @type: usb bam event type.
Shimrit Malichidbf43d72013-03-16 03:32:27 +020073* @event: holds event data.
74* @callback: suspend/resume callback.
75* @param: port num (for suspend) or NULL (for resume).
76* @event_w: holds work queue parameters.
77*/
78struct usb_bam_event_info {
Ido Shayevitz1ef192f2013-04-25 21:14:34 +030079 enum usb_bam_event_type type;
Shimrit Malichidbf43d72013-03-16 03:32:27 +020080 struct sps_register_event event;
81 int (*callback)(void *);
82 void *param;
83 struct work_struct event_w;
84};
85
86/**
87* struct usb_bam_pipe_connect: pipe connection information
88* between USB/HSIC BAM and another BAM. USB/HSIC BAM can be
89* either src BAM or dst BAM
90* @name: pipe description.
91* @mem_type: type of memory used for BAM FIFOs
92* @src_phy_addr: src bam physical address.
93* @src_pipe_index: src bam pipe index.
94* @dst_phy_addr: dst bam physical address.
95* @dst_pipe_index: dst bam pipe index.
96* @data_fifo_base_offset: data fifo offset.
97* @data_fifo_size: data fifo size.
98* @desc_fifo_base_offset: descriptor fifo offset.
99* @desc_fifo_size: descriptor fifo size.
100* @data_mem_buf: data fifo buffer.
101* @desc_mem_buf: descriptor fifo buffer.
Ido Shayevitz1ef192f2013-04-25 21:14:34 +0300102* @event: event for wakeup.
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200103* @enabled: true if pipe is enabled.
Lena Salman05b544f2013-05-13 15:49:10 +0300104* @ipa_clnt_hdl : pipe handle to ipa api.
Ido Shayevitz1ef192f2013-04-25 21:14:34 +0300105* @priv: private data to return upon activity_notify
106* or inactivity_notify callbacks.
107* @activity_notify: callback to invoke on activity on one of the in pipes.
108* @inactivity_notify: callback to invoke on inactivity on all pipes.
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200109*/
110struct usb_bam_pipe_connect {
111 const char *name;
112 u32 pipe_num;
113 enum usb_pipe_mem_type mem_type;
114 enum usb_bam_pipe_dir dir;
115 enum usb_bam bam_type;
116 enum peer_bam peer_bam;
117 u32 src_phy_addr;
118 u32 src_pipe_index;
119 u32 dst_phy_addr;
120 u32 dst_pipe_index;
121 u32 data_fifo_base_offset;
122 u32 data_fifo_size;
123 u32 desc_fifo_base_offset;
124 u32 desc_fifo_size;
125 struct sps_mem_buffer data_mem_buf;
126 struct sps_mem_buffer desc_mem_buf;
Ido Shayevitz1ef192f2013-04-25 21:14:34 +0300127 struct usb_bam_event_info event;
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200128 bool enabled;
Ido Shayevitzaa165c52013-05-12 16:01:28 +0200129 bool suspended;
Lena Salman05b544f2013-05-13 15:49:10 +0300130 int ipa_clnt_hdl;
Ido Shayevitz1ef192f2013-04-25 21:14:34 +0300131 void *priv;
132 int (*activity_notify)(void *priv);
133 int (*inactivity_notify)(void *priv);
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200134};
135
136/**
137 * struct msm_usb_bam_platform_data: pipe connection information
138 * between USB/HSIC BAM and another BAM. USB/HSIC BAM can be
139 * either src BAM or dst BAM
140 * @connections: holds all pipe connections data.
141 * @usb_bam_num_pipes: max number of pipes to use.
142 * @active_conn_num: number of active pipe connections.
Vamsi Krishnafd09ddd2013-03-27 15:39:49 -0700143 * @usb_bam_fifo_baseaddr: base address for bam pipe's data and descriptor
144 * fifos. This can be on chip memory (ocimem) or usb
145 * private memory.
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200146 * @ignore_core_reset_ack: BAM can ignore ACK from USB core during PIPE RESET
147 * @disable_clk_gating: Disable clock gating
148 */
149struct msm_usb_bam_platform_data {
150 struct usb_bam_pipe_connect *connections;
151 u8 max_connections;
152 int usb_bam_num_pipes;
Vamsi Krishnafd09ddd2013-03-27 15:39:49 -0700153 phys_addr_t usb_bam_fifo_baseaddr;
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200154 bool ignore_core_reset_ack;
155 bool reset_on_connect[MAX_BAMS];
156 bool disable_clk_gating;
157};
158
Amit Blaye5bb35e2012-05-08 20:38:20 +0300159#ifdef CONFIG_USB_BAM
160/**
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200161 * Connect USB-to-Peripheral SPS connection.
Ofir Cohenc7827e42011-12-13 20:10:01 +0200162 *
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200163 * This function returns the allocated pipe number.
Ofir Cohenc7827e42011-12-13 20:10:01 +0200164 *
165 * @idx - Connection index.
166 *
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200167 * @bam_pipe_idx - allocated pipe index.
Ofir Cohenc7827e42011-12-13 20:10:01 +0200168 *
169 * @return 0 on success, negative value on error
170 *
171 */
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200172int usb_bam_connect(u8 idx, u32 *bam_pipe_idx);
Amit Blaye5bb35e2012-05-08 20:38:20 +0300173
174/**
Ofir Cohence5e3f22012-11-16 15:47:40 +0200175 * Connect USB-to-IPA SPS connection.
176 *
Lena Salmanabde35d2013-04-25 15:29:43 +0300177 * This function returns the allocated pipes number and clnt
178 * handles. Assumes that the user first connects producer pipes
179 * and only after that consumer pipes, since that's the correct
180 * sequence for the handshake with the IPA.
Ofir Cohence5e3f22012-11-16 15:47:40 +0200181 *
182 * @ipa_params - in/out parameters
183 *
184 * @return 0 on success, negative value on error
185 *
186 */
187int usb_bam_connect_ipa(struct usb_bam_connect_ipa_params *ipa_params);
188
189/**
190 * Disconnect USB-to-IPA SPS connection.
191 *
Ofir Cohence5e3f22012-11-16 15:47:40 +0200192 * @ipa_params - in/out parameters
193 *
194 * @return 0 on success, negative value on error
195 *
196 */
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200197int usb_bam_disconnect_ipa(
Ofir Cohence5e3f22012-11-16 15:47:40 +0200198 struct usb_bam_connect_ipa_params *ipa_params);
199
200/**
Amit Blaye5bb35e2012-05-08 20:38:20 +0300201 * Register a wakeup callback from peer BAM.
202 *
203 * @idx - Connection index.
204 *
205 * @callback - the callback function
206 *
207 * @return 0 on success, negative value on error
208 *
209 */
210int usb_bam_register_wake_cb(u8 idx,
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200211 int (*callback)(void *), void *param);
Shimrit Malichi255b5342012-08-02 21:01:43 +0300212
213/**
Amit Blay0c929f42012-12-26 12:02:29 +0200214 * Register a callback for peer BAM reset.
215 *
Amit Blay0c929f42012-12-26 12:02:29 +0200216 * @callback - the callback function that will be called in USB
217 * driver upon a peer bam reset
218 *
219 * @param - context that the caller can supply
220 *
221 * @return 0 on success, negative value on error
222 *
223 */
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200224int usb_bam_register_peer_reset_cb(int (*callback)(void *), void *param);
Amit Blay0c929f42012-12-26 12:02:29 +0200225
226/**
Lena Salman05b544f2013-05-13 15:49:10 +0300227 * Register callbacks for start/stop of transfers.
228 *
229 * @start - the callback function that will be called in USB
230 * driver to start transfers
231 * @stop - the callback function that will be called in USB
232 * driver to stop transfers
233 *
234 * @param - context that the caller can supply
235 *
236 * @return 0 on success, negative value on error
237 *
238 */
239int usb_bam_register_start_stop_cbs(
240 void (*start)(void *, enum usb_bam_pipe_dir),
241 void (*stop)(void *, enum usb_bam_pipe_dir),
242 void *param);
243
244/**
245 * Start usb suspend sequence
246 *
247 * @ipa_params - in/out parameters
248 *
249 */
250void usb_bam_suspend(struct usb_bam_connect_ipa_params *ipa_params);
251
252/**
253 * Start usb resume sequence
254 *
255 * @ipa_params - in/out parameters
256 *
257 */
258void usb_bam_resume(struct usb_bam_connect_ipa_params *ipa_params);
259/**
Shimrit Malichi255b5342012-08-02 21:01:43 +0300260 * Disconnect USB-to-Periperal SPS connection.
261 *
262 * @idx - Connection index.
263 *
264 * @return 0 on success, negative value on error
265 */
266int usb_bam_disconnect_pipe(u8 idx);
267
268/**
269 * Returns usb bam connection parameters.
270 *
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200271 * @idx - Connection index.
Shimrit Malichi255b5342012-08-02 21:01:43 +0300272 *
273 * @usb_bam_handle - Usb bam handle.
274 *
275 * @usb_bam_pipe_idx - Usb bam pipe index.
276 *
277 * @peer_pipe_idx - Peer pipe index.
278 *
279 * @desc_fifo - Descriptor fifo parameters.
280 *
281 * @data_fifo - Data fifo parameters.
282 *
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200283 * @return pipe index on success, negative value on error.
Shimrit Malichi255b5342012-08-02 21:01:43 +0300284 */
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200285int get_bam2bam_connection_info(u8 idx,
Shimrit Malichi255b5342012-08-02 21:01:43 +0300286 u32 *usb_bam_handle, u32 *usb_bam_pipe_idx, u32 *peer_pipe_idx,
287 struct sps_mem_buffer *desc_fifo, struct sps_mem_buffer *data_fifo);
288
Amit Blay0c929f42012-12-26 12:02:29 +0200289/**
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200290 * Resets the USB BAM that has A2 pipes
Amit Blay0c929f42012-12-26 12:02:29 +0200291 *
292 */
Bar Weiner189bb3c2013-06-09 14:24:56 +0300293int usb_bam_a2_reset(bool to_reconnect);
Amit Blay0c929f42012-12-26 12:02:29 +0200294
295/**
296 * Indicates if the client of the USB BAM is ready to start
297 * sending/receiving transfers.
298 *
299 * @ready - TRUE to enable, FALSE to disable.
300 *
301 */
302int usb_bam_client_ready(bool ready);
Bar Weiner189bb3c2013-06-09 14:24:56 +0300303
304/**
305* Returns upon reset completion if reset is in progress
306* immediately otherwise.
307*
308*/
309void usb_bam_reset_complete(void);
310
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200311/**
312* Returns qdss index from the connections array.
313*
314* @num - The qdss pipe number.
315*
316* @return pipe index on success, negative value on error
317*/
318int usb_bam_get_qdss_idx(u8 num);
319
320/**
321* Saves qdss core number.
322*
323* @qdss_core - The qdss core name.
324*/
325void usb_bam_set_qdss_core(const char *qdss_core);
326
327/**
328* Indicates if the client of the USB BAM is ready to start
329* sending/receiving transfers.
330*
331* @name - Core name (ssusb/hsusb/hsic).
332*
333* @client - Usb pipe peer (a2, ipa, qdss...)
334*
335* @dir - In (from peer to usb) or out (from usb to peer)
336*
337* @num - Pipe number.
338*
339* @return 0 on success, negative value on error
340*/
341int usb_bam_get_connection_idx(const char *name, enum peer_bam client,
342 enum usb_bam_pipe_dir dir, u32 num);
Amit Blay0c929f42012-12-26 12:02:29 +0200343
Ofir Cohenc7827e42011-12-13 20:10:01 +0200344#else
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200345static inline int usb_bam_connect(u8 idx, u32 *bam_pipe_idx)
Amit Blaye5bb35e2012-05-08 20:38:20 +0300346{
347 return -ENODEV;
348}
349
Ofir Cohence5e3f22012-11-16 15:47:40 +0200350static inline int usb_bam_connect_ipa(
351 struct usb_bam_connect_ipa_params *ipa_params)
352{
353 return -ENODEV;
354}
355
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200356static inline int usb_bam_disconnect_ipa(
Ofir Cohence5e3f22012-11-16 15:47:40 +0200357 struct usb_bam_connect_ipa_params *ipa_params)
358{
359 return -ENODEV;
360}
361
Lena Salman05b544f2013-05-13 15:49:10 +0300362static inline void usb_bam_wait_for_cons_granted(
363 struct usb_bam_connect_ipa_params *ipa_params)
364{
365 return;
366}
367
Amit Blaye5bb35e2012-05-08 20:38:20 +0300368static inline int usb_bam_register_wake_cb(u8 idx,
369 int (*callback)(void *), void* param)
Ofir Cohenc7827e42011-12-13 20:10:01 +0200370{
371 return -ENODEV;
372}
Shimrit Malichi255b5342012-08-02 21:01:43 +0300373
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200374static inline int usb_bam_register_peer_reset_cb(
375 int (*callback)(void *), void *param)
Amit Blay0c929f42012-12-26 12:02:29 +0200376{
377 return -ENODEV;
378}
379
Lena Salman05b544f2013-05-13 15:49:10 +0300380static inline int usb_bam_register_start_stop_cbs(
381 void (*start)(void *, enum usb_bam_pipe_dir),
382 void (*stop)(void *, enum usb_bam_pipe_dir),
383 void *param)
384{
385 return -ENODEV;
386}
387
388static inline void usb_bam_suspend(
389 struct usb_bam_connect_ipa_params *ipa_params){}
390
391static inline void usb_bam_resume(
392 struct usb_bam_connect_ipa_params *ipa_params) {}
393
Shimrit Malichi255b5342012-08-02 21:01:43 +0300394static inline int usb_bam_disconnect_pipe(u8 idx)
395{
396 return -ENODEV;
397}
398
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200399static inline int get_bam2bam_connection_info(u8 idx,
400 u32 *usb_bam_handle, u32 *usb_bam_pipe_idx, u32 *peer_pipe_idx,
Shimrit Malichi255b5342012-08-02 21:01:43 +0300401 struct sps_mem_buffer *desc_fifo, struct sps_mem_buffer *data_fifo)
402{
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200403 return -ENODEV;
Shimrit Malichi255b5342012-08-02 21:01:43 +0300404}
Amit Blay0c929f42012-12-26 12:02:29 +0200405
Bar Weiner189bb3c2013-06-09 14:24:56 +0300406static inline int usb_bam_a2_reset(bool to_reconnect)
Amit Blay0c929f42012-12-26 12:02:29 +0200407{
408 return -ENODEV;
409}
410
411static inline int usb_bam_client_ready(bool ready)
412{
413 return -ENODEV;
414}
415
Bar Weiner189bb3c2013-06-09 14:24:56 +0300416static inline void usb_bam_reset_complete(void)
417{
418 return;
419}
420
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200421static inline int usb_bam_get_qdss_idx(u8 num)
422{
423 return -ENODEV;
424}
425
426static inline void usb_bam_set_qdss_core(const char *qdss_core)
427{
428 return;
429}
430
431static inline int usb_bam_get_connection_idx(const char *name,
432 enum peer_bam client, enum usb_bam_pipe_dir dir, u32 num)
433{
434 return -ENODEV;
435}
Ofir Cohenc7827e42011-12-13 20:10:01 +0200436#endif
437#endif /* _USB_BAM_H_ */