xref: /netbsd-src/sys/arch/epoc32/epoc32/external.c (revision c7fb772b85b2b5d4cfb282f868f454b4701534fd)
1 /*	$NetBSD: external.c,v 1.4 2021/08/07 16:18:48 thorpej Exp $	*/
2 /*
3  * Copyright (c) 2012, 2013 KIYOHARA Takashi
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
19  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
23  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
24  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25  * POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #include <sys/cdefs.h>
29 __KERNEL_RCSID(0, "$NetBSD: external.c,v 1.4 2021/08/07 16:18:48 thorpej Exp $");
30 
31 #include <sys/param.h>
32 #include <sys/bus.h>
33 #include <sys/device.h>
34 #include <sys/errno.h>
35 
36 #include <machine/epoc32.h>
37 
38 #include "locators.h"
39 
40 extern struct bus_space external_bs_tag;
41 
42 static int external_match(device_t, cfdata_t, void *);
43 static void external_attach(device_t parent, device_t self, void *aux);
44 
45 static int external_search(device_t, cfdata_t, const int *, void *);
46 static int external_print(void *, const char *);
47 
48 CFATTACH_DECL_NEW(external, 0, external_match, external_attach, NULL, NULL);
49 
50 
51 /* ARGSUSED */
52 static int
external_match(device_t parent,cfdata_t match,void * aux)53 external_match(device_t parent, cfdata_t match, void *aux)
54 {
55 	/* always attach */
56 	return 1;
57 }
58 
59 /* ARGSUSED */
60 static void
external_attach(device_t parent,device_t self,void * aux)61 external_attach(device_t parent, device_t self, void *aux)
62 {
63 
64 	aprint_naive("\n");
65 	aprint_normal("\n");
66 
67 	config_search(self, NULL,
68 	    CFARGS(.search = external_search));
69 }
70 
71 /* ARGSUSED */
72 static int
external_search(device_t parent,cfdata_t cf,const int * ldesc,void * aux)73 external_search(device_t parent, cfdata_t cf, const int *ldesc, void *aux)
74 {
75 	struct external_attach_args aa;
76 
77 	aa.name = cf->cf_name;
78 	aa.iot = &external_bs_tag;
79 	aa.addr = cf->cf_loc[EXTERNALCF_ADDR];
80 	aa.addr2 = cf->cf_loc[EXTERNALCF_ADDR2];
81 	aa.irq = cf->cf_loc[EXTERNALCF_IRQ];
82 	if (config_probe(parent, cf, &aa))
83 		config_attach(parent, cf, &aa, external_print, CFARGS_NONE);
84 
85 	return 0;
86 }
87 
88 static int
external_print(void * aux,const char * pnp)89 external_print(void *aux, const char *pnp)
90 {
91 	struct external_attach_args *aa = aux;
92 
93 	if (pnp)
94 		return QUIET;
95 
96 	if (aa->addr != -1)
97 		aprint_normal(" addr 0x%04lx", aa->addr);
98 	if (aa->addr2 != -1)
99 		aprint_normal(",0x%04lx", aa->addr2);
100 	if (aa->irq != -1)
101 		aprint_normal(" irq %d", aa->irq);
102 
103 	return UNCONF;
104 }
105