3 * Larry Johnson, lrj@acm.org
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 * National Semiconductor LM73 Temperature Sensor
35 #ifdef CONFIG_DTT_LM73
36 #if !defined(CFG_EEPROM_PAGE_WRITE_ENABLE) || \
37 (CFG_EEPROM_PAGE_WRITE_BITS < 1)
38 # error "CFG_EEPROM_PAGE_WRITE_ENABLE must be defined and CFG_EEPROM_PAGE_WRITE_BITS must be greater than 1 to use CONFIG_DTT_LM73"
47 #define DTT_I2C_DEV_CODE 0x48 /* National Semi's LM73 device */
49 int dtt_read(int sensor, int reg)
55 * Validate 'reg' param and get register size.
72 * Calculate sensor address and register.
74 sensor = DTT_I2C_DEV_CODE + (sensor & 0x07); /* calculate LM73 addr */
76 * Now try to read the register.
78 if (i2c_read(sensor, reg, 1, data, dlen) != 0)
81 * Handle 2 byte result.
84 return ((int)((short)data[1] + (((short)data[0]) << 8)));
89 int dtt_write(int sensor, int reg, int val)
95 * Validate 'reg' param and handle register size
101 data[0] = (char)(val & 0xff);
106 data[0] = (char)((val >> 8) & 0xff); /* MSB first */
107 data[1] = (char)(val & 0xff);
113 * Calculate sensor address and register.
115 sensor = DTT_I2C_DEV_CODE + (sensor & 0x07); /* calculate LM73 addr */
117 * Write value to register.
119 return i2c_write(sensor, reg, 1, data, dlen) != 0;
122 static int _dtt_init(int sensor)
127 * Validate the Identification register
129 if (0x0190 != dtt_read(sensor, DTT_ID))
132 * Setup THIGH (upper-limit) and TLOW (lower-limit) registers
134 val = CFG_DTT_MAX_TEMP << 7;
135 if (dtt_write(sensor, DTT_TEMP_HIGH, val))
138 val = CFG_DTT_MIN_TEMP << 7;
139 if (dtt_write(sensor, DTT_TEMP_LOW, val))
142 * Setup configuraton register
144 /* config = alert active low, disabled, and reset */
146 if (dtt_write(sensor, DTT_CONFIG, val))
149 * Setup control/status register
151 /* control = temp resolution 0.25C */
153 if (dtt_write(sensor, DTT_CONTROL, val))
156 dtt_read(sensor, DTT_CONTROL); /* clear temperature flags */
163 unsigned char sensors[] = CONFIG_DTT_SENSORS;
164 const char *const header = "DTT: ";
166 for (i = 0; i < sizeof(sensors); i++) {
167 if (_dtt_init(sensors[i]) != 0)
168 printf("%s%d FAILED INIT\n", header, i + 1);
170 printf("%s%d is %i C\n", header, i + 1,
171 dtt_get_temp(sensors[i]));
176 int dtt_get_temp(int sensor)
178 return (dtt_read(sensor, DTT_READ_TEMP) + 0x0040) >> 7;
179 } /* dtt_get_temp() */
181 #endif /* CONFIG_DTT_LM73 */