1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17#include <common.h>
18#include <i2c.h>
19#include <dtt.h>
20
21
22
23
24#define DTT_I2C_DEV_CODE 0x2c
25#define DTT_READ_TEMP 0x27
26#define DTT_CONFIG_TEMP 0x4b
27#define DTT_TEMP_MAX 0x39
28#define DTT_TEMP_HYST 0x3a
29#define DTT_CONFIG 0x40
30
31int dtt_read(int sensor, int reg)
32{
33 int dlen = 1;
34 uchar data[2];
35
36
37
38
39 sensor = DTT_I2C_DEV_CODE + (sensor & 0x03);
40
41
42
43
44 if (i2c_read(sensor, reg, 1, data, dlen) != 0)
45 return -1;
46
47 return (int)data[0];
48}
49
50
51int dtt_write(int sensor, int reg, int val)
52{
53 uchar data;
54
55
56
57
58 sensor = DTT_I2C_DEV_CODE + (sensor & 0x03);
59
60 data = (char)(val & 0xff);
61
62
63
64
65 if (i2c_write(sensor, reg, 1, &data, 1) != 0)
66 return 1;
67
68 return 0;
69}
70
71#define DTT_MANU 0x3e
72#define DTT_REV 0x3f
73#define DTT_CONFIG 0x40
74#define DTT_ADR 0x48
75
76int dtt_init_one(int sensor)
77{
78 int man;
79 int adr;
80 int rev;
81
82 if (dtt_write (sensor, DTT_CONFIG, 0x01) < 0)
83 return 1;
84
85 udelay (400000);
86 man = dtt_read (sensor, DTT_MANU);
87 if (man != 0x01)
88 return 1;
89 adr = dtt_read (sensor, DTT_ADR);
90 if (adr < 0)
91 return 1;
92 rev = dtt_read (sensor, DTT_REV);
93 if (adr < 0)
94 return 1;
95
96 debug ("DTT: Found LM81@%x Rev: %d\n", adr, rev);
97 return 0;
98}
99
100
101#define TEMP_FROM_REG(temp) \
102 ((temp)<256?((((temp)&0x1fe) >> 1) * 10) + ((temp) & 1) * 5: \
103 ((((temp)&0x1fe) >> 1) -255) * 10 - ((temp) & 1) * 5) \
104
105int dtt_get_temp(int sensor)
106{
107 int val = dtt_read (sensor, DTT_READ_TEMP);
108 int tmpcnf = dtt_read (sensor, DTT_CONFIG_TEMP);
109
110 return (TEMP_FROM_REG((val << 1) + ((tmpcnf & 0x80) >> 7))) / 10;
111}
112