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, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
34 #define AR9170_WATCH_DOG_TIMER 0x100
36 static void timer_init(const unsigned int timer, const unsigned int interval)
38 /* Set timer to periodic mode */
39 orl(AR9170_TIMER_REG_CONTROL, BIT(timer));
41 /* Set time interval */
42 set(AR9170_TIMER_REG_TIMER0 + (timer << 2), interval - 1);
44 /* Clear timer interrupt flag */
45 orl(AR9170_TIMER_REG_INTERRUPT, BIT(timer));
48 void clock_set(enum cpu_clock_t clock_, bool on)
52 * This setting does more than just mess with the CPU Clock.
53 * So watch out, if you need _stable_ timer interrupts.
55 if (fw.phy.frequency < 3000000)
56 set(AR9170_PWR_REG_PLL_ADDAC, 0x5163);
58 set(AR9170_PWR_REG_PLL_ADDAC, 0x5143);
60 fw.ticks_per_usec = GET_VAL(AR9170_PWR_PLL_ADDAC_DIV,
61 get(AR9170_PWR_REG_PLL_ADDAC));
63 set(AR9170_PWR_REG_CLOCK_SEL, (uint32_t) ((on ? 0x70 : 0x600) | clock_));
67 fw.ticks_per_usec >>= 1;
70 fw.ticks_per_usec >>= 1;
75 timer_init(1, (fw.ticks_per_usec * 25) >> 1);
77 INFO("SET CLOCK c:%d t:%d tt:%d f:%d\n", clock_, fw.ticks_per_usec, (fw.ticks_per_usec * 25) >> 1, fw.phy.frequency);
80 static void init(void)
84 #ifdef CONFIG_CARL9170FW_DEBUG_UART
86 #endif /* CONFIG_CARL9170FW_DEBUG_UART */
88 /* 25/50/100ms timer (depends on cpu clock) */
94 /* initialize DMA memory */
95 memset(&dma_mem, 0, sizeof(dma_mem));
98 dma_init_descriptors();
100 /* clear all interrupt */
101 set(AR9170_MAC_REG_INT_CTRL, 0xffff);
103 orl(AR9170_MAC_REG_AFTER_PNP, 1);
105 /* Init watch dog control flag */
106 fw.watchdog_enable = 1;
108 set(AR9170_TIMER_REG_WATCH_DOG, AR9170_WATCH_DOG_TIMER);
110 #ifdef CONFIG_CARL9170FW_GPIO_INTERRUPT
111 fw.cached_gpio_state.gpio = get(AR9170_GPIO_REG_PORT_DATA) &
113 #endif /* CONFIG_CARL9170FW_GPIO_INTERRUPT */
115 /* this will get the downqueue moving. */
119 static void handle_fw(void)
121 if (fw.watchdog_enable == 1)
122 set(AR9170_TIMER_REG_WATCH_DOG, AR9170_WATCH_DOG_TIMER);
128 static void timer0_isr(void)
132 #ifdef CONFIG_CARL9170FW_GPIO_INTERRUPT
134 #endif /* CONFIG_CARL9170FW_GPIO_INTERRUPT */
136 #ifdef CONFIG_CARL9170FW_DEBUG_LED_HEARTBEAT
137 set(AR9170_GPIO_REG_PORT_DATA, get(AR9170_GPIO_REG_PORT_DATA) ^ 1);
138 #endif /* CONFIG_CARL9170FW_DEBUG_LED_HEARTBEAT */
141 static void timer1_isr(void)
145 static void handle_timer(void)
149 intr = get(AR9170_TIMER_REG_INTERRUPT);
151 /* ACK timer interrupt */
152 set(AR9170_TIMER_REG_INTERRUPT, intr);
154 #define HANDLER(intr, flag, func) \
156 if ((intr & flag) != 0) { \
162 HANDLER(intr, BIT(0), timer0_isr);
164 HANDLER(intr, BIT(1), timer1_isr);
167 DBG("Unhandled Timer Event %x", (unsigned int) intr);
172 static void __noreturn main_loop(void)
179 * Due to frame order persevation, the wlan subroutines
180 * must be executed before handle_host_interface.
184 handle_host_interface();
195 * The bootcode will work with the device driver to load the firmware
196 * onto the device's Program SRAM. The Program SRAM has a size of 16 KB
197 * and also contains the stack, which grows down from 0x204000.
199 * The Program SRAM starts at address 0x200000 on the device.
200 * The firmware entry point (0x200004) is located in boot.S.
201 * we put _start() there with the linker script carl9170.lds.
204 void __section(boot) start(void)
206 clock_set(AHB_40MHZ_OSC, true);
208 /* watchdog magic pattern check */
209 if ((get(AR9170_PWR_REG_WATCH_DOG_MAGIC) & 0xffff0000) == 0x12340000) {
210 /* watch dog warm start */
211 incl(AR9170_PWR_REG_WATCH_DOG_MAGIC);
213 } else if ((get(AR9170_PWR_REG_WATCH_DOG_MAGIC) & 0xffff0000) == 0x98760000) {
217 /* write the magic pattern for watch dog */
218 andl(AR9170_PWR_REG_WATCH_DOG_MAGIC, 0xFFFF);
219 orl(AR9170_PWR_REG_WATCH_DOG_MAGIC, 0x12340000);
223 #ifdef CONFIG_CARL9170FW_DEBUG
226 BUG_ON(0x2b || !0x2b);
227 INFO("INFO MESSAGE");
229 /* a set of unique characters to detect transfer data corruptions */
230 DBG("AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz"
231 " ~`!1@2#3$4%%5^6&7*8(9)0_-+={[}]|\\:;\"'<,>.?/");
232 #endif /* CONFIG_CARL9170FW_DEBUG */
235 * Tell the host, that the firmware has booted and is
236 * now ready to process requests.
238 send_cmd_to_host(0, CARL9170_RSP_BOOT, 0x00, NULL);