w1.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /*
  2. * w1.h
  3. *
  4. * Copyright (c) 2004 Evgeniy Polyakov <johnpol@2ka.mipt.ru>
  5. *
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. */
  21. #ifndef __W1_H
  22. #define __W1_H
  23. struct w1_reg_num
  24. {
  25. #if defined(__LITTLE_ENDIAN_BITFIELD)
  26. __u64 family:8,
  27. id:48,
  28. crc:8;
  29. #elif defined(__BIG_ENDIAN_BITFIELD)
  30. __u64 crc:8,
  31. id:48,
  32. family:8;
  33. #else
  34. #error "Please fix <asm/byteorder.h>"
  35. #endif
  36. };
  37. #ifdef __KERNEL__
  38. #include <linux/completion.h>
  39. #include <linux/device.h>
  40. #include <net/sock.h>
  41. #include <asm/semaphore.h>
  42. #include "w1_family.h"
  43. #define W1_MAXNAMELEN 32
  44. #define W1_SLAVE_DATA_SIZE 128
  45. #define W1_SEARCH 0xF0
  46. #define W1_CONDITIONAL_SEARCH 0xEC
  47. #define W1_CONVERT_TEMP 0x44
  48. #define W1_SKIP_ROM 0xCC
  49. #define W1_READ_SCRATCHPAD 0xBE
  50. #define W1_READ_ROM 0x33
  51. #define W1_READ_PSUPPLY 0xB4
  52. #define W1_MATCH_ROM 0x55
  53. #define W1_SLAVE_ACTIVE (1<<0)
  54. struct w1_slave
  55. {
  56. struct module *owner;
  57. unsigned char name[W1_MAXNAMELEN];
  58. struct list_head w1_slave_entry;
  59. struct w1_reg_num reg_num;
  60. atomic_t refcnt;
  61. u8 rom[9];
  62. u32 flags;
  63. int ttl;
  64. struct w1_master *master;
  65. struct w1_family *family;
  66. struct device dev;
  67. struct completion dev_released;
  68. struct bin_attribute attr_bin;
  69. struct device_attribute attr_name;
  70. };
  71. typedef void (* w1_slave_found_callback)(unsigned long, u64);
  72. /**
  73. * Note: read_bit and write_bit are very low level functions and should only
  74. * be used with hardware that doesn't really support 1-wire operations,
  75. * like a parallel/serial port.
  76. * Either define read_bit and write_bit OR define, at minimum, touch_bit and
  77. * reset_bus.
  78. */
  79. struct w1_bus_master
  80. {
  81. /** the first parameter in all the functions below */
  82. unsigned long data;
  83. /**
  84. * Sample the line level
  85. * @return the level read (0 or 1)
  86. */
  87. u8 (*read_bit)(unsigned long);
  88. /** Sets the line level */
  89. void (*write_bit)(unsigned long, u8);
  90. /**
  91. * touch_bit is the lowest-level function for devices that really
  92. * support the 1-wire protocol.
  93. * touch_bit(0) = write-0 cycle
  94. * touch_bit(1) = write-1 / read cycle
  95. * @return the bit read (0 or 1)
  96. */
  97. u8 (*touch_bit)(unsigned long, u8);
  98. /**
  99. * Reads a bytes. Same as 8 touch_bit(1) calls.
  100. * @return the byte read
  101. */
  102. u8 (*read_byte)(unsigned long);
  103. /**
  104. * Writes a byte. Same as 8 touch_bit(x) calls.
  105. */
  106. void (*write_byte)(unsigned long, u8);
  107. /**
  108. * Same as a series of read_byte() calls
  109. * @return the number of bytes read
  110. */
  111. u8 (*read_block)(unsigned long, u8 *, int);
  112. /** Same as a series of write_byte() calls */
  113. void (*write_block)(unsigned long, const u8 *, int);
  114. /**
  115. * Combines two reads and a smart write for ROM searches
  116. * @return bit0=Id bit1=comp_id bit2=dir_taken
  117. */
  118. u8 (*triplet)(unsigned long, u8);
  119. /**
  120. * long write-0 with a read for the presence pulse detection
  121. * @return -1=Error, 0=Device present, 1=No device present
  122. */
  123. u8 (*reset_bus)(unsigned long);
  124. /** Really nice hardware can handles the ROM searches */
  125. void (*search)(unsigned long, w1_slave_found_callback);
  126. };
  127. #define W1_MASTER_NEED_EXIT 0
  128. #define W1_MASTER_NEED_RECONNECT 1
  129. struct w1_master
  130. {
  131. struct list_head w1_master_entry;
  132. struct module *owner;
  133. unsigned char name[W1_MAXNAMELEN];
  134. struct list_head slist;
  135. int max_slave_count, slave_count;
  136. unsigned long attempts;
  137. int slave_ttl;
  138. int initialized;
  139. u32 id;
  140. int search_count;
  141. atomic_t refcnt;
  142. void *priv;
  143. int priv_size;
  144. long flags;
  145. pid_t kpid;
  146. struct semaphore mutex;
  147. struct device_driver *driver;
  148. struct device dev;
  149. struct completion dev_released;
  150. struct completion dev_exited;
  151. struct w1_bus_master *bus_master;
  152. u32 seq, groups;
  153. struct sock *nls;
  154. };
  155. int w1_create_master_attributes(struct w1_master *);
  156. void w1_search(struct w1_master *dev, w1_slave_found_callback cb);
  157. #endif /* __KERNEL__ */
  158. #endif /* __W1_H */