PageRenderTime 46ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/drivers/staging/comedi/drivers/pcl730.c

https://bitbucket.org/wisechild/galaxy-nexus
C | 183 lines | 131 code | 32 blank | 20 comment | 10 complexity | 06194e98d29da2066477768c890ad9f1 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, AGPL-1.0
  1. /*
  2. * comedi/drivers/pcl730.c
  3. * Driver for Advantech PCL-730 and clones
  4. * José Luis Sánchez
  5. */
  6. /*
  7. Driver: pcl730
  8. Description: Advantech PCL-730 (& compatibles)
  9. Author: José Luis Sánchez (jsanchezv@teleline.es)
  10. Status: untested
  11. Devices: [Advantech] PCL-730 (pcl730), [ICP] ISO-730 (iso730),
  12. [Adlink] ACL-7130 (acl7130)
  13. Interrupts are not supported.
  14. The ACL-7130 card have an 8254 timer/counter not supported by this driver.
  15. */
  16. #include "../comedidev.h"
  17. #include <linux/ioport.h>
  18. #define PCL730_SIZE 4
  19. #define ACL7130_SIZE 8
  20. #define PCL730_IDIO_LO 0 /* Isolated Digital I/O low byte (ID0-ID7) */
  21. #define PCL730_IDIO_HI 1 /* Isolated Digital I/O high byte (ID8-ID15) */
  22. #define PCL730_DIO_LO 2 /* TTL Digital I/O low byte (D0-D7) */
  23. #define PCL730_DIO_HI 3 /* TTL Digital I/O high byte (D8-D15) */
  24. static int pcl730_attach(struct comedi_device *dev,
  25. struct comedi_devconfig *it);
  26. static int pcl730_detach(struct comedi_device *dev);
  27. struct pcl730_board {
  28. const char *name; /* board name */
  29. unsigned int io_range; /* len of I/O space */
  30. };
  31. static const struct pcl730_board boardtypes[] = {
  32. {"pcl730", PCL730_SIZE,},
  33. {"iso730", PCL730_SIZE,},
  34. {"acl7130", ACL7130_SIZE,},
  35. };
  36. #define n_boardtypes (sizeof(boardtypes)/sizeof(struct pcl730_board))
  37. #define this_board ((const struct pcl730_board *)dev->board_ptr)
  38. static struct comedi_driver driver_pcl730 = {
  39. .driver_name = "pcl730",
  40. .module = THIS_MODULE,
  41. .attach = pcl730_attach,
  42. .detach = pcl730_detach,
  43. .board_name = &boardtypes[0].name,
  44. .num_names = n_boardtypes,
  45. .offset = sizeof(struct pcl730_board),
  46. };
  47. static int __init driver_pcl730_init_module(void)
  48. {
  49. return comedi_driver_register(&driver_pcl730);
  50. }
  51. static void __exit driver_pcl730_cleanup_module(void)
  52. {
  53. comedi_driver_unregister(&driver_pcl730);
  54. }
  55. module_init(driver_pcl730_init_module);
  56. module_exit(driver_pcl730_cleanup_module);
  57. static int pcl730_do_insn(struct comedi_device *dev, struct comedi_subdevice *s,
  58. struct comedi_insn *insn, unsigned int *data)
  59. {
  60. if (insn->n != 2)
  61. return -EINVAL;
  62. if (data[0]) {
  63. s->state &= ~data[0];
  64. s->state |= (data[0] & data[1]);
  65. }
  66. if (data[0] & 0x00ff)
  67. outb(s->state & 0xff,
  68. dev->iobase + ((unsigned long)s->private));
  69. if (data[0] & 0xff00)
  70. outb((s->state >> 8),
  71. dev->iobase + ((unsigned long)s->private) + 1);
  72. data[1] = s->state;
  73. return 2;
  74. }
  75. static int pcl730_di_insn(struct comedi_device *dev, struct comedi_subdevice *s,
  76. struct comedi_insn *insn, unsigned int *data)
  77. {
  78. if (insn->n != 2)
  79. return -EINVAL;
  80. data[1] = inb(dev->iobase + ((unsigned long)s->private)) |
  81. (inb(dev->iobase + ((unsigned long)s->private) + 1) << 8);
  82. return 2;
  83. }
  84. static int pcl730_attach(struct comedi_device *dev, struct comedi_devconfig *it)
  85. {
  86. struct comedi_subdevice *s;
  87. unsigned long iobase;
  88. unsigned int iorange;
  89. iobase = it->options[0];
  90. iorange = this_board->io_range;
  91. printk(KERN_INFO "comedi%d: pcl730: board=%s 0x%04lx ", dev->minor,
  92. this_board->name, iobase);
  93. if (!request_region(iobase, iorange, "pcl730")) {
  94. printk("I/O port conflict\n");
  95. return -EIO;
  96. }
  97. dev->board_name = this_board->name;
  98. dev->iobase = iobase;
  99. dev->irq = 0;
  100. if (alloc_subdevices(dev, 4) < 0)
  101. return -ENOMEM;
  102. s = dev->subdevices + 0;
  103. /* Isolated do */
  104. s->type = COMEDI_SUBD_DO;
  105. s->subdev_flags = SDF_WRITABLE;
  106. s->maxdata = 1;
  107. s->n_chan = 16;
  108. s->insn_bits = pcl730_do_insn;
  109. s->range_table = &range_digital;
  110. s->private = (void *)PCL730_IDIO_LO;
  111. s = dev->subdevices + 1;
  112. /* Isolated di */
  113. s->type = COMEDI_SUBD_DI;
  114. s->subdev_flags = SDF_READABLE;
  115. s->maxdata = 1;
  116. s->n_chan = 16;
  117. s->insn_bits = pcl730_di_insn;
  118. s->range_table = &range_digital;
  119. s->private = (void *)PCL730_IDIO_LO;
  120. s = dev->subdevices + 2;
  121. /* TTL do */
  122. s->type = COMEDI_SUBD_DO;
  123. s->subdev_flags = SDF_WRITABLE;
  124. s->maxdata = 1;
  125. s->n_chan = 16;
  126. s->insn_bits = pcl730_do_insn;
  127. s->range_table = &range_digital;
  128. s->private = (void *)PCL730_DIO_LO;
  129. s = dev->subdevices + 3;
  130. /* TTL di */
  131. s->type = COMEDI_SUBD_DI;
  132. s->subdev_flags = SDF_READABLE;
  133. s->maxdata = 1;
  134. s->n_chan = 16;
  135. s->insn_bits = pcl730_di_insn;
  136. s->range_table = &range_digital;
  137. s->private = (void *)PCL730_DIO_LO;
  138. printk(KERN_INFO "\n");
  139. return 0;
  140. }
  141. static int pcl730_detach(struct comedi_device *dev)
  142. {
  143. printk(KERN_INFO "comedi%d: pcl730: remove\n", dev->minor);
  144. if (dev->iobase)
  145. release_region(dev->iobase, this_board->io_range);
  146. return 0;
  147. }
  148. MODULE_AUTHOR("Comedi http://www.comedi.org");
  149. MODULE_DESCRIPTION("Comedi low-level driver");
  150. MODULE_LICENSE("GPL");