diff options
author | Evgeniy Polyakov <johnpol@2ka.mipt.ru> | 2006-03-23 11:11:58 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2006-06-22 14:22:50 -0400 |
commit | f522d2396138e68bcb9cc5650aa368a81d7f7ff0 (patch) | |
tree | 3446d411b996b19094856c5729725e0e43ff4b0e /drivers/w1 | |
parent | 52ab3f3dc711eeccbfbcc5d4f5c5d9b9ff59650f (diff) |
[PATCH] w1: Added default generic read/write operations.
Special file in each w1 slave device's directory called "rw" is created
each time new slave and no appropriate w1 family is registered.
"rw" file supports read and write operations, which allows to perform
almost any kind of operations. Each logical operation is a transaction
in nature, which can contain several (two or one) low-level operations.
Let's see how one can read EEPROM context:
1. one must write control buffer, i.e. buffer containing command byte
and two byte address. At this step bus is reset and appropriate device
is selected using either W1_SKIP_ROM or W1_MATCH_ROM command.
Then provided control buffer is being written to the wire.
2. reading. This will issue reading eeprom response.
It is possible that between 1. and 2. w1 master thread will reset bus for
searching and slave device will be even removed, but in this case 0xff will
be read, since no device was selected.
Signed-off-by: Evgeniy Polyakov <johnpol@2ka.mipt.ru>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/w1')
-rw-r--r-- | drivers/w1/w1.c | 69 | ||||
-rw-r--r-- | drivers/w1/w1.h | 2 |
2 files changed, 69 insertions, 2 deletions
diff --git a/drivers/w1/w1.c b/drivers/w1/w1.c index a698b517e86..c9486c16850 100644 --- a/drivers/w1/w1.c +++ b/drivers/w1/w1.c | |||
@@ -139,7 +139,74 @@ static struct bin_attribute w1_slave_attr_bin_id = { | |||
139 | }; | 139 | }; |
140 | 140 | ||
141 | /* Default family */ | 141 | /* Default family */ |
142 | static struct w1_family w1_default_family; | 142 | |
143 | static ssize_t w1_default_write(struct kobject *kobj, char *buf, loff_t off, size_t count) | ||
144 | { | ||
145 | struct w1_slave *sl = kobj_to_w1_slave(kobj); | ||
146 | |||
147 | if (down_interruptible(&sl->master->mutex)) { | ||
148 | count = 0; | ||
149 | goto out; | ||
150 | } | ||
151 | |||
152 | if (w1_reset_select_slave(sl)) { | ||
153 | count = 0; | ||
154 | goto out_up; | ||
155 | } | ||
156 | |||
157 | w1_write_block(sl->master, buf, count); | ||
158 | |||
159 | out_up: | ||
160 | up(&sl->master->mutex); | ||
161 | out: | ||
162 | return count; | ||
163 | } | ||
164 | |||
165 | static ssize_t w1_default_read(struct kobject *kobj, char *buf, loff_t off, size_t count) | ||
166 | { | ||
167 | struct w1_slave *sl = kobj_to_w1_slave(kobj); | ||
168 | |||
169 | if (down_interruptible(&sl->master->mutex)) { | ||
170 | count = 0; | ||
171 | goto out; | ||
172 | } | ||
173 | |||
174 | w1_read_block(sl->master, buf, count); | ||
175 | |||
176 | up(&sl->master->mutex); | ||
177 | out: | ||
178 | return count; | ||
179 | } | ||
180 | |||
181 | static struct bin_attribute w1_default_attr = { | ||
182 | .attr = { | ||
183 | .name = "rw", | ||
184 | .mode = S_IRUGO | S_IWUSR, | ||
185 | .owner = THIS_MODULE, | ||
186 | }, | ||
187 | .size = PAGE_SIZE, | ||
188 | .read = w1_default_read, | ||
189 | .write = w1_default_write, | ||
190 | }; | ||
191 | |||
192 | static int w1_default_add_slave(struct w1_slave *sl) | ||
193 | { | ||
194 | return sysfs_create_bin_file(&sl->dev.kobj, &w1_default_attr); | ||
195 | } | ||
196 | |||
197 | static void w1_default_remove_slave(struct w1_slave *sl) | ||
198 | { | ||
199 | sysfs_remove_bin_file(&sl->dev.kobj, &w1_default_attr); | ||
200 | } | ||
201 | |||
202 | static struct w1_family_ops w1_default_fops = { | ||
203 | .add_slave = w1_default_add_slave, | ||
204 | .remove_slave = w1_default_remove_slave, | ||
205 | }; | ||
206 | |||
207 | static struct w1_family w1_default_family = { | ||
208 | .fops = &w1_default_fops, | ||
209 | }; | ||
143 | 210 | ||
144 | static int w1_uevent(struct device *dev, char **envp, int num_envp, char *buffer, int buffer_size); | 211 | static int w1_uevent(struct device *dev, char **envp, int num_envp, char *buffer, int buffer_size); |
145 | 212 | ||
diff --git a/drivers/w1/w1.h b/drivers/w1/w1.h index 56980505e6c..02e8caddfb3 100644 --- a/drivers/w1/w1.h +++ b/drivers/w1/w1.h | |||
@@ -60,7 +60,7 @@ struct w1_reg_num | |||
60 | #define W1_READ_PSUPPLY 0xB4 | 60 | #define W1_READ_PSUPPLY 0xB4 |
61 | #define W1_MATCH_ROM 0x55 | 61 | #define W1_MATCH_ROM 0x55 |
62 | 62 | ||
63 | #define W1_SLAVE_ACTIVE (1<<0) | 63 | #define W1_SLAVE_ACTIVE 0 |
64 | 64 | ||
65 | struct w1_slave | 65 | struct w1_slave |
66 | { | 66 | { |