2 * Copyright (c) 2013 Qualcomm Atheros, Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted (subject to the limitations in the
7 * disclaimer below) provided that the following conditions are met:
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the
17 * * Neither the name of Qualcomm Atheros nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
22 * GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
23 * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
24 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
30 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
32 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
33 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 #include "app_start.h"
41 #include "athos_api.h"
43 #include "adf_os_mem.h"
49 void htc_setup_comp(void)
53 /* target WMI command related globals */
54 static void dispatch_magpie_sys_cmds(void *pContext, A_UINT16 Command,
55 A_UINT16 SeqNo, A_UINT8 *buffer, int Length);
57 #if MAGPIE_ENABLE_WLAN == 0
58 static WMI_DISPATCH_ENTRY Magpie_Sys_DispatchEntries[] =
60 {dispatch_magpie_sys_cmds, WMI_ECHO_CMDID, 0},
61 {dispatch_magpie_sys_cmds, WMI_ACCESS_MEMORY_CMDID, 0}
64 static WMI_DECLARE_DISPATCH_TABLE(Magpie_Sys_Commands_Tbl, Magpie_Sys_DispatchEntries);
67 htc_handle_t htc_handle;
69 extern void HTC_Loopback_Init(htc_handle_t handle);
70 extern void _wmi_cmd_rsp(void *pContext, WMI_COMMAND_ID cmd_id,
71 A_UINT16 SeqNo, A_UINT8 *buffer, int Length);
73 static void handle_echo_command(void *pContext, A_UINT16 SeqNo,
74 A_UINT8 *buffer, int Length)
76 _wmi_cmd_rsp(pContext, WMI_ECHO_CMDID, SeqNo, buffer, Length);
79 static void dispatch_magpie_sys_cmds(void *pContext, A_UINT16 Command,
80 A_UINT16 SeqNo, A_UINT8 *buffer, int Length)
85 handle_echo_command(pContext, SeqNo, buffer, Length);
88 case WMI_ACCESS_MEMORY_CMDID:
93 void _wmi_cmd_rsp(void *pContext, WMI_COMMAND_ID cmd_id, A_UINT16 SeqNo,
94 A_UINT8 *buffer, int Length)
96 adf_nbuf_t netbuf = ADF_NBUF_NULL;
99 netbuf = WMI_AllocEvent(pContext, WMI_EVT_CLASS_CMD_REPLY, sizeof(WMI_CMD_HDR) + Length);
101 if (netbuf == ADF_NBUF_NULL) {
102 adf_os_print("%s: buffer allocation for event_id %x failed!\n", __FUNCTION__, cmd_id);
107 if (Length != 0 && buffer != NULL) {
108 pData = (A_UINT8 *)adf_nbuf_put_tail(netbuf, Length);
109 adf_os_mem_copy(pData, buffer, Length);
112 WMI_SendEvent(pContext, netbuf, cmd_id, SeqNo, Length);
116 void Magpie_init(void)
118 A_PRINTF("[+++Magpie_init]\n\r");
120 A_PRINTF("[+++VBUF_init(%d)]\n\r", MAX_BUF_NUM);
121 VBUF_init(MAX_BUF_NUM);
123 A_PRINTF("[+++VBUF_init(%d)]\n\r", MAX_DESC_NUM);
124 VDESC_init(MAX_DESC_NUM);
126 #if MAGPIE_ENABLE_WLAN == 0
127 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
128 hif_handle = HIF_init(0);
130 #if ZM_FM_LOOPBACK == 1
131 HIF_config_pipe(hif_handle, HIF_USB_PIPE_TX, 5);
132 HIF_config_pipe(hif_handle, HIF_USB_PIPE_COMMAND, 2);
134 #if SYSTEM_MODULE_HP_EP5
135 HIF_config_pipe(hif_handle, HIF_USB_PIPE_HP_TX, 3);
137 #if SYSTEM_MODULE_HP_EP6
138 HIF_config_pipe(hif_handle, HIF_USB_PIPE_MP_TX, 3);
141 A_PRINTF("[+++HIF_init(0)]\n\r");
143 HIF_start(hif_handle);
145 #else /* ZM_FM_LOOPBACK == 0 */
147 htcConf.CreditSize = 320;
148 htcConf.CreditNumber = 10;
150 htcConf.ControlDownLinkPipeID = HIF_USB_PIPE_INTERRUPT; // Target -> Host
151 htcConf.ControlUpLinkPipeID = HIF_USB_PIPE_COMMAND; // Host -> Target
153 htcConf.ControlDownLinkPipeID = HIF_USB_PIPE_RX;
154 htcConf.ControlUpLinkPipeID = HIF_USB_PIPE_TX;
156 htcConf.HIFHandle = hif_handle;
157 htcConf.OSHandle = 0; // not used
158 htcConf.PoolHandle = pool_handle;
160 htc_handle = HTC_init(htc_setup_comp, &htcConf);
161 // Initialize HTC services
162 HTC_Loopback_Init(htc_handle);
164 adf_os_mem_zero(&wmiConfig, sizeof(WMI_SVC_CONFIG));
165 wmiConfig.HtcHandle = htc_handle;
166 wmiConfig.PoolHandle = pool_handle;
167 wmiConfig.MaxCmdReplyEvts = 1;
168 wmiConfig.MaxEventEvts = 1;
170 wmi_handle = WMI_Init(&wmiConfig);
171 Magpie_Sys_Commands_Tbl.pContext = wmi_handle;
172 WMI_RegisterDispatchTable(Magpie_Sys_Commands_Tbl.pContext, &Magpie_Sys_Commands_Tbl);
174 #endif/* ZM_FM_LOOPBACK == 0 */
175 #endif /* MAGPIE_ENABLE_WLAN */
178 #endif /* #if MAGPIE==1 */
180 #endif /* #if defined(_RAM_) */