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
48
49
50
51
52
53#include <linux/module.h>
54#include <linux/delay.h>
55#include <linux/interrupt.h>
56#include <linux/kernel.h>
57#include <linux/types.h>
58
59#include "../comedi_pci.h"
60
61#include "s626.h"
62
63struct s626_buffer_dma {
64 dma_addr_t physical_base;
65 void *logical_base;
66};
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83struct s626_private {
84 u8 ai_cmd_running;
85 unsigned int ai_sample_timer;
86 int ai_convert_count;
87 unsigned int ai_convert_timer;
88 u16 counter_int_enabs;
89 u8 adc_items;
90 struct s626_buffer_dma rps_buf;
91 struct s626_buffer_dma ana_buf;
92 u32 *dac_wbuf;
93 u16 dacpol;
94 u8 trim_setpoint[12];
95 u32 i2c_adrs;
96};
97
98
99#define S626_INDXMASK(C) (1 << (((C) > 2) ? ((C) * 2 - 1) : ((C) * 2 + 4)))
100#define S626_OVERMASK(C) (1 << (((C) > 2) ? ((C) * 2 + 5) : ((C) * 2 + 10)))
101
102
103
104
105
106static void s626_mc_enable(struct comedi_device *dev,
107 unsigned int cmd, unsigned int reg)
108{
109 unsigned int val = (cmd << 16) | cmd;
110
111 writel(val, dev->mmio + reg);
112}
113
114static void s626_mc_disable(struct comedi_device *dev,
115 unsigned int cmd, unsigned int reg)
116{
117 writel(cmd << 16, dev->mmio + reg);
118}
119
120static bool s626_mc_test(struct comedi_device *dev,
121 unsigned int cmd, unsigned int reg)
122{
123 unsigned int val;
124
125 val = readl(dev->mmio + reg);
126
127 return (val & cmd) ? true : false;
128}
129
130#define S626_BUGFIX_STREG(REGADRS) ((REGADRS) - 4)
131
132
133#define S626_VECTPORT(VECTNUM) (S626_P_TSL2 + ((VECTNUM) << 2))
134
135static const struct comedi_lrange s626_range_table = {
136 2, {
137 BIP_RANGE(5),
138 BIP_RANGE(10)
139 }
140};
141
142
143
144
145static void s626_debi_transfer(struct comedi_device *dev)
146{
147 static const int timeout = 10000;
148 int i;
149
150
151 s626_mc_enable(dev, S626_MC2_UPLD_DEBI, S626_P_MC2);
152
153
154
155
156
157 for (i = 0; i < timeout; i++) {
158 if (s626_mc_test(dev, S626_MC2_UPLD_DEBI, S626_P_MC2))
159 break;
160 udelay(1);
161 }
162 if (i == timeout)
163 dev_err(dev->class_dev,
164 "Timeout while uploading to DEBI control register\n");
165
166
167 for (i = 0; i < timeout; i++) {
168 if (!(readl(dev->mmio + S626_P_PSR) & S626_PSR_DEBI_S))
169 break;
170 udelay(1);
171 }
172 if (i == timeout)
173 dev_err(dev->class_dev, "DEBI transfer timeout\n");
174}
175
176
177
178
179static u16 s626_debi_read(struct comedi_device *dev, u16 addr)
180{
181
182 writel(S626_DEBI_CMD_RDWORD | addr, dev->mmio + S626_P_DEBICMD);
183
184
185 s626_debi_transfer(dev);
186
187 return readl(dev->mmio + S626_P_DEBIAD);
188}
189
190
191
192
193static void s626_debi_write(struct comedi_device *dev, u16 addr,
194 u16 wdata)
195{
196
197 writel(S626_DEBI_CMD_WRWORD | addr, dev->mmio + S626_P_DEBICMD);
198 writel(wdata, dev->mmio + S626_P_DEBIAD);
199
200
201 s626_debi_transfer(dev);
202}
203
204
205
206
207
208
209static void s626_debi_replace(struct comedi_device *dev, unsigned int addr,
210 unsigned int mask, unsigned int wdata)
211{
212 unsigned int val;
213
214 addr &= 0xffff;
215 writel(S626_DEBI_CMD_RDWORD | addr, dev->mmio + S626_P_DEBICMD);
216 s626_debi_transfer(dev);
217
218 writel(S626_DEBI_CMD_WRWORD | addr, dev->mmio + S626_P_DEBICMD);
219 val = readl(dev->mmio + S626_P_DEBIAD);
220 val &= mask;
221 val |= wdata;
222 writel(val & 0xffff, dev->mmio + S626_P_DEBIAD);
223 s626_debi_transfer(dev);
224}
225
226
227
228static int s626_i2c_handshake_eoc(struct comedi_device *dev,
229 struct comedi_subdevice *s,
230 struct comedi_insn *insn,
231 unsigned long context)
232{
233 bool status;
234
235 status = s626_mc_test(dev, S626_MC2_UPLD_IIC, S626_P_MC2);
236 if (status)
237 return 0;
238 return -EBUSY;
239}
240
241static int s626_i2c_handshake(struct comedi_device *dev, u32 val)
242{
243 unsigned int ctrl;
244 int ret;
245
246
247 writel(val, dev->mmio + S626_P_I2CCTRL);
248
249
250
251
252
253 s626_mc_enable(dev, S626_MC2_UPLD_IIC, S626_P_MC2);
254 ret = comedi_timeout(dev, NULL, NULL, s626_i2c_handshake_eoc, 0);
255 if (ret)
256 return ret;
257
258
259 do {
260 ctrl = readl(dev->mmio + S626_P_I2CCTRL);
261 } while ((ctrl & (S626_I2C_BUSY | S626_I2C_ERR)) == S626_I2C_BUSY);
262
263
264 return ctrl & S626_I2C_ERR;
265}
266
267
268static u8 s626_i2c_read(struct comedi_device *dev, u8 addr)
269{
270 struct s626_private *devpriv = dev->private;
271
272
273
274
275
276
277
278 if (s626_i2c_handshake(dev, S626_I2C_B2(S626_I2C_ATTRSTART,
279 devpriv->i2c_adrs) |
280 S626_I2C_B1(S626_I2C_ATTRSTOP, addr) |
281 S626_I2C_B0(S626_I2C_ATTRNOP, 0)))
282
283 return 0;
284
285
286
287
288
289
290
291 if (s626_i2c_handshake(dev, S626_I2C_B2(S626_I2C_ATTRSTART,
292 (devpriv->i2c_adrs | 1)) |
293 S626_I2C_B1(S626_I2C_ATTRSTOP, 0) |
294 S626_I2C_B0(S626_I2C_ATTRNOP, 0)))
295
296 return 0;
297
298 return (readl(dev->mmio + S626_P_I2CCTRL) >> 16) & 0xff;
299}
300
301
302
303
304static const u8 s626_trimchan[] = { 10, 9, 8, 3, 2, 7, 6, 1, 0, 5, 4 };
305
306
307static const u8 s626_trimadrs[] = {
308 0x40, 0x41, 0x42, 0x50, 0x51, 0x52, 0x53, 0x60, 0x61, 0x62, 0x63
309};
310
311enum {
312 s626_send_dac_wait_not_mc1_a2out,
313 s626_send_dac_wait_ssr_af2_out,
314 s626_send_dac_wait_fb_buffer2_msb_00,
315 s626_send_dac_wait_fb_buffer2_msb_ff
316};
317
318static int s626_send_dac_eoc(struct comedi_device *dev,
319 struct comedi_subdevice *s,
320 struct comedi_insn *insn,
321 unsigned long context)
322{
323 unsigned int status;
324
325 switch (context) {
326 case s626_send_dac_wait_not_mc1_a2out:
327 status = readl(dev->mmio + S626_P_MC1);
328 if (!(status & S626_MC1_A2OUT))
329 return 0;
330 break;
331 case s626_send_dac_wait_ssr_af2_out:
332 status = readl(dev->mmio + S626_P_SSR);
333 if (status & S626_SSR_AF2_OUT)
334 return 0;
335 break;
336 case s626_send_dac_wait_fb_buffer2_msb_00:
337 status = readl(dev->mmio + S626_P_FB_BUFFER2);
338 if (!(status & 0xff000000))
339 return 0;
340 break;
341 case s626_send_dac_wait_fb_buffer2_msb_ff:
342 status = readl(dev->mmio + S626_P_FB_BUFFER2);
343 if (status & 0xff000000)
344 return 0;
345 break;
346 default:
347 return -EINVAL;
348 }
349 return -EBUSY;
350}
351
352
353
354
355
356
357static int s626_send_dac(struct comedi_device *dev, u32 val)
358{
359 struct s626_private *devpriv = dev->private;
360 int ret;
361
362
363
364
365
366
367
368
369
370
371
372
373
374 s626_debi_write(dev, S626_LP_DACPOL, devpriv->dacpol);
375
376
377
378
379
380 *devpriv->dac_wbuf = val;
381
382
383
384
385
386
387
388 s626_mc_enable(dev, S626_MC1_A2OUT, S626_P_MC1);
389
390
391
392
393
394
395
396
397 writel(S626_ISR_AFOU, dev->mmio + S626_P_ISR);
398
399
400
401
402
403
404
405
406 ret = comedi_timeout(dev, NULL, NULL, s626_send_dac_eoc,
407 s626_send_dac_wait_not_mc1_a2out);
408 if (ret) {
409 dev_err(dev->class_dev, "DMA transfer timeout\n");
410 return ret;
411 }
412
413
414
415
416
417
418
419
420
421 writel(S626_XSD2 | S626_RSD3 | S626_SIB_A2,
422 dev->mmio + S626_VECTPORT(0));
423
424
425
426
427
428
429
430
431 ret = comedi_timeout(dev, NULL, NULL, s626_send_dac_eoc,
432 s626_send_dac_wait_ssr_af2_out);
433 if (ret) {
434 dev_err(dev->class_dev,
435 "TSL timeout waiting for slot 1 to execute\n");
436 return ret;
437 }
438
439
440
441
442
443
444
445
446 writel(S626_XSD2 | S626_XFIFO_2 | S626_RSD2 | S626_SIB_A2 | S626_EOS,
447 dev->mmio + S626_VECTPORT(0));
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469 if (readl(dev->mmio + S626_P_FB_BUFFER2) & 0xff000000) {
470
471
472
473
474
475
476
477 ret = comedi_timeout(dev, NULL, NULL, s626_send_dac_eoc,
478 s626_send_dac_wait_fb_buffer2_msb_00);
479 if (ret) {
480 dev_err(dev->class_dev,
481 "TSL timeout waiting for slot 0 to execute\n");
482 return ret;
483 }
484 }
485
486
487
488
489
490
491
492
493
494 writel(S626_RSD3 | S626_SIB_A2 | S626_EOS,
495 dev->mmio + S626_VECTPORT(0));
496
497
498
499
500
501
502 ret = comedi_timeout(dev, NULL, NULL, s626_send_dac_eoc,
503 s626_send_dac_wait_fb_buffer2_msb_ff);
504 if (ret) {
505 dev_err(dev->class_dev,
506 "TSL timeout waiting for slot 0 to execute\n");
507 return ret;
508 }
509 return 0;
510}
511
512
513
514
515static int s626_set_dac(struct comedi_device *dev,
516 u16 chan, int16_t dacdata)
517{
518 struct s626_private *devpriv = dev->private;
519 u16 signmask;
520 u32 ws_image;
521 u32 val;
522
523
524
525
526 signmask = 1 << chan;
527 if (dacdata < 0) {
528 dacdata = -dacdata;
529 devpriv->dacpol |= signmask;
530 } else {
531 devpriv->dacpol &= ~signmask;
532 }
533
534
535 if ((u16)dacdata > 0x1FFF)
536 dacdata = 0x1FFF;
537
538
539
540
541
542
543
544
545
546
547
548
549
550 ws_image = (chan & 2) ? S626_WS1 : S626_WS2;
551
552 writel(S626_XSD2 | S626_XFIFO_1 | ws_image,
553 dev->mmio + S626_VECTPORT(2));
554
555 writel(S626_XSD2 | S626_XFIFO_0 | ws_image,
556 dev->mmio + S626_VECTPORT(3));
557
558 writel(S626_XSD2 | S626_XFIFO_3 | S626_WS3,
559 dev->mmio + S626_VECTPORT(4));
560
561 writel(S626_XSD2 | S626_XFIFO_2 | S626_WS3 | S626_EOS,
562 dev->mmio + S626_VECTPORT(5));
563
564
565
566
567
568
569
570
571 val = 0x0F000000;
572
573
574 val |= 0x00004000;
575
576
577 val |= ((u32)(chan & 1) << 15);
578
579
580 val |= (u32)dacdata;
581 return s626_send_dac(dev, val);
582}
583
584static int s626_write_trim_dac(struct comedi_device *dev,
585 u8 logical_chan, u8 dac_data)
586{
587 struct s626_private *devpriv = dev->private;
588 u32 chan;
589
590
591
592
593
594 devpriv->trim_setpoint[logical_chan] = dac_data;
595
596
597 chan = s626_trimchan[logical_chan];
598
599
600
601
602
603
604
605
606 writel(S626_XSD2 | S626_XFIFO_1 | S626_WS3,
607 dev->mmio + S626_VECTPORT(2));
608
609 writel(S626_XSD2 | S626_XFIFO_0 | S626_WS3,
610 dev->mmio + S626_VECTPORT(3));
611
612 writel(S626_XSD2 | S626_XFIFO_3 | S626_WS1,
613 dev->mmio + S626_VECTPORT(4));
614
615 writel(S626_XSD2 | S626_XFIFO_2 | S626_WS1 | S626_EOS,
616 dev->mmio + S626_VECTPORT(5));
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631 return s626_send_dac(dev, (chan << 8) | dac_data);
632}
633
634static int s626_load_trim_dacs(struct comedi_device *dev)
635{
636 u8 i;
637 int ret;
638
639
640 for (i = 0; i < ARRAY_SIZE(s626_trimchan); i++) {
641 ret = s626_write_trim_dac(dev, i,
642 s626_i2c_read(dev, s626_trimadrs[i]));
643 if (ret)
644 return ret;
645 }
646 return 0;
647}
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663static void s626_set_latch_source(struct comedi_device *dev,
664 unsigned int chan, u16 value)
665{
666 s626_debi_replace(dev, S626_LP_CRB(chan),
667 ~(S626_CRBMSK_INTCTRL | S626_CRBMSK_LATCHSRC),
668 S626_SET_CRB_LATCHSRC(value));
669}
670
671
672
673
674static void s626_preload(struct comedi_device *dev,
675 unsigned int chan, u32 value)
676{
677 s626_debi_write(dev, S626_LP_CNTR(chan), value);
678 s626_debi_write(dev, S626_LP_CNTR(chan) + 2, value >> 16);
679}
680
681
682
683
684
685
686static void s626_reset_cap_flags(struct comedi_device *dev,
687 unsigned int chan)
688{
689 u16 set;
690
691 set = S626_SET_CRB_INTRESETCMD(1);
692 if (chan < 3)
693 set |= S626_SET_CRB_INTRESET_A(1);
694 else
695 set |= S626_SET_CRB_INTRESET_B(1);
696
697 s626_debi_replace(dev, S626_LP_CRB(chan), ~S626_CRBMSK_INTCTRL, set);
698}
699
700
701
702
703
704
705
706static void s626_set_mode_a(struct comedi_device *dev,
707 unsigned int chan, u16 setup,
708 u16 disable_int_src)
709{
710 struct s626_private *devpriv = dev->private;
711 u16 cra;
712 u16 crb;
713 unsigned int cntsrc, clkmult, clkpol;
714
715
716
717 cra = S626_SET_CRA_LOADSRC_A(S626_GET_STD_LOADSRC(setup));
718
719 cra |= S626_SET_CRA_INDXSRC_A(S626_GET_STD_INDXSRC(setup));
720
721
722 crb = S626_SET_CRB_INTRESETCMD(1) | S626_SET_CRB_INTRESET_A(1);
723
724 crb |= S626_SET_CRB_CLKENAB_A(S626_GET_STD_CLKENAB(setup));
725
726
727 if (!disable_int_src)
728 cra |= S626_SET_CRA_INTSRC_A(S626_GET_STD_INTSRC(setup));
729
730
731 clkpol = S626_GET_STD_CLKPOL(setup);
732 switch (S626_GET_STD_ENCMODE(setup)) {
733 case S626_ENCMODE_EXTENDER:
734
735
736 case S626_ENCMODE_TIMER:
737
738 cntsrc = S626_CNTSRC_SYSCLK;
739
740 cntsrc |= clkpol;
741
742 clkpol = 1;
743
744 clkmult = S626_CLKMULT_1X;
745 break;
746 default:
747
748 cntsrc = S626_CNTSRC_ENCODER;
749
750
751 clkmult = S626_GET_STD_CLKMULT(setup);
752 if (clkmult == S626_CLKMULT_SPECIAL)
753 clkmult = S626_CLKMULT_1X;
754 break;
755 }
756 cra |= S626_SET_CRA_CNTSRC_A(cntsrc) | S626_SET_CRA_CLKPOL_A(clkpol) |
757 S626_SET_CRA_CLKMULT_A(clkmult);
758
759
760
761
762
763 if (S626_GET_STD_INDXSRC(setup) != S626_INDXSRC_SOFT)
764 cra |= S626_SET_CRA_INDXPOL_A(S626_GET_STD_INDXPOL(setup));
765
766
767
768
769
770 if (disable_int_src)
771 devpriv->counter_int_enabs &= ~(S626_OVERMASK(chan) |
772 S626_INDXMASK(chan));
773
774
775
776
777
778 s626_debi_replace(dev, S626_LP_CRA(chan),
779 S626_CRAMSK_INDXSRC_B | S626_CRAMSK_CNTSRC_B, cra);
780 s626_debi_replace(dev, S626_LP_CRB(chan),
781 ~(S626_CRBMSK_INTCTRL | S626_CRBMSK_CLKENAB_A), crb);
782}
783
784static void s626_set_mode_b(struct comedi_device *dev,
785 unsigned int chan, u16 setup,
786 u16 disable_int_src)
787{
788 struct s626_private *devpriv = dev->private;
789 u16 cra;
790 u16 crb;
791 unsigned int cntsrc, clkmult, clkpol;
792
793
794
795 cra = S626_SET_CRA_INDXSRC_B(S626_GET_STD_INDXSRC(setup));
796
797
798 crb = S626_SET_CRB_INTRESETCMD(1) | S626_SET_CRB_INTRESET_B(1);
799
800 crb |= S626_SET_CRB_CLKENAB_B(S626_GET_STD_CLKENAB(setup));
801
802 crb |= S626_SET_CRB_LOADSRC_B(S626_GET_STD_LOADSRC(setup));
803
804
805 if (!disable_int_src)
806 crb |= S626_SET_CRB_INTSRC_B(S626_GET_STD_INTSRC(setup));
807
808
809 clkpol = S626_GET_STD_CLKPOL(setup);
810 switch (S626_GET_STD_ENCMODE(setup)) {
811 case S626_ENCMODE_TIMER:
812
813 cntsrc = S626_CNTSRC_SYSCLK;
814
815 cntsrc |= clkpol;
816
817 clkpol = 1;
818
819 clkmult = S626_CLKMULT_1X;
820 break;
821 case S626_ENCMODE_EXTENDER:
822
823 cntsrc = S626_CNTSRC_SYSCLK;
824
825 cntsrc |= clkpol;
826
827 clkpol = 1;
828
829 clkmult = S626_CLKMULT_SPECIAL;
830 break;
831 default:
832
833 cntsrc = S626_CNTSRC_ENCODER;
834
835
836 clkmult = S626_GET_STD_CLKMULT(setup);
837 if (clkmult == S626_CLKMULT_SPECIAL)
838 clkmult = S626_CLKMULT_1X;
839 break;
840 }
841 cra |= S626_SET_CRA_CNTSRC_B(cntsrc);
842 crb |= S626_SET_CRB_CLKPOL_B(clkpol) | S626_SET_CRB_CLKMULT_B(clkmult);
843
844
845
846
847
848 if (S626_GET_STD_INDXSRC(setup) != S626_INDXSRC_SOFT)
849 crb |= S626_SET_CRB_INDXPOL_B(S626_GET_STD_INDXPOL(setup));
850
851
852
853
854
855 if (disable_int_src)
856 devpriv->counter_int_enabs &= ~(S626_OVERMASK(chan) |
857 S626_INDXMASK(chan));
858
859
860
861
862
863 s626_debi_replace(dev, S626_LP_CRA(chan),
864 ~(S626_CRAMSK_INDXSRC_B | S626_CRAMSK_CNTSRC_B), cra);
865 s626_debi_replace(dev, S626_LP_CRB(chan),
866 S626_CRBMSK_CLKENAB_A | S626_CRBMSK_LATCHSRC, crb);
867}
868
869static void s626_set_mode(struct comedi_device *dev,
870 unsigned int chan,
871 u16 setup, u16 disable_int_src)
872{
873 if (chan < 3)
874 s626_set_mode_a(dev, chan, setup, disable_int_src);
875 else
876 s626_set_mode_b(dev, chan, setup, disable_int_src);
877}
878
879
880
881
882static void s626_set_enable(struct comedi_device *dev,
883 unsigned int chan, u16 enab)
884{
885 unsigned int mask = S626_CRBMSK_INTCTRL;
886 unsigned int set;
887
888 if (chan < 3) {
889 mask |= S626_CRBMSK_CLKENAB_A;
890 set = S626_SET_CRB_CLKENAB_A(enab);
891 } else {
892 mask |= S626_CRBMSK_CLKENAB_B;
893 set = S626_SET_CRB_CLKENAB_B(enab);
894 }
895 s626_debi_replace(dev, S626_LP_CRB(chan), ~mask, set);
896}
897
898
899
900
901
902
903static void s626_set_load_trig(struct comedi_device *dev,
904 unsigned int chan, u16 trig)
905{
906 u16 reg;
907 u16 mask;
908 u16 set;
909
910 if (chan < 3) {
911 reg = S626_LP_CRA(chan);
912 mask = S626_CRAMSK_LOADSRC_A;
913 set = S626_SET_CRA_LOADSRC_A(trig);
914 } else {
915 reg = S626_LP_CRB(chan);
916 mask = S626_CRBMSK_LOADSRC_B | S626_CRBMSK_INTCTRL;
917 set = S626_SET_CRB_LOADSRC_B(trig);
918 }
919 s626_debi_replace(dev, reg, ~mask, set);
920}
921
922
923
924
925
926
927static void s626_set_int_src(struct comedi_device *dev,
928 unsigned int chan, u16 int_source)
929{
930 struct s626_private *devpriv = dev->private;
931 u16 cra_reg = S626_LP_CRA(chan);
932 u16 crb_reg = S626_LP_CRB(chan);
933
934 if (chan < 3) {
935
936 s626_debi_replace(dev, crb_reg, ~S626_CRBMSK_INTCTRL,
937 S626_SET_CRB_INTRESETCMD(1) |
938 S626_SET_CRB_INTRESET_A(1));
939
940
941 s626_debi_replace(dev, cra_reg, ~S626_CRAMSK_INTSRC_A,
942 S626_SET_CRA_INTSRC_A(int_source));
943 } else {
944 u16 crb;
945
946
947 crb = s626_debi_read(dev, crb_reg);
948 crb &= ~S626_CRBMSK_INTCTRL;
949
950
951 s626_debi_write(dev, crb_reg,
952 crb | S626_SET_CRB_INTRESETCMD(1) |
953 S626_SET_CRB_INTRESET_B(1));
954
955
956 s626_debi_write(dev, crb_reg,
957 (crb & ~S626_CRBMSK_INTSRC_B) |
958 S626_SET_CRB_INTSRC_B(int_source));
959 }
960
961
962 devpriv->counter_int_enabs &= ~(S626_OVERMASK(chan) |
963 S626_INDXMASK(chan));
964 switch (int_source) {
965 case 0:
966 default:
967 break;
968 case 1:
969 devpriv->counter_int_enabs |= S626_OVERMASK(chan);
970 break;
971 case 2:
972 devpriv->counter_int_enabs |= S626_INDXMASK(chan);
973 break;
974 case 3:
975 devpriv->counter_int_enabs |= (S626_OVERMASK(chan) |
976 S626_INDXMASK(chan));
977 break;
978 }
979}
980
981
982
983
984static void s626_pulse_index(struct comedi_device *dev,
985 unsigned int chan)
986{
987 if (chan < 3) {
988 u16 cra;
989
990 cra = s626_debi_read(dev, S626_LP_CRA(chan));
991
992
993 s626_debi_write(dev, S626_LP_CRA(chan),
994 (cra ^ S626_CRAMSK_INDXPOL_A));
995 s626_debi_write(dev, S626_LP_CRA(chan), cra);
996 } else {
997 u16 crb;
998
999 crb = s626_debi_read(dev, S626_LP_CRB(chan));
1000 crb &= ~S626_CRBMSK_INTCTRL;
1001
1002
1003 s626_debi_write(dev, S626_LP_CRB(chan),
1004 (crb ^ S626_CRBMSK_INDXPOL_B));
1005 s626_debi_write(dev, S626_LP_CRB(chan), crb);
1006 }
1007}
1008
1009static unsigned int s626_ai_reg_to_uint(unsigned int data)
1010{
1011 return ((data >> 18) & 0x3fff) ^ 0x2000;
1012}
1013
1014static int s626_dio_set_irq(struct comedi_device *dev, unsigned int chan)
1015{
1016 unsigned int group = chan / 16;
1017 unsigned int mask = 1 << (chan - (16 * group));
1018 unsigned int status;
1019
1020
1021 status = s626_debi_read(dev, S626_LP_RDEDGSEL(group));
1022 s626_debi_write(dev, S626_LP_WREDGSEL(group), mask | status);
1023
1024
1025 status = s626_debi_read(dev, S626_LP_RDINTSEL(group));
1026 s626_debi_write(dev, S626_LP_WRINTSEL(group), mask | status);
1027
1028
1029 s626_debi_write(dev, S626_LP_MISC1, S626_MISC1_EDCAP);
1030
1031
1032 status = s626_debi_read(dev, S626_LP_RDCAPSEL(group));
1033 s626_debi_write(dev, S626_LP_WRCAPSEL(group), mask | status);
1034
1035 return 0;
1036}
1037
1038static int s626_dio_reset_irq(struct comedi_device *dev, unsigned int group,
1039 unsigned int mask)
1040{
1041
1042 s626_debi_write(dev, S626_LP_MISC1, S626_MISC1_NOEDCAP);
1043
1044
1045 s626_debi_write(dev, S626_LP_WRCAPSEL(group), mask);
1046
1047 return 0;
1048}
1049
1050static int s626_dio_clear_irq(struct comedi_device *dev)
1051{
1052 unsigned int group;
1053
1054
1055 s626_debi_write(dev, S626_LP_MISC1, S626_MISC1_NOEDCAP);
1056
1057
1058 for (group = 0; group < S626_DIO_BANKS; group++)
1059 s626_debi_write(dev, S626_LP_WRCAPSEL(group), 0xffff);
1060
1061 return 0;
1062}
1063
1064static void s626_handle_dio_interrupt(struct comedi_device *dev,
1065 u16 irqbit, u8 group)
1066{
1067 struct s626_private *devpriv = dev->private;
1068 struct comedi_subdevice *s = dev->read_subdev;
1069 struct comedi_cmd *cmd = &s->async->cmd;
1070
1071 s626_dio_reset_irq(dev, group, irqbit);
1072
1073 if (devpriv->ai_cmd_running) {
1074
1075 if ((irqbit >> (cmd->start_arg - (16 * group))) == 1 &&
1076 cmd->start_src == TRIG_EXT) {
1077
1078 s626_mc_enable(dev, S626_MC1_ERPS1, S626_P_MC1);
1079
1080 if (cmd->scan_begin_src == TRIG_EXT)
1081 s626_dio_set_irq(dev, cmd->scan_begin_arg);
1082 }
1083 if ((irqbit >> (cmd->scan_begin_arg - (16 * group))) == 1 &&
1084 cmd->scan_begin_src == TRIG_EXT) {
1085
1086 s626_mc_enable(dev, S626_MC2_ADC_RPS, S626_P_MC2);
1087
1088 if (cmd->convert_src == TRIG_EXT) {
1089 devpriv->ai_convert_count = cmd->chanlist_len;
1090
1091 s626_dio_set_irq(dev, cmd->convert_arg);
1092 }
1093
1094 if (cmd->convert_src == TRIG_TIMER) {
1095 devpriv->ai_convert_count = cmd->chanlist_len;
1096 s626_set_enable(dev, 5, S626_CLKENAB_ALWAYS);
1097 }
1098 }
1099 if ((irqbit >> (cmd->convert_arg - (16 * group))) == 1 &&
1100 cmd->convert_src == TRIG_EXT) {
1101
1102 s626_mc_enable(dev, S626_MC2_ADC_RPS, S626_P_MC2);
1103
1104 devpriv->ai_convert_count--;
1105 if (devpriv->ai_convert_count > 0)
1106 s626_dio_set_irq(dev, cmd->convert_arg);
1107 }
1108 }
1109}
1110
1111static void s626_check_dio_interrupts(struct comedi_device *dev)
1112{
1113 u16 irqbit;
1114 u8 group;
1115
1116 for (group = 0; group < S626_DIO_BANKS; group++) {
1117
1118 irqbit = s626_debi_read(dev, S626_LP_RDCAPFLG(group));
1119
1120
1121 if (irqbit) {
1122 s626_handle_dio_interrupt(dev, irqbit, group);
1123 return;
1124 }
1125 }
1126}
1127
1128static void s626_check_counter_interrupts(struct comedi_device *dev)
1129{
1130 struct s626_private *devpriv = dev->private;
1131 struct comedi_subdevice *s = dev->read_subdev;
1132 struct comedi_async *async = s->async;
1133 struct comedi_cmd *cmd = &async->cmd;
1134 u16 irqbit;
1135
1136
1137 irqbit = s626_debi_read(dev, S626_LP_RDMISC2);
1138
1139
1140 if (irqbit & S626_IRQ_COINT1A) {
1141
1142 s626_reset_cap_flags(dev, 0);
1143 }
1144 if (irqbit & S626_IRQ_COINT2A) {
1145
1146 s626_reset_cap_flags(dev, 1);
1147 }
1148 if (irqbit & S626_IRQ_COINT3A) {
1149
1150 s626_reset_cap_flags(dev, 2);
1151 }
1152 if (irqbit & S626_IRQ_COINT1B) {
1153
1154 s626_reset_cap_flags(dev, 3);
1155 }
1156 if (irqbit & S626_IRQ_COINT2B) {
1157
1158 s626_reset_cap_flags(dev, 4);
1159
1160 if (devpriv->ai_convert_count > 0) {
1161 devpriv->ai_convert_count--;
1162 if (devpriv->ai_convert_count == 0)
1163 s626_set_enable(dev, 4, S626_CLKENAB_INDEX);
1164
1165 if (cmd->convert_src == TRIG_TIMER) {
1166
1167 s626_mc_enable(dev, S626_MC2_ADC_RPS,
1168 S626_P_MC2);
1169 }
1170 }
1171 }
1172 if (irqbit & S626_IRQ_COINT3B) {
1173
1174 s626_reset_cap_flags(dev, 5);
1175
1176 if (cmd->scan_begin_src == TRIG_TIMER) {
1177
1178 s626_mc_enable(dev, S626_MC2_ADC_RPS, S626_P_MC2);
1179 }
1180
1181 if (cmd->convert_src == TRIG_TIMER) {
1182 devpriv->ai_convert_count = cmd->chanlist_len;
1183 s626_set_enable(dev, 4, S626_CLKENAB_ALWAYS);
1184 }
1185 }
1186}
1187
1188static bool s626_handle_eos_interrupt(struct comedi_device *dev)
1189{
1190 struct s626_private *devpriv = dev->private;
1191 struct comedi_subdevice *s = dev->read_subdev;
1192 struct comedi_async *async = s->async;
1193 struct comedi_cmd *cmd = &async->cmd;
1194
1195
1196
1197
1198
1199 u32 *readaddr = (u32 *)devpriv->ana_buf.logical_base + 1;
1200 int i;
1201
1202
1203 for (i = 0; i < cmd->chanlist_len; i++) {
1204 unsigned short tempdata;
1205
1206
1207
1208
1209
1210 tempdata = s626_ai_reg_to_uint(*readaddr);
1211 readaddr++;
1212
1213 comedi_buf_write_samples(s, &tempdata, 1);
1214 }
1215
1216 if (cmd->stop_src == TRIG_COUNT && async->scans_done >= cmd->stop_arg)
1217 async->events |= COMEDI_CB_EOA;
1218
1219 if (async->events & COMEDI_CB_CANCEL_MASK)
1220 devpriv->ai_cmd_running = 0;
1221
1222 if (devpriv->ai_cmd_running && cmd->scan_begin_src == TRIG_EXT)
1223 s626_dio_set_irq(dev, cmd->scan_begin_arg);
1224
1225 comedi_handle_events(dev, s);
1226
1227 return !devpriv->ai_cmd_running;
1228}
1229
1230static irqreturn_t s626_irq_handler(int irq, void *d)
1231{
1232 struct comedi_device *dev = d;
1233 unsigned long flags;
1234 u32 irqtype, irqstatus;
1235
1236 if (!dev->attached)
1237 return IRQ_NONE;
1238
1239 spin_lock_irqsave(&dev->spinlock, flags);
1240
1241
1242 irqstatus = readl(dev->mmio + S626_P_IER);
1243
1244
1245 irqtype = readl(dev->mmio + S626_P_ISR);
1246
1247
1248 writel(0, dev->mmio + S626_P_IER);
1249
1250
1251 writel(irqtype, dev->mmio + S626_P_ISR);
1252
1253 switch (irqtype) {
1254 case S626_IRQ_RPS1:
1255 if (s626_handle_eos_interrupt(dev))
1256 irqstatus = 0;
1257 break;
1258 case S626_IRQ_GPIO3:
1259
1260 s626_check_dio_interrupts(dev);
1261 s626_check_counter_interrupts(dev);
1262 break;
1263 }
1264
1265
1266 writel(irqstatus, dev->mmio + S626_P_IER);
1267
1268 spin_unlock_irqrestore(&dev->spinlock, flags);
1269 return IRQ_HANDLED;
1270}
1271
1272
1273
1274
1275static void s626_reset_adc(struct comedi_device *dev, u8 *ppl)
1276{
1277 struct s626_private *devpriv = dev->private;
1278 struct comedi_subdevice *s = dev->read_subdev;
1279 struct comedi_cmd *cmd = &s->async->cmd;
1280 u32 *rps;
1281 u32 jmp_adrs;
1282 u16 i;
1283 u16 n;
1284 u32 local_ppl;
1285
1286
1287 s626_mc_disable(dev, S626_MC1_ERPS1, S626_P_MC1);
1288
1289
1290 rps = (u32 *)devpriv->rps_buf.logical_base;
1291
1292
1293 writel((u32)devpriv->rps_buf.physical_base,
1294 dev->mmio + S626_P_RPSADDR1);
1295
1296
1297 if (cmd->scan_begin_src != TRIG_FOLLOW) {
1298
1299 *rps++ = S626_RPS_PAUSE | S626_RPS_SIGADC;
1300 *rps++ = S626_RPS_CLRSIGNAL | S626_RPS_SIGADC;
1301 }
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312 *rps++ = S626_RPS_LDREG | (S626_P_DEBICMD >> 2);
1313 *rps++ = S626_DEBI_CMD_WRWORD | S626_LP_GSEL;
1314 *rps++ = S626_RPS_LDREG | (S626_P_DEBIAD >> 2);
1315
1316 *rps++ = S626_GSEL_BIPOLAR5V;
1317 *rps++ = S626_RPS_CLRSIGNAL | S626_RPS_DEBI;
1318
1319
1320 *rps++ = S626_RPS_UPLOAD | S626_RPS_DEBI;
1321
1322 *rps++ = S626_RPS_PAUSE | S626_RPS_DEBI;
1323
1324
1325
1326
1327
1328
1329 for (devpriv->adc_items = 0; devpriv->adc_items < 16;
1330 devpriv->adc_items++) {
1331
1332
1333
1334
1335
1336
1337 local_ppl = (*ppl << 8) | (*ppl & 0x10 ? S626_GSEL_BIPOLAR5V :
1338 S626_GSEL_BIPOLAR10V);
1339
1340
1341
1342 *rps++ = S626_RPS_LDREG | (S626_P_DEBICMD >> 2);
1343 *rps++ = S626_DEBI_CMD_WRWORD | S626_LP_GSEL;
1344
1345 *rps++ = S626_RPS_LDREG | (S626_P_DEBIAD >> 2);
1346 *rps++ = local_ppl;
1347
1348 *rps++ = S626_RPS_CLRSIGNAL | S626_RPS_DEBI;
1349
1350 *rps++ = S626_RPS_UPLOAD | S626_RPS_DEBI;
1351
1352 *rps++ = S626_RPS_PAUSE | S626_RPS_DEBI;
1353
1354 *rps++ = S626_RPS_LDREG | (S626_P_DEBICMD >> 2);
1355
1356 *rps++ = S626_DEBI_CMD_WRWORD | S626_LP_ISEL;
1357 *rps++ = S626_RPS_LDREG | (S626_P_DEBIAD >> 2);
1358
1359 *rps++ = local_ppl;
1360
1361 *rps++ = S626_RPS_CLRSIGNAL | S626_RPS_DEBI;
1362
1363 *rps++ = S626_RPS_UPLOAD | S626_RPS_DEBI;
1364
1365 *rps++ = S626_RPS_PAUSE | S626_RPS_DEBI;
1366
1367
1368
1369
1370
1371
1372
1373
1374 jmp_adrs =
1375 (u32)devpriv->rps_buf.physical_base +
1376 (u32)((unsigned long)rps -
1377 (unsigned long)devpriv->rps_buf.logical_base);
1378 for (i = 0; i < (10 * S626_RPSCLK_PER_US / 2); i++) {
1379 jmp_adrs += 8;
1380
1381 *rps++ = S626_RPS_JUMP;
1382 *rps++ = jmp_adrs;
1383 }
1384
1385 if (cmd->convert_src != TRIG_NOW) {
1386
1387 *rps++ = S626_RPS_PAUSE | S626_RPS_SIGADC;
1388 *rps++ = S626_RPS_CLRSIGNAL | S626_RPS_SIGADC;
1389 }
1390
1391
1392 *rps++ = S626_RPS_LDREG | (S626_P_GPIO >> 2);
1393 *rps++ = S626_GPIO_BASE | S626_GPIO1_LO;
1394 *rps++ = S626_RPS_NOP;
1395
1396
1397 *rps++ = S626_RPS_LDREG | (S626_P_GPIO >> 2);
1398 *rps++ = S626_GPIO_BASE | S626_GPIO1_HI;
1399
1400
1401
1402
1403
1404
1405 *rps++ = S626_RPS_PAUSE | S626_RPS_GPIO2;
1406
1407
1408 *rps++ = S626_RPS_STREG |
1409 (S626_BUGFIX_STREG(S626_P_FB_BUFFER1) >> 2);
1410 *rps++ = (u32)devpriv->ana_buf.physical_base +
1411 (devpriv->adc_items << 2);
1412
1413
1414
1415
1416
1417 if (*ppl++ & S626_EOPL) {
1418 devpriv->adc_items++;
1419 break;
1420 }
1421 }
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431 for (n = 0; n < (2 * S626_RPSCLK_PER_US); n++)
1432 *rps++ = S626_RPS_NOP;
1433
1434
1435
1436
1437
1438
1439 *rps++ = S626_RPS_LDREG | (S626_P_GPIO >> 2);
1440 *rps++ = S626_GPIO_BASE | S626_GPIO1_LO;
1441 *rps++ = S626_RPS_NOP;
1442
1443 *rps++ = S626_RPS_LDREG | (S626_P_GPIO >> 2);
1444 *rps++ = S626_GPIO_BASE | S626_GPIO1_HI;
1445
1446
1447
1448
1449
1450 *rps++ = S626_RPS_PAUSE | S626_RPS_GPIO2;
1451
1452
1453 *rps++ = S626_RPS_STREG | (S626_BUGFIX_STREG(S626_P_FB_BUFFER1) >> 2);
1454 *rps++ = (u32)devpriv->ana_buf.physical_base +
1455 (devpriv->adc_items << 2);
1456
1457
1458
1459
1460
1461
1462 if (devpriv->ai_cmd_running == 1)
1463 *rps++ = S626_RPS_IRQ;
1464
1465
1466 *rps++ = S626_RPS_JUMP;
1467 *rps++ = (u32)devpriv->rps_buf.physical_base;
1468
1469
1470}
1471
1472static int s626_ai_eoc(struct comedi_device *dev,
1473 struct comedi_subdevice *s,
1474 struct comedi_insn *insn,
1475 unsigned long context)
1476{
1477 unsigned int status;
1478
1479 status = readl(dev->mmio + S626_P_PSR);
1480 if (status & S626_PSR_GPIO2)
1481 return 0;
1482 return -EBUSY;
1483}
1484
1485static int s626_ai_insn_read(struct comedi_device *dev,
1486 struct comedi_subdevice *s,
1487 struct comedi_insn *insn,
1488 unsigned int *data)
1489{
1490 u16 chan = CR_CHAN(insn->chanspec);
1491 u16 range = CR_RANGE(insn->chanspec);
1492 u16 adc_spec = 0;
1493 u32 gpio_image;
1494 u32 tmp;
1495 int ret;
1496 int n;
1497
1498
1499
1500
1501
1502 if (range == 0)
1503 adc_spec = (chan << 8) | (S626_GSEL_BIPOLAR5V);
1504 else
1505 adc_spec = (chan << 8) | (S626_GSEL_BIPOLAR10V);
1506
1507
1508 s626_debi_write(dev, S626_LP_GSEL, adc_spec);
1509
1510
1511 s626_debi_write(dev, S626_LP_ISEL, adc_spec);
1512
1513 for (n = 0; n < insn->n; n++) {
1514
1515 usleep_range(10, 20);
1516
1517
1518 gpio_image = readl(dev->mmio + S626_P_GPIO);
1519
1520 writel(gpio_image & ~S626_GPIO1_HI, dev->mmio + S626_P_GPIO);
1521
1522 writel(gpio_image & ~S626_GPIO1_HI, dev->mmio + S626_P_GPIO);
1523 writel(gpio_image & ~S626_GPIO1_HI, dev->mmio + S626_P_GPIO);
1524
1525 writel(gpio_image | S626_GPIO1_HI, dev->mmio + S626_P_GPIO);
1526
1527
1528
1529
1530
1531
1532
1533
1534 ret = comedi_timeout(dev, s, insn, s626_ai_eoc, 0);
1535 if (ret)
1536 return ret;
1537
1538
1539 if (n != 0) {
1540 tmp = readl(dev->mmio + S626_P_FB_BUFFER1);
1541 data[n - 1] = s626_ai_reg_to_uint(tmp);
1542 }
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553 udelay(4);
1554 }
1555
1556
1557
1558
1559
1560 gpio_image = readl(dev->mmio + S626_P_GPIO);
1561
1562 writel(gpio_image & ~S626_GPIO1_HI, dev->mmio + S626_P_GPIO);
1563
1564 writel(gpio_image & ~S626_GPIO1_HI, dev->mmio + S626_P_GPIO);
1565 writel(gpio_image & ~S626_GPIO1_HI, dev->mmio + S626_P_GPIO);
1566
1567 writel(gpio_image | S626_GPIO1_HI, dev->mmio + S626_P_GPIO);
1568
1569
1570
1571
1572 ret = comedi_timeout(dev, s, insn, s626_ai_eoc, 0);
1573 if (ret)
1574 return ret;
1575
1576
1577
1578
1579 if (n != 0) {
1580 tmp = readl(dev->mmio + S626_P_FB_BUFFER1);
1581 data[n - 1] = s626_ai_reg_to_uint(tmp);
1582 }
1583
1584 return n;
1585}
1586
1587static int s626_ai_load_polllist(u8 *ppl, struct comedi_cmd *cmd)
1588{
1589 int n;
1590
1591 for (n = 0; n < cmd->chanlist_len; n++) {
1592 if (CR_RANGE(cmd->chanlist[n]) == 0)
1593 ppl[n] = CR_CHAN(cmd->chanlist[n]) | S626_RANGE_5V;
1594 else
1595 ppl[n] = CR_CHAN(cmd->chanlist[n]) | S626_RANGE_10V;
1596 }
1597 if (n != 0)
1598 ppl[n - 1] |= S626_EOPL;
1599
1600 return n;
1601}
1602
1603static int s626_ai_inttrig(struct comedi_device *dev,
1604 struct comedi_subdevice *s,
1605 unsigned int trig_num)
1606{
1607 struct comedi_cmd *cmd = &s->async->cmd;
1608
1609 if (trig_num != cmd->start_arg)
1610 return -EINVAL;
1611
1612
1613 s626_mc_enable(dev, S626_MC1_ERPS1, S626_P_MC1);
1614
1615 s->async->inttrig = NULL;
1616
1617 return 1;
1618}
1619
1620
1621
1622
1623
1624
1625
1626
1627static int s626_ns_to_timer(unsigned int *nanosec, unsigned int flags)
1628{
1629 int divider, base;
1630
1631 base = 500;
1632
1633 switch (flags & CMDF_ROUND_MASK) {
1634 case CMDF_ROUND_NEAREST:
1635 default:
1636 divider = DIV_ROUND_CLOSEST(*nanosec, base);
1637 break;
1638 case CMDF_ROUND_DOWN:
1639 divider = (*nanosec) / base;
1640 break;
1641 case CMDF_ROUND_UP:
1642 divider = DIV_ROUND_UP(*nanosec, base);
1643 break;
1644 }
1645
1646 *nanosec = base * divider;
1647 return divider - 1;
1648}
1649
1650static void s626_timer_load(struct comedi_device *dev,
1651 unsigned int chan, int tick)
1652{
1653 u16 setup =
1654
1655 S626_SET_STD_LOADSRC(S626_LOADSRC_INDX) |
1656
1657 S626_SET_STD_INDXSRC(S626_INDXSRC_SOFT) |
1658
1659 S626_SET_STD_ENCMODE(S626_ENCMODE_TIMER) |
1660
1661 S626_SET_STD_CLKPOL(S626_CNTDIR_DOWN) |
1662
1663 S626_SET_STD_CLKMULT(S626_CLKMULT_1X) |
1664
1665 S626_SET_STD_CLKENAB(S626_CLKENAB_INDEX);
1666 u16 value_latchsrc = S626_LATCHSRC_A_INDXA;
1667
1668
1669 s626_set_mode(dev, chan, setup, false);
1670
1671
1672 s626_preload(dev, chan, tick);
1673
1674
1675
1676
1677
1678 s626_set_load_trig(dev, chan, 0);
1679 s626_pulse_index(dev, chan);
1680
1681
1682 s626_set_load_trig(dev, chan, 1);
1683
1684
1685 s626_set_int_src(dev, chan, S626_INTSRC_OVER);
1686
1687 s626_set_latch_source(dev, chan, value_latchsrc);
1688
1689}
1690
1691
1692static int s626_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
1693{
1694 struct s626_private *devpriv = dev->private;
1695 u8 ppl[16];
1696 struct comedi_cmd *cmd = &s->async->cmd;
1697 int tick;
1698
1699 if (devpriv->ai_cmd_running) {
1700 dev_err(dev->class_dev,
1701 "%s: Another ai_cmd is running\n", __func__);
1702 return -EBUSY;
1703 }
1704
1705 writel(0, dev->mmio + S626_P_IER);
1706
1707
1708 writel(S626_IRQ_RPS1 | S626_IRQ_GPIO3, dev->mmio + S626_P_ISR);
1709
1710
1711 s626_dio_clear_irq(dev);
1712
1713
1714
1715 devpriv->ai_cmd_running = 0;
1716
1717 s626_ai_load_polllist(ppl, cmd);
1718 devpriv->ai_cmd_running = 1;
1719 devpriv->ai_convert_count = 0;
1720
1721 switch (cmd->scan_begin_src) {
1722 case TRIG_FOLLOW:
1723 break;
1724 case TRIG_TIMER:
1725
1726
1727
1728
1729 tick = s626_ns_to_timer(&cmd->scan_begin_arg, cmd->flags);
1730
1731
1732 s626_timer_load(dev, 5, tick);
1733 s626_set_enable(dev, 5, S626_CLKENAB_ALWAYS);
1734 break;
1735 case TRIG_EXT:
1736
1737 if (cmd->start_src != TRIG_EXT)
1738 s626_dio_set_irq(dev, cmd->scan_begin_arg);
1739 break;
1740 }
1741
1742 switch (cmd->convert_src) {
1743 case TRIG_NOW:
1744 break;
1745 case TRIG_TIMER:
1746
1747
1748
1749
1750 tick = s626_ns_to_timer(&cmd->convert_arg, cmd->flags);
1751
1752
1753 s626_timer_load(dev, 4, tick);
1754 s626_set_enable(dev, 4, S626_CLKENAB_INDEX);
1755 break;
1756 case TRIG_EXT:
1757
1758 if (cmd->scan_begin_src != TRIG_EXT &&
1759 cmd->start_src == TRIG_EXT)
1760 s626_dio_set_irq(dev, cmd->convert_arg);
1761 break;
1762 }
1763
1764 s626_reset_adc(dev, ppl);
1765
1766 switch (cmd->start_src) {
1767 case TRIG_NOW:
1768
1769
1770
1771
1772 s626_mc_enable(dev, S626_MC1_ERPS1, S626_P_MC1);
1773 s->async->inttrig = NULL;
1774 break;
1775 case TRIG_EXT:
1776
1777 s626_dio_set_irq(dev, cmd->start_arg);
1778 s->async->inttrig = NULL;
1779 break;
1780 case TRIG_INT:
1781 s->async->inttrig = s626_ai_inttrig;
1782 break;
1783 }
1784
1785
1786 writel(S626_IRQ_GPIO3 | S626_IRQ_RPS1, dev->mmio + S626_P_IER);
1787
1788 return 0;
1789}
1790
1791static int s626_ai_cmdtest(struct comedi_device *dev,
1792 struct comedi_subdevice *s, struct comedi_cmd *cmd)
1793{
1794 int err = 0;
1795 unsigned int arg;
1796
1797
1798
1799 err |= comedi_check_trigger_src(&cmd->start_src,
1800 TRIG_NOW | TRIG_INT | TRIG_EXT);
1801 err |= comedi_check_trigger_src(&cmd->scan_begin_src,
1802 TRIG_TIMER | TRIG_EXT | TRIG_FOLLOW);
1803 err |= comedi_check_trigger_src(&cmd->convert_src,
1804 TRIG_TIMER | TRIG_EXT | TRIG_NOW);
1805 err |= comedi_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
1806 err |= comedi_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE);
1807
1808 if (err)
1809 return 1;
1810
1811
1812
1813 err |= comedi_check_trigger_is_unique(cmd->start_src);
1814 err |= comedi_check_trigger_is_unique(cmd->scan_begin_src);
1815 err |= comedi_check_trigger_is_unique(cmd->convert_src);
1816 err |= comedi_check_trigger_is_unique(cmd->stop_src);
1817
1818
1819
1820 if (err)
1821 return 2;
1822
1823
1824
1825 switch (cmd->start_src) {
1826 case TRIG_NOW:
1827 case TRIG_INT:
1828 err |= comedi_check_trigger_arg_is(&cmd->start_arg, 0);
1829 break;
1830 case TRIG_EXT:
1831 err |= comedi_check_trigger_arg_max(&cmd->start_arg, 39);
1832 break;
1833 }
1834
1835 if (cmd->scan_begin_src == TRIG_EXT)
1836 err |= comedi_check_trigger_arg_max(&cmd->scan_begin_arg, 39);
1837 if (cmd->convert_src == TRIG_EXT)
1838 err |= comedi_check_trigger_arg_max(&cmd->convert_arg, 39);
1839
1840#define S626_MAX_SPEED 200000
1841#define S626_MIN_SPEED 2000000000
1842
1843 if (cmd->scan_begin_src == TRIG_TIMER) {
1844 err |= comedi_check_trigger_arg_min(&cmd->scan_begin_arg,
1845 S626_MAX_SPEED);
1846 err |= comedi_check_trigger_arg_max(&cmd->scan_begin_arg,
1847 S626_MIN_SPEED);
1848 } else {
1849
1850
1851
1852
1853
1854
1855 }
1856 if (cmd->convert_src == TRIG_TIMER) {
1857 err |= comedi_check_trigger_arg_min(&cmd->convert_arg,
1858 S626_MAX_SPEED);
1859 err |= comedi_check_trigger_arg_max(&cmd->convert_arg,
1860 S626_MIN_SPEED);
1861 } else {
1862
1863
1864
1865
1866 }
1867
1868 err |= comedi_check_trigger_arg_is(&cmd->scan_end_arg,
1869 cmd->chanlist_len);
1870
1871 if (cmd->stop_src == TRIG_COUNT)
1872 err |= comedi_check_trigger_arg_min(&cmd->stop_arg, 1);
1873 else
1874 err |= comedi_check_trigger_arg_is(&cmd->stop_arg, 0);
1875
1876 if (err)
1877 return 3;
1878
1879
1880
1881 if (cmd->scan_begin_src == TRIG_TIMER) {
1882 arg = cmd->scan_begin_arg;
1883 s626_ns_to_timer(&arg, cmd->flags);
1884 err |= comedi_check_trigger_arg_is(&cmd->scan_begin_arg, arg);
1885 }
1886
1887 if (cmd->convert_src == TRIG_TIMER) {
1888 arg = cmd->convert_arg;
1889 s626_ns_to_timer(&arg, cmd->flags);
1890 err |= comedi_check_trigger_arg_is(&cmd->convert_arg, arg);
1891
1892 if (cmd->scan_begin_src == TRIG_TIMER) {
1893 arg = cmd->convert_arg * cmd->scan_end_arg;
1894 err |= comedi_check_trigger_arg_min(
1895 &cmd->scan_begin_arg, arg);
1896 }
1897 }
1898
1899 if (err)
1900 return 4;
1901
1902 return 0;
1903}
1904
1905static int s626_ai_cancel(struct comedi_device *dev, struct comedi_subdevice *s)
1906{
1907 struct s626_private *devpriv = dev->private;
1908
1909
1910 s626_mc_disable(dev, S626_MC1_ERPS1, S626_P_MC1);
1911
1912
1913 writel(0, dev->mmio + S626_P_IER);
1914
1915 devpriv->ai_cmd_running = 0;
1916
1917 return 0;
1918}
1919
1920static int s626_ao_insn_write(struct comedi_device *dev,
1921 struct comedi_subdevice *s,
1922 struct comedi_insn *insn,
1923 unsigned int *data)
1924{
1925 unsigned int chan = CR_CHAN(insn->chanspec);
1926 int i;
1927
1928 for (i = 0; i < insn->n; i++) {
1929 s16 dacdata = (s16)data[i];
1930 int ret;
1931
1932 dacdata -= (0x1fff);
1933
1934 ret = s626_set_dac(dev, chan, dacdata);
1935 if (ret)
1936 return ret;
1937
1938 s->readback[chan] = data[i];
1939 }
1940
1941 return insn->n;
1942}
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952static void s626_dio_init(struct comedi_device *dev)
1953{
1954 u16 group;
1955
1956
1957 s626_debi_write(dev, S626_LP_MISC1, S626_MISC1_NOEDCAP);
1958
1959
1960 for (group = 0; group < S626_DIO_BANKS; group++) {
1961
1962 s626_debi_write(dev, S626_LP_WRINTSEL(group), 0);
1963
1964 s626_debi_write(dev, S626_LP_WRCAPSEL(group), 0xffff);
1965
1966 s626_debi_write(dev, S626_LP_WREDGSEL(group), 0);
1967
1968 s626_debi_write(dev, S626_LP_WRDOUT(group), 0);
1969 }
1970}
1971
1972static int s626_dio_insn_bits(struct comedi_device *dev,
1973 struct comedi_subdevice *s,
1974 struct comedi_insn *insn,
1975 unsigned int *data)
1976{
1977 unsigned long group = (unsigned long)s->private;
1978
1979 if (comedi_dio_update_state(s, data))
1980 s626_debi_write(dev, S626_LP_WRDOUT(group), s->state);
1981
1982 data[1] = s626_debi_read(dev, S626_LP_RDDIN(group));
1983
1984 return insn->n;
1985}
1986
1987static int s626_dio_insn_config(struct comedi_device *dev,
1988 struct comedi_subdevice *s,
1989 struct comedi_insn *insn,
1990 unsigned int *data)
1991{
1992 unsigned long group = (unsigned long)s->private;
1993 int ret;
1994
1995 ret = comedi_dio_insn_config(dev, s, insn, data, 0);
1996 if (ret)
1997 return ret;
1998
1999 s626_debi_write(dev, S626_LP_WRDOUT(group), s->io_bits);
2000
2001 return insn->n;
2002}
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013static int s626_enc_insn_config(struct comedi_device *dev,
2014 struct comedi_subdevice *s,
2015 struct comedi_insn *insn, unsigned int *data)
2016{
2017 unsigned int chan = CR_CHAN(insn->chanspec);
2018 u16 setup =
2019
2020 S626_SET_STD_LOADSRC(S626_LOADSRC_INDX) |
2021
2022 S626_SET_STD_INDXSRC(S626_INDXSRC_SOFT) |
2023
2024 S626_SET_STD_ENCMODE(S626_ENCMODE_COUNTER) |
2025
2026 S626_SET_STD_CLKPOL(S626_CLKPOL_POS) |
2027
2028 S626_SET_STD_CLKMULT(S626_CLKMULT_1X) |
2029
2030 S626_SET_STD_CLKENAB(S626_CLKENAB_INDEX);
2031
2032
2033 u16 value_latchsrc = S626_LATCHSRC_AB_READ;
2034 u16 enab = S626_CLKENAB_ALWAYS;
2035
2036
2037
2038 s626_set_mode(dev, chan, setup, true);
2039 s626_preload(dev, chan, data[0]);
2040 s626_pulse_index(dev, chan);
2041 s626_set_latch_source(dev, chan, value_latchsrc);
2042 s626_set_enable(dev, chan, (enab != 0));
2043
2044 return insn->n;
2045}
2046
2047static int s626_enc_insn_read(struct comedi_device *dev,
2048 struct comedi_subdevice *s,
2049 struct comedi_insn *insn,
2050 unsigned int *data)
2051{
2052 unsigned int chan = CR_CHAN(insn->chanspec);
2053 u16 cntr_latch_reg = S626_LP_CNTR(chan);
2054 int i;
2055
2056 for (i = 0; i < insn->n; i++) {
2057 unsigned int val;
2058
2059
2060
2061
2062
2063 val = s626_debi_read(dev, cntr_latch_reg);
2064 val |= (s626_debi_read(dev, cntr_latch_reg + 2) << 16);
2065 data[i] = val;
2066 }
2067
2068 return insn->n;
2069}
2070
2071static int s626_enc_insn_write(struct comedi_device *dev,
2072 struct comedi_subdevice *s,
2073 struct comedi_insn *insn, unsigned int *data)
2074{
2075 unsigned int chan = CR_CHAN(insn->chanspec);
2076
2077
2078 s626_preload(dev, chan, data[0]);
2079
2080
2081
2082
2083
2084 s626_set_load_trig(dev, chan, 0);
2085 s626_pulse_index(dev, chan);
2086 s626_set_load_trig(dev, chan, 2);
2087
2088 return 1;
2089}
2090
2091static void s626_write_misc2(struct comedi_device *dev, u16 new_image)
2092{
2093 s626_debi_write(dev, S626_LP_MISC1, S626_MISC1_WENABLE);
2094 s626_debi_write(dev, S626_LP_WRMISC2, new_image);
2095 s626_debi_write(dev, S626_LP_MISC1, S626_MISC1_WDISABLE);
2096}
2097
2098static void s626_counters_init(struct comedi_device *dev)
2099{
2100 int chan;
2101 u16 setup =
2102
2103 S626_SET_STD_LOADSRC(S626_LOADSRC_INDX) |
2104
2105 S626_SET_STD_INDXSRC(S626_INDXSRC_SOFT) |
2106
2107 S626_SET_STD_ENCMODE(S626_ENCMODE_COUNTER) |
2108
2109 S626_SET_STD_CLKPOL(S626_CLKPOL_POS) |
2110
2111 S626_SET_STD_CLKMULT(S626_CLKMULT_1X) |
2112
2113 S626_SET_STD_CLKENAB(S626_CLKENAB_INDEX);
2114
2115
2116
2117
2118 for (chan = 0; chan < S626_ENCODER_CHANNELS; chan++) {
2119 s626_set_mode(dev, chan, setup, true);
2120 s626_set_int_src(dev, chan, 0);
2121 s626_reset_cap_flags(dev, chan);
2122 s626_set_enable(dev, chan, S626_CLKENAB_ALWAYS);
2123 }
2124}
2125
2126static int s626_allocate_dma_buffers(struct comedi_device *dev)
2127{
2128 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
2129 struct s626_private *devpriv = dev->private;
2130 void *addr;
2131 dma_addr_t appdma;
2132
2133 addr = dma_alloc_coherent(&pcidev->dev, S626_DMABUF_SIZE, &appdma,
2134 GFP_KERNEL);
2135 if (!addr)
2136 return -ENOMEM;
2137 devpriv->ana_buf.logical_base = addr;
2138 devpriv->ana_buf.physical_base = appdma;
2139
2140 addr = dma_alloc_coherent(&pcidev->dev, S626_DMABUF_SIZE, &appdma,
2141 GFP_KERNEL);
2142 if (!addr)
2143 return -ENOMEM;
2144 devpriv->rps_buf.logical_base = addr;
2145 devpriv->rps_buf.physical_base = appdma;
2146
2147 return 0;
2148}
2149
2150static void s626_free_dma_buffers(struct comedi_device *dev)
2151{
2152 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
2153 struct s626_private *devpriv = dev->private;
2154
2155 if (!devpriv)
2156 return;
2157
2158 if (devpriv->rps_buf.logical_base)
2159 dma_free_coherent(&pcidev->dev, S626_DMABUF_SIZE,
2160 devpriv->rps_buf.logical_base,
2161 devpriv->rps_buf.physical_base);
2162 if (devpriv->ana_buf.logical_base)
2163 dma_free_coherent(&pcidev->dev, S626_DMABUF_SIZE,
2164 devpriv->ana_buf.logical_base,
2165 devpriv->ana_buf.physical_base);
2166}
2167
2168static int s626_initialize(struct comedi_device *dev)
2169{
2170 struct s626_private *devpriv = dev->private;
2171 dma_addr_t phys_buf;
2172 u16 chan;
2173 int i;
2174 int ret;
2175
2176
2177 s626_mc_enable(dev, S626_MC1_DEBI | S626_MC1_AUDIO | S626_MC1_I2C,
2178 S626_P_MC1);
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188 writel(S626_DEBI_CFG_SLAVE16 |
2189 (S626_DEBI_TOUT << S626_DEBI_CFG_TOUT_BIT) | S626_DEBI_SWAP |
2190 S626_DEBI_CFG_INTEL, dev->mmio + S626_P_DEBICFG);
2191
2192
2193 writel(S626_DEBI_PAGE_DISABLE, dev->mmio + S626_P_DEBIPAGE);
2194
2195
2196 writel(S626_GPIO_BASE | S626_GPIO1_HI, dev->mmio + S626_P_GPIO);
2197
2198
2199 devpriv->i2c_adrs = 0xA0;
2200
2201
2202
2203
2204
2205 writel(S626_I2C_CLKSEL | S626_I2C_ABORT,
2206 dev->mmio + S626_P_I2CSTAT);
2207 s626_mc_enable(dev, S626_MC2_UPLD_IIC, S626_P_MC2);
2208 ret = comedi_timeout(dev, NULL, NULL, s626_i2c_handshake_eoc, 0);
2209 if (ret)
2210 return ret;
2211
2212
2213
2214
2215
2216 for (i = 0; i < 2; i++) {
2217 writel(S626_I2C_CLKSEL, dev->mmio + S626_P_I2CSTAT);
2218 s626_mc_enable(dev, S626_MC2_UPLD_IIC, S626_P_MC2);
2219 ret = comedi_timeout(dev, NULL,
2220 NULL, s626_i2c_handshake_eoc, 0);
2221 if (ret)
2222 return ret;
2223 }
2224
2225
2226
2227
2228
2229
2230
2231 writel(S626_ACON2_INIT, dev->mmio + S626_P_ACON2);
2232
2233
2234
2235
2236
2237
2238
2239 writel(S626_RSD1 | S626_SIB_A1, dev->mmio + S626_P_TSL1);
2240 writel(S626_RSD1 | S626_SIB_A1 | S626_EOS,
2241 dev->mmio + S626_P_TSL1 + 4);
2242
2243
2244 writel(S626_ACON1_ADCSTART, dev->mmio + S626_P_ACON1);
2245
2246
2247
2248
2249
2250
2251 writel((u32)devpriv->rps_buf.physical_base,
2252 dev->mmio + S626_P_RPSADDR1);
2253
2254 writel(0, dev->mmio + S626_P_RPSPAGE1);
2255
2256 writel(0, dev->mmio + S626_P_RPS1_TOUT);
2257
2258#if 0
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268 {
2269 struct comedi_subdevice *s = dev->read_subdev;
2270 u8 poll_list;
2271 u16 adc_data;
2272 u16 start_val;
2273 u16 index;
2274 unsigned int data[16];
2275
2276
2277 poll_list = S626_EOPL;
2278 s626_reset_adc(dev, &poll_list);
2279
2280
2281 s626_ai_rinsn(dev, s, NULL, data);
2282 start_val = data[0];
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294 for (index = 0; index < 500; index++) {
2295 s626_ai_rinsn(dev, s, NULL, data);
2296 adc_data = data[0];
2297 if (adc_data != start_val)
2298 break;
2299 }
2300 }
2301#endif
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312 writel(0, dev->mmio + S626_P_PCI_BT_A);
2313
2314
2315
2316
2317
2318
2319
2320 phys_buf = devpriv->ana_buf.physical_base +
2321 (S626_DAC_WDMABUF_OS * sizeof(u32));
2322 writel((u32)phys_buf, dev->mmio + S626_P_BASEA2_OUT);
2323 writel((u32)(phys_buf + sizeof(u32)),
2324 dev->mmio + S626_P_PROTA2_OUT);
2325
2326
2327
2328
2329
2330 devpriv->dac_wbuf = (u32 *)devpriv->ana_buf.logical_base +
2331 S626_DAC_WDMABUF_OS;
2332
2333
2334
2335
2336
2337
2338
2339 writel(8, dev->mmio + S626_P_PAGEA2_OUT);
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354 writel(S626_XSD2 | S626_RSD3 | S626_SIB_A2 | S626_EOS,
2355 dev->mmio + S626_VECTPORT(0));
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367 writel(S626_LF_A2, dev->mmio + S626_VECTPORT(1));
2368
2369
2370 writel(S626_ACON1_DACSTART, dev->mmio + S626_P_ACON1);
2371
2372
2373
2374
2375
2376
2377 s626_load_trim_dacs(dev);
2378 ret = s626_load_trim_dacs(dev);
2379 if (ret)
2380 return ret;
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394 for (chan = 0; chan < S626_DAC_CHANNELS; chan++) {
2395 ret = s626_set_dac(dev, chan, 0);
2396 if (ret)
2397 return ret;
2398 }
2399
2400
2401 s626_counters_init(dev);
2402
2403
2404
2405
2406
2407
2408
2409 s626_write_misc2(dev, (s626_debi_read(dev, S626_LP_RDMISC2) &
2410 S626_MISC2_BATT_ENABLE));
2411
2412
2413 s626_dio_init(dev);
2414
2415 return 0;
2416}
2417
2418static int s626_auto_attach(struct comedi_device *dev,
2419 unsigned long context_unused)
2420{
2421 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
2422 struct s626_private *devpriv;
2423 struct comedi_subdevice *s;
2424 int ret;
2425
2426 devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
2427 if (!devpriv)
2428 return -ENOMEM;
2429
2430 ret = comedi_pci_enable(dev);
2431 if (ret)
2432 return ret;
2433
2434 dev->mmio = pci_ioremap_bar(pcidev, 0);
2435 if (!dev->mmio)
2436 return -ENOMEM;
2437
2438
2439 writel(0, dev->mmio + S626_P_IER);
2440
2441
2442 writel(S626_MC1_SOFT_RESET, dev->mmio + S626_P_MC1);
2443
2444
2445
2446 ret = s626_allocate_dma_buffers(dev);
2447 if (ret)
2448 return ret;
2449
2450 if (pcidev->irq) {
2451 ret = request_irq(pcidev->irq, s626_irq_handler, IRQF_SHARED,
2452 dev->board_name, dev);
2453
2454 if (ret == 0)
2455 dev->irq = pcidev->irq;
2456 }
2457
2458 ret = comedi_alloc_subdevices(dev, 6);
2459 if (ret)
2460 return ret;
2461
2462 s = &dev->subdevices[0];
2463
2464 s->type = COMEDI_SUBD_AI;
2465 s->subdev_flags = SDF_READABLE | SDF_DIFF;
2466 s->n_chan = S626_ADC_CHANNELS;
2467 s->maxdata = 0x3fff;
2468 s->range_table = &s626_range_table;
2469 s->len_chanlist = S626_ADC_CHANNELS;
2470 s->insn_read = s626_ai_insn_read;
2471 if (dev->irq) {
2472 dev->read_subdev = s;
2473 s->subdev_flags |= SDF_CMD_READ;
2474 s->do_cmd = s626_ai_cmd;
2475 s->do_cmdtest = s626_ai_cmdtest;
2476 s->cancel = s626_ai_cancel;
2477 }
2478
2479 s = &dev->subdevices[1];
2480
2481 s->type = COMEDI_SUBD_AO;
2482 s->subdev_flags = SDF_WRITABLE | SDF_READABLE;
2483 s->n_chan = S626_DAC_CHANNELS;
2484 s->maxdata = 0x3fff;
2485 s->range_table = &range_bipolar10;
2486 s->insn_write = s626_ao_insn_write;
2487
2488 ret = comedi_alloc_subdev_readback(s);
2489 if (ret)
2490 return ret;
2491
2492 s = &dev->subdevices[2];
2493
2494 s->type = COMEDI_SUBD_DIO;
2495 s->subdev_flags = SDF_WRITABLE | SDF_READABLE;
2496 s->n_chan = 16;
2497 s->maxdata = 1;
2498 s->io_bits = 0xffff;
2499 s->private = (void *)0;
2500 s->range_table = &range_digital;
2501 s->insn_config = s626_dio_insn_config;
2502 s->insn_bits = s626_dio_insn_bits;
2503
2504 s = &dev->subdevices[3];
2505
2506 s->type = COMEDI_SUBD_DIO;
2507 s->subdev_flags = SDF_WRITABLE | SDF_READABLE;
2508 s->n_chan = 16;
2509 s->maxdata = 1;
2510 s->io_bits = 0xffff;
2511 s->private = (void *)1;
2512 s->range_table = &range_digital;
2513 s->insn_config = s626_dio_insn_config;
2514 s->insn_bits = s626_dio_insn_bits;
2515
2516 s = &dev->subdevices[4];
2517
2518 s->type = COMEDI_SUBD_DIO;
2519 s->subdev_flags = SDF_WRITABLE | SDF_READABLE;
2520 s->n_chan = 16;
2521 s->maxdata = 1;
2522 s->io_bits = 0xffff;
2523 s->private = (void *)2;
2524 s->range_table = &range_digital;
2525 s->insn_config = s626_dio_insn_config;
2526 s->insn_bits = s626_dio_insn_bits;
2527
2528 s = &dev->subdevices[5];
2529
2530 s->type = COMEDI_SUBD_COUNTER;
2531 s->subdev_flags = SDF_WRITABLE | SDF_READABLE | SDF_LSAMPL;
2532 s->n_chan = S626_ENCODER_CHANNELS;
2533 s->maxdata = 0xffffff;
2534 s->range_table = &range_unknown;
2535 s->insn_config = s626_enc_insn_config;
2536 s->insn_read = s626_enc_insn_read;
2537 s->insn_write = s626_enc_insn_write;
2538
2539 return s626_initialize(dev);
2540}
2541
2542static void s626_detach(struct comedi_device *dev)
2543{
2544 struct s626_private *devpriv = dev->private;
2545
2546 if (devpriv) {
2547
2548 devpriv->ai_cmd_running = 0;
2549
2550 if (dev->mmio) {
2551
2552
2553 writel(0, dev->mmio + S626_P_IER);
2554
2555 writel(S626_IRQ_GPIO3 | S626_IRQ_RPS1,
2556 dev->mmio + S626_P_ISR);
2557
2558
2559 s626_write_misc2(dev, 0);
2560
2561
2562 writel(S626_MC1_SHUTDOWN, dev->mmio + S626_P_MC1);
2563 writel(S626_ACON1_BASE, dev->mmio + S626_P_ACON1);
2564 }
2565 }
2566 comedi_pci_detach(dev);
2567 s626_free_dma_buffers(dev);
2568}
2569
2570static struct comedi_driver s626_driver = {
2571 .driver_name = "s626",
2572 .module = THIS_MODULE,
2573 .auto_attach = s626_auto_attach,
2574 .detach = s626_detach,
2575};
2576
2577static int s626_pci_probe(struct pci_dev *dev,
2578 const struct pci_device_id *id)
2579{
2580 return comedi_pci_auto_config(dev, &s626_driver, id->driver_data);
2581}
2582
2583
2584
2585
2586
2587
2588static const struct pci_device_id s626_pci_table[] = {
2589 { PCI_DEVICE_SUB(PCI_VENDOR_ID_PHILIPS, PCI_DEVICE_ID_PHILIPS_SAA7146,
2590 0x6000, 0x0272) },
2591 { 0 }
2592};
2593MODULE_DEVICE_TABLE(pci, s626_pci_table);
2594
2595static struct pci_driver s626_pci_driver = {
2596 .name = "s626",
2597 .id_table = s626_pci_table,
2598 .probe = s626_pci_probe,
2599 .remove = comedi_pci_auto_unconfig,
2600};
2601module_comedi_pci_driver(s626_driver, s626_pci_driver);
2602
2603MODULE_AUTHOR("Gianluca Palli <gpalli@deis.unibo.it>");
2604MODULE_DESCRIPTION("Sensoray 626 Comedi driver module");
2605MODULE_LICENSE("GPL");
2606