uni-n.c revision 1.1 1 1.1 macallan /* $NetBSD: uni-n.c,v 1.1 2005/08/10 14:30:15 macallan Exp $ */
2 1.1 macallan
3 1.1 macallan /*-
4 1.1 macallan * Copyright (C) 2005 Michael Lorenz.
5 1.1 macallan *
6 1.1 macallan * Redistribution and use in source and binary forms, with or without
7 1.1 macallan * modification, are permitted provided that the following conditions
8 1.1 macallan * are met:
9 1.1 macallan * 1. Redistributions of source code must retain the above copyright
10 1.1 macallan * notice, this list of conditions and the following disclaimer.
11 1.1 macallan * 2. Redistributions in binary form must reproduce the above copyright
12 1.1 macallan * notice, this list of conditions and the following disclaimer in the
13 1.1 macallan * documentation and/or other materials provided with the distribution.
14 1.1 macallan * 3. The name of the author may not be used to endorse or promote products
15 1.1 macallan * derived from this software without specific prior written permission.
16 1.1 macallan *
17 1.1 macallan * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 1.1 macallan * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 1.1 macallan * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 1.1 macallan * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 1.1 macallan * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 1.1 macallan * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 1.1 macallan * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 1.1 macallan * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 1.1 macallan * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 1.1 macallan * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 1.1 macallan */
28 1.1 macallan
29 1.1 macallan /*
30 1.1 macallan * a driver to match the uni_n node in OF's device tree and attach its children
31 1.1 macallan */
32 1.1 macallan
33 1.1 macallan #include <sys/cdefs.h>
34 1.1 macallan __KERNEL_RCSID(0, "$NetBSD: uni-n.c,v 1.1 2005/08/10 14:30:15 macallan Exp $");
35 1.1 macallan
36 1.1 macallan #include <sys/param.h>
37 1.1 macallan #include <sys/systm.h>
38 1.1 macallan #include <sys/kernel.h>
39 1.1 macallan #include <sys/device.h>
40 1.1 macallan
41 1.1 macallan #include <dev/ofw/openfirm.h>
42 1.1 macallan
43 1.1 macallan #include <machine/autoconf.h>
44 1.1 macallan
45 1.1 macallan static void uni_n_attach(struct device *, struct device *, void *);
46 1.1 macallan static int uni_n_match(struct device *, struct cfdata *, void *);
47 1.1 macallan static int uni_n_print(void *, const char *);
48 1.1 macallan
49 1.1 macallan struct uni_n_softc {
50 1.1 macallan struct device sc_dev;
51 1.1 macallan int sc_node;
52 1.1 macallan };
53 1.1 macallan
54 1.1 macallan CFATTACH_DECL(uni_n, sizeof(struct uni_n_softc),
55 1.1 macallan uni_n_match, uni_n_attach, NULL, NULL);
56 1.1 macallan
57 1.1 macallan int
58 1.1 macallan uni_n_match(parent, cf, aux)
59 1.1 macallan struct device *parent;
60 1.1 macallan struct cfdata *cf;
61 1.1 macallan void *aux;
62 1.1 macallan {
63 1.1 macallan struct confargs *ca = aux;
64 1.1 macallan char compat[32];
65 1.1 macallan if (strcmp(ca->ca_name, "uni-n") != 0)
66 1.1 macallan return 0;
67 1.1 macallan
68 1.1 macallan memset(compat, 0, sizeof(compat));
69 1.1 macallan OF_getprop(ca->ca_node, "compatible", compat, sizeof(compat));
70 1.1 macallan if (strcmp(compat, "uni-north") != 0)
71 1.1 macallan return 0;
72 1.1 macallan
73 1.1 macallan return 1;
74 1.1 macallan }
75 1.1 macallan
76 1.1 macallan /*
77 1.1 macallan * Attach all the sub-devices we can find
78 1.1 macallan */
79 1.1 macallan void
80 1.1 macallan uni_n_attach(parent, self, aux)
81 1.1 macallan struct device *parent, *self;
82 1.1 macallan void *aux;
83 1.1 macallan {
84 1.1 macallan struct uni_n_softc *sc = (struct uni_n_softc *)self;
85 1.1 macallan struct confargs *our_ca = aux;
86 1.1 macallan struct confargs ca;
87 1.1 macallan int node, child, namelen;
88 1.1 macallan u_int reg[20];
89 1.1 macallan int intr[6];
90 1.1 macallan char name[32];
91 1.1 macallan
92 1.1 macallan node = OF_finddevice("/uni-n");
93 1.1 macallan sc->sc_node = node;
94 1.1 macallan printf(" address 0x%08x\n",our_ca->ca_reg[0]);
95 1.1 macallan
96 1.1 macallan for (child = OF_child(node); child; child = OF_peer(child)) {
97 1.1 macallan namelen = OF_getprop(child, "name", name, sizeof(name));
98 1.1 macallan if (namelen < 0)
99 1.1 macallan continue;
100 1.1 macallan if (namelen >= sizeof(name))
101 1.1 macallan continue;
102 1.1 macallan
103 1.1 macallan name[namelen] = 0;
104 1.1 macallan ca.ca_name = name;
105 1.1 macallan ca.ca_node = child;
106 1.1 macallan
107 1.1 macallan ca.ca_nreg = OF_getprop(child, "reg", reg, sizeof(reg));
108 1.1 macallan ca.ca_nintr = OF_getprop(child, "AAPL,interrupts", intr,
109 1.1 macallan sizeof(intr));
110 1.1 macallan if (ca.ca_nintr == -1)
111 1.1 macallan ca.ca_nintr = OF_getprop(child, "interrupts", intr,
112 1.1 macallan sizeof(intr));
113 1.1 macallan
114 1.1 macallan ca.ca_reg = reg;
115 1.1 macallan ca.ca_intr = intr;
116 1.1 macallan
117 1.1 macallan config_found(self, &ca, uni_n_print);
118 1.1 macallan }
119 1.1 macallan }
120 1.1 macallan
121 1.1 macallan int
122 1.1 macallan uni_n_print(aux, uni_n)
123 1.1 macallan void *aux;
124 1.1 macallan const char *uni_n;
125 1.1 macallan {
126 1.1 macallan struct confargs *ca = aux;
127 1.1 macallan if (uni_n)
128 1.1 macallan aprint_normal("%s at %s", ca->ca_name, uni_n);
129 1.1 macallan
130 1.1 macallan if (ca->ca_nreg > 0)
131 1.1 macallan aprint_normal(" address 0x%x", ca->ca_reg[0]);
132 1.1 macallan
133 1.1 macallan return UNCONF;
134 1.1 macallan }
135