obio.c revision 1.31 1 1.31 phx /* $NetBSD: obio.c,v 1.31 2010/12/05 13:33:50 phx Exp $ */
2 1.2 tsubai
3 1.2 tsubai /*-
4 1.2 tsubai * Copyright (C) 1998 Internet Research Institute, Inc.
5 1.2 tsubai * All rights reserved.
6 1.2 tsubai *
7 1.2 tsubai * Redistribution and use in source and binary forms, with or without
8 1.2 tsubai * modification, are permitted provided that the following conditions
9 1.2 tsubai * are met:
10 1.2 tsubai * 1. Redistributions of source code must retain the above copyright
11 1.2 tsubai * notice, this list of conditions and the following disclaimer.
12 1.2 tsubai * 2. Redistributions in binary form must reproduce the above copyright
13 1.2 tsubai * notice, this list of conditions and the following disclaimer in the
14 1.2 tsubai * documentation and/or other materials provided with the distribution.
15 1.2 tsubai * 3. All advertising materials mentioning features or use of this software
16 1.2 tsubai * must display the following acknowledgement:
17 1.2 tsubai * This product includes software developed by
18 1.2 tsubai * Internet Research Institute, Inc.
19 1.2 tsubai * 4. The name of the author may not be used to endorse or promote products
20 1.2 tsubai * derived from this software without specific prior written permission.
21 1.2 tsubai *
22 1.2 tsubai * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 1.2 tsubai * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 1.2 tsubai * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 1.2 tsubai * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 1.2 tsubai * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 1.2 tsubai * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 1.2 tsubai * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 1.2 tsubai * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 1.2 tsubai * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 1.2 tsubai * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 1.2 tsubai */
33 1.19 lukem
34 1.19 lukem #include <sys/cdefs.h>
35 1.31 phx __KERNEL_RCSID(0, "$NetBSD: obio.c,v 1.31 2010/12/05 13:33:50 phx Exp $");
36 1.2 tsubai
37 1.1 tsubai #include <sys/param.h>
38 1.1 tsubai #include <sys/systm.h>
39 1.1 tsubai #include <sys/kernel.h>
40 1.1 tsubai #include <sys/device.h>
41 1.27 garbled #include <sys/sysctl.h>
42 1.1 tsubai
43 1.1 tsubai #include <dev/pci/pcivar.h>
44 1.1 tsubai #include <dev/pci/pcidevs.h>
45 1.1 tsubai
46 1.1 tsubai #include <dev/ofw/openfirm.h>
47 1.1 tsubai
48 1.1 tsubai #include <machine/autoconf.h>
49 1.1 tsubai
50 1.28 macallan #include <macppc/dev/obiovar.h>
51 1.28 macallan
52 1.30 phx #include <powerpc/cpu.h>
53 1.30 phx
54 1.27 garbled #include "opt_obio.h"
55 1.27 garbled
56 1.27 garbled #ifdef OBIO_DEBUG
57 1.27 garbled # define DPRINTF printf
58 1.27 garbled #else
59 1.27 garbled # define DPRINTF while (0) printf
60 1.27 garbled #endif
61 1.27 garbled
62 1.27 garbled static void obio_attach(struct device *, struct device *, void *);
63 1.27 garbled static int obio_match(struct device *, struct cfdata *, void *);
64 1.27 garbled static int obio_print(void *, const char *);
65 1.1 tsubai
66 1.1 tsubai struct obio_softc {
67 1.1 tsubai struct device sc_dev;
68 1.27 garbled bus_space_tag_t sc_tag;
69 1.27 garbled bus_space_handle_t sc_bh;
70 1.1 tsubai int sc_node;
71 1.27 garbled #ifdef OBIO_SPEED_CONTROL
72 1.27 garbled int sc_voltage;
73 1.27 garbled int sc_busspeed;
74 1.27 garbled #endif
75 1.1 tsubai };
76 1.1 tsubai
77 1.28 macallan static struct obio_softc *obio0 = NULL;
78 1.28 macallan
79 1.27 garbled #ifdef OBIO_SPEED_CONTROL
80 1.27 garbled static void obio_setup_gpios(struct obio_softc *, int);
81 1.27 garbled static void obio_set_cpu_speed(struct obio_softc *, int);
82 1.27 garbled static int obio_get_cpu_speed(struct obio_softc *);
83 1.27 garbled static int sysctl_cpuspeed_temp(SYSCTLFN_ARGS);
84 1.27 garbled
85 1.27 garbled static const char *keylargo[] = {"Keylargo",
86 1.27 garbled "AAPL,Keylargo",
87 1.27 garbled NULL};
88 1.27 garbled
89 1.27 garbled #endif
90 1.1 tsubai
91 1.16 thorpej CFATTACH_DECL(obio, sizeof(struct obio_softc),
92 1.16 thorpej obio_match, obio_attach, NULL, NULL);
93 1.1 tsubai
94 1.1 tsubai int
95 1.27 garbled obio_match(struct device *parent, struct cfdata *cf, void *aux)
96 1.1 tsubai {
97 1.1 tsubai struct pci_attach_args *pa = aux;
98 1.1 tsubai
99 1.2 tsubai if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_APPLE)
100 1.2 tsubai switch (PCI_PRODUCT(pa->pa_id)) {
101 1.7 tsubai case PCI_PRODUCT_APPLE_GC:
102 1.7 tsubai case PCI_PRODUCT_APPLE_OHARE:
103 1.7 tsubai case PCI_PRODUCT_APPLE_HEATHROW:
104 1.7 tsubai case PCI_PRODUCT_APPLE_PADDINGTON:
105 1.7 tsubai case PCI_PRODUCT_APPLE_KEYLARGO:
106 1.14 tsubai case PCI_PRODUCT_APPLE_PANGEA_MACIO:
107 1.18 hamajima case PCI_PRODUCT_APPLE_INTREPID:
108 1.24 sanjayl case PCI_PRODUCT_APPLE_K2:
109 1.2 tsubai return 1;
110 1.2 tsubai }
111 1.1 tsubai
112 1.1 tsubai return 0;
113 1.1 tsubai }
114 1.1 tsubai
115 1.1 tsubai /*
116 1.1 tsubai * Attach all the sub-devices we can find
117 1.1 tsubai */
118 1.1 tsubai void
119 1.27 garbled obio_attach(struct device *parent, struct device *self, void *aux)
120 1.1 tsubai {
121 1.1 tsubai struct obio_softc *sc = (struct obio_softc *)self;
122 1.2 tsubai struct pci_attach_args *pa = aux;
123 1.1 tsubai struct confargs ca;
124 1.27 garbled bus_space_handle_t bsh;
125 1.27 garbled int node, child, namelen, error;
126 1.1 tsubai u_int reg[20];
127 1.21 briggs int intr[6], parent_intr = 0, parent_nintr = 0;
128 1.1 tsubai char name[32];
129 1.21 briggs char compat[32];
130 1.1 tsubai
131 1.27 garbled #ifdef OBIO_SPEED_CONTROL
132 1.27 garbled sc->sc_voltage = -1;
133 1.27 garbled sc->sc_busspeed = -1;
134 1.27 garbled #endif
135 1.27 garbled
136 1.2 tsubai switch (PCI_PRODUCT(pa->pa_id)) {
137 1.2 tsubai
138 1.7 tsubai case PCI_PRODUCT_APPLE_GC:
139 1.7 tsubai case PCI_PRODUCT_APPLE_OHARE:
140 1.7 tsubai case PCI_PRODUCT_APPLE_HEATHROW:
141 1.7 tsubai case PCI_PRODUCT_APPLE_PADDINGTON:
142 1.7 tsubai case PCI_PRODUCT_APPLE_KEYLARGO:
143 1.14 tsubai case PCI_PRODUCT_APPLE_PANGEA_MACIO:
144 1.18 hamajima case PCI_PRODUCT_APPLE_INTREPID:
145 1.21 briggs node = pcidev_to_ofdev(pa->pa_pc, pa->pa_tag);
146 1.6 tsubai if (node == -1)
147 1.21 briggs node = OF_finddevice("mac-io");
148 1.21 briggs if (node == -1)
149 1.21 briggs node = OF_finddevice("/pci/mac-io");
150 1.2 tsubai break;
151 1.24 sanjayl case PCI_PRODUCT_APPLE_K2:
152 1.24 sanjayl node = OF_finddevice("mac-io");
153 1.24 sanjayl break;
154 1.2 tsubai
155 1.2 tsubai default:
156 1.27 garbled node = -1;
157 1.27 garbled break;
158 1.2 tsubai }
159 1.27 garbled if (node == -1)
160 1.27 garbled panic("macio not found or unknown");
161 1.2 tsubai
162 1.1 tsubai sc->sc_node = node;
163 1.1 tsubai
164 1.24 sanjayl #if defined (PMAC_G5)
165 1.24 sanjayl if (OF_getprop(node, "assigned-addresses", reg, sizeof(reg)) < 20)
166 1.24 sanjayl {
167 1.24 sanjayl return;
168 1.24 sanjayl }
169 1.24 sanjayl #else
170 1.1 tsubai if (OF_getprop(node, "assigned-addresses", reg, sizeof(reg)) < 12)
171 1.1 tsubai return;
172 1.24 sanjayl #endif /* PMAC_G5 */
173 1.24 sanjayl
174 1.28 macallan /*
175 1.28 macallan * XXX
176 1.28 macallan * This relies on the primary obio always attaching first which is
177 1.28 macallan * true on the PowerBook 3400c and similar machines but may or may
178 1.28 macallan * not work on others. We can't rely on the node name since Apple
179 1.28 macallan * didn't follow anything remotely resembling a consistent naming
180 1.28 macallan * scheme.
181 1.28 macallan */
182 1.28 macallan if (obio0 == NULL)
183 1.28 macallan obio0 = sc;
184 1.28 macallan
185 1.1 tsubai ca.ca_baseaddr = reg[2];
186 1.27 garbled ca.ca_tag = pa->pa_memt;
187 1.27 garbled sc->sc_tag = pa->pa_memt;
188 1.27 garbled error = bus_space_map (pa->pa_memt, ca.ca_baseaddr, 0x80, 0, &bsh);
189 1.27 garbled if (error)
190 1.27 garbled panic(": failed to map mac-io %#x", ca.ca_baseaddr);
191 1.27 garbled sc->sc_bh = bsh;
192 1.1 tsubai
193 1.1 tsubai printf(": addr 0x%x\n", ca.ca_baseaddr);
194 1.13 tsubai
195 1.20 briggs /* Enable internal modem (KeyLargo) */
196 1.20 briggs if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_APPLE_KEYLARGO) {
197 1.27 garbled aprint_normal("%s: enabling KeyLargo internal modem\n",
198 1.27 garbled self->dv_xname);
199 1.27 garbled bus_space_write_4(ca.ca_tag, bsh, 0x40,
200 1.27 garbled bus_space_read_4(ca.ca_tag, bsh, 0x40) & ~(1<<25));
201 1.20 briggs }
202 1.26 macallan
203 1.20 briggs /* Enable internal modem (Pangea) */
204 1.20 briggs if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_APPLE_PANGEA_MACIO) {
205 1.27 garbled /* set reset */
206 1.27 garbled bus_space_write_1(ca.ca_tag, bsh, 0x006a + 0x03, 0x04);
207 1.27 garbled /* power modem on */
208 1.27 garbled bus_space_write_1(ca.ca_tag, bsh, 0x006a + 0x02, 0x04);
209 1.27 garbled /* unset reset */
210 1.27 garbled bus_space_write_1(ca.ca_tag, bsh, 0x006a + 0x03, 0x05);
211 1.20 briggs }
212 1.20 briggs
213 1.21 briggs /* Gatwick and Paddington use same product ID */
214 1.21 briggs namelen = OF_getprop(node, "compatible", compat, sizeof(compat));
215 1.1 tsubai
216 1.21 briggs if (strcmp(compat, "gatwick") == 0) {
217 1.21 briggs parent_nintr = OF_getprop(node, "AAPL,interrupts", intr,
218 1.21 briggs sizeof(intr));
219 1.21 briggs parent_intr = intr[0];
220 1.21 briggs } else {
221 1.21 briggs /* Enable CD and microphone sound input. */
222 1.21 briggs if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_APPLE_PADDINGTON)
223 1.27 garbled bus_space_write_1(ca.ca_tag, bsh, 0x37, 0x03);
224 1.21 briggs }
225 1.27 garbled
226 1.1 tsubai for (child = OF_child(node); child; child = OF_peer(child)) {
227 1.1 tsubai namelen = OF_getprop(child, "name", name, sizeof(name));
228 1.1 tsubai if (namelen < 0)
229 1.1 tsubai continue;
230 1.1 tsubai if (namelen >= sizeof(name))
231 1.1 tsubai continue;
232 1.1 tsubai
233 1.27 garbled #ifdef OBIO_SPEED_CONTROL
234 1.27 garbled if (strcmp(name, "gpio") == 0) {
235 1.27 garbled
236 1.27 garbled obio_setup_gpios(sc, child);
237 1.27 garbled continue;
238 1.27 garbled }
239 1.27 garbled #endif
240 1.27 garbled
241 1.1 tsubai name[namelen] = 0;
242 1.1 tsubai ca.ca_name = name;
243 1.1 tsubai ca.ca_node = child;
244 1.25 macallan ca.ca_tag = pa->pa_memt;
245 1.26 macallan
246 1.21 briggs ca.ca_nreg = OF_getprop(child, "reg", reg, sizeof(reg));
247 1.26 macallan
248 1.21 briggs if (strcmp(compat, "gatwick") != 0) {
249 1.21 briggs ca.ca_nintr = OF_getprop(child, "AAPL,interrupts", intr,
250 1.5 tsubai sizeof(intr));
251 1.21 briggs if (ca.ca_nintr == -1)
252 1.21 briggs ca.ca_nintr = OF_getprop(child, "interrupts", intr,
253 1.21 briggs sizeof(intr));
254 1.21 briggs } else {
255 1.21 briggs intr[0] = parent_intr;
256 1.21 briggs ca.ca_nintr = parent_nintr;
257 1.21 briggs }
258 1.1 tsubai ca.ca_reg = reg;
259 1.1 tsubai ca.ca_intr = intr;
260 1.1 tsubai
261 1.1 tsubai config_found(self, &ca, obio_print);
262 1.1 tsubai }
263 1.1 tsubai }
264 1.1 tsubai
265 1.27 garbled static const char * const skiplist[] = {
266 1.8 tsubai "interrupt-controller",
267 1.8 tsubai "gpio",
268 1.8 tsubai "escc-legacy",
269 1.8 tsubai "timer",
270 1.9 tsubai "i2c",
271 1.24 sanjayl "power-mgt",
272 1.27 garbled "escc",
273 1.27 garbled "battery",
274 1.27 garbled "backlight"
275 1.24 sanjayl
276 1.8 tsubai };
277 1.8 tsubai
278 1.8 tsubai #define N_LIST (sizeof(skiplist) / sizeof(skiplist[0]))
279 1.8 tsubai
280 1.1 tsubai int
281 1.29 dsl obio_print(void *aux, const char *obio)
282 1.1 tsubai {
283 1.1 tsubai struct confargs *ca = aux;
284 1.8 tsubai int i;
285 1.8 tsubai
286 1.8 tsubai for (i = 0; i < N_LIST; i++)
287 1.8 tsubai if (strcmp(ca->ca_name, skiplist[i]) == 0)
288 1.8 tsubai return QUIET;
289 1.1 tsubai
290 1.1 tsubai if (obio)
291 1.17 thorpej aprint_normal("%s at %s", ca->ca_name, obio);
292 1.1 tsubai
293 1.1 tsubai if (ca->ca_nreg > 0)
294 1.17 thorpej aprint_normal(" offset 0x%x", ca->ca_reg[0]);
295 1.1 tsubai
296 1.1 tsubai return UNCONF;
297 1.1 tsubai }
298 1.27 garbled
299 1.28 macallan void obio_write_4(int offset, uint32_t value)
300 1.28 macallan {
301 1.28 macallan if (obio0 == NULL)
302 1.28 macallan return;
303 1.28 macallan bus_space_write_4(obio0->sc_tag, obio0->sc_bh, offset, value);
304 1.28 macallan }
305 1.28 macallan
306 1.28 macallan void obio_write_1(int offset, uint8_t value)
307 1.28 macallan {
308 1.28 macallan if (obio0 == NULL)
309 1.28 macallan return;
310 1.28 macallan bus_space_write_1(obio0->sc_tag, obio0->sc_bh, offset, value);
311 1.28 macallan }
312 1.28 macallan
313 1.28 macallan uint32_t obio_read_4(int offset)
314 1.28 macallan {
315 1.28 macallan if (obio0 == NULL)
316 1.28 macallan return 0xffffffff;
317 1.28 macallan return bus_space_read_4(obio0->sc_tag, obio0->sc_bh, offset);
318 1.28 macallan }
319 1.28 macallan
320 1.28 macallan uint8_t obio_read_1(int offset)
321 1.28 macallan {
322 1.28 macallan if (obio0 == NULL)
323 1.28 macallan return 0xff;
324 1.28 macallan return bus_space_read_1(obio0->sc_tag, obio0->sc_bh, offset);
325 1.28 macallan }
326 1.28 macallan
327 1.27 garbled #ifdef OBIO_SPEED_CONTROL
328 1.27 garbled
329 1.27 garbled static void
330 1.27 garbled obio_setup_gpios(struct obio_softc *sc, int node)
331 1.27 garbled {
332 1.31 phx uint32_t gpio_base, reg[6];
333 1.30 phx struct sysctlnode *sysctl_node;
334 1.27 garbled char name[32];
335 1.31 phx int child, use_dfs;
336 1.27 garbled
337 1.27 garbled if (of_compatible(sc->sc_node, keylargo) == -1)
338 1.27 garbled return;
339 1.27 garbled
340 1.27 garbled if (OF_getprop(node, "reg", reg, sizeof(reg)) < 4)
341 1.27 garbled return;
342 1.27 garbled
343 1.27 garbled gpio_base = reg[0];
344 1.27 garbled DPRINTF("gpio_base: %02x\n", gpio_base);
345 1.27 garbled
346 1.27 garbled /* now look for voltage and bus speed gpios */
347 1.30 phx use_dfs = 0;
348 1.27 garbled for (child = OF_child(node); child; child = OF_peer(child)) {
349 1.27 garbled
350 1.27 garbled if (OF_getprop(child, "name", name, sizeof(name)) < 1)
351 1.27 garbled continue;
352 1.27 garbled
353 1.27 garbled if (OF_getprop(child, "reg", reg, sizeof(reg)) < 4)
354 1.27 garbled continue;
355 1.27 garbled
356 1.31 phx /*
357 1.31 phx * These register offsets either have to be added to the obio
358 1.31 phx * base address or to the gpio base address. This differs
359 1.31 phx * even in the same OF-tree! So we guess the offset is
360 1.31 phx * based on obio when it is larger than the gpio_base.
361 1.31 phx */
362 1.31 phx if (reg[0] >= gpio_base)
363 1.31 phx reg[0] -= gpio_base;
364 1.31 phx
365 1.27 garbled if (strcmp(name, "frequency-gpio") == 0) {
366 1.27 garbled DPRINTF("found frequency_gpio at %02x\n", reg[0]);
367 1.27 garbled sc->sc_busspeed = gpio_base + reg[0];
368 1.27 garbled }
369 1.27 garbled if (strcmp(name, "voltage-gpio") == 0) {
370 1.27 garbled DPRINTF("found voltage_gpio at %02x\n", reg[0]);
371 1.27 garbled sc->sc_voltage = gpio_base + reg[0];
372 1.27 garbled }
373 1.30 phx if (strcmp(name, "cpu-vcore-select") == 0) {
374 1.30 phx DPRINTF("found cpu-vcore-select at %02x\n", reg[0]);
375 1.30 phx sc->sc_voltage = gpio_base + reg[0];
376 1.30 phx /* frequency gpio is not needed, we use cpu's DFS */
377 1.30 phx use_dfs = 1;
378 1.30 phx }
379 1.27 garbled }
380 1.27 garbled
381 1.30 phx if ((sc->sc_voltage < 0) || (sc->sc_busspeed < 0 && !use_dfs))
382 1.27 garbled return;
383 1.27 garbled
384 1.27 garbled printf("%s: enabling Intrepid CPU speed control\n",
385 1.27 garbled sc->sc_dev.dv_xname);
386 1.27 garbled
387 1.30 phx sysctl_node = NULL;
388 1.27 garbled sysctl_createv(NULL, 0, NULL,
389 1.27 garbled (const struct sysctlnode **)&sysctl_node,
390 1.27 garbled CTLFLAG_READWRITE | CTLFLAG_OWNDESC | CTLFLAG_IMMEDIATE,
391 1.27 garbled CTLTYPE_INT, "cpu_speed", "CPU speed", sysctl_cpuspeed_temp,
392 1.27 garbled (unsigned long)sc, NULL, 0, CTL_MACHDEP, CTL_CREATE, CTL_EOL);
393 1.31 phx if (sysctl_node != NULL)
394 1.27 garbled sysctl_node->sysctl_data = (void *)sc;
395 1.27 garbled }
396 1.27 garbled
397 1.27 garbled static void
398 1.27 garbled obio_set_cpu_speed(struct obio_softc *sc, int fast)
399 1.27 garbled {
400 1.27 garbled
401 1.30 phx if (sc->sc_voltage < 0)
402 1.27 garbled return;
403 1.27 garbled
404 1.30 phx if (sc->sc_busspeed >= 0) {
405 1.30 phx /* set voltage and speed via gpio */
406 1.30 phx if (fast) {
407 1.30 phx bus_space_write_1(sc->sc_tag, sc->sc_bh,
408 1.30 phx sc->sc_voltage, 5);
409 1.30 phx bus_space_write_1(sc->sc_tag, sc->sc_bh,
410 1.30 phx sc->sc_busspeed, 5);
411 1.30 phx } else {
412 1.30 phx bus_space_write_1(sc->sc_tag, sc->sc_bh,
413 1.30 phx sc->sc_busspeed, 4);
414 1.30 phx bus_space_write_1(sc->sc_tag, sc->sc_bh,
415 1.30 phx sc->sc_voltage, 4);
416 1.30 phx }
417 1.30 phx }
418 1.30 phx else {
419 1.30 phx /* set voltage via gpio and speed via the 7447A's DFS bit */
420 1.30 phx if (fast) {
421 1.30 phx bus_space_write_1(sc->sc_tag, sc->sc_bh,
422 1.30 phx sc->sc_voltage, 5);
423 1.30 phx DELAY(1000);
424 1.30 phx }
425 1.30 phx
426 1.30 phx /* set DFS for all cpus */
427 1.30 phx cpu_set_dfs(fast ? 1 : 2);
428 1.30 phx DELAY(100);
429 1.30 phx
430 1.30 phx if (!fast) {
431 1.30 phx bus_space_write_1(sc->sc_tag, sc->sc_bh,
432 1.30 phx sc->sc_voltage, 4);
433 1.30 phx DELAY(1000);
434 1.30 phx }
435 1.27 garbled }
436 1.27 garbled }
437 1.27 garbled
438 1.27 garbled static int
439 1.27 garbled obio_get_cpu_speed(struct obio_softc *sc)
440 1.27 garbled {
441 1.27 garbled
442 1.30 phx if (sc->sc_voltage < 0)
443 1.27 garbled return 0;
444 1.27 garbled
445 1.30 phx if (sc->sc_busspeed >= 0) {
446 1.30 phx if (bus_space_read_1(sc->sc_tag, sc->sc_bh, sc->sc_busspeed)
447 1.30 phx & 1)
448 1.31 phx return 1;
449 1.30 phx }
450 1.30 phx else
451 1.30 phx return cpu_get_dfs() == 1;
452 1.27 garbled
453 1.27 garbled return 0;
454 1.27 garbled }
455 1.27 garbled
456 1.27 garbled static int
457 1.27 garbled sysctl_cpuspeed_temp(SYSCTLFN_ARGS)
458 1.27 garbled {
459 1.27 garbled struct sysctlnode node = *rnode;
460 1.27 garbled struct obio_softc *sc = node.sysctl_data;
461 1.27 garbled const int *np = newp;
462 1.27 garbled int speed, nd = 0;
463 1.27 garbled
464 1.27 garbled speed = obio_get_cpu_speed(sc);
465 1.27 garbled node.sysctl_idata = speed;
466 1.27 garbled if (np) {
467 1.27 garbled /* we're asked to write */
468 1.27 garbled nd = *np;
469 1.27 garbled node.sysctl_data = &speed;
470 1.27 garbled if (sysctl_lookup(SYSCTLFN_CALL(&node)) == 0) {
471 1.27 garbled int new_reg;
472 1.30 phx
473 1.27 garbled new_reg = (max(0, min(1, node.sysctl_idata)));
474 1.27 garbled obio_set_cpu_speed(sc, new_reg);
475 1.27 garbled return 0;
476 1.27 garbled }
477 1.27 garbled return EINVAL;
478 1.27 garbled } else {
479 1.27 garbled node.sysctl_size = 4;
480 1.27 garbled return(sysctl_lookup(SYSCTLFN_CALL(&node)));
481 1.27 garbled }
482 1.27 garbled }
483 1.27 garbled
484 1.27 garbled #endif /* OBIO_SPEEDCONTROL */
485