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