xref: /netbsd/sys/arch/mvme68k/dev/memc_68k.c (revision bf9ec67e)
1 /*	$NetBSD: memc_68k.c,v 1.1 2002/02/12 20:38:20 scw Exp $	*/
2 
3 /*-
4  * Copyright (c) 2000, 2002 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Steve C. Woodford.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *        This product includes software developed by the NetBSD
21  *        Foundation, Inc. and its contributors.
22  * 4. Neither the name of The NetBSD Foundation nor the names of its
23  *    contributors may be used to endorse or promote products derived
24  *    from this software without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  * POSSIBILITY OF SUCH DAMAGE.
37  */
38 
39 /*
40  * Support for the MEMECC and MEMC40 memory controllers on MVME68K
41  */
42 
43 #include <sys/param.h>
44 #include <sys/kernel.h>
45 #include <sys/systm.h>
46 #include <sys/device.h>
47 #include <sys/malloc.h>
48 
49 #include <machine/cpu.h>
50 #include <machine/bus.h>
51 
52 #include <mvme68k/dev/mainbus.h>
53 
54 #include <dev/mvme/memcvar.h>
55 #include <dev/mvme/memcreg.h>
56 #include <dev/mvme/pcctwovar.h>
57 #include <dev/mvme/pcctworeg.h>
58 
59 
60 int memc_match(struct device *, struct cfdata *, void *);
61 void memc_attach(struct device *, struct device *, void *);
62 
63 struct cfattach memc_ca = {
64 	sizeof(struct memc_softc), memc_match, memc_attach
65 };
66 
67 extern struct cfdriver memc_cd;
68 
69 
70 /* ARGSUSED */
71 int
72 memc_match(parent, cf, aux)
73 	struct device *parent;
74 	struct cfdata *cf;
75 	void *aux;
76 {
77 	struct mainbus_attach_args *ma = aux;
78 	bus_space_handle_t bh;
79 	u_int8_t chipid;
80 	int rv;
81 
82 #ifdef MVME68K
83 	if (machineid != MVME_167 && machineid != MVME_177 &&
84 	    machineid != MVME_162 && machineid != MVME_172)
85 		return (0);
86 #endif
87 
88 	if (strcmp(ma->ma_name, memc_cd.cd_name))
89 		return (0);
90 
91 	if (bus_space_map(ma->ma_bust, ma->ma_offset, MEMC_REGSIZE, 0, &bh))
92 		return (0);
93 
94 	rv = bus_space_peek_1(ma->ma_bust, bh, MEMC_REG_CHIP_ID, &chipid);
95 	bus_space_unmap(ma->ma_bust, bh, MEMC_REGSIZE);
96 
97 	if (rv)
98 		return (0);
99 
100 	/* Verify the Chip Id register is sane */
101 	if (chipid != MEMC_CHIP_ID_MEMC040 && chipid != MEMC_CHIP_ID_MEMECC)
102 		return (0);
103 
104 	return (1);
105 }
106 
107 /* ARGSUSED */
108 void
109 memc_attach(parent, self, aux)
110 	struct device *parent;
111 	struct device *self;
112 	void *aux;
113 {
114 	struct mainbus_attach_args *ma = aux;
115 	struct memc_softc *sc = (struct memc_softc *) self;
116 
117 	sc->sc_bust = ma->ma_bust;
118 
119 	/* Map the memory controller's registers */
120 	bus_space_map(sc->sc_bust, ma->ma_offset, MEMC_REGSIZE, 0,
121 	    &sc->sc_bush);
122 
123 	/* Finish initialisation in common code */
124 	memc_init(sc);
125 }
126