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 static void init(void)
52 #ifdef CONFIG_CARL9170FW_DEBUG_UART
54 #endif /* CONFIG_CARL9170FW_DEBUG_UART */
56 /* 25/50/100ms timer (depends on cpu clock) */
62 /* initialize DMA memory */
63 memset(&dma_mem, 0, sizeof(dma_mem));
66 dma_init_descriptors();
68 /* clear all interrupt */
69 set(AR9170_MAC_REG_INT_CTRL, 0xffff);
71 orl(AR9170_MAC_REG_AFTER_PNP, 1);
73 /* Init watch dog control flag */
74 fw.watchdog_enable = 1;
76 set(AR9170_TIMER_REG_WATCH_DOG, AR9170_WATCH_DOG_TIMER);
78 #ifdef CONFIG_CARL9170FW_GPIO_INTERRUPT
79 fw.cached_gpio_state.gpio = get(AR9170_GPIO_REG_PORT_DATA) &
81 #endif /* CONFIG_CARL9170FW_GPIO_INTERRUPT */
83 /* this will get the downqueue moving. */
87 static void handle_fw(void)
89 if (fw.watchdog_enable == 1)
90 set(AR9170_TIMER_REG_WATCH_DOG, AR9170_WATCH_DOG_TIMER);
96 static void timer0_isr(void)
100 #ifdef CONFIG_CARL9170FW_GPIO_INTERRUPT
102 #endif /* CONFIG_CARL9170FW_GPIO_INTERRUPT */
104 #ifdef CONFIG_CARL9170FW_DEBUG_LED_HEARTBEAT
105 set(AR9170_GPIO_REG_PORT_DATA, get(AR9170_GPIO_REG_PORT_DATA) ^ 1);
106 #endif /* CONFIG_CARL9170FW_DEBUG_LED_HEARTBEAT */
109 static void handle_timer(void)
113 intr = get(AR9170_TIMER_REG_INTERRUPT);
115 /* ACK timer interrupt */
116 set(AR9170_TIMER_REG_INTERRUPT, intr);
118 #define HANDLER(intr, flag, func) \
120 if ((intr & flag) != 0) { \
126 HANDLER(intr, BIT(0), timer0_isr);
129 DBG("Unhandled Timer Event %x", (unsigned int) intr);
134 static void __noreturn main_loop(void)
141 * Due to frame order persevation, the wlan subroutines
142 * must be executed before handle_host_interface.
146 handle_host_interface();
157 * The bootcode will work with the device driver to load the firmware
158 * onto the device's Program SRAM. The Program SRAM has a size of 16 KB
159 * and also contains the stack, which grows down from 0x204000.
161 * The Program SRAM starts at address 0x200000 on the device.
162 * The firmware entry point (0x200004) is located in boot.S.
163 * we put _start() there with the linker script carl9170.lds.
168 clock_set(AHB_40MHZ_OSC, true);
170 /* watchdog magic pattern check */
171 if ((get(AR9170_PWR_REG_WATCH_DOG_MAGIC) & 0xffff0000) == 0x12340000) {
172 /* watch dog warm start */
173 incl(AR9170_PWR_REG_WATCH_DOG_MAGIC);
175 } else if ((get(AR9170_PWR_REG_WATCH_DOG_MAGIC) & 0xffff0000) == 0x98760000) {
179 /* write the magic pattern for watch dog */
180 andl(AR9170_PWR_REG_WATCH_DOG_MAGIC, 0xFFFF);
181 orl(AR9170_PWR_REG_WATCH_DOG_MAGIC, 0x12340000);
185 #ifdef CONFIG_CARL9170FW_DEBUG
188 BUG_ON(0x2b || !0x2b);
189 INFO("INFO MESSAGE");
191 /* a set of unique characters to detect transfer data corruptions */
192 DBG("AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz"
193 " ~`!1@2#3$4%%5^6&7*8(9)0_-+={[}]|\\:;\"'<,>.?/");
194 #endif /* CONFIG_CARL9170FW_DEBUG */
197 * Tell the host, that the firmware has booted and is
198 * now ready to process requests.
200 send_cmd_to_host(0, CARL9170_RSP_BOOT, 0x00, NULL);