q40ide.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*
  2. * 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. * Addresses are pretranslated for Q40 ISA access.
  56. */
  57. void q40_ide_setup_ports ( hw_regs_t *hw,
  58. unsigned long base, int *offsets,
  59. unsigned long ctrl, unsigned long intr,
  60. ide_ack_intr_t *ack_intr,
  61. int irq)
  62. {
  63. int i;
  64. memset(hw, 0, sizeof(hw_regs_t));
  65. for (i = 0; i < IDE_NR_PORTS; i++) {
  66. /* BIG FAT WARNING:
  67. assumption: only DATA port is ever used in 16 bit mode */
  68. if ( i==0 )
  69. hw->io_ports[i] = Q40_ISA_IO_W(base + offsets[i]);
  70. else
  71. hw->io_ports[i] = Q40_ISA_IO_B(base + offsets[i]);
  72. }
  73. hw->irq = irq;
  74. hw->ack_intr = ack_intr;
  75. }
  76. /*
  77. * the static array is needed to have the name reported in /proc/ioports,
  78. * hwif->name unfortunately isn't available yet
  79. */
  80. static const char *q40_ide_names[Q40IDE_NUM_HWIFS]={
  81. "ide0", "ide1"
  82. };
  83. /*
  84. * Probe for Q40 IDE interfaces
  85. */
  86. static int __init q40ide_init(void)
  87. {
  88. int i;
  89. ide_hwif_t *hwif;
  90. const char *name;
  91. u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
  92. if (!MACH_IS_Q40)
  93. return -ENODEV;
  94. printk(KERN_INFO "ide: Q40 IDE controller\n");
  95. for (i = 0; i < Q40IDE_NUM_HWIFS; i++) {
  96. hw_regs_t hw;
  97. name = q40_ide_names[i];
  98. if (!request_region(pcide_bases[i], 8, name)) {
  99. printk("could not reserve ports %lx-%lx for %s\n",
  100. pcide_bases[i],pcide_bases[i]+8,name);
  101. continue;
  102. }
  103. if (!request_region(pcide_bases[i]+0x206, 1, name)) {
  104. printk("could not reserve port %lx for %s\n",
  105. pcide_bases[i]+0x206,name);
  106. release_region(pcide_bases[i], 8);
  107. continue;
  108. }
  109. q40_ide_setup_ports(&hw,(unsigned long) pcide_bases[i], (int *)pcide_offsets,
  110. pcide_bases[i]+0x206,
  111. 0, NULL,
  112. // m68kide_iops,
  113. q40ide_default_irq(pcide_bases[i]));
  114. hwif = ide_find_port();
  115. if (hwif) {
  116. ide_init_port_data(hwif, hwif->index);
  117. ide_init_port_hw(hwif, &hw);
  118. hwif->mmio = 1;
  119. idx[i] = hwif->index;
  120. }
  121. }
  122. ide_device_add(idx, NULL);
  123. return 0;
  124. }
  125. module_init(q40ide_init);
  126. MODULE_LICENSE("GPL");