core.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830
  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 <linux/smsc911x.h>
  32. #include <linux/ata_platform.h>
  33. #include <linux/amba/mmci.h>
  34. #include <asm/clkdev.h>
  35. #include <asm/system.h>
  36. #include <mach/hardware.h>
  37. #include <asm/irq.h>
  38. #include <asm/leds.h>
  39. #include <asm/mach-types.h>
  40. #include <asm/hardware/arm_timer.h>
  41. #include <asm/hardware/icst.h>
  42. #include <asm/mach/arch.h>
  43. #include <asm/mach/flash.h>
  44. #include <asm/mach/irq.h>
  45. #include <asm/mach/map.h>
  46. #include <asm/hardware/gic.h>
  47. #include <mach/clkdev.h>
  48. #include <mach/platform.h>
  49. #include <mach/irqs.h>
  50. #include "core.h"
  51. #define REALVIEW_REFCOUNTER (__io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_24MHz_OFFSET)
  52. /* used by entry-macro.S and platsmp.c */
  53. void __iomem *gic_cpu_base_addr;
  54. #ifdef CONFIG_ZONE_DMA
  55. /*
  56. * Adjust the zones if there are restrictions for DMA access.
  57. */
  58. void __init realview_adjust_zones(int node, unsigned long *size,
  59. unsigned long *hole)
  60. {
  61. unsigned long dma_size = SZ_256M >> PAGE_SHIFT;
  62. if (!machine_is_realview_pbx() || node || (size[0] <= dma_size))
  63. return;
  64. size[ZONE_NORMAL] = size[0] - dma_size;
  65. size[ZONE_DMA] = dma_size;
  66. hole[ZONE_NORMAL] = hole[0];
  67. hole[ZONE_DMA] = 0;
  68. }
  69. #endif
  70. /*
  71. * This is the RealView sched_clock implementation. This has
  72. * a resolution of 41.7ns, and a maximum value of about 179s.
  73. */
  74. unsigned long long sched_clock(void)
  75. {
  76. unsigned long long v;
  77. v = (unsigned long long)readl(REALVIEW_REFCOUNTER) * 125;
  78. do_div(v, 3);
  79. return v;
  80. }
  81. #define REALVIEW_FLASHCTRL (__io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_FLASH_OFFSET)
  82. static int realview_flash_init(void)
  83. {
  84. u32 val;
  85. val = __raw_readl(REALVIEW_FLASHCTRL);
  86. val &= ~REALVIEW_FLASHPROG_FLVPPEN;
  87. __raw_writel(val, REALVIEW_FLASHCTRL);
  88. return 0;
  89. }
  90. static void realview_flash_exit(void)
  91. {
  92. u32 val;
  93. val = __raw_readl(REALVIEW_FLASHCTRL);
  94. val &= ~REALVIEW_FLASHPROG_FLVPPEN;
  95. __raw_writel(val, REALVIEW_FLASHCTRL);
  96. }
  97. static void realview_flash_set_vpp(int on)
  98. {
  99. u32 val;
  100. val = __raw_readl(REALVIEW_FLASHCTRL);
  101. if (on)
  102. val |= REALVIEW_FLASHPROG_FLVPPEN;
  103. else
  104. val &= ~REALVIEW_FLASHPROG_FLVPPEN;
  105. __raw_writel(val, REALVIEW_FLASHCTRL);
  106. }
  107. static struct flash_platform_data realview_flash_data = {
  108. .map_name = "cfi_probe",
  109. .width = 4,
  110. .init = realview_flash_init,
  111. .exit = realview_flash_exit,
  112. .set_vpp = realview_flash_set_vpp,
  113. };
  114. struct platform_device realview_flash_device = {
  115. .name = "armflash",
  116. .id = 0,
  117. .dev = {
  118. .platform_data = &realview_flash_data,
  119. },
  120. };
  121. int realview_flash_register(struct resource *res, u32 num)
  122. {
  123. realview_flash_device.resource = res;
  124. realview_flash_device.num_resources = num;
  125. return platform_device_register(&realview_flash_device);
  126. }
  127. static struct smsc911x_platform_config smsc911x_config = {
  128. .flags = SMSC911X_USE_32BIT,
  129. .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_HIGH,
  130. .irq_type = SMSC911X_IRQ_TYPE_PUSH_PULL,
  131. .phy_interface = PHY_INTERFACE_MODE_MII,
  132. };
  133. static struct platform_device realview_eth_device = {
  134. .name = "smsc911x",
  135. .id = 0,
  136. .num_resources = 2,
  137. };
  138. int realview_eth_register(const char *name, struct resource *res)
  139. {
  140. if (name)
  141. realview_eth_device.name = name;
  142. realview_eth_device.resource = res;
  143. if (strcmp(realview_eth_device.name, "smsc911x") == 0)
  144. realview_eth_device.dev.platform_data = &smsc911x_config;
  145. return platform_device_register(&realview_eth_device);
  146. }
  147. struct platform_device realview_usb_device = {
  148. .name = "isp1760",
  149. .num_resources = 2,
  150. };
  151. int realview_usb_register(struct resource *res)
  152. {
  153. realview_usb_device.resource = res;
  154. return platform_device_register(&realview_usb_device);
  155. }
  156. static struct pata_platform_info pata_platform_data = {
  157. .ioport_shift = 1,
  158. };
  159. static struct resource pata_resources[] = {
  160. [0] = {
  161. .start = REALVIEW_CF_BASE,
  162. .end = REALVIEW_CF_BASE + 0xff,
  163. .flags = IORESOURCE_MEM,
  164. },
  165. [1] = {
  166. .start = REALVIEW_CF_BASE + 0x100,
  167. .end = REALVIEW_CF_BASE + SZ_4K - 1,
  168. .flags = IORESOURCE_MEM,
  169. },
  170. };
  171. struct platform_device realview_cf_device = {
  172. .name = "pata_platform",
  173. .id = -1,
  174. .num_resources = ARRAY_SIZE(pata_resources),
  175. .resource = pata_resources,
  176. .dev = {
  177. .platform_data = &pata_platform_data,
  178. },
  179. };
  180. static struct resource realview_i2c_resource = {
  181. .start = REALVIEW_I2C_BASE,
  182. .end = REALVIEW_I2C_BASE + SZ_4K - 1,
  183. .flags = IORESOURCE_MEM,
  184. };
  185. struct platform_device realview_i2c_device = {
  186. .name = "versatile-i2c",
  187. .id = 0,
  188. .num_resources = 1,
  189. .resource = &realview_i2c_resource,
  190. };
  191. static struct i2c_board_info realview_i2c_board_info[] = {
  192. {
  193. I2C_BOARD_INFO("ds1338", 0xd0 >> 1),
  194. },
  195. };
  196. static int __init realview_i2c_init(void)
  197. {
  198. return i2c_register_board_info(0, realview_i2c_board_info,
  199. ARRAY_SIZE(realview_i2c_board_info));
  200. }
  201. arch_initcall(realview_i2c_init);
  202. #define REALVIEW_SYSMCI (__io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_MCI_OFFSET)
  203. /*
  204. * This is only used if GPIOLIB support is disabled
  205. */
  206. static unsigned int realview_mmc_status(struct device *dev)
  207. {
  208. struct amba_device *adev = container_of(dev, struct amba_device, dev);
  209. u32 mask;
  210. if (adev->res.start == REALVIEW_MMCI0_BASE)
  211. mask = 1;
  212. else
  213. mask = 2;
  214. return readl(REALVIEW_SYSMCI) & mask;
  215. }
  216. struct mmci_platform_data realview_mmc0_plat_data = {
  217. .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
  218. .status = realview_mmc_status,
  219. .gpio_wp = 17,
  220. .gpio_cd = 16,
  221. };
  222. struct mmci_platform_data realview_mmc1_plat_data = {
  223. .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
  224. .status = realview_mmc_status,
  225. .gpio_wp = 19,
  226. .gpio_cd = 18,
  227. };
  228. /*
  229. * Clock handling
  230. */
  231. static const struct icst_params realview_oscvco_params = {
  232. .ref = 24000000,
  233. .vco_max = ICST307_VCO_MAX,
  234. .vco_min = ICST307_VCO_MIN,
  235. .vd_min = 4 + 8,
  236. .vd_max = 511 + 8,
  237. .rd_min = 1 + 2,
  238. .rd_max = 127 + 2,
  239. .s2div = icst307_s2div,
  240. .idx2s = icst307_idx2s,
  241. };
  242. static void realview_oscvco_set(struct clk *clk, struct icst_vco vco)
  243. {
  244. void __iomem *sys_lock = __io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_LOCK_OFFSET;
  245. void __iomem *sys_osc;
  246. u32 val;
  247. if (machine_is_realview_pb1176())
  248. sys_osc = __io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_OSC0_OFFSET;
  249. else
  250. sys_osc = __io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_OSC4_OFFSET;
  251. val = readl(sys_osc) & ~0x7ffff;
  252. val |= vco.v | (vco.r << 9) | (vco.s << 16);
  253. writel(0xa05f, sys_lock);
  254. writel(val, sys_osc);
  255. writel(0, sys_lock);
  256. }
  257. static struct clk oscvco_clk = {
  258. .params = &realview_oscvco_params,
  259. .setvco = realview_oscvco_set,
  260. };
  261. /*
  262. * These are fixed clocks.
  263. */
  264. static struct clk ref24_clk = {
  265. .rate = 24000000,
  266. };
  267. static struct clk_lookup lookups[] = {
  268. { /* UART0 */
  269. .dev_id = "dev:uart0",
  270. .clk = &ref24_clk,
  271. }, { /* UART1 */
  272. .dev_id = "dev:uart1",
  273. .clk = &ref24_clk,
  274. }, { /* UART2 */
  275. .dev_id = "dev:uart2",
  276. .clk = &ref24_clk,
  277. }, { /* UART3 */
  278. .dev_id = "fpga:uart3",
  279. .clk = &ref24_clk,
  280. }, { /* KMI0 */
  281. .dev_id = "fpga:kmi0",
  282. .clk = &ref24_clk,
  283. }, { /* KMI1 */
  284. .dev_id = "fpga:kmi1",
  285. .clk = &ref24_clk,
  286. }, { /* MMC0 */
  287. .dev_id = "fpga:mmc0",
  288. .clk = &ref24_clk,
  289. }, { /* EB:CLCD */
  290. .dev_id = "dev:clcd",
  291. .clk = &oscvco_clk,
  292. }, { /* PB:CLCD */
  293. .dev_id = "issp:clcd",
  294. .clk = &oscvco_clk,
  295. }
  296. };
  297. static int __init clk_init(void)
  298. {
  299. clkdev_add_table(lookups, ARRAY_SIZE(lookups));
  300. return 0;
  301. }
  302. arch_initcall(clk_init);
  303. /*
  304. * CLCD support.
  305. */
  306. #define SYS_CLCD_NLCDIOON (1 << 2)
  307. #define SYS_CLCD_VDDPOSSWITCH (1 << 3)
  308. #define SYS_CLCD_PWR3V5SWITCH (1 << 4)
  309. #define SYS_CLCD_ID_MASK (0x1f << 8)
  310. #define SYS_CLCD_ID_SANYO_3_8 (0x00 << 8)
  311. #define SYS_CLCD_ID_UNKNOWN_8_4 (0x01 << 8)
  312. #define SYS_CLCD_ID_EPSON_2_2 (0x02 << 8)
  313. #define SYS_CLCD_ID_SANYO_2_5 (0x07 << 8)
  314. #define SYS_CLCD_ID_VGA (0x1f << 8)
  315. static struct clcd_panel vga = {
  316. .mode = {
  317. .name = "VGA",
  318. .refresh = 60,
  319. .xres = 640,
  320. .yres = 480,
  321. .pixclock = 39721,
  322. .left_margin = 40,
  323. .right_margin = 24,
  324. .upper_margin = 32,
  325. .lower_margin = 11,
  326. .hsync_len = 96,
  327. .vsync_len = 2,
  328. .sync = 0,
  329. .vmode = FB_VMODE_NONINTERLACED,
  330. },
  331. .width = -1,
  332. .height = -1,
  333. .tim2 = TIM2_BCD | TIM2_IPC,
  334. .cntl = CNTL_LCDTFT | CNTL_BGR | CNTL_LCDVCOMP(1),
  335. .bpp = 16,
  336. };
  337. static struct clcd_panel xvga = {
  338. .mode = {
  339. .name = "XVGA",
  340. .refresh = 60,
  341. .xres = 1024,
  342. .yres = 768,
  343. .pixclock = 15748,
  344. .left_margin = 152,
  345. .right_margin = 48,
  346. .upper_margin = 23,
  347. .lower_margin = 3,
  348. .hsync_len = 104,
  349. .vsync_len = 4,
  350. .sync = 0,
  351. .vmode = FB_VMODE_NONINTERLACED,
  352. },
  353. .width = -1,
  354. .height = -1,
  355. .tim2 = TIM2_BCD | TIM2_IPC,
  356. .cntl = CNTL_LCDTFT | CNTL_BGR | CNTL_LCDVCOMP(1),
  357. .bpp = 16,
  358. };
  359. static struct clcd_panel sanyo_3_8_in = {
  360. .mode = {
  361. .name = "Sanyo QVGA",
  362. .refresh = 116,
  363. .xres = 320,
  364. .yres = 240,
  365. .pixclock = 100000,
  366. .left_margin = 6,
  367. .right_margin = 6,
  368. .upper_margin = 5,
  369. .lower_margin = 5,
  370. .hsync_len = 6,
  371. .vsync_len = 6,
  372. .sync = 0,
  373. .vmode = FB_VMODE_NONINTERLACED,
  374. },
  375. .width = -1,
  376. .height = -1,
  377. .tim2 = TIM2_BCD,
  378. .cntl = CNTL_LCDTFT | CNTL_BGR | CNTL_LCDVCOMP(1),
  379. .bpp = 16,
  380. };
  381. static struct clcd_panel sanyo_2_5_in = {
  382. .mode = {
  383. .name = "Sanyo QVGA Portrait",
  384. .refresh = 116,
  385. .xres = 240,
  386. .yres = 320,
  387. .pixclock = 100000,
  388. .left_margin = 20,
  389. .right_margin = 10,
  390. .upper_margin = 2,
  391. .lower_margin = 2,
  392. .hsync_len = 10,
  393. .vsync_len = 2,
  394. .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  395. .vmode = FB_VMODE_NONINTERLACED,
  396. },
  397. .width = -1,
  398. .height = -1,
  399. .tim2 = TIM2_IVS | TIM2_IHS | TIM2_IPC,
  400. .cntl = CNTL_LCDTFT | CNTL_BGR | CNTL_LCDVCOMP(1),
  401. .bpp = 16,
  402. };
  403. static struct clcd_panel epson_2_2_in = {
  404. .mode = {
  405. .name = "Epson QCIF",
  406. .refresh = 390,
  407. .xres = 176,
  408. .yres = 220,
  409. .pixclock = 62500,
  410. .left_margin = 3,
  411. .right_margin = 2,
  412. .upper_margin = 1,
  413. .lower_margin = 0,
  414. .hsync_len = 3,
  415. .vsync_len = 2,
  416. .sync = 0,
  417. .vmode = FB_VMODE_NONINTERLACED,
  418. },
  419. .width = -1,
  420. .height = -1,
  421. .tim2 = TIM2_BCD | TIM2_IPC,
  422. .cntl = CNTL_LCDTFT | CNTL_BGR | CNTL_LCDVCOMP(1),
  423. .bpp = 16,
  424. };
  425. /*
  426. * Detect which LCD panel is connected, and return the appropriate
  427. * clcd_panel structure. Note: we do not have any information on
  428. * the required timings for the 8.4in panel, so we presently assume
  429. * VGA timings.
  430. */
  431. static struct clcd_panel *realview_clcd_panel(void)
  432. {
  433. void __iomem *sys_clcd = __io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_CLCD_OFFSET;
  434. struct clcd_panel *vga_panel;
  435. struct clcd_panel *panel;
  436. u32 val;
  437. if (machine_is_realview_eb())
  438. vga_panel = &vga;
  439. else
  440. vga_panel = &xvga;
  441. val = readl(sys_clcd) & SYS_CLCD_ID_MASK;
  442. if (val == SYS_CLCD_ID_SANYO_3_8)
  443. panel = &sanyo_3_8_in;
  444. else if (val == SYS_CLCD_ID_SANYO_2_5)
  445. panel = &sanyo_2_5_in;
  446. else if (val == SYS_CLCD_ID_EPSON_2_2)
  447. panel = &epson_2_2_in;
  448. else if (val == SYS_CLCD_ID_VGA)
  449. panel = vga_panel;
  450. else {
  451. printk(KERN_ERR "CLCD: unknown LCD panel ID 0x%08x, using VGA\n",
  452. val);
  453. panel = vga_panel;
  454. }
  455. return panel;
  456. }
  457. /*
  458. * Disable all display connectors on the interface module.
  459. */
  460. static void realview_clcd_disable(struct clcd_fb *fb)
  461. {
  462. void __iomem *sys_clcd = __io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_CLCD_OFFSET;
  463. u32 val;
  464. val = readl(sys_clcd);
  465. val &= ~SYS_CLCD_NLCDIOON | SYS_CLCD_PWR3V5SWITCH;
  466. writel(val, sys_clcd);
  467. }
  468. /*
  469. * Enable the relevant connector on the interface module.
  470. */
  471. static void realview_clcd_enable(struct clcd_fb *fb)
  472. {
  473. void __iomem *sys_clcd = __io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_CLCD_OFFSET;
  474. u32 val;
  475. /*
  476. * Enable the PSUs
  477. */
  478. val = readl(sys_clcd);
  479. val |= SYS_CLCD_NLCDIOON | SYS_CLCD_PWR3V5SWITCH;
  480. writel(val, sys_clcd);
  481. }
  482. static int realview_clcd_setup(struct clcd_fb *fb)
  483. {
  484. unsigned long framesize;
  485. dma_addr_t dma;
  486. if (machine_is_realview_eb())
  487. /* VGA, 16bpp */
  488. framesize = 640 * 480 * 2;
  489. else
  490. /* XVGA, 16bpp */
  491. framesize = 1024 * 768 * 2;
  492. fb->panel = realview_clcd_panel();
  493. fb->fb.screen_base = dma_alloc_writecombine(&fb->dev->dev, framesize,
  494. &dma, GFP_KERNEL | GFP_DMA);
  495. if (!fb->fb.screen_base) {
  496. printk(KERN_ERR "CLCD: unable to map framebuffer\n");
  497. return -ENOMEM;
  498. }
  499. fb->fb.fix.smem_start = dma;
  500. fb->fb.fix.smem_len = framesize;
  501. return 0;
  502. }
  503. static int realview_clcd_mmap(struct clcd_fb *fb, struct vm_area_struct *vma)
  504. {
  505. return dma_mmap_writecombine(&fb->dev->dev, vma,
  506. fb->fb.screen_base,
  507. fb->fb.fix.smem_start,
  508. fb->fb.fix.smem_len);
  509. }
  510. static void realview_clcd_remove(struct clcd_fb *fb)
  511. {
  512. dma_free_writecombine(&fb->dev->dev, fb->fb.fix.smem_len,
  513. fb->fb.screen_base, fb->fb.fix.smem_start);
  514. }
  515. struct clcd_board clcd_plat_data = {
  516. .name = "RealView",
  517. .check = clcdfb_check,
  518. .decode = clcdfb_decode,
  519. .disable = realview_clcd_disable,
  520. .enable = realview_clcd_enable,
  521. .setup = realview_clcd_setup,
  522. .mmap = realview_clcd_mmap,
  523. .remove = realview_clcd_remove,
  524. };
  525. #ifdef CONFIG_LEDS
  526. #define VA_LEDS_BASE (__io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_LED_OFFSET)
  527. void realview_leds_event(led_event_t ledevt)
  528. {
  529. unsigned long flags;
  530. u32 val;
  531. u32 led = 1 << smp_processor_id();
  532. local_irq_save(flags);
  533. val = readl(VA_LEDS_BASE);
  534. switch (ledevt) {
  535. case led_idle_start:
  536. val = val & ~led;
  537. break;
  538. case led_idle_end:
  539. val = val | led;
  540. break;
  541. case led_timer:
  542. val = val ^ REALVIEW_SYS_LED7;
  543. break;
  544. case led_halted:
  545. val = 0;
  546. break;
  547. default:
  548. break;
  549. }
  550. writel(val, VA_LEDS_BASE);
  551. local_irq_restore(flags);
  552. }
  553. #endif /* CONFIG_LEDS */
  554. /*
  555. * Where is the timer (VA)?
  556. */
  557. void __iomem *timer0_va_base;
  558. void __iomem *timer1_va_base;
  559. void __iomem *timer2_va_base;
  560. void __iomem *timer3_va_base;
  561. /*
  562. * How long is the timer interval?
  563. */
  564. #define TIMER_INTERVAL (TICKS_PER_uSEC * mSEC_10)
  565. #if TIMER_INTERVAL >= 0x100000
  566. #define TIMER_RELOAD (TIMER_INTERVAL >> 8)
  567. #define TIMER_DIVISOR (TIMER_CTRL_DIV256)
  568. #define TICKS2USECS(x) (256 * (x) / TICKS_PER_uSEC)
  569. #elif TIMER_INTERVAL >= 0x10000
  570. #define TIMER_RELOAD (TIMER_INTERVAL >> 4) /* Divide by 16 */
  571. #define TIMER_DIVISOR (TIMER_CTRL_DIV16)
  572. #define TICKS2USECS(x) (16 * (x) / TICKS_PER_uSEC)
  573. #else
  574. #define TIMER_RELOAD (TIMER_INTERVAL)
  575. #define TIMER_DIVISOR (TIMER_CTRL_DIV1)
  576. #define TICKS2USECS(x) ((x) / TICKS_PER_uSEC)
  577. #endif
  578. static void timer_set_mode(enum clock_event_mode mode,
  579. struct clock_event_device *clk)
  580. {
  581. unsigned long ctrl;
  582. switch(mode) {
  583. case CLOCK_EVT_MODE_PERIODIC:
  584. writel(TIMER_RELOAD, timer0_va_base + TIMER_LOAD);
  585. ctrl = TIMER_CTRL_PERIODIC;
  586. ctrl |= TIMER_CTRL_32BIT | TIMER_CTRL_IE | TIMER_CTRL_ENABLE;
  587. break;
  588. case CLOCK_EVT_MODE_ONESHOT:
  589. /* period set, and timer enabled in 'next_event' hook */
  590. ctrl = TIMER_CTRL_ONESHOT;
  591. ctrl |= TIMER_CTRL_32BIT | TIMER_CTRL_IE;
  592. break;
  593. case CLOCK_EVT_MODE_UNUSED:
  594. case CLOCK_EVT_MODE_SHUTDOWN:
  595. default:
  596. ctrl = 0;
  597. }
  598. writel(ctrl, timer0_va_base + TIMER_CTRL);
  599. }
  600. static int timer_set_next_event(unsigned long evt,
  601. struct clock_event_device *unused)
  602. {
  603. unsigned long ctrl = readl(timer0_va_base + TIMER_CTRL);
  604. writel(evt, timer0_va_base + TIMER_LOAD);
  605. writel(ctrl | TIMER_CTRL_ENABLE, timer0_va_base + TIMER_CTRL);
  606. return 0;
  607. }
  608. static struct clock_event_device timer0_clockevent = {
  609. .name = "timer0",
  610. .shift = 32,
  611. .features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT,
  612. .set_mode = timer_set_mode,
  613. .set_next_event = timer_set_next_event,
  614. .rating = 300,
  615. .cpumask = cpu_all_mask,
  616. };
  617. static void __init realview_clockevents_init(unsigned int timer_irq)
  618. {
  619. timer0_clockevent.irq = timer_irq;
  620. timer0_clockevent.mult =
  621. div_sc(1000000, NSEC_PER_SEC, timer0_clockevent.shift);
  622. timer0_clockevent.max_delta_ns =
  623. clockevent_delta2ns(0xffffffff, &timer0_clockevent);
  624. timer0_clockevent.min_delta_ns =
  625. clockevent_delta2ns(0xf, &timer0_clockevent);
  626. clockevents_register_device(&timer0_clockevent);
  627. }
  628. /*
  629. * IRQ handler for the timer
  630. */
  631. static irqreturn_t realview_timer_interrupt(int irq, void *dev_id)
  632. {
  633. struct clock_event_device *evt = &timer0_clockevent;
  634. /* clear the interrupt */
  635. writel(1, timer0_va_base + TIMER_INTCLR);
  636. evt->event_handler(evt);
  637. return IRQ_HANDLED;
  638. }
  639. static struct irqaction realview_timer_irq = {
  640. .name = "RealView Timer Tick",
  641. .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
  642. .handler = realview_timer_interrupt,
  643. };
  644. static cycle_t realview_get_cycles(struct clocksource *cs)
  645. {
  646. return ~readl(timer3_va_base + TIMER_VALUE);
  647. }
  648. static struct clocksource clocksource_realview = {
  649. .name = "timer3",
  650. .rating = 200,
  651. .read = realview_get_cycles,
  652. .mask = CLOCKSOURCE_MASK(32),
  653. .shift = 20,
  654. .flags = CLOCK_SOURCE_IS_CONTINUOUS,
  655. };
  656. static void __init realview_clocksource_init(void)
  657. {
  658. /* setup timer 0 as free-running clocksource */
  659. writel(0, timer3_va_base + TIMER_CTRL);
  660. writel(0xffffffff, timer3_va_base + TIMER_LOAD);
  661. writel(0xffffffff, timer3_va_base + TIMER_VALUE);
  662. writel(TIMER_CTRL_32BIT | TIMER_CTRL_ENABLE | TIMER_CTRL_PERIODIC,
  663. timer3_va_base + TIMER_CTRL);
  664. clocksource_realview.mult =
  665. clocksource_khz2mult(1000, clocksource_realview.shift);
  666. clocksource_register(&clocksource_realview);
  667. }
  668. /*
  669. * Set up the clock source and clock events devices
  670. */
  671. void __init realview_timer_init(unsigned int timer_irq)
  672. {
  673. u32 val;
  674. /*
  675. * set clock frequency:
  676. * REALVIEW_REFCLK is 32KHz
  677. * REALVIEW_TIMCLK is 1MHz
  678. */
  679. val = readl(__io_address(REALVIEW_SCTL_BASE));
  680. writel((REALVIEW_TIMCLK << REALVIEW_TIMER1_EnSel) |
  681. (REALVIEW_TIMCLK << REALVIEW_TIMER2_EnSel) |
  682. (REALVIEW_TIMCLK << REALVIEW_TIMER3_EnSel) |
  683. (REALVIEW_TIMCLK << REALVIEW_TIMER4_EnSel) | val,
  684. __io_address(REALVIEW_SCTL_BASE));
  685. /*
  686. * Initialise to a known state (all timers off)
  687. */
  688. writel(0, timer0_va_base + TIMER_CTRL);
  689. writel(0, timer1_va_base + TIMER_CTRL);
  690. writel(0, timer2_va_base + TIMER_CTRL);
  691. writel(0, timer3_va_base + TIMER_CTRL);
  692. /*
  693. * Make irqs happen for the system timer
  694. */
  695. setup_irq(timer_irq, &realview_timer_irq);
  696. realview_clocksource_init();
  697. realview_clockevents_init(timer_irq);
  698. }
  699. /*
  700. * Setup the memory banks.
  701. */
  702. void realview_fixup(struct machine_desc *mdesc, struct tag *tags, char **from,
  703. struct meminfo *meminfo)
  704. {
  705. /*
  706. * Most RealView platforms have 512MB contiguous RAM at 0x70000000.
  707. * Half of this is mirrored at 0.
  708. */
  709. #ifdef CONFIG_REALVIEW_HIGH_PHYS_OFFSET
  710. meminfo->bank[0].start = 0x70000000;
  711. meminfo->bank[0].size = SZ_512M;
  712. meminfo->nr_banks = 1;
  713. #else
  714. meminfo->bank[0].start = 0;
  715. meminfo->bank[0].size = SZ_256M;
  716. meminfo->nr_banks = 1;
  717. #endif
  718. }