Home | History | Annotate | Line # | Download | only in mainbus
      1  1.7  thorpej /* $NetBSD: atppc_pioc.c,v 1.7 2023/12/20 06:13:59 thorpej Exp $ */
      2  1.1    bjh21 
      3  1.1    bjh21 /*-
      4  1.1    bjh21  * Copyright (c) 2001 Alcove - Nicolas Souchu
      5  1.1    bjh21  * All rights reserved.
      6  1.1    bjh21  *
      7  1.1    bjh21  * Redistribution and use in source and binary forms, with or without
      8  1.1    bjh21  * modification, are permitted provided that the following conditions
      9  1.1    bjh21  * are met:
     10  1.1    bjh21  * 1. Redistributions of source code must retain the above copyright
     11  1.1    bjh21  *    notice, this list of conditions and the following disclaimer.
     12  1.1    bjh21  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1    bjh21  *    notice, this list of conditions and the following disclaimer in the
     14  1.1    bjh21  *    documentation and/or other materials provided with the distribution.
     15  1.1    bjh21  *
     16  1.1    bjh21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     17  1.1    bjh21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     18  1.1    bjh21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     19  1.1    bjh21  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     20  1.1    bjh21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     21  1.1    bjh21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     22  1.1    bjh21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     23  1.1    bjh21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     24  1.1    bjh21  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25  1.1    bjh21  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26  1.1    bjh21  * SUCH DAMAGE.
     27  1.1    bjh21  *
     28  1.1    bjh21  * FreeBSD: src/sys/isa/ppc.c,v 1.26.2.5 2001/10/02 05:21:45 nsouch Exp
     29  1.1    bjh21  *
     30  1.1    bjh21  */
     31  1.1    bjh21 
     32  1.1    bjh21 #include "opt_atppc.h"
     33  1.1    bjh21 
     34  1.1    bjh21 #include <sys/param.h>
     35  1.7  thorpej __KERNEL_RCSID(0, "$NetBSD: atppc_pioc.c,v 1.7 2023/12/20 06:13:59 thorpej Exp $");
     36  1.1    bjh21 
     37  1.1    bjh21 #include <sys/systm.h>
     38  1.1    bjh21 #include <sys/kernel.h>
     39  1.1    bjh21 #include <sys/device.h>
     40  1.6   dyoung #include <sys/bus.h>
     41  1.1    bjh21 
     42  1.1    bjh21 #include <machine/intr.h>
     43  1.1    bjh21 
     44  1.1    bjh21 #include <arch/acorn32/mainbus/piocvar.h>
     45  1.1    bjh21 
     46  1.1    bjh21 #include <dev/ic/atppcreg.h>
     47  1.1    bjh21 #include <dev/ic/atppcvar.h>
     48  1.1    bjh21 
     49  1.1    bjh21 #include "locators.h"
     50  1.1    bjh21 
     51  1.1    bjh21 /* Probe and attach functions for a atppc device on the PIOC. */
     52  1.4   cegger static int atppc_pioc_probe(device_t, cfdata_t, void *);
     53  1.4   cegger static void atppc_pioc_attach(device_t, device_t, void *);
     54  1.1    bjh21 
     55  1.4   cegger CFATTACH_DECL_NEW(atppc_pioc, sizeof(struct atppc_softc), atppc_pioc_probe,
     56  1.1    bjh21 	atppc_pioc_attach, NULL, NULL);
     57  1.1    bjh21 
     58  1.1    bjh21 #define IO_LPTSIZE 8
     59  1.1    bjh21 
     60  1.1    bjh21 /*
     61  1.1    bjh21  * Probe function: find parallel port controller on isa bus. Combined from
     62  1.1    bjh21  * lpt_isa_probe() in lpt.c and atppc_detect_port() from FreeBSD's ppc.c.
     63  1.1    bjh21  */
     64  1.1    bjh21 static int
     65  1.4   cegger atppc_pioc_probe(device_t parent, cfdata_t cf, void *aux)
     66  1.1    bjh21 {
     67  1.1    bjh21 	bus_space_handle_t ioh;
     68  1.1    bjh21 	struct pioc_attach_args *pa = aux;
     69  1.1    bjh21 	bus_space_tag_t iot = pa->pa_iot;
     70  1.1    bjh21 	int addr = pa->pa_iobase + pa->pa_offset;
     71  1.1    bjh21 	int rval = 0;
     72  1.1    bjh21 
     73  1.1    bjh21 	if (pa->pa_name && strcmp(pa->pa_name, "lpt") != 0)
     74  1.1    bjh21 		return 0;
     75  1.1    bjh21 
     76  1.1    bjh21 	if (pa->pa_offset == PIOCCF_OFFSET_DEFAULT) {
     77  1.5   cegger 		aprint_error_dev(parent, "(%s): io port unknown.\n", __func__);
     78  1.1    bjh21 	} else if (bus_space_map(iot, addr, IO_LPTSIZE, 0, &ioh) == 0) {
     79  1.1    bjh21 		if (atppc_detect_port(iot, ioh) == 0)
     80  1.1    bjh21 			rval = 1;
     81  1.1    bjh21 		else
     82  1.5   cegger 			aprint_error_dev(parent,
     83  1.5   cegger 			    "(%s): unable to write/read I/O port.\n",
     84  1.5   cegger 			    __func__);
     85  1.1    bjh21 		bus_space_unmap(iot, ioh, IO_LPTSIZE);
     86  1.1    bjh21 	} else {
     87  1.5   cegger 		aprint_error_dev(parent, "(%s): attempt to map bus space failed.\n",
     88  1.5   cegger 		    __func__);
     89  1.1    bjh21 	}
     90  1.1    bjh21 
     91  1.1    bjh21 	return rval;
     92  1.1    bjh21 }
     93  1.1    bjh21 
     94  1.1    bjh21 /* Attach function: attach and configure parallel port controller on isa bus. */
     95  1.1    bjh21 static void
     96  1.4   cegger atppc_pioc_attach(device_t parent, device_t self, void *aux)
     97  1.1    bjh21 {
     98  1.4   cegger 	struct atppc_softc *sc = device_private(self);
     99  1.1    bjh21 	struct pioc_attach_args *pa = aux;
    100  1.1    bjh21 	bus_addr_t iobase;
    101  1.1    bjh21 
    102  1.4   cegger 	sc->sc_dev = self;
    103  1.1    bjh21 	sc->sc_iot = pa->pa_iot;
    104  1.1    bjh21 	sc->sc_has = 0;
    105  1.1    bjh21 	iobase = pa->pa_iobase + pa->pa_offset;
    106  1.1    bjh21 
    107  1.1    bjh21 	if (bus_space_map(sc->sc_iot, iobase, IO_LPTSIZE, 0,
    108  1.1    bjh21 		&sc->sc_ioh) != 0) {
    109  1.1    bjh21 		aprint_error(": attempt to map bus space failed, device not "
    110  1.1    bjh21 			"properly attached.\n");
    111  1.1    bjh21 		sc->sc_dev_ok = ATPPC_NOATTACH;
    112  1.1    bjh21 		return;
    113  1.1    bjh21 	}
    114  1.1    bjh21 	sc->sc_dev_ok = ATPPC_ATTACHED;
    115  1.1    bjh21 
    116  1.1    bjh21 	/* Assign interrupt handler */
    117  1.3  thorpej 	if (!(device_cfdata(self)->cf_flags & ATPPC_FLAG_DISABLE_INTR)) {
    118  1.1    bjh21 		if (pa->pa_irq != MAINBUSCF_IRQ_DEFAULT) {
    119  1.1    bjh21 			/* Establish interrupt handler. */
    120  1.1    bjh21 			sc->sc_ieh = intr_claim(pa->pa_irq, IPL_TTY, "atppc",
    121  1.1    bjh21 			    atppcintr, sc);
    122  1.1    bjh21 			sc->sc_has |= ATPPC_HAS_INTR;
    123  1.1    bjh21 		} else
    124  1.1    bjh21 			ATPPC_DPRINTF(("%s: IRQ not assigned or bad number of "
    125  1.5   cegger 				"IRQs.\n", device_xname(self)));
    126  1.1    bjh21 	} else
    127  1.1    bjh21 		ATPPC_VPRINTF(("%s: interrupts not configured due to flags.\n",
    128  1.5   cegger 			device_xname(self)));
    129  1.1    bjh21 
    130  1.1    bjh21 	/* Run soft configuration attach */
    131  1.1    bjh21 	atppc_sc_attach(sc);
    132  1.1    bjh21 }
    133