xref: /netbsd-src/sys/arch/mips/atheros/ar5315_board.c (revision fa40faf65a740d892a78142c6206a181c64c761b)
1*fa40faf6Smatt /* $NetBSD: ar5315_board.c,v 1.4 2011/07/10 06:24:18 matt Exp $ */
2e653071cSgdamore 
3e653071cSgdamore /*
4e653071cSgdamore  * Copyright (c) 2006 Urbana-Champaign Independent Media Center.
5e653071cSgdamore  * Copyright (c) 2006 Garrett D'Amore.
6e653071cSgdamore  * All rights reserved.
7e653071cSgdamore  *
8e653071cSgdamore  * Portions of this code were written by Garrett D'Amore for the
9e653071cSgdamore  * Champaign-Urbana Community Wireless Network Project.
10e653071cSgdamore  *
11e653071cSgdamore  * Redistribution and use in source and binary forms, with or
12e653071cSgdamore  * without modification, are permitted provided that the following
13e653071cSgdamore  * conditions are met:
14e653071cSgdamore  * 1. Redistributions of source code must retain the above copyright
15e653071cSgdamore  *    notice, this list of conditions and the following disclaimer.
16e653071cSgdamore  * 2. Redistributions in binary form must reproduce the above
17e653071cSgdamore  *    copyright notice, this list of conditions and the following
18e653071cSgdamore  *    disclaimer in the documentation and/or other materials provided
19e653071cSgdamore  *    with the distribution.
20e653071cSgdamore  * 3. All advertising materials mentioning features or use of this
21e653071cSgdamore  *    software must display the following acknowledgements:
22e653071cSgdamore  *      This product includes software developed by the Urbana-Champaign
23e653071cSgdamore  *      Independent Media Center.
24e653071cSgdamore  *	This product includes software developed by Garrett D'Amore.
25e653071cSgdamore  * 4. Urbana-Champaign Independent Media Center's name and Garrett
26e653071cSgdamore  *    D'Amore's name may not be used to endorse or promote products
27e653071cSgdamore  *    derived from this software without specific prior written permission.
28e653071cSgdamore  *
29e653071cSgdamore  * THIS SOFTWARE IS PROVIDED BY THE URBANA-CHAMPAIGN INDEPENDENT
30e653071cSgdamore  * MEDIA CENTER AND GARRETT D'AMORE ``AS IS'' AND ANY EXPRESS OR
31e653071cSgdamore  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
32e653071cSgdamore  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33e653071cSgdamore  * ARE DISCLAIMED.  IN NO EVENT SHALL THE URBANA-CHAMPAIGN INDEPENDENT
34e653071cSgdamore  * MEDIA CENTER OR GARRETT D'AMORE BE LIABLE FOR ANY DIRECT, INDIRECT,
35e653071cSgdamore  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
36e653071cSgdamore  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
37e653071cSgdamore  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
38e653071cSgdamore  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39e653071cSgdamore  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
40e653071cSgdamore  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
41e653071cSgdamore  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42e653071cSgdamore  */
43e653071cSgdamore 
44e653071cSgdamore /*
45e653071cSgdamore  * This file provides code to locate board-specific configuration and radio
46e653071cSgdamore  * information data in flash for the AR5315.
47e653071cSgdamore  */
48e653071cSgdamore #include <sys/cdefs.h>
49*fa40faf6Smatt __KERNEL_RCSID(0, "$NetBSD: ar5315_board.c,v 1.4 2011/07/10 06:24:18 matt Exp $");
50e653071cSgdamore 
51e653071cSgdamore #include "opt_ddb.h"
52e653071cSgdamore #include "opt_kgdb.h"
53e653071cSgdamore 
54e653071cSgdamore #include "opt_memsize.h"
55e653071cSgdamore #include <sys/param.h>
56e653071cSgdamore #include <sys/systm.h>
57e653071cSgdamore #include <sys/kernel.h>
58e653071cSgdamore #include <sys/buf.h>
59e653071cSgdamore 
60e653071cSgdamore #include <dev/cons.h>
61e653071cSgdamore 
62e653071cSgdamore #include <mips/cache.h>
63e653071cSgdamore #include <mips/locore.h>
64e653071cSgdamore #include <mips/cpuregs.h>
65e653071cSgdamore 
66e653071cSgdamore #include <net/if.h>
67e653071cSgdamore #include <net/if_ether.h>
68e653071cSgdamore 
696ce0e276Salc #include <ah_soc.h>	/* XXX really doesn't belong in hal */
70e653071cSgdamore 
71e653071cSgdamore #include <mips/atheros/include/ar5315reg.h>
72e653071cSgdamore #include <mips/atheros/include/arbusvar.h>
7381d18a2fSmatt #include <mips/atheros/include/platform.h>
74e653071cSgdamore 
75*fa40faf6Smatt #include <mips/locore.h>
76e653071cSgdamore #include "com.h"
77e653071cSgdamore 
78e653071cSgdamore /*
79e653071cSgdamore  * Locate the Board Configuration data using heuristics.
80e653071cSgdamore  * Search backward from the (aliased) end of flash looking
81e653071cSgdamore  * for the signature string that marks the start of the data.
82e653071cSgdamore  * We search at most 500KB.
83e653071cSgdamore  */
8481d18a2fSmatt static const struct ar531x_boarddata *
ar5315_get_board_info(void)8581d18a2fSmatt ar5315_get_board_info(void)
86e653071cSgdamore {
87e653071cSgdamore 	static const struct ar531x_boarddata *board = NULL;
88e653071cSgdamore 	const uint8_t *ptr, *end;
89e653071cSgdamore 
90e653071cSgdamore 	if (board == NULL) {
91e653071cSgdamore 
92e653071cSgdamore 		/* search backward in the flash looking for the signature */
93e653071cSgdamore 		ptr = (const uint8_t *) MIPS_PHYS_TO_KSEG1(AR5315_CONFIG_END
94e653071cSgdamore 		    - 0x1000);
95e653071cSgdamore 		end = (const uint8_t *)AR5315_CONFIG_BASE;
96e653071cSgdamore 		/* XXX validate end */
97e653071cSgdamore 		for (; ptr > end; ptr -= 0x1000)
98e653071cSgdamore 			if (*(const uint32_t *)ptr == AR531X_BD_MAGIC) {
99e653071cSgdamore 				board = (const struct ar531x_boarddata *) ptr;
100e653071cSgdamore 				break;
101e653071cSgdamore 			}
102e653071cSgdamore 	}
103e653071cSgdamore 	return board;
104e653071cSgdamore }
105e653071cSgdamore 
106e653071cSgdamore /*
107e653071cSgdamore  * Locate the radio configuration data; it is located relative to the
108e653071cSgdamore  * board configuration data.
109e653071cSgdamore  */
11081d18a2fSmatt static const void *
ar5315_get_radio_info(void)11181d18a2fSmatt ar5315_get_radio_info(void)
112e653071cSgdamore {
113e653071cSgdamore 	static const void *radio = NULL;
114e653071cSgdamore 	const struct ar531x_boarddata *board;
115e653071cSgdamore 	const uint8_t *baddr, *ptr, *end;
116e653071cSgdamore 
117e653071cSgdamore 	if (radio)
118e653071cSgdamore 		goto done;
119e653071cSgdamore 
12081d18a2fSmatt 	board = ar5315_get_board_info();
121e653071cSgdamore 	if (board == NULL)
122e653071cSgdamore 		return NULL;
123e653071cSgdamore 	baddr = (const uint8_t *) board;
124e653071cSgdamore 	end = (const uint8_t *)MIPS_PHYS_TO_KSEG1(AR5315_RADIO_END);
125e653071cSgdamore 
126e653071cSgdamore 	for (ptr = baddr + 0x1000; ptr < end; ptr += 0x1000)
127e653071cSgdamore 		if (*(const uint32_t *)ptr != 0xffffffffU) {
128e653071cSgdamore 			radio = ptr;
129e653071cSgdamore 			goto done;
130e653071cSgdamore 		}
131e653071cSgdamore 
132e653071cSgdamore 	/* AR2316 moves radio data */
133e653071cSgdamore 	for (ptr = baddr + 0xf8; ptr < end; ptr += 0x1000)
134e653071cSgdamore 		if (*(const uint32_t *)ptr != 0xffffffffU) {
135e653071cSgdamore 			radio = ptr;
136e653071cSgdamore 			goto done;
137e653071cSgdamore 		}
138e653071cSgdamore 
139e653071cSgdamore done:
140e653071cSgdamore 	return radio;
141e653071cSgdamore }
142e653071cSgdamore 
14381d18a2fSmatt const struct atheros_boardsw ar5315_boardsw = {
14481d18a2fSmatt 	.absw_get_board_info = ar5315_get_board_info,
14581d18a2fSmatt 	.absw_get_radio_info = ar5315_get_radio_info,
14681d18a2fSmatt };
147