core.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609
  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_OSC1_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_MODE_MASK (3 << 0)
  172. #define SYS_CLCD_MODE_888 (0 << 0)
  173. #define SYS_CLCD_MODE_5551 (1 << 0)
  174. #define SYS_CLCD_MODE_565_RLSB (2 << 0)
  175. #define SYS_CLCD_MODE_565_BLSB (3 << 0)
  176. #define SYS_CLCD_NLCDIOON (1 << 2)
  177. #define SYS_CLCD_VDDPOSSWITCH (1 << 3)
  178. #define SYS_CLCD_PWR3V5SWITCH (1 << 4)
  179. #define SYS_CLCD_ID_MASK (0x1f << 8)
  180. #define SYS_CLCD_ID_SANYO_3_8 (0x00 << 8)
  181. #define SYS_CLCD_ID_UNKNOWN_8_4 (0x01 << 8)
  182. #define SYS_CLCD_ID_EPSON_2_2 (0x02 << 8)
  183. #define SYS_CLCD_ID_SANYO_2_5 (0x07 << 8)
  184. #define SYS_CLCD_ID_VGA (0x1f << 8)
  185. static struct clcd_panel vga = {
  186. .mode = {
  187. .name = "VGA",
  188. .refresh = 60,
  189. .xres = 640,
  190. .yres = 480,
  191. .pixclock = 39721,
  192. .left_margin = 40,
  193. .right_margin = 24,
  194. .upper_margin = 32,
  195. .lower_margin = 11,
  196. .hsync_len = 96,
  197. .vsync_len = 2,
  198. .sync = 0,
  199. .vmode = FB_VMODE_NONINTERLACED,
  200. },
  201. .width = -1,
  202. .height = -1,
  203. .tim2 = TIM2_BCD | TIM2_IPC,
  204. .cntl = CNTL_LCDTFT | CNTL_LCDVCOMP(1),
  205. .bpp = 16,
  206. };
  207. static struct clcd_panel sanyo_3_8_in = {
  208. .mode = {
  209. .name = "Sanyo QVGA",
  210. .refresh = 116,
  211. .xres = 320,
  212. .yres = 240,
  213. .pixclock = 100000,
  214. .left_margin = 6,
  215. .right_margin = 6,
  216. .upper_margin = 5,
  217. .lower_margin = 5,
  218. .hsync_len = 6,
  219. .vsync_len = 6,
  220. .sync = 0,
  221. .vmode = FB_VMODE_NONINTERLACED,
  222. },
  223. .width = -1,
  224. .height = -1,
  225. .tim2 = TIM2_BCD,
  226. .cntl = CNTL_LCDTFT | CNTL_LCDVCOMP(1),
  227. .bpp = 16,
  228. };
  229. static struct clcd_panel sanyo_2_5_in = {
  230. .mode = {
  231. .name = "Sanyo QVGA Portrait",
  232. .refresh = 116,
  233. .xres = 240,
  234. .yres = 320,
  235. .pixclock = 100000,
  236. .left_margin = 20,
  237. .right_margin = 10,
  238. .upper_margin = 2,
  239. .lower_margin = 2,
  240. .hsync_len = 10,
  241. .vsync_len = 2,
  242. .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  243. .vmode = FB_VMODE_NONINTERLACED,
  244. },
  245. .width = -1,
  246. .height = -1,
  247. .tim2 = TIM2_IVS | TIM2_IHS | TIM2_IPC,
  248. .cntl = CNTL_LCDTFT | CNTL_LCDVCOMP(1),
  249. .bpp = 16,
  250. };
  251. static struct clcd_panel epson_2_2_in = {
  252. .mode = {
  253. .name = "Epson QCIF",
  254. .refresh = 390,
  255. .xres = 176,
  256. .yres = 220,
  257. .pixclock = 62500,
  258. .left_margin = 3,
  259. .right_margin = 2,
  260. .upper_margin = 1,
  261. .lower_margin = 0,
  262. .hsync_len = 3,
  263. .vsync_len = 2,
  264. .sync = 0,
  265. .vmode = FB_VMODE_NONINTERLACED,
  266. },
  267. .width = -1,
  268. .height = -1,
  269. .tim2 = TIM2_BCD | TIM2_IPC,
  270. .cntl = CNTL_LCDTFT | CNTL_LCDVCOMP(1),
  271. .bpp = 16,
  272. };
  273. /*
  274. * Detect which LCD panel is connected, and return the appropriate
  275. * clcd_panel structure. Note: we do not have any information on
  276. * the required timings for the 8.4in panel, so we presently assume
  277. * VGA timings.
  278. */
  279. static struct clcd_panel *realview_clcd_panel(void)
  280. {
  281. void __iomem *sys_clcd = __io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_CLCD_OFFSET;
  282. struct clcd_panel *panel = &vga;
  283. u32 val;
  284. val = readl(sys_clcd) & SYS_CLCD_ID_MASK;
  285. if (val == SYS_CLCD_ID_SANYO_3_8)
  286. panel = &sanyo_3_8_in;
  287. else if (val == SYS_CLCD_ID_SANYO_2_5)
  288. panel = &sanyo_2_5_in;
  289. else if (val == SYS_CLCD_ID_EPSON_2_2)
  290. panel = &epson_2_2_in;
  291. else if (val == SYS_CLCD_ID_VGA)
  292. panel = &vga;
  293. else {
  294. printk(KERN_ERR "CLCD: unknown LCD panel ID 0x%08x, using VGA\n",
  295. val);
  296. panel = &vga;
  297. }
  298. return panel;
  299. }
  300. /*
  301. * Disable all display connectors on the interface module.
  302. */
  303. static void realview_clcd_disable(struct clcd_fb *fb)
  304. {
  305. void __iomem *sys_clcd = __io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_CLCD_OFFSET;
  306. u32 val;
  307. val = readl(sys_clcd);
  308. val &= ~SYS_CLCD_NLCDIOON | SYS_CLCD_PWR3V5SWITCH;
  309. writel(val, sys_clcd);
  310. }
  311. /*
  312. * Enable the relevant connector on the interface module.
  313. */
  314. static void realview_clcd_enable(struct clcd_fb *fb)
  315. {
  316. void __iomem *sys_clcd = __io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_CLCD_OFFSET;
  317. u32 val;
  318. val = readl(sys_clcd);
  319. val &= ~SYS_CLCD_MODE_MASK;
  320. switch (fb->fb.var.green.length) {
  321. case 5:
  322. val |= SYS_CLCD_MODE_5551;
  323. break;
  324. case 6:
  325. val |= SYS_CLCD_MODE_565_RLSB;
  326. break;
  327. case 8:
  328. val |= SYS_CLCD_MODE_888;
  329. break;
  330. }
  331. /*
  332. * Set the MUX
  333. */
  334. writel(val, sys_clcd);
  335. /*
  336. * And now enable the PSUs
  337. */
  338. val |= SYS_CLCD_NLCDIOON | SYS_CLCD_PWR3V5SWITCH;
  339. writel(val, sys_clcd);
  340. }
  341. static unsigned long framesize = SZ_1M;
  342. static int realview_clcd_setup(struct clcd_fb *fb)
  343. {
  344. dma_addr_t dma;
  345. fb->panel = realview_clcd_panel();
  346. fb->fb.screen_base = dma_alloc_writecombine(&fb->dev->dev, framesize,
  347. &dma, GFP_KERNEL);
  348. if (!fb->fb.screen_base) {
  349. printk(KERN_ERR "CLCD: unable to map framebuffer\n");
  350. return -ENOMEM;
  351. }
  352. fb->fb.fix.smem_start = dma;
  353. fb->fb.fix.smem_len = framesize;
  354. return 0;
  355. }
  356. static int realview_clcd_mmap(struct clcd_fb *fb, struct vm_area_struct *vma)
  357. {
  358. return dma_mmap_writecombine(&fb->dev->dev, vma,
  359. fb->fb.screen_base,
  360. fb->fb.fix.smem_start,
  361. fb->fb.fix.smem_len);
  362. }
  363. static void realview_clcd_remove(struct clcd_fb *fb)
  364. {
  365. dma_free_writecombine(&fb->dev->dev, fb->fb.fix.smem_len,
  366. fb->fb.screen_base, fb->fb.fix.smem_start);
  367. }
  368. struct clcd_board clcd_plat_data = {
  369. .name = "RealView",
  370. .check = clcdfb_check,
  371. .decode = clcdfb_decode,
  372. .disable = realview_clcd_disable,
  373. .enable = realview_clcd_enable,
  374. .setup = realview_clcd_setup,
  375. .mmap = realview_clcd_mmap,
  376. .remove = realview_clcd_remove,
  377. };
  378. #ifdef CONFIG_LEDS
  379. #define VA_LEDS_BASE (__io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_LED_OFFSET)
  380. void realview_leds_event(led_event_t ledevt)
  381. {
  382. unsigned long flags;
  383. u32 val;
  384. local_irq_save(flags);
  385. val = readl(VA_LEDS_BASE);
  386. switch (ledevt) {
  387. case led_idle_start:
  388. val = val & ~REALVIEW_SYS_LED0;
  389. break;
  390. case led_idle_end:
  391. val = val | REALVIEW_SYS_LED0;
  392. break;
  393. case led_timer:
  394. val = val ^ REALVIEW_SYS_LED1;
  395. break;
  396. case led_halted:
  397. val = 0;
  398. break;
  399. default:
  400. break;
  401. }
  402. writel(val, VA_LEDS_BASE);
  403. local_irq_restore(flags);
  404. }
  405. #endif /* CONFIG_LEDS */
  406. /*
  407. * Where is the timer (VA)?
  408. */
  409. #define TIMER0_VA_BASE __io_address(REALVIEW_TIMER0_1_BASE)
  410. #define TIMER1_VA_BASE (__io_address(REALVIEW_TIMER0_1_BASE) + 0x20)
  411. #define TIMER2_VA_BASE __io_address(REALVIEW_TIMER2_3_BASE)
  412. #define TIMER3_VA_BASE (__io_address(REALVIEW_TIMER2_3_BASE) + 0x20)
  413. /*
  414. * How long is the timer interval?
  415. */
  416. #define TIMER_INTERVAL (TICKS_PER_uSEC * mSEC_10)
  417. #if TIMER_INTERVAL >= 0x100000
  418. #define TIMER_RELOAD (TIMER_INTERVAL >> 8)
  419. #define TIMER_DIVISOR (TIMER_CTRL_DIV256)
  420. #define TICKS2USECS(x) (256 * (x) / TICKS_PER_uSEC)
  421. #elif TIMER_INTERVAL >= 0x10000
  422. #define TIMER_RELOAD (TIMER_INTERVAL >> 4) /* Divide by 16 */
  423. #define TIMER_DIVISOR (TIMER_CTRL_DIV16)
  424. #define TICKS2USECS(x) (16 * (x) / TICKS_PER_uSEC)
  425. #else
  426. #define TIMER_RELOAD (TIMER_INTERVAL)
  427. #define TIMER_DIVISOR (TIMER_CTRL_DIV1)
  428. #define TICKS2USECS(x) ((x) / TICKS_PER_uSEC)
  429. #endif
  430. /*
  431. * Returns number of ms since last clock interrupt. Note that interrupts
  432. * will have been disabled by do_gettimeoffset()
  433. */
  434. static unsigned long realview_gettimeoffset(void)
  435. {
  436. unsigned long ticks1, ticks2, status;
  437. /*
  438. * Get the current number of ticks. Note that there is a race
  439. * condition between us reading the timer and checking for
  440. * an interrupt. We get around this by ensuring that the
  441. * counter has not reloaded between our two reads.
  442. */
  443. ticks2 = readl(TIMER0_VA_BASE + TIMER_VALUE) & 0xffff;
  444. do {
  445. ticks1 = ticks2;
  446. status = __raw_readl(__io_address(REALVIEW_GIC_DIST_BASE + GIC_DIST_PENDING_SET)
  447. + ((IRQ_TIMERINT0_1 >> 5) << 2));
  448. ticks2 = readl(TIMER0_VA_BASE + TIMER_VALUE) & 0xffff;
  449. } while (ticks2 > ticks1);
  450. /*
  451. * Number of ticks since last interrupt.
  452. */
  453. ticks1 = TIMER_RELOAD - ticks2;
  454. /*
  455. * Interrupt pending? If so, we've reloaded once already.
  456. *
  457. * FIXME: Need to check this is effectively timer 0 that expires
  458. */
  459. if (status & IRQMASK_TIMERINT0_1)
  460. ticks1 += TIMER_RELOAD;
  461. /*
  462. * Convert the ticks to usecs
  463. */
  464. return TICKS2USECS(ticks1);
  465. }
  466. /*
  467. * IRQ handler for the timer
  468. */
  469. static irqreturn_t realview_timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  470. {
  471. write_seqlock(&xtime_lock);
  472. // ...clear the interrupt
  473. writel(1, TIMER0_VA_BASE + TIMER_INTCLR);
  474. timer_tick(regs);
  475. #if defined(CONFIG_SMP) && !defined(CONFIG_LOCAL_TIMERS)
  476. smp_send_timer();
  477. update_process_times(user_mode(regs));
  478. #endif
  479. write_sequnlock(&xtime_lock);
  480. return IRQ_HANDLED;
  481. }
  482. static struct irqaction realview_timer_irq = {
  483. .name = "RealView Timer Tick",
  484. .flags = SA_INTERRUPT | SA_TIMER,
  485. .handler = realview_timer_interrupt,
  486. };
  487. /*
  488. * Set up timer interrupt, and return the current time in seconds.
  489. */
  490. static void __init realview_timer_init(void)
  491. {
  492. u32 val;
  493. /*
  494. * set clock frequency:
  495. * REALVIEW_REFCLK is 32KHz
  496. * REALVIEW_TIMCLK is 1MHz
  497. */
  498. val = readl(__io_address(REALVIEW_SCTL_BASE));
  499. writel((REALVIEW_TIMCLK << REALVIEW_TIMER1_EnSel) |
  500. (REALVIEW_TIMCLK << REALVIEW_TIMER2_EnSel) |
  501. (REALVIEW_TIMCLK << REALVIEW_TIMER3_EnSel) |
  502. (REALVIEW_TIMCLK << REALVIEW_TIMER4_EnSel) | val,
  503. __io_address(REALVIEW_SCTL_BASE));
  504. /*
  505. * Initialise to a known state (all timers off)
  506. */
  507. writel(0, TIMER0_VA_BASE + TIMER_CTRL);
  508. writel(0, TIMER1_VA_BASE + TIMER_CTRL);
  509. writel(0, TIMER2_VA_BASE + TIMER_CTRL);
  510. writel(0, TIMER3_VA_BASE + TIMER_CTRL);
  511. writel(TIMER_RELOAD, TIMER0_VA_BASE + TIMER_LOAD);
  512. writel(TIMER_RELOAD, TIMER0_VA_BASE + TIMER_VALUE);
  513. writel(TIMER_DIVISOR | TIMER_CTRL_ENABLE | TIMER_CTRL_PERIODIC |
  514. TIMER_CTRL_IE, TIMER0_VA_BASE + TIMER_CTRL);
  515. /*
  516. * Make irqs happen for the system timer
  517. */
  518. setup_irq(IRQ_TIMERINT0_1, &realview_timer_irq);
  519. }
  520. struct sys_timer realview_timer = {
  521. .init = realview_timer_init,
  522. .offset = realview_gettimeoffset,
  523. };