mirror of
https://github.com/lm-sensors/lm-sensors.git
synced 2026-10-16 10:49:31 +00:00
header and gave them the prefix LM75_. Also rewrote them according to the lm75 datasheet. The next step is to replace all the various scattered (broken?) copies of these functions (especially in Winbond subclients) with this one. git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@2130 7894878c-1315-0410-8ee3-d5d059ff63e0
50 lines
1.7 KiB
C
50 lines
1.7 KiB
C
/*
|
|
lm75.h - Part of lm_sensors, Linux kernel modules for hardware
|
|
monitoring
|
|
Copyright (c) 2003 Mark M. Hoffman <mhoffman@lightlink.com>
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program; if not, write to the Free Software
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
*/
|
|
|
|
/*
|
|
This file contains common code for encoding/decoding LM75 type
|
|
temperature readings, which are emulated by many of the chips
|
|
we support. As the user is unlikely to load more than one driver
|
|
which contains this code, we don't worry about the wasted space.
|
|
*/
|
|
|
|
#include <linux/i2c-proc.h>
|
|
|
|
/* straight from the datasheet */
|
|
#define LM75_TEMP_MIN (-550)
|
|
#define LM75_TEMP_MAX 1250
|
|
|
|
/* TEMP: 0.1C/bit (-55C to +125C)
|
|
REG: (0.5C/bit, two's complement) << 7 */
|
|
static inline u16 LM75_TEMP_TO_REG(int temp)
|
|
{
|
|
int ntemp = SENSORS_LIMIT(temp, LM75_TEMP_MIN, LM75_TEMP_MAX);
|
|
ntemp += (ntemp<0 ? -2 : 2);
|
|
return (u16)((ntemp / 5) << 7);
|
|
}
|
|
|
|
static inline int LM75_TEMP_FROM_REG(u16 reg)
|
|
{
|
|
/* use integer division instead of equivalent right shift to
|
|
guarantee arithmetic shift and preserve the sign */
|
|
return ((s16)reg / 128) * 5;
|
|
}
|
|
|