Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | on20.c (c) 1996-8 Grant R. Guenther <grant@torque.net> |
| 3 | Under the terms of the GNU General Public License. |
| 4 | |
| 5 | on20.c is a low-level protocol driver for the |
| 6 | Onspec 90c20 parallel to IDE adapter. |
| 7 | */ |
| 8 | |
| 9 | /* Changes: |
| 10 | |
| 11 | 1.01 GRG 1998.05.06 init_proto, release_proto |
| 12 | |
| 13 | */ |
| 14 | |
| 15 | #define ON20_VERSION "1.01" |
| 16 | |
| 17 | #include <linux/module.h> |
| 18 | #include <linux/init.h> |
| 19 | #include <linux/delay.h> |
| 20 | #include <linux/kernel.h> |
| 21 | #include <linux/types.h> |
| 22 | #include <linux/wait.h> |
| 23 | #include <asm/io.h> |
| 24 | |
| 25 | #include "paride.h" |
| 26 | |
| 27 | #define op(f) w2(4);w0(f);w2(5);w2(0xd);w2(5);w2(0xd);w2(5);w2(4); |
| 28 | #define vl(v) w2(4);w0(v);w2(5);w2(7);w2(5);w2(4); |
| 29 | |
| 30 | #define j44(a,b) (((a>>4)&0x0f)|(b&0xf0)) |
| 31 | |
| 32 | /* cont = 0 - access the IDE register file |
| 33 | cont = 1 - access the IDE command set |
| 34 | */ |
| 35 | |
| 36 | static int on20_read_regr( PIA *pi, int cont, int regr ) |
| 37 | |
| 38 | { int h,l, r ; |
| 39 | |
| 40 | r = (regr<<2) + 1 + cont; |
| 41 | |
| 42 | op(1); vl(r); op(0); |
| 43 | |
| 44 | switch (pi->mode) { |
| 45 | |
| 46 | case 0: w2(4); w2(6); l = r1(); |
| 47 | w2(4); w2(6); h = r1(); |
| 48 | w2(4); w2(6); w2(4); w2(6); w2(4); |
| 49 | return j44(l,h); |
| 50 | |
| 51 | case 1: w2(4); w2(0x26); r = r0(); |
| 52 | w2(4); w2(0x26); w2(4); |
| 53 | return r; |
| 54 | |
| 55 | } |
| 56 | return -1; |
| 57 | } |
| 58 | |
| 59 | static void on20_write_regr( PIA *pi, int cont, int regr, int val ) |
| 60 | |
| 61 | { int r; |
| 62 | |
| 63 | r = (regr<<2) + 1 + cont; |
| 64 | |
| 65 | op(1); vl(r); |
| 66 | op(0); vl(val); |
| 67 | op(0); vl(val); |
| 68 | } |
| 69 | |
| 70 | static void on20_connect ( PIA *pi) |
| 71 | |
| 72 | { pi->saved_r0 = r0(); |
| 73 | pi->saved_r2 = r2(); |
| 74 | |
| 75 | w2(4);w0(0);w2(0xc);w2(4);w2(6);w2(4);w2(6);w2(4); |
| 76 | if (pi->mode) { op(2); vl(8); op(2); vl(9); } |
| 77 | else { op(2); vl(0); op(2); vl(8); } |
| 78 | } |
| 79 | |
| 80 | static void on20_disconnect ( PIA *pi ) |
| 81 | |
| 82 | { w2(4);w0(7);w2(4);w2(0xc);w2(4); |
| 83 | w0(pi->saved_r0); |
| 84 | w2(pi->saved_r2); |
| 85 | } |
| 86 | |
| 87 | static void on20_read_block( PIA *pi, char * buf, int count ) |
| 88 | |
| 89 | { int k, l, h; |
| 90 | |
| 91 | op(1); vl(1); op(0); |
| 92 | |
| 93 | for (k=0;k<count;k++) |
| 94 | if (pi->mode) { |
| 95 | w2(4); w2(0x26); buf[k] = r0(); |
| 96 | } else { |
| 97 | w2(6); l = r1(); w2(4); |
| 98 | w2(6); h = r1(); w2(4); |
| 99 | buf[k] = j44(l,h); |
| 100 | } |
| 101 | w2(4); |
| 102 | } |
| 103 | |
| 104 | static void on20_write_block( PIA *pi, char * buf, int count ) |
| 105 | |
| 106 | { int k; |
| 107 | |
| 108 | op(1); vl(1); op(0); |
| 109 | |
| 110 | for (k=0;k<count;k++) { w2(5); w0(buf[k]); w2(7); } |
| 111 | w2(4); |
| 112 | } |
| 113 | |
| 114 | static void on20_log_adapter( PIA *pi, char * scratch, int verbose ) |
| 115 | |
| 116 | { char *mode_string[2] = {"4-bit","8-bit"}; |
| 117 | |
| 118 | printk("%s: on20 %s, OnSpec 90c20 at 0x%x, ", |
| 119 | pi->device,ON20_VERSION,pi->port); |
| 120 | printk("mode %d (%s), delay %d\n",pi->mode, |
| 121 | mode_string[pi->mode],pi->delay); |
| 122 | |
| 123 | } |
| 124 | |
| 125 | static struct pi_protocol on20 = { |
| 126 | .owner = THIS_MODULE, |
| 127 | .name = "on20", |
| 128 | .max_mode = 2, |
| 129 | .epp_first = 2, |
| 130 | .default_delay = 1, |
| 131 | .max_units = 1, |
| 132 | .write_regr = on20_write_regr, |
| 133 | .read_regr = on20_read_regr, |
| 134 | .write_block = on20_write_block, |
| 135 | .read_block = on20_read_block, |
| 136 | .connect = on20_connect, |
| 137 | .disconnect = on20_disconnect, |
| 138 | .log_adapter = on20_log_adapter, |
| 139 | }; |
| 140 | |
| 141 | static int __init on20_init(void) |
| 142 | { |
Alexey Dobriyan | b4178ab | 2006-12-06 20:36:21 -0800 | [diff] [blame] | 143 | return paride_register(&on20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | static void __exit on20_exit(void) |
| 147 | { |
Alexey Dobriyan | f433000 | 2006-12-06 20:36:20 -0800 | [diff] [blame] | 148 | paride_unregister(&on20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | MODULE_LICENSE("GPL"); |
| 152 | module_init(on20_init) |
| 153 | module_exit(on20_exit) |