]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/staging/comedi/drivers/comedi_fc.h
fed0a54e5af67ae66162d07d50a1236df06b512b
[karo-tx-linux.git] / drivers / staging / comedi / drivers / comedi_fc.h
1 /*
2  * comedi_fc.h
3  * This is a place for code driver writers wish to share between
4  * two or more drivers. These functions are meant to be used only
5  * by drivers, they are NOT part of the kcomedilib API!
6  *
7  * Author: Frank Mori Hess <fmhess@users.sourceforge.net>
8  * Copyright (C) 2002 Frank Mori Hess
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  */
20
21 #ifndef _COMEDI_FC_H
22 #define _COMEDI_FC_H
23
24 #include "../comedidev.h"
25
26 static inline unsigned int cfc_write_array_to_buffer(struct comedi_subdevice *s,
27                                                      const void *data,
28                                                      unsigned int num_bytes)
29 {
30         return comedi_write_array_to_buffer(s, data, num_bytes);
31 }
32
33 static inline unsigned int cfc_write_to_buffer(struct comedi_subdevice *s,
34                                                unsigned short data)
35 {
36         return comedi_write_array_to_buffer(s, &data, sizeof(data));
37 };
38
39 static inline unsigned int cfc_write_long_to_buffer(struct comedi_subdevice *s,
40                                                     unsigned int data)
41 {
42         return comedi_write_array_to_buffer(s, &data, sizeof(data));
43 };
44
45 /**
46  * cfc_check_trigger_src() - trivially validate a comedi_cmd trigger source
47  * @src: pointer to the trigger source to validate
48  * @flags: bitmask of valid TRIG_* for the trigger
49  *
50  * This is used in "step 1" of the do_cmdtest functions of comedi drivers
51  * to vaildate the comedi_cmd triggers. The mask of the @src against the
52  * @flags allows the userspace comedilib to pass all the comedi_cmd
53  * triggers as TRIG_ANY and get back a bitmask of the valid trigger sources.
54  */
55 static inline int cfc_check_trigger_src(unsigned int *src, unsigned int flags)
56 {
57         unsigned int orig_src = *src;
58
59         *src = orig_src & flags;
60         if (*src == TRIG_INVALID || *src != orig_src)
61                 return -EINVAL;
62         return 0;
63 }
64
65 /**
66  * cfc_check_trigger_is_unique() - make sure a trigger source is unique
67  * @src: the trigger source to check
68  */
69 static inline int cfc_check_trigger_is_unique(unsigned int src)
70 {
71         /* this test is true if more than one _src bit is set */
72         if ((src & (src - 1)) != 0)
73                 return -EINVAL;
74         return 0;
75 }
76
77 /**
78  * cfc_check_trigger_arg_is() - trivially validate a trigger argument
79  * @arg: pointer to the trigger arg to validate
80  * @val: the value the argument should be
81  */
82 static inline int cfc_check_trigger_arg_is(unsigned int *arg, unsigned int val)
83 {
84         if (*arg != val) {
85                 *arg = val;
86                 return -EINVAL;
87         }
88         return 0;
89 }
90
91 /**
92  * cfc_check_trigger_arg_min() - trivially validate a trigger argument
93  * @arg: pointer to the trigger arg to validate
94  * @val: the minimum value the argument should be
95  */
96 static inline int cfc_check_trigger_arg_min(unsigned int *arg,
97                                             unsigned int val)
98 {
99         if (*arg < val) {
100                 *arg = val;
101                 return -EINVAL;
102         }
103         return 0;
104 }
105
106 /**
107  * cfc_check_trigger_arg_max() - trivially validate a trigger argument
108  * @arg: pointer to the trigger arg to validate
109  * @val: the maximum value the argument should be
110  */
111 static inline int cfc_check_trigger_arg_max(unsigned int *arg,
112                                             unsigned int val)
113 {
114         if (*arg > val) {
115                 *arg = val;
116                 return -EINVAL;
117         }
118         return 0;
119 }
120
121 #endif /* _COMEDI_FC_H */