core.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  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. #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(struct irq_data *d)
  34. {
  35. __raw_writeb(1 << d->irq, IRQ_MCLR);
  36. }
  37. static void ebsa110_unmask_irq(struct irq_data *d)
  38. {
  39. __raw_writeb(1 << d->irq, IRQ_MSET);
  40. }
  41. static struct irq_chip ebsa110_irq_chip = {
  42. .irq_ack = ebsa110_mask_irq,
  43. .irq_mask = ebsa110_mask_irq,
  44. .irq_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. irq_set_chip_and_handler(irq, &ebsa110_irq_chip,
  60. handle_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. static void __iomem *ebsa110_ioremap_caller(unsigned long cookie, size_t size,
  109. unsigned int flags, void *caller)
  110. {
  111. return (void __iomem *)cookie;
  112. }
  113. static void ebsa110_iounmap(volatile void __iomem *io_addr)
  114. {}
  115. static void __init ebsa110_init_early(void)
  116. {
  117. arch_ioremap_caller = ebsa110_ioremap_caller;
  118. arch_iounmap = ebsa110_iounmap;
  119. }
  120. #define PIT_CTRL (PIT_BASE + 0x0d)
  121. #define PIT_T2 (PIT_BASE + 0x09)
  122. #define PIT_T1 (PIT_BASE + 0x05)
  123. #define PIT_T0 (PIT_BASE + 0x01)
  124. /*
  125. * This is the rate at which your MCLK signal toggles (in Hz)
  126. * This was measured on a 10 digit frequency counter sampling
  127. * over 1 second.
  128. */
  129. #define MCLK 47894000
  130. /*
  131. * This is the rate at which the PIT timers get clocked
  132. */
  133. #define CLKBY7 (MCLK / 7)
  134. /*
  135. * This is the counter value. We tick at 200Hz on this platform.
  136. */
  137. #define COUNT ((CLKBY7 + (HZ / 2)) / HZ)
  138. /*
  139. * Get the time offset from the system PIT. Note that if we have missed an
  140. * interrupt, then the PIT counter will roll over (ie, be negative).
  141. * This actually works out to be convenient.
  142. */
  143. static unsigned long ebsa110_gettimeoffset(void)
  144. {
  145. unsigned long offset, count;
  146. __raw_writeb(0x40, PIT_CTRL);
  147. count = __raw_readb(PIT_T1);
  148. count |= __raw_readb(PIT_T1) << 8;
  149. /*
  150. * If count > COUNT, make the number negative.
  151. */
  152. if (count > COUNT)
  153. count |= 0xffff0000;
  154. offset = COUNT;
  155. offset -= count;
  156. /*
  157. * `offset' is in units of timer counts. Convert
  158. * offset to units of microseconds.
  159. */
  160. offset = offset * (1000000 / HZ) / COUNT;
  161. return offset;
  162. }
  163. static irqreturn_t
  164. ebsa110_timer_interrupt(int irq, void *dev_id)
  165. {
  166. u32 count;
  167. /* latch and read timer 1 */
  168. __raw_writeb(0x40, PIT_CTRL);
  169. count = __raw_readb(PIT_T1);
  170. count |= __raw_readb(PIT_T1) << 8;
  171. count += COUNT;
  172. __raw_writeb(count & 0xff, PIT_T1);
  173. __raw_writeb(count >> 8, PIT_T1);
  174. timer_tick();
  175. return IRQ_HANDLED;
  176. }
  177. static struct irqaction ebsa110_timer_irq = {
  178. .name = "EBSA110 Timer Tick",
  179. .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
  180. .handler = ebsa110_timer_interrupt,
  181. };
  182. /*
  183. * Set up timer interrupt.
  184. */
  185. static void __init ebsa110_timer_init(void)
  186. {
  187. /*
  188. * Timer 1, mode 2, LSB/MSB
  189. */
  190. __raw_writeb(0x70, PIT_CTRL);
  191. __raw_writeb(COUNT & 0xff, PIT_T1);
  192. __raw_writeb(COUNT >> 8, PIT_T1);
  193. setup_irq(IRQ_EBSA110_TIMER0, &ebsa110_timer_irq);
  194. }
  195. static struct sys_timer ebsa110_timer = {
  196. .init = ebsa110_timer_init,
  197. .offset = ebsa110_gettimeoffset,
  198. };
  199. static struct plat_serial8250_port serial_platform_data[] = {
  200. {
  201. .iobase = 0x3f8,
  202. .irq = 1,
  203. .uartclk = 1843200,
  204. .regshift = 0,
  205. .iotype = UPIO_PORT,
  206. .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST,
  207. },
  208. {
  209. .iobase = 0x2f8,
  210. .irq = 2,
  211. .uartclk = 1843200,
  212. .regshift = 0,
  213. .iotype = UPIO_PORT,
  214. .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST,
  215. },
  216. { },
  217. };
  218. static struct platform_device serial_device = {
  219. .name = "serial8250",
  220. .id = PLAT8250_DEV_PLATFORM,
  221. .dev = {
  222. .platform_data = serial_platform_data,
  223. },
  224. };
  225. static struct resource am79c961_resources[] = {
  226. {
  227. .start = 0x220,
  228. .end = 0x238,
  229. .flags = IORESOURCE_IO,
  230. }, {
  231. .start = IRQ_EBSA110_ETHERNET,
  232. .end = IRQ_EBSA110_ETHERNET,
  233. .flags = IORESOURCE_IRQ,
  234. },
  235. };
  236. static struct platform_device am79c961_device = {
  237. .name = "am79c961",
  238. .id = -1,
  239. .num_resources = ARRAY_SIZE(am79c961_resources),
  240. .resource = am79c961_resources,
  241. };
  242. static struct platform_device *ebsa110_devices[] = {
  243. &serial_device,
  244. &am79c961_device,
  245. };
  246. /*
  247. * EBSA110 idling methodology:
  248. *
  249. * We can not execute the "wait for interrupt" instruction since that
  250. * will stop our MCLK signal (which provides the clock for the glue
  251. * logic, and therefore the timer interrupt).
  252. *
  253. * Instead, we spin, polling the IRQ_STAT register for the occurrence
  254. * of any interrupt with core clock down to the memory clock.
  255. */
  256. static void ebsa110_idle(void)
  257. {
  258. const char *irq_stat = (char *)0xff000000;
  259. /* disable clock switching */
  260. asm volatile ("mcr p15, 0, ip, c15, c2, 2" : : : "cc");
  261. /* wait for an interrupt to occur */
  262. while (!*irq_stat);
  263. /* enable clock switching */
  264. asm volatile ("mcr p15, 0, ip, c15, c1, 2" : : : "cc");
  265. }
  266. static int __init ebsa110_init(void)
  267. {
  268. arm_pm_idle = ebsa110_idle;
  269. return platform_add_devices(ebsa110_devices, ARRAY_SIZE(ebsa110_devices));
  270. }
  271. arch_initcall(ebsa110_init);
  272. static void ebsa110_restart(char mode, const char *cmd)
  273. {
  274. soft_restart(0x80000000);
  275. }
  276. MACHINE_START(EBSA110, "EBSA110")
  277. /* Maintainer: Russell King */
  278. .atag_offset = 0x400,
  279. .reserve_lp0 = 1,
  280. .reserve_lp2 = 1,
  281. .restart_mode = 's',
  282. .map_io = ebsa110_map_io,
  283. .init_early = ebsa110_init_early,
  284. .init_irq = ebsa110_init_irq,
  285. .timer = &ebsa110_timer,
  286. .restart = ebsa110_restart,
  287. MACHINE_END