]>
git.ipfire.org Git - people/ms/u-boot.git/blob - drivers/hwmon/lm73.c
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 * 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
40 #define DTT_I2C_DEV_CODE 0x48 /* National Semi's LM73 device */
41 #define DTT_READ_TEMP 0x0
42 #define DTT_CONFIG 0x1
43 #define DTT_TEMP_HIGH 0x2
44 #define DTT_TEMP_LOW 0x3
45 #define DTT_CONTROL 0x4
48 int dtt_read(int const sensor
, int const reg
)
54 * Validate 'reg' param and get register size.
71 * Try to read the register at the calculated sensor address.
74 i2c_read(DTT_I2C_DEV_CODE
+ (sensor
& 0x07), reg
, 1, data
, dlen
))
77 * Handle 2 byte result.
80 return (int)((unsigned)data
[0] << 8 | (unsigned)data
[1]);
85 int dtt_write(int const sensor
, int const reg
, int const val
)
91 * Validate 'reg' param and handle register size
97 data
[0] = (uint8_t) val
;
102 data
[0] = (uint8_t) (val
>> 8); /* MSB first */
103 data
[1] = (uint8_t) val
;
109 * Write value to register at the calculated sensor address.
111 return 0 != i2c_write(DTT_I2C_DEV_CODE
+ (sensor
& 0x07), reg
, 1, data
,
115 static int _dtt_init(int const sensor
)
120 * Validate the Identification register
122 if (0x0190 != dtt_read(sensor
, DTT_ID
))
125 * Setup THIGH (upper-limit) and TLOW (lower-limit) registers
127 val
= CFG_DTT_MAX_TEMP
<< 7;
128 if (dtt_write(sensor
, DTT_TEMP_HIGH
, val
))
131 val
= CFG_DTT_MIN_TEMP
<< 7;
132 if (dtt_write(sensor
, DTT_TEMP_LOW
, val
))
135 * Setup configuraton register
137 /* config = alert active low, disabled, and reset */
139 if (dtt_write(sensor
, DTT_CONFIG
, val
))
142 * Setup control/status register
144 /* control = temp resolution 0.25C */
146 if (dtt_write(sensor
, DTT_CONTROL
, val
))
149 dtt_read(sensor
, DTT_CONTROL
); /* clear temperature flags */
156 unsigned char sensors
[] = CONFIG_DTT_SENSORS
;
157 const char *const header
= "DTT: ";
159 for (i
= 0; i
< sizeof(sensors
); i
++) {
160 if (0 != _dtt_init(sensors
[i
]))
161 printf("%s%d FAILED INIT\n", header
, i
+ 1);
163 printf("%s%d is %i C\n", header
, i
+ 1,
164 dtt_get_temp(sensors
[i
]));
169 int dtt_get_temp(int const sensor
)
171 int const ret
= dtt_read(sensor
, DTT_READ_TEMP
);
174 printf("DTT temperature read failed.\n");
177 return (int)((int16_t) ret
+ 0x0040) >> 7;
178 } /* dtt_get_temp() */