1*c7fb772bSthorpej /* $NetBSD: obio.c,v 1.3 2021/08/07 16:18:49 thorpej Exp $ */
26fe6c35aSmacallan
36fe6c35aSmacallan /*
46fe6c35aSmacallan * Copyright (c) 2001, 2002, 2003 Wasabi Systems, Inc.
56fe6c35aSmacallan * All rights reserved.
66fe6c35aSmacallan *
76fe6c35aSmacallan * Written by Jason R. Thorpe for Wasabi Systems, Inc.
86fe6c35aSmacallan *
96fe6c35aSmacallan * Redistribution and use in source and binary forms, with or without
106fe6c35aSmacallan * modification, are permitted provided that the following conditions
116fe6c35aSmacallan * are met:
126fe6c35aSmacallan * 1. Redistributions of source code must retain the above copyright
136fe6c35aSmacallan * notice, this list of conditions and the following disclaimer.
146fe6c35aSmacallan * 2. Redistributions in binary form must reproduce the above copyright
156fe6c35aSmacallan * notice, this list of conditions and the following disclaimer in the
166fe6c35aSmacallan * documentation and/or other materials provided with the distribution.
176fe6c35aSmacallan * 3. All advertising materials mentioning features or use of this software
186fe6c35aSmacallan * must display the following acknowledgement:
196fe6c35aSmacallan * This product includes software developed for the NetBSD Project by
206fe6c35aSmacallan * Wasabi Systems, Inc.
216fe6c35aSmacallan * 4. The name of Wasabi Systems, Inc. may not be used to endorse
226fe6c35aSmacallan * or promote products derived from this software without specific prior
236fe6c35aSmacallan * written permission.
246fe6c35aSmacallan *
256fe6c35aSmacallan * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
266fe6c35aSmacallan * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
276fe6c35aSmacallan * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
286fe6c35aSmacallan * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
296fe6c35aSmacallan * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
306fe6c35aSmacallan * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
316fe6c35aSmacallan * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
326fe6c35aSmacallan * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
336fe6c35aSmacallan * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
346fe6c35aSmacallan * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
356fe6c35aSmacallan * POSSIBILITY OF SUCH DAMAGE.
366fe6c35aSmacallan */
376fe6c35aSmacallan
386fe6c35aSmacallan /*
396fe6c35aSmacallan * On-board device autoconfiguration support for Tungsten motherboards.
406fe6c35aSmacallan */
416fe6c35aSmacallan
426fe6c35aSmacallan #include <sys/cdefs.h>
43*c7fb772bSthorpej __KERNEL_RCSID(0, "$NetBSD: obio.c,v 1.3 2021/08/07 16:18:49 thorpej Exp $");
446fe6c35aSmacallan
456fe6c35aSmacallan #include <sys/param.h>
466fe6c35aSmacallan #include <sys/systm.h>
476fe6c35aSmacallan #include <sys/device.h>
486fe6c35aSmacallan
496fe6c35aSmacallan #include <machine/autoconf.h>
506fe6c35aSmacallan #include <sys/bus.h>
516fe6c35aSmacallan
526fe6c35aSmacallan #include <arm/xscale/i80321reg.h>
536fe6c35aSmacallan
546fe6c35aSmacallan #include <evbarm/iyonix/iyonixreg.h>
556fe6c35aSmacallan #include <evbarm/iyonix/obiovar.h>
566fe6c35aSmacallan
576fe6c35aSmacallan #include "locators.h"
586fe6c35aSmacallan
596fe6c35aSmacallan int obio_match(device_t, cfdata_t, void *);
606fe6c35aSmacallan void obio_attach(device_t, device_t, void *);
616fe6c35aSmacallan
626fe6c35aSmacallan CFATTACH_DECL_NEW(obio, 0,
636fe6c35aSmacallan obio_match, obio_attach, NULL, NULL);
646fe6c35aSmacallan
656fe6c35aSmacallan int obio_print(void *, const char *);
666fe6c35aSmacallan int obio_search(device_t, cfdata_t, const int *, void *);
676fe6c35aSmacallan
686fe6c35aSmacallan /* there can be only one */
696fe6c35aSmacallan bool obio_found;
706fe6c35aSmacallan
716fe6c35aSmacallan int
obio_match(device_t parent,cfdata_t cf,void * aux)726fe6c35aSmacallan obio_match(device_t parent, cfdata_t cf, void *aux)
736fe6c35aSmacallan {
746fe6c35aSmacallan #if 0
756fe6c35aSmacallan struct mainbus_attach_args *ma = aux;
766fe6c35aSmacallan #endif
776fe6c35aSmacallan
786fe6c35aSmacallan if (obio_found)
796fe6c35aSmacallan return (0);
806fe6c35aSmacallan
816fe6c35aSmacallan #if 1
826fe6c35aSmacallan /* XXX Shoot arch/arm/mainbus in the head. */
836fe6c35aSmacallan return (1);
846fe6c35aSmacallan #else
856fe6c35aSmacallan if (strcmp(cf->cf_name, ma->ma_name) == 0)
866fe6c35aSmacallan return (1);
876fe6c35aSmacallan
886fe6c35aSmacallan return (0);
896fe6c35aSmacallan #endif
906fe6c35aSmacallan }
916fe6c35aSmacallan
926fe6c35aSmacallan void
obio_attach(device_t parent,device_t self,void * aux)936fe6c35aSmacallan obio_attach(device_t parent, device_t self, void *aux)
946fe6c35aSmacallan {
956fe6c35aSmacallan
966fe6c35aSmacallan obio_found = true;
976fe6c35aSmacallan
986fe6c35aSmacallan aprint_naive("\n");
996fe6c35aSmacallan aprint_normal("\n");
1006fe6c35aSmacallan
1016fe6c35aSmacallan /*
1026fe6c35aSmacallan * Attach all on-board devices as described in the kernel
1036fe6c35aSmacallan * configuration file.
1046fe6c35aSmacallan */
1052685996bSthorpej config_search(self, NULL,
106*c7fb772bSthorpej CFARGS(.search = obio_search));
1076fe6c35aSmacallan }
1086fe6c35aSmacallan
1096fe6c35aSmacallan int
obio_print(void * aux,const char * pnp)1106fe6c35aSmacallan obio_print(void *aux, const char *pnp)
1116fe6c35aSmacallan {
1126fe6c35aSmacallan struct obio_attach_args *oba = aux;
1136fe6c35aSmacallan
1146fe6c35aSmacallan aprint_normal(" addr 0x%08lx", oba->oba_addr);
1156fe6c35aSmacallan if (oba->oba_size != OBIOCF_SIZE_DEFAULT)
1166fe6c35aSmacallan aprint_normal("-0x%08lx", oba->oba_addr + (oba->oba_size - 1));
1176fe6c35aSmacallan if (oba->oba_width != OBIOCF_WIDTH_DEFAULT)
1186fe6c35aSmacallan aprint_normal(" width %d", oba->oba_width);
1196fe6c35aSmacallan if (oba->oba_irq != -1)
1206fe6c35aSmacallan aprint_normal(" xint %d", oba->oba_irq - ICU_INT_XINT0);
1216fe6c35aSmacallan
1226fe6c35aSmacallan return (UNCONF);
1236fe6c35aSmacallan }
1246fe6c35aSmacallan
1256fe6c35aSmacallan int
obio_search(device_t parent,cfdata_t cf,const int * ldesc,void * aux)1266fe6c35aSmacallan obio_search(device_t parent, cfdata_t cf, const int *ldesc, void *aux)
1276fe6c35aSmacallan {
1286fe6c35aSmacallan struct obio_attach_args oba;
1296fe6c35aSmacallan
1306fe6c35aSmacallan oba.oba_st = &obio_bs_tag;
1316fe6c35aSmacallan
1326fe6c35aSmacallan oba.oba_addr = cf->cf_loc[OBIOCF_ADDR];
1336fe6c35aSmacallan oba.oba_size = cf->cf_loc[OBIOCF_SIZE];
1346fe6c35aSmacallan oba.oba_width = cf->cf_loc[OBIOCF_WIDTH];
1356fe6c35aSmacallan
1366fe6c35aSmacallan if (cf->cf_loc[OBIOCF_XINT] != OBIOCF_XINT_DEFAULT)
1376fe6c35aSmacallan oba.oba_irq = ICU_INT_XINT(cf->cf_loc[OBIOCF_XINT]);
1386fe6c35aSmacallan else
1396fe6c35aSmacallan oba.oba_irq = -1;
1406fe6c35aSmacallan
1412685996bSthorpej if (config_probe(parent, cf, &oba))
142*c7fb772bSthorpej config_attach(parent, cf, &oba, obio_print, CFARGS_NONE);
1436fe6c35aSmacallan
1446fe6c35aSmacallan return (0);
1456fe6c35aSmacallan }
146