1 
   2 
   3 
   4 
   5 
   6 
   7 
   8 
   9 
  10 
  11 #ifndef _COMEDI_8254_H
  12 #define _COMEDI_8254_H
  13 
  14 #include <linux/types.h>
  15 
  16 struct comedi_device;
  17 struct comedi_insn;
  18 struct comedi_subdevice;
  19 
  20 
  21 
  22 
  23 #define I8254_OSC_BASE_10MHZ    100
  24 #define I8254_OSC_BASE_5MHZ     200
  25 #define I8254_OSC_BASE_4MHZ     250
  26 #define I8254_OSC_BASE_2MHZ     500
  27 #define I8254_OSC_BASE_1MHZ     1000
  28 #define I8254_OSC_BASE_100KHZ   10000
  29 #define I8254_OSC_BASE_10KHZ    100000
  30 #define I8254_OSC_BASE_1KHZ     1000000
  31 
  32 
  33 
  34 
  35 #define I8254_IO8               1
  36 #define I8254_IO16              2
  37 #define I8254_IO32              4
  38 
  39 
  40 
  41 
  42 #define I8254_COUNTER0_REG              0x00
  43 #define I8254_COUNTER1_REG              0x01
  44 #define I8254_COUNTER2_REG              0x02
  45 #define I8254_CTRL_REG                  0x03
  46 #define I8254_CTRL_SEL_CTR(x)           ((x) << 6)
  47 #define I8254_CTRL_READBACK(x)          (I8254_CTRL_SEL_CTR(3) | BIT(x))
  48 #define I8254_CTRL_READBACK_COUNT       I8254_CTRL_READBACK(4)
  49 #define I8254_CTRL_READBACK_STATUS      I8254_CTRL_READBACK(5)
  50 #define I8254_CTRL_READBACK_SEL_CTR(x)  (2 << (x))
  51 #define I8254_CTRL_RW(x)                (((x) & 0x3) << 4)
  52 #define I8254_CTRL_LATCH                I8254_CTRL_RW(0)
  53 #define I8254_CTRL_LSB_ONLY             I8254_CTRL_RW(1)
  54 #define I8254_CTRL_MSB_ONLY             I8254_CTRL_RW(2)
  55 #define I8254_CTRL_LSB_MSB              I8254_CTRL_RW(3)
  56 
  57 
  58 #define I8254_MAX_COUNT                 0x10000
  59 
  60 
  61 
  62 
  63 
  64 
  65 
  66 
  67 
  68 
  69 
  70 
  71 
  72 
  73 
  74 
  75 
  76 
  77 
  78 struct comedi_8254 {
  79         unsigned long iobase;
  80         void __iomem *mmio;
  81         unsigned int iosize;
  82         unsigned int regshift;
  83         unsigned int osc_base;
  84         unsigned int divisor;
  85         unsigned int divisor1;
  86         unsigned int divisor2;
  87         unsigned int next_div;
  88         unsigned int next_div1;
  89         unsigned int next_div2;
  90         unsigned int clock_src[3];
  91         unsigned int gate_src[3];
  92         bool busy[3];
  93 
  94         int (*insn_config)(struct comedi_device *dev,
  95                            struct comedi_subdevice *s,
  96                            struct comedi_insn *insn, unsigned int *data);
  97 };
  98 
  99 unsigned int comedi_8254_status(struct comedi_8254 *i8254,
 100                                 unsigned int counter);
 101 unsigned int comedi_8254_read(struct comedi_8254 *i8254, unsigned int counter);
 102 void comedi_8254_write(struct comedi_8254 *i8254,
 103                        unsigned int counter, unsigned int val);
 104 
 105 int comedi_8254_set_mode(struct comedi_8254 *i8254,
 106                          unsigned int counter, unsigned int mode);
 107 int comedi_8254_load(struct comedi_8254 *i8254,
 108                      unsigned int counter, unsigned int val, unsigned int mode);
 109 
 110 void comedi_8254_pacer_enable(struct comedi_8254 *i8254,
 111                               unsigned int counter1, unsigned int counter2,
 112                               bool enable);
 113 void comedi_8254_update_divisors(struct comedi_8254 *i8254);
 114 void comedi_8254_cascade_ns_to_timer(struct comedi_8254 *i8254,
 115                                      unsigned int *nanosec, unsigned int flags);
 116 void comedi_8254_ns_to_timer(struct comedi_8254 *i8254,
 117                              unsigned int *nanosec, unsigned int flags);
 118 
 119 void comedi_8254_set_busy(struct comedi_8254 *i8254,
 120                           unsigned int counter, bool busy);
 121 
 122 void comedi_8254_subdevice_init(struct comedi_subdevice *s,
 123                                 struct comedi_8254 *i8254);
 124 
 125 struct comedi_8254 *comedi_8254_init(unsigned long iobase,
 126                                      unsigned int osc_base,
 127                                      unsigned int iosize,
 128                                      unsigned int regshift);
 129 struct comedi_8254 *comedi_8254_mm_init(void __iomem *mmio,
 130                                         unsigned int osc_base,
 131                                         unsigned int iosize,
 132                                         unsigned int regshift);
 133 
 134 #endif