blob: 9b2c5b69ce5503837560329ba5c42a3c0a4fc4e8 [file] [log] [blame]
Ricardo Ribalda Delgadod0039d42008-07-23 19:10:14 +02001/*
2 * (C) Copyright 2008
Ricardo Ribalda Delgado5b218ae2016-01-26 11:24:08 +01003 * Ricado Ribalda-Universidad Autonoma de Madrid, ricardo.ribalda@gmail.com
Ricardo Ribalda Delgadod0039d42008-07-23 19:10:14 +02004 * This work has been supported by: QTechnology http://qtec.com/
Wolfgang Denk1a459662013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
6 */
Ricardo Ribalda Delgadod0039d42008-07-23 19:10:14 +02007
8#include <common.h>
9#include <i2c.h>
10#include <dtt.h>
11
12#define ADT7460_ADDRESS 0x2c
13#define ADT7460_INVALID 128
14#define ADT7460_CONFIG 0x40
15#define ADT7460_REM1_TEMP 0x25
16#define ADT7460_LOCAL_TEMP 0x26
17#define ADT7460_REM2_TEMP 0x27
18
19int dtt_read(int sensor, int reg)
20{
21 u8 dir = reg;
22 u8 data;
23
24 if (i2c_read(ADT7460_ADDRESS, dir, 1, &data, 1) == -1)
25 return -1;
26 if (data == ADT7460_INVALID)
27 return -1;
28
29 return data;
30}
31
32int dtt_write(int sensor, int reg, int val)
33{
34 u8 dir = reg;
35 u8 data = val;
36
37 if (i2c_write(ADT7460_ADDRESS, dir, 1, &data, 1) == -1)
38 return -1;
39
40 return 0;
41}
42
Heiko Schocher780f13a2011-08-01 04:01:43 +000043int dtt_init_one(int sensor)
Ricardo Ribalda Delgadod0039d42008-07-23 19:10:14 +020044{
45 printf("ADT7460 at I2C address 0x%2x\n", ADT7460_ADDRESS);
46
47 if (dtt_write(0, ADT7460_CONFIG, 1) == -1) {
48 puts("Error initialiting ADT7460\n");
49 return -1;
50 }
51
52 return 0;
53}
54
55int dtt_get_temp(int sensor)
56{
57 int aux;
58 u8 table[] =
59 { ADT7460_REM1_TEMP, ADT7460_LOCAL_TEMP, ADT7460_REM2_TEMP };
60
61 if (sensor > 2) {
62 puts("DTT sensor does not exist\n");
63 return -1;
64 }
65
66 aux = dtt_read(0, table[sensor]);
67 if (aux == -1) {
68 puts("DTT temperature read failed\n");
69 return -1;
70 }
71
72 return aux;
73}