38 #include <linux/kernel.h>
39 #include <linux/module.h>
40 #include <linux/sched.h>
42 #include <linux/errno.h>
46 #include <linux/timex.h>
51 #include "../comedidev.h"
53 static u8 ReadByteFromHwPort(
unsigned long addr)
59 static void WriteByteToHwPort(
unsigned long addr,
u8 val)
64 #define C6XDIGIO_SIZE 3
69 #define C6XDIGIO_PARALLEL_DATA 0
70 #define C6XDIGIO_PARALLEL_STATUS 1
71 #define C6XDIGIO_PARALLEL_CONTROL 2
98 #define C6XDIGIO_TIME_OUT 20
100 static void C6X_pwmInit(
unsigned long baseAddr)
106 WriteByteToHwPort(baseAddr, 0x70);
107 while (((ReadByteFromHwPort(baseAddr + 1) & 0x80) == 0)
112 WriteByteToHwPort(baseAddr, 0x74);
114 while (((ReadByteFromHwPort(baseAddr + 1) & 0x80) == 0x80)
119 WriteByteToHwPort(baseAddr, 0x70);
121 while (((ReadByteFromHwPort(baseAddr + 1) & 0x80) == 0x0)
126 WriteByteToHwPort(baseAddr, 0x0);
128 while (((ReadByteFromHwPort(baseAddr + 1) & 0x80) == 0x80)
135 static void C6X_pwmOutput(
unsigned long baseAddr,
unsigned channel,
int value)
156 WriteByteToHwPort(baseAddr, ppcmd +
pwm.bits.sb0);
157 tmp = ReadByteFromHwPort(baseAddr + 1);
159 tmp = ReadByteFromHwPort(baseAddr + 1);
163 WriteByteToHwPort(baseAddr, ppcmd +
pwm.bits.sb1 + 0x4);
165 tmp = ReadByteFromHwPort(baseAddr + 1);
167 tmp = ReadByteFromHwPort(baseAddr + 1);
171 WriteByteToHwPort(baseAddr, ppcmd +
pwm.bits.sb2);
172 tmp = ReadByteFromHwPort(baseAddr + 1);
174 tmp = ReadByteFromHwPort(baseAddr + 1);
178 WriteByteToHwPort(baseAddr, ppcmd +
pwm.bits.sb3 + 0x4);
180 tmp = ReadByteFromHwPort(baseAddr + 1);
182 tmp = ReadByteFromHwPort(baseAddr + 1);
186 WriteByteToHwPort(baseAddr, ppcmd +
pwm.bits.sb4);
187 tmp = ReadByteFromHwPort(baseAddr + 1);
189 tmp = ReadByteFromHwPort(baseAddr + 1);
193 WriteByteToHwPort(baseAddr, 0x0);
195 tmp = ReadByteFromHwPort(baseAddr + 1);
197 tmp = ReadByteFromHwPort(baseAddr + 1);
203 static int C6X_encInput(
unsigned long baseAddr,
unsigned channel)
218 WriteByteToHwPort(baseAddr, ppcmd);
219 tmp = ReadByteFromHwPort(baseAddr + 1);
221 tmp = ReadByteFromHwPort(baseAddr + 1);
225 enc.bits.sb0 = ((ReadByteFromHwPort(baseAddr + 1) >> 3) & 0x7);
226 WriteByteToHwPort(baseAddr, ppcmd + 0x4);
228 tmp = ReadByteFromHwPort(baseAddr + 1);
230 tmp = ReadByteFromHwPort(baseAddr + 1);
233 enc.bits.sb1 = ((ReadByteFromHwPort(baseAddr + 1) >> 3) & 0x7);
234 WriteByteToHwPort(baseAddr, ppcmd);
236 tmp = ReadByteFromHwPort(baseAddr + 1);
238 tmp = ReadByteFromHwPort(baseAddr + 1);
241 enc.bits.sb2 = ((ReadByteFromHwPort(baseAddr + 1) >> 3) & 0x7);
242 WriteByteToHwPort(baseAddr, ppcmd + 0x4);
244 tmp = ReadByteFromHwPort(baseAddr + 1);
246 tmp = ReadByteFromHwPort(baseAddr + 1);
249 enc.bits.sb3 = ((ReadByteFromHwPort(baseAddr + 1) >> 3) & 0x7);
250 WriteByteToHwPort(baseAddr, ppcmd);
252 tmp = ReadByteFromHwPort(baseAddr + 1);
254 tmp = ReadByteFromHwPort(baseAddr + 1);
257 enc.bits.sb4 = ((ReadByteFromHwPort(baseAddr + 1) >> 3) & 0x7);
258 WriteByteToHwPort(baseAddr, ppcmd + 0x4);
260 tmp = ReadByteFromHwPort(baseAddr + 1);
262 tmp = ReadByteFromHwPort(baseAddr + 1);
265 enc.bits.sb5 = ((ReadByteFromHwPort(baseAddr + 1) >> 3) & 0x7);
266 WriteByteToHwPort(baseAddr, ppcmd);
268 tmp = ReadByteFromHwPort(baseAddr + 1);
270 tmp = ReadByteFromHwPort(baseAddr + 1);
273 enc.bits.sb6 = ((ReadByteFromHwPort(baseAddr + 1) >> 3) & 0x7);
274 WriteByteToHwPort(baseAddr, ppcmd + 0x4);
276 tmp = ReadByteFromHwPort(baseAddr + 1);
278 tmp = ReadByteFromHwPort(baseAddr + 1);
281 enc.bits.sb7 = ((ReadByteFromHwPort(baseAddr + 1) >> 3) & 0x7);
282 WriteByteToHwPort(baseAddr, ppcmd);
284 tmp = ReadByteFromHwPort(baseAddr + 1);
286 tmp = ReadByteFromHwPort(baseAddr + 1);
290 WriteByteToHwPort(baseAddr, 0x0);
292 tmp = ReadByteFromHwPort(baseAddr + 1);
294 tmp = ReadByteFromHwPort(baseAddr + 1);
298 return enc.value ^ 0x800000;
301 static void C6X_encResetAll(
unsigned long baseAddr)
303 unsigned timeout = 0;
307 WriteByteToHwPort(baseAddr, 0x68);
308 while (((ReadByteFromHwPort(baseAddr + 1) & 0x80) == 0)
312 WriteByteToHwPort(baseAddr, 0x6C);
314 while (((ReadByteFromHwPort(baseAddr + 1) & 0x80) == 0x80)
318 WriteByteToHwPort(baseAddr, 0x68);
320 while (((ReadByteFromHwPort(baseAddr + 1) & 0x80) == 0x0)
324 WriteByteToHwPort(baseAddr, 0x0);
326 while (((ReadByteFromHwPort(baseAddr + 1) & 0x80) == 0x80)
349 for (i = 0; i < insn->
n; i++) {
350 C6X_pwmOutput(dev->
iobase, chan, data[i]);
384 for (n = 0; n < insn->
n; n++)
385 data[n] = (C6X_encInput(dev->
iobase, chan) & 0xffffff);
396 C6X_encResetAll(dev->
iobase);
408 {.id =
"PNP0400", .driver_data = 0},
410 {.id =
"PNP0401", .driver_data = 0},
414 static struct pnp_driver c6xdigio_pnp_driver = {
416 .id_table = c6xdigio_pnp_tbl,
499 .driver_name =
"c6xdigio",
501 .attach = c6xdigio_attach,
502 .detach = c6xdigio_detach,