i2c-sensor.h 12 KB

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