Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

W1: feature, enable hardware strong pullup

Add a strong pullup option to the w1 system. This supplies extra power
for parasite powered devices. There is a w1_master_pullup sysfs entry and
enable_pullup module parameter to enable or disable the strong pullup.

The one wire bus requires at a minimum one wire and ground. The common
wire is used for sending and receiving data as well as supplying power to
devices that are parasite powered of which temperature sensors can be one
example. The bus must be idle and left high while a temperature
conversion is in progress, in addition the normal pullup resister on
larger networks or even higher temperatures might not supply enough power.
The pullup resister can't provide too much pullup current, because
devices need to pull the bus down to write a value. This enables the
strong pullup for supported hardware, which can supply more current when
requested. Unsupported hardware will just delay with the bus high.

The hardware USB 2490 one wire bus master has a bit on some commands which
will enable the strong pullup as soon as the command finishes executing.
To use strong pullup, call the new w1_next_pullup function to register the
duration. The next write command will call set_pullup before sending the
data, and reset the duration to zero once it returns.

Switched from simple_strtol to strict_strtol.

Signed-off-by: David Fries <david@fries.net>
Cc: Evgeniy Polyakov <johnpol@2ka.mipt.ru>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

David Fries and committed by
Linus Torvalds
6a158c0d 3c52e4e6

+131 -5
+39 -1
drivers/w1/w1.c
··· 246 246 struct device_attribute *attr, 247 247 const char * buf, size_t count) 248 248 { 249 + long tmp; 249 250 struct w1_master *md = dev_to_w1_master(dev); 250 251 252 + if (strict_strtol(buf, 0, &tmp) == -EINVAL) 253 + return -EINVAL; 254 + 251 255 mutex_lock(&md->mutex); 252 - md->search_count = simple_strtol(buf, NULL, 0); 256 + md->search_count = tmp; 253 257 mutex_unlock(&md->mutex); 254 258 wake_up_process(md->thread); 255 259 ··· 269 265 270 266 mutex_lock(&md->mutex); 271 267 count = sprintf(buf, "%d\n", md->search_count); 268 + mutex_unlock(&md->mutex); 269 + 270 + return count; 271 + } 272 + 273 + static ssize_t w1_master_attribute_store_pullup(struct device *dev, 274 + struct device_attribute *attr, 275 + const char *buf, size_t count) 276 + { 277 + long tmp; 278 + struct w1_master *md = dev_to_w1_master(dev); 279 + 280 + if (strict_strtol(buf, 0, &tmp) == -EINVAL) 281 + return -EINVAL; 282 + 283 + mutex_lock(&md->mutex); 284 + md->enable_pullup = tmp; 285 + mutex_unlock(&md->mutex); 286 + wake_up_process(md->thread); 287 + 288 + return count; 289 + } 290 + 291 + static ssize_t w1_master_attribute_show_pullup(struct device *dev, 292 + struct device_attribute *attr, 293 + char *buf) 294 + { 295 + struct w1_master *md = dev_to_w1_master(dev); 296 + ssize_t count; 297 + 298 + mutex_lock(&md->mutex); 299 + count = sprintf(buf, "%d\n", md->enable_pullup); 272 300 mutex_unlock(&md->mutex); 273 301 274 302 return count; ··· 401 365 static W1_MASTER_ATTR_RO(timeout, S_IRUGO); 402 366 static W1_MASTER_ATTR_RO(pointer, S_IRUGO); 403 367 static W1_MASTER_ATTR_RW(search, S_IRUGO | S_IWUGO); 368 + static W1_MASTER_ATTR_RW(pullup, S_IRUGO | S_IWUGO); 404 369 405 370 static struct attribute *w1_master_default_attrs[] = { 406 371 &w1_master_attribute_name.attr, ··· 412 375 &w1_master_attribute_timeout.attr, 413 376 &w1_master_attribute_pointer.attr, 414 377 &w1_master_attribute_search.attr, 378 + &w1_master_attribute_pullup.attr, 415 379 NULL 416 380 }; 417 381
+12
drivers/w1/w1.h
··· 142 142 */ 143 143 u8 (*reset_bus)(void *); 144 144 145 + /** 146 + * Put out a strong pull-up pulse of the specified duration. 147 + * @return -1=Error, 0=completed 148 + */ 149 + u8 (*set_pullup)(void *, int); 150 + 145 151 /** Really nice hardware can handles the different types of ROM search 146 152 * w1_master* is passed to the slave found callback. 147 153 */ ··· 172 166 173 167 void *priv; 174 168 int priv_size; 169 + 170 + /** 5V strong pullup enabled flag, 1 enabled, zero disabled. */ 171 + int enable_pullup; 172 + /** 5V strong pullup duration in milliseconds, zero disabled. */ 173 + int pullup_duration; 175 174 176 175 struct task_struct *thread; 177 176 struct mutex mutex; ··· 212 201 void w1_write_block(struct w1_master *, const u8 *, int); 213 202 u8 w1_read_block(struct w1_master *, u8 *, int); 214 203 int w1_reset_select_slave(struct w1_slave *sl); 204 + void w1_next_pullup(struct w1_master *, int); 215 205 216 206 static inline struct w1_slave* dev_to_w1_slave(struct device *dev) 217 207 {
+16
drivers/w1/w1_int.c
··· 31 31 32 32 static u32 w1_ids = 1; 33 33 34 + static int w1_enable_pullup = 1; 35 + module_param_named(enable_pullup, w1_enable_pullup, int, 0); 36 + 34 37 static struct w1_master * w1_alloc_dev(u32 id, int slave_count, int slave_ttl, 35 38 struct device_driver *driver, 36 39 struct device *device) ··· 62 59 dev->initialized = 0; 63 60 dev->id = id; 64 61 dev->slave_ttl = slave_ttl; 62 + dev->enable_pullup = w1_enable_pullup; 65 63 dev->search_count = -1; /* continual scan */ 66 64 67 65 /* 1 for w1_process to decrement ··· 111 107 printk(KERN_ERR "w1_add_master_device: invalid function set\n"); 112 108 return(-EINVAL); 113 109 } 110 + /* While it would be electrically possible to make a device that 111 + * generated a strong pullup in bit bang mode, only hardare that 112 + * controls 1-wire time frames are even expected to support a strong 113 + * pullup. w1_io.c would need to support calling set_pullup before 114 + * the last write_bit operation of a w1_write_8 which it currently 115 + * doesn't. 116 + */ 117 + if (!master->write_byte && !master->touch_bit && master->set_pullup) { 118 + printk(KERN_ERR "w1_add_master_device: set_pullup requires " 119 + "write_byte or touch_bit, disabling\n"); 120 + master->set_pullup = NULL; 121 + } 114 122 115 123 dev = w1_alloc_dev(w1_ids++, w1_max_slave_count, w1_max_slave_ttl, &w1_master_driver, &w1_master_device); 116 124 if (!dev)
+64 -4
drivers/w1/w1_io.c
··· 93 93 } 94 94 95 95 /** 96 + * Pre-write operation, currently only supporting strong pullups. 97 + * Program the hardware for a strong pullup, if one has been requested and 98 + * the hardware supports it. 99 + * 100 + * @param dev the master device 101 + */ 102 + static void w1_pre_write(struct w1_master *dev) 103 + { 104 + if (dev->pullup_duration && 105 + dev->enable_pullup && dev->bus_master->set_pullup) { 106 + dev->bus_master->set_pullup(dev->bus_master->data, 107 + dev->pullup_duration); 108 + } 109 + } 110 + 111 + /** 112 + * Post-write operation, currently only supporting strong pullups. 113 + * If a strong pullup was requested, clear it if the hardware supports 114 + * them, or execute the delay otherwise, in either case clear the request. 115 + * 116 + * @param dev the master device 117 + */ 118 + static void w1_post_write(struct w1_master *dev) 119 + { 120 + if (dev->pullup_duration) { 121 + if (dev->enable_pullup && dev->bus_master->set_pullup) 122 + dev->bus_master->set_pullup(dev->bus_master->data, 0); 123 + else 124 + msleep(dev->pullup_duration); 125 + dev->pullup_duration = 0; 126 + } 127 + } 128 + 129 + /** 96 130 * Writes 8 bits. 97 131 * 98 132 * @param dev the master device ··· 136 102 { 137 103 int i; 138 104 139 - if (dev->bus_master->write_byte) 105 + if (dev->bus_master->write_byte) { 106 + w1_pre_write(dev); 140 107 dev->bus_master->write_byte(dev->bus_master->data, byte); 108 + } 141 109 else 142 - for (i = 0; i < 8; ++i) 110 + for (i = 0; i < 8; ++i) { 111 + if (i == 7) 112 + w1_pre_write(dev); 143 113 w1_touch_bit(dev, (byte >> i) & 0x1); 114 + } 115 + w1_post_write(dev); 144 116 } 145 117 EXPORT_SYMBOL_GPL(w1_write_8); 146 118 ··· 243 203 { 244 204 int i; 245 205 246 - if (dev->bus_master->write_block) 206 + if (dev->bus_master->write_block) { 207 + w1_pre_write(dev); 247 208 dev->bus_master->write_block(dev->bus_master->data, buf, len); 209 + } 248 210 else 249 211 for (i = 0; i < len; ++i) 250 - w1_write_8(dev, buf[i]); 212 + w1_write_8(dev, buf[i]); /* calls w1_pre_write */ 213 + w1_post_write(dev); 251 214 } 252 215 EXPORT_SYMBOL_GPL(w1_write_block); 253 216 ··· 349 306 return 0; 350 307 } 351 308 EXPORT_SYMBOL_GPL(w1_reset_select_slave); 309 + 310 + /** 311 + * Put out a strong pull-up of the specified duration after the next write 312 + * operation. Not all hardware supports strong pullups. Hardware that 313 + * doesn't support strong pullups will sleep for the given time after the 314 + * write operation without a strong pullup. This is a one shot request for 315 + * the next write, specifying zero will clear a previous request. 316 + * The w1 master lock must be held. 317 + * 318 + * @param delay time in milliseconds 319 + * @return 0=success, anything else=error 320 + */ 321 + void w1_next_pullup(struct w1_master *dev, int delay) 322 + { 323 + dev->pullup_duration = delay; 324 + } 325 + EXPORT_SYMBOL_GPL(w1_next_pullup);