core.c 6.3 KB

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