core.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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, TRICK4_PHYS, PGDIR_SIZE, MT_DEVICE }, /* IRQ_STAT/IRQ_MCLR */
  69. { IRQ_MASK, TRICK3_PHYS, PGDIR_SIZE, MT_DEVICE }, /* IRQ_MASK/IRQ_MSET */
  70. { SOFT_BASE, TRICK1_PHYS, PGDIR_SIZE, MT_DEVICE }, /* SOFT_BASE */
  71. { PIT_BASE, TRICK0_PHYS, PGDIR_SIZE, MT_DEVICE }, /* PIT_BASE */
  72. /*
  73. * self-decode ISAIO space
  74. */
  75. { ISAIO_BASE, ISAIO_PHYS, ISAIO_SIZE, MT_DEVICE },
  76. { ISAMEM_BASE, ISAMEM_PHYS, ISAMEM_SIZE, MT_DEVICE }
  77. };
  78. static void __init ebsa110_map_io(void)
  79. {
  80. iotable_init(ebsa110_io_desc, ARRAY_SIZE(ebsa110_io_desc));
  81. }
  82. #define PIT_CTRL (PIT_BASE + 0x0d)
  83. #define PIT_T2 (PIT_BASE + 0x09)
  84. #define PIT_T1 (PIT_BASE + 0x05)
  85. #define PIT_T0 (PIT_BASE + 0x01)
  86. /*
  87. * This is the rate at which your MCLK signal toggles (in Hz)
  88. * This was measured on a 10 digit frequency counter sampling
  89. * over 1 second.
  90. */
  91. #define MCLK 47894000
  92. /*
  93. * This is the rate at which the PIT timers get clocked
  94. */
  95. #define CLKBY7 (MCLK / 7)
  96. /*
  97. * This is the counter value. We tick at 200Hz on this platform.
  98. */
  99. #define COUNT ((CLKBY7 + (HZ / 2)) / HZ)
  100. /*
  101. * Get the time offset from the system PIT. Note that if we have missed an
  102. * interrupt, then the PIT counter will roll over (ie, be negative).
  103. * This actually works out to be convenient.
  104. */
  105. static unsigned long ebsa110_gettimeoffset(void)
  106. {
  107. unsigned long offset, count;
  108. __raw_writeb(0x40, PIT_CTRL);
  109. count = __raw_readb(PIT_T1);
  110. count |= __raw_readb(PIT_T1) << 8;
  111. /*
  112. * If count > COUNT, make the number negative.
  113. */
  114. if (count > COUNT)
  115. count |= 0xffff0000;
  116. offset = COUNT;
  117. offset -= count;
  118. /*
  119. * `offset' is in units of timer counts. Convert
  120. * offset to units of microseconds.
  121. */
  122. offset = offset * (1000000 / HZ) / COUNT;
  123. return offset;
  124. }
  125. static irqreturn_t
  126. ebsa110_timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  127. {
  128. u32 count;
  129. write_seqlock(&xtime_lock);
  130. /* latch and read timer 1 */
  131. __raw_writeb(0x40, PIT_CTRL);
  132. count = __raw_readb(PIT_T1);
  133. count |= __raw_readb(PIT_T1) << 8;
  134. count += COUNT;
  135. __raw_writeb(count & 0xff, PIT_T1);
  136. __raw_writeb(count >> 8, PIT_T1);
  137. timer_tick(regs);
  138. write_sequnlock(&xtime_lock);
  139. return IRQ_HANDLED;
  140. }
  141. static struct irqaction ebsa110_timer_irq = {
  142. .name = "EBSA110 Timer Tick",
  143. .flags = SA_INTERRUPT | SA_TIMER,
  144. .handler = ebsa110_timer_interrupt,
  145. };
  146. /*
  147. * Set up timer interrupt.
  148. */
  149. static void __init ebsa110_timer_init(void)
  150. {
  151. /*
  152. * Timer 1, mode 2, LSB/MSB
  153. */
  154. __raw_writeb(0x70, PIT_CTRL);
  155. __raw_writeb(COUNT & 0xff, PIT_T1);
  156. __raw_writeb(COUNT >> 8, PIT_T1);
  157. setup_irq(IRQ_EBSA110_TIMER0, &ebsa110_timer_irq);
  158. }
  159. static struct sys_timer ebsa110_timer = {
  160. .init = ebsa110_timer_init,
  161. .offset = ebsa110_gettimeoffset,
  162. };
  163. static struct plat_serial8250_port serial_platform_data[] = {
  164. {
  165. .iobase = 0x3f8,
  166. .irq = 1,
  167. .uartclk = 1843200,
  168. .regshift = 0,
  169. .iotype = UPIO_PORT,
  170. .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST,
  171. },
  172. {
  173. .iobase = 0x2f8,
  174. .irq = 2,
  175. .uartclk = 1843200,
  176. .regshift = 0,
  177. .iotype = UPIO_PORT,
  178. .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST,
  179. },
  180. { },
  181. };
  182. static struct platform_device serial_device = {
  183. .name = "serial8250",
  184. .id = PLAT8250_DEV_PLATFORM,
  185. .dev = {
  186. .platform_data = serial_platform_data,
  187. },
  188. };
  189. static int __init ebsa110_init(void)
  190. {
  191. return platform_device_register(&serial_device);
  192. }
  193. arch_initcall(ebsa110_init);
  194. MACHINE_START(EBSA110, "EBSA110")
  195. /* Maintainer: Russell King */
  196. .phys_ram = 0x00000000,
  197. .phys_io = 0xe0000000,
  198. .io_pg_offst = ((0xe0000000) >> 18) & 0xfffc,
  199. .boot_params = 0x00000400,
  200. .reserve_lp0 = 1,
  201. .reserve_lp2 = 1,
  202. .soft_reboot = 1,
  203. .map_io = ebsa110_map_io,
  204. .init_irq = ebsa110_init_irq,
  205. .timer = &ebsa110_timer,
  206. MACHINE_END