Import 2.1.77
[davej-history.git] / drivers / block / paride / on20.c
blobc9b3fa35bc7dd08e2935609162aa9eb32f7e7ffc
1 /*
2 on20.c (c) 1996 Grant R. Guenther <grant@torque.net>
3 Under the terms of the GNU public license.
5 on20.c is a low-level protocol driver for the
6 Onspec 90c20 parallel to IDE adapter.
7 */
9 #define ON20_VERSION "1.0"
11 #include <linux/module.h>
12 #include <linux/delay.h>
13 #include <linux/kernel.h>
14 #include <linux/types.h>
15 #include <asm/io.h>
17 #include "paride.h"
19 #define op(f) w2(4);w0(f);w2(5);w2(0xd);w2(5);w2(0xd);w2(5);w2(4);
20 #define vl(v) w2(4);w0(v);w2(5);w2(7);w2(5);w2(4);
22 #define j44(a,b) (((a>>4)&0x0f)|(b&0xf0))
24 /* cont = 0 - access the IDE register file
25 cont = 1 - access the IDE command set
28 static int on20_read_regr( PIA *pi, int cont, int regr )
30 { int h,l, r ;
32 r = (regr<<2) + 1 + cont;
34 op(1); vl(r); op(0);
36 switch (pi->mode) {
38 case 0: w2(4); w2(6); l = r1();
39 w2(4); w2(6); h = r1();
40 w2(4); w2(6); w2(4); w2(6); w2(4);
41 return j44(l,h);
43 case 1: w2(4); w2(0x26); r = r0();
44 w2(4); w2(0x26); w2(4);
45 return r;
48 return -1;
51 static void on20_write_regr( PIA *pi, int cont, int regr, int val )
53 { int r;
55 r = (regr<<2) + 1 + cont;
57 op(1); vl(r);
58 op(0); vl(val);
59 op(0); vl(val);
62 static void on20_connect ( PIA *pi)
64 { pi->saved_r0 = r0();
65 pi->saved_r2 = r2();
67 w2(4);w0(0);w2(0xc);w2(4);w2(6);w2(4);w2(6);w2(4);
68 if (pi->mode) { op(2); vl(8); op(2); vl(9); }
69 else { op(2); vl(0); op(2); vl(8); }
72 static void on20_disconnect ( PIA *pi )
74 { w2(4);w0(7);w2(4);w2(0xc);w2(4);
75 w0(pi->saved_r0);
76 w2(pi->saved_r2);
79 static void on20_read_block( PIA *pi, char * buf, int count )
81 { int k, l, h;
83 op(1); vl(1); op(0);
85 for (k=0;k<count;k++)
86 if (pi->mode) {
87 w2(4); w2(0x26); buf[k] = r0();
88 } else {
89 w2(6); l = r1(); w2(4);
90 w2(6); h = r1(); w2(4);
91 buf[k] = j44(l,h);
93 w2(4);
96 static void on20_write_block( PIA *pi, char * buf, int count )
98 { int k;
100 op(1); vl(1); op(0);
102 for (k=0;k<count;k++) { w2(5); w0(buf[k]); w2(7); }
103 w2(4);
106 static void on20_log_adapter( PIA *pi, char * scratch, int verbose )
108 { char *mode_string[2] = {"4-bit","8-bit"};
110 printk("%s: on20 %s, OnSpec 90c20 at 0x%x, ",
111 pi->device,ON20_VERSION,pi->port);
112 printk("mode %d (%s), delay %d\n",pi->mode,
113 mode_string[pi->mode],pi->delay);
117 static void on20_inc_use ( void )
119 { MOD_INC_USE_COUNT;
122 static void on20_dec_use ( void )
124 { MOD_DEC_USE_COUNT;
127 struct pi_protocol on20 = {"on20",0,2,2,1,1,
128 on20_write_regr,
129 on20_read_regr,
130 on20_write_block,
131 on20_read_block,
132 on20_connect,
133 on20_disconnect,
137 on20_log_adapter,
138 on20_inc_use,
139 on20_dec_use
143 #ifdef MODULE
145 int init_module(void)
147 { return pi_register( &on20 ) - 1;
150 void cleanup_module(void)
152 { pi_unregister( &on20 );
155 #endif
157 /* end of on20.c */