Setting up repository
[linux-libre-firmware.git] / ath9k_htc / target_firmware / magpie_fw_dev / target / init / magpie.c
1 /*
2  * Copyright (c) 2013 Qualcomm Atheros, Inc.
3  * All rights reserved.
4  *
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:
8  *
9  *  * Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  *
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
15  *    distribution.
16  *
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.
20  *
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.
34  */
35 #include "sys_cfg.h"
36
37 #if defined(_RAM_)
38
39 #include "dt_defs.h"
40 #include "athos_api.h"
41
42 #include "adf_os_mem.h"
43
44 #define MAGPIE 1
45
46 #if MAGPIE==1
47
48 void htc_setup_comp(void)
49 {
50 }
51
52 /* target WMI command related globals */
53 static void dispatch_magpie_sys_cmds(void *pContext, A_UINT16 Command,
54                                      A_UINT16 SeqNo, A_UINT8 *buffer, int Length);
55
56 #if MAGPIE_ENABLE_WLAN == 0
57 static WMI_DISPATCH_ENTRY Magpie_Sys_DispatchEntries[] =
58 {
59         {dispatch_magpie_sys_cmds,  WMI_ECHO_CMDID, 0},
60         {dispatch_magpie_sys_cmds,  WMI_ACCESS_MEMORY_CMDID, 0}
61 };
62
63 static WMI_DECLARE_DISPATCH_TABLE(Magpie_Sys_Commands_Tbl, Magpie_Sys_DispatchEntries);
64 #endif
65
66 htc_handle_t htc_handle;
67
68 extern void HTC_Loopback_Init(htc_handle_t handle);
69 extern void _wmi_cmd_rsp(void *pContext, WMI_COMMAND_ID cmd_id,
70                          A_UINT16 SeqNo, A_UINT8 *buffer, int Length);
71
72 static void handle_echo_command(void *pContext, A_UINT16 SeqNo,
73                                 A_UINT8 *buffer, int Length)
74 {
75         _wmi_cmd_rsp(pContext, WMI_ECHO_CMDID, SeqNo, buffer, Length);
76 }
77
78 static void dispatch_magpie_sys_cmds(void *pContext, A_UINT16 Command,
79                                      A_UINT16 SeqNo, A_UINT8 *buffer, int Length)
80 {
81         switch(Command)
82         {
83         case WMI_ECHO_CMDID:
84                 handle_echo_command(pContext, SeqNo, buffer, Length);
85                 break;
86
87         case WMI_ACCESS_MEMORY_CMDID:
88                 break;
89         }
90 }
91
92 void _wmi_cmd_rsp(void *pContext, WMI_COMMAND_ID cmd_id, A_UINT16 SeqNo,
93                   A_UINT8 *buffer, int Length)
94 {
95         adf_nbuf_t netbuf = ADF_NBUF_NULL;
96         A_UINT8 *pData;
97
98         netbuf = WMI_AllocEvent(pContext, WMI_EVT_CLASS_CMD_REPLY, sizeof(WMI_CMD_HDR) + Length);
99     
100         if (netbuf == ADF_NBUF_NULL) {
101                 adf_os_print("%s: buffer allocation for event_id %x failed!\n", __FUNCTION__, cmd_id);
102                 adf_os_assert(0);
103                 return;
104         }
105
106         if (Length != 0 && buffer != NULL) {
107                 pData = (A_UINT8 *)adf_nbuf_put_tail(netbuf, Length);
108                 adf_os_mem_copy(pData, buffer, Length);
109         }
110
111         WMI_SendEvent(pContext, netbuf, cmd_id, SeqNo, Length);
112 }
113
114
115 void Magpie_init(void)
116 {
117         A_PRINTF("[+++Magpie_init]\n\r");
118  
119         A_PRINTF("[+++VBUF_init(%d)]\n\r", MAX_BUF_NUM);
120         VBUF_init(MAX_BUF_NUM);
121     
122         A_PRINTF("[+++VBUF_init(%d)]\n\r", MAX_DESC_NUM);
123         VDESC_init(MAX_DESC_NUM);
124
125 #if MAGPIE_ENABLE_WLAN == 0
126         aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
127                 hif_handle = HIF_init(0);
128
129 #if ZM_FM_LOOPBACK == 1
130         HIF_config_pipe(hif_handle, HIF_USB_PIPE_TX, 5);
131         HIF_config_pipe(hif_handle, HIF_USB_PIPE_COMMAND, 2);
132
133 #if SYSTEM_MODULE_HP_EP5
134         HIF_config_pipe(hif_handle, HIF_USB_PIPE_HP_TX, 3);
135 #endif
136 #if SYSTEM_MODULE_HP_EP6
137         HIF_config_pipe(hif_handle, HIF_USB_PIPE_MP_TX, 3);
138 #endif
139     
140         A_PRINTF("[+++HIF_init(0)]\n\r");
141
142         HIF_start(hif_handle);
143
144 #else /* ZM_FM_LOOPBACK == 0 */
145         // initialize HTC
146         htcConf.CreditSize = 320;
147         htcConf.CreditNumber = 10;
148 #if 1
149         htcConf.ControlDownLinkPipeID = HIF_USB_PIPE_INTERRUPT;         // Target -> Host
150         htcConf.ControlUpLinkPipeID = HIF_USB_PIPE_COMMAND;             // Host   -> Target
151 #else
152         htcConf.ControlDownLinkPipeID = HIF_USB_PIPE_RX;
153         htcConf.ControlUpLinkPipeID = HIF_USB_PIPE_TX;
154 #endif
155         htcConf.HIFHandle = hif_handle;
156         htcConf.OSHandle = 0;             // not used
157         htcConf.PoolHandle = pool_handle;
158
159         htc_handle = HTC_init(htc_setup_comp, &htcConf);
160         // Initialize HTC services
161         HTC_Loopback_Init(htc_handle);
162
163         adf_os_mem_zero(&wmiConfig, sizeof(WMI_SVC_CONFIG));
164         wmiConfig.HtcHandle = htc_handle;
165         wmiConfig.PoolHandle = pool_handle;
166         wmiConfig.MaxCmdReplyEvts = 1;
167         wmiConfig.MaxEventEvts = 1;
168
169         wmi_handle = WMI_Init(&wmiConfig);
170         Magpie_Sys_Commands_Tbl.pContext = wmi_handle;
171         WMI_RegisterDispatchTable(Magpie_Sys_Commands_Tbl.pContext, &Magpie_Sys_Commands_Tbl);
172
173 #endif/* ZM_FM_LOOPBACK == 0 */
174 #endif /* MAGPIE_ENABLE_WLAN */                 
175 }
176
177 #endif /* #if MAGPIE==1 */
178
179 #endif /* #if defined(_RAM_) */