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