Home | History | Annotate | Line # | Download | only in iomd
iomd.c revision 1.21.52.1
      1  1.21.52.1  thorpej /*	$NetBSD: iomd.c,v 1.21.52.1 2021/03/21 21:08:55 thorpej Exp $	*/
      2        1.1  reinoud 
      3        1.1  reinoud /*
      4        1.1  reinoud  * Copyright (c) 1996-1997 Mark Brinicombe.
      5        1.1  reinoud  * Copyright (c) 1997 Causality Limited
      6        1.1  reinoud  * All rights reserved.
      7        1.1  reinoud  *
      8        1.1  reinoud  * Redistribution and use in source and binary forms, with or without
      9        1.1  reinoud  * modification, are permitted provided that the following conditions
     10        1.1  reinoud  * are met:
     11        1.1  reinoud  * 1. Redistributions of source code must retain the above copyright
     12        1.1  reinoud  *    notice, this list of conditions and the following disclaimer.
     13        1.1  reinoud  * 2. Redistributions in binary form must reproduce the above copyright
     14        1.1  reinoud  *    notice, this list of conditions and the following disclaimer in the
     15        1.1  reinoud  *    documentation and/or other materials provided with the distribution.
     16        1.1  reinoud  * 3. All advertising materials mentioning features or use of this software
     17        1.1  reinoud  *    must display the following acknowledgement:
     18        1.1  reinoud  *	This product includes software developed by Mark Brinicombe.
     19        1.1  reinoud  * 4. The name of the company nor the name of the author may be used to
     20        1.1  reinoud  *    endorse or promote products derived from this software without specific
     21        1.1  reinoud  *    prior written permission.
     22        1.1  reinoud  *
     23        1.1  reinoud  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
     24        1.1  reinoud  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     25        1.1  reinoud  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     26        1.1  reinoud  * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
     27        1.1  reinoud  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     28        1.1  reinoud  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     29        1.1  reinoud  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30        1.1  reinoud  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31        1.1  reinoud  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32        1.1  reinoud  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33        1.1  reinoud  * SUCH DAMAGE.
     34        1.1  reinoud  *
     35        1.1  reinoud  * RiscBSD kernel project
     36        1.1  reinoud  *
     37        1.1  reinoud  * iomd.c
     38        1.1  reinoud  *
     39        1.1  reinoud  * Probing and configuration for the IOMD
     40        1.1  reinoud  *
     41        1.1  reinoud  * Created      : 10/10/95
     42        1.1  reinoud  * Updated	: 18/03/01 for rpckbd as part of the wscons project
     43        1.1  reinoud  */
     44       1.10    lukem 
     45       1.10    lukem #include <sys/cdefs.h>
     46  1.21.52.1  thorpej __KERNEL_RCSID(0, "$NetBSD: iomd.c,v 1.21.52.1 2021/03/21 21:08:55 thorpej Exp $");
     47        1.1  reinoud 
     48        1.1  reinoud #include <sys/param.h>
     49        1.1  reinoud #include <sys/systm.h>
     50        1.1  reinoud #include <sys/kernel.h>
     51        1.1  reinoud #include <sys/conf.h>
     52        1.1  reinoud #include <sys/malloc.h>
     53        1.1  reinoud #include <sys/device.h>
     54       1.17   dyoung #include <sys/bus.h>
     55        1.1  reinoud #include <machine/cpu.h>
     56        1.2  thorpej #include <machine/intr.h>
     57        1.1  reinoud #include <arm/iomd/iomdreg.h>
     58        1.1  reinoud #include <arm/iomd/iomdvar.h>
     59        1.1  reinoud 
     60        1.1  reinoud #include "iomd.h"
     61        1.1  reinoud 
     62        1.1  reinoud /*
     63        1.1  reinoud  * IOMD device.
     64        1.1  reinoud  *
     65        1.1  reinoud  * This probes and attaches the top level IOMD device.
     66        1.1  reinoud  * It then configures any children of the IOMD device.
     67        1.1  reinoud  */
     68        1.1  reinoud 
     69        1.1  reinoud /*
     70        1.1  reinoud  * IOMD softc structure.
     71        1.1  reinoud  *
     72        1.1  reinoud  * Contains the device node, bus space tag, handle and address
     73        1.1  reinoud  * and the IOMD id.
     74        1.1  reinoud  */
     75        1.1  reinoud 
     76        1.1  reinoud struct iomd_softc {
     77       1.20    skrll 	device_t 		sc_dev;	/* device node */
     78        1.1  reinoud 	bus_space_tag_t		sc_iot;	/* bus tag */
     79        1.1  reinoud 	bus_space_handle_t	sc_ioh;	/* bus handle */
     80        1.1  reinoud 	int			sc_id;	/* IOMD id */
     81        1.1  reinoud };
     82        1.1  reinoud 
     83       1.19    skrll static int iomdmatch(device_t parent, cfdata_t cf, void *aux);
     84       1.19    skrll static void iomdattach(device_t parent, device_t self, void *aux);
     85       1.15    bjh21 static int iomdprint(void *aux, const char *iomdbus);
     86        1.1  reinoud 
     87       1.19    skrll CFATTACH_DECL_NEW(iomd, sizeof(struct iomd_softc),
     88        1.8  thorpej     iomdmatch, iomdattach, NULL, NULL);
     89        1.1  reinoud 
     90        1.1  reinoud extern struct bus_space iomd_bs_tag;
     91        1.1  reinoud 
     92        1.1  reinoud int       iomd_found;
     93       1.18    skrll uint32_t iomd_base = IOMD_BASE;
     94        1.1  reinoud 
     95        1.1  reinoud /* following flag is used in iomd_irq.s ... has to be cleaned up one day ! */
     96       1.18    skrll uint32_t arm7500_ioc_found = 0;
     97        1.1  reinoud 
     98        1.1  reinoud 
     99        1.1  reinoud /* Declare prototypes */
    100        1.1  reinoud 
    101        1.1  reinoud /*
    102        1.1  reinoud  * int iomdprint(void *aux, const char *name)
    103        1.1  reinoud  *
    104        1.1  reinoud  * print configuration info for children
    105        1.1  reinoud  */
    106        1.1  reinoud 
    107        1.1  reinoud static int
    108       1.15    bjh21 iomdprint(void *aux, const char *name)
    109        1.1  reinoud {
    110        1.1  reinoud /*	union iomd_attach_args *ia = aux;*/
    111        1.1  reinoud 
    112       1.15    bjh21 	return QUIET;
    113        1.1  reinoud }
    114        1.1  reinoud 
    115        1.1  reinoud /*
    116       1.19    skrll  * int iomdmatch(device_t parent, cfdata_t cf, void *aux)
    117        1.1  reinoud  *
    118        1.1  reinoud  * Just return ok for this if it is device 0
    119        1.1  reinoud  */
    120        1.1  reinoud 
    121        1.1  reinoud static int
    122       1.19    skrll iomdmatch(device_t parent, cfdata_t cf, void *aux)
    123        1.1  reinoud {
    124       1.15    bjh21 
    125        1.1  reinoud 	if (iomd_found)
    126        1.1  reinoud 		return 0;
    127        1.1  reinoud 	return 1;
    128        1.1  reinoud }
    129        1.1  reinoud 
    130        1.1  reinoud 
    131        1.1  reinoud /*
    132       1.19    skrll  * void iomdattach(device_t parent, device_t dev, void *aux)
    133        1.1  reinoud  *
    134        1.1  reinoud  * Map the IOMD and identify it.
    135        1.1  reinoud  * Then configure the child devices based on the IOMD ID.
    136        1.1  reinoud  */
    137        1.1  reinoud 
    138        1.1  reinoud static void
    139       1.19    skrll iomdattach(device_t parent, device_t self, void *aux)
    140        1.1  reinoud {
    141       1.19    skrll 	struct iomd_softc *sc = device_private(self);
    142        1.1  reinoud /*	struct mainbus_attach_args *mb = aux;*/
    143        1.1  reinoud 	int refresh;
    144        1.1  reinoud #if 0
    145        1.9    bjh21 	int i, tmp;
    146        1.1  reinoud #endif
    147        1.1  reinoud 	union iomd_attach_args ia;
    148        1.1  reinoud 	bus_space_tag_t iot;
    149        1.1  reinoud 	bus_space_handle_t ioh;
    150        1.1  reinoud 
    151        1.1  reinoud 	/* There can be only 1 IOMD. */
    152        1.1  reinoud 	iomd_found = 1;
    153        1.1  reinoud 
    154       1.19    skrll 	sc->sc_dev = self;
    155        1.1  reinoud 	iot = sc->sc_iot = &iomd_bs_tag;
    156        1.1  reinoud 
    157        1.1  reinoud 	/* Map the IOMD */
    158        1.1  reinoud 	if (bus_space_map(iot, (int) iomd_base, IOMD_SIZE, 0, &ioh))
    159       1.21    skrll 		panic("%s: Cannot map registers", device_xname(self));
    160        1.1  reinoud 
    161        1.1  reinoud 	sc->sc_ioh = ioh;
    162        1.1  reinoud 
    163        1.1  reinoud 	/* Get the ID */
    164        1.1  reinoud 	sc->sc_id = bus_space_read_1(iot, ioh, IOMD_ID0)
    165        1.1  reinoud 		  | (bus_space_read_1(iot, ioh, IOMD_ID1) << 8);
    166       1.19    skrll 	aprint_normal(": ");
    167        1.1  reinoud 
    168        1.1  reinoud 	/* Identify it and get the DRAM refresh rate */
    169        1.1  reinoud 	switch (sc->sc_id) {
    170        1.1  reinoud 	case ARM7500_IOC_ID:
    171       1.19    skrll 		aprint_normal("ARM7500 IOMD ");
    172        1.1  reinoud 		refresh = bus_space_read_1(iot, ioh, IOMD_REFCR) & 0x0f;
    173        1.1  reinoud 		arm7500_ioc_found = 1;
    174        1.1  reinoud 		break;
    175        1.1  reinoud 	case ARM7500FE_IOC_ID:
    176       1.19    skrll 		aprint_normal("ARM7500FE IOMD ");
    177        1.1  reinoud 		refresh = bus_space_read_1(iot, ioh, IOMD_REFCR) & 0x0f;
    178        1.1  reinoud 		arm7500_ioc_found = 1;
    179        1.1  reinoud 		break;
    180        1.1  reinoud 	case RPC600_IOMD_ID:
    181       1.19    skrll 		aprint_normal("IOMD20 ");
    182        1.1  reinoud 		refresh = bus_space_read_1(iot, ioh, IOMD_VREFCR) & 0x09;
    183        1.1  reinoud 		arm7500_ioc_found = 0;
    184        1.1  reinoud 		break;
    185        1.1  reinoud 	default:
    186       1.19    skrll 		aprint_normal("Unknown IOMD ID=%04x ", sc->sc_id);
    187        1.1  reinoud 		refresh = -1;
    188        1.1  reinoud 		arm7500_ioc_found = 0;		/* just in case */
    189        1.1  reinoud 		break;
    190        1.1  reinoud 	}
    191       1.19    skrll 	aprint_normal("version %d\n", bus_space_read_1(iot, ioh, IOMD_VERSION));
    192        1.1  reinoud 
    193        1.1  reinoud 	/* Report the DRAM refresh rate */
    194       1.21    skrll 	aprint_normal("%s: ", device_xname(self));
    195       1.19    skrll 	aprint_normal("DRAM refresh=");
    196        1.1  reinoud 	switch (refresh) {
    197        1.1  reinoud 	case 0x0:
    198       1.19    skrll 		aprint_normal("off");
    199        1.1  reinoud 		break;
    200        1.1  reinoud 	case 0x1:
    201       1.19    skrll 		aprint_normal("16us");
    202        1.1  reinoud 		break;
    203        1.1  reinoud 	case 0x2:
    204       1.19    skrll 		aprint_normal("32us");
    205        1.1  reinoud 		break;
    206        1.1  reinoud 	case 0x4:
    207       1.19    skrll 		aprint_normal("64us");
    208        1.1  reinoud 		break;
    209        1.1  reinoud 	case 0x8:
    210       1.19    skrll 		aprint_normal("128us");
    211        1.1  reinoud 		break;
    212        1.1  reinoud 	default:
    213       1.19    skrll 		aprint_normal("unknown [%02x]", refresh);
    214        1.1  reinoud 		break;
    215        1.1  reinoud 	}
    216        1.1  reinoud 
    217       1.19    skrll 	aprint_normal("\n");
    218        1.1  reinoud #if 0
    219        1.1  reinoud 	/*
    220        1.1  reinoud 	 * No point in reporting this as it may get changed when devices are
    221        1.1  reinoud 	 * attached
    222        1.1  reinoud 	 */
    223        1.9    bjh21 	tmp = bus_space_read_1(iot, ioh, IOMD_IOTCR);
    224       1.21    skrll 	aprint_normal("%s: I/O timings: combo %c, NPCCS1/2 %c", device_xname(self),
    225        1.9    bjh21 	    'A' + ((tmp >>2) & 3), 'A' + (tmp & 3));
    226        1.9    bjh21 	tmp = bus_space_read_1(iot, ioh, IOMD_ECTCR);
    227       1.19    skrll 	aprint_normal(", EASI ");
    228        1.9    bjh21 	for (i = 0; i < 8; i++, tmp >>= 1)
    229       1.19    skrll 		aprint_normal("%c", 'A' + ((tmp & 1) << 2));
    230        1.9    bjh21 	tmp = bus_space_read_1(iot, ioh, IOMD_DMATCR);
    231       1.19    skrll 	aprint_normal(", DMA ");
    232        1.9    bjh21 	for (i = 0; i < 4; i++, tmp >>= 2)
    233       1.19    skrll 		aprint_normal("%c", 'A' + (tmp & 3));
    234       1.19    skrll 	aprint_normal("\n");
    235        1.1  reinoud #endif
    236        1.1  reinoud 
    237        1.1  reinoud 	/* Set up the external DMA channels */
    238       1.16      wiz 	/* XXX - this should be machine dependent not IOMD dependent */
    239        1.1  reinoud 	switch (sc->sc_id) {
    240        1.1  reinoud 	case ARM7500_IOC_ID:
    241        1.1  reinoud 	case ARM7500FE_IOC_ID:
    242        1.1  reinoud 		break;
    243        1.1  reinoud 	case RPC600_IOMD_ID:
    244        1.1  reinoud 		/* DMA channels 2 & 3 are external */
    245        1.1  reinoud 		bus_space_write_1(iot, ioh, IOMD_DMAEXT, 0x0c);
    246        1.1  reinoud 		break;
    247        1.1  reinoud    	}
    248        1.1  reinoud 
    249        1.1  reinoud 	/* Configure the child devices */
    250        1.1  reinoud 
    251        1.1  reinoud 	/* Attach clock device */
    252        1.1  reinoud 
    253        1.1  reinoud 	ia.ia_clk.ca_name = "clk";
    254        1.1  reinoud 	ia.ia_clk.ca_iot = iot;
    255        1.1  reinoud 	ia.ia_clk.ca_ioh = ioh;
    256  1.21.52.1  thorpej 	config_found(self, &ia, iomdprint, CFARG_EOL);
    257        1.1  reinoud 
    258        1.1  reinoud 	/* Attach kbd device when configured */
    259       1.12    bjh21 	if (bus_space_subregion(iot, ioh, IOMD_KBDDAT, 8, &ia.ia_kbd.ka_ioh))
    260       1.21    skrll 		panic("%s: Cannot map kbd registers", device_xname(self));
    261        1.1  reinoud 	ia.ia_kbd.ka_name = "kbd";
    262        1.1  reinoud 	ia.ia_kbd.ka_iot = iot;
    263        1.1  reinoud 	ia.ia_kbd.ka_rxirq = IRQ_KBDRX;
    264        1.1  reinoud 	ia.ia_kbd.ka_txirq = IRQ_KBDTX;
    265  1.21.52.1  thorpej 	config_found(self, &ia, iomdprint, CFARG_EOL);
    266        1.1  reinoud 
    267        1.1  reinoud 	/* Attach iic device */
    268        1.1  reinoud 
    269       1.12    bjh21 	if (bus_space_subregion(iot, ioh, IOMD_IOCR, 4, &ia.ia_iic.ia_ioh))
    270       1.21    skrll 		panic("%s: Cannot map iic registers", device_xname(self));
    271        1.1  reinoud 	ia.ia_iic.ia_name = "iic";
    272        1.1  reinoud 	ia.ia_iic.ia_iot = iot;
    273        1.1  reinoud 	ia.ia_iic.ia_irq = -1;
    274  1.21.52.1  thorpej 	config_found(self, &ia, iomdprint, CFARG_EOL);
    275        1.1  reinoud 
    276        1.1  reinoud 	switch (sc->sc_id) {
    277        1.1  reinoud 	case ARM7500_IOC_ID:
    278        1.1  reinoud 	case ARM7500FE_IOC_ID:
    279        1.3      wiz 		/* Attach opms device */
    280        1.1  reinoud 
    281       1.12    bjh21 		if (bus_space_subregion(iot, ioh, IOMD_MSDATA, 8,
    282       1.11    bjh21 			&ia.ia_opms.pa_ioh))
    283       1.21    skrll 			panic("%s: Cannot map opms registers", device_xname(self));
    284        1.3      wiz 		ia.ia_opms.pa_name = "opms";
    285        1.3      wiz 		ia.ia_opms.pa_iot = iot;
    286        1.3      wiz 		ia.ia_opms.pa_irq = IRQ_MSDRX;
    287  1.21.52.1  thorpej 		config_found(self, &ia, iomdprint, CFARG_EOL);
    288        1.1  reinoud 		break;
    289        1.1  reinoud 	case RPC600_IOMD_ID:
    290        1.1  reinoud 		/* Attach (ws)qms device */
    291        1.1  reinoud 
    292       1.12    bjh21 		if (bus_space_subregion(iot, ioh, IOMD_MOUSEX, 8,
    293       1.11    bjh21 			&ia.ia_qms.qa_ioh))
    294       1.21    skrll 			panic("%s: Cannot map qms registers", device_xname(self));
    295        1.1  reinoud 
    296        1.1  reinoud 		if (bus_space_map(iot, IO_MOUSE_BUTTONS, 4, 0, &ia.ia_qms.qa_ioh_but))
    297       1.21    skrll 			panic("%s: Cannot map registers", device_xname(self));
    298        1.1  reinoud 		ia.ia_qms.qa_name = "qms";
    299        1.1  reinoud 		ia.ia_qms.qa_iot = iot;
    300        1.1  reinoud 		ia.ia_qms.qa_irq = IRQ_VSYNC;
    301  1.21.52.1  thorpej 		config_found(self, &ia, iomdprint, CFARG_EOL);
    302        1.1  reinoud 		break;
    303        1.1  reinoud 	}
    304        1.1  reinoud }
    305        1.1  reinoud 
    306        1.1  reinoud /* End of iomd.c */
    307