1 /* $Id: omap2_gpmc.c,v 1.5 2008/11/21 17:13:07 matt Exp $ */
4 /* $NetBSD: omap2_gpmc.c,v 1.4 2008/08/27 11:03:10 matt Exp $ */
8 * Autoconfiguration support for the Texas Instruments OMAP GPMC bus.
9 * Based on arm/omap/omap_emifs.c which in turn was derived
10 * Based on arm/xscale/pxa2x0.c which in turn was derived
11 * from arm/sa11x0/sa11x0.c
13 * Copyright (c) 2002, 2005 Genetec Corporation. All rights reserved.
14 * Written by Hiroyuki Bessho for Genetec Corporation.
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions
19 * 1. Redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer.
21 * 2. Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution.
24 * 3. All advertising materials mentioning features or use of this software
25 * must display the following acknowledgement:
26 * This product includes software developed for the NetBSD Project by
27 * Genetec Corporation.
28 * 4. The name of Genetec Corporation may not be used to endorse or
29 * promote products derived from this software without specific prior
32 * THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``AS IS'' AND
33 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
34 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
35 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GENETEC CORPORATION
36 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
37 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
38 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
39 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
40 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
41 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 * POSSIBILITY OF SUCH DAMAGE.
44 * Copyright (c) 1997,1998, 2001, The NetBSD Foundation, Inc.
45 * All rights reserved.
47 * This code is derived from software contributed to The NetBSD Foundation
48 * by IWAMOTO Toshihiro, Ichiro FUKUHARA and Paul Kranenburg.
50 * Redistribution and use in source and binary forms, with or without
51 * modification, are permitted provided that the following conditions
53 * 1. Redistributions of source code must retain the above copyright
54 * notice, this list of conditions and the following disclaimer.
55 * 2. Redistributions in binary form must reproduce the above copyright
56 * notice, this list of conditions and the following disclaimer in the
57 * documentation and/or other materials provided with the distribution.
59 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
60 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
61 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
62 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
63 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
64 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
65 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
66 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
67 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
68 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
69 * POSSIBILITY OF SUCH DAMAGE.
72 * Shin Takemura and PocketBSD Project. All rights reserved.
74 * Redistribution and use in source and binary forms, with or without
75 * modification, are permitted provided that the following conditions
77 * 1. Redistributions of source code must retain the above copyright
78 * notice, this list of conditions and the following disclaimer.
79 * 2. Redistributions in binary form must reproduce the above copyright
80 * notice, this list of conditions and the following disclaimer in the
81 * documentation and/or other materials provided with the distribution.
82 * 3. All advertising materials mentioning features or use of this software
83 * must display the following acknowledgement:
84 * This product includes software developed by the PocketBSD project
85 * and its contributors.
86 * 4. Neither the name of the project nor the names of its contributors
87 * may be used to endorse or promote products derived from this software
88 * without specific prior written permission.
90 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
91 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
92 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
93 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
94 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
95 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
96 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
97 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
98 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
99 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
103 #include "opt_omap.h"
104 #include <sys/cdefs.h>
105 __KERNEL_RCSID(0, "$NetBSD: omap2_gpmc.c,v 1.4 2008/08/27 11:03:10 matt Exp $");
107 #include "locators.h"
109 #include <sys/param.h>
110 #include <sys/systm.h>
111 #include <sys/device.h>
112 #include <sys/kernel.h>
113 #include <sys/reboot.h>
115 #include <machine/cpu.h>
116 #include <machine/bus.h>
118 #include <arm/cpufunc.h>
119 #include <arm/mainbus/mainbus.h>
120 #include <arm/omap/omap_var.h>
122 #include <arm/omap/omap2_gpmcreg.h>
123 #include <arm/omap/omap2_gpmcvar.h>
133 bus_dma_tag_t sc_dmac
;
134 bus_space_tag_t sc_iot
;
135 bus_space_handle_t sc_ioh
;
136 gpmc_csconfig_t sc_csconfig
[GPMC_NCS
];
140 static bus_size_t csreg7
[GPMC_NCS
] = {
153 static int gpmc_match(device_t
, cfdata_t
, void *);
154 static void gpmc_attach(device_t
, device_t
, void *);
155 static void gpmc_csconfig_init(struct gpmc_softc
*);
156 static int gpmc_search(device_t
, cfdata_t
, const int *, void *);
157 static int gpmc_print(void *, const char *);
159 /* attach structures */
160 CFATTACH_DECL_NEW(gpmc
, sizeof(struct gpmc_softc
),
161 gpmc_match
, gpmc_attach
, NULL
, NULL
);
163 static int gpmc_attached
; /* XXX assumes only 1 instance */
166 gpmc_match(device_t parent
, cfdata_t match
, void *aux
)
168 struct mainbus_attach_args
*mb
= aux
;
170 if (gpmc_attached
!= 0)
174 if (mb
->mb_iobase
== GPMC_BASE
)
182 gpmc_attach(device_t parent
, device_t self
, void *aux
)
184 struct gpmc_softc
*sc
= device_private(self
);
185 struct mainbus_attach_args
*mb
= aux
;
186 bus_space_handle_t ioh
;
191 sc
->sc_iot
= &omap_bs_tag
;
193 err
= bus_space_map(sc
->sc_iot
, mb
->mb_iobase
, GPMC_SIZE
, 0, &ioh
);
195 panic("%s: Cannot map registers, error %d",
196 device_xname(self
), err
);
198 aprint_normal(": General Purpose Memory Controller");
200 rev
= bus_space_read_4(sc
->sc_iot
, ioh
, GPMC_REVISION
);
202 aprint_normal(", rev %d.%d\n",
203 GPMC_REVISION_REV_MAJ(rev
),
204 GPMC_REVISION_REV_MIN(rev
));
209 gpmc_csconfig_init(sc
);
214 * Attach all our devices
216 config_search_ia(gpmc_search
, self
, "gpmc", NULL
);
220 gpmc_csconfig_init(struct gpmc_softc
*sc
)
227 cs
= &sc
->sc_csconfig
[0];
228 for (i
=0; i
< GPMC_NCS
; i
++) {
229 memset(cs
, 0, sizeof(gpmc_csconfig_t
));
230 r
= bus_space_read_4(sc
->sc_iot
, sc
->sc_ioh
, csreg7
[i
]);
231 if ((r
& GPMC_CONFIG7_CSVALID
) != 0) {
233 cs
->cs_addr
= omap_gpmc_config7_addr(r
);
234 cs
->cs_size
= omap_gpmc_config7_size(r
);
235 aprint_normal("%s: CS#%d valid, "
236 "addr 0x%08lx, size %3ldMB\n",
237 device_xname(sc
->sc_dev
), i
,
238 cs
->cs_addr
, (cs
->cs_size
>> 20));
245 gpmc_search(device_t parent
, cfdata_t cf
, const int *ldesc
, void *aux
)
247 struct gpmc_softc
*sc
= device_private(parent
);
248 struct gpmc_attach_args aa
;
252 /* Set up the attach args. */
253 if (cf
->cf_loc
[GPMCCF_NOBYTEACC
] == 1) {
254 if (cf
->cf_loc
[GPMCCF_MULT
] == 1)
255 aa
.gpmc_iot
= &nobyteacc_bs_tag
;
257 panic("nobyteacc specified for device with "
258 "non-byte multiplier\n");
260 switch (cf
->cf_loc
[GPMCCF_MULT
]) {
262 aa
.gpmc_iot
= &omap_bs_tag
;
265 aa
.gpmc_iot
= &omap_a2x_bs_tag
;
268 aa
.gpmc_iot
= &omap_a4x_bs_tag
;
271 panic("Unsupported EMIFS multiplier.");
276 aa
.gpmc_dmac
= sc
->sc_dmac
;
277 aa
.gpmc_addr
= cf
->cf_loc
[GPMCCF_ADDR
];
278 aa
.gpmc_size
= cf
->cf_loc
[GPMCCF_SIZE
];
279 aa
.gpmc_intr
= cf
->cf_loc
[GPMCCF_INTR
];
281 cs
= &sc
->sc_csconfig
[0];
282 for (i
=0; i
< GPMC_NCS
; i
++) {
283 if ((aa
.gpmc_addr
>= cs
->cs_addr
)
284 && (aa
.gpmc_addr
< (cs
->cs_addr
+ cs
->cs_size
))) {
286 * if size was specified, then check it too
287 * otherwise just assume it is OK
289 if ((aa
.gpmc_size
!= GPMCCF_SIZE_DEFAULT
)
290 && ((aa
.gpmc_addr
+ aa
.gpmc_size
)
291 >= (cs
->cs_addr
+ cs
->cs_size
)))
293 if (config_match(parent
, cf
, &aa
)) {
294 config_attach(parent
, cf
, &aa
, gpmc_print
);
295 return 0; /* love it */
304 gpmc_print(void *aux
, const char *name
)
306 struct gpmc_attach_args
*sa
= (struct gpmc_attach_args
*)aux
;
308 if (sa
->gpmc_addr
!= GPMCCF_ADDR_DEFAULT
) {
309 aprint_normal(" addr 0x%08lx", sa
->gpmc_addr
);
310 if (sa
->gpmc_size
!= GPMCCF_SIZE_DEFAULT
)
311 aprint_normal("-0x%08lx",
312 sa
->gpmc_addr
+ sa
->gpmc_size
-1);
314 if (sa
->gpmc_intr
!= GPMCCF_INTR_DEFAULT
)
315 aprint_normal(" intr %d", sa
->gpmc_intr
);