fdc-io.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. #ifndef _FDC_IO_H
  2. #define _FDC_IO_H
  3. /*
  4. * Copyright (C) 1993-1996 Bas Laarhoven,
  5. * (C) 1996-1997 Claus-Justus Heine.
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; see the file COPYING. If not, write to
  16. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  17. *
  18. * $Source: /homes/cvs/ftape-stacked/ftape/lowlevel/fdc-io.h,v $
  19. * $Revision: 1.3 $
  20. * $Date: 1997/10/05 19:18:06 $
  21. *
  22. * This file contains the declarations for the low level
  23. * functions that communicate with the floppy disk controller,
  24. * for the QIC-40/80/3010/3020 floppy-tape driver "ftape" for
  25. * Linux.
  26. */
  27. #include <linux/fdreg.h>
  28. #include "../lowlevel/ftape-bsm.h"
  29. #define FDC_SK_BIT (0x20)
  30. #define FDC_MT_BIT (0x80)
  31. #define FDC_READ (FD_READ & ~(FDC_SK_BIT | FDC_MT_BIT))
  32. #define FDC_WRITE (FD_WRITE & ~FDC_MT_BIT)
  33. #define FDC_READ_DELETED (0x4c)
  34. #define FDC_WRITE_DELETED (0x49)
  35. #define FDC_VERIFY (0x56)
  36. #define FDC_READID (0x4a)
  37. #define FDC_SENSED (0x04)
  38. #define FDC_SENSEI (FD_SENSEI)
  39. #define FDC_FORMAT (FD_FORMAT)
  40. #define FDC_RECAL (FD_RECALIBRATE)
  41. #define FDC_SEEK (FD_SEEK)
  42. #define FDC_SPECIFY (FD_SPECIFY)
  43. #define FDC_RECALIBR (FD_RECALIBRATE)
  44. #define FDC_VERSION (FD_VERSION)
  45. #define FDC_PERPEND (FD_PERPENDICULAR)
  46. #define FDC_DUMPREGS (FD_DUMPREGS)
  47. #define FDC_LOCK (FD_LOCK)
  48. #define FDC_UNLOCK (FD_UNLOCK)
  49. #define FDC_CONFIGURE (FD_CONFIGURE)
  50. #define FDC_DRIVE_SPEC (0x8e) /* i82078 has this (any others?) */
  51. #define FDC_PARTID (0x18) /* i82078 has this */
  52. #define FDC_SAVE (0x2e) /* i82078 has this (any others?) */
  53. #define FDC_RESTORE (0x4e) /* i82078 has this (any others?) */
  54. #define FDC_STATUS_MASK (STATUS_BUSY | STATUS_DMA | STATUS_DIR | STATUS_READY)
  55. #define FDC_DATA_READY (STATUS_READY)
  56. #define FDC_DATA_OUTPUT (STATUS_DIR)
  57. #define FDC_DATA_READY_MASK (STATUS_READY | STATUS_DIR)
  58. #define FDC_DATA_OUT_READY (STATUS_READY | STATUS_DIR)
  59. #define FDC_DATA_IN_READY (STATUS_READY)
  60. #define FDC_BUSY (STATUS_BUSY)
  61. #define FDC_CLK48_BIT (0x80)
  62. #define FDC_SEL3V_BIT (0x40)
  63. #define ST0_INT_MASK (ST0_INTR)
  64. #define FDC_INT_NORMAL (ST0_INTR & 0x00)
  65. #define FDC_INT_ABNORMAL (ST0_INTR & 0x40)
  66. #define FDC_INT_INVALID (ST0_INTR & 0x80)
  67. #define FDC_INT_READYCH (ST0_INTR & 0xC0)
  68. #define ST0_SEEK_END (ST0_SE)
  69. #define ST3_TRACK_0 (ST3_TZ)
  70. #define FDC_RESET_NOT (0x04)
  71. #define FDC_DMA_MODE (0x08)
  72. #define FDC_MOTOR_0 (0x10)
  73. #define FDC_MOTOR_1 (0x20)
  74. typedef struct {
  75. void (**hook) (void); /* our wedge into the isr */
  76. enum {
  77. no_fdc, i8272, i82077, i82077AA, fc10,
  78. i82078, i82078_1
  79. } type; /* FDC type */
  80. unsigned int irq; /* FDC irq nr */
  81. unsigned int dma; /* FDC dma channel nr */
  82. __u16 sra; /* Status register A (PS/2 only) */
  83. __u16 srb; /* Status register B (PS/2 only) */
  84. __u16 dor; /* Digital output register */
  85. __u16 tdr; /* Tape Drive Register (82077SL-1 &
  86. 82078 only) */
  87. __u16 msr; /* Main Status Register */
  88. __u16 dsr; /* Datarate Select Register (8207x only) */
  89. __u16 fifo; /* Data register / Fifo on 8207x */
  90. __u16 dir; /* Digital Input Register */
  91. __u16 ccr; /* Configuration Control Register */
  92. __u16 dor2; /* Alternate dor on MACH-2 controller,
  93. also used with FC-10, meaning unknown */
  94. } fdc_config_info;
  95. typedef enum {
  96. fdc_data_rate_250 = 2,
  97. fdc_data_rate_300 = 1, /* any fdc in default configuration */
  98. fdc_data_rate_500 = 0,
  99. fdc_data_rate_1000 = 3,
  100. fdc_data_rate_2000 = 1, /* i82078-1: when using Data Rate Table #2 */
  101. } fdc_data_rate_type;
  102. typedef enum {
  103. fdc_idle = 0,
  104. fdc_reading_data = FDC_READ,
  105. fdc_seeking = FDC_SEEK,
  106. fdc_writing_data = FDC_WRITE,
  107. fdc_deleting = FDC_WRITE_DELETED,
  108. fdc_reading_id = FDC_READID,
  109. fdc_recalibrating = FDC_RECAL,
  110. fdc_formatting = FDC_FORMAT,
  111. fdc_verifying = FDC_VERIFY
  112. } fdc_mode_enum;
  113. typedef enum {
  114. waiting = 0,
  115. reading,
  116. writing,
  117. formatting,
  118. verifying,
  119. deleting,
  120. done,
  121. error,
  122. mmapped,
  123. } buffer_state_enum;
  124. typedef struct {
  125. __u8 *address;
  126. volatile buffer_state_enum status;
  127. volatile __u8 *ptr;
  128. volatile unsigned int bytes;
  129. volatile unsigned int segment_id;
  130. /* bitmap for remainder of segment not yet handled.
  131. * one bit set for each bad sector that must be skipped.
  132. */
  133. volatile SectorMap bad_sector_map;
  134. /* bitmap with bad data blocks in data buffer.
  135. * the errors in this map may be retried.
  136. */
  137. volatile SectorMap soft_error_map;
  138. /* bitmap with bad data blocks in data buffer
  139. * the errors in this map may not be retried.
  140. */
  141. volatile SectorMap hard_error_map;
  142. /* retry counter for soft errors.
  143. */
  144. volatile int retry;
  145. /* sectors to skip on retry ???
  146. */
  147. volatile unsigned int skip;
  148. /* nr of data blocks in data buffer
  149. */
  150. volatile unsigned int data_offset;
  151. /* offset in segment for first sector to be handled.
  152. */
  153. volatile unsigned int sector_offset;
  154. /* size of cluster of good sectors to be handled.
  155. */
  156. volatile unsigned int sector_count;
  157. /* size of remaining part of segment to be handled.
  158. */
  159. volatile unsigned int remaining;
  160. /* points to next segment (contiguous) to be handled,
  161. * or is zero if no read-ahead is allowed.
  162. */
  163. volatile unsigned int next_segment;
  164. /* flag being set if deleted data was read.
  165. */
  166. volatile int deleted;
  167. /* floppy coordinates of first sector in segment */
  168. volatile __u8 head;
  169. volatile __u8 cyl;
  170. volatile __u8 sect;
  171. /* gap to use when formatting */
  172. __u8 gap3;
  173. /* flag set when buffer is mmaped */
  174. int mmapped;
  175. } buffer_struct;
  176. /*
  177. * fdc-io.c defined public variables
  178. */
  179. extern volatile fdc_mode_enum fdc_mode;
  180. extern int fdc_setup_error; /* outdated ??? */
  181. extern wait_queue_head_t ftape_wait_intr;
  182. extern volatile int ftape_current_cylinder; /* track nr FDC thinks we're on */
  183. extern volatile __u8 fdc_head; /* FDC head */
  184. extern volatile __u8 fdc_cyl; /* FDC track */
  185. extern volatile __u8 fdc_sect; /* FDC sector */
  186. extern fdc_config_info fdc; /* FDC hardware configuration */
  187. extern unsigned int ft_fdc_base;
  188. extern unsigned int ft_fdc_irq;
  189. extern unsigned int ft_fdc_dma;
  190. extern unsigned int ft_fdc_threshold;
  191. extern unsigned int ft_fdc_rate_limit;
  192. extern int ft_probe_fc10;
  193. extern int ft_mach2;
  194. /*
  195. * fdc-io.c defined public functions
  196. */
  197. extern void fdc_catch_stray_interrupts(int count);
  198. extern int fdc_ready_wait(unsigned int timeout);
  199. extern int fdc_command(const __u8 * cmd_data, int cmd_len);
  200. extern int fdc_result(__u8 * res_data, int res_len);
  201. extern int fdc_interrupt_wait(unsigned int time);
  202. extern int fdc_seek(int track);
  203. extern int fdc_sense_drive_status(int *st3);
  204. extern void fdc_motor(int motor);
  205. extern void fdc_reset(void);
  206. extern void fdc_disable(void);
  207. extern int fdc_fifo_threshold(__u8 threshold,
  208. int *fifo_state, int *lock_state, int *fifo_thr);
  209. extern void fdc_wait_calibrate(void);
  210. extern int fdc_sense_interrupt_status(int *st0, int *current_cylinder);
  211. extern void fdc_save_drive_specs(void);
  212. extern void fdc_restore_drive_specs(void);
  213. extern int fdc_set_data_rate(int rate);
  214. extern void fdc_set_write_precomp(int precomp);
  215. extern int fdc_release_irq_and_dma(void);
  216. extern void fdc_release_regions(void);
  217. extern int fdc_init(void);
  218. extern int fdc_setup_read_write(buffer_struct * buff, __u8 operation);
  219. extern int fdc_setup_formatting(buffer_struct * buff);
  220. #endif