core.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /*
  2. * linux/arch/arm/mach-integrator/core.c
  3. *
  4. * Copyright (C) 2000-2003 Deep Blue Solutions Ltd
  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/types.h>
  11. #include <linux/kernel.h>
  12. #include <linux/init.h>
  13. #include <linux/device.h>
  14. #include <linux/spinlock.h>
  15. #include <linux/interrupt.h>
  16. #include <linux/irq.h>
  17. #include <linux/memblock.h>
  18. #include <linux/sched.h>
  19. #include <linux/smp.h>
  20. #include <linux/termios.h>
  21. #include <linux/amba/bus.h>
  22. #include <linux/amba/serial.h>
  23. #include <linux/io.h>
  24. #include <linux/clkdev.h>
  25. #include <mach/hardware.h>
  26. #include <mach/platform.h>
  27. #include <mach/cm.h>
  28. #include <mach/irqs.h>
  29. #include <asm/leds.h>
  30. #include <asm/mach-types.h>
  31. #include <asm/mach/time.h>
  32. #include <asm/pgtable.h>
  33. static struct amba_pl010_data integrator_uart_data;
  34. #define INTEGRATOR_RTC_IRQ { IRQ_RTCINT }
  35. #define INTEGRATOR_UART0_IRQ { IRQ_UARTINT0 }
  36. #define INTEGRATOR_UART1_IRQ { IRQ_UARTINT1 }
  37. #define KMI0_IRQ { IRQ_KMIINT0 }
  38. #define KMI1_IRQ { IRQ_KMIINT1 }
  39. static AMBA_APB_DEVICE(rtc, "mb:15", 0,
  40. INTEGRATOR_RTC_BASE, INTEGRATOR_RTC_IRQ, NULL);
  41. static AMBA_APB_DEVICE(uart0, "mb:16", 0,
  42. INTEGRATOR_UART0_BASE, INTEGRATOR_UART0_IRQ, &integrator_uart_data);
  43. static AMBA_APB_DEVICE(uart1, "mb:17", 0,
  44. INTEGRATOR_UART1_BASE, INTEGRATOR_UART1_IRQ, &integrator_uart_data);
  45. static AMBA_APB_DEVICE(kmi0, "mb:18", 0, KMI0_BASE, KMI0_IRQ, NULL);
  46. static AMBA_APB_DEVICE(kmi1, "mb:19", 0, KMI1_BASE, KMI1_IRQ, NULL);
  47. static struct amba_device *amba_devs[] __initdata = {
  48. &rtc_device,
  49. &uart0_device,
  50. &uart1_device,
  51. &kmi0_device,
  52. &kmi1_device,
  53. };
  54. /*
  55. * These are fixed clocks.
  56. */
  57. static struct clk clk24mhz = {
  58. .rate = 24000000,
  59. };
  60. static struct clk uartclk = {
  61. .rate = 14745600,
  62. };
  63. static struct clk dummy_apb_pclk;
  64. static struct clk_lookup lookups[] = {
  65. { /* Bus clock */
  66. .con_id = "apb_pclk",
  67. .clk = &dummy_apb_pclk,
  68. }, {
  69. /* Integrator/AP timer frequency */
  70. .dev_id = "ap_timer",
  71. .clk = &clk24mhz,
  72. }, { /* UART0 */
  73. .dev_id = "mb:16",
  74. .clk = &uartclk,
  75. }, { /* UART1 */
  76. .dev_id = "mb:17",
  77. .clk = &uartclk,
  78. }, { /* KMI0 */
  79. .dev_id = "mb:18",
  80. .clk = &clk24mhz,
  81. }, { /* KMI1 */
  82. .dev_id = "mb:19",
  83. .clk = &clk24mhz,
  84. }, { /* MMCI - IntegratorCP */
  85. .dev_id = "mb:1c",
  86. .clk = &uartclk,
  87. }
  88. };
  89. void __init integrator_init_early(void)
  90. {
  91. clkdev_add_table(lookups, ARRAY_SIZE(lookups));
  92. }
  93. static int __init integrator_init(void)
  94. {
  95. int i;
  96. /*
  97. * The Integrator/AP lacks necessary AMBA PrimeCell IDs, so we need to
  98. * hard-code them. The Integator/CP and forward have proper cell IDs.
  99. * Else we leave them undefined to the bus driver can autoprobe them.
  100. */
  101. if (machine_is_integrator()) {
  102. rtc_device.periphid = 0x00041030;
  103. uart0_device.periphid = 0x00041010;
  104. uart1_device.periphid = 0x00041010;
  105. kmi0_device.periphid = 0x00041050;
  106. kmi1_device.periphid = 0x00041050;
  107. }
  108. for (i = 0; i < ARRAY_SIZE(amba_devs); i++) {
  109. struct amba_device *d = amba_devs[i];
  110. amba_device_register(d, &iomem_resource);
  111. }
  112. return 0;
  113. }
  114. arch_initcall(integrator_init);
  115. /*
  116. * On the Integrator platform, the port RTS and DTR are provided by
  117. * bits in the following SC_CTRLS register bits:
  118. * RTS DTR
  119. * UART0 7 6
  120. * UART1 5 4
  121. */
  122. #define SC_CTRLC IO_ADDRESS(INTEGRATOR_SC_CTRLC)
  123. #define SC_CTRLS IO_ADDRESS(INTEGRATOR_SC_CTRLS)
  124. static void integrator_uart_set_mctrl(struct amba_device *dev, void __iomem *base, unsigned int mctrl)
  125. {
  126. unsigned int ctrls = 0, ctrlc = 0, rts_mask, dtr_mask;
  127. if (dev == &uart0_device) {
  128. rts_mask = 1 << 4;
  129. dtr_mask = 1 << 5;
  130. } else {
  131. rts_mask = 1 << 6;
  132. dtr_mask = 1 << 7;
  133. }
  134. if (mctrl & TIOCM_RTS)
  135. ctrlc |= rts_mask;
  136. else
  137. ctrls |= rts_mask;
  138. if (mctrl & TIOCM_DTR)
  139. ctrlc |= dtr_mask;
  140. else
  141. ctrls |= dtr_mask;
  142. __raw_writel(ctrls, SC_CTRLS);
  143. __raw_writel(ctrlc, SC_CTRLC);
  144. }
  145. static struct amba_pl010_data integrator_uart_data = {
  146. .set_mctrl = integrator_uart_set_mctrl,
  147. };
  148. #define CM_CTRL IO_ADDRESS(INTEGRATOR_HDR_CTRL)
  149. static DEFINE_RAW_SPINLOCK(cm_lock);
  150. /**
  151. * cm_control - update the CM_CTRL register.
  152. * @mask: bits to change
  153. * @set: bits to set
  154. */
  155. void cm_control(u32 mask, u32 set)
  156. {
  157. unsigned long flags;
  158. u32 val;
  159. raw_spin_lock_irqsave(&cm_lock, flags);
  160. val = readl(CM_CTRL) & ~mask;
  161. writel(val | set, CM_CTRL);
  162. raw_spin_unlock_irqrestore(&cm_lock, flags);
  163. }
  164. EXPORT_SYMBOL(cm_control);
  165. /*
  166. * We need to stop things allocating the low memory; ideally we need a
  167. * better implementation of GFP_DMA which does not assume that DMA-able
  168. * memory starts at zero.
  169. */
  170. void __init integrator_reserve(void)
  171. {
  172. memblock_reserve(PHYS_OFFSET, __pa(swapper_pg_dir) - PHYS_OFFSET);
  173. }
  174. /*
  175. * To reset, we hit the on-board reset register in the system FPGA
  176. */
  177. void integrator_restart(char mode, const char *cmd)
  178. {
  179. cm_control(CM_CTRL_RESET, CM_CTRL_RESET);
  180. }