1 /* Watchdog Related Defines */
3 #define ADDIDATA_TIMER 0
4 #define ADDIDATA_WATCHDOG 2
7 * (*insn_config) for the timer subdevice
9 * Configures The Timer, Counter or Watchdog
10 * Data Pointer contains configuration parameters as below
11 * data[0] : 0 Configure As Timer
12 * 1 Configure As Counter
13 * 2 Configure As Watchdog
14 * data[1] : 1 Enable Interrupt
17 * data[3] : Reload Value
19 static int apci3501_config_insn_timer(struct comedi_device *dev,
20 struct comedi_subdevice *s,
21 struct comedi_insn *insn,
24 struct apci3501_private *devpriv = dev->private;
25 unsigned int ul_Command1 = 0;
27 devpriv->tsk_Current = current;
28 if (data[0] == ADDIDATA_WATCHDOG) {
30 devpriv->b_TimerSelectMode = ADDIDATA_WATCHDOG;
31 /* Disable the watchdog */
32 outl(0x0, dev->iobase + APCI3501_TIMER_CTRL_REG);
35 /* Enable TIMER int & DISABLE ALL THE OTHER int SOURCES */
36 outl(0x02, dev->iobase + APCI3501_TIMER_CTRL_REG);
38 /* disable Timer interrupt */
39 outl(0x0, dev->iobase + APCI3501_TIMER_CTRL_REG);
42 outl(data[2], dev->iobase + APCI3501_TIMER_TIMEBASE_REG);
43 outl(data[3], dev->iobase + APCI3501_TIMER_RELOAD_REG);
45 /* Set the mode (e2->e0) */
46 ul_Command1 = inl(dev->iobase + APCI3501_TIMER_CTRL_REG) | 0xFFF819E0UL;
47 outl(ul_Command1, dev->iobase + APCI3501_TIMER_CTRL_REG);
50 else if (data[0] == ADDIDATA_TIMER) {
51 /* First Stop The Timer */
52 ul_Command1 = inl(dev->iobase + APCI3501_TIMER_CTRL_REG);
53 ul_Command1 = ul_Command1 & 0xFFFFF9FEUL;
54 outl(ul_Command1, dev->iobase + APCI3501_TIMER_CTRL_REG);
55 devpriv->b_TimerSelectMode = ADDIDATA_TIMER;
57 /* Enable TIMER int & DISABLE ALL THE OTHER int SOURCES */
58 outl(0x02, dev->iobase + APCI3501_TIMER_CTRL_REG);
60 /* disable Timer interrupt */
61 outl(0x0, dev->iobase + APCI3501_TIMER_CTRL_REG);
64 outl(data[2], dev->iobase + APCI3501_TIMER_TIMEBASE_REG);
65 outl(data[3], dev->iobase + APCI3501_TIMER_RELOAD_REG);
68 ul_Command1 = inl(dev->iobase + APCI3501_TIMER_CTRL_REG);
70 (ul_Command1 & 0xFFF719E2UL) | 2UL << 13UL | 0x10UL;
71 outl(ul_Command1, dev->iobase + APCI3501_TIMER_CTRL_REG);
78 * (*insn_write) for the timer subdevice
80 * Start / Stop The Selected Timer , Counter or Watchdog
81 * Data Pointer contains configuration parameters as below
89 static int apci3501_write_insn_timer(struct comedi_device *dev,
90 struct comedi_subdevice *s,
91 struct comedi_insn *insn,
94 struct apci3501_private *devpriv = dev->private;
95 unsigned int ul_Command1 = 0;
97 if (devpriv->b_TimerSelectMode == ADDIDATA_WATCHDOG) {
100 ul_Command1 = inl(dev->iobase + APCI3501_TIMER_CTRL_REG);
101 ul_Command1 = (ul_Command1 & 0xFFFFF9FFUL) | 0x1UL;
102 /* Enable the Watchdog */
103 outl(ul_Command1, dev->iobase + APCI3501_TIMER_CTRL_REG);
104 } else if (data[1] == 0) { /* Stop The Watchdog */
105 ul_Command1 = inl(dev->iobase + APCI3501_TIMER_CTRL_REG);
106 ul_Command1 = ul_Command1 & 0xFFFFF9FEUL;
107 outl(0x0, dev->iobase + APCI3501_TIMER_CTRL_REG);
108 } else if (data[1] == 2) {
109 ul_Command1 = inl(dev->iobase + APCI3501_TIMER_CTRL_REG);
110 ul_Command1 = (ul_Command1 & 0xFFFFF9FFUL) | 0x200UL;
111 outl(ul_Command1, dev->iobase + APCI3501_TIMER_CTRL_REG);
115 if (devpriv->b_TimerSelectMode == ADDIDATA_TIMER) {
118 ul_Command1 = inl(dev->iobase + APCI3501_TIMER_CTRL_REG);
119 ul_Command1 = (ul_Command1 & 0xFFFFF9FFUL) | 0x1UL;
120 /* Enable the Timer */
121 outl(ul_Command1, dev->iobase + APCI3501_TIMER_CTRL_REG);
122 } else if (data[1] == 0) {
124 ul_Command1 = inl(dev->iobase + APCI3501_TIMER_CTRL_REG);
125 ul_Command1 = ul_Command1 & 0xFFFFF9FEUL;
126 outl(ul_Command1, dev->iobase + APCI3501_TIMER_CTRL_REG);
129 else if (data[1] == 2) {
130 /* Trigger the Timer */
131 ul_Command1 = inl(dev->iobase + APCI3501_TIMER_CTRL_REG);
132 ul_Command1 = (ul_Command1 & 0xFFFFF9FFUL) | 0x200UL;
133 outl(ul_Command1, dev->iobase + APCI3501_TIMER_CTRL_REG);
137 inl(dev->iobase + APCI3501_TIMER_STATUS_REG);
142 * (*insn_read) for the timer subdevice
144 * Read The Selected Timer, Counter or Watchdog
145 * Data Pointer contains configuration parameters as below
149 * data[1] : Timer Counter Watchdog Number
151 static int apci3501_read_insn_timer(struct comedi_device *dev,
152 struct comedi_subdevice *s,
153 struct comedi_insn *insn,
156 struct apci3501_private *devpriv = dev->private;
158 if (devpriv->b_TimerSelectMode == ADDIDATA_WATCHDOG) {
159 data[0] = inl(dev->iobase + APCI3501_TIMER_STATUS_REG) & 0x1;
160 data[1] = inl(dev->iobase + APCI3501_TIMER_SYNC_REG);
163 else if (devpriv->b_TimerSelectMode == ADDIDATA_TIMER) {
164 data[0] = inl(dev->iobase + APCI3501_TIMER_STATUS_REG) & 0x1;
165 data[1] = inl(dev->iobase + APCI3501_TIMER_SYNC_REG);
168 else if ((devpriv->b_TimerSelectMode != ADDIDATA_TIMER)
169 && (devpriv->b_TimerSelectMode != ADDIDATA_WATCHDOG)) {
170 dev_err(dev->class_dev, "Invalid subdevice.\n");