Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2009, 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/err.h> |
| 14 | #include <mach/rpc_hsusb.h> |
| 15 | #include <mach/msm_hsusb.h> |
| 16 | #include <mach/msm_rpcrouter.h> |
| 17 | #include <mach/board.h> |
| 18 | |
| 19 | #define PM_APP_OTG_PROG 0x30000080 |
| 20 | #define PM_APP_OTG_VERS 0x00010001 |
| 21 | |
| 22 | #define PM_APP_OTG_INIT_PHY 17 |
| 23 | #define PM_APP_OTG_RESET_PHY 18 |
| 24 | #define PM_APP_OTG_SUSPEND_PHY 7 |
| 25 | #define PM_APP_OTG_RESUME_PHY 8 |
| 26 | #define PM_APP_OTG_DEV_DISCONNECTED 9 |
| 27 | #define PM_APP_OTG_SET_WAKEUP 10 |
| 28 | #define PM_APP_OTG_ACQUIRE_BUS 3 |
| 29 | #define PM_APP_OTG_RELINQUISH_BUS 4 |
| 30 | |
| 31 | #define PM_APP_OTG_INIT_DONE_CB_PROC 1 |
| 32 | #define PM_APP_OTG_HOST_INIT_CB_PROC 3 |
| 33 | #define PM_APP_OTG_REMOTE_DEV_LOST_CB_PROC 8 |
| 34 | #define PM_APP_OTG_REMOTE_DEV_RESUMED_CB_PROC 9 |
| 35 | #define PM_APP_OTG_ERROR_NOTIFY_CB_PROC 11 |
| 36 | |
| 37 | #define NUM_OF_CALLBACKS 11 |
| 38 | static struct msm_rpc_client *client; |
| 39 | static struct msm_otg_ops *host_ops; |
| 40 | |
| 41 | static int msm_fsusb_rpc_arg(struct msm_rpc_client *client, |
| 42 | void *buf, void *data) |
| 43 | { |
| 44 | int i, size = 0; |
| 45 | uint32_t proc = *(uint32_t *)data; |
| 46 | |
| 47 | switch (proc) { |
| 48 | case PM_APP_OTG_INIT_PHY: { |
| 49 | for (i = 0; i < NUM_OF_CALLBACKS; i++) { |
| 50 | *((uint32_t *)buf) = cpu_to_be32(0x11111111); |
| 51 | size += sizeof(uint32_t); |
| 52 | buf += sizeof(uint32_t); |
| 53 | } |
| 54 | |
| 55 | /* sleep_assert callback fucntion will be registered locally*/ |
| 56 | *((uint32_t *)buf) = cpu_to_be32(0xffffffff); |
| 57 | size += sizeof(uint32_t); |
| 58 | break; |
| 59 | } |
| 60 | case PM_APP_OTG_SET_WAKEUP: { |
| 61 | *((uint32_t *)buf) = cpu_to_be32(1); |
| 62 | size += sizeof(uint32_t); |
| 63 | break; |
| 64 | } |
| 65 | case PM_APP_OTG_ACQUIRE_BUS: { |
| 66 | *((uint32_t *)buf) = cpu_to_be32(0xffffffff); |
| 67 | size += sizeof(uint32_t); |
| 68 | break; |
| 69 | } |
| 70 | default: |
| 71 | pr_info("%s: No arguments expected\n", __func__); |
| 72 | } |
| 73 | return size; |
| 74 | } |
| 75 | |
| 76 | int msm_fsusb_init_phy(void) |
| 77 | { |
| 78 | uint32_t data = PM_APP_OTG_INIT_PHY; |
| 79 | |
| 80 | return msm_rpc_client_req(client, |
| 81 | PM_APP_OTG_INIT_PHY, |
| 82 | msm_fsusb_rpc_arg, &data, |
| 83 | NULL, NULL, -1); |
| 84 | } |
| 85 | EXPORT_SYMBOL(msm_fsusb_init_phy); |
| 86 | |
| 87 | int msm_fsusb_reset_phy(void) |
| 88 | { |
| 89 | return msm_rpc_client_req(client, |
| 90 | PM_APP_OTG_RESET_PHY, |
| 91 | NULL, NULL, |
| 92 | NULL, NULL, -1); |
| 93 | |
| 94 | } |
| 95 | EXPORT_SYMBOL(msm_fsusb_reset_phy); |
| 96 | |
| 97 | int msm_fsusb_suspend_phy(void) |
| 98 | { |
| 99 | return msm_rpc_client_req(client, |
| 100 | PM_APP_OTG_SUSPEND_PHY, |
| 101 | NULL, NULL, |
| 102 | NULL, NULL, -1); |
| 103 | |
| 104 | } |
| 105 | EXPORT_SYMBOL(msm_fsusb_suspend_phy); |
| 106 | |
| 107 | int msm_fsusb_resume_phy(void) |
| 108 | { |
| 109 | return msm_rpc_client_req(client, |
| 110 | PM_APP_OTG_RESUME_PHY, |
| 111 | NULL, NULL, |
| 112 | NULL, NULL, -1); |
| 113 | |
| 114 | } |
| 115 | EXPORT_SYMBOL(msm_fsusb_resume_phy); |
| 116 | |
| 117 | int msm_fsusb_remote_dev_disconnected(void) |
| 118 | { |
| 119 | return msm_rpc_client_req(client, |
| 120 | PM_APP_OTG_DEV_DISCONNECTED, |
| 121 | NULL, NULL, |
| 122 | NULL, NULL, -1); |
| 123 | |
| 124 | } |
| 125 | EXPORT_SYMBOL(msm_fsusb_remote_dev_disconnected); |
| 126 | |
| 127 | int msm_fsusb_set_remote_wakeup(void) |
| 128 | { |
| 129 | uint32_t data = PM_APP_OTG_SET_WAKEUP; |
| 130 | |
| 131 | return msm_rpc_client_req(client, |
| 132 | PM_APP_OTG_SET_WAKEUP, |
| 133 | msm_fsusb_rpc_arg, &data, |
| 134 | NULL, NULL, -1); |
| 135 | |
| 136 | } |
| 137 | EXPORT_SYMBOL(msm_fsusb_set_remote_wakeup); |
| 138 | |
| 139 | static int msm_fsusb_acquire_bus(void) |
| 140 | { |
| 141 | uint32_t data = PM_APP_OTG_ACQUIRE_BUS; |
| 142 | |
| 143 | return msm_rpc_client_req(client, |
| 144 | PM_APP_OTG_ACQUIRE_BUS, |
| 145 | msm_fsusb_rpc_arg, &data, |
| 146 | NULL, NULL, -1); |
| 147 | |
| 148 | } |
| 149 | |
| 150 | static int msm_fsusb_relinquish_bus(void) |
| 151 | { |
| 152 | return msm_rpc_client_req(client, |
| 153 | PM_APP_OTG_RELINQUISH_BUS, |
| 154 | NULL, NULL, |
| 155 | NULL, NULL, -1); |
| 156 | |
| 157 | } |
| 158 | |
| 159 | static void msm_fsusb_request_session(void) |
| 160 | { |
| 161 | int ret; |
| 162 | |
| 163 | ret = msm_fsusb_relinquish_bus(); |
| 164 | if (ret < 0) |
| 165 | pr_err("relinquish_bus rpc failed\n"); |
| 166 | ret = msm_fsusb_acquire_bus(); |
| 167 | if (ret < 0) |
| 168 | pr_err("acquire_bus rpc failed\n"); |
| 169 | } |
| 170 | |
| 171 | static int msm_fsusb_cb_func(struct msm_rpc_client *client, |
| 172 | void *buffer, int in_size) |
| 173 | { |
| 174 | struct rpc_request_hdr *req; |
| 175 | int rc; |
| 176 | |
| 177 | req = buffer; |
| 178 | |
| 179 | msm_rpc_start_accepted_reply(client, be32_to_cpu(req->xid), |
| 180 | RPC_ACCEPTSTAT_SUCCESS); |
| 181 | rc = msm_rpc_send_accepted_reply(client, 0); |
| 182 | if (rc) { |
| 183 | pr_err("%s: sending reply failed: %d\n", __func__, rc); |
| 184 | return rc; |
| 185 | } |
| 186 | |
| 187 | switch (be32_to_cpu(req->procedure)) { |
| 188 | case PM_APP_OTG_INIT_DONE_CB_PROC: { |
| 189 | pr_debug("pm_app_otg_init_done callback received"); |
| 190 | msm_fsusb_request_session(); |
| 191 | break; |
| 192 | } |
| 193 | case PM_APP_OTG_HOST_INIT_CB_PROC: { |
| 194 | pr_debug("pm_app_otg_host_init_cb_proc callback received"); |
| 195 | host_ops->request(host_ops->handle, REQUEST_START); |
| 196 | break; |
| 197 | } |
| 198 | case PM_APP_OTG_REMOTE_DEV_LOST_CB_PROC: { |
| 199 | pr_debug("pm_app_otg_remote_dev_lost_cb_proc" |
| 200 | " callback received"); |
| 201 | msm_fsusb_acquire_bus(); |
| 202 | host_ops->request(host_ops->handle, REQUEST_STOP); |
| 203 | break; |
| 204 | } |
| 205 | case PM_APP_OTG_REMOTE_DEV_RESUMED_CB_PROC: { |
| 206 | pr_debug("pm_app_otg_remote_dev_resumed_cb_proc" |
| 207 | "callback received"); |
| 208 | host_ops->request(host_ops->handle, REQUEST_RESUME); |
| 209 | break; |
| 210 | } |
| 211 | case PM_APP_OTG_ERROR_NOTIFY_CB_PROC: { |
| 212 | pr_err("pm_app_otg_error_notify_cb_proc callback received"); |
| 213 | break; |
| 214 | } |
| 215 | default: |
| 216 | pr_err("%s: unknown callback(proc = %d) received\n", |
| 217 | __func__, req->procedure); |
| 218 | } |
| 219 | return 0; |
| 220 | } |
| 221 | |
| 222 | int msm_fsusb_rpc_init(struct msm_otg_ops *ops) |
| 223 | { |
| 224 | host_ops = ops; |
| 225 | client = msm_rpc_register_client("fsusb", |
| 226 | PM_APP_OTG_PROG, |
| 227 | PM_APP_OTG_VERS, 1, |
| 228 | msm_fsusb_cb_func); |
| 229 | if (IS_ERR(client)) { |
| 230 | pr_err("%s: couldn't open rpc client\n", __func__); |
| 231 | return PTR_ERR(client); |
| 232 | } |
| 233 | |
| 234 | return 0; |
| 235 | |
| 236 | } |
| 237 | EXPORT_SYMBOL(msm_fsusb_rpc_init); |
| 238 | |
| 239 | void msm_fsusb_rpc_deinit(void) |
| 240 | { |
| 241 | msm_rpc_unregister_client(client); |
| 242 | } |
| 243 | EXPORT_SYMBOL(msm_fsusb_rpc_deinit); |