Home | History | Annotate | Line # | Download | only in dev
sti_dio.c revision 1.4.4.2
      1  1.4.4.2  perseant /*	$NetBSD: sti_dio.c,v 1.4.4.2 2025/08/02 05:55:38 perseant Exp $	*/
      2  1.4.4.2  perseant /*	$OpenBSD: sti_dio.c,v 1.1 2011/08/18 20:02:57 miod Exp $	*/
      3  1.4.4.2  perseant 
      4  1.4.4.2  perseant /*
      5  1.4.4.2  perseant  * Copyright (c) 2005, 2011, Miodrag Vallat
      6  1.4.4.2  perseant  *
      7  1.4.4.2  perseant  * Redistribution and use in source and binary forms, with or without
      8  1.4.4.2  perseant  * modification, are permitted provided that the following conditions
      9  1.4.4.2  perseant  * are met:
     10  1.4.4.2  perseant  * 1. Redistributions of source code must retain the above copyright
     11  1.4.4.2  perseant  *    notice, this list of conditions and the following disclaimer.
     12  1.4.4.2  perseant  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.4.4.2  perseant  *    notice, this list of conditions and the following disclaimer in the
     14  1.4.4.2  perseant  *    documentation and/or other materials provided with the distribution.
     15  1.4.4.2  perseant  *
     16  1.4.4.2  perseant  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17  1.4.4.2  perseant  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     18  1.4.4.2  perseant  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     19  1.4.4.2  perseant  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
     20  1.4.4.2  perseant  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     21  1.4.4.2  perseant  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     22  1.4.4.2  perseant  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     23  1.4.4.2  perseant  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     24  1.4.4.2  perseant  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
     25  1.4.4.2  perseant  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     26  1.4.4.2  perseant  * POSSIBILITY OF SUCH DAMAGE.
     27  1.4.4.2  perseant  *
     28  1.4.4.2  perseant  */
     29  1.4.4.2  perseant #include <sys/cdefs.h>
     30  1.4.4.2  perseant __KERNEL_RCSID(0, "$NetBSD: sti_dio.c,v 1.4.4.2 2025/08/02 05:55:38 perseant Exp $");
     31  1.4.4.2  perseant 
     32  1.4.4.2  perseant #include <sys/param.h>
     33  1.4.4.2  perseant #include <sys/device.h>
     34  1.4.4.2  perseant #include <sys/bus.h>
     35  1.4.4.2  perseant 
     36  1.4.4.2  perseant #include <machine/autoconf.h>
     37  1.4.4.2  perseant 
     38  1.4.4.2  perseant #include <hp300/dev/dioreg.h>
     39  1.4.4.2  perseant #include <hp300/dev/diovar.h>
     40  1.4.4.2  perseant #include <hp300/dev/diodevs.h>
     41  1.4.4.2  perseant #include <hp300/dev/sti_diovar.h>
     42  1.4.4.2  perseant #include <hp300/dev/sti_machdep.h>
     43  1.4.4.2  perseant 
     44  1.4.4.2  perseant static int  sti_dio_match(device_t, cfdata_t, void *);
     45  1.4.4.2  perseant static void sti_dio_attach(device_t, device_t, void *);
     46  1.4.4.2  perseant 
     47  1.4.4.2  perseant static int sti_dio_probe(bus_space_tag_t, int);
     48  1.4.4.2  perseant 
     49  1.4.4.2  perseant CFATTACH_DECL_NEW(sti_dio, sizeof(struct sti_machdep_softc),
     50  1.4.4.2  perseant     sti_dio_match, sti_dio_attach, NULL, NULL);
     51  1.4.4.2  perseant 
     52  1.4.4.2  perseant static int
     53  1.4.4.2  perseant sti_dio_match(device_t parent, cfdata_t cf, void *aux)
     54  1.4.4.2  perseant {
     55  1.4.4.2  perseant 	struct dio_attach_args *da = aux;
     56  1.4.4.2  perseant 
     57  1.4.4.2  perseant 	if (da->da_id != DIO_DEVICE_ID_FRAMEBUFFER ||
     58  1.4.4.2  perseant 	    (da->da_secid != DIO_DEVICE_SECID_A1474MID &&
     59  1.4.4.2  perseant 	     da->da_secid != DIO_DEVICE_SECID_A147xVGA))
     60  1.4.4.2  perseant 		return 0;
     61  1.4.4.2  perseant 
     62  1.4.4.2  perseant 	/*
     63  1.4.4.2  perseant 	 * If we already probed it successfully as a console device, go ahead,
     64  1.4.4.2  perseant 	 * since we will not be able to bus_space_map() again.
     65  1.4.4.2  perseant 	 */
     66  1.4.4.2  perseant 	if (da->da_scode == conscode ||
     67  1.4.4.2  perseant 	    sti_dio_probe(da->da_bst, da->da_scode) != 0)
     68  1.4.4.2  perseant 		return 10;	/* Beat old gendiofb(4) */
     69  1.4.4.2  perseant 
     70  1.4.4.2  perseant 	return 0;
     71  1.4.4.2  perseant }
     72  1.4.4.2  perseant 
     73  1.4.4.2  perseant static void
     74  1.4.4.2  perseant sti_dio_attach(device_t parent, device_t self, void *aux)
     75  1.4.4.2  perseant {
     76  1.4.4.2  perseant 	struct sti_machdep_softc *sc = device_private(self);
     77  1.4.4.2  perseant 	struct sti_softc *ssc = &sc->sc_sti;
     78  1.4.4.2  perseant 	struct dio_attach_args *da = aux;
     79  1.4.4.2  perseant 	bus_addr_t base;
     80  1.4.4.2  perseant 	bus_space_tag_t bst;
     81  1.4.4.2  perseant 	bus_space_handle_t romh;
     82  1.4.4.2  perseant 	u_int romend;
     83  1.4.4.2  perseant 	int i;
     84  1.4.4.2  perseant 
     85  1.4.4.2  perseant 	ssc->sc_dev = self;
     86  1.4.4.2  perseant 	bst = da->da_bst;
     87  1.4.4.2  perseant 
     88  1.4.4.2  perseant 	base = (paddr_t)dio_scodetopa(da->da_scode + STI_DIO_SCODE_OFFSET);
     89  1.4.4.2  perseant 	sc->sc_base = base;
     90  1.4.4.2  perseant 
     91  1.4.4.2  perseant 	/*
     92  1.4.4.2  perseant 	 * If we already probed it successfully as a console device, go ahead,
     93  1.4.4.2  perseant 	 * since we will not be able to bus_space_map() again.
     94  1.4.4.2  perseant 	 */
     95  1.4.4.2  perseant 	if (da->da_scode == conscode) {
     96  1.4.4.2  perseant 		sti_machdep_attach_console(sc);
     97  1.4.4.2  perseant 	} else {
     98  1.4.4.2  perseant 		if (bus_space_map(bst, base, PAGE_SIZE, 0, &romh)) {
     99  1.4.4.2  perseant 			aprint_error(": can't map frame buffer");
    100  1.4.4.2  perseant 			return;
    101  1.4.4.2  perseant 		}
    102  1.4.4.2  perseant 
    103  1.4.4.2  perseant 		/*
    104  1.4.4.2  perseant 		 * Compute real PROM size
    105  1.4.4.2  perseant 		 */
    106  1.4.4.2  perseant 		romend = sti_rom_size(bst, romh);
    107  1.4.4.2  perseant 
    108  1.4.4.2  perseant 		bus_space_unmap(bst, romh, PAGE_SIZE);
    109  1.4.4.2  perseant 
    110  1.4.4.2  perseant 		if (bus_space_map(bst, base, romend, 0, &romh)) {
    111  1.4.4.2  perseant 			aprint_error(": can't map frame buffer");
    112  1.4.4.2  perseant 			return;
    113  1.4.4.2  perseant 		}
    114  1.4.4.2  perseant 
    115  1.4.4.2  perseant 		ssc->bases[0] = romh;
    116  1.4.4.2  perseant 		for (i = 1; i < STI_REGION_MAX; i++)
    117  1.4.4.2  perseant 			ssc->bases[i] = base;
    118  1.4.4.2  perseant 
    119  1.4.4.2  perseant 		if (sti_attach_common(ssc, bst, bst, romh,
    120  1.4.4.2  perseant 		    STI_CODEBASE_M68K) != 0)
    121  1.4.4.2  perseant 			return;
    122  1.4.4.2  perseant 	}
    123  1.4.4.2  perseant 
    124  1.4.4.2  perseant 	sti_machdep_attach(sc);
    125  1.4.4.2  perseant }
    126  1.4.4.2  perseant 
    127  1.4.4.2  perseant static int
    128  1.4.4.2  perseant sti_dio_probe(bus_space_tag_t bst, int scode)
    129  1.4.4.2  perseant {
    130  1.4.4.2  perseant 	bus_space_handle_t bsh;
    131  1.4.4.2  perseant 	bus_addr_t addr, base;
    132  1.4.4.2  perseant 	int devtype;
    133  1.4.4.2  perseant 	u_int span;
    134  1.4.4.2  perseant 
    135  1.4.4.2  perseant 	/*
    136  1.4.4.2  perseant 	 * Sanity checks:
    137  1.4.4.2  perseant 	 * these devices provide both a DIO and an STI ROM. We expect the
    138  1.4.4.2  perseant 	 * DIO ROM to be a DIO-II ROM (i.e. to be at a DIO-II select code)
    139  1.4.4.2  perseant 	 * and report the device as spanning at least four select codes.
    140  1.4.4.2  perseant 	 */
    141  1.4.4.2  perseant 
    142  1.4.4.2  perseant 	if (!DIO_ISDIOII(scode))
    143  1.4.4.2  perseant 		return 0;
    144  1.4.4.2  perseant 
    145  1.4.4.2  perseant 	addr = (bus_addr_t)dio_scodetopa(scode);
    146  1.4.4.2  perseant 	if (bus_space_map(bst, addr, PAGE_SIZE, 0, &bsh))
    147  1.4.4.2  perseant 		return 0;
    148  1.4.4.2  perseant 	span = bus_space_read_1(bst, bsh, DIOII_SIZEOFF);
    149  1.4.4.2  perseant 	bus_space_unmap(bst, bsh, PAGE_SIZE);
    150  1.4.4.2  perseant 
    151  1.4.4.2  perseant 	if (span < STI_DIO_SIZE - 1)
    152  1.4.4.2  perseant 		return 0;
    153  1.4.4.2  perseant 
    154  1.4.4.2  perseant 	base = (bus_addr_t)dio_scodetopa(scode + STI_DIO_SCODE_OFFSET);
    155  1.4.4.2  perseant 	if (bus_space_map(bst, base, PAGE_SIZE, 0, &bsh))
    156  1.4.4.2  perseant 		return 0;
    157  1.4.4.2  perseant 	devtype = bus_space_read_1(bst, bsh, 3);
    158  1.4.4.2  perseant 	bus_space_unmap(bst, bsh, PAGE_SIZE);
    159  1.4.4.2  perseant 
    160  1.4.4.2  perseant 	if (devtype != STI_DEVTYPE1 && devtype != STI_DEVTYPE4)
    161  1.4.4.2  perseant 		return 0;
    162  1.4.4.2  perseant 
    163  1.4.4.2  perseant 	return 1;
    164  1.4.4.2  perseant }
    165  1.4.4.2  perseant 
    166  1.4.4.2  perseant int
    167  1.4.4.2  perseant sti_dio_cnprobe(bus_space_tag_t bst, bus_addr_t addr, int scode)
    168  1.4.4.2  perseant {
    169  1.4.4.2  perseant 
    170  1.4.4.2  perseant 	if (sti_dio_probe(bst, scode) == 0) {
    171  1.4.4.2  perseant 		/* not found */
    172  1.4.4.2  perseant 		return 1;
    173  1.4.4.2  perseant 	}
    174  1.4.4.2  perseant 	conscode = scode;
    175  1.4.4.2  perseant 
    176  1.4.4.2  perseant 	return 0;
    177  1.4.4.2  perseant }
    178  1.4.4.2  perseant 
    179  1.4.4.2  perseant void
    180  1.4.4.2  perseant sti_dio_cnattach(bus_space_tag_t bst, int scode)
    181  1.4.4.2  perseant {
    182  1.4.4.2  perseant 	paddr_t base;
    183  1.4.4.2  perseant 
    184  1.4.4.2  perseant 	base = (paddr_t)dio_scodetopa(scode + STI_DIO_SCODE_OFFSET);
    185  1.4.4.2  perseant 	sti_machdep_cnattach(bst, base);
    186  1.4.4.2  perseant }
    187