134 lines · plain
1=========================================2Introduction to the 1-wire (w1) subsystem3=========================================4 5The 1-wire bus is a simple master-slave bus that communicates via a single6signal wire (plus ground, so two wires).7 8Devices communicate on the bus by pulling the signal to ground via an open9drain output and by sampling the logic level of the signal line.10 11The w1 subsystem provides the framework for managing w1 masters and12communication with slaves.13 14All w1 slave devices must be connected to a w1 bus master device.15 16Example w1 master devices:17 18 - DS9490 usb device19 - W1-over-GPIO20 - DS2482 (i2c to w1 bridge)21 - Emulated devices, such as a RS232 converter, parallel port adapter, etc22 23 24What does the w1 subsystem do?25------------------------------26 27When a w1 master driver registers with the w1 subsystem, the following occurs:28 29 - sysfs entries for that w1 master are created30 - the w1 bus is periodically searched for new slave devices31 32When a device is found on the bus, w1 core tries to load the driver for its family33and check if it is loaded. If so, the family driver is attached to the slave.34If there is no driver for the family, default one is assigned, which allows to perform35almost any kind of operations. Each logical operation is a transaction36in nature, which can contain several (two or one) low-level operations.37Let's see how one can read EEPROM context:381. one must write control buffer, i.e. buffer containing command byte39and two byte address. At this step bus is reset and appropriate device40is selected using either W1_SKIP_ROM or W1_MATCH_ROM command.41Then provided control buffer is being written to the wire.422. reading. This will issue reading eeprom response.43 44It is possible that between 1. and 2. w1 master thread will reset bus for searching45and slave device will be even removed, but in this case 0xff will46be read, since no device was selected.47 48 49W1 device families50------------------51 52Slave devices are handled by a driver written for a family of w1 devices.53 54A family driver populates a struct w1_family_ops (see w1_family.h) and55registers with the w1 subsystem.56 57Current family drivers:58 59w1_therm60 - (ds18?20 thermal sensor family driver)61 provides temperature reading function which is bound to ->rbin() method62 of the above w1_family_ops structure.63 64w1_smem65 - driver for simple 64bit memory cell provides ID reading method.66 67You can call above methods by reading appropriate sysfs files.68 69 70What does a w1 master driver need to implement?71-----------------------------------------------72 73The driver for w1 bus master must provide at minimum two functions.74 75Emulated devices must provide the ability to set the output signal level76(write_bit) and sample the signal level (read_bit).77 78Devices that support the 1-wire natively must provide the ability to write and79sample a bit (touch_bit) and reset the bus (reset_bus).80 81Most hardware provides higher-level functions that offload w1 handling.82See struct w1_bus_master definition in w1.h for details.83 84 85w1 master sysfs interface86-------------------------87 88========================= =====================================================89<xx-xxxxxxxxxxxx> A directory for a found device. The format is90 family-serial91bus (standard) symlink to the w1 bus92driver (standard) symlink to the w1 driver93w1_master_add (rw) manually register a slave device94w1_master_attempts (ro) the number of times a search was attempted95w1_master_max_slave_count (rw) maximum number of slaves to search for at a time96w1_master_name (ro) the name of the device (w1_bus_masterX)97w1_master_pullup (rw) 5V strong pullup 0 enabled, 1 disabled98w1_master_remove (rw) manually remove a slave device99w1_master_search (rw) the number of searches left to do,100 -1=continual (default)101w1_master_slave_count (ro) the number of slaves found102w1_master_slaves (ro) the names of the slaves, one per line103w1_master_timeout (ro) the delay in seconds between searches104w1_master_timeout_us (ro) the delay in microseconds between searches105========================= =====================================================106 107If you have a w1 bus that never changes (you don't add or remove devices),108you can set the module parameter search_count to a small positive number109for an initially small number of bus searches. Alternatively it could be110set to zero, then manually add the slave device serial numbers by111w1_master_add device file. The w1_master_add and w1_master_remove files112generally only make sense when searching is disabled, as a search will113redetect manually removed devices that are present and timeout manually114added devices that aren't on the bus.115 116Bus searches occur at an interval, specified as a sum of timeout and117timeout_us module parameters (either of which may be 0) for as long as118w1_master_search remains greater than 0 or is -1. Each search attempt119decrements w1_master_search by 1 (down to 0) and increments120w1_master_attempts by 1.121 122w1 slave sysfs interface123------------------------124 125=================== ============================================================126bus (standard) symlink to the w1 bus127driver (standard) symlink to the w1 driver128name the device name, usually the same as the directory name129w1_slave (optional) a binary file whose meaning depends on the130 family driver131rw (optional) created for slave devices which do not have132 appropriate family driver. Allows to read/write binary data.133=================== ============================================================134