Home | History | Annotate | Line # | Download | only in atheros
ar_conf.c revision 1.1
      1  1.1  matt /*	$NetBSD: ar_conf.c,v 1.1 2011/07/07 05:06:44 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.1  matt __KERNEL_RCSID(0, "$NetBSD: ar_conf.c,v 1.1 2011/07/07 05:06:44 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.1  matt 		.ac_chipid =		ARCHIP_AR9344,
    106  1.1  matt 		.ac_chipmask =		0xff,
    107  1.1  matt 		.ac_cid =		MIPS_PRID_CID_MTI,
    108  1.1  matt 		.ac_pid =		MIPS_74K,
    109  1.1  matt 		.ac_name =		"AR9344"
    110  1.1  matt 	},
    111  1.1  matt #endif
    112  1.1  matt };
    113  1.1  matt 
    114  1.1  matt __CTASSERT(__arraycount(chips) > 0);
    115  1.1  matt 
    116  1.1  matt const struct atheros_platformsw *platformsw;
    117  1.1  matt 
    118  1.1  matt static const struct atheros_chip *my_chip;
    119  1.1  matt 
    120  1.1  matt static struct arfreqs chip_freqs;
    121  1.1  matt 
    122  1.1  matt const char *
    123  1.1  matt atheros_get_cpuname(void)
    124  1.1  matt {
    125  1.1  matt 	return my_chip->ac_name;
    126  1.1  matt }
    127  1.1  matt 
    128  1.1  matt u_int
    129  1.1  matt atheros_get_chipid(void)
    130  1.1  matt {
    131  1.1  matt 	return my_chip->ac_chipid;
    132  1.1  matt }
    133  1.1  matt 
    134  1.1  matt uint32_t
    135  1.1  matt atheros_get_bus_freq(void)
    136  1.1  matt {
    137  1.1  matt 	return chip_freqs.freq_bus;
    138  1.1  matt }
    139  1.1  matt 
    140  1.1  matt uint32_t
    141  1.1  matt atheros_get_cpu_freq(void)
    142  1.1  matt {
    143  1.1  matt 	return chip_freqs.freq_cpu;
    144  1.1  matt }
    145  1.1  matt 
    146  1.1  matt uint32_t
    147  1.1  matt atheros_get_mem_freq(void)
    148  1.1  matt {
    149  1.1  matt 	return chip_freqs.freq_mem;
    150  1.1  matt }
    151  1.1  matt 
    152  1.1  matt void
    153  1.1  matt atheros_set_platformsw(void)
    154  1.1  matt {
    155  1.1  matt 	const u_int cid = MIPS_PRID_CID(mips_options.mips_cpu_id);
    156  1.1  matt 	const u_int pid = MIPS_PRID_IMPL(mips_options.mips_cpu_id);
    157  1.1  matt 
    158  1.1  matt 	for (const struct atheros_chip *ac = chips;
    159  1.1  matt 	    ac < chips + __arraycount(chips);
    160  1.1  matt 	    ac++) {
    161  1.1  matt 		const struct atheros_platformsw * const apsw = ac->ac_platformsw;
    162  1.1  matt                 if (cid != ac->ac_cid || pid != ac->ac_pid)
    163  1.1  matt 			continue;
    164  1.1  matt 
    165  1.1  matt 		const uint32_t revision_id = *(volatile uint32_t *)
    166  1.1  matt 		    MIPS_PHYS_TO_KSEG1(apsw->apsw_revision_id_addr);
    167  1.1  matt 		const uint32_t chipid = AR9344_REVISION_CHIPID(revision_id);
    168  1.1  matt 
    169  1.1  matt 		if ((chipid & ac->ac_chipmask) == ac->ac_chipid) {
    170  1.1  matt 			platformsw = apsw;
    171  1.1  matt 			my_chip = ac;
    172  1.1  matt 			atheros_early_consinit();
    173  1.1  matt 			printf("Early console started!\n");
    174  1.1  matt 			(*apsw->apsw_get_freqs)(&chip_freqs);
    175  1.1  matt 			return;
    176  1.1  matt 		}
    177  1.1  matt 	}
    178  1.1  matt 	panic("%s: unrecognized platform", __func__);
    179  1.1  matt }
    180  1.1  matt 
    181  1.1  matt #include "ath_arbus.h"
    182  1.1  matt #if NATH_ARBUS > 0
    183  1.1  matt #include <ah_soc.h>
    184  1.1  matt 
    185  1.1  matt const struct ar531x_boarddata *
    186  1.1  matt atheros_get_board_info(void)
    187  1.1  matt {
    188  1.1  matt 	const struct atheros_boardsw * const boardsw = my_chip->ac_boardsw;
    189  1.1  matt 	if (boardsw == NULL)
    190  1.1  matt 		return NULL;
    191  1.1  matt 	return (*boardsw->absw_get_board_info)();
    192  1.1  matt }
    193  1.1  matt 
    194  1.1  matt /*
    195  1.1  matt  * Locate board and radio configuration data in flash.
    196  1.1  matt  */
    197  1.1  matt int
    198  1.1  matt atheros_get_board_config(struct ar531x_config *config)
    199  1.1  matt {
    200  1.1  matt 	const struct atheros_boardsw * const boardsw = my_chip->ac_boardsw;
    201  1.1  matt 	if (boardsw == NULL)
    202  1.1  matt 		return ENOENT;
    203  1.1  matt 
    204  1.1  matt 	config->board = (*boardsw->absw_get_board_info)();
    205  1.1  matt 	if (config->board == NULL)
    206  1.1  matt 		return ENOENT;
    207  1.1  matt 
    208  1.1  matt 	config->radio = (*boardsw->absw_get_radio_info)();
    209  1.1  matt 	if (config->radio == NULL)
    210  1.1  matt 		return ENOENT;		/* XXX distinct code */
    211  1.1  matt 
    212  1.1  matt 	return 0;
    213  1.1  matt }
    214  1.1  matt #endif /* NATH_ARBUS > 0 */
    215