core.c 19 KB

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