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