core.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914
  1. /*
  2. * linux/arch/arm/mach-versatile/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/device.h>
  23. #include <linux/dma-mapping.h>
  24. #include <linux/platform_device.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/hardware/vic.h>
  37. #include <asm/mach-types.h>
  38. #include <asm/mach/arch.h>
  39. #include <asm/mach/flash.h>
  40. #include <asm/mach/irq.h>
  41. #include <asm/mach/time.h>
  42. #include <asm/mach/map.h>
  43. #include <asm/mach/mmc.h>
  44. #include "core.h"
  45. #include "clock.h"
  46. /*
  47. * All IO addresses are mapped onto VA 0xFFFx.xxxx, where x.xxxx
  48. * is the (PA >> 12).
  49. *
  50. * Setup a VA for the Versatile Vectored Interrupt Controller.
  51. */
  52. #define __io_address(n) __io(IO_ADDRESS(n))
  53. #define VA_VIC_BASE __io_address(VERSATILE_VIC_BASE)
  54. #define VA_SIC_BASE __io_address(VERSATILE_SIC_BASE)
  55. static void sic_mask_irq(unsigned int irq)
  56. {
  57. irq -= IRQ_SIC_START;
  58. writel(1 << irq, VA_SIC_BASE + SIC_IRQ_ENABLE_CLEAR);
  59. }
  60. static void sic_unmask_irq(unsigned int irq)
  61. {
  62. irq -= IRQ_SIC_START;
  63. writel(1 << irq, VA_SIC_BASE + SIC_IRQ_ENABLE_SET);
  64. }
  65. static struct irqchip sic_chip = {
  66. .ack = sic_mask_irq,
  67. .mask = sic_mask_irq,
  68. .unmask = sic_unmask_irq,
  69. };
  70. static void
  71. sic_handle_irq(unsigned int irq, struct irqdesc *desc, struct pt_regs *regs)
  72. {
  73. unsigned long status = readl(VA_SIC_BASE + SIC_IRQ_STATUS);
  74. if (status == 0) {
  75. do_bad_IRQ(irq, desc, regs);
  76. return;
  77. }
  78. do {
  79. irq = ffs(status) - 1;
  80. status &= ~(1 << irq);
  81. irq += IRQ_SIC_START;
  82. desc = irq_desc + irq;
  83. desc_handle_irq(irq, desc, regs);
  84. } while (status);
  85. }
  86. #if 1
  87. #define IRQ_MMCI0A IRQ_VICSOURCE22
  88. #define IRQ_AACI IRQ_VICSOURCE24
  89. #define IRQ_ETH IRQ_VICSOURCE25
  90. #define PIC_MASK 0xFFD00000
  91. #else
  92. #define IRQ_MMCI0A IRQ_SIC_MMCI0A
  93. #define IRQ_AACI IRQ_SIC_AACI
  94. #define IRQ_ETH IRQ_SIC_ETH
  95. #define PIC_MASK 0
  96. #endif
  97. void __init versatile_init_irq(void)
  98. {
  99. unsigned int i;
  100. vic_init(VA_VIC_BASE, IRQ_VIC_START, ~0);
  101. set_irq_chained_handler(IRQ_VICSOURCE31, sic_handle_irq);
  102. /* Do second interrupt controller */
  103. writel(~0, VA_SIC_BASE + SIC_IRQ_ENABLE_CLEAR);
  104. for (i = IRQ_SIC_START; i <= IRQ_SIC_END; i++) {
  105. if ((PIC_MASK & (1 << (i - IRQ_SIC_START))) == 0) {
  106. set_irq_chip(i, &sic_chip);
  107. set_irq_handler(i, do_level_IRQ);
  108. set_irq_flags(i, IRQF_VALID | IRQF_PROBE);
  109. }
  110. }
  111. /*
  112. * Interrupts on secondary controller from 0 to 8 are routed to
  113. * source 31 on PIC.
  114. * Interrupts from 21 to 31 are routed directly to the VIC on
  115. * the corresponding number on primary controller. This is controlled
  116. * by setting PIC_ENABLEx.
  117. */
  118. writel(PIC_MASK, VA_SIC_BASE + SIC_INT_PIC_ENABLE);
  119. }
  120. static struct map_desc versatile_io_desc[] __initdata = {
  121. {
  122. .virtual = IO_ADDRESS(VERSATILE_SYS_BASE),
  123. .pfn = __phys_to_pfn(VERSATILE_SYS_BASE),
  124. .length = SZ_4K,
  125. .type = MT_DEVICE
  126. }, {
  127. .virtual = IO_ADDRESS(VERSATILE_SIC_BASE),
  128. .pfn = __phys_to_pfn(VERSATILE_SIC_BASE),
  129. .length = SZ_4K,
  130. .type = MT_DEVICE
  131. }, {
  132. .virtual = IO_ADDRESS(VERSATILE_VIC_BASE),
  133. .pfn = __phys_to_pfn(VERSATILE_VIC_BASE),
  134. .length = SZ_4K,
  135. .type = MT_DEVICE
  136. }, {
  137. .virtual = IO_ADDRESS(VERSATILE_SCTL_BASE),
  138. .pfn = __phys_to_pfn(VERSATILE_SCTL_BASE),
  139. .length = SZ_4K * 9,
  140. .type = MT_DEVICE
  141. },
  142. #ifdef CONFIG_MACH_VERSATILE_AB
  143. {
  144. .virtual = IO_ADDRESS(VERSATILE_GPIO0_BASE),
  145. .pfn = __phys_to_pfn(VERSATILE_GPIO0_BASE),
  146. .length = SZ_4K,
  147. .type = MT_DEVICE
  148. }, {
  149. .virtual = IO_ADDRESS(VERSATILE_IB2_BASE),
  150. .pfn = __phys_to_pfn(VERSATILE_IB2_BASE),
  151. .length = SZ_64M,
  152. .type = MT_DEVICE
  153. },
  154. #endif
  155. #ifdef CONFIG_DEBUG_LL
  156. {
  157. .virtual = IO_ADDRESS(VERSATILE_UART0_BASE),
  158. .pfn = __phys_to_pfn(VERSATILE_UART0_BASE),
  159. .length = SZ_4K,
  160. .type = MT_DEVICE
  161. },
  162. #endif
  163. #ifdef CONFIG_PCI
  164. {
  165. .virtual = IO_ADDRESS(VERSATILE_PCI_CORE_BASE),
  166. .pfn = __phys_to_pfn(VERSATILE_PCI_CORE_BASE),
  167. .length = SZ_4K,
  168. .type = MT_DEVICE
  169. }, {
  170. .virtual = VERSATILE_PCI_VIRT_BASE,
  171. .pfn = __phys_to_pfn(VERSATILE_PCI_BASE),
  172. .length = VERSATILE_PCI_BASE_SIZE,
  173. .type = MT_DEVICE
  174. }, {
  175. .virtual = VERSATILE_PCI_CFG_VIRT_BASE,
  176. .pfn = __phys_to_pfn(VERSATILE_PCI_CFG_BASE),
  177. .length = VERSATILE_PCI_CFG_BASE_SIZE,
  178. .type = MT_DEVICE
  179. },
  180. #if 0
  181. {
  182. .virtual = VERSATILE_PCI_VIRT_MEM_BASE0,
  183. .pfn = __phys_to_pfn(VERSATILE_PCI_MEM_BASE0),
  184. .length = SZ_16M,
  185. .type = MT_DEVICE
  186. }, {
  187. .virtual = VERSATILE_PCI_VIRT_MEM_BASE1,
  188. .pfn = __phys_to_pfn(VERSATILE_PCI_MEM_BASE1),
  189. .length = SZ_16M,
  190. .type = MT_DEVICE
  191. }, {
  192. .virtual = VERSATILE_PCI_VIRT_MEM_BASE2,
  193. .pfn = __phys_to_pfn(VERSATILE_PCI_MEM_BASE2),
  194. .length = SZ_16M,
  195. .type = MT_DEVICE
  196. },
  197. #endif
  198. #endif
  199. };
  200. void __init versatile_map_io(void)
  201. {
  202. iotable_init(versatile_io_desc, ARRAY_SIZE(versatile_io_desc));
  203. }
  204. #define VERSATILE_REFCOUNTER (__io_address(VERSATILE_SYS_BASE) + VERSATILE_SYS_24MHz_OFFSET)
  205. /*
  206. * This is the Versatile sched_clock implementation. This has
  207. * a resolution of 41.7ns, and a maximum value of about 179s.
  208. */
  209. unsigned long long sched_clock(void)
  210. {
  211. unsigned long long v;
  212. v = (unsigned long long)readl(VERSATILE_REFCOUNTER) * 125;
  213. do_div(v, 3);
  214. return v;
  215. }
  216. #define VERSATILE_FLASHCTRL (__io_address(VERSATILE_SYS_BASE) + VERSATILE_SYS_FLASH_OFFSET)
  217. static int versatile_flash_init(void)
  218. {
  219. u32 val;
  220. val = __raw_readl(VERSATILE_FLASHCTRL);
  221. val &= ~VERSATILE_FLASHPROG_FLVPPEN;
  222. __raw_writel(val, VERSATILE_FLASHCTRL);
  223. return 0;
  224. }
  225. static void versatile_flash_exit(void)
  226. {
  227. u32 val;
  228. val = __raw_readl(VERSATILE_FLASHCTRL);
  229. val &= ~VERSATILE_FLASHPROG_FLVPPEN;
  230. __raw_writel(val, VERSATILE_FLASHCTRL);
  231. }
  232. static void versatile_flash_set_vpp(int on)
  233. {
  234. u32 val;
  235. val = __raw_readl(VERSATILE_FLASHCTRL);
  236. if (on)
  237. val |= VERSATILE_FLASHPROG_FLVPPEN;
  238. else
  239. val &= ~VERSATILE_FLASHPROG_FLVPPEN;
  240. __raw_writel(val, VERSATILE_FLASHCTRL);
  241. }
  242. static struct flash_platform_data versatile_flash_data = {
  243. .map_name = "cfi_probe",
  244. .width = 4,
  245. .init = versatile_flash_init,
  246. .exit = versatile_flash_exit,
  247. .set_vpp = versatile_flash_set_vpp,
  248. };
  249. static struct resource versatile_flash_resource = {
  250. .start = VERSATILE_FLASH_BASE,
  251. .end = VERSATILE_FLASH_BASE + VERSATILE_FLASH_SIZE,
  252. .flags = IORESOURCE_MEM,
  253. };
  254. static struct platform_device versatile_flash_device = {
  255. .name = "armflash",
  256. .id = 0,
  257. .dev = {
  258. .platform_data = &versatile_flash_data,
  259. },
  260. .num_resources = 1,
  261. .resource = &versatile_flash_resource,
  262. };
  263. static struct resource smc91x_resources[] = {
  264. [0] = {
  265. .start = VERSATILE_ETH_BASE,
  266. .end = VERSATILE_ETH_BASE + SZ_64K - 1,
  267. .flags = IORESOURCE_MEM,
  268. },
  269. [1] = {
  270. .start = IRQ_ETH,
  271. .end = IRQ_ETH,
  272. .flags = IORESOURCE_IRQ,
  273. },
  274. };
  275. static struct platform_device smc91x_device = {
  276. .name = "smc91x",
  277. .id = 0,
  278. .num_resources = ARRAY_SIZE(smc91x_resources),
  279. .resource = smc91x_resources,
  280. };
  281. #define VERSATILE_SYSMCI (__io_address(VERSATILE_SYS_BASE) + VERSATILE_SYS_MCI_OFFSET)
  282. unsigned int mmc_status(struct device *dev)
  283. {
  284. struct amba_device *adev = container_of(dev, struct amba_device, dev);
  285. u32 mask;
  286. if (adev->res.start == VERSATILE_MMCI0_BASE)
  287. mask = 1;
  288. else
  289. mask = 2;
  290. return readl(VERSATILE_SYSMCI) & mask;
  291. }
  292. static struct mmc_platform_data mmc0_plat_data = {
  293. .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
  294. .status = mmc_status,
  295. };
  296. /*
  297. * Clock handling
  298. */
  299. static const struct icst307_params versatile_oscvco_params = {
  300. .ref = 24000,
  301. .vco_max = 200000,
  302. .vd_min = 4 + 8,
  303. .vd_max = 511 + 8,
  304. .rd_min = 1 + 2,
  305. .rd_max = 127 + 2,
  306. };
  307. static void versatile_oscvco_set(struct clk *clk, struct icst307_vco vco)
  308. {
  309. void __iomem *sys_lock = __io_address(VERSATILE_SYS_BASE) + VERSATILE_SYS_LOCK_OFFSET;
  310. void __iomem *sys_osc = __io_address(VERSATILE_SYS_BASE) + VERSATILE_SYS_OSCCLCD_OFFSET;
  311. u32 val;
  312. val = readl(sys_osc) & ~0x7ffff;
  313. val |= vco.v | (vco.r << 9) | (vco.s << 16);
  314. writel(0xa05f, sys_lock);
  315. writel(val, sys_osc);
  316. writel(0, sys_lock);
  317. }
  318. static struct clk versatile_clcd_clk = {
  319. .name = "CLCDCLK",
  320. .params = &versatile_oscvco_params,
  321. .setvco = versatile_oscvco_set,
  322. };
  323. /*
  324. * CLCD support.
  325. */
  326. #define SYS_CLCD_MODE_MASK (3 << 0)
  327. #define SYS_CLCD_MODE_888 (0 << 0)
  328. #define SYS_CLCD_MODE_5551 (1 << 0)
  329. #define SYS_CLCD_MODE_565_RLSB (2 << 0)
  330. #define SYS_CLCD_MODE_565_BLSB (3 << 0)
  331. #define SYS_CLCD_NLCDIOON (1 << 2)
  332. #define SYS_CLCD_VDDPOSSWITCH (1 << 3)
  333. #define SYS_CLCD_PWR3V5SWITCH (1 << 4)
  334. #define SYS_CLCD_ID_MASK (0x1f << 8)
  335. #define SYS_CLCD_ID_SANYO_3_8 (0x00 << 8)
  336. #define SYS_CLCD_ID_UNKNOWN_8_4 (0x01 << 8)
  337. #define SYS_CLCD_ID_EPSON_2_2 (0x02 << 8)
  338. #define SYS_CLCD_ID_SANYO_2_5 (0x07 << 8)
  339. #define SYS_CLCD_ID_VGA (0x1f << 8)
  340. static struct clcd_panel vga = {
  341. .mode = {
  342. .name = "VGA",
  343. .refresh = 60,
  344. .xres = 640,
  345. .yres = 480,
  346. .pixclock = 39721,
  347. .left_margin = 40,
  348. .right_margin = 24,
  349. .upper_margin = 32,
  350. .lower_margin = 11,
  351. .hsync_len = 96,
  352. .vsync_len = 2,
  353. .sync = 0,
  354. .vmode = FB_VMODE_NONINTERLACED,
  355. },
  356. .width = -1,
  357. .height = -1,
  358. .tim2 = TIM2_BCD | TIM2_IPC,
  359. .cntl = CNTL_LCDTFT | CNTL_LCDVCOMP(1),
  360. .bpp = 16,
  361. };
  362. static struct clcd_panel sanyo_3_8_in = {
  363. .mode = {
  364. .name = "Sanyo QVGA",
  365. .refresh = 116,
  366. .xres = 320,
  367. .yres = 240,
  368. .pixclock = 100000,
  369. .left_margin = 6,
  370. .right_margin = 6,
  371. .upper_margin = 5,
  372. .lower_margin = 5,
  373. .hsync_len = 6,
  374. .vsync_len = 6,
  375. .sync = 0,
  376. .vmode = FB_VMODE_NONINTERLACED,
  377. },
  378. .width = -1,
  379. .height = -1,
  380. .tim2 = TIM2_BCD,
  381. .cntl = CNTL_LCDTFT | CNTL_LCDVCOMP(1),
  382. .bpp = 16,
  383. };
  384. static struct clcd_panel sanyo_2_5_in = {
  385. .mode = {
  386. .name = "Sanyo QVGA Portrait",
  387. .refresh = 116,
  388. .xres = 240,
  389. .yres = 320,
  390. .pixclock = 100000,
  391. .left_margin = 20,
  392. .right_margin = 10,
  393. .upper_margin = 2,
  394. .lower_margin = 2,
  395. .hsync_len = 10,
  396. .vsync_len = 2,
  397. .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  398. .vmode = FB_VMODE_NONINTERLACED,
  399. },
  400. .width = -1,
  401. .height = -1,
  402. .tim2 = TIM2_IVS | TIM2_IHS | TIM2_IPC,
  403. .cntl = CNTL_LCDTFT | CNTL_LCDVCOMP(1),
  404. .bpp = 16,
  405. };
  406. static struct clcd_panel epson_2_2_in = {
  407. .mode = {
  408. .name = "Epson QCIF",
  409. .refresh = 390,
  410. .xres = 176,
  411. .yres = 220,
  412. .pixclock = 62500,
  413. .left_margin = 3,
  414. .right_margin = 2,
  415. .upper_margin = 1,
  416. .lower_margin = 0,
  417. .hsync_len = 3,
  418. .vsync_len = 2,
  419. .sync = 0,
  420. .vmode = FB_VMODE_NONINTERLACED,
  421. },
  422. .width = -1,
  423. .height = -1,
  424. .tim2 = TIM2_BCD | TIM2_IPC,
  425. .cntl = CNTL_LCDTFT | CNTL_LCDVCOMP(1),
  426. .bpp = 16,
  427. };
  428. /*
  429. * Detect which LCD panel is connected, and return the appropriate
  430. * clcd_panel structure. Note: we do not have any information on
  431. * the required timings for the 8.4in panel, so we presently assume
  432. * VGA timings.
  433. */
  434. static struct clcd_panel *versatile_clcd_panel(void)
  435. {
  436. void __iomem *sys_clcd = __io_address(VERSATILE_SYS_BASE) + VERSATILE_SYS_CLCD_OFFSET;
  437. struct clcd_panel *panel = &vga;
  438. u32 val;
  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;
  448. else {
  449. printk(KERN_ERR "CLCD: unknown LCD panel ID 0x%08x, using VGA\n",
  450. val);
  451. panel = &vga;
  452. }
  453. return panel;
  454. }
  455. /*
  456. * Disable all display connectors on the interface module.
  457. */
  458. static void versatile_clcd_disable(struct clcd_fb *fb)
  459. {
  460. void __iomem *sys_clcd = __io_address(VERSATILE_SYS_BASE) + VERSATILE_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. #ifdef CONFIG_MACH_VERSATILE_AB
  466. /*
  467. * If the LCD is Sanyo 2x5 in on the IB2 board, turn the back-light off
  468. */
  469. if (machine_is_versatile_ab() && fb->panel == &sanyo_2_5_in) {
  470. void __iomem *versatile_ib2_ctrl = __io_address(VERSATILE_IB2_CTRL);
  471. unsigned long ctrl;
  472. ctrl = readl(versatile_ib2_ctrl);
  473. ctrl &= ~0x01;
  474. writel(ctrl, versatile_ib2_ctrl);
  475. }
  476. #endif
  477. }
  478. /*
  479. * Enable the relevant connector on the interface module.
  480. */
  481. static void versatile_clcd_enable(struct clcd_fb *fb)
  482. {
  483. void __iomem *sys_clcd = __io_address(VERSATILE_SYS_BASE) + VERSATILE_SYS_CLCD_OFFSET;
  484. u32 val;
  485. val = readl(sys_clcd);
  486. val &= ~SYS_CLCD_MODE_MASK;
  487. switch (fb->fb.var.green.length) {
  488. case 5:
  489. val |= SYS_CLCD_MODE_5551;
  490. break;
  491. case 6:
  492. val |= SYS_CLCD_MODE_565_RLSB;
  493. break;
  494. case 8:
  495. val |= SYS_CLCD_MODE_888;
  496. break;
  497. }
  498. /*
  499. * Set the MUX
  500. */
  501. writel(val, sys_clcd);
  502. /*
  503. * And now enable the PSUs
  504. */
  505. val |= SYS_CLCD_NLCDIOON | SYS_CLCD_PWR3V5SWITCH;
  506. writel(val, sys_clcd);
  507. #ifdef CONFIG_MACH_VERSATILE_AB
  508. /*
  509. * If the LCD is Sanyo 2x5 in on the IB2 board, turn the back-light on
  510. */
  511. if (machine_is_versatile_ab() && fb->panel == &sanyo_2_5_in) {
  512. void __iomem *versatile_ib2_ctrl = __io_address(VERSATILE_IB2_CTRL);
  513. unsigned long ctrl;
  514. ctrl = readl(versatile_ib2_ctrl);
  515. ctrl |= 0x01;
  516. writel(ctrl, versatile_ib2_ctrl);
  517. }
  518. #endif
  519. }
  520. static unsigned long framesize = SZ_1M;
  521. static int versatile_clcd_setup(struct clcd_fb *fb)
  522. {
  523. dma_addr_t dma;
  524. fb->panel = versatile_clcd_panel();
  525. fb->fb.screen_base = dma_alloc_writecombine(&fb->dev->dev, framesize,
  526. &dma, GFP_KERNEL);
  527. if (!fb->fb.screen_base) {
  528. printk(KERN_ERR "CLCD: unable to map framebuffer\n");
  529. return -ENOMEM;
  530. }
  531. fb->fb.fix.smem_start = dma;
  532. fb->fb.fix.smem_len = framesize;
  533. return 0;
  534. }
  535. static int versatile_clcd_mmap(struct clcd_fb *fb, struct vm_area_struct *vma)
  536. {
  537. return dma_mmap_writecombine(&fb->dev->dev, vma,
  538. fb->fb.screen_base,
  539. fb->fb.fix.smem_start,
  540. fb->fb.fix.smem_len);
  541. }
  542. static void versatile_clcd_remove(struct clcd_fb *fb)
  543. {
  544. dma_free_writecombine(&fb->dev->dev, fb->fb.fix.smem_len,
  545. fb->fb.screen_base, fb->fb.fix.smem_start);
  546. }
  547. static struct clcd_board clcd_plat_data = {
  548. .name = "Versatile",
  549. .check = clcdfb_check,
  550. .decode = clcdfb_decode,
  551. .disable = versatile_clcd_disable,
  552. .enable = versatile_clcd_enable,
  553. .setup = versatile_clcd_setup,
  554. .mmap = versatile_clcd_mmap,
  555. .remove = versatile_clcd_remove,
  556. };
  557. #define AACI_IRQ { IRQ_AACI, NO_IRQ }
  558. #define AACI_DMA { 0x80, 0x81 }
  559. #define MMCI0_IRQ { IRQ_MMCI0A,IRQ_SIC_MMCI0B }
  560. #define MMCI0_DMA { 0x84, 0 }
  561. #define KMI0_IRQ { IRQ_SIC_KMI0, NO_IRQ }
  562. #define KMI0_DMA { 0, 0 }
  563. #define KMI1_IRQ { IRQ_SIC_KMI1, NO_IRQ }
  564. #define KMI1_DMA { 0, 0 }
  565. /*
  566. * These devices are connected directly to the multi-layer AHB switch
  567. */
  568. #define SMC_IRQ { NO_IRQ, NO_IRQ }
  569. #define SMC_DMA { 0, 0 }
  570. #define MPMC_IRQ { NO_IRQ, NO_IRQ }
  571. #define MPMC_DMA { 0, 0 }
  572. #define CLCD_IRQ { IRQ_CLCDINT, NO_IRQ }
  573. #define CLCD_DMA { 0, 0 }
  574. #define DMAC_IRQ { IRQ_DMAINT, NO_IRQ }
  575. #define DMAC_DMA { 0, 0 }
  576. /*
  577. * These devices are connected via the core APB bridge
  578. */
  579. #define SCTL_IRQ { NO_IRQ, NO_IRQ }
  580. #define SCTL_DMA { 0, 0 }
  581. #define WATCHDOG_IRQ { IRQ_WDOGINT, NO_IRQ }
  582. #define WATCHDOG_DMA { 0, 0 }
  583. #define GPIO0_IRQ { IRQ_GPIOINT0, NO_IRQ }
  584. #define GPIO0_DMA { 0, 0 }
  585. #define GPIO1_IRQ { IRQ_GPIOINT1, NO_IRQ }
  586. #define GPIO1_DMA { 0, 0 }
  587. #define RTC_IRQ { IRQ_RTCINT, NO_IRQ }
  588. #define RTC_DMA { 0, 0 }
  589. /*
  590. * These devices are connected via the DMA APB bridge
  591. */
  592. #define SCI_IRQ { IRQ_SCIINT, NO_IRQ }
  593. #define SCI_DMA { 7, 6 }
  594. #define UART0_IRQ { IRQ_UARTINT0, NO_IRQ }
  595. #define UART0_DMA { 15, 14 }
  596. #define UART1_IRQ { IRQ_UARTINT1, NO_IRQ }
  597. #define UART1_DMA { 13, 12 }
  598. #define UART2_IRQ { IRQ_UARTINT2, NO_IRQ }
  599. #define UART2_DMA { 11, 10 }
  600. #define SSP_IRQ { IRQ_SSPINT, NO_IRQ }
  601. #define SSP_DMA { 9, 8 }
  602. /* FPGA Primecells */
  603. AMBA_DEVICE(aaci, "fpga:04", AACI, NULL);
  604. AMBA_DEVICE(mmc0, "fpga:05", MMCI0, &mmc0_plat_data);
  605. AMBA_DEVICE(kmi0, "fpga:06", KMI0, NULL);
  606. AMBA_DEVICE(kmi1, "fpga:07", KMI1, NULL);
  607. /* DevChip Primecells */
  608. AMBA_DEVICE(smc, "dev:00", SMC, NULL);
  609. AMBA_DEVICE(mpmc, "dev:10", MPMC, NULL);
  610. AMBA_DEVICE(clcd, "dev:20", CLCD, &clcd_plat_data);
  611. AMBA_DEVICE(dmac, "dev:30", DMAC, NULL);
  612. AMBA_DEVICE(sctl, "dev:e0", SCTL, NULL);
  613. AMBA_DEVICE(wdog, "dev:e1", WATCHDOG, NULL);
  614. AMBA_DEVICE(gpio0, "dev:e4", GPIO0, NULL);
  615. AMBA_DEVICE(gpio1, "dev:e5", GPIO1, NULL);
  616. AMBA_DEVICE(rtc, "dev:e8", RTC, NULL);
  617. AMBA_DEVICE(sci0, "dev:f0", SCI, NULL);
  618. AMBA_DEVICE(uart0, "dev:f1", UART0, NULL);
  619. AMBA_DEVICE(uart1, "dev:f2", UART1, NULL);
  620. AMBA_DEVICE(uart2, "dev:f3", UART2, NULL);
  621. AMBA_DEVICE(ssp0, "dev:f4", SSP, NULL);
  622. static struct amba_device *amba_devs[] __initdata = {
  623. &dmac_device,
  624. &uart0_device,
  625. &uart1_device,
  626. &uart2_device,
  627. &smc_device,
  628. &mpmc_device,
  629. &clcd_device,
  630. &sctl_device,
  631. &wdog_device,
  632. &gpio0_device,
  633. &gpio1_device,
  634. &rtc_device,
  635. &sci0_device,
  636. &ssp0_device,
  637. &aaci_device,
  638. &mmc0_device,
  639. &kmi0_device,
  640. &kmi1_device,
  641. };
  642. #ifdef CONFIG_LEDS
  643. #define VA_LEDS_BASE (__io_address(VERSATILE_SYS_BASE) + VERSATILE_SYS_LED_OFFSET)
  644. static void versatile_leds_event(led_event_t ledevt)
  645. {
  646. unsigned long flags;
  647. u32 val;
  648. local_irq_save(flags);
  649. val = readl(VA_LEDS_BASE);
  650. switch (ledevt) {
  651. case led_idle_start:
  652. val = val & ~VERSATILE_SYS_LED0;
  653. break;
  654. case led_idle_end:
  655. val = val | VERSATILE_SYS_LED0;
  656. break;
  657. case led_timer:
  658. val = val ^ VERSATILE_SYS_LED1;
  659. break;
  660. case led_halted:
  661. val = 0;
  662. break;
  663. default:
  664. break;
  665. }
  666. writel(val, VA_LEDS_BASE);
  667. local_irq_restore(flags);
  668. }
  669. #endif /* CONFIG_LEDS */
  670. void __init versatile_init(void)
  671. {
  672. int i;
  673. clk_register(&versatile_clcd_clk);
  674. platform_device_register(&versatile_flash_device);
  675. platform_device_register(&smc91x_device);
  676. for (i = 0; i < ARRAY_SIZE(amba_devs); i++) {
  677. struct amba_device *d = amba_devs[i];
  678. amba_device_register(d, &iomem_resource);
  679. }
  680. #ifdef CONFIG_LEDS
  681. leds_event = versatile_leds_event;
  682. #endif
  683. }
  684. /*
  685. * Where is the timer (VA)?
  686. */
  687. #define TIMER0_VA_BASE __io_address(VERSATILE_TIMER0_1_BASE)
  688. #define TIMER1_VA_BASE (__io_address(VERSATILE_TIMER0_1_BASE) + 0x20)
  689. #define TIMER2_VA_BASE __io_address(VERSATILE_TIMER2_3_BASE)
  690. #define TIMER3_VA_BASE (__io_address(VERSATILE_TIMER2_3_BASE) + 0x20)
  691. #define VA_IC_BASE __io_address(VERSATILE_VIC_BASE)
  692. /*
  693. * How long is the timer interval?
  694. */
  695. #define TIMER_INTERVAL (TICKS_PER_uSEC * mSEC_10)
  696. #if TIMER_INTERVAL >= 0x100000
  697. #define TIMER_RELOAD (TIMER_INTERVAL >> 8)
  698. #define TIMER_DIVISOR (TIMER_CTRL_DIV256)
  699. #define TICKS2USECS(x) (256 * (x) / TICKS_PER_uSEC)
  700. #elif TIMER_INTERVAL >= 0x10000
  701. #define TIMER_RELOAD (TIMER_INTERVAL >> 4) /* Divide by 16 */
  702. #define TIMER_DIVISOR (TIMER_CTRL_DIV16)
  703. #define TICKS2USECS(x) (16 * (x) / TICKS_PER_uSEC)
  704. #else
  705. #define TIMER_RELOAD (TIMER_INTERVAL)
  706. #define TIMER_DIVISOR (TIMER_CTRL_DIV1)
  707. #define TICKS2USECS(x) ((x) / TICKS_PER_uSEC)
  708. #endif
  709. /*
  710. * Returns number of ms since last clock interrupt. Note that interrupts
  711. * will have been disabled by do_gettimeoffset()
  712. */
  713. static unsigned long versatile_gettimeoffset(void)
  714. {
  715. unsigned long ticks1, ticks2, status;
  716. /*
  717. * Get the current number of ticks. Note that there is a race
  718. * condition between us reading the timer and checking for
  719. * an interrupt. We get around this by ensuring that the
  720. * counter has not reloaded between our two reads.
  721. */
  722. ticks2 = readl(TIMER0_VA_BASE + TIMER_VALUE) & 0xffff;
  723. do {
  724. ticks1 = ticks2;
  725. status = __raw_readl(VA_IC_BASE + VIC_RAW_STATUS);
  726. ticks2 = readl(TIMER0_VA_BASE + TIMER_VALUE) & 0xffff;
  727. } while (ticks2 > ticks1);
  728. /*
  729. * Number of ticks since last interrupt.
  730. */
  731. ticks1 = TIMER_RELOAD - ticks2;
  732. /*
  733. * Interrupt pending? If so, we've reloaded once already.
  734. *
  735. * FIXME: Need to check this is effectively timer 0 that expires
  736. */
  737. if (status & IRQMASK_TIMERINT0_1)
  738. ticks1 += TIMER_RELOAD;
  739. /*
  740. * Convert the ticks to usecs
  741. */
  742. return TICKS2USECS(ticks1);
  743. }
  744. /*
  745. * IRQ handler for the timer
  746. */
  747. static irqreturn_t versatile_timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  748. {
  749. write_seqlock(&xtime_lock);
  750. // ...clear the interrupt
  751. writel(1, TIMER0_VA_BASE + TIMER_INTCLR);
  752. timer_tick(regs);
  753. write_sequnlock(&xtime_lock);
  754. return IRQ_HANDLED;
  755. }
  756. static struct irqaction versatile_timer_irq = {
  757. .name = "Versatile Timer Tick",
  758. .flags = IRQF_DISABLED | IRQF_TIMER,
  759. .handler = versatile_timer_interrupt,
  760. };
  761. /*
  762. * Set up timer interrupt, and return the current time in seconds.
  763. */
  764. static void __init versatile_timer_init(void)
  765. {
  766. u32 val;
  767. /*
  768. * set clock frequency:
  769. * VERSATILE_REFCLK is 32KHz
  770. * VERSATILE_TIMCLK is 1MHz
  771. */
  772. val = readl(__io_address(VERSATILE_SCTL_BASE));
  773. writel((VERSATILE_TIMCLK << VERSATILE_TIMER1_EnSel) |
  774. (VERSATILE_TIMCLK << VERSATILE_TIMER2_EnSel) |
  775. (VERSATILE_TIMCLK << VERSATILE_TIMER3_EnSel) |
  776. (VERSATILE_TIMCLK << VERSATILE_TIMER4_EnSel) | val,
  777. __io_address(VERSATILE_SCTL_BASE));
  778. /*
  779. * Initialise to a known state (all timers off)
  780. */
  781. writel(0, TIMER0_VA_BASE + TIMER_CTRL);
  782. writel(0, TIMER1_VA_BASE + TIMER_CTRL);
  783. writel(0, TIMER2_VA_BASE + TIMER_CTRL);
  784. writel(0, TIMER3_VA_BASE + TIMER_CTRL);
  785. writel(TIMER_RELOAD, TIMER0_VA_BASE + TIMER_LOAD);
  786. writel(TIMER_RELOAD, TIMER0_VA_BASE + TIMER_VALUE);
  787. writel(TIMER_DIVISOR | TIMER_CTRL_ENABLE | TIMER_CTRL_PERIODIC |
  788. TIMER_CTRL_IE, TIMER0_VA_BASE + TIMER_CTRL);
  789. /*
  790. * Make irqs happen for the system timer
  791. */
  792. setup_irq(IRQ_TIMERINT0_1, &versatile_timer_irq);
  793. }
  794. struct sys_timer versatile_timer = {
  795. .init = versatile_timer_init,
  796. .offset = versatile_gettimeoffset,
  797. };