macide.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. * 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/types.h>
  14. #include <linux/mm.h>
  15. #include <linux/interrupt.h>
  16. #include <linux/blkdev.h>
  17. #include <linux/delay.h>
  18. #include <linux/ide.h>
  19. #include <linux/module.h>
  20. #include <linux/platform_device.h>
  21. #include <asm/macintosh.h>
  22. #define DRV_NAME "mac_ide"
  23. #define IDE_BASE 0x50F1A000 /* Base address of IDE controller */
  24. /*
  25. * Generic IDE registers as offsets from the base
  26. * These match MkLinux so they should be correct.
  27. */
  28. #define IDE_CONTROL 0x38 /* control/altstatus */
  29. /*
  30. * Mac-specific registers
  31. */
  32. /*
  33. * this register is odd; it doesn't seem to do much and it's
  34. * not word-aligned like virtually every other hardware register
  35. * on the Mac...
  36. */
  37. #define IDE_IFR 0x101 /* (0x101) IDE interrupt flags on Quadra:
  38. *
  39. * Bit 0+1: some interrupt flags
  40. * Bit 2+3: some interrupt enable
  41. * Bit 4: ??
  42. * Bit 5: IDE interrupt flag (any hwif)
  43. * Bit 6: maybe IDE interrupt enable (any hwif) ??
  44. * Bit 7: Any interrupt condition
  45. */
  46. volatile unsigned char *ide_ifr = (unsigned char *) (IDE_BASE + IDE_IFR);
  47. int macide_test_irq(ide_hwif_t *hwif)
  48. {
  49. if (*ide_ifr & 0x20)
  50. return 1;
  51. return 0;
  52. }
  53. static void macide_clear_irq(ide_drive_t *drive)
  54. {
  55. *ide_ifr &= ~0x20;
  56. }
  57. static void __init macide_setup_ports(struct ide_hw *hw, unsigned long base,
  58. int irq)
  59. {
  60. int i;
  61. memset(hw, 0, sizeof(*hw));
  62. for (i = 0; i < 8; i++)
  63. hw->io_ports_array[i] = base + i * 4;
  64. hw->io_ports.ctl_addr = base + IDE_CONTROL;
  65. hw->irq = irq;
  66. }
  67. static const struct ide_port_ops macide_port_ops = {
  68. .clear_irq = macide_clear_irq,
  69. .test_irq = macide_test_irq,
  70. };
  71. static const struct ide_port_info macide_port_info = {
  72. .port_ops = &macide_port_ops,
  73. .host_flags = IDE_HFLAG_MMIO | IDE_HFLAG_NO_DMA,
  74. .irq_flags = IRQF_SHARED,
  75. .chipset = ide_generic,
  76. };
  77. static const char *mac_ide_name[] =
  78. { "Quadra", "Powerbook", "Powerbook Baboon" };
  79. /*
  80. * Probe for a Macintosh IDE interface
  81. */
  82. static int mac_ide_probe(struct platform_device *pdev)
  83. {
  84. struct resource *mem, *irq;
  85. struct ide_hw hw, *hws[] = { &hw };
  86. struct ide_port_info d = macide_port_info;
  87. struct ide_host *host;
  88. int rc;
  89. if (!MACH_IS_MAC)
  90. return -ENODEV;
  91. mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  92. if (!mem)
  93. return -ENODEV;
  94. irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  95. if (!irq)
  96. return -ENODEV;
  97. if (!devm_request_mem_region(&pdev->dev, mem->start,
  98. resource_size(mem), DRV_NAME)) {
  99. dev_err(&pdev->dev, "resources busy\n");
  100. return -EBUSY;
  101. }
  102. printk(KERN_INFO "ide: Macintosh %s IDE controller\n",
  103. mac_ide_name[macintosh_config->ide_type - 1]);
  104. macide_setup_ports(&hw, mem->start, irq->start);
  105. rc = ide_host_add(&d, hws, 1, &host);
  106. if (rc)
  107. return rc;
  108. platform_set_drvdata(pdev, host);
  109. return 0;
  110. }
  111. static int mac_ide_remove(struct platform_device *pdev)
  112. {
  113. struct ide_host *host = platform_get_drvdata(pdev);
  114. ide_host_remove(host);
  115. return 0;
  116. }
  117. static struct platform_driver mac_ide_driver = {
  118. .driver = {
  119. .name = DRV_NAME,
  120. },
  121. .probe = mac_ide_probe,
  122. .remove = mac_ide_remove,
  123. };
  124. module_platform_driver(mac_ide_driver);
  125. MODULE_ALIAS("platform:" DRV_NAME);
  126. MODULE_LICENSE("GPL");