Linux-2.6.12-rc2
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / block / paride / bpck6.c
blob08d858ad64db9533a134996a8fa0c4002f7bdcac
1 /*
2 backpack.c (c) 2001 Micro Solutions Inc.
3 Released under the terms of the GNU General Public license
5 backpack.c is a low-level protocol driver for the Micro Solutions
6 "BACKPACK" parallel port IDE adapter
7 (Works on Series 6 drives)
9 Written by: Ken Hahn (linux-dev@micro-solutions.com)
10 Clive Turvey (linux-dev@micro-solutions.com)
15 This is Ken's linux wrapper for the PPC library
16 Version 1.0.0 is the backpack driver for which source is not available
17 Version 2.0.0 is the first to have source released
18 Version 2.0.1 is the "Cox-ified" source code
19 Version 2.0.2 - fixed version string usage, and made ppc functions static
23 /* PARAMETERS */
24 static int verbose; /* set this to 1 to see debugging messages and whatnot */
26 #define BACKPACK_VERSION "2.0.2"
28 #include <linux/module.h>
29 #include <linux/init.h>
30 #include <linux/kernel.h>
31 #include <linux/slab.h>
32 #include <linux/types.h>
33 #include <asm/io.h>
35 #if defined(CONFIG_PARPORT_MODULE)||defined(CONFIG_PARPORT)
36 #include <linux/parport.h>
37 #endif
39 #include "ppc6lnx.c"
40 #include "paride.h"
44 #define PPCSTRUCT(pi) ((Interface *)(pi->private))
46 /****************************************************************/
48 ATAPI CDROM DRIVE REGISTERS
50 #define ATAPI_DATA 0 /* data port */
51 #define ATAPI_ERROR 1 /* error register (read) */
52 #define ATAPI_FEATURES 1 /* feature register (write) */
53 #define ATAPI_INT_REASON 2 /* interrupt reason register */
54 #define ATAPI_COUNT_LOW 4 /* byte count register (low) */
55 #define ATAPI_COUNT_HIGH 5 /* byte count register (high) */
56 #define ATAPI_DRIVE_SEL 6 /* drive select register */
57 #define ATAPI_STATUS 7 /* status port (read) */
58 #define ATAPI_COMMAND 7 /* command port (write) */
59 #define ATAPI_ALT_STATUS 0x0e /* alternate status reg (read) */
60 #define ATAPI_DEVICE_CONTROL 0x0e /* device control (write) */
61 /****************************************************************/
63 static int bpck6_read_regr(PIA *pi, int cont, int reg)
65 unsigned int out;
67 /* check for bad settings */
68 if (reg<0 || reg>7 || cont<0 || cont>2)
70 return(-1);
72 out=ppc6_rd_port(PPCSTRUCT(pi),cont?reg|8:reg);
73 return(out);
76 static void bpck6_write_regr(PIA *pi, int cont, int reg, int val)
78 /* check for bad settings */
79 if (reg>=0 && reg<=7 && cont>=0 && cont<=1)
81 ppc6_wr_port(PPCSTRUCT(pi),cont?reg|8:reg,(u8)val);
85 static void bpck6_write_block( PIA *pi, char * buf, int len )
87 ppc6_wr_port16_blk(PPCSTRUCT(pi),ATAPI_DATA,buf,(u32)len>>1);
90 static void bpck6_read_block( PIA *pi, char * buf, int len )
92 ppc6_rd_port16_blk(PPCSTRUCT(pi),ATAPI_DATA,buf,(u32)len>>1);
95 static void bpck6_connect ( PIA *pi )
97 if(verbose)
99 printk(KERN_DEBUG "connect\n");
102 if(pi->mode >=2)
104 PPCSTRUCT(pi)->mode=4+pi->mode-2;
106 else if(pi->mode==1)
108 PPCSTRUCT(pi)->mode=3;
110 else
112 PPCSTRUCT(pi)->mode=1;
115 ppc6_open(PPCSTRUCT(pi));
116 ppc6_wr_extout(PPCSTRUCT(pi),0x3);
119 static void bpck6_disconnect ( PIA *pi )
121 if(verbose)
123 printk("disconnect\n");
125 ppc6_wr_extout(PPCSTRUCT(pi),0x0);
126 ppc6_close(PPCSTRUCT(pi));
129 static int bpck6_test_port ( PIA *pi ) /* check for 8-bit port */
131 if(verbose)
133 printk(KERN_DEBUG "PARPORT indicates modes=%x for lp=0x%lx\n",
134 ((struct pardevice*)(pi->pardev))->port->modes,
135 ((struct pardevice *)(pi->pardev))->port->base);
138 /*copy over duplicate stuff.. initialize state info*/
139 PPCSTRUCT(pi)->ppc_id=pi->unit;
140 PPCSTRUCT(pi)->lpt_addr=pi->port;
142 #ifdef CONFIG_PARPORT_PC_MODULE
143 #define CONFIG_PARPORT_PC
144 #endif
146 #ifdef CONFIG_PARPORT_PC
147 /* look at the parport device to see if what modes we can use */
148 if(((struct pardevice *)(pi->pardev))->port->modes &
149 (PARPORT_MODE_EPP)
152 return 5; /* Can do EPP*/
154 else if(((struct pardevice *)(pi->pardev))->port->modes &
155 (PARPORT_MODE_TRISTATE)
158 return 2;
160 else /*Just flat SPP*/
162 return 1;
164 #else
165 /* there is no way of knowing what kind of port we have
166 default to the highest mode possible */
167 return 5;
168 #endif
171 static int bpck6_probe_unit ( PIA *pi )
173 int out;
175 if(verbose)
177 printk(KERN_DEBUG "PROBE UNIT %x on port:%x\n",pi->unit,pi->port);
180 /*SET PPC UNIT NUMBER*/
181 PPCSTRUCT(pi)->ppc_id=pi->unit;
183 /*LOWER DOWN TO UNIDIRECTIONAL*/
184 PPCSTRUCT(pi)->mode=1;
186 out=ppc6_open(PPCSTRUCT(pi));
188 if(verbose)
190 printk(KERN_DEBUG "ppc_open returned %2x\n",out);
193 if(out)
195 ppc6_close(PPCSTRUCT(pi));
196 if(verbose)
198 printk(KERN_DEBUG "leaving probe\n");
200 return(1);
202 else
204 if(verbose)
206 printk(KERN_DEBUG "Failed open\n");
208 return(0);
212 static void bpck6_log_adapter( PIA *pi, char * scratch, int verbose )
214 char *mode_string[5]=
215 {"4-bit","8-bit","EPP-8","EPP-16","EPP-32"};
217 printk("%s: BACKPACK Protocol Driver V"BACKPACK_VERSION"\n",pi->device);
218 printk("%s: Copyright 2001 by Micro Solutions, Inc., DeKalb IL.\n",pi->device);
219 printk("%s: BACKPACK %s, Micro Solutions BACKPACK Drive at 0x%x\n",
220 pi->device,BACKPACK_VERSION,pi->port);
221 printk("%s: Unit: %d Mode:%d (%s) Delay %d\n",pi->device,
222 pi->unit,pi->mode,mode_string[pi->mode],pi->delay);
225 static int bpck6_init_proto(PIA *pi)
227 Interface *p = kmalloc(sizeof(Interface), GFP_KERNEL);
229 if (p) {
230 memset(p, 0, sizeof(Interface));
231 pi->private = (unsigned long)p;
232 return 0;
235 printk(KERN_ERR "%s: ERROR COULDN'T ALLOCATE MEMORY\n", pi->device);
236 return -1;
239 static void bpck6_release_proto(PIA *pi)
241 kfree((void *)(pi->private));
244 static struct pi_protocol bpck6 = {
245 .owner = THIS_MODULE,
246 .name = "bpck6",
247 .max_mode = 5,
248 .epp_first = 2, /* 2-5 use epp (need 8 ports) */
249 .max_units = 255,
250 .write_regr = bpck6_write_regr,
251 .read_regr = bpck6_read_regr,
252 .write_block = bpck6_write_block,
253 .read_block = bpck6_read_block,
254 .connect = bpck6_connect,
255 .disconnect = bpck6_disconnect,
256 .test_port = bpck6_test_port,
257 .probe_unit = bpck6_probe_unit,
258 .log_adapter = bpck6_log_adapter,
259 .init_proto = bpck6_init_proto,
260 .release_proto = bpck6_release_proto,
263 static int __init bpck6_init(void)
265 printk(KERN_INFO "bpck6: BACKPACK Protocol Driver V"BACKPACK_VERSION"\n");
266 printk(KERN_INFO "bpck6: Copyright 2001 by Micro Solutions, Inc., DeKalb IL. USA\n");
267 if(verbose)
268 printk(KERN_DEBUG "bpck6: verbose debug enabled.\n");
269 return pi_register(&bpck6) - 1;
272 static void __exit bpck6_exit(void)
274 pi_unregister(&bpck6);
277 MODULE_LICENSE("GPL");
278 MODULE_AUTHOR("Micro Solutions Inc.");
279 MODULE_DESCRIPTION("BACKPACK Protocol module, compatible with PARIDE");
280 module_param(verbose, bool, 0644);
281 module_init(bpck6_init)
282 module_exit(bpck6_exit)