core.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585
  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/config.h>
  22. #include <linux/init.h>
  23. #include <linux/platform_device.h>
  24. #include <linux/dma-mapping.h>
  25. #include <linux/sysdev.h>
  26. #include <linux/interrupt.h>
  27. #include <linux/amba/bus.h>
  28. #include <linux/amba/clcd.h>
  29. #include <asm/system.h>
  30. #include <asm/hardware.h>
  31. #include <asm/io.h>
  32. #include <asm/irq.h>
  33. #include <asm/leds.h>
  34. #include <asm/hardware/arm_timer.h>
  35. #include <asm/hardware/icst307.h>
  36. #include <asm/mach/arch.h>
  37. #include <asm/mach/flash.h>
  38. #include <asm/mach/irq.h>
  39. #include <asm/mach/time.h>
  40. #include <asm/mach/map.h>
  41. #include <asm/mach/mmc.h>
  42. #include <asm/hardware/gic.h>
  43. #include "core.h"
  44. #include "clock.h"
  45. #define REALVIEW_REFCOUNTER (__io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_24MHz_OFFSET)
  46. /*
  47. * This is the RealView sched_clock implementation. This has
  48. * a resolution of 41.7ns, and a maximum value of about 179s.
  49. */
  50. unsigned long long sched_clock(void)
  51. {
  52. unsigned long long v;
  53. v = (unsigned long long)readl(REALVIEW_REFCOUNTER) * 125;
  54. do_div(v, 3);
  55. return v;
  56. }
  57. #define REALVIEW_FLASHCTRL (__io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_FLASH_OFFSET)
  58. static int realview_flash_init(void)
  59. {
  60. u32 val;
  61. val = __raw_readl(REALVIEW_FLASHCTRL);
  62. val &= ~REALVIEW_FLASHPROG_FLVPPEN;
  63. __raw_writel(val, REALVIEW_FLASHCTRL);
  64. return 0;
  65. }
  66. static void realview_flash_exit(void)
  67. {
  68. u32 val;
  69. val = __raw_readl(REALVIEW_FLASHCTRL);
  70. val &= ~REALVIEW_FLASHPROG_FLVPPEN;
  71. __raw_writel(val, REALVIEW_FLASHCTRL);
  72. }
  73. static void realview_flash_set_vpp(int on)
  74. {
  75. u32 val;
  76. val = __raw_readl(REALVIEW_FLASHCTRL);
  77. if (on)
  78. val |= REALVIEW_FLASHPROG_FLVPPEN;
  79. else
  80. val &= ~REALVIEW_FLASHPROG_FLVPPEN;
  81. __raw_writel(val, REALVIEW_FLASHCTRL);
  82. }
  83. static struct flash_platform_data realview_flash_data = {
  84. .map_name = "cfi_probe",
  85. .width = 4,
  86. .init = realview_flash_init,
  87. .exit = realview_flash_exit,
  88. .set_vpp = realview_flash_set_vpp,
  89. };
  90. static struct resource realview_flash_resource = {
  91. .start = REALVIEW_FLASH_BASE,
  92. .end = REALVIEW_FLASH_BASE + REALVIEW_FLASH_SIZE,
  93. .flags = IORESOURCE_MEM,
  94. };
  95. struct platform_device realview_flash_device = {
  96. .name = "armflash",
  97. .id = 0,
  98. .dev = {
  99. .platform_data = &realview_flash_data,
  100. },
  101. .num_resources = 1,
  102. .resource = &realview_flash_resource,
  103. };
  104. static struct resource realview_smc91x_resources[] = {
  105. [0] = {
  106. .start = REALVIEW_ETH_BASE,
  107. .end = REALVIEW_ETH_BASE + SZ_64K - 1,
  108. .flags = IORESOURCE_MEM,
  109. },
  110. [1] = {
  111. .start = IRQ_ETH,
  112. .end = IRQ_ETH,
  113. .flags = IORESOURCE_IRQ,
  114. },
  115. };
  116. struct platform_device realview_smc91x_device = {
  117. .name = "smc91x",
  118. .id = 0,
  119. .num_resources = ARRAY_SIZE(realview_smc91x_resources),
  120. .resource = realview_smc91x_resources,
  121. };
  122. #define REALVIEW_SYSMCI (__io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_MCI_OFFSET)
  123. static unsigned int realview_mmc_status(struct device *dev)
  124. {
  125. struct amba_device *adev = container_of(dev, struct amba_device, dev);
  126. u32 mask;
  127. if (adev->res.start == REALVIEW_MMCI0_BASE)
  128. mask = 1;
  129. else
  130. mask = 2;
  131. return readl(REALVIEW_SYSMCI) & mask;
  132. }
  133. struct mmc_platform_data realview_mmc0_plat_data = {
  134. .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
  135. .status = realview_mmc_status,
  136. };
  137. struct mmc_platform_data realview_mmc1_plat_data = {
  138. .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
  139. .status = realview_mmc_status,
  140. };
  141. /*
  142. * Clock handling
  143. */
  144. static const struct icst307_params realview_oscvco_params = {
  145. .ref = 24000,
  146. .vco_max = 200000,
  147. .vd_min = 4 + 8,
  148. .vd_max = 511 + 8,
  149. .rd_min = 1 + 2,
  150. .rd_max = 127 + 2,
  151. };
  152. static void realview_oscvco_set(struct clk *clk, struct icst307_vco vco)
  153. {
  154. void __iomem *sys_lock = __io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_LOCK_OFFSET;
  155. void __iomem *sys_osc = __io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_OSC4_OFFSET;
  156. u32 val;
  157. val = readl(sys_osc) & ~0x7ffff;
  158. val |= vco.v | (vco.r << 9) | (vco.s << 16);
  159. writel(0xa05f, sys_lock);
  160. writel(val, sys_osc);
  161. writel(0, sys_lock);
  162. }
  163. struct clk realview_clcd_clk = {
  164. .name = "CLCDCLK",
  165. .params = &realview_oscvco_params,
  166. .setvco = realview_oscvco_set,
  167. };
  168. /*
  169. * CLCD support.
  170. */
  171. #define SYS_CLCD_NLCDIOON (1 << 2)
  172. #define SYS_CLCD_VDDPOSSWITCH (1 << 3)
  173. #define SYS_CLCD_PWR3V5SWITCH (1 << 4)
  174. #define SYS_CLCD_ID_MASK (0x1f << 8)
  175. #define SYS_CLCD_ID_SANYO_3_8 (0x00 << 8)
  176. #define SYS_CLCD_ID_UNKNOWN_8_4 (0x01 << 8)
  177. #define SYS_CLCD_ID_EPSON_2_2 (0x02 << 8)
  178. #define SYS_CLCD_ID_SANYO_2_5 (0x07 << 8)
  179. #define SYS_CLCD_ID_VGA (0x1f << 8)
  180. static struct clcd_panel vga = {
  181. .mode = {
  182. .name = "VGA",
  183. .refresh = 60,
  184. .xres = 640,
  185. .yres = 480,
  186. .pixclock = 39721,
  187. .left_margin = 40,
  188. .right_margin = 24,
  189. .upper_margin = 32,
  190. .lower_margin = 11,
  191. .hsync_len = 96,
  192. .vsync_len = 2,
  193. .sync = 0,
  194. .vmode = FB_VMODE_NONINTERLACED,
  195. },
  196. .width = -1,
  197. .height = -1,
  198. .tim2 = TIM2_BCD | TIM2_IPC,
  199. .cntl = CNTL_LCDTFT | CNTL_LCDVCOMP(1),
  200. .bpp = 16,
  201. };
  202. static struct clcd_panel sanyo_3_8_in = {
  203. .mode = {
  204. .name = "Sanyo QVGA",
  205. .refresh = 116,
  206. .xres = 320,
  207. .yres = 240,
  208. .pixclock = 100000,
  209. .left_margin = 6,
  210. .right_margin = 6,
  211. .upper_margin = 5,
  212. .lower_margin = 5,
  213. .hsync_len = 6,
  214. .vsync_len = 6,
  215. .sync = 0,
  216. .vmode = FB_VMODE_NONINTERLACED,
  217. },
  218. .width = -1,
  219. .height = -1,
  220. .tim2 = TIM2_BCD,
  221. .cntl = CNTL_LCDTFT | CNTL_LCDVCOMP(1),
  222. .bpp = 16,
  223. };
  224. static struct clcd_panel sanyo_2_5_in = {
  225. .mode = {
  226. .name = "Sanyo QVGA Portrait",
  227. .refresh = 116,
  228. .xres = 240,
  229. .yres = 320,
  230. .pixclock = 100000,
  231. .left_margin = 20,
  232. .right_margin = 10,
  233. .upper_margin = 2,
  234. .lower_margin = 2,
  235. .hsync_len = 10,
  236. .vsync_len = 2,
  237. .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  238. .vmode = FB_VMODE_NONINTERLACED,
  239. },
  240. .width = -1,
  241. .height = -1,
  242. .tim2 = TIM2_IVS | TIM2_IHS | TIM2_IPC,
  243. .cntl = CNTL_LCDTFT | CNTL_LCDVCOMP(1),
  244. .bpp = 16,
  245. };
  246. static struct clcd_panel epson_2_2_in = {
  247. .mode = {
  248. .name = "Epson QCIF",
  249. .refresh = 390,
  250. .xres = 176,
  251. .yres = 220,
  252. .pixclock = 62500,
  253. .left_margin = 3,
  254. .right_margin = 2,
  255. .upper_margin = 1,
  256. .lower_margin = 0,
  257. .hsync_len = 3,
  258. .vsync_len = 2,
  259. .sync = 0,
  260. .vmode = FB_VMODE_NONINTERLACED,
  261. },
  262. .width = -1,
  263. .height = -1,
  264. .tim2 = TIM2_BCD | TIM2_IPC,
  265. .cntl = CNTL_LCDTFT | CNTL_LCDVCOMP(1),
  266. .bpp = 16,
  267. };
  268. /*
  269. * Detect which LCD panel is connected, and return the appropriate
  270. * clcd_panel structure. Note: we do not have any information on
  271. * the required timings for the 8.4in panel, so we presently assume
  272. * VGA timings.
  273. */
  274. static struct clcd_panel *realview_clcd_panel(void)
  275. {
  276. void __iomem *sys_clcd = __io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_CLCD_OFFSET;
  277. struct clcd_panel *panel = &vga;
  278. u32 val;
  279. val = readl(sys_clcd) & SYS_CLCD_ID_MASK;
  280. if (val == SYS_CLCD_ID_SANYO_3_8)
  281. panel = &sanyo_3_8_in;
  282. else if (val == SYS_CLCD_ID_SANYO_2_5)
  283. panel = &sanyo_2_5_in;
  284. else if (val == SYS_CLCD_ID_EPSON_2_2)
  285. panel = &epson_2_2_in;
  286. else if (val == SYS_CLCD_ID_VGA)
  287. panel = &vga;
  288. else {
  289. printk(KERN_ERR "CLCD: unknown LCD panel ID 0x%08x, using VGA\n",
  290. val);
  291. panel = &vga;
  292. }
  293. return panel;
  294. }
  295. /*
  296. * Disable all display connectors on the interface module.
  297. */
  298. static void realview_clcd_disable(struct clcd_fb *fb)
  299. {
  300. void __iomem *sys_clcd = __io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_CLCD_OFFSET;
  301. u32 val;
  302. val = readl(sys_clcd);
  303. val &= ~SYS_CLCD_NLCDIOON | SYS_CLCD_PWR3V5SWITCH;
  304. writel(val, sys_clcd);
  305. }
  306. /*
  307. * Enable the relevant connector on the interface module.
  308. */
  309. static void realview_clcd_enable(struct clcd_fb *fb)
  310. {
  311. void __iomem *sys_clcd = __io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_CLCD_OFFSET;
  312. u32 val;
  313. /*
  314. * Enable the PSUs
  315. */
  316. val = readl(sys_clcd);
  317. val |= SYS_CLCD_NLCDIOON | SYS_CLCD_PWR3V5SWITCH;
  318. writel(val, sys_clcd);
  319. }
  320. static unsigned long framesize = SZ_1M;
  321. static int realview_clcd_setup(struct clcd_fb *fb)
  322. {
  323. dma_addr_t dma;
  324. fb->panel = realview_clcd_panel();
  325. fb->fb.screen_base = dma_alloc_writecombine(&fb->dev->dev, framesize,
  326. &dma, GFP_KERNEL);
  327. if (!fb->fb.screen_base) {
  328. printk(KERN_ERR "CLCD: unable to map framebuffer\n");
  329. return -ENOMEM;
  330. }
  331. fb->fb.fix.smem_start = dma;
  332. fb->fb.fix.smem_len = framesize;
  333. return 0;
  334. }
  335. static int realview_clcd_mmap(struct clcd_fb *fb, struct vm_area_struct *vma)
  336. {
  337. return dma_mmap_writecombine(&fb->dev->dev, vma,
  338. fb->fb.screen_base,
  339. fb->fb.fix.smem_start,
  340. fb->fb.fix.smem_len);
  341. }
  342. static void realview_clcd_remove(struct clcd_fb *fb)
  343. {
  344. dma_free_writecombine(&fb->dev->dev, fb->fb.fix.smem_len,
  345. fb->fb.screen_base, fb->fb.fix.smem_start);
  346. }
  347. struct clcd_board clcd_plat_data = {
  348. .name = "RealView",
  349. .check = clcdfb_check,
  350. .decode = clcdfb_decode,
  351. .disable = realview_clcd_disable,
  352. .enable = realview_clcd_enable,
  353. .setup = realview_clcd_setup,
  354. .mmap = realview_clcd_mmap,
  355. .remove = realview_clcd_remove,
  356. };
  357. #ifdef CONFIG_LEDS
  358. #define VA_LEDS_BASE (__io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_LED_OFFSET)
  359. void realview_leds_event(led_event_t ledevt)
  360. {
  361. unsigned long flags;
  362. u32 val;
  363. local_irq_save(flags);
  364. val = readl(VA_LEDS_BASE);
  365. switch (ledevt) {
  366. case led_idle_start:
  367. val = val & ~REALVIEW_SYS_LED0;
  368. break;
  369. case led_idle_end:
  370. val = val | REALVIEW_SYS_LED0;
  371. break;
  372. case led_timer:
  373. val = val ^ REALVIEW_SYS_LED1;
  374. break;
  375. case led_halted:
  376. val = 0;
  377. break;
  378. default:
  379. break;
  380. }
  381. writel(val, VA_LEDS_BASE);
  382. local_irq_restore(flags);
  383. }
  384. #endif /* CONFIG_LEDS */
  385. /*
  386. * Where is the timer (VA)?
  387. */
  388. #define TIMER0_VA_BASE __io_address(REALVIEW_TIMER0_1_BASE)
  389. #define TIMER1_VA_BASE (__io_address(REALVIEW_TIMER0_1_BASE) + 0x20)
  390. #define TIMER2_VA_BASE __io_address(REALVIEW_TIMER2_3_BASE)
  391. #define TIMER3_VA_BASE (__io_address(REALVIEW_TIMER2_3_BASE) + 0x20)
  392. /*
  393. * How long is the timer interval?
  394. */
  395. #define TIMER_INTERVAL (TICKS_PER_uSEC * mSEC_10)
  396. #if TIMER_INTERVAL >= 0x100000
  397. #define TIMER_RELOAD (TIMER_INTERVAL >> 8)
  398. #define TIMER_DIVISOR (TIMER_CTRL_DIV256)
  399. #define TICKS2USECS(x) (256 * (x) / TICKS_PER_uSEC)
  400. #elif TIMER_INTERVAL >= 0x10000
  401. #define TIMER_RELOAD (TIMER_INTERVAL >> 4) /* Divide by 16 */
  402. #define TIMER_DIVISOR (TIMER_CTRL_DIV16)
  403. #define TICKS2USECS(x) (16 * (x) / TICKS_PER_uSEC)
  404. #else
  405. #define TIMER_RELOAD (TIMER_INTERVAL)
  406. #define TIMER_DIVISOR (TIMER_CTRL_DIV1)
  407. #define TICKS2USECS(x) ((x) / TICKS_PER_uSEC)
  408. #endif
  409. /*
  410. * Returns number of ms since last clock interrupt. Note that interrupts
  411. * will have been disabled by do_gettimeoffset()
  412. */
  413. static unsigned long realview_gettimeoffset(void)
  414. {
  415. unsigned long ticks1, ticks2, status;
  416. /*
  417. * Get the current number of ticks. Note that there is a race
  418. * condition between us reading the timer and checking for
  419. * an interrupt. We get around this by ensuring that the
  420. * counter has not reloaded between our two reads.
  421. */
  422. ticks2 = readl(TIMER0_VA_BASE + TIMER_VALUE) & 0xffff;
  423. do {
  424. ticks1 = ticks2;
  425. status = __raw_readl(__io_address(REALVIEW_GIC_DIST_BASE + GIC_DIST_PENDING_SET)
  426. + ((IRQ_TIMERINT0_1 >> 5) << 2));
  427. ticks2 = readl(TIMER0_VA_BASE + TIMER_VALUE) & 0xffff;
  428. } while (ticks2 > ticks1);
  429. /*
  430. * Number of ticks since last interrupt.
  431. */
  432. ticks1 = TIMER_RELOAD - ticks2;
  433. /*
  434. * Interrupt pending? If so, we've reloaded once already.
  435. *
  436. * FIXME: Need to check this is effectively timer 0 that expires
  437. */
  438. if (status & IRQMASK_TIMERINT0_1)
  439. ticks1 += TIMER_RELOAD;
  440. /*
  441. * Convert the ticks to usecs
  442. */
  443. return TICKS2USECS(ticks1);
  444. }
  445. /*
  446. * IRQ handler for the timer
  447. */
  448. static irqreturn_t realview_timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  449. {
  450. write_seqlock(&xtime_lock);
  451. // ...clear the interrupt
  452. writel(1, TIMER0_VA_BASE + TIMER_INTCLR);
  453. timer_tick(regs);
  454. #if defined(CONFIG_SMP) && !defined(CONFIG_LOCAL_TIMERS)
  455. smp_send_timer();
  456. update_process_times(user_mode(regs));
  457. #endif
  458. write_sequnlock(&xtime_lock);
  459. return IRQ_HANDLED;
  460. }
  461. static struct irqaction realview_timer_irq = {
  462. .name = "RealView Timer Tick",
  463. .flags = SA_INTERRUPT | SA_TIMER,
  464. .handler = realview_timer_interrupt,
  465. };
  466. /*
  467. * Set up timer interrupt, and return the current time in seconds.
  468. */
  469. static void __init realview_timer_init(void)
  470. {
  471. u32 val;
  472. /*
  473. * set clock frequency:
  474. * REALVIEW_REFCLK is 32KHz
  475. * REALVIEW_TIMCLK is 1MHz
  476. */
  477. val = readl(__io_address(REALVIEW_SCTL_BASE));
  478. writel((REALVIEW_TIMCLK << REALVIEW_TIMER1_EnSel) |
  479. (REALVIEW_TIMCLK << REALVIEW_TIMER2_EnSel) |
  480. (REALVIEW_TIMCLK << REALVIEW_TIMER3_EnSel) |
  481. (REALVIEW_TIMCLK << REALVIEW_TIMER4_EnSel) | val,
  482. __io_address(REALVIEW_SCTL_BASE));
  483. /*
  484. * Initialise to a known state (all timers off)
  485. */
  486. writel(0, TIMER0_VA_BASE + TIMER_CTRL);
  487. writel(0, TIMER1_VA_BASE + TIMER_CTRL);
  488. writel(0, TIMER2_VA_BASE + TIMER_CTRL);
  489. writel(0, TIMER3_VA_BASE + TIMER_CTRL);
  490. writel(TIMER_RELOAD, TIMER0_VA_BASE + TIMER_LOAD);
  491. writel(TIMER_RELOAD, TIMER0_VA_BASE + TIMER_VALUE);
  492. writel(TIMER_DIVISOR | TIMER_CTRL_ENABLE | TIMER_CTRL_PERIODIC |
  493. TIMER_CTRL_IE, TIMER0_VA_BASE + TIMER_CTRL);
  494. /*
  495. * Make irqs happen for the system timer
  496. */
  497. setup_irq(IRQ_TIMERINT0_1, &realview_timer_irq);
  498. }
  499. struct sys_timer realview_timer = {
  500. .init = realview_timer_init,
  501. .offset = realview_gettimeoffset,
  502. };