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
20 Version 2.0.2ac - additional cleanup (privptr now not private to fix 64bit
21 platforms), use memset, rename clashing PPC define.
26 int verbose=0; /* set this to 1 to see debugging messages and whatnot */
28 #define BACKPACK_VERSION "2.0.2ac"
30 #include <linux/module.h>
31 #include <linux/kernel.h>
32 #include <linux/slab.h>
33 #include <linux/types.h>
36 #if defined(CONFIG_PARPORT_MODULE)||defined(CONFIG_PARPORT)
37 #include <linux/parport.h>
45 #define PPCSTRUCT(pi) ((PPC_STORAGE *)(pi->privptr))
47 /****************************************************************/
49 ATAPI CDROM DRIVE REGISTERS
51 #define ATAPI_DATA 0 /* data port */
52 #define ATAPI_ERROR 1 /* error register (read) */
53 #define ATAPI_FEATURES 1 /* feature register (write) */
54 #define ATAPI_INT_REASON 2 /* interrupt reason register */
55 #define ATAPI_COUNT_LOW 4 /* byte count register (low) */
56 #define ATAPI_COUNT_HIGH 5 /* byte count register (high) */
57 #define ATAPI_DRIVE_SEL 6 /* drive select register */
58 #define ATAPI_STATUS 7 /* status port (read) */
59 #define ATAPI_COMMAND 7 /* command port (write) */
60 #define ATAPI_ALT_STATUS 0x0e /* alternate status reg (read) */
61 #define ATAPI_DEVICE_CONTROL 0x0e /* device control (write) */
62 /****************************************************************/
64 static int bpck6_read_regr(PIA *pi, int cont, int reg)
68 /* check for bad settings */
69 if (reg<0 || reg>7 || cont<0 || cont>2)
73 out=ppc6_rd_port(PPCSTRUCT(pi),cont?reg|8:reg);
77 static void bpck6_write_regr(PIA *pi, int cont, int reg, int val)
79 /* check for bad settings */
80 if (reg>=0 && reg<=7 && cont>=0 && cont<=1)
82 ppc6_wr_port(PPCSTRUCT(pi),cont?reg|8:reg,(u8)val);
86 static void bpck6_write_block( PIA *pi, char * buf, int len )
88 ppc6_wr_port16_blk(PPCSTRUCT(pi),ATAPI_DATA,buf,(u32)len>>1);
91 static void bpck6_read_block( PIA *pi, char * buf, int len )
93 ppc6_rd_port16_blk(PPCSTRUCT(pi),ATAPI_DATA,buf,(u32)len>>1);
96 static void bpck6_connect ( PIA *pi )
100 printk(KERN_DEBUG "connect\n");
105 PPCSTRUCT(pi)->mode=4+pi->mode-2;
109 PPCSTRUCT(pi)->mode=3;
113 PPCSTRUCT(pi)->mode=1;
116 ppc6_open(PPCSTRUCT(pi));
117 ppc6_wr_extout(PPCSTRUCT(pi),0x3);
120 static void bpck6_disconnect ( PIA *pi )
124 printk("disconnect\n");
126 ppc6_wr_extout(PPCSTRUCT(pi),0x0);
127 ppc6_close(PPCSTRUCT(pi));
130 static int bpck6_test_port ( PIA *pi ) /* check for 8-bit port */
134 printk(KERN_DEBUG "PARPORT indicates modes=%x for lp=0x%lx\n",
135 ((struct pardevice*)(pi->pardev))->port->modes,
136 ((struct pardevice *)(pi->pardev))->port->base);
139 /*copy over duplicate stuff.. initialize state info*/
140 PPCSTRUCT(pi)->ppc_id=pi->unit;
141 PPCSTRUCT(pi)->lpt_addr=pi->port;
143 #ifdef CONFIG_PARPORT_PC_MODULE
144 #define CONFIG_PARPORT_PC
147 #ifdef CONFIG_PARPORT_PC
148 /* look at the parport device to see if what modes we can use */
149 if(((struct pardevice *)(pi->pardev))->port->modes &
153 return 5; /* Can do EPP*/
155 else if(((struct pardevice *)(pi->pardev))->port->modes &
156 (PARPORT_MODE_TRISTATE)
161 else /*Just flat SPP*/
166 /* there is no way of knowing what kind of port we have
167 default to the highest mode possible */
172 static int bpck6_probe_unit ( PIA *pi )
178 printk(KERN_DEBUG "PROBE UNIT %x on port:%x\n",pi->unit,pi->port);
181 /*SET PPC UNIT NUMBER*/
182 PPCSTRUCT(pi)->ppc_id=pi->unit;
184 /*LOWER DOWN TO UNIDIRECTIONAL*/
185 PPCSTRUCT(pi)->mode=1;
187 out=ppc6_open(PPCSTRUCT(pi));
191 printk(KERN_DEBUG "ppc_open returned %2x\n",out);
196 ppc6_close(PPCSTRUCT(pi));
199 printk(KERN_DEBUG "leaving probe\n");
207 printk(KERN_DEBUG "Failed open\n");
213 static void bpck6_log_adapter( PIA *pi, char * scratch, int verbose )
215 char *mode_string[5]=
216 {"4-bit","8-bit","EPP-8","EPP-16","EPP-32"};
218 printk("%s: BACKPACK Protocol Driver V"BACKPACK_VERSION"\n",pi->device);
219 printk("%s: Copyright 2001 by Micro Solutions, Inc., DeKalb IL.\n",pi->device);
220 printk("%s: BACKPACK %s, Micro Solutions BACKPACK Drive at 0x%x\n",
221 pi->device,BACKPACK_VERSION,pi->port);
222 printk("%s: Unit: %d Mode:%d (%s) Delay %d\n",pi->device,
223 pi->unit,pi->mode,mode_string[pi->mode],pi->delay);
226 static void bpck6_init_proto(PIA *pi)
228 /* allocate a state structure for this item */
229 pi->privptr=kmalloc(sizeof(PPC_STORAGE),GFP_KERNEL);
231 if(pi->privptr==NULL)
233 printk(KERN_ERR "%s: ERROR COULDN'T ALLOCATE MEMORY\n",pi->device);
241 memset(pi->privptr, 0, sizeof(PPC_STORAGE));
244 static void bpck6_release_proto(PIA *pi)
247 /* free after use count decremented so that we aren't using it
248 when it is decremented */
252 struct pi_protocol bpck6 = { "bpck6", /* name for proto*/
253 0, /* index into proto table */
255 2, /* 2-5 use epp (need 8 ports) */
256 0, /* no delay (not used anyway) */
257 255, /* we can have units up to 255 */
273 EXPORT_SYMBOL(bpck6_write_regr);
274 EXPORT_SYMBOL(bpck6_read_regr);
275 EXPORT_SYMBOL(bpck6_write_block);
276 EXPORT_SYMBOL(bpck6_read_block);
277 EXPORT_SYMBOL(bpck6_connect);
278 EXPORT_SYMBOL(bpck6_disconnect);
279 EXPORT_SYMBOL(bpck6_test_port);
280 EXPORT_SYMBOL(bpck6_probe_unit);
281 EXPORT_SYMBOL(bpck6_log_adapter);
282 EXPORT_SYMBOL(bpck6_init_proto);
283 EXPORT_SYMBOL(bpck6_release_proto);
285 /*---------------------------MODULE STUFF-----------------------*/
288 /*module information*/
290 int init_module(void)
292 printk(KERN_INFO "bpck6: BACKPACK Protocol Driver V"BACKPACK_VERSION"\n");
293 printk(KERN_INFO "bpck6: Copyright 2001 by Micro Solutions, Inc., DeKalb IL. USA\n");
297 printk(KERN_DEBUG "bpck6: verbose debug enabled.\n");
300 return pi_register(&bpck6) - 1;
303 void cleanup_module(void)
305 pi_unregister(&bpck6);
308 MODULE_AUTHOR("Micro Solutions Inc.");
309 MODULE_DESCRIPTION("BACKPACK Protocol module, compatible with PARIDE");
310 MODULE_PARM(verbose,"i");