cf-enabler.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /* $Id: cf-enabler.c,v 1.4 2004/02/22 22:44:36 kkojima Exp $
  2. *
  3. * linux/drivers/block/cf-enabler.c
  4. *
  5. * Copyright (C) 1999 Niibe Yutaka
  6. * Copyright (C) 2000 Toshiharu Nozawa
  7. * Copyright (C) 2001 A&D Co., Ltd.
  8. *
  9. * Enable the CF configuration.
  10. */
  11. #include <linux/init.h>
  12. #include <linux/mm.h>
  13. #include <linux/vmalloc.h>
  14. #include <asm/io.h>
  15. #include <asm/irq.h>
  16. /*
  17. * You can connect Compact Flash directly to the bus of SuperH.
  18. * This is the enabler for that.
  19. *
  20. * SIM: How generic is this really? It looks pretty board, or at
  21. * least SH sub-type, specific to me.
  22. * I know it doesn't work on the Overdrive!
  23. */
  24. /*
  25. * 0xB8000000 : Attribute
  26. * 0xB8001000 : Common Memory
  27. * 0xBA000000 : I/O
  28. */
  29. #if defined(CONFIG_IDE) && defined(CONFIG_CPU_SH4)
  30. /* SH4 can't access PCMCIA interface through P2 area.
  31. * we must remap it with appropreate attribute bit of the page set.
  32. * this part is based on Greg Banks' hd64465_ss.c implementation - Masahiro Abe */
  33. #if defined(CONFIG_CF_AREA6)
  34. #define slot_no 0
  35. #else
  36. #define slot_no 1
  37. #endif
  38. /* use this pointer to access to directly connected compact flash io area*/
  39. void *cf_io_base;
  40. static int __init allocate_cf_area(void)
  41. {
  42. pgprot_t prot;
  43. unsigned long paddrbase, psize;
  44. /* open I/O area window */
  45. paddrbase = virt_to_phys((void*)CONFIG_CF_BASE_ADDR);
  46. psize = PAGE_SIZE;
  47. prot = PAGE_KERNEL_PCC(slot_no, _PAGE_PCC_IO16);
  48. cf_io_base = p3_ioremap(paddrbase, psize, prot.pgprot);
  49. if (!cf_io_base) {
  50. printk("allocate_cf_area : can't open CF I/O window!\n");
  51. return -ENOMEM;
  52. }
  53. /* printk("p3_ioremap(paddr=0x%08lx, psize=0x%08lx, prot=0x%08lx)=0x%08lx\n",
  54. paddrbase, psize, prot.pgprot, cf_io_base);*/
  55. /* XXX : do we need attribute and common-memory area also? */
  56. return 0;
  57. }
  58. #endif
  59. static int __init cf_init_default(void)
  60. {
  61. /* You must have enabled the card, and set the level interrupt
  62. * before reaching this point. Possibly in boot ROM or boot loader.
  63. */
  64. #if defined(CONFIG_IDE) && defined(CONFIG_CPU_SH4)
  65. allocate_cf_area();
  66. #endif
  67. #if defined(CONFIG_SH_UNKNOWN)
  68. /* This should be done in each board's init_xxx_irq. */
  69. make_imask_irq(14);
  70. disable_irq(14);
  71. #endif
  72. return 0;
  73. }
  74. #if defined(CONFIG_SH_SOLUTION_ENGINE)
  75. #include <asm/se.h>
  76. /*
  77. * SolutionEngine
  78. *
  79. * 0xB8400000 : Common Memory
  80. * 0xB8500000 : Attribute
  81. * 0xB8600000 : I/O
  82. */
  83. static int __init cf_init_se(void)
  84. {
  85. if ((ctrl_inw(MRSHPC_CSR) & 0x000c) != 0)
  86. return 0; /* Not detected */
  87. if ((ctrl_inw(MRSHPC_CSR) & 0x0080) == 0) {
  88. ctrl_outw(0x0674, MRSHPC_CPWCR); /* Card Vcc is 3.3v? */
  89. } else {
  90. ctrl_outw(0x0678, MRSHPC_CPWCR); /* Card Vcc is 5V */
  91. }
  92. /*
  93. * PC-Card window open
  94. * flag == COMMON/ATTRIBUTE/IO
  95. */
  96. /* common window open */
  97. ctrl_outw(0x8a84, MRSHPC_MW0CR1);/* window 0xb8400000 */
  98. if((ctrl_inw(MRSHPC_CSR) & 0x4000) != 0)
  99. /* common mode & bus width 16bit SWAP = 1*/
  100. ctrl_outw(0x0b00, MRSHPC_MW0CR2);
  101. else
  102. /* common mode & bus width 16bit SWAP = 0*/
  103. ctrl_outw(0x0300, MRSHPC_MW0CR2);
  104. /* attribute window open */
  105. ctrl_outw(0x8a85, MRSHPC_MW1CR1);/* window 0xb8500000 */
  106. if ((ctrl_inw(MRSHPC_CSR) & 0x4000) != 0)
  107. /* attribute mode & bus width 16bit SWAP = 1*/
  108. ctrl_outw(0x0a00, MRSHPC_MW1CR2);
  109. else
  110. /* attribute mode & bus width 16bit SWAP = 0*/
  111. ctrl_outw(0x0200, MRSHPC_MW1CR2);
  112. /* I/O window open */
  113. ctrl_outw(0x8a86, MRSHPC_IOWCR1);/* I/O window 0xb8600000 */
  114. ctrl_outw(0x0008, MRSHPC_CDCR); /* I/O card mode */
  115. if ((ctrl_inw(MRSHPC_CSR) & 0x4000) != 0)
  116. ctrl_outw(0x0a00, MRSHPC_IOWCR2); /* bus width 16bit SWAP = 1*/
  117. else
  118. ctrl_outw(0x0200, MRSHPC_IOWCR2); /* bus width 16bit SWAP = 0*/
  119. ctrl_outw(0x2000, MRSHPC_ICR);
  120. ctrl_outb(0x00, PA_MRSHPC_MW2 + 0x206);
  121. ctrl_outb(0x42, PA_MRSHPC_MW2 + 0x200);
  122. return 0;
  123. }
  124. #endif
  125. int __init cf_init(void)
  126. {
  127. #if defined(CONFIG_SH_SOLUTION_ENGINE)
  128. if (MACH_SE)
  129. return cf_init_se();
  130. #endif
  131. return cf_init_default();
  132. }
  133. __initcall (cf_init);