blob: 5ecc63b06a74706e9fbf1a57887509f861983ec6 [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;
Lena Salman05b544f2013-05-13 15:49:10 +0300129 int ipa_clnt_hdl;
Ido Shayevitz1ef192f2013-04-25 21:14:34 +0300130 void *priv;
131 int (*activity_notify)(void *priv);
132 int (*inactivity_notify)(void *priv);
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200133};
134
135/**
136 * struct msm_usb_bam_platform_data: pipe connection information
137 * between USB/HSIC BAM and another BAM. USB/HSIC BAM can be
138 * either src BAM or dst BAM
139 * @connections: holds all pipe connections data.
140 * @usb_bam_num_pipes: max number of pipes to use.
141 * @active_conn_num: number of active pipe connections.
Vamsi Krishnafd09ddd2013-03-27 15:39:49 -0700142 * @usb_bam_fifo_baseaddr: base address for bam pipe's data and descriptor
143 * fifos. This can be on chip memory (ocimem) or usb
144 * private memory.
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200145 * @ignore_core_reset_ack: BAM can ignore ACK from USB core during PIPE RESET
146 * @disable_clk_gating: Disable clock gating
147 */
148struct msm_usb_bam_platform_data {
149 struct usb_bam_pipe_connect *connections;
150 u8 max_connections;
151 int usb_bam_num_pipes;
Vamsi Krishnafd09ddd2013-03-27 15:39:49 -0700152 phys_addr_t usb_bam_fifo_baseaddr;
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200153 bool ignore_core_reset_ack;
154 bool reset_on_connect[MAX_BAMS];
155 bool disable_clk_gating;
156};
157
Amit Blaye5bb35e2012-05-08 20:38:20 +0300158#ifdef CONFIG_USB_BAM
159/**
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200160 * Connect USB-to-Peripheral SPS connection.
Ofir Cohenc7827e42011-12-13 20:10:01 +0200161 *
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200162 * This function returns the allocated pipe number.
Ofir Cohenc7827e42011-12-13 20:10:01 +0200163 *
164 * @idx - Connection index.
165 *
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200166 * @bam_pipe_idx - allocated pipe index.
Ofir Cohenc7827e42011-12-13 20:10:01 +0200167 *
168 * @return 0 on success, negative value on error
169 *
170 */
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200171int usb_bam_connect(u8 idx, u32 *bam_pipe_idx);
Amit Blaye5bb35e2012-05-08 20:38:20 +0300172
173/**
Ofir Cohence5e3f22012-11-16 15:47:40 +0200174 * Connect USB-to-IPA SPS connection.
175 *
Lena Salmanabde35d2013-04-25 15:29:43 +0300176 * This function returns the allocated pipes number and clnt
177 * handles. Assumes that the user first connects producer pipes
178 * and only after that consumer pipes, since that's the correct
179 * sequence for the handshake with the IPA.
Ofir Cohence5e3f22012-11-16 15:47:40 +0200180 *
181 * @ipa_params - in/out parameters
182 *
183 * @return 0 on success, negative value on error
184 *
185 */
186int usb_bam_connect_ipa(struct usb_bam_connect_ipa_params *ipa_params);
187
188/**
189 * Disconnect USB-to-IPA SPS connection.
190 *
Ofir Cohence5e3f22012-11-16 15:47:40 +0200191 * @ipa_params - in/out parameters
192 *
193 * @return 0 on success, negative value on error
194 *
195 */
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200196int usb_bam_disconnect_ipa(
Ofir Cohence5e3f22012-11-16 15:47:40 +0200197 struct usb_bam_connect_ipa_params *ipa_params);
198
199/**
Lena Salman05b544f2013-05-13 15:49:10 +0300200 * Wait for Consumer granted from Resource Manager.
201 *
202 * @ipa_params - in/out parameters
203 *
204 */
205void usb_bam_wait_for_cons_granted(
206 struct usb_bam_connect_ipa_params *ipa_params);
207/**
Amit Blaye5bb35e2012-05-08 20:38:20 +0300208 * Register a wakeup callback from peer BAM.
209 *
210 * @idx - Connection index.
211 *
212 * @callback - the callback function
213 *
214 * @return 0 on success, negative value on error
215 *
216 */
217int usb_bam_register_wake_cb(u8 idx,
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200218 int (*callback)(void *), void *param);
Shimrit Malichi255b5342012-08-02 21:01:43 +0300219
220/**
Amit Blay0c929f42012-12-26 12:02:29 +0200221 * Register a callback for peer BAM reset.
222 *
Amit Blay0c929f42012-12-26 12:02:29 +0200223 * @callback - the callback function that will be called in USB
224 * driver upon a peer bam reset
225 *
226 * @param - context that the caller can supply
227 *
228 * @return 0 on success, negative value on error
229 *
230 */
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200231int usb_bam_register_peer_reset_cb(int (*callback)(void *), void *param);
Amit Blay0c929f42012-12-26 12:02:29 +0200232
233/**
Lena Salman05b544f2013-05-13 15:49:10 +0300234 * Register callbacks for start/stop of transfers.
235 *
236 * @start - the callback function that will be called in USB
237 * driver to start transfers
238 * @stop - the callback function that will be called in USB
239 * driver to stop transfers
240 *
241 * @param - context that the caller can supply
242 *
243 * @return 0 on success, negative value on error
244 *
245 */
246int usb_bam_register_start_stop_cbs(
247 void (*start)(void *, enum usb_bam_pipe_dir),
248 void (*stop)(void *, enum usb_bam_pipe_dir),
249 void *param);
250
251/**
252 * Start usb suspend sequence
253 *
254 * @ipa_params - in/out parameters
255 *
256 */
257void usb_bam_suspend(struct usb_bam_connect_ipa_params *ipa_params);
258
259/**
260 * Start usb resume sequence
261 *
262 * @ipa_params - in/out parameters
263 *
264 */
265void usb_bam_resume(struct usb_bam_connect_ipa_params *ipa_params);
266/**
Shimrit Malichi255b5342012-08-02 21:01:43 +0300267 * Disconnect USB-to-Periperal SPS connection.
268 *
269 * @idx - Connection index.
270 *
271 * @return 0 on success, negative value on error
272 */
273int usb_bam_disconnect_pipe(u8 idx);
274
275/**
276 * Returns usb bam connection parameters.
277 *
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200278 * @idx - Connection index.
Shimrit Malichi255b5342012-08-02 21:01:43 +0300279 *
280 * @usb_bam_handle - Usb bam handle.
281 *
282 * @usb_bam_pipe_idx - Usb bam pipe index.
283 *
284 * @peer_pipe_idx - Peer pipe index.
285 *
286 * @desc_fifo - Descriptor fifo parameters.
287 *
288 * @data_fifo - Data fifo parameters.
289 *
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200290 * @return pipe index on success, negative value on error.
Shimrit Malichi255b5342012-08-02 21:01:43 +0300291 */
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200292int get_bam2bam_connection_info(u8 idx,
Shimrit Malichi255b5342012-08-02 21:01:43 +0300293 u32 *usb_bam_handle, u32 *usb_bam_pipe_idx, u32 *peer_pipe_idx,
294 struct sps_mem_buffer *desc_fifo, struct sps_mem_buffer *data_fifo);
295
Amit Blay0c929f42012-12-26 12:02:29 +0200296/**
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200297 * Resets the USB BAM that has A2 pipes
Amit Blay0c929f42012-12-26 12:02:29 +0200298 *
299 */
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200300int usb_bam_a2_reset(void);
Amit Blay0c929f42012-12-26 12:02:29 +0200301
302/**
303 * Indicates if the client of the USB BAM is ready to start
304 * sending/receiving transfers.
305 *
306 * @ready - TRUE to enable, FALSE to disable.
307 *
308 */
309int usb_bam_client_ready(bool ready);
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200310/**
311* Returns qdss index from the connections array.
312*
313* @num - The qdss pipe number.
314*
315* @return pipe index on success, negative value on error
316*/
317int usb_bam_get_qdss_idx(u8 num);
318
319/**
320* Saves qdss core number.
321*
322* @qdss_core - The qdss core name.
323*/
324void usb_bam_set_qdss_core(const char *qdss_core);
325
326/**
327* Indicates if the client of the USB BAM is ready to start
328* sending/receiving transfers.
329*
330* @name - Core name (ssusb/hsusb/hsic).
331*
332* @client - Usb pipe peer (a2, ipa, qdss...)
333*
334* @dir - In (from peer to usb) or out (from usb to peer)
335*
336* @num - Pipe number.
337*
338* @return 0 on success, negative value on error
339*/
340int usb_bam_get_connection_idx(const char *name, enum peer_bam client,
341 enum usb_bam_pipe_dir dir, u32 num);
Amit Blay0c929f42012-12-26 12:02:29 +0200342
Ofir Cohenc7827e42011-12-13 20:10:01 +0200343#else
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200344static inline int usb_bam_connect(u8 idx, u32 *bam_pipe_idx)
Amit Blaye5bb35e2012-05-08 20:38:20 +0300345{
346 return -ENODEV;
347}
348
Ofir Cohence5e3f22012-11-16 15:47:40 +0200349static inline int usb_bam_connect_ipa(
350 struct usb_bam_connect_ipa_params *ipa_params)
351{
352 return -ENODEV;
353}
354
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200355static inline int usb_bam_disconnect_ipa(
Ofir Cohence5e3f22012-11-16 15:47:40 +0200356 struct usb_bam_connect_ipa_params *ipa_params)
357{
358 return -ENODEV;
359}
360
Lena Salman05b544f2013-05-13 15:49:10 +0300361static inline void usb_bam_wait_for_cons_granted(
362 struct usb_bam_connect_ipa_params *ipa_params)
363{
364 return;
365}
366
Amit Blaye5bb35e2012-05-08 20:38:20 +0300367static inline int usb_bam_register_wake_cb(u8 idx,
368 int (*callback)(void *), void* param)
Ofir Cohenc7827e42011-12-13 20:10:01 +0200369{
370 return -ENODEV;
371}
Shimrit Malichi255b5342012-08-02 21:01:43 +0300372
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200373static inline int usb_bam_register_peer_reset_cb(
374 int (*callback)(void *), void *param)
Amit Blay0c929f42012-12-26 12:02:29 +0200375{
376 return -ENODEV;
377}
378
Lena Salman05b544f2013-05-13 15:49:10 +0300379static inline int usb_bam_register_start_stop_cbs(
380 void (*start)(void *, enum usb_bam_pipe_dir),
381 void (*stop)(void *, enum usb_bam_pipe_dir),
382 void *param)
383{
384 return -ENODEV;
385}
386
387static inline void usb_bam_suspend(
388 struct usb_bam_connect_ipa_params *ipa_params){}
389
390static inline void usb_bam_resume(
391 struct usb_bam_connect_ipa_params *ipa_params) {}
392
Shimrit Malichi255b5342012-08-02 21:01:43 +0300393static inline int usb_bam_disconnect_pipe(u8 idx)
394{
395 return -ENODEV;
396}
397
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200398static inline int get_bam2bam_connection_info(u8 idx,
399 u32 *usb_bam_handle, u32 *usb_bam_pipe_idx, u32 *peer_pipe_idx,
Shimrit Malichi255b5342012-08-02 21:01:43 +0300400 struct sps_mem_buffer *desc_fifo, struct sps_mem_buffer *data_fifo)
401{
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200402 return -ENODEV;
Shimrit Malichi255b5342012-08-02 21:01:43 +0300403}
Amit Blay0c929f42012-12-26 12:02:29 +0200404
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200405static inline int usb_bam_a2_reset(void)
Amit Blay0c929f42012-12-26 12:02:29 +0200406{
407 return -ENODEV;
408}
409
410static inline int usb_bam_client_ready(bool ready)
411{
412 return -ENODEV;
413}
414
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200415static inline int usb_bam_get_qdss_idx(u8 num)
416{
417 return -ENODEV;
418}
419
420static inline void usb_bam_set_qdss_core(const char *qdss_core)
421{
422 return;
423}
424
425static inline int usb_bam_get_connection_idx(const char *name,
426 enum peer_bam client, enum usb_bam_pipe_dir dir, u32 num)
427{
428 return -ENODEV;
429}
Ofir Cohenc7827e42011-12-13 20:10:01 +0200430#endif
431#endif /* _USB_BAM_H_ */