root/i2c/trunk/kernel/i2c-proc.h @ 3527

Revision 3527, 17.8 KB (checked in by mds, 13 years ago)

Copy sensors.c and sensors.h from the lm_sensors package and

name them i2c-proc.c and i2c-proc.h.
Add DEVICEID's from sensors.h to i2c-id.h.
Add #defines from i2c-isa.h in lm_sensors to i2c.h.
Update mkpatch for i2c-proc.[ch].

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/*
2    sensors.h - Part of lm_sensors, Linux kernel modules for hardware
3                monitoring
4    Copyright (c) 1998, 1999  Frodo Looijaard <frodol@dds.nl>
5
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
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/
20
21#ifndef SENSORS_SENSORS_H
22#define SENSORS_SENSORS_H
23
24#ifdef __KERNEL__
25
26/* Next two must be included before sysctl.h can be included, in 2.0 kernels */
27#include <linux/types.h>
28#include <linux/fs.h>
29#include <linux/sysctl.h>
30
31/* The type of callback functions used in sensors_{proc,sysctl}_real */
32typedef void (*sensors_real_callback) (struct i2c_client * client,
33                                       int operation, int ctl_name,
34                                       int *nrels_mag, long *results);
35
36/* Values for the operation field in the above function type */
37#define SENSORS_PROC_REAL_INFO 1
38#define SENSORS_PROC_REAL_READ 2
39#define SENSORS_PROC_REAL_WRITE 3
40
41/* These funcion reads or writes a 'real' value (encoded by the combination
42   of an integer and a magnitude, the last is the power of ten the value
43   should be divided with) to a /proc/sys directory. To use these functions,
44   you must (before registering the ctl_table) set the extra2 field to the
45   client, and the extra1 field to a function of the form:
46      void func(struct i2c_client *client, int operation, int ctl_name,
47                int *nrels_mag, long *results)
48   This last function can be called for three values of operation. If
49   operation equals SENSORS_PROC_REAL_INFO, the magnitude should be returned
50   in nrels_mag. If operation equals SENSORS_PROC_REAL_READ, values should
51   be read into results. nrels_mag should return the number of elements
52   read; the maximum number is put in it on entry. Finally, if operation
53   equals SENSORS_PROC_REAL_WRITE, the values in results should be
54   written to the chip. nrels_mag contains on entry the number of elements
55   found.
56   In all cases, client points to the client we wish to interact with,
57   and ctl_name is the SYSCTL id of the file we are accessing. */
58extern int sensors_sysctl_real(ctl_table * table, int *name, int nlen,
59                               void *oldval, size_t * oldlenp,
60                               void *newval, size_t newlen,
61                               void **context);
62extern int sensors_proc_real(ctl_table * ctl, int write, struct file *filp,
63                             void *buffer, size_t * lenp);
64
65
66
67/* These rather complex functions must be called when you want to add or
68   delete an entry in /proc/sys/dev/sensors/chips (not yet implemented). It
69   also creates a new directory within /proc/sys/dev/sensors/.
70   ctl_template should be a template of the newly created directory. It is
71   copied in memory. The extra2 field of each file is set to point to client.
72   If any driver wants subdirectories within the newly created directory,
73   these functions must be updated! */
74extern int sensors_register_entry(struct i2c_client *client,
75                                  const char *prefix,
76                                  ctl_table * ctl_template,
77                                  struct module *controlling_mod);
78
79extern void sensors_deregister_entry(int id);
80
81
82/* A structure containing detect information.
83   Force variables overrule all other variables; they force a detection on
84   that place. If a specific chip is given, the module blindly assumes this
85   chip type is present; if a general force (kind == 0) is given, the module
86   will still try to figure out what type of chip is present. This is useful
87   if for some reasons the detect for SMBus or ISA address space filled
88   fails.
89   probe: insmod parameter. Initialize this list with SENSORS_I2C_END values.
90     A list of pairs. The first value is a bus number (SENSORS_ISA_BUS for
91     the ISA bus, -1 for any I2C bus), the second is the address.
92   kind: The kind of chip. 0 equals any chip.
93*/
94struct sensors_force_data {
95        unsigned short *force;
96        unsigned short kind;
97};
98
99/* A structure containing the detect information.
100   normal_i2c: filled in by the module writer. Terminated by SENSORS_I2C_END.
101     A list of I2C addresses which should normally be examined.
102   normal_i2c_range: filled in by the module writer. Terminated by
103     SENSORS_I2C_END
104     A list of pairs of I2C addresses, each pair being an inclusive range of
105     addresses which should normally be examined.
106   normal_isa: filled in by the module writer. Terminated by SENSORS_ISA_END.
107     A list of ISA addresses which should normally be examined.
108   normal_isa_range: filled in by the module writer. Terminated by
109     SENSORS_ISA_END
110     A list of triples. The first two elements are ISA addresses, being an
111     range of addresses which should normally be examined. The third is the
112     modulo parameter: only addresses which are 0 module this value relative
113     to the first address of the range are actually considered.
114   probe: insmod parameter. Initialize this list with SENSORS_I2C_END values.
115     A list of pairs. The first value is a bus number (SENSORS_ISA_BUS for
116     the ISA bus, -1 for any I2C bus), the second is the address. These
117     addresses are also probed, as if they were in the 'normal' list.
118   probe_range: insmod parameter. Initialize this list with SENSORS_I2C_END
119     values.
120     A list of triples. The first value is a bus number (SENSORS_ISA_BUS for
121     the ISA bus, -1 for any I2C bus), the second and third are addresses.
122     These form an inclusive range of addresses that are also probed, as
123     if they were in the 'normal' list.
124   ignore: insmod parameter. Initialize this list with SENSORS_I2C_END values.
125     A list of pairs. The first value is a bus number (SENSORS_ISA_BUS for
126     the ISA bus, -1 for any I2C bus), the second is the I2C address. These
127     addresses are never probed. This parameter overrules 'normal' and
128     'probe', but not the 'force' lists.
129   ignore_range: insmod parameter. Initialize this list with SENSORS_I2C_END
130      values.
131     A list of triples. The first value is a bus number (SENSORS_ISA_BUS for
132     the ISA bus, -1 for any I2C bus), the second and third are addresses.
133     These form an inclusive range of I2C addresses that are never probed.
134     This parameter overrules 'normal' and 'probe', but not the 'force' lists.
135   force_data: insmod parameters. A list, ending with an element of which
136     the force field is NULL.
137*/
138struct sensors_address_data {
139        unsigned short *normal_i2c;
140        unsigned short *normal_i2c_range;
141        unsigned int *normal_isa;
142        unsigned int *normal_isa_range;
143        unsigned short *probe;
144        unsigned short *probe_range;
145        unsigned short *ignore;
146        unsigned short *ignore_range;
147        struct sensors_force_data *forces;
148};
149
150/* Internal numbers to terminate lists */
151#define SENSORS_I2C_END 0xfffe
152#define SENSORS_ISA_END 0xfffefffe
153
154/* The numbers to use to set an ISA or I2C bus address */
155#define SENSORS_ISA_BUS 9191
156#define SENSORS_ANY_I2C_BUS 0xffff
157
158/* The length of the option lists */
159#define SENSORS_MAX_OPTS 48
160
161/* Default fill of many variables */
162#define SENSORS_DEFAULTS {SENSORS_I2C_END, SENSORS_I2C_END, SENSORS_I2C_END, \
163                          SENSORS_I2C_END, SENSORS_I2C_END, SENSORS_I2C_END, \
164                          SENSORS_I2C_END, SENSORS_I2C_END, SENSORS_I2C_END, \
165                          SENSORS_I2C_END, SENSORS_I2C_END, SENSORS_I2C_END, \
166                          SENSORS_I2C_END, SENSORS_I2C_END, SENSORS_I2C_END, \
167                          SENSORS_I2C_END, SENSORS_I2C_END, SENSORS_I2C_END, \
168                          SENSORS_I2C_END, SENSORS_I2C_END, SENSORS_I2C_END, \
169                          SENSORS_I2C_END, SENSORS_I2C_END, SENSORS_I2C_END, \
170                          SENSORS_I2C_END, SENSORS_I2C_END, SENSORS_I2C_END, \
171                          SENSORS_I2C_END, SENSORS_I2C_END, SENSORS_I2C_END, \
172                          SENSORS_I2C_END, SENSORS_I2C_END, SENSORS_I2C_END, \
173                          SENSORS_I2C_END, SENSORS_I2C_END, SENSORS_I2C_END, \
174                          SENSORS_I2C_END, SENSORS_I2C_END, SENSORS_I2C_END, \
175                          SENSORS_I2C_END, SENSORS_I2C_END, SENSORS_I2C_END, \
176                          SENSORS_I2C_END, SENSORS_I2C_END, SENSORS_I2C_END, \
177                          SENSORS_I2C_END, SENSORS_I2C_END, SENSORS_I2C_END}
178
179/* This is ugly. We need to evaluate SENSORS_MAX_OPTS before it is
180   stringified */
181#define SENSORS_MODPARM_AUX1(x) "1-" #x "h"
182#define SENSORS_MODPARM_AUX(x) SENSORS_MODPARM_AUX1(x)
183#define SENSORS_MODPARM SENSORS_MODPARM_AUX(SENSORS_MAX_OPTS)
184
185/* SENSORS_MODULE_PARM creates a module parameter, and puts it in the
186   module header */
187#define SENSORS_MODULE_PARM(var,desc) \
188  static unsigned short var[SENSORS_MAX_OPTS] = SENSORS_DEFAULTS; \
189  MODULE_PARM(var,SENSORS_MODPARM); \
190  MODULE_PARM_DESC(var,desc)
191
192/* SENSORS_MODULE_PARM creates a 'force_*' module parameter, and puts it in
193   the module header */
194#define SENSORS_MODULE_PARM_FORCE(name) \
195  SENSORS_MODULE_PARM(force_ ## name, \
196                      "List of adapter,address pairs which are unquestionably" \
197                      " assumed to contain a `" # name "' chip")
198
199
200/* This defines several insmod variables, and the addr_data structure */
201#define SENSORS_INSMOD \
202  SENSORS_MODULE_PARM(probe, \
203                      "List of adapter,address pairs to scan additionally"); \
204  SENSORS_MODULE_PARM(probe_range, \
205                      "List of adapter,start-addr,end-addr triples to scan " \
206                      "additionally"); \
207  SENSORS_MODULE_PARM(ignore, \
208                      "List of adapter,address pairs not to scan"); \
209  SENSORS_MODULE_PARM(ignore_range, \
210                      "List of adapter,start-addr,end-addr triples not to " \
211                      "scan"); \
212  static struct sensors_address_data addr_data = \
213                                       {normal_i2c, normal_i2c_range, \
214                                        normal_isa, normal_isa_range, \
215                                        probe, probe_range, \
216                                        ignore, ignore_range, \
217                                        forces}
218
219/* The following functions create an enum with the chip names as elements.
220   The first element of the enum is any_chip. These are the only macros
221   a module will want to use. */
222
223#define SENSORS_INSMOD_0 \
224  enum chips { any_chip }; \
225  SENSORS_MODULE_PARM(force, \
226                      "List of adapter,address pairs to boldly assume " \
227                      "to be present"); \
228  static struct sensors_force_data forces[] = {{force,any_chip},{NULL}}; \
229  SENSORS_INSMOD
230
231#define SENSORS_INSMOD_1(chip1) \
232  enum chips { any_chip, chip1 }; \
233  SENSORS_MODULE_PARM(force, \
234                      "List of adapter,address pairs to boldly assume " \
235                      "to be present"); \
236  SENSORS_MODULE_PARM_FORCE(chip1); \
237  static struct sensors_force_data forces[] = {{force,any_chip},\
238                                                 {force_ ## chip1,chip1}, \
239                                                 {NULL}}; \
240  SENSORS_INSMOD
241
242#define SENSORS_INSMOD_2(chip1,chip2) \
243  enum chips { any_chip, chip1, chip2 }; \
244  SENSORS_MODULE_PARM(force, \
245                      "List of adapter,address pairs to boldly assume " \
246                      "to be present"); \
247  SENSORS_MODULE_PARM_FORCE(chip1); \
248  SENSORS_MODULE_PARM_FORCE(chip2); \
249  static struct sensors_force_data forces[] = {{force,any_chip}, \
250                                                 {force_ ## chip1,chip1}, \
251                                                 {force_ ## chip2,chip2}, \
252                                                 {NULL}}; \
253  SENSORS_INSMOD
254
255#define SENSORS_INSMOD_3(chip1,chip2,chip3) \
256  enum chips { any_chip, chip1, chip2, chip3 }; \
257  SENSORS_MODULE_PARM(force, \
258                      "List of adapter,address pairs to boldly assume " \
259                      "to be present"); \
260  SENSORS_MODULE_PARM_FORCE(chip1); \
261  SENSORS_MODULE_PARM_FORCE(chip2); \
262  SENSORS_MODULE_PARM_FORCE(chip3); \
263  static struct sensors_force_data forces[] = {{force,any_chip}, \
264                                                 {force_ ## chip1,chip1}, \
265                                                 {force_ ## chip2,chip2}, \
266                                                 {force_ ## chip3,chip3}, \
267                                                 {NULL}}; \
268  SENSORS_INSMOD
269
270#define SENSORS_INSMOD_4(chip1,chip2,chip3,chip4) \
271  enum chips { any_chip, chip1, chip2, chip3, chip4 }; \
272  SENSORS_MODULE_PARM(force, \
273                      "List of adapter,address pairs to boldly assume " \
274                      "to be present"); \
275  SENSORS_MODULE_PARM_FORCE(chip1); \
276  SENSORS_MODULE_PARM_FORCE(chip2); \
277  SENSORS_MODULE_PARM_FORCE(chip3); \
278  SENSORS_MODULE_PARM_FORCE(chip4); \
279  static struct sensors_force_data forces[] = {{force,any_chip}, \
280                                                 {force_ ## chip1,chip1}, \
281                                                 {force_ ## chip2,chip2}, \
282                                                 {force_ ## chip3,chip3}, \
283                                                 {force_ ## chip4,chip4}, \
284                                                 {NULL}}; \
285  SENSORS_INSMOD
286
287#define SENSORS_INSMOD_5(chip1,chip2,chip3,chip4,chip5) \
288  enum chips { any_chip, chip1, chip2, chip3, chip4, chip5 }; \
289  SENSORS_MODULE_PARM(force, \
290                      "List of adapter,address pairs to boldly assume " \
291                      "to be present"); \
292  SENSORS_MODULE_PARM_FORCE(chip1); \
293  SENSORS_MODULE_PARM_FORCE(chip2); \
294  SENSORS_MODULE_PARM_FORCE(chip3); \
295  SENSORS_MODULE_PARM_FORCE(chip4); \
296  SENSORS_MODULE_PARM_FORCE(chip5); \
297  static struct sensors_force_data forces[] = {{force,any_chip}, \
298                                                 {force_ ## chip1,chip1}, \
299                                                 {force_ ## chip2,chip2}, \
300                                                 {force_ ## chip3,chip3}, \
301                                                 {force_ ## chip4,chip4}, \
302                                                 {force_ ## chip5,chip5}, \
303                                                 {NULL}}; \
304  SENSORS_INSMOD
305
306#define SENSORS_INSMOD_6(chip1,chip2,chip3,chip4,chip5,chip6) \
307  enum chips { any_chip, chip1, chip2, chip3, chip4, chip5, chip6 }; \
308  SENSORS_MODULE_PARM(force, \
309                      "List of adapter,address pairs to boldly assume " \
310                      "to be present"); \
311  SENSORS_MODULE_PARM_FORCE(chip1); \
312  SENSORS_MODULE_PARM_FORCE(chip2); \
313  SENSORS_MODULE_PARM_FORCE(chip3); \
314  SENSORS_MODULE_PARM_FORCE(chip4); \
315  SENSORS_MODULE_PARM_FORCE(chip5); \
316  SENSORS_MODULE_PARM_FORCE(chip6); \
317  static struct sensors_force_data forces[] = {{force,any_chip}, \
318                                                 {force_ ## chip1,chip1}, \
319                                                 {force_ ## chip2,chip2}, \
320                                                 {force_ ## chip3,chip3}, \
321                                                 {force_ ## chip4,chip4}, \
322                                                 {force_ ## chip5,chip5}, \
323                                                 {force_ ## chip6,chip6}, \
324                                                 {NULL}}; \
325  SENSORS_INSMOD
326
327#define SENSORS_INSMOD_7(chip1,chip2,chip3,chip4,chip5,chip6,chip7) \
328  enum chips { any_chip, chip1, chip2, chip3, chip4, chip5, chip6, chip7 }; \
329  SENSORS_MODULE_PARM(force, \
330                      "List of adapter,address pairs to boldly assume " \
331                      "to be present"); \
332  SENSORS_MODULE_PARM_FORCE(chip1); \
333  SENSORS_MODULE_PARM_FORCE(chip2); \
334  SENSORS_MODULE_PARM_FORCE(chip3); \
335  SENSORS_MODULE_PARM_FORCE(chip4); \
336  SENSORS_MODULE_PARM_FORCE(chip5); \
337  SENSORS_MODULE_PARM_FORCE(chip6); \
338  SENSORS_MODULE_PARM_FORCE(chip7); \
339  static struct sensors_force_data forces[] = {{force,any_chip}, \
340                                                 {force_ ## chip1,chip1}, \
341                                                 {force_ ## chip2,chip2}, \
342                                                 {force_ ## chip3,chip3}, \
343                                                 {force_ ## chip4,chip4}, \
344                                                 {force_ ## chip5,chip5}, \
345                                                 {force_ ## chip6,chip6}, \
346                                                 {force_ ## chip7,chip7}, \
347                                                 {NULL}}; \
348  SENSORS_INSMOD
349
350typedef int sensors_found_addr_proc(struct i2c_adapter *adapter,
351                                    int addr, unsigned short flags,
352                                    int kind);
353
354/* Detect function. It itterates over all possible addresses itself. For
355   SMBus addresses, it will only call found_proc if some client is connected
356   to the SMBus (unless a 'force' matched); for ISA detections, this is not
357   done. */
358extern int sensors_detect(struct i2c_adapter *adapter,
359                          struct sensors_address_data *address_data,
360                          sensors_found_addr_proc * found_proc);
361
362
363/* This macro is used to scale user-input to sensible values in almost all
364   chip drivers. */
365extern inline int SENSORS_LIMIT(long value, long low, long high)
366{
367        if (value < low)
368                return low;
369        else if (value > high)
370                return high;
371        else
372                return value;
373}
374
375#endif                          /* def __KERNEL__ */
376
377
378/* The maximum length of the prefix */
379#define SENSORS_PREFIX_MAX 20
380
381/* Sysctl IDs */
382#ifdef DEV_HWMON
383#define DEV_SENSORS DEV_HWMON
384#else                           /* ndef DEV_HWMOM */
385#define DEV_SENSORS 2           /* The id of the lm_sensors directory within the
386                                   dev table */
387#endif                          /* def DEV_HWMON */
388
389#define SENSORS_CHIPS 1
390struct sensors_chips_data {
391        int sysctl_id;
392        char name[SENSORS_PREFIX_MAX + 13];
393};
394
395#endif                          /* def SENSORS_SENSORS_H */
396
Note: See TracBrowser for help on using the browser.