aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/staging/vme/devices/vme_pio2.h
blob: d5d94c43c07409953da19e961b48fdc80c1d3fed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
#ifndef _VME_PIO2_H_
#define _VME_PIO2_H_

#define PIO2_CARDS_MAX			32

#define PIO2_VARIANT_LENGTH		5

#define PIO2_NUM_CHANNELS		32
#define PIO2_NUM_IRQS			11
#define PIO2_NUM_CNTRS			6

#define PIO2_REGS_SIZE			0x40

#define PIO2_REGS_DATA0			0x0
#define PIO2_REGS_DATA1			0x1
#define PIO2_REGS_DATA2			0x2
#define PIO2_REGS_DATA3			0x3

static const int PIO2_REGS_DATA[4] = { PIO2_REGS_DATA0, PIO2_REGS_DATA1,
					PIO2_REGS_DATA2, PIO2_REGS_DATA3 };

#define PIO2_REGS_INT_STAT0		0x8
#define PIO2_REGS_INT_STAT1		0x9
#define PIO2_REGS_INT_STAT2		0xa
#define PIO2_REGS_INT_STAT3		0xb

static const int PIO2_REGS_INT_STAT[4] = { PIO2_REGS_INT_STAT0,
					PIO2_REGS_INT_STAT1,
					PIO2_REGS_INT_STAT2,
					PIO2_REGS_INT_STAT3 };

#define PIO2_REGS_INT_STAT_CNTR		0xc
#define PIO2_REGS_INT_MASK0		0x10
#define PIO2_REGS_INT_MASK1		0x11
#define PIO2_REGS_INT_MASK2		0x12
#define PIO2_REGS_INT_MASK3		0x13
#define PIO2_REGS_INT_MASK4		0x14
#define PIO2_REGS_INT_MASK5		0x15
#define PIO2_REGS_INT_MASK6		0x16
#define PIO2_REGS_INT_MASK7		0x17

static const int PIO2_REGS_INT_MASK[8] = { PIO2_REGS_INT_MASK0,
					PIO2_REGS_INT_MASK1,
					PIO2_REGS_INT_MASK2,
					PIO2_REGS_INT_MASK3,
					PIO2_REGS_INT_MASK4,
					PIO2_REGS_INT_MASK5,
					PIO2_REGS_INT_MASK6,
					PIO2_REGS_INT_MASK7 };



#define PIO2_REGS_CTRL			0x18
#define PIO2_REGS_VME_VECTOR		0x19
#define PIO2_REGS_CNTR0			0x20
#define PIO2_REGS_CNTR1			0x22
#define PIO2_REGS_CNTR2			0x24
#define PIO2_REGS_CTRL_WRD0		0x26
#define PIO2_REGS_CNTR3			0x28
#define PIO2_REGS_CNTR4			0x2a
#define PIO2_REGS_CNTR5			0x2c
#define PIO2_REGS_CTRL_WRD1		0x2e

#define PIO2_REGS_ID			0x30


/* PIO2_REGS_DATAx (0x0 - 0x3) */

static const int PIO2_CHANNEL_BANK[32] = { 0, 0, 0, 0, 0, 0, 0, 0,
					1, 1, 1, 1, 1, 1, 1, 1,
					2, 2, 2, 2, 2, 2, 2, 2,
					3, 3, 3, 3, 3, 3, 3, 3 };

#define PIO2_CHANNEL0_BIT		(1 << 0)
#define PIO2_CHANNEL1_BIT		(1 << 1)
#define PIO2_CHANNEL2_BIT		(1 << 2)
#define PIO2_CHANNEL3_BIT		(1 << 3)
#define PIO2_CHANNEL4_BIT		(1 << 4)
#define PIO2_CHANNEL5_BIT		(1 << 5)
#define PIO2_CHANNEL6_BIT		(1 << 6)
#define PIO2_CHANNEL7_BIT		(1 << 7)
#define PIO2_CHANNEL8_BIT		(1 << 0)
#define PIO2_CHANNEL9_BIT		(1 << 1)
#define PIO2_CHANNEL10_BIT		(1 << 2)
#define PIO2_CHANNEL11_BIT		(1 << 3)
#define PIO2_CHANNEL12_BIT		(1 << 4)
#define PIO2_CHANNEL13_BIT		(1 << 5)
#define PIO2_CHANNEL14_BIT		(1 << 6)
#define PIO2_CHANNEL15_BIT		(1 << 7)
#define PIO2_CHANNEL16_BIT		(1 << 0)
#define PIO2_CHANNEL17_BIT		(1 << 1)
#define PIO2_CHANNEL18_BIT		(1 << 2)
#define PIO2_CHANNEL19_BIT		(1 << 3)
#define PIO2_CHANNEL20_BIT		(1 << 4)
#define PIO2_CHANNEL21_BIT		(1 << 5)
#define PIO2_CHANNEL22_BIT		(1 << 6)
#define PIO2_CHANNEL23_BIT		(1 << 7)
#define PIO2_CHANNEL24_BIT		(1 << 0)
#define PIO2_CHANNEL25_BIT		(1 << 1)
#define PIO2_CHANNEL26_BIT		(1 << 2)
#define PIO2_CHANNEL27_BIT		(1 << 3)
#define PIO2_CHANNEL28_BIT		(1 << 4)
#define PIO2_CHANNEL29_BIT		(1 << 5)
#define PIO2_CHANNEL30_BIT		(1 << 6)
#define PIO2_CHANNEL31_BIT		(1 << 7)

static const int PIO2_CHANNEL_BIT[32] = { PIO2_CHANNEL0_BIT, PIO2_CHANNEL1_BIT,
					PIO2_CHANNEL2_BIT, PIO2_CHANNEL3_BIT,
					PIO2_CHANNEL4_BIT, PIO2_CHANNEL5_BIT,
					PIO2_CHANNEL6_BIT, PIO2_CHANNEL7_BIT,
					PIO2_CHANNEL8_BIT, PIO2_CHANNEL9_BIT,
					PIO2_CHANNEL10_BIT, PIO2_CHANNEL11_BIT,
					PIO2_CHANNEL12_BIT, PIO2_CHANNEL13_BIT,
					PIO2_CHANNEL14_BIT, PIO2_CHANNEL15_BIT,
					PIO2_CHANNEL16_BIT, PIO2_CHANNEL17_BIT,
					PIO2_CHANNEL18_BIT, PIO2_CHANNEL19_BIT,
					PIO2_CHANNEL20_BIT, PIO2_CHANNEL21_BIT,
					PIO2_CHANNEL22_BIT, PIO2_CHANNEL23_BIT,
					PIO2_CHANNEL24_BIT, PIO2_CHANNEL25_BIT,
					PIO2_CHANNEL26_BIT, PIO2_CHANNEL27_BIT,
					PIO2_CHANNEL28_BIT, PIO2_CHANNEL29_BIT,
					PIO2_CHANNEL30_BIT, PIO2_CHANNEL31_BIT
					};

/* PIO2_REGS_INT_STAT_CNTR (0xc) */
#define PIO2_COUNTER0			(1 << 0)
#define PIO2_COUNTER1			(1 << 1)
#define PIO2_COUNTER2			(1 << 2)
#define PIO2_COUNTER3			(1 << 3)
#define PIO2_COUNTER4			(1 << 4)
#define PIO2_COUNTER5			(1 << 5)

static const int PIO2_COUNTER[6] = { PIO2_COUNTER0, PIO2_COUNTER1,
					PIO2_COUNTER2, PIO2_COUNTER3,
					PIO2_COUNTER4, PIO2_COUNTER5 };

/* PIO2_REGS_CTRL (0x18) */
#define PIO2_VME_INT_MASK		0x7
#define PIO2_LED			(1 << 6)
#define PIO2_LOOP			(1 << 7)

/* PIO2_REGS_VME_VECTOR (0x19) */
#define PIO2_VME_VECTOR_SPUR		0x0
#define PIO2_VME_VECTOR_BANK0		0x1
#define PIO2_VME_VECTOR_BANK1		0x2
#define PIO2_VME_VECTOR_BANK2		0x3
#define PIO2_VME_VECTOR_BANK3		0x4
#define PIO2_VME_VECTOR_CNTR0		0x5
#define PIO2_VME_VECTOR_CNTR1		0x6
#define PIO2_VME_VECTOR_CNTR2		0x7
#define PIO2_VME_VECTOR_CNTR3		0x8
#define PIO2_VME_VECTOR_CNTR4		0x9
#define PIO2_VME_VECTOR_CNTR5		0xa

#define PIO2_VME_VECTOR_MASK		0xf0

static const int PIO2_VECTOR_BANK[4] = { PIO2_VME_VECTOR_BANK0,
					PIO2_VME_VECTOR_BANK1,
					PIO2_VME_VECTOR_BANK2,
					PIO2_VME_VECTOR_BANK3 };

static const int PIO2_VECTOR_CNTR[6] = { PIO2_VME_VECTOR_CNTR0,
					PIO2_VME_VECTOR_CNTR1,
					PIO2_VME_VECTOR_CNTR2,
					PIO2_VME_VECTOR_CNTR3,
					PIO2_VME_VECTOR_CNTR4,
					PIO2_VME_VECTOR_CNTR5 };

/* PIO2_REGS_CNTRx (0x20 - 0x24 & 0x28 - 0x2c) */

static const int PIO2_CNTR_DATA[6] = { PIO2_REGS_CNTR0, PIO2_REGS_CNTR1,
					PIO2_REGS_CNTR2, PIO2_REGS_CNTR3,
					PIO2_REGS_CNTR4, PIO2_REGS_CNTR5 };

/* PIO2_REGS_CTRL_WRDx (0x26 & 0x2e) */

static const int PIO2_CNTR_CTRL[6] = { PIO2_REGS_CTRL_WRD0,
					PIO2_REGS_CTRL_WRD0,
					PIO2_REGS_CTRL_WRD0,
					PIO2_REGS_CTRL_WRD1,
					PIO2_REGS_CTRL_WRD1,
					PIO2_REGS_CTRL_WRD1 };

#define PIO2_CNTR_SC_DEV0		0
#define PIO2_CNTR_SC_DEV1		(1 << 6)
#define PIO2_CNTR_SC_DEV2		(2 << 6)
#define PIO2_CNTR_SC_RDBACK		(3 << 6)

static const int PIO2_CNTR_SC_DEV[6] = { PIO2_CNTR_SC_DEV0, PIO2_CNTR_SC_DEV1,
					PIO2_CNTR_SC_DEV2, PIO2_CNTR_SC_DEV0,
					PIO2_CNTR_SC_DEV1, PIO2_CNTR_SC_DEV2 };

#define PIO2_CNTR_RW_LATCH		0
#define PIO2_CNTR_RW_LSB		(1 << 4)
#define PIO2_CNTR_RW_MSB		(2 << 4)
#define PIO2_CNTR_RW_BOTH		(3 << 4)

#define PIO2_CNTR_MODE0			0
#define PIO2_CNTR_MODE1			(1 << 1)
#define PIO2_CNTR_MODE2			(2 << 1)
#define PIO2_CNTR_MODE3			(3 << 1)
#define PIO2_CNTR_MODE4			(4 << 1)
#define PIO2_CNTR_MODE5			(5 << 1)

#define PIO2_CNTR_BCD			1



enum pio2_bank_config { NOFIT, INPUT, OUTPUT, BOTH };
enum pio2_int_config { NONE = 0, LOW2HIGH = 1, HIGH2LOW = 2, EITHER = 4 };

/* Bank configuration structure */
struct pio2_io_bank {
	enum pio2_bank_config config;
	u8 value;
	enum pio2_int_config irq[8];
};

/* Counter configuration structure */
struct pio2_cntr {
	int mode;
	int count;
};

struct pio2_card {
	int id;
	int bus;
	long base;
	int irq_vector;
	int irq_level;
	char variant[6];
	int led;

	struct vme_dev *vdev;
	struct vme_resource *window;

	struct gpio_chip gc;
	struct pio2_io_bank bank[4];

	struct pio2_cntr cntr[6];
};

int pio2_cntr_reset(struct pio2_card *);

int pio2_gpio_reset(struct pio2_card *);
int pio2_gpio_init(struct pio2_card *);
void pio2_gpio_exit(struct pio2_card *);

#endif /* _VME_PIO2_H_ */

Privacy Policy