ar_conf.c revision 1.2 1 1.2 matt /* $NetBSD: ar_conf.c,v 1.2 2011/07/10 06:26:02 matt Exp $ */
2 1.1 matt /*-
3 1.1 matt * Copyright (c) 2011 The NetBSD Foundation, Inc.
4 1.1 matt * All rights reserved.
5 1.1 matt *
6 1.1 matt * This code is derived from software contributed to The NetBSD Foundation
7 1.1 matt * by Matt Thomas of 3am Software Foundry.
8 1.1 matt *
9 1.1 matt * Redistribution and use in source and binary forms, with or without
10 1.1 matt * modification, are permitted provided that the following conditions
11 1.1 matt * are met:
12 1.1 matt * 1. Redistributions of source code must retain the above copyright
13 1.1 matt * notice, this list of conditions and the following disclaimer.
14 1.1 matt * 2. Redistributions in binary form must reproduce the above copyright
15 1.1 matt * notice, this list of conditions and the following disclaimer in the
16 1.1 matt * documentation and/or other materials provided with the distribution.
17 1.1 matt *
18 1.1 matt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19 1.1 matt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20 1.1 matt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 1.1 matt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22 1.1 matt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 1.1 matt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 1.1 matt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 1.1 matt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 1.1 matt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 1.1 matt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 1.1 matt * POSSIBILITY OF SUCH DAMAGE.
29 1.1 matt */
30 1.1 matt
31 1.1 matt #include <sys/cdefs.h>
32 1.1 matt
33 1.2 matt __KERNEL_RCSID(0, "$NetBSD: ar_conf.c,v 1.2 2011/07/10 06:26:02 matt Exp $");
34 1.1 matt
35 1.1 matt #include <sys/param.h>
36 1.1 matt
37 1.1 matt #include "opt_wisoc.h"
38 1.1 matt
39 1.1 matt #include <mips/cpuregs.h>
40 1.1 matt #include <mips/locore.h>
41 1.1 matt
42 1.1 matt #include <mips/atheros/include/platform.h>
43 1.1 matt #include <mips/atheros/include/ar9344reg.h>
44 1.1 matt
45 1.1 matt struct atheros_chip {
46 1.1 matt const struct atheros_platformsw *ac_platformsw;
47 1.1 matt const struct atheros_boardsw *ac_boardsw;
48 1.1 matt uint8_t ac_chipid;
49 1.1 matt uint8_t ac_chipmask;
50 1.1 matt uint8_t ac_cid;
51 1.1 matt uint8_t ac_pid;
52 1.1 matt const char ac_name[8];
53 1.1 matt };
54 1.1 matt
55 1.1 matt static const struct atheros_chip chips[] = {
56 1.1 matt #ifdef WISOC_AR5312
57 1.1 matt {
58 1.1 matt .ac_platformsw = &ar5312_platformsw,
59 1.1 matt .ac_boardsw = &ar5312_boardsw,
60 1.1 matt .ac_chipid = ARCHIP_AR5312,
61 1.1 matt .ac_chipmask = 0xff,
62 1.1 matt .ac_cid = MIPS_PRID_CID_MTI,
63 1.1 matt .ac_pid = MIPS_4Kc,
64 1.1 matt .ac_name = "AR5312"
65 1.1 matt },
66 1.1 matt #endif
67 1.1 matt #ifdef WISOC_AR5315
68 1.1 matt {
69 1.1 matt .ac_platformsw = &ar5315_platformsw,
70 1.1 matt .ac_boardsw = &ar5315_boardsw,
71 1.1 matt .ac_chipid = ARCHIP_AR5315,
72 1.1 matt .ac_chipmask = 0xf0,
73 1.1 matt .ac_cid = MIPS_PRID_CID_MTI,
74 1.1 matt .ac_pid = MIPS_4Kc,
75 1.1 matt .ac_name = "AR5315"
76 1.1 matt },
77 1.1 matt #endif
78 1.1 matt #ifdef WISOC_AR7100
79 1.1 matt {
80 1.1 matt .ac_platformsw = &ar7100_platformsw,
81 1.1 matt .ac_chipid = ARCHIP_AR7130,
82 1.1 matt .ac_chipmask = 0xf3,
83 1.1 matt .ac_cid = MIPS_PRID_CID_MTI,
84 1.1 matt .ac_pid = MIPS_24K,
85 1.1 matt .ac_name = "AR7130"
86 1.1 matt }, {
87 1.1 matt .ac_platformsw = &ar7100_platformsw,
88 1.1 matt .ac_chipid = ARCHIP_AR7141,
89 1.1 matt .ac_chipmask = 0xf3,
90 1.1 matt .ac_cid = MIPS_PRID_CID_MTI,
91 1.1 matt .ac_pid = MIPS_24K,
92 1.1 matt .ac_name = "AR7141"
93 1.1 matt }, {
94 1.1 matt .ac_platformsw = &ar7100_platformsw,
95 1.1 matt .ac_chipid = ARCHIP_AR7161,
96 1.1 matt .ac_chipmask = 0xf3,
97 1.1 matt .ac_cid = MIPS_PRID_CID_MTI,
98 1.1 matt .ac_pid = MIPS_24K,
99 1.1 matt .ac_name = "AR7161"
100 1.1 matt },
101 1.1 matt #endif
102 1.1 matt #ifdef WISOC_AR9344
103 1.1 matt {
104 1.1 matt .ac_platformsw = &ar9344_platformsw,
105 1.2 matt .ac_chipid = 0x20, /* 7240? */
106 1.2 matt .ac_chipmask = 0xff,
107 1.2 matt .ac_cid = MIPS_PRID_CID_MTI,
108 1.2 matt .ac_pid = MIPS_74K,
109 1.2 matt .ac_name = "AR7240"
110 1.2 matt }, {
111 1.2 matt .ac_platformsw = &ar9344_platformsw,
112 1.1 matt .ac_chipid = ARCHIP_AR9344,
113 1.1 matt .ac_chipmask = 0xff,
114 1.1 matt .ac_cid = MIPS_PRID_CID_MTI,
115 1.1 matt .ac_pid = MIPS_74K,
116 1.1 matt .ac_name = "AR9344"
117 1.1 matt },
118 1.1 matt #endif
119 1.1 matt };
120 1.1 matt
121 1.1 matt __CTASSERT(__arraycount(chips) > 0);
122 1.1 matt
123 1.1 matt const struct atheros_platformsw *platformsw;
124 1.1 matt
125 1.1 matt static const struct atheros_chip *my_chip;
126 1.1 matt
127 1.1 matt static struct arfreqs chip_freqs;
128 1.1 matt
129 1.1 matt const char *
130 1.1 matt atheros_get_cpuname(void)
131 1.1 matt {
132 1.1 matt return my_chip->ac_name;
133 1.1 matt }
134 1.1 matt
135 1.1 matt u_int
136 1.1 matt atheros_get_chipid(void)
137 1.1 matt {
138 1.1 matt return my_chip->ac_chipid;
139 1.1 matt }
140 1.1 matt
141 1.1 matt uint32_t
142 1.2 matt atheros_get_uart_freq(void)
143 1.2 matt {
144 1.2 matt if (chip_freqs.freq_uart)
145 1.2 matt return chip_freqs.freq_uart;
146 1.2 matt
147 1.2 matt return chip_freqs.freq_bus;
148 1.2 matt }
149 1.2 matt
150 1.2 matt uint32_t
151 1.1 matt atheros_get_bus_freq(void)
152 1.1 matt {
153 1.1 matt return chip_freqs.freq_bus;
154 1.1 matt }
155 1.1 matt
156 1.1 matt uint32_t
157 1.1 matt atheros_get_cpu_freq(void)
158 1.1 matt {
159 1.1 matt return chip_freqs.freq_cpu;
160 1.1 matt }
161 1.1 matt
162 1.1 matt uint32_t
163 1.1 matt atheros_get_mem_freq(void)
164 1.1 matt {
165 1.1 matt return chip_freqs.freq_mem;
166 1.1 matt }
167 1.1 matt
168 1.1 matt void
169 1.1 matt atheros_set_platformsw(void)
170 1.1 matt {
171 1.1 matt const u_int cid = MIPS_PRID_CID(mips_options.mips_cpu_id);
172 1.1 matt const u_int pid = MIPS_PRID_IMPL(mips_options.mips_cpu_id);
173 1.1 matt
174 1.1 matt for (const struct atheros_chip *ac = chips;
175 1.1 matt ac < chips + __arraycount(chips);
176 1.1 matt ac++) {
177 1.1 matt const struct atheros_platformsw * const apsw = ac->ac_platformsw;
178 1.1 matt if (cid != ac->ac_cid || pid != ac->ac_pid)
179 1.1 matt continue;
180 1.1 matt
181 1.1 matt const uint32_t revision_id = *(volatile uint32_t *)
182 1.1 matt MIPS_PHYS_TO_KSEG1(apsw->apsw_revision_id_addr);
183 1.1 matt const uint32_t chipid = AR9344_REVISION_CHIPID(revision_id);
184 1.1 matt
185 1.1 matt if ((chipid & ac->ac_chipmask) == ac->ac_chipid) {
186 1.1 matt platformsw = apsw;
187 1.1 matt my_chip = ac;
188 1.1 matt atheros_early_consinit();
189 1.1 matt printf("Early console started!\n");
190 1.1 matt (*apsw->apsw_get_freqs)(&chip_freqs);
191 1.2 matt printf("freqs: cpu=%u bus=%u mem=%u ref=%u pll=%u\n",
192 1.2 matt chip_freqs.freq_cpu,
193 1.2 matt chip_freqs.freq_bus,
194 1.2 matt chip_freqs.freq_mem,
195 1.2 matt chip_freqs.freq_ref,
196 1.2 matt chip_freqs.freq_pll);
197 1.1 matt return;
198 1.1 matt }
199 1.1 matt }
200 1.1 matt panic("%s: unrecognized platform", __func__);
201 1.1 matt }
202 1.1 matt
203 1.1 matt #include "ath_arbus.h"
204 1.1 matt #if NATH_ARBUS > 0
205 1.1 matt #include <ah_soc.h>
206 1.1 matt
207 1.1 matt const struct ar531x_boarddata *
208 1.1 matt atheros_get_board_info(void)
209 1.1 matt {
210 1.1 matt const struct atheros_boardsw * const boardsw = my_chip->ac_boardsw;
211 1.1 matt if (boardsw == NULL)
212 1.1 matt return NULL;
213 1.1 matt return (*boardsw->absw_get_board_info)();
214 1.1 matt }
215 1.1 matt
216 1.1 matt /*
217 1.1 matt * Locate board and radio configuration data in flash.
218 1.1 matt */
219 1.1 matt int
220 1.1 matt atheros_get_board_config(struct ar531x_config *config)
221 1.1 matt {
222 1.1 matt const struct atheros_boardsw * const boardsw = my_chip->ac_boardsw;
223 1.1 matt if (boardsw == NULL)
224 1.1 matt return ENOENT;
225 1.1 matt
226 1.1 matt config->board = (*boardsw->absw_get_board_info)();
227 1.1 matt if (config->board == NULL)
228 1.1 matt return ENOENT;
229 1.1 matt
230 1.1 matt config->radio = (*boardsw->absw_get_radio_info)();
231 1.1 matt if (config->radio == NULL)
232 1.1 matt return ENOENT; /* XXX distinct code */
233 1.1 matt
234 1.1 matt return 0;
235 1.1 matt }
236 1.1 matt #endif /* NATH_ARBUS > 0 */
237