core.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. /*
  2. * linux/arch/arm/mach-ebsa110/core.c
  3. *
  4. * Copyright (C) 1998-2001 Russell King
  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. * Extra MM routines for the EBSA-110 architecture
  11. */
  12. #include <linux/kernel.h>
  13. #include <linux/mm.h>
  14. #include <linux/interrupt.h>
  15. #include <linux/serial_8250.h>
  16. #include <linux/init.h>
  17. #include <linux/io.h>
  18. #include <mach/hardware.h>
  19. #include <asm/irq.h>
  20. #include <asm/setup.h>
  21. #include <asm/mach-types.h>
  22. #include <asm/pgtable.h>
  23. #include <asm/page.h>
  24. #include <asm/system.h>
  25. #include <asm/mach/arch.h>
  26. #include <asm/mach/irq.h>
  27. #include <asm/mach/map.h>
  28. #include <asm/mach/time.h>
  29. #include "core.h"
  30. static void ebsa110_mask_irq(struct irq_data *d)
  31. {
  32. __raw_writeb(1 << d->irq, IRQ_MCLR);
  33. }
  34. static void ebsa110_unmask_irq(struct irq_data *d)
  35. {
  36. __raw_writeb(1 << d->irq, IRQ_MSET);
  37. }
  38. static struct irq_chip ebsa110_irq_chip = {
  39. .irq_ack = ebsa110_mask_irq,
  40. .irq_mask = ebsa110_mask_irq,
  41. .irq_unmask = ebsa110_unmask_irq,
  42. };
  43. static void __init ebsa110_init_irq(void)
  44. {
  45. unsigned long flags;
  46. unsigned int irq;
  47. local_irq_save(flags);
  48. __raw_writeb(0xff, IRQ_MCLR);
  49. __raw_writeb(0x55, IRQ_MSET);
  50. __raw_writeb(0x00, IRQ_MSET);
  51. if (__raw_readb(IRQ_MASK) != 0x55)
  52. while (1);
  53. __raw_writeb(0xff, IRQ_MCLR); /* clear all interrupt enables */
  54. local_irq_restore(flags);
  55. for (irq = 0; irq < NR_IRQS; irq++) {
  56. irq_set_chip_and_handler(irq, &ebsa110_irq_chip,
  57. handle_level_irq);
  58. set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
  59. }
  60. }
  61. static struct map_desc ebsa110_io_desc[] __initdata = {
  62. /*
  63. * sparse external-decode ISAIO space
  64. */
  65. { /* IRQ_STAT/IRQ_MCLR */
  66. .virtual = IRQ_STAT,
  67. .pfn = __phys_to_pfn(TRICK4_PHYS),
  68. .length = TRICK4_SIZE,
  69. .type = MT_DEVICE
  70. }, { /* IRQ_MASK/IRQ_MSET */
  71. .virtual = IRQ_MASK,
  72. .pfn = __phys_to_pfn(TRICK3_PHYS),
  73. .length = TRICK3_SIZE,
  74. .type = MT_DEVICE
  75. }, { /* SOFT_BASE */
  76. .virtual = SOFT_BASE,
  77. .pfn = __phys_to_pfn(TRICK1_PHYS),
  78. .length = TRICK1_SIZE,
  79. .type = MT_DEVICE
  80. }, { /* PIT_BASE */
  81. .virtual = PIT_BASE,
  82. .pfn = __phys_to_pfn(TRICK0_PHYS),
  83. .length = TRICK0_SIZE,
  84. .type = MT_DEVICE
  85. },
  86. /*
  87. * self-decode ISAIO space
  88. */
  89. {
  90. .virtual = ISAIO_BASE,
  91. .pfn = __phys_to_pfn(ISAIO_PHYS),
  92. .length = ISAIO_SIZE,
  93. .type = MT_DEVICE
  94. }, {
  95. .virtual = ISAMEM_BASE,
  96. .pfn = __phys_to_pfn(ISAMEM_PHYS),
  97. .length = ISAMEM_SIZE,
  98. .type = MT_DEVICE
  99. }
  100. };
  101. static void __init ebsa110_map_io(void)
  102. {
  103. iotable_init(ebsa110_io_desc, ARRAY_SIZE(ebsa110_io_desc));
  104. }
  105. #define PIT_CTRL (PIT_BASE + 0x0d)
  106. #define PIT_T2 (PIT_BASE + 0x09)
  107. #define PIT_T1 (PIT_BASE + 0x05)
  108. #define PIT_T0 (PIT_BASE + 0x01)
  109. /*
  110. * This is the rate at which your MCLK signal toggles (in Hz)
  111. * This was measured on a 10 digit frequency counter sampling
  112. * over 1 second.
  113. */
  114. #define MCLK 47894000
  115. /*
  116. * This is the rate at which the PIT timers get clocked
  117. */
  118. #define CLKBY7 (MCLK / 7)
  119. /*
  120. * This is the counter value. We tick at 200Hz on this platform.
  121. */
  122. #define COUNT ((CLKBY7 + (HZ / 2)) / HZ)
  123. /*
  124. * Get the time offset from the system PIT. Note that if we have missed an
  125. * interrupt, then the PIT counter will roll over (ie, be negative).
  126. * This actually works out to be convenient.
  127. */
  128. static unsigned long ebsa110_gettimeoffset(void)
  129. {
  130. unsigned long offset, count;
  131. __raw_writeb(0x40, PIT_CTRL);
  132. count = __raw_readb(PIT_T1);
  133. count |= __raw_readb(PIT_T1) << 8;
  134. /*
  135. * If count > COUNT, make the number negative.
  136. */
  137. if (count > COUNT)
  138. count |= 0xffff0000;
  139. offset = COUNT;
  140. offset -= count;
  141. /*
  142. * `offset' is in units of timer counts. Convert
  143. * offset to units of microseconds.
  144. */
  145. offset = offset * (1000000 / HZ) / COUNT;
  146. return offset;
  147. }
  148. static irqreturn_t
  149. ebsa110_timer_interrupt(int irq, void *dev_id)
  150. {
  151. u32 count;
  152. /* latch and read timer 1 */
  153. __raw_writeb(0x40, PIT_CTRL);
  154. count = __raw_readb(PIT_T1);
  155. count |= __raw_readb(PIT_T1) << 8;
  156. count += COUNT;
  157. __raw_writeb(count & 0xff, PIT_T1);
  158. __raw_writeb(count >> 8, PIT_T1);
  159. timer_tick();
  160. return IRQ_HANDLED;
  161. }
  162. static struct irqaction ebsa110_timer_irq = {
  163. .name = "EBSA110 Timer Tick",
  164. .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
  165. .handler = ebsa110_timer_interrupt,
  166. };
  167. /*
  168. * Set up timer interrupt.
  169. */
  170. static void __init ebsa110_timer_init(void)
  171. {
  172. /*
  173. * Timer 1, mode 2, LSB/MSB
  174. */
  175. __raw_writeb(0x70, PIT_CTRL);
  176. __raw_writeb(COUNT & 0xff, PIT_T1);
  177. __raw_writeb(COUNT >> 8, PIT_T1);
  178. setup_irq(IRQ_EBSA110_TIMER0, &ebsa110_timer_irq);
  179. }
  180. static struct sys_timer ebsa110_timer = {
  181. .init = ebsa110_timer_init,
  182. .offset = ebsa110_gettimeoffset,
  183. };
  184. static struct plat_serial8250_port serial_platform_data[] = {
  185. {
  186. .iobase = 0x3f8,
  187. .irq = 1,
  188. .uartclk = 1843200,
  189. .regshift = 0,
  190. .iotype = UPIO_PORT,
  191. .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST,
  192. },
  193. {
  194. .iobase = 0x2f8,
  195. .irq = 2,
  196. .uartclk = 1843200,
  197. .regshift = 0,
  198. .iotype = UPIO_PORT,
  199. .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST,
  200. },
  201. { },
  202. };
  203. static struct platform_device serial_device = {
  204. .name = "serial8250",
  205. .id = PLAT8250_DEV_PLATFORM,
  206. .dev = {
  207. .platform_data = serial_platform_data,
  208. },
  209. };
  210. static struct resource am79c961_resources[] = {
  211. {
  212. .start = 0x220,
  213. .end = 0x238,
  214. .flags = IORESOURCE_IO,
  215. }, {
  216. .start = IRQ_EBSA110_ETHERNET,
  217. .end = IRQ_EBSA110_ETHERNET,
  218. .flags = IORESOURCE_IRQ,
  219. },
  220. };
  221. static struct platform_device am79c961_device = {
  222. .name = "am79c961",
  223. .id = -1,
  224. .num_resources = ARRAY_SIZE(am79c961_resources),
  225. .resource = am79c961_resources,
  226. };
  227. static struct platform_device *ebsa110_devices[] = {
  228. &serial_device,
  229. &am79c961_device,
  230. };
  231. static int __init ebsa110_init(void)
  232. {
  233. return platform_add_devices(ebsa110_devices, ARRAY_SIZE(ebsa110_devices));
  234. }
  235. arch_initcall(ebsa110_init);
  236. static void ebsa110_restart(char mode, const char *cmd)
  237. {
  238. soft_restart(0x80000000);
  239. }
  240. MACHINE_START(EBSA110, "EBSA110")
  241. /* Maintainer: Russell King */
  242. .atag_offset = 0x400,
  243. .reserve_lp0 = 1,
  244. .reserve_lp2 = 1,
  245. .restart_mode = 's',
  246. .map_io = ebsa110_map_io,
  247. .init_irq = ebsa110_init_irq,
  248. .timer = &ebsa110_timer,
  249. .restart = ebsa110_restart,
  250. MACHINE_END