core.c 7.2 KB

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