Home | History | Annotate | Line # | Download | only in atheros
      1  1.3  matt /*	$NetBSD: ar_conf.c,v 1.3 2015/06/09 22:50:50 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.3  matt __KERNEL_RCSID(0, "$NetBSD: ar_conf.c,v 1.3 2015/06/09 22:50:50 matt Exp $");
     34  1.1  matt 
     35  1.1  matt #include <sys/param.h>
     36  1.3  matt #include <sys/cpu.h>
     37  1.1  matt 
     38  1.1  matt #include "opt_wisoc.h"
     39  1.1  matt 
     40  1.1  matt #include <mips/cpuregs.h>
     41  1.1  matt #include <mips/locore.h>
     42  1.1  matt 
     43  1.1  matt #include <mips/atheros/include/platform.h>
     44  1.1  matt #include <mips/atheros/include/ar9344reg.h>
     45  1.1  matt 
     46  1.1  matt struct atheros_chip {
     47  1.1  matt 	const struct atheros_platformsw *ac_platformsw;
     48  1.1  matt 	const struct atheros_boardsw *ac_boardsw;
     49  1.1  matt 	uint8_t ac_chipid;
     50  1.1  matt 	uint8_t ac_chipmask;
     51  1.1  matt 	uint8_t ac_cid;
     52  1.1  matt 	uint8_t ac_pid;
     53  1.1  matt 	const char ac_name[8];
     54  1.1  matt };
     55  1.1  matt 
     56  1.1  matt static const struct atheros_chip chips[] = {
     57  1.1  matt #ifdef WISOC_AR5312
     58  1.1  matt 	{
     59  1.1  matt 		.ac_platformsw =	&ar5312_platformsw,
     60  1.1  matt 		.ac_boardsw =		&ar5312_boardsw,
     61  1.1  matt 		.ac_chipid =		ARCHIP_AR5312,
     62  1.1  matt 		.ac_chipmask =		0xff,
     63  1.1  matt 		.ac_cid =		MIPS_PRID_CID_MTI,
     64  1.1  matt 		.ac_pid =		MIPS_4Kc,
     65  1.1  matt 		.ac_name =		"AR5312"
     66  1.1  matt 	},
     67  1.1  matt #endif
     68  1.1  matt #ifdef WISOC_AR5315
     69  1.1  matt 	{
     70  1.1  matt 		.ac_platformsw =	&ar5315_platformsw,
     71  1.1  matt 		.ac_boardsw =		&ar5315_boardsw,
     72  1.1  matt 		.ac_chipid =		ARCHIP_AR5315,
     73  1.1  matt 		.ac_chipmask =		0xf0,
     74  1.1  matt 		.ac_cid =		MIPS_PRID_CID_MTI,
     75  1.1  matt 		.ac_pid =		MIPS_4Kc,
     76  1.1  matt 		.ac_name =		"AR5315"
     77  1.1  matt 	},
     78  1.1  matt #endif
     79  1.1  matt #ifdef WISOC_AR7100
     80  1.1  matt 	{
     81  1.1  matt 		.ac_platformsw =	&ar7100_platformsw,
     82  1.1  matt 		.ac_chipid =		ARCHIP_AR7130,
     83  1.1  matt 		.ac_chipmask =		0xf3,
     84  1.1  matt 		.ac_cid =		MIPS_PRID_CID_MTI,
     85  1.1  matt 		.ac_pid =		MIPS_24K,
     86  1.1  matt 		.ac_name =		"AR7130"
     87  1.1  matt 	}, {
     88  1.1  matt 		.ac_platformsw =	&ar7100_platformsw,
     89  1.1  matt 		.ac_chipid =		ARCHIP_AR7141,
     90  1.1  matt 		.ac_chipmask =		0xf3,
     91  1.1  matt 		.ac_cid =		MIPS_PRID_CID_MTI,
     92  1.1  matt 		.ac_pid =		MIPS_24K,
     93  1.1  matt 		.ac_name =		"AR7141"
     94  1.1  matt 	}, {
     95  1.1  matt 		.ac_platformsw =	&ar7100_platformsw,
     96  1.1  matt 		.ac_chipid =		ARCHIP_AR7161,
     97  1.1  matt 		.ac_chipmask =		0xf3,
     98  1.1  matt 		.ac_cid =		MIPS_PRID_CID_MTI,
     99  1.1  matt 		.ac_pid =		MIPS_24K,
    100  1.1  matt 		.ac_name =		"AR7161"
    101  1.1  matt 	},
    102  1.1  matt #endif
    103  1.1  matt #ifdef WISOC_AR9344
    104  1.1  matt 	{
    105  1.1  matt 		.ac_platformsw =	&ar9344_platformsw,
    106  1.2  matt 		.ac_chipid =		0x20,	/* 7240? */
    107  1.2  matt 		.ac_chipmask =		0xff,
    108  1.2  matt 		.ac_cid =		MIPS_PRID_CID_MTI,
    109  1.2  matt 		.ac_pid =		MIPS_74K,
    110  1.2  matt 		.ac_name =		"AR7240"
    111  1.2  matt 	}, {
    112  1.2  matt 		.ac_platformsw =	&ar9344_platformsw,
    113  1.1  matt 		.ac_chipid =		ARCHIP_AR9344,
    114  1.1  matt 		.ac_chipmask =		0xff,
    115  1.1  matt 		.ac_cid =		MIPS_PRID_CID_MTI,
    116  1.1  matt 		.ac_pid =		MIPS_74K,
    117  1.1  matt 		.ac_name =		"AR9344"
    118  1.1  matt 	},
    119  1.1  matt #endif
    120  1.1  matt };
    121  1.1  matt 
    122  1.1  matt __CTASSERT(__arraycount(chips) > 0);
    123  1.1  matt 
    124  1.1  matt const struct atheros_platformsw *platformsw;
    125  1.1  matt 
    126  1.1  matt static const struct atheros_chip *my_chip;
    127  1.1  matt 
    128  1.1  matt static struct arfreqs chip_freqs;
    129  1.1  matt 
    130  1.1  matt const char *
    131  1.1  matt atheros_get_cpuname(void)
    132  1.1  matt {
    133  1.1  matt 	return my_chip->ac_name;
    134  1.1  matt }
    135  1.1  matt 
    136  1.1  matt u_int
    137  1.1  matt atheros_get_chipid(void)
    138  1.1  matt {
    139  1.1  matt 	return my_chip->ac_chipid;
    140  1.1  matt }
    141  1.1  matt 
    142  1.1  matt uint32_t
    143  1.2  matt atheros_get_uart_freq(void)
    144  1.2  matt {
    145  1.2  matt 	if (chip_freqs.freq_uart)
    146  1.2  matt 		return chip_freqs.freq_uart;
    147  1.2  matt 
    148  1.2  matt 	return chip_freqs.freq_bus;
    149  1.2  matt }
    150  1.2  matt 
    151  1.2  matt uint32_t
    152  1.1  matt atheros_get_bus_freq(void)
    153  1.1  matt {
    154  1.1  matt 	return chip_freqs.freq_bus;
    155  1.1  matt }
    156  1.1  matt 
    157  1.1  matt uint32_t
    158  1.1  matt atheros_get_cpu_freq(void)
    159  1.1  matt {
    160  1.1  matt 	return chip_freqs.freq_cpu;
    161  1.1  matt }
    162  1.1  matt 
    163  1.1  matt uint32_t
    164  1.1  matt atheros_get_mem_freq(void)
    165  1.1  matt {
    166  1.1  matt 	return chip_freqs.freq_mem;
    167  1.1  matt }
    168  1.1  matt 
    169  1.1  matt void
    170  1.1  matt atheros_set_platformsw(void)
    171  1.1  matt {
    172  1.1  matt 	const u_int cid = MIPS_PRID_CID(mips_options.mips_cpu_id);
    173  1.1  matt 	const u_int pid = MIPS_PRID_IMPL(mips_options.mips_cpu_id);
    174  1.1  matt 
    175  1.1  matt 	for (const struct atheros_chip *ac = chips;
    176  1.1  matt 	    ac < chips + __arraycount(chips);
    177  1.1  matt 	    ac++) {
    178  1.1  matt 		const struct atheros_platformsw * const apsw = ac->ac_platformsw;
    179  1.1  matt                 if (cid != ac->ac_cid || pid != ac->ac_pid)
    180  1.1  matt 			continue;
    181  1.1  matt 
    182  1.1  matt 		const uint32_t revision_id = *(volatile uint32_t *)
    183  1.1  matt 		    MIPS_PHYS_TO_KSEG1(apsw->apsw_revision_id_addr);
    184  1.1  matt 		const uint32_t chipid = AR9344_REVISION_CHIPID(revision_id);
    185  1.1  matt 
    186  1.1  matt 		if ((chipid & ac->ac_chipmask) == ac->ac_chipid) {
    187  1.1  matt 			platformsw = apsw;
    188  1.1  matt 			my_chip = ac;
    189  1.1  matt 			atheros_early_consinit();
    190  1.1  matt 			printf("Early console started!\n");
    191  1.1  matt 			(*apsw->apsw_get_freqs)(&chip_freqs);
    192  1.2  matt 			printf("freqs: cpu=%u bus=%u mem=%u ref=%u pll=%u\n",
    193  1.2  matt 			     chip_freqs.freq_cpu,
    194  1.2  matt 			     chip_freqs.freq_bus,
    195  1.2  matt 			     chip_freqs.freq_mem,
    196  1.2  matt 			     chip_freqs.freq_ref,
    197  1.2  matt 			     chip_freqs.freq_pll);
    198  1.1  matt 			return;
    199  1.1  matt 		}
    200  1.1  matt 	}
    201  1.1  matt 	panic("%s: unrecognized platform", __func__);
    202  1.1  matt }
    203  1.1  matt 
    204  1.1  matt #include "ath_arbus.h"
    205  1.1  matt #if NATH_ARBUS > 0
    206  1.1  matt #include <ah_soc.h>
    207  1.1  matt 
    208  1.1  matt const struct ar531x_boarddata *
    209  1.1  matt atheros_get_board_info(void)
    210  1.1  matt {
    211  1.1  matt 	const struct atheros_boardsw * const boardsw = my_chip->ac_boardsw;
    212  1.1  matt 	if (boardsw == NULL)
    213  1.1  matt 		return NULL;
    214  1.1  matt 	return (*boardsw->absw_get_board_info)();
    215  1.1  matt }
    216  1.1  matt 
    217  1.1  matt /*
    218  1.1  matt  * Locate board and radio configuration data in flash.
    219  1.1  matt  */
    220  1.1  matt int
    221  1.1  matt atheros_get_board_config(struct ar531x_config *config)
    222  1.1  matt {
    223  1.1  matt 	const struct atheros_boardsw * const boardsw = my_chip->ac_boardsw;
    224  1.1  matt 	if (boardsw == NULL)
    225  1.1  matt 		return ENOENT;
    226  1.1  matt 
    227  1.1  matt 	config->board = (*boardsw->absw_get_board_info)();
    228  1.1  matt 	if (config->board == NULL)
    229  1.1  matt 		return ENOENT;
    230  1.1  matt 
    231  1.1  matt 	config->radio = (*boardsw->absw_get_radio_info)();
    232  1.1  matt 	if (config->radio == NULL)
    233  1.1  matt 		return ENOENT;		/* XXX distinct code */
    234  1.1  matt 
    235  1.1  matt 	return 0;
    236  1.1  matt }
    237  1.1  matt #endif /* NATH_ARBUS > 0 */
    238