common.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. /*
  2. * linux/arch/arm/mach-footbridge/common.c
  3. *
  4. * Copyright (C) 1998-2000 Russell King, Dave Gilbert.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #include <linux/module.h>
  11. #include <linux/types.h>
  12. #include <linux/mm.h>
  13. #include <linux/ioport.h>
  14. #include <linux/list.h>
  15. #include <linux/init.h>
  16. #include <linux/io.h>
  17. #include <linux/spinlock.h>
  18. #include <asm/pgtable.h>
  19. #include <asm/page.h>
  20. #include <asm/irq.h>
  21. #include <asm/mach-types.h>
  22. #include <asm/setup.h>
  23. #include <asm/hardware/dec21285.h>
  24. #include <asm/mach/irq.h>
  25. #include <asm/mach/map.h>
  26. #include "common.h"
  27. unsigned int mem_fclk_21285 = 50000000;
  28. EXPORT_SYMBOL(mem_fclk_21285);
  29. static int __init early_fclk(char *arg)
  30. {
  31. mem_fclk_21285 = simple_strtoul(arg, NULL, 0);
  32. return 0;
  33. }
  34. early_param("mem_fclk_21285", early_fclk);
  35. static int __init parse_tag_memclk(const struct tag *tag)
  36. {
  37. mem_fclk_21285 = tag->u.memclk.fmemclk;
  38. return 0;
  39. }
  40. __tagtable(ATAG_MEMCLK, parse_tag_memclk);
  41. /*
  42. * Footbridge IRQ translation table
  43. * Converts from our IRQ numbers into FootBridge masks
  44. */
  45. static const int fb_irq_mask[] = {
  46. IRQ_MASK_UART_RX, /* 0 */
  47. IRQ_MASK_UART_TX, /* 1 */
  48. IRQ_MASK_TIMER1, /* 2 */
  49. IRQ_MASK_TIMER2, /* 3 */
  50. IRQ_MASK_TIMER3, /* 4 */
  51. IRQ_MASK_IN0, /* 5 */
  52. IRQ_MASK_IN1, /* 6 */
  53. IRQ_MASK_IN2, /* 7 */
  54. IRQ_MASK_IN3, /* 8 */
  55. IRQ_MASK_DOORBELLHOST, /* 9 */
  56. IRQ_MASK_DMA1, /* 10 */
  57. IRQ_MASK_DMA2, /* 11 */
  58. IRQ_MASK_PCI, /* 12 */
  59. IRQ_MASK_SDRAMPARITY, /* 13 */
  60. IRQ_MASK_I2OINPOST, /* 14 */
  61. IRQ_MASK_PCI_ABORT, /* 15 */
  62. IRQ_MASK_PCI_SERR, /* 16 */
  63. IRQ_MASK_DISCARD_TIMER, /* 17 */
  64. IRQ_MASK_PCI_DPERR, /* 18 */
  65. IRQ_MASK_PCI_PERR, /* 19 */
  66. };
  67. static void fb_mask_irq(struct irq_data *d)
  68. {
  69. *CSR_IRQ_DISABLE = fb_irq_mask[_DC21285_INR(d->irq)];
  70. }
  71. static void fb_unmask_irq(struct irq_data *d)
  72. {
  73. *CSR_IRQ_ENABLE = fb_irq_mask[_DC21285_INR(d->irq)];
  74. }
  75. static struct irq_chip fb_chip = {
  76. .irq_ack = fb_mask_irq,
  77. .irq_mask = fb_mask_irq,
  78. .irq_unmask = fb_unmask_irq,
  79. };
  80. static void __init __fb_init_irq(void)
  81. {
  82. unsigned int irq;
  83. /*
  84. * setup DC21285 IRQs
  85. */
  86. *CSR_IRQ_DISABLE = -1;
  87. *CSR_FIQ_DISABLE = -1;
  88. for (irq = _DC21285_IRQ(0); irq < _DC21285_IRQ(20); irq++) {
  89. irq_set_chip_and_handler(irq, &fb_chip, handle_level_irq);
  90. set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
  91. }
  92. }
  93. void __init footbridge_init_irq(void)
  94. {
  95. __fb_init_irq();
  96. if (!footbridge_cfn_mode())
  97. return;
  98. if (machine_is_ebsa285())
  99. /* The following is dependent on which slot
  100. * you plug the Southbridge card into. We
  101. * currently assume that you plug it into
  102. * the right-hand most slot.
  103. */
  104. isa_init_irq(IRQ_PCI);
  105. if (machine_is_cats())
  106. isa_init_irq(IRQ_IN2);
  107. if (machine_is_netwinder())
  108. isa_init_irq(IRQ_IN3);
  109. }
  110. /*
  111. * Common mapping for all systems. Note that the outbound write flush is
  112. * commented out since there is a "No Fix" problem with it. Not mapping
  113. * it means that we have extra bullet protection on our feet.
  114. */
  115. static struct map_desc fb_common_io_desc[] __initdata = {
  116. {
  117. .virtual = ARMCSR_BASE,
  118. .pfn = __phys_to_pfn(DC21285_ARMCSR_BASE),
  119. .length = ARMCSR_SIZE,
  120. .type = MT_DEVICE,
  121. }, {
  122. .virtual = XBUS_BASE,
  123. .pfn = __phys_to_pfn(0x40000000),
  124. .length = XBUS_SIZE,
  125. .type = MT_DEVICE,
  126. }
  127. };
  128. /*
  129. * The mapping when the footbridge is in host mode. We don't map any of
  130. * this when we are in add-in mode.
  131. */
  132. static struct map_desc ebsa285_host_io_desc[] __initdata = {
  133. #if defined(CONFIG_ARCH_FOOTBRIDGE) && defined(CONFIG_FOOTBRIDGE_HOST)
  134. {
  135. .virtual = PCIMEM_BASE,
  136. .pfn = __phys_to_pfn(DC21285_PCI_MEM),
  137. .length = PCIMEM_SIZE,
  138. .type = MT_DEVICE,
  139. }, {
  140. .virtual = PCICFG0_BASE,
  141. .pfn = __phys_to_pfn(DC21285_PCI_TYPE_0_CONFIG),
  142. .length = PCICFG0_SIZE,
  143. .type = MT_DEVICE,
  144. }, {
  145. .virtual = PCICFG1_BASE,
  146. .pfn = __phys_to_pfn(DC21285_PCI_TYPE_1_CONFIG),
  147. .length = PCICFG1_SIZE,
  148. .type = MT_DEVICE,
  149. }, {
  150. .virtual = PCIIACK_BASE,
  151. .pfn = __phys_to_pfn(DC21285_PCI_IACK),
  152. .length = PCIIACK_SIZE,
  153. .type = MT_DEVICE,
  154. }, {
  155. .virtual = PCIO_BASE,
  156. .pfn = __phys_to_pfn(DC21285_PCI_IO),
  157. .length = PCIO_SIZE,
  158. .type = MT_DEVICE,
  159. },
  160. #endif
  161. };
  162. void __init footbridge_map_io(void)
  163. {
  164. /*
  165. * Set up the common mapping first; we need this to
  166. * determine whether we're in host mode or not.
  167. */
  168. iotable_init(fb_common_io_desc, ARRAY_SIZE(fb_common_io_desc));
  169. /*
  170. * Now, work out what we've got to map in addition on this
  171. * platform.
  172. */
  173. if (footbridge_cfn_mode())
  174. iotable_init(ebsa285_host_io_desc, ARRAY_SIZE(ebsa285_host_io_desc));
  175. }
  176. #ifdef CONFIG_FOOTBRIDGE_ADDIN
  177. static inline unsigned long fb_bus_sdram_offset(void)
  178. {
  179. return *CSR_PCISDRAMBASE & 0xfffffff0;
  180. }
  181. /*
  182. * These two functions convert virtual addresses to PCI addresses and PCI
  183. * addresses to virtual addresses. Note that it is only legal to use these
  184. * on memory obtained via get_zeroed_page or kmalloc.
  185. */
  186. unsigned long __virt_to_bus(unsigned long res)
  187. {
  188. WARN_ON(res < PAGE_OFFSET || res >= (unsigned long)high_memory);
  189. return res + (fb_bus_sdram_offset() - PAGE_OFFSET);
  190. }
  191. EXPORT_SYMBOL(__virt_to_bus);
  192. unsigned long __bus_to_virt(unsigned long res)
  193. {
  194. res = res - (fb_bus_sdram_offset() - PAGE_OFFSET);
  195. WARN_ON(res < PAGE_OFFSET || res >= (unsigned long)high_memory);
  196. return res;
  197. }
  198. EXPORT_SYMBOL(__bus_to_virt);
  199. unsigned long __pfn_to_bus(unsigned long pfn)
  200. {
  201. return __pfn_to_phys(pfn) + (fb_bus_sdram_offset() - PHYS_OFFSET);
  202. }
  203. EXPORT_SYMBOL(__pfn_to_bus);
  204. unsigned long __bus_to_pfn(unsigned long bus)
  205. {
  206. return __phys_to_pfn(bus - (fb_bus_sdram_offset() - PHYS_OFFSET));
  207. }
  208. EXPORT_SYMBOL(__bus_to_pfn);
  209. #endif