Shimrit Malichi | a00d732 | 2012-08-05 13:56:28 +0300 | [diff] [blame^] | 1 | /* Copyright (c) 2012, Code Aurora Forum. All rights reserved. |
| 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; |
| 33 | u32 sps_params = 0; |
| 34 | |
| 35 | pr_debug("send_sps_req\n"); |
| 36 | |
| 37 | req = usb_ep_alloc_request(data_ep, GFP_ATOMIC); |
| 38 | if (!req) { |
| 39 | pr_err("usb_ep_alloc_request failed\n"); |
| 40 | return -ENOMEM; |
| 41 | } |
| 42 | |
| 43 | req->length = 32*1024; |
| 44 | |
| 45 | sps_params = MSM_SPS_MODE | MSM_DISABLE_WB | MSM_INTERNAL_MEM | |
| 46 | bam_info.usb_bam_pipe_idx; |
| 47 | req->udc_priv = sps_params; |
| 48 | qdss->endless_req = req; |
| 49 | if (usb_ep_queue(data_ep, req, GFP_ATOMIC)) { |
| 50 | pr_err("send_sps_req: usb_ep_queue error\n"); |
| 51 | return -EIO; |
| 52 | } |
| 53 | return 0; |
| 54 | } |
| 55 | |
| 56 | int set_qdss_data_connection(struct usb_ep *data_ep, u8 data_addr, int enable) |
| 57 | { |
| 58 | int res = 0; |
| 59 | |
| 60 | pr_debug("set_qdss_data_connection\n"); |
| 61 | |
| 62 | if (enable) { |
| 63 | res = usb_bam_connect(BAM_CONNC_IDX, NULL, |
| 64 | &(bam_info.usb_bam_pipe_idx)); |
| 65 | if (res) { |
| 66 | pr_err("usb_bam_connection error\n"); |
| 67 | return res; |
| 68 | } |
| 69 | |
| 70 | bam_info.data_fifo = |
| 71 | kzalloc(sizeof(struct sps_mem_buffer *), GFP_KERNEL); |
| 72 | if (!bam_info.data_fifo) { |
| 73 | pr_err("qdss_data_connection: memory alloc failed\n"); |
| 74 | return -ENOMEM; |
| 75 | } |
| 76 | get_bam2bam_connection_info(BAM_CONNC_IDX, |
| 77 | PEER_PERIPHERAL_TO_USB, &bam_info.usb_bam_handle, |
| 78 | &bam_info.usb_bam_pipe_idx, &bam_info.peer_pipe_idx, |
| 79 | NULL, bam_info.data_fifo); |
| 80 | |
| 81 | msm_data_fifo_config(data_ep, bam_info.data_fifo->phys_base, |
| 82 | bam_info.data_fifo->size, bam_info.usb_bam_pipe_idx); |
| 83 | } else { |
| 84 | kfree(bam_info.data_fifo); |
| 85 | res = usb_bam_disconnect_pipe(BAM_CONNC_IDX); |
| 86 | if (res) { |
| 87 | pr_err("usb_bam_disconnection error\n"); |
| 88 | return res; |
| 89 | } |
| 90 | |
| 91 | } |
| 92 | return res; |
| 93 | } |
| 94 | |
| 95 | int init_data(struct usb_ep *ep) |
| 96 | { |
| 97 | int res = 0; |
| 98 | |
| 99 | pr_debug("init_data\n"); |
| 100 | |
| 101 | res = msm_ep_config(ep); |
| 102 | if (res) |
| 103 | pr_err("msm_ep_config failed\n"); |
| 104 | |
| 105 | return res; |
| 106 | } |
| 107 | |
| 108 | int uninit_data(struct usb_ep *ep) |
| 109 | { |
| 110 | int res = 0; |
| 111 | |
| 112 | pr_err("uninit_data\n"); |
| 113 | |
| 114 | res = msm_ep_unconfig(ep); |
| 115 | if (res) |
| 116 | pr_err("msm_ep_config failed\n"); |
| 117 | return res; |
| 118 | } |