2 * (C) Copyright 2007-2008
3 * Larry Johnson, lrj@acm.org
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 * National Semiconductor LM73 Temperature Sensor
24 #define DTT_I2C_DEV_CODE 0x48 /* National Semi's LM73 device */
25 #define DTT_READ_TEMP 0x0
26 #define DTT_CONFIG 0x1
27 #define DTT_TEMP_HIGH 0x2
28 #define DTT_TEMP_LOW 0x3
29 #define DTT_CONTROL 0x4
32 int dtt_read(int const sensor
, int const reg
)
38 * Validate 'reg' param and get register size.
55 * Try to read the register at the calculated sensor address.
58 i2c_read(DTT_I2C_DEV_CODE
+ (sensor
& 0x07), reg
, 1, data
, dlen
))
61 * Handle 2 byte result.
64 return (int)((unsigned)data
[0] << 8 | (unsigned)data
[1]);
69 int dtt_write(int const sensor
, int const reg
, int const val
)
75 * Validate 'reg' param and handle register size
81 data
[0] = (uint8_t) val
;
86 data
[0] = (uint8_t) (val
>> 8); /* MSB first */
87 data
[1] = (uint8_t) val
;
93 * Write value to register at the calculated sensor address.
95 return 0 != i2c_write(DTT_I2C_DEV_CODE
+ (sensor
& 0x07), reg
, 1, data
,
99 int dtt_init_one(int const sensor
)
104 * Validate the Identification register
106 if (0x0190 != dtt_read(sensor
, DTT_ID
))
109 * Setup THIGH (upper-limit) and TLOW (lower-limit) registers
111 val
= CONFIG_SYS_DTT_MAX_TEMP
<< 7;
112 if (dtt_write(sensor
, DTT_TEMP_HIGH
, val
))
115 val
= CONFIG_SYS_DTT_MIN_TEMP
<< 7;
116 if (dtt_write(sensor
, DTT_TEMP_LOW
, val
))
119 * Setup configuraton register
121 /* config = alert active low, disabled, and reset */
123 if (dtt_write(sensor
, DTT_CONFIG
, val
))
126 * Setup control/status register
128 /* control = temp resolution 0.25C */
130 if (dtt_write(sensor
, DTT_CONTROL
, val
))
133 dtt_read(sensor
, DTT_CONTROL
); /* clear temperature flags */
135 } /* dtt_init_one() */
137 int dtt_get_temp(int const sensor
)
139 int const ret
= dtt_read(sensor
, DTT_READ_TEMP
);
142 printf("DTT temperature read failed.\n");
145 return (int)((int16_t) ret
+ 0x0040) >> 7;
146 } /* dtt_get_temp() */