This source file includes following definitions.
- fake_sawtooth
- fake_squarewave
- fake_flatline
- fake_waveform
- waveform_ai_timer
- waveform_ai_cmdtest
- waveform_ai_cmd
- waveform_ai_cancel
- waveform_ai_insn_read
- waveform_ao_timer
- waveform_ao_inttrig_start
- waveform_ao_cmdtest
- waveform_ao_cmd
- waveform_ao_cancel
- waveform_ao_insn_write
- waveform_ai_insn_config
- waveform_ao_insn_config
- waveform_common_attach
- waveform_attach
- waveform_auto_attach
- waveform_detach
- comedi_test_init
- comedi_test_exit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47 #include <linux/module.h>
48 #include "../comedidev.h"
49
50 #include <asm/div64.h>
51
52 #include <linux/timer.h>
53 #include <linux/ktime.h>
54 #include <linux/jiffies.h>
55 #include <linux/device.h>
56 #include <linux/kdev_t.h>
57
58 #define N_CHANS 8
59 #define DEV_NAME "comedi_testd"
60 #define CLASS_NAME "comedi_test"
61
62 static bool config_mode;
63 static unsigned int set_amplitude;
64 static unsigned int set_period;
65 static struct class *ctcls;
66 static struct device *ctdev;
67
68 module_param_named(noauto, config_mode, bool, 0444);
69 MODULE_PARM_DESC(noauto, "Disable auto-configuration: (1=disable [defaults to enable])");
70
71 module_param_named(amplitude, set_amplitude, uint, 0444);
72 MODULE_PARM_DESC(amplitude, "Set auto mode wave amplitude in microvolts: (defaults to 1 volt)");
73
74 module_param_named(period, set_period, uint, 0444);
75 MODULE_PARM_DESC(period, "Set auto mode wave period in microseconds: (defaults to 0.1 sec)");
76
77
78 struct waveform_private {
79 struct timer_list ai_timer;
80 u64 ai_convert_time;
81 unsigned int wf_amplitude;
82 unsigned int wf_period;
83 unsigned int wf_current;
84 unsigned int ai_scan_period;
85 unsigned int ai_convert_period;
86 struct timer_list ao_timer;
87 struct comedi_device *dev;
88 u64 ao_last_scan_time;
89 unsigned int ao_scan_period;
90 unsigned short ao_loopbacks[N_CHANS];
91 };
92
93
94 static const struct comedi_lrange waveform_ai_ranges = {
95 2, {
96 BIP_RANGE(10),
97 BIP_RANGE(5)
98 }
99 };
100
101 static unsigned short fake_sawtooth(struct comedi_device *dev,
102 unsigned int range_index,
103 unsigned int current_time)
104 {
105 struct waveform_private *devpriv = dev->private;
106 struct comedi_subdevice *s = dev->read_subdev;
107 unsigned int offset = s->maxdata / 2;
108 u64 value;
109 const struct comedi_krange *krange =
110 &s->range_table->range[range_index];
111 u64 binary_amplitude;
112
113 binary_amplitude = s->maxdata;
114 binary_amplitude *= devpriv->wf_amplitude;
115 do_div(binary_amplitude, krange->max - krange->min);
116
117 value = current_time;
118 value *= binary_amplitude * 2;
119 do_div(value, devpriv->wf_period);
120 value += offset;
121
122 if (value < binary_amplitude) {
123 value = 0;
124 } else {
125 value -= binary_amplitude;
126 if (value > s->maxdata)
127 value = s->maxdata;
128 }
129
130 return value;
131 }
132
133 static unsigned short fake_squarewave(struct comedi_device *dev,
134 unsigned int range_index,
135 unsigned int current_time)
136 {
137 struct waveform_private *devpriv = dev->private;
138 struct comedi_subdevice *s = dev->read_subdev;
139 unsigned int offset = s->maxdata / 2;
140 u64 value;
141 const struct comedi_krange *krange =
142 &s->range_table->range[range_index];
143
144 value = s->maxdata;
145 value *= devpriv->wf_amplitude;
146 do_div(value, krange->max - krange->min);
147
148
149 if (current_time < devpriv->wf_period / 2) {
150 if (offset < value)
151 value = 0;
152 else
153 value = offset - value;
154 } else {
155 value += offset;
156 if (value > s->maxdata)
157 value = s->maxdata;
158 }
159
160 return value;
161 }
162
163 static unsigned short fake_flatline(struct comedi_device *dev,
164 unsigned int range_index,
165 unsigned int current_time)
166 {
167 return dev->read_subdev->maxdata / 2;
168 }
169
170
171 static unsigned short fake_waveform(struct comedi_device *dev,
172 unsigned int channel, unsigned int range,
173 unsigned int current_time)
174 {
175 enum {
176 SAWTOOTH_CHAN,
177 SQUARE_CHAN,
178 };
179 switch (channel) {
180 case SAWTOOTH_CHAN:
181 return fake_sawtooth(dev, range, current_time);
182 case SQUARE_CHAN:
183 return fake_squarewave(dev, range, current_time);
184 default:
185 break;
186 }
187
188 return fake_flatline(dev, range, current_time);
189 }
190
191
192
193
194
195
196 static void waveform_ai_timer(struct timer_list *t)
197 {
198 struct waveform_private *devpriv = from_timer(devpriv, t, ai_timer);
199 struct comedi_device *dev = devpriv->dev;
200 struct comedi_subdevice *s = dev->read_subdev;
201 struct comedi_async *async = s->async;
202 struct comedi_cmd *cmd = &async->cmd;
203 u64 now;
204 unsigned int nsamples;
205 unsigned int time_increment;
206
207 now = ktime_to_us(ktime_get());
208 nsamples = comedi_nsamples_left(s, UINT_MAX);
209
210 while (nsamples && devpriv->ai_convert_time < now) {
211 unsigned int chanspec = cmd->chanlist[async->cur_chan];
212 unsigned short sample;
213
214 sample = fake_waveform(dev, CR_CHAN(chanspec),
215 CR_RANGE(chanspec), devpriv->wf_current);
216 if (comedi_buf_write_samples(s, &sample, 1) == 0)
217 goto overrun;
218 time_increment = devpriv->ai_convert_period;
219 if (async->scan_progress == 0) {
220
221 time_increment += devpriv->ai_scan_period -
222 devpriv->ai_convert_period *
223 cmd->scan_end_arg;
224 }
225 devpriv->wf_current += time_increment;
226 if (devpriv->wf_current >= devpriv->wf_period)
227 devpriv->wf_current %= devpriv->wf_period;
228 devpriv->ai_convert_time += time_increment;
229 nsamples--;
230 }
231
232 if (cmd->stop_src == TRIG_COUNT && async->scans_done >= cmd->stop_arg) {
233 async->events |= COMEDI_CB_EOA;
234 } else {
235 if (devpriv->ai_convert_time > now)
236 time_increment = devpriv->ai_convert_time - now;
237 else
238 time_increment = 1;
239 mod_timer(&devpriv->ai_timer,
240 jiffies + usecs_to_jiffies(time_increment));
241 }
242
243 overrun:
244 comedi_handle_events(dev, s);
245 }
246
247 static int waveform_ai_cmdtest(struct comedi_device *dev,
248 struct comedi_subdevice *s,
249 struct comedi_cmd *cmd)
250 {
251 int err = 0;
252 unsigned int arg, limit;
253
254
255
256 err |= comedi_check_trigger_src(&cmd->start_src, TRIG_NOW);
257 err |= comedi_check_trigger_src(&cmd->scan_begin_src,
258 TRIG_FOLLOW | TRIG_TIMER);
259 err |= comedi_check_trigger_src(&cmd->convert_src,
260 TRIG_NOW | TRIG_TIMER);
261 err |= comedi_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
262 err |= comedi_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE);
263
264 if (err)
265 return 1;
266
267
268
269 err |= comedi_check_trigger_is_unique(cmd->convert_src);
270 err |= comedi_check_trigger_is_unique(cmd->stop_src);
271
272
273
274 if (cmd->scan_begin_src == TRIG_FOLLOW && cmd->convert_src == TRIG_NOW)
275 err |= -EINVAL;
276
277 if (err)
278 return 2;
279
280
281
282 err |= comedi_check_trigger_arg_is(&cmd->start_arg, 0);
283
284 if (cmd->convert_src == TRIG_NOW) {
285 err |= comedi_check_trigger_arg_is(&cmd->convert_arg, 0);
286 } else {
287 if (cmd->scan_begin_src == TRIG_FOLLOW) {
288 err |= comedi_check_trigger_arg_min(&cmd->convert_arg,
289 NSEC_PER_USEC);
290 }
291 }
292
293 if (cmd->scan_begin_src == TRIG_FOLLOW) {
294 err |= comedi_check_trigger_arg_is(&cmd->scan_begin_arg, 0);
295 } else {
296 err |= comedi_check_trigger_arg_min(&cmd->scan_begin_arg,
297 NSEC_PER_USEC);
298 }
299
300 err |= comedi_check_trigger_arg_min(&cmd->chanlist_len, 1);
301 err |= comedi_check_trigger_arg_is(&cmd->scan_end_arg,
302 cmd->chanlist_len);
303
304 if (cmd->stop_src == TRIG_COUNT)
305 err |= comedi_check_trigger_arg_min(&cmd->stop_arg, 1);
306 else
307 err |= comedi_check_trigger_arg_is(&cmd->stop_arg, 0);
308
309 if (err)
310 return 3;
311
312
313
314 if (cmd->convert_src == TRIG_TIMER) {
315
316 arg = cmd->convert_arg;
317 arg = min(arg,
318 rounddown(UINT_MAX, (unsigned int)NSEC_PER_USEC));
319 arg = NSEC_PER_USEC * DIV_ROUND_CLOSEST(arg, NSEC_PER_USEC);
320 if (cmd->scan_begin_arg == TRIG_TIMER) {
321
322 limit = UINT_MAX / cmd->scan_end_arg;
323 limit = rounddown(limit, (unsigned int)NSEC_PER_SEC);
324 arg = min(arg, limit);
325 }
326 err |= comedi_check_trigger_arg_is(&cmd->convert_arg, arg);
327 }
328
329 if (cmd->scan_begin_src == TRIG_TIMER) {
330
331 arg = cmd->scan_begin_arg;
332 arg = min(arg,
333 rounddown(UINT_MAX, (unsigned int)NSEC_PER_USEC));
334 arg = NSEC_PER_USEC * DIV_ROUND_CLOSEST(arg, NSEC_PER_USEC);
335 if (cmd->convert_src == TRIG_TIMER) {
336
337 arg = max(arg, cmd->convert_arg * cmd->scan_end_arg);
338 }
339 err |= comedi_check_trigger_arg_is(&cmd->scan_begin_arg, arg);
340 }
341
342 if (err)
343 return 4;
344
345 return 0;
346 }
347
348 static int waveform_ai_cmd(struct comedi_device *dev,
349 struct comedi_subdevice *s)
350 {
351 struct waveform_private *devpriv = dev->private;
352 struct comedi_cmd *cmd = &s->async->cmd;
353 unsigned int first_convert_time;
354 u64 wf_current;
355
356 if (cmd->flags & CMDF_PRIORITY) {
357 dev_err(dev->class_dev,
358 "commands at RT priority not supported in this driver\n");
359 return -1;
360 }
361
362 if (cmd->convert_src == TRIG_NOW)
363 devpriv->ai_convert_period = 0;
364 else
365 devpriv->ai_convert_period = cmd->convert_arg / NSEC_PER_USEC;
366
367 if (cmd->scan_begin_src == TRIG_FOLLOW) {
368 devpriv->ai_scan_period = devpriv->ai_convert_period *
369 cmd->scan_end_arg;
370 } else {
371 devpriv->ai_scan_period = cmd->scan_begin_arg / NSEC_PER_USEC;
372 }
373
374
375
376
377
378
379
380
381 first_convert_time = devpriv->ai_convert_period;
382 if (cmd->scan_begin_src == TRIG_TIMER)
383 first_convert_time += devpriv->ai_scan_period;
384 devpriv->ai_convert_time = ktime_to_us(ktime_get()) +
385 first_convert_time;
386
387
388 wf_current = devpriv->ai_convert_time;
389 devpriv->wf_current = do_div(wf_current, devpriv->wf_period);
390
391
392
393
394
395
396 devpriv->ai_timer.expires =
397 jiffies + usecs_to_jiffies(devpriv->ai_convert_period) + 1;
398 add_timer(&devpriv->ai_timer);
399 return 0;
400 }
401
402 static int waveform_ai_cancel(struct comedi_device *dev,
403 struct comedi_subdevice *s)
404 {
405 struct waveform_private *devpriv = dev->private;
406
407 if (in_softirq()) {
408
409 del_timer(&devpriv->ai_timer);
410 } else {
411 del_timer_sync(&devpriv->ai_timer);
412 }
413 return 0;
414 }
415
416 static int waveform_ai_insn_read(struct comedi_device *dev,
417 struct comedi_subdevice *s,
418 struct comedi_insn *insn, unsigned int *data)
419 {
420 struct waveform_private *devpriv = dev->private;
421 int i, chan = CR_CHAN(insn->chanspec);
422
423 for (i = 0; i < insn->n; i++)
424 data[i] = devpriv->ao_loopbacks[chan];
425
426 return insn->n;
427 }
428
429
430
431
432
433 static void waveform_ao_timer(struct timer_list *t)
434 {
435 struct waveform_private *devpriv = from_timer(devpriv, t, ao_timer);
436 struct comedi_device *dev = devpriv->dev;
437 struct comedi_subdevice *s = dev->write_subdev;
438 struct comedi_async *async = s->async;
439 struct comedi_cmd *cmd = &async->cmd;
440 u64 now;
441 u64 scans_since;
442 unsigned int scans_avail = 0;
443
444
445 now = ktime_to_us(ktime_get());
446 scans_since = now - devpriv->ao_last_scan_time;
447 do_div(scans_since, devpriv->ao_scan_period);
448 if (scans_since) {
449 unsigned int i;
450
451
452 scans_avail = comedi_nscans_left(s, 0);
453 if (scans_avail > scans_since)
454 scans_avail = scans_since;
455 if (scans_avail) {
456
457 if (scans_avail > 1) {
458 unsigned int skip_bytes, nbytes;
459
460 skip_bytes =
461 comedi_samples_to_bytes(s, cmd->scan_end_arg *
462 (scans_avail - 1));
463 nbytes = comedi_buf_read_alloc(s, skip_bytes);
464 comedi_buf_read_free(s, nbytes);
465 comedi_inc_scan_progress(s, nbytes);
466 if (nbytes < skip_bytes) {
467
468 async->events |= COMEDI_CB_OVERFLOW;
469 goto underrun;
470 }
471 }
472
473 for (i = 0; i < cmd->scan_end_arg; i++) {
474 unsigned int chan = CR_CHAN(cmd->chanlist[i]);
475 unsigned short *pd;
476
477 pd = &devpriv->ao_loopbacks[chan];
478
479 if (!comedi_buf_read_samples(s, pd, 1)) {
480
481 async->events |= COMEDI_CB_OVERFLOW;
482 goto underrun;
483 }
484 }
485
486 devpriv->ao_last_scan_time +=
487 (u64)scans_avail * devpriv->ao_scan_period;
488 }
489 }
490 if (cmd->stop_src == TRIG_COUNT && async->scans_done >= cmd->stop_arg) {
491 async->events |= COMEDI_CB_EOA;
492 } else if (scans_avail < scans_since) {
493 async->events |= COMEDI_CB_OVERFLOW;
494 } else {
495 unsigned int time_inc = devpriv->ao_last_scan_time +
496 devpriv->ao_scan_period - now;
497
498 mod_timer(&devpriv->ao_timer,
499 jiffies + usecs_to_jiffies(time_inc));
500 }
501
502 underrun:
503 comedi_handle_events(dev, s);
504 }
505
506 static int waveform_ao_inttrig_start(struct comedi_device *dev,
507 struct comedi_subdevice *s,
508 unsigned int trig_num)
509 {
510 struct waveform_private *devpriv = dev->private;
511 struct comedi_async *async = s->async;
512 struct comedi_cmd *cmd = &async->cmd;
513
514 if (trig_num != cmd->start_arg)
515 return -EINVAL;
516
517 async->inttrig = NULL;
518
519 devpriv->ao_last_scan_time = ktime_to_us(ktime_get());
520 devpriv->ao_timer.expires =
521 jiffies + usecs_to_jiffies(devpriv->ao_scan_period);
522 add_timer(&devpriv->ao_timer);
523
524 return 1;
525 }
526
527 static int waveform_ao_cmdtest(struct comedi_device *dev,
528 struct comedi_subdevice *s,
529 struct comedi_cmd *cmd)
530 {
531 int err = 0;
532 unsigned int arg;
533
534
535
536 err |= comedi_check_trigger_src(&cmd->start_src, TRIG_INT);
537 err |= comedi_check_trigger_src(&cmd->scan_begin_src, TRIG_TIMER);
538 err |= comedi_check_trigger_src(&cmd->convert_src, TRIG_NOW);
539 err |= comedi_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
540 err |= comedi_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE);
541
542 if (err)
543 return 1;
544
545
546
547 err |= comedi_check_trigger_is_unique(cmd->stop_src);
548
549
550
551 if (err)
552 return 2;
553
554
555
556 err |= comedi_check_trigger_arg_min(&cmd->scan_begin_arg,
557 NSEC_PER_USEC);
558 err |= comedi_check_trigger_arg_is(&cmd->convert_arg, 0);
559 err |= comedi_check_trigger_arg_min(&cmd->chanlist_len, 1);
560 err |= comedi_check_trigger_arg_is(&cmd->scan_end_arg,
561 cmd->chanlist_len);
562 if (cmd->stop_src == TRIG_COUNT)
563 err |= comedi_check_trigger_arg_min(&cmd->stop_arg, 1);
564 else
565 err |= comedi_check_trigger_arg_is(&cmd->stop_arg, 0);
566
567 if (err)
568 return 3;
569
570
571
572
573 arg = cmd->scan_begin_arg;
574 arg = min(arg, rounddown(UINT_MAX, (unsigned int)NSEC_PER_USEC));
575 arg = NSEC_PER_USEC * DIV_ROUND_CLOSEST(arg, NSEC_PER_USEC);
576 err |= comedi_check_trigger_arg_is(&cmd->scan_begin_arg, arg);
577
578 if (err)
579 return 4;
580
581 return 0;
582 }
583
584 static int waveform_ao_cmd(struct comedi_device *dev,
585 struct comedi_subdevice *s)
586 {
587 struct waveform_private *devpriv = dev->private;
588 struct comedi_cmd *cmd = &s->async->cmd;
589
590 if (cmd->flags & CMDF_PRIORITY) {
591 dev_err(dev->class_dev,
592 "commands at RT priority not supported in this driver\n");
593 return -1;
594 }
595
596 devpriv->ao_scan_period = cmd->scan_begin_arg / NSEC_PER_USEC;
597 s->async->inttrig = waveform_ao_inttrig_start;
598 return 0;
599 }
600
601 static int waveform_ao_cancel(struct comedi_device *dev,
602 struct comedi_subdevice *s)
603 {
604 struct waveform_private *devpriv = dev->private;
605
606 s->async->inttrig = NULL;
607 if (in_softirq()) {
608
609 del_timer(&devpriv->ao_timer);
610 } else {
611 del_timer_sync(&devpriv->ao_timer);
612 }
613 return 0;
614 }
615
616 static int waveform_ao_insn_write(struct comedi_device *dev,
617 struct comedi_subdevice *s,
618 struct comedi_insn *insn, unsigned int *data)
619 {
620 struct waveform_private *devpriv = dev->private;
621 int i, chan = CR_CHAN(insn->chanspec);
622
623 for (i = 0; i < insn->n; i++)
624 devpriv->ao_loopbacks[chan] = data[i];
625
626 return insn->n;
627 }
628
629 static int waveform_ai_insn_config(struct comedi_device *dev,
630 struct comedi_subdevice *s,
631 struct comedi_insn *insn,
632 unsigned int *data)
633 {
634 if (data[0] == INSN_CONFIG_GET_CMD_TIMING_CONSTRAINTS) {
635
636
637
638
639 if (data[1] == TRIG_FOLLOW) {
640
641 data[1] = 0;
642 data[2] = NSEC_PER_USEC;
643 } else {
644 data[1] = NSEC_PER_USEC;
645 if (data[2] & TRIG_TIMER)
646 data[2] = NSEC_PER_USEC;
647 else
648 data[2] = 0;
649 }
650 return 0;
651 }
652
653 return -EINVAL;
654 }
655
656 static int waveform_ao_insn_config(struct comedi_device *dev,
657 struct comedi_subdevice *s,
658 struct comedi_insn *insn,
659 unsigned int *data)
660 {
661 if (data[0] == INSN_CONFIG_GET_CMD_TIMING_CONSTRAINTS) {
662
663 data[1] = NSEC_PER_USEC;
664 data[2] = 0;
665 return 0;
666 }
667
668 return -EINVAL;
669 }
670
671 static int waveform_common_attach(struct comedi_device *dev,
672 int amplitude, int period)
673 {
674 struct waveform_private *devpriv;
675 struct comedi_subdevice *s;
676 int i;
677 int ret;
678
679 devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
680 if (!devpriv)
681 return -ENOMEM;
682
683 devpriv->wf_amplitude = amplitude;
684 devpriv->wf_period = period;
685
686 ret = comedi_alloc_subdevices(dev, 2);
687 if (ret)
688 return ret;
689
690 s = &dev->subdevices[0];
691 dev->read_subdev = s;
692
693 s->type = COMEDI_SUBD_AI;
694 s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_CMD_READ;
695 s->n_chan = N_CHANS;
696 s->maxdata = 0xffff;
697 s->range_table = &waveform_ai_ranges;
698 s->len_chanlist = s->n_chan * 2;
699 s->insn_read = waveform_ai_insn_read;
700 s->do_cmd = waveform_ai_cmd;
701 s->do_cmdtest = waveform_ai_cmdtest;
702 s->cancel = waveform_ai_cancel;
703 s->insn_config = waveform_ai_insn_config;
704
705 s = &dev->subdevices[1];
706 dev->write_subdev = s;
707
708 s->type = COMEDI_SUBD_AO;
709 s->subdev_flags = SDF_WRITABLE | SDF_GROUND | SDF_CMD_WRITE;
710 s->n_chan = N_CHANS;
711 s->maxdata = 0xffff;
712 s->range_table = &waveform_ai_ranges;
713 s->len_chanlist = s->n_chan;
714 s->insn_write = waveform_ao_insn_write;
715 s->insn_read = waveform_ai_insn_read;
716 s->do_cmd = waveform_ao_cmd;
717 s->do_cmdtest = waveform_ao_cmdtest;
718 s->cancel = waveform_ao_cancel;
719 s->insn_config = waveform_ao_insn_config;
720
721
722 for (i = 0; i < s->n_chan; i++)
723 devpriv->ao_loopbacks[i] = s->maxdata / 2;
724
725 devpriv->dev = dev;
726 timer_setup(&devpriv->ai_timer, waveform_ai_timer, 0);
727 timer_setup(&devpriv->ao_timer, waveform_ao_timer, 0);
728
729 dev_info(dev->class_dev,
730 "%s: %u microvolt, %u microsecond waveform attached\n",
731 dev->board_name,
732 devpriv->wf_amplitude, devpriv->wf_period);
733
734 return 0;
735 }
736
737 static int waveform_attach(struct comedi_device *dev,
738 struct comedi_devconfig *it)
739 {
740 int amplitude = it->options[0];
741 int period = it->options[1];
742
743
744 if (amplitude <= 0)
745 amplitude = 1000000;
746 if (period <= 0)
747 period = 100000;
748
749 return waveform_common_attach(dev, amplitude, period);
750 }
751
752 static int waveform_auto_attach(struct comedi_device *dev,
753 unsigned long context_unused)
754 {
755 int amplitude = set_amplitude;
756 int period = set_period;
757
758
759 if (!amplitude)
760 amplitude = 1000000;
761 if (!period)
762 period = 100000;
763
764 return waveform_common_attach(dev, amplitude, period);
765 }
766
767 static void waveform_detach(struct comedi_device *dev)
768 {
769 struct waveform_private *devpriv = dev->private;
770
771 if (devpriv) {
772 del_timer_sync(&devpriv->ai_timer);
773 del_timer_sync(&devpriv->ao_timer);
774 }
775 }
776
777 static struct comedi_driver waveform_driver = {
778 .driver_name = "comedi_test",
779 .module = THIS_MODULE,
780 .attach = waveform_attach,
781 .auto_attach = waveform_auto_attach,
782 .detach = waveform_detach,
783 };
784
785
786
787
788
789 static int __init comedi_test_init(void)
790 {
791 int ret;
792
793 ret = comedi_driver_register(&waveform_driver);
794 if (ret) {
795 pr_err("comedi_test: unable to register driver\n");
796 return ret;
797 }
798
799 if (!config_mode) {
800 ctcls = class_create(THIS_MODULE, CLASS_NAME);
801 if (IS_ERR(ctcls)) {
802 pr_warn("comedi_test: unable to create class\n");
803 goto clean3;
804 }
805
806 ctdev = device_create(ctcls, NULL, MKDEV(0, 0), NULL, DEV_NAME);
807 if (IS_ERR(ctdev)) {
808 pr_warn("comedi_test: unable to create device\n");
809 goto clean2;
810 }
811
812 ret = comedi_auto_config(ctdev, &waveform_driver, 0);
813 if (ret) {
814 pr_warn("comedi_test: unable to auto-configure device\n");
815 goto clean;
816 }
817 }
818
819 return 0;
820
821 clean:
822 device_destroy(ctcls, MKDEV(0, 0));
823 clean2:
824 class_destroy(ctcls);
825 ctdev = NULL;
826 clean3:
827 ctcls = NULL;
828
829 return 0;
830 }
831 module_init(comedi_test_init);
832
833 static void __exit comedi_test_exit(void)
834 {
835 if (ctdev)
836 comedi_auto_unconfig(ctdev);
837
838 if (ctcls) {
839 device_destroy(ctcls, MKDEV(0, 0));
840 class_destroy(ctcls);
841 }
842
843 comedi_driver_unregister(&waveform_driver);
844 }
845 module_exit(comedi_test_exit);
846
847 MODULE_AUTHOR("Comedi http://www.comedi.org");
848 MODULE_DESCRIPTION("Comedi low-level driver");
849 MODULE_LICENSE("GPL");