Home | History | Annotate | Line # | Download | only in gemini
gemini_obio.c revision 1.5
      1 /*	$NetBSD: gemini_obio.c,v 1.5 2008/11/13 05:03:05 cliff Exp $	*/
      2 
      3 /* adapted from:
      4  *	$Id: gemini_obio.c,v 1.5 2008/11/13 05:03:05 cliff Exp $
      5  */
      6 
      7 /*
      8  * Autoconfiguration support for the Texas Instruments OMAP "On Board" I/O.
      9  *
     10  * Based on arm/omap/omap_emifs.c which in turn was derived
     11  * Based on arm/xscale/pxa2x0.c which in turn was derived
     12  * from arm/sa11x0/sa11x0.c
     13  *
     14  * Copyright (c) 2002, 2005  Genetec Corporation.  All rights reserved.
     15  * Written by Hiroyuki Bessho for Genetec Corporation.
     16  *
     17  * Redistribution and use in source and binary forms, with or without
     18  * modification, are permitted provided that the following conditions
     19  * are met:
     20  * 1. Redistributions of source code must retain the above copyright
     21  *    notice, this list of conditions and the following disclaimer.
     22  * 2. Redistributions in binary form must reproduce the above copyright
     23  *    notice, this list of conditions and the following disclaimer in the
     24  *    documentation and/or other materials provided with the distribution.
     25  * 3. All advertising materials mentioning features or use of this software
     26  *    must display the following acknowledgement:
     27  *	This product includes software developed for the NetBSD Project by
     28  *	Genetec Corporation.
     29  * 4. The name of Genetec Corporation may not be used to endorse or
     30  *    promote products derived from this software without specific prior
     31  *    written permission.
     32  *
     33  * THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``AS IS'' AND
     34  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     35  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     36  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL GENETEC CORPORATION
     37  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     38  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     39  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     40  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     41  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     42  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     43  * POSSIBILITY OF SUCH DAMAGE.
     44  *
     45  * Copyright (c) 1997,1998, 2001, The NetBSD Foundation, Inc.
     46  * All rights reserved.
     47  *
     48  * This code is derived from software contributed to The NetBSD Foundation
     49  * by IWAMOTO Toshihiro, Ichiro FUKUHARA and Paul Kranenburg.
     50  *
     51  * Redistribution and use in source and binary forms, with or without
     52  * modification, are permitted provided that the following conditions
     53  * are met:
     54  * 1. Redistributions of source code must retain the above copyright
     55  *    notice, this list of conditions and the following disclaimer.
     56  * 2. Redistributions in binary form must reproduce the above copyright
     57  *    notice, this list of conditions and the following disclaimer in the
     58  *    documentation and/or other materials provided with the distribution.
     59  *
     60  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     61  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     62  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     63  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     64  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     65  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     66  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     67  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     68  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     69  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     70  * POSSIBILITY OF SUCH DAMAGE.
     71  *
     72  * Copyright (c) 1999
     73  *         Shin Takemura and PocketBSD Project. All rights reserved.
     74  *
     75  * Redistribution and use in source and binary forms, with or without
     76  * modification, are permitted provided that the following conditions
     77  * are met:
     78  * 1. Redistributions of source code must retain the above copyright
     79  *    notice, this list of conditions and the following disclaimer.
     80  * 2. Redistributions in binary form must reproduce the above copyright
     81  *    notice, this list of conditions and the following disclaimer in the
     82  *    documentation and/or other materials provided with the distribution.
     83  * 3. All advertising materials mentioning features or use of this software
     84  *    must display the following acknowledgement:
     85  *	This product includes software developed by the PocketBSD project
     86  *	and its contributors.
     87  * 4. Neither the name of the project nor the names of its contributors
     88  *    may be used to endorse or promote products derived from this software
     89  *    without specific prior written permission.
     90  *
     91  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     92  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     93  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     94  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     95  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     96  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     97  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     98  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     99  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    100  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    101  * SUCH DAMAGE.
    102  */
    103 
    104 #include "opt_gemini.h"
    105 #include <sys/cdefs.h>
    106 __KERNEL_RCSID(0, "$NetBSD: gemini_obio.c,v 1.5 2008/11/13 05:03:05 cliff Exp $");
    107 
    108 #include "locators.h"
    109 #include "obio.h"
    110 #include "geminiicu.h"
    111 #include "pci.h"
    112 
    113 #include <sys/param.h>
    114 #include <sys/systm.h>
    115 #include <sys/device.h>
    116 #include <sys/kernel.h>
    117 #include <sys/reboot.h>
    118 
    119 #include <machine/cpu.h>
    120 #include <machine/bus.h>
    121 
    122 #include <arm/cpufunc.h>
    123 #include <arm/mainbus/mainbus.h>
    124 #include <arm/gemini/gemini_var.h>
    125 #include <arm/gemini/gemini_reg.h>
    126 
    127 #include <arm/gemini/gemini_obiovar.h>
    128 
    129 typedef struct {
    130 	boolean_t	cs_valid;
    131 	ulong		cs_addr;
    132 	ulong		cs_size;
    133 } obio_csconfig_t;
    134 
    135 /* prototypes */
    136 static int	obio_match(device_t, cfdata_t, void *);
    137 static void	obio_attach(device_t, device_t, void *);
    138 static int 	obio_search(device_t, cfdata_t, const int *, void *);
    139 static int	obio_find(device_t, cfdata_t, const int *, void *);
    140 static int	obio_print(void *, const char *);
    141 static void	obio_attach_critical(struct obio_softc *);
    142 
    143 /* attach structures */
    144 CFATTACH_DECL(obio, sizeof(struct obio_softc),
    145 	obio_match, obio_attach, NULL, NULL);
    146 
    147 
    148 static int
    149 obio_match(device_t parent, cfdata_t match, void *aux)
    150 {
    151 	return 1;
    152 }
    153 
    154 static void
    155 obio_attach(device_t parent, device_t self, void *aux)
    156 {
    157 	struct obio_softc *sc = device_private(self);
    158 	struct mainbus_attach_args *mb = (struct mainbus_attach_args *)aux;
    159 #if NPCI > 0
    160 	struct pcibus_attach_args pba;
    161 #endif
    162 
    163 	sc->sc_iot = &gemini_bs_tag;
    164 
    165 	aprint_normal(": On-Board IO\n");
    166 
    167 #ifdef GEMINI_SLAVE
    168 	sc->sc_dmarange.dr_sysbase = 0;
    169 	sc->sc_dmarange.dr_busbase = (128 - MEMSIZE) * 1024 * 1024;
    170 	sc->sc_dmarange.dr_len = MEMSIZE * 1024 * 1024;
    171 	gemini_bus_dma_tag._ranges = &sc->sc_dmarange;
    172 	gemini_bus_dma_tag._nranges = 1;
    173 #endif
    174 
    175 	sc->sc_ioh = 0;
    176 	sc->sc_dmat = &gemini_bus_dma_tag;
    177 	sc->sc_base = mb->mb_iobase;
    178 	sc->sc_size = mb->mb_iosize;
    179 
    180 	/*
    181 	 * Attach critical devices first.
    182 	 */
    183 	obio_attach_critical(sc);
    184 
    185 #if NPCI > 0
    186 	/*
    187 	 * map PCI controller registers
    188 	 */
    189 	if (bus_space_map(sc->sc_iot, GEMINI_PCICFG_BASE,
    190 		GEMINI_PCI_CFG_DATA+4, 0, &sc->sc_pcicfg_ioh)) {
    191 			aprint_error("cannot map PCI controller at %#x\n",
    192 				GEMINI_PCICFG_BASE);
    193 			return;
    194 	}
    195 	/*
    196 	 * initialize the PCI chipset tag
    197 	 */
    198 	gemini_pci_init(&sc->sc_pci_chipset, sc);
    199 #endif	/* NPCI */
    200 
    201 	/*
    202 	 * attach the rest of our devices
    203 	 */
    204 	config_search_ia(obio_search, self, "obio", NULL);
    205 
    206 #if NPCI > 0
    207 	/*
    208 	 * attach the PCI bus
    209 	 */
    210 	pba.pba_memt = sc->sc_iot;
    211 	pba.pba_iot =  sc->sc_iot;;
    212 	pba.pba_dmat = sc->sc_dmat;
    213 	pba.pba_dmat64 = NULL;
    214 	pba.pba_pc = &sc->sc_pci_chipset;
    215 	pba.pba_bus = 0;
    216 	pba.pba_bridgetag = NULL;
    217 	pba.pba_intrswiz = 0;
    218 	pba.pba_intrtag = 0;
    219 	pba.pba_flags = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED |
    220 	    PCI_FLAGS_MRL_OKAY | PCI_FLAGS_MRM_OKAY | PCI_FLAGS_MWI_OKAY;
    221 
    222 	(void) config_found_ia(&sc->sc_dev, "pcibus", &pba, pcibusprint);
    223 #endif	/* NPCI */
    224 
    225 }
    226 
    227 static int
    228 obio_search(device_t parent, cfdata_t cf, const int *ldesc, void *aux)
    229 {
    230 	struct obio_softc * const sc = device_private(parent);
    231 	struct obio_attach_args oa;
    232 
    233 	/* Set up the attach args. */
    234 	if (cf->cf_loc[OBIOCF_NOBYTEACC] == 1) {
    235 #if 0
    236 		if (cf->cf_loc[OBIOCF_MULT] == 1)
    237 			oa.obio_iot = &nobyteacc_bs_tag;
    238 		else
    239 #endif
    240 			panic("nobyteacc specified for device with "
    241 				"non-byte multiplier\n");
    242 	} else {
    243 		switch (cf->cf_loc[OBIOCF_MULT]) {
    244 		case 1:
    245 			oa.obio_iot = &gemini_bs_tag;
    246 			break;
    247 #if 0
    248 		case 2:
    249 			oa.obio_iot = &gemini_a2x_bs_tag;
    250 			break;
    251 #endif
    252 		case 4:
    253 			oa.obio_iot = &gemini_a4x_bs_tag;
    254 			break;
    255 		default:
    256 			panic("Unsupported obio bus multiplier.");
    257 			break;
    258 		}
    259 	}
    260 
    261 	oa.obio_dmat = sc->sc_dmat;
    262 	oa.obio_addr = cf->cf_loc[OBIOCF_ADDR];
    263 	oa.obio_size = cf->cf_loc[OBIOCF_SIZE];
    264 	oa.obio_intr = cf->cf_loc[OBIOCF_INTR];
    265 	oa.obio_intrbase = cf->cf_loc[OBIOCF_INTRBASE];
    266 
    267 	if (config_match(parent, cf, &oa)) {
    268 		config_attach(parent, cf, &oa, obio_print);
    269 		return 0;			/* love it */
    270 	}
    271 
    272 	return UNCONF;	/* NG */
    273 }
    274 
    275 static int
    276 obio_find(device_t parent, cfdata_t cf, const int *ldesc, void *aux)
    277 {
    278 	struct obio_attach_args * const oa = aux;
    279 
    280 	if (oa->obio_addr != OBIOCF_ADDR_DEFAULT
    281 	    && oa->obio_addr != cf->cf_loc[OBIOCF_ADDR])
    282 		return 0;
    283 	if (oa->obio_size != OBIOCF_SIZE_DEFAULT
    284 	    && oa->obio_size != cf->cf_loc[OBIOCF_SIZE])
    285 		return 0;
    286 	if (oa->obio_intr != OBIOCF_INTR_DEFAULT
    287 	    && oa->obio_intr != cf->cf_loc[OBIOCF_INTR])
    288 		return 0;
    289 	if (oa->obio_intrbase != OBIOCF_INTRBASE_DEFAULT
    290 	    && oa->obio_intrbase != cf->cf_loc[OBIOCF_INTRBASE])
    291 		return 0;
    292 
    293 	/* Set up the attach args. */
    294 	if (cf->cf_loc[OBIOCF_NOBYTEACC] == 1) {
    295 #if 0
    296 		if (cf->cf_loc[OBIOCF_MULT] == 1)
    297 			oa->obio_iot = &nobyteacc_bs_tag;
    298 		else
    299 #endif
    300 			panic("nobyteacc specified for device with "
    301 				"non-byte multiplier\n");
    302 	} else {
    303 		switch (cf->cf_loc[OBIOCF_MULT]) {
    304 		case 1:
    305 			oa->obio_iot = &gemini_bs_tag;
    306 			break;
    307 #if 0
    308 		case 2:
    309 			oa->obio_iot = &gemini_a2x_bs_tag;
    310 			break;
    311 #endif
    312 		case 4:
    313 			oa->obio_iot = &gemini_a4x_bs_tag;
    314 			break;
    315 		default:
    316 			panic("Unsupported obio bus multiplier.");
    317 			break;
    318 		}
    319 	}
    320 	oa->obio_addr = cf->cf_loc[OBIOCF_ADDR];
    321 	oa->obio_size = cf->cf_loc[OBIOCF_SIZE];
    322 	oa->obio_intr = cf->cf_loc[OBIOCF_INTR];
    323 	oa->obio_intrbase = cf->cf_loc[OBIOCF_INTRBASE];
    324 
    325 	return config_match(parent, cf, oa);
    326 }
    327 
    328 #if NGEMINIICU == 0
    329 #error no geminiicu present in config file
    330 #endif
    331 
    332 static const struct {
    333 	const char *name;
    334 	bus_addr_t addr;
    335 	bool required;
    336 } critical_devs[] = {
    337 #if defined(GEMINI_MASTER) || defined(GEMINI_SINGLE)
    338 	{ .name = "geminiicu0",   .addr = 0x48000000, .required = true },
    339 	{ .name = "geminiwdt0",   .addr = 0x41000000, .required = true },
    340 	{ .name = "geminitmr0",   .addr = 0x43000000, .required = true },
    341 	{ .name = "geminitmr2",   .addr = 0x43000000, .required = true },
    342 	{ .name = "com0",         .addr = 0x42000000, .required = true },
    343 #elif defined(GEMINI_SLAVE)
    344 	{ .name = "geminiicu1",   .addr = 0x49000000, .required = true },
    345 	{ .name = "geminitmr1",   .addr = 0x43000000, .required = true },
    346 	{ .name = "geminitmr2",   .addr = 0x43000000, .required = true },
    347 	{ .name = "geminilpchc0", .addr = 0x47000000, .required = true },
    348 #endif
    349 };
    350 
    351 static void
    352 obio_attach_critical(struct obio_softc *sc)
    353 {
    354 	struct obio_attach_args oa;
    355 	cfdata_t cf;
    356 	size_t i;
    357 
    358 	for (i = 0; i < __arraycount(critical_devs); i++) {
    359 		oa.obio_iot = sc->sc_iot;
    360 		oa.obio_dmat = sc->sc_dmat;
    361 
    362 		oa.obio_addr = critical_devs[i].addr;
    363 		oa.obio_size = OBIOCF_SIZE_DEFAULT;
    364 		oa.obio_intr = OBIOCF_INTR_DEFAULT;
    365 		oa.obio_intrbase = OBIOCF_INTRBASE_DEFAULT;
    366 
    367 #if 0
    368 		if (oa.obio_addr != OBIOCF_ADDR_DEFAULT
    369 		    && (oa.obio_addr < sc->sc_base
    370 		        || oa.obio_addr >= sc->sc_base + sc->sc_size))
    371 			continue;
    372 #endif
    373 
    374 		cf = config_search_ia(obio_find, &sc->sc_dev, "obio", &oa);
    375 		if (cf == NULL && critical_devs[i].required)
    376 			panic("obio_attach_critical: failed to find %s!",
    377 			    critical_devs[i].name);
    378 
    379 		oa.obio_addr = cf->cf_loc[OBIOCF_ADDR];
    380 		oa.obio_size = cf->cf_loc[OBIOCF_SIZE];
    381 		oa.obio_intr = cf->cf_loc[OBIOCF_INTR];
    382 		oa.obio_intrbase = cf->cf_loc[OBIOCF_INTRBASE];
    383 		config_attach(&sc->sc_dev, cf, &oa, obio_print);
    384 	}
    385 }
    386 
    387 static int
    388 obio_print(void *aux, const char *name)
    389 {
    390 	struct obio_attach_args *oa = (struct obio_attach_args*)aux;
    391 
    392 	if (oa->obio_addr != OBIOCF_ADDR_DEFAULT) {
    393 		aprint_normal(" addr 0x%08lx", oa->obio_addr);
    394 		if (oa->obio_size != OBIOCF_SIZE_DEFAULT)
    395 			aprint_normal("-0x%08lx",
    396 				oa->obio_addr + oa->obio_size-1);
    397 	}
    398 	if (oa->obio_intr != OBIOCF_INTR_DEFAULT)
    399 		aprint_normal(" intr %d", oa->obio_intr);
    400 	if (oa->obio_intrbase != OBIOCF_INTRBASE_DEFAULT)
    401 		aprint_normal(" intrbase %d", oa->obio_intrbase);
    402 
    403 	return UNCONF;
    404 }
    405