lm75.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. lm75.h - Part of lm_sensors, Linux kernel modules for hardware
  3. monitoring
  4. Copyright (c) 2003 Mark M. Hoffman <mhoffman@lightlink.com>
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. */
  17. /*
  18. This file contains common code for encoding/decoding LM75 type
  19. temperature readings, which are emulated by many of the chips
  20. we support. As the user is unlikely to load more than one driver
  21. which contains this code, we don't worry about the wasted space.
  22. */
  23. #include <linux/hwmon.h>
  24. /* straight from the datasheet */
  25. #define LM75_TEMP_MIN (-55000)
  26. #define LM75_TEMP_MAX 125000
  27. #define LM75_SHUTDOWN 0x01
  28. /* TEMP: 0.001C/bit (-55C to +125C)
  29. REG: (0.5C/bit, two's complement) << 7 */
  30. static inline u16 LM75_TEMP_TO_REG(long temp)
  31. {
  32. int ntemp = SENSORS_LIMIT(temp, LM75_TEMP_MIN, LM75_TEMP_MAX);
  33. ntemp += (ntemp<0 ? -250 : 250);
  34. return (u16)((ntemp / 500) << 7);
  35. }
  36. static inline int LM75_TEMP_FROM_REG(u16 reg)
  37. {
  38. /* use integer division instead of equivalent right shift to
  39. guarantee arithmetic shift and preserve the sign */
  40. return ((s16)reg / 128) * 500;
  41. }