blob: b7e36fe461e096c5e8b40699efb4b8828b21c3dd [file] [log] [blame]
Ricardo Ribalda Delgado3c024d32008-07-23 19:10:14 +02001/*
2 * (C) Copyright 2008
3 * Ricado Ribalda-Universidad Autonoma de Madrid, ricardo.ribalda@uam.es
4 * This work has been supported by: QTechnology http://qtec.com/
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#include <common.h>
19#include <i2c.h>
20#include <dtt.h>
21
22#define ADT7460_ADDRESS 0x2c
23#define ADT7460_INVALID 128
24#define ADT7460_CONFIG 0x40
25#define ADT7460_REM1_TEMP 0x25
26#define ADT7460_LOCAL_TEMP 0x26
27#define ADT7460_REM2_TEMP 0x27
28
29int dtt_read(int sensor, int reg)
30{
31 u8 dir = reg;
32 u8 data;
33
34 if (i2c_read(ADT7460_ADDRESS, dir, 1, &data, 1) == -1)
35 return -1;
36 if (data == ADT7460_INVALID)
37 return -1;
38
39 return data;
40}
41
42int dtt_write(int sensor, int reg, int val)
43{
44 u8 dir = reg;
45 u8 data = val;
46
47 if (i2c_write(ADT7460_ADDRESS, dir, 1, &data, 1) == -1)
48 return -1;
49
50 return 0;
51}
52
Heiko Schocher8df768c2011-08-01 04:01:43 +000053int dtt_init_one(int sensor)
Ricardo Ribalda Delgado3c024d32008-07-23 19:10:14 +020054{
55 printf("ADT7460 at I2C address 0x%2x\n", ADT7460_ADDRESS);
56
57 if (dtt_write(0, ADT7460_CONFIG, 1) == -1) {
58 puts("Error initialiting ADT7460\n");
59 return -1;
60 }
61
62 return 0;
63}
64
65int dtt_get_temp(int sensor)
66{
67 int aux;
68 u8 table[] =
69 { ADT7460_REM1_TEMP, ADT7460_LOCAL_TEMP, ADT7460_REM2_TEMP };
70
71 if (sensor > 2) {
72 puts("DTT sensor does not exist\n");
73 return -1;
74 }
75
76 aux = dtt_read(0, table[sensor]);
77 if (aux == -1) {
78 puts("DTT temperature read failed\n");
79 return -1;
80 }
81
82 return aux;
83}