1*4882a593Smuzhiyun========================================= 2*4882a593SmuzhiyunIntroduction to the 1-wire (w1) subsystem 3*4882a593Smuzhiyun========================================= 4*4882a593Smuzhiyun 5*4882a593SmuzhiyunThe 1-wire bus is a simple master-slave bus that communicates via a single 6*4882a593Smuzhiyunsignal wire (plus ground, so two wires). 7*4882a593Smuzhiyun 8*4882a593SmuzhiyunDevices communicate on the bus by pulling the signal to ground via an open 9*4882a593Smuzhiyundrain output and by sampling the logic level of the signal line. 10*4882a593Smuzhiyun 11*4882a593SmuzhiyunThe w1 subsystem provides the framework for managing w1 masters and 12*4882a593Smuzhiyuncommunication with slaves. 13*4882a593Smuzhiyun 14*4882a593SmuzhiyunAll w1 slave devices must be connected to a w1 bus master device. 15*4882a593Smuzhiyun 16*4882a593SmuzhiyunExample w1 master devices: 17*4882a593Smuzhiyun 18*4882a593Smuzhiyun - DS9490 usb device 19*4882a593Smuzhiyun - W1-over-GPIO 20*4882a593Smuzhiyun - DS2482 (i2c to w1 bridge) 21*4882a593Smuzhiyun - Emulated devices, such as a RS232 converter, parallel port adapter, etc 22*4882a593Smuzhiyun 23*4882a593Smuzhiyun 24*4882a593SmuzhiyunWhat does the w1 subsystem do? 25*4882a593Smuzhiyun------------------------------ 26*4882a593Smuzhiyun 27*4882a593SmuzhiyunWhen a w1 master driver registers with the w1 subsystem, the following occurs: 28*4882a593Smuzhiyun 29*4882a593Smuzhiyun - sysfs entries for that w1 master are created 30*4882a593Smuzhiyun - the w1 bus is periodically searched for new slave devices 31*4882a593Smuzhiyun 32*4882a593SmuzhiyunWhen a device is found on the bus, w1 core tries to load the driver for its family 33*4882a593Smuzhiyunand check if it is loaded. If so, the family driver is attached to the slave. 34*4882a593SmuzhiyunIf there is no driver for the family, default one is assigned, which allows to perform 35*4882a593Smuzhiyunalmost any kind of operations. Each logical operation is a transaction 36*4882a593Smuzhiyunin nature, which can contain several (two or one) low-level operations. 37*4882a593SmuzhiyunLet's see how one can read EEPROM context: 38*4882a593Smuzhiyun1. one must write control buffer, i.e. buffer containing command byte 39*4882a593Smuzhiyunand two byte address. At this step bus is reset and appropriate device 40*4882a593Smuzhiyunis selected using either W1_SKIP_ROM or W1_MATCH_ROM command. 41*4882a593SmuzhiyunThen provided control buffer is being written to the wire. 42*4882a593Smuzhiyun2. reading. This will issue reading eeprom response. 43*4882a593Smuzhiyun 44*4882a593SmuzhiyunIt is possible that between 1. and 2. w1 master thread will reset bus for searching 45*4882a593Smuzhiyunand slave device will be even removed, but in this case 0xff will 46*4882a593Smuzhiyunbe read, since no device was selected. 47*4882a593Smuzhiyun 48*4882a593Smuzhiyun 49*4882a593SmuzhiyunW1 device families 50*4882a593Smuzhiyun------------------ 51*4882a593Smuzhiyun 52*4882a593SmuzhiyunSlave devices are handled by a driver written for a family of w1 devices. 53*4882a593Smuzhiyun 54*4882a593SmuzhiyunA family driver populates a struct w1_family_ops (see w1_family.h) and 55*4882a593Smuzhiyunregisters with the w1 subsystem. 56*4882a593Smuzhiyun 57*4882a593SmuzhiyunCurrent family drivers: 58*4882a593Smuzhiyun 59*4882a593Smuzhiyunw1_therm 60*4882a593Smuzhiyun - (ds18?20 thermal sensor family driver) 61*4882a593Smuzhiyun provides temperature reading function which is bound to ->rbin() method 62*4882a593Smuzhiyun of the above w1_family_ops structure. 63*4882a593Smuzhiyun 64*4882a593Smuzhiyunw1_smem 65*4882a593Smuzhiyun - driver for simple 64bit memory cell provides ID reading method. 66*4882a593Smuzhiyun 67*4882a593SmuzhiyunYou can call above methods by reading appropriate sysfs files. 68*4882a593Smuzhiyun 69*4882a593Smuzhiyun 70*4882a593SmuzhiyunWhat does a w1 master driver need to implement? 71*4882a593Smuzhiyun----------------------------------------------- 72*4882a593Smuzhiyun 73*4882a593SmuzhiyunThe driver for w1 bus master must provide at minimum two functions. 74*4882a593Smuzhiyun 75*4882a593SmuzhiyunEmulated devices must provide the ability to set the output signal level 76*4882a593Smuzhiyun(write_bit) and sample the signal level (read_bit). 77*4882a593Smuzhiyun 78*4882a593SmuzhiyunDevices that support the 1-wire natively must provide the ability to write and 79*4882a593Smuzhiyunsample a bit (touch_bit) and reset the bus (reset_bus). 80*4882a593Smuzhiyun 81*4882a593SmuzhiyunMost hardware provides higher-level functions that offload w1 handling. 82*4882a593SmuzhiyunSee struct w1_bus_master definition in w1.h for details. 83*4882a593Smuzhiyun 84*4882a593Smuzhiyun 85*4882a593Smuzhiyunw1 master sysfs interface 86*4882a593Smuzhiyun------------------------- 87*4882a593Smuzhiyun 88*4882a593Smuzhiyun========================= ===================================================== 89*4882a593Smuzhiyun<xx-xxxxxxxxxxxx> A directory for a found device. The format is 90*4882a593Smuzhiyun family-serial 91*4882a593Smuzhiyunbus (standard) symlink to the w1 bus 92*4882a593Smuzhiyundriver (standard) symlink to the w1 driver 93*4882a593Smuzhiyunw1_master_add (rw) manually register a slave device 94*4882a593Smuzhiyunw1_master_attempts (ro) the number of times a search was attempted 95*4882a593Smuzhiyunw1_master_max_slave_count (rw) maximum number of slaves to search for at a time 96*4882a593Smuzhiyunw1_master_name (ro) the name of the device (w1_bus_masterX) 97*4882a593Smuzhiyunw1_master_pullup (rw) 5V strong pullup 0 enabled, 1 disabled 98*4882a593Smuzhiyunw1_master_remove (rw) manually remove a slave device 99*4882a593Smuzhiyunw1_master_search (rw) the number of searches left to do, 100*4882a593Smuzhiyun -1=continual (default) 101*4882a593Smuzhiyunw1_master_slave_count (ro) the number of slaves found 102*4882a593Smuzhiyunw1_master_slaves (ro) the names of the slaves, one per line 103*4882a593Smuzhiyunw1_master_timeout (ro) the delay in seconds between searches 104*4882a593Smuzhiyunw1_master_timeout_us (ro) the delay in microseconds beetwen searches 105*4882a593Smuzhiyun========================= ===================================================== 106*4882a593Smuzhiyun 107*4882a593SmuzhiyunIf you have a w1 bus that never changes (you don't add or remove devices), 108*4882a593Smuzhiyunyou can set the module parameter search_count to a small positive number 109*4882a593Smuzhiyunfor an initially small number of bus searches. Alternatively it could be 110*4882a593Smuzhiyunset to zero, then manually add the slave device serial numbers by 111*4882a593Smuzhiyunw1_master_add device file. The w1_master_add and w1_master_remove files 112*4882a593Smuzhiyungenerally only make sense when searching is disabled, as a search will 113*4882a593Smuzhiyunredetect manually removed devices that are present and timeout manually 114*4882a593Smuzhiyunadded devices that aren't on the bus. 115*4882a593Smuzhiyun 116*4882a593SmuzhiyunBus searches occur at an interval, specified as a summ of timeout and 117*4882a593Smuzhiyuntimeout_us module parameters (either of which may be 0) for as long as 118*4882a593Smuzhiyunw1_master_search remains greater than 0 or is -1. Each search attempt 119*4882a593Smuzhiyundecrements w1_master_search by 1 (down to 0) and increments 120*4882a593Smuzhiyunw1_master_attempts by 1. 121*4882a593Smuzhiyun 122*4882a593Smuzhiyunw1 slave sysfs interface 123*4882a593Smuzhiyun------------------------ 124*4882a593Smuzhiyun 125*4882a593Smuzhiyun=================== ============================================================ 126*4882a593Smuzhiyunbus (standard) symlink to the w1 bus 127*4882a593Smuzhiyundriver (standard) symlink to the w1 driver 128*4882a593Smuzhiyunname the device name, usually the same as the directory name 129*4882a593Smuzhiyunw1_slave (optional) a binary file whose meaning depends on the 130*4882a593Smuzhiyun family driver 131*4882a593Smuzhiyunrw (optional) created for slave devices which do not have 132*4882a593Smuzhiyun appropriate family driver. Allows to read/write binary data. 133*4882a593Smuzhiyun=================== ============================================================ 134