1 --- linux-2.6.0-test11-mmh/drivers/i2c/chips/lm75.c.old 2003-12-14 18:02:18.000000000 -0500
2 +++ linux-2.6.0-test11-mmh/drivers/i2c/chips/lm75.c 2003-12-14 19:28:08.000000000 -0500
4 #include <linux/slab.h>
6 #include <linux/i2c-sensor.h>
10 /* Addresses to scan */
12 #define LM75_REG_TEMP_HYST 0x02
13 #define LM75_REG_TEMP_OS 0x03
15 -/* Conversions. Rounding and limit checking is only done on the TO_REG
16 - variants. Note that you should be a bit careful with which arguments
17 - these macros are called: arguments may be evaluated more than once.
18 - Fixing this is just not worth it. */
19 -#define TEMP_FROM_REG(val) ((((val & 0x7fff) >> 7) * 5) | ((val & 0x8000)?-256:0))
20 -#define TEMP_TO_REG(val) (SENSORS_LIMIT((val<0?(0x200+((val)/5))<<7:(((val) + 2) / 5) << 7),0,0xffff))
22 /* Each client has this additional data */
24 struct semaphore update_lock;
26 static int lm75_id = 0;
29 -static ssize_t show_##value(struct device *dev, char *buf) \
31 - struct i2c_client *client = to_i2c_client(dev); \
32 - struct lm75_data *data = i2c_get_clientdata(client); \
35 - lm75_update_client(client); \
36 - temp = TEMP_FROM_REG(data->value); \
37 - return sprintf(buf, "%d\n", temp * 100); \
38 +static ssize_t show_##value(struct device *dev, char *buf) \
40 + struct i2c_client *client = to_i2c_client(dev); \
41 + struct lm75_data *data = i2c_get_clientdata(client); \
42 + lm75_update_client(client); \
43 + return sprintf(buf, "%d\n", LM75_TEMP_FROM_REG(data->value)); \
49 struct i2c_client *client = to_i2c_client(dev); \
50 struct lm75_data *data = i2c_get_clientdata(client); \
51 - int temp = simple_strtoul(buf, NULL, 10) / 100; \
53 - data->value = TEMP_TO_REG(temp); \
54 + int temp = simple_strtoul(buf, NULL, 10); \
55 + data->value = LM75_TEMP_TO_REG(temp); \
56 lm75_write_value(client, reg, data->value); \
59 --- linux-2.6.0-test11-mmh/drivers/i2c/chips/lm75.h.old 2003-12-14 18:05:09.000000000 -0500
60 +++ linux-2.6.0-test11-mmh/drivers/i2c/chips/lm75.h 2003-12-14 18:32:46.000000000 -0500
63 + lm75.h - Part of lm_sensors, Linux kernel modules for hardware
65 + Copyright (c) 2003 Mark M. Hoffman <mhoffman@lightlink.com>
67 + This program is free software; you can redistribute it and/or modify
68 + it under the terms of the GNU General Public License as published by
69 + the Free Software Foundation; either version 2 of the License, or
70 + (at your option) any later version.
72 + This program is distributed in the hope that it will be useful,
73 + but WITHOUT ANY WARRANTY; without even the implied warranty of
74 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
75 + GNU General Public License for more details.
77 + You should have received a copy of the GNU General Public License
78 + along with this program; if not, write to the Free Software
79 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
83 + This file contains common code for encoding/decoding LM75 type
84 + temperature readings, which are emulated by many of the chips
85 + we support. As the user is unlikely to load more than one driver
86 + which contains this code, we don't worry about the wasted space.
89 +#include <linux/i2c-sensor.h>
91 +/* straight from the datasheet */
92 +#define LM75_TEMP_MIN (-55000)
93 +#define LM75_TEMP_MAX 125000
95 +/* TEMP: 0.001C/bit (-55C to +125C)
96 + REG: (0.5C/bit, two's complement) << 7 */
97 +static inline u16 LM75_TEMP_TO_REG(int temp)
99 + int ntemp = SENSORS_LIMIT(temp, LM75_TEMP_MIN, LM75_TEMP_MAX);
100 + ntemp += (ntemp<0 ? -250 : 250);
101 + return (u16)((ntemp / 500) << 7);
104 +static inline int LM75_TEMP_FROM_REG(u16 reg)
106 + /* use integer division instead of equivalent right shift to
107 + guarantee arithmetic shift and preserve the sign */
108 + return ((s16)reg / 128) * 500;