Mayank Rana | 20c7884 | 2017-02-14 17:34:45 -0800 | [diff] [blame] | 1 | /* |
| 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 Rana | 20c7884 | 2017-02-14 17:34:45 -0800 | [diff] [blame] | 16 | #include <linux/usb_bam.h> |
| 17 | |
| 18 | #include "f_qdss.h" |
| 19 | static 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 | |
| 42 | static int init_data(struct usb_ep *ep); |
Vijayavardhan Vennapusa | b4a565e | 2017-03-15 13:31:02 +0530 | [diff] [blame] | 43 | int set_qdss_data_connection(struct f_qdss *qdss, int enable) |
Mayank Rana | 20c7884 | 2017-02-14 17:34:45 -0800 | [diff] [blame] | 44 | { |
| 45 | enum usb_ctrl usb_bam_type; |
| 46 | int res = 0; |
| 47 | int idx; |
Vijayavardhan Vennapusa | b4a565e | 2017-03-15 13:31:02 +0530 | [diff] [blame] | 48 | struct usb_qdss_bam_connect_info bam_info; |
| 49 | struct usb_gadget *gadget; |
Mayank Rana | 20c7884 | 2017-02-14 17:34:45 -0800 | [diff] [blame] | 50 | |
| 51 | pr_debug("set_qdss_data_connection\n"); |
| 52 | |
Vijayavardhan Vennapusa | b4a565e | 2017-03-15 13:31:02 +0530 | [diff] [blame] | 53 | if (!qdss) { |
| 54 | pr_err("%s: qdss ptr is NULL\n", __func__); |
| 55 | return -EINVAL; |
| 56 | } |
| 57 | |
| 58 | gadget = qdss->gadget; |
Mayank Rana | 20c7884 | 2017-02-14 17:34:45 -0800 | [diff] [blame] | 59 | usb_bam_type = usb_bam_get_bam_type(gadget->name); |
| 60 | |
Vijayavardhan Vennapusa | b4a565e | 2017-03-15 13:31:02 +0530 | [diff] [blame] | 61 | bam_info = qdss->bam_info; |
Mayank Rana | 20c7884 | 2017-02-14 17:34:45 -0800 | [diff] [blame] | 62 | /* There is only one qdss pipe, so the pipe number can be set to 0 */ |
| 63 | idx = usb_bam_get_connection_idx(usb_bam_type, QDSS_P_BAM, |
| 64 | PEER_PERIPHERAL_TO_USB, USB_BAM_DEVICE, 0); |
| 65 | if (idx < 0) { |
| 66 | pr_err("%s: usb_bam_get_connection_idx failed\n", __func__); |
| 67 | return idx; |
| 68 | } |
| 69 | |
| 70 | if (enable) { |
| 71 | usb_bam_alloc_fifos(usb_bam_type, idx); |
| 72 | bam_info.data_fifo = |
| 73 | kzalloc(sizeof(struct sps_mem_buffer), GFP_KERNEL); |
| 74 | if (!bam_info.data_fifo) { |
| 75 | pr_err("qdss_data_connection: memory alloc failed\n"); |
Vijayavardhan Vennapusa | b4a565e | 2017-03-15 13:31:02 +0530 | [diff] [blame] | 76 | usb_bam_free_fifos(usb_bam_type, idx); |
Mayank Rana | 20c7884 | 2017-02-14 17:34:45 -0800 | [diff] [blame] | 77 | return -ENOMEM; |
| 78 | } |
| 79 | get_bam2bam_connection_info(usb_bam_type, idx, |
| 80 | &bam_info.usb_bam_pipe_idx, |
| 81 | NULL, bam_info.data_fifo, NULL); |
| 82 | |
Vijayavardhan Vennapusa | b4a565e | 2017-03-15 13:31:02 +0530 | [diff] [blame] | 83 | alloc_sps_req(qdss->port.data); |
| 84 | msm_data_fifo_config(qdss->port.data, |
| 85 | bam_info.data_fifo->phys_base, |
Mayank Rana | 20c7884 | 2017-02-14 17:34:45 -0800 | [diff] [blame] | 86 | bam_info.data_fifo->size, |
| 87 | bam_info.usb_bam_pipe_idx); |
| 88 | init_data(qdss->port.data); |
| 89 | |
| 90 | res = usb_bam_connect(usb_bam_type, idx, |
| 91 | &(bam_info.usb_bam_pipe_idx)); |
| 92 | } else { |
| 93 | kfree(bam_info.data_fifo); |
| 94 | res = usb_bam_disconnect_pipe(usb_bam_type, idx); |
| 95 | if (res) |
| 96 | pr_err("usb_bam_disconnection error\n"); |
| 97 | usb_bam_free_fifos(usb_bam_type, idx); |
| 98 | } |
| 99 | |
| 100 | return res; |
| 101 | } |
| 102 | |
| 103 | static int init_data(struct usb_ep *ep) |
| 104 | { |
Mayank Rana | 20c7884 | 2017-02-14 17:34:45 -0800 | [diff] [blame] | 105 | int res = 0; |
| 106 | |
| 107 | pr_debug("init_data\n"); |
| 108 | |
Mayank Rana | 9f189e0 | 2017-02-27 14:55:09 -0800 | [diff] [blame] | 109 | res = msm_ep_config(ep); |
Mayank Rana | 20c7884 | 2017-02-14 17:34:45 -0800 | [diff] [blame] | 110 | if (res) |
| 111 | pr_err("msm_ep_config failed\n"); |
| 112 | |
| 113 | return res; |
| 114 | } |
| 115 | |
| 116 | int uninit_data(struct usb_ep *ep) |
| 117 | { |
| 118 | int res = 0; |
| 119 | |
| 120 | pr_err("uninit_data\n"); |
| 121 | |
| 122 | res = msm_ep_unconfig(ep); |
| 123 | if (res) |
| 124 | pr_err("msm_ep_unconfig failed\n"); |
| 125 | |
| 126 | return res; |
| 127 | } |