blob: e241e29226180035ec6bb59cc462c08d29c644ed [file] [log] [blame]
Shimrit Malichidbf43d72013-03-16 03:32:27 +02001/* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
Shimrit Malichia00d7322012-08-05 13:56:28 +03002 *
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#include <linux/kernel.h>
14#include <linux/device.h>
15#include <linux/usb/msm_hsusb.h>
16#include <mach/usb_bam.h>
17
Shimrit Malichia00d7322012-08-05 13:56:28 +030018struct usb_qdss_bam_connect_info {
19 u32 usb_bam_pipe_idx;
20 u32 peer_pipe_idx;
21 u32 usb_bam_handle;
22 struct sps_mem_buffer *data_fifo;
23};
24
25static struct usb_qdss_bam_connect_info bam_info;
26
27int send_sps_req(struct usb_ep *data_ep)
28{
29 struct usb_request *req = NULL;
30 struct f_qdss *qdss = data_ep->driver_data;
Manu Gautam76aa18b2012-07-25 17:12:37 +053031 struct usb_gadget *gadget = qdss->cdev->gadget;
Shimrit Malichia00d7322012-08-05 13:56:28 +030032 u32 sps_params = 0;
33
34 pr_debug("send_sps_req\n");
35
36 req = usb_ep_alloc_request(data_ep, GFP_ATOMIC);
37 if (!req) {
38 pr_err("usb_ep_alloc_request failed\n");
39 return -ENOMEM;
40 }
41
Manu Gautam76aa18b2012-07-25 17:12:37 +053042 if (gadget_is_dwc3(gadget)) {
43 req->length = 32*1024;
44 sps_params = MSM_SPS_MODE | MSM_DISABLE_WB | MSM_INTERNAL_MEM |
45 bam_info.usb_bam_pipe_idx;
46 } else {
47 /* non DWC3 BAM requires req->length to be 0 */
48 req->length = 0;
49 sps_params = (MSM_SPS_MODE | bam_info.usb_bam_pipe_idx |
50 MSM_VENDOR_ID) & ~MSM_IS_FINITE_TRANSFER;
51 }
Shimrit Malichia00d7322012-08-05 13:56:28 +030052 req->udc_priv = sps_params;
53 qdss->endless_req = req;
54 if (usb_ep_queue(data_ep, req, GFP_ATOMIC)) {
55 pr_err("send_sps_req: usb_ep_queue error\n");
56 return -EIO;
57 }
58 return 0;
59}
60
Shimrit Malichidbf43d72013-03-16 03:32:27 +020061static int set_qdss_data_connection(struct usb_gadget *gadget,
62 struct usb_ep *data_ep, u8 data_addr, int enable)
Shimrit Malichia00d7322012-08-05 13:56:28 +030063{
64 int res = 0;
Shimrit Malichidbf43d72013-03-16 03:32:27 +020065 u8 idx;
Shimrit Malichi83df3ff2013-03-10 13:16:12 +020066
Shimrit Malichia00d7322012-08-05 13:56:28 +030067 pr_debug("set_qdss_data_connection\n");
68
Shimrit Malichidbf43d72013-03-16 03:32:27 +020069 /* There is only one qdss pipe, so the pipe number can be set to 0 */
70 idx = usb_bam_get_connection_idx(gadget->name, QDSS_P_BAM,
71 PEER_PERIPHERAL_TO_USB, 0);
72 if (idx < 0) {
73 pr_err("%s: usb_bam_get_connection_idx failed\n", __func__);
74 return idx;
75 }
Shimrit Malichia00d7322012-08-05 13:56:28 +030076
Shimrit Malichidbf43d72013-03-16 03:32:27 +020077 if (enable) {
78 res = usb_bam_connect(idx, &(bam_info.usb_bam_pipe_idx));
Shimrit Malichia00d7322012-08-05 13:56:28 +030079 bam_info.data_fifo =
80 kzalloc(sizeof(struct sps_mem_buffer *), GFP_KERNEL);
81 if (!bam_info.data_fifo) {
82 pr_err("qdss_data_connection: memory alloc failed\n");
83 return -ENOMEM;
84 }
Shimrit Malichidbf43d72013-03-16 03:32:27 +020085 usb_bam_set_qdss_core(gadget->name);
86 get_bam2bam_connection_info(idx,
87 &bam_info.usb_bam_handle,
Shimrit Malichia00d7322012-08-05 13:56:28 +030088 &bam_info.usb_bam_pipe_idx, &bam_info.peer_pipe_idx,
89 NULL, bam_info.data_fifo);
90
91 msm_data_fifo_config(data_ep, bam_info.data_fifo->phys_base,
92 bam_info.data_fifo->size, bam_info.usb_bam_pipe_idx);
93 } else {
94 kfree(bam_info.data_fifo);
Shimrit Malichidbf43d72013-03-16 03:32:27 +020095 res = usb_bam_disconnect_pipe(idx);
Shimrit Malichia00d7322012-08-05 13:56:28 +030096 if (res) {
97 pr_err("usb_bam_disconnection error\n");
98 return res;
99 }
Shimrit Malichia00d7322012-08-05 13:56:28 +0300100 }
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200101
Shimrit Malichia00d7322012-08-05 13:56:28 +0300102 return res;
103}
104
105int init_data(struct usb_ep *ep)
106{
Manu Gautam76aa18b2012-07-25 17:12:37 +0530107 struct f_qdss *qdss = ep->driver_data;
108 struct usb_gadget *gadget = qdss->cdev->gadget;
Shimrit Malichia00d7322012-08-05 13:56:28 +0300109 int res = 0;
110
111 pr_debug("init_data\n");
112
Manu Gautam76aa18b2012-07-25 17:12:37 +0530113 if (gadget_is_dwc3(gadget)) {
114 res = msm_ep_config(ep);
115 if (res)
116 pr_err("msm_ep_config failed\n");
117 } else {
118 pr_debug("QDSS is used with non DWC3 core\n");
119 }
Shimrit Malichia00d7322012-08-05 13:56:28 +0300120
121 return res;
122}
123
124int uninit_data(struct usb_ep *ep)
125{
Manu Gautam76aa18b2012-07-25 17:12:37 +0530126 struct f_qdss *qdss = ep->driver_data;
127 struct usb_gadget *gadget = qdss->cdev->gadget;
Shimrit Malichia00d7322012-08-05 13:56:28 +0300128 int res = 0;
129
130 pr_err("uninit_data\n");
131
Manu Gautam76aa18b2012-07-25 17:12:37 +0530132 if (gadget_is_dwc3(gadget)) {
133 res = msm_ep_unconfig(ep);
134 if (res)
Manu Gautam4a51a062012-12-07 11:24:39 +0530135 pr_err("msm_ep_unconfig failed\n");
Manu Gautam76aa18b2012-07-25 17:12:37 +0530136 }
137
Shimrit Malichia00d7322012-08-05 13:56:28 +0300138 return res;
139}