core.c 23 KB

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