Back to home page

OSCL-LXR

 
 

    


0001 =========================================
0002 Introduction to the 1-wire (w1) subsystem
0003 =========================================
0004 
0005 The 1-wire bus is a simple master-slave bus that communicates via a single
0006 signal wire (plus ground, so two wires).
0007 
0008 Devices communicate on the bus by pulling the signal to ground via an open
0009 drain output and by sampling the logic level of the signal line.
0010 
0011 The w1 subsystem provides the framework for managing w1 masters and
0012 communication with slaves.
0013 
0014 All w1 slave devices must be connected to a w1 bus master device.
0015 
0016 Example w1 master devices:
0017 
0018     - DS9490 usb device
0019     - W1-over-GPIO
0020     - DS2482 (i2c to w1 bridge)
0021     - Emulated devices, such as a RS232 converter, parallel port adapter, etc
0022 
0023 
0024 What does the w1 subsystem do?
0025 ------------------------------
0026 
0027 When a w1 master driver registers with the w1 subsystem, the following occurs:
0028 
0029  - sysfs entries for that w1 master are created
0030  - the w1 bus is periodically searched for new slave devices
0031 
0032 When a device is found on the bus, w1 core tries to load the driver for its family
0033 and check if it is loaded. If so, the family driver is attached to the slave.
0034 If there is no driver for the family, default one is assigned, which allows to perform
0035 almost any kind of operations. Each logical operation is a transaction
0036 in nature, which can contain several (two or one) low-level operations.
0037 Let's see how one can read EEPROM context:
0038 1. one must write control buffer, i.e. buffer containing command byte
0039 and two byte address. At this step bus is reset and appropriate device
0040 is selected using either W1_SKIP_ROM or W1_MATCH_ROM command.
0041 Then provided control buffer is being written to the wire.
0042 2. reading. This will issue reading eeprom response.
0043 
0044 It is possible that between 1. and 2. w1 master thread will reset bus for searching
0045 and slave device will be even removed, but in this case 0xff will
0046 be read, since no device was selected.
0047 
0048 
0049 W1 device families
0050 ------------------
0051 
0052 Slave devices are handled by a driver written for a family of w1 devices.
0053 
0054 A family driver populates a struct w1_family_ops (see w1_family.h) and
0055 registers with the w1 subsystem.
0056 
0057 Current family drivers:
0058 
0059 w1_therm
0060   - (ds18?20 thermal sensor family driver)
0061     provides temperature reading function which is bound to ->rbin() method
0062     of the above w1_family_ops structure.
0063 
0064 w1_smem
0065   - driver for simple 64bit memory cell provides ID reading method.
0066 
0067 You can call above methods by reading appropriate sysfs files.
0068 
0069 
0070 What does a w1 master driver need to implement?
0071 -----------------------------------------------
0072 
0073 The driver for w1 bus master must provide at minimum two functions.
0074 
0075 Emulated devices must provide the ability to set the output signal level
0076 (write_bit) and sample the signal level (read_bit).
0077 
0078 Devices that support the 1-wire natively must provide the ability to write and
0079 sample a bit (touch_bit) and reset the bus (reset_bus).
0080 
0081 Most hardware provides higher-level functions that offload w1 handling.
0082 See struct w1_bus_master definition in w1.h for details.
0083 
0084 
0085 w1 master sysfs interface
0086 -------------------------
0087 
0088 ========================= =====================================================
0089 <xx-xxxxxxxxxxxx>         A directory for a found device. The format is
0090                           family-serial
0091 bus                       (standard) symlink to the w1 bus
0092 driver                    (standard) symlink to the w1 driver
0093 w1_master_add             (rw) manually register a slave device
0094 w1_master_attempts        (ro) the number of times a search was attempted
0095 w1_master_max_slave_count (rw) maximum number of slaves to search for at a time
0096 w1_master_name            (ro) the name of the device (w1_bus_masterX)
0097 w1_master_pullup          (rw) 5V strong pullup 0 enabled, 1 disabled
0098 w1_master_remove          (rw) manually remove a slave device
0099 w1_master_search          (rw) the number of searches left to do,
0100                           -1=continual (default)
0101 w1_master_slave_count     (ro) the number of slaves found
0102 w1_master_slaves          (ro) the names of the slaves, one per line
0103 w1_master_timeout         (ro) the delay in seconds between searches
0104 w1_master_timeout_us      (ro) the delay in microseconds beetwen searches
0105 ========================= =====================================================
0106 
0107 If you have a w1 bus that never changes (you don't add or remove devices),
0108 you can set the module parameter search_count to a small positive number
0109 for an initially small number of bus searches.  Alternatively it could be
0110 set to zero, then manually add the slave device serial numbers by
0111 w1_master_add device file.  The w1_master_add and w1_master_remove files
0112 generally only make sense when searching is disabled, as a search will
0113 redetect manually removed devices that are present and timeout manually
0114 added devices that aren't on the bus.
0115 
0116 Bus searches occur at an interval, specified as a summ of timeout and
0117 timeout_us module parameters (either of which may be 0) for as long as
0118 w1_master_search remains greater than 0 or is -1.  Each search attempt
0119 decrements w1_master_search by 1 (down to 0) and increments
0120 w1_master_attempts by 1.
0121 
0122 w1 slave sysfs interface
0123 ------------------------
0124 
0125 =================== ============================================================
0126 bus                 (standard) symlink to the w1 bus
0127 driver              (standard) symlink to the w1 driver
0128 name                the device name, usually the same as the directory name
0129 w1_slave            (optional) a binary file whose meaning depends on the
0130                     family driver
0131 rw                  (optional) created for slave devices which do not have
0132                     appropriate family driver. Allows to read/write binary data.
0133 =================== ============================================================