core.c 7.2 KB

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