2 * carl9170 firmware - used by the ar9170 wireless device
4 * initialization and main() loop
6 * Copyright (c) 2000-2005 ZyDAS Technology Corporation
7 * Copyright (c) 2007-2009 Atheros Communications, Inc.
8 * Copyright 2009 Johannes Berg <johannes@sipsolutions.net>
9 * Copyright 2009-2011 Christian Lamparter <chunkeey@googlemail.com>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License along
22 * with this program; If not, see <http://www.gnu.org/licenses/>.
34 #define AR9170_WATCH_DOG_TIMER 0x100
36 static void init(void)
40 #ifdef CONFIG_CARL9170FW_DEBUG_UART
42 #endif /* CONFIG_CARL9170FW_DEBUG_UART */
44 /* 25/50/100ms timer (depends on cpu clock) */
50 /* initialize DMA memory */
51 memset(&dma_mem, 0, sizeof(dma_mem));
54 dma_init_descriptors();
56 /* clear all interrupt */
57 set(AR9170_MAC_REG_INT_CTRL, 0xffff);
59 orl(AR9170_MAC_REG_AFTER_PNP, 1);
61 /* Init watch dog control flag */
62 fw.watchdog_enable = 1;
64 set(AR9170_TIMER_REG_WATCH_DOG, AR9170_WATCH_DOG_TIMER);
66 #ifdef CONFIG_CARL9170FW_GPIO_INTERRUPT
67 fw.cached_gpio_state.gpio = get(AR9170_GPIO_REG_PORT_DATA) &
69 #endif /* CONFIG_CARL9170FW_GPIO_INTERRUPT */
71 /* this will get the downqueue moving. */
75 static void handle_fw(void)
77 if (fw.watchdog_enable == 1)
78 set(AR9170_TIMER_REG_WATCH_DOG, AR9170_WATCH_DOG_TIMER);
84 static void tally_update(void)
88 time = get_clock_counter();
89 #ifdef CONFIG_CARL9170FW_RADIO_FUNCTIONS
90 if (fw.phy.state == CARL9170_PHY_ON) {
91 unsigned int boff, delta;
93 delta = (time - fw.tally_clock);
95 fw.tally.active += delta;
97 boff = get(AR9170_MAC_REG_BACKOFF_STATUS);
98 if (boff & AR9170_MAC_BACKOFF_TX_PE)
99 fw.tally.tx_time += delta;
100 if (boff & AR9170_MAC_BACKOFF_CCA)
101 fw.tally.cca += delta;
103 #endif /* CONFIG_CARL9170FW_RADIO_FUNCTIONS */
104 fw.tally_clock = time;
108 static void __noreturn main_loop(void)
115 * Due to frame order persevation, the wlan subroutines
116 * must be executed before handle_host_interface.
120 handle_host_interface();
131 * The bootcode will work with the device driver to load the firmware
132 * onto the device's Program SRAM. The Program SRAM has a size of 16 KB
133 * and also contains the stack, which grows down from 0x204000.
135 * The Program SRAM starts at address 0x200000 on the device.
136 * The firmware entry point (0x200004) is located in boot.S.
137 * we put _start() there with the linker script carl9170.lds.
140 void __in_section(boot) __noreturn __visible start(void)
142 clock_set(AHB_40MHZ_OSC, true);
144 /* watchdog magic pattern check */
145 if ((get(AR9170_PWR_REG_WATCH_DOG_MAGIC) & 0xffff0000) == 0x12340000) {
146 /* watch dog warm start */
147 incl(AR9170_PWR_REG_WATCH_DOG_MAGIC);
149 } else if ((get(AR9170_PWR_REG_WATCH_DOG_MAGIC) & 0xffff0000) == 0x98760000) {
153 /* write the magic pattern for watch dog */
154 andl(AR9170_PWR_REG_WATCH_DOG_MAGIC, 0xFFFF);
155 orl(AR9170_PWR_REG_WATCH_DOG_MAGIC, 0x12340000);
159 #ifdef CONFIG_CARL9170FW_DEBUG
162 BUG_ON(0x2b || !0x2b);
163 INFO("INFO MESSAGE");
165 /* a set of unique characters to detect transfer data corruptions */
166 DBG("AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz"
167 " ~`!1@2#3$4%%5^6&7*8(9)0_-+={[}]|\\:;\"'<,>.?/");
168 #endif /* CONFIG_CARL9170FW_DEBUG */
171 * Tell the host, that the firmware has booted and is
172 * now ready to process requests.
174 send_cmd_to_host(0, CARL9170_RSP_BOOT, 0x00, NULL);