Back to home page

OSCL-LXR

 
 

    


0001 /*
0002     backpack.c (c) 2001 Micro Solutions Inc.
0003         Released under the terms of the GNU General Public license
0004 
0005     backpack.c is a low-level protocol driver for the Micro Solutions
0006         "BACKPACK" parallel port IDE adapter
0007         (Works on Series 6 drives)
0008 
0009     Written by: Ken Hahn     (linux-dev@micro-solutions.com)
0010                 Clive Turvey (linux-dev@micro-solutions.com)
0011 
0012 */
0013 
0014 /*
0015    This is Ken's linux wrapper for the PPC library
0016    Version 1.0.0 is the backpack driver for which source is not available
0017    Version 2.0.0 is the first to have source released 
0018    Version 2.0.1 is the "Cox-ified" source code 
0019    Version 2.0.2 - fixed version string usage, and made ppc functions static 
0020 */
0021 
0022 
0023 #define BACKPACK_VERSION "2.0.2"
0024 
0025 #include <linux/module.h>
0026 #include <linux/init.h>
0027 #include <linux/kernel.h>
0028 #include <linux/slab.h>
0029 #include <linux/types.h>
0030 #include <asm/io.h>
0031 #include <linux/parport.h>
0032 
0033 #include "ppc6lnx.c"
0034 #include "paride.h"
0035 
0036 /* PARAMETERS */
0037 static bool verbose; /* set this to 1 to see debugging messages and whatnot */
0038  
0039 
0040 #define PPCSTRUCT(pi) ((Interface *)(pi->private))
0041 
0042 /****************************************************************/
0043 /*
0044  ATAPI CDROM DRIVE REGISTERS
0045 */
0046 #define ATAPI_DATA       0      /* data port                  */
0047 #define ATAPI_ERROR      1      /* error register (read)      */
0048 #define ATAPI_FEATURES   1      /* feature register (write)   */
0049 #define ATAPI_INT_REASON 2      /* interrupt reason register  */
0050 #define ATAPI_COUNT_LOW  4      /* byte count register (low)  */
0051 #define ATAPI_COUNT_HIGH 5      /* byte count register (high) */
0052 #define ATAPI_DRIVE_SEL  6      /* drive select register      */
0053 #define ATAPI_STATUS     7      /* status port (read)         */
0054 #define ATAPI_COMMAND    7      /* command port (write)       */
0055 #define ATAPI_ALT_STATUS 0x0e /* alternate status reg (read) */
0056 #define ATAPI_DEVICE_CONTROL 0x0e /* device control (write)   */
0057 /****************************************************************/
0058 
0059 static int bpck6_read_regr(PIA *pi, int cont, int reg)
0060 {
0061     unsigned int out;
0062 
0063     /* check for bad settings */
0064     if (reg<0 || reg>7 || cont<0 || cont>2)
0065     {
0066         return(-1);
0067     }
0068     out=ppc6_rd_port(PPCSTRUCT(pi),cont?reg|8:reg);
0069     return(out);
0070 }
0071 
0072 static void bpck6_write_regr(PIA *pi, int cont, int reg, int val)
0073 {
0074     /* check for bad settings */
0075     if (reg>=0 && reg<=7 && cont>=0 && cont<=1)
0076     {
0077         ppc6_wr_port(PPCSTRUCT(pi),cont?reg|8:reg,(u8)val);
0078     }
0079 }
0080 
0081 static void bpck6_write_block( PIA *pi, char * buf, int len )
0082 {
0083     ppc6_wr_port16_blk(PPCSTRUCT(pi),ATAPI_DATA,buf,(u32)len>>1); 
0084 }
0085 
0086 static void bpck6_read_block( PIA *pi, char * buf, int len )
0087 {
0088     ppc6_rd_port16_blk(PPCSTRUCT(pi),ATAPI_DATA,buf,(u32)len>>1);
0089 }
0090 
0091 static void bpck6_connect ( PIA *pi  )
0092 {
0093     if(verbose)
0094     {
0095         printk(KERN_DEBUG "connect\n");
0096     }
0097 
0098     if(pi->mode >=2)
0099     {
0100         PPCSTRUCT(pi)->mode=4+pi->mode-2;   
0101     }
0102     else if(pi->mode==1)
0103     {
0104         PPCSTRUCT(pi)->mode=3;  
0105     }
0106     else
0107     {
0108         PPCSTRUCT(pi)->mode=1;      
0109     }
0110 
0111     ppc6_open(PPCSTRUCT(pi));  
0112     ppc6_wr_extout(PPCSTRUCT(pi),0x3);
0113 }
0114 
0115 static void bpck6_disconnect ( PIA *pi )
0116 {
0117     if(verbose)
0118     {
0119         printk("disconnect\n");
0120     }
0121     ppc6_wr_extout(PPCSTRUCT(pi),0x0);
0122     ppc6_close(PPCSTRUCT(pi));
0123 }
0124 
0125 static int bpck6_test_port ( PIA *pi )   /* check for 8-bit port */
0126 {
0127     if(verbose)
0128     {
0129         printk(KERN_DEBUG "PARPORT indicates modes=%x for lp=0x%lx\n",
0130                     ((struct pardevice*)(pi->pardev))->port->modes,
0131             ((struct pardevice *)(pi->pardev))->port->base); 
0132     }
0133 
0134     /*copy over duplicate stuff.. initialize state info*/
0135     PPCSTRUCT(pi)->ppc_id=pi->unit;
0136     PPCSTRUCT(pi)->lpt_addr=pi->port;
0137 
0138     /* look at the parport device to see if what modes we can use */
0139     if(((struct pardevice *)(pi->pardev))->port->modes & 
0140         (PARPORT_MODE_EPP)
0141           )
0142     {
0143         return 5; /* Can do EPP*/
0144     }
0145     else if(((struct pardevice *)(pi->pardev))->port->modes & 
0146             (PARPORT_MODE_TRISTATE)
0147                )
0148     {
0149         return 2;
0150     }
0151     else /*Just flat SPP*/
0152     {
0153         return 1;
0154     }
0155 }
0156 
0157 static int bpck6_probe_unit ( PIA *pi )
0158 {
0159     int out;
0160 
0161     if(verbose)
0162     {
0163         printk(KERN_DEBUG "PROBE UNIT %x on port:%x\n",pi->unit,pi->port);
0164     }
0165 
0166     /*SET PPC UNIT NUMBER*/
0167     PPCSTRUCT(pi)->ppc_id=pi->unit;
0168 
0169     /*LOWER DOWN TO UNIDIRECTIONAL*/
0170     PPCSTRUCT(pi)->mode=1;      
0171 
0172     out=ppc6_open(PPCSTRUCT(pi));
0173 
0174     if(verbose)
0175     {
0176         printk(KERN_DEBUG "ppc_open returned %2x\n",out);
0177     }
0178 
0179     if(out)
0180     {
0181         ppc6_close(PPCSTRUCT(pi));
0182         if(verbose)
0183         {
0184             printk(KERN_DEBUG "leaving probe\n");
0185         }
0186                return(1);
0187     }
0188     else
0189     {
0190         if(verbose)
0191         {
0192             printk(KERN_DEBUG "Failed open\n");
0193         }
0194             return(0);
0195     }
0196 }
0197 
0198 static void bpck6_log_adapter( PIA *pi, char * scratch, int verbose )
0199 {
0200     char *mode_string[5]=
0201         {"4-bit","8-bit","EPP-8","EPP-16","EPP-32"};
0202 
0203     printk("%s: BACKPACK Protocol Driver V"BACKPACK_VERSION"\n",pi->device);
0204     printk("%s: Copyright 2001 by Micro Solutions, Inc., DeKalb IL.\n",pi->device);
0205     printk("%s: BACKPACK %s, Micro Solutions BACKPACK Drive at 0x%x\n",
0206         pi->device,BACKPACK_VERSION,pi->port);
0207     printk("%s: Unit: %d Mode:%d (%s) Delay %d\n",pi->device,
0208         pi->unit,pi->mode,mode_string[pi->mode],pi->delay);
0209 }
0210 
0211 static int bpck6_init_proto(PIA *pi)
0212 {
0213     Interface *p = kzalloc(sizeof(Interface), GFP_KERNEL);
0214 
0215     if (p) {
0216         pi->private = (unsigned long)p;
0217         return 0;
0218     }
0219 
0220     printk(KERN_ERR "%s: ERROR COULDN'T ALLOCATE MEMORY\n", pi->device); 
0221     return -1;
0222 }
0223 
0224 static void bpck6_release_proto(PIA *pi)
0225 {
0226     kfree((void *)(pi->private)); 
0227 }
0228 
0229 static struct pi_protocol bpck6 = {
0230     .owner      = THIS_MODULE,
0231     .name       = "bpck6",
0232     .max_mode   = 5,
0233     .epp_first  = 2, /* 2-5 use epp (need 8 ports) */
0234     .max_units  = 255,
0235     .write_regr = bpck6_write_regr,
0236     .read_regr  = bpck6_read_regr,
0237     .write_block    = bpck6_write_block,
0238     .read_block = bpck6_read_block,
0239     .connect    = bpck6_connect,
0240     .disconnect = bpck6_disconnect,
0241     .test_port  = bpck6_test_port,
0242     .probe_unit = bpck6_probe_unit,
0243     .log_adapter    = bpck6_log_adapter,
0244     .init_proto = bpck6_init_proto,
0245     .release_proto  = bpck6_release_proto,
0246 };
0247 
0248 static int __init bpck6_init(void)
0249 {
0250     printk(KERN_INFO "bpck6: BACKPACK Protocol Driver V"BACKPACK_VERSION"\n");
0251     printk(KERN_INFO "bpck6: Copyright 2001 by Micro Solutions, Inc., DeKalb IL. USA\n");
0252     if(verbose)
0253         printk(KERN_DEBUG "bpck6: verbose debug enabled.\n");
0254     return paride_register(&bpck6);
0255 }
0256 
0257 static void __exit bpck6_exit(void)
0258 {
0259     paride_unregister(&bpck6);
0260 }
0261 
0262 MODULE_LICENSE("GPL");
0263 MODULE_AUTHOR("Micro Solutions Inc.");
0264 MODULE_DESCRIPTION("BACKPACK Protocol module, compatible with PARIDE");
0265 module_param(verbose, bool, 0644);
0266 module_init(bpck6_init)
0267 module_exit(bpck6_exit)