u_qdss.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /* Copyright (c) 2012-2013, The Linux Foundation. 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. #include <linux/kernel.h>
  13. #include <linux/device.h>
  14. #include <linux/usb/msm_hsusb.h>
  15. #include <mach/usb_bam.h>
  16. #include "gadget_chips.h"
  17. struct usb_qdss_bam_connect_info {
  18. u32 usb_bam_pipe_idx;
  19. u32 peer_pipe_idx;
  20. u32 usb_bam_handle;
  21. struct sps_mem_buffer *data_fifo;
  22. };
  23. static struct usb_qdss_bam_connect_info bam_info;
  24. int send_sps_req(struct usb_ep *data_ep)
  25. {
  26. struct usb_request *req = NULL;
  27. struct f_qdss *qdss = data_ep->driver_data;
  28. struct usb_gadget *gadget = qdss->cdev->gadget;
  29. u32 sps_params = 0;
  30. pr_debug("send_sps_req\n");
  31. req = usb_ep_alloc_request(data_ep, GFP_ATOMIC);
  32. if (!req) {
  33. pr_err("usb_ep_alloc_request failed\n");
  34. return -ENOMEM;
  35. }
  36. if (gadget_is_dwc3(gadget)) {
  37. req->length = 32*1024;
  38. sps_params = MSM_SPS_MODE | MSM_DISABLE_WB | MSM_INTERNAL_MEM |
  39. bam_info.usb_bam_pipe_idx;
  40. } else {
  41. /* non DWC3 BAM requires req->length to be 0 */
  42. req->length = 0;
  43. sps_params = (MSM_SPS_MODE | bam_info.usb_bam_pipe_idx |
  44. MSM_VENDOR_ID) & ~MSM_IS_FINITE_TRANSFER;
  45. }
  46. req->udc_priv = sps_params;
  47. qdss->endless_req = req;
  48. if (usb_ep_queue(data_ep, req, GFP_ATOMIC)) {
  49. pr_err("send_sps_req: usb_ep_queue error\n");
  50. return -EIO;
  51. }
  52. return 0;
  53. }
  54. static int set_qdss_data_connection(struct usb_gadget *gadget,
  55. struct usb_ep *data_ep, u8 data_addr, int enable)
  56. {
  57. int res = 0;
  58. u8 idx;
  59. pr_debug("set_qdss_data_connection\n");
  60. /* There is only one qdss pipe, so the pipe number can be set to 0 */
  61. idx = usb_bam_get_connection_idx(gadget->name, QDSS_P_BAM,
  62. PEER_PERIPHERAL_TO_USB, 0);
  63. if (idx < 0) {
  64. pr_err("%s: usb_bam_get_connection_idx failed\n", __func__);
  65. return idx;
  66. }
  67. if (enable) {
  68. res = usb_bam_connect(idx, &(bam_info.usb_bam_pipe_idx));
  69. bam_info.data_fifo =
  70. kzalloc(sizeof(struct sps_mem_buffer), GFP_KERNEL);
  71. if (!bam_info.data_fifo) {
  72. pr_err("qdss_data_connection: memory alloc failed\n");
  73. return -ENOMEM;
  74. }
  75. usb_bam_set_qdss_core(gadget->name);
  76. get_bam2bam_connection_info(idx,
  77. &bam_info.usb_bam_handle,
  78. &bam_info.usb_bam_pipe_idx, &bam_info.peer_pipe_idx,
  79. NULL, bam_info.data_fifo);
  80. if (gadget_is_dwc3(gadget))
  81. msm_data_fifo_config(data_ep,
  82. bam_info.data_fifo->phys_base,
  83. bam_info.data_fifo->size,
  84. bam_info.usb_bam_pipe_idx);
  85. } else {
  86. kfree(bam_info.data_fifo);
  87. res = usb_bam_disconnect_pipe(idx);
  88. if (res) {
  89. pr_err("usb_bam_disconnection error\n");
  90. return res;
  91. }
  92. }
  93. return res;
  94. }
  95. int init_data(struct usb_ep *ep)
  96. {
  97. struct f_qdss *qdss = ep->driver_data;
  98. struct usb_gadget *gadget = qdss->cdev->gadget;
  99. int res = 0;
  100. pr_debug("init_data\n");
  101. if (gadget_is_dwc3(gadget)) {
  102. res = msm_ep_config(ep);
  103. if (res)
  104. pr_err("msm_ep_config failed\n");
  105. } else {
  106. pr_debug("QDSS is used with non DWC3 core\n");
  107. }
  108. return res;
  109. }
  110. int uninit_data(struct usb_ep *ep)
  111. {
  112. struct f_qdss *qdss = ep->driver_data;
  113. struct usb_gadget *gadget = qdss->cdev->gadget;
  114. int res = 0;
  115. pr_err("uninit_data\n");
  116. if (gadget_is_dwc3(gadget)) {
  117. res = msm_ep_unconfig(ep);
  118. if (res)
  119. pr_err("msm_ep_unconfig failed\n");
  120. }
  121. return res;
  122. }