1 /*	$NetBSD: if_cs_ofisa_machdep.c,v 1.1 2002/02/10 01:57:57 thorpej Exp $	*/
2 
3 /*
4  * Copyright 1998
5  * Digital Equipment Corporation. All rights reserved.
6  *
7  * This software is furnished under license and may be used and
8  * copied only in accordance with the following terms and conditions.
9  * Subject to these conditions, you may download, copy, install,
10  * use, modify and distribute this software in source and/or binary
11  * form. No title or ownership is transferred hereby.
12  *
13  * 1) Any source code used, modified or distributed must reproduce
14  *    and retain this copyright notice and list of conditions as
15  *    they appear in the source file.
16  *
17  * 2) No right is granted to use any trade name, trademark, or logo of
18  *    Digital Equipment Corporation. Neither the "Digital Equipment
19  *    Corporation" name nor any trademark or logo of Digital Equipment
20  *    Corporation may be used to endorse or promote products derived
21  *    from this software without the prior written permission of
22  *    Digital Equipment Corporation.
23  *
24  * 3) This software is provided "AS-IS" and any express or implied
25  *    warranties, including but not limited to, any implied warranties
26  *    of merchantability, fitness for a particular purpose, or
27  *    non-infringement are disclaimed. In no event shall DIGITAL be
28  *    liable for any damages whatsoever, and in particular, DIGITAL
29  *    shall not be liable for special, indirect, consequential, or
30  *    incidental damages or damages for lost profits, loss of
31  *    revenue or loss of use, whether such damages arise in contract,
32  *    negligence, tort, under statute, in equity, at law or otherwise,
33  *    even if advised of the possibility of such damage.
34  */
35 
36 /*
37  * WARNING: THIS FILE IS VERY SHARK-SPECIFIC!
38  */
39 
40 #include <sys/param.h>
41 #include <sys/device.h>
42 #include <sys/systm.h>
43 #include <sys/malloc.h>
44 #include <sys/socket.h>
45 
46 #include <net/if.h>
47 #include <net/if_ether.h>
48 #include <net/if_media.h>
49 
50 #include <machine/bus.h>
51 #include <machine/intr.h>
52 
53 #include <dev/ofw/openfirm.h>
54 #include <dev/isa/isavar.h>
55 #include <dev/ofisa/ofisavar.h>
56 
57 #include <dev/ic/cs89x0reg.h>
58 #include <dev/ic/cs89x0var.h>
59 
60 #ifdef COMPAT_OLD_OFW
61 
62 int
63 cs_ofisa_md_match(parent, cf, aux)
64 	struct device *parent;
65 	struct cfdata *cf;
66 	void *aux;
67 {
68 	struct ofisa_attach_args *aa = aux;
69 	char type[64];
70 	char name[64];
71 	char model[64];
72 	char compatible[64];
73 	int rv;
74 
75 	rv = 0;
76 	if (1) {		/* XXX old firmware compat enabled */
77 		/* At a minimum, must match type and name properties. */
78 		if (OF_getprop(aa->oba.oba_phandle, "device_type", type,
79 		    sizeof(type)) < 0 || strcmp(type, "network") != 0 ||
80 		    OF_getprop(aa->oba.oba_phandle, "name", name,
81 		    sizeof(name)) < 0 || strcmp(name, "ethernet") != 0)
82 			return (0);
83 
84 		/* Full match on model. */
85 		if (OF_getprop(aa->oba.oba_phandle, "model", model,
86 		    sizeof(model)) > 0 && strcmp(model, "CS8900") == 0)
87 			rv = 3;
88 
89 		/* Check for compatible match. */
90 		if (OF_getprop(aa->oba.oba_phandle, "compatible", compatible,
91 		    sizeof(compatible)) > 0 && pmatch(compatible, "*CS8900*",
92 		    NULL) > 0)
93 			rv = 2;
94 	}
95 	return (rv);
96 }
97 
98 int
99 cs_ofisa_md_reg_fixup(parent, self, aux, descp, ndescs, ndescsfilled)
100 	struct device *parent, *self;
101 	void *aux;
102 	struct ofisa_reg_desc *descp;
103 	int ndescs, ndescsfilled;
104 {
105 
106 	if (1) {		/* XXX old firmware compat enabled */
107 		/* We can't provide it. */
108 		if (ndescs != 2)
109 			return (ndescsfilled);
110 
111 		/* Firmware provided it. */
112 		if (ndescsfilled == 2)
113 			return (ndescsfilled);
114 
115 		descp[0].type = OFISA_REG_TYPE_IO;
116 		descp[0].addr = 0x300;
117 		descp[0].len  = CS8900_IOSIZE;
118 
119 		descp[1].type = OFISA_REG_TYPE_MEM;
120 		descp[1].addr = 0xd0000;
121 		descp[1].len  = 4096;
122 	}
123 	return (ndescsfilled);
124 }
125 
126 int
127 cs_ofisa_md_intr_fixup(parent, self, aux, descp, ndescs, ndescsfilled)
128 	struct device *parent, *self;
129 	void *aux;
130 	struct ofisa_intr_desc *descp;
131 	int ndescs, ndescsfilled;
132 {
133 
134 	if (1)			/* XXX old firmware compat enabled */
135 	if (ndescs > 0 && ndescsfilled > 0)
136                 descp[0].share = IST_LEVEL;
137 	return (ndescsfilled);
138 }
139 
140 int *
141 cs_ofisa_md_media_fixup(parent, self, aux, media, nmediap, defmediap)
142 	struct device *parent, *self;
143 	void *aux;
144 	int *media, *nmediap, *defmediap;
145 {
146 
147 	if (1) {		/* XXX old firmware compat enabled */
148 		if (media == NULL) {
149 			media = malloc(2 * sizeof(int), M_TEMP, M_NOWAIT);
150 			if (media == NULL)
151 				return (NULL);
152 			media[0] = IFM_ETHER|IFM_10_T;
153 			media[1] = IFM_ETHER|IFM_10_T|IFM_FDX;
154 			*nmediap = 2;
155 			*defmediap = media[0];
156 		}
157 	}
158 	return (media);
159 }
160 
161 int
162 cs_ofisa_md_dma_fixup(parent, self, aux, descp, ndescs, ndescsfilled)
163 	struct device *parent, *self;
164 	void *aux;
165 	struct ofisa_dma_desc *descp;
166 	int ndescs, ndescsfilled;
167 {
168 	struct ofisa_attach_args *aa = aux;
169 
170 	if (ndescs > 0 && ndescsfilled > 0) {
171 		if (OF_getproplen(aa->oba.oba_phandle, "no-dma") >= 0)
172 			descp[0].drq = ISACF_DRQ_DEFAULT;
173 	}
174 	return (ndescsfilled);
175 }
176 
177 #endif /* COMPAT_OLD_OFW */
178 
179 int
180 cs_ofisa_md_cfgflags_fixup(parent, self, aux)
181 	struct device *parent, *self;
182 	void *aux;
183 {
184 
185 	return (CFGFLG_USE_SA|CFGFLG_IOCHRDY|CFGFLG_NOT_EEPROM);
186 }
187