aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/w1/w1.c
diff options
context:
space:
mode:
authorEvgeniy Polyakov <johnpol@2ka.mipt.ru>2006-03-23 11:11:58 -0500
committerGreg Kroah-Hartman <gregkh@suse.de>2006-06-22 14:22:50 -0400
commitf522d2396138e68bcb9cc5650aa368a81d7f7ff0 (patch)
tree3446d411b996b19094856c5729725e0e43ff4b0e /drivers/w1/w1.c
parent52ab3f3dc711eeccbfbcc5d4f5c5d9b9ff59650f (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/w1.c')
-rw-r--r--drivers/w1/w1.c69
1 files changed, 68 insertions, 1 deletions
diff --git a/drivers/w1/w1.c b/drivers/w1/w1.c
index a698b517e863..c9486c168505 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 */
142static struct w1_family w1_default_family; 142
143static 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
159out_up:
160 up(&sl->master->mutex);
161out:
162 return count;
163}
164
165static 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);
177out:
178 return count;
179}
180
181static 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
192static int w1_default_add_slave(struct w1_slave *sl)
193{
194 return sysfs_create_bin_file(&sl->dev.kobj, &w1_default_attr);
195}
196
197static void w1_default_remove_slave(struct w1_slave *sl)
198{
199 sysfs_remove_bin_file(&sl->dev.kobj, &w1_default_attr);
200}
201
202static struct w1_family_ops w1_default_fops = {
203 .add_slave = w1_default_add_slave,
204 .remove_slave = w1_default_remove_slave,
205};
206
207static struct w1_family w1_default_family = {
208 .fops = &w1_default_fops,
209};
143 210
144static int w1_uevent(struct device *dev, char **envp, int num_envp, char *buffer, int buffer_size); 211static int w1_uevent(struct device *dev, char **envp, int num_envp, char *buffer, int buffer_size);
145 212