1211476Sadrian/*-
2211476Sadrian * Copyright (c) 2010 Adrian Chadd
3211476Sadrian * All rights reserved.
4211476Sadrian *
5211476Sadrian * Redistribution and use in source and binary forms, with or without
6211476Sadrian * modification, are permitted provided that the following conditions
7211476Sadrian * are met:
8211476Sadrian * 1. Redistributions of source code must retain the above copyright
9211476Sadrian *    notice, this list of conditions and the following disclaimer.
10211476Sadrian * 2. Redistributions in binary form must reproduce the above copyright
11211476Sadrian *    notice, this list of conditions and the following disclaimer in the
12211476Sadrian *    documentation and/or other materials provided with the distribution.
13211476Sadrian *
14211476Sadrian * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15211476Sadrian * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16211476Sadrian * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17211476Sadrian * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18211476Sadrian * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19211476Sadrian * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20211476Sadrian * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21211476Sadrian * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22211476Sadrian * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23211476Sadrian * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24211476Sadrian * SUCH DAMAGE.
25211476Sadrian */
26211476Sadrian
27211476Sadrian#include <sys/cdefs.h>
28211476Sadrian__FBSDID("$FreeBSD$");
29211476Sadrian
30211476Sadrian#include "opt_ddb.h"
31211476Sadrian
32211476Sadrian#include <sys/param.h>
33211476Sadrian#include <sys/conf.h>
34211476Sadrian#include <sys/kernel.h>
35211476Sadrian#include <sys/systm.h>
36211476Sadrian#include <sys/bus.h>
37211476Sadrian#include <sys/cons.h>
38211476Sadrian#include <sys/kdb.h>
39211476Sadrian#include <sys/reboot.h>
40211476Sadrian
41211476Sadrian#include <vm/vm.h>
42211476Sadrian#include <vm/vm_page.h>
43211476Sadrian
44211476Sadrian#include <net/ethernet.h>
45211476Sadrian
46211476Sadrian#include <machine/clock.h>
47211476Sadrian#include <machine/cpu.h>
48223562Skevlo#include <machine/cpuregs.h>
49211476Sadrian#include <machine/hwfunc.h>
50211476Sadrian#include <machine/md_var.h>
51211476Sadrian#include <machine/trap.h>
52211476Sadrian#include <machine/vmparam.h>
53211476Sadrian
54211476Sadrian#include <mips/atheros/ar71xxreg.h>
55248844Sadrian#include <mips/atheros/ar933xreg.h>
56253511Sadrian#include <mips/atheros/ar934xreg.h>
57248844Sadrian
58211476Sadrian#include <mips/atheros/ar71xx_setup.h>
59211476Sadrian
60211476Sadrian#include <mips/atheros/ar71xx_cpudef.h>
61211476Sadrian
62211476Sadrian#include <mips/atheros/ar71xx_chip.h>
63211503Sadrian#include <mips/atheros/ar724x_chip.h>
64211502Sadrian#include <mips/atheros/ar91xx_chip.h>
65248844Sadrian#include <mips/atheros/ar933x_chip.h>
66253511Sadrian#include <mips/atheros/ar934x_chip.h>
67211476Sadrian
68211476Sadrian#define	AR71XX_SYS_TYPE_LEN		128
69211476Sadrian
70211476Sadrianstatic char ar71xx_sys_type[AR71XX_SYS_TYPE_LEN];
71211476Sadrianenum ar71xx_soc_type ar71xx_soc;
72211476Sadrianstruct ar71xx_cpu_def * ar71xx_cpu_ops = NULL;
73211476Sadrian
74211476Sadrianvoid
75211476Sadrianar71xx_detect_sys_type(void)
76211476Sadrian{
77211476Sadrian	char *chip = "????";
78211476Sadrian	uint32_t id;
79211476Sadrian	uint32_t major;
80211476Sadrian	uint32_t minor;
81211476Sadrian	uint32_t rev = 0;
82211476Sadrian
83211476Sadrian	id = ATH_READ_REG(AR71XX_RST_RESET_REG_REV_ID);
84211476Sadrian	major = id & REV_ID_MAJOR_MASK;
85211476Sadrian
86211476Sadrian	switch (major) {
87211476Sadrian	case REV_ID_MAJOR_AR71XX:
88211476Sadrian		minor = id & AR71XX_REV_ID_MINOR_MASK;
89211476Sadrian		rev = id >> AR71XX_REV_ID_REVISION_SHIFT;
90211476Sadrian		rev &= AR71XX_REV_ID_REVISION_MASK;
91211504Sadrian		ar71xx_cpu_ops = &ar71xx_chip_def;
92211476Sadrian		switch (minor) {
93211476Sadrian		case AR71XX_REV_ID_MINOR_AR7130:
94211476Sadrian			ar71xx_soc = AR71XX_SOC_AR7130;
95211476Sadrian			chip = "7130";
96211476Sadrian			break;
97211476Sadrian
98211476Sadrian		case AR71XX_REV_ID_MINOR_AR7141:
99211476Sadrian			ar71xx_soc = AR71XX_SOC_AR7141;
100211476Sadrian			chip = "7141";
101211476Sadrian			break;
102211476Sadrian
103211476Sadrian		case AR71XX_REV_ID_MINOR_AR7161:
104211476Sadrian			ar71xx_soc = AR71XX_SOC_AR7161;
105211476Sadrian			chip = "7161";
106211476Sadrian			break;
107211476Sadrian		}
108211476Sadrian		break;
109211476Sadrian
110211503Sadrian	case REV_ID_MAJOR_AR7240:
111211503Sadrian		ar71xx_soc = AR71XX_SOC_AR7240;
112211503Sadrian		chip = "7240";
113211504Sadrian		ar71xx_cpu_ops = &ar724x_chip_def;
114211503Sadrian		rev = (id & AR724X_REV_ID_REVISION_MASK);
115211503Sadrian		break;
116211503Sadrian
117211503Sadrian	case REV_ID_MAJOR_AR7241:
118211503Sadrian		ar71xx_soc = AR71XX_SOC_AR7241;
119211503Sadrian		chip = "7241";
120211504Sadrian		ar71xx_cpu_ops = &ar724x_chip_def;
121211503Sadrian		rev = (id & AR724X_REV_ID_REVISION_MASK);
122211503Sadrian		break;
123211503Sadrian
124211503Sadrian	case REV_ID_MAJOR_AR7242:
125211503Sadrian		ar71xx_soc = AR71XX_SOC_AR7242;
126211503Sadrian		chip = "7242";
127211504Sadrian		ar71xx_cpu_ops = &ar724x_chip_def;
128211503Sadrian		rev = (id & AR724X_REV_ID_REVISION_MASK);
129211503Sadrian		break;
130211503Sadrian
131211502Sadrian	case REV_ID_MAJOR_AR913X:
132211502Sadrian		minor = id & AR91XX_REV_ID_MINOR_MASK;
133211502Sadrian		rev = id >> AR91XX_REV_ID_REVISION_SHIFT;
134211502Sadrian		rev &= AR91XX_REV_ID_REVISION_MASK;
135211504Sadrian		ar71xx_cpu_ops = &ar91xx_chip_def;
136211502Sadrian		switch (minor) {
137211502Sadrian		case AR91XX_REV_ID_MINOR_AR9130:
138211502Sadrian			ar71xx_soc = AR71XX_SOC_AR9130;
139211502Sadrian			chip = "9130";
140211502Sadrian			break;
141211502Sadrian
142211502Sadrian		case AR91XX_REV_ID_MINOR_AR9132:
143211502Sadrian			ar71xx_soc = AR71XX_SOC_AR9132;
144211502Sadrian			chip = "9132";
145211502Sadrian			break;
146211502Sadrian		}
147211502Sadrian		break;
148248844Sadrian	case REV_ID_MAJOR_AR9330:
149248844Sadrian		minor = 0;
150248844Sadrian		rev = (id & AR933X_REV_ID_REVISION_MASK);
151248844Sadrian		chip = "9330";
152248844Sadrian		ar71xx_cpu_ops = &ar933x_chip_def;
153249118Sadrian		ar71xx_soc = AR71XX_SOC_AR9330;
154248844Sadrian		break;
155248844Sadrian	case REV_ID_MAJOR_AR9331:
156248844Sadrian		minor = 1;
157248844Sadrian		rev = (id & AR933X_REV_ID_REVISION_MASK);
158248844Sadrian		chip = "9331";
159249118Sadrian		ar71xx_soc = AR71XX_SOC_AR9331;
160248844Sadrian		ar71xx_cpu_ops = &ar933x_chip_def;
161248844Sadrian		break;
162211502Sadrian
163253511Sadrian	case REV_ID_MAJOR_AR9341:
164253511Sadrian		minor = 0;
165253511Sadrian		rev = (id & AR934X_REV_ID_REVISION_MASK);
166253511Sadrian		chip = "9341";
167253511Sadrian		ar71xx_soc = AR71XX_SOC_AR9341;
168253511Sadrian		ar71xx_cpu_ops = &ar934x_chip_def;
169253511Sadrian		break;
170253511Sadrian
171253511Sadrian	case REV_ID_MAJOR_AR9342:
172253511Sadrian		minor = 0;
173253511Sadrian		rev = (id & AR934X_REV_ID_REVISION_MASK);
174253511Sadrian		chip = "9342";
175253511Sadrian		ar71xx_soc = AR71XX_SOC_AR9342;
176253511Sadrian		ar71xx_cpu_ops = &ar934x_chip_def;
177253511Sadrian		break;
178253511Sadrian
179253511Sadrian	case REV_ID_MAJOR_AR9344:
180253511Sadrian		minor = 0;
181253511Sadrian		rev = (id & AR934X_REV_ID_REVISION_MASK);
182253511Sadrian		chip = "9344";
183253511Sadrian		ar71xx_soc = AR71XX_SOC_AR9344;
184253511Sadrian		ar71xx_cpu_ops = &ar934x_chip_def;
185253511Sadrian		break;
186253511Sadrian
187211476Sadrian	default:
188211476Sadrian		panic("ar71xx: unknown chip id:0x%08x\n", id);
189211476Sadrian	}
190211476Sadrian
191211476Sadrian	sprintf(ar71xx_sys_type, "Atheros AR%s rev %u", chip, rev);
192211476Sadrian}
193211476Sadrian
194211476Sadrianconst char *
195211476Sadrianar71xx_get_system_type(void)
196211476Sadrian{
197211476Sadrian	return ar71xx_sys_type;
198211476Sadrian}
199211476Sadrian
200