/drivers/block/paride/bpck6.c

https://bitbucket.org/evzijst/gittest · C · 282 lines · 208 code · 41 blank · 33 comment · 25 complexity · 974ce68bf0d3be6726401778624fd59e MD5 · raw file

  1. /*
  2. backpack.c (c) 2001 Micro Solutions Inc.
  3. Released under the terms of the GNU General Public license
  4. backpack.c is a low-level protocol driver for the Micro Solutions
  5. "BACKPACK" parallel port IDE adapter
  6. (Works on Series 6 drives)
  7. Written by: Ken Hahn (linux-dev@micro-solutions.com)
  8. Clive Turvey (linux-dev@micro-solutions.com)
  9. */
  10. /*
  11. This is Ken's linux wrapper for the PPC library
  12. Version 1.0.0 is the backpack driver for which source is not available
  13. Version 2.0.0 is the first to have source released
  14. Version 2.0.1 is the "Cox-ified" source code
  15. Version 2.0.2 - fixed version string usage, and made ppc functions static
  16. */
  17. /* PARAMETERS */
  18. static int verbose; /* set this to 1 to see debugging messages and whatnot */
  19. #define BACKPACK_VERSION "2.0.2"
  20. #include <linux/module.h>
  21. #include <linux/init.h>
  22. #include <linux/kernel.h>
  23. #include <linux/slab.h>
  24. #include <linux/types.h>
  25. #include <asm/io.h>
  26. #if defined(CONFIG_PARPORT_MODULE)||defined(CONFIG_PARPORT)
  27. #include <linux/parport.h>
  28. #endif
  29. #include "ppc6lnx.c"
  30. #include "paride.h"
  31. #define PPCSTRUCT(pi) ((Interface *)(pi->private))
  32. /****************************************************************/
  33. /*
  34. ATAPI CDROM DRIVE REGISTERS
  35. */
  36. #define ATAPI_DATA 0 /* data port */
  37. #define ATAPI_ERROR 1 /* error register (read) */
  38. #define ATAPI_FEATURES 1 /* feature register (write) */
  39. #define ATAPI_INT_REASON 2 /* interrupt reason register */
  40. #define ATAPI_COUNT_LOW 4 /* byte count register (low) */
  41. #define ATAPI_COUNT_HIGH 5 /* byte count register (high) */
  42. #define ATAPI_DRIVE_SEL 6 /* drive select register */
  43. #define ATAPI_STATUS 7 /* status port (read) */
  44. #define ATAPI_COMMAND 7 /* command port (write) */
  45. #define ATAPI_ALT_STATUS 0x0e /* alternate status reg (read) */
  46. #define ATAPI_DEVICE_CONTROL 0x0e /* device control (write) */
  47. /****************************************************************/
  48. static int bpck6_read_regr(PIA *pi, int cont, int reg)
  49. {
  50. unsigned int out;
  51. /* check for bad settings */
  52. if (reg<0 || reg>7 || cont<0 || cont>2)
  53. {
  54. return(-1);
  55. }
  56. out=ppc6_rd_port(PPCSTRUCT(pi),cont?reg|8:reg);
  57. return(out);
  58. }
  59. static void bpck6_write_regr(PIA *pi, int cont, int reg, int val)
  60. {
  61. /* check for bad settings */
  62. if (reg>=0 && reg<=7 && cont>=0 && cont<=1)
  63. {
  64. ppc6_wr_port(PPCSTRUCT(pi),cont?reg|8:reg,(u8)val);
  65. }
  66. }
  67. static void bpck6_write_block( PIA *pi, char * buf, int len )
  68. {
  69. ppc6_wr_port16_blk(PPCSTRUCT(pi),ATAPI_DATA,buf,(u32)len>>1);
  70. }
  71. static void bpck6_read_block( PIA *pi, char * buf, int len )
  72. {
  73. ppc6_rd_port16_blk(PPCSTRUCT(pi),ATAPI_DATA,buf,(u32)len>>1);
  74. }
  75. static void bpck6_connect ( PIA *pi )
  76. {
  77. if(verbose)
  78. {
  79. printk(KERN_DEBUG "connect\n");
  80. }
  81. if(pi->mode >=2)
  82. {
  83. PPCSTRUCT(pi)->mode=4+pi->mode-2;
  84. }
  85. else if(pi->mode==1)
  86. {
  87. PPCSTRUCT(pi)->mode=3;
  88. }
  89. else
  90. {
  91. PPCSTRUCT(pi)->mode=1;
  92. }
  93. ppc6_open(PPCSTRUCT(pi));
  94. ppc6_wr_extout(PPCSTRUCT(pi),0x3);
  95. }
  96. static void bpck6_disconnect ( PIA *pi )
  97. {
  98. if(verbose)
  99. {
  100. printk("disconnect\n");
  101. }
  102. ppc6_wr_extout(PPCSTRUCT(pi),0x0);
  103. ppc6_close(PPCSTRUCT(pi));
  104. }
  105. static int bpck6_test_port ( PIA *pi ) /* check for 8-bit port */
  106. {
  107. if(verbose)
  108. {
  109. printk(KERN_DEBUG "PARPORT indicates modes=%x for lp=0x%lx\n",
  110. ((struct pardevice*)(pi->pardev))->port->modes,
  111. ((struct pardevice *)(pi->pardev))->port->base);
  112. }
  113. /*copy over duplicate stuff.. initialize state info*/
  114. PPCSTRUCT(pi)->ppc_id=pi->unit;
  115. PPCSTRUCT(pi)->lpt_addr=pi->port;
  116. #ifdef CONFIG_PARPORT_PC_MODULE
  117. #define CONFIG_PARPORT_PC
  118. #endif
  119. #ifdef CONFIG_PARPORT_PC
  120. /* look at the parport device to see if what modes we can use */
  121. if(((struct pardevice *)(pi->pardev))->port->modes &
  122. (PARPORT_MODE_EPP)
  123. )
  124. {
  125. return 5; /* Can do EPP*/
  126. }
  127. else if(((struct pardevice *)(pi->pardev))->port->modes &
  128. (PARPORT_MODE_TRISTATE)
  129. )
  130. {
  131. return 2;
  132. }
  133. else /*Just flat SPP*/
  134. {
  135. return 1;
  136. }
  137. #else
  138. /* there is no way of knowing what kind of port we have
  139. default to the highest mode possible */
  140. return 5;
  141. #endif
  142. }
  143. static int bpck6_probe_unit ( PIA *pi )
  144. {
  145. int out;
  146. if(verbose)
  147. {
  148. printk(KERN_DEBUG "PROBE UNIT %x on port:%x\n",pi->unit,pi->port);
  149. }
  150. /*SET PPC UNIT NUMBER*/
  151. PPCSTRUCT(pi)->ppc_id=pi->unit;
  152. /*LOWER DOWN TO UNIDIRECTIONAL*/
  153. PPCSTRUCT(pi)->mode=1;
  154. out=ppc6_open(PPCSTRUCT(pi));
  155. if(verbose)
  156. {
  157. printk(KERN_DEBUG "ppc_open returned %2x\n",out);
  158. }
  159. if(out)
  160. {
  161. ppc6_close(PPCSTRUCT(pi));
  162. if(verbose)
  163. {
  164. printk(KERN_DEBUG "leaving probe\n");
  165. }
  166. return(1);
  167. }
  168. else
  169. {
  170. if(verbose)
  171. {
  172. printk(KERN_DEBUG "Failed open\n");
  173. }
  174. return(0);
  175. }
  176. }
  177. static void bpck6_log_adapter( PIA *pi, char * scratch, int verbose )
  178. {
  179. char *mode_string[5]=
  180. {"4-bit","8-bit","EPP-8","EPP-16","EPP-32"};
  181. printk("%s: BACKPACK Protocol Driver V"BACKPACK_VERSION"\n",pi->device);
  182. printk("%s: Copyright 2001 by Micro Solutions, Inc., DeKalb IL.\n",pi->device);
  183. printk("%s: BACKPACK %s, Micro Solutions BACKPACK Drive at 0x%x\n",
  184. pi->device,BACKPACK_VERSION,pi->port);
  185. printk("%s: Unit: %d Mode:%d (%s) Delay %d\n",pi->device,
  186. pi->unit,pi->mode,mode_string[pi->mode],pi->delay);
  187. }
  188. static int bpck6_init_proto(PIA *pi)
  189. {
  190. Interface *p = kmalloc(sizeof(Interface), GFP_KERNEL);
  191. if (p) {
  192. memset(p, 0, sizeof(Interface));
  193. pi->private = (unsigned long)p;
  194. return 0;
  195. }
  196. printk(KERN_ERR "%s: ERROR COULDN'T ALLOCATE MEMORY\n", pi->device);
  197. return -1;
  198. }
  199. static void bpck6_release_proto(PIA *pi)
  200. {
  201. kfree((void *)(pi->private));
  202. }
  203. static struct pi_protocol bpck6 = {
  204. .owner = THIS_MODULE,
  205. .name = "bpck6",
  206. .max_mode = 5,
  207. .epp_first = 2, /* 2-5 use epp (need 8 ports) */
  208. .max_units = 255,
  209. .write_regr = bpck6_write_regr,
  210. .read_regr = bpck6_read_regr,
  211. .write_block = bpck6_write_block,
  212. .read_block = bpck6_read_block,
  213. .connect = bpck6_connect,
  214. .disconnect = bpck6_disconnect,
  215. .test_port = bpck6_test_port,
  216. .probe_unit = bpck6_probe_unit,
  217. .log_adapter = bpck6_log_adapter,
  218. .init_proto = bpck6_init_proto,
  219. .release_proto = bpck6_release_proto,
  220. };
  221. static int __init bpck6_init(void)
  222. {
  223. printk(KERN_INFO "bpck6: BACKPACK Protocol Driver V"BACKPACK_VERSION"\n");
  224. printk(KERN_INFO "bpck6: Copyright 2001 by Micro Solutions, Inc., DeKalb IL. USA\n");
  225. if(verbose)
  226. printk(KERN_DEBUG "bpck6: verbose debug enabled.\n");
  227. return pi_register(&bpck6) - 1;
  228. }
  229. static void __exit bpck6_exit(void)
  230. {
  231. pi_unregister(&bpck6);
  232. }
  233. MODULE_LICENSE("GPL");
  234. MODULE_AUTHOR("Micro Solutions Inc.");
  235. MODULE_DESCRIPTION("BACKPACK Protocol module, compatible with PARIDE");
  236. module_param(verbose, bool, 0644);
  237. module_init(bpck6_init)
  238. module_exit(bpck6_exit)