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
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
|
/*
ppc6lnx.c (c) 2001 Micro Solutions Inc.
Released under the terms of the GNU General Public license
ppc6lnx.c is a par of the protocol driver for the Micro Solutions
"BACKPACK" parallel port IDE adapter
(Works on Series 6 drives)
*/
//***************************************************************************
// PPC 6 Code in C sanitized for LINUX
// Original x86 ASM by Ron, Converted to C by Clive
//***************************************************************************
// 60772 Commands
#define ACCESS_REG 0x00
#define ACCESS_PORT 0x40
#define ACCESS_READ 0x00
#define ACCESS_WRITE 0x20
// 60772 Command Prefix
#define CMD_PREFIX_SET 0xe0 // Special command that modifies the next command's operation
#define CMD_PREFIX_RESET 0xc0 // Resets current cmd modifier reg bits
#define PREFIX_IO16 0x01 // perform 16-bit wide I/O
#define PREFIX_FASTWR 0x04 // enable PPC mode fast-write
#define PREFIX_BLK 0x08 // enable block transfer mode
// 60772 Registers
#define REG_STATUS 0x00 // status register
#define STATUS_IRQA 0x01 // Peripheral IRQA line
#define STATUS_EEPROM_DO 0x40 // Serial EEPROM data bit
#define REG_VERSION 0x01 // PPC version register (read)
#define REG_HWCFG 0x02 // Hardware Config register
#define REG_RAMSIZE 0x03 // Size of RAM Buffer
#define RAMSIZE_128K 0x02
#define REG_EEPROM 0x06 // EEPROM control register
#define EEPROM_SK 0x01 // eeprom SK bit
#define EEPROM_DI 0x02 // eeprom DI bit
#define EEPROM_CS 0x04 // eeprom CS bit
#define EEPROM_EN 0x08 // eeprom output enable
#define REG_BLKSIZE 0x08 // Block transfer len (24 bit)
//***************************************************************************
// ppc_flags
#define fifo_wait 0x10
//***************************************************************************
// DONT CHANGE THESE LEST YOU BREAK EVERYTHING - BIT FIELD DEPENDENCIES
#define PPCMODE_UNI_SW 0
#define PPCMODE_UNI_FW 1
#define PPCMODE_BI_SW 2
#define PPCMODE_BI_FW 3
#define PPCMODE_EPP_BYTE 4
#define PPCMODE_EPP_WORD 5
#define PPCMODE_EPP_DWORD 6
//***************************************************************************
static int ppc6_select(struct pi_adapter *pi);
static void ppc6_deselect(struct pi_adapter *pi);
static void ppc6_send_cmd(struct pi_adapter *pi, u8 cmd);
static void ppc6_wr_data_byte(struct pi_adapter *pi, u8 data);
static u8 ppc6_rd_data_byte(struct pi_adapter *pi);
static void ppc6_rd_data_blk(struct pi_adapter *pi, u8 *data, long count);
static void ppc6_wait_for_fifo(struct pi_adapter *pi);
static void ppc6_wr_data_blk(struct pi_adapter *pi, u8 *data, long count);
static void ppc6_wr_extout(struct pi_adapter *pi, u8 regdata);
static int ppc6_open(struct pi_adapter *pi);
//***************************************************************************
int mode_map[] = { PPCMODE_UNI_FW, PPCMODE_BI_FW, PPCMODE_EPP_BYTE,
PPCMODE_EPP_WORD, PPCMODE_EPP_DWORD };
static int ppc6_select(struct pi_adapter *pi)
{
u8 i, j, k;
pi->saved_r0 = parport_read_data(pi->pardev->port);
pi->saved_r2 = parport_read_control(pi->pardev->port) & 0x5F; // readback ctrl
parport_frob_control(pi->pardev->port, PARPORT_CONTROL_SELECT, PARPORT_CONTROL_SELECT);
if (pi->saved_r0 == 'b')
parport_write_data(pi->pardev->port, 'x');
parport_write_data(pi->pardev->port, 'b');
parport_write_data(pi->pardev->port, 'p');
parport_write_data(pi->pardev->port, pi->unit);
parport_write_data(pi->pardev->port, ~pi->unit);
parport_frob_control(pi->pardev->port, PARPORT_CONTROL_SELECT, 0);
parport_write_control(pi->pardev->port, PARPORT_CONTROL_INIT);
i = mode_map[pi->mode] & 0x0C;
if (i == 0)
i = (mode_map[pi->mode] & 2) | 1;
parport_write_data(pi->pardev->port, i);
parport_frob_control(pi->pardev->port, PARPORT_CONTROL_SELECT, PARPORT_CONTROL_SELECT);
// DELAY
parport_frob_control(pi->pardev->port, PARPORT_CONTROL_AUTOFD, PARPORT_CONTROL_AUTOFD);
j = ((i & 0x08) << 4) | ((i & 0x07) << 3);
k = parport_read_status(pi->pardev->port) & 0xB8;
if (j == k)
{
parport_frob_control(pi->pardev->port, PARPORT_CONTROL_AUTOFD, 0);
k = (parport_read_status(pi->pardev->port) & 0xB8) ^ 0xB8;
if (j == k)
{
if (i & 4) // EPP
parport_frob_control(pi->pardev->port,
PARPORT_CONTROL_SELECT | PARPORT_CONTROL_INIT, 0);
else // PPC/ECP
parport_frob_control(pi->pardev->port,
PARPORT_CONTROL_SELECT, 0);
return(1);
}
}
parport_write_control(pi->pardev->port, pi->saved_r2);
parport_write_data(pi->pardev->port, pi->saved_r0);
return(0); // FAIL
}
//***************************************************************************
static void ppc6_deselect(struct pi_adapter *pi)
{
if (mode_map[pi->mode] & 4) // EPP
parport_frob_control(pi->pardev->port,
PARPORT_CONTROL_INIT, PARPORT_CONTROL_INIT);
else // PPC/ECP
parport_frob_control(pi->pardev->port,
PARPORT_CONTROL_SELECT, PARPORT_CONTROL_SELECT);
parport_write_data(pi->pardev->port, pi->saved_r0);
parport_write_control(pi->pardev->port, (pi->saved_r2 | PARPORT_CONTROL_SELECT));
parport_write_control(pi->pardev->port, pi->saved_r2);
}
//***************************************************************************
static void ppc6_send_cmd(struct pi_adapter *pi, u8 cmd)
{
switch (mode_map[pi->mode])
{
case PPCMODE_UNI_SW :
case PPCMODE_UNI_FW :
case PPCMODE_BI_SW :
case PPCMODE_BI_FW :
{
parport_write_data(pi->pardev->port, cmd);
parport_frob_control(pi->pardev->port, 0, PARPORT_CONTROL_AUTOFD);
break;
}
case PPCMODE_EPP_BYTE :
case PPCMODE_EPP_WORD :
case PPCMODE_EPP_DWORD :
{
pi->pardev->port->ops->epp_write_addr(pi->pardev->port, &cmd, 1, 0);
break;
}
}
}
//***************************************************************************
static void ppc6_wr_data_byte(struct pi_adapter *pi, u8 data)
{
switch (mode_map[pi->mode])
{
case PPCMODE_UNI_SW :
case PPCMODE_UNI_FW :
case PPCMODE_BI_SW :
case PPCMODE_BI_FW :
{
parport_write_data(pi->pardev->port, data);
parport_frob_control(pi->pardev->port, 0, PARPORT_CONTROL_INIT);
break;
}
case PPCMODE_EPP_BYTE :
case PPCMODE_EPP_WORD :
case PPCMODE_EPP_DWORD :
{
pi->pardev->port->ops->epp_write_data(pi->pardev->port, &data, 1, 0);
break;
}
}
}
//***************************************************************************
static u8 ppc6_rd_data_byte(struct pi_adapter *pi)
{
u8 data = 0;
switch (mode_map[pi->mode])
{
case PPCMODE_UNI_SW :
case PPCMODE_UNI_FW :
{
parport_frob_control(pi->pardev->port,
PARPORT_CONTROL_STROBE, PARPORT_CONTROL_INIT);
// DELAY
data = parport_read_status(pi->pardev->port);
data = ((data & 0x80) >> 1) | ((data & 0x38) >> 3);
parport_frob_control(pi->pardev->port,
PARPORT_CONTROL_STROBE, PARPORT_CONTROL_STROBE);
// DELAY
data |= parport_read_status(pi->pardev->port) & 0xB8;
break;
}
case PPCMODE_BI_SW :
case PPCMODE_BI_FW :
{
parport_data_reverse(pi->pardev->port);
parport_frob_control(pi->pardev->port, PARPORT_CONTROL_STROBE,
PARPORT_CONTROL_STROBE | PARPORT_CONTROL_INIT);
data = parport_read_data(pi->pardev->port);
parport_frob_control(pi->pardev->port, PARPORT_CONTROL_STROBE, 0);
parport_data_forward(pi->pardev->port);
break;
}
case PPCMODE_EPP_BYTE :
case PPCMODE_EPP_WORD :
case PPCMODE_EPP_DWORD :
{
pi->pardev->port->ops->epp_read_data(pi->pardev->port, &data, 1, 0);
break;
}
}
return(data);
}
//***************************************************************************
static void ppc6_rd_data_blk(struct pi_adapter *pi, u8 *data, long count)
{
switch (mode_map[pi->mode])
{
case PPCMODE_UNI_SW :
case PPCMODE_UNI_FW :
{
while(count)
{
u8 d;
parport_frob_control(pi->pardev->port,
PARPORT_CONTROL_STROBE, PARPORT_CONTROL_INIT);
// DELAY
d = parport_read_status(pi->pardev->port);
d = ((d & 0x80) >> 1) | ((d & 0x38) >> 3);
parport_frob_control(pi->pardev->port,
PARPORT_CONTROL_STROBE, PARPORT_CONTROL_STROBE);
// DELAY
d |= parport_read_status(pi->pardev->port) & 0xB8;
*data++ = d;
count--;
}
break;
}
case PPCMODE_BI_SW :
case PPCMODE_BI_FW :
{
parport_data_reverse(pi->pardev->port);
while(count)
{
parport_frob_control(pi->pardev->port, PARPORT_CONTROL_STROBE,
PARPORT_CONTROL_STROBE | PARPORT_CONTROL_INIT);
*data++ = parport_read_data(pi->pardev->port);
count--;
}
parport_frob_control(pi->pardev->port, PARPORT_CONTROL_STROBE, 0);
parport_data_forward(pi->pardev->port);
break;
}
case PPCMODE_EPP_BYTE :
{
// DELAY
pi->pardev->port->ops->epp_read_data(pi->pardev->port,
data, count, PARPORT_EPP_FAST_8);
break;
}
case PPCMODE_EPP_WORD :
{
// DELAY
pi->pardev->port->ops->epp_read_data(pi->pardev->port,
data, count, PARPORT_EPP_FAST_16);
break;
}
case PPCMODE_EPP_DWORD :
{
// DELAY
pi->pardev->port->ops->epp_read_data(pi->pardev->port,
data, count, PARPORT_EPP_FAST_32);
break;
}
}
}
//***************************************************************************
static void ppc6_wait_for_fifo(struct pi_adapter *pi)
{
int i;
if (pi->private & fifo_wait)
{
for(i=0; i<20; i++)
parport_read_status(pi->pardev->port);
}
}
//***************************************************************************
static void ppc6_wr_data_blk(struct pi_adapter *pi, u8 *data, long count)
{
switch (mode_map[pi->mode])
{
case PPCMODE_UNI_SW :
case PPCMODE_BI_SW :
{
while(count--)
{
parport_write_data(pi->pardev->port, *data++);
parport_frob_control(pi->pardev->port, 0, PARPORT_CONTROL_INIT);
}
break;
}
case PPCMODE_UNI_FW :
case PPCMODE_BI_FW :
{
u8 this, last;
ppc6_send_cmd(pi, CMD_PREFIX_SET | PREFIX_FASTWR);
parport_frob_control(pi->pardev->port,
PARPORT_CONTROL_STROBE, PARPORT_CONTROL_STROBE);
last = *data;
parport_write_data(pi->pardev->port, last);
while(count)
{
this = *data++;
count--;
if (this == last)
{
parport_frob_control(pi->pardev->port,
0, PARPORT_CONTROL_INIT);
}
else
{
parport_write_data(pi->pardev->port, this);
last = this;
}
}
parport_frob_control(pi->pardev->port, PARPORT_CONTROL_STROBE, 0);
ppc6_send_cmd(pi, CMD_PREFIX_RESET | PREFIX_FASTWR);
break;
}
case PPCMODE_EPP_BYTE :
{
pi->pardev->port->ops->epp_write_data(pi->pardev->port,
data, count, PARPORT_EPP_FAST_8);
ppc6_wait_for_fifo(pi);
break;
}
case PPCMODE_EPP_WORD :
{
pi->pardev->port->ops->epp_write_data(pi->pardev->port,
data, count, PARPORT_EPP_FAST_16);
ppc6_wait_for_fifo(pi);
break;
}
case PPCMODE_EPP_DWORD :
{
pi->pardev->port->ops->epp_write_data(pi->pardev->port,
data, count, PARPORT_EPP_FAST_32);
ppc6_wait_for_fifo(pi);
break;
}
}
}
//***************************************************************************
static void ppc6_wr_extout(struct pi_adapter *pi, u8 regdata)
{
ppc6_send_cmd(pi, REG_VERSION | ACCESS_REG | ACCESS_WRITE);
ppc6_wr_data_byte(pi, (u8)((regdata & 0x03) << 6));
}
//***************************************************************************
static int ppc6_open(struct pi_adapter *pi)
{
int ret;
ret = ppc6_select(pi);
if (ret == 0)
return(ret);
pi->private = 0;
ppc6_send_cmd(pi, ACCESS_REG | ACCESS_WRITE | REG_RAMSIZE);
ppc6_wr_data_byte(pi, RAMSIZE_128K);
ppc6_send_cmd(pi, ACCESS_REG | ACCESS_READ | REG_VERSION);
if ((ppc6_rd_data_byte(pi) & 0x3F) == 0x0C)
pi->private |= fifo_wait;
return(ret);
}
//***************************************************************************
|