10 #include <linux/kernel.h>
11 #include <linux/module.h>
13 #include <linux/device.h>
14 #include <linux/types.h>
16 #include <linux/slab.h>
19 #include "../w1_int.h"
20 #include "../w1_family.h"
27 #define W1_F29_RETRIES 3
29 #define W1_F29_REG_LOGIG_STATE 0x88
30 #define W1_F29_REG_OUTPUT_LATCH_STATE 0x89
31 #define W1_F29_REG_ACTIVITY_LATCH_STATE 0x8A
32 #define W1_F29_REG_COND_SEARCH_SELECT_MASK 0x8B
33 #define W1_F29_REG_COND_SEARCH_POL_SELECT 0x8C
34 #define W1_F29_REG_CONTROL_AND_STATUS 0x8D
36 #define W1_F29_FUNC_READ_PIO_REGS 0xF0
37 #define W1_F29_FUNC_CHANN_ACCESS_READ 0xF5
38 #define W1_F29_FUNC_CHANN_ACCESS_WRITE 0x5A
40 #define W1_F29_FUNC_WRITE_COND_SEARCH_REG 0xCC
41 #define W1_F29_FUNC_RESET_ACTIVITY_LATCHES 0xC3
43 #define W1_F29_SUCCESS_CONFIRM_BYTE 0xAA
45 static int _read_reg(
struct w1_slave *
sl,
u8 address,
unsigned char*
buf)
49 "Reading with slave: %p, reg addr: %0#4x, buff addr: %p",
50 sl, (
unsigned int)address, buf);
56 dev_dbg(&sl->dev,
"mutex locked");
70 dev_dbg(&sl->dev,
"mutex unlocked");
74 static ssize_t w1_f29_read_state(
80 "Reading %s kobj: %p, off: %0#10x, count: %zu, buff addr: %p",
81 bin_attr->
attr.name, kobj, (
unsigned int)off, count, buf);
82 if (count != 1 || off != 0)
87 static ssize_t w1_f29_read_output(
90 char *buf, loff_t off,
size_t count)
93 "Reading %s kobj: %p, off: %0#10x, count: %zu, buff addr: %p",
94 bin_attr->
attr.name, kobj, (
unsigned int)off, count, buf);
95 if (count != 1 || off != 0)
97 return _read_reg(kobj_to_w1_slave(kobj),
101 static ssize_t w1_f29_read_activity(
104 char *buf, loff_t off,
size_t count)
107 "Reading %s kobj: %p, off: %0#10x, count: %zu, buff addr: %p",
108 bin_attr->
attr.name, kobj, (
unsigned int)off, count, buf);
109 if (count != 1 || off != 0)
111 return _read_reg(kobj_to_w1_slave(kobj),
115 static ssize_t w1_f29_read_cond_search_mask(
118 char *buf, loff_t off,
size_t count)
121 "Reading %s kobj: %p, off: %0#10x, count: %zu, buff addr: %p",
122 bin_attr->
attr.name, kobj, (
unsigned int)off, count, buf);
123 if (count != 1 || off != 0)
125 return _read_reg(kobj_to_w1_slave(kobj),
129 static ssize_t w1_f29_read_cond_search_polarity(
132 char *buf, loff_t off,
size_t count)
134 if (count != 1 || off != 0)
136 return _read_reg(kobj_to_w1_slave(kobj),
140 static ssize_t w1_f29_read_status_control(
143 char *buf, loff_t off,
size_t count)
145 if (count != 1 || off != 0)
147 return _read_reg(kobj_to_w1_slave(kobj),
154 static ssize_t w1_f29_write_output(
157 char *buf, loff_t off,
size_t count)
159 struct w1_slave *
sl = kobj_to_w1_slave(kobj);
164 if (count != 1 || off != 0)
167 dev_dbg(&sl->dev,
"locking mutex for write_output");
169 dev_dbg(&sl->dev,
"mutex locked");
189 if (readBack != 0xAA) {
205 "mutex unlocked, retries:%d", retries);
211 dev_dbg(&sl->dev,
"mutex unlocked in error, retries:%d", retries);
220 static ssize_t w1_f29_write_activity(
223 char *buf, loff_t off,
size_t count)
225 struct w1_slave *sl = kobj_to_w1_slave(kobj);
228 if (count != 1 || off != 0)
251 static ssize_t w1_f29_write_status_control(
259 struct w1_slave *sl = kobj_to_w1_slave(kobj);
263 if (count != 1 || off != 0)
300 #define NB_SYSFS_BIN_FILES 6
308 .read = w1_f29_read_state,
316 .read = w1_f29_read_output,
317 .write = w1_f29_write_output,
325 .read = w1_f29_read_activity,
326 .write = w1_f29_write_activity,
330 .name =
"cond_search_mask",
334 .read = w1_f29_read_cond_search_mask,
338 .name =
"cond_search_polarity",
342 .read = w1_f29_read_cond_search_polarity,
346 .name =
"status_control",
350 .read = w1_f29_read_status_control,
351 .write = w1_f29_write_status_control,
355 static int w1_f29_add_slave(
struct w1_slave *sl)
363 &(w1_f29_sysfs_bin_files[i]));
367 &(w1_f29_sysfs_bin_files[i]));
371 static void w1_f29_remove_slave(
struct w1_slave *sl)
376 &(w1_f29_sysfs_bin_files[i]));
380 .add_slave = w1_f29_add_slave,
381 .remove_slave = w1_f29_remove_slave,
386 .fops = &w1_f29_fops,
389 static int __init w1_f29_init(
void)
394 static void __exit w1_f29_exit(
void)