Lines Matching +full:high +full:- +full:resolution
1 /*-
3 * Copyright (c) 2013-2014 Luiz Otavio O Souza <loos@freebsd.org>
64 #define LM75_MIN_TEMP -55
138 return (-1); in lm75_read()
151 return (-1); in lm75_write()
165 sc->sc_max_resolution = 9; in lm75_probe()
173 switch (compat_ptr->ocd_data){ in lm75_probe()
175 sc->sc_max_resolution = 9; in lm75_probe()
178 sc->sc_max_resolution = 11; in lm75_probe()
195 sc->sc_dev = dev; in lm75_attach()
196 sc->sc_addr = iicbus_get_addr(dev); in lm75_attach()
198 sc->enum_hook.ich_func = lm75_start; in lm75_attach()
199 sc->enum_hook.ich_arg = dev; in lm75_attach()
201 switch (sc->sc_max_resolution) { in lm75_attach()
203 sc->sc_resolution = 9; in lm75_attach()
204 sc->sc_max_resolution = 9; in lm75_attach()
205 sc->sc_multiplier = 10; in lm75_attach()
208 sc->sc_resolution = 11; in lm75_attach()
209 sc->sc_max_resolution = 11; in lm75_attach()
210 sc->sc_multiplier = 1000; in lm75_attach()
220 if (config_intrhook_establish(&sc->enum_hook) != 0) in lm75_attach()
235 return (-1); in lm75_type_detect()
236 conf = sc->sc_conf; in lm75_type_detect()
242 sc->sc_conf = LM75_TEST_PATTERN; in lm75_type_detect()
244 return (-1); in lm75_type_detect()
251 return (-1); in lm75_type_detect()
252 if (sc->sc_conf != LM75_TEST_PATTERN) in lm75_type_detect()
253 return (-1); in lm75_type_detect()
258 * LM75 will return the last read value - our test pattern written to in lm75_type_detect()
263 if (lm75_read(sc->sc_dev, sc->sc_addr, i, in lm75_type_detect()
265 return (-1); in lm75_type_detect()
267 return (-1); in lm75_type_detect()
272 sc->sc_multiplier = 1000; in lm75_type_detect()
273 sc->sc_resolution = 11; in lm75_type_detect()
274 sc->sc_max_resolution = 11; in lm75_type_detect()
278 sc->sc_conf = conf; in lm75_type_detect()
280 return (-1); in lm75_type_detect()
301 config_intrhook_disestablish(&sc->enum_hook); in lm75_start()
314 device_printf(dev,"%d bit resolution sensor attached.\n", in lm75_start()
315 sc->sc_resolution); in lm75_start()
317 if (sc->sc_multiplier == 1000) in lm75_start()
346 SYSCTL_ADD_PROC(ctx, tree, OID_AUTO, "resolution", in lm75_start()
348 lm75_resolution_sysctl, "IU", "LM75 resolution"); in lm75_start()
356 if (lm75_read(sc->sc_dev, sc->sc_addr, LM75_CONF, in lm75_conf_read()
358 return (-1); in lm75_conf_read()
359 sc->sc_conf = (uint32_t)buf8; in lm75_conf_read()
370 buf8[1] = (uint8_t)sc->sc_conf & LM75_CONF_MASK; in lm75_conf_write()
371 if (lm75_write(sc->sc_dev, sc->sc_addr, buf8, sizeof(buf8)) < 0) in lm75_conf_write()
372 return (-1); in lm75_conf_write()
382 uint8_t resolution = sc->sc_resolution; in lm75_temp_read() local
383 uint16_t multiplier = sc->sc_multiplier; in lm75_temp_read()
385 if (lm75_read(sc->sc_dev, sc->sc_addr, reg, buf8, sizeof(buf8)) < 0) in lm75_temp_read()
386 return (-1); in lm75_temp_read()
389 *temp = ((buf >> (16 - resolution)) * multiplier) >> (resolution - 8); in lm75_temp_read()
391 *temp += TZ_ZEROC * sc->sc_multiplier / TZ_ZEROC_DIVIDER; in lm75_temp_read()
400 uint8_t buf8[3], resolution = sc->sc_resolution; in lm75_temp_write() local
401 uint16_t multiplier = sc->sc_multiplier; in lm75_temp_write()
403 temp -= TZ_ZEROC * multiplier / TZ_ZEROC_DIVIDER; in lm75_temp_write()
409 buf = ((temp << (resolution - 8)) / multiplier) << (16 - resolution); in lm75_temp_write()
415 if (lm75_write(sc->sc_dev, sc->sc_addr, buf8, sizeof(buf8)) < 0) in lm75_temp_write()
416 return (-1); in lm75_temp_write()
426 rtrn = -1; in lm75_str_mode()
441 rtrn = -1; in lm75_str_pol()
443 if (len > 1 && strncasecmp("high", buf, len) == 0) in lm75_str_pol()
447 else if (len > 8 && strncasecmp("active-high", buf, len) == 0) in lm75_str_pol()
449 else if (len > 8 && strncasecmp("active-low", buf, len) == 0) in lm75_str_pol()
472 if (error != 0 || req->newptr == NULL) in lm75_temp_sysctl()
491 tmp = (sc->sc_conf & LM75_CONF_FAULT) >> LM75_CONF_FSHIFT; in lm75_faults_sysctl()
493 tmp = nitems(lm75_faults) - 1; in lm75_faults_sysctl()
497 if (error != 0 || req->newptr == NULL) in lm75_faults_sysctl()
505 sc->sc_conf &= ~LM75_CONF_FAULT; in lm75_faults_sysctl()
506 sc->sc_conf |= newf << LM75_CONF_FSHIFT; in lm75_faults_sysctl()
524 if (sc->sc_conf & LM75_CONF_MODE) { in lm75_mode_sysctl()
533 if (error != 0 || req->newptr == NULL) in lm75_mode_sysctl()
537 if (newm != -1 && mode != newm) { in lm75_mode_sysctl()
538 sc->sc_conf &= ~LM75_CONF_MODE; in lm75_mode_sysctl()
540 sc->sc_conf |= LM75_CONF_MODE; in lm75_mode_sysctl()
558 if (sc->sc_conf & LM75_CONF_POL) { in lm75_pol_sysctl()
560 strlcpy(buf, "active-high", sizeof(buf)); in lm75_pol_sysctl()
563 strlcpy(buf, "active-low", sizeof(buf)); in lm75_pol_sysctl()
567 if (error != 0 || req->newptr == NULL) in lm75_pol_sysctl()
571 if (newp != -1 && pol != newp) { in lm75_pol_sysctl()
572 sc->sc_conf &= ~LM75_CONF_POL; in lm75_pol_sysctl()
574 sc->sc_conf |= LM75_CONF_POL; in lm75_pol_sysctl()
591 tmp = shutdown = (sc->sc_conf & LM75_CONF_SHUTD) ? 1 : 0; in lm75_shutdown_sysctl()
594 if (error != 0 || req->newptr == NULL) in lm75_shutdown_sysctl()
598 sc->sc_conf &= ~LM75_CONF_SHUTD; in lm75_shutdown_sysctl()
600 sc->sc_conf |= LM75_CONF_SHUTD; in lm75_shutdown_sysctl()
614 int resolution; in lm75_resolution_sysctl() local
618 resolution = sc->sc_resolution; in lm75_resolution_sysctl()
620 error = sysctl_handle_int(oidp, &resolution, 0, req); in lm75_resolution_sysctl()
621 if (error != 0 || req->newptr == NULL) in lm75_resolution_sysctl()
624 if (resolution > sc->sc_max_resolution || resolution < 9) in lm75_resolution_sysctl()
627 sc->sc_resolution = (uint8_t) resolution; in lm75_resolution_sysctl()