i2c-sensor.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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 detect information.
  21. Force variables overrule all other variables; they force a detection on
  22. that place. If a specific chip is given, the module blindly assumes this
  23. chip type is present; if a general force (kind == 0) is given, the module
  24. will still try to figure out what type of chip is present. This is useful
  25. if for some reasons the detect for SMBus or ISA address space filled
  26. fails.
  27. probe: insmod parameter. Initialize this list with I2C_CLIENT_ISA_END values.
  28. A list of pairs. The first value is a bus number (ANY_I2C_ISA_BUS for
  29. the ISA bus, -1 for any I2C bus), the second is the address.
  30. kind: The kind of chip. 0 equals any chip.
  31. */
  32. struct i2c_force_data {
  33. unsigned short *force;
  34. unsigned short kind;
  35. };
  36. /* A structure containing the detect information.
  37. normal_i2c: filled in by the module writer. Terminated by I2C_CLIENT_ISA_END.
  38. A list of I2C addresses which should normally be examined.
  39. normal_isa: filled in by the module writer. Terminated by SENSORS_ISA_END.
  40. A list of ISA addresses which should normally be examined.
  41. probe: insmod parameter. Initialize this list with I2C_CLIENT_ISA_END values.
  42. A list of pairs. The first value is a bus number (ANY_I2C_ISA_BUS for
  43. the ISA bus, -1 for any I2C bus), the second is the address. These
  44. addresses are also probed, as if they were in the 'normal' list.
  45. ignore: insmod parameter. Initialize this list with I2C_CLIENT_ISA_END values.
  46. A list of pairs. The first value is a bus number (ANY_I2C_ISA_BUS for
  47. the ISA bus, -1 for any I2C bus), the second is the I2C address. These
  48. addresses are never probed. This parameter overrules 'normal' and
  49. 'probe', but not the 'force' lists.
  50. force_data: insmod parameters. A list, ending with an element of which
  51. the force field is NULL.
  52. */
  53. struct i2c_address_data {
  54. unsigned short *normal_i2c;
  55. unsigned int *normal_isa;
  56. unsigned short *probe;
  57. unsigned short *ignore;
  58. struct i2c_force_data *forces;
  59. };
  60. #define SENSORS_MODULE_PARM_FORCE(name) \
  61. I2C_CLIENT_MODULE_PARM(force_ ## name, \
  62. "List of adapter,address pairs which are unquestionably" \
  63. " assumed to contain a `" # name "' chip")
  64. /* This defines several insmod variables, and the addr_data structure */
  65. #define SENSORS_INSMOD \
  66. I2C_CLIENT_MODULE_PARM(probe, \
  67. "List of adapter,address pairs to scan additionally"); \
  68. I2C_CLIENT_MODULE_PARM(ignore, \
  69. "List of adapter,address pairs not to scan"); \
  70. static struct i2c_address_data addr_data = { \
  71. .normal_i2c = normal_i2c, \
  72. .normal_isa = normal_isa, \
  73. .probe = probe, \
  74. .ignore = ignore, \
  75. .forces = forces, \
  76. }
  77. /* The following functions create an enum with the chip names as elements.
  78. The first element of the enum is any_chip. These are the only macros
  79. a module will want to use. */
  80. #define SENSORS_INSMOD_0 \
  81. enum chips { any_chip }; \
  82. I2C_CLIENT_MODULE_PARM(force, \
  83. "List of adapter,address pairs to boldly assume " \
  84. "to be present"); \
  85. static struct i2c_force_data forces[] = {{force,any_chip},{NULL}}; \
  86. SENSORS_INSMOD
  87. #define SENSORS_INSMOD_1(chip1) \
  88. enum chips { any_chip, chip1 }; \
  89. I2C_CLIENT_MODULE_PARM(force, \
  90. "List of adapter,address pairs to boldly assume " \
  91. "to be present"); \
  92. SENSORS_MODULE_PARM_FORCE(chip1); \
  93. static struct i2c_force_data forces[] = {{force,any_chip},\
  94. {force_ ## chip1,chip1}, \
  95. {NULL}}; \
  96. SENSORS_INSMOD
  97. #define SENSORS_INSMOD_2(chip1,chip2) \
  98. enum chips { any_chip, chip1, chip2 }; \
  99. I2C_CLIENT_MODULE_PARM(force, \
  100. "List of adapter,address pairs to boldly assume " \
  101. "to be present"); \
  102. SENSORS_MODULE_PARM_FORCE(chip1); \
  103. SENSORS_MODULE_PARM_FORCE(chip2); \
  104. static struct i2c_force_data forces[] = {{force,any_chip}, \
  105. {force_ ## chip1,chip1}, \
  106. {force_ ## chip2,chip2}, \
  107. {NULL}}; \
  108. SENSORS_INSMOD
  109. #define SENSORS_INSMOD_3(chip1,chip2,chip3) \
  110. enum chips { any_chip, chip1, chip2, chip3 }; \
  111. I2C_CLIENT_MODULE_PARM(force, \
  112. "List of adapter,address pairs to boldly assume " \
  113. "to be present"); \
  114. SENSORS_MODULE_PARM_FORCE(chip1); \
  115. SENSORS_MODULE_PARM_FORCE(chip2); \
  116. SENSORS_MODULE_PARM_FORCE(chip3); \
  117. static struct i2c_force_data forces[] = {{force,any_chip}, \
  118. {force_ ## chip1,chip1}, \
  119. {force_ ## chip2,chip2}, \
  120. {force_ ## chip3,chip3}, \
  121. {NULL}}; \
  122. SENSORS_INSMOD
  123. #define SENSORS_INSMOD_4(chip1,chip2,chip3,chip4) \
  124. enum chips { any_chip, chip1, chip2, chip3, chip4 }; \
  125. I2C_CLIENT_MODULE_PARM(force, \
  126. "List of adapter,address pairs to boldly assume " \
  127. "to be present"); \
  128. SENSORS_MODULE_PARM_FORCE(chip1); \
  129. SENSORS_MODULE_PARM_FORCE(chip2); \
  130. SENSORS_MODULE_PARM_FORCE(chip3); \
  131. SENSORS_MODULE_PARM_FORCE(chip4); \
  132. static struct i2c_force_data forces[] = {{force,any_chip}, \
  133. {force_ ## chip1,chip1}, \
  134. {force_ ## chip2,chip2}, \
  135. {force_ ## chip3,chip3}, \
  136. {force_ ## chip4,chip4}, \
  137. {NULL}}; \
  138. SENSORS_INSMOD
  139. #define SENSORS_INSMOD_5(chip1,chip2,chip3,chip4,chip5) \
  140. enum chips { any_chip, chip1, chip2, chip3, chip4, chip5 }; \
  141. I2C_CLIENT_MODULE_PARM(force, \
  142. "List of adapter,address pairs to boldly assume " \
  143. "to be present"); \
  144. SENSORS_MODULE_PARM_FORCE(chip1); \
  145. SENSORS_MODULE_PARM_FORCE(chip2); \
  146. SENSORS_MODULE_PARM_FORCE(chip3); \
  147. SENSORS_MODULE_PARM_FORCE(chip4); \
  148. SENSORS_MODULE_PARM_FORCE(chip5); \
  149. static struct i2c_force_data forces[] = {{force,any_chip}, \
  150. {force_ ## chip1,chip1}, \
  151. {force_ ## chip2,chip2}, \
  152. {force_ ## chip3,chip3}, \
  153. {force_ ## chip4,chip4}, \
  154. {force_ ## chip5,chip5}, \
  155. {NULL}}; \
  156. SENSORS_INSMOD
  157. #define SENSORS_INSMOD_6(chip1,chip2,chip3,chip4,chip5,chip6) \
  158. enum chips { any_chip, chip1, chip2, chip3, chip4, chip5, chip6 }; \
  159. I2C_CLIENT_MODULE_PARM(force, \
  160. "List of adapter,address pairs to boldly assume " \
  161. "to be present"); \
  162. SENSORS_MODULE_PARM_FORCE(chip1); \
  163. SENSORS_MODULE_PARM_FORCE(chip2); \
  164. SENSORS_MODULE_PARM_FORCE(chip3); \
  165. SENSORS_MODULE_PARM_FORCE(chip4); \
  166. SENSORS_MODULE_PARM_FORCE(chip5); \
  167. SENSORS_MODULE_PARM_FORCE(chip6); \
  168. static struct i2c_force_data forces[] = {{force,any_chip}, \
  169. {force_ ## chip1,chip1}, \
  170. {force_ ## chip2,chip2}, \
  171. {force_ ## chip3,chip3}, \
  172. {force_ ## chip4,chip4}, \
  173. {force_ ## chip5,chip5}, \
  174. {force_ ## chip6,chip6}, \
  175. {NULL}}; \
  176. SENSORS_INSMOD
  177. #define SENSORS_INSMOD_7(chip1,chip2,chip3,chip4,chip5,chip6,chip7) \
  178. enum chips { any_chip, chip1, chip2, chip3, chip4, chip5, chip6, chip7 }; \
  179. I2C_CLIENT_MODULE_PARM(force, \
  180. "List of adapter,address pairs to boldly assume " \
  181. "to be present"); \
  182. SENSORS_MODULE_PARM_FORCE(chip1); \
  183. SENSORS_MODULE_PARM_FORCE(chip2); \
  184. SENSORS_MODULE_PARM_FORCE(chip3); \
  185. SENSORS_MODULE_PARM_FORCE(chip4); \
  186. SENSORS_MODULE_PARM_FORCE(chip5); \
  187. SENSORS_MODULE_PARM_FORCE(chip6); \
  188. SENSORS_MODULE_PARM_FORCE(chip7); \
  189. static struct i2c_force_data forces[] = {{force,any_chip}, \
  190. {force_ ## chip1,chip1}, \
  191. {force_ ## chip2,chip2}, \
  192. {force_ ## chip3,chip3}, \
  193. {force_ ## chip4,chip4}, \
  194. {force_ ## chip5,chip5}, \
  195. {force_ ## chip6,chip6}, \
  196. {force_ ## chip7,chip7}, \
  197. {NULL}}; \
  198. SENSORS_INSMOD
  199. #define SENSORS_INSMOD_8(chip1,chip2,chip3,chip4,chip5,chip6,chip7,chip8) \
  200. enum chips { any_chip, chip1, chip2, chip3, chip4, chip5, chip6, chip7, chip8 }; \
  201. I2C_CLIENT_MODULE_PARM(force, \
  202. "List of adapter,address pairs to boldly assume " \
  203. "to be present"); \
  204. SENSORS_MODULE_PARM_FORCE(chip1); \
  205. SENSORS_MODULE_PARM_FORCE(chip2); \
  206. SENSORS_MODULE_PARM_FORCE(chip3); \
  207. SENSORS_MODULE_PARM_FORCE(chip4); \
  208. SENSORS_MODULE_PARM_FORCE(chip5); \
  209. SENSORS_MODULE_PARM_FORCE(chip6); \
  210. SENSORS_MODULE_PARM_FORCE(chip7); \
  211. SENSORS_MODULE_PARM_FORCE(chip8); \
  212. static struct i2c_force_data forces[] = {{force,any_chip}, \
  213. {force_ ## chip1,chip1}, \
  214. {force_ ## chip2,chip2}, \
  215. {force_ ## chip3,chip3}, \
  216. {force_ ## chip4,chip4}, \
  217. {force_ ## chip5,chip5}, \
  218. {force_ ## chip6,chip6}, \
  219. {force_ ## chip7,chip7}, \
  220. {force_ ## chip8,chip8}, \
  221. {NULL}}; \
  222. SENSORS_INSMOD
  223. /* Detect function. It iterates over all possible addresses itself. For
  224. SMBus addresses, it will only call found_proc if some client is connected
  225. to the SMBus (unless a 'force' matched); for ISA detections, this is not
  226. done. */
  227. extern int i2c_detect(struct i2c_adapter *adapter,
  228. struct i2c_address_data *address_data,
  229. int (*found_proc) (struct i2c_adapter *, int, int));
  230. /* This macro is used to scale user-input to sensible values in almost all
  231. chip drivers. */
  232. static inline int SENSORS_LIMIT(long value, long low, long high)
  233. {
  234. if (value < low)
  235. return low;
  236. else if (value > high)
  237. return high;
  238. else
  239. return value;
  240. }
  241. #endif /* def _LINUX_I2C_SENSOR_H */