![]() |
|
|||
0001 /* SPDX-License-Identifier: GPL-2.0-or-later */ 0002 /* 0003 * lm75.h - Part of lm_sensors, Linux kernel modules for hardware monitoring 0004 * Copyright (c) 2003 Mark M. Hoffman <mhoffman@lightlink.com> 0005 */ 0006 0007 /* 0008 * This file contains common code for encoding/decoding LM75 type 0009 * temperature readings, which are emulated by many of the chips 0010 * we support. As the user is unlikely to load more than one driver 0011 * which contains this code, we don't worry about the wasted space. 0012 */ 0013 0014 #include <linux/minmax.h> 0015 #include <linux/types.h> 0016 0017 /* straight from the datasheet */ 0018 #define LM75_TEMP_MIN (-55000) 0019 #define LM75_TEMP_MAX 125000 0020 #define LM75_SHUTDOWN 0x01 0021 0022 /* 0023 * TEMP: 0.001C/bit (-55C to +125C) 0024 * REG: (0.5C/bit, two's complement) << 7 0025 */ 0026 static inline u16 LM75_TEMP_TO_REG(long temp) 0027 { 0028 int ntemp = clamp_val(temp, LM75_TEMP_MIN, LM75_TEMP_MAX); 0029 0030 ntemp += (ntemp < 0 ? -250 : 250); 0031 return (u16)((ntemp / 500) << 7); 0032 } 0033 0034 static inline int LM75_TEMP_FROM_REG(u16 reg) 0035 { 0036 /* 0037 * use integer division instead of equivalent right shift to 0038 * guarantee arithmetic shift and preserve the sign 0039 */ 0040 return ((s16)reg / 128) * 500; 0041 }
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |
![]() ![]() |