Full support for Ginger Console
[linux-ginger.git] / drivers / block / paride / friq.c
blob4f2ba244689b40583f03f476252b592493f751e9
1 /*
2 friq.c (c) 1998 Grant R. Guenther <grant@torque.net>
3 Under the terms of the GNU General Public License
5 friq.c is a low-level protocol driver for the Freecom "IQ"
6 parallel port IDE adapter. Early versions of this adapter
7 use the 'frpw' protocol.
9 Freecom uses this adapter in a battery powered external
10 CD-ROM drive. It is also used in LS-120 drives by
11 Maxell and Panasonic, and other devices.
13 The battery powered drive requires software support to
14 control the power to the drive. This module enables the
15 drive power when the high level driver (pcd) is loaded
16 and disables it when the module is unloaded. Note, if
17 the friq module is built in to the kernel, the power
18 will never be switched off, so other means should be
19 used to conserve battery power.
23 /* Changes:
25 1.01 GRG 1998.12.20 Added support for soft power switch
28 #define FRIQ_VERSION "1.01"
30 #include <linux/module.h>
31 #include <linux/init.h>
32 #include <linux/delay.h>
33 #include <linux/kernel.h>
34 #include <linux/types.h>
35 #include <linux/wait.h>
36 #include <asm/io.h>
38 #include "paride.h"
40 #define CMD(x) w2(4);w0(0xff);w0(0xff);w0(0x73);w0(0x73);\
41 w0(0xc9);w0(0xc9);w0(0x26);w0(0x26);w0(x);w0(x);
43 #define j44(l,h) (((l>>4)&0x0f)|(h&0xf0))
45 /* cont = 0 - access the IDE register file
46 cont = 1 - access the IDE command set
49 static int cont_map[2] = { 0x08, 0x10 };
51 static int friq_read_regr( PIA *pi, int cont, int regr )
53 { int h,l,r;
55 r = regr + cont_map[cont];
57 CMD(r);
58 w2(6); l = r1();
59 w2(4); h = r1();
60 w2(4);
62 return j44(l,h);
66 static void friq_write_regr( PIA *pi, int cont, int regr, int val)
68 { int r;
70 r = regr + cont_map[cont];
72 CMD(r);
73 w0(val);
74 w2(5);w2(7);w2(5);w2(4);
77 static void friq_read_block_int( PIA *pi, char * buf, int count, int regr )
79 { int h, l, k, ph;
81 switch(pi->mode) {
83 case 0: CMD(regr);
84 for (k=0;k<count;k++) {
85 w2(6); l = r1();
86 w2(4); h = r1();
87 buf[k] = j44(l,h);
89 w2(4);
90 break;
92 case 1: ph = 2;
93 CMD(regr+0xc0);
94 w0(0xff);
95 for (k=0;k<count;k++) {
96 w2(0xa4 + ph);
97 buf[k] = r0();
98 ph = 2 - ph;
100 w2(0xac); w2(0xa4); w2(4);
101 break;
103 case 2: CMD(regr+0x80);
104 for (k=0;k<count-2;k++) buf[k] = r4();
105 w2(0xac); w2(0xa4);
106 buf[count-2] = r4();
107 buf[count-1] = r4();
108 w2(4);
109 break;
111 case 3: CMD(regr+0x80);
112 for (k=0;k<(count/2)-1;k++) ((u16 *)buf)[k] = r4w();
113 w2(0xac); w2(0xa4);
114 buf[count-2] = r4();
115 buf[count-1] = r4();
116 w2(4);
117 break;
119 case 4: CMD(regr+0x80);
120 for (k=0;k<(count/4)-1;k++) ((u32 *)buf)[k] = r4l();
121 buf[count-4] = r4();
122 buf[count-3] = r4();
123 w2(0xac); w2(0xa4);
124 buf[count-2] = r4();
125 buf[count-1] = r4();
126 w2(4);
127 break;
132 static void friq_read_block( PIA *pi, char * buf, int count)
134 { friq_read_block_int(pi,buf,count,0x08);
137 static void friq_write_block( PIA *pi, char * buf, int count )
139 { int k;
141 switch(pi->mode) {
143 case 0:
144 case 1: CMD(8); w2(5);
145 for (k=0;k<count;k++) {
146 w0(buf[k]);
147 w2(7);w2(5);
149 w2(4);
150 break;
152 case 2: CMD(0xc8); w2(5);
153 for (k=0;k<count;k++) w4(buf[k]);
154 w2(4);
155 break;
157 case 3: CMD(0xc8); w2(5);
158 for (k=0;k<count/2;k++) w4w(((u16 *)buf)[k]);
159 w2(4);
160 break;
162 case 4: CMD(0xc8); w2(5);
163 for (k=0;k<count/4;k++) w4l(((u32 *)buf)[k]);
164 w2(4);
165 break;
169 static void friq_connect ( PIA *pi )
171 { pi->saved_r0 = r0();
172 pi->saved_r2 = r2();
173 w2(4);
176 static void friq_disconnect ( PIA *pi )
178 { CMD(0x20);
179 w0(pi->saved_r0);
180 w2(pi->saved_r2);
183 static int friq_test_proto( PIA *pi, char * scratch, int verbose )
185 { int j, k, r;
186 int e[2] = {0,0};
188 pi->saved_r0 = r0();
189 w0(0xff); udelay(20); CMD(0x3d); /* turn the power on */
190 udelay(500);
191 w0(pi->saved_r0);
193 friq_connect(pi);
194 for (j=0;j<2;j++) {
195 friq_write_regr(pi,0,6,0xa0+j*0x10);
196 for (k=0;k<256;k++) {
197 friq_write_regr(pi,0,2,k^0xaa);
198 friq_write_regr(pi,0,3,k^0x55);
199 if (friq_read_regr(pi,0,2) != (k^0xaa)) e[j]++;
202 friq_disconnect(pi);
204 friq_connect(pi);
205 friq_read_block_int(pi,scratch,512,0x10);
206 r = 0;
207 for (k=0;k<128;k++) if (scratch[k] != k) r++;
208 friq_disconnect(pi);
210 if (verbose) {
211 printk("%s: friq: port 0x%x, mode %d, test=(%d,%d,%d)\n",
212 pi->device,pi->port,pi->mode,e[0],e[1],r);
215 return (r || (e[0] && e[1]));
219 static void friq_log_adapter( PIA *pi, char * scratch, int verbose )
221 { char *mode_string[6] = {"4-bit","8-bit",
222 "EPP-8","EPP-16","EPP-32"};
224 printk("%s: friq %s, Freecom IQ ASIC-2 adapter at 0x%x, ", pi->device,
225 FRIQ_VERSION,pi->port);
226 printk("mode %d (%s), delay %d\n",pi->mode,
227 mode_string[pi->mode],pi->delay);
229 pi->private = 1;
230 friq_connect(pi);
231 CMD(0x9e); /* disable sleep timer */
232 friq_disconnect(pi);
236 static void friq_release_proto( PIA *pi)
238 if (pi->private) { /* turn off the power */
239 friq_connect(pi);
240 CMD(0x1d); CMD(0x1e);
241 friq_disconnect(pi);
242 pi->private = 0;
246 static struct pi_protocol friq = {
247 .owner = THIS_MODULE,
248 .name = "friq",
249 .max_mode = 5,
250 .epp_first = 2,
251 .default_delay = 1,
252 .max_units = 1,
253 .write_regr = friq_write_regr,
254 .read_regr = friq_read_regr,
255 .write_block = friq_write_block,
256 .read_block = friq_read_block,
257 .connect = friq_connect,
258 .disconnect = friq_disconnect,
259 .test_proto = friq_test_proto,
260 .log_adapter = friq_log_adapter,
261 .release_proto = friq_release_proto,
264 static int __init friq_init(void)
266 return paride_register(&friq);
269 static void __exit friq_exit(void)
271 paride_unregister(&friq);
274 MODULE_LICENSE("GPL");
275 module_init(friq_init)
276 module_exit(friq_exit)