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 * 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 * Analog Devices's ADM1021
31 * "Low Cost Microprocessor System Temperature Monitor"
36 #ifdef CONFIG_DTT_ADM1021
43 uint i2c_addr:7; /* 7bit i2c chip address */
44 uint conv_rate:3; /* conversion rate */
45 uint enable_alert:1; /* enable alert output pin */
46 uint enable_local:1; /* enable internal temp sensor */
47 uint max_local:8; /* internal temp maximum */
48 uint min_local:8; /* internal temp minimum */
49 uint enable_remote:1; /* enable remote temp sensor */
50 uint max_remote:8; /* remote temp maximum */
51 uint min_remote:8; /* remote temp minimum */
55 dtt_cfg_t dttcfg[] = CFG_DTT_ADM1021;
58 dtt_read (int sensor, int reg)
60 dtt_cfg_t *dcp = &dttcfg[sensor >> 1];
63 if (i2c_read(dcp->i2c_addr, reg, 1, &data, 1) != 0)
70 dtt_write (int sensor, int reg, int val)
72 dtt_cfg_t *dcp = &dttcfg[sensor >> 1];
75 data = (uchar)(val & 0xff);
77 if (i2c_write(dcp->i2c_addr, reg, 1, &data, 1) != 0)
84 _dtt_init (int sensor)
86 dtt_cfg_t *dcp = &dttcfg[sensor >> 1];
89 if (((sensor & 1) == 0 ? dcp->enable_local : dcp->enable_remote) == 0)
90 return 1; /* sensor is disabled (or rather ignored) */
93 * Setup High Limit register
95 if ((sensor & 1) == 0) {
96 reg = DTT_WRITE_LOC_HIGHLIM;
100 reg = DTT_WRITE_REM_HIGHLIM;
101 val = dcp->max_remote;
103 if (dtt_write (sensor, reg, val) != 0)
107 * Setup Low Limit register
109 if ((sensor & 1) == 0) {
110 reg = DTT_WRITE_LOC_LOWLIM;
111 val = dcp->min_local;
114 reg = DTT_WRITE_REM_LOWLIM;
115 val = dcp->min_remote;
117 if (dtt_write (sensor, reg, val) != 0)
120 /* shouldn't hurt if the rest gets done twice */
123 * Setup Conversion Rate register
125 if (dtt_write (sensor, DTT_WRITE_CONVRATE, dcp->conv_rate) != 0)
129 * Setup configuraton register
131 val = 0; /* running */
132 if (dcp->enable_alert == 0)
133 val |= DTT_CONFIG_ALERT_MASKED; /* mask ALERT pin */
134 if (dtt_write (sensor, DTT_WRITE_CONFIG, val) != 0)
144 unsigned char sensors[] = CONFIG_DTT_SENSORS;
145 const char *const header = "DTT: ";
147 for (i = 0; i < sizeof(sensors); i++) {
148 if (_dtt_init(sensors[i]) != 0)
149 printf ("%s%d FAILED INIT\n", header, i+1);
151 printf ("%s%d is %i C\n", header, i+1,
152 dtt_get_temp(sensors[i]));
159 dtt_get_temp (int sensor)
163 if ((sensor & 1) == 0)
164 val = dtt_read(sensor, DTT_READ_LOC_VALUE);
166 val = dtt_read(sensor, DTT_READ_REM_VALUE);
169 } /* dtt_get_temp() */
171 #endif /* CONFIG_DTT_ADM1021 */