Home | History | Annotate | Line # | Download | only in atheros
ar5315_board.c revision 1.1.72.1
      1  1.1.72.1      snj /* $NetBSD: ar5315_board.c,v 1.1.72.1 2009/08/07 06:50:48 snj Exp $ */
      2       1.1  gdamore 
      3       1.1  gdamore /*
      4       1.1  gdamore  * Copyright (c) 2006 Urbana-Champaign Independent Media Center.
      5       1.1  gdamore  * Copyright (c) 2006 Garrett D'Amore.
      6       1.1  gdamore  * All rights reserved.
      7       1.1  gdamore  *
      8       1.1  gdamore  * Portions of this code were written by Garrett D'Amore for the
      9       1.1  gdamore  * Champaign-Urbana Community Wireless Network Project.
     10       1.1  gdamore  *
     11       1.1  gdamore  * Redistribution and use in source and binary forms, with or
     12       1.1  gdamore  * without modification, are permitted provided that the following
     13       1.1  gdamore  * conditions are met:
     14       1.1  gdamore  * 1. Redistributions of source code must retain the above copyright
     15       1.1  gdamore  *    notice, this list of conditions and the following disclaimer.
     16       1.1  gdamore  * 2. Redistributions in binary form must reproduce the above
     17       1.1  gdamore  *    copyright notice, this list of conditions and the following
     18       1.1  gdamore  *    disclaimer in the documentation and/or other materials provided
     19       1.1  gdamore  *    with the distribution.
     20       1.1  gdamore  * 3. All advertising materials mentioning features or use of this
     21       1.1  gdamore  *    software must display the following acknowledgements:
     22       1.1  gdamore  *      This product includes software developed by the Urbana-Champaign
     23       1.1  gdamore  *      Independent Media Center.
     24       1.1  gdamore  *	This product includes software developed by Garrett D'Amore.
     25       1.1  gdamore  * 4. Urbana-Champaign Independent Media Center's name and Garrett
     26       1.1  gdamore  *    D'Amore's name may not be used to endorse or promote products
     27       1.1  gdamore  *    derived from this software without specific prior written permission.
     28       1.1  gdamore  *
     29       1.1  gdamore  * THIS SOFTWARE IS PROVIDED BY THE URBANA-CHAMPAIGN INDEPENDENT
     30       1.1  gdamore  * MEDIA CENTER AND GARRETT D'AMORE ``AS IS'' AND ANY EXPRESS OR
     31       1.1  gdamore  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     32       1.1  gdamore  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     33       1.1  gdamore  * ARE DISCLAIMED.  IN NO EVENT SHALL THE URBANA-CHAMPAIGN INDEPENDENT
     34       1.1  gdamore  * MEDIA CENTER OR GARRETT D'AMORE BE LIABLE FOR ANY DIRECT, INDIRECT,
     35       1.1  gdamore  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     36       1.1  gdamore  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     37       1.1  gdamore  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
     38       1.1  gdamore  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39       1.1  gdamore  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     40       1.1  gdamore  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
     41       1.1  gdamore  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     42       1.1  gdamore  */
     43       1.1  gdamore 
     44       1.1  gdamore /*
     45       1.1  gdamore  * This file provides code to locate board-specific configuration and radio
     46       1.1  gdamore  * information data in flash for the AR5315.
     47       1.1  gdamore  */
     48       1.1  gdamore #include <sys/cdefs.h>
     49  1.1.72.1      snj __KERNEL_RCSID(0, "$NetBSD: ar5315_board.c,v 1.1.72.1 2009/08/07 06:50:48 snj Exp $");
     50       1.1  gdamore 
     51       1.1  gdamore #include "opt_ddb.h"
     52       1.1  gdamore #include "opt_kgdb.h"
     53       1.1  gdamore 
     54       1.1  gdamore #include "opt_memsize.h"
     55       1.1  gdamore #include <sys/param.h>
     56       1.1  gdamore #include <sys/systm.h>
     57       1.1  gdamore #include <sys/kernel.h>
     58       1.1  gdamore #include <sys/buf.h>
     59       1.1  gdamore 
     60       1.1  gdamore #include <dev/cons.h>
     61       1.1  gdamore 
     62       1.1  gdamore #include <mips/cache.h>
     63       1.1  gdamore #include <mips/locore.h>
     64       1.1  gdamore #include <mips/cpuregs.h>
     65       1.1  gdamore 
     66       1.1  gdamore #include <net/if.h>
     67       1.1  gdamore #include <net/if_ether.h>
     68       1.1  gdamore 
     69  1.1.72.1      snj #include <ah_soc.h>	/* XXX really doesn't belong in hal */
     70       1.1  gdamore 
     71       1.1  gdamore #include <mips/atheros/include/ar5315reg.h>
     72       1.1  gdamore #include <mips/atheros/include/ar531xvar.h>
     73       1.1  gdamore #include <mips/atheros/include/arbusvar.h>
     74       1.1  gdamore 
     75       1.1  gdamore #include <machine/locore.h>
     76       1.1  gdamore #include "com.h"
     77       1.1  gdamore 
     78       1.1  gdamore /*
     79       1.1  gdamore  * Locate the Board Configuration data using heuristics.
     80       1.1  gdamore  * Search backward from the (aliased) end of flash looking
     81       1.1  gdamore  * for the signature string that marks the start of the data.
     82       1.1  gdamore  * We search at most 500KB.
     83       1.1  gdamore  */
     84       1.1  gdamore const struct ar531x_boarddata *
     85       1.1  gdamore ar531x_board_info(void)
     86       1.1  gdamore {
     87       1.1  gdamore 	static const struct ar531x_boarddata *board = NULL;
     88       1.1  gdamore 	const uint8_t *ptr, *end;
     89       1.1  gdamore 
     90       1.1  gdamore 	if (board == NULL) {
     91       1.1  gdamore 
     92       1.1  gdamore 		/* search backward in the flash looking for the signature */
     93       1.1  gdamore 		ptr = (const uint8_t *) MIPS_PHYS_TO_KSEG1(AR5315_CONFIG_END
     94       1.1  gdamore 		    - 0x1000);
     95       1.1  gdamore 		end = (const uint8_t *)AR5315_CONFIG_BASE;
     96       1.1  gdamore 		/* XXX validate end */
     97       1.1  gdamore 		for (; ptr > end; ptr -= 0x1000)
     98       1.1  gdamore 			if (*(const uint32_t *)ptr == AR531X_BD_MAGIC) {
     99       1.1  gdamore 				board = (const struct ar531x_boarddata *) ptr;
    100       1.1  gdamore 				break;
    101       1.1  gdamore 			}
    102       1.1  gdamore 	}
    103       1.1  gdamore 	return board;
    104       1.1  gdamore }
    105       1.1  gdamore 
    106       1.1  gdamore /*
    107       1.1  gdamore  * Locate the radio configuration data; it is located relative to the
    108       1.1  gdamore  * board configuration data.
    109       1.1  gdamore  */
    110       1.1  gdamore const void *
    111       1.1  gdamore ar531x_radio_info(void)
    112       1.1  gdamore {
    113       1.1  gdamore 	static const void *radio = NULL;
    114       1.1  gdamore 	const struct ar531x_boarddata *board;
    115       1.1  gdamore 	const uint8_t *baddr, *ptr, *end;
    116       1.1  gdamore 
    117       1.1  gdamore 	if (radio)
    118       1.1  gdamore 		goto done;
    119       1.1  gdamore 
    120       1.1  gdamore 	board = ar531x_board_info();
    121       1.1  gdamore 	if (board == NULL)
    122       1.1  gdamore 		return NULL;
    123       1.1  gdamore 	baddr = (const uint8_t *) board;
    124       1.1  gdamore 	end = (const uint8_t *)MIPS_PHYS_TO_KSEG1(AR5315_RADIO_END);
    125       1.1  gdamore 
    126       1.1  gdamore 	for (ptr = baddr + 0x1000; ptr < end; ptr += 0x1000)
    127       1.1  gdamore 		if (*(const uint32_t *)ptr != 0xffffffffU) {
    128       1.1  gdamore 			radio = ptr;
    129       1.1  gdamore 			goto done;
    130       1.1  gdamore 		}
    131       1.1  gdamore 
    132       1.1  gdamore 	/* AR2316 moves radio data */
    133       1.1  gdamore 	for (ptr = baddr + 0xf8; ptr < end; ptr += 0x1000)
    134       1.1  gdamore 		if (*(const uint32_t *)ptr != 0xffffffffU) {
    135       1.1  gdamore 			radio = ptr;
    136       1.1  gdamore 			goto done;
    137       1.1  gdamore 		}
    138       1.1  gdamore 
    139       1.1  gdamore done:
    140       1.1  gdamore 	return radio;
    141       1.1  gdamore }
    142       1.1  gdamore 
    143       1.1  gdamore /*
    144       1.1  gdamore  * Locate board and radio configuration data in flash.
    145       1.1  gdamore  */
    146       1.1  gdamore int
    147       1.1  gdamore ar531x_board_config(struct ar531x_config *config)
    148       1.1  gdamore {
    149       1.1  gdamore 
    150       1.1  gdamore 	config->board = ar531x_board_info();
    151       1.1  gdamore 	if (config->board == NULL)
    152       1.1  gdamore 		return ENOENT;
    153       1.1  gdamore 
    154       1.1  gdamore 	config->radio = ar531x_radio_info();
    155       1.1  gdamore 	if (config->radio == NULL)
    156       1.1  gdamore 		return ENOENT;		/* XXX distinct code */
    157       1.1  gdamore 
    158       1.1  gdamore 	return 0;
    159       1.1  gdamore }
    160