]>
Commit | Line | Data |
---|---|---|
7a8e9bed | 1 | #include <common.h> |
8907b8db GR |
2 | #include <asm/ic/ssi.h> |
3 | #include <ds1722.h> | |
58b74b05 | 4 | |
7a8e9bed WD |
5 | static void ds1722_select(int dev) |
6 | { | |
7 | ssi_set_interface(4096, 0, 0, 0); | |
8 | ssi_chip_select(0); | |
9 | udelay(1); | |
10 | ssi_chip_select(dev); | |
11 | udelay(1); | |
12 | } | |
13 | ||
14 | ||
15 | u8 ds1722_read(int dev, int addr) | |
16 | { | |
17 | u8 res; | |
8bde7f77 | 18 | |
7a8e9bed | 19 | ds1722_select(dev); |
8bde7f77 WD |
20 | |
21 | ssi_tx_byte(addr); | |
22 | res = ssi_rx_byte(); | |
23 | ||
7a8e9bed | 24 | ssi_chip_select(0); |
8bde7f77 | 25 | |
7a8e9bed WD |
26 | return res; |
27 | } | |
28 | ||
29 | void ds1722_write(int dev, int addr, u8 data) | |
30 | { | |
31 | ds1722_select(dev); | |
8bde7f77 WD |
32 | |
33 | ssi_tx_byte(0x80|addr); | |
34 | ssi_tx_byte(data); | |
35 | ||
7a8e9bed WD |
36 | ssi_chip_select(0); |
37 | } | |
38 | ||
39 | ||
40 | u16 ds1722_temp(int dev, int resolution) | |
41 | { | |
42 | static int useconds[] = { | |
8bde7f77 | 43 | 75000, 150000, 300000, 600000, 1200000 |
7a8e9bed WD |
44 | }; |
45 | char temp; | |
46 | u16 res; | |
8bde7f77 WD |
47 | |
48 | ||
7a8e9bed WD |
49 | /* set up the desired resulotion ... */ |
50 | ds1722_write(dev, 0, 0xe0 | (resolution << 1)); | |
8bde7f77 | 51 | |
7a8e9bed | 52 | /* wait while the chip measures the tremperature */ |
8bde7f77 WD |
53 | udelay(useconds[resolution]); |
54 | ||
7a8e9bed | 55 | res = (temp = ds1722_read(dev, 2)) << 8; |
8bde7f77 WD |
56 | |
57 | if (temp < 0) { | |
7a8e9bed WD |
58 | temp = (16 - (ds1722_read(dev, 1) >> 4)) & 0x0f; |
59 | } else { | |
60 | temp = (ds1722_read(dev, 1) >> 4); | |
61 | } | |
8bde7f77 | 62 | |
7a8e9bed WD |
63 | switch (temp) { |
64 | case 0: | |
65 | /* .0000 */ | |
66 | break; | |
67 | case 1: | |
68 | /* .0625 */ | |
69 | res |=1; | |
70 | break; | |
71 | case 2: | |
72 | /* .1250 */ | |
73 | res |=1; | |
74 | break; | |
75 | case 3: | |
76 | /* .1875 */ | |
77 | res |=2; | |
78 | break; | |
79 | case 4: | |
80 | /* .2500 */ | |
81 | res |=3; | |
82 | break; | |
83 | case 5: | |
84 | /* .3125 */ | |
85 | res |=3; | |
86 | break; | |
87 | case 6: | |
88 | /* .3750 */ | |
89 | res |=4; | |
90 | break; | |
91 | case 7: | |
92 | /* .4375 */ | |
93 | res |=4; | |
94 | break; | |
95 | case 8: | |
96 | /* .5000 */ | |
97 | res |=5; | |
98 | break; | |
99 | case 9: | |
100 | /* .5625 */ | |
101 | res |=6; | |
102 | break; | |
103 | case 10: | |
104 | /* .6250 */ | |
105 | res |=6; | |
106 | break; | |
107 | case 11: | |
108 | /* .6875 */ | |
109 | res |=7; | |
110 | break; | |
111 | case 12: | |
112 | /* .7500 */ | |
113 | res |=8; | |
114 | break; | |
115 | case 13: | |
116 | /* .8125 */ | |
117 | res |=8; | |
118 | break; | |
119 | case 14: | |
120 | /* .8750 */ | |
121 | res |=9; | |
122 | break; | |
123 | case 15: | |
124 | /* .9375 */ | |
125 | res |=9; | |
126 | break; | |
127 | } | |
128 | return res; | |
8bde7f77 | 129 | |
7a8e9bed WD |
130 | } |
131 | ||
132 | int ds1722_probe(int dev) | |
133 | { | |
134 | u16 temp = ds1722_temp(dev, DS1722_RESOLUTION_12BIT); | |
135 | printf("%d.%d deg C\n\n", (char)(temp >> 8), temp & 0xff); | |
136 | return 0; | |
137 | } |