Home | History | Annotate | Line # | Download | only in atheros
      1  1.5     matt /* $NetBSD: ar5312_board.c,v 1.5 2015/06/09 22:50:50 matt Exp $ */
      2  1.1  gdamore /*
      3  1.1  gdamore  * Copyright (c) 2006 Urbana-Champaign Independent Media Center.
      4  1.1  gdamore  * Copyright (c) 2006 Garrett D'Amore.
      5  1.1  gdamore  * All rights reserved.
      6  1.1  gdamore  *
      7  1.1  gdamore  * This code was written by Garrett D'Amore for the Champaign-Urbana
      8  1.1  gdamore  * Community Wireless Network Project.
      9  1.1  gdamore  *
     10  1.1  gdamore  * Redistribution and use in source and binary forms, with or
     11  1.1  gdamore  * without modification, are permitted provided that the following
     12  1.1  gdamore  * conditions are met:
     13  1.1  gdamore  * 1. Redistributions of source code must retain the above copyright
     14  1.1  gdamore  *    notice, this list of conditions and the following disclaimer.
     15  1.1  gdamore  * 2. Redistributions in binary form must reproduce the above
     16  1.1  gdamore  *    copyright notice, this list of conditions and the following
     17  1.1  gdamore  *    disclaimer in the documentation and/or other materials provided
     18  1.1  gdamore  *    with the distribution.
     19  1.1  gdamore  * 3. All advertising materials mentioning features or use of this
     20  1.1  gdamore  *    software must display the following acknowledgements:
     21  1.1  gdamore  *      This product includes software developed by the Urbana-Champaign
     22  1.1  gdamore  *      Independent Media Center.
     23  1.1  gdamore  *	This product includes software developed by Garrett D'Amore.
     24  1.1  gdamore  * 4. Urbana-Champaign Independent Media Center's name and Garrett
     25  1.1  gdamore  *    D'Amore's name may not be used to endorse or promote products
     26  1.1  gdamore  *    derived from this software without specific prior written permission.
     27  1.1  gdamore  *
     28  1.1  gdamore  * THIS SOFTWARE IS PROVIDED BY THE URBANA-CHAMPAIGN INDEPENDENT
     29  1.1  gdamore  * MEDIA CENTER AND GARRETT D'AMORE ``AS IS'' AND ANY EXPRESS OR
     30  1.1  gdamore  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     31  1.1  gdamore  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     32  1.1  gdamore  * ARE DISCLAIMED.  IN NO EVENT SHALL THE URBANA-CHAMPAIGN INDEPENDENT
     33  1.1  gdamore  * MEDIA CENTER OR GARRETT D'AMORE BE LIABLE FOR ANY DIRECT, INDIRECT,
     34  1.1  gdamore  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     35  1.1  gdamore  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     36  1.1  gdamore  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
     37  1.1  gdamore  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     38  1.1  gdamore  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     39  1.1  gdamore  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
     40  1.1  gdamore  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     41  1.1  gdamore  */
     42  1.1  gdamore #include <sys/cdefs.h>
     43  1.5     matt __KERNEL_RCSID(0, "$NetBSD: ar5312_board.c,v 1.5 2015/06/09 22:50:50 matt Exp $");
     44  1.1  gdamore 
     45  1.1  gdamore #include <sys/param.h>
     46  1.5     matt #include <sys/bus.h>
     47  1.5     matt #include <sys/device.h>
     48  1.1  gdamore #include <sys/systm.h>
     49  1.1  gdamore 
     50  1.5     matt #include <mips/cpuregs.h>
     51  1.5     matt 
     52  1.1  gdamore #include <mips/atheros/include/ar5312reg.h>
     53  1.4     matt #include <mips/atheros/include/platform.h>
     54  1.1  gdamore 
     55  1.2      alc #include <ah_soc.h>
     56  1.1  gdamore 
     57  1.1  gdamore extern const char *ether_sprintf(const uint8_t *);
     58  1.1  gdamore 
     59  1.1  gdamore /*
     60  1.1  gdamore  * Locate the Board Configuration data using heuristics.
     61  1.1  gdamore  * Search backward from the (aliased) end of flash looking
     62  1.1  gdamore  * for the signature string that marks the start of the data.
     63  1.1  gdamore  * We search at most 500KB.
     64  1.1  gdamore  */
     65  1.4     matt static const struct ar531x_boarddata *
     66  1.4     matt ar5312_get_board_info(void)
     67  1.1  gdamore {
     68  1.1  gdamore 	static const struct ar531x_boarddata *board = NULL;
     69  1.1  gdamore 	const uint8_t *ptr, *end;
     70  1.1  gdamore 	uint32_t fctl;
     71  1.1  gdamore 
     72  1.1  gdamore 	if (board == NULL) {
     73  1.1  gdamore 		/* configure flash bank 0 */
     74  1.1  gdamore 		fctl = REGVAL(AR5312_FLASHCTL_BASE + AR5312_FLASHCTL_0) &
     75  1.4     matt 		    AR5312_FLASHCTL_MW;
     76  1.1  gdamore 
     77  1.1  gdamore 		fctl |=
     78  1.1  gdamore 		    AR5312_FLASHCTL_E |
     79  1.1  gdamore 		    AR5312_FLASHCTL_RBLE |
     80  1.1  gdamore 		    AR5312_FLASHCTL_AC_8M |
     81  1.4     matt 		    __SHIFTIN(1, AR5312_FLASHCTL_IDCY) |
     82  1.4     matt 		    __SHIFTIN(7, AR5312_FLASHCTL_WST1) |
     83  1.4     matt 		    __SHIFTIN(7, AR5312_FLASHCTL_WST2);
     84  1.1  gdamore 
     85  1.1  gdamore 		REGVAL(AR5312_FLASHCTL_BASE + AR5312_FLASHCTL_0) = fctl;
     86  1.1  gdamore 
     87  1.1  gdamore 		REGVAL(AR5312_FLASHCTL_BASE + AR5312_FLASHCTL_1) &=
     88  1.4     matt 		    ~(AR5312_FLASHCTL_E | AR5312_FLASHCTL_AC);
     89  1.1  gdamore 
     90  1.1  gdamore 		REGVAL(AR5312_FLASHCTL_BASE + AR5312_FLASHCTL_2) &=
     91  1.4     matt 		    ~(AR5312_FLASHCTL_E | AR5312_FLASHCTL_AC);
     92  1.1  gdamore 
     93  1.1  gdamore 		/* search backward in the flash looking for the signature */
     94  1.1  gdamore 		ptr = (const uint8_t *) MIPS_PHYS_TO_KSEG1(AR5312_FLASH_END - 0x1000);
     95  1.1  gdamore 		end = ptr - (500 * 1024);	/* NB: max 500KB window */
     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
    108  1.1  gdamore  * to the board configuration data.
    109  1.1  gdamore  */
    110  1.4     matt static const void *
    111  1.4     matt ar5312_get_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 == NULL) {
    118  1.4     matt 		board = ar5312_get_board_info();
    119  1.1  gdamore 		if (board == NULL)
    120  1.1  gdamore 			return NULL;
    121  1.1  gdamore 		baddr = (const uint8_t *) board;
    122  1.1  gdamore 		ptr = baddr + 0x1000;
    123  1.1  gdamore 		end = (const uint8_t *)
    124  1.1  gdamore 		    MIPS_PHYS_TO_KSEG1(AR5312_FLASH_END-0x1000);
    125  1.1  gdamore 	again:
    126  1.1  gdamore 		for (; ptr < end; ptr += 0x1000)
    127  1.1  gdamore 			if (*(const uint32_t *)ptr != 0xffffffff) {
    128  1.1  gdamore 				radio = ptr;
    129  1.1  gdamore 				goto done;
    130  1.1  gdamore 			}
    131  1.1  gdamore 		/* sort of an Algol-style for loop ... */
    132  1.1  gdamore 		if (end == (uint8_t *) MIPS_PHYS_TO_KSEG1(AR5312_FLASH_END)) {
    133  1.1  gdamore 			/* NB: AR2316 has radio data in a different location */
    134  1.1  gdamore 			ptr = baddr + 0xf8;
    135  1.1  gdamore 			end = (const uint8_t *)
    136  1.1  gdamore 			    MIPS_PHYS_TO_KSEG1(AR5312_FLASH_END-0x1000 + 0xf8);
    137  1.1  gdamore 			goto again;
    138  1.1  gdamore 		}
    139  1.1  gdamore 	}
    140  1.1  gdamore done:
    141  1.1  gdamore 	return radio;
    142  1.1  gdamore }
    143  1.1  gdamore 
    144  1.4     matt const struct atheros_boardsw ar5312_boardsw = {
    145  1.4     matt 	.absw_get_board_info = ar5312_get_board_info,
    146  1.4     matt 	.absw_get_radio_info = ar5312_get_radio_info,
    147  1.4     matt };
    148