68 #include <linux/kernel.h>
69 #include <linux/types.h>
71 #include "../comedidev.h"
76 #define PCI_VENDOR_ID_S626 0x1131
77 #define PCI_DEVICE_ID_S626 0x7146
78 #define PCI_SUBVENDOR_ID_S626 0x6000
79 #define PCI_SUBDEVICE_ID_S626 0x0272
164 #define devpriv ((struct s626_private *)dev->private)
165 #define diopriv ((struct dio_private *)s->private)
188 #define encpriv ((struct enc_private *)(dev->subdevices+5)->private)
191 #define INDXMASK(C) (1 << (((C) > 2) ? ((C) * 2 - 1) : ((C) * 2 + 4)))
192 #define OVERMASK(C) (1 << (((C) > 2) ? ((C) * 2 + 5) : ((C) * 2 + 10)))
193 #define EVBITS(C) { 0, OVERMASK(C), INDXMASK(C), OVERMASK(C) | INDXMASK(C) }
200 #define MC_ENABLE(REGADRS, CTRLWORD) writel(((uint32_t)(CTRLWORD) << 16) | (uint32_t)(CTRLWORD), devpriv->base_addr+(REGADRS))
202 #define MC_DISABLE(REGADRS, CTRLWORD) writel((uint32_t)(CTRLWORD) << 16 , devpriv->base_addr+(REGADRS))
204 #define MC_TEST(REGADRS, CTRLWORD) ((readl(devpriv->base_addr+(REGADRS)) & CTRLWORD) != 0)
208 #define WR7146(REGARDS, CTRLWORD) writel(CTRLWORD, devpriv->base_addr+(REGARDS))
212 #define RR7146(REGARDS) readl(devpriv->base_addr+(REGARDS))
214 #define BUGFIX_STREG(REGADRS) (REGADRS - 4)
217 #define VECTPORT(VECTNUM) (P_TSL2 + ((VECTNUM) << 2))
218 #define SETVECT(VECTNUM, VECTVAL) WR7146(VECTPORT(VECTNUM), (VECTVAL))
221 #define I2C_B2(ATTR, VAL) (((ATTR) << 6) | ((VAL) << 24))
222 #define I2C_B1(ATTR, VAL) (((ATTR) << 4) | ((VAL) << 16))
223 #define I2C_B0(ATTR, VAL) (((ATTR) << 2) | ((VAL) << 8))
363 #define VECT0 (XSD2 | RSD3 | SIB_A2)
367 static uint8_t trimchan[] = { 10, 9, 8, 3, 2, 7, 6, 1, 0, 5, 4 };
370 static uint8_t trimadrs[] = { 0x40, 0x41, 0x42, 0x50, 0x51, 0x52, 0x53, 0x60, 0x61, 0x62, 0x63 };
504 signmask = 1 << chan;
525 WSImage = (chan & 2) ?
WS1 :
WS2;
542 SendDAC(dev, 0x0F000000
562 chan = (
uint32_t) trimchan[LogicalChan];
597 WriteTrimDAC(dev, i, I2Cread(dev, trimadrs[i]));
629 DEBIreplace(dev, k->
MyCRB,
643 static unsigned int s626_ai_reg_to_uint(
int data)
645 unsigned int tempdata;
647 tempdata = (data >> 18);
648 if (tempdata & 0x2000)
651 tempdata += (1 << 13);
660 static int s626_dio_set_irq(
struct comedi_device *dev,
unsigned int chan)
668 bitmask = 1 << (chan - (16 *
group));
671 status = DEBIread(dev,
673 group)->private)->RDEdgSel);
676 group)->private)->WREdgSel,
680 status = DEBIread(dev,
682 group)->private)->RDIntSel);
685 group)->private)->WRIntSel,
692 status = DEBIread(dev,
694 group)->private)->RDCapSel);
697 group)->private)->WRCapSel,
703 static int s626_dio_reset_irq(
struct comedi_device *dev,
unsigned int group,
712 group)->private)->WRCapSel, mask);
728 group)->private)->WRCapSel,
770 cmd = &(s->
async->cmd);
779 for (i = 0; i < (s->
async->cmd.chanlist_len); i++) {
782 tempdata = s626_ai_reg_to_uint((
int)*readaddr);
787 if (cfc_write_to_buffer(s, tempdata) == 0)
789 (
"s626_irq_handler: cfc_write_to_buffer error!\n");
797 if (
devpriv->ai_sample_count <= 0) {
818 cmd = &(s->
async->cmd);
825 irqbit = DEBIread(dev,
834 s626_dio_reset_irq(dev, group, irqbit);
845 s626_dio_set_irq(dev,
862 s626_dio_set_irq(dev,
884 if (
devpriv->ai_convert_count >
886 s626_dio_set_irq(dev,
929 if (
devpriv->ai_convert_count > 0) {
931 if (
devpriv->ai_convert_count == 0)
962 spin_unlock_irqrestore(&dev->
spinlock, flags);
1071 (
unsigned long)
devpriv->RPSBuf.LogicalBase);
1105 if (*ppl++ &
EOPL) {
1145 if (
devpriv->ai_cmd_running == 1) {
1212 AdcSpec = (chan << 8) | (GSEL_BIPOLAR10V);
1215 DEBIwrite(dev,
LP_GSEL, AdcSpec);
1218 DEBIwrite(dev,
LP_ISEL, AdcSpec);
1220 for (n = 0; n < insn->
n; n++) {
1321 static int s626_ns_to_timer(
int *nanosec,
int round_mode)
1327 switch (round_mode) {
1330 divider = (*nanosec + base / 2) / base;
1333 divider = (*nanosec) / base;
1336 divider = (*nanosec + base - 1) / base;
1340 *nanosec = base * divider;
1361 Preload(dev, k, tick);
1374 SetLatchSource(dev, k, valueSrclatch);
1387 if (
devpriv->ai_cmd_running) {
1399 s626_dio_clear_irq(dev);
1409 if (dev->
irq == 0) {
1411 "s626_ai_cmd: cannot run command without an irq");
1415 s626_ai_load_polllist(ppl, cmd);
1417 devpriv->ai_convert_count = 0;
1429 s626_timer_load(dev, k, tick);
1449 s626_timer_load(dev, k, tick);
1492 s->
async->inttrig = s626_ai_inttrig;
1510 err |= cfc_check_trigger_src(&cmd->
start_src,
1524 err |= cfc_check_trigger_is_unique(cmd->
start_src);
1526 err |= cfc_check_trigger_is_unique(cmd->
convert_src);
1527 err |= cfc_check_trigger_is_unique(cmd->
stop_src);
1555 #define MAX_SPEED 200000
1556 #define MIN_SPEED 2000000000
1665 for (i = 0; i < insn->
n; i++) {
1668 dacdata -= (0x1fff);
1670 SetDAC(dev, chan, dacdata);
1681 for (i = 0; i < insn->
n; i++)
1704 DEBIwrite(dev,
diopriv->WRIntSel, 0);
1705 DEBIwrite(dev,
diopriv->WRCapSel, 0xFFFF);
1707 DEBIwrite(dev,
diopriv->WREdgSel, 0);
1710 DEBIwrite(dev,
diopriv->WRDOut, 0);
1733 if ((s->
io_bits & data[0]) != data[0])
1736 s->
state &= ~data[0];
1737 s->
state |= data[0] & data[1];
1743 data[1] = DEBIread(dev,
diopriv->RDDIn);
1803 Preload(dev, k, data[0]);
1805 SetLatchSource(dev, k, valueSrclatch);
1819 for (n = 0; n < insn->
n; n++)
1820 data[n] = ReadLatch(dev, k);
1833 Preload(dev, k, data[0]);
1898 cra = DEBIread(dev, k->
MyCRA);
1899 crb = DEBIread(dev, k->
MyCRB);
1935 cra = DEBIread(dev, k->
MyCRA);
1936 crb = DEBIread(dev, k->
MyCRB);
2016 if (~setup & STDMSK_INDXSRC)
2028 DEBIreplace(dev, k->
MyCRB,
2078 if (~setup & STDMSK_INDXSRC)
2089 DEBIreplace(dev, k->
MyCRA,
2099 DEBIreplace(dev, k->
MyCRB,
2107 DEBIreplace(dev, k->
MyCRB,
2145 DEBIreplace(dev, k->
MyCRB,
2178 (
devpriv->CounterIntEnabs & ~k->
2191 DEBIwrite(dev, k->
MyCRB,
2195 DEBIwrite(dev, k->
MyCRB,
2201 (
devpriv->CounterIntEnabs & ~k->
2281 cra = DEBIread(dev, k->
MyCRA);
2283 DEBIwrite(dev, k->
MyCRA, cra);
2292 DEBIwrite(dev, k->
MyCRB, crb);
2297 .GetEnable = GetEnable_A,
2298 .GetIntSrc = GetIntSrc_A,
2299 .GetLoadTrig = GetLoadTrig_A,
2300 .GetMode = GetMode_A,
2301 .PulseIndex = PulseIndex_A,
2302 .SetEnable = SetEnable_A,
2303 .SetIntSrc = SetIntSrc_A,
2304 .SetLoadTrig = SetLoadTrig_A,
2305 .SetMode = SetMode_A,
2306 .ResetCapFlags = ResetCapFlags_A,
2310 .MyEventBits =
EVBITS(0),
2312 .GetEnable = GetEnable_A,
2313 .GetIntSrc = GetIntSrc_A,
2314 .GetLoadTrig = GetLoadTrig_A,
2315 .GetMode = GetMode_A,
2316 .PulseIndex = PulseIndex_A,
2317 .SetEnable = SetEnable_A,
2318 .SetIntSrc = SetIntSrc_A,
2319 .SetLoadTrig = SetLoadTrig_A,
2320 .SetMode = SetMode_A,
2321 .ResetCapFlags = ResetCapFlags_A,
2325 .MyEventBits =
EVBITS(1),
2327 .GetEnable = GetEnable_A,
2328 .GetIntSrc = GetIntSrc_A,
2329 .GetLoadTrig = GetLoadTrig_A,
2330 .GetMode = GetMode_A,
2331 .PulseIndex = PulseIndex_A,
2332 .SetEnable = SetEnable_A,
2333 .SetIntSrc = SetIntSrc_A,
2334 .SetLoadTrig = SetLoadTrig_A,
2335 .SetMode = SetMode_A,
2336 .ResetCapFlags = ResetCapFlags_A,
2340 .MyEventBits =
EVBITS(2),
2342 .GetEnable = GetEnable_B,
2343 .GetIntSrc = GetIntSrc_B,
2344 .GetLoadTrig = GetLoadTrig_B,
2345 .GetMode = GetMode_B,
2346 .PulseIndex = PulseIndex_B,
2347 .SetEnable = SetEnable_B,
2348 .SetIntSrc = SetIntSrc_B,
2349 .SetLoadTrig = SetLoadTrig_B,
2350 .SetMode = SetMode_B,
2351 .ResetCapFlags = ResetCapFlags_B,
2355 .MyEventBits =
EVBITS(3),
2357 .GetEnable = GetEnable_B,
2358 .GetIntSrc = GetIntSrc_B,
2359 .GetLoadTrig = GetLoadTrig_B,
2360 .GetMode = GetMode_B,
2361 .PulseIndex = PulseIndex_B,
2362 .SetEnable = SetEnable_B,
2363 .SetIntSrc = SetIntSrc_B,
2364 .SetLoadTrig = SetLoadTrig_B,
2365 .SetMode = SetMode_B,
2366 .ResetCapFlags = ResetCapFlags_B,
2370 .MyEventBits =
EVBITS(4),
2372 .GetEnable = GetEnable_B,
2373 .GetIntSrc = GetIntSrc_B,
2374 .GetLoadTrig = GetLoadTrig_B,
2375 .GetMode = GetMode_B,
2376 .PulseIndex = PulseIndex_B,
2377 .SetEnable = SetEnable_B,
2378 .SetIntSrc = SetIntSrc_B,
2379 .SetLoadTrig = SetLoadTrig_B,
2380 .SetMode = SetMode_B,
2381 .ResetCapFlags = ResetCapFlags_B,
2385 .MyEventBits =
EVBITS(5),
2412 static int s626_allocate_dma_buffers(
struct comedi_device *dev)
2414 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
2422 devpriv->ANABuf.PhysicalBase = appdma;
2428 devpriv->RPSBuf.PhysicalBase = appdma;
2476 for (i = 0; i < 2; i++) {
2530 unsigned int data[16];
2534 ResetADC(dev, &PollList);
2549 for (index = 0; index < 500; index++) {
2552 if (AdcData != StartVal)
2576 pPhysBuf =
devpriv->ANABuf.PhysicalBase +
2647 SetDAC(dev, chan, 0);
2673 comedi_set_hw_dev(dev, &pcidev->
dev);
2676 if (alloc_private(dev,
sizeof(
struct s626_private)) < 0)
2697 ret = s626_allocate_dma_buffers(dev);
2727 s->
cancel = s626_ai_cancel;
2780 s->
private = enc_private_data;
2787 s626_initialize(dev);
2796 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
2830 .driver_name =
"s626",
2832 .attach_pci = s626_attach_pci,
2833 .detach = s626_detach,
2861 .id_table = s626_pci_table,
2862 .probe = s626_pci_probe,