Home | History | Annotate | Line # | Download | only in adm5120
adm5120_obio.c revision 1.1
      1  1.1  dyoung /* $NetBSD: adm5120_obio.c,v 1.1 2007/03/20 08:52:03 dyoung Exp $ */
      2  1.1  dyoung 
      3  1.1  dyoung /*-
      4  1.1  dyoung  * Copyright (c) 2007 Ruslan Ermilov and Vsevolod Lobko.
      5  1.1  dyoung  * All rights reserved.
      6  1.1  dyoung  *
      7  1.1  dyoung  * Redistribution and use in source and binary forms, with or
      8  1.1  dyoung  * without modification, are permitted provided that the following
      9  1.1  dyoung  * conditions are met:
     10  1.1  dyoung  * 1. Redistributions of source code must retain the above copyright
     11  1.1  dyoung  *    notice, this list of conditions and the following disclaimer.
     12  1.1  dyoung  * 2. Redistributions in binary form must reproduce the above
     13  1.1  dyoung  *    copyright notice, this list of conditions and the following
     14  1.1  dyoung  *    disclaimer in the documentation and/or other materials provided
     15  1.1  dyoung  *    with the distribution.
     16  1.1  dyoung  * 3. The names of the authors may not be used to endorse or promote
     17  1.1  dyoung  *    products derived from this software without specific prior
     18  1.1  dyoung  *    written permission.
     19  1.1  dyoung  *
     20  1.1  dyoung  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY
     21  1.1  dyoung  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     22  1.1  dyoung  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
     23  1.1  dyoung  * PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS
     24  1.1  dyoung  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
     25  1.1  dyoung  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     26  1.1  dyoung  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
     27  1.1  dyoung  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28  1.1  dyoung  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
     29  1.1  dyoung  * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
     30  1.1  dyoung  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
     31  1.1  dyoung  * OF SUCH DAMAGE.
     32  1.1  dyoung  */
     33  1.1  dyoung /*
     34  1.1  dyoung  * Copyright 2002 Wasabi Systems, Inc.
     35  1.1  dyoung  * All rights reserved.
     36  1.1  dyoung  *
     37  1.1  dyoung  * Written by Simon Burge for Wasabi Systems, Inc.
     38  1.1  dyoung  *
     39  1.1  dyoung  * Redistribution and use in source and binary forms, with or without
     40  1.1  dyoung  * modification, are permitted provided that the following conditions
     41  1.1  dyoung  * are met:
     42  1.1  dyoung  * 1. Redistributions of source code must retain the above copyright
     43  1.1  dyoung  *    notice, this list of conditions and the following disclaimer.
     44  1.1  dyoung  * 2. Redistributions in binary form must reproduce the above copyright
     45  1.1  dyoung  *    notice, this list of conditions and the following disclaimer in the
     46  1.1  dyoung  *    documentation and/or other materials provided with the distribution.
     47  1.1  dyoung  * 3. All advertising materials mentioning features or use of this software
     48  1.1  dyoung  *    must display the following acknowledgement:
     49  1.1  dyoung  *      This product includes software developed for the NetBSD Project by
     50  1.1  dyoung  *      Wasabi Systems, Inc.
     51  1.1  dyoung  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     52  1.1  dyoung  *    or promote products derived from this software without specific prior
     53  1.1  dyoung  *    written permission.
     54  1.1  dyoung  *
     55  1.1  dyoung  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     56  1.1  dyoung  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     57  1.1  dyoung  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     58  1.1  dyoung  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     59  1.1  dyoung  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     60  1.1  dyoung  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     61  1.1  dyoung  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     62  1.1  dyoung  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     63  1.1  dyoung  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     64  1.1  dyoung  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     65  1.1  dyoung  * POSSIBILITY OF SUCH DAMAGE.
     66  1.1  dyoung  */
     67  1.1  dyoung 
     68  1.1  dyoung #include <sys/cdefs.h>
     69  1.1  dyoung __KERNEL_RCSID(0, "$NetBSD: adm5120_obio.c,v 1.1 2007/03/20 08:52:03 dyoung Exp $");
     70  1.1  dyoung 
     71  1.1  dyoung #include <sys/param.h>
     72  1.1  dyoung #include <sys/systm.h>
     73  1.1  dyoung #include <sys/device.h>
     74  1.1  dyoung 
     75  1.1  dyoung #include <machine/bus.h>
     76  1.1  dyoung 
     77  1.1  dyoung #include <mips/cache.h>
     78  1.1  dyoung #include <mips/cpuregs.h>
     79  1.1  dyoung 
     80  1.1  dyoung #include <mips/adm5120/include/adm5120reg.h>
     81  1.1  dyoung #include <mips/adm5120/include/adm5120var.h>
     82  1.1  dyoung #include <mips/adm5120/include/adm5120_mainbusvar.h>
     83  1.1  dyoung #include <mips/adm5120/include/adm5120_obiovar.h>
     84  1.1  dyoung 
     85  1.1  dyoung #include "locators.h"
     86  1.1  dyoung 
     87  1.1  dyoung #ifdef OBIO_DEBUG
     88  1.1  dyoung int obio_debug = 1;
     89  1.1  dyoung #define	OBIO_DPRINTF(__fmt, ...)		\
     90  1.1  dyoung do {						\
     91  1.1  dyoung 	if (obio_debug)			\
     92  1.1  dyoung 		printf((__fmt), __VA_ARGS__);	\
     93  1.1  dyoung } while (/*CONSTCOND*/0)
     94  1.1  dyoung #else /* !OBIO_DEBUG */
     95  1.1  dyoung #define	OBIO_DPRINTF(__fmt, ...)	do { } while (/*CONSTCOND*/0)
     96  1.1  dyoung #endif /* OBIO_DEBUG */
     97  1.1  dyoung 
     98  1.1  dyoung static int	obio_match(struct device *, struct cfdata *, void *);
     99  1.1  dyoung static void	obio_attach(struct device *, struct device *, void *);
    100  1.1  dyoung static int	obio_submatch(struct device *, struct cfdata *,
    101  1.1  dyoung 			      const int *, void *);
    102  1.1  dyoung static int	obio_print(void *, const char *);
    103  1.1  dyoung 
    104  1.1  dyoung CFATTACH_DECL(obio, sizeof(struct device), obio_match, obio_attach, NULL, NULL);
    105  1.1  dyoung 
    106  1.1  dyoung /* There can be only one. */
    107  1.1  dyoung int	obio_found;
    108  1.1  dyoung 
    109  1.1  dyoung struct obiodev {
    110  1.1  dyoung 	const char	*od_name;
    111  1.1  dyoung 	bus_addr_t	od_addr;
    112  1.1  dyoung 	int		od_irq;
    113  1.1  dyoung 	uint32_t	od_gpio_mask;
    114  1.1  dyoung };
    115  1.1  dyoung 
    116  1.1  dyoung struct obiodev obiodevs[] = {
    117  1.1  dyoung 	{"uart",	ADM5120_BASE_UART0,	1, 0x0},
    118  1.1  dyoung 	{"uart",	ADM5120_BASE_UART1,	2, 0x0},
    119  1.1  dyoung 	{"admsw",	ADM5120_BASE_SWITCH,	9, 0x0},
    120  1.1  dyoung 	{"ahci",	ADM5120_BASE_USB,	3, 0x0},
    121  1.1  dyoung 	{"admflash",	ADM5120_BASE_SRAM0,	0, 0x0},
    122  1.1  dyoung 	{NULL,		0,			0, 0x0},
    123  1.1  dyoung };
    124  1.1  dyoung 
    125  1.1  dyoung static int
    126  1.1  dyoung obio_match(struct device *parent, struct cfdata *match, void *aux)
    127  1.1  dyoung {
    128  1.1  dyoung 	return !obio_found;
    129  1.1  dyoung }
    130  1.1  dyoung 
    131  1.1  dyoung static void
    132  1.1  dyoung obio_attach_args_create(struct obio_attach_args *oa, struct obiodev *od,
    133  1.1  dyoung     void *gpio, bus_dma_tag_t dmat, bus_space_tag_t st)
    134  1.1  dyoung {
    135  1.1  dyoung 	oa->oba_name = od->od_name;
    136  1.1  dyoung 	oa->oba_addr = od->od_addr;
    137  1.1  dyoung 	oa->oba_irq = od->od_irq;
    138  1.1  dyoung 	oa->oba_dt = dmat;
    139  1.1  dyoung 	oa->oba_st = st;
    140  1.1  dyoung 	oa->oba_gpio = gpio;
    141  1.1  dyoung 	oa->oba_gpio_mask = od->od_gpio_mask;
    142  1.1  dyoung }
    143  1.1  dyoung 
    144  1.1  dyoung static void
    145  1.1  dyoung obio_attach(struct device *parent, struct device *self, void *aux)
    146  1.1  dyoung {
    147  1.1  dyoung 	struct mainbus_attach_args *ma = (struct mainbus_attach_args *)aux;
    148  1.1  dyoung 	struct obio_attach_args oa;
    149  1.1  dyoung 	struct obiodev *od;
    150  1.1  dyoung 
    151  1.1  dyoung 	obio_found = 1;
    152  1.1  dyoung 	printf("\n");
    153  1.1  dyoung 
    154  1.1  dyoung 	OBIO_DPRINTF("%s: %d\n", __func__, __LINE__);
    155  1.1  dyoung 
    156  1.1  dyoung 	OBIO_DPRINTF("%s: %d\n", __func__, __LINE__);
    157  1.1  dyoung 	for (od = obiodevs; od->od_name != NULL; od++) {
    158  1.1  dyoung 		OBIO_DPRINTF("%s: %d\n", __func__, __LINE__);
    159  1.1  dyoung 		obio_attach_args_create(&oa, od, ma->ma_gpio, ma->ma_dmat,
    160  1.1  dyoung 		    ma->ma_obiot);
    161  1.1  dyoung 		OBIO_DPRINTF("%s: %d\n", __func__, __LINE__);
    162  1.1  dyoung 		(void)config_found_sm_loc(self, "obio", NULL, &oa, obio_print,
    163  1.1  dyoung 		    obio_submatch);
    164  1.1  dyoung 	}
    165  1.1  dyoung 	OBIO_DPRINTF("%s: %d\n", __func__, __LINE__);
    166  1.1  dyoung }
    167  1.1  dyoung 
    168  1.1  dyoung static int
    169  1.1  dyoung obio_submatch(struct device *parent, struct cfdata *cf,
    170  1.1  dyoung 	      const int *ldesc, void *aux)
    171  1.1  dyoung {
    172  1.1  dyoung 	struct obio_attach_args *oa = aux;
    173  1.1  dyoung 
    174  1.1  dyoung 	if (cf->cf_loc[OBIOCF_ADDR] != OBIOCF_ADDR_DEFAULT &&
    175  1.1  dyoung 	    cf->cf_loc[OBIOCF_ADDR] != oa->oba_addr)
    176  1.1  dyoung 		return 0;
    177  1.1  dyoung 
    178  1.1  dyoung 	return config_match(parent, cf, aux);
    179  1.1  dyoung }
    180  1.1  dyoung 
    181  1.1  dyoung static int
    182  1.1  dyoung obio_print(void *aux, const char *pnp)
    183  1.1  dyoung {
    184  1.1  dyoung 	struct obio_attach_args *oa = aux;
    185  1.1  dyoung 
    186  1.1  dyoung 	if (pnp != NULL)
    187  1.1  dyoung 		aprint_normal("%s at %s", oa->oba_name, pnp);
    188  1.1  dyoung 	if (oa->oba_addr != OBIOCF_ADDR_DEFAULT)
    189  1.1  dyoung 		aprint_normal(" addr 0x%lx", oa->oba_addr);
    190  1.1  dyoung 	if (oa->oba_gpio_mask != OBIOCF_GPIO_MASK_DEFAULT)
    191  1.1  dyoung 		aprint_normal(" gpio_mask 0x%02x", oa->oba_gpio_mask);
    192  1.1  dyoung 
    193  1.1  dyoung 	return UNCONF;
    194  1.1  dyoung }
    195