Home | History | Annotate | Line # | Download | only in dev
      1  1.21  thorpej /*	$NetBSD: ioblix_zbus.c,v 1.21 2021/08/07 16:18:41 thorpej Exp $ */
      2   1.2       is 
      3   1.1       is /*-
      4   1.1       is  * Copyright (c) 2000 The NetBSD Foundation, Inc.
      5   1.1       is  * All rights reserved.
      6   1.1       is  *
      7   1.1       is  * This code is derived from software contributed to The NetBSD Foundation
      8   1.1       is  * by Ignatios Souvatzis.
      9   1.1       is  *
     10   1.1       is  * Redistribution and use in source and binary forms, with or without
     11   1.1       is  * modification, are permitted provided that the following conditions
     12   1.1       is  * are met:
     13   1.1       is  * 1. Redistributions of source code must retain the above copyright
     14   1.1       is  *    notice, this list of conditions and the following disclaimer.
     15   1.1       is  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.1       is  *    notice, this list of conditions and the following disclaimer in the
     17   1.1       is  *    documentation and/or other materials provided with the distribution.
     18   1.1       is  *
     19   1.1       is  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20   1.1       is  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21   1.1       is  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22   1.1       is  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23   1.1       is  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24   1.1       is  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25   1.1       is  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26   1.1       is  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27   1.1       is  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28   1.1       is  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29   1.1       is  * POSSIBILITY OF SUCH DAMAGE.
     30   1.1       is  */
     31   1.6  aymeric 
     32   1.6  aymeric #include <sys/cdefs.h>
     33  1.21  thorpej __KERNEL_RCSID(0, "$NetBSD: ioblix_zbus.c,v 1.21 2021/08/07 16:18:41 thorpej Exp $");
     34   1.1       is 
     35   1.1       is /* IOBlix Zorro driver */
     36   1.1       is /* XXX to be done: we need to probe the com clock speed! */
     37   1.1       is 
     38   1.1       is #include <sys/types.h>
     39   1.1       is 
     40  1.15      phx #include <sys/device.h>
     41   1.1       is #include <sys/conf.h>
     42   1.1       is #include <sys/systm.h>
     43   1.1       is #include <sys/param.h>
     44  1.18   dyoung #include <sys/bus.h>
     45   1.1       is 
     46   1.1       is #include <amiga/include/cpu.h>
     47   1.1       is 
     48   1.1       is #include <amiga/amiga/device.h>
     49   1.1       is #include <amiga/amiga/drcustom.h>
     50   1.1       is 
     51   1.1       is #include <amiga/dev/supio.h>
     52   1.1       is #include <amiga/dev/zbusvar.h>
     53   1.1       is 
     54  1.16    jklos #include "opt_iobzclock.h"
     55   1.1       is 
     56   1.1       is struct iobz_softc {
     57   1.1       is 	struct bus_space_tag sc_bst;
     58   1.1       is };
     59   1.1       is 
     60  1.19      chs int iobzmatch(device_t, cfdata_t, void *);
     61  1.19      chs void iobzattach(device_t, device_t, void *);
     62  1.19      chs int iobzprint(void *, const char *);
     63   1.5       is void iobz_shutdown(void *);
     64   1.1       is 
     65  1.19      chs CFATTACH_DECL_NEW(iobl_zbus, sizeof(struct iobz_softc),
     66   1.9  thorpej     iobzmatch, iobzattach, NULL, NULL);
     67   1.1       is 
     68   1.1       is int
     69  1.19      chs iobzmatch(device_t parent, cfdata_t cf, void *aux)
     70   1.1       is {
     71   1.1       is 
     72   1.1       is 	struct zbus_args *zap;
     73   1.1       is 
     74  1.19      chs 	zap = aux;
     75   1.1       is 
     76   1.1       is 	if (zap->manid != 4711)
     77   1.1       is 		return (0);
     78   1.1       is 
     79   1.1       is 	if (zap->prodid != 1)
     80   1.1       is 		return (0);
     81   1.1       is 
     82   1.1       is 	return (1);
     83   1.1       is }
     84   1.1       is 
     85   1.1       is struct iobz_devs {
     86  1.12      jmc 	const char *name;
     87   1.1       is 	unsigned off;
     88   1.1       is 	int arg;
     89   1.1       is } iobzdevices[] = {
     90  1.17    jklos 	{ "com", 0x108, 24000000 },	/* XXX see below */
     91  1.17    jklos 	{ "com", 0x100, 24000000 },
     92  1.17    jklos 	{ "com", 0x118, 24000000 },
     93   1.1       is 	{ "com", 0x110, 24000000 },
     94   1.1       is 	{ "lpt", 0x200, 0 },
     95   1.1       is 	{ "lpt", 0x300, 0 },
     96   1.1       is 	{ 0, 0, 0}
     97   1.1       is };
     98   1.1       is 
     99   1.3       is #ifndef IOBZCLOCK
    100   1.3       is #define IOBZCLOCK 22118400;
    101   1.3       is #endif
    102   1.3       is int iobzclock = IOBZCLOCK;		/* patchable! */
    103   1.1       is 
    104   1.1       is void
    105  1.19      chs iobzattach(device_t parent, device_t self, void *aux)
    106   1.1       is {
    107   1.1       is 	struct iobz_softc *iobzsc;
    108   1.1       is 	struct iobz_devs  *iobzd;
    109   1.1       is 	struct zbus_args *zap;
    110   1.1       is 	struct supio_attach_args supa;
    111   1.1       is 	extern const struct amiga_bus_space_methods amiga_bus_stride_16;
    112   1.1       is 	volatile u_int8_t *p;
    113   1.1       is 
    114   1.1       is 
    115  1.19      chs 	iobzsc = device_private(self);
    116  1.19      chs 	zap = aux;
    117   1.1       is 
    118   1.1       is 	if (parent)
    119   1.1       is 		printf("\n");
    120   1.1       is 
    121   1.1       is 	iobzsc->sc_bst.base = (u_long)zap->va;
    122   1.1       is 	iobzsc->sc_bst.absm = &amiga_bus_stride_16;
    123   1.1       is 
    124   1.1       is 	supa.supio_iot = &iobzsc->sc_bst;
    125   1.1       is 	supa.supio_ipl = 6;
    126   1.1       is 
    127   1.1       is 	iobzd = iobzdevices;
    128   1.1       is 
    129   1.1       is 	while (iobzd->name) {
    130   1.1       is 		supa.supio_name = iobzd->name;
    131   1.1       is 		supa.supio_iobase = iobzd->off;
    132  1.16    jklos 		supa.supio_arg = iobzd->arg ? iobzclock : 0 /* XXX iobzd->arg */;
    133  1.21  thorpej 		config_found(self, &supa, iobzprint, CFARGS_NONE); /* XXX */
    134   1.1       is 		++iobzd;
    135   1.1       is 	}
    136   1.1       is 
    137   1.1       is 	p = (volatile u_int8_t *)zap->va + 2;
    138  1.12      jmc 	(void)shutdownhook_establish(iobz_shutdown, __UNVOLATILE(p));
    139   1.1       is 	*p = ((*p) & 0x1F) | 0x80;
    140   1.1       is }
    141   1.1       is 
    142   1.1       is int
    143  1.19      chs iobzprint(void *aux, const char *pnp)
    144   1.1       is {
    145   1.1       is 	struct supio_attach_args *supa;
    146  1.19      chs 	supa = aux;
    147   1.1       is 
    148   1.1       is 	if (pnp == NULL)
    149   1.1       is 		return(QUIET);
    150   1.1       is 
    151  1.10  thorpej 	aprint_normal("%s at %s port 0x%02x",
    152   1.1       is 	    supa->supio_name, pnp, supa->supio_iobase);
    153   1.1       is 
    154   1.1       is 	return(UNCONF);
    155   1.5       is }
    156   1.5       is 
    157   1.5       is /*
    158  1.11      wiz  * Disable board interrupts at shutdown time.
    159   1.5       is  */
    160   1.5       is 
    161   1.5       is void
    162   1.5       is iobz_shutdown(void *p) {
    163   1.5       is 	volatile int8_t *q;
    164   1.5       is 
    165   1.5       is 	q = p;
    166   1.5       is 
    167   1.5       is 	*q &= 0x1F;
    168   1.1       is }
    169