core.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. /*
  2. * derived from linux/arch/arm/mach-versatile/core.c
  3. * linux/arch/arm/mach-bcmring/core.c
  4. *
  5. * Copyright (C) 1999 - 2003 ARM Limited
  6. * Copyright (C) 2000 Deep Blue Solutions Ltd
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. */
  22. /* Portions copyright Broadcom 2008 */
  23. #include <linux/init.h>
  24. #include <linux/device.h>
  25. #include <linux/dma-mapping.h>
  26. #include <linux/platform_device.h>
  27. #include <linux/interrupt.h>
  28. #include <linux/amba/bus.h>
  29. #include <linux/clkdev.h>
  30. #include <mach/csp/mm_addr.h>
  31. #include <mach/hardware.h>
  32. #include <linux/io.h>
  33. #include <asm/irq.h>
  34. #include <asm/hardware/arm_timer.h>
  35. #include <asm/hardware/timer-sp.h>
  36. #include <asm/mach-types.h>
  37. #include <asm/mach/arch.h>
  38. #include <asm/mach/flash.h>
  39. #include <asm/mach/irq.h>
  40. #include <asm/mach/time.h>
  41. #include <asm/mach/map.h>
  42. #include <cfg_global.h>
  43. #include "clock.h"
  44. #include <csp/secHw.h>
  45. #include <mach/csp/secHw_def.h>
  46. #include <mach/csp/chipcHw_inline.h>
  47. #include <mach/csp/tmrHw_reg.h>
  48. static AMBA_APB_DEVICE(uartA, "uarta", MM_ADDR_IO_UARTA, { IRQ_UARTA }, NULL);
  49. static AMBA_APB_DEVICE(uartB, "uartb", MM_ADDR_IO_UARTB, { IRQ_UARTB }, NULL);
  50. static struct clk pll1_clk = {
  51. .name = "PLL1",
  52. .type = CLK_TYPE_PRIMARY | CLK_TYPE_PLL1,
  53. .rate_hz = 2000000000,
  54. .use_cnt = 7,
  55. };
  56. static struct clk uart_clk = {
  57. .name = "UART",
  58. .type = CLK_TYPE_PROGRAMMABLE,
  59. .csp_id = chipcHw_CLOCK_UART,
  60. .rate_hz = HW_CFG_UART_CLK_HZ,
  61. .parent = &pll1_clk,
  62. };
  63. static struct clk dummy_apb_pclk = {
  64. .name = "BUSCLK",
  65. .type = CLK_TYPE_PRIMARY,
  66. .mode = CLK_MODE_XTAL,
  67. };
  68. /* Timer 0 - 25 MHz, Timer3 at bus clock rate, typically 150-166 MHz */
  69. #if defined(CONFIG_ARCH_FPGA11107)
  70. /* fpga cpu/bus are currently 30 times slower so scale frequency as well to */
  71. /* slow down Linux's sense of time */
  72. #define TIMER0_FREQUENCY_MHZ (tmrHw_LOW_FREQUENCY_MHZ * 30)
  73. #define TIMER1_FREQUENCY_MHZ (tmrHw_LOW_FREQUENCY_MHZ * 30)
  74. #define TIMER3_FREQUENCY_MHZ (tmrHw_HIGH_FREQUENCY_MHZ * 30)
  75. #define TIMER3_FREQUENCY_KHZ (tmrHw_HIGH_FREQUENCY_HZ / 1000 * 30)
  76. #else
  77. #define TIMER0_FREQUENCY_MHZ tmrHw_LOW_FREQUENCY_MHZ
  78. #define TIMER1_FREQUENCY_MHZ tmrHw_LOW_FREQUENCY_MHZ
  79. #define TIMER3_FREQUENCY_MHZ tmrHw_HIGH_FREQUENCY_MHZ
  80. #define TIMER3_FREQUENCY_KHZ (tmrHw_HIGH_FREQUENCY_HZ / 1000)
  81. #endif
  82. static struct clk sp804_timer012_clk = {
  83. .name = "sp804-timer-0,1,2",
  84. .type = CLK_TYPE_PRIMARY,
  85. .mode = CLK_MODE_XTAL,
  86. .rate_hz = TIMER1_FREQUENCY_MHZ * 1000000,
  87. };
  88. static struct clk sp804_timer3_clk = {
  89. .name = "sp804-timer-3",
  90. .type = CLK_TYPE_PRIMARY,
  91. .mode = CLK_MODE_XTAL,
  92. .rate_hz = TIMER3_FREQUENCY_KHZ * 1000,
  93. };
  94. static struct clk_lookup lookups[] = {
  95. { /* Bus clock */
  96. .con_id = "apb_pclk",
  97. .clk = &dummy_apb_pclk,
  98. }, { /* UART0 */
  99. .dev_id = "uarta",
  100. .clk = &uart_clk,
  101. }, { /* UART1 */
  102. .dev_id = "uartb",
  103. .clk = &uart_clk,
  104. }, { /* SP804 timer 0 */
  105. .dev_id = "sp804",
  106. .con_id = "timer0",
  107. .clk = &sp804_timer012_clk,
  108. }, { /* SP804 timer 1 */
  109. .dev_id = "sp804",
  110. .con_id = "timer1",
  111. .clk = &sp804_timer012_clk,
  112. }, { /* SP804 timer 3 */
  113. .dev_id = "sp804",
  114. .con_id = "timer3",
  115. .clk = &sp804_timer3_clk,
  116. }
  117. };
  118. static struct amba_device *amba_devs[] __initdata = {
  119. &uartA_device,
  120. &uartB_device,
  121. };
  122. void __init bcmring_amba_init(void)
  123. {
  124. int i;
  125. u32 bus_clock;
  126. /* Linux is run initially in non-secure mode. Secure peripherals */
  127. /* generate FIQ, and must be handled in secure mode. Until we have */
  128. /* a linux security monitor implementation, keep everything in */
  129. /* non-secure mode. */
  130. chipcHw_busInterfaceClockEnable(chipcHw_REG_BUS_CLOCK_SPU);
  131. secHw_setUnsecure(secHw_BLK_MASK_CHIP_CONTROL |
  132. secHw_BLK_MASK_KEY_SCAN |
  133. secHw_BLK_MASK_TOUCH_SCREEN |
  134. secHw_BLK_MASK_UART0 |
  135. secHw_BLK_MASK_UART1 |
  136. secHw_BLK_MASK_WATCHDOG |
  137. secHw_BLK_MASK_SPUM |
  138. secHw_BLK_MASK_DDR2 |
  139. secHw_BLK_MASK_SPU |
  140. secHw_BLK_MASK_PKA |
  141. secHw_BLK_MASK_RNG |
  142. secHw_BLK_MASK_RTC |
  143. secHw_BLK_MASK_OTP |
  144. secHw_BLK_MASK_BOOT |
  145. secHw_BLK_MASK_MPU |
  146. secHw_BLK_MASK_TZCTRL | secHw_BLK_MASK_INTR);
  147. /* Only the devices attached to the AMBA bus are enabled just before the bus is */
  148. /* scanned and the drivers are loaded. The clocks need to be on for the AMBA bus */
  149. /* driver to access these blocks. The bus is probed, and the drivers are loaded. */
  150. /* FIXME Need to remove enable of PIF once CLCD clock enable used properly in FPGA. */
  151. bus_clock = chipcHw_REG_BUS_CLOCK_GE
  152. | chipcHw_REG_BUS_CLOCK_SDIO0 | chipcHw_REG_BUS_CLOCK_SDIO1;
  153. chipcHw_busInterfaceClockEnable(bus_clock);
  154. for (i = 0; i < ARRAY_SIZE(amba_devs); i++) {
  155. struct amba_device *d = amba_devs[i];
  156. amba_device_register(d, &iomem_resource);
  157. }
  158. }
  159. /*
  160. * Where is the timer (VA)?
  161. */
  162. #define TIMER0_VA_BASE ((void __iomem *)MM_IO_BASE_TMR)
  163. #define TIMER1_VA_BASE ((void __iomem *)(MM_IO_BASE_TMR + 0x20))
  164. #define TIMER2_VA_BASE ((void __iomem *)(MM_IO_BASE_TMR + 0x40))
  165. #define TIMER3_VA_BASE ((void __iomem *)(MM_IO_BASE_TMR + 0x60))
  166. static int __init bcmring_clocksource_init(void)
  167. {
  168. /* setup timer1 as free-running clocksource */
  169. sp804_clocksource_init(TIMER1_VA_BASE, "timer1");
  170. /* setup timer3 as free-running clocksource */
  171. sp804_clocksource_init(TIMER3_VA_BASE, "timer3");
  172. return 0;
  173. }
  174. /*
  175. * Set up timer interrupt, and return the current time in seconds.
  176. */
  177. void __init bcmring_init_timer(void)
  178. {
  179. printk(KERN_INFO "bcmring_init_timer\n");
  180. /*
  181. * Initialise to a known state (all timers off)
  182. */
  183. writel(0, TIMER0_VA_BASE + TIMER_CTRL);
  184. writel(0, TIMER1_VA_BASE + TIMER_CTRL);
  185. writel(0, TIMER2_VA_BASE + TIMER_CTRL);
  186. writel(0, TIMER3_VA_BASE + TIMER_CTRL);
  187. /*
  188. * Make irqs happen for the system timer
  189. */
  190. bcmring_clocksource_init();
  191. sp804_clockevents_init(TIMER0_VA_BASE, IRQ_TIMER0, "timer0");
  192. }
  193. struct sys_timer bcmring_timer = {
  194. .init = bcmring_init_timer,
  195. };
  196. void __init bcmring_init_early(void)
  197. {
  198. clkdev_add_table(lookups, ARRAY_SIZE(lookups));
  199. }