core.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  1. /*
  2. * linux/arch/arm/mach-realview/core.c
  3. *
  4. * Copyright (C) 1999 - 2003 ARM Limited
  5. * Copyright (C) 2000 Deep Blue Solutions Ltd
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. */
  21. #include <linux/init.h>
  22. #include <linux/platform_device.h>
  23. #include <linux/dma-mapping.h>
  24. #include <linux/sysdev.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/amba/bus.h>
  27. #include <linux/amba/clcd.h>
  28. #include <linux/clocksource.h>
  29. #include <linux/clockchips.h>
  30. #include <linux/io.h>
  31. #include <asm/system.h>
  32. #include <mach/hardware.h>
  33. #include <asm/irq.h>
  34. #include <asm/leds.h>
  35. #include <asm/mach-types.h>
  36. #include <asm/hardware/arm_timer.h>
  37. #include <asm/hardware/icst307.h>
  38. #include <asm/mach/arch.h>
  39. #include <asm/mach/flash.h>
  40. #include <asm/mach/irq.h>
  41. #include <asm/mach/map.h>
  42. #include <asm/mach/mmc.h>
  43. #include <asm/hardware/gic.h>
  44. #include "core.h"
  45. #include "clock.h"
  46. #define REALVIEW_REFCOUNTER (__io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_24MHz_OFFSET)
  47. /* used by entry-macro.S and platsmp.c */
  48. void __iomem *gic_cpu_base_addr;
  49. /*
  50. * This is the RealView sched_clock implementation. This has
  51. * a resolution of 41.7ns, and a maximum value of about 179s.
  52. */
  53. unsigned long long sched_clock(void)
  54. {
  55. unsigned long long v;
  56. v = (unsigned long long)readl(REALVIEW_REFCOUNTER) * 125;
  57. do_div(v, 3);
  58. return v;
  59. }
  60. #define REALVIEW_FLASHCTRL (__io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_FLASH_OFFSET)
  61. static int realview_flash_init(void)
  62. {
  63. u32 val;
  64. val = __raw_readl(REALVIEW_FLASHCTRL);
  65. val &= ~REALVIEW_FLASHPROG_FLVPPEN;
  66. __raw_writel(val, REALVIEW_FLASHCTRL);
  67. return 0;
  68. }
  69. static void realview_flash_exit(void)
  70. {
  71. u32 val;
  72. val = __raw_readl(REALVIEW_FLASHCTRL);
  73. val &= ~REALVIEW_FLASHPROG_FLVPPEN;
  74. __raw_writel(val, REALVIEW_FLASHCTRL);
  75. }
  76. static void realview_flash_set_vpp(int on)
  77. {
  78. u32 val;
  79. val = __raw_readl(REALVIEW_FLASHCTRL);
  80. if (on)
  81. val |= REALVIEW_FLASHPROG_FLVPPEN;
  82. else
  83. val &= ~REALVIEW_FLASHPROG_FLVPPEN;
  84. __raw_writel(val, REALVIEW_FLASHCTRL);
  85. }
  86. static struct flash_platform_data realview_flash_data = {
  87. .map_name = "cfi_probe",
  88. .width = 4,
  89. .init = realview_flash_init,
  90. .exit = realview_flash_exit,
  91. .set_vpp = realview_flash_set_vpp,
  92. };
  93. struct platform_device realview_flash_device = {
  94. .name = "armflash",
  95. .id = 0,
  96. .dev = {
  97. .platform_data = &realview_flash_data,
  98. },
  99. };
  100. int realview_flash_register(struct resource *res, u32 num)
  101. {
  102. realview_flash_device.resource = res;
  103. realview_flash_device.num_resources = num;
  104. return platform_device_register(&realview_flash_device);
  105. }
  106. static struct resource realview_i2c_resource = {
  107. .start = REALVIEW_I2C_BASE,
  108. .end = REALVIEW_I2C_BASE + SZ_4K - 1,
  109. .flags = IORESOURCE_MEM,
  110. };
  111. struct platform_device realview_i2c_device = {
  112. .name = "versatile-i2c",
  113. .id = -1,
  114. .num_resources = 1,
  115. .resource = &realview_i2c_resource,
  116. };
  117. #define REALVIEW_SYSMCI (__io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_MCI_OFFSET)
  118. static unsigned int realview_mmc_status(struct device *dev)
  119. {
  120. struct amba_device *adev = container_of(dev, struct amba_device, dev);
  121. u32 mask;
  122. if (adev->res.start == REALVIEW_MMCI0_BASE)
  123. mask = 1;
  124. else
  125. mask = 2;
  126. return readl(REALVIEW_SYSMCI) & mask;
  127. }
  128. struct mmc_platform_data realview_mmc0_plat_data = {
  129. .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
  130. .status = realview_mmc_status,
  131. };
  132. struct mmc_platform_data realview_mmc1_plat_data = {
  133. .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
  134. .status = realview_mmc_status,
  135. };
  136. /*
  137. * Clock handling
  138. */
  139. static const struct icst307_params realview_oscvco_params = {
  140. .ref = 24000,
  141. .vco_max = 200000,
  142. .vd_min = 4 + 8,
  143. .vd_max = 511 + 8,
  144. .rd_min = 1 + 2,
  145. .rd_max = 127 + 2,
  146. };
  147. static void realview_oscvco_set(struct clk *clk, struct icst307_vco vco)
  148. {
  149. void __iomem *sys_lock = __io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_LOCK_OFFSET;
  150. void __iomem *sys_osc;
  151. u32 val;
  152. if (machine_is_realview_pb1176())
  153. sys_osc = __io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_OSC0_OFFSET;
  154. else
  155. sys_osc = __io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_OSC4_OFFSET;
  156. val = readl(sys_osc) & ~0x7ffff;
  157. val |= vco.v | (vco.r << 9) | (vco.s << 16);
  158. writel(0xa05f, sys_lock);
  159. writel(val, sys_osc);
  160. writel(0, sys_lock);
  161. }
  162. struct clk realview_clcd_clk = {
  163. .name = "CLCDCLK",
  164. .params = &realview_oscvco_params,
  165. .setvco = realview_oscvco_set,
  166. };
  167. /*
  168. * CLCD support.
  169. */
  170. #define SYS_CLCD_NLCDIOON (1 << 2)
  171. #define SYS_CLCD_VDDPOSSWITCH (1 << 3)
  172. #define SYS_CLCD_PWR3V5SWITCH (1 << 4)
  173. #define SYS_CLCD_ID_MASK (0x1f << 8)
  174. #define SYS_CLCD_ID_SANYO_3_8 (0x00 << 8)
  175. #define SYS_CLCD_ID_UNKNOWN_8_4 (0x01 << 8)
  176. #define SYS_CLCD_ID_EPSON_2_2 (0x02 << 8)
  177. #define SYS_CLCD_ID_SANYO_2_5 (0x07 << 8)
  178. #define SYS_CLCD_ID_VGA (0x1f << 8)
  179. static struct clcd_panel vga = {
  180. .mode = {
  181. .name = "VGA",
  182. .refresh = 60,
  183. .xres = 640,
  184. .yres = 480,
  185. .pixclock = 39721,
  186. .left_margin = 40,
  187. .right_margin = 24,
  188. .upper_margin = 32,
  189. .lower_margin = 11,
  190. .hsync_len = 96,
  191. .vsync_len = 2,
  192. .sync = 0,
  193. .vmode = FB_VMODE_NONINTERLACED,
  194. },
  195. .width = -1,
  196. .height = -1,
  197. .tim2 = TIM2_BCD | TIM2_IPC,
  198. .cntl = CNTL_LCDTFT | CNTL_BGR | CNTL_LCDVCOMP(1),
  199. .bpp = 16,
  200. };
  201. static struct clcd_panel xvga = {
  202. .mode = {
  203. .name = "XVGA",
  204. .refresh = 60,
  205. .xres = 1024,
  206. .yres = 768,
  207. .pixclock = 15748,
  208. .left_margin = 152,
  209. .right_margin = 48,
  210. .upper_margin = 23,
  211. .lower_margin = 3,
  212. .hsync_len = 104,
  213. .vsync_len = 4,
  214. .sync = 0,
  215. .vmode = FB_VMODE_NONINTERLACED,
  216. },
  217. .width = -1,
  218. .height = -1,
  219. .tim2 = TIM2_BCD | TIM2_IPC,
  220. .cntl = CNTL_LCDTFT | CNTL_BGR | CNTL_LCDVCOMP(1),
  221. .bpp = 16,
  222. };
  223. static struct clcd_panel sanyo_3_8_in = {
  224. .mode = {
  225. .name = "Sanyo QVGA",
  226. .refresh = 116,
  227. .xres = 320,
  228. .yres = 240,
  229. .pixclock = 100000,
  230. .left_margin = 6,
  231. .right_margin = 6,
  232. .upper_margin = 5,
  233. .lower_margin = 5,
  234. .hsync_len = 6,
  235. .vsync_len = 6,
  236. .sync = 0,
  237. .vmode = FB_VMODE_NONINTERLACED,
  238. },
  239. .width = -1,
  240. .height = -1,
  241. .tim2 = TIM2_BCD,
  242. .cntl = CNTL_LCDTFT | CNTL_BGR | CNTL_LCDVCOMP(1),
  243. .bpp = 16,
  244. };
  245. static struct clcd_panel sanyo_2_5_in = {
  246. .mode = {
  247. .name = "Sanyo QVGA Portrait",
  248. .refresh = 116,
  249. .xres = 240,
  250. .yres = 320,
  251. .pixclock = 100000,
  252. .left_margin = 20,
  253. .right_margin = 10,
  254. .upper_margin = 2,
  255. .lower_margin = 2,
  256. .hsync_len = 10,
  257. .vsync_len = 2,
  258. .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  259. .vmode = FB_VMODE_NONINTERLACED,
  260. },
  261. .width = -1,
  262. .height = -1,
  263. .tim2 = TIM2_IVS | TIM2_IHS | TIM2_IPC,
  264. .cntl = CNTL_LCDTFT | CNTL_BGR | CNTL_LCDVCOMP(1),
  265. .bpp = 16,
  266. };
  267. static struct clcd_panel epson_2_2_in = {
  268. .mode = {
  269. .name = "Epson QCIF",
  270. .refresh = 390,
  271. .xres = 176,
  272. .yres = 220,
  273. .pixclock = 62500,
  274. .left_margin = 3,
  275. .right_margin = 2,
  276. .upper_margin = 1,
  277. .lower_margin = 0,
  278. .hsync_len = 3,
  279. .vsync_len = 2,
  280. .sync = 0,
  281. .vmode = FB_VMODE_NONINTERLACED,
  282. },
  283. .width = -1,
  284. .height = -1,
  285. .tim2 = TIM2_BCD | TIM2_IPC,
  286. .cntl = CNTL_LCDTFT | CNTL_BGR | CNTL_LCDVCOMP(1),
  287. .bpp = 16,
  288. };
  289. /*
  290. * Detect which LCD panel is connected, and return the appropriate
  291. * clcd_panel structure. Note: we do not have any information on
  292. * the required timings for the 8.4in panel, so we presently assume
  293. * VGA timings.
  294. */
  295. static struct clcd_panel *realview_clcd_panel(void)
  296. {
  297. void __iomem *sys_clcd = __io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_CLCD_OFFSET;
  298. struct clcd_panel *vga_panel;
  299. struct clcd_panel *panel;
  300. u32 val;
  301. if (machine_is_realview_eb())
  302. vga_panel = &vga;
  303. else
  304. vga_panel = &xvga;
  305. val = readl(sys_clcd) & SYS_CLCD_ID_MASK;
  306. if (val == SYS_CLCD_ID_SANYO_3_8)
  307. panel = &sanyo_3_8_in;
  308. else if (val == SYS_CLCD_ID_SANYO_2_5)
  309. panel = &sanyo_2_5_in;
  310. else if (val == SYS_CLCD_ID_EPSON_2_2)
  311. panel = &epson_2_2_in;
  312. else if (val == SYS_CLCD_ID_VGA)
  313. panel = vga_panel;
  314. else {
  315. printk(KERN_ERR "CLCD: unknown LCD panel ID 0x%08x, using VGA\n",
  316. val);
  317. panel = vga_panel;
  318. }
  319. return panel;
  320. }
  321. /*
  322. * Disable all display connectors on the interface module.
  323. */
  324. static void realview_clcd_disable(struct clcd_fb *fb)
  325. {
  326. void __iomem *sys_clcd = __io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_CLCD_OFFSET;
  327. u32 val;
  328. val = readl(sys_clcd);
  329. val &= ~SYS_CLCD_NLCDIOON | SYS_CLCD_PWR3V5SWITCH;
  330. writel(val, sys_clcd);
  331. }
  332. /*
  333. * Enable the relevant connector on the interface module.
  334. */
  335. static void realview_clcd_enable(struct clcd_fb *fb)
  336. {
  337. void __iomem *sys_clcd = __io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_CLCD_OFFSET;
  338. u32 val;
  339. /*
  340. * Enable the PSUs
  341. */
  342. val = readl(sys_clcd);
  343. val |= SYS_CLCD_NLCDIOON | SYS_CLCD_PWR3V5SWITCH;
  344. writel(val, sys_clcd);
  345. }
  346. static int realview_clcd_setup(struct clcd_fb *fb)
  347. {
  348. unsigned long framesize;
  349. dma_addr_t dma;
  350. if (machine_is_realview_eb())
  351. /* VGA, 16bpp */
  352. framesize = 640 * 480 * 2;
  353. else
  354. /* XVGA, 16bpp */
  355. framesize = 1024 * 768 * 2;
  356. fb->panel = realview_clcd_panel();
  357. fb->fb.screen_base = dma_alloc_writecombine(&fb->dev->dev, framesize,
  358. &dma, GFP_KERNEL);
  359. if (!fb->fb.screen_base) {
  360. printk(KERN_ERR "CLCD: unable to map framebuffer\n");
  361. return -ENOMEM;
  362. }
  363. fb->fb.fix.smem_start = dma;
  364. fb->fb.fix.smem_len = framesize;
  365. return 0;
  366. }
  367. static int realview_clcd_mmap(struct clcd_fb *fb, struct vm_area_struct *vma)
  368. {
  369. return dma_mmap_writecombine(&fb->dev->dev, vma,
  370. fb->fb.screen_base,
  371. fb->fb.fix.smem_start,
  372. fb->fb.fix.smem_len);
  373. }
  374. static void realview_clcd_remove(struct clcd_fb *fb)
  375. {
  376. dma_free_writecombine(&fb->dev->dev, fb->fb.fix.smem_len,
  377. fb->fb.screen_base, fb->fb.fix.smem_start);
  378. }
  379. struct clcd_board clcd_plat_data = {
  380. .name = "RealView",
  381. .check = clcdfb_check,
  382. .decode = clcdfb_decode,
  383. .disable = realview_clcd_disable,
  384. .enable = realview_clcd_enable,
  385. .setup = realview_clcd_setup,
  386. .mmap = realview_clcd_mmap,
  387. .remove = realview_clcd_remove,
  388. };
  389. #ifdef CONFIG_LEDS
  390. #define VA_LEDS_BASE (__io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_LED_OFFSET)
  391. void realview_leds_event(led_event_t ledevt)
  392. {
  393. unsigned long flags;
  394. u32 val;
  395. local_irq_save(flags);
  396. val = readl(VA_LEDS_BASE);
  397. switch (ledevt) {
  398. case led_idle_start:
  399. val = val & ~REALVIEW_SYS_LED0;
  400. break;
  401. case led_idle_end:
  402. val = val | REALVIEW_SYS_LED0;
  403. break;
  404. case led_timer:
  405. val = val ^ REALVIEW_SYS_LED1;
  406. break;
  407. case led_halted:
  408. val = 0;
  409. break;
  410. default:
  411. break;
  412. }
  413. writel(val, VA_LEDS_BASE);
  414. local_irq_restore(flags);
  415. }
  416. #endif /* CONFIG_LEDS */
  417. /*
  418. * Where is the timer (VA)?
  419. */
  420. void __iomem *timer0_va_base;
  421. void __iomem *timer1_va_base;
  422. void __iomem *timer2_va_base;
  423. void __iomem *timer3_va_base;
  424. /*
  425. * How long is the timer interval?
  426. */
  427. #define TIMER_INTERVAL (TICKS_PER_uSEC * mSEC_10)
  428. #if TIMER_INTERVAL >= 0x100000
  429. #define TIMER_RELOAD (TIMER_INTERVAL >> 8)
  430. #define TIMER_DIVISOR (TIMER_CTRL_DIV256)
  431. #define TICKS2USECS(x) (256 * (x) / TICKS_PER_uSEC)
  432. #elif TIMER_INTERVAL >= 0x10000
  433. #define TIMER_RELOAD (TIMER_INTERVAL >> 4) /* Divide by 16 */
  434. #define TIMER_DIVISOR (TIMER_CTRL_DIV16)
  435. #define TICKS2USECS(x) (16 * (x) / TICKS_PER_uSEC)
  436. #else
  437. #define TIMER_RELOAD (TIMER_INTERVAL)
  438. #define TIMER_DIVISOR (TIMER_CTRL_DIV1)
  439. #define TICKS2USECS(x) ((x) / TICKS_PER_uSEC)
  440. #endif
  441. static void timer_set_mode(enum clock_event_mode mode,
  442. struct clock_event_device *clk)
  443. {
  444. unsigned long ctrl;
  445. switch(mode) {
  446. case CLOCK_EVT_MODE_PERIODIC:
  447. writel(TIMER_RELOAD, timer0_va_base + TIMER_LOAD);
  448. ctrl = TIMER_CTRL_PERIODIC;
  449. ctrl |= TIMER_CTRL_32BIT | TIMER_CTRL_IE | TIMER_CTRL_ENABLE;
  450. break;
  451. case CLOCK_EVT_MODE_ONESHOT:
  452. /* period set, and timer enabled in 'next_event' hook */
  453. ctrl = TIMER_CTRL_ONESHOT;
  454. ctrl |= TIMER_CTRL_32BIT | TIMER_CTRL_IE;
  455. break;
  456. case CLOCK_EVT_MODE_UNUSED:
  457. case CLOCK_EVT_MODE_SHUTDOWN:
  458. default:
  459. ctrl = 0;
  460. }
  461. writel(ctrl, timer0_va_base + TIMER_CTRL);
  462. }
  463. static int timer_set_next_event(unsigned long evt,
  464. struct clock_event_device *unused)
  465. {
  466. unsigned long ctrl = readl(timer0_va_base + TIMER_CTRL);
  467. writel(evt, timer0_va_base + TIMER_LOAD);
  468. writel(ctrl | TIMER_CTRL_ENABLE, timer0_va_base + TIMER_CTRL);
  469. return 0;
  470. }
  471. static struct clock_event_device timer0_clockevent = {
  472. .name = "timer0",
  473. .shift = 32,
  474. .features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT,
  475. .set_mode = timer_set_mode,
  476. .set_next_event = timer_set_next_event,
  477. .rating = 300,
  478. .cpumask = CPU_MASK_ALL,
  479. };
  480. static void __init realview_clockevents_init(unsigned int timer_irq)
  481. {
  482. timer0_clockevent.irq = timer_irq;
  483. timer0_clockevent.mult =
  484. div_sc(1000000, NSEC_PER_SEC, timer0_clockevent.shift);
  485. timer0_clockevent.max_delta_ns =
  486. clockevent_delta2ns(0xffffffff, &timer0_clockevent);
  487. timer0_clockevent.min_delta_ns =
  488. clockevent_delta2ns(0xf, &timer0_clockevent);
  489. clockevents_register_device(&timer0_clockevent);
  490. }
  491. /*
  492. * IRQ handler for the timer
  493. */
  494. static irqreturn_t realview_timer_interrupt(int irq, void *dev_id)
  495. {
  496. struct clock_event_device *evt = &timer0_clockevent;
  497. /* clear the interrupt */
  498. writel(1, timer0_va_base + TIMER_INTCLR);
  499. evt->event_handler(evt);
  500. return IRQ_HANDLED;
  501. }
  502. static struct irqaction realview_timer_irq = {
  503. .name = "RealView Timer Tick",
  504. .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
  505. .handler = realview_timer_interrupt,
  506. };
  507. static cycle_t realview_get_cycles(void)
  508. {
  509. return ~readl(timer3_va_base + TIMER_VALUE);
  510. }
  511. static struct clocksource clocksource_realview = {
  512. .name = "timer3",
  513. .rating = 200,
  514. .read = realview_get_cycles,
  515. .mask = CLOCKSOURCE_MASK(32),
  516. .shift = 20,
  517. .flags = CLOCK_SOURCE_IS_CONTINUOUS,
  518. };
  519. static void __init realview_clocksource_init(void)
  520. {
  521. /* setup timer 0 as free-running clocksource */
  522. writel(0, timer3_va_base + TIMER_CTRL);
  523. writel(0xffffffff, timer3_va_base + TIMER_LOAD);
  524. writel(0xffffffff, timer3_va_base + TIMER_VALUE);
  525. writel(TIMER_CTRL_32BIT | TIMER_CTRL_ENABLE | TIMER_CTRL_PERIODIC,
  526. timer3_va_base + TIMER_CTRL);
  527. clocksource_realview.mult =
  528. clocksource_khz2mult(1000, clocksource_realview.shift);
  529. clocksource_register(&clocksource_realview);
  530. }
  531. /*
  532. * Set up the clock source and clock events devices
  533. */
  534. void __init realview_timer_init(unsigned int timer_irq)
  535. {
  536. u32 val;
  537. #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
  538. /*
  539. * The dummy clock device has to be registered before the main device
  540. * so that the latter will broadcast the clock events
  541. */
  542. local_timer_setup();
  543. #endif
  544. /*
  545. * set clock frequency:
  546. * REALVIEW_REFCLK is 32KHz
  547. * REALVIEW_TIMCLK is 1MHz
  548. */
  549. val = readl(__io_address(REALVIEW_SCTL_BASE));
  550. writel((REALVIEW_TIMCLK << REALVIEW_TIMER1_EnSel) |
  551. (REALVIEW_TIMCLK << REALVIEW_TIMER2_EnSel) |
  552. (REALVIEW_TIMCLK << REALVIEW_TIMER3_EnSel) |
  553. (REALVIEW_TIMCLK << REALVIEW_TIMER4_EnSel) | val,
  554. __io_address(REALVIEW_SCTL_BASE));
  555. /*
  556. * Initialise to a known state (all timers off)
  557. */
  558. writel(0, timer0_va_base + TIMER_CTRL);
  559. writel(0, timer1_va_base + TIMER_CTRL);
  560. writel(0, timer2_va_base + TIMER_CTRL);
  561. writel(0, timer3_va_base + TIMER_CTRL);
  562. /*
  563. * Make irqs happen for the system timer
  564. */
  565. setup_irq(timer_irq, &realview_timer_irq);
  566. realview_clocksource_init();
  567. realview_clockevents_init(timer_irq);
  568. }