w1.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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, attr_val;
  70. };
  71. typedef void (* w1_slave_found_callback)(unsigned long, u64);
  72. struct w1_bus_master
  73. {
  74. unsigned long data;
  75. u8 (*read_bit)(unsigned long);
  76. void (*write_bit)(unsigned long, u8);
  77. u8 (*read_byte)(unsigned long);
  78. void (*write_byte)(unsigned long, u8);
  79. u8 (*read_block)(unsigned long, u8 *, int);
  80. void (*write_block)(unsigned long, u8 *, int);
  81. u8 (*touch_bit)(unsigned long, u8);
  82. u8 (*reset_bus)(unsigned long);
  83. void (*search)(unsigned long, w1_slave_found_callback);
  84. };
  85. struct w1_master
  86. {
  87. struct list_head w1_master_entry;
  88. struct module *owner;
  89. unsigned char name[W1_MAXNAMELEN];
  90. struct list_head slist;
  91. int max_slave_count, slave_count;
  92. unsigned long attempts;
  93. int slave_ttl;
  94. int initialized;
  95. u32 id;
  96. atomic_t refcnt;
  97. void *priv;
  98. int priv_size;
  99. int need_exit;
  100. pid_t kpid;
  101. struct semaphore mutex;
  102. struct device_driver *driver;
  103. struct device dev;
  104. struct completion dev_released;
  105. struct completion dev_exited;
  106. struct w1_bus_master *bus_master;
  107. u32 seq, groups;
  108. struct sock *nls;
  109. };
  110. int w1_create_master_attributes(struct w1_master *);
  111. void w1_search(struct w1_master *dev);
  112. #endif /* __KERNEL__ */
  113. #endif /* __W1_H */