plumpower.c revision 1.2 1 1.2 uch /* $NetBSD: plumpower.c,v 1.2 1999/12/07 17:21:45 uch Exp $ */
2 1.1 uch
3 1.1 uch /*
4 1.1 uch * Copyright (c) 1999, by UCHIYAMA Yasushi
5 1.1 uch * All rights reserved.
6 1.1 uch *
7 1.1 uch * Redistribution and use in source and binary forms, with or without
8 1.1 uch * modification, are permitted provided that the following conditions
9 1.1 uch * are met:
10 1.1 uch * 1. Redistributions of source code must retain the above copyright
11 1.1 uch * notice, this list of conditions and the following disclaimer.
12 1.1 uch * 2. The name of the developer may NOT be used to endorse or promote products
13 1.1 uch * derived from this software without specific prior written permission.
14 1.1 uch *
15 1.1 uch * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 1.1 uch * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 1.1 uch * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 1.1 uch * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 1.1 uch * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 1.1 uch * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 1.1 uch * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 1.1 uch * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 1.1 uch * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 1.1 uch * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 1.1 uch * SUCH DAMAGE.
26 1.1 uch *
27 1.1 uch */
28 1.1 uch
29 1.1 uch #include "opt_tx39_debug.h"
30 1.1 uch
31 1.1 uch #include <sys/param.h>
32 1.1 uch #include <sys/systm.h>
33 1.1 uch #include <sys/device.h>
34 1.1 uch #include <sys/malloc.h>
35 1.1 uch
36 1.1 uch #include <machine/bus.h>
37 1.1 uch #include <machine/intr.h>
38 1.1 uch
39 1.1 uch #include <hpcmips/tx/tx39var.h>
40 1.1 uch #include <hpcmips/dev/plumvar.h>
41 1.1 uch #include <hpcmips/dev/plumpowervar.h>
42 1.1 uch #include <hpcmips/dev/plumpowerreg.h>
43 1.1 uch
44 1.1 uch int plumpower_match __P((struct device*, struct cfdata*, void*));
45 1.1 uch void plumpower_attach __P((struct device*, struct device*, void*));
46 1.1 uch
47 1.1 uch struct plumpower_softc {
48 1.1 uch struct device sc_dev;
49 1.1 uch plum_chipset_tag_t sc_pc;
50 1.1 uch bus_space_tag_t sc_regt;
51 1.1 uch bus_space_handle_t sc_regh;
52 1.1 uch };
53 1.1 uch
54 1.1 uch struct cfattach plumpower_ca = {
55 1.1 uch sizeof(struct plumpower_softc), plumpower_match, plumpower_attach
56 1.1 uch };
57 1.1 uch
58 1.1 uch void plumpower_dump __P((struct plumpower_softc*));
59 1.1 uch
60 1.1 uch int
61 1.1 uch plumpower_match(parent, cf, aux)
62 1.1 uch struct device *parent;
63 1.1 uch struct cfdata *cf;
64 1.1 uch void *aux;
65 1.1 uch {
66 1.1 uch return 2; /* 1st attach group */
67 1.1 uch }
68 1.1 uch
69 1.1 uch void
70 1.1 uch plumpower_attach(parent, self, aux)
71 1.1 uch struct device *parent;
72 1.1 uch struct device *self;
73 1.1 uch void *aux;
74 1.1 uch {
75 1.1 uch struct plum_attach_args *pa = aux;
76 1.1 uch struct plumpower_softc *sc = (void*)self;
77 1.1 uch
78 1.1 uch printf("\n");
79 1.1 uch sc->sc_pc = pa->pa_pc;
80 1.1 uch sc->sc_regt = pa->pa_regt;
81 1.1 uch
82 1.1 uch if (bus_space_map(sc->sc_regt, PLUM_POWER_REGBASE,
83 1.1 uch PLUM_POWER_REGSIZE, 0, &sc->sc_regh)) {
84 1.1 uch printf(": register map failed\n");
85 1.1 uch return;
86 1.1 uch }
87 1.1 uch plum_conf_register_power(sc->sc_pc, (void*)sc);
88 1.1 uch
89 1.1 uch plumpower_dump(sc);
90 1.1 uch
91 1.2 uch /* disable all power/clock */
92 1.2 uch plum_conf_write(sc->sc_regt, sc->sc_regh,
93 1.2 uch PLUM_POWER_PWRCONT_REG, 0);
94 1.2 uch plum_conf_write(sc->sc_regt, sc->sc_regh,
95 1.2 uch PLUM_POWER_CLKCONT_REG, 0);
96 1.2 uch delay(300 * 1000);
97 1.2 uch
98 1.2 uch /* enable MCS interface from TX3922 */
99 1.1 uch plum_conf_write(sc->sc_regt, sc->sc_regh, PLUM_POWER_INPENA_REG,
100 1.1 uch PLUM_POWER_INPENA);
101 1.2 uch plumpower_dump(sc);
102 1.1 uch }
103 1.1 uch
104 1.1 uch void
105 1.1 uch plum_power_ioreset(pc)
106 1.1 uch plum_chipset_tag_t pc;
107 1.1 uch {
108 1.1 uch struct plumpower_softc *sc = pc->pc_powert;
109 1.1 uch bus_space_tag_t regt = sc->sc_regt;
110 1.1 uch bus_space_handle_t regh = sc->sc_regh;
111 1.1 uch
112 1.1 uch plum_conf_write(regt, regh, PLUM_POWER_RESETC_REG,
113 1.1 uch PLUM_POWER_RESETC_IO5CL1 |
114 1.1 uch PLUM_POWER_RESETC_IO5CL1);
115 1.1 uch delay(100*1000);
116 1.1 uch plum_conf_write(regt, regh, PLUM_POWER_RESETC_REG, 0);
117 1.1 uch delay(100*1000);
118 1.1 uch }
119 1.1 uch
120 1.1 uch void*
121 1.1 uch plum_power_establish(pc, src)
122 1.1 uch plum_chipset_tag_t pc;
123 1.1 uch int src;
124 1.1 uch {
125 1.1 uch struct plumpower_softc *sc = pc->pc_powert;
126 1.1 uch bus_space_tag_t regt = sc->sc_regt;
127 1.1 uch bus_space_handle_t regh = sc->sc_regh;
128 1.1 uch plumreg_t pwrreg, clkreg;
129 1.1 uch
130 1.1 uch pwrreg = plum_conf_read(regt, regh, PLUM_POWER_PWRCONT_REG);
131 1.1 uch clkreg = plum_conf_read(regt, regh, PLUM_POWER_CLKCONT_REG);
132 1.1 uch
133 1.1 uch switch(src) {
134 1.1 uch default:
135 1.1 uch panic("plum_power_establish: unknown power source");
136 1.1 uch case PLUM_PWR_LCD:
137 1.2 uch pwrreg |= PLUM_POWER_PWRCONT_LCDPWR;
138 1.2 uch plum_conf_write(regt, regh, PLUM_POWER_PWRCONT_REG, pwrreg);
139 1.2 uch pwrreg |= PLUM_POWER_PWRCONT_LCDDSP;
140 1.2 uch plum_conf_write(regt, regh, PLUM_POWER_PWRCONT_REG, pwrreg);
141 1.2 uch pwrreg |= PLUM_POWER_PWRCONT_LCDOE;
142 1.2 uch plum_conf_write(regt, regh, PLUM_POWER_PWRCONT_REG, pwrreg);
143 1.1 uch break;
144 1.1 uch case PLUM_PWR_BKL:
145 1.1 uch pwrreg |= PLUM_POWER_PWRCONT_BKLIGHT;
146 1.1 uch break;
147 1.1 uch case PLUM_PWR_IO5:
148 1.2 uch /* reset I/O bus (High/Low) */
149 1.2 uch plum_power_ioreset(pc);
150 1.2 uch
151 1.2 uch /* supply power */
152 1.2 uch pwrreg |= PLUM_POWER_PWRCONT_IO5PWR;
153 1.2 uch plum_conf_write(regt, regh, PLUM_POWER_PWRCONT_REG, pwrreg);
154 1.2 uch delay(300*1000);
155 1.2 uch
156 1.2 uch /* output enable & supply clock */
157 1.2 uch pwrreg |= PLUM_POWER_PWRCONT_IO5OE;
158 1.1 uch clkreg |= PLUM_POWER_CLKCONT_IO5CLK;
159 1.1 uch break;
160 1.1 uch case PLUM_PWR_EXTPW0:
161 1.1 uch pwrreg |= PLUM_POWER_PWRCONT_EXTPW0;
162 1.1 uch break;
163 1.1 uch case PLUM_PWR_EXTPW1:
164 1.1 uch pwrreg |= PLUM_POWER_PWRCONT_EXTPW1;
165 1.1 uch break;
166 1.1 uch case PLUM_PWR_EXTPW2:
167 1.1 uch pwrreg |= PLUM_POWER_PWRCONT_EXTPW2;
168 1.1 uch break;
169 1.1 uch case PLUM_PWR_USB:
170 1.2 uch /* output enable */
171 1.1 uch pwrreg |= PLUM_POWER_PWRCONT_USBEN;
172 1.2 uch /* supply clock to the USB host controller */
173 1.2 uch clkreg |= PLUM_POWER_CLKCONT_USBCLK1;
174 1.2 uch /* clock supply is adaptively controlled by hardware */
175 1.2 uch clkreg &= ~PLUM_POWER_CLKCONT_USBCLK2;
176 1.1 uch break;
177 1.1 uch case PLUM_PWR_SM:
178 1.1 uch clkreg |= PLUM_POWER_CLKCONT_SMCLK;
179 1.1 uch break;
180 1.1 uch case PLUM_PWR_PCC1:
181 1.1 uch clkreg |= PLUM_POWER_CLKCONT_PCCCLK1;
182 1.1 uch break;
183 1.1 uch case PLUM_PWR_PCC2:
184 1.1 uch clkreg |= PLUM_POWER_CLKCONT_PCCCLK2;
185 1.1 uch break;
186 1.1 uch }
187 1.1 uch
188 1.1 uch plum_conf_write(regt, regh, PLUM_POWER_PWRCONT_REG, pwrreg);
189 1.2 uch delay(300*1000);
190 1.2 uch
191 1.1 uch plum_conf_write(regt, regh, PLUM_POWER_CLKCONT_REG, clkreg);
192 1.2 uch delay(300*1000);
193 1.2 uch
194 1.2 uch plumpower_dump(sc);
195 1.1 uch
196 1.1 uch return (void*)src;
197 1.1 uch }
198 1.1 uch
199 1.1 uch void
200 1.1 uch plum_power_disestablish(pc, ph)
201 1.1 uch plum_chipset_tag_t pc;
202 1.1 uch int ph;
203 1.1 uch {
204 1.1 uch struct plumpower_softc *sc = pc->pc_powert;
205 1.1 uch bus_space_tag_t regt = sc->sc_regt;
206 1.1 uch bus_space_handle_t regh = sc->sc_regh;
207 1.1 uch int src = (int)ph;
208 1.1 uch plumreg_t pwrreg, clkreg;
209 1.1 uch
210 1.1 uch pwrreg = plum_conf_read(regt, regh, PLUM_POWER_PWRCONT_REG);
211 1.1 uch clkreg = plum_conf_read(regt, regh, PLUM_POWER_CLKCONT_REG);
212 1.1 uch
213 1.1 uch switch(src) {
214 1.1 uch default:
215 1.1 uch panic("plum_power_disestablish: unknown power source");
216 1.1 uch case PLUM_PWR_LCD:
217 1.1 uch pwrreg &= ~(PLUM_POWER_PWRCONT_LCDOE |
218 1.2 uch PLUM_POWER_PWRCONT_LCDPWR |
219 1.2 uch PLUM_POWER_PWRCONT_LCDDSP);
220 1.1 uch break;
221 1.1 uch case PLUM_PWR_BKL:
222 1.1 uch pwrreg &= ~PLUM_POWER_PWRCONT_BKLIGHT;
223 1.1 uch break;
224 1.1 uch case PLUM_PWR_IO5:
225 1.1 uch pwrreg &= ~(PLUM_POWER_PWRCONT_IO5PWR |
226 1.1 uch PLUM_POWER_PWRCONT_IO5OE);
227 1.1 uch clkreg &= ~PLUM_POWER_CLKCONT_IO5CLK;
228 1.1 uch break;
229 1.1 uch case PLUM_PWR_EXTPW0:
230 1.1 uch pwrreg &= ~PLUM_POWER_PWRCONT_EXTPW0;
231 1.1 uch break;
232 1.1 uch case PLUM_PWR_EXTPW1:
233 1.1 uch pwrreg &= ~PLUM_POWER_PWRCONT_EXTPW1;
234 1.1 uch break;
235 1.1 uch case PLUM_PWR_EXTPW2:
236 1.1 uch pwrreg &= ~PLUM_POWER_PWRCONT_EXTPW2;
237 1.1 uch break;
238 1.1 uch case PLUM_PWR_USB:
239 1.1 uch pwrreg &= ~PLUM_POWER_PWRCONT_USBEN;
240 1.1 uch clkreg &= ~(PLUM_POWER_CLKCONT_USBCLK1 |
241 1.1 uch PLUM_POWER_CLKCONT_USBCLK2);
242 1.1 uch break;
243 1.1 uch case PLUM_PWR_SM:
244 1.1 uch clkreg &= ~PLUM_POWER_CLKCONT_SMCLK;
245 1.1 uch break;
246 1.1 uch case PLUM_PWR_PCC1:
247 1.1 uch clkreg &= ~PLUM_POWER_CLKCONT_PCCCLK1;
248 1.1 uch break;
249 1.1 uch case PLUM_PWR_PCC2:
250 1.1 uch clkreg &= ~PLUM_POWER_CLKCONT_PCCCLK2;
251 1.1 uch break;
252 1.1 uch }
253 1.1 uch
254 1.1 uch plum_conf_write(regt, regh, PLUM_POWER_PWRCONT_REG, pwrreg);
255 1.1 uch plum_conf_write(regt, regh, PLUM_POWER_CLKCONT_REG, clkreg);
256 1.1 uch
257 1.2 uch plumpower_dump(sc);
258 1.1 uch }
259 1.1 uch
260 1.1 uch #define ISPOWERSUPPLY(r, m) __is_set_print(r, PLUM_POWER_PWRCONT_##m, #m)
261 1.1 uch #define ISCLOCKSUPPLY(r, m) __is_set_print(r, PLUM_POWER_CLKCONT_##m, #m)
262 1.1 uch
263 1.1 uch void
264 1.1 uch plumpower_dump(sc)
265 1.1 uch struct plumpower_softc *sc;
266 1.1 uch {
267 1.1 uch bus_space_tag_t regt = sc->sc_regt;
268 1.1 uch bus_space_handle_t regh = sc->sc_regh;
269 1.1 uch plumreg_t reg;
270 1.1 uch
271 1.1 uch reg = plum_conf_read(regt, regh, PLUM_POWER_PWRCONT_REG);
272 1.1 uch printf(" power:");
273 1.1 uch ISPOWERSUPPLY(reg, USBEN);
274 1.1 uch ISPOWERSUPPLY(reg, IO5OE);
275 1.1 uch ISPOWERSUPPLY(reg, LCDOE);
276 1.1 uch ISPOWERSUPPLY(reg, EXTPW2);
277 1.1 uch ISPOWERSUPPLY(reg, EXTPW1);
278 1.1 uch ISPOWERSUPPLY(reg, EXTPW0);
279 1.1 uch ISPOWERSUPPLY(reg, IO5PWR);
280 1.1 uch ISPOWERSUPPLY(reg, BKLIGHT);
281 1.1 uch ISPOWERSUPPLY(reg, LCDPWR);
282 1.1 uch ISPOWERSUPPLY(reg, LCDDSP);
283 1.1 uch reg = plum_conf_read(regt, regh, PLUM_POWER_CLKCONT_REG);
284 1.1 uch printf("\n clock:");
285 1.1 uch ISCLOCKSUPPLY(reg, USBCLK2);
286 1.1 uch ISCLOCKSUPPLY(reg, USBCLK1);
287 1.1 uch ISCLOCKSUPPLY(reg, IO5CLK);
288 1.1 uch ISCLOCKSUPPLY(reg, SMCLK);
289 1.1 uch ISCLOCKSUPPLY(reg, PCCCLK2);
290 1.1 uch ISCLOCKSUPPLY(reg, PCCCLK1);
291 1.1 uch reg = plum_conf_read(regt, regh, PLUM_POWER_INPENA_REG);
292 1.1 uch printf("\n MCS interface %sebled",
293 1.1 uch reg & PLUM_POWER_INPENA ? "en" : "dis");
294 1.1 uch reg = plum_conf_read(regt, regh, PLUM_POWER_RESETC_REG);
295 1.1 uch printf("\n IO5 reset:%s %s",
296 1.1 uch reg & PLUM_POWER_RESETC_IO5CL0 ? "CLRL" : "",
297 1.1 uch reg & PLUM_POWER_RESETC_IO5CL1 ? "CLRH" : "");
298 1.1 uch printf("\n");
299 1.1 uch }
300 1.1 uch
301 1.1 uch
302