xref: /netbsd-src/sys/arch/mvme68k/dev/memc_68k.c (revision 8ac07aec990b9d2e483062509d0a9fa5b4f57cf2)
1 /*	$NetBSD: memc_68k.c,v 1.6 2008/01/12 09:54:22 tsutsui 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.6 2008/01/12 09:54:22 tsutsui 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 #include "ioconf.h"
63 
64 int memc_match(struct device *, struct cfdata *, void *);
65 void memc_attach(struct device *, struct device *, void *);
66 
67 CFATTACH_DECL(memc, sizeof(struct memc_softc),
68     memc_match, memc_attach, NULL, NULL);
69 
70 
71 /* ARGSUSED */
72 int
73 memc_match(struct device *parent, struct cfdata *cf, void *aux)
74 {
75 	struct mainbus_attach_args *ma = aux;
76 	bus_space_handle_t bh;
77 	uint8_t chipid;
78 	int rv;
79 
80 #ifdef MVME68K
81 	if (machineid != MVME_167 && machineid != MVME_177 &&
82 	    machineid != MVME_162 && machineid != MVME_172)
83 		return 0;
84 #endif
85 
86 	if (strcmp(ma->ma_name, memc_cd.cd_name))
87 		return 0;
88 
89 	if (bus_space_map(ma->ma_bust, ma->ma_offset, MEMC_REGSIZE, 0, &bh))
90 		return 0;
91 
92 	rv = bus_space_peek_1(ma->ma_bust, bh, MEMC_REG_CHIP_ID, &chipid);
93 	bus_space_unmap(ma->ma_bust, bh, MEMC_REGSIZE);
94 
95 	if (rv)
96 		return 0;
97 
98 	/* Verify the Chip Id register is sane */
99 	if (chipid != MEMC_CHIP_ID_MEMC040 && chipid != MEMC_CHIP_ID_MEMECC)
100 		return 0;
101 
102 	return 1;
103 }
104 
105 /* ARGSUSED */
106 void
107 memc_attach(struct device *parent, struct device *self, void *aux)
108 {
109 	struct mainbus_attach_args *ma = aux;
110 	struct memc_softc *sc = (struct memc_softc *)self;
111 
112 	sc->sc_bust = ma->ma_bust;
113 
114 	/* Map the memory controller's registers */
115 	bus_space_map(sc->sc_bust, ma->ma_offset, MEMC_REGSIZE, 0,
116 	    &sc->sc_bush);
117 
118 	/* Finish initialisation in common code */
119 	memc_init(sc);
120 }
121