macide.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*
  2. * linux/drivers/ide/legacy/macide.c -- Macintosh IDE Driver
  3. *
  4. * Copyright (C) 1998 by Michael Schmitz
  5. *
  6. * This driver was written based on information obtained from the MacOS IDE
  7. * driver binary by Mikael Forselius
  8. *
  9. * This file is subject to the terms and conditions of the GNU General Public
  10. * License. See the file COPYING in the main directory of this archive for
  11. * more details.
  12. */
  13. #include <linux/config.h>
  14. #include <linux/types.h>
  15. #include <linux/mm.h>
  16. #include <linux/interrupt.h>
  17. #include <linux/blkdev.h>
  18. #include <linux/hdreg.h>
  19. #include <linux/delay.h>
  20. #include <linux/ide.h>
  21. #include <asm/machw.h>
  22. #include <asm/macintosh.h>
  23. #include <asm/macints.h>
  24. #include <asm/mac_baboon.h>
  25. #define IDE_BASE 0x50F1A000 /* Base address of IDE controller */
  26. /*
  27. * Generic IDE registers as offsets from the base
  28. * These match MkLinux so they should be correct.
  29. */
  30. #define IDE_DATA 0x00
  31. #define IDE_ERROR 0x04 /* see err-bits */
  32. #define IDE_NSECTOR 0x08 /* nr of sectors to read/write */
  33. #define IDE_SECTOR 0x0c /* starting sector */
  34. #define IDE_LCYL 0x10 /* starting cylinder */
  35. #define IDE_HCYL 0x14 /* high byte of starting cyl */
  36. #define IDE_SELECT 0x18 /* 101dhhhh , d=drive, hhhh=head */
  37. #define IDE_STATUS 0x1c /* see status-bits */
  38. #define IDE_CONTROL 0x38 /* control/altstatus */
  39. /*
  40. * Mac-specific registers
  41. */
  42. /*
  43. * this register is odd; it doesn't seem to do much and it's
  44. * not word-aligned like virtually every other hardware register
  45. * on the Mac...
  46. */
  47. #define IDE_IFR 0x101 /* (0x101) IDE interrupt flags on Quadra:
  48. *
  49. * Bit 0+1: some interrupt flags
  50. * Bit 2+3: some interrupt enable
  51. * Bit 4: ??
  52. * Bit 5: IDE interrupt flag (any hwif)
  53. * Bit 6: maybe IDE interrupt enable (any hwif) ??
  54. * Bit 7: Any interrupt condition
  55. */
  56. volatile unsigned char *ide_ifr = (unsigned char *) (IDE_BASE + IDE_IFR);
  57. static int macide_offsets[IDE_NR_PORTS] = {
  58. IDE_DATA, IDE_ERROR, IDE_NSECTOR, IDE_SECTOR, IDE_LCYL,
  59. IDE_HCYL, IDE_SELECT, IDE_STATUS, IDE_CONTROL
  60. };
  61. int macide_ack_intr(ide_hwif_t* hwif)
  62. {
  63. if (*ide_ifr & 0x20) {
  64. *ide_ifr &= ~0x20;
  65. return 1;
  66. }
  67. return 0;
  68. }
  69. #ifdef CONFIG_BLK_DEV_MAC_MEDIABAY
  70. static void macide_mediabay_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  71. {
  72. int state = baboon->mb_status & 0x04;
  73. printk(KERN_INFO "macide: media bay %s detected\n", state? "removal":"insertion");
  74. }
  75. #endif
  76. /*
  77. * Probe for a Macintosh IDE interface
  78. */
  79. void macide_init(void)
  80. {
  81. hw_regs_t hw;
  82. ide_hwif_t *hwif;
  83. int index = -1;
  84. switch (macintosh_config->ide_type) {
  85. case MAC_IDE_QUADRA:
  86. ide_setup_ports(&hw, IDE_BASE, macide_offsets,
  87. 0, 0, macide_ack_intr,
  88. // quadra_ide_iops,
  89. IRQ_NUBUS_F);
  90. index = ide_register_hw(&hw, &hwif);
  91. break;
  92. case MAC_IDE_PB:
  93. ide_setup_ports(&hw, IDE_BASE, macide_offsets,
  94. 0, 0, macide_ack_intr,
  95. // macide_pb_iops,
  96. IRQ_NUBUS_C);
  97. index = ide_register_hw(&hw, &hwif);
  98. break;
  99. case MAC_IDE_BABOON:
  100. ide_setup_ports(&hw, BABOON_BASE, macide_offsets,
  101. 0, 0, NULL,
  102. // macide_baboon_iops,
  103. IRQ_BABOON_1);
  104. index = ide_register_hw(&hw, &hwif);
  105. if (index == -1) break;
  106. if (macintosh_config->ident == MAC_MODEL_PB190) {
  107. /* Fix breakage in ide-disk.c: drive capacity */
  108. /* is not initialized for drives without a */
  109. /* hardware ID, and we can't get that without */
  110. /* probing the drive which freezes a 190. */
  111. ide_drive_t *drive = &ide_hwifs[index].drives[0];
  112. drive->capacity64 = drive->cyl*drive->head*drive->sect;
  113. #ifdef CONFIG_BLK_DEV_MAC_MEDIABAY
  114. request_irq(IRQ_BABOON_2, macide_mediabay_interrupt,
  115. IRQ_FLG_FAST, "mediabay",
  116. macide_mediabay_interrupt);
  117. #endif
  118. }
  119. break;
  120. default:
  121. return;
  122. }
  123. if (index != -1) {
  124. hwif->mmio = 2;
  125. if (macintosh_config->ide_type == MAC_IDE_QUADRA)
  126. printk(KERN_INFO "ide%d: Macintosh Quadra IDE interface\n", index);
  127. else if (macintosh_config->ide_type == MAC_IDE_PB)
  128. printk(KERN_INFO "ide%d: Macintosh Powerbook IDE interface\n", index);
  129. else if (macintosh_config->ide_type == MAC_IDE_BABOON)
  130. printk(KERN_INFO "ide%d: Macintosh Powerbook Baboon IDE interface\n", index);
  131. else
  132. printk(KERN_INFO "ide%d: Unknown Macintosh IDE interface\n", index);
  133. }
  134. }