xref: /netbsd-src/sys/arch/hpcmips/vr/vrdsu.c (revision 20ca0a94c9204c98944fd2dceaed8740650a2c8b)
1*20ca0a94Smatt /*	$NetBSD: vrdsu.c,v 1.12 2015/06/09 22:46:36 matt Exp $	*/
262009df2Stakemura 
362009df2Stakemura /*
462009df2Stakemura  * Copyright (c) 1999 Shin Takemura All rights reserved.
562009df2Stakemura  * Copyright (c) 1999 PocketBSD Project. All rights reserved.
662009df2Stakemura  *
762009df2Stakemura  * Redistribution and use in source and binary forms, with or without
862009df2Stakemura  * modification, are permitted provided that the following conditions
962009df2Stakemura  * are met:
1062009df2Stakemura  * 1. Redistributions of source code must retain the above copyright
1162009df2Stakemura  *    notice, this list of conditions and the following disclaimer.
1262009df2Stakemura  * 2. Redistributions in binary form must reproduce the above copyright
1362009df2Stakemura  *    notice, this list of conditions and the following disclaimer in the
1462009df2Stakemura  *    documentation and/or other materials provided with the distribution.
1562009df2Stakemura  *
1662009df2Stakemura  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1762009df2Stakemura  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1862009df2Stakemura  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1962009df2Stakemura  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2062009df2Stakemura  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2162009df2Stakemura  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2262009df2Stakemura  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2362009df2Stakemura  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2462009df2Stakemura  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2562009df2Stakemura  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2662009df2Stakemura  * SUCH DAMAGE.
2762009df2Stakemura  */
2862009df2Stakemura 
290c82163cSlukem #include <sys/cdefs.h>
30*20ca0a94Smatt __KERNEL_RCSID(0, "$NetBSD: vrdsu.c,v 1.12 2015/06/09 22:46:36 matt Exp $");
310c82163cSlukem 
3262009df2Stakemura #include <sys/param.h>
33*20ca0a94Smatt #include <sys/bus.h>
3462009df2Stakemura #include <sys/device.h>
35*20ca0a94Smatt #include <sys/systm.h>
3662009df2Stakemura 
37*20ca0a94Smatt #include <uvm/uvm_extern.h>
38*20ca0a94Smatt 
39*20ca0a94Smatt #include <mips/cpuregs.h>
4062009df2Stakemura 
41a0584b29Stakemura #include <hpcmips/vr/vripif.h>
4262009df2Stakemura #include <hpcmips/vr/dsureg.h>
4362009df2Stakemura #include <hpcmips/vr/vrdsuvar.h>
4462009df2Stakemura 
4562009df2Stakemura struct vrdsu_softc {
4662009df2Stakemura 	bus_space_tag_t sc_iot;
4762009df2Stakemura 	bus_space_handle_t sc_ioh;
4862009df2Stakemura };
4962009df2Stakemura 
50cbab9cadSchs static int vrdsumatch(device_t, cfdata_t, void *);
51cbab9cadSchs static void vrdsuattach(device_t, device_t, void *);
5262009df2Stakemura 
53961880b5Such static void vrdsu_write(struct vrdsu_softc *, int, unsigned short);
54961880b5Such static unsigned short vrdsu_read(struct vrdsu_softc *, int);
5562009df2Stakemura 
56cbab9cadSchs CFATTACH_DECL_NEW(vrdsu, sizeof(struct vrdsu_softc),
57c5e91d44Sthorpej     vrdsumatch, vrdsuattach, NULL, NULL);
5862009df2Stakemura 
5962009df2Stakemura struct vrdsu_softc *the_dsu_sc = NULL;
6062009df2Stakemura 
6162009df2Stakemura static inline void
vrdsu_write(struct vrdsu_softc * sc,int port,unsigned short val)62961880b5Such vrdsu_write(struct vrdsu_softc *sc, int port, unsigned short val)
6362009df2Stakemura {
64961880b5Such 
6562009df2Stakemura 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, port, val);
6662009df2Stakemura }
6762009df2Stakemura 
6862009df2Stakemura static inline unsigned short
vrdsu_read(struct vrdsu_softc * sc,int port)69961880b5Such vrdsu_read(struct vrdsu_softc *sc, int port)
7062009df2Stakemura {
71961880b5Such 
72961880b5Such 	return (bus_space_read_2(sc->sc_iot, sc->sc_ioh, port));
7362009df2Stakemura }
7462009df2Stakemura 
7562009df2Stakemura static int
vrdsumatch(device_t parent,cfdata_t cf,void * aux)76cbab9cadSchs vrdsumatch(device_t parent, cfdata_t cf, void *aux)
7762009df2Stakemura {
78961880b5Such 
79961880b5Such 	return (1);
8062009df2Stakemura }
8162009df2Stakemura 
8262009df2Stakemura static void
vrdsuattach(device_t parent,device_t self,void * aux)83cbab9cadSchs vrdsuattach(device_t parent, device_t self, void *aux)
8462009df2Stakemura {
85cbab9cadSchs 	struct vrdsu_softc *sc = device_private(self);
8662009df2Stakemura 	struct vrip_attach_args *va = aux;
8762009df2Stakemura 
8863a8704aSsato 	sc->sc_iot = va->va_iot;
8962009df2Stakemura 	if (bus_space_map(va->va_iot, va->va_addr, va->va_size,
9062009df2Stakemura 	    0, &sc->sc_ioh)) {
9162009df2Stakemura 		printf(": can't map bus space\n");
9262009df2Stakemura 		return;
9362009df2Stakemura 	}
9462009df2Stakemura 	printf("\n");
9562009df2Stakemura 	the_dsu_sc = sc;
9662009df2Stakemura }
9762009df2Stakemura 
9862009df2Stakemura void
vrdsu_reset(void)99df7f595eScegger vrdsu_reset(void)
10062009df2Stakemura {
101961880b5Such 
10262009df2Stakemura 	if (the_dsu_sc) {
10362009df2Stakemura 		splhigh();
10462009df2Stakemura 		vrdsu_write(the_dsu_sc, DSUSET_REG_W, 1); /* 1 sec */
10562009df2Stakemura 		vrdsu_write(the_dsu_sc, DSUCNT_REG_W, DSUCNT_DSWEN);
10679606e01Sshin 		/*
10779606e01Sshin 		 * wipe out all physical memory for clean WinCE boot.
10879606e01Sshin 		 */
10979606e01Sshin 		memset((void *)MIPS_PHYS_TO_KSEG1(0), 0, ptoa(physmem) - 0);
11062009df2Stakemura 		while (1);
11162009df2Stakemura 	} else {
11262009df2Stakemura 		printf("%s(%d): There is no DSU.", __FILE__, __LINE__);
11362009df2Stakemura 	}
11462009df2Stakemura }
115