aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/w1/w1.generic18
-rw-r--r--drivers/w1/w1.c69
-rw-r--r--drivers/w1/w1.h2
3 files changed, 84 insertions, 5 deletions
diff --git a/Documentation/w1/w1.generic b/Documentation/w1/w1.generic
index f937fbe1cacb..4c6509dd4789 100644
--- a/Documentation/w1/w1.generic
+++ b/Documentation/w1/w1.generic
@@ -27,8 +27,19 @@ When a w1 master driver registers with the w1 subsystem, the following occurs:
27 27
28When a device is found on the bus, w1 core checks if driver for it's family is 28When a device is found on the bus, w1 core checks if driver for it's family is
29loaded. If so, the family driver is attached to the slave. 29loaded. If so, the family driver is attached to the slave.
30If there is no driver for the family, a simple sysfs entry is created 30If there is no driver for the family, default one is assigned, which allows to perform
31for the slave device. 31almost any kind of operations. Each logical operation is a transaction
32in nature, which can contain several (two or one) low-level operations.
33Let's see how one can read EEPROM context:
341. one must write control buffer, i.e. buffer containing command byte
35and two byte address. At this step bus is reset and appropriate device
36is selected using either W1_SKIP_ROM or W1_MATCH_ROM command.
37Then provided control buffer is being written to the wire.
382. reading. This will issue reading eeprom response.
39
40It is possible that between 1. and 2. w1 master thread will reset bus for searching
41and slave device will be even removed, but in this case 0xff will
42be read, since no device was selected.
32 43
33 44
34W1 device families 45W1 device families
@@ -89,4 +100,5 @@ driver - (standard) symlink to the w1 driver
89name - the device name, usually the same as the directory name 100name - the device name, usually the same as the directory name
90w1_slave - (optional) a binary file whose meaning depends on the 101w1_slave - (optional) a binary file whose meaning depends on the
91 family driver 102 family driver
92 103rw - (optional) created for slave devices which do not have
104 appropriate family driver. Allows to read/write binary data.
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
diff --git a/drivers/w1/w1.h b/drivers/w1/w1.h
index 56980505e6c4..02e8caddfb36 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
65struct w1_slave 65struct w1_slave
66{ 66{