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