blob: b4353ac7fdd1080a29b34815e4fa014a9c7f838c [file] [log] [blame]
Mayank Rana20c78842017-02-14 17:34:45 -08001/*
2 * Copyright (c) 2012-2017, The Linux Foundation. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 and
6 * only version 2 as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details
12 */
13
14#include <linux/kernel.h>
15#include <linux/device.h>
Mayank Rana20c78842017-02-14 17:34:45 -080016#include <linux/usb_bam.h>
17
18#include "f_qdss.h"
19static int alloc_sps_req(struct usb_ep *data_ep)
20{
21 struct usb_request *req = NULL;
22 struct f_qdss *qdss = data_ep->driver_data;
23 u32 sps_params = 0;
24
25 pr_debug("send_sps_req\n");
26
27 req = usb_ep_alloc_request(data_ep, GFP_ATOMIC);
28 if (!req) {
29 pr_err("usb_ep_alloc_request failed\n");
30 return -ENOMEM;
31 }
32
33 req->length = 32*1024;
34 sps_params = MSM_SPS_MODE | MSM_DISABLE_WB |
35 qdss->bam_info.usb_bam_pipe_idx;
36 req->udc_priv = sps_params;
37 qdss->endless_req = req;
38
39 return 0;
40}
41
42static int init_data(struct usb_ep *ep);
Vijayavardhan Vennapusab4a565e2017-03-15 13:31:02 +053043int set_qdss_data_connection(struct f_qdss *qdss, int enable)
Mayank Rana20c78842017-02-14 17:34:45 -080044{
45 enum usb_ctrl usb_bam_type;
46 int res = 0;
47 int idx;
Vijayavardhan Vennapusab4a565e2017-03-15 13:31:02 +053048 struct usb_qdss_bam_connect_info bam_info;
49 struct usb_gadget *gadget;
Mayank Ranac40bb372017-11-07 15:29:44 -080050 struct device *dev;
51 int ret;
Mayank Rana20c78842017-02-14 17:34:45 -080052
53 pr_debug("set_qdss_data_connection\n");
54
Vijayavardhan Vennapusab4a565e2017-03-15 13:31:02 +053055 if (!qdss) {
56 pr_err("%s: qdss ptr is NULL\n", __func__);
57 return -EINVAL;
58 }
59
60 gadget = qdss->gadget;
Mayank Rana20c78842017-02-14 17:34:45 -080061 usb_bam_type = usb_bam_get_bam_type(gadget->name);
Mayank Ranac40bb372017-11-07 15:29:44 -080062 dev = gadget->dev.parent;
Mayank Rana20c78842017-02-14 17:34:45 -080063
Vijayavardhan Vennapusab4a565e2017-03-15 13:31:02 +053064 bam_info = qdss->bam_info;
Mayank Rana20c78842017-02-14 17:34:45 -080065 /* There is only one qdss pipe, so the pipe number can be set to 0 */
66 idx = usb_bam_get_connection_idx(usb_bam_type, QDSS_P_BAM,
67 PEER_PERIPHERAL_TO_USB, USB_BAM_DEVICE, 0);
68 if (idx < 0) {
69 pr_err("%s: usb_bam_get_connection_idx failed\n", __func__);
70 return idx;
71 }
72
73 if (enable) {
Mayank Ranac40bb372017-11-07 15:29:44 -080074 ret = get_qdss_bam_info(usb_bam_type, idx,
75 &bam_info.qdss_bam_phys,
76 &bam_info.qdss_bam_size);
77 if (ret) {
78 pr_err("%s(): failed to get qdss bam info err(%d)\n",
79 __func__, ret);
80 return ret;
81 }
82
83 bam_info.qdss_bam_iova = dma_map_resource(dev->parent,
84 bam_info.qdss_bam_phys, bam_info.qdss_bam_size,
85 DMA_BIDIRECTIONAL, 0);
86 if (!bam_info.qdss_bam_iova) {
87 pr_err("dma_map_resource failed\n");
88 return -ENOMEM;
89 }
90
Mayank Rana20c78842017-02-14 17:34:45 -080091 usb_bam_alloc_fifos(usb_bam_type, idx);
92 bam_info.data_fifo =
93 kzalloc(sizeof(struct sps_mem_buffer), GFP_KERNEL);
94 if (!bam_info.data_fifo) {
95 pr_err("qdss_data_connection: memory alloc failed\n");
Vijayavardhan Vennapusab4a565e2017-03-15 13:31:02 +053096 usb_bam_free_fifos(usb_bam_type, idx);
Mayank Rana20c78842017-02-14 17:34:45 -080097 return -ENOMEM;
98 }
Mayank Ranac40bb372017-11-07 15:29:44 -080099
100 pr_debug("%s(): qdss_bam: iova:%lx p_addr:%lx size:%x\n",
101 __func__, bam_info.qdss_bam_iova,
102 (unsigned long)bam_info.qdss_bam_phys,
103 bam_info.qdss_bam_size);
104
Mayank Rana20c78842017-02-14 17:34:45 -0800105 get_bam2bam_connection_info(usb_bam_type, idx,
106 &bam_info.usb_bam_pipe_idx,
107 NULL, bam_info.data_fifo, NULL);
108
Vijayavardhan Vennapusab4a565e2017-03-15 13:31:02 +0530109 alloc_sps_req(qdss->port.data);
110 msm_data_fifo_config(qdss->port.data,
Mayank Rana52594a82017-11-06 16:58:04 -0800111 bam_info.data_fifo->iova,
112 bam_info.data_fifo->size,
113 bam_info.usb_bam_pipe_idx);
Mayank Rana20c78842017-02-14 17:34:45 -0800114 init_data(qdss->port.data);
115
116 res = usb_bam_connect(usb_bam_type, idx,
Mayank Ranac40bb372017-11-07 15:29:44 -0800117 &(bam_info.usb_bam_pipe_idx),
118 bam_info.qdss_bam_iova);
Mayank Rana20c78842017-02-14 17:34:45 -0800119 } else {
Mayank Rana20c78842017-02-14 17:34:45 -0800120 res = usb_bam_disconnect_pipe(usb_bam_type, idx);
121 if (res)
122 pr_err("usb_bam_disconnection error\n");
Mayank Ranac40bb372017-11-07 15:29:44 -0800123 dma_unmap_resource(dev->parent, bam_info.qdss_bam_iova,
124 bam_info.qdss_bam_size, DMA_BIDIRECTIONAL, 0);
Mayank Rana20c78842017-02-14 17:34:45 -0800125 usb_bam_free_fifos(usb_bam_type, idx);
Mayank Ranac40bb372017-11-07 15:29:44 -0800126 kfree(bam_info.data_fifo);
Mayank Rana20c78842017-02-14 17:34:45 -0800127 }
128
129 return res;
130}
131
132static int init_data(struct usb_ep *ep)
133{
Mayank Rana20c78842017-02-14 17:34:45 -0800134 int res = 0;
135
136 pr_debug("init_data\n");
137
Mayank Rana9f189e02017-02-27 14:55:09 -0800138 res = msm_ep_config(ep);
Mayank Rana20c78842017-02-14 17:34:45 -0800139 if (res)
140 pr_err("msm_ep_config failed\n");
141
142 return res;
143}
144
145int uninit_data(struct usb_ep *ep)
146{
147 int res = 0;
148
149 pr_err("uninit_data\n");
150
151 res = msm_ep_unconfig(ep);
152 if (res)
153 pr_err("msm_ep_unconfig failed\n");
154
155 return res;
156}