xref: /netbsd-src/sys/arch/hpcmips/vr/cmu.c (revision cbab9cadce21ae72fac13910001079fff214cc29)
1*cbab9cadSchs /*	$NetBSD: cmu.c,v 1.14 2012/10/27 17:17:55 chs Exp $	*/
2db2b0adeStakemura 
3db2b0adeStakemura /*-
4db2b0adeStakemura  * Copyright (c) 1999 SASAKI Takesi
56929f9f4Stakemura  * Copyright (c) 1999, 2000, 2002 PocketBSD Project. All rights reserved.
6db2b0adeStakemura  * All rights reserved.
7db2b0adeStakemura  *
8db2b0adeStakemura  * Redistribution and use in source and binary forms, with or without
9db2b0adeStakemura  * modification, are permitted provided that the following conditions
10db2b0adeStakemura  * are met:
11db2b0adeStakemura  * 1. Redistributions of source code must retain the above copyright
12db2b0adeStakemura  *    notice, this list of conditions and the following disclaimer.
13db2b0adeStakemura  * 2. Redistributions in binary form must reproduce the above copyright
14db2b0adeStakemura  *    notice, this list of conditions and the following disclaimer in the
15db2b0adeStakemura  *    documentation and/or other materials provided with the distribution.
16db2b0adeStakemura  * 3. All advertising materials mentioning features or use of this software
17db2b0adeStakemura  *    must display the following acknowledgement:
18db2b0adeStakemura  *	This product includes software developed by the PocketBSD project
19db2b0adeStakemura  *	and its contributors.
20db2b0adeStakemura  * 4. Neither the name of the project nor the names of its contributors
21db2b0adeStakemura  *    may be used to endorse or promote products derived from this software
22db2b0adeStakemura  *    without specific prior written permission.
23db2b0adeStakemura  *
24db2b0adeStakemura  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25db2b0adeStakemura  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26db2b0adeStakemura  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27db2b0adeStakemura  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28db2b0adeStakemura  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29db2b0adeStakemura  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30db2b0adeStakemura  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31db2b0adeStakemura  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32db2b0adeStakemura  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33db2b0adeStakemura  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34db2b0adeStakemura  * SUCH DAMAGE.
35db2b0adeStakemura  *
36db2b0adeStakemura  */
37f81775f0Senami 
380c82163cSlukem #include <sys/cdefs.h>
39*cbab9cadSchs __KERNEL_RCSID(0, "$NetBSD: cmu.c,v 1.14 2012/10/27 17:17:55 chs Exp $");
400c82163cSlukem 
41db2b0adeStakemura #include <sys/param.h>
42db2b0adeStakemura #include <sys/systm.h>
43db2b0adeStakemura #include <sys/device.h>
44db2b0adeStakemura 
45db2b0adeStakemura #include <mips/cpuregs.h>
46db2b0adeStakemura 
47db2b0adeStakemura #include <machine/bus.h>
487d170993Such #include <machine/debug.h>
49db2b0adeStakemura 
50d4262d1aSsato #include "opt_vr41xx.h"
51db2b0adeStakemura #include <hpcmips/vr/vr.h>
52d4262d1aSsato #include <hpcmips/vr/vrcpudef.h>
53a0584b29Stakemura #include <hpcmips/vr/vripif.h>
54d4262d1aSsato #include <hpcmips/vr/vripreg.h>
55db2b0adeStakemura 
56db2b0adeStakemura #include <hpcmips/vr/cmureg.h>
57db2b0adeStakemura 
589a5210c7Ssato #include <machine/config_hook.h>
599a5210c7Ssato 
60db2b0adeStakemura struct vrcmu_softc {
61db2b0adeStakemura 	bus_space_tag_t sc_iot;
62db2b0adeStakemura 	bus_space_handle_t sc_ioh;
639a5210c7Ssato 	config_hook_tag sc_hardpower;
649a5210c7Ssato 	int sc_save;
65a0584b29Stakemura 	struct vrcmu_chipset_tag sc_chipset;
66db2b0adeStakemura };
67db2b0adeStakemura 
68*cbab9cadSchs int	vrcmu_match(device_t, cfdata_t, void *);
69*cbab9cadSchs void	vrcmu_attach(device_t, device_t, void *);
70961880b5Such int	vrcmu_supply(vrcmu_chipset_tag_t, u_int16_t, int);
71961880b5Such int	vrcmu_hardpower(void *, int, long, void *);
729a5210c7Ssato 
73*cbab9cadSchs CFATTACH_DECL_NEW(vrcmu, sizeof(struct vrcmu_softc),
74c5e91d44Sthorpej     vrcmu_match, vrcmu_attach, NULL, NULL);
75db2b0adeStakemura 
76db2b0adeStakemura int
vrcmu_match(device_t parent,cfdata_t cf,void * aux)77*cbab9cadSchs vrcmu_match(device_t parent, cfdata_t cf, void *aux)
78db2b0adeStakemura {
79f81775f0Senami 
80f81775f0Senami 	return (2);		/* 1st attach group of vrip */
81db2b0adeStakemura }
82db2b0adeStakemura 
83db2b0adeStakemura void
vrcmu_attach(device_t parent,device_t self,void * aux)84*cbab9cadSchs vrcmu_attach(device_t parent, device_t self, void *aux)
85db2b0adeStakemura {
86db2b0adeStakemura 	struct vrip_attach_args *va = aux;
87*cbab9cadSchs 	struct vrcmu_softc *sc = device_private(self);
88db2b0adeStakemura 
89db2b0adeStakemura 	sc->sc_iot = va->va_iot;
90a0584b29Stakemura 	sc->sc_chipset.cc_sc = sc;
91a0584b29Stakemura 	sc->sc_chipset.cc_clock = vrcmu_supply;
92db2b0adeStakemura 	if (bus_space_map(sc->sc_iot, va->va_addr, va->va_size,
93db2b0adeStakemura 	    0 /* no flags */, &sc->sc_ioh)) {
94f81775f0Senami 		printf(": can't map i/o space\n");
95db2b0adeStakemura 		return;
96db2b0adeStakemura 	}
97db2b0adeStakemura 	printf ("\n");
98f81775f0Senami 
99a0584b29Stakemura 	vrip_register_cmu(va->va_vc, &sc->sc_chipset);
1009a5210c7Ssato 	sc->sc_hardpower = config_hook(CONFIG_HOOK_PMEVENT,
1019a5210c7Ssato 	    CONFIG_HOOK_PMEVENT_HARDPOWER,
1029a5210c7Ssato 	    CONFIG_HOOK_SHARE,
1039a5210c7Ssato 	    vrcmu_hardpower, sc);
1049a5210c7Ssato }
105f81775f0Senami 
106db2b0adeStakemura int
vrcmu_supply(vrcmu_chipset_tag_t cc,u_int16_t mask,int onoff)107961880b5Such vrcmu_supply(vrcmu_chipset_tag_t cc, u_int16_t mask, int onoff)
108db2b0adeStakemura {
109a0584b29Stakemura 	struct vrcmu_softc *sc = cc->cc_sc;
110db2b0adeStakemura 	u_int16_t reg;
111db2b0adeStakemura 
112db2b0adeStakemura 	reg = bus_space_read_2(sc->sc_iot, sc->sc_ioh, 0);
113db2b0adeStakemura #ifdef VRCMU_VERBOSE
114db2b0adeStakemura 	printf("cmu register(enter):");
1157d170993Such 	dbg_bit_print(reg);
116db2b0adeStakemura #endif
117db2b0adeStakemura 	if (onoff)
118db2b0adeStakemura 		reg |= mask;
119db2b0adeStakemura 	else
120db2b0adeStakemura 		reg &= ~mask;
121db2b0adeStakemura 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0, reg);
122db2b0adeStakemura #ifdef VRCMU_VERBOSE
123db2b0adeStakemura 	printf("cmu register(exit) :");
1247d170993Such 	dbg_bit_print(reg);
125db2b0adeStakemura #endif
126f81775f0Senami 	return (0);
127db2b0adeStakemura }
128db2b0adeStakemura 
1299a5210c7Ssato int
vrcmu_hardpower(void * ctx,int type,long id,void * msg)130961880b5Such vrcmu_hardpower(void *ctx, int type, long id, void *msg)
1319a5210c7Ssato {
1329a5210c7Ssato 	struct vrcmu_softc *sc = ctx;
1339a5210c7Ssato 	int why = (int)msg;
1349a5210c7Ssato 
1359a5210c7Ssato 	switch (why) {
1369a5210c7Ssato 	case PWR_STANDBY:
1379a5210c7Ssato 	case PWR_SUSPEND:
1389a5210c7Ssato 		sc->sc_save = bus_space_read_2(sc->sc_iot, sc->sc_ioh, 0);
1399a5210c7Ssato 		bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0, 0);
1409a5210c7Ssato 		break;
1419a5210c7Ssato 	case PWR_RESUME:
1429a5210c7Ssato 		bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0, sc->sc_save);
1439a5210c7Ssato 		break;
1449a5210c7Ssato 	}
1459a5210c7Ssato 	return (0);
1469a5210c7Ssato }
147