cmu.c revision 1.13.122.1 1 1.13.122.1 tls /* $NetBSD: cmu.c,v 1.13.122.1 2012/11/20 03:01:24 tls Exp $ */
2 1.1 takemura
3 1.1 takemura /*-
4 1.1 takemura * Copyright (c) 1999 SASAKI Takesi
5 1.9 takemura * Copyright (c) 1999, 2000, 2002 PocketBSD Project. All rights reserved.
6 1.1 takemura * All rights reserved.
7 1.1 takemura *
8 1.1 takemura * Redistribution and use in source and binary forms, with or without
9 1.1 takemura * modification, are permitted provided that the following conditions
10 1.1 takemura * are met:
11 1.1 takemura * 1. Redistributions of source code must retain the above copyright
12 1.1 takemura * notice, this list of conditions and the following disclaimer.
13 1.1 takemura * 2. Redistributions in binary form must reproduce the above copyright
14 1.1 takemura * notice, this list of conditions and the following disclaimer in the
15 1.1 takemura * documentation and/or other materials provided with the distribution.
16 1.1 takemura * 3. All advertising materials mentioning features or use of this software
17 1.1 takemura * must display the following acknowledgement:
18 1.1 takemura * This product includes software developed by the PocketBSD project
19 1.1 takemura * and its contributors.
20 1.1 takemura * 4. Neither the name of the project nor the names of its contributors
21 1.1 takemura * may be used to endorse or promote products derived from this software
22 1.1 takemura * without specific prior written permission.
23 1.1 takemura *
24 1.1 takemura * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 1.1 takemura * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 1.1 takemura * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 1.1 takemura * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 1.1 takemura * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 1.1 takemura * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 1.1 takemura * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 1.1 takemura * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 1.1 takemura * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 1.1 takemura * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 1.1 takemura * SUCH DAMAGE.
35 1.1 takemura *
36 1.1 takemura */
37 1.12 lukem
38 1.12 lukem #include <sys/cdefs.h>
39 1.13.122.1 tls __KERNEL_RCSID(0, "$NetBSD: cmu.c,v 1.13.122.1 2012/11/20 03:01:24 tls Exp $");
40 1.4 enami
41 1.1 takemura #include <sys/param.h>
42 1.1 takemura #include <sys/systm.h>
43 1.1 takemura #include <sys/device.h>
44 1.1 takemura
45 1.1 takemura #include <mips/cpuregs.h>
46 1.1 takemura
47 1.1 takemura #include <machine/bus.h>
48 1.8 uch #include <machine/debug.h>
49 1.1 takemura
50 1.3 sato #include "opt_vr41xx.h"
51 1.1 takemura #include <hpcmips/vr/vr.h>
52 1.3 sato #include <hpcmips/vr/vrcpudef.h>
53 1.7 takemura #include <hpcmips/vr/vripif.h>
54 1.3 sato #include <hpcmips/vr/vripreg.h>
55 1.1 takemura
56 1.1 takemura #include <hpcmips/vr/cmureg.h>
57 1.1 takemura
58 1.2 sato #include <machine/config_hook.h>
59 1.2 sato
60 1.1 takemura struct vrcmu_softc {
61 1.1 takemura bus_space_tag_t sc_iot;
62 1.1 takemura bus_space_handle_t sc_ioh;
63 1.2 sato config_hook_tag sc_hardpower;
64 1.2 sato int sc_save;
65 1.7 takemura struct vrcmu_chipset_tag sc_chipset;
66 1.1 takemura };
67 1.1 takemura
68 1.13.122.1 tls int vrcmu_match(device_t, cfdata_t, void *);
69 1.13.122.1 tls void vrcmu_attach(device_t, device_t, void *);
70 1.5 uch int vrcmu_supply(vrcmu_chipset_tag_t, u_int16_t, int);
71 1.5 uch int vrcmu_hardpower(void *, int, long, void *);
72 1.1 takemura
73 1.13.122.1 tls CFATTACH_DECL_NEW(vrcmu, sizeof(struct vrcmu_softc),
74 1.11 thorpej vrcmu_match, vrcmu_attach, NULL, NULL);
75 1.1 takemura
76 1.1 takemura int
77 1.13.122.1 tls vrcmu_match(device_t parent, cfdata_t cf, void *aux)
78 1.1 takemura {
79 1.4 enami
80 1.4 enami return (2); /* 1st attach group of vrip */
81 1.1 takemura }
82 1.1 takemura
83 1.1 takemura void
84 1.13.122.1 tls vrcmu_attach(device_t parent, device_t self, void *aux)
85 1.1 takemura {
86 1.1 takemura struct vrip_attach_args *va = aux;
87 1.13.122.1 tls struct vrcmu_softc *sc = device_private(self);
88 1.4 enami
89 1.1 takemura sc->sc_iot = va->va_iot;
90 1.7 takemura sc->sc_chipset.cc_sc = sc;
91 1.7 takemura sc->sc_chipset.cc_clock = vrcmu_supply;
92 1.1 takemura if (bus_space_map(sc->sc_iot, va->va_addr, va->va_size,
93 1.4 enami 0 /* no flags */, &sc->sc_ioh)) {
94 1.4 enami printf(": can't map i/o space\n");
95 1.1 takemura return;
96 1.1 takemura }
97 1.4 enami printf ("\n");
98 1.4 enami
99 1.7 takemura vrip_register_cmu(va->va_vc, &sc->sc_chipset);
100 1.2 sato sc->sc_hardpower = config_hook(CONFIG_HOOK_PMEVENT,
101 1.4 enami CONFIG_HOOK_PMEVENT_HARDPOWER,
102 1.4 enami CONFIG_HOOK_SHARE,
103 1.4 enami vrcmu_hardpower, sc);
104 1.1 takemura }
105 1.1 takemura
106 1.1 takemura int
107 1.5 uch vrcmu_supply(vrcmu_chipset_tag_t cc, u_int16_t mask, int onoff)
108 1.1 takemura {
109 1.7 takemura struct vrcmu_softc *sc = cc->cc_sc;
110 1.1 takemura u_int16_t reg;
111 1.4 enami
112 1.1 takemura reg = bus_space_read_2(sc->sc_iot, sc->sc_ioh, 0);
113 1.1 takemura #ifdef VRCMU_VERBOSE
114 1.4 enami printf("cmu register(enter):");
115 1.8 uch dbg_bit_print(reg);
116 1.1 takemura #endif
117 1.1 takemura if (onoff)
118 1.1 takemura reg |= mask;
119 1.1 takemura else
120 1.1 takemura reg &= ~mask;
121 1.1 takemura bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0, reg);
122 1.1 takemura #ifdef VRCMU_VERBOSE
123 1.4 enami printf("cmu register(exit) :");
124 1.8 uch dbg_bit_print(reg);
125 1.1 takemura #endif
126 1.4 enami return (0);
127 1.1 takemura }
128 1.1 takemura
129 1.2 sato int
130 1.5 uch vrcmu_hardpower(void *ctx, int type, long id, void *msg)
131 1.2 sato {
132 1.2 sato struct vrcmu_softc *sc = ctx;
133 1.4 enami int why = (int)msg;
134 1.2 sato
135 1.2 sato switch (why) {
136 1.2 sato case PWR_STANDBY:
137 1.2 sato case PWR_SUSPEND:
138 1.2 sato sc->sc_save = bus_space_read_2(sc->sc_iot, sc->sc_ioh, 0);
139 1.2 sato bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0, 0);
140 1.2 sato break;
141 1.2 sato case PWR_RESUME:
142 1.2 sato bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0, sc->sc_save);
143 1.2 sato break;
144 1.2 sato }
145 1.2 sato return (0);
146 1.2 sato }
147