q40ide.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. * linux/drivers/ide/legacy/q40ide.c -- Q40 I/O port IDE Driver
  3. *
  4. * (c) Richard Zidlicky
  5. *
  6. * This file is subject to the terms and conditions of the GNU General Public
  7. * License. See the file COPYING in the main directory of this archive for
  8. * more details.
  9. *
  10. *
  11. */
  12. #include <linux/types.h>
  13. #include <linux/mm.h>
  14. #include <linux/interrupt.h>
  15. #include <linux/blkdev.h>
  16. #include <linux/hdreg.h>
  17. #include <linux/ide.h>
  18. /*
  19. * Bases of the IDE interfaces
  20. */
  21. #define Q40IDE_NUM_HWIFS 2
  22. #define PCIDE_BASE1 0x1f0
  23. #define PCIDE_BASE2 0x170
  24. #define PCIDE_BASE3 0x1e8
  25. #define PCIDE_BASE4 0x168
  26. #define PCIDE_BASE5 0x1e0
  27. #define PCIDE_BASE6 0x160
  28. static const unsigned long pcide_bases[Q40IDE_NUM_HWIFS] = {
  29. PCIDE_BASE1, PCIDE_BASE2, /* PCIDE_BASE3, PCIDE_BASE4 , PCIDE_BASE5,
  30. PCIDE_BASE6 */
  31. };
  32. /*
  33. * Offsets from one of the above bases
  34. */
  35. /* used to do addr translation here but it is easier to do in setup ports */
  36. /*#define IDE_OFF_B(x) ((unsigned long)Q40_ISA_IO_B((IDE_##x##_OFFSET)))*/
  37. #define IDE_OFF_B(x) ((unsigned long)((IDE_##x##_OFFSET)))
  38. #define IDE_OFF_W(x) ((unsigned long)((IDE_##x##_OFFSET)))
  39. static const int pcide_offsets[IDE_NR_PORTS] = {
  40. IDE_OFF_W(DATA), IDE_OFF_B(ERROR), IDE_OFF_B(NSECTOR), IDE_OFF_B(SECTOR),
  41. IDE_OFF_B(LCYL), IDE_OFF_B(HCYL), 6 /*IDE_OFF_B(CURRENT)*/, IDE_OFF_B(STATUS),
  42. 518/*IDE_OFF(CMD)*/
  43. };
  44. static int q40ide_default_irq(unsigned long base)
  45. {
  46. switch (base) {
  47. case 0x1f0: return 14;
  48. case 0x170: return 15;
  49. case 0x1e8: return 11;
  50. default:
  51. return 0;
  52. }
  53. }
  54. /*
  55. * This is very similar to ide_setup_ports except that addresses
  56. * are pretranslated for q40 ISA access
  57. */
  58. void q40_ide_setup_ports ( hw_regs_t *hw,
  59. unsigned long base, int *offsets,
  60. unsigned long ctrl, unsigned long intr,
  61. ide_ack_intr_t *ack_intr,
  62. /*
  63. * ide_io_ops_t *iops,
  64. */
  65. int irq)
  66. {
  67. int i;
  68. for (i = 0; i < IDE_NR_PORTS; i++) {
  69. /* BIG FAT WARNING:
  70. assumption: only DATA port is ever used in 16 bit mode */
  71. if ( i==0 )
  72. hw->io_ports[i] = Q40_ISA_IO_W(base + offsets[i]);
  73. else
  74. hw->io_ports[i] = Q40_ISA_IO_B(base + offsets[i]);
  75. }
  76. hw->irq = irq;
  77. hw->dma = NO_DMA;
  78. hw->ack_intr = ack_intr;
  79. /*
  80. * hw->iops = iops;
  81. */
  82. }
  83. /*
  84. * the static array is needed to have the name reported in /proc/ioports,
  85. * hwif->name unfortunately isn´t available yet
  86. */
  87. static const char *q40_ide_names[Q40IDE_NUM_HWIFS]={
  88. "ide0", "ide1"
  89. };
  90. /*
  91. * Probe for Q40 IDE interfaces
  92. */
  93. void q40ide_init(void)
  94. {
  95. int i;
  96. ide_hwif_t *hwif;
  97. int index;
  98. const char *name;
  99. if (!MACH_IS_Q40)
  100. return ;
  101. for (i = 0; i < Q40IDE_NUM_HWIFS; i++) {
  102. hw_regs_t hw;
  103. name = q40_ide_names[i];
  104. if (!request_region(pcide_bases[i], 8, name)) {
  105. printk("could not reserve ports %lx-%lx for %s\n",
  106. pcide_bases[i],pcide_bases[i]+8,name);
  107. continue;
  108. }
  109. if (!request_region(pcide_bases[i]+0x206, 1, name)) {
  110. printk("could not reserve port %lx for %s\n",
  111. pcide_bases[i]+0x206,name);
  112. release_region(pcide_bases[i], 8);
  113. continue;
  114. }
  115. q40_ide_setup_ports(&hw,(unsigned long) pcide_bases[i], (int *)pcide_offsets,
  116. pcide_bases[i]+0x206,
  117. 0, NULL,
  118. // m68kide_iops,
  119. q40ide_default_irq(pcide_bases[i]));
  120. index = ide_register_hw(&hw, &hwif);
  121. // **FIXME**
  122. if (index != -1)
  123. hwif->mmio = 2;
  124. }
  125. }