Duy Truong | e833aca | 2013-02-12 13:35:08 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2012, 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 | |
| 18 | #define BAM_CONNC_IDX 0 /* USB bam connection index */ |
| 19 | |
| 20 | struct usb_qdss_bam_connect_info { |
| 21 | u32 usb_bam_pipe_idx; |
| 22 | u32 peer_pipe_idx; |
| 23 | u32 usb_bam_handle; |
| 24 | struct sps_mem_buffer *data_fifo; |
| 25 | }; |
| 26 | |
| 27 | static struct usb_qdss_bam_connect_info bam_info; |
| 28 | |
| 29 | int send_sps_req(struct usb_ep *data_ep) |
| 30 | { |
| 31 | struct usb_request *req = NULL; |
| 32 | struct f_qdss *qdss = data_ep->driver_data; |
Manu Gautam | 76aa18b | 2012-07-25 17:12:37 +0530 | [diff] [blame] | 33 | struct usb_gadget *gadget = qdss->cdev->gadget; |
Shimrit Malichi | a00d732 | 2012-08-05 13:56:28 +0300 | [diff] [blame] | 34 | u32 sps_params = 0; |
| 35 | |
| 36 | pr_debug("send_sps_req\n"); |
| 37 | |
| 38 | req = usb_ep_alloc_request(data_ep, GFP_ATOMIC); |
| 39 | if (!req) { |
| 40 | pr_err("usb_ep_alloc_request failed\n"); |
| 41 | return -ENOMEM; |
| 42 | } |
| 43 | |
Manu Gautam | 76aa18b | 2012-07-25 17:12:37 +0530 | [diff] [blame] | 44 | if (gadget_is_dwc3(gadget)) { |
| 45 | req->length = 32*1024; |
| 46 | sps_params = MSM_SPS_MODE | MSM_DISABLE_WB | MSM_INTERNAL_MEM | |
| 47 | bam_info.usb_bam_pipe_idx; |
| 48 | } else { |
| 49 | /* non DWC3 BAM requires req->length to be 0 */ |
| 50 | req->length = 0; |
| 51 | sps_params = (MSM_SPS_MODE | bam_info.usb_bam_pipe_idx | |
| 52 | MSM_VENDOR_ID) & ~MSM_IS_FINITE_TRANSFER; |
| 53 | } |
Shimrit Malichi | a00d732 | 2012-08-05 13:56:28 +0300 | [diff] [blame] | 54 | req->udc_priv = sps_params; |
| 55 | qdss->endless_req = req; |
| 56 | if (usb_ep_queue(data_ep, req, GFP_ATOMIC)) { |
| 57 | pr_err("send_sps_req: usb_ep_queue error\n"); |
| 58 | return -EIO; |
| 59 | } |
| 60 | return 0; |
| 61 | } |
| 62 | |
| 63 | int set_qdss_data_connection(struct usb_ep *data_ep, u8 data_addr, int enable) |
| 64 | { |
| 65 | int res = 0; |
| 66 | |
| 67 | pr_debug("set_qdss_data_connection\n"); |
| 68 | |
| 69 | if (enable) { |
| 70 | res = usb_bam_connect(BAM_CONNC_IDX, NULL, |
| 71 | &(bam_info.usb_bam_pipe_idx)); |
| 72 | if (res) { |
| 73 | pr_err("usb_bam_connection error\n"); |
| 74 | return res; |
| 75 | } |
| 76 | |
| 77 | bam_info.data_fifo = |
| 78 | kzalloc(sizeof(struct sps_mem_buffer *), GFP_KERNEL); |
| 79 | if (!bam_info.data_fifo) { |
| 80 | pr_err("qdss_data_connection: memory alloc failed\n"); |
| 81 | return -ENOMEM; |
| 82 | } |
| 83 | get_bam2bam_connection_info(BAM_CONNC_IDX, |
| 84 | PEER_PERIPHERAL_TO_USB, &bam_info.usb_bam_handle, |
| 85 | &bam_info.usb_bam_pipe_idx, &bam_info.peer_pipe_idx, |
| 86 | NULL, bam_info.data_fifo); |
| 87 | |
| 88 | msm_data_fifo_config(data_ep, bam_info.data_fifo->phys_base, |
| 89 | bam_info.data_fifo->size, bam_info.usb_bam_pipe_idx); |
| 90 | } else { |
| 91 | kfree(bam_info.data_fifo); |
| 92 | res = usb_bam_disconnect_pipe(BAM_CONNC_IDX); |
| 93 | if (res) { |
| 94 | pr_err("usb_bam_disconnection error\n"); |
| 95 | return res; |
| 96 | } |
| 97 | |
| 98 | } |
| 99 | return res; |
| 100 | } |
| 101 | |
| 102 | int init_data(struct usb_ep *ep) |
| 103 | { |
Manu Gautam | 76aa18b | 2012-07-25 17:12:37 +0530 | [diff] [blame] | 104 | struct f_qdss *qdss = ep->driver_data; |
| 105 | struct usb_gadget *gadget = qdss->cdev->gadget; |
Shimrit Malichi | a00d732 | 2012-08-05 13:56:28 +0300 | [diff] [blame] | 106 | int res = 0; |
| 107 | |
| 108 | pr_debug("init_data\n"); |
| 109 | |
Manu Gautam | 76aa18b | 2012-07-25 17:12:37 +0530 | [diff] [blame] | 110 | if (gadget_is_dwc3(gadget)) { |
| 111 | res = msm_ep_config(ep); |
| 112 | if (res) |
| 113 | pr_err("msm_ep_config failed\n"); |
| 114 | } else { |
| 115 | pr_debug("QDSS is used with non DWC3 core\n"); |
| 116 | } |
Shimrit Malichi | a00d732 | 2012-08-05 13:56:28 +0300 | [diff] [blame] | 117 | |
| 118 | return res; |
| 119 | } |
| 120 | |
| 121 | int uninit_data(struct usb_ep *ep) |
| 122 | { |
Manu Gautam | 76aa18b | 2012-07-25 17:12:37 +0530 | [diff] [blame] | 123 | struct f_qdss *qdss = ep->driver_data; |
| 124 | struct usb_gadget *gadget = qdss->cdev->gadget; |
Shimrit Malichi | a00d732 | 2012-08-05 13:56:28 +0300 | [diff] [blame] | 125 | int res = 0; |
| 126 | |
| 127 | pr_err("uninit_data\n"); |
| 128 | |
Manu Gautam | 76aa18b | 2012-07-25 17:12:37 +0530 | [diff] [blame] | 129 | if (gadget_is_dwc3(gadget)) { |
| 130 | res = msm_ep_unconfig(ep); |
| 131 | if (res) |
| 132 | pr_err("msm_ep_config failed\n"); |
| 133 | } |
| 134 | |
Shimrit Malichi | a00d732 | 2012-08-05 13:56:28 +0300 | [diff] [blame] | 135 | return res; |
| 136 | } |