aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/w1/w1_therm.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/w1/w1_therm.c')
-rw-r--r--drivers/w1/w1_therm.c47
1 files changed, 26 insertions, 21 deletions
diff --git a/drivers/w1/w1_therm.c b/drivers/w1/w1_therm.c
index 165526c9360a..4577df3cfc48 100644
--- a/drivers/w1/w1_therm.c
+++ b/drivers/w1/w1_therm.c
@@ -42,12 +42,31 @@ static u8 bad_roms[][9] = {
42 {} 42 {}
43 }; 43 };
44 44
45static ssize_t w1_therm_read_name(struct device *, struct device_attribute *attr, char *);
46static ssize_t w1_therm_read_bin(struct kobject *, char *, loff_t, size_t); 45static ssize_t w1_therm_read_bin(struct kobject *, char *, loff_t, size_t);
47 46
47static struct bin_attribute w1_therm_bin_attr = {
48 .attr = {
49 .name = "w1_slave",
50 .mode = S_IRUGO,
51 .owner = THIS_MODULE,
52 },
53 .size = W1_SLAVE_DATA_SIZE,
54 .read = w1_therm_read_bin,
55};
56
57static int w1_therm_add_slave(struct w1_slave *sl)
58{
59 return sysfs_create_bin_file(&sl->dev.kobj, &w1_therm_bin_attr);
60}
61
62static void w1_therm_remove_slave(struct w1_slave *sl)
63{
64 sysfs_remove_bin_file(&sl->dev.kobj, &w1_therm_bin_attr);
65}
66
48static struct w1_family_ops w1_therm_fops = { 67static struct w1_family_ops w1_therm_fops = {
49 .rname = &w1_therm_read_name, 68 .add_slave = w1_therm_add_slave,
50 .rbin = &w1_therm_read_bin, 69 .remove_slave = w1_therm_remove_slave,
51}; 70};
52 71
53static struct w1_family w1_therm_family_DS18S20 = { 72static struct w1_family w1_therm_family_DS18S20 = {
@@ -59,6 +78,7 @@ static struct w1_family w1_therm_family_DS18B20 = {
59 .fid = W1_THERM_DS18B20, 78 .fid = W1_THERM_DS18B20,
60 .fops = &w1_therm_fops, 79 .fops = &w1_therm_fops,
61}; 80};
81
62static struct w1_family w1_therm_family_DS1822 = { 82static struct w1_family w1_therm_family_DS1822 = {
63 .fid = W1_THERM_DS1822, 83 .fid = W1_THERM_DS1822,
64 .fops = &w1_therm_fops, 84 .fops = &w1_therm_fops,
@@ -90,13 +110,6 @@ static struct w1_therm_family_converter w1_therm_families[] = {
90 }, 110 },
91}; 111};
92 112
93static ssize_t w1_therm_read_name(struct device *dev, struct device_attribute *attr, char *buf)
94{
95 struct w1_slave *sl = container_of(dev, struct w1_slave, dev);
96
97 return sprintf(buf, "%s\n", sl->name);
98}
99
100static inline int w1_DS18B20_convert_temp(u8 rom[9]) 113static inline int w1_DS18B20_convert_temp(u8 rom[9])
101{ 114{
102 int t = (rom[1] << 8) | rom[0]; 115 int t = (rom[1] << 8) | rom[0];
@@ -148,8 +161,7 @@ static int w1_therm_check_rom(u8 rom[9])
148 161
149static ssize_t w1_therm_read_bin(struct kobject *kobj, char *buf, loff_t off, size_t count) 162static ssize_t w1_therm_read_bin(struct kobject *kobj, char *buf, loff_t off, size_t count)
150{ 163{
151 struct w1_slave *sl = container_of(container_of(kobj, struct device, kobj), 164 struct w1_slave *sl = kobj_to_w1_slave(kobj);
152 struct w1_slave, dev);
153 struct w1_master *dev = sl->master; 165 struct w1_master *dev = sl->master;
154 u8 rom[9], crc, verdict; 166 u8 rom[9], crc, verdict;
155 int i, max_trying = 10; 167 int i, max_trying = 10;
@@ -178,15 +190,10 @@ static ssize_t w1_therm_read_bin(struct kobject *kobj, char *buf, loff_t off, si
178 crc = 0; 190 crc = 0;
179 191
180 while (max_trying--) { 192 while (max_trying--) {
181 if (!w1_reset_bus (dev)) { 193 if (!w1_reset_select_slave(sl)) {
182 int count = 0; 194 int count = 0;
183 u8 match[9] = {W1_MATCH_ROM, };
184 unsigned int tm = 750; 195 unsigned int tm = 750;
185 196
186 memcpy(&match[1], (u64 *) & sl->reg_num, 8);
187
188 w1_write_block(dev, match, 9);
189
190 w1_write_8(dev, W1_CONVERT_TEMP); 197 w1_write_8(dev, W1_CONVERT_TEMP);
191 198
192 while (tm) { 199 while (tm) {
@@ -195,8 +202,7 @@ static ssize_t w1_therm_read_bin(struct kobject *kobj, char *buf, loff_t off, si
195 flush_signals(current); 202 flush_signals(current);
196 } 203 }
197 204
198 if (!w1_reset_bus (dev)) { 205 if (!w1_reset_select_slave(sl)) {
199 w1_write_block(dev, match, 9);
200 206
201 w1_write_8(dev, W1_READ_SCRATCHPAD); 207 w1_write_8(dev, W1_READ_SCRATCHPAD);
202 if ((count = w1_read_block(dev, rom, 9)) != 9) { 208 if ((count = w1_read_block(dev, rom, 9)) != 9) {
@@ -207,7 +213,6 @@ static ssize_t w1_therm_read_bin(struct kobject *kobj, char *buf, loff_t off, si
207 213
208 if (rom[8] == crc && rom[0]) 214 if (rom[8] == crc && rom[0])
209 verdict = 1; 215 verdict = 1;
210
211 } 216 }
212 } 217 }
213 218