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