rpi_vcmbox.c revision 1.3 1 1.3 skrll /* $NetBSD: rpi_vcmbox.c,v 1.3 2014/04/01 06:55:29 skrll Exp $ */
2 1.1 jmcneill
3 1.1 jmcneill /*-
4 1.1 jmcneill * Copyright (c) 2013 Jared D. McNeill <jmcneill (at) invisible.ca>
5 1.1 jmcneill * All rights reserved.
6 1.1 jmcneill *
7 1.1 jmcneill * Redistribution and use in source and binary forms, with or without
8 1.1 jmcneill * modification, are permitted provided that the following conditions
9 1.1 jmcneill * are met:
10 1.1 jmcneill * 1. Redistributions of source code must retain the above copyright
11 1.1 jmcneill * notice, this list of conditions and the following disclaimer.
12 1.1 jmcneill * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 jmcneill * notice, this list of conditions and the following disclaimer in the
14 1.1 jmcneill * documentation and/or other materials provided with the distribution.
15 1.1 jmcneill *
16 1.1 jmcneill * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 1.1 jmcneill * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 1.1 jmcneill * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 1.1 jmcneill * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 1.1 jmcneill * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 1.1 jmcneill * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 1.1 jmcneill * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 1.1 jmcneill * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 1.1 jmcneill * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 1.1 jmcneill * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 1.1 jmcneill * POSSIBILITY OF SUCH DAMAGE.
27 1.1 jmcneill */
28 1.1 jmcneill
29 1.1 jmcneill /*
30 1.1 jmcneill * Raspberry Pi VC Mailbox Interface
31 1.1 jmcneill */
32 1.1 jmcneill
33 1.1 jmcneill #include <sys/cdefs.h>
34 1.3 skrll __KERNEL_RCSID(0, "$NetBSD: rpi_vcmbox.c,v 1.3 2014/04/01 06:55:29 skrll Exp $");
35 1.1 jmcneill
36 1.1 jmcneill #include <sys/param.h>
37 1.1 jmcneill #include <sys/types.h>
38 1.1 jmcneill #include <sys/systm.h>
39 1.1 jmcneill #include <sys/device.h>
40 1.1 jmcneill #include <sys/conf.h>
41 1.1 jmcneill #include <sys/bus.h>
42 1.1 jmcneill #include <sys/kmem.h>
43 1.2 jmcneill #include <sys/sysctl.h>
44 1.1 jmcneill
45 1.1 jmcneill #include <dev/sysmon/sysmonvar.h>
46 1.1 jmcneill
47 1.1 jmcneill #include <arm/broadcom/bcm2835_mbox.h>
48 1.1 jmcneill
49 1.1 jmcneill #include <evbarm/rpi/vcio.h>
50 1.1 jmcneill #include <evbarm/rpi/vcprop.h>
51 1.1 jmcneill
52 1.1 jmcneill struct vcmbox_temp_request {
53 1.1 jmcneill struct vcprop_buffer_hdr vb_hdr;
54 1.1 jmcneill struct vcprop_tag_temperature vbt_temp;
55 1.1 jmcneill struct vcprop_tag end;
56 1.1 jmcneill } __packed;
57 1.1 jmcneill
58 1.2 jmcneill struct vcmbox_clockrate_request {
59 1.2 jmcneill struct vcprop_buffer_hdr vb_hdr;
60 1.2 jmcneill struct vcprop_tag_clockrate vbt_clockrate;
61 1.2 jmcneill struct vcprop_tag end;
62 1.2 jmcneill } __packed;
63 1.2 jmcneill
64 1.2 jmcneill #define RATE2MHZ(rate) ((rate) / 1000000)
65 1.2 jmcneill #define MHZ2RATE(mhz) ((mhz) * 1000000)
66 1.2 jmcneill
67 1.1 jmcneill #define VCMBOX_INIT_REQUEST(req) \
68 1.1 jmcneill do { \
69 1.1 jmcneill memset(&(req), 0, sizeof((req))); \
70 1.1 jmcneill (req).vb_hdr.vpb_len = sizeof((req)); \
71 1.1 jmcneill (req).vb_hdr.vpb_rcode = VCPROP_PROCESS_REQUEST; \
72 1.1 jmcneill (req).end.vpt_tag = VCPROPTAG_NULL; \
73 1.1 jmcneill } while (0)
74 1.1 jmcneill #define VCMBOX_INIT_TAG(s, t) \
75 1.1 jmcneill do { \
76 1.1 jmcneill (s).tag.vpt_tag = (t); \
77 1.1 jmcneill (s).tag.vpt_rcode = VCPROPTAG_REQUEST; \
78 1.1 jmcneill (s).tag.vpt_len = VCPROPTAG_LEN(s); \
79 1.1 jmcneill } while (0)
80 1.1 jmcneill
81 1.1 jmcneill struct vcmbox_softc {
82 1.1 jmcneill device_t sc_dev;
83 1.1 jmcneill
84 1.1 jmcneill /* temperature sensor */
85 1.1 jmcneill struct sysmon_envsys *sc_sme;
86 1.1 jmcneill #define VCMBOX_SENSOR_TEMP 0
87 1.1 jmcneill #define VCMBOX_NSENSORS 1
88 1.1 jmcneill envsys_data_t sc_sensor[VCMBOX_NSENSORS];
89 1.2 jmcneill
90 1.2 jmcneill /* cpu frequency scaling */
91 1.2 jmcneill struct sysctllog *sc_log;
92 1.2 jmcneill uint32_t sc_cpu_minrate;
93 1.2 jmcneill uint32_t sc_cpu_maxrate;
94 1.2 jmcneill int sc_node_target;
95 1.2 jmcneill int sc_node_current;
96 1.2 jmcneill int sc_node_min;
97 1.2 jmcneill int sc_node_max;
98 1.1 jmcneill };
99 1.1 jmcneill
100 1.1 jmcneill static const char *vcmbox_sensor_name[VCMBOX_NSENSORS] = {
101 1.1 jmcneill "temperature",
102 1.1 jmcneill };
103 1.1 jmcneill
104 1.1 jmcneill static int vcmbox_sensor_id[VCMBOX_NSENSORS] = {
105 1.1 jmcneill VCPROP_TEMP_SOC,
106 1.1 jmcneill };
107 1.1 jmcneill
108 1.1 jmcneill static int vcmbox_match(device_t, cfdata_t, void *);
109 1.1 jmcneill static void vcmbox_attach(device_t, device_t, void *);
110 1.1 jmcneill
111 1.1 jmcneill static int vcmbox_read_temp(struct vcmbox_softc *, uint32_t, int,
112 1.1 jmcneill uint32_t *);
113 1.2 jmcneill static int vcmbox_read_clockrate(struct vcmbox_softc *, uint32_t, int,
114 1.2 jmcneill uint32_t *);
115 1.2 jmcneill static int vcmbox_write_clockrate(struct vcmbox_softc *, uint32_t, int,
116 1.2 jmcneill uint32_t);
117 1.2 jmcneill
118 1.2 jmcneill static int vcmbox_cpufreq_init(struct vcmbox_softc *);
119 1.2 jmcneill static int vcmbox_cpufreq_sysctl_helper(SYSCTLFN_PROTO);
120 1.2 jmcneill
121 1.2 jmcneill static void vcmbox_create_sensors(struct vcmbox_softc *);
122 1.1 jmcneill static void vcmbox_sensor_get_limits(struct sysmon_envsys *,
123 1.1 jmcneill envsys_data_t *,
124 1.1 jmcneill sysmon_envsys_lim_t *, uint32_t *);
125 1.1 jmcneill static void vcmbox_sensor_refresh(struct sysmon_envsys *,
126 1.1 jmcneill envsys_data_t *);
127 1.1 jmcneill
128 1.1 jmcneill CFATTACH_DECL_NEW(vcmbox, sizeof(struct vcmbox_softc),
129 1.1 jmcneill vcmbox_match, vcmbox_attach, NULL, NULL);
130 1.1 jmcneill
131 1.1 jmcneill static int
132 1.1 jmcneill vcmbox_match(device_t parent, cfdata_t match, void *aux)
133 1.1 jmcneill {
134 1.1 jmcneill return 1;
135 1.1 jmcneill }
136 1.1 jmcneill
137 1.1 jmcneill static void
138 1.1 jmcneill vcmbox_attach(device_t parent, device_t self, void *aux)
139 1.1 jmcneill {
140 1.1 jmcneill struct vcmbox_softc *sc = device_private(self);
141 1.1 jmcneill
142 1.1 jmcneill sc->sc_dev = self;
143 1.1 jmcneill
144 1.1 jmcneill aprint_naive("\n");
145 1.1 jmcneill aprint_normal("\n");
146 1.1 jmcneill
147 1.2 jmcneill vcmbox_cpufreq_init(sc);
148 1.2 jmcneill
149 1.1 jmcneill sc->sc_sme = sysmon_envsys_create();
150 1.1 jmcneill sc->sc_sme->sme_cookie = sc;
151 1.1 jmcneill sc->sc_sme->sme_name = device_xname(sc->sc_dev);
152 1.1 jmcneill sc->sc_sme->sme_refresh = vcmbox_sensor_refresh;
153 1.1 jmcneill sc->sc_sme->sme_get_limits = vcmbox_sensor_get_limits;
154 1.1 jmcneill vcmbox_create_sensors(sc);
155 1.1 jmcneill sysmon_envsys_register(sc->sc_sme);
156 1.1 jmcneill }
157 1.1 jmcneill
158 1.2 jmcneill static int
159 1.2 jmcneill vcmbox_read_temp(struct vcmbox_softc *sc, uint32_t tag, int id, uint32_t *val)
160 1.2 jmcneill {
161 1.2 jmcneill struct vcmbox_temp_request vb;
162 1.2 jmcneill uint32_t res;
163 1.2 jmcneill int error;
164 1.2 jmcneill
165 1.2 jmcneill VCMBOX_INIT_REQUEST(vb);
166 1.2 jmcneill VCMBOX_INIT_TAG(vb.vbt_temp, tag);
167 1.2 jmcneill vb.vbt_temp.id = id;
168 1.2 jmcneill error = bcmmbox_request(BCMMBOX_CHANARM2VC, &vb, sizeof(vb), &res);
169 1.2 jmcneill if (error)
170 1.2 jmcneill return error;
171 1.2 jmcneill if (!vcprop_buffer_success_p(&vb.vb_hdr) ||
172 1.2 jmcneill !vcprop_tag_success_p(&vb.vbt_temp.tag)) {
173 1.2 jmcneill return EIO;
174 1.2 jmcneill }
175 1.2 jmcneill *val = vb.vbt_temp.value;
176 1.2 jmcneill
177 1.2 jmcneill return 0;
178 1.2 jmcneill }
179 1.2 jmcneill
180 1.2 jmcneill static int
181 1.2 jmcneill vcmbox_read_clockrate(struct vcmbox_softc *sc, uint32_t tag, int id,
182 1.2 jmcneill uint32_t *val)
183 1.2 jmcneill {
184 1.2 jmcneill struct vcmbox_clockrate_request vb;
185 1.2 jmcneill uint32_t res;
186 1.2 jmcneill int error;
187 1.2 jmcneill
188 1.2 jmcneill VCMBOX_INIT_REQUEST(vb);
189 1.2 jmcneill VCMBOX_INIT_TAG(vb.vbt_clockrate, tag);
190 1.2 jmcneill vb.vbt_clockrate.id = id;
191 1.2 jmcneill error = bcmmbox_request(BCMMBOX_CHANARM2VC, &vb, sizeof(vb), &res);
192 1.2 jmcneill if (error)
193 1.2 jmcneill return error;
194 1.2 jmcneill if (!vcprop_buffer_success_p(&vb.vb_hdr) ||
195 1.2 jmcneill !vcprop_tag_success_p(&vb.vbt_clockrate.tag)) {
196 1.2 jmcneill return EIO;
197 1.2 jmcneill }
198 1.2 jmcneill *val = vb.vbt_clockrate.rate;
199 1.2 jmcneill
200 1.2 jmcneill return 0;
201 1.2 jmcneill }
202 1.2 jmcneill
203 1.2 jmcneill static int
204 1.2 jmcneill vcmbox_write_clockrate(struct vcmbox_softc *sc, uint32_t tag, int id,
205 1.2 jmcneill uint32_t val)
206 1.2 jmcneill {
207 1.2 jmcneill struct vcmbox_clockrate_request vb;
208 1.2 jmcneill uint32_t res;
209 1.2 jmcneill int error;
210 1.2 jmcneill
211 1.2 jmcneill VCMBOX_INIT_REQUEST(vb);
212 1.2 jmcneill VCMBOX_INIT_TAG(vb.vbt_clockrate, tag);
213 1.2 jmcneill vb.vbt_clockrate.id = id;
214 1.2 jmcneill vb.vbt_clockrate.rate = val;
215 1.2 jmcneill error = bcmmbox_request(BCMMBOX_CHANARM2VC, &vb, sizeof(vb), &res);
216 1.2 jmcneill if (error)
217 1.2 jmcneill return error;
218 1.2 jmcneill if (!vcprop_buffer_success_p(&vb.vb_hdr) ||
219 1.2 jmcneill !vcprop_tag_success_p(&vb.vbt_clockrate.tag)) {
220 1.2 jmcneill return EIO;
221 1.2 jmcneill }
222 1.2 jmcneill
223 1.2 jmcneill return 0;
224 1.2 jmcneill }
225 1.2 jmcneill
226 1.2 jmcneill
227 1.2 jmcneill static int
228 1.2 jmcneill vcmbox_cpufreq_init(struct vcmbox_softc *sc)
229 1.2 jmcneill {
230 1.2 jmcneill const struct sysctlnode *node, *cpunode, *freqnode;
231 1.2 jmcneill int error;
232 1.2 jmcneill
233 1.2 jmcneill error = vcmbox_read_clockrate(sc, VCPROPTAG_GET_MIN_CLOCKRATE,
234 1.2 jmcneill VCPROP_CLK_ARM, &sc->sc_cpu_minrate);
235 1.2 jmcneill if (error) {
236 1.2 jmcneill aprint_error_dev(sc->sc_dev, "couldn't read min clkrate (%d)\n",
237 1.2 jmcneill error);
238 1.2 jmcneill return error;
239 1.2 jmcneill }
240 1.2 jmcneill error = vcmbox_read_clockrate(sc, VCPROPTAG_GET_MAX_CLOCKRATE,
241 1.2 jmcneill VCPROP_CLK_ARM, &sc->sc_cpu_maxrate);
242 1.2 jmcneill if (error) {
243 1.2 jmcneill aprint_error_dev(sc->sc_dev, "couldn't read max clkrate (%d)\n",
244 1.2 jmcneill error);
245 1.2 jmcneill return error;
246 1.2 jmcneill }
247 1.2 jmcneill
248 1.2 jmcneill error = sysctl_createv(&sc->sc_log, 0, NULL, &node,
249 1.2 jmcneill CTLFLAG_PERMANENT, CTLTYPE_NODE, "machdep", NULL,
250 1.2 jmcneill NULL, 0, NULL, 0, CTL_MACHDEP, CTL_EOL);
251 1.2 jmcneill if (error)
252 1.2 jmcneill goto sysctl_failed;
253 1.2 jmcneill error = sysctl_createv(&sc->sc_log, 0, &node, &cpunode,
254 1.2 jmcneill 0, CTLTYPE_NODE, "cpu", NULL,
255 1.2 jmcneill NULL, 0, NULL, 0, CTL_CREATE, CTL_EOL);
256 1.2 jmcneill if (error)
257 1.2 jmcneill goto sysctl_failed;
258 1.2 jmcneill error = sysctl_createv(&sc->sc_log, 0, &cpunode, &freqnode,
259 1.2 jmcneill 0, CTLTYPE_NODE, "frequency", NULL,
260 1.2 jmcneill NULL, 0, NULL, 0, CTL_CREATE, CTL_EOL);
261 1.2 jmcneill if (error)
262 1.2 jmcneill goto sysctl_failed;
263 1.2 jmcneill
264 1.2 jmcneill error = sysctl_createv(&sc->sc_log, 0, &freqnode, &node,
265 1.2 jmcneill CTLFLAG_READWRITE, CTLTYPE_INT, "target", NULL,
266 1.2 jmcneill vcmbox_cpufreq_sysctl_helper, 0, (void *)sc, 0,
267 1.3 skrll CTL_CREATE, CTL_EOL);
268 1.2 jmcneill if (error)
269 1.2 jmcneill goto sysctl_failed;
270 1.2 jmcneill sc->sc_node_target = node->sysctl_num;
271 1.2 jmcneill
272 1.2 jmcneill error = sysctl_createv(&sc->sc_log, 0, &freqnode, &node,
273 1.2 jmcneill 0, CTLTYPE_INT, "current", NULL,
274 1.2 jmcneill vcmbox_cpufreq_sysctl_helper, 0, (void *)sc, 0,
275 1.3 skrll CTL_CREATE, CTL_EOL);
276 1.2 jmcneill if (error)
277 1.2 jmcneill goto sysctl_failed;
278 1.2 jmcneill sc->sc_node_current = node->sysctl_num;
279 1.2 jmcneill
280 1.2 jmcneill error = sysctl_createv(&sc->sc_log, 0, &freqnode, &node,
281 1.2 jmcneill 0, CTLTYPE_INT, "min", NULL,
282 1.2 jmcneill vcmbox_cpufreq_sysctl_helper, 0, (void *)sc, 0,
283 1.3 skrll CTL_CREATE, CTL_EOL);
284 1.2 jmcneill if (error)
285 1.2 jmcneill goto sysctl_failed;
286 1.2 jmcneill sc->sc_node_min = node->sysctl_num;
287 1.2 jmcneill
288 1.2 jmcneill error = sysctl_createv(&sc->sc_log, 0, &freqnode, &node,
289 1.2 jmcneill 0, CTLTYPE_INT, "max", NULL,
290 1.2 jmcneill vcmbox_cpufreq_sysctl_helper, 0, (void *)sc, 0,
291 1.3 skrll CTL_CREATE, CTL_EOL);
292 1.2 jmcneill if (error)
293 1.2 jmcneill goto sysctl_failed;
294 1.2 jmcneill sc->sc_node_max = node->sysctl_num;
295 1.2 jmcneill
296 1.2 jmcneill return 0;
297 1.2 jmcneill
298 1.2 jmcneill sysctl_failed:
299 1.2 jmcneill aprint_error_dev(sc->sc_dev, "couldn't create sysctl nodes (%d)\n",
300 1.2 jmcneill error);
301 1.2 jmcneill sysctl_teardown(&sc->sc_log);
302 1.2 jmcneill return error;
303 1.2 jmcneill }
304 1.2 jmcneill
305 1.2 jmcneill static int
306 1.2 jmcneill vcmbox_cpufreq_sysctl_helper(SYSCTLFN_ARGS)
307 1.2 jmcneill {
308 1.2 jmcneill struct sysctlnode node;
309 1.2 jmcneill struct vcmbox_softc *sc;
310 1.2 jmcneill int fq, oldfq = 0, error;
311 1.2 jmcneill uint32_t rate;
312 1.2 jmcneill
313 1.2 jmcneill node = *rnode;
314 1.2 jmcneill sc = node.sysctl_data;
315 1.2 jmcneill
316 1.2 jmcneill node.sysctl_data = &fq;
317 1.2 jmcneill
318 1.2 jmcneill if (rnode->sysctl_num == sc->sc_node_target ||
319 1.2 jmcneill rnode->sysctl_num == sc->sc_node_current) {
320 1.2 jmcneill error = vcmbox_read_clockrate(sc, VCPROPTAG_GET_CLOCKRATE,
321 1.2 jmcneill VCPROP_CLK_ARM, &rate);
322 1.2 jmcneill if (error)
323 1.2 jmcneill return error;
324 1.2 jmcneill fq = RATE2MHZ(rate);
325 1.2 jmcneill if (rnode->sysctl_num == sc->sc_node_target)
326 1.2 jmcneill oldfq = fq;
327 1.2 jmcneill } else if (rnode->sysctl_num == sc->sc_node_min) {
328 1.2 jmcneill fq = RATE2MHZ(sc->sc_cpu_minrate);
329 1.2 jmcneill } else if (rnode->sysctl_num == sc->sc_node_max) {
330 1.2 jmcneill fq = RATE2MHZ(sc->sc_cpu_maxrate);
331 1.2 jmcneill } else
332 1.2 jmcneill return EOPNOTSUPP;
333 1.2 jmcneill
334 1.2 jmcneill error = sysctl_lookup(SYSCTLFN_CALL(&node));
335 1.2 jmcneill if (error || newp == NULL)
336 1.2 jmcneill return error;
337 1.2 jmcneill
338 1.2 jmcneill if (fq == oldfq || rnode->sysctl_num != sc->sc_node_target)
339 1.2 jmcneill return 0;
340 1.2 jmcneill
341 1.2 jmcneill if (fq < RATE2MHZ(sc->sc_cpu_minrate))
342 1.2 jmcneill fq = RATE2MHZ(sc->sc_cpu_minrate);
343 1.2 jmcneill if (fq > RATE2MHZ(sc->sc_cpu_maxrate))
344 1.2 jmcneill fq = RATE2MHZ(sc->sc_cpu_maxrate);
345 1.2 jmcneill
346 1.2 jmcneill return vcmbox_write_clockrate(sc, VCPROPTAG_SET_CLOCKRATE,
347 1.2 jmcneill VCPROP_CLK_ARM, MHZ2RATE(fq));
348 1.2 jmcneill }
349 1.2 jmcneill
350 1.1 jmcneill static void
351 1.1 jmcneill vcmbox_create_sensors(struct vcmbox_softc *sc)
352 1.1 jmcneill {
353 1.1 jmcneill uint32_t val;
354 1.1 jmcneill
355 1.1 jmcneill sc->sc_sensor[VCMBOX_SENSOR_TEMP].sensor = VCMBOX_SENSOR_TEMP;
356 1.1 jmcneill sc->sc_sensor[VCMBOX_SENSOR_TEMP].units = ENVSYS_STEMP;
357 1.1 jmcneill sc->sc_sensor[VCMBOX_SENSOR_TEMP].state = ENVSYS_SINVALID;
358 1.1 jmcneill sc->sc_sensor[VCMBOX_SENSOR_TEMP].flags = ENVSYS_FHAS_ENTROPY;
359 1.1 jmcneill strlcpy(sc->sc_sensor[VCMBOX_SENSOR_TEMP].desc,
360 1.1 jmcneill vcmbox_sensor_name[VCMBOX_SENSOR_TEMP],
361 1.1 jmcneill sizeof(sc->sc_sensor[VCMBOX_SENSOR_TEMP].desc));
362 1.1 jmcneill if (vcmbox_read_temp(sc, VCPROPTAG_GET_MAX_TEMPERATURE,
363 1.1 jmcneill vcmbox_sensor_id[VCMBOX_SENSOR_TEMP], &val) == 0) {
364 1.3 skrll sc->sc_sensor[VCMBOX_SENSOR_TEMP].value_max =
365 1.1 jmcneill val * 1000 + 273150000;
366 1.1 jmcneill sc->sc_sensor[VCMBOX_SENSOR_TEMP].flags |= ENVSYS_FVALID_MAX;
367 1.1 jmcneill }
368 1.1 jmcneill sysmon_envsys_sensor_attach(sc->sc_sme,
369 1.1 jmcneill &sc->sc_sensor[VCMBOX_SENSOR_TEMP]);
370 1.1 jmcneill }
371 1.1 jmcneill
372 1.1 jmcneill static void
373 1.1 jmcneill vcmbox_sensor_get_limits(struct sysmon_envsys *sme, envsys_data_t *edata,
374 1.1 jmcneill sysmon_envsys_lim_t *limits, uint32_t *props)
375 1.1 jmcneill {
376 1.1 jmcneill struct vcmbox_softc *sc = sme->sme_cookie;
377 1.1 jmcneill uint32_t val;
378 1.1 jmcneill
379 1.1 jmcneill *props = 0;
380 1.1 jmcneill
381 1.1 jmcneill if (edata->units == ENVSYS_STEMP) {
382 1.1 jmcneill if (vcmbox_read_temp(sc, VCPROPTAG_GET_MAX_TEMPERATURE,
383 1.1 jmcneill vcmbox_sensor_id[edata->sensor], &val))
384 1.1 jmcneill return;
385 1.1 jmcneill *props = PROP_CRITMAX;
386 1.1 jmcneill limits->sel_critmax = val * 1000 + 273150000;
387 1.1 jmcneill }
388 1.1 jmcneill }
389 1.1 jmcneill
390 1.1 jmcneill static void
391 1.1 jmcneill vcmbox_sensor_refresh(struct sysmon_envsys *sme, envsys_data_t *edata)
392 1.1 jmcneill {
393 1.1 jmcneill struct vcmbox_softc *sc = sme->sme_cookie;
394 1.1 jmcneill uint32_t val;
395 1.1 jmcneill
396 1.1 jmcneill edata->state = ENVSYS_SINVALID;
397 1.1 jmcneill
398 1.1 jmcneill if (edata->units == ENVSYS_STEMP) {
399 1.1 jmcneill if (vcmbox_read_temp(sc, VCPROPTAG_GET_TEMPERATURE,
400 1.1 jmcneill vcmbox_sensor_id[edata->sensor], &val))
401 1.1 jmcneill return;
402 1.1 jmcneill
403 1.1 jmcneill edata->value_cur = val * 1000 + 273150000;
404 1.1 jmcneill edata->state = ENVSYS_SVALID;
405 1.1 jmcneill }
406 1.1 jmcneill }
407