Home | History | Annotate | Line # | Download | only in dev
      1 /*	$NetBSD: drsupio.c,v 1.23 2021/08/07 16:18:41 thorpej Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 1997 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Ignatios Souvatzis.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 #include <sys/cdefs.h>
     33 __KERNEL_RCSID(0, "$NetBSD: drsupio.c,v 1.23 2021/08/07 16:18:41 thorpej Exp $");
     34 
     35 /*
     36  * DraCo multi-io chip bus space stuff
     37  */
     38 
     39 #include <sys/types.h>
     40 
     41 #include <sys/conf.h>
     42 #include <sys/device.h>
     43 #include <sys/systm.h>
     44 #include <sys/param.h>
     45 #include <sys/bus.h>
     46 
     47 #include <amiga/include/cpu.h>
     48 
     49 #include <amiga/amiga/device.h>
     50 #include <amiga/amiga/drcustom.h>
     51 
     52 #include <amiga/dev/supio.h>
     53 
     54 struct drsupio_softc {
     55 	struct bus_space_tag sc_bst;
     56 };
     57 
     58 int drsupiomatch(device_t, cfdata_t, void *);
     59 void drsupioattach(device_t, device_t, void *);
     60 int drsupprint(void *, const char *);
     61 void drlptintack(void *);
     62 
     63 CFATTACH_DECL_NEW(drsupio, sizeof(struct drsupio_softc),
     64     drsupiomatch, drsupioattach, NULL, NULL);
     65 
     66 int
     67 drsupiomatch(device_t parent, cfdata_t cf, void *aux)
     68 {
     69 	static int drsupio_matched = 0;
     70 
     71 	/* Exactly one of us lives on the DraCo */
     72 	if (!is_draco() || !matchname(aux, "drsupio") || drsupio_matched)
     73 		return 0;
     74 
     75 	drsupio_matched = 1;
     76 	return 1;
     77 }
     78 
     79 struct drsupio_devs {
     80 	const char *name;
     81 	int off;
     82 	int arg;
     83 } drsupiodevs[] = {
     84 	{ "com", 0x3f8, 115200 * 16 },
     85 	{ "com", 0x2f8, 115200 * 16 },
     86 	{ "lpt", 0x278, (int)drlptintack },
     87 	{ "fdc", 0x3f0, 0 },
     88 	/* WD port? */
     89 	{ 0 }
     90 };
     91 
     92 void
     93 drsupioattach(device_t parent, device_t self, void *aux)
     94 {
     95 	struct drsupio_softc *drsc;
     96 	struct drsupio_devs  *drsd;
     97 	struct drioct *ioct;
     98 	struct supio_attach_args supa;
     99 
    100 	drsc = device_private(self);
    101 	drsd = drsupiodevs;
    102 
    103 	if (parent)
    104 		printf("\n");
    105 
    106 	drsc->sc_bst.base = DRCCADDR + PAGE_SIZE * DRSUPIOPG + 1;
    107 	drsc->sc_bst.absm = &amiga_bus_stride_4;
    108 
    109 	supa.supio_iot = &drsc->sc_bst;
    110 	supa.supio_ipl = 5;
    111 
    112 	while (drsd->name) {
    113 		supa.supio_name = drsd->name;
    114 		supa.supio_iobase = drsd->off;
    115 		supa.supio_arg = drsd->arg;
    116 		config_found(self, &supa, drsupprint, CFARGS_NONE); /* XXX */
    117 		++drsd;
    118 	}
    119 
    120 	drlptintack(0);
    121 	ioct = (struct drioct *)(DRCCADDR + PAGE_SIZE * DRIOCTLPG);
    122 	ioct->io_status2 |= DRSTAT2_PARIRQENA;
    123 }
    124 
    125 void
    126 drlptintack(void *p)
    127 {
    128 	struct drioct *ioct;
    129 
    130 	(void)p;
    131 	ioct = (struct drioct *)(DRCCADDR + PAGE_SIZE * DRIOCTLPG);
    132 
    133 	ioct->io_parrst = 0;	/* any value works */
    134 }
    135 
    136 int
    137 drsupprint(void *aux, const char *pnp)
    138 {
    139 	struct supio_attach_args *supa;
    140 
    141 	supa = aux;
    142 
    143 	if (pnp == NULL)
    144 		return(QUIET);
    145 
    146 	aprint_normal("%s at %s port 0x%02x",
    147 	    supa->supio_name, pnp, supa->supio_iobase);
    148 
    149 	return(UNCONF);
    150 }
    151