]>
git.ipfire.org Git - people/ms/u-boot.git/blob - drivers/hwmon/adm1021.c
3 * Murray Jensen, CSIRO-MIT, Murray.Jensen@csiro.au
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 * Analog Devices's ADM1021
15 * "Low Cost Microprocessor System Temperature Monitor"
23 #define DTT_READ_LOC_VALUE 0x00
24 #define DTT_READ_REM_VALUE 0x01
25 #define DTT_READ_STATUS 0x02
26 #define DTT_READ_CONFIG 0x03
27 #define DTT_READ_CONVRATE 0x04
28 #define DTT_READ_LOC_HIGHLIM 0x05
29 #define DTT_READ_LOC_LOWLIM 0x06
30 #define DTT_READ_REM_HIGHLIM 0x07
31 #define DTT_READ_REM_LOWLIM 0x08
32 #define DTT_READ_DEVID 0xfe
34 #define DTT_WRITE_CONFIG 0x09
35 #define DTT_WRITE_CONVRATE 0x0a
36 #define DTT_WRITE_LOC_HIGHLIM 0x0b
37 #define DTT_WRITE_LOC_LOWLIM 0x0c
38 #define DTT_WRITE_REM_HIGHLIM 0x0d
39 #define DTT_WRITE_REM_LOWLIM 0x0e
40 #define DTT_WRITE_ONESHOT 0x0f
42 #define DTT_STATUS_BUSY 0x80 /* 1=ADC Converting */
43 #define DTT_STATUS_LHIGH 0x40 /* 1=Local High Temp Limit Tripped */
44 #define DTT_STATUS_LLOW 0x20 /* 1=Local Low Temp Limit Tripped */
45 #define DTT_STATUS_RHIGH 0x10 /* 1=Remote High Temp Limit Tripped */
46 #define DTT_STATUS_RLOW 0x08 /* 1=Remote Low Temp Limit Tripped */
47 #define DTT_STATUS_OPEN 0x04 /* 1=Remote Sensor Open-Circuit */
49 #define DTT_CONFIG_ALERT_MASKED 0x80 /* 0=ALERT Enabled, 1=ALERT Masked */
50 #define DTT_CONFIG_STANDBY 0x40 /* 0=Run, 1=Standby */
52 #define DTT_ADM1021_DEVID 0x41
56 uint i2c_addr
:7; /* 7bit i2c chip address */
57 uint conv_rate
:3; /* conversion rate */
58 uint enable_alert
:1; /* enable alert output pin */
59 uint enable_local
:1; /* enable internal temp sensor */
60 uint max_local
:8; /* internal temp maximum */
61 uint min_local
:8; /* internal temp minimum */
62 uint enable_remote
:1; /* enable remote temp sensor */
63 uint max_remote
:8; /* remote temp maximum */
64 uint min_remote
:8; /* remote temp minimum */
68 dtt_cfg_t dttcfg
[] = CONFIG_SYS_DTT_ADM1021
;
71 dtt_read (int sensor
, int reg
)
73 dtt_cfg_t
*dcp
= &dttcfg
[sensor
>> 1];
76 if (i2c_read(dcp
->i2c_addr
, reg
, 1, &data
, 1) != 0)
83 dtt_write (int sensor
, int reg
, int val
)
85 dtt_cfg_t
*dcp
= &dttcfg
[sensor
>> 1];
88 data
= (uchar
)(val
& 0xff);
90 if (i2c_write(dcp
->i2c_addr
, reg
, 1, &data
, 1) != 0)
97 dtt_init_one(int sensor
)
99 dtt_cfg_t
*dcp
= &dttcfg
[sensor
>> 1];
102 if (((sensor
& 1) == 0 ? dcp
->enable_local
: dcp
->enable_remote
) == 0)
103 return 1; /* sensor is disabled (or rather ignored) */
106 * Setup High Limit register
108 if ((sensor
& 1) == 0) {
109 reg
= DTT_WRITE_LOC_HIGHLIM
;
110 val
= dcp
->max_local
;
113 reg
= DTT_WRITE_REM_HIGHLIM
;
114 val
= dcp
->max_remote
;
116 if (dtt_write (sensor
, reg
, val
) != 0)
120 * Setup Low Limit register
122 if ((sensor
& 1) == 0) {
123 reg
= DTT_WRITE_LOC_LOWLIM
;
124 val
= dcp
->min_local
;
127 reg
= DTT_WRITE_REM_LOWLIM
;
128 val
= dcp
->min_remote
;
130 if (dtt_write (sensor
, reg
, val
) != 0)
133 /* shouldn't hurt if the rest gets done twice */
136 * Setup Conversion Rate register
138 if (dtt_write (sensor
, DTT_WRITE_CONVRATE
, dcp
->conv_rate
) != 0)
142 * Setup configuraton register
144 val
= 0; /* running */
145 if (dcp
->enable_alert
== 0)
146 val
|= DTT_CONFIG_ALERT_MASKED
; /* mask ALERT pin */
147 if (dtt_write (sensor
, DTT_WRITE_CONFIG
, val
) != 0)
151 } /* dtt_init_one() */
154 dtt_get_temp (int sensor
)
158 if ((sensor
& 1) == 0)
159 val
= dtt_read(sensor
, DTT_READ_LOC_VALUE
);
161 val
= dtt_read(sensor
, DTT_READ_REM_VALUE
);
164 } /* dtt_get_temp() */