core.c 14 KB

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