1*cbab9cadSchs /* $NetBSD: hpcin.c,v 1.15 2012/10/27 17:18:17 chs Exp $ */
226b0905dStakemura
326b0905dStakemura /*-
426b0905dStakemura * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc.
526b0905dStakemura * All rights reserved.
626b0905dStakemura *
726b0905dStakemura * This code is derived from software contributed to The NetBSD Foundation
826b0905dStakemura * by UCHIYAMA Yasushi.
926b0905dStakemura *
1026b0905dStakemura * Redistribution and use in source and binary forms, with or without
1126b0905dStakemura * modification, are permitted provided that the following conditions
1226b0905dStakemura * are met:
1326b0905dStakemura * 1. Redistributions of source code must retain the above copyright
1426b0905dStakemura * notice, this list of conditions and the following disclaimer.
1526b0905dStakemura * 2. Redistributions in binary form must reproduce the above copyright
1626b0905dStakemura * notice, this list of conditions and the following disclaimer in the
1726b0905dStakemura * documentation and/or other materials provided with the distribution.
1826b0905dStakemura *
1926b0905dStakemura * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2026b0905dStakemura * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2126b0905dStakemura * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2226b0905dStakemura * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2326b0905dStakemura * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2426b0905dStakemura * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2526b0905dStakemura * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2626b0905dStakemura * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2726b0905dStakemura * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2826b0905dStakemura * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2926b0905dStakemura * POSSIBILITY OF SUCH DAMAGE.
3026b0905dStakemura */
31b84f53efSlukem
32b84f53efSlukem #include <sys/cdefs.h>
33*cbab9cadSchs __KERNEL_RCSID(0, "$NetBSD: hpcin.c,v 1.15 2012/10/27 17:18:17 chs Exp $");
34b84f53efSlukem
3526b0905dStakemura #include <sys/param.h>
3626b0905dStakemura #include <sys/systm.h>
3726b0905dStakemura #include <sys/device.h>
3826b0905dStakemura
3926b0905dStakemura #include <machine/config_hook.h>
40a2a38285Sad #include <sys/bus.h>
41a9d7b546Such
4226b0905dStakemura #include <dev/hpc/hpciovar.h>
4326b0905dStakemura #include <dev/hpc/hpciomanvar.h>
4426b0905dStakemura
4526b0905dStakemura #include "locators.h"
4626b0905dStakemura
47529e91fcScegger int hpcin_match(device_t, cfdata_t, void *);
48529e91fcScegger void hpcin_attach(device_t, device_t, void *);
4926b0905dStakemura int hpcin_intr(void *);
5026b0905dStakemura
5126b0905dStakemura struct hpcin_softc {
5226b0905dStakemura struct hpcioman_attach_args sc_hma;
5326b0905dStakemura hpcio_intr_handle_t sc_ih;
543d94c421Stakemura config_call_tag sc_ct;
5526b0905dStakemura };
5626b0905dStakemura
5726b0905dStakemura #define sc_hc sc_hma.hma_hc
5826b0905dStakemura #define sc_intr_mode sc_hma.hma_intr_mode
5926b0905dStakemura #define sc_type sc_hma.hma_type
6026b0905dStakemura #define sc_id sc_hma.hma_id
6126b0905dStakemura #define sc_port sc_hma.hma_port
6226b0905dStakemura #define sc_initvalue sc_hma.hma_initvalue
6326b0905dStakemura #define sc_on sc_hma.hma_on
6426b0905dStakemura #define sc_off sc_hma.hma_off
653d94c421Stakemura #define sc_connect sc_hma.hma_connect
6626b0905dStakemura
67*cbab9cadSchs CFATTACH_DECL_NEW(hpcin, sizeof(struct hpcin_softc),
68c9b3657cSthorpej hpcin_match, hpcin_attach, NULL, NULL);
6926b0905dStakemura
7026b0905dStakemura int
hpcin_match(device_t parent,cfdata_t cf,void * aux)71529e91fcScegger hpcin_match(device_t parent, cfdata_t cf, void *aux)
7226b0905dStakemura {
73859a6a49Such return (1);
7426b0905dStakemura }
7526b0905dStakemura
7626b0905dStakemura void
hpcin_attach(device_t parent,device_t self,void * aux)77529e91fcScegger hpcin_attach(device_t parent, device_t self, void *aux)
7826b0905dStakemura {
7926b0905dStakemura struct hpcioman_attach_args *hma = aux;
8092c7bba3Sthorpej struct hpcin_softc *sc = device_private(self);
8126b0905dStakemura
8226b0905dStakemura if (hma->hma_hc == NULL ||
8326b0905dStakemura hma->hma_type == HPCIOMANCF_EVTYPE_DEFAULT ||
8426b0905dStakemura hma->hma_id == HPCIOMANCF_ID_DEFAULT ||
8526b0905dStakemura hma->hma_port == HPCIOMANCF_PORT_DEFAULT) {
8626b0905dStakemura printf(": ignored\n");
8726b0905dStakemura return;
8826b0905dStakemura }
8926b0905dStakemura printf("\n");
9026b0905dStakemura
9126b0905dStakemura sc->sc_hma = *hma; /* structure assignment */
9226b0905dStakemura
9326b0905dStakemura /* install interrupt handler */
9426b0905dStakemura sc->sc_ih = hpcio_intr_establish(sc->sc_hc, sc->sc_port,
95859a6a49Such sc->sc_intr_mode, hpcin_intr, sc);
9626b0905dStakemura if (sc->sc_ih == NULL)
9726b0905dStakemura printf("hpcin: can't install interrupt handler\n");
983d94c421Stakemura
993d94c421Stakemura if (sc->sc_connect)
1003d94c421Stakemura sc->sc_ct = config_connect(sc->sc_type, sc->sc_id);
10126b0905dStakemura }
10226b0905dStakemura
10326b0905dStakemura int
hpcin_intr(void * arg)10426b0905dStakemura hpcin_intr(void *arg)
10526b0905dStakemura {
10626b0905dStakemura struct hpcin_softc *sc = arg;
10726b0905dStakemura int on;
10826b0905dStakemura
10926b0905dStakemura on = (hpcio_portread(sc->sc_hc, sc->sc_port) == sc->sc_on);
1103d94c421Stakemura if (sc->sc_connect) {
1113d94c421Stakemura config_connected_call(sc->sc_ct, (void *)on);
1123d94c421Stakemura } else {
1139b2b412cSperry printf("%s: type=%d, id=%d\n", __func__,
1143d94c421Stakemura sc->sc_type, sc->sc_id);
11526b0905dStakemura config_hook_call(sc->sc_type, sc->sc_id, (void *)on);
11626b0905dStakemura printf("done.\n");
1173d94c421Stakemura }
11826b0905dStakemura
119859a6a49Such return (0);
12026b0905dStakemura }
121