3 * Heiko Schocher, DENX Software Enginnering <hs@denx.de>
5 * based on dtt/lm75.c which is ...
8 * Bill Hunter, Wave 7 Optics, williamhunter@mediaone.net
10 * See file CREDITS for list of people who contributed to this
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License as
15 * published by the Free Software Foundation; either version 2 of
16 * the License, or (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
30 * On Semiconductor's LM81 Temperature Sensor
40 #define DTT_I2C_DEV_CODE 0x2c /* ON Semi's LM81 device */
41 #define DTT_READ_TEMP 0x27
42 #define DTT_CONFIG_TEMP 0x4b
43 #define DTT_TEMP_MAX 0x39
44 #define DTT_TEMP_HYST 0x3a
45 #define DTT_CONFIG 0x40
47 int dtt_read(int sensor, int reg)
53 * Calculate sensor address and register.
55 sensor = DTT_I2C_DEV_CODE + (sensor & 0x03); /* calculate address of lm81 */
58 * Now try to read the register.
60 if (i2c_read(sensor, reg, 1, data, dlen) != 0)
67 int dtt_write(int sensor, int reg, int val)
72 * Calculate sensor address and register.
74 sensor = DTT_I2C_DEV_CODE + (sensor & 0x03); /* calculate address of lm81 */
76 data = (char)(val & 0xff);
79 * Write value to register.
81 if (i2c_write(sensor, reg, 1, &data, 1) != 0)
89 #define DTT_CONFIG 0x40
92 static int _dtt_init(int sensor)
98 if (dtt_write (sensor, DTT_CONFIG, 0x01) < 0)
100 /* The LM81 needs 400ms to get the correct values ... */
102 man = dtt_read (sensor, DTT_MANU);
105 adr = dtt_read (sensor, DTT_ADR);
108 rev = dtt_read (sensor, DTT_REV);
112 debug ("DTT: Found LM81@%x Rev: %d\n", adr, rev);
120 unsigned char sensors[] = CONFIG_DTT_SENSORS;
121 const char *const header = "DTT: ";
123 for (i = 0; i < sizeof(sensors); i++) {
124 if (_dtt_init(sensors[i]) != 0)
125 printf("%s%d FAILED INIT\n", header, i+1);
127 printf("%s%d is %i C\n", header, i+1,
128 dtt_get_temp(sensors[i]));
134 #define TEMP_FROM_REG(temp) \
135 ((temp)<256?((((temp)&0x1fe) >> 1) * 10) + ((temp) & 1) * 5: \
136 ((((temp)&0x1fe) >> 1) -255) * 10 - ((temp) & 1) * 5) \
138 int dtt_get_temp(int sensor)
140 int val = dtt_read (sensor, DTT_READ_TEMP);
141 int tmpcnf = dtt_read (sensor, DTT_CONFIG_TEMP);
143 return (TEMP_FROM_REG((val << 1) + ((tmpcnf & 0x80) >> 7))) / 10;
144 } /* dtt_get_temp() */