common.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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/system_misc.h>
  24. #include <asm/hardware/dec21285.h>
  25. #include <asm/mach/irq.h>
  26. #include <asm/mach/map.h>
  27. #include <asm/mach/pci.h>
  28. #include "common.h"
  29. unsigned int mem_fclk_21285 = 50000000;
  30. EXPORT_SYMBOL(mem_fclk_21285);
  31. static int __init early_fclk(char *arg)
  32. {
  33. mem_fclk_21285 = simple_strtoul(arg, NULL, 0);
  34. return 0;
  35. }
  36. early_param("mem_fclk_21285", early_fclk);
  37. static int __init parse_tag_memclk(const struct tag *tag)
  38. {
  39. mem_fclk_21285 = tag->u.memclk.fmemclk;
  40. return 0;
  41. }
  42. __tagtable(ATAG_MEMCLK, parse_tag_memclk);
  43. /*
  44. * Footbridge IRQ translation table
  45. * Converts from our IRQ numbers into FootBridge masks
  46. */
  47. static const int fb_irq_mask[] = {
  48. IRQ_MASK_UART_RX, /* 0 */
  49. IRQ_MASK_UART_TX, /* 1 */
  50. IRQ_MASK_TIMER1, /* 2 */
  51. IRQ_MASK_TIMER2, /* 3 */
  52. IRQ_MASK_TIMER3, /* 4 */
  53. IRQ_MASK_IN0, /* 5 */
  54. IRQ_MASK_IN1, /* 6 */
  55. IRQ_MASK_IN2, /* 7 */
  56. IRQ_MASK_IN3, /* 8 */
  57. IRQ_MASK_DOORBELLHOST, /* 9 */
  58. IRQ_MASK_DMA1, /* 10 */
  59. IRQ_MASK_DMA2, /* 11 */
  60. IRQ_MASK_PCI, /* 12 */
  61. IRQ_MASK_SDRAMPARITY, /* 13 */
  62. IRQ_MASK_I2OINPOST, /* 14 */
  63. IRQ_MASK_PCI_ABORT, /* 15 */
  64. IRQ_MASK_PCI_SERR, /* 16 */
  65. IRQ_MASK_DISCARD_TIMER, /* 17 */
  66. IRQ_MASK_PCI_DPERR, /* 18 */
  67. IRQ_MASK_PCI_PERR, /* 19 */
  68. };
  69. static void fb_mask_irq(struct irq_data *d)
  70. {
  71. *CSR_IRQ_DISABLE = fb_irq_mask[_DC21285_INR(d->irq)];
  72. }
  73. static void fb_unmask_irq(struct irq_data *d)
  74. {
  75. *CSR_IRQ_ENABLE = fb_irq_mask[_DC21285_INR(d->irq)];
  76. }
  77. static struct irq_chip fb_chip = {
  78. .irq_ack = fb_mask_irq,
  79. .irq_mask = fb_mask_irq,
  80. .irq_unmask = fb_unmask_irq,
  81. };
  82. static void __init __fb_init_irq(void)
  83. {
  84. unsigned int irq;
  85. /*
  86. * setup DC21285 IRQs
  87. */
  88. *CSR_IRQ_DISABLE = -1;
  89. *CSR_FIQ_DISABLE = -1;
  90. for (irq = _DC21285_IRQ(0); irq < _DC21285_IRQ(20); irq++) {
  91. irq_set_chip_and_handler(irq, &fb_chip, handle_level_irq);
  92. set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
  93. }
  94. }
  95. void __init footbridge_init_irq(void)
  96. {
  97. __fb_init_irq();
  98. if (!footbridge_cfn_mode())
  99. return;
  100. if (machine_is_ebsa285())
  101. /* The following is dependent on which slot
  102. * you plug the Southbridge card into. We
  103. * currently assume that you plug it into
  104. * the right-hand most slot.
  105. */
  106. isa_init_irq(IRQ_PCI);
  107. if (machine_is_cats())
  108. isa_init_irq(IRQ_IN2);
  109. if (machine_is_netwinder())
  110. isa_init_irq(IRQ_IN3);
  111. }
  112. /*
  113. * Common mapping for all systems. Note that the outbound write flush is
  114. * commented out since there is a "No Fix" problem with it. Not mapping
  115. * it means that we have extra bullet protection on our feet.
  116. */
  117. static struct map_desc fb_common_io_desc[] __initdata = {
  118. {
  119. .virtual = ARMCSR_BASE,
  120. .pfn = __phys_to_pfn(DC21285_ARMCSR_BASE),
  121. .length = ARMCSR_SIZE,
  122. .type = MT_DEVICE,
  123. }, {
  124. .virtual = XBUS_BASE,
  125. .pfn = __phys_to_pfn(0x40000000),
  126. .length = XBUS_SIZE,
  127. .type = MT_DEVICE,
  128. }
  129. };
  130. /*
  131. * The mapping when the footbridge is in host mode. We don't map any of
  132. * this when we are in add-in mode.
  133. */
  134. static struct map_desc ebsa285_host_io_desc[] __initdata = {
  135. #if defined(CONFIG_ARCH_FOOTBRIDGE) && defined(CONFIG_FOOTBRIDGE_HOST)
  136. {
  137. .virtual = PCIMEM_BASE,
  138. .pfn = __phys_to_pfn(DC21285_PCI_MEM),
  139. .length = PCIMEM_SIZE,
  140. .type = MT_DEVICE,
  141. }, {
  142. .virtual = PCICFG0_BASE,
  143. .pfn = __phys_to_pfn(DC21285_PCI_TYPE_0_CONFIG),
  144. .length = PCICFG0_SIZE,
  145. .type = MT_DEVICE,
  146. }, {
  147. .virtual = PCICFG1_BASE,
  148. .pfn = __phys_to_pfn(DC21285_PCI_TYPE_1_CONFIG),
  149. .length = PCICFG1_SIZE,
  150. .type = MT_DEVICE,
  151. }, {
  152. .virtual = PCIIACK_BASE,
  153. .pfn = __phys_to_pfn(DC21285_PCI_IACK),
  154. .length = PCIIACK_SIZE,
  155. .type = MT_DEVICE,
  156. },
  157. #endif
  158. };
  159. void __init footbridge_map_io(void)
  160. {
  161. /*
  162. * Set up the common mapping first; we need this to
  163. * determine whether we're in host mode or not.
  164. */
  165. iotable_init(fb_common_io_desc, ARRAY_SIZE(fb_common_io_desc));
  166. /*
  167. * Now, work out what we've got to map in addition on this
  168. * platform.
  169. */
  170. if (footbridge_cfn_mode()) {
  171. iotable_init(ebsa285_host_io_desc, ARRAY_SIZE(ebsa285_host_io_desc));
  172. pci_map_io_early(__phys_to_pfn(DC21285_PCI_IO));
  173. }
  174. }
  175. void footbridge_restart(char mode, const char *cmd)
  176. {
  177. if (mode == 's') {
  178. /* Jump into the ROM */
  179. soft_restart(0x41000000);
  180. } else {
  181. /*
  182. * Force the watchdog to do a CPU reset.
  183. *
  184. * After making sure that the watchdog is disabled
  185. * (so we can change the timer registers) we first
  186. * enable the timer to autoreload itself. Next, the
  187. * timer interval is set really short and any
  188. * current interrupt request is cleared (so we can
  189. * see an edge transition). Finally, TIMER4 is
  190. * enabled as the watchdog.
  191. */
  192. *CSR_SA110_CNTL &= ~(1 << 13);
  193. *CSR_TIMER4_CNTL = TIMER_CNTL_ENABLE |
  194. TIMER_CNTL_AUTORELOAD |
  195. TIMER_CNTL_DIV16;
  196. *CSR_TIMER4_LOAD = 0x2;
  197. *CSR_TIMER4_CLR = 0;
  198. *CSR_SA110_CNTL |= (1 << 13);
  199. }
  200. }
  201. #ifdef CONFIG_FOOTBRIDGE_ADDIN
  202. static inline unsigned long fb_bus_sdram_offset(void)
  203. {
  204. return *CSR_PCISDRAMBASE & 0xfffffff0;
  205. }
  206. /*
  207. * These two functions convert virtual addresses to PCI addresses and PCI
  208. * addresses to virtual addresses. Note that it is only legal to use these
  209. * on memory obtained via get_zeroed_page or kmalloc.
  210. */
  211. unsigned long __virt_to_bus(unsigned long res)
  212. {
  213. WARN_ON(res < PAGE_OFFSET || res >= (unsigned long)high_memory);
  214. return res + (fb_bus_sdram_offset() - PAGE_OFFSET);
  215. }
  216. EXPORT_SYMBOL(__virt_to_bus);
  217. unsigned long __bus_to_virt(unsigned long res)
  218. {
  219. res = res - (fb_bus_sdram_offset() - PAGE_OFFSET);
  220. WARN_ON(res < PAGE_OFFSET || res >= (unsigned long)high_memory);
  221. return res;
  222. }
  223. EXPORT_SYMBOL(__bus_to_virt);
  224. unsigned long __pfn_to_bus(unsigned long pfn)
  225. {
  226. return __pfn_to_phys(pfn) + (fb_bus_sdram_offset() - PHYS_OFFSET);
  227. }
  228. EXPORT_SYMBOL(__pfn_to_bus);
  229. unsigned long __bus_to_pfn(unsigned long bus)
  230. {
  231. return __phys_to_pfn(bus - (fb_bus_sdram_offset() - PHYS_OFFSET));
  232. }
  233. EXPORT_SYMBOL(__bus_to_pfn);
  234. #endif