core.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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 <mach/cfg_global.h>
  43. #include "clock.h"
  44. #include <mach/csp/secHw_def.h>
  45. #include <mach/csp/chipcHw_inline.h>
  46. #include <mach/csp/tmrHw_reg.h>
  47. static AMBA_APB_DEVICE(uartA, "uartA", 0, MM_ADDR_IO_UARTA, {IRQ_UARTA}, NULL);
  48. static AMBA_APB_DEVICE(uartB, "uartB", 0, MM_ADDR_IO_UARTB, {IRQ_UARTB}, NULL);
  49. static struct clk pll1_clk = {
  50. .name = "PLL1",
  51. .type = CLK_TYPE_PRIMARY | CLK_TYPE_PLL1,
  52. .rate_hz = 2000000000,
  53. .use_cnt = 7,
  54. };
  55. static struct clk uart_clk = {
  56. .name = "UART",
  57. .type = CLK_TYPE_PROGRAMMABLE,
  58. .csp_id = chipcHw_CLOCK_UART,
  59. .rate_hz = HW_CFG_UART_CLK_HZ,
  60. .parent = &pll1_clk,
  61. };
  62. static struct clk dummy_apb_pclk = {
  63. .name = "BUSCLK",
  64. .type = CLK_TYPE_PRIMARY,
  65. .mode = CLK_MODE_XTAL,
  66. };
  67. /* Timer 0 - 25 MHz, Timer3 at bus clock rate, typically 150-166 MHz */
  68. #if defined(CONFIG_ARCH_FPGA11107)
  69. /* fpga cpu/bus are currently 30 times slower so scale frequency as well to */
  70. /* slow down Linux's sense of time */
  71. #define TIMER0_FREQUENCY_MHZ (tmrHw_LOW_FREQUENCY_MHZ * 30)
  72. #define TIMER1_FREQUENCY_MHZ (tmrHw_LOW_FREQUENCY_MHZ * 30)
  73. #define TIMER3_FREQUENCY_MHZ (tmrHw_HIGH_FREQUENCY_MHZ * 30)
  74. #define TIMER3_FREQUENCY_KHZ (tmrHw_HIGH_FREQUENCY_HZ / 1000 * 30)
  75. #else
  76. #define TIMER0_FREQUENCY_MHZ tmrHw_LOW_FREQUENCY_MHZ
  77. #define TIMER1_FREQUENCY_MHZ tmrHw_LOW_FREQUENCY_MHZ
  78. #define TIMER3_FREQUENCY_MHZ tmrHw_HIGH_FREQUENCY_MHZ
  79. #define TIMER3_FREQUENCY_KHZ (tmrHw_HIGH_FREQUENCY_HZ / 1000)
  80. #endif
  81. static struct clk sp804_timer012_clk = {
  82. .name = "sp804-timer-0,1,2",
  83. .type = CLK_TYPE_PRIMARY,
  84. .mode = CLK_MODE_XTAL,
  85. .rate_hz = TIMER1_FREQUENCY_MHZ * 1000000,
  86. };
  87. static struct clk sp804_timer3_clk = {
  88. .name = "sp804-timer-3",
  89. .type = CLK_TYPE_PRIMARY,
  90. .mode = CLK_MODE_XTAL,
  91. .rate_hz = TIMER3_FREQUENCY_KHZ * 1000,
  92. };
  93. static struct clk_lookup lookups[] = {
  94. { /* Bus clock */
  95. .con_id = "apb_pclk",
  96. .clk = &dummy_apb_pclk,
  97. }, { /* UART0 */
  98. .dev_id = "uarta",
  99. .clk = &uart_clk,
  100. }, { /* UART1 */
  101. .dev_id = "uartb",
  102. .clk = &uart_clk,
  103. }, { /* SP804 timer 0 */
  104. .dev_id = "sp804",
  105. .con_id = "timer0",
  106. .clk = &sp804_timer012_clk,
  107. }, { /* SP804 timer 1 */
  108. .dev_id = "sp804",
  109. .con_id = "timer1",
  110. .clk = &sp804_timer012_clk,
  111. }, { /* SP804 timer 3 */
  112. .dev_id = "sp804",
  113. .con_id = "timer3",
  114. .clk = &sp804_timer3_clk,
  115. }
  116. };
  117. static struct amba_device *amba_devs[] __initdata = {
  118. &uartA_device,
  119. &uartB_device,
  120. };
  121. void __init bcmring_amba_init(void)
  122. {
  123. int i;
  124. u32 bus_clock;
  125. /* Linux is run initially in non-secure mode. Secure peripherals */
  126. /* generate FIQ, and must be handled in secure mode. Until we have */
  127. /* a linux security monitor implementation, keep everything in */
  128. /* non-secure mode. */
  129. chipcHw_busInterfaceClockEnable(chipcHw_REG_BUS_CLOCK_SPU);
  130. secHw_setUnsecure(secHw_BLK_MASK_CHIP_CONTROL |
  131. secHw_BLK_MASK_KEY_SCAN |
  132. secHw_BLK_MASK_TOUCH_SCREEN |
  133. secHw_BLK_MASK_UART0 |
  134. secHw_BLK_MASK_UART1 |
  135. secHw_BLK_MASK_WATCHDOG |
  136. secHw_BLK_MASK_SPUM |
  137. secHw_BLK_MASK_DDR2 |
  138. secHw_BLK_MASK_SPU |
  139. secHw_BLK_MASK_PKA |
  140. secHw_BLK_MASK_RNG |
  141. secHw_BLK_MASK_RTC |
  142. secHw_BLK_MASK_OTP |
  143. secHw_BLK_MASK_BOOT |
  144. secHw_BLK_MASK_MPU |
  145. secHw_BLK_MASK_TZCTRL | secHw_BLK_MASK_INTR);
  146. /* Only the devices attached to the AMBA bus are enabled just before the bus is */
  147. /* scanned and the drivers are loaded. The clocks need to be on for the AMBA bus */
  148. /* driver to access these blocks. The bus is probed, and the drivers are loaded. */
  149. /* FIXME Need to remove enable of PIF once CLCD clock enable used properly in FPGA. */
  150. bus_clock = chipcHw_REG_BUS_CLOCK_GE
  151. | chipcHw_REG_BUS_CLOCK_SDIO0 | chipcHw_REG_BUS_CLOCK_SDIO1;
  152. chipcHw_busInterfaceClockEnable(bus_clock);
  153. for (i = 0; i < ARRAY_SIZE(amba_devs); i++) {
  154. struct amba_device *d = amba_devs[i];
  155. amba_device_register(d, &iomem_resource);
  156. }
  157. }
  158. /*
  159. * Where is the timer (VA)?
  160. */
  161. #define TIMER0_VA_BASE ((void __iomem *)MM_IO_BASE_TMR)
  162. #define TIMER1_VA_BASE ((void __iomem *)(MM_IO_BASE_TMR + 0x20))
  163. #define TIMER2_VA_BASE ((void __iomem *)(MM_IO_BASE_TMR + 0x40))
  164. #define TIMER3_VA_BASE ((void __iomem *)(MM_IO_BASE_TMR + 0x60))
  165. static int __init bcmring_clocksource_init(void)
  166. {
  167. /* setup timer1 as free-running clocksource */
  168. sp804_clocksource_init(TIMER1_VA_BASE, "timer1");
  169. /* setup timer3 as free-running clocksource */
  170. sp804_clocksource_init(TIMER3_VA_BASE, "timer3");
  171. return 0;
  172. }
  173. /*
  174. * Set up timer interrupt, and return the current time in seconds.
  175. */
  176. void __init bcmring_init_timer(void)
  177. {
  178. printk(KERN_INFO "bcmring_init_timer\n");
  179. /*
  180. * Initialise to a known state (all timers off)
  181. */
  182. writel(0, TIMER0_VA_BASE + TIMER_CTRL);
  183. writel(0, TIMER1_VA_BASE + TIMER_CTRL);
  184. writel(0, TIMER2_VA_BASE + TIMER_CTRL);
  185. writel(0, TIMER3_VA_BASE + TIMER_CTRL);
  186. /*
  187. * Make irqs happen for the system timer
  188. */
  189. bcmring_clocksource_init();
  190. sp804_clockevents_init(TIMER0_VA_BASE, IRQ_TIMER0, "timer0");
  191. }
  192. struct sys_timer bcmring_timer = {
  193. .init = bcmring_init_timer,
  194. };
  195. void __init bcmring_init_early(void)
  196. {
  197. clkdev_add_table(lookups, ARRAY_SIZE(lookups));
  198. }