xref: /netbsd-src/sys/arch/mvme68k/dev/memc_68k.c (revision 23c8222edbfb0f0932d88a8351d3a0cf817dfb9e)
1 /*	$NetBSD: memc_68k.c,v 1.4 2003/07/15 02:43:46 lukem 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/cdefs.h>
44 __KERNEL_RCSID(0, "$NetBSD: memc_68k.c,v 1.4 2003/07/15 02:43:46 lukem Exp $");
45 
46 #include <sys/param.h>
47 #include <sys/kernel.h>
48 #include <sys/systm.h>
49 #include <sys/device.h>
50 #include <sys/malloc.h>
51 
52 #include <machine/cpu.h>
53 #include <machine/bus.h>
54 
55 #include <mvme68k/dev/mainbus.h>
56 
57 #include <dev/mvme/memcvar.h>
58 #include <dev/mvme/memcreg.h>
59 #include <dev/mvme/pcctwovar.h>
60 #include <dev/mvme/pcctworeg.h>
61 
62 
63 int memc_match(struct device *, struct cfdata *, void *);
64 void memc_attach(struct device *, struct device *, void *);
65 
66 CFATTACH_DECL(memc, sizeof(struct memc_softc),
67     memc_match, memc_attach, NULL, NULL);
68 
69 extern struct cfdriver memc_cd;
70 
71 
72 /* ARGSUSED */
73 int
74 memc_match(parent, cf, aux)
75 	struct device *parent;
76 	struct cfdata *cf;
77 	void *aux;
78 {
79 	struct mainbus_attach_args *ma = aux;
80 	bus_space_handle_t bh;
81 	u_int8_t chipid;
82 	int rv;
83 
84 #ifdef MVME68K
85 	if (machineid != MVME_167 && machineid != MVME_177 &&
86 	    machineid != MVME_162 && machineid != MVME_172)
87 		return (0);
88 #endif
89 
90 	if (strcmp(ma->ma_name, memc_cd.cd_name))
91 		return (0);
92 
93 	if (bus_space_map(ma->ma_bust, ma->ma_offset, MEMC_REGSIZE, 0, &bh))
94 		return (0);
95 
96 	rv = bus_space_peek_1(ma->ma_bust, bh, MEMC_REG_CHIP_ID, &chipid);
97 	bus_space_unmap(ma->ma_bust, bh, MEMC_REGSIZE);
98 
99 	if (rv)
100 		return (0);
101 
102 	/* Verify the Chip Id register is sane */
103 	if (chipid != MEMC_CHIP_ID_MEMC040 && chipid != MEMC_CHIP_ID_MEMECC)
104 		return (0);
105 
106 	return (1);
107 }
108 
109 /* ARGSUSED */
110 void
111 memc_attach(parent, self, aux)
112 	struct device *parent;
113 	struct device *self;
114 	void *aux;
115 {
116 	struct mainbus_attach_args *ma = aux;
117 	struct memc_softc *sc = (struct memc_softc *) self;
118 
119 	sc->sc_bust = ma->ma_bust;
120 
121 	/* Map the memory controller's registers */
122 	bus_space_map(sc->sc_bust, ma->ma_offset, MEMC_REGSIZE, 0,
123 	    &sc->sc_bush);
124 
125 	/* Finish initialisation in common code */
126 	memc_init(sc);
127 }
128