core.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  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/clkdev.h>
  32. #include <asm/system.h>
  33. #include <mach/hardware.h>
  34. #include <asm/irq.h>
  35. #include <asm/leds.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 */
  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 = __io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_OSC4_OFFSET;
  151. u32 val;
  152. val = readl(sys_osc) & ~0x7ffff;
  153. val |= vco.v | (vco.r << 9) | (vco.s << 16);
  154. writel(0xa05f, sys_lock);
  155. writel(val, sys_osc);
  156. writel(0, sys_lock);
  157. }
  158. static struct clk oscvco_clk = {
  159. .params = &realview_oscvco_params,
  160. .setvco = realview_oscvco_set,
  161. };
  162. /*
  163. * These are fixed clocks.
  164. */
  165. static struct clk ref24_clk = {
  166. .rate = 24000000,
  167. };
  168. static struct clk_lookup lookups[] = {
  169. { /* UART0 */
  170. .dev_id = "dev:f1",
  171. .clk = &ref24_clk,
  172. }, { /* UART1 */
  173. .dev_id = "dev:f2",
  174. .clk = &ref24_clk,
  175. }, { /* UART2 */
  176. .dev_id = "dev:f3",
  177. .clk = &ref24_clk,
  178. }, { /* UART3 */
  179. .dev_id = "fpga:09",
  180. .clk = &ref24_clk,
  181. }, { /* KMI0 */
  182. .dev_id = "fpga:06",
  183. .clk = &ref24_clk,
  184. }, { /* KMI1 */
  185. .dev_id = "fpga:07",
  186. .clk = &ref24_clk,
  187. }, { /* MMC0 */
  188. .dev_id = "fpga:05",
  189. .clk = &ref24_clk,
  190. }, { /* EB:CLCD */
  191. .dev_id = "dev:20",
  192. .clk = &oscvco_clk,
  193. }, { /* PB:CLCD */
  194. .dev_id = "issp:20",
  195. .clk = &oscvco_clk,
  196. }
  197. };
  198. static int __init clk_init(void)
  199. {
  200. int i;
  201. for (i = 0; i < ARRAY_SIZE(lookups); i++)
  202. clkdev_add(&lookups[i]);
  203. return 0;
  204. }
  205. arch_initcall(clk_init);
  206. /*
  207. * CLCD support.
  208. */
  209. #define SYS_CLCD_NLCDIOON (1 << 2)
  210. #define SYS_CLCD_VDDPOSSWITCH (1 << 3)
  211. #define SYS_CLCD_PWR3V5SWITCH (1 << 4)
  212. #define SYS_CLCD_ID_MASK (0x1f << 8)
  213. #define SYS_CLCD_ID_SANYO_3_8 (0x00 << 8)
  214. #define SYS_CLCD_ID_UNKNOWN_8_4 (0x01 << 8)
  215. #define SYS_CLCD_ID_EPSON_2_2 (0x02 << 8)
  216. #define SYS_CLCD_ID_SANYO_2_5 (0x07 << 8)
  217. #define SYS_CLCD_ID_VGA (0x1f << 8)
  218. static struct clcd_panel vga = {
  219. .mode = {
  220. .name = "VGA",
  221. .refresh = 60,
  222. .xres = 640,
  223. .yres = 480,
  224. .pixclock = 39721,
  225. .left_margin = 40,
  226. .right_margin = 24,
  227. .upper_margin = 32,
  228. .lower_margin = 11,
  229. .hsync_len = 96,
  230. .vsync_len = 2,
  231. .sync = 0,
  232. .vmode = FB_VMODE_NONINTERLACED,
  233. },
  234. .width = -1,
  235. .height = -1,
  236. .tim2 = TIM2_BCD | TIM2_IPC,
  237. .cntl = CNTL_LCDTFT | CNTL_LCDVCOMP(1),
  238. .bpp = 16,
  239. };
  240. static struct clcd_panel sanyo_3_8_in = {
  241. .mode = {
  242. .name = "Sanyo QVGA",
  243. .refresh = 116,
  244. .xres = 320,
  245. .yres = 240,
  246. .pixclock = 100000,
  247. .left_margin = 6,
  248. .right_margin = 6,
  249. .upper_margin = 5,
  250. .lower_margin = 5,
  251. .hsync_len = 6,
  252. .vsync_len = 6,
  253. .sync = 0,
  254. .vmode = FB_VMODE_NONINTERLACED,
  255. },
  256. .width = -1,
  257. .height = -1,
  258. .tim2 = TIM2_BCD,
  259. .cntl = CNTL_LCDTFT | CNTL_LCDVCOMP(1),
  260. .bpp = 16,
  261. };
  262. static struct clcd_panel sanyo_2_5_in = {
  263. .mode = {
  264. .name = "Sanyo QVGA Portrait",
  265. .refresh = 116,
  266. .xres = 240,
  267. .yres = 320,
  268. .pixclock = 100000,
  269. .left_margin = 20,
  270. .right_margin = 10,
  271. .upper_margin = 2,
  272. .lower_margin = 2,
  273. .hsync_len = 10,
  274. .vsync_len = 2,
  275. .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  276. .vmode = FB_VMODE_NONINTERLACED,
  277. },
  278. .width = -1,
  279. .height = -1,
  280. .tim2 = TIM2_IVS | TIM2_IHS | TIM2_IPC,
  281. .cntl = CNTL_LCDTFT | CNTL_LCDVCOMP(1),
  282. .bpp = 16,
  283. };
  284. static struct clcd_panel epson_2_2_in = {
  285. .mode = {
  286. .name = "Epson QCIF",
  287. .refresh = 390,
  288. .xres = 176,
  289. .yres = 220,
  290. .pixclock = 62500,
  291. .left_margin = 3,
  292. .right_margin = 2,
  293. .upper_margin = 1,
  294. .lower_margin = 0,
  295. .hsync_len = 3,
  296. .vsync_len = 2,
  297. .sync = 0,
  298. .vmode = FB_VMODE_NONINTERLACED,
  299. },
  300. .width = -1,
  301. .height = -1,
  302. .tim2 = TIM2_BCD | TIM2_IPC,
  303. .cntl = CNTL_LCDTFT | CNTL_LCDVCOMP(1),
  304. .bpp = 16,
  305. };
  306. /*
  307. * Detect which LCD panel is connected, and return the appropriate
  308. * clcd_panel structure. Note: we do not have any information on
  309. * the required timings for the 8.4in panel, so we presently assume
  310. * VGA timings.
  311. */
  312. static struct clcd_panel *realview_clcd_panel(void)
  313. {
  314. void __iomem *sys_clcd = __io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_CLCD_OFFSET;
  315. struct clcd_panel *panel = &vga;
  316. u32 val;
  317. val = readl(sys_clcd) & SYS_CLCD_ID_MASK;
  318. if (val == SYS_CLCD_ID_SANYO_3_8)
  319. panel = &sanyo_3_8_in;
  320. else if (val == SYS_CLCD_ID_SANYO_2_5)
  321. panel = &sanyo_2_5_in;
  322. else if (val == SYS_CLCD_ID_EPSON_2_2)
  323. panel = &epson_2_2_in;
  324. else if (val == SYS_CLCD_ID_VGA)
  325. panel = &vga;
  326. else {
  327. printk(KERN_ERR "CLCD: unknown LCD panel ID 0x%08x, using VGA\n",
  328. val);
  329. panel = &vga;
  330. }
  331. return panel;
  332. }
  333. /*
  334. * Disable all display connectors on the interface module.
  335. */
  336. static void realview_clcd_disable(struct clcd_fb *fb)
  337. {
  338. void __iomem *sys_clcd = __io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_CLCD_OFFSET;
  339. u32 val;
  340. val = readl(sys_clcd);
  341. val &= ~SYS_CLCD_NLCDIOON | SYS_CLCD_PWR3V5SWITCH;
  342. writel(val, sys_clcd);
  343. }
  344. /*
  345. * Enable the relevant connector on the interface module.
  346. */
  347. static void realview_clcd_enable(struct clcd_fb *fb)
  348. {
  349. void __iomem *sys_clcd = __io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_CLCD_OFFSET;
  350. u32 val;
  351. /*
  352. * Enable the PSUs
  353. */
  354. val = readl(sys_clcd);
  355. val |= SYS_CLCD_NLCDIOON | SYS_CLCD_PWR3V5SWITCH;
  356. writel(val, sys_clcd);
  357. }
  358. static unsigned long framesize = SZ_1M;
  359. static int realview_clcd_setup(struct clcd_fb *fb)
  360. {
  361. dma_addr_t dma;
  362. fb->panel = realview_clcd_panel();
  363. fb->fb.screen_base = dma_alloc_writecombine(&fb->dev->dev, framesize,
  364. &dma, GFP_KERNEL);
  365. if (!fb->fb.screen_base) {
  366. printk(KERN_ERR "CLCD: unable to map framebuffer\n");
  367. return -ENOMEM;
  368. }
  369. fb->fb.fix.smem_start = dma;
  370. fb->fb.fix.smem_len = framesize;
  371. return 0;
  372. }
  373. static int realview_clcd_mmap(struct clcd_fb *fb, struct vm_area_struct *vma)
  374. {
  375. return dma_mmap_writecombine(&fb->dev->dev, vma,
  376. fb->fb.screen_base,
  377. fb->fb.fix.smem_start,
  378. fb->fb.fix.smem_len);
  379. }
  380. static void realview_clcd_remove(struct clcd_fb *fb)
  381. {
  382. dma_free_writecombine(&fb->dev->dev, fb->fb.fix.smem_len,
  383. fb->fb.screen_base, fb->fb.fix.smem_start);
  384. }
  385. struct clcd_board clcd_plat_data = {
  386. .name = "RealView",
  387. .check = clcdfb_check,
  388. .decode = clcdfb_decode,
  389. .disable = realview_clcd_disable,
  390. .enable = realview_clcd_enable,
  391. .setup = realview_clcd_setup,
  392. .mmap = realview_clcd_mmap,
  393. .remove = realview_clcd_remove,
  394. };
  395. #ifdef CONFIG_LEDS
  396. #define VA_LEDS_BASE (__io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_LED_OFFSET)
  397. void realview_leds_event(led_event_t ledevt)
  398. {
  399. unsigned long flags;
  400. u32 val;
  401. local_irq_save(flags);
  402. val = readl(VA_LEDS_BASE);
  403. switch (ledevt) {
  404. case led_idle_start:
  405. val = val & ~REALVIEW_SYS_LED0;
  406. break;
  407. case led_idle_end:
  408. val = val | REALVIEW_SYS_LED0;
  409. break;
  410. case led_timer:
  411. val = val ^ REALVIEW_SYS_LED1;
  412. break;
  413. case led_halted:
  414. val = 0;
  415. break;
  416. default:
  417. break;
  418. }
  419. writel(val, VA_LEDS_BASE);
  420. local_irq_restore(flags);
  421. }
  422. #endif /* CONFIG_LEDS */
  423. /*
  424. * Where is the timer (VA)?
  425. */
  426. void __iomem *timer0_va_base;
  427. void __iomem *timer1_va_base;
  428. void __iomem *timer2_va_base;
  429. void __iomem *timer3_va_base;
  430. /*
  431. * How long is the timer interval?
  432. */
  433. #define TIMER_INTERVAL (TICKS_PER_uSEC * mSEC_10)
  434. #if TIMER_INTERVAL >= 0x100000
  435. #define TIMER_RELOAD (TIMER_INTERVAL >> 8)
  436. #define TIMER_DIVISOR (TIMER_CTRL_DIV256)
  437. #define TICKS2USECS(x) (256 * (x) / TICKS_PER_uSEC)
  438. #elif TIMER_INTERVAL >= 0x10000
  439. #define TIMER_RELOAD (TIMER_INTERVAL >> 4) /* Divide by 16 */
  440. #define TIMER_DIVISOR (TIMER_CTRL_DIV16)
  441. #define TICKS2USECS(x) (16 * (x) / TICKS_PER_uSEC)
  442. #else
  443. #define TIMER_RELOAD (TIMER_INTERVAL)
  444. #define TIMER_DIVISOR (TIMER_CTRL_DIV1)
  445. #define TICKS2USECS(x) ((x) / TICKS_PER_uSEC)
  446. #endif
  447. static void timer_set_mode(enum clock_event_mode mode,
  448. struct clock_event_device *clk)
  449. {
  450. unsigned long ctrl;
  451. switch(mode) {
  452. case CLOCK_EVT_MODE_PERIODIC:
  453. writel(TIMER_RELOAD, timer0_va_base + TIMER_LOAD);
  454. ctrl = TIMER_CTRL_PERIODIC;
  455. ctrl |= TIMER_CTRL_32BIT | TIMER_CTRL_IE | TIMER_CTRL_ENABLE;
  456. break;
  457. case CLOCK_EVT_MODE_ONESHOT:
  458. /* period set, and timer enabled in 'next_event' hook */
  459. ctrl = TIMER_CTRL_ONESHOT;
  460. ctrl |= TIMER_CTRL_32BIT | TIMER_CTRL_IE;
  461. break;
  462. case CLOCK_EVT_MODE_UNUSED:
  463. case CLOCK_EVT_MODE_SHUTDOWN:
  464. default:
  465. ctrl = 0;
  466. }
  467. writel(ctrl, timer0_va_base + TIMER_CTRL);
  468. }
  469. static int timer_set_next_event(unsigned long evt,
  470. struct clock_event_device *unused)
  471. {
  472. unsigned long ctrl = readl(timer0_va_base + TIMER_CTRL);
  473. writel(evt, timer0_va_base + TIMER_LOAD);
  474. writel(ctrl | TIMER_CTRL_ENABLE, timer0_va_base + TIMER_CTRL);
  475. return 0;
  476. }
  477. static struct clock_event_device timer0_clockevent = {
  478. .name = "timer0",
  479. .shift = 32,
  480. .features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT,
  481. .set_mode = timer_set_mode,
  482. .set_next_event = timer_set_next_event,
  483. .rating = 300,
  484. .cpumask = CPU_MASK_ALL,
  485. };
  486. static void __init realview_clockevents_init(unsigned int timer_irq)
  487. {
  488. timer0_clockevent.irq = timer_irq;
  489. timer0_clockevent.mult =
  490. div_sc(1000000, NSEC_PER_SEC, timer0_clockevent.shift);
  491. timer0_clockevent.max_delta_ns =
  492. clockevent_delta2ns(0xffffffff, &timer0_clockevent);
  493. timer0_clockevent.min_delta_ns =
  494. clockevent_delta2ns(0xf, &timer0_clockevent);
  495. clockevents_register_device(&timer0_clockevent);
  496. }
  497. /*
  498. * IRQ handler for the timer
  499. */
  500. static irqreturn_t realview_timer_interrupt(int irq, void *dev_id)
  501. {
  502. struct clock_event_device *evt = &timer0_clockevent;
  503. /* clear the interrupt */
  504. writel(1, timer0_va_base + TIMER_INTCLR);
  505. evt->event_handler(evt);
  506. return IRQ_HANDLED;
  507. }
  508. static struct irqaction realview_timer_irq = {
  509. .name = "RealView Timer Tick",
  510. .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
  511. .handler = realview_timer_interrupt,
  512. };
  513. static cycle_t realview_get_cycles(void)
  514. {
  515. return ~readl(timer3_va_base + TIMER_VALUE);
  516. }
  517. static struct clocksource clocksource_realview = {
  518. .name = "timer3",
  519. .rating = 200,
  520. .read = realview_get_cycles,
  521. .mask = CLOCKSOURCE_MASK(32),
  522. .shift = 20,
  523. .flags = CLOCK_SOURCE_IS_CONTINUOUS,
  524. };
  525. static void __init realview_clocksource_init(void)
  526. {
  527. /* setup timer 0 as free-running clocksource */
  528. writel(0, timer3_va_base + TIMER_CTRL);
  529. writel(0xffffffff, timer3_va_base + TIMER_LOAD);
  530. writel(0xffffffff, timer3_va_base + TIMER_VALUE);
  531. writel(TIMER_CTRL_32BIT | TIMER_CTRL_ENABLE | TIMER_CTRL_PERIODIC,
  532. timer3_va_base + TIMER_CTRL);
  533. clocksource_realview.mult =
  534. clocksource_khz2mult(1000, clocksource_realview.shift);
  535. clocksource_register(&clocksource_realview);
  536. }
  537. /*
  538. * Set up the clock source and clock events devices
  539. */
  540. void __init realview_timer_init(unsigned int timer_irq)
  541. {
  542. u32 val;
  543. #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
  544. /*
  545. * The dummy clock device has to be registered before the main device
  546. * so that the latter will broadcast the clock events
  547. */
  548. local_timer_setup(smp_processor_id());
  549. #endif
  550. /*
  551. * set clock frequency:
  552. * REALVIEW_REFCLK is 32KHz
  553. * REALVIEW_TIMCLK is 1MHz
  554. */
  555. val = readl(__io_address(REALVIEW_SCTL_BASE));
  556. writel((REALVIEW_TIMCLK << REALVIEW_TIMER1_EnSel) |
  557. (REALVIEW_TIMCLK << REALVIEW_TIMER2_EnSel) |
  558. (REALVIEW_TIMCLK << REALVIEW_TIMER3_EnSel) |
  559. (REALVIEW_TIMCLK << REALVIEW_TIMER4_EnSel) | val,
  560. __io_address(REALVIEW_SCTL_BASE));
  561. /*
  562. * Initialise to a known state (all timers off)
  563. */
  564. writel(0, timer0_va_base + TIMER_CTRL);
  565. writel(0, timer1_va_base + TIMER_CTRL);
  566. writel(0, timer2_va_base + TIMER_CTRL);
  567. writel(0, timer3_va_base + TIMER_CTRL);
  568. /*
  569. * Make irqs happen for the system timer
  570. */
  571. setup_irq(timer_irq, &realview_timer_irq);
  572. realview_clocksource_init();
  573. realview_clockevents_init(timer_irq);
  574. }