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.
37 #if SYSTEM_MODULE_MISC
39 #include "athos_api.h"
43 extern uint16_t UsbDeviceDescriptor[];
46 /* This number gets bumped on each official build. */
47 // uint32_t cmnos_target_software_id = AR6K_SW_VERSION;
53 cmnos_system_reset(void)
55 /* TBD: to be finished */
57 * sytem reset backdoor
59 HAL_WORD_REG_WRITE(MAGPIE_REG_RST_RESET_ADDR, (0x1<<24));
66 #LOCAL void cmnos_wdt_reset(void)
68 HAL_WORD_REG_WRITE(MAGPIE_REG_RST_RESET_ADDR, (0x1<<24));
78 /* TBD: to be finished */
84 volatile int assloop = 1;
87 //A_COMPILE_TIME_ASSERT(verify_RD_SIZE, (RD_SIZE == sizeof(CPU_exception_frame_t)))
90 cmnos_misaligned_load_handler(struct register_dump_s *dump)
92 /* TBD: to be finished */
93 if (A_IML_IS_ASSERT(dump->badvaddr)) {
95 * Probably an Intentional Misaligned Load, used to
96 * signal an assertion failure
98 dump->assline = A_IML_ASSLINE(dump->badvaddr);
101 /* A genuine misaligned load */
102 A_PRINTF("Misaligned load: pc=0x%x badvaddr=0x%x dump area=0x%x\n",
103 dump->pc, dump->badvaddr, dump);
105 A_ASSFAIL(dump); /* Not really an assertion failure, but we'll treat it similarly. */
108 // trigger wdt, in case hang
109 HAL_WORD_REG_WRITE(MAGPIE_REG_RST_WDT_TIMER_CTRL_ADDR, 0x03);
110 HAL_WORD_REG_WRITE(MAGPIE_REG_RST_WDT_TIMER_ADDR, 0x10);
115 struct register_dump_s *current_dump = NULL;
118 * A convenient place to set a breakpoint.
119 * Whenever an A_ASSERT triggers, it comes here.
122 cmnos_assfail(struct register_dump_s *dump)
124 if (current_dump == NULL ) {
128 //A_TARGET_ID_GET(&target_id);
129 dump->target_id = target_id;
134 A_PRINTF("assertion failed? pc=0x%x, line=%d, dump area=0x%x\n",
135 dump->pc, dump->assline, dump);
136 // INF_DBG2_LOG(INF_ASSERTION_FAILED, dump->pc,
137 // A_IML_ASSLINE(dump->badvaddr));
138 // INF_DBG1_LOG(INF_ASSERTION_FAILED, (A_UINT32)dump);
140 A_PRINTF("Target ID: 0x%x (%d)\n", target_id, target_id);
141 // INF_DBG1_LOG(INF_TARGET_ID, target_id);
143 A_PRINTF("Debug Info:");
144 for (i=0; i<(sizeof(struct register_dump_s)/sizeof(A_UINT32)); i++) {
148 A_PRINTF("0x%08x ", ((A_UINT32 *)dump)[i]);
149 // INF_DBG1_LOG(INF_ASSERTION_FAILED, ((A_UINT32 *)dump)[i]);
155 * We must have assfail'ed again while processing the first assfail.
156 * Don't try to print anything -- keep it very simple.
163 * failure state report
166 cmnos_report_failure_to_host(struct register_dump_s *dump, int len)
168 /* TBD: to be removed! */
175 cmnos_target_id_get(void)
177 /* TBD: to be removed! */
181 * get keyboard hit with delay
184 cmnos_get_kbhit(uint8_t delay)
186 uint32_t last_ccount;
189 last_ccount = xthal_get_ccount();
192 if( A_GETC(&kbhit) != 0 )
195 if((xthal_get_ccount() - last_ccount)>=delay*1000*ONE_MSEC)
205 * host alive & return the hostif type
208 cmnos_is_host_present(void)
211 * TODO: check the hostif and return the type of host interface
213 A_HOSTIF mHif = HIF_USB;
214 #if defined(PROJECT_K2)
215 A_PRINTF("5. usb only!!\n");
217 #elif defined(PROJECT_MAGPIE)
220 mData = MAGPIE_REG_RST_BOOTSTRAP;
222 //@RYAN@TODO - this one is somehow not working on L5, need to turn on!!!
224 /* 4:3 of BOOTSTRAP could distinguish the host interfce
247 //A_PRINTF("5. hif (0x%08x) is read!!\n", mData);
253 * get ROM code version
256 cmnos_rom_version_get(void)
258 #if SYSTEM_MODULE_USB
259 /* USB Device Descriptor : byte 12, 13 Device BCD -> Device release number in binary-coded decimal. */
260 return UsbDeviceDescriptor[6];
267 cmnos_misc_module_install(struct misc_api *tbl)
269 tbl->_system_reset = cmnos_system_reset;
270 tbl->_mac_reset = cmnos_mac_reset;
271 tbl->_assfail = cmnos_assfail;
272 tbl->_misaligned_load_handler= cmnos_misaligned_load_handler;
273 tbl->_report_failure_to_host = cmnos_report_failure_to_host;
274 //tbl->_target_id_get = cmnos_target_id_get;
275 tbl->_is_host_present = cmnos_is_host_present;
276 tbl->_kbhit = cmnos_get_kbhit;
277 tbl->_rom_version_get = cmnos_rom_version_get;