Home | History | Annotate | Line # | Download | only in adm5120
      1  1.6  thorpej /* $NetBSD: adm5120_obio.c,v 1.6 2021/08/07 16:18:58 thorpej 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.6  thorpej __KERNEL_RCSID(0, "$NetBSD: adm5120_obio.c,v 1.6 2021/08/07 16:18:58 thorpej 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.4   dyoung #include <sys/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.3     matt static int	obio_match(device_t, cfdata_t, void *);
     99  1.3     matt static void	obio_attach(device_t, device_t, void *);
    100  1.3     matt static int	obio_submatch(device_t, cfdata_t, const int *, void *);
    101  1.1   dyoung static int	obio_print(void *, const char *);
    102  1.1   dyoung 
    103  1.3     matt CFATTACH_DECL_NEW(obio, 0, obio_match, obio_attach, NULL, NULL);
    104  1.1   dyoung 
    105  1.1   dyoung /* There can be only one. */
    106  1.1   dyoung int	obio_found;
    107  1.1   dyoung 
    108  1.1   dyoung struct obiodev {
    109  1.1   dyoung 	const char	*od_name;
    110  1.1   dyoung 	bus_addr_t	od_addr;
    111  1.1   dyoung 	int		od_irq;
    112  1.1   dyoung 	uint32_t	od_gpio_mask;
    113  1.1   dyoung };
    114  1.1   dyoung 
    115  1.3     matt const struct obiodev obiodevs[] = {
    116  1.1   dyoung 	{"uart",	ADM5120_BASE_UART0,	1, 0x0},
    117  1.1   dyoung 	{"uart",	ADM5120_BASE_UART1,	2, 0x0},
    118  1.1   dyoung 	{"admsw",	ADM5120_BASE_SWITCH,	9, 0x0},
    119  1.1   dyoung 	{"ahci",	ADM5120_BASE_USB,	3, 0x0},
    120  1.1   dyoung 	{"admflash",	ADM5120_BASE_SRAM0,	0, 0x0},
    121  1.1   dyoung 	{NULL,		0,			0, 0x0},
    122  1.1   dyoung };
    123  1.1   dyoung 
    124  1.1   dyoung static int
    125  1.3     matt obio_match(device_t parent, cfdata_t match, void *aux)
    126  1.1   dyoung {
    127  1.1   dyoung 	return !obio_found;
    128  1.1   dyoung }
    129  1.1   dyoung 
    130  1.1   dyoung static void
    131  1.3     matt obio_attach_args_create(struct obio_attach_args *oa, const struct obiodev *od,
    132  1.1   dyoung     void *gpio, bus_dma_tag_t dmat, bus_space_tag_t st)
    133  1.1   dyoung {
    134  1.1   dyoung 	oa->oba_name = od->od_name;
    135  1.1   dyoung 	oa->oba_addr = od->od_addr;
    136  1.1   dyoung 	oa->oba_irq = od->od_irq;
    137  1.1   dyoung 	oa->oba_dt = dmat;
    138  1.1   dyoung 	oa->oba_st = st;
    139  1.1   dyoung 	oa->oba_gpio = gpio;
    140  1.1   dyoung 	oa->oba_gpio_mask = od->od_gpio_mask;
    141  1.1   dyoung }
    142  1.1   dyoung 
    143  1.1   dyoung static void
    144  1.3     matt obio_attach(device_t parent, device_t self, void *aux)
    145  1.1   dyoung {
    146  1.1   dyoung 	struct mainbus_attach_args *ma = (struct mainbus_attach_args *)aux;
    147  1.1   dyoung 	struct obio_attach_args oa;
    148  1.3     matt 	const struct obiodev *od;
    149  1.1   dyoung 
    150  1.1   dyoung 	obio_found = 1;
    151  1.1   dyoung 	printf("\n");
    152  1.1   dyoung 
    153  1.1   dyoung 	OBIO_DPRINTF("%s: %d\n", __func__, __LINE__);
    154  1.1   dyoung 
    155  1.1   dyoung 	OBIO_DPRINTF("%s: %d\n", __func__, __LINE__);
    156  1.1   dyoung 	for (od = obiodevs; od->od_name != NULL; od++) {
    157  1.1   dyoung 		OBIO_DPRINTF("%s: %d\n", __func__, __LINE__);
    158  1.1   dyoung 		obio_attach_args_create(&oa, od, ma->ma_gpio, ma->ma_dmat,
    159  1.1   dyoung 		    ma->ma_obiot);
    160  1.1   dyoung 		OBIO_DPRINTF("%s: %d\n", __func__, __LINE__);
    161  1.5  thorpej 		config_found(self, &oa, obio_print,
    162  1.6  thorpej 		    CFARGS(.submatch = obio_submatch,
    163  1.6  thorpej 			   .iattr = "obio"));
    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.3     matt obio_submatch(device_t parent, cfdata_t cf, const int *ldesc, void *aux)
    170  1.1   dyoung {
    171  1.1   dyoung 	struct obio_attach_args *oa = aux;
    172  1.1   dyoung 
    173  1.1   dyoung 	if (cf->cf_loc[OBIOCF_ADDR] != OBIOCF_ADDR_DEFAULT &&
    174  1.1   dyoung 	    cf->cf_loc[OBIOCF_ADDR] != oa->oba_addr)
    175  1.1   dyoung 		return 0;
    176  1.1   dyoung 
    177  1.1   dyoung 	return config_match(parent, cf, aux);
    178  1.1   dyoung }
    179  1.1   dyoung 
    180  1.1   dyoung static int
    181  1.1   dyoung obio_print(void *aux, const char *pnp)
    182  1.1   dyoung {
    183  1.1   dyoung 	struct obio_attach_args *oa = aux;
    184  1.1   dyoung 
    185  1.1   dyoung 	if (pnp != NULL)
    186  1.1   dyoung 		aprint_normal("%s at %s", oa->oba_name, pnp);
    187  1.1   dyoung 	if (oa->oba_addr != OBIOCF_ADDR_DEFAULT)
    188  1.3     matt 		aprint_normal(" addr 0x%"PRIxBUSADDR, oa->oba_addr);
    189  1.1   dyoung 	if (oa->oba_gpio_mask != OBIOCF_GPIO_MASK_DEFAULT)
    190  1.1   dyoung 		aprint_normal(" gpio_mask 0x%02x", oa->oba_gpio_mask);
    191  1.1   dyoung 
    192  1.1   dyoung 	return UNCONF;
    193  1.1   dyoung }
    194