Home | History | Annotate | Line # | Download | only in isa
      1 /* $NetBSD: mcclock_isa.c,v 1.22 2024/03/06 06:30:49 thorpej Exp $ */
      2 
      3 /*
      4  * Copyright (c) 1995, 1996 Carnegie-Mellon University.
      5  * All rights reserved.
      6  *
      7  * Author: Chris G. Demetriou
      8  *
      9  * Permission to use, copy, modify and distribute this software and
     10  * its documentation is hereby granted, provided that both the copyright
     11  * notice and this permission notice appear in all copies of the
     12  * software, derivative works or modified versions, and any portions
     13  * thereof, and that both notices appear in supporting documentation.
     14  *
     15  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     16  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     17  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     18  *
     19  * Carnegie Mellon requests users of this software to return to
     20  *
     21  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     22  *  School of Computer Science
     23  *  Carnegie Mellon University
     24  *  Pittsburgh PA 15213-3890
     25  *
     26  * any improvements or extensions that they make and grant Carnegie the
     27  * rights to redistribute these changes.
     28  */
     29 
     30 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
     31 
     32 __KERNEL_RCSID(0, "$NetBSD: mcclock_isa.c,v 1.22 2024/03/06 06:30:49 thorpej Exp $");
     33 
     34 #include <sys/param.h>
     35 #include <sys/kernel.h>
     36 #include <sys/systm.h>
     37 #include <sys/device.h>
     38 
     39 #include <sys/bus.h>
     40 
     41 #include <dev/clock_subr.h>
     42 
     43 #include <dev/ic/mc146818reg.h>
     44 #include <dev/ic/mc146818var.h>
     45 #include <dev/isa/isavar.h>
     46 
     47 #include <alpha/alpha/mcclockvar.h>
     48 
     49 static int	mcclock_isa_match(device_t, cfdata_t, void *);
     50 static void	mcclock_isa_attach(device_t, device_t, void *);
     51 
     52 CFATTACH_DECL_NEW(mcclock_isa, sizeof(struct mcclock_softc),
     53     mcclock_isa_match, mcclock_isa_attach, NULL, NULL);
     54 
     55 static void	mcclock_isa_write(struct mc146818_softc *, u_int, u_int);
     56 static u_int	mcclock_isa_read(struct mc146818_softc *, u_int);
     57 
     58 static int
     59 mcclock_isa_match(device_t parent, cfdata_t cf, void *aux)
     60 {
     61 	struct isa_attach_args *ia = aux;
     62 	bus_space_handle_t ioh;
     63 
     64 	if (ia->ia_nio < 1 ||
     65 	    (ia->ia_io[0].ir_addr != ISA_UNKNOWN_PORT &&
     66 	     ia->ia_io[0].ir_addr != 0x70))
     67 		return (0);
     68 
     69 	if (ia->ia_niomem > 0 &&
     70 	    (ia->ia_iomem[0].ir_addr != ISA_UNKNOWN_IOMEM))
     71 		return (0);
     72 
     73 	if (ia->ia_nirq > 0 &&
     74 	    (ia->ia_irq[0].ir_irq != ISA_UNKNOWN_IRQ))
     75 		return (0);
     76 
     77 	if (ia->ia_ndrq > 0 &&
     78 	    (ia->ia_drq[0].ir_drq != ISA_UNKNOWN_DRQ))
     79 		return (0);
     80 
     81 	if (bus_space_map(ia->ia_iot, 0x70, 0x2, 0, &ioh))
     82 		return (0);
     83 
     84 	bus_space_unmap(ia->ia_iot, ioh, 0x2);
     85 
     86 	ia->ia_nio = 1;
     87 	ia->ia_io[0].ir_addr = 0x70;
     88 	ia->ia_io[0].ir_size = 0x02;
     89 
     90 	ia->ia_niomem = 0;
     91 	ia->ia_nirq = 0;
     92 	ia->ia_ndrq = 0;
     93 
     94 	return (1);
     95 }
     96 
     97 static void
     98 mcclock_isa_attach(device_t parent, device_t self, void *aux)
     99 {
    100 	struct mcclock_softc *msc = device_private(self);
    101 	struct mc146818_softc *sc = &msc->sc_mc146818;
    102 	struct isa_attach_args *ia = aux;
    103 
    104 	sc->sc_dev = self;
    105 	sc->sc_bst = ia->ia_iot;
    106 	if (bus_space_map(sc->sc_bst, ia->ia_io[0].ir_addr,
    107 	    ia->ia_io[0].ir_size, 0, &sc->sc_bsh))
    108 		panic("mcclock_isa_attach: couldn't map clock I/O space");
    109 
    110 	sc->sc_mcread  = mcclock_isa_read;
    111 	sc->sc_mcwrite = mcclock_isa_write;
    112 
    113 	mcclock_attach(msc);
    114 }
    115 
    116 static void
    117 mcclock_isa_write(struct mc146818_softc *sc, u_int reg, u_int datum)
    118 {
    119 	bus_space_tag_t iot = sc->sc_bst;
    120 	bus_space_handle_t ioh = sc->sc_bsh;
    121 
    122 	bus_space_write_1(iot, ioh, 0, reg);
    123 	bus_space_write_1(iot, ioh, 1, datum);
    124 }
    125 
    126 static u_int
    127 mcclock_isa_read(struct mc146818_softc *sc, u_int reg)
    128 {
    129 	bus_space_tag_t iot = sc->sc_bst;
    130 	bus_space_handle_t ioh = sc->sc_bsh;
    131 
    132 	bus_space_write_1(iot, ioh, 0, reg);
    133 	return bus_space_read_1(iot, ioh, 1);
    134 }
    135