Added support for the Hynix HY27US08121A 64MB Flash chip.
[u-boot-openmoko/mini2440.git] / drivers / hwmon / lm73.c
blobdb8ef662adc27194bf6cf96c212fbcbb3f48d247
1 /*
2 * (C) Copyright 2007
3 * Larry Johnson, lrj@acm.org
5 * based on dtt/lm75.c which is ...
7 * (C) Copyright 2001
8 * Bill Hunter, Wave 7 Optics, williamhunter@mediaone.net
10 * See file CREDITS for list of people who contributed to this
11 * project.
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,
26 * MA 02111-1307 USA
30 * National Semiconductor LM73 Temperature Sensor
33 #include <common.h>
34 #include <i2c.h>
35 #include <dtt.h>
38 * Device code
40 #define DTT_I2C_DEV_CODE 0x48 /* National Semi's LM73 device */
42 int dtt_read(int sensor, int reg)
44 int dlen;
45 uchar data[2];
48 * Validate 'reg' param and get register size.
50 switch (reg) {
51 case DTT_CONFIG:
52 case DTT_CONTROL:
53 dlen = 1;
54 break;
55 case DTT_READ_TEMP:
56 case DTT_TEMP_HIGH:
57 case DTT_TEMP_LOW:
58 case DTT_ID:
59 dlen = 2;
60 break;
61 default:
62 return -1;
65 * Calculate sensor address and register.
67 sensor = DTT_I2C_DEV_CODE + (sensor & 0x07); /* calculate LM73 addr */
69 * Now try to read the register.
71 if (i2c_read(sensor, reg, 1, data, dlen) != 0)
72 return -1;
74 * Handle 2 byte result.
76 if (2 == dlen)
77 return ((int)((short)data[1] + (((short)data[0]) << 8)));
79 return (int)data[0];
80 } /* dtt_read() */
82 int dtt_write(int sensor, int reg, int val)
84 int dlen;
85 uchar data[2];
88 * Validate 'reg' param and handle register size
90 switch (reg) {
91 case DTT_CONFIG:
92 case DTT_CONTROL:
93 dlen = 1;
94 data[0] = (char)(val & 0xff);
95 break;
96 case DTT_TEMP_HIGH:
97 case DTT_TEMP_LOW:
98 dlen = 2;
99 data[0] = (char)((val >> 8) & 0xff); /* MSB first */
100 data[1] = (char)(val & 0xff);
101 break;
102 default:
103 return -1;
106 * Calculate sensor address and register.
108 sensor = DTT_I2C_DEV_CODE + (sensor & 0x07); /* calculate LM73 addr */
110 * Write value to register.
112 return i2c_write(sensor, reg, 1, data, dlen) != 0;
113 } /* dtt_write() */
115 static int _dtt_init(int sensor)
117 int val;
120 * Validate the Identification register
122 if (0x0190 != dtt_read(sensor, DTT_ID))
123 return 1;
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))
129 return 1;
131 val = CFG_DTT_MIN_TEMP << 7;
132 if (dtt_write(sensor, DTT_TEMP_LOW, val))
133 return 1;
135 * Setup configuraton register
137 /* config = alert active low, disabled, and reset */
138 val = 0x64;
139 if (dtt_write(sensor, DTT_CONFIG, val))
140 return 1;
142 * Setup control/status register
144 /* control = temp resolution 0.25C */
145 val = 0x00;
146 if (dtt_write(sensor, DTT_CONTROL, val))
147 return 1;
149 dtt_read(sensor, DTT_CONTROL); /* clear temperature flags */
150 return 0;
151 } /* _dtt_init() */
153 int dtt_init(void)
155 int i;
156 unsigned char sensors[] = CONFIG_DTT_SENSORS;
157 const char *const header = "DTT: ";
159 for (i = 0; i < sizeof(sensors); i++) {
160 if (_dtt_init(sensors[i]) != 0)
161 printf("%s%d FAILED INIT\n", header, i + 1);
162 else
163 printf("%s%d is %i C\n", header, i + 1,
164 dtt_get_temp(sensors[i]));
166 return 0;
167 } /* dtt_init() */
169 int dtt_get_temp(int sensor)
171 return (dtt_read(sensor, DTT_READ_TEMP) + 0x0040) >> 7;
172 } /* dtt_get_temp() */