1 /**
2 * @file mesubdevice.c
3 *
4 * @brief Subdevice base class implemention.
5 * @note Copyright (C) 2007 Meilhaus Electronic GmbH (support@meilhaus.de)
6 * @author Guenter Gebhardt
7 */
8
9 /*
10 * This file 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 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 */
24
25 #ifndef __KERNEL__
26 # define __KERNEL__
27 #endif
28
29 #include <linux/slab.h>
30
31 #include "medefines.h"
32 #include "meerror.h"
33
34 #include "medebug.h"
35 #include "mesubdevice.h"
36
me_subdevice_io_irq_start(struct me_subdevice * subdevice,struct file * filep,int channel,int irq_source,int irq_edge,int irq_arg,int flags)37 static int me_subdevice_io_irq_start(struct me_subdevice *subdevice,
38 struct file *filep,
39 int channel,
40 int irq_source,
41 int irq_edge, int irq_arg, int flags)
42 {
43 PDEBUG("executed.\n");
44 return ME_ERRNO_NOT_SUPPORTED;
45 }
46
me_subdevice_io_irq_wait(struct me_subdevice * subdevice,struct file * filep,int channel,int * irq_count,int * value,int time_out,int flags)47 static int me_subdevice_io_irq_wait(struct me_subdevice *subdevice,
48 struct file *filep,
49 int channel,
50 int *irq_count,
51 int *value, int time_out, int flags)
52 {
53 PDEBUG("executed.\n");
54 return ME_ERRNO_NOT_SUPPORTED;
55 }
56
me_subdevice_io_irq_stop(struct me_subdevice * subdevice,struct file * filep,int channel,int flags)57 static int me_subdevice_io_irq_stop(struct me_subdevice *subdevice,
58 struct file *filep, int channel, int flags)
59 {
60 PDEBUG("executed.\n");
61 return ME_ERRNO_NOT_SUPPORTED;
62 }
63
me_subdevice_io_reset_subdevice(struct me_subdevice * subdevice,struct file * filep,int flags)64 static int me_subdevice_io_reset_subdevice(struct me_subdevice *subdevice,
65 struct file *filep, int flags)
66 {
67 PDEBUG("executed.\n");
68 return ME_ERRNO_NOT_SUPPORTED;
69 }
70
me_subdevice_io_single_config(struct me_subdevice * subdevice,struct file * filep,int channel,int single_config,int ref,int trig_chan,int trig_type,int trig_edge,int flags)71 static int me_subdevice_io_single_config(struct me_subdevice *subdevice,
72 struct file *filep,
73 int channel,
74 int single_config,
75 int ref,
76 int trig_chan,
77 int trig_type,
78 int trig_edge, int flags)
79 {
80 PDEBUG("executed.\n");
81 return ME_ERRNO_NOT_SUPPORTED;
82 }
83
me_subdevice_io_single_read(struct me_subdevice * subdevice,struct file * filep,int channel,int * value,int time_out,int flags)84 static int me_subdevice_io_single_read(struct me_subdevice *subdevice,
85 struct file *filep,
86 int channel,
87 int *value, int time_out, int flags)
88 {
89 PDEBUG("executed.\n");
90 return ME_ERRNO_NOT_SUPPORTED;
91 }
92
me_subdevice_io_single_write(struct me_subdevice * subdevice,struct file * filep,int channel,int value,int time_out,int flags)93 static int me_subdevice_io_single_write(struct me_subdevice *subdevice,
94 struct file *filep,
95 int channel,
96 int value, int time_out, int flags)
97 {
98 PDEBUG("executed.\n");
99 return ME_ERRNO_NOT_SUPPORTED;
100 }
101
me_subdevice_io_stream_config(struct me_subdevice * subdevice,struct file * filep,meIOStreamConfig_t * config_list,int count,meIOStreamTrigger_t * trigger,int fifo_irq_threshold,int flags)102 static int me_subdevice_io_stream_config(struct me_subdevice *subdevice,
103 struct file *filep,
104 meIOStreamConfig_t * config_list,
105 int count,
106 meIOStreamTrigger_t * trigger,
107 int fifo_irq_threshold, int flags)
108 {
109 PDEBUG("executed.\n");
110 return ME_ERRNO_NOT_SUPPORTED;
111 }
112
me_subdevice_io_stream_new_values(struct me_subdevice * subdevice,struct file * filep,int time_out,int * count,int flags)113 static int me_subdevice_io_stream_new_values(struct me_subdevice *subdevice,
114 struct file *filep,
115 int time_out,
116 int *count, int flags)
117 {
118 PDEBUG("executed.\n");
119 return ME_ERRNO_NOT_SUPPORTED;
120 }
121
me_subdevice_io_stream_read(struct me_subdevice * subdevice,struct file * filep,int read_mode,int * values,int * count,int flags)122 static int me_subdevice_io_stream_read(struct me_subdevice *subdevice,
123 struct file *filep,
124 int read_mode,
125 int *values, int *count, int flags)
126 {
127 PDEBUG("executed.\n");
128 return ME_ERRNO_NOT_SUPPORTED;
129 }
130
me_subdevice_io_stream_start(struct me_subdevice * subdevice,struct file * filep,int start_mode,int time_out,int flags)131 static int me_subdevice_io_stream_start(struct me_subdevice *subdevice,
132 struct file *filep,
133 int start_mode, int time_out, int flags)
134 {
135 PDEBUG("executed.\n");
136 return ME_ERRNO_NOT_SUPPORTED;
137 }
138
me_subdevice_io_stream_status(struct me_subdevice * subdevice,struct file * filep,int wait,int * status,int * count,int flags)139 static int me_subdevice_io_stream_status(struct me_subdevice *subdevice,
140 struct file *filep,
141 int wait,
142 int *status, int *count, int flags)
143 {
144 PDEBUG("executed.\n");
145 return ME_ERRNO_NOT_SUPPORTED;
146 }
147
me_subdevice_io_stream_stop(struct me_subdevice * subdevice,struct file * filep,int stop_mode,int flags)148 static int me_subdevice_io_stream_stop(struct me_subdevice *subdevice,
149 struct file *filep,
150 int stop_mode, int flags)
151 {
152 PDEBUG("executed.\n");
153 return ME_ERRNO_NOT_SUPPORTED;
154 }
155
me_subdevice_io_stream_write(struct me_subdevice * subdevice,struct file * filep,int write_mode,int * values,int * count,int flags)156 static int me_subdevice_io_stream_write(struct me_subdevice *subdevice,
157 struct file *filep,
158 int write_mode,
159 int *values, int *count, int flags)
160 {
161 PDEBUG("executed.\n");
162 return ME_ERRNO_NOT_SUPPORTED;
163 }
164
me_subdevice_lock_subdevice(me_subdevice_t * subdevice,struct file * filep,int lock,int flags)165 static int me_subdevice_lock_subdevice(me_subdevice_t * subdevice,
166 struct file *filep, int lock, int flags)
167 {
168 PDEBUG("executed.\n");
169 return me_slock_lock(&subdevice->lock, filep, lock);
170 }
171
me_subdevice_query_number_channels(struct me_subdevice * subdevice,int * number)172 static int me_subdevice_query_number_channels(struct me_subdevice *subdevice,
173 int *number)
174 {
175 PDEBUG("executed.\n");
176 return ME_ERRNO_NOT_SUPPORTED;
177 }
178
me_subdevice_query_number_ranges(struct me_subdevice * subdevice,int unit,int * count)179 static int me_subdevice_query_number_ranges(struct me_subdevice *subdevice,
180 int unit, int *count)
181 {
182 PDEBUG("executed.\n");
183 return ME_ERRNO_NOT_SUPPORTED;
184 }
185
me_subdevice_query_range_by_min_max(struct me_subdevice * subdevice,int unit,int * min,int * max,int * maxdata,int * range)186 static int me_subdevice_query_range_by_min_max(struct me_subdevice *subdevice,
187 int unit,
188 int *min,
189 int *max,
190 int *maxdata, int *range)
191 {
192 PDEBUG("executed.\n");
193 return ME_ERRNO_NOT_SUPPORTED;
194 }
195
me_subdevice_query_range_info(struct me_subdevice * subdevice,int range,int * unit,int * min,int * max,int * maxdata)196 static int me_subdevice_query_range_info(struct me_subdevice *subdevice,
197 int range,
198 int *unit,
199 int *min, int *max, int *maxdata)
200 {
201 PDEBUG("executed.\n");
202 return ME_ERRNO_NOT_SUPPORTED;
203 }
204
me_subdevice_query_subdevice_type(struct me_subdevice * subdevice,int * type,int * subtype)205 static int me_subdevice_query_subdevice_type(struct me_subdevice *subdevice,
206 int *type, int *subtype)
207 {
208 PDEBUG("executed.\n");
209 return ME_ERRNO_NOT_SUPPORTED;
210 }
211
me_subdevice_query_subdevice_caps(struct me_subdevice * subdevice,int * caps)212 static int me_subdevice_query_subdevice_caps(struct me_subdevice *subdevice,
213 int *caps)
214 {
215 PDEBUG("executed.\n");
216 *caps = 0;
217 return ME_ERRNO_SUCCESS;
218 }
219
me_subdevice_query_subdevice_caps_args(struct me_subdevice * subdevice,int cap,int * args,int count)220 static int me_subdevice_query_subdevice_caps_args(struct me_subdevice
221 *subdevice, int cap,
222 int *args, int count)
223 {
224 PDEBUG("executed.\n");
225 return ME_ERRNO_NOT_SUPPORTED;
226 }
227
me_subdevice_query_timer(struct me_subdevice * subdevice,int timer,int * base_frequency,long long * min_ticks,long long * max_ticks)228 static int me_subdevice_query_timer(struct me_subdevice *subdevice,
229 int timer,
230 int *base_frequency,
231 long long *min_ticks, long long *max_ticks)
232 {
233 PDEBUG("executed.\n");
234 return ME_ERRNO_NOT_SUPPORTED;
235 }
236
me_subdevice_config_load(struct me_subdevice * subdevice,me_cfg_device_entry_t * config)237 static int me_subdevice_config_load(struct me_subdevice *subdevice,
238 me_cfg_device_entry_t * config)
239 {
240 PDEBUG("executed.\n");
241 return ME_ERRNO_SUCCESS;
242 }
243
me_subdevice_destructor(struct me_subdevice * subdevice)244 static void me_subdevice_destructor(struct me_subdevice *subdevice)
245 {
246 PDEBUG("executed.\n");
247 me_subdevice_deinit(subdevice);
248 kfree(subdevice);
249 }
250
me_subdevice_init(me_subdevice_t * subdevice)251 int me_subdevice_init(me_subdevice_t * subdevice)
252 {
253 int err;
254
255 PDEBUG("executed.\n");
256
257 /* Init list head */
258 INIT_LIST_HEAD(&subdevice->list);
259
260 /* Initialize the subdevice lock instance */
261
262 err = me_slock_init(&subdevice->lock);
263
264 if (err) {
265 PERROR("Cannot initialize subdevice lock instance.\n");
266 return 1;
267 }
268
269 /* Subdevice base class methods */
270 subdevice->me_subdevice_io_irq_start = me_subdevice_io_irq_start;
271 subdevice->me_subdevice_io_irq_wait = me_subdevice_io_irq_wait;
272 subdevice->me_subdevice_io_irq_stop = me_subdevice_io_irq_stop;
273 subdevice->me_subdevice_io_reset_subdevice =
274 me_subdevice_io_reset_subdevice;
275 subdevice->me_subdevice_io_single_config =
276 me_subdevice_io_single_config;
277 subdevice->me_subdevice_io_single_read = me_subdevice_io_single_read;
278 subdevice->me_subdevice_io_single_write = me_subdevice_io_single_write;
279 subdevice->me_subdevice_io_stream_config =
280 me_subdevice_io_stream_config;
281 subdevice->me_subdevice_io_stream_new_values =
282 me_subdevice_io_stream_new_values;
283 subdevice->me_subdevice_io_stream_read = me_subdevice_io_stream_read;
284 subdevice->me_subdevice_io_stream_start = me_subdevice_io_stream_start;
285 subdevice->me_subdevice_io_stream_status =
286 me_subdevice_io_stream_status;
287 subdevice->me_subdevice_io_stream_stop = me_subdevice_io_stream_stop;
288 subdevice->me_subdevice_io_stream_write = me_subdevice_io_stream_write;
289 subdevice->me_subdevice_lock_subdevice = me_subdevice_lock_subdevice;
290 subdevice->me_subdevice_query_number_channels =
291 me_subdevice_query_number_channels;
292 subdevice->me_subdevice_query_number_ranges =
293 me_subdevice_query_number_ranges;
294 subdevice->me_subdevice_query_range_by_min_max =
295 me_subdevice_query_range_by_min_max;
296 subdevice->me_subdevice_query_range_info =
297 me_subdevice_query_range_info;
298 subdevice->me_subdevice_query_subdevice_type =
299 me_subdevice_query_subdevice_type;
300 subdevice->me_subdevice_query_subdevice_caps =
301 me_subdevice_query_subdevice_caps;
302 subdevice->me_subdevice_query_subdevice_caps_args =
303 me_subdevice_query_subdevice_caps_args;
304 subdevice->me_subdevice_query_timer = me_subdevice_query_timer;
305 subdevice->me_subdevice_config_load = me_subdevice_config_load;
306 subdevice->me_subdevice_destructor = me_subdevice_destructor;
307
308 return 0;
309 }
310
me_subdevice_deinit(me_subdevice_t * subdevice)311 void me_subdevice_deinit(me_subdevice_t * subdevice)
312 {
313 PDEBUG("executed.\n");
314 me_subdevice_io_reset_subdevice(subdevice, NULL,
315 ME_IO_RESET_SUBDEVICE_NO_FLAGS);
316 me_slock_deinit(&subdevice->lock);
317 }
318