xref: /netbsd-src/sys/arch/hppa/gsc/fdc_gsc.c (revision 6d3ceb1d619615401b17c9aa3e4bc674a1cb048b)
1 /*	$NetBSD: fdc_gsc.c,v 1.1 2014/02/24 07:23:43 skrll Exp $	*/
2 
3 /*	$OpenBSD: fdc_gsc.c,v 1.1 1998/09/30 04:45:46 mickey Exp $	*/
4 
5 /*
6  * Copyright (c) 1998 Michael Shalayeff
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21  * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
22  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24  * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
27  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
28  * THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #include <sys/cdefs.h>
32 __KERNEL_RCSID(0, "$NetBSD: fdc_gsc.c,v 1.1 2014/02/24 07:23:43 skrll Exp $");
33 
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/device.h>
37 
38 #include <machine/iomod.h>
39 #include <sys/bus.h>
40 #include <machine/intr.h>
41 #include <machine/autoconf.h>
42 
43 #include <dev/ic/fdreg.h>
44 #include <dev/ic/fdlink.h>
45 
46 #include <hppa/dev/cpudevs.h>
47 
48 /* controller driver configuration */
49 int fdc_gsc_probe(device_t, cfdata_t, void *);
50 void fdc_gsc_attach(device_t, device_t, void *);
51 
52 CFATTACH_DECL_NEW(fdc_gsc, sizeof(struct fdc_softc),
53     fdc_gsc_probe, fdc_gsc_attach, NULL, NULL);
54 
55 int
fdc_gsc_probe(device_t parent,cfdata_t match,void * aux)56 fdc_gsc_probe(device_t parent, cfdata_t match, void *aux)
57 {
58 	struct confargs *ca = aux;
59 	bus_space_handle_t ioh;
60 	int rv;
61 
62 	if (ca->ca_type.iodc_type != HPPA_TYPE_FIO ||
63 	    ca->ca_type.iodc_sv_model != HPPA_FIO_GPCFD)
64 		return 0;
65 
66 	/* Map the i/o space. */
67 	if (bus_space_map(ca->ca_iot, ca->ca_hpa, IOMOD_HPASIZE, 0, &ioh))
68 		return 0;
69 
70 	rv = fdcprobe1(ca->ca_iot, ioh | IOMOD_DEVOFFSET);
71 	bus_space_unmap(ca->ca_iot, ioh, IOMOD_HPASIZE);
72 	return rv;
73 }
74 
75 void
fdc_gsc_attach(device_t parent,device_t self,void * aux)76 fdc_gsc_attach(device_t parent, device_t self, void *aux)
77 {
78 	struct fdc_softc *sc = device_private(self);
79 	bus_space_handle_t ioh;
80 	struct confargs *ca = aux;
81 
82 	sc->sc_dev = self;
83 
84 	/* Re-map the I/O space. */
85 	if (bus_space_map(ca->ca_iot, ca->ca_hpa, IOMOD_HPASIZE, 0, &ioh)) {
86 		aprint_error(": can't map I/O ports\n");
87 		return;
88 	}
89 
90 	ioh |= IOMOD_DEVOFFSET;
91 	sc->sc_iot = ca->ca_iot;
92 	sc->sc_ioh = ioh;
93 	sc->sc_ioh_ctl = ioh + FDCTL_OFFSET;
94 
95 	fdc_attach_subr(sc);
96 }
97