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