9 #ifndef __ASM_SPARC64_FLOPPY_H
10 #define __ASM_SPARC64_FLOPPY_H
22 #undef PCI_FDC_SWAP_DRIVES
36 #define drs_82077 status_82077
40 #define dcr_82077 dir_82077
64 #define fd_inb(port) sun_fdops.fd_inb(port)
65 #define fd_outb(value,port) sun_fdops.fd_outb(value,port)
66 #define fd_enable_dma() sun_fdops.fd_enable_dma()
67 #define fd_disable_dma() sun_fdops.fd_disable_dma()
68 #define fd_request_dma() (0)
70 #define fd_clear_dma_ff()
71 #define fd_set_dma_mode(mode) sun_fdops.fd_set_dma_mode(mode)
72 #define fd_set_dma_addr(addr) sun_fdops.fd_set_dma_addr(addr)
73 #define fd_set_dma_count(count) sun_fdops.fd_set_dma_count(count)
74 #define get_dma_residue(x) sun_fdops.get_dma_residue()
75 #define fd_cacheflush(addr, size)
76 #define fd_request_irq() sun_fdops.fd_request_irq()
77 #define fd_free_irq() sun_fdops.fd_free_irq()
78 #define fd_eject(drive) sun_fdops.fd_eject(drive)
81 #undef HAVE_DISABLE_HLT
83 static int sun_floppy_types[2] = { 0, 0 };
89 #define FLOPPY0_TYPE sun_floppy_init()
90 #define FLOPPY1_TYPE sun_floppy_types[1]
92 #define FDC1 ((unsigned long)sun_fdc)
98 #define CROSS_64KB(a,s) (0)
100 static unsigned char sun_82077_fd_inb(
unsigned long port)
105 printk(
"floppy: Asked to read unknown port %lx\n", port);
106 panic(
"floppy: Port bolixed.");
115 panic(
"sun_82072_fd_inb: How did I get here?");
118 static void sun_82077_fd_outb(
unsigned char value,
unsigned long port)
123 printk(
"floppy: Asked to write to unknown port %lx\n", port);
124 panic(
"floppy: Port bolixed.");
161 static void sun_fd_disable_dma(
void)
167 static void sun_fd_set_dma_mode(
int mode)
177 printk(
"Unknown dma mode %d\n", mode);
178 panic(
"floppy: Giving up...");
182 static void sun_fd_set_dma_addr(
char *
buffer)
187 static void sun_fd_set_dma_count(
int length)
192 static void sun_fd_enable_dma(
void)
221 *vaddr++ =
readb(stat + 1);
223 unsigned char data = *vaddr++;
248 static int sun_fd_request_irq(
void)
259 return ((error == 0) ? 0 : -1);
264 static void sun_fd_free_irq(
void)
268 static unsigned int sun_get_dma_residue(
void)
274 static int sun_fd_eject(
int drive)
276 set_dor(0x00, 0xff, 0x90);
278 set_dor(0x00, 0x6f, 0x00);
287 static struct device *sun_floppy_dev;
288 static int sun_pci_broken_drive = -1;
301 static unsigned char sun_pci_fd_inb(
unsigned long port)
307 static void sun_pci_fd_outb(
unsigned char val,
unsigned long port)
313 static void sun_pci_fd_broken_outb(
unsigned char val,
unsigned long port)
323 if (port == ((
unsigned long)sun_fdc) + 2) {
324 if (((val & 0x03) == sun_pci_broken_drive) && (val & 0x20)) {
331 #ifdef PCI_FDC_SWAP_DRIVES
332 static void sun_pci_fd_lde_broken_outb(
unsigned char val,
unsigned long port)
342 if (port == ((
unsigned long)sun_fdc) + 2) {
343 if (((val & 0x03) == sun_pci_broken_drive) && (val & 0x10)) {
352 static void sun_pci_fd_enable_dma(
void)
355 (0 == sun_pci_dma_pending.
len) ||
358 sun_pci_dma_current.
buf = sun_pci_dma_pending.
buf;
359 sun_pci_dma_current.
len = sun_pci_dma_pending.
len;
362 sun_pci_dma_pending.
buf =
NULL;
363 sun_pci_dma_pending.
len = 0;
365 sun_pci_dma_pending.
addr = -1
U;
367 sun_pci_dma_current.
addr =
369 sun_pci_dma_current.
buf,
370 sun_pci_dma_current.
len,
376 sun_pci_dma_current.
addr,
377 sun_pci_dma_current.
len))
381 static void sun_pci_fd_disable_dma(
void)
384 if (sun_pci_dma_current.
addr != -1
U)
386 sun_pci_dma_current.
addr,
387 sun_pci_dma_current.
len,
389 sun_pci_dma_current.
addr = -1
U;
392 static void sun_pci_fd_set_dma_mode(
int mode)
402 static void sun_pci_fd_set_dma_count(
int length)
407 static void sun_pci_fd_set_dma_addr(
char *
buffer)
412 static unsigned int sun_pci_get_dma_residue(
void)
417 static int sun_pci_fd_request_irq(
void)
422 static void sun_pci_fd_free_irq(
void)
427 static int sun_pci_fd_eject(
int drive)
442 #define DOR (port + 2)
443 #define MSR (port + 4)
444 #define FIFO (port + 5)
446 static void sun_pci_fd_out_byte(
unsigned long port,
unsigned char val,
452 while (!((status =
inb(
MSR)) & 0x80) && --timeout)
457 static unsigned char sun_pci_fd_sensei(
unsigned long port)
459 unsigned char result[2] = { 0x70, 0x00 };
463 sun_pci_fd_out_byte(port, 0x08,
FIFO);
467 while (!((status =
inb(
MSR)) & 0x80) && --timeout)
473 if ((status & 0xf0) == 0xd0)
482 static void sun_pci_fd_reset(
unsigned long port)
484 unsigned char mask = 0x00;
490 status = sun_pci_fd_sensei(port);
491 if ((status & 0xc0) == 0xc0)
492 mask |= 1 << (status & 0x03);
495 }
while ((mask != 0x0f) && --timeout);
498 static int sun_pci_fd_test_drive(
unsigned long port,
int drive)
504 sun_pci_fd_reset(port);
506 data = (0x10 << drive) | 0x0c | drive;
507 sun_pci_fd_out_byte(port, data,
DOR);
509 sun_pci_fd_out_byte(port, 0x07,
FIFO);
510 sun_pci_fd_out_byte(port, drive & 0x03,
FIFO);
514 status = sun_pci_fd_sensei(port);
515 }
while (((status & 0xc0) == 0x80) && --timeout);
520 ready = (status & 0x10) ? 0 : 1;
522 sun_pci_fd_reset(port);
537 if (compat && !
strcmp(compat,
"fdthree"))
543 static unsigned long __init sun_floppy_init(
void)
552 return sun_floppy_types[0];
557 for_each_node_by_name(dp,
"SUNW,fdtwo") {
570 const char *state_prop;
574 for_each_node_by_name(ebus_dp,
"ebus") {
576 if (ebus_fdthree_p(dp))
589 if (state_prop && !
strncmp(state_prop,
"disabled", 8))
600 sun_floppy_dev = &op->
dev;
605 sun_pci_fd_ebus_dma.regs = (
void __iomem *)
607 if (!sun_pci_fd_ebus_dma.regs)
613 sun_pci_fd_ebus_dma.client_cookie =
NULL;
614 sun_pci_fd_ebus_dma.irq = FLOPPY_IRQ;
615 strcpy(sun_pci_fd_ebus_dma.name,
"floppy");
622 sun_fdops.fd_inb = sun_pci_fd_inb;
623 sun_fdops.fd_outb = sun_pci_fd_outb;
625 can_use_virtual_dma = use_virtual_dma = 0;
626 sun_fdops.fd_enable_dma = sun_pci_fd_enable_dma;
627 sun_fdops.fd_disable_dma = sun_pci_fd_disable_dma;
628 sun_fdops.fd_set_dma_mode = sun_pci_fd_set_dma_mode;
629 sun_fdops.fd_set_dma_addr = sun_pci_fd_set_dma_addr;
630 sun_fdops.fd_set_dma_count = sun_pci_fd_set_dma_count;
631 sun_fdops.get_dma_residue = sun_pci_get_dma_residue;
633 sun_fdops.fd_request_irq = sun_pci_fd_request_irq;
634 sun_fdops.fd_free_irq = sun_pci_fd_free_irq;
636 sun_fdops.fd_eject = sun_pci_fd_eject;
638 fdc_status = (
unsigned long) &sun_fdc->status_82077;
644 sun_pci_broken_drive = 1;
645 sun_fdops.fd_outb = sun_pci_fd_broken_outb;
648 allowed_drive_mask = 0;
649 if (sun_pci_fd_test_drive((
unsigned long)sun_fdc, 0))
650 sun_floppy_types[0] = 4;
651 if (sun_pci_fd_test_drive((
unsigned long)sun_fdc, 1))
652 sun_floppy_types[1] = 4;
664 config = ecpp_op->
resource[1].start;
673 switch (config & 0x3ff) {
684 return sun_floppy_types[0];
687 ns87303_modify(config,
ASC, 0, 0xc0);
689 #ifdef PCI_FDC_SWAP_DRIVES
693 if (!sun_floppy_types[0] && sun_floppy_types[1]) {
702 config = sun_floppy_types[0];
703 sun_floppy_types[0] = sun_floppy_types[1];
704 sun_floppy_types[1] =
config;
706 if (sun_pci_broken_drive != -1) {
707 sun_pci_broken_drive = 1 - sun_pci_broken_drive;
708 sun_fdops.fd_outb = sun_pci_fd_lde_broken_outb;
713 return sun_floppy_types[0];
716 if (prop && !
strncmp(state,
"disabled", 8))
730 if (
sbus_readb(&sun_fdc->status1_82077) == 0xff) {
735 sun_fdops.fd_inb = sun_82077_fd_inb;
736 sun_fdops.fd_outb = sun_82077_fd_outb;
738 can_use_virtual_dma = use_virtual_dma = 1;
739 sun_fdops.fd_enable_dma = sun_fd_enable_dma;
740 sun_fdops.fd_disable_dma = sun_fd_disable_dma;
741 sun_fdops.fd_set_dma_mode = sun_fd_set_dma_mode;
742 sun_fdops.fd_set_dma_addr = sun_fd_set_dma_addr;
743 sun_fdops.fd_set_dma_count = sun_fd_set_dma_count;
744 sun_fdops.get_dma_residue = sun_get_dma_residue;
746 sun_fdops.fd_request_irq = sun_fd_request_irq;
747 sun_fdops.fd_free_irq = sun_fd_free_irq;
749 sun_fdops.fd_eject = sun_fd_eject;
754 allowed_drive_mask = 0x01;
755 sun_floppy_types[0] = 4;
756 sun_floppy_types[1] = 0;
758 return sun_floppy_types[0];
761 #define EXTRA_FLOPPY_PARAMS
765 #define claim_dma_lock() \
766 ({ unsigned long flags; \
767 spin_lock_irqsave(&dma_spin_lock, flags); \
771 #define release_dma_lock(__flags) \
772 spin_unlock_irqrestore(&dma_spin_lock, __flags);