i2c-sensor.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. /*
  2. i2c-sensor.h - Part of the i2c package
  3. was originally sensors.h - Part of lm_sensors, Linux kernel modules
  4. for hardware monitoring
  5. Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl>
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18. #ifndef _LINUX_I2C_SENSOR_H
  19. #define _LINUX_I2C_SENSOR_H
  20. /* A structure containing the detect information.
  21. normal_i2c: filled in by the module writer. Terminated by I2C_CLIENT_END.
  22. A list of I2C addresses which should normally be examined.
  23. probe: insmod parameter. Initialize this list with I2C_CLIENT_END values.
  24. A list of pairs. The first value is a bus number (ANY_I2C_BUS for any
  25. I2C bus), the second is the address. These addresses are also probed,
  26. as if they were in the 'normal' list.
  27. ignore: insmod parameter. Initialize this list with I2C_CLIENT_END values.
  28. A list of pairs. The first value is a bus number (ANY_I2C_BUS for any
  29. I2C bus), the second is the I2C address. These addresses are never
  30. probed. This parameter overrules 'normal' and probe', but not the
  31. 'force' lists.
  32. forces: insmod parameters. A list, ending with a NULL element.
  33. Force variables overrule all other variables; they force a detection on
  34. that place. If a specific chip is given, the module blindly assumes this
  35. chip type is present; if a general force (kind == 0) is given, the module
  36. will still try to figure out what type of chip is present. This is useful
  37. if for some reasons the detect for SMBus address space filled fails.
  38. */
  39. struct i2c_address_data {
  40. unsigned short *normal_i2c;
  41. unsigned short *probe;
  42. unsigned short *ignore;
  43. unsigned short **forces;
  44. };
  45. #define SENSORS_MODULE_PARM_FORCE(name) \
  46. I2C_CLIENT_MODULE_PARM(force_ ## name, \
  47. "List of adapter,address pairs which are unquestionably" \
  48. " assumed to contain a `" # name "' chip")
  49. /* This defines several insmod variables, and the addr_data structure */
  50. #define SENSORS_INSMOD \
  51. I2C_CLIENT_MODULE_PARM(probe, \
  52. "List of adapter,address pairs to scan additionally"); \
  53. I2C_CLIENT_MODULE_PARM(ignore, \
  54. "List of adapter,address pairs not to scan"); \
  55. static struct i2c_address_data addr_data = { \
  56. .normal_i2c = normal_i2c, \
  57. .probe = probe, \
  58. .ignore = ignore, \
  59. .forces = forces, \
  60. }
  61. /* The following functions create an enum with the chip names as elements.
  62. The first element of the enum is any_chip. These are the only macros
  63. a module will want to use. */
  64. #define SENSORS_INSMOD_0 \
  65. enum chips { any_chip }; \
  66. I2C_CLIENT_MODULE_PARM(force, \
  67. "List of adapter,address pairs to boldly assume " \
  68. "to be present"); \
  69. static unsigned short *forces[] = { force, \
  70. NULL }; \
  71. SENSORS_INSMOD
  72. #define SENSORS_INSMOD_1(chip1) \
  73. enum chips { any_chip, chip1 }; \
  74. I2C_CLIENT_MODULE_PARM(force, \
  75. "List of adapter,address pairs to boldly assume " \
  76. "to be present"); \
  77. SENSORS_MODULE_PARM_FORCE(chip1); \
  78. static unsigned short *forces[] = { force, \
  79. force_##chip1, \
  80. NULL }; \
  81. SENSORS_INSMOD
  82. #define SENSORS_INSMOD_2(chip1,chip2) \
  83. enum chips { any_chip, chip1, chip2 }; \
  84. I2C_CLIENT_MODULE_PARM(force, \
  85. "List of adapter,address pairs to boldly assume " \
  86. "to be present"); \
  87. SENSORS_MODULE_PARM_FORCE(chip1); \
  88. SENSORS_MODULE_PARM_FORCE(chip2); \
  89. static unsigned short *forces[] = { force, \
  90. force_##chip1, \
  91. force_##chip2, \
  92. NULL }; \
  93. SENSORS_INSMOD
  94. #define SENSORS_INSMOD_3(chip1,chip2,chip3) \
  95. enum chips { any_chip, chip1, chip2, chip3 }; \
  96. I2C_CLIENT_MODULE_PARM(force, \
  97. "List of adapter,address pairs to boldly assume " \
  98. "to be present"); \
  99. SENSORS_MODULE_PARM_FORCE(chip1); \
  100. SENSORS_MODULE_PARM_FORCE(chip2); \
  101. SENSORS_MODULE_PARM_FORCE(chip3); \
  102. static unsigned short *forces[] = { force, \
  103. force_##chip1, \
  104. force_##chip2, \
  105. force_##chip3, \
  106. NULL }; \
  107. SENSORS_INSMOD
  108. #define SENSORS_INSMOD_4(chip1,chip2,chip3,chip4) \
  109. enum chips { any_chip, chip1, chip2, chip3, chip4 }; \
  110. I2C_CLIENT_MODULE_PARM(force, \
  111. "List of adapter,address pairs to boldly assume " \
  112. "to be present"); \
  113. SENSORS_MODULE_PARM_FORCE(chip1); \
  114. SENSORS_MODULE_PARM_FORCE(chip2); \
  115. SENSORS_MODULE_PARM_FORCE(chip3); \
  116. SENSORS_MODULE_PARM_FORCE(chip4); \
  117. static unsigned short *forces[] = { force, \
  118. force_##chip1, \
  119. force_##chip2, \
  120. force_##chip3, \
  121. force_##chip4, \
  122. NULL}; \
  123. SENSORS_INSMOD
  124. #define SENSORS_INSMOD_5(chip1,chip2,chip3,chip4,chip5) \
  125. enum chips { any_chip, chip1, chip2, chip3, chip4, chip5 }; \
  126. I2C_CLIENT_MODULE_PARM(force, \
  127. "List of adapter,address pairs to boldly assume " \
  128. "to be present"); \
  129. SENSORS_MODULE_PARM_FORCE(chip1); \
  130. SENSORS_MODULE_PARM_FORCE(chip2); \
  131. SENSORS_MODULE_PARM_FORCE(chip3); \
  132. SENSORS_MODULE_PARM_FORCE(chip4); \
  133. SENSORS_MODULE_PARM_FORCE(chip5); \
  134. static unsigned short *forces[] = { force, \
  135. force_##chip1, \
  136. force_##chip2, \
  137. force_##chip3, \
  138. force_##chip4, \
  139. force_##chip5, \
  140. NULL }; \
  141. SENSORS_INSMOD
  142. #define SENSORS_INSMOD_6(chip1,chip2,chip3,chip4,chip5,chip6) \
  143. enum chips { any_chip, chip1, chip2, chip3, chip4, chip5, chip6 }; \
  144. I2C_CLIENT_MODULE_PARM(force, \
  145. "List of adapter,address pairs to boldly assume " \
  146. "to be present"); \
  147. SENSORS_MODULE_PARM_FORCE(chip1); \
  148. SENSORS_MODULE_PARM_FORCE(chip2); \
  149. SENSORS_MODULE_PARM_FORCE(chip3); \
  150. SENSORS_MODULE_PARM_FORCE(chip4); \
  151. SENSORS_MODULE_PARM_FORCE(chip5); \
  152. SENSORS_MODULE_PARM_FORCE(chip6); \
  153. static unsigned short *forces[] = { force, \
  154. force_##chip1, \
  155. force_##chip2, \
  156. force_##chip3, \
  157. force_##chip4, \
  158. force_##chip5, \
  159. force_##chip6, \
  160. NULL }; \
  161. SENSORS_INSMOD
  162. #define SENSORS_INSMOD_7(chip1,chip2,chip3,chip4,chip5,chip6,chip7) \
  163. enum chips { any_chip, chip1, chip2, chip3, chip4, chip5, chip6, chip7 }; \
  164. I2C_CLIENT_MODULE_PARM(force, \
  165. "List of adapter,address pairs to boldly assume " \
  166. "to be present"); \
  167. SENSORS_MODULE_PARM_FORCE(chip1); \
  168. SENSORS_MODULE_PARM_FORCE(chip2); \
  169. SENSORS_MODULE_PARM_FORCE(chip3); \
  170. SENSORS_MODULE_PARM_FORCE(chip4); \
  171. SENSORS_MODULE_PARM_FORCE(chip5); \
  172. SENSORS_MODULE_PARM_FORCE(chip6); \
  173. SENSORS_MODULE_PARM_FORCE(chip7); \
  174. static unsigned short *forces[] = { force, \
  175. force_##chip1, \
  176. force_##chip2, \
  177. force_##chip3, \
  178. force_##chip4, \
  179. force_##chip5, \
  180. force_##chip6, \
  181. force_##chip7, \
  182. NULL }; \
  183. SENSORS_INSMOD
  184. #define SENSORS_INSMOD_8(chip1,chip2,chip3,chip4,chip5,chip6,chip7,chip8) \
  185. enum chips { any_chip, chip1, chip2, chip3, chip4, chip5, chip6, chip7, chip8 }; \
  186. I2C_CLIENT_MODULE_PARM(force, \
  187. "List of adapter,address pairs to boldly assume " \
  188. "to be present"); \
  189. SENSORS_MODULE_PARM_FORCE(chip1); \
  190. SENSORS_MODULE_PARM_FORCE(chip2); \
  191. SENSORS_MODULE_PARM_FORCE(chip3); \
  192. SENSORS_MODULE_PARM_FORCE(chip4); \
  193. SENSORS_MODULE_PARM_FORCE(chip5); \
  194. SENSORS_MODULE_PARM_FORCE(chip6); \
  195. SENSORS_MODULE_PARM_FORCE(chip7); \
  196. SENSORS_MODULE_PARM_FORCE(chip8); \
  197. static unsigned short *forces[] = { force, \
  198. force_##chip1, \
  199. force_##chip2, \
  200. force_##chip3, \
  201. force_##chip4, \
  202. force_##chip5, \
  203. force_##chip6, \
  204. force_##chip7, \
  205. force_##chip8, \
  206. NULL }; \
  207. SENSORS_INSMOD
  208. /* Detect function. It iterates over all possible addresses itself. For
  209. SMBus addresses, it will only call found_proc if some client is connected
  210. to the SMBus (unless a 'force' matched). */
  211. extern int i2c_detect(struct i2c_adapter *adapter,
  212. struct i2c_address_data *address_data,
  213. int (*found_proc) (struct i2c_adapter *, int, int));
  214. #endif /* def _LINUX_I2C_SENSOR_H */