xref: /netbsd-src/sys/arch/evbmips/alchemy/obio.c (revision c7fb772b85b2b5d4cfb282f868f454b4701534fd)
1 /* $NetBSD: obio.c,v 1.6 2021/08/07 16:18:51 thorpej Exp $ */
2 
3 /*
4  * Copyright 2002 Wasabi Systems, Inc.
5  * All rights reserved.
6  *
7  * Written by Simon Burge for Wasabi Systems, Inc.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  * 3. All advertising materials mentioning features or use of this software
18  *    must display the following acknowledgement:
19  *      This product includes software developed for the NetBSD Project by
20  *      Wasabi Systems, Inc.
21  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22  *    or promote products derived from this software without specific prior
23  *    written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
29  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35  * POSSIBILITY OF SUCH DAMAGE.
36  */
37 
38 #include <sys/cdefs.h>
39 __KERNEL_RCSID(0, "$NetBSD: obio.c,v 1.6 2021/08/07 16:18:51 thorpej Exp $");
40 
41 #include <sys/param.h>
42 #include <sys/systm.h>
43 #include <sys/device.h>
44 
45 #include <sys/bus.h>
46 
47 #include <mips/cache.h>
48 #include <mips/cpuregs.h>
49 
50 #include <evbmips/alchemy/board.h>
51 #include <evbmips/alchemy/obiovar.h>
52 
53 #include "locators.h"
54 
55 static int	obio_match(device_t, cfdata_t, void *);
56 static void	obio_attach(device_t, device_t, void *);
57 static int	obio_submatch(device_t, cfdata_t, const int *, void *);
58 static int	obio_print(void *, const char *);
59 
60 CFATTACH_DECL_NEW(obio, 0,
61     obio_match, obio_attach, NULL, NULL);
62 
63 /* There can be only one. */
64 static int	obio_found = 0;
65 
66 static int
obio_match(device_t parent,cfdata_t match,void * aux)67 obio_match(device_t parent, cfdata_t match, void *aux)
68 {
69 
70 	if (obio_found)
71 		return (0);
72 
73 	return (1);
74 }
75 
76 static void
obio_attach(device_t parent,device_t self,void * aux)77 obio_attach(device_t parent, device_t self, void *aux)
78 {
79 	struct obio_attach_args oa;
80 	const struct obiodev *od;
81 	const struct alchemy_board *board;
82 
83 	obio_found = 1;
84 	printf("\n");
85 
86 	board = board_info();
87 	for (od = board->ab_devices; od->od_name != NULL; od++) {
88 		oa.oba_name = od->od_name;
89 		oa.oba_addr = od->od_addr;
90 		oa.oba_irq = od->od_irq;
91 		config_found(self, &oa, obio_print,
92 		    CFARGS(.submatch = obio_submatch));
93 	}
94 }
95 
96 static int
obio_submatch(device_t parent,cfdata_t cf,const int * ldesc,void * aux)97 obio_submatch(device_t parent, cfdata_t cf,
98 	      const int *ldesc, void *aux)
99 {
100 	struct obio_attach_args *oa = aux;
101 
102 	if (cf->cf_loc[OBIOCF_ADDR] != OBIOCF_ADDR_DEFAULT &&
103 	    cf->cf_loc[OBIOCF_ADDR] != oa->oba_addr)
104 		return (0);
105 
106 	return (config_match(parent, cf, aux));
107 }
108 
109 static int
obio_print(void * aux,const char * pnp)110 obio_print(void *aux, const char *pnp)
111 {
112 	struct obio_attach_args *oa = aux;
113 
114 	if (pnp)
115 		aprint_normal("%s at %s", oa->oba_name, pnp);
116 	if (oa->oba_addr != OBIOCF_ADDR_DEFAULT)
117 		aprint_normal(" addr 0x%"PRIxBUSADDR, oa->oba_addr);
118 
119 	return (UNCONF);
120 }
121