root/include/asm-sparc/floppy.h

/* [previous][next][first][last][top][bottom][index][help] */

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. sun_82072_fd_inb
  2. sun_82072_fd_outb
  3. sun_82077_fd_inb
  4. sun_82077_fd_outb
  5. virtual_dma_init
  6. sun_fd_disable_dma
  7. sun_fd_set_dma_mode
  8. sun_fd_set_dma_addr
  9. sun_fd_set_dma_count
  10. sun_fd_enable_dma
  11. sun_fd_request_irq
  12. sun_floppy_init

   1 /* $Id: floppy.h,v 1.8 1995/11/25 02:31:45 davem Exp $
   2  * asm-sparc/floppy.h: Sparc specific parts of the Floppy driver.
   3  *
   4  * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
   5  */
   6 
   7 #ifndef __ASM_SPARC_FLOPPY_H
   8 #define __ASM_SPARC_FLOPPY_H
   9 
  10 #include <asm/page.h>
  11 #include <asm/pgtable.h>
  12 #include <asm/system.h>
  13 #include <asm/idprom.h>
  14 #include <asm/machines.h>
  15 #include <asm/oplib.h>
  16 #include <asm/auxio.h>
  17 #include <asm/irq.h>
  18 
  19 /* References:
  20  * 1) Netbsd Sun floppy driver.
  21  * 2) NCR 82077 controller manual
  22  * 3) Intel 82077 controller manual
  23  */
  24 struct sun_flpy_controller {
  25         volatile unsigned char status_82072;  /* Main Status reg. */
  26 #define dcr_82072              status_82072   /* Digital Control reg. */
  27 #define status1_82077          status_82072   /* Auxiliary Status reg. 1 */
  28 
  29         volatile unsigned char data_82072;    /* Data fifo. */
  30 #define status2_82077          data_82072     /* Auxiliary Status reg. 2 */
  31 
  32         volatile unsigned char dor_82077;     /* Digital Output reg. */
  33         volatile unsigned char tapectl_82077; /* What the? Tape control reg? */
  34 
  35         volatile unsigned char status_82077;  /* Main Status Register. */
  36 #define drs_82077              status_82077   /* Digital Rate Select reg. */
  37 
  38         volatile unsigned char data_82077;    /* Data fifo. */
  39         volatile unsigned char ___unused;
  40         volatile unsigned char dir_82077;     /* Digital Input reg. */
  41 #define dcr_82077              dir_82077      /* Config Control reg. */
  42 };
  43 
  44 /* You'll only ever find one controller on a SparcStation anyways. */
  45 static struct sun_flpy_controller *sun_fdc = NULL;
  46 volatile unsigned char *fdc_status;
  47 
  48 struct sun_floppy_ops {
  49         unsigned char (*fd_inb)(int port);
  50         void (*fd_outb)(unsigned char value, int port);
  51 };
  52 
  53 static struct sun_floppy_ops sun_fdops;
  54 
  55 #define fd_inb(port)              sun_fdops.fd_inb(port)
  56 #define fd_outb(value,port)       sun_fdops.fd_outb(value,port)
  57 #define fd_enable_dma()           sun_fd_enable_dma()
  58 #define fd_disable_dma()          sun_fd_disable_dma()
  59 #define fd_request_dma()          (0) /* nothing... */
  60 #define fd_free_dma()             /* nothing... */
  61 #define fd_clear_dma_ff()         /* nothing... */
  62 #define fd_set_dma_mode(mode)     sun_fd_set_dma_mode(mode)
  63 #define fd_set_dma_addr(addr)     sun_fd_set_dma_addr(addr)
  64 #define fd_set_dma_count(count)   sun_fd_set_dma_count(count)
  65 #define fd_enable_irq()           /* nothing... */
  66 #define fd_disable_irq()          /* nothing... */
  67 #define fd_cacheflush(addr, size) /* nothing... */
  68 #define fd_request_irq()          sun_fd_request_irq()
  69 #define fd_free_irq()             /* nothing... */
  70 
  71 /* It's all the same... */
  72 #define virt_to_bus(x)            (x)
  73 #define bus_to_virt(x)            (x)
  74 
  75 /* XXX This isn't really correct. XXX */
  76 #define get_dma_residue(x)        (0)
  77 
  78 #define FLOPPY0_TYPE  4
  79 #define FLOPPY1_TYPE  0
  80 
  81 /* Super paranoid... */
  82 #undef HAVE_DISABLE_HLT
  83 
  84 /* Here is where we catch the floppy driver trying to initialize,
  85  * therefore this is where we call the PROM device tree probing
  86  * routine etc. on the Sparc.
  87  */
  88 #define FDC1                      sun_floppy_init()
  89 
  90 static int FDC2=-1;
  91 
  92 #define N_FDC    1
  93 #define N_DRIVE  8
  94 
  95 /* No 64k boundry crossing problems on the Sparc. */
  96 #define CROSS_64KB(a,s) (0)
  97 
  98 /* Routines unique to each controller type on a Sun. */
  99 static unsigned char sun_82072_fd_inb(int port)
     /* [previous][next][first][last][top][bottom][index][help] */
 100 {
 101         switch(port & 7) {
 102         default:
 103                 printk("floppy: Asked to read unknown port %d\n", port);
 104                 panic("floppy: Port bolixed.");
 105         case 4: /* FD_STATUS */
 106                 return sun_fdc->status_82072 & ~STATUS_DMA;
 107         case 5: /* FD_DATA */
 108                 return sun_fdc->data_82072;
 109         case 7: /* FD_DIR */
 110                 /* Always return 0, the disk never changes
 111                  * without the kernel explicitly doing so.
 112                  */
 113                 return 0;
 114         };
 115         panic("sun_82072_fd_inb: How did I get here?");
 116 }
 117 
 118 static void sun_82072_fd_outb(unsigned char value, int port)
     /* [previous][next][first][last][top][bottom][index][help] */
 119 {
 120         switch(port & 7) {
 121         default:
 122                 printk("floppy: Asked to write to unknown port %d\n", port);
 123                 panic("floppy: Port bolixed.");
 124         case 2: /* FD_DOR */
 125                 /* Oh geese, 82072 on the Sun has no DOR register,
 126                  * the functionality is implemented via the AUXIO
 127                  * I/O register.  So we must emulate the behavior.
 128                  *
 129                  * ASSUMPTIONS:  There will only ever be one floppy
 130                  *               drive attached to a Sun controller
 131                  *               and it will be at drive zero.
 132                  */
 133                 if(value & 0xf0)
 134                         set_auxio(AUXIO_FLPY_DSEL, 0);
 135 #if 0
 136                 else
 137                         set_auxio(0, AUXIO_FLPY_DSEL);
 138 #endif
 139                 break;
 140         case 5: /* FD_DATA */
 141                 sun_fdc->data_82072 = value;
 142                 break;
 143         case 7: /* FD_DCR */
 144                 sun_fdc->dcr_82072 = value;
 145                 break;
 146         case 4: /* FD_STATUS */
 147                 sun_fdc->status_82072 = value;
 148                 break;
 149         };
 150         return;
 151 }
 152 
 153 static unsigned char sun_82077_fd_inb(int port)
     /* [previous][next][first][last][top][bottom][index][help] */
 154 {
 155         switch(port & 7) {
 156         default:
 157                 printk("floppy: Asked to read unknown port %d\n", port);
 158                 panic("floppy: Port bolixed.");
 159         case 4: /* FD_STATUS */
 160                 return sun_fdc->status_82077 & ~STATUS_DMA;
 161         case 5: /* FD_DATA */
 162                 return sun_fdc->data_82077;
 163         case 7: /* FD_DIR */
 164                 /* Always return 0, the disk never changes
 165                  * without the kernel explicitly ejecting it.
 166                  */
 167                 return 0;
 168         };
 169         panic("sun_82072_fd_inb: How did I get here?");
 170 }
 171 
 172 static void sun_82077_fd_outb(unsigned char value, int port)
     /* [previous][next][first][last][top][bottom][index][help] */
 173 {
 174         switch(port & 7) {
 175         default:
 176                 printk("floppy: Asked to write to unknown port %d\n", port);
 177                 panic("floppy: Port bolixed.");
 178         case 2: /* FD_DOR */
 179                 /* Happily, the 82077 has a real DOR register. */
 180                 sun_fdc->dor_82077 = value;
 181                 break;
 182         case 5: /* FD_DATA */
 183                 sun_fdc->data_82077 = value;
 184                 break;
 185         case 7: /* FD_DCR */
 186                 sun_fdc->dcr_82077 = value;
 187                 break;
 188         case 4: /* FD_STATUS */
 189                 sun_fdc->status_82077 = value;
 190                 break;
 191         };
 192         return;
 193 }
 194 
 195 /* For pseudo-dma (Sun floppy drives have no real DMA available to
 196  * them so we must eat the data fifo bytes directly ourselves) we have
 197  * three state variables.  doing_pdma tells our inline low-level
 198  * assembly floppy interrupt entry point whether it should sit and eat
 199  * bytes from the fifo or just transfer control up to the higher level
 200  * floppy interrupt c-code.  I tried very hard but I could not get the
 201  * pseudo-dma to work in c-code without getting many overruns and
 202  * underruns.  If non-zero, doing_pdma encodes the direction of
 203  * the transfer for debugging.  1=read 2=write
 204  */
 205 char *pdma_vaddr;
 206 char *pdma_vsave;
 207 unsigned long pdma_size;
 208 int doing_pdma = 0;
 209 
 210 /* Common routines to all controller types on the Sparc. */
 211 static inline void virtual_dma_init(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 212 {
 213         /* nothing... */
 214 }
 215 
 216 static inline void sun_fd_disable_dma(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 217 {
 218         doing_pdma = 0;
 219 }
 220 
 221 static inline void sun_fd_set_dma_mode(int mode)
     /* [previous][next][first][last][top][bottom][index][help] */
 222 {
 223         switch(mode) {
 224         case DMA_MODE_READ:
 225                 doing_pdma = 1;
 226                 break;
 227         case DMA_MODE_WRITE:
 228                 doing_pdma = 2;
 229                 break;
 230         default:
 231                 printk("Unknown dma mode %d\n", mode);
 232                 panic("floppy: Giving up...");
 233         }
 234 }
 235 
 236 static inline void sun_fd_set_dma_addr(char *buffer)
     /* [previous][next][first][last][top][bottom][index][help] */
 237 {
 238         pdma_vaddr = buffer;
 239 }
 240 
 241 static inline void sun_fd_set_dma_count(int length)
     /* [previous][next][first][last][top][bottom][index][help] */
 242 {
 243         pdma_size = length;
 244 }
 245 
 246 static inline void sun_fd_enable_dma(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 247 {
 248         /* We're about to let it rip, lock any tlb entries necessary. */
 249         pdma_vaddr = pdma_vsave = mmu_lockarea(pdma_vaddr, pdma_size);
 250 }
 251 
 252 /* Our low-level entry point in arch/sparc/kernel/entry.S */
 253 extern void floppy_hardint(int irq, struct pt_regs *regs);
 254 
 255 static int sun_fd_request_irq(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 256 {
 257         static int once = 0;
 258         int error;
 259 
 260         if(!once) {
 261                 once = 1;
 262                 error = request_fast_irq(FLOPPY_IRQ, floppy_hardint, SA_INTERRUPT, "floppy");
 263                 return ((error == 0) ? 0 : -1);
 264         } else return 0;
 265 }
 266 
 267 static struct linux_prom_registers fd_regs[2];
 268 
 269 static int sun_floppy_init(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 270 {
 271         char state[128];
 272         int tnode, fd_node, num_regs;
 273 
 274         FLOPPY_IRQ = 11;
 275         /* Forget it if we aren't on a machine that could possibly
 276          * ever have a floppy drive.
 277          */
 278         if((sparc_cpu_model != sun4c && sparc_cpu_model != sun4m) ||
 279            ((idprom->id_machtype == (SM_SUN4C | SM_4C_SLC)) ||
 280             (idprom->id_machtype == (SM_SUN4C | SM_4C_ELC)))) {
 281                 /* We certainly don't have a floppy controller. */
 282                 goto no_sun_fdc;
 283         }
 284         /* Well, try and find one. */
 285         tnode = prom_getchild(prom_root_node);
 286         fd_node = prom_searchsiblings(tnode, "obio");
 287         if(fd_node != 0) {
 288                 tnode = prom_getchild(fd_node);
 289                 fd_node = prom_searchsiblings(tnode, "SUNW,fdtwo");
 290         } else {
 291                 fd_node = prom_searchsiblings(tnode, "fd");
 292         }
 293         if(fd_node == 0) {
 294                 goto no_sun_fdc;
 295         }
 296 
 297         /* The sun4m lets us know if the controller is actually usable. */
 298         if(sparc_cpu_model == sun4m) {
 299                 prom_getproperty(fd_node, "status", state, sizeof(state));
 300                 if(!strcmp(state, "disabled")) {
 301                         goto no_sun_fdc;
 302                 }
 303         }
 304         num_regs = prom_getproperty(fd_node, "reg", (char *) fd_regs, sizeof(fd_regs));
 305         num_regs = (num_regs / sizeof(fd_regs[0]));
 306         prom_apply_obio_ranges(fd_regs, num_regs);
 307         sun_fdc = (struct sun_flpy_controller *) sparc_alloc_io(fd_regs[0].phys_addr,
 308                                                                 0x0,
 309                                                                 fd_regs[0].reg_size,
 310                                                                 "floppy",
 311                                                                 fd_regs[0].which_io,
 312                                                                 0x0);
 313         /* Last minute sanity check... */
 314         if(sun_fdc->status_82072 == 0xff) {
 315                 sun_fdc = NULL;
 316                 goto no_sun_fdc;
 317         }
 318 
 319         /* We need the version as early as possible to set up the
 320          * function pointers correctly.  Assume 82077 for probing
 321          * purposes.
 322          */
 323         sun_fdops.fd_inb = sun_82077_fd_inb;
 324         sun_fdops.fd_outb = sun_82077_fd_outb;
 325         fdc_status = &sun_fdc->status_82077;
 326 
 327         /* This controller detection technique is from the netbsd
 328          * Sun floppy driver, origionally Chris Torek of BSDI came
 329          * up with this.  It seems to work pretty well.
 330          */
 331         if(sun_fdc->dor_82077 == 0x80) {
 332                 sun_fdc->dor_82077 = 2;
 333                 if(sun_fdc->dor_82077 == 0x80) {
 334                         /* Ok, it's really an 82072. */
 335                         sun_fdops.fd_inb = sun_82072_fd_inb;
 336                         sun_fdops.fd_outb = sun_82072_fd_outb;
 337                         fdc_status = &sun_fdc->status_82072;
 338                 }
 339         }
 340 
 341         /* P3: The only realiable way which I found for ejection
 342          * of boot floppy. AUXIO_FLPY_EJCT is not enougth alone.
 343          */
 344         set_auxio(AUXIO_FLPY_EJCT, 0);
 345         udelay(1000);
 346         set_auxio(AUXIO_FLPY_DSEL, AUXIO_FLPY_EJCT);
 347         udelay(1000);
 348         set_auxio(0, AUXIO_FLPY_DSEL);
 349 
 350         /* Success... */
 351         return (int) sun_fdc;
 352 
 353 no_sun_fdc:
 354         return -1;
 355 }
 356 
 357 #endif /* !(__ASM_SPARC_FLOPPY_H) */

/* [previous][next][first][last][top][bottom][index][help] */