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 * SPDX-License-Identifier: GPL-2.0+
14 * On Semiconductor's LM81 Temperature Sensor
24 #define DTT_I2C_DEV_CODE 0x2c /* ON Semi's LM81 device */
25 #define DTT_READ_TEMP 0x27
26 #define DTT_CONFIG_TEMP 0x4b
27 #define DTT_TEMP_MAX 0x39
28 #define DTT_TEMP_HYST 0x3a
29 #define DTT_CONFIG 0x40
31 int dtt_read(int sensor, int reg)
37 * Calculate sensor address and register.
39 sensor = DTT_I2C_DEV_CODE + (sensor & 0x03); /* calculate address of lm81 */
42 * Now try to read the register.
44 if (i2c_read(sensor, reg, 1, data, dlen) != 0)
51 int dtt_write(int sensor, int reg, int val)
56 * Calculate sensor address and register.
58 sensor = DTT_I2C_DEV_CODE + (sensor & 0x03); /* calculate address of lm81 */
60 data = (char)(val & 0xff);
63 * Write value to register.
65 if (i2c_write(sensor, reg, 1, &data, 1) != 0)
73 #define DTT_CONFIG 0x40
76 int dtt_init_one(int sensor)
82 if (dtt_write (sensor, DTT_CONFIG, 0x01) < 0)
84 /* The LM81 needs 400ms to get the correct values ... */
86 man = dtt_read (sensor, DTT_MANU);
89 adr = dtt_read (sensor, DTT_ADR);
92 rev = dtt_read (sensor, DTT_REV);
96 debug ("DTT: Found LM81@%x Rev: %d\n", adr, rev);
98 } /* dtt_init_one() */
101 #define TEMP_FROM_REG(temp) \
102 ((temp)<256?((((temp)&0x1fe) >> 1) * 10) + ((temp) & 1) * 5: \
103 ((((temp)&0x1fe) >> 1) -255) * 10 - ((temp) & 1) * 5) \
105 int dtt_get_temp(int sensor)
107 int val = dtt_read (sensor, DTT_READ_TEMP);
108 int tmpcnf = dtt_read (sensor, DTT_CONFIG_TEMP);
110 return (TEMP_FROM_REG((val << 1) + ((tmpcnf & 0x80) >> 7))) / 10;
111 } /* dtt_get_temp() */