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