Shimrit Malichi | dbf43d7 | 2013-03-16 03:32:27 +0200 | [diff] [blame] | 1 | /* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved. |
Shimrit Malichi | a00d732 | 2012-08-05 13:56:28 +0300 | [diff] [blame] | 2 | * |
| 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 Malichi | a00d732 | 2012-08-05 13:56:28 +0300 | [diff] [blame] | 18 | struct 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 | |
| 25 | static struct usb_qdss_bam_connect_info bam_info; |
| 26 | |
| 27 | int 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 Gautam | 76aa18b | 2012-07-25 17:12:37 +0530 | [diff] [blame] | 31 | struct usb_gadget *gadget = qdss->cdev->gadget; |
Shimrit Malichi | a00d732 | 2012-08-05 13:56:28 +0300 | [diff] [blame] | 32 | 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 Gautam | 76aa18b | 2012-07-25 17:12:37 +0530 | [diff] [blame] | 42 | 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 Malichi | a00d732 | 2012-08-05 13:56:28 +0300 | [diff] [blame] | 52 | 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 Malichi | dbf43d7 | 2013-03-16 03:32:27 +0200 | [diff] [blame] | 61 | static int set_qdss_data_connection(struct usb_gadget *gadget, |
| 62 | struct usb_ep *data_ep, u8 data_addr, int enable) |
Shimrit Malichi | a00d732 | 2012-08-05 13:56:28 +0300 | [diff] [blame] | 63 | { |
| 64 | int res = 0; |
Shimrit Malichi | dbf43d7 | 2013-03-16 03:32:27 +0200 | [diff] [blame] | 65 | u8 idx; |
Shimrit Malichi | 83df3ff | 2013-03-10 13:16:12 +0200 | [diff] [blame] | 66 | |
Shimrit Malichi | a00d732 | 2012-08-05 13:56:28 +0300 | [diff] [blame] | 67 | pr_debug("set_qdss_data_connection\n"); |
| 68 | |
Shimrit Malichi | dbf43d7 | 2013-03-16 03:32:27 +0200 | [diff] [blame] | 69 | /* 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 Malichi | a00d732 | 2012-08-05 13:56:28 +0300 | [diff] [blame] | 76 | |
Shimrit Malichi | dbf43d7 | 2013-03-16 03:32:27 +0200 | [diff] [blame] | 77 | if (enable) { |
| 78 | res = usb_bam_connect(idx, &(bam_info.usb_bam_pipe_idx)); |
Shimrit Malichi | a00d732 | 2012-08-05 13:56:28 +0300 | [diff] [blame] | 79 | 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 Malichi | dbf43d7 | 2013-03-16 03:32:27 +0200 | [diff] [blame] | 85 | usb_bam_set_qdss_core(gadget->name); |
| 86 | get_bam2bam_connection_info(idx, |
| 87 | &bam_info.usb_bam_handle, |
Shimrit Malichi | a00d732 | 2012-08-05 13:56:28 +0300 | [diff] [blame] | 88 | &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 Malichi | dbf43d7 | 2013-03-16 03:32:27 +0200 | [diff] [blame] | 95 | res = usb_bam_disconnect_pipe(idx); |
Shimrit Malichi | a00d732 | 2012-08-05 13:56:28 +0300 | [diff] [blame] | 96 | if (res) { |
| 97 | pr_err("usb_bam_disconnection error\n"); |
| 98 | return res; |
| 99 | } |
Shimrit Malichi | a00d732 | 2012-08-05 13:56:28 +0300 | [diff] [blame] | 100 | } |
Shimrit Malichi | dbf43d7 | 2013-03-16 03:32:27 +0200 | [diff] [blame] | 101 | |
Shimrit Malichi | a00d732 | 2012-08-05 13:56:28 +0300 | [diff] [blame] | 102 | return res; |
| 103 | } |
| 104 | |
| 105 | int init_data(struct usb_ep *ep) |
| 106 | { |
Manu Gautam | 76aa18b | 2012-07-25 17:12:37 +0530 | [diff] [blame] | 107 | struct f_qdss *qdss = ep->driver_data; |
| 108 | struct usb_gadget *gadget = qdss->cdev->gadget; |
Shimrit Malichi | a00d732 | 2012-08-05 13:56:28 +0300 | [diff] [blame] | 109 | int res = 0; |
| 110 | |
| 111 | pr_debug("init_data\n"); |
| 112 | |
Manu Gautam | 76aa18b | 2012-07-25 17:12:37 +0530 | [diff] [blame] | 113 | 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 Malichi | a00d732 | 2012-08-05 13:56:28 +0300 | [diff] [blame] | 120 | |
| 121 | return res; |
| 122 | } |
| 123 | |
| 124 | int uninit_data(struct usb_ep *ep) |
| 125 | { |
Manu Gautam | 76aa18b | 2012-07-25 17:12:37 +0530 | [diff] [blame] | 126 | struct f_qdss *qdss = ep->driver_data; |
| 127 | struct usb_gadget *gadget = qdss->cdev->gadget; |
Shimrit Malichi | a00d732 | 2012-08-05 13:56:28 +0300 | [diff] [blame] | 128 | int res = 0; |
| 129 | |
| 130 | pr_err("uninit_data\n"); |
| 131 | |
Manu Gautam | 76aa18b | 2012-07-25 17:12:37 +0530 | [diff] [blame] | 132 | if (gadget_is_dwc3(gadget)) { |
| 133 | res = msm_ep_unconfig(ep); |
| 134 | if (res) |
Manu Gautam | 4a51a06 | 2012-12-07 11:24:39 +0530 | [diff] [blame] | 135 | pr_err("msm_ep_unconfig failed\n"); |
Manu Gautam | 76aa18b | 2012-07-25 17:12:37 +0530 | [diff] [blame] | 136 | } |
| 137 | |
Shimrit Malichi | a00d732 | 2012-08-05 13:56:28 +0300 | [diff] [blame] | 138 | return res; |
| 139 | } |