4039eae8ad9c683e243d8a3179b70320c392c897
[open-ath9k-htc-firmware.git] / target_firmware / magpie_fw_dev / target / init / magpie.c
1 #include "sys_cfg.h"
2
3 #if defined(_RAM_)
4
5 #include "dt_defs.h"
6 #include "athos_api.h"
7
8 #include "adf_os_mem.h"
9
10 #define MAGPIE 1
11
12 #if MAGPIE==1
13
14 void htc_setup_comp(void)
15 {
16 }
17
18 /* target WMI command related globals */
19 static void dispatch_magpie_sys_cmds(void *pContext, A_UINT16 Command,
20                                      A_UINT16 SeqNo, A_UINT8 *buffer, int Length);
21
22 static WMI_DISPATCH_ENTRY Magpie_Sys_DispatchEntries[] =
23 {
24         {dispatch_magpie_sys_cmds,  WMI_ECHO_CMDID, 0},
25         {dispatch_magpie_sys_cmds,  WMI_ACCESS_MEMORY_CMDID, 0}
26 };
27
28 static WMI_DECLARE_DISPATCH_TABLE(Magpie_Sys_Commands_Tbl, Magpie_Sys_DispatchEntries);
29
30 htc_handle_t htc_handle;
31
32 extern void HTC_Loopback_Init(htc_handle_t handle);
33 extern void _wmi_cmd_rsp(void *pContext, WMI_COMMAND_ID cmd_id,
34                          A_UINT16 SeqNo, A_UINT8 *buffer, int Length);
35
36 static void handle_echo_command(void *pContext, A_UINT16 SeqNo,
37                                 A_UINT8 *buffer, int Length)
38 {
39         _wmi_cmd_rsp(pContext, WMI_ECHO_CMDID, SeqNo, buffer, Length);
40 }
41
42 static void dispatch_magpie_sys_cmds(void *pContext, A_UINT16 Command,
43                                      A_UINT16 SeqNo, A_UINT8 *buffer, int Length)
44 {
45         switch(Command)
46         {
47         case WMI_ECHO_CMDID:
48                 handle_echo_command(pContext, SeqNo, buffer, Length);
49                 break;
50
51         case WMI_ACCESS_MEMORY_CMDID:
52                 break;
53         }
54 }
55
56 void _wmi_cmd_rsp(void *pContext, WMI_COMMAND_ID cmd_id, A_UINT16 SeqNo,
57                   A_UINT8 *buffer, int Length)
58 {
59         adf_nbuf_t netbuf = ADF_NBUF_NULL;
60         A_UINT8 *pData;
61
62         netbuf = WMI_AllocEvent(pContext, WMI_EVT_CLASS_CMD_REPLY, sizeof(WMI_CMD_HDR) + Length);
63     
64         if (netbuf == ADF_NBUF_NULL) {
65                 adf_os_print("%s: buffer allocation for event_id %x failed!\n", __FUNCTION__, cmd_id);
66                 adf_os_assert(0);
67                 return;
68         }
69
70         if (Length != 0 && buffer != NULL) {
71                 pData = (A_UINT8 *)adf_nbuf_put_tail(netbuf, Length);
72                 adf_os_mem_copy(pData, buffer, Length);
73         }
74
75         WMI_SendEvent(pContext, netbuf, cmd_id, SeqNo, Length);
76 }
77
78
79 void Magpie_init(void)
80 {
81         A_PRINTF("[+++Magpie_init]\n\r");
82  
83         A_PRINTF("[+++VBUF_init(%d)]\n\r", MAX_BUF_NUM);
84         VBUF_init(MAX_BUF_NUM);
85     
86         A_PRINTF("[+++VBUF_init(%d)]\n\r", MAX_DESC_NUM);
87         VDESC_init(MAX_DESC_NUM);
88
89 #if MAGPIE_ENABLE_WLAN == 0
90         aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
91                 hif_handle = HIF_init(0);
92
93 #if ZM_FM_LOOPBACK == 1
94         HIF_config_pipe(hif_handle, HIF_USB_PIPE_TX, 5);
95         HIF_config_pipe(hif_handle, HIF_USB_PIPE_COMMAND, 2);
96
97 #if SYSTEM_MODULE_HP_EP5
98         HIF_config_pipe(hif_handle, HIF_USB_PIPE_HP_TX, 3);
99 #endif
100 #if SYSTEM_MODULE_HP_EP6
101         HIF_config_pipe(hif_handle, HIF_USB_PIPE_MP_TX, 3);
102 #endif
103     
104         A_PRINTF("[+++HIF_init(0)]\n\r");
105
106         HIF_start(hif_handle);
107
108 #else /* ZM_FM_LOOPBACK == 0 */
109         // initialize HTC
110         htcConf.CreditSize = 320;
111         htcConf.CreditNumber = 10;
112 #if 1
113         htcConf.ControlDownLinkPipeID = HIF_USB_PIPE_INTERRUPT;         // Target -> Host
114         htcConf.ControlUpLinkPipeID = HIF_USB_PIPE_COMMAND;             // Host   -> Target
115 #else
116         htcConf.ControlDownLinkPipeID = HIF_USB_PIPE_RX;
117         htcConf.ControlUpLinkPipeID = HIF_USB_PIPE_TX;
118 #endif
119         htcConf.HIFHandle = hif_handle;
120         htcConf.OSHandle = 0;             // not used
121         htcConf.PoolHandle = pool_handle;
122
123         htc_handle = HTC_init(htc_setup_comp, &htcConf);
124         // Initialize HTC services
125         HTC_Loopback_Init(htc_handle);
126
127         adf_os_mem_zero(&wmiConfig, sizeof(WMI_SVC_CONFIG));
128         wmiConfig.HtcHandle = htc_handle;
129         wmiConfig.PoolHandle = pool_handle;
130         wmiConfig.MaxCmdReplyEvts = 1;
131         wmiConfig.MaxEventEvts = 1;
132
133         wmi_handle = WMI_Init(&wmiConfig);
134         Magpie_Sys_Commands_Tbl.pContext = wmi_handle;
135         WMI_RegisterDispatchTable(Magpie_Sys_Commands_Tbl.pContext, &Magpie_Sys_Commands_Tbl);
136
137 #endif/* ZM_FM_LOOPBACK == 0 */
138 #endif /* MAGPIE_ENABLE_WLAN */                 
139 }
140
141 #endif /* #if MAGPIE==1 */
142
143 #endif /* #if defined(_RAM_) */