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/icst307.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/platform.h>
  48. #include <mach/irqs.h>
  49. #include "core.h"
  50. #include "clock.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 icst307_params realview_oscvco_params = {
  232. .ref = 24000,
  233. .vco_max = 200000,
  234. .vd_min = 4 + 8,
  235. .vd_max = 511 + 8,
  236. .rd_min = 1 + 2,
  237. .rd_max = 127 + 2,
  238. };
  239. static void realview_oscvco_set(struct clk *clk, struct icst307_vco vco)
  240. {
  241. void __iomem *sys_lock = __io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_LOCK_OFFSET;
  242. void __iomem *sys_osc;
  243. u32 val;
  244. if (machine_is_realview_pb1176())
  245. sys_osc = __io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_OSC0_OFFSET;
  246. else
  247. sys_osc = __io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_OSC4_OFFSET;
  248. val = readl(sys_osc) & ~0x7ffff;
  249. val |= vco.v | (vco.r << 9) | (vco.s << 16);
  250. writel(0xa05f, sys_lock);
  251. writel(val, sys_osc);
  252. writel(0, sys_lock);
  253. }
  254. static struct clk oscvco_clk = {
  255. .params = &realview_oscvco_params,
  256. .setvco = realview_oscvco_set,
  257. };
  258. /*
  259. * These are fixed clocks.
  260. */
  261. static struct clk ref24_clk = {
  262. .rate = 24000000,
  263. };
  264. static struct clk_lookup lookups[] = {
  265. { /* UART0 */
  266. .dev_id = "dev:uart0",
  267. .clk = &ref24_clk,
  268. }, { /* UART1 */
  269. .dev_id = "dev:uart1",
  270. .clk = &ref24_clk,
  271. }, { /* UART2 */
  272. .dev_id = "dev:uart2",
  273. .clk = &ref24_clk,
  274. }, { /* UART3 */
  275. .dev_id = "fpga:uart3",
  276. .clk = &ref24_clk,
  277. }, { /* KMI0 */
  278. .dev_id = "fpga:kmi0",
  279. .clk = &ref24_clk,
  280. }, { /* KMI1 */
  281. .dev_id = "fpga:kmi1",
  282. .clk = &ref24_clk,
  283. }, { /* MMC0 */
  284. .dev_id = "fpga:mmc0",
  285. .clk = &ref24_clk,
  286. }, { /* EB:CLCD */
  287. .dev_id = "dev:clcd",
  288. .clk = &oscvco_clk,
  289. }, { /* PB:CLCD */
  290. .dev_id = "issp:clcd",
  291. .clk = &oscvco_clk,
  292. }
  293. };
  294. static int __init clk_init(void)
  295. {
  296. int i;
  297. for (i = 0; i < ARRAY_SIZE(lookups); i++)
  298. clkdev_add(&lookups[i]);
  299. return 0;
  300. }
  301. arch_initcall(clk_init);
  302. /*
  303. * CLCD support.
  304. */
  305. #define SYS_CLCD_NLCDIOON (1 << 2)
  306. #define SYS_CLCD_VDDPOSSWITCH (1 << 3)
  307. #define SYS_CLCD_PWR3V5SWITCH (1 << 4)
  308. #define SYS_CLCD_ID_MASK (0x1f << 8)
  309. #define SYS_CLCD_ID_SANYO_3_8 (0x00 << 8)
  310. #define SYS_CLCD_ID_UNKNOWN_8_4 (0x01 << 8)
  311. #define SYS_CLCD_ID_EPSON_2_2 (0x02 << 8)
  312. #define SYS_CLCD_ID_SANYO_2_5 (0x07 << 8)
  313. #define SYS_CLCD_ID_VGA (0x1f << 8)
  314. static struct clcd_panel vga = {
  315. .mode = {
  316. .name = "VGA",
  317. .refresh = 60,
  318. .xres = 640,
  319. .yres = 480,
  320. .pixclock = 39721,
  321. .left_margin = 40,
  322. .right_margin = 24,
  323. .upper_margin = 32,
  324. .lower_margin = 11,
  325. .hsync_len = 96,
  326. .vsync_len = 2,
  327. .sync = 0,
  328. .vmode = FB_VMODE_NONINTERLACED,
  329. },
  330. .width = -1,
  331. .height = -1,
  332. .tim2 = TIM2_BCD | TIM2_IPC,
  333. .cntl = CNTL_LCDTFT | CNTL_BGR | CNTL_LCDVCOMP(1),
  334. .bpp = 16,
  335. };
  336. static struct clcd_panel xvga = {
  337. .mode = {
  338. .name = "XVGA",
  339. .refresh = 60,
  340. .xres = 1024,
  341. .yres = 768,
  342. .pixclock = 15748,
  343. .left_margin = 152,
  344. .right_margin = 48,
  345. .upper_margin = 23,
  346. .lower_margin = 3,
  347. .hsync_len = 104,
  348. .vsync_len = 4,
  349. .sync = 0,
  350. .vmode = FB_VMODE_NONINTERLACED,
  351. },
  352. .width = -1,
  353. .height = -1,
  354. .tim2 = TIM2_BCD | TIM2_IPC,
  355. .cntl = CNTL_LCDTFT | CNTL_BGR | CNTL_LCDVCOMP(1),
  356. .bpp = 16,
  357. };
  358. static struct clcd_panel sanyo_3_8_in = {
  359. .mode = {
  360. .name = "Sanyo QVGA",
  361. .refresh = 116,
  362. .xres = 320,
  363. .yres = 240,
  364. .pixclock = 100000,
  365. .left_margin = 6,
  366. .right_margin = 6,
  367. .upper_margin = 5,
  368. .lower_margin = 5,
  369. .hsync_len = 6,
  370. .vsync_len = 6,
  371. .sync = 0,
  372. .vmode = FB_VMODE_NONINTERLACED,
  373. },
  374. .width = -1,
  375. .height = -1,
  376. .tim2 = TIM2_BCD,
  377. .cntl = CNTL_LCDTFT | CNTL_BGR | CNTL_LCDVCOMP(1),
  378. .bpp = 16,
  379. };
  380. static struct clcd_panel sanyo_2_5_in = {
  381. .mode = {
  382. .name = "Sanyo QVGA Portrait",
  383. .refresh = 116,
  384. .xres = 240,
  385. .yres = 320,
  386. .pixclock = 100000,
  387. .left_margin = 20,
  388. .right_margin = 10,
  389. .upper_margin = 2,
  390. .lower_margin = 2,
  391. .hsync_len = 10,
  392. .vsync_len = 2,
  393. .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  394. .vmode = FB_VMODE_NONINTERLACED,
  395. },
  396. .width = -1,
  397. .height = -1,
  398. .tim2 = TIM2_IVS | TIM2_IHS | TIM2_IPC,
  399. .cntl = CNTL_LCDTFT | CNTL_BGR | CNTL_LCDVCOMP(1),
  400. .bpp = 16,
  401. };
  402. static struct clcd_panel epson_2_2_in = {
  403. .mode = {
  404. .name = "Epson QCIF",
  405. .refresh = 390,
  406. .xres = 176,
  407. .yres = 220,
  408. .pixclock = 62500,
  409. .left_margin = 3,
  410. .right_margin = 2,
  411. .upper_margin = 1,
  412. .lower_margin = 0,
  413. .hsync_len = 3,
  414. .vsync_len = 2,
  415. .sync = 0,
  416. .vmode = FB_VMODE_NONINTERLACED,
  417. },
  418. .width = -1,
  419. .height = -1,
  420. .tim2 = TIM2_BCD | TIM2_IPC,
  421. .cntl = CNTL_LCDTFT | CNTL_BGR | CNTL_LCDVCOMP(1),
  422. .bpp = 16,
  423. };
  424. /*
  425. * Detect which LCD panel is connected, and return the appropriate
  426. * clcd_panel structure. Note: we do not have any information on
  427. * the required timings for the 8.4in panel, so we presently assume
  428. * VGA timings.
  429. */
  430. static struct clcd_panel *realview_clcd_panel(void)
  431. {
  432. void __iomem *sys_clcd = __io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_CLCD_OFFSET;
  433. struct clcd_panel *vga_panel;
  434. struct clcd_panel *panel;
  435. u32 val;
  436. if (machine_is_realview_eb())
  437. vga_panel = &vga;
  438. else
  439. vga_panel = &xvga;
  440. val = readl(sys_clcd) & SYS_CLCD_ID_MASK;
  441. if (val == SYS_CLCD_ID_SANYO_3_8)
  442. panel = &sanyo_3_8_in;
  443. else if (val == SYS_CLCD_ID_SANYO_2_5)
  444. panel = &sanyo_2_5_in;
  445. else if (val == SYS_CLCD_ID_EPSON_2_2)
  446. panel = &epson_2_2_in;
  447. else if (val == SYS_CLCD_ID_VGA)
  448. panel = vga_panel;
  449. else {
  450. printk(KERN_ERR "CLCD: unknown LCD panel ID 0x%08x, using VGA\n",
  451. val);
  452. panel = vga_panel;
  453. }
  454. return panel;
  455. }
  456. /*
  457. * Disable all display connectors on the interface module.
  458. */
  459. static void realview_clcd_disable(struct clcd_fb *fb)
  460. {
  461. void __iomem *sys_clcd = __io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_CLCD_OFFSET;
  462. u32 val;
  463. val = readl(sys_clcd);
  464. val &= ~SYS_CLCD_NLCDIOON | SYS_CLCD_PWR3V5SWITCH;
  465. writel(val, sys_clcd);
  466. }
  467. /*
  468. * Enable the relevant connector on the interface module.
  469. */
  470. static void realview_clcd_enable(struct clcd_fb *fb)
  471. {
  472. void __iomem *sys_clcd = __io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_CLCD_OFFSET;
  473. u32 val;
  474. /*
  475. * Enable the PSUs
  476. */
  477. val = readl(sys_clcd);
  478. val |= SYS_CLCD_NLCDIOON | SYS_CLCD_PWR3V5SWITCH;
  479. writel(val, sys_clcd);
  480. }
  481. static int realview_clcd_setup(struct clcd_fb *fb)
  482. {
  483. unsigned long framesize;
  484. dma_addr_t dma;
  485. if (machine_is_realview_eb())
  486. /* VGA, 16bpp */
  487. framesize = 640 * 480 * 2;
  488. else
  489. /* XVGA, 16bpp */
  490. framesize = 1024 * 768 * 2;
  491. fb->panel = realview_clcd_panel();
  492. fb->fb.screen_base = dma_alloc_writecombine(&fb->dev->dev, framesize,
  493. &dma, GFP_KERNEL | GFP_DMA);
  494. if (!fb->fb.screen_base) {
  495. printk(KERN_ERR "CLCD: unable to map framebuffer\n");
  496. return -ENOMEM;
  497. }
  498. fb->fb.fix.smem_start = dma;
  499. fb->fb.fix.smem_len = framesize;
  500. return 0;
  501. }
  502. static int realview_clcd_mmap(struct clcd_fb *fb, struct vm_area_struct *vma)
  503. {
  504. return dma_mmap_writecombine(&fb->dev->dev, vma,
  505. fb->fb.screen_base,
  506. fb->fb.fix.smem_start,
  507. fb->fb.fix.smem_len);
  508. }
  509. static void realview_clcd_remove(struct clcd_fb *fb)
  510. {
  511. dma_free_writecombine(&fb->dev->dev, fb->fb.fix.smem_len,
  512. fb->fb.screen_base, fb->fb.fix.smem_start);
  513. }
  514. struct clcd_board clcd_plat_data = {
  515. .name = "RealView",
  516. .check = clcdfb_check,
  517. .decode = clcdfb_decode,
  518. .disable = realview_clcd_disable,
  519. .enable = realview_clcd_enable,
  520. .setup = realview_clcd_setup,
  521. .mmap = realview_clcd_mmap,
  522. .remove = realview_clcd_remove,
  523. };
  524. #ifdef CONFIG_LEDS
  525. #define VA_LEDS_BASE (__io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_LED_OFFSET)
  526. void realview_leds_event(led_event_t ledevt)
  527. {
  528. unsigned long flags;
  529. u32 val;
  530. u32 led = 1 << smp_processor_id();
  531. local_irq_save(flags);
  532. val = readl(VA_LEDS_BASE);
  533. switch (ledevt) {
  534. case led_idle_start:
  535. val = val & ~led;
  536. break;
  537. case led_idle_end:
  538. val = val | led;
  539. break;
  540. case led_timer:
  541. val = val ^ REALVIEW_SYS_LED7;
  542. break;
  543. case led_halted:
  544. val = 0;
  545. break;
  546. default:
  547. break;
  548. }
  549. writel(val, VA_LEDS_BASE);
  550. local_irq_restore(flags);
  551. }
  552. #endif /* CONFIG_LEDS */
  553. /*
  554. * Where is the timer (VA)?
  555. */
  556. void __iomem *timer0_va_base;
  557. void __iomem *timer1_va_base;
  558. void __iomem *timer2_va_base;
  559. void __iomem *timer3_va_base;
  560. /*
  561. * How long is the timer interval?
  562. */
  563. #define TIMER_INTERVAL (TICKS_PER_uSEC * mSEC_10)
  564. #if TIMER_INTERVAL >= 0x100000
  565. #define TIMER_RELOAD (TIMER_INTERVAL >> 8)
  566. #define TIMER_DIVISOR (TIMER_CTRL_DIV256)
  567. #define TICKS2USECS(x) (256 * (x) / TICKS_PER_uSEC)
  568. #elif TIMER_INTERVAL >= 0x10000
  569. #define TIMER_RELOAD (TIMER_INTERVAL >> 4) /* Divide by 16 */
  570. #define TIMER_DIVISOR (TIMER_CTRL_DIV16)
  571. #define TICKS2USECS(x) (16 * (x) / TICKS_PER_uSEC)
  572. #else
  573. #define TIMER_RELOAD (TIMER_INTERVAL)
  574. #define TIMER_DIVISOR (TIMER_CTRL_DIV1)
  575. #define TICKS2USECS(x) ((x) / TICKS_PER_uSEC)
  576. #endif
  577. static void timer_set_mode(enum clock_event_mode mode,
  578. struct clock_event_device *clk)
  579. {
  580. unsigned long ctrl;
  581. switch(mode) {
  582. case CLOCK_EVT_MODE_PERIODIC:
  583. writel(TIMER_RELOAD, timer0_va_base + TIMER_LOAD);
  584. ctrl = TIMER_CTRL_PERIODIC;
  585. ctrl |= TIMER_CTRL_32BIT | TIMER_CTRL_IE | TIMER_CTRL_ENABLE;
  586. break;
  587. case CLOCK_EVT_MODE_ONESHOT:
  588. /* period set, and timer enabled in 'next_event' hook */
  589. ctrl = TIMER_CTRL_ONESHOT;
  590. ctrl |= TIMER_CTRL_32BIT | TIMER_CTRL_IE;
  591. break;
  592. case CLOCK_EVT_MODE_UNUSED:
  593. case CLOCK_EVT_MODE_SHUTDOWN:
  594. default:
  595. ctrl = 0;
  596. }
  597. writel(ctrl, timer0_va_base + TIMER_CTRL);
  598. }
  599. static int timer_set_next_event(unsigned long evt,
  600. struct clock_event_device *unused)
  601. {
  602. unsigned long ctrl = readl(timer0_va_base + TIMER_CTRL);
  603. writel(evt, timer0_va_base + TIMER_LOAD);
  604. writel(ctrl | TIMER_CTRL_ENABLE, timer0_va_base + TIMER_CTRL);
  605. return 0;
  606. }
  607. static struct clock_event_device timer0_clockevent = {
  608. .name = "timer0",
  609. .shift = 32,
  610. .features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT,
  611. .set_mode = timer_set_mode,
  612. .set_next_event = timer_set_next_event,
  613. .rating = 300,
  614. .cpumask = cpu_all_mask,
  615. };
  616. static void __init realview_clockevents_init(unsigned int timer_irq)
  617. {
  618. timer0_clockevent.irq = timer_irq;
  619. timer0_clockevent.mult =
  620. div_sc(1000000, NSEC_PER_SEC, timer0_clockevent.shift);
  621. timer0_clockevent.max_delta_ns =
  622. clockevent_delta2ns(0xffffffff, &timer0_clockevent);
  623. timer0_clockevent.min_delta_ns =
  624. clockevent_delta2ns(0xf, &timer0_clockevent);
  625. clockevents_register_device(&timer0_clockevent);
  626. }
  627. /*
  628. * IRQ handler for the timer
  629. */
  630. static irqreturn_t realview_timer_interrupt(int irq, void *dev_id)
  631. {
  632. struct clock_event_device *evt = &timer0_clockevent;
  633. /* clear the interrupt */
  634. writel(1, timer0_va_base + TIMER_INTCLR);
  635. evt->event_handler(evt);
  636. return IRQ_HANDLED;
  637. }
  638. static struct irqaction realview_timer_irq = {
  639. .name = "RealView Timer Tick",
  640. .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
  641. .handler = realview_timer_interrupt,
  642. };
  643. static cycle_t realview_get_cycles(struct clocksource *cs)
  644. {
  645. return ~readl(timer3_va_base + TIMER_VALUE);
  646. }
  647. static struct clocksource clocksource_realview = {
  648. .name = "timer3",
  649. .rating = 200,
  650. .read = realview_get_cycles,
  651. .mask = CLOCKSOURCE_MASK(32),
  652. .shift = 20,
  653. .flags = CLOCK_SOURCE_IS_CONTINUOUS,
  654. };
  655. static void __init realview_clocksource_init(void)
  656. {
  657. /* setup timer 0 as free-running clocksource */
  658. writel(0, timer3_va_base + TIMER_CTRL);
  659. writel(0xffffffff, timer3_va_base + TIMER_LOAD);
  660. writel(0xffffffff, timer3_va_base + TIMER_VALUE);
  661. writel(TIMER_CTRL_32BIT | TIMER_CTRL_ENABLE | TIMER_CTRL_PERIODIC,
  662. timer3_va_base + TIMER_CTRL);
  663. clocksource_realview.mult =
  664. clocksource_khz2mult(1000, clocksource_realview.shift);
  665. clocksource_register(&clocksource_realview);
  666. }
  667. /*
  668. * Set up the clock source and clock events devices
  669. */
  670. void __init realview_timer_init(unsigned int timer_irq)
  671. {
  672. u32 val;
  673. /*
  674. * set clock frequency:
  675. * REALVIEW_REFCLK is 32KHz
  676. * REALVIEW_TIMCLK is 1MHz
  677. */
  678. val = readl(__io_address(REALVIEW_SCTL_BASE));
  679. writel((REALVIEW_TIMCLK << REALVIEW_TIMER1_EnSel) |
  680. (REALVIEW_TIMCLK << REALVIEW_TIMER2_EnSel) |
  681. (REALVIEW_TIMCLK << REALVIEW_TIMER3_EnSel) |
  682. (REALVIEW_TIMCLK << REALVIEW_TIMER4_EnSel) | val,
  683. __io_address(REALVIEW_SCTL_BASE));
  684. /*
  685. * Initialise to a known state (all timers off)
  686. */
  687. writel(0, timer0_va_base + TIMER_CTRL);
  688. writel(0, timer1_va_base + TIMER_CTRL);
  689. writel(0, timer2_va_base + TIMER_CTRL);
  690. writel(0, timer3_va_base + TIMER_CTRL);
  691. /*
  692. * Make irqs happen for the system timer
  693. */
  694. setup_irq(timer_irq, &realview_timer_irq);
  695. realview_clocksource_init();
  696. realview_clockevents_init(timer_irq);
  697. }
  698. /*
  699. * Setup the memory banks.
  700. */
  701. void realview_fixup(struct machine_desc *mdesc, struct tag *tags, char **from,
  702. struct meminfo *meminfo)
  703. {
  704. /*
  705. * Most RealView platforms have 512MB contiguous RAM at 0x70000000.
  706. * Half of this is mirrored at 0.
  707. */
  708. #ifdef CONFIG_REALVIEW_HIGH_PHYS_OFFSET
  709. meminfo->bank[0].start = 0x70000000;
  710. meminfo->bank[0].size = SZ_512M;
  711. meminfo->nr_banks = 1;
  712. #else
  713. meminfo->bank[0].start = 0;
  714. meminfo->bank[0].size = SZ_256M;
  715. meminfo->nr_banks = 1;
  716. #endif
  717. }