3 Under the terms of the GNU General Public License.
5 on26.c is a low-level protocol driver for the
6 OnSpec 90c26 parallel to IDE adapter chip.
10 #include <linux/module.h>
11 #include <linux/init.h>
12 #include <linux/delay.h>
13 #include <linux/kernel.h>
14 #include <linux/types.h>
15 #include <linux/wait.h>
17 #include "pata_parport.h"
19 /* mode codes: 0 nybble reads, 8-bit writes
20 1 8-bit reads and writes
26 #define j44(a,b) (((a>>4)&0x0f)|(b&0xf0))
28 #define P1 w2(5);w2(0xd);w2(5);w2(0xd);w2(5);w2(4);
29 #define P2 w2(5);w2(7);w2(5);w2(4);
31 /* cont = 0 - access the IDE register file
32 cont = 1 - access the IDE command set
35 static int on26_read_regr(struct pi_adapter *pi, int cont, int regr)
39 r = (regr<<2) + 1 + cont;
43 case 0: w0(1); P1; w0(r); P2; w0(0); P1;
44 w2(6); a = r1(); w2(4);
45 w2(6); b = r1(); w2(4);
46 w2(6); w2(4); w2(6); w2(4);
49 case 1: w0(1); P1; w0(r); P2; w0(0); P1;
50 w2(0x26); a = r0(); w2(4); w2(0x26); w2(4);
55 case 4: w3(1); w3(1); w2(5); w4(r); w2(4);
56 w3(0); w3(0); w2(0x24); a = r4(); w2(4);
57 w2(0x24); (void)r4(); w2(4);
64 static void on26_write_regr(struct pi_adapter *pi, int cont, int regr, int val)
68 r = (regr<<2) + 1 + cont;
73 case 1: w0(1); P1; w0(r); P2; w0(0); P1;
74 w0(val); P2; w0(val); P2;
79 case 4: w3(1); w3(1); w2(5); w4(r); w2(4);
81 w2(5); w4(val); w2(4);
82 w2(5); w4(val); w2(4);
87 #define CCP(x) w0(0xfe);w0(0xaa);w0(0x55);w0(0);w0(0xff);\
88 w0(0x87);w0(0x78);w0(x);w2(4);w2(5);w2(4);w0(0xff);
90 static void on26_connect(struct pi_adapter *pi)
98 x = 8; if (pi->mode) x = 9;
100 w0(2); P1; w0(8); P2;
101 w0(2); P1; w0(x); P2;
104 static void on26_disconnect(struct pi_adapter *pi)
106 { if (pi->mode >= 2) { w3(4); w3(4); w3(4); w3(4); }
107 else { w0(4); P1; w0(4); P1; }
113 #define RESET_WAIT 200
115 static int on26_test_port(struct pi_adapter *pi) /* hard reset */
117 { int i, m, d, x=0, y=0;
131 w0(0xfe);w0(0xaa);w0(0x55);w0(0);w0(0xff);
132 i = ((r1() & 0xf0) << 4); w0(0x87);
133 i |= (r1() & 0xf0); w0(0x78);
134 w0(0x20);w2(4);w2(5);
135 i |= ((r1() & 0xf0) >> 4);
140 w0(2); P1; w0(0); P2;
141 w0(3); P1; w0(0); P2;
142 w0(2); P1; w0(8); P2; udelay(100);
143 w0(2); P1; w0(0xa); P2; udelay(100);
144 w0(2); P1; w0(8); P2; udelay(1000);
146 on26_write_regr(pi,0,6,0xa0);
148 for (i=0;i<RESET_WAIT;i++) {
149 on26_write_regr(pi,0,6,0xa0);
150 x = on26_read_regr(pi,0,7);
151 on26_write_regr(pi,0,6,0xb0);
152 y = on26_read_regr(pi,0,7);
153 if (!((x&0x80)||(y&0x80))) break;
158 dev_err(&pi->dev, "on26: Device reset failed (%x,%x)\n", x, y);
160 w0(4); P1; w0(4); P1;
174 static void on26_read_block(struct pi_adapter *pi, char *buf, int count)
180 case 0: w0(1); P1; w0(1); P2; w0(2); P1; w0(0x18); P2; w0(0); P1;
182 for (k=0;k<count;k++) {
187 w0(2); P1; w0(8); P2;
190 case 1: w0(1); P1; w0(1); P2; w0(2); P1; w0(0x19); P2; w0(0); P1;
192 for (k=0;k<count/2;k++) {
193 w2(0x26); buf[2*k] = r0();
194 w2(0x24); buf[2*k+1] = r0();
196 w0(2); P1; w0(9); P2;
199 case 2: w3(1); w3(1); w2(5); w4(1); w2(4);
200 w3(0); w3(0); w2(0x24);
202 for (k=0;k<count;k++) buf[k] = r4();
206 case 3: w3(1); w3(1); w2(5); w4(1); w2(4);
207 w3(0); w3(0); w2(0x24);
209 for (k=0;k<count/2;k++) ((u16 *)buf)[k] = r4w();
213 case 4: w3(1); w3(1); w2(5); w4(1); w2(4);
214 w3(0); w3(0); w2(0x24);
216 for (k=0;k<count/4;k++) ((u32 *)buf)[k] = r4l();
223 static void on26_write_block(struct pi_adapter *pi, char *buf, int count)
230 case 1: w0(1); P1; w0(1); P2;
231 w0(2); P1; w0(0x18+pi->mode); P2; w0(0); P1;
233 for (k=0;k<count/2;k++) {
235 w2(7); w0(buf[2*k+1]);
238 w0(2); P1; w0(8+pi->mode); P2;
241 case 2: w3(1); w3(1); w2(5); w4(1); w2(4);
242 w3(0); w3(0); w2(0xc5);
244 for (k=0;k<count;k++) w4(buf[k]);
248 case 3: w3(1); w3(1); w2(5); w4(1); w2(4);
249 w3(0); w3(0); w2(0xc5);
251 for (k=0;k<count/2;k++) w4w(((u16 *)buf)[k]);
255 case 4: w3(1); w3(1); w2(5); w4(1); w2(4);
256 w3(0); w3(0); w2(0xc5);
258 for (k=0;k<count/4;k++) w4l(((u32 *)buf)[k]);
266 static void on26_log_adapter(struct pi_adapter *pi)
268 { char *mode_string[5] = {"4-bit","8-bit","EPP-8",
271 dev_info(&pi->dev, "OnSpec 90c26 at 0x%x, mode %d (%s), delay %d\n",
272 pi->port, pi->mode, mode_string[pi->mode], pi->delay);
275 static struct pi_protocol on26 = {
276 .owner = THIS_MODULE,
282 .write_regr = on26_write_regr,
283 .read_regr = on26_read_regr,
284 .write_block = on26_write_block,
285 .read_block = on26_read_block,
286 .connect = on26_connect,
287 .disconnect = on26_disconnect,
288 .test_port = on26_test_port,
289 .log_adapter = on26_log_adapter,
292 MODULE_LICENSE("GPL");
293 module_pata_parport_driver(on26);