diff options
Diffstat (limited to 'drivers/w1/slaves/w1_ds2408.c')
-rw-r--r-- | drivers/w1/slaves/w1_ds2408.c | 174 |
1 files changed, 52 insertions, 122 deletions
diff --git a/drivers/w1/slaves/w1_ds2408.c b/drivers/w1/slaves/w1_ds2408.c index cb8a8e5d9573..7dfa0e11688a 100644 --- a/drivers/w1/slaves/w1_ds2408.c +++ b/drivers/w1/slaves/w1_ds2408.c | |||
@@ -72,10 +72,9 @@ static int _read_reg(struct w1_slave *sl, u8 address, unsigned char* buf) | |||
72 | return 1; | 72 | return 1; |
73 | } | 73 | } |
74 | 74 | ||
75 | static ssize_t w1_f29_read_state( | 75 | static ssize_t state_read(struct file *filp, struct kobject *kobj, |
76 | struct file *filp, struct kobject *kobj, | 76 | struct bin_attribute *bin_attr, char *buf, loff_t off, |
77 | struct bin_attribute *bin_attr, | 77 | size_t count) |
78 | char *buf, loff_t off, size_t count) | ||
79 | { | 78 | { |
80 | dev_dbg(&kobj_to_w1_slave(kobj)->dev, | 79 | dev_dbg(&kobj_to_w1_slave(kobj)->dev, |
81 | "Reading %s kobj: %p, off: %0#10x, count: %zu, buff addr: %p", | 80 | "Reading %s kobj: %p, off: %0#10x, count: %zu, buff addr: %p", |
@@ -85,10 +84,9 @@ static ssize_t w1_f29_read_state( | |||
85 | return _read_reg(kobj_to_w1_slave(kobj), W1_F29_REG_LOGIG_STATE, buf); | 84 | return _read_reg(kobj_to_w1_slave(kobj), W1_F29_REG_LOGIG_STATE, buf); |
86 | } | 85 | } |
87 | 86 | ||
88 | static ssize_t w1_f29_read_output( | 87 | static ssize_t output_read(struct file *filp, struct kobject *kobj, |
89 | struct file *filp, struct kobject *kobj, | 88 | struct bin_attribute *bin_attr, char *buf, |
90 | struct bin_attribute *bin_attr, | 89 | loff_t off, size_t count) |
91 | char *buf, loff_t off, size_t count) | ||
92 | { | 90 | { |
93 | dev_dbg(&kobj_to_w1_slave(kobj)->dev, | 91 | dev_dbg(&kobj_to_w1_slave(kobj)->dev, |
94 | "Reading %s kobj: %p, off: %0#10x, count: %zu, buff addr: %p", | 92 | "Reading %s kobj: %p, off: %0#10x, count: %zu, buff addr: %p", |
@@ -99,10 +97,9 @@ static ssize_t w1_f29_read_output( | |||
99 | W1_F29_REG_OUTPUT_LATCH_STATE, buf); | 97 | W1_F29_REG_OUTPUT_LATCH_STATE, buf); |
100 | } | 98 | } |
101 | 99 | ||
102 | static ssize_t w1_f29_read_activity( | 100 | static ssize_t activity_read(struct file *filp, struct kobject *kobj, |
103 | struct file *filp, struct kobject *kobj, | 101 | struct bin_attribute *bin_attr, char *buf, |
104 | struct bin_attribute *bin_attr, | 102 | loff_t off, size_t count) |
105 | char *buf, loff_t off, size_t count) | ||
106 | { | 103 | { |
107 | dev_dbg(&kobj_to_w1_slave(kobj)->dev, | 104 | dev_dbg(&kobj_to_w1_slave(kobj)->dev, |
108 | "Reading %s kobj: %p, off: %0#10x, count: %zu, buff addr: %p", | 105 | "Reading %s kobj: %p, off: %0#10x, count: %zu, buff addr: %p", |
@@ -113,10 +110,9 @@ static ssize_t w1_f29_read_activity( | |||
113 | W1_F29_REG_ACTIVITY_LATCH_STATE, buf); | 110 | W1_F29_REG_ACTIVITY_LATCH_STATE, buf); |
114 | } | 111 | } |
115 | 112 | ||
116 | static ssize_t w1_f29_read_cond_search_mask( | 113 | static ssize_t cond_search_mask_read(struct file *filp, struct kobject *kobj, |
117 | struct file *filp, struct kobject *kobj, | 114 | struct bin_attribute *bin_attr, char *buf, |
118 | struct bin_attribute *bin_attr, | 115 | loff_t off, size_t count) |
119 | char *buf, loff_t off, size_t count) | ||
120 | { | 116 | { |
121 | dev_dbg(&kobj_to_w1_slave(kobj)->dev, | 117 | dev_dbg(&kobj_to_w1_slave(kobj)->dev, |
122 | "Reading %s kobj: %p, off: %0#10x, count: %zu, buff addr: %p", | 118 | "Reading %s kobj: %p, off: %0#10x, count: %zu, buff addr: %p", |
@@ -127,10 +123,10 @@ static ssize_t w1_f29_read_cond_search_mask( | |||
127 | W1_F29_REG_COND_SEARCH_SELECT_MASK, buf); | 123 | W1_F29_REG_COND_SEARCH_SELECT_MASK, buf); |
128 | } | 124 | } |
129 | 125 | ||
130 | static ssize_t w1_f29_read_cond_search_polarity( | 126 | static ssize_t cond_search_polarity_read(struct file *filp, |
131 | struct file *filp, struct kobject *kobj, | 127 | struct kobject *kobj, |
132 | struct bin_attribute *bin_attr, | 128 | struct bin_attribute *bin_attr, |
133 | char *buf, loff_t off, size_t count) | 129 | char *buf, loff_t off, size_t count) |
134 | { | 130 | { |
135 | if (count != 1 || off != 0) | 131 | if (count != 1 || off != 0) |
136 | return -EFAULT; | 132 | return -EFAULT; |
@@ -138,10 +134,9 @@ static ssize_t w1_f29_read_cond_search_polarity( | |||
138 | W1_F29_REG_COND_SEARCH_POL_SELECT, buf); | 134 | W1_F29_REG_COND_SEARCH_POL_SELECT, buf); |
139 | } | 135 | } |
140 | 136 | ||
141 | static ssize_t w1_f29_read_status_control( | 137 | static ssize_t status_control_read(struct file *filp, struct kobject *kobj, |
142 | struct file *filp, struct kobject *kobj, | 138 | struct bin_attribute *bin_attr, char *buf, |
143 | struct bin_attribute *bin_attr, | 139 | loff_t off, size_t count) |
144 | char *buf, loff_t off, size_t count) | ||
145 | { | 140 | { |
146 | if (count != 1 || off != 0) | 141 | if (count != 1 || off != 0) |
147 | return -EFAULT; | 142 | return -EFAULT; |
@@ -149,13 +144,9 @@ static ssize_t w1_f29_read_status_control( | |||
149 | W1_F29_REG_CONTROL_AND_STATUS, buf); | 144 | W1_F29_REG_CONTROL_AND_STATUS, buf); |
150 | } | 145 | } |
151 | 146 | ||
152 | 147 | static ssize_t output_write(struct file *filp, struct kobject *kobj, | |
153 | 148 | struct bin_attribute *bin_attr, char *buf, | |
154 | 149 | loff_t off, size_t count) | |
155 | static ssize_t w1_f29_write_output( | ||
156 | struct file *filp, struct kobject *kobj, | ||
157 | struct bin_attribute *bin_attr, | ||
158 | char *buf, loff_t off, size_t count) | ||
159 | { | 150 | { |
160 | struct w1_slave *sl = kobj_to_w1_slave(kobj); | 151 | struct w1_slave *sl = kobj_to_w1_slave(kobj); |
161 | u8 w1_buf[3]; | 152 | u8 w1_buf[3]; |
@@ -224,10 +215,9 @@ error: | |||
224 | /** | 215 | /** |
225 | * Writing to the activity file resets the activity latches. | 216 | * Writing to the activity file resets the activity latches. |
226 | */ | 217 | */ |
227 | static ssize_t w1_f29_write_activity( | 218 | static ssize_t activity_write(struct file *filp, struct kobject *kobj, |
228 | struct file *filp, struct kobject *kobj, | 219 | struct bin_attribute *bin_attr, char *buf, |
229 | struct bin_attribute *bin_attr, | 220 | loff_t off, size_t count) |
230 | char *buf, loff_t off, size_t count) | ||
231 | { | 221 | { |
232 | struct w1_slave *sl = kobj_to_w1_slave(kobj); | 222 | struct w1_slave *sl = kobj_to_w1_slave(kobj); |
233 | unsigned int retries = W1_F29_RETRIES; | 223 | unsigned int retries = W1_F29_RETRIES; |
@@ -255,13 +245,9 @@ error: | |||
255 | return -EIO; | 245 | return -EIO; |
256 | } | 246 | } |
257 | 247 | ||
258 | static ssize_t w1_f29_write_status_control( | 248 | static ssize_t status_control_write(struct file *filp, struct kobject *kobj, |
259 | struct file *filp, | 249 | struct bin_attribute *bin_attr, char *buf, |
260 | struct kobject *kobj, | 250 | loff_t off, size_t count) |
261 | struct bin_attribute *bin_attr, | ||
262 | char *buf, | ||
263 | loff_t off, | ||
264 | size_t count) | ||
265 | { | 251 | { |
266 | struct w1_slave *sl = kobj_to_w1_slave(kobj); | 252 | struct w1_slave *sl = kobj_to_w1_slave(kobj); |
267 | u8 w1_buf[4]; | 253 | u8 w1_buf[4]; |
@@ -330,91 +316,35 @@ out: | |||
330 | return res; | 316 | return res; |
331 | } | 317 | } |
332 | 318 | ||
333 | static struct bin_attribute w1_f29_sysfs_bin_files[] = { | 319 | static BIN_ATTR_RO(state, 1); |
334 | { | 320 | static BIN_ATTR_RW(output, 1); |
335 | .attr = { | 321 | static BIN_ATTR_RW(activity, 1); |
336 | .name = "state", | 322 | static BIN_ATTR_RO(cond_search_mask, 1); |
337 | .mode = S_IRUGO, | 323 | static BIN_ATTR_RO(cond_search_polarity, 1); |
338 | }, | 324 | static BIN_ATTR_RW(status_control, 1); |
339 | .size = 1, | 325 | |
340 | .read = w1_f29_read_state, | 326 | static struct bin_attribute *w1_f29_bin_attrs[] = { |
341 | }, | 327 | &bin_attr_state, |
342 | { | 328 | &bin_attr_output, |
343 | .attr = { | 329 | &bin_attr_activity, |
344 | .name = "output", | 330 | &bin_attr_cond_search_mask, |
345 | .mode = S_IRUGO | S_IWUSR | S_IWGRP, | 331 | &bin_attr_cond_search_polarity, |
346 | }, | 332 | &bin_attr_status_control, |
347 | .size = 1, | 333 | NULL, |
348 | .read = w1_f29_read_output, | ||
349 | .write = w1_f29_write_output, | ||
350 | }, | ||
351 | { | ||
352 | .attr = { | ||
353 | .name = "activity", | ||
354 | .mode = S_IRUGO, | ||
355 | }, | ||
356 | .size = 1, | ||
357 | .read = w1_f29_read_activity, | ||
358 | .write = w1_f29_write_activity, | ||
359 | }, | ||
360 | { | ||
361 | .attr = { | ||
362 | .name = "cond_search_mask", | ||
363 | .mode = S_IRUGO, | ||
364 | }, | ||
365 | .size = 1, | ||
366 | .read = w1_f29_read_cond_search_mask, | ||
367 | }, | ||
368 | { | ||
369 | .attr = { | ||
370 | .name = "cond_search_polarity", | ||
371 | .mode = S_IRUGO, | ||
372 | }, | ||
373 | .size = 1, | ||
374 | .read = w1_f29_read_cond_search_polarity, | ||
375 | }, | ||
376 | { | ||
377 | .attr = { | ||
378 | .name = "status_control", | ||
379 | .mode = S_IRUGO | S_IWUSR | S_IWGRP, | ||
380 | }, | ||
381 | .size = 1, | ||
382 | .read = w1_f29_read_status_control, | ||
383 | .write = w1_f29_write_status_control, | ||
384 | } | ||
385 | }; | 334 | }; |
386 | 335 | ||
387 | static int w1_f29_add_slave(struct w1_slave *sl) | 336 | static const struct attribute_group w1_f29_group = { |
388 | { | 337 | .bin_attrs = w1_f29_bin_attrs, |
389 | int err = 0; | 338 | }; |
390 | int i; | ||
391 | |||
392 | err = w1_f29_disable_test_mode(sl); | ||
393 | if (err) | ||
394 | return err; | ||
395 | |||
396 | for (i = 0; i < ARRAY_SIZE(w1_f29_sysfs_bin_files) && !err; ++i) | ||
397 | err = sysfs_create_bin_file( | ||
398 | &sl->dev.kobj, | ||
399 | &(w1_f29_sysfs_bin_files[i])); | ||
400 | if (err) | ||
401 | while (--i >= 0) | ||
402 | sysfs_remove_bin_file(&sl->dev.kobj, | ||
403 | &(w1_f29_sysfs_bin_files[i])); | ||
404 | return err; | ||
405 | } | ||
406 | 339 | ||
407 | static void w1_f29_remove_slave(struct w1_slave *sl) | 340 | static const struct attribute_group *w1_f29_groups[] = { |
408 | { | 341 | &w1_f29_group, |
409 | int i; | 342 | NULL, |
410 | for (i = ARRAY_SIZE(w1_f29_sysfs_bin_files) - 1; i >= 0; --i) | 343 | }; |
411 | sysfs_remove_bin_file(&sl->dev.kobj, | ||
412 | &(w1_f29_sysfs_bin_files[i])); | ||
413 | } | ||
414 | 344 | ||
415 | static struct w1_family_ops w1_f29_fops = { | 345 | static struct w1_family_ops w1_f29_fops = { |
416 | .add_slave = w1_f29_add_slave, | 346 | .add_slave = w1_f29_disable_test_mode, |
417 | .remove_slave = w1_f29_remove_slave, | 347 | .groups = w1_f29_groups, |
418 | }; | 348 | }; |
419 | 349 | ||
420 | static struct w1_family w1_family_29 = { | 350 | static struct w1_family w1_family_29 = { |