1/* asm/floppy.h: Sparc specific parts of the Floppy driver. 2 * 3 * Copyright (C) 1995 David S. Miller (davem@davemloft.net) 4 */ 5 6#ifndef __ASM_SPARC_FLOPPY_H 7#define __ASM_SPARC_FLOPPY_H 8 9#include <linux/of.h> 10#include <linux/of_device.h> 11 12#include <asm/page.h> 13#include <asm/pgtable.h> 14#include <asm/system.h> 15#include <asm/idprom.h> 16#include <asm/machines.h> 17#include <asm/oplib.h> 18#include <asm/auxio.h> 19#include <asm/irq.h> 20 21/* We don't need no stinkin' I/O port allocation crap. */ 22#undef release_region 23#undef request_region 24#define release_region(X, Y) do { } while(0) 25#define request_region(X, Y, Z) (1) 26 27/* References: 28 * 1) Netbsd Sun floppy driver. 29 * 2) NCR 82077 controller manual 30 * 3) Intel 82077 controller manual 31 */ 32struct sun_flpy_controller { 33 volatile unsigned char status_82072; /* Main Status reg. */ 34#define dcr_82072 status_82072 /* Digital Control reg. */ 35#define status1_82077 status_82072 /* Auxiliary Status reg. 1 */ 36 37 volatile unsigned char data_82072; /* Data fifo. */ 38#define status2_82077 data_82072 /* Auxiliary Status reg. 2 */ 39 40 volatile unsigned char dor_82077; /* Digital Output reg. */ 41 volatile unsigned char tapectl_82077; /* What the? Tape control reg? */ 42 43 volatile unsigned char status_82077; /* Main Status Register. */ 44#define drs_82077 status_82077 /* Digital Rate Select reg. */ 45 46 volatile unsigned char data_82077; /* Data fifo. */ 47 volatile unsigned char ___unused; 48 volatile unsigned char dir_82077; /* Digital Input reg. */ 49#define dcr_82077 dir_82077 /* Config Control reg. */ 50}; 51 52/* You'll only ever find one controller on a SparcStation anyways. */ 53static struct sun_flpy_controller *sun_fdc = NULL; 54extern volatile unsigned char *fdc_status; 55 56struct sun_floppy_ops { 57 unsigned char (*fd_inb)(int port); 58 void (*fd_outb)(unsigned char value, int port); 59}; 60 61static struct sun_floppy_ops sun_fdops; 62 63#define fd_inb(port) sun_fdops.fd_inb(port) 64#define fd_outb(value,port) sun_fdops.fd_outb(value,port) 65#define fd_enable_dma() sun_fd_enable_dma() 66#define fd_disable_dma() sun_fd_disable_dma() 67#define fd_request_dma() (0) /* nothing... */ 68#define fd_free_dma() /* nothing... */ 69#define fd_clear_dma_ff() /* nothing... */ 70#define fd_set_dma_mode(mode) sun_fd_set_dma_mode(mode) 71#define fd_set_dma_addr(addr) sun_fd_set_dma_addr(addr) 72#define fd_set_dma_count(count) sun_fd_set_dma_count(count) 73#define fd_enable_irq() /* nothing... */ 74#define fd_disable_irq() /* nothing... */ 75#define fd_cacheflush(addr, size) /* nothing... */ 76#define fd_request_irq() sun_fd_request_irq() 77#define fd_free_irq() /* nothing... */ 78 79#define get_dma_residue(x) (0) 80 81#define FLOPPY0_TYPE 4 82#define FLOPPY1_TYPE 0 83 84/* Super paranoid... */ 85#undef HAVE_DISABLE_HLT 86 87/* Here is where we catch the floppy driver trying to initialize, 88 * therefore this is where we call the PROM device tree probing 89 * routine etc. on the Sparc. 90 */ 91#define FDC1 sun_floppy_init() 92 93#define N_FDC 1 94#define N_DRIVE 8 95 96/* No 64k boundary crossing problems on the Sparc. */ 97#define CROSS_64KB(a,s) (0) 98 99/* Routines unique to each controller type on a Sun. */ 100static void sun_set_dor(unsigned char value, int fdc_82077) 101{ 102 if (sparc_cpu_model == sun4c) { 103 unsigned int bits = 0; 104 if (value & 0x10) 105 bits |= AUXIO_FLPY_DSEL; 106 if ((value & 0x80) == 0) 107 bits |= AUXIO_FLPY_EJCT; 108 set_auxio(bits, (~bits) & (AUXIO_FLPY_DSEL|AUXIO_FLPY_EJCT)); 109 } 110 if (fdc_82077) { 111 sun_fdc->dor_82077 = value; 112 } 113} 114 115static unsigned char sun_read_dir(void) 116{ 117 if (sparc_cpu_model == sun4c) 118 return (get_auxio() & AUXIO_FLPY_DCHG) ? 0x80 : 0; 119 else 120 return sun_fdc->dir_82077; 121} 122 123static unsigned char sun_82072_fd_inb(int port) 124{ 125 udelay(5); 126 switch(port & 7) { 127 default: 128 printk("floppy: Asked to read unknown port %d\n", port); 129 panic("floppy: Port bolixed."); 130 case 4: /* FD_STATUS */ 131 return sun_fdc->status_82072 & ~STATUS_DMA; 132 case 5: /* FD_DATA */ 133 return sun_fdc->data_82072; 134 case 7: /* FD_DIR */ 135 return sun_read_dir(); 136 }; 137 panic("sun_82072_fd_inb: How did I get here?"); 138} 139 140static void sun_82072_fd_outb(unsigned char value, int port) 141{ 142 udelay(5); 143 switch(port & 7) { 144 default: 145 printk("floppy: Asked to write to unknown port %d\n", port); 146 panic("floppy: Port bolixed."); 147 case 2: /* FD_DOR */ 148 sun_set_dor(value, 0); 149 break; 150 case 5: /* FD_DATA */ 151 sun_fdc->data_82072 = value; 152 break; 153 case 7: /* FD_DCR */ 154 sun_fdc->dcr_82072 = value; 155 break; 156 case 4: /* FD_STATUS */ 157 sun_fdc->status_82072 = value; 158 break; 159 }; 160 return; 161} 162 163static unsigned char sun_82077_fd_inb(int port) 164{ 165 udelay(5); 166 switch(port & 7) { 167 default: 168 printk("floppy: Asked to read unknown port %d\n", port); 169 panic("floppy: Port bolixed."); 170 case 0: /* FD_STATUS_0 */ 171 return sun_fdc->status1_82077; 172 case 1: /* FD_STATUS_1 */ 173 return sun_fdc->status2_82077; 174 case 2: /* FD_DOR */ 175 return sun_fdc->dor_82077; 176 case 3: /* FD_TDR */ 177 return sun_fdc->tapectl_82077; 178 case 4: /* FD_STATUS */ 179 return sun_fdc->status_82077 & ~STATUS_DMA; 180 case 5: /* FD_DATA */ 181 return sun_fdc->data_82077; 182 case 7: /* FD_DIR */ 183 return sun_read_dir(); 184 }; 185 panic("sun_82077_fd_inb: How did I get here?"); 186} 187 188static void sun_82077_fd_outb(unsigned char value, int port) 189{ 190 udelay(5); 191 switch(port & 7) { 192 default: 193 printk("floppy: Asked to write to unknown port %d\n", port); 194 panic("floppy: Port bolixed."); 195 case 2: /* FD_DOR */ 196 sun_set_dor(value, 1); 197 break; 198 case 5: /* FD_DATA */ 199 sun_fdc->data_82077 = value; 200 break; 201 case 7: /* FD_DCR */ 202 sun_fdc->dcr_82077 = value; 203 break; 204 case 4: /* FD_STATUS */ 205 sun_fdc->status_82077 = value; 206 break; 207 case 3: /* FD_TDR */ 208 sun_fdc->tapectl_82077 = value; 209 break; 210 }; 211 return; 212} 213 214/* For pseudo-dma (Sun floppy drives have no real DMA available to 215 * them so we must eat the data fifo bytes directly ourselves) we have 216 * three state variables. doing_pdma tells our inline low-level 217 * assembly floppy interrupt entry point whether it should sit and eat 218 * bytes from the fifo or just transfer control up to the higher level 219 * floppy interrupt c-code. I tried very hard but I could not get the 220 * pseudo-dma to work in c-code without getting many overruns and 221 * underruns. If non-zero, doing_pdma encodes the direction of 222 * the transfer for debugging. 1=read 2=write 223 */ 224extern char *pdma_vaddr; 225extern unsigned long pdma_size; 226extern volatile int doing_pdma; 227 228/* This is software state */ 229extern char *pdma_base; 230extern unsigned long pdma_areasize; 231 232/* Common routines to all controller types on the Sparc. */ 233static inline void virtual_dma_init(void) 234{ 235 /* nothing... */ 236} 237 238static inline void sun_fd_disable_dma(void) 239{ 240 doing_pdma = 0; 241 if (pdma_base) { 242 mmu_unlockarea(pdma_base, pdma_areasize); 243 pdma_base = NULL; 244 } 245} 246 247static inline void sun_fd_set_dma_mode(int mode) 248{ 249 switch(mode) { 250 case DMA_MODE_READ: 251 doing_pdma = 1; 252 break; 253 case DMA_MODE_WRITE: 254 doing_pdma = 2; 255 break; 256 default: 257 printk("Unknown dma mode %d\n", mode); 258 panic("floppy: Giving up..."); 259 } 260} 261 262static inline void sun_fd_set_dma_addr(char *buffer) 263{ 264 pdma_vaddr = buffer; 265} 266 267static inline void sun_fd_set_dma_count(int length) 268{ 269 pdma_size = length; 270} 271 272static inline void sun_fd_enable_dma(void) 273{ 274 pdma_vaddr = mmu_lockarea(pdma_vaddr, pdma_size); 275 pdma_base = pdma_vaddr; 276 pdma_areasize = pdma_size; 277} 278 279/* Our low-level entry point in arch/sparc/kernel/entry.S */ 280extern int sparc_floppy_request_irq(int irq, unsigned long flags, 281 irq_handler_t irq_handler); 282 283static int sun_fd_request_irq(void) 284{ 285 static int once = 0; 286 int error; 287 288 if(!once) { 289 once = 1; 290 error = sparc_floppy_request_irq(FLOPPY_IRQ, 291 IRQF_DISABLED, 292 floppy_interrupt); 293 return ((error == 0) ? 0 : -1); 294 } else return 0; 295} 296 297static struct linux_prom_registers fd_regs[2]; 298 299static int sun_floppy_init(void) 300{ 301 char state[128]; 302 int tnode, fd_node, num_regs; 303 struct resource r; 304 305 use_virtual_dma = 1; 306 307 FLOPPY_IRQ = 11; 308 /* Forget it if we aren't on a machine that could possibly 309 * ever have a floppy drive. 310 */ 311 if((sparc_cpu_model != sun4c && sparc_cpu_model != sun4m) || 312 ((idprom->id_machtype == (SM_SUN4C | SM_4C_SLC)) || 313 (idprom->id_machtype == (SM_SUN4C | SM_4C_ELC)))) { 314 /* We certainly don't have a floppy controller. */ 315 goto no_sun_fdc; 316 } 317 /* Well, try to find one. */ 318 tnode = prom_getchild(prom_root_node); 319 fd_node = prom_searchsiblings(tnode, "obio"); 320 if(fd_node != 0) { 321 tnode = prom_getchild(fd_node); 322 fd_node = prom_searchsiblings(tnode, "SUNW,fdtwo"); 323 } else { 324 fd_node = prom_searchsiblings(tnode, "fd"); 325 } 326 if(fd_node == 0) { 327 goto no_sun_fdc; 328 } 329 330 /* The sun4m lets us know if the controller is actually usable. */ 331 if(sparc_cpu_model == sun4m && 332 prom_getproperty(fd_node, "status", state, sizeof(state)) != -1) { 333 if(!strcmp(state, "disabled")) { 334 goto no_sun_fdc; 335 } 336 } 337 num_regs = prom_getproperty(fd_node, "reg", (char *) fd_regs, sizeof(fd_regs)); 338 num_regs = (num_regs / sizeof(fd_regs[0])); 339 prom_apply_obio_ranges(fd_regs, num_regs); 340 memset(&r, 0, sizeof(r)); 341 r.flags = fd_regs[0].which_io; 342 r.start = fd_regs[0].phys_addr; 343 sun_fdc = (struct sun_flpy_controller *) 344 of_ioremap(&r, 0, fd_regs[0].reg_size, "floppy"); 345 346 /* Last minute sanity check... */ 347 if(sun_fdc->status_82072 == 0xff) { 348 sun_fdc = NULL; 349 goto no_sun_fdc; 350 } 351 352 sun_fdops.fd_inb = sun_82077_fd_inb; 353 sun_fdops.fd_outb = sun_82077_fd_outb; 354 fdc_status = &sun_fdc->status_82077; 355 356 if (sun_fdc->dor_82077 == 0x80) { 357 sun_fdc->dor_82077 = 0x02; 358 if (sun_fdc->dor_82077 == 0x80) { 359 sun_fdops.fd_inb = sun_82072_fd_inb; 360 sun_fdops.fd_outb = sun_82072_fd_outb; 361 fdc_status = &sun_fdc->status_82072; 362 } 363 } 364 365 /* Success... */ 366 allowed_drive_mask = 0x01; 367 return (int) sun_fdc; 368 369no_sun_fdc: 370 return -1; 371} 372 373static int sparc_eject(void) 374{ 375 set_dor(0x00, 0xff, 0x90); 376 udelay(500); 377 set_dor(0x00, 0x6f, 0x00); 378 udelay(500); 379 return 0; 380} 381 382#define fd_eject(drive) sparc_eject() 383 384#define EXTRA_FLOPPY_PARAMS 385 386static DEFINE_SPINLOCK(dma_spin_lock); 387 388#define claim_dma_lock() \ 389({ unsigned long flags; \ 390 spin_lock_irqsave(&dma_spin_lock, flags); \ 391 flags; \ 392}) 393 394#define release_dma_lock(__flags) \ 395 spin_unlock_irqrestore(&dma_spin_lock, __flags); 396 397#endif /* !(__ASM_SPARC_FLOPPY_H) */ 398