w1.generic 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. The 1-wire (w1) subsystem
  2. ------------------------------------------------------------------
  3. The 1-wire bus is a simple master-slave bus that communicates via a single
  4. signal wire (plus ground, so two wires).
  5. Devices communicate on the bus by pulling the signal to ground via an open
  6. drain output and by sampling the logic level of the signal line.
  7. The w1 subsystem provides the framework for managing w1 masters and
  8. communication with slaves.
  9. All w1 slave devices must be connected to a w1 bus master device.
  10. Example w1 master devices:
  11. DS9490 usb device
  12. W1-over-GPIO
  13. DS2482 (i2c to w1 bridge)
  14. Emulated devices, such as a RS232 converter, parallel port adapter, etc
  15. What does the w1 subsystem do?
  16. ------------------------------------------------------------------
  17. When a w1 master driver registers with the w1 subsystem, the following occurs:
  18. - sysfs entries for that w1 master are created
  19. - the w1 bus is periodically searched for new slave devices
  20. When a device is found on the bus, w1 core checks if driver for its family is
  21. loaded. If so, the family driver is attached to the slave.
  22. If there is no driver for the family, default one is assigned, which allows to perform
  23. almost any kind of operations. Each logical operation is a transaction
  24. in nature, which can contain several (two or one) low-level operations.
  25. Let's see how one can read EEPROM context:
  26. 1. one must write control buffer, i.e. buffer containing command byte
  27. and two byte address. At this step bus is reset and appropriate device
  28. is selected using either W1_SKIP_ROM or W1_MATCH_ROM command.
  29. Then provided control buffer is being written to the wire.
  30. 2. reading. This will issue reading eeprom response.
  31. It is possible that between 1. and 2. w1 master thread will reset bus for searching
  32. and slave device will be even removed, but in this case 0xff will
  33. be read, since no device was selected.
  34. W1 device families
  35. ------------------------------------------------------------------
  36. Slave devices are handled by a driver written for a family of w1 devices.
  37. A family driver populates a struct w1_family_ops (see w1_family.h) and
  38. registers with the w1 subsystem.
  39. Current family drivers:
  40. w1_therm - (ds18?20 thermal sensor family driver)
  41. provides temperature reading function which is bound to ->rbin() method
  42. of the above w1_family_ops structure.
  43. w1_smem - driver for simple 64bit memory cell provides ID reading method.
  44. You can call above methods by reading appropriate sysfs files.
  45. What does a w1 master driver need to implement?
  46. ------------------------------------------------------------------
  47. The driver for w1 bus master must provide at minimum two functions.
  48. Emulated devices must provide the ability to set the output signal level
  49. (write_bit) and sample the signal level (read_bit).
  50. Devices that support the 1-wire natively must provide the ability to write and
  51. sample a bit (touch_bit) and reset the bus (reset_bus).
  52. Most hardware provides higher-level functions that offload w1 handling.
  53. See struct w1_bus_master definition in w1.h for details.
  54. w1 master sysfs interface
  55. ------------------------------------------------------------------
  56. <xx-xxxxxxxxxxxxx> - a directory for a found device. The format is family-serial
  57. bus - (standard) symlink to the w1 bus
  58. driver - (standard) symlink to the w1 driver
  59. w1_master_add - Manually register a slave device
  60. w1_master_attempts - the number of times a search was attempted
  61. w1_master_max_slave_count
  62. - the maximum slaves that may be attached to a master
  63. w1_master_name - the name of the device (w1_bus_masterX)
  64. w1_master_pullup - 5V strong pullup 0 enabled, 1 disabled
  65. w1_master_remove - Manually remove a slave device
  66. w1_master_search - the number of searches left to do, -1=continual (default)
  67. w1_master_slave_count
  68. - the number of slaves found
  69. w1_master_slaves - the names of the slaves, one per line
  70. w1_master_timeout - the delay in seconds between searches
  71. If you have a w1 bus that never changes (you don't add or remove devices),
  72. you can set the module parameter search_count to a small positive number
  73. for an initially small number of bus searches. Alternatively it could be
  74. set to zero, then manually add the slave device serial numbers by
  75. w1_master_add device file. The w1_master_add and w1_master_remove files
  76. generally only make sense when searching is disabled, as a search will
  77. redetect manually removed devices that are present and timeout manually
  78. added devices that aren't on the bus.
  79. w1 slave sysfs interface
  80. ------------------------------------------------------------------
  81. bus - (standard) symlink to the w1 bus
  82. driver - (standard) symlink to the w1 driver
  83. name - the device name, usually the same as the directory name
  84. w1_slave - (optional) a binary file whose meaning depends on the
  85. family driver
  86. rw - (optional) created for slave devices which do not have
  87. appropriate family driver. Allows to read/write binary data.