ar5312_board.c revision 1.1.8.2 1 1.1.8.2 yamt /* $Id: ar5312_board.c,v 1.1.8.2 2006/12/30 20:46:30 yamt Exp $ */
2 1.1.8.2 yamt /*
3 1.1.8.2 yamt * Copyright (c) 2006 Urbana-Champaign Independent Media Center.
4 1.1.8.2 yamt * Copyright (c) 2006 Garrett D'Amore.
5 1.1.8.2 yamt * All rights reserved.
6 1.1.8.2 yamt *
7 1.1.8.2 yamt * This code was written by Garrett D'Amore for the Champaign-Urbana
8 1.1.8.2 yamt * Community Wireless Network Project.
9 1.1.8.2 yamt *
10 1.1.8.2 yamt * Redistribution and use in source and binary forms, with or
11 1.1.8.2 yamt * without modification, are permitted provided that the following
12 1.1.8.2 yamt * conditions are met:
13 1.1.8.2 yamt * 1. Redistributions of source code must retain the above copyright
14 1.1.8.2 yamt * notice, this list of conditions and the following disclaimer.
15 1.1.8.2 yamt * 2. Redistributions in binary form must reproduce the above
16 1.1.8.2 yamt * copyright notice, this list of conditions and the following
17 1.1.8.2 yamt * disclaimer in the documentation and/or other materials provided
18 1.1.8.2 yamt * with the distribution.
19 1.1.8.2 yamt * 3. All advertising materials mentioning features or use of this
20 1.1.8.2 yamt * software must display the following acknowledgements:
21 1.1.8.2 yamt * This product includes software developed by the Urbana-Champaign
22 1.1.8.2 yamt * Independent Media Center.
23 1.1.8.2 yamt * This product includes software developed by Garrett D'Amore.
24 1.1.8.2 yamt * 4. Urbana-Champaign Independent Media Center's name and Garrett
25 1.1.8.2 yamt * D'Amore's name may not be used to endorse or promote products
26 1.1.8.2 yamt * derived from this software without specific prior written permission.
27 1.1.8.2 yamt *
28 1.1.8.2 yamt * THIS SOFTWARE IS PROVIDED BY THE URBANA-CHAMPAIGN INDEPENDENT
29 1.1.8.2 yamt * MEDIA CENTER AND GARRETT D'AMORE ``AS IS'' AND ANY EXPRESS OR
30 1.1.8.2 yamt * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
31 1.1.8.2 yamt * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32 1.1.8.2 yamt * ARE DISCLAIMED. IN NO EVENT SHALL THE URBANA-CHAMPAIGN INDEPENDENT
33 1.1.8.2 yamt * MEDIA CENTER OR GARRETT D'AMORE BE LIABLE FOR ANY DIRECT, INDIRECT,
34 1.1.8.2 yamt * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
35 1.1.8.2 yamt * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
36 1.1.8.2 yamt * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
37 1.1.8.2 yamt * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
38 1.1.8.2 yamt * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
39 1.1.8.2 yamt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
40 1.1.8.2 yamt * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 1.1.8.2 yamt */
42 1.1.8.2 yamt #include <sys/cdefs.h>
43 1.1.8.2 yamt __KERNEL_RCSID(0, "$NetBSD: ar5312_board.c,v 1.1.8.2 2006/12/30 20:46:30 yamt Exp $");
44 1.1.8.2 yamt
45 1.1.8.2 yamt #include <sys/param.h>
46 1.1.8.2 yamt #include <sys/systm.h>
47 1.1.8.2 yamt #include <sys/device.h>
48 1.1.8.2 yamt
49 1.1.8.2 yamt #include <machine/bus.h>
50 1.1.8.2 yamt #include <mips/atheros/include/ar5312reg.h>
51 1.1.8.2 yamt #include <mips/atheros/include/ar531xvar.h>
52 1.1.8.2 yamt
53 1.1.8.2 yamt #include <contrib/dev/ath/ah_soc.h>
54 1.1.8.2 yamt
55 1.1.8.2 yamt extern const char *ether_sprintf(const uint8_t *);
56 1.1.8.2 yamt
57 1.1.8.2 yamt /*
58 1.1.8.2 yamt * Locate the Board Configuration data using heuristics.
59 1.1.8.2 yamt * Search backward from the (aliased) end of flash looking
60 1.1.8.2 yamt * for the signature string that marks the start of the data.
61 1.1.8.2 yamt * We search at most 500KB.
62 1.1.8.2 yamt */
63 1.1.8.2 yamt const struct ar531x_boarddata *
64 1.1.8.2 yamt ar531x_board_info(void)
65 1.1.8.2 yamt {
66 1.1.8.2 yamt static const struct ar531x_boarddata *board = NULL;
67 1.1.8.2 yamt const uint8_t *ptr, *end;
68 1.1.8.2 yamt uint32_t fctl;
69 1.1.8.2 yamt
70 1.1.8.2 yamt if (board == NULL) {
71 1.1.8.2 yamt /* configure flash bank 0 */
72 1.1.8.2 yamt fctl = REGVAL(AR5312_FLASHCTL_BASE + AR5312_FLASHCTL_0) &
73 1.1.8.2 yamt AR5312_FLASHCTL_MW_MASK;
74 1.1.8.2 yamt
75 1.1.8.2 yamt fctl |=
76 1.1.8.2 yamt AR5312_FLASHCTL_E |
77 1.1.8.2 yamt AR5312_FLASHCTL_RBLE |
78 1.1.8.2 yamt AR5312_FLASHCTL_AC_8M |
79 1.1.8.2 yamt (1 << AR5312_FLASHCTL_IDCY_SHIFT) |
80 1.1.8.2 yamt (7 << AR5312_FLASHCTL_WST1_SHIFT) |
81 1.1.8.2 yamt (7 << AR5312_FLASHCTL_WST2_SHIFT);
82 1.1.8.2 yamt
83 1.1.8.2 yamt REGVAL(AR5312_FLASHCTL_BASE + AR5312_FLASHCTL_0) = fctl;
84 1.1.8.2 yamt
85 1.1.8.2 yamt REGVAL(AR5312_FLASHCTL_BASE + AR5312_FLASHCTL_1) &=
86 1.1.8.2 yamt ~(AR5312_FLASHCTL_E | AR5312_FLASHCTL_AC_MASK);
87 1.1.8.2 yamt
88 1.1.8.2 yamt REGVAL(AR5312_FLASHCTL_BASE + AR5312_FLASHCTL_2) &=
89 1.1.8.2 yamt ~(AR5312_FLASHCTL_E | AR5312_FLASHCTL_AC_MASK);
90 1.1.8.2 yamt
91 1.1.8.2 yamt /* search backward in the flash looking for the signature */
92 1.1.8.2 yamt ptr = (const uint8_t *) MIPS_PHYS_TO_KSEG1(AR5312_FLASH_END - 0x1000);
93 1.1.8.2 yamt end = ptr - (500 * 1024); /* NB: max 500KB window */
94 1.1.8.2 yamt /* XXX validate end */
95 1.1.8.2 yamt for (; ptr > end; ptr -= 0x1000)
96 1.1.8.2 yamt if (*(const uint32_t *)ptr == AR531X_BD_MAGIC) {
97 1.1.8.2 yamt board = (const struct ar531x_boarddata *) ptr;
98 1.1.8.2 yamt break;
99 1.1.8.2 yamt }
100 1.1.8.2 yamt }
101 1.1.8.2 yamt return board;
102 1.1.8.2 yamt }
103 1.1.8.2 yamt
104 1.1.8.2 yamt /*
105 1.1.8.2 yamt * Locate the radio configuration data; it is located relative
106 1.1.8.2 yamt * to the board configuration data.
107 1.1.8.2 yamt */
108 1.1.8.2 yamt const void *
109 1.1.8.2 yamt ar531x_radio_info(void)
110 1.1.8.2 yamt {
111 1.1.8.2 yamt static const void *radio = NULL;
112 1.1.8.2 yamt const struct ar531x_boarddata *board;
113 1.1.8.2 yamt const uint8_t *baddr, *ptr, *end;
114 1.1.8.2 yamt
115 1.1.8.2 yamt if (radio == NULL) {
116 1.1.8.2 yamt board = ar531x_board_info();
117 1.1.8.2 yamt if (board == NULL)
118 1.1.8.2 yamt return NULL;
119 1.1.8.2 yamt baddr = (const uint8_t *) board;
120 1.1.8.2 yamt ptr = baddr + 0x1000;
121 1.1.8.2 yamt end = (const uint8_t *)
122 1.1.8.2 yamt MIPS_PHYS_TO_KSEG1(AR5312_FLASH_END-0x1000);
123 1.1.8.2 yamt again:
124 1.1.8.2 yamt for (; ptr < end; ptr += 0x1000)
125 1.1.8.2 yamt if (*(const uint32_t *)ptr != 0xffffffff) {
126 1.1.8.2 yamt radio = ptr;
127 1.1.8.2 yamt goto done;
128 1.1.8.2 yamt }
129 1.1.8.2 yamt /* sort of an Algol-style for loop ... */
130 1.1.8.2 yamt if (end == (uint8_t *) MIPS_PHYS_TO_KSEG1(AR5312_FLASH_END)) {
131 1.1.8.2 yamt /* NB: AR2316 has radio data in a different location */
132 1.1.8.2 yamt ptr = baddr + 0xf8;
133 1.1.8.2 yamt end = (const uint8_t *)
134 1.1.8.2 yamt MIPS_PHYS_TO_KSEG1(AR5312_FLASH_END-0x1000 + 0xf8);
135 1.1.8.2 yamt goto again;
136 1.1.8.2 yamt }
137 1.1.8.2 yamt }
138 1.1.8.2 yamt done:
139 1.1.8.2 yamt return radio;
140 1.1.8.2 yamt }
141 1.1.8.2 yamt
142 1.1.8.2 yamt /*
143 1.1.8.2 yamt * Locate board and radio configuration data in flash.
144 1.1.8.2 yamt */
145 1.1.8.2 yamt int
146 1.1.8.2 yamt ar531x_board_config(struct ar531x_config *config)
147 1.1.8.2 yamt {
148 1.1.8.2 yamt
149 1.1.8.2 yamt config->board = ar531x_board_info();
150 1.1.8.2 yamt if (config->board == NULL)
151 1.1.8.2 yamt return ENOENT;
152 1.1.8.2 yamt config->radio = ar531x_radio_info();
153 1.1.8.2 yamt if (config->radio == NULL)
154 1.1.8.2 yamt return ENOENT; /* XXX distinct code */
155 1.1.8.2 yamt return 0;
156 1.1.8.2 yamt }
157