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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
|
/*
* SBE 2T3E3 synchronous serial card driver for Linux
*
* Copyright (C) 2009-2010 Krzysztof Halasa <khc@pm.waw.pl>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License
* as published by the Free Software Foundation.
*
* This code is based on a driver written by SBE Inc.
*/
#include <linux/ip.h>
#include "2t3e3.h"
#include "ctrl.h"
/* All access to registers done via the 21143 on port 0 must be
* protected via the card->bootrom_lock. */
/* private define to be used here only - must be protected by card->bootrom_lock */
#define cpld_write_nolock(channel, reg, val) \
bootrom_write((channel), CPLD_MAP_REG(reg, channel), val)
u32 cpld_read(struct channel *channel, u32 reg)
{
unsigned long flags;
u32 val;
spin_lock_irqsave(&channel->card->bootrom_lock, flags);
val = bootrom_read((channel), CPLD_MAP_REG(reg, channel));
spin_unlock_irqrestore(&channel->card->bootrom_lock, flags);
return val;
}
/****************************************
* Access via BootROM port
****************************************/
u32 bootrom_read(struct channel *channel, u32 reg)
{
unsigned long addr = channel->card->bootrom_addr;
u32 result;
/* select BootROM address */
dc_write(addr, SBE_2T3E3_21143_REG_BOOT_ROM_PROGRAMMING_ADDRESS, reg & 0x3FFFF);
/* select reading from BootROM */
dc_write(addr, SBE_2T3E3_21143_REG_BOOT_ROM_SERIAL_ROM_AND_MII_MANAGEMENT,
SBE_2T3E3_21143_VAL_READ_OPERATION |
SBE_2T3E3_21143_VAL_BOOT_ROM_SELECT);
udelay(2); /* 20 PCI cycles */
/* read from BootROM */
result = dc_read(addr, SBE_2T3E3_21143_REG_BOOT_ROM_SERIAL_ROM_AND_MII_MANAGEMENT) & 0xff;
/* reset CSR9 */
dc_write(addr, SBE_2T3E3_21143_REG_BOOT_ROM_SERIAL_ROM_AND_MII_MANAGEMENT, 0);
return result;
}
void bootrom_write(struct channel *channel, u32 reg, u32 val)
{
unsigned long addr = channel->card->bootrom_addr;
/* select BootROM address */
dc_write(addr, SBE_2T3E3_21143_REG_BOOT_ROM_PROGRAMMING_ADDRESS, reg & 0x3FFFF);
/* select writting to BootROM */
dc_write(addr, SBE_2T3E3_21143_REG_BOOT_ROM_SERIAL_ROM_AND_MII_MANAGEMENT,
SBE_2T3E3_21143_VAL_WRITE_OPERATION |
SBE_2T3E3_21143_VAL_BOOT_ROM_SELECT |
(val & 0xff));
udelay(2); /* 20 PCI cycles */
/* reset CSR9 */
dc_write(addr, SBE_2T3E3_21143_REG_BOOT_ROM_SERIAL_ROM_AND_MII_MANAGEMENT, 0);
}
/****************************************
* Access via Serial I/O port
****************************************/
static u32 serialrom_read_bit(struct channel *channel)
{
unsigned long addr = channel->card->bootrom_addr;
u32 bit;
dc_write(addr, SBE_2T3E3_21143_REG_BOOT_ROM_SERIAL_ROM_AND_MII_MANAGEMENT,
SBE_2T3E3_21143_VAL_READ_OPERATION |
SBE_2T3E3_21143_VAL_SERIAL_ROM_SELECT |
SBE_2T3E3_21143_VAL_SERIAL_ROM_CLOCK |
SBE_2T3E3_21143_VAL_SERIAL_ROM_CHIP_SELECT); /* clock high */
bit = (dc_read(addr, SBE_2T3E3_21143_REG_BOOT_ROM_SERIAL_ROM_AND_MII_MANAGEMENT) &
SBE_2T3E3_21143_VAL_SERIAL_ROM_DATA_OUT) > 0 ? 1 : 0;
dc_write(addr, SBE_2T3E3_21143_REG_BOOT_ROM_SERIAL_ROM_AND_MII_MANAGEMENT,
SBE_2T3E3_21143_VAL_READ_OPERATION |
SBE_2T3E3_21143_VAL_SERIAL_ROM_SELECT |
SBE_2T3E3_21143_VAL_SERIAL_ROM_CHIP_SELECT); /* clock low */
return bit;
}
static void serialrom_write_bit(struct channel *channel, u32 bit)
{
unsigned long addr = channel->card->bootrom_addr;
u32 lastbit = -1;
bit &= 1;
if (bit != lastbit) {
dc_write(addr, SBE_2T3E3_21143_REG_BOOT_ROM_SERIAL_ROM_AND_MII_MANAGEMENT,
SBE_2T3E3_21143_VAL_WRITE_OPERATION |
SBE_2T3E3_21143_VAL_SERIAL_ROM_SELECT |
SBE_2T3E3_21143_VAL_SERIAL_ROM_CHIP_SELECT |
(bit << 2)); /* clock low */
lastbit = bit;
}
dc_write(addr, SBE_2T3E3_21143_REG_BOOT_ROM_SERIAL_ROM_AND_MII_MANAGEMENT,
SBE_2T3E3_21143_VAL_WRITE_OPERATION |
SBE_2T3E3_21143_VAL_SERIAL_ROM_SELECT |
SBE_2T3E3_21143_VAL_SERIAL_ROM_CLOCK |
SBE_2T3E3_21143_VAL_SERIAL_ROM_CHIP_SELECT |
(bit << 2)); /* clock high */
dc_write(addr, SBE_2T3E3_21143_REG_BOOT_ROM_SERIAL_ROM_AND_MII_MANAGEMENT,
SBE_2T3E3_21143_VAL_WRITE_OPERATION |
SBE_2T3E3_21143_VAL_SERIAL_ROM_SELECT |
SBE_2T3E3_21143_VAL_SERIAL_ROM_CHIP_SELECT |
(bit << 2)); /* clock low */
}
/****************************************
* Access to SerialROM (eeprom)
****************************************/
u32 t3e3_eeprom_read_word(struct channel *channel, u32 address)
{
unsigned long addr = channel->card->bootrom_addr;
u32 i, val;
unsigned long flags;
address &= 0x3f;
spin_lock_irqsave(&channel->card->bootrom_lock, flags);
/* select correct Serial Chip */
cpld_write_nolock(channel, SBE_2T3E3_CPLD_REG_SERIAL_CHIP_SELECT,
SBE_2T3E3_CPLD_VAL_EEPROM_SELECT);
/* select reading from Serial I/O Bus */
dc_write(addr, SBE_2T3E3_21143_REG_BOOT_ROM_SERIAL_ROM_AND_MII_MANAGEMENT,
SBE_2T3E3_21143_VAL_READ_OPERATION |
SBE_2T3E3_21143_VAL_SERIAL_ROM_SELECT |
SBE_2T3E3_21143_VAL_SERIAL_ROM_CHIP_SELECT); /* clock low */
/* select read operation */
serialrom_write_bit(channel, 0);
serialrom_write_bit(channel, 1);
serialrom_write_bit(channel, 1);
serialrom_write_bit(channel, 0);
for (i = 0x20; i; i >>= 1)
serialrom_write_bit(channel, address & i ? 1 : 0);
val = 0;
for (i = 0x8000; i; i >>= 1)
val |= (serialrom_read_bit(channel) ? i : 0);
/* Reset 21143's CSR9 */
dc_write(addr, SBE_2T3E3_21143_REG_BOOT_ROM_SERIAL_ROM_AND_MII_MANAGEMENT,
SBE_2T3E3_21143_VAL_READ_OPERATION |
SBE_2T3E3_21143_VAL_SERIAL_ROM_SELECT |
SBE_2T3E3_21143_VAL_SERIAL_ROM_CHIP_SELECT); /* clock low */
dc_write(addr, SBE_2T3E3_21143_REG_BOOT_ROM_SERIAL_ROM_AND_MII_MANAGEMENT, 0);
/* Unselect Serial Chip */
cpld_write_nolock(channel, SBE_2T3E3_CPLD_REG_SERIAL_CHIP_SELECT, 0);
spin_unlock_irqrestore(&channel->card->bootrom_lock, flags);
return ntohs(val);
}
/****************************************
* Access to Framer
****************************************/
u32 exar7250_read(struct channel *channel, u32 reg)
{
u32 result;
unsigned long flags;
spin_lock_irqsave(&channel->card->bootrom_lock, flags);
result = bootrom_read(channel, cpld_reg_map[SBE_2T3E3_CPLD_REG_FRAMER_BASE_ADDRESS]
[channel->h.slot] + (t3e3_framer_reg_map[reg] << 2));
spin_unlock_irqrestore(&channel->card->bootrom_lock, flags);
return result;
}
void exar7250_write(struct channel *channel, u32 reg, u32 val)
{
unsigned long flags;
val &= 0xff;
channel->framer_regs[reg] = val;
spin_lock_irqsave(&channel->card->bootrom_lock, flags);
bootrom_write(channel, cpld_reg_map[SBE_2T3E3_CPLD_REG_FRAMER_BASE_ADDRESS]
[channel->h.slot] + (t3e3_framer_reg_map[reg] << 2), val);
spin_unlock_irqrestore(&channel->card->bootrom_lock, flags);
}
/****************************************
* Access to LIU
****************************************/
u32 exar7300_read(struct channel *channel, u32 reg)
{
unsigned long addr = channel->card->bootrom_addr, flags;
u32 i, val;
/* select correct Serial Chip */
spin_lock_irqsave(&channel->card->bootrom_lock, flags);
cpld_write_nolock(channel, SBE_2T3E3_CPLD_REG_SERIAL_CHIP_SELECT,
cpld_val_map[SBE_2T3E3_CPLD_VAL_LIU_SELECT][channel->h.slot]);
/* select reading from Serial I/O Bus */
dc_write(addr, SBE_2T3E3_21143_REG_BOOT_ROM_SERIAL_ROM_AND_MII_MANAGEMENT,
SBE_2T3E3_21143_VAL_READ_OPERATION |
SBE_2T3E3_21143_VAL_SERIAL_ROM_SELECT |
SBE_2T3E3_21143_VAL_SERIAL_ROM_CHIP_SELECT); /* clock low */
/* select read operation */
serialrom_write_bit(channel, 1);
/* Exar7300 register address is 4 bit long */
reg = t3e3_liu_reg_map[reg];
for (i = 0; i < 4; i++, reg >>= 1) /* 4 bits of SerialROM address */
serialrom_write_bit(channel, reg & 1);
for (i = 0; i < 3; i++) /* remaining 3 bits of SerialROM address */
serialrom_write_bit(channel, 0);
val = 0; /* Exar7300 register value is 5 bit long */
for (i = 0; i < 8; i++) /* 8 bits of SerialROM value */
val += (serialrom_read_bit(channel) << i);
/* Reset 21143's CSR9 */
dc_write(addr, SBE_2T3E3_21143_REG_BOOT_ROM_SERIAL_ROM_AND_MII_MANAGEMENT,
SBE_2T3E3_21143_VAL_READ_OPERATION |
SBE_2T3E3_21143_VAL_SERIAL_ROM_SELECT |
SBE_2T3E3_21143_VAL_SERIAL_ROM_CHIP_SELECT); /* clock low */
dc_write(addr, SBE_2T3E3_21143_REG_BOOT_ROM_SERIAL_ROM_AND_MII_MANAGEMENT, 0);
/* Unselect Serial Chip */
cpld_write_nolock(channel, SBE_2T3E3_CPLD_REG_SERIAL_CHIP_SELECT, 0);
spin_unlock_irqrestore(&channel->card->bootrom_lock, flags);
return val;
}
void exar7300_write(struct channel *channel, u32 reg, u32 val)
{
unsigned long addr = channel->card->bootrom_addr, flags;
u32 i;
channel->liu_regs[reg] = val;
/* select correct Serial Chip */
spin_lock_irqsave(&channel->card->bootrom_lock, flags);
cpld_write_nolock(channel, SBE_2T3E3_CPLD_REG_SERIAL_CHIP_SELECT,
cpld_val_map[SBE_2T3E3_CPLD_VAL_LIU_SELECT][channel->h.slot]);
/* select writting to Serial I/O Bus */
dc_write(addr, SBE_2T3E3_21143_REG_BOOT_ROM_SERIAL_ROM_AND_MII_MANAGEMENT,
SBE_2T3E3_21143_VAL_WRITE_OPERATION |
SBE_2T3E3_21143_VAL_SERIAL_ROM_SELECT |
SBE_2T3E3_21143_VAL_SERIAL_ROM_CHIP_SELECT); /* clock low */
/* select write operation */
serialrom_write_bit(channel, 0);
/* Exar7300 register address is 4 bit long */
reg = t3e3_liu_reg_map[reg];
for
|