blob: 68313c575073cc676cfee7e84202d15649dc4507 [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
Ofir Cohence5e3f22012-11-16 15:47:40 +020045struct usb_bam_connect_ipa_params {
Shimrit Malichidbf43d72013-03-16 03:32:27 +020046 u8 src_idx;
47 u8 dst_idx;
Ofir Cohence5e3f22012-11-16 15:47:40 +020048 u32 *src_pipe;
49 u32 *dst_pipe;
50 enum usb_bam_pipe_dir dir;
51 /* client handle assigned by IPA to client */
52 u32 prod_clnt_hdl;
53 u32 cons_clnt_hdl;
54 /* params assigned by the CD */
55 enum ipa_client_type client;
56 struct ipa_ep_cfg ipa_ep_cfg;
57 void *priv;
58 void (*notify)(void *priv, enum ipa_dp_evt_type evt,
59 unsigned long data);
60};
61
Shimrit Malichidbf43d72013-03-16 03:32:27 +020062/**
63* struct usb_bam_event_info: suspend/resume event information.
64* @event: holds event data.
65* @callback: suspend/resume callback.
66* @param: port num (for suspend) or NULL (for resume).
67* @event_w: holds work queue parameters.
68*/
69struct usb_bam_event_info {
70 struct sps_register_event event;
71 int (*callback)(void *);
72 void *param;
73 struct work_struct event_w;
74};
75
76/**
77* struct usb_bam_pipe_connect: pipe connection information
78* between USB/HSIC BAM and another BAM. USB/HSIC BAM can be
79* either src BAM or dst BAM
80* @name: pipe description.
81* @mem_type: type of memory used for BAM FIFOs
82* @src_phy_addr: src bam physical address.
83* @src_pipe_index: src bam pipe index.
84* @dst_phy_addr: dst bam physical address.
85* @dst_pipe_index: dst bam pipe index.
86* @data_fifo_base_offset: data fifo offset.
87* @data_fifo_size: data fifo size.
88* @desc_fifo_base_offset: descriptor fifo offset.
89* @desc_fifo_size: descriptor fifo size.
90* @data_mem_buf: data fifo buffer.
91* @desc_mem_buf: descriptor fifo buffer.
92* @wake_event: event for wakeup.
93* @enabled: true if pipe is enabled.
94*/
95struct usb_bam_pipe_connect {
96 const char *name;
97 u32 pipe_num;
98 enum usb_pipe_mem_type mem_type;
99 enum usb_bam_pipe_dir dir;
100 enum usb_bam bam_type;
101 enum peer_bam peer_bam;
102 u32 src_phy_addr;
103 u32 src_pipe_index;
104 u32 dst_phy_addr;
105 u32 dst_pipe_index;
106 u32 data_fifo_base_offset;
107 u32 data_fifo_size;
108 u32 desc_fifo_base_offset;
109 u32 desc_fifo_size;
110 struct sps_mem_buffer data_mem_buf;
111 struct sps_mem_buffer desc_mem_buf;
112 struct usb_bam_event_info wake_event;
113 bool enabled;
114};
115
116/**
117 * struct msm_usb_bam_platform_data: pipe connection information
118 * between USB/HSIC BAM and another BAM. USB/HSIC BAM can be
119 * either src BAM or dst BAM
120 * @connections: holds all pipe connections data.
121 * @usb_bam_num_pipes: max number of pipes to use.
122 * @active_conn_num: number of active pipe connections.
Vamsi Krishnafd09ddd2013-03-27 15:39:49 -0700123 * @usb_bam_fifo_baseaddr: base address for bam pipe's data and descriptor
124 * fifos. This can be on chip memory (ocimem) or usb
125 * private memory.
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200126 * @ignore_core_reset_ack: BAM can ignore ACK from USB core during PIPE RESET
127 * @disable_clk_gating: Disable clock gating
128 */
129struct msm_usb_bam_platform_data {
130 struct usb_bam_pipe_connect *connections;
131 u8 max_connections;
132 int usb_bam_num_pipes;
Vamsi Krishnafd09ddd2013-03-27 15:39:49 -0700133 phys_addr_t usb_bam_fifo_baseaddr;
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200134 bool ignore_core_reset_ack;
135 bool reset_on_connect[MAX_BAMS];
136 bool disable_clk_gating;
137};
138
Amit Blaye5bb35e2012-05-08 20:38:20 +0300139#ifdef CONFIG_USB_BAM
140/**
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200141 * Connect USB-to-Peripheral SPS connection.
Ofir Cohenc7827e42011-12-13 20:10:01 +0200142 *
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200143 * This function returns the allocated pipe number.
Ofir Cohenc7827e42011-12-13 20:10:01 +0200144 *
145 * @idx - Connection index.
146 *
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200147 * @bam_pipe_idx - allocated pipe index.
Ofir Cohenc7827e42011-12-13 20:10:01 +0200148 *
149 * @return 0 on success, negative value on error
150 *
151 */
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200152int usb_bam_connect(u8 idx, u32 *bam_pipe_idx);
Amit Blaye5bb35e2012-05-08 20:38:20 +0300153
154/**
Ofir Cohence5e3f22012-11-16 15:47:40 +0200155 * Connect USB-to-IPA SPS connection.
156 *
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200157 * This function returns the allocated pipes number and clnt handles.
Ofir Cohence5e3f22012-11-16 15:47:40 +0200158 *
159 * @ipa_params - in/out parameters
160 *
161 * @return 0 on success, negative value on error
162 *
163 */
164int usb_bam_connect_ipa(struct usb_bam_connect_ipa_params *ipa_params);
165
166/**
167 * Disconnect USB-to-IPA SPS connection.
168 *
Ofir Cohence5e3f22012-11-16 15:47:40 +0200169 * @ipa_params - in/out parameters
170 *
171 * @return 0 on success, negative value on error
172 *
173 */
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200174int usb_bam_disconnect_ipa(
Ofir Cohence5e3f22012-11-16 15:47:40 +0200175 struct usb_bam_connect_ipa_params *ipa_params);
176
177/**
Amit Blaye5bb35e2012-05-08 20:38:20 +0300178 * Register a wakeup callback from peer BAM.
179 *
180 * @idx - Connection index.
181 *
182 * @callback - the callback function
183 *
184 * @return 0 on success, negative value on error
185 *
186 */
187int usb_bam_register_wake_cb(u8 idx,
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200188 int (*callback)(void *), void *param);
Shimrit Malichi255b5342012-08-02 21:01:43 +0300189
190/**
Amit Blay0c929f42012-12-26 12:02:29 +0200191 * Register a callback for peer BAM reset.
192 *
Amit Blay0c929f42012-12-26 12:02:29 +0200193 * @callback - the callback function that will be called in USB
194 * driver upon a peer bam reset
195 *
196 * @param - context that the caller can supply
197 *
198 * @return 0 on success, negative value on error
199 *
200 */
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200201int usb_bam_register_peer_reset_cb(int (*callback)(void *), void *param);
Amit Blay0c929f42012-12-26 12:02:29 +0200202
203/**
Shimrit Malichi255b5342012-08-02 21:01:43 +0300204 * Disconnect USB-to-Periperal SPS connection.
205 *
206 * @idx - Connection index.
207 *
208 * @return 0 on success, negative value on error
209 */
210int usb_bam_disconnect_pipe(u8 idx);
211
212/**
213 * Returns usb bam connection parameters.
214 *
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200215 * @idx - Connection index.
Shimrit Malichi255b5342012-08-02 21:01:43 +0300216 *
217 * @usb_bam_handle - Usb bam handle.
218 *
219 * @usb_bam_pipe_idx - Usb bam pipe index.
220 *
221 * @peer_pipe_idx - Peer pipe index.
222 *
223 * @desc_fifo - Descriptor fifo parameters.
224 *
225 * @data_fifo - Data fifo parameters.
226 *
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200227 * @return pipe index on success, negative value on error.
Shimrit Malichi255b5342012-08-02 21:01:43 +0300228 */
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200229int get_bam2bam_connection_info(u8 idx,
Shimrit Malichi255b5342012-08-02 21:01:43 +0300230 u32 *usb_bam_handle, u32 *usb_bam_pipe_idx, u32 *peer_pipe_idx,
231 struct sps_mem_buffer *desc_fifo, struct sps_mem_buffer *data_fifo);
232
Amit Blay0c929f42012-12-26 12:02:29 +0200233/**
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200234 * Resets the USB BAM that has A2 pipes
Amit Blay0c929f42012-12-26 12:02:29 +0200235 *
236 */
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200237int usb_bam_a2_reset(void);
Amit Blay0c929f42012-12-26 12:02:29 +0200238
239/**
240 * Indicates if the client of the USB BAM is ready to start
241 * sending/receiving transfers.
242 *
243 * @ready - TRUE to enable, FALSE to disable.
244 *
245 */
246int usb_bam_client_ready(bool ready);
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200247/**
248* Returns qdss index from the connections array.
249*
250* @num - The qdss pipe number.
251*
252* @return pipe index on success, negative value on error
253*/
254int usb_bam_get_qdss_idx(u8 num);
255
256/**
257* Saves qdss core number.
258*
259* @qdss_core - The qdss core name.
260*/
261void usb_bam_set_qdss_core(const char *qdss_core);
262
263/**
264* Indicates if the client of the USB BAM is ready to start
265* sending/receiving transfers.
266*
267* @name - Core name (ssusb/hsusb/hsic).
268*
269* @client - Usb pipe peer (a2, ipa, qdss...)
270*
271* @dir - In (from peer to usb) or out (from usb to peer)
272*
273* @num - Pipe number.
274*
275* @return 0 on success, negative value on error
276*/
277int usb_bam_get_connection_idx(const char *name, enum peer_bam client,
278 enum usb_bam_pipe_dir dir, u32 num);
Amit Blay0c929f42012-12-26 12:02:29 +0200279
Ofir Cohenc7827e42011-12-13 20:10:01 +0200280#else
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200281static inline int usb_bam_connect(u8 idx, u32 *bam_pipe_idx)
Amit Blaye5bb35e2012-05-08 20:38:20 +0300282{
283 return -ENODEV;
284}
285
Ofir Cohence5e3f22012-11-16 15:47:40 +0200286static inline int usb_bam_connect_ipa(
287 struct usb_bam_connect_ipa_params *ipa_params)
288{
289 return -ENODEV;
290}
291
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200292static inline int usb_bam_disconnect_ipa(
Ofir Cohence5e3f22012-11-16 15:47:40 +0200293 struct usb_bam_connect_ipa_params *ipa_params)
294{
295 return -ENODEV;
296}
297
Amit Blaye5bb35e2012-05-08 20:38:20 +0300298static inline int usb_bam_register_wake_cb(u8 idx,
299 int (*callback)(void *), void* param)
Ofir Cohenc7827e42011-12-13 20:10:01 +0200300{
301 return -ENODEV;
302}
Shimrit Malichi255b5342012-08-02 21:01:43 +0300303
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200304static inline int usb_bam_register_peer_reset_cb(
305 int (*callback)(void *), void *param)
Amit Blay0c929f42012-12-26 12:02:29 +0200306{
307 return -ENODEV;
308}
309
Shimrit Malichi255b5342012-08-02 21:01:43 +0300310static inline int usb_bam_disconnect_pipe(u8 idx)
311{
312 return -ENODEV;
313}
314
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200315static inline int get_bam2bam_connection_info(u8 idx,
316 u32 *usb_bam_handle, u32 *usb_bam_pipe_idx, u32 *peer_pipe_idx,
Shimrit Malichi255b5342012-08-02 21:01:43 +0300317 struct sps_mem_buffer *desc_fifo, struct sps_mem_buffer *data_fifo)
318{
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200319 return -ENODEV;
Shimrit Malichi255b5342012-08-02 21:01:43 +0300320}
Amit Blay0c929f42012-12-26 12:02:29 +0200321
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200322static inline int usb_bam_a2_reset(void)
Amit Blay0c929f42012-12-26 12:02:29 +0200323{
324 return -ENODEV;
325}
326
327static inline int usb_bam_client_ready(bool ready)
328{
329 return -ENODEV;
330}
331
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200332static inline int usb_bam_get_qdss_idx(u8 num)
333{
334 return -ENODEV;
335}
336
337static inline void usb_bam_set_qdss_core(const char *qdss_core)
338{
339 return;
340}
341
342static inline int usb_bam_get_connection_idx(const char *name,
343 enum peer_bam client, enum usb_bam_pipe_dir dir, u32 num)
344{
345 return -ENODEV;
346}
Ofir Cohenc7827e42011-12-13 20:10:01 +0200347#endif
348#endif /* _USB_BAM_H_ */