rpi_vcmbox.c revision 1.4 1 1.4 mlelstv /* $NetBSD: rpi_vcmbox.c,v 1.4 2014/10/04 13:18:34 mlelstv 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.4 mlelstv __KERNEL_RCSID(0, "$NetBSD: rpi_vcmbox.c,v 1.4 2014/10/04 13:18:34 mlelstv 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.4 mlelstv if (sysmon_envsys_register(sc->sc_sme) == 0)
156 1.4 mlelstv return;
157 1.4 mlelstv
158 1.4 mlelstv aprint_error_dev(self, "unable to register with sysmon\n");
159 1.4 mlelstv sysmon_envsys_destroy(sc->sc_sme);
160 1.1 jmcneill }
161 1.1 jmcneill
162 1.2 jmcneill static int
163 1.2 jmcneill vcmbox_read_temp(struct vcmbox_softc *sc, uint32_t tag, int id, uint32_t *val)
164 1.2 jmcneill {
165 1.2 jmcneill struct vcmbox_temp_request vb;
166 1.2 jmcneill uint32_t res;
167 1.2 jmcneill int error;
168 1.2 jmcneill
169 1.2 jmcneill VCMBOX_INIT_REQUEST(vb);
170 1.2 jmcneill VCMBOX_INIT_TAG(vb.vbt_temp, tag);
171 1.2 jmcneill vb.vbt_temp.id = id;
172 1.2 jmcneill error = bcmmbox_request(BCMMBOX_CHANARM2VC, &vb, sizeof(vb), &res);
173 1.2 jmcneill if (error)
174 1.2 jmcneill return error;
175 1.2 jmcneill if (!vcprop_buffer_success_p(&vb.vb_hdr) ||
176 1.2 jmcneill !vcprop_tag_success_p(&vb.vbt_temp.tag)) {
177 1.2 jmcneill return EIO;
178 1.2 jmcneill }
179 1.2 jmcneill *val = vb.vbt_temp.value;
180 1.2 jmcneill
181 1.2 jmcneill return 0;
182 1.2 jmcneill }
183 1.2 jmcneill
184 1.2 jmcneill static int
185 1.2 jmcneill vcmbox_read_clockrate(struct vcmbox_softc *sc, uint32_t tag, int id,
186 1.2 jmcneill uint32_t *val)
187 1.2 jmcneill {
188 1.2 jmcneill struct vcmbox_clockrate_request vb;
189 1.2 jmcneill uint32_t res;
190 1.2 jmcneill int error;
191 1.2 jmcneill
192 1.2 jmcneill VCMBOX_INIT_REQUEST(vb);
193 1.2 jmcneill VCMBOX_INIT_TAG(vb.vbt_clockrate, tag);
194 1.2 jmcneill vb.vbt_clockrate.id = id;
195 1.2 jmcneill error = bcmmbox_request(BCMMBOX_CHANARM2VC, &vb, sizeof(vb), &res);
196 1.2 jmcneill if (error)
197 1.2 jmcneill return error;
198 1.2 jmcneill if (!vcprop_buffer_success_p(&vb.vb_hdr) ||
199 1.2 jmcneill !vcprop_tag_success_p(&vb.vbt_clockrate.tag)) {
200 1.2 jmcneill return EIO;
201 1.2 jmcneill }
202 1.2 jmcneill *val = vb.vbt_clockrate.rate;
203 1.2 jmcneill
204 1.2 jmcneill return 0;
205 1.2 jmcneill }
206 1.2 jmcneill
207 1.2 jmcneill static int
208 1.2 jmcneill vcmbox_write_clockrate(struct vcmbox_softc *sc, uint32_t tag, int id,
209 1.2 jmcneill uint32_t val)
210 1.2 jmcneill {
211 1.2 jmcneill struct vcmbox_clockrate_request vb;
212 1.2 jmcneill uint32_t res;
213 1.2 jmcneill int error;
214 1.2 jmcneill
215 1.2 jmcneill VCMBOX_INIT_REQUEST(vb);
216 1.2 jmcneill VCMBOX_INIT_TAG(vb.vbt_clockrate, tag);
217 1.2 jmcneill vb.vbt_clockrate.id = id;
218 1.2 jmcneill vb.vbt_clockrate.rate = val;
219 1.2 jmcneill error = bcmmbox_request(BCMMBOX_CHANARM2VC, &vb, sizeof(vb), &res);
220 1.2 jmcneill if (error)
221 1.2 jmcneill return error;
222 1.2 jmcneill if (!vcprop_buffer_success_p(&vb.vb_hdr) ||
223 1.2 jmcneill !vcprop_tag_success_p(&vb.vbt_clockrate.tag)) {
224 1.2 jmcneill return EIO;
225 1.2 jmcneill }
226 1.2 jmcneill
227 1.2 jmcneill return 0;
228 1.2 jmcneill }
229 1.2 jmcneill
230 1.2 jmcneill
231 1.2 jmcneill static int
232 1.2 jmcneill vcmbox_cpufreq_init(struct vcmbox_softc *sc)
233 1.2 jmcneill {
234 1.2 jmcneill const struct sysctlnode *node, *cpunode, *freqnode;
235 1.2 jmcneill int error;
236 1.2 jmcneill
237 1.2 jmcneill error = vcmbox_read_clockrate(sc, VCPROPTAG_GET_MIN_CLOCKRATE,
238 1.2 jmcneill VCPROP_CLK_ARM, &sc->sc_cpu_minrate);
239 1.2 jmcneill if (error) {
240 1.2 jmcneill aprint_error_dev(sc->sc_dev, "couldn't read min clkrate (%d)\n",
241 1.2 jmcneill error);
242 1.2 jmcneill return error;
243 1.2 jmcneill }
244 1.2 jmcneill error = vcmbox_read_clockrate(sc, VCPROPTAG_GET_MAX_CLOCKRATE,
245 1.2 jmcneill VCPROP_CLK_ARM, &sc->sc_cpu_maxrate);
246 1.2 jmcneill if (error) {
247 1.2 jmcneill aprint_error_dev(sc->sc_dev, "couldn't read max clkrate (%d)\n",
248 1.2 jmcneill error);
249 1.2 jmcneill return error;
250 1.2 jmcneill }
251 1.2 jmcneill
252 1.2 jmcneill error = sysctl_createv(&sc->sc_log, 0, NULL, &node,
253 1.2 jmcneill CTLFLAG_PERMANENT, CTLTYPE_NODE, "machdep", NULL,
254 1.2 jmcneill NULL, 0, NULL, 0, CTL_MACHDEP, CTL_EOL);
255 1.2 jmcneill if (error)
256 1.2 jmcneill goto sysctl_failed;
257 1.2 jmcneill error = sysctl_createv(&sc->sc_log, 0, &node, &cpunode,
258 1.2 jmcneill 0, CTLTYPE_NODE, "cpu", NULL,
259 1.2 jmcneill NULL, 0, NULL, 0, CTL_CREATE, CTL_EOL);
260 1.2 jmcneill if (error)
261 1.2 jmcneill goto sysctl_failed;
262 1.2 jmcneill error = sysctl_createv(&sc->sc_log, 0, &cpunode, &freqnode,
263 1.2 jmcneill 0, CTLTYPE_NODE, "frequency", NULL,
264 1.2 jmcneill NULL, 0, NULL, 0, CTL_CREATE, CTL_EOL);
265 1.2 jmcneill if (error)
266 1.2 jmcneill goto sysctl_failed;
267 1.2 jmcneill
268 1.2 jmcneill error = sysctl_createv(&sc->sc_log, 0, &freqnode, &node,
269 1.2 jmcneill CTLFLAG_READWRITE, CTLTYPE_INT, "target", NULL,
270 1.2 jmcneill vcmbox_cpufreq_sysctl_helper, 0, (void *)sc, 0,
271 1.3 skrll CTL_CREATE, CTL_EOL);
272 1.2 jmcneill if (error)
273 1.2 jmcneill goto sysctl_failed;
274 1.2 jmcneill sc->sc_node_target = node->sysctl_num;
275 1.2 jmcneill
276 1.2 jmcneill error = sysctl_createv(&sc->sc_log, 0, &freqnode, &node,
277 1.2 jmcneill 0, CTLTYPE_INT, "current", NULL,
278 1.2 jmcneill vcmbox_cpufreq_sysctl_helper, 0, (void *)sc, 0,
279 1.3 skrll CTL_CREATE, CTL_EOL);
280 1.2 jmcneill if (error)
281 1.2 jmcneill goto sysctl_failed;
282 1.2 jmcneill sc->sc_node_current = node->sysctl_num;
283 1.2 jmcneill
284 1.2 jmcneill error = sysctl_createv(&sc->sc_log, 0, &freqnode, &node,
285 1.2 jmcneill 0, CTLTYPE_INT, "min", NULL,
286 1.2 jmcneill vcmbox_cpufreq_sysctl_helper, 0, (void *)sc, 0,
287 1.3 skrll CTL_CREATE, CTL_EOL);
288 1.2 jmcneill if (error)
289 1.2 jmcneill goto sysctl_failed;
290 1.2 jmcneill sc->sc_node_min = node->sysctl_num;
291 1.2 jmcneill
292 1.2 jmcneill error = sysctl_createv(&sc->sc_log, 0, &freqnode, &node,
293 1.2 jmcneill 0, CTLTYPE_INT, "max", NULL,
294 1.2 jmcneill vcmbox_cpufreq_sysctl_helper, 0, (void *)sc, 0,
295 1.3 skrll CTL_CREATE, CTL_EOL);
296 1.2 jmcneill if (error)
297 1.2 jmcneill goto sysctl_failed;
298 1.2 jmcneill sc->sc_node_max = node->sysctl_num;
299 1.2 jmcneill
300 1.2 jmcneill return 0;
301 1.2 jmcneill
302 1.2 jmcneill sysctl_failed:
303 1.2 jmcneill aprint_error_dev(sc->sc_dev, "couldn't create sysctl nodes (%d)\n",
304 1.2 jmcneill error);
305 1.2 jmcneill sysctl_teardown(&sc->sc_log);
306 1.2 jmcneill return error;
307 1.2 jmcneill }
308 1.2 jmcneill
309 1.2 jmcneill static int
310 1.2 jmcneill vcmbox_cpufreq_sysctl_helper(SYSCTLFN_ARGS)
311 1.2 jmcneill {
312 1.2 jmcneill struct sysctlnode node;
313 1.2 jmcneill struct vcmbox_softc *sc;
314 1.2 jmcneill int fq, oldfq = 0, error;
315 1.2 jmcneill uint32_t rate;
316 1.2 jmcneill
317 1.2 jmcneill node = *rnode;
318 1.2 jmcneill sc = node.sysctl_data;
319 1.2 jmcneill
320 1.2 jmcneill node.sysctl_data = &fq;
321 1.2 jmcneill
322 1.2 jmcneill if (rnode->sysctl_num == sc->sc_node_target ||
323 1.2 jmcneill rnode->sysctl_num == sc->sc_node_current) {
324 1.2 jmcneill error = vcmbox_read_clockrate(sc, VCPROPTAG_GET_CLOCKRATE,
325 1.2 jmcneill VCPROP_CLK_ARM, &rate);
326 1.2 jmcneill if (error)
327 1.2 jmcneill return error;
328 1.2 jmcneill fq = RATE2MHZ(rate);
329 1.2 jmcneill if (rnode->sysctl_num == sc->sc_node_target)
330 1.2 jmcneill oldfq = fq;
331 1.2 jmcneill } else if (rnode->sysctl_num == sc->sc_node_min) {
332 1.2 jmcneill fq = RATE2MHZ(sc->sc_cpu_minrate);
333 1.2 jmcneill } else if (rnode->sysctl_num == sc->sc_node_max) {
334 1.2 jmcneill fq = RATE2MHZ(sc->sc_cpu_maxrate);
335 1.2 jmcneill } else
336 1.2 jmcneill return EOPNOTSUPP;
337 1.2 jmcneill
338 1.2 jmcneill error = sysctl_lookup(SYSCTLFN_CALL(&node));
339 1.2 jmcneill if (error || newp == NULL)
340 1.2 jmcneill return error;
341 1.2 jmcneill
342 1.2 jmcneill if (fq == oldfq || rnode->sysctl_num != sc->sc_node_target)
343 1.2 jmcneill return 0;
344 1.2 jmcneill
345 1.2 jmcneill if (fq < RATE2MHZ(sc->sc_cpu_minrate))
346 1.2 jmcneill fq = RATE2MHZ(sc->sc_cpu_minrate);
347 1.2 jmcneill if (fq > RATE2MHZ(sc->sc_cpu_maxrate))
348 1.2 jmcneill fq = RATE2MHZ(sc->sc_cpu_maxrate);
349 1.2 jmcneill
350 1.2 jmcneill return vcmbox_write_clockrate(sc, VCPROPTAG_SET_CLOCKRATE,
351 1.2 jmcneill VCPROP_CLK_ARM, MHZ2RATE(fq));
352 1.2 jmcneill }
353 1.2 jmcneill
354 1.1 jmcneill static void
355 1.1 jmcneill vcmbox_create_sensors(struct vcmbox_softc *sc)
356 1.1 jmcneill {
357 1.1 jmcneill uint32_t val;
358 1.1 jmcneill
359 1.1 jmcneill sc->sc_sensor[VCMBOX_SENSOR_TEMP].sensor = VCMBOX_SENSOR_TEMP;
360 1.1 jmcneill sc->sc_sensor[VCMBOX_SENSOR_TEMP].units = ENVSYS_STEMP;
361 1.1 jmcneill sc->sc_sensor[VCMBOX_SENSOR_TEMP].state = ENVSYS_SINVALID;
362 1.4 mlelstv sc->sc_sensor[VCMBOX_SENSOR_TEMP].flags = ENVSYS_FMONLIMITS |
363 1.4 mlelstv ENVSYS_FHAS_ENTROPY;
364 1.1 jmcneill strlcpy(sc->sc_sensor[VCMBOX_SENSOR_TEMP].desc,
365 1.1 jmcneill vcmbox_sensor_name[VCMBOX_SENSOR_TEMP],
366 1.1 jmcneill sizeof(sc->sc_sensor[VCMBOX_SENSOR_TEMP].desc));
367 1.1 jmcneill if (vcmbox_read_temp(sc, VCPROPTAG_GET_MAX_TEMPERATURE,
368 1.1 jmcneill vcmbox_sensor_id[VCMBOX_SENSOR_TEMP], &val) == 0) {
369 1.3 skrll sc->sc_sensor[VCMBOX_SENSOR_TEMP].value_max =
370 1.1 jmcneill val * 1000 + 273150000;
371 1.1 jmcneill sc->sc_sensor[VCMBOX_SENSOR_TEMP].flags |= ENVSYS_FVALID_MAX;
372 1.1 jmcneill }
373 1.1 jmcneill sysmon_envsys_sensor_attach(sc->sc_sme,
374 1.1 jmcneill &sc->sc_sensor[VCMBOX_SENSOR_TEMP]);
375 1.1 jmcneill }
376 1.1 jmcneill
377 1.1 jmcneill static void
378 1.1 jmcneill vcmbox_sensor_get_limits(struct sysmon_envsys *sme, envsys_data_t *edata,
379 1.1 jmcneill sysmon_envsys_lim_t *limits, uint32_t *props)
380 1.1 jmcneill {
381 1.1 jmcneill struct vcmbox_softc *sc = sme->sme_cookie;
382 1.1 jmcneill uint32_t val;
383 1.1 jmcneill
384 1.1 jmcneill *props = 0;
385 1.1 jmcneill
386 1.1 jmcneill if (edata->units == ENVSYS_STEMP) {
387 1.1 jmcneill if (vcmbox_read_temp(sc, VCPROPTAG_GET_MAX_TEMPERATURE,
388 1.1 jmcneill vcmbox_sensor_id[edata->sensor], &val))
389 1.1 jmcneill return;
390 1.1 jmcneill *props = PROP_CRITMAX;
391 1.1 jmcneill limits->sel_critmax = val * 1000 + 273150000;
392 1.1 jmcneill }
393 1.1 jmcneill }
394 1.1 jmcneill
395 1.1 jmcneill static void
396 1.1 jmcneill vcmbox_sensor_refresh(struct sysmon_envsys *sme, envsys_data_t *edata)
397 1.1 jmcneill {
398 1.1 jmcneill struct vcmbox_softc *sc = sme->sme_cookie;
399 1.1 jmcneill uint32_t val;
400 1.1 jmcneill
401 1.1 jmcneill edata->state = ENVSYS_SINVALID;
402 1.1 jmcneill
403 1.1 jmcneill if (edata->units == ENVSYS_STEMP) {
404 1.1 jmcneill if (vcmbox_read_temp(sc, VCPROPTAG_GET_TEMPERATURE,
405 1.1 jmcneill vcmbox_sensor_id[edata->sensor], &val))
406 1.1 jmcneill return;
407 1.1 jmcneill
408 1.1 jmcneill edata->value_cur = val * 1000 + 273150000;
409 1.1 jmcneill edata->state = ENVSYS_SVALID;
410 1.1 jmcneill }
411 1.1 jmcneill }
412