Home | History | Annotate | Line # | Download | only in atheros
arbus.c revision 1.2.2.5
      1  1.2.2.5  yamt /* $Id: arbus.c,v 1.2.2.5 2006/08/11 15:42:14 yamt Exp $ */
      2  1.2.2.2  yamt /*
      3  1.2.2.2  yamt  * Copyright (c) 2006 Urbana-Champaign Independent Media Center.
      4  1.2.2.2  yamt  * Copyright (c) 2006 Garrett D'Amore.
      5  1.2.2.2  yamt  * All rights reserved.
      6  1.2.2.2  yamt  *
      7  1.2.2.2  yamt  * This code was written by Garrett D'Amore for the Champaign-Urbana
      8  1.2.2.2  yamt  * Community Wireless Network Project.
      9  1.2.2.2  yamt  *
     10  1.2.2.2  yamt  * Redistribution and use in source and binary forms, with or
     11  1.2.2.2  yamt  * without modification, are permitted provided that the following
     12  1.2.2.2  yamt  * conditions are met:
     13  1.2.2.2  yamt  * 1. Redistributions of source code must retain the above copyright
     14  1.2.2.2  yamt  *    notice, this list of conditions and the following disclaimer.
     15  1.2.2.2  yamt  * 2. Redistributions in binary form must reproduce the above
     16  1.2.2.2  yamt  *    copyright notice, this list of conditions and the following
     17  1.2.2.2  yamt  *    disclaimer in the documentation and/or other materials provided
     18  1.2.2.2  yamt  *    with the distribution.
     19  1.2.2.2  yamt  * 3. All advertising materials mentioning features or use of this
     20  1.2.2.2  yamt  *    software must display the following acknowledgements:
     21  1.2.2.2  yamt  *      This product includes software developed by the Urbana-Champaign
     22  1.2.2.2  yamt  *      Independent Media Center.
     23  1.2.2.2  yamt  *	This product includes software developed by Garrett D'Amore.
     24  1.2.2.2  yamt  * 4. Urbana-Champaign Independent Media Center's name and Garrett
     25  1.2.2.2  yamt  *    D'Amore's name may not be used to endorse or promote products
     26  1.2.2.2  yamt  *    derived from this software without specific prior written permission.
     27  1.2.2.2  yamt  *
     28  1.2.2.2  yamt  * THIS SOFTWARE IS PROVIDED BY THE URBANA-CHAMPAIGN INDEPENDENT
     29  1.2.2.2  yamt  * MEDIA CENTER AND GARRETT D'AMORE ``AS IS'' AND ANY EXPRESS OR
     30  1.2.2.2  yamt  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     31  1.2.2.2  yamt  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     32  1.2.2.2  yamt  * ARE DISCLAIMED.  IN NO EVENT SHALL THE URBANA-CHAMPAIGN INDEPENDENT
     33  1.2.2.2  yamt  * MEDIA CENTER OR GARRETT D'AMORE BE LIABLE FOR ANY DIRECT, INDIRECT,
     34  1.2.2.2  yamt  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     35  1.2.2.2  yamt  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     36  1.2.2.2  yamt  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
     37  1.2.2.2  yamt  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     38  1.2.2.2  yamt  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     39  1.2.2.2  yamt  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
     40  1.2.2.2  yamt  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     41  1.2.2.2  yamt  */
     42  1.2.2.2  yamt 
     43  1.2.2.2  yamt #include <sys/cdefs.h>
     44  1.2.2.5  yamt __KERNEL_RCSID(0, "$NetBSD: arbus.c,v 1.2.2.5 2006/08/11 15:42:14 yamt Exp $");
     45  1.2.2.2  yamt 
     46  1.2.2.2  yamt #include "locators.h"
     47  1.2.2.2  yamt #include <sys/param.h>
     48  1.2.2.2  yamt #include <sys/systm.h>
     49  1.2.2.2  yamt #include <sys/device.h>
     50  1.2.2.2  yamt #include <sys/extent.h>
     51  1.2.2.2  yamt #include <sys/malloc.h>
     52  1.2.2.2  yamt 
     53  1.2.2.2  yamt #define	_MIPS_BUS_DMA_PRIVATE
     54  1.2.2.2  yamt #include <machine/bus.h>
     55  1.2.2.2  yamt #include <mips/atheros/include/ar531xreg.h>
     56  1.2.2.2  yamt #include <mips/atheros/include/ar531xvar.h>
     57  1.2.2.2  yamt #include <mips/atheros/include/arbusvar.h>
     58  1.2.2.2  yamt 
     59  1.2.2.2  yamt static int arbus_match(struct device *, struct cfdata *, void *);
     60  1.2.2.2  yamt static void arbus_attach(struct device *, struct device *, void *);
     61  1.2.2.2  yamt static int arbus_print(void *, const char *);
     62  1.2.2.2  yamt static void arbus_bus_mem_init(bus_space_tag_t, void *);
     63  1.2.2.2  yamt static void arbus_dma_init(struct device *, bus_dma_tag_t);
     64  1.2.2.2  yamt 
     65  1.2.2.2  yamt struct arbus_intrhand {
     66  1.2.2.2  yamt 	int		ih_irq;
     67  1.2.2.2  yamt 	int		ih_misc;
     68  1.2.2.2  yamt 	void		*ih_cookie;
     69  1.2.2.2  yamt };
     70  1.2.2.2  yamt 
     71  1.2.2.2  yamt CFATTACH_DECL(arbus, sizeof(struct device), arbus_match, arbus_attach,
     72  1.2.2.2  yamt     NULL, NULL);
     73  1.2.2.2  yamt 
     74  1.2.2.2  yamt struct mips_bus_space	arbus_mbst;
     75  1.2.2.2  yamt struct mips_bus_dma_tag	arbus_mdt;
     76  1.2.2.2  yamt 
     77  1.2.2.2  yamt void
     78  1.2.2.2  yamt arbus_init(void)
     79  1.2.2.2  yamt {
     80  1.2.2.2  yamt 	static int done = 0;
     81  1.2.2.2  yamt 	if (done)
     82  1.2.2.2  yamt 		return;
     83  1.2.2.2  yamt 	done++;
     84  1.2.2.2  yamt 
     85  1.2.2.2  yamt 	arbus_bus_mem_init(&arbus_mbst, NULL);
     86  1.2.2.2  yamt 	arbus_dma_init(NULL, &arbus_mdt);
     87  1.2.2.2  yamt }
     88  1.2.2.2  yamt 
     89  1.2.2.2  yamt static struct {
     90  1.2.2.2  yamt 	const char	*name;
     91  1.2.2.2  yamt 	bus_addr_t	addr;
     92  1.2.2.2  yamt 	int		irq;
     93  1.2.2.2  yamt 	uint32_t	mask;
     94  1.2.2.2  yamt 	uint32_t	reset;
     95  1.2.2.2  yamt 	uint32_t	enable;
     96  1.2.2.2  yamt } arbus_devices[] = {
     97  1.2.2.2  yamt     {
     98  1.2.2.2  yamt 	    "ae",
     99  1.2.2.2  yamt 	    AR531X_ENET0_BASE,
    100  1.2.2.2  yamt 	    ARBUS_IRQ_ENET0,
    101  1.2.2.2  yamt 	    AR531X_BOARD_CONFIG_ENET0,
    102  1.2.2.2  yamt 	    AR531X_RESET_ENET0 | AR531X_RESET_PHY0,
    103  1.2.2.2  yamt 	    AR531X_ENABLE_ENET0
    104  1.2.2.2  yamt     },
    105  1.2.2.2  yamt     {
    106  1.2.2.2  yamt 	    "ae",
    107  1.2.2.2  yamt 	    AR531X_ENET1_BASE,
    108  1.2.2.2  yamt 	    ARBUS_IRQ_ENET1,
    109  1.2.2.2  yamt 	    AR531X_BOARD_CONFIG_ENET1,
    110  1.2.2.2  yamt 	    AR531X_RESET_ENET1 | AR531X_RESET_PHY1,
    111  1.2.2.2  yamt 	    AR531X_ENABLE_ENET1
    112  1.2.2.2  yamt     },
    113  1.2.2.2  yamt     {
    114  1.2.2.2  yamt 	    "com",
    115  1.2.2.2  yamt 	    AR531X_UART0_BASE,
    116  1.2.2.2  yamt 	    ARBUS_IRQ_UART0,
    117  1.2.2.2  yamt 	    AR531X_BOARD_CONFIG_UART0,
    118  1.2.2.2  yamt 	    0,
    119  1.2.2.2  yamt 	    0,
    120  1.2.2.2  yamt     },
    121  1.2.2.2  yamt     {
    122  1.2.2.2  yamt 	    "com",
    123  1.2.2.2  yamt 	    AR531X_UART1_BASE,
    124  1.2.2.2  yamt 	    -1,
    125  1.2.2.2  yamt 	    AR531X_BOARD_CONFIG_UART1,
    126  1.2.2.2  yamt 	    0,
    127  1.2.2.2  yamt 	    0,
    128  1.2.2.2  yamt     },
    129  1.2.2.2  yamt     {
    130  1.2.2.2  yamt 	    "ath",
    131  1.2.2.2  yamt 	    AR531X_WLAN0_BASE,
    132  1.2.2.2  yamt 	    ARBUS_IRQ_WLAN0,
    133  1.2.2.2  yamt 	    AR531X_BOARD_CONFIG_WLAN0,
    134  1.2.2.2  yamt 	    AR531X_RESET_WLAN0 |
    135  1.2.2.2  yamt 	    	AR531X_RESET_WARM_WLAN0_MAC |
    136  1.2.2.2  yamt 	    	AR531X_RESET_WARM_WLAN0_BB,
    137  1.2.2.2  yamt 	    AR531X_ENABLE_WLAN0
    138  1.2.2.2  yamt     },
    139  1.2.2.2  yamt     {
    140  1.2.2.2  yamt 	    "ath",
    141  1.2.2.2  yamt 	    AR531X_WLAN1_BASE,
    142  1.2.2.2  yamt 	    ARBUS_IRQ_WLAN1,
    143  1.2.2.2  yamt 	    AR531X_BOARD_CONFIG_WLAN1,
    144  1.2.2.2  yamt 	    AR531X_RESET_WLAN1 |
    145  1.2.2.2  yamt 	    	AR531X_RESET_WARM_WLAN1_MAC |
    146  1.2.2.2  yamt 	    	AR531X_RESET_WARM_WLAN1_BB,
    147  1.2.2.2  yamt 	    AR531X_ENABLE_WLAN1
    148  1.2.2.2  yamt     },
    149  1.2.2.4  yamt     {
    150  1.2.2.4  yamt 	    "athflash",
    151  1.2.2.4  yamt 	    AR531X_FLASH_BASE,
    152  1.2.2.4  yamt 	    -1,
    153  1.2.2.4  yamt 	    0,
    154  1.2.2.4  yamt 	    0,
    155  1.2.2.4  yamt 	    0,
    156  1.2.2.4  yamt     },
    157  1.2.2.2  yamt     {
    158  1.2.2.2  yamt 	    "argpio",
    159  1.2.2.2  yamt 	    AR531X_GPIO_BASE,
    160  1.2.2.5  yamt 	    ARBUS_IRQ_GPIO,
    161  1.2.2.2  yamt 	    0,
    162  1.2.2.2  yamt 	    0,
    163  1.2.2.2  yamt 	    0
    164  1.2.2.2  yamt     },
    165  1.2.2.2  yamt     { NULL }
    166  1.2.2.2  yamt };
    167  1.2.2.2  yamt 
    168  1.2.2.2  yamt /* this primarily exists so we can get to the console... */
    169  1.2.2.2  yamt bus_space_tag_t
    170  1.2.2.2  yamt arbus_get_bus_space_tag(void)
    171  1.2.2.2  yamt {
    172  1.2.2.2  yamt 	arbus_init();
    173  1.2.2.2  yamt 	return (&arbus_mbst);
    174  1.2.2.2  yamt }
    175  1.2.2.2  yamt 
    176  1.2.2.2  yamt bus_dma_tag_t
    177  1.2.2.2  yamt arbus_get_bus_dma_tag(void)
    178  1.2.2.2  yamt {
    179  1.2.2.2  yamt 	arbus_init();
    180  1.2.2.2  yamt 	return (&arbus_mdt);
    181  1.2.2.2  yamt }
    182  1.2.2.2  yamt 
    183  1.2.2.2  yamt int
    184  1.2.2.2  yamt arbus_match(struct device *parent, struct cfdata *match, void *aux)
    185  1.2.2.2  yamt {
    186  1.2.2.2  yamt 
    187  1.2.2.2  yamt 	return 1;
    188  1.2.2.2  yamt }
    189  1.2.2.2  yamt 
    190  1.2.2.2  yamt void
    191  1.2.2.2  yamt arbus_attach(struct device *parent, struct device *self, void *aux)
    192  1.2.2.2  yamt {
    193  1.2.2.2  yamt 	struct arbus_attach_args aa;
    194  1.2.2.4  yamt 	const struct ar531x_boarddata *info;
    195  1.2.2.2  yamt 	int i;
    196  1.2.2.2  yamt 
    197  1.2.2.2  yamt 	printf("\n");
    198  1.2.2.2  yamt 	int locs[ARBUSCF_NLOCS];
    199  1.2.2.2  yamt 
    200  1.2.2.2  yamt 	info = ar531x_board_info();
    201  1.2.2.2  yamt 	arbus_init();
    202  1.2.2.2  yamt 
    203  1.2.2.2  yamt 	for (i = 0; arbus_devices[i].name; i++) {
    204  1.2.2.3  yamt 		if (arbus_devices[i].mask &&
    205  1.2.2.4  yamt 		    ((arbus_devices[i].mask & info->config) == 0)) {
    206  1.2.2.2  yamt 			continue;
    207  1.2.2.2  yamt 		}
    208  1.2.2.2  yamt 		aa.aa_name = arbus_devices[i].name;
    209  1.2.2.2  yamt 		aa.aa_dmat = &arbus_mdt;
    210  1.2.2.2  yamt 		aa.aa_bst = &arbus_mbst;
    211  1.2.2.2  yamt 		aa.aa_irq = arbus_devices[i].irq;
    212  1.2.2.2  yamt 		aa.aa_addr = arbus_devices[i].addr;
    213  1.2.2.2  yamt 
    214  1.2.2.4  yamt 		if (aa.aa_addr < AR531X_UART0_BASE)
    215  1.2.2.2  yamt 			aa.aa_size = 0x00100000;
    216  1.2.2.4  yamt 		else if (aa.aa_addr < AR531X_FLASH_BASE)
    217  1.2.2.2  yamt 			aa.aa_size = 0x1000;
    218  1.2.2.2  yamt 
    219  1.2.2.2  yamt 		locs[ARBUSCF_ADDR] = aa.aa_addr;
    220  1.2.2.2  yamt 
    221  1.2.2.2  yamt 		if (arbus_devices[i].reset) {
    222  1.2.2.2  yamt 			/* put device into reset */
    223  1.2.2.2  yamt 			PUTSYSREG(AR531X_SYSREG_RESETCTL,
    224  1.2.2.2  yamt 			    GETSYSREG(AR531X_SYSREG_RESETCTL) |
    225  1.2.2.2  yamt 			    arbus_devices[i].reset);
    226  1.2.2.2  yamt 
    227  1.2.2.2  yamt 			/* this could probably be a tsleep */
    228  1.2.2.2  yamt 			delay(15000);
    229  1.2.2.2  yamt 
    230  1.2.2.2  yamt 			/* take it out of reset */
    231  1.2.2.2  yamt 			PUTSYSREG(AR531X_SYSREG_RESETCTL,
    232  1.2.2.2  yamt 			    GETSYSREG(AR531X_SYSREG_RESETCTL) &
    233  1.2.2.2  yamt 			    ~arbus_devices[i].reset);
    234  1.2.2.2  yamt 
    235  1.2.2.2  yamt 			delay(25);
    236  1.2.2.2  yamt 		}
    237  1.2.2.2  yamt 
    238  1.2.2.2  yamt 		if (arbus_devices[i].enable) {
    239  1.2.2.2  yamt 			/* enable it */
    240  1.2.2.2  yamt 			PUTSYSREG(AR531X_SYSREG_ENABLE,
    241  1.2.2.2  yamt 			    GETSYSREG(AR531X_SYSREG_ENABLE) |
    242  1.2.2.2  yamt 			    arbus_devices[i].enable);
    243  1.2.2.2  yamt 		}
    244  1.2.2.2  yamt 
    245  1.2.2.2  yamt 		(void) config_found_sm_loc(self, "arbus", locs, &aa,
    246  1.2.2.2  yamt 		    arbus_print, config_stdsubmatch);
    247  1.2.2.2  yamt 	}
    248  1.2.2.2  yamt }
    249  1.2.2.2  yamt 
    250  1.2.2.2  yamt int
    251  1.2.2.2  yamt arbus_print(void *aux, const char *pnp)
    252  1.2.2.2  yamt {
    253  1.2.2.2  yamt 	struct arbus_attach_args *aa = aux;
    254  1.2.2.2  yamt 
    255  1.2.2.2  yamt 	if (pnp)
    256  1.2.2.2  yamt 		aprint_normal("%s at %s", aa->aa_name, pnp);
    257  1.2.2.2  yamt 
    258  1.2.2.2  yamt 	if (aa->aa_addr)
    259  1.2.2.2  yamt 		aprint_normal(" addr 0x%lx", aa->aa_addr);
    260  1.2.2.2  yamt 
    261  1.2.2.2  yamt 	if (ARBUS_IRQ_CPU(aa->aa_irq))
    262  1.2.2.2  yamt 		aprint_normal(" interrupt %d", ARBUS_IRQ_CPU(aa->aa_irq));
    263  1.2.2.2  yamt 
    264  1.2.2.2  yamt 	if (ARBUS_IRQ_MISC(aa->aa_irq))
    265  1.2.2.2  yamt 		aprint_normal(" irq %d", ARBUS_IRQ_MISC(aa->aa_irq));
    266  1.2.2.2  yamt 
    267  1.2.2.2  yamt 	return (UNCONF);
    268  1.2.2.2  yamt }
    269  1.2.2.2  yamt 
    270  1.2.2.2  yamt void *
    271  1.2.2.2  yamt arbus_intr_establish(int irq, int (*handler)(void *), void *arg)
    272  1.2.2.2  yamt {
    273  1.2.2.2  yamt 	struct arbus_intrhand	*ih;
    274  1.2.2.2  yamt 
    275  1.2.2.2  yamt 	ih = malloc(sizeof(*ih), M_DEVBUF, M_NOWAIT);
    276  1.2.2.2  yamt 	if (ih == NULL)
    277  1.2.2.2  yamt 		return NULL;
    278  1.2.2.2  yamt 
    279  1.2.2.2  yamt 	ih->ih_irq = irq;
    280  1.2.2.2  yamt 	ih->ih_cookie = NULL;
    281  1.2.2.2  yamt 
    282  1.2.2.2  yamt 	if (ARBUS_IRQ_MISC(irq)) {
    283  1.2.2.2  yamt 		irq = ARBUS_IRQ_MISC(irq);
    284  1.2.2.2  yamt 		ih->ih_misc = 1;
    285  1.2.2.2  yamt 		ih->ih_cookie = ar531x_misc_intr_establish(irq, handler, arg);
    286  1.2.2.2  yamt 	} else {
    287  1.2.2.2  yamt 		irq = ARBUS_IRQ_CPU(irq);
    288  1.2.2.2  yamt 		ih->ih_misc = 0;
    289  1.2.2.2  yamt 		ih->ih_cookie = ar531x_intr_establish(irq, handler, arg);
    290  1.2.2.2  yamt 	}
    291  1.2.2.2  yamt 
    292  1.2.2.2  yamt 	if (ih->ih_cookie == NULL) {
    293  1.2.2.2  yamt 		free(ih, M_DEVBUF);
    294  1.2.2.2  yamt 		return NULL;
    295  1.2.2.2  yamt 	}
    296  1.2.2.2  yamt 	return ih;
    297  1.2.2.2  yamt }
    298  1.2.2.2  yamt 
    299  1.2.2.2  yamt void
    300  1.2.2.2  yamt arbus_intr_disestablish(void *arg)
    301  1.2.2.2  yamt {
    302  1.2.2.2  yamt 	struct arbus_intrhand	*ih = arg;
    303  1.2.2.2  yamt 	if (ih->ih_misc)
    304  1.2.2.2  yamt 		ar531x_misc_intr_disestablish(ih->ih_cookie);
    305  1.2.2.2  yamt 	else
    306  1.2.2.2  yamt 		ar531x_intr_disestablish(ih->ih_cookie);
    307  1.2.2.2  yamt 	free(ih, M_DEVBUF);
    308  1.2.2.2  yamt }
    309  1.2.2.2  yamt 
    310  1.2.2.2  yamt 
    311  1.2.2.2  yamt void
    312  1.2.2.2  yamt arbus_dma_init(struct device *sc, bus_dma_tag_t pdt)
    313  1.2.2.2  yamt {
    314  1.2.2.2  yamt 	bus_dma_tag_t	t;
    315  1.2.2.2  yamt 
    316  1.2.2.2  yamt 	t = pdt;
    317  1.2.2.2  yamt 	t->_cookie = sc;
    318  1.2.2.2  yamt 	t->_wbase = 0;
    319  1.2.2.2  yamt 	t->_physbase = 0;
    320  1.2.2.2  yamt 	t->_wsize = MIPS_KSEG1_START - MIPS_KSEG0_START;
    321  1.2.2.2  yamt 	t->_dmamap_create = _bus_dmamap_create;
    322  1.2.2.2  yamt 	t->_dmamap_destroy = _bus_dmamap_destroy;
    323  1.2.2.2  yamt 	t->_dmamap_load = _bus_dmamap_load;
    324  1.2.2.2  yamt 	t->_dmamap_load_mbuf = _bus_dmamap_load_mbuf;
    325  1.2.2.2  yamt 	t->_dmamap_load_uio = _bus_dmamap_load_uio;
    326  1.2.2.2  yamt 	t->_dmamap_load_raw = _bus_dmamap_load_raw;
    327  1.2.2.2  yamt 	t->_dmamap_unload = _bus_dmamap_unload;
    328  1.2.2.2  yamt 	t->_dmamap_sync = _bus_dmamap_sync;
    329  1.2.2.2  yamt 	t->_dmamem_alloc = _bus_dmamem_alloc;
    330  1.2.2.2  yamt 	t->_dmamem_free = _bus_dmamem_free;
    331  1.2.2.2  yamt 	t->_dmamem_map = _bus_dmamem_map;
    332  1.2.2.2  yamt 	t->_dmamem_unmap = _bus_dmamem_unmap;
    333  1.2.2.2  yamt 	t->_dmamem_mmap = _bus_dmamem_mmap;
    334  1.2.2.2  yamt }
    335  1.2.2.2  yamt 
    336  1.2.2.2  yamt /*
    337  1.2.2.2  yamt  * CPU memory/register stuff
    338  1.2.2.2  yamt  */
    339  1.2.2.2  yamt 
    340  1.2.2.2  yamt #define CHIP	   		arbus
    341  1.2.2.2  yamt #define	CHIP_MEM		/* defined */
    342  1.2.2.2  yamt #define	CHIP_W1_BUS_START(v)	0x00000000UL
    343  1.2.2.2  yamt #define CHIP_W1_BUS_END(v)	0x1fffffffUL
    344  1.2.2.2  yamt #define	CHIP_W1_SYS_START(v)	CHIP_W1_BUS_START(v)
    345  1.2.2.2  yamt #define	CHIP_W1_SYS_END(v)	CHIP_W1_BUS_END(v)
    346  1.2.2.2  yamt 
    347  1.2.2.2  yamt #include <mips/mips/bus_space_alignstride_chipdep.c>
    348