pwmclock.c revision 1.3.4.3 1 1.3.4.3 mrg /* $NetBSD: pwmclock.c,v 1.3.4.3 2012/02/24 09:11:42 mrg Exp $ */
2 1.3.4.2 mrg
3 1.3.4.2 mrg /*
4 1.3.4.2 mrg * Copyright (c) 2011 Michael Lorenz
5 1.3.4.2 mrg * All rights reserved.
6 1.3.4.2 mrg *
7 1.3.4.2 mrg * Redistribution and use in source and binary forms, with or without
8 1.3.4.2 mrg * modification, are permitted provided that the following conditions
9 1.3.4.2 mrg * are met:
10 1.3.4.2 mrg * 1. Redistributions of source code must retain the above copyright
11 1.3.4.2 mrg * notice, this list of conditions and the following disclaimer.
12 1.3.4.2 mrg * 2. Redistributions in binary form must reproduce the above copyright
13 1.3.4.2 mrg * notice, this list of conditions and the following disclaimer in the
14 1.3.4.2 mrg * documentation and/or other materials provided with the distribution.
15 1.3.4.2 mrg *
16 1.3.4.2 mrg * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 1.3.4.2 mrg * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 1.3.4.2 mrg * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 1.3.4.2 mrg * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 1.3.4.2 mrg * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 1.3.4.2 mrg * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 1.3.4.2 mrg * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 1.3.4.2 mrg * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 1.3.4.2 mrg * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 1.3.4.2 mrg * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 1.3.4.2 mrg */
27 1.3.4.2 mrg
28 1.3.4.2 mrg #include <sys/cdefs.h>
29 1.3.4.3 mrg __KERNEL_RCSID(0, "$NetBSD: pwmclock.c,v 1.3.4.3 2012/02/24 09:11:42 mrg Exp $");
30 1.3.4.2 mrg
31 1.3.4.2 mrg #include <sys/param.h>
32 1.3.4.2 mrg #include <sys/systm.h>
33 1.3.4.2 mrg #include <sys/kernel.h>
34 1.3.4.2 mrg #include <sys/device.h>
35 1.3.4.2 mrg #include <sys/cpu.h>
36 1.3.4.2 mrg #include <sys/timetc.h>
37 1.3.4.2 mrg #include <sys/sysctl.h>
38 1.3.4.2 mrg
39 1.3.4.2 mrg #include <dev/pci/voyagervar.h>
40 1.3.4.2 mrg #include <dev/ic/sm502reg.h>
41 1.3.4.2 mrg
42 1.3.4.2 mrg #include <mips/mips3_clock.h>
43 1.3.4.2 mrg #include <mips/locore.h>
44 1.3.4.2 mrg #include <mips/bonito/bonitoreg.h>
45 1.3.4.2 mrg #include <mips/bonito/bonitovar.h>
46 1.3.4.2 mrg
47 1.3.4.2 mrg #include "opt_pwmclock.h"
48 1.3.4.2 mrg
49 1.3.4.2 mrg #ifdef PWMCLOCK_DEBUG
50 1.3.4.2 mrg #define DPRINTF aprint_error
51 1.3.4.2 mrg #else
52 1.3.4.2 mrg #define DPRINTF while (0) printf
53 1.3.4.2 mrg #endif
54 1.3.4.2 mrg
55 1.3.4.2 mrg int pwmclock_intr(void *);
56 1.3.4.2 mrg
57 1.3.4.2 mrg struct pwmclock_softc {
58 1.3.4.2 mrg device_t sc_dev;
59 1.3.4.2 mrg bus_space_tag_t sc_memt;
60 1.3.4.2 mrg bus_space_handle_t sc_regh;
61 1.3.4.2 mrg uint32_t sc_reg, sc_last;
62 1.3.4.2 mrg uint32_t sc_scale[8];
63 1.3.4.2 mrg uint32_t sc_count; /* should probably be 64 bit */
64 1.3.4.2 mrg int sc_step;
65 1.3.4.2 mrg int sc_step_wanted;
66 1.3.4.3 mrg void *sc_shutdown_cookie;
67 1.3.4.2 mrg };
68 1.3.4.2 mrg
69 1.3.4.2 mrg static int pwmclock_match(device_t, cfdata_t, void *);
70 1.3.4.2 mrg static void pwmclock_attach(device_t, device_t, void *);
71 1.3.4.2 mrg
72 1.3.4.2 mrg CFATTACH_DECL_NEW(pwmclock, sizeof(struct pwmclock_softc),
73 1.3.4.2 mrg pwmclock_match, pwmclock_attach, NULL, NULL);
74 1.3.4.2 mrg
75 1.3.4.2 mrg static void pwmclock_start(void);
76 1.3.4.2 mrg static u_int get_pwmclock_timecount(struct timecounter *);
77 1.3.4.2 mrg
78 1.3.4.2 mrg struct pwmclock_softc *pwmclock;
79 1.3.4.2 mrg extern void (*initclocks_ptr)(void);
80 1.3.4.2 mrg extern struct clockframe cf;
81 1.3.4.2 mrg
82 1.3.4.2 mrg /* 0, 1/4, 3/8, 1/2, 5/8, 3/4, 7/8, 1 */
83 1.3.4.2 mrg static int scale_m[] = {1, 1, 3, 1, 5, 3, 7, 1};
84 1.3.4.2 mrg static int scale_d[] = {0, 4, 8, 2, 8, 4, 8, 1};
85 1.3.4.2 mrg
86 1.3.4.2 mrg #define scale(x, f) (x * scale_d[f] / scale_m[f])
87 1.3.4.2 mrg
88 1.3.4.2 mrg void pwmclock_set_speed(struct pwmclock_softc *, int);
89 1.3.4.2 mrg static int pwmclock_cpuspeed_temp(SYSCTLFN_ARGS);
90 1.3.4.2 mrg static int pwmclock_cpuspeed_cur(SYSCTLFN_ARGS);
91 1.3.4.2 mrg static int pwmclock_cpuspeed_available(SYSCTLFN_ARGS);
92 1.3.4.2 mrg
93 1.3.4.3 mrg static void pwmclock_shutdown(void *);
94 1.3.4.3 mrg
95 1.3.4.2 mrg static struct timecounter pwmclock_timecounter = {
96 1.3.4.2 mrg get_pwmclock_timecount, /* get_timecount */
97 1.3.4.2 mrg 0, /* no poll_pps */
98 1.3.4.2 mrg 0xffffffff, /* counter_mask */
99 1.3.4.2 mrg 0, /* frequency */
100 1.3.4.2 mrg "pwm", /* name */
101 1.3.4.2 mrg 100, /* quality */
102 1.3.4.2 mrg NULL, /* tc_priv */
103 1.3.4.2 mrg NULL /* tc_next */
104 1.3.4.2 mrg };
105 1.3.4.2 mrg
106 1.3.4.2 mrg static int
107 1.3.4.2 mrg pwmclock_match(device_t parent, cfdata_t match, void *aux)
108 1.3.4.2 mrg {
109 1.3.4.2 mrg struct voyager_attach_args *vaa = (struct voyager_attach_args *)aux;
110 1.3.4.2 mrg
111 1.3.4.2 mrg if (strcmp(vaa->vaa_name, "pwmclock") == 0) return 100;
112 1.3.4.2 mrg return 0;
113 1.3.4.2 mrg }
114 1.3.4.2 mrg
115 1.3.4.2 mrg static uint32_t
116 1.3.4.2 mrg pwmclock_wait_edge(struct pwmclock_softc *sc)
117 1.3.4.2 mrg {
118 1.3.4.2 mrg /* clear interrupt */
119 1.3.4.2 mrg bus_space_write_4(sc->sc_memt, sc->sc_regh, SM502_PWM1, sc->sc_reg);
120 1.3.4.3 mrg while ((bus_space_read_4(sc->sc_memt, sc->sc_regh, SM502_PWM1) &
121 1.3.4.3 mrg SM502_PWM_INTR_PENDING) == 0);
122 1.3.4.2 mrg return mips3_cp0_count_read();
123 1.3.4.2 mrg }
124 1.3.4.2 mrg
125 1.3.4.2 mrg static void
126 1.3.4.2 mrg pwmclock_attach(device_t parent, device_t self, void *aux)
127 1.3.4.2 mrg {
128 1.3.4.2 mrg struct pwmclock_softc *sc = device_private(self);
129 1.3.4.2 mrg struct voyager_attach_args *vaa = aux;
130 1.3.4.2 mrg const struct sysctlnode *sysctl_node, *me, *freq;
131 1.3.4.2 mrg uint32_t reg, last, curr, diff, acc;
132 1.3.4.2 mrg int i, clk;
133 1.3.4.2 mrg
134 1.3.4.2 mrg sc->sc_dev = self;
135 1.3.4.2 mrg sc->sc_memt = vaa->vaa_tag;
136 1.3.4.2 mrg sc->sc_regh = vaa->vaa_regh;
137 1.3.4.2 mrg
138 1.3.4.2 mrg aprint_normal("\n");
139 1.3.4.2 mrg
140 1.3.4.2 mrg voyager_establish_intr(parent, 22, pwmclock_intr, sc);
141 1.3.4.2 mrg reg = voyager_set_pwm(100, 100); /* 100Hz, 10% duty cycle */
142 1.3.4.3 mrg reg |= SM502_PWM_ENABLE | SM502_PWM_ENABLE_INTR |
143 1.3.4.3 mrg SM502_PWM_INTR_PENDING;
144 1.3.4.2 mrg sc->sc_reg = reg;
145 1.3.4.2 mrg pwmclock = sc;
146 1.3.4.2 mrg initclocks_ptr = pwmclock_start;
147 1.3.4.2 mrg
148 1.3.4.3 mrg /*
149 1.3.4.3 mrg * Establish a hook so on shutdown we can set the CPU clock back to
150 1.3.4.3 mrg * full speed. This is necessary because PMON doesn't change the
151 1.3.4.3 mrg * clock scale register on a warm boot, the MIPS clock code gets
152 1.3.4.3 mrg * confused if we're too slow and the loongson-specific bits run
153 1.3.4.3 mrg * too late in the boot process
154 1.3.4.3 mrg */
155 1.3.4.3 mrg sc->sc_shutdown_cookie = shutdownhook_establish(pwmclock_shutdown, sc);
156 1.3.4.3 mrg
157 1.3.4.2 mrg /* ok, let's see how far the cycle counter gets between interrupts */
158 1.3.4.2 mrg DPRINTF("calibrating CPU timer...\n");
159 1.3.4.2 mrg for (clk = 1; clk < 8; clk++) {
160 1.3.4.3 mrg REGVAL(LS2F_CHIPCFG0) =
161 1.3.4.3 mrg (REGVAL(LS2F_CHIPCFG0) & ~LS2FCFG_FREQSCALE_MASK) | clk;
162 1.3.4.3 mrg bus_space_write_4(sc->sc_memt, sc->sc_regh, SM502_PWM1,
163 1.3.4.3 mrg sc->sc_reg);
164 1.3.4.2 mrg acc = 0;
165 1.3.4.2 mrg last = pwmclock_wait_edge(sc);
166 1.3.4.2 mrg for (i = 0; i < 16; i++) {
167 1.3.4.2 mrg curr = pwmclock_wait_edge(sc);
168 1.3.4.2 mrg diff = curr - last;
169 1.3.4.2 mrg acc += diff;
170 1.3.4.2 mrg last = curr;
171 1.3.4.2 mrg }
172 1.3.4.2 mrg sc->sc_scale[clk] = (acc >> 4) / 5000;
173 1.3.4.2 mrg }
174 1.3.4.2 mrg #ifdef PWMCLOCK_DEBUG
175 1.3.4.2 mrg for (clk = 1; clk < 8; clk++) {
176 1.3.4.3 mrg aprint_normal_dev(sc->sc_dev, "%d/8: %d\n", clk + 1,
177 1.3.4.3 mrg sc->sc_scale[clk]);
178 1.3.4.2 mrg }
179 1.3.4.2 mrg #endif
180 1.3.4.2 mrg sc->sc_step = 7;
181 1.3.4.2 mrg sc->sc_step_wanted = 7;
182 1.3.4.2 mrg
183 1.3.4.2 mrg /* now setup sysctl */
184 1.3.4.2 mrg if (sysctl_createv(NULL, 0, NULL,
185 1.3.4.2 mrg &me,
186 1.3.4.2 mrg CTLFLAG_READWRITE, CTLTYPE_NODE, "loongson", NULL, NULL,
187 1.3.4.2 mrg 0, NULL, 0, CTL_MACHDEP, CTL_CREATE, CTL_EOL) != 0)
188 1.3.4.3 mrg aprint_error_dev(sc->sc_dev,
189 1.3.4.3 mrg "couldn't create 'loongson' node\n");
190 1.3.4.3 mrg
191 1.3.4.2 mrg if (sysctl_createv(NULL, 0, NULL,
192 1.3.4.2 mrg &freq,
193 1.3.4.3 mrg CTLFLAG_READWRITE, CTLTYPE_NODE, "frequency", NULL, NULL, 0, NULL,
194 1.3.4.3 mrg 0, CTL_MACHDEP, me->sysctl_num, CTL_CREATE, CTL_EOL) != 0)
195 1.3.4.3 mrg aprint_error_dev(sc->sc_dev,
196 1.3.4.3 mrg "couldn't create 'frequency' node\n");
197 1.3.4.2 mrg
198 1.3.4.2 mrg if (sysctl_createv(NULL, 0, NULL,
199 1.3.4.2 mrg &sysctl_node,
200 1.3.4.2 mrg CTLFLAG_READWRITE | CTLFLAG_OWNDESC,
201 1.3.4.2 mrg CTLTYPE_INT, "target", "CPU speed", pwmclock_cpuspeed_temp,
202 1.3.4.2 mrg 0, sc, 0, CTL_MACHDEP, me->sysctl_num, freq->sysctl_num,
203 1.3.4.2 mrg CTL_CREATE, CTL_EOL) == 0) {
204 1.3.4.2 mrg } else
205 1.3.4.3 mrg aprint_error_dev(sc->sc_dev,
206 1.3.4.3 mrg "couldn't create 'target' node\n");
207 1.3.4.2 mrg
208 1.3.4.2 mrg if (sysctl_createv(NULL, 0, NULL,
209 1.3.4.2 mrg &sysctl_node,
210 1.3.4.2 mrg CTLFLAG_READWRITE,
211 1.3.4.2 mrg CTLTYPE_INT, "current", NULL, pwmclock_cpuspeed_cur,
212 1.3.4.2 mrg 1, sc, 0, CTL_MACHDEP, me->sysctl_num, freq->sysctl_num,
213 1.3.4.2 mrg CTL_CREATE, CTL_EOL) == 0) {
214 1.3.4.2 mrg } else
215 1.3.4.3 mrg aprint_error_dev(sc->sc_dev,
216 1.3.4.3 mrg "couldn't create 'current' node\n");
217 1.3.4.2 mrg
218 1.3.4.2 mrg if (sysctl_createv(NULL, 0, NULL,
219 1.3.4.2 mrg &sysctl_node,
220 1.3.4.2 mrg CTLFLAG_READWRITE,
221 1.3.4.2 mrg CTLTYPE_STRING, "available", NULL, pwmclock_cpuspeed_available,
222 1.3.4.2 mrg 2, sc, 0, CTL_MACHDEP, me->sysctl_num, freq->sysctl_num,
223 1.3.4.2 mrg CTL_CREATE, CTL_EOL) == 0) {
224 1.3.4.2 mrg } else
225 1.3.4.3 mrg aprint_error_dev(sc->sc_dev,
226 1.3.4.3 mrg "couldn't create 'available' node\n");
227 1.3.4.3 mrg }
228 1.3.4.3 mrg
229 1.3.4.3 mrg static void
230 1.3.4.3 mrg pwmclock_shutdown(void *cookie)
231 1.3.4.3 mrg {
232 1.3.4.3 mrg struct pwmclock_softc *sc = cookie;
233 1.3.4.3 mrg
234 1.3.4.3 mrg /* just in case the interrupt handler runs again after this */
235 1.3.4.3 mrg sc->sc_step_wanted = 7;
236 1.3.4.3 mrg /* set the clock to full speed */
237 1.3.4.3 mrg REGVAL(LS2F_CHIPCFG0) =
238 1.3.4.3 mrg (REGVAL(LS2F_CHIPCFG0) & ~LS2FCFG_FREQSCALE_MASK) | 7;
239 1.3.4.2 mrg }
240 1.3.4.2 mrg
241 1.3.4.2 mrg void
242 1.3.4.2 mrg pwmclock_set_speed(struct pwmclock_softc *sc, int speed)
243 1.3.4.2 mrg {
244 1.3.4.2 mrg
245 1.3.4.2 mrg if ((speed < 1) || (speed > 7))
246 1.3.4.2 mrg return;
247 1.3.4.2 mrg sc->sc_step_wanted = speed;
248 1.3.4.2 mrg DPRINTF("%s: %d\n", __func__, speed);
249 1.3.4.2 mrg }
250 1.3.4.2 mrg
251 1.3.4.2 mrg /*
252 1.3.4.2 mrg * the PWM interrupt handler
253 1.3.4.2 mrg * we don't have a CPU clock independent, high resolution counter so we're
254 1.3.4.2 mrg * stuck with a PWM that can't count and a CP0 counter that slows down or
255 1.3.4.2 mrg * speeds up with the actual CPU speed. In order to still get halfway
256 1.3.4.2 mrg * accurate time we do the following:
257 1.3.4.2 mrg * - only change CPU speed in the timer interrupt
258 1.3.4.2 mrg * - each timer interrupt we measure how many CP0 cycles passed since last
259 1.3.4.2 mrg * time, adjust for CPU speed since we can be sure it didn't change, use
260 1.3.4.2 mrg * that to update a separate counter
261 1.3.4.2 mrg * - when reading the time counter we take the number of CP0 ticks since
262 1.3.4.2 mrg * the last timer interrupt, scale it to CPU clock, return that plus the
263 1.3.4.2 mrg * interrupt updated counter mentioned above to get something close to
264 1.3.4.2 mrg * CP0 running at full speed
265 1.3.4.2 mrg * - when changing CPU speed do it as close to taking the time from CP0 as
266 1.3.4.2 mrg * possible to keep the period of time we spend with CP0 running at the
267 1.3.4.2 mrg * wrong frequency as short as possible - hopefully short enough to stay
268 1.3.4.2 mrg * insignificant compared to other noise since switching speeds isn't
269 1.3.4.2 mrg * going to happen all that often
270 1.3.4.2 mrg */
271 1.3.4.2 mrg
272 1.3.4.2 mrg int
273 1.3.4.2 mrg pwmclock_intr(void *cookie)
274 1.3.4.2 mrg {
275 1.3.4.2 mrg struct pwmclock_softc *sc = cookie;
276 1.3.4.2 mrg uint32_t reg, now, diff;
277 1.3.4.2 mrg
278 1.3.4.2 mrg /* is it us? */
279 1.3.4.2 mrg reg = bus_space_read_4(sc->sc_memt, sc->sc_regh, SM502_PWM1);
280 1.3.4.2 mrg if ((reg & SM502_PWM_INTR_PENDING) == 0)
281 1.3.4.2 mrg return 0;
282 1.3.4.2 mrg
283 1.3.4.2 mrg /* yes, it's us, so clear the interrupt */
284 1.3.4.2 mrg bus_space_write_4(sc->sc_memt, sc->sc_regh, SM502_PWM1, sc->sc_reg);
285 1.3.4.2 mrg
286 1.3.4.2 mrg /*
287 1.3.4.2 mrg * this looks kinda funny but what we want here is this:
288 1.3.4.2 mrg * - reading the counter and changing the CPU clock should be as
289 1.3.4.2 mrg * close together as possible in order to remain halfway accurate
290 1.3.4.2 mrg * - we need to use the previous sc_step in order to scale the
291 1.3.4.2 mrg * interval passed since the last clock interrupt correctly, so
292 1.3.4.2 mrg * we only change sc_step after doing that
293 1.3.4.2 mrg */
294 1.3.4.2 mrg if (sc->sc_step_wanted != sc->sc_step) {
295 1.3.4.2 mrg REGVAL(LS2F_CHIPCFG0) =
296 1.3.4.2 mrg (REGVAL(LS2F_CHIPCFG0) & ~LS2FCFG_FREQSCALE_MASK) |
297 1.3.4.2 mrg sc->sc_step_wanted;
298 1.3.4.2 mrg }
299 1.3.4.2 mrg
300 1.3.4.2 mrg now = mips3_cp0_count_read();
301 1.3.4.2 mrg diff = now - sc->sc_last;
302 1.3.4.2 mrg sc->sc_count += scale(diff, sc->sc_step);
303 1.3.4.2 mrg sc->sc_last = now;
304 1.3.4.2 mrg if (sc->sc_step_wanted != sc->sc_step) {
305 1.3.4.2 mrg sc->sc_step = sc->sc_step_wanted;
306 1.3.4.2 mrg }
307 1.3.4.2 mrg hardclock(&cf);
308 1.3.4.2 mrg
309 1.3.4.2 mrg return 1;
310 1.3.4.2 mrg }
311 1.3.4.2 mrg
312 1.3.4.2 mrg static void
313 1.3.4.2 mrg pwmclock_start(void)
314 1.3.4.2 mrg {
315 1.3.4.2 mrg struct pwmclock_softc *sc = pwmclock;
316 1.3.4.2 mrg sc->sc_count = 0;
317 1.3.4.2 mrg sc->sc_last = mips3_cp0_count_read();
318 1.3.4.2 mrg pwmclock_timecounter.tc_frequency = curcpu()->ci_cpu_freq / 2;
319 1.3.4.2 mrg tc_init(&pwmclock_timecounter);
320 1.3.4.2 mrg bus_space_write_4(sc->sc_memt, sc->sc_regh, SM502_PWM1, sc->sc_reg);
321 1.3.4.2 mrg }
322 1.3.4.2 mrg
323 1.3.4.2 mrg static u_int
324 1.3.4.2 mrg get_pwmclock_timecount(struct timecounter *tc)
325 1.3.4.2 mrg {
326 1.3.4.2 mrg struct pwmclock_softc *sc = pwmclock;
327 1.3.4.2 mrg uint32_t now, diff;
328 1.3.4.2 mrg
329 1.3.4.2 mrg now = mips3_cp0_count_read();
330 1.3.4.2 mrg diff = now - sc->sc_last;
331 1.3.4.2 mrg return sc->sc_count + scale(diff, sc->sc_step);
332 1.3.4.2 mrg }
333 1.3.4.2 mrg
334 1.3.4.2 mrg static int
335 1.3.4.2 mrg pwmclock_cpuspeed_temp(SYSCTLFN_ARGS)
336 1.3.4.2 mrg {
337 1.3.4.2 mrg struct sysctlnode node = *rnode;
338 1.3.4.2 mrg struct pwmclock_softc *sc = node.sysctl_data;
339 1.3.4.2 mrg int mhz, i;
340 1.3.4.2 mrg
341 1.3.4.2 mrg mhz = sc->sc_scale[sc->sc_step_wanted];
342 1.3.4.2 mrg
343 1.3.4.2 mrg node.sysctl_data = &mhz;
344 1.3.4.2 mrg if (sysctl_lookup(SYSCTLFN_CALL(&node)) == 0) {
345 1.3.4.2 mrg int new_reg;
346 1.3.4.2 mrg
347 1.3.4.2 mrg new_reg = *(int *)node.sysctl_data;
348 1.3.4.2 mrg i = 1;
349 1.3.4.2 mrg while ((i < 8) && (sc->sc_scale[i] != new_reg))
350 1.3.4.2 mrg i++;
351 1.3.4.2 mrg if (i > 7)
352 1.3.4.2 mrg return EINVAL;
353 1.3.4.2 mrg pwmclock_set_speed(sc, i);
354 1.3.4.2 mrg return 0;
355 1.3.4.2 mrg }
356 1.3.4.2 mrg return EINVAL;
357 1.3.4.2 mrg }
358 1.3.4.2 mrg
359 1.3.4.2 mrg static int
360 1.3.4.2 mrg pwmclock_cpuspeed_cur(SYSCTLFN_ARGS)
361 1.3.4.2 mrg {
362 1.3.4.2 mrg struct sysctlnode node = *rnode;
363 1.3.4.2 mrg struct pwmclock_softc *sc = node.sysctl_data;
364 1.3.4.2 mrg int mhz;
365 1.3.4.2 mrg
366 1.3.4.2 mrg mhz = sc->sc_scale[sc->sc_step];
367 1.3.4.2 mrg node.sysctl_data = &mhz;
368 1.3.4.2 mrg return sysctl_lookup(SYSCTLFN_CALL(&node));
369 1.3.4.2 mrg }
370 1.3.4.2 mrg
371 1.3.4.2 mrg static int
372 1.3.4.2 mrg pwmclock_cpuspeed_available(SYSCTLFN_ARGS)
373 1.3.4.2 mrg {
374 1.3.4.2 mrg struct sysctlnode node = *rnode;
375 1.3.4.2 mrg struct pwmclock_softc *sc = node.sysctl_data;
376 1.3.4.2 mrg char buf[128];
377 1.3.4.2 mrg
378 1.3.4.2 mrg snprintf(buf, 128, "%d %d %d %d %d %d %d", sc->sc_scale[1],
379 1.3.4.2 mrg sc->sc_scale[2], sc->sc_scale[3], sc->sc_scale[4],
380 1.3.4.2 mrg sc->sc_scale[5], sc->sc_scale[6], sc->sc_scale[7]);
381 1.3.4.2 mrg node.sysctl_data = buf;
382 1.3.4.2 mrg return(sysctl_lookup(SYSCTLFN_CALL(&node)));
383 1.3.4.2 mrg }
384 1.3.4.2 mrg
385 1.3.4.2 mrg SYSCTL_SETUP(sysctl_ams_setup, "sysctl obio subtree setup")
386 1.3.4.2 mrg {
387 1.3.4.2 mrg
388 1.3.4.2 mrg sysctl_createv(NULL, 0, NULL, NULL,
389 1.3.4.2 mrg CTLFLAG_PERMANENT,
390 1.3.4.2 mrg CTLTYPE_NODE, "machdep", NULL,
391 1.3.4.2 mrg NULL, 0, NULL, 0,
392 1.3.4.2 mrg CTL_MACHDEP, CTL_EOL);
393 1.3.4.2 mrg }
394