xref: /netbsd-src/sys/dev/hpc/hpcout.c (revision cbab9cadce21ae72fac13910001079fff214cc29)
1*cbab9cadSchs /*	$NetBSD: hpcout.c,v 1.16 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: hpcout.c,v 1.16 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	hpcout_match(device_t, cfdata_t, void *);
48529e91fcScegger void	hpcout_attach(device_t, device_t, void *);
4926b0905dStakemura int	hpcout_hook(void *, int, long, void *);
5026b0905dStakemura 
5126b0905dStakemura struct hpcout_softc {
5226b0905dStakemura 	struct hpcioman_attach_args sc_hma;
5326b0905dStakemura };
5426b0905dStakemura 
5526b0905dStakemura #define sc_hc		sc_hma.hma_hc
5626b0905dStakemura #define sc_intr_mode	sc_hma.hma_intr_mode
5726b0905dStakemura #define sc_type		sc_hma.hma_type
5826b0905dStakemura #define sc_id		sc_hma.hma_id
5926b0905dStakemura #define sc_port		sc_hma.hma_port
6026b0905dStakemura #define sc_initvalue	sc_hma.hma_initvalue
6126b0905dStakemura #define sc_on		sc_hma.hma_on
6226b0905dStakemura #define sc_off		sc_hma.hma_off
6326b0905dStakemura 
64*cbab9cadSchs CFATTACH_DECL_NEW(hpcout, sizeof(struct hpcout_softc),
65c9b3657cSthorpej     hpcout_match, hpcout_attach, NULL, NULL);
6626b0905dStakemura 
6726b0905dStakemura int
hpcout_match(device_t parent,cfdata_t cf,void * aux)68529e91fcScegger hpcout_match(device_t parent, cfdata_t cf, void *aux)
6926b0905dStakemura {
70859a6a49Such 	return (1);
7126b0905dStakemura }
7226b0905dStakemura 
7326b0905dStakemura void
hpcout_attach(device_t parent,device_t self,void * aux)74529e91fcScegger hpcout_attach(device_t parent, device_t self, void *aux)
7526b0905dStakemura {
7626b0905dStakemura 	struct hpcioman_attach_args *hma = aux;
7792c7bba3Sthorpej 	struct hpcout_softc *sc = device_private(self);
7826b0905dStakemura 
79a9d7b546Such 	sc->sc_hma = *hma;	/* structure assignment */
80a9d7b546Such 
8126b0905dStakemura 	if (hma->hma_hc == NULL ||
8226b0905dStakemura 	    hma->hma_type == HPCIOMANCF_EVTYPE_DEFAULT ||
8326b0905dStakemura 	    hma->hma_id == HPCIOMANCF_ID_DEFAULT ||
8426b0905dStakemura 	    hma->hma_port == HPCIOMANCF_PORT_DEFAULT) {
8526b0905dStakemura 		printf(": ignored\n");
8626b0905dStakemura 		return;
8726b0905dStakemura 	}
8826b0905dStakemura 	printf("\n");
8926b0905dStakemura 
9026b0905dStakemura 	if (hma->hma_initvalue != -1)
9126b0905dStakemura 		hpcio_portwrite(sc->sc_hc, sc->sc_port, hma->hma_initvalue);
9226b0905dStakemura 
9326b0905dStakemura 	config_hook(sc->sc_type, sc->sc_id, CONFIG_HOOK_SHARE,
9426b0905dStakemura 	    hpcout_hook, sc);
9526b0905dStakemura }
9626b0905dStakemura 
9726b0905dStakemura int
hpcout_hook(void * arg,int type,long id,void * msg)9826b0905dStakemura hpcout_hook(void *arg, int type, long id, void *msg)
9926b0905dStakemura {
10026b0905dStakemura 	struct hpcout_softc *sc = arg;
10126b0905dStakemura 
1029b2b412cSperry 	printf("%s: port %d: %s\n", __func__, sc->sc_port,
10326b0905dStakemura 	    (int)msg ? "on" : "off");
10426b0905dStakemura 	hpcio_portwrite(sc->sc_hc, sc->sc_port,
10526b0905dStakemura 	    (int)msg ? sc->sc_on : sc->sc_off);
10626b0905dStakemura 
107859a6a49Such 	return (0);
10826b0905dStakemura }
109